ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 18 Aug 2016 17:26:36 -0500doubt about cyclotomic polynomialshttp://ask.sagemath.org/question/34467/doubt-about-cyclotomic-polynomials/ 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 ?Sun, 14 Aug 2016 03:45:13 -0500http://ask.sagemath.org/question/34467/doubt-about-cyclotomic-polynomials/Comment by FrédéricC for <pre><code> 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}
</code></pre>
<p>I don't understand the notation. What does the last line mean ?</p>
http://ask.sagemath.org/question/34467/doubt-about-cyclotomic-polynomials/?comment=34470#post-id-34470Read the doc. The result of this function is either the list of all coefficients, or a dictionary {index: coefficient}.Sun, 14 Aug 2016 08:01:37 -0500http://ask.sagemath.org/question/34467/doubt-about-cyclotomic-polynomials/?comment=34470#post-id-34470Answer by tmonteil for <pre><code> 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}
</code></pre>
<p>I don't understand the notation. What does the last line mean ?</p>
http://ask.sagemath.org/question/34467/doubt-about-cyclotomic-polynomials/?answer=34526#post-id-34526This 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 + 1Thu, 18 Aug 2016 17:26:36 -0500http://ask.sagemath.org/question/34467/doubt-about-cyclotomic-polynomials/?answer=34526#post-id-34526