ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 21 Jan 2015 22:49:33 +0100A problem with changing ringshttps://ask.sagemath.org/question/25596/a-problem-with-changing-rings/Why is this piece of code not working?
a = 1; b = 1; c = 1; m = 1; k = 6; w = exp((2*pi*I*m )/k)
p = x^4 - 6*x^2 -x *(w^(a-c) + w^(c-a) + w^b + w^(-b) + w^(b-c) + w^(c-b) + w^a + w^(-a)) + (3 -w^c - w^(-c) - w^(a+b-c) - w^(-a-b+c) - w^(a-b) - w^(-a+b))
g = real_part(p).simplify()
q = g.change_ring(QQbar)
I would have thought that I can get the exact roots of `q` above using `.solve` since in the field of algebraic numbers (`QQbar`) the above should have exact roots.Wed, 21 Jan 2015 19:03:54 +0100https://ask.sagemath.org/question/25596/a-problem-with-changing-rings/Comment by tmonteil for <p>Why is this piece of code not working?</p>
<pre><code>a = 1; b = 1; c = 1; m = 1; k = 6; w = exp((2*pi*I*m )/k)
p = x^4 - 6*x^2 -x *(w^(a-c) + w^(c-a) + w^b + w^(-b) + w^(b-c) + w^(c-b) + w^a + w^(-a)) + (3 -w^c - w^(-c) - w^(a+b-c) - w^(-a-b+c) - w^(a-b) - w^(-a+b))
g = real_part(p).simplify()
q = g.change_ring(QQbar)
</code></pre>
<p>I would have thought that I can get the exact roots of <code>q</code> above using <code>.solve</code> since in the field of algebraic numbers (<code>QQbar</code>) the above should have exact roots.</p>
https://ask.sagemath.org/question/25596/a-problem-with-changing-rings/?comment=25598#post-id-25598It has been answered in [your previous question](http://ask.sagemath.org/question/25579/about-roots-of-a-certain-polynomial-equation/?answer=25590#post-id-25590), where you could discover the difference between a symbolic expression and a genuine polynomial.Wed, 21 Jan 2015 22:49:33 +0100https://ask.sagemath.org/question/25596/a-problem-with-changing-rings/?comment=25598#post-id-25598Answer by slelievre for <p>Why is this piece of code not working?</p>
<pre><code>a = 1; b = 1; c = 1; m = 1; k = 6; w = exp((2*pi*I*m )/k)
p = x^4 - 6*x^2 -x *(w^(a-c) + w^(c-a) + w^b + w^(-b) + w^(b-c) + w^(c-b) + w^a + w^(-a)) + (3 -w^c - w^(-c) - w^(a+b-c) - w^(-a-b+c) - w^(a-b) - w^(-a+b))
g = real_part(p).simplify()
q = g.change_ring(QQbar)
</code></pre>
<p>I would have thought that I can get the exact roots of <code>q</code> above using <code>.solve</code> since in the field of algebraic numbers (<code>QQbar</code>) the above should have exact roots.</p>
https://ask.sagemath.org/question/25596/a-problem-with-changing-rings/?answer=25597#post-id-25597Your `g` is an expression in Sage's symbolic ring.
sage: a, b, c, m, k = 1, 1, 1, 1, 6
sage: w = exp(2*pi*I*m/k)
sage: p = x^4 - 6*x^2 - x*(w^(a-c) + w^(c-a) + w^b + w^(-b) + w^(b-c) + w^(c-b) + w^a + w^(-a)) + (3 - w^c - w^(-c) - w^(a+b-c) - w^(-a-b+c) - w^(a-b) - w^(-a+b))
sage: g = real_part(p).simplify()
sage: g
x^4 - 6*x^2 - 6*x - 1
sage: g.parent()
Symbolic Ring
To turn it into a polynomial, use the `polynomial` method.
sage: q = g.polynomial(QQbar)
sage: q
x^4 - 6*x^2 - 6*x - 1
sage: q.parent()
Univariate Polynomial Ring in x over Algebraic Field
Now that it is an element in some polynomial ring, you can change ring:
sage: qq = q.change_ring(ZZ)
sage: qq
x^4 - 6*x^2 - 6*x - 1
sage: qq.parent()
Univariate Polynomial Ring in x over Integer Ring
Wed, 21 Jan 2015 19:50:14 +0100https://ask.sagemath.org/question/25596/a-problem-with-changing-rings/?answer=25597#post-id-25597