sage: from sage.rings.polynomial.cyclotomic import cyclotomic_coeffs
sage: cyclotomic_coeffs(30)
[1, 1, 0, -1, -1, -1, 0, 1, 1]
sage: cyclotomic_coeffs(10^5)
{0: 1, 10000: -1, 40000: 1, 30000: -1, 20000: 1}


I don't understand the notation. What does the last line mean ?

edit retag close merge delete

Read the doc. The result of this function is either the list of all coefficients, or a dictionary {index: coefficient}.

( 2016-08-14 15:01:37 +0200 )edit

Sort by » oldest newest most voted

This is the difference between dense and sparse representations. In the first case, the polynomial is x^8 + x^7 - x^5 - x^4 - x^3 + x + 1 so it can be represented as the list of its first 9 coefficients: [1, 1, 0, -1, -1, -1, 0, 1, 1]. In the second case, the polynomial is x^40000 - x^30000 + x^20000 - x^10000 + 1 so instead of storing the first 40001 coefficients, it is wiser to only store the nonzero ones. For this, Sage use a dictionary that tells that x^0 has coefficient 1, x^1000 has coefficient -1, and so on.

As written in the doc, you can get the polynomials as follows:

sage: R = QQ['x']
sage: R
Univariate Polynomial Ring in x over Rational Field
sage: R(cyclotomic_coeffs(30))
x^8 + x^7 - x^5 - x^4 - x^3 + x + 1
sage: R(cyclotomic_coeffs(10^5))
x^40000 - x^30000 + x^20000 - x^10000 + 1

more