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.Thu, 24 Aug 2017 08:21:27 +0200Sage not returning roots of polynomimalhttps://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/ I have a polynomial
w=q^32 - q^30 + 3*q^28 - 3*q^26 + 6*q^24 - 6*q^22 + 9*q^20 - 9*q^18 + 12*q^16 - 9*q^14 + 9*q^12 - 6*q^10 + 6*q^8 - 3*q^6 + 3*q^4 - q^2 + 1
and I tried using
solve(w==0,q).
But sage only returns
[0 == q^32 - q^30 + 3*q^28 - 3*q^26 + 6*q^24 - 6*q^22 + 9*q^20 - 9*q^18 + 12*q^16 - 9*q^14 + 9*q^12 - 6*q^10 + 6*q^8 - 3*q^6 + 3*q^4 - q^2 + 1]
why is this? I'm looking for complex roots.Fri, 28 Jul 2017 23:58:17 +0200https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/Comment by mforets for <p>I have a polynomial</p>
<p>w=q^32 - q^30 + 3<em>q^28 - 3</em>q^26 + 6<em>q^24 - 6</em>q^22 + 9<em>q^20 - 9</em>q^18 + 12<em>q^16 - 9</em>q^14 + 9<em>q^12 - 6</em>q^10 + 6<em>q^8 - 3</em>q^6 + 3*q^4 - q^2 + 1</p>
<p>and I tried using
solve(w==0,q).</p>
<p>But sage only returns</p>
<p>[0 == q^32 - q^30 + 3<em>q^28 - 3</em>q^26 + 6<em>q^24 - 6</em>q^22 + 9<em>q^20 - 9</em>q^18 + 12<em>q^16 - 9</em>q^14 + 9<em>q^12 - 6</em>q^10 + 6<em>q^8 - 3</em>q^6 + 3*q^4 - q^2 + 1]</p>
<p>why is this? I'm looking for complex roots.</p>
https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/?comment=38433#post-id-38433also for approx solutions, try with: `solve(f, x, to_poly_solve=True)`Sat, 29 Jul 2017 08:33:00 +0200https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/?comment=38433#post-id-38433Answer by Emmanuel Charpentier for <p>I have a polynomial</p>
<p>w=q^32 - q^30 + 3<em>q^28 - 3</em>q^26 + 6<em>q^24 - 6</em>q^22 + 9<em>q^20 - 9</em>q^18 + 12<em>q^16 - 9</em>q^14 + 9<em>q^12 - 6</em>q^10 + 6<em>q^8 - 3</em>q^6 + 3*q^4 - q^2 + 1</p>
<p>and I tried using
solve(w==0,q).</p>
<p>But sage only returns</p>
<p>[0 == q^32 - q^30 + 3<em>q^28 - 3</em>q^26 + 6<em>q^24 - 6</em>q^22 + 9<em>q^20 - 9</em>q^18 + 12<em>q^16 - 9</em>q^14 + 9<em>q^12 - 6</em>q^10 + 6<em>q^8 - 3</em>q^6 + 3*q^4 - q^2 + 1]</p>
<p>why is this? I'm looking for complex roots.</p>
https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/?answer=38434#post-id-38434Try :
SQ=w.roots(ring=QQbar)
(or, equivalently, replace CC by QQbar in fidbc's answer). It turns out that :
sage: SQ[0][0].parent()
Algebraic Field
which is exact :
sage: SQ[0][0].parent().is_exact()
True
a property that holds for all the roots thus obtained :
sage: all(map(lambda r:r[0].parent().is_exact(), SQ))
True
(Here, "exact" means that Sage can give you arbitrary precision for a numerical approximation). However, you won't (always : you might get lucky, but there is no guarantee...) get algebraic expressions for that (ISTR that someone called Galois explained why...).
If you need algebraic expressions of these roots and happen to be able to read French, you might have a look at the excellent ["Calcul mathématique avec Sage"](http://sagebook.gforge.inria.fr/), which IMHO, should be translated in English, and might benefit from an updated edition : Sage(math) has made huge progress since this book was written).
You might also explicitely work in the ring of polynomials in q, but I'll defer to the official documentation...
HTH,Sat, 29 Jul 2017 12:24:25 +0200https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/?answer=38434#post-id-38434Comment by vdelecroix for <p>Try :</p>
<pre><code>SQ=w.roots(ring=QQbar)
</code></pre>
<p>(or, equivalently, replace CC by QQbar in fidbc's answer). It turns out that :</p>
<pre><code>sage: SQ[0][0].parent()
Algebraic Field
</code></pre>
<p>which is exact :</p>
<pre><code>sage: SQ[0][0].parent().is_exact()
True
</code></pre>
<p>a property that holds for all the roots thus obtained :</p>
<pre><code>sage: all(map(lambda r:r[0].parent().is_exact(), SQ))
True
</code></pre>
<p>(Here, "exact" means that Sage can give you arbitrary precision for a numerical approximation). However, you won't (always : you might get lucky, but there is no guarantee...) get algebraic expressions for that (ISTR that someone called Galois explained why...).</p>
<p>If you need algebraic expressions of these roots and happen to be able to read French, you might have a look at the excellent <a href="http://sagebook.gforge.inria.fr/">"Calcul mathématique avec Sage"</a>, which IMHO, should be translated in English, and might benefit from an updated edition : Sage(math) has made huge progress since this book was written).</p>
<p>You might also explicitely work in the ring of polynomials in q, but I'll defer to the official documentation...</p>
<p>HTH,</p>
https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/?comment=38435#post-id-38435"Calcul Mathématique avec Sage" has a preliminary english version available on their website!Sat, 29 Jul 2017 14:15:31 +0200https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/?comment=38435#post-id-38435Comment by Emmanuel Charpentier for <p>Try :</p>
<pre><code>SQ=w.roots(ring=QQbar)
</code></pre>
<p>(or, equivalently, replace CC by QQbar in fidbc's answer). It turns out that :</p>
<pre><code>sage: SQ[0][0].parent()
Algebraic Field
</code></pre>
<p>which is exact :</p>
<pre><code>sage: SQ[0][0].parent().is_exact()
True
</code></pre>
<p>a property that holds for all the roots thus obtained :</p>
<pre><code>sage: all(map(lambda r:r[0].parent().is_exact(), SQ))
True
</code></pre>
<p>(Here, "exact" means that Sage can give you arbitrary precision for a numerical approximation). However, you won't (always : you might get lucky, but there is no guarantee...) get algebraic expressions for that (ISTR that someone called Galois explained why...).</p>
<p>If you need algebraic expressions of these roots and happen to be able to read French, you might have a look at the excellent <a href="http://sagebook.gforge.inria.fr/">"Calcul mathématique avec Sage"</a>, which IMHO, should be translated in English, and might benefit from an updated edition : Sage(math) has made huge progress since this book was written).</p>
<p>You might also explicitely work in the ring of polynomials in q, but I'll defer to the official documentation...</p>
<p>HTH,</p>
https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/?comment=38446#post-id-38446Thanks, Vincent. I wasn't aware of this...Sun, 30 Jul 2017 20:57:00 +0200https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/?comment=38446#post-id-38446Comment by rws for <p>Try :</p>
<pre><code>SQ=w.roots(ring=QQbar)
</code></pre>
<p>(or, equivalently, replace CC by QQbar in fidbc's answer). It turns out that :</p>
<pre><code>sage: SQ[0][0].parent()
Algebraic Field
</code></pre>
<p>which is exact :</p>
<pre><code>sage: SQ[0][0].parent().is_exact()
True
</code></pre>
<p>a property that holds for all the roots thus obtained :</p>
<pre><code>sage: all(map(lambda r:r[0].parent().is_exact(), SQ))
True
</code></pre>
<p>(Here, "exact" means that Sage can give you arbitrary precision for a numerical approximation). However, you won't (always : you might get lucky, but there is no guarantee...) get algebraic expressions for that (ISTR that someone called Galois explained why...).</p>
<p>If you need algebraic expressions of these roots and happen to be able to read French, you might have a look at the excellent <a href="http://sagebook.gforge.inria.fr/">"Calcul mathématique avec Sage"</a>, which IMHO, should be translated in English, and might benefit from an updated edition : Sage(math) has made huge progress since this book was written).</p>
<p>You might also explicitely work in the ring of polynomials in q, but I'll defer to the official documentation...</p>
<p>HTH,</p>
https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/?comment=38633#post-id-38633sage: print([SQ[i*2][0].minpoly().degree() for i in range(16)])
[32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]Thu, 24 Aug 2017 08:21:27 +0200https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/?comment=38633#post-id-38633Answer by dan_fulea for <p>I have a polynomial</p>
<p>w=q^32 - q^30 + 3<em>q^28 - 3</em>q^26 + 6<em>q^24 - 6</em>q^22 + 9<em>q^20 - 9</em>q^18 + 12<em>q^16 - 9</em>q^14 + 9<em>q^12 - 6</em>q^10 + 6<em>q^8 - 3</em>q^6 + 3*q^4 - q^2 + 1</p>
<p>and I tried using
solve(w==0,q).</p>
<p>But sage only returns</p>
<p>[0 == q^32 - q^30 + 3<em>q^28 - 3</em>q^26 + 6<em>q^24 - 6</em>q^22 + 9<em>q^20 - 9</em>q^18 + 12<em>q^16 - 9</em>q^14 + 9<em>q^12 - 6</em>q^10 + 6<em>q^8 - 3</em>q^6 + 3*q^4 - q^2 + 1]</p>
<p>why is this? I'm looking for complex roots.</p>
https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/?answer=38439#post-id-38439This is a further answer to the question, although [fidbc](https://ask.sagemath.org/users/382/fidbc/) and [Emmanuel Charpentier](https://ask.sagemath.org/users/1336/emmanuel-charpentier/) did already said all.
But the given polynomial is a special one, it is a **reciprocal polynomial in $q^2$**, so we may go some steps further. (But unfortunately i could not find an explicit form either.)
So it is natural to make the substitution
$$ t = q^2+\frac 1 {q^2}=q^2+r^2\ , r =\frac 1q\ .$$
I am doing this substitutions my way...
R.<q,r, t> = PolynomialRing(QQ)
W = q^32 - q^30 + 3*q^28 - 3*q^26 + 6*q^24 - 6*q^22 + 9*q^20 - 9*q^18 + 12*q^16 - 9*q^14 + 9*q^12 - 6*q^10 + 6*q^8 - 3*q^6 + 3*q^4 - q^2 + 1
J = R.ideal( [ W, q^2 + r^2 - t, q*r-1 ] )
K = J.elimination_ideal( [ q,r ] )
P = K.gens()[0]
print P
and the polynomial in $t$ is after substitution (or rather elimination):
sage: print P
t^8 - t^7 - 5*t^6 + 4*t^5 + 8*t^4 - 5*t^3 - 4*t^2 + t + 2
(*The further lines are misleading unless we are searching for exact solutions...*)
The roots of this polynomial are:
sage: var( 't' );
sage: P = t^8 - t^7 - 5*t^6 + 4*t^5 + 8*t^4 - 5*t^3 - 4*t^2 + t + 2
sage: for root in P.roots( ring=QQbar, multiplicities=False ):
....: print root
....:
1.514032200639550?
1.791264905617066?
-1.480484671919947? - 0.2566820580880113?*I
-1.480484671919947? + 0.2566820580880113?*I
-0.4934011167978715? - 0.4011241207989847?*I
-0.4934011167978715? + 0.4011241207989847?*I
0.8212372355895106? - 0.3652199571071136?*I
0.8212372355895106? + 0.3652199571071136?*I
and the two real $t$-roots correspond to the eight roots of absolute value one of the initial polynomial:
sage: R.<q> = PolynomialRing(QQ)
....: W = q^32 - q^30 + 3*q^28 - 3*q^26 + 6*q^24 - 6*q^22 + 9*q^20 - 9*q^18 + 12*q^16 - 9*q^14 + 9*q^12 - 6*q^10 + 6*q^8 - 3*q^6 + 3*q^4 - q^2 + 1
sage: for w in W.roots( ring=QQbar, multiplicities=False ):
....: if abs(w) != 1: continue
....: print "w = %s |w| = %.2f w^2 + w^-2 = %.8f" % ( w, abs(w), w^2+w^-2 )
....:
w = -0.9735585377388802? - 0.2284376798948314?*I |w| = 1.00 w^2 + w^-2 = 1.79126491
w = -0.9735585377388802? + 0.2284376798948314?*I |w| = 1.00 w^2 + w^-2 = 1.79126491
w = -0.9372876026918778? - 0.3485569535099145?*I |w| = 1.00 w^2 + w^-2 = 1.51403220
w = -0.9372876026918778? + 0.3485569535099145?*I |w| = 1.00 w^2 + w^-2 = 1.51403220
w = 0.9372876026918778? - 0.3485569535099145?*I |w| = 1.00 w^2 + w^-2 = 1.51403220
w = 0.9372876026918778? + 0.3485569535099145?*I |w| = 1.00 w^2 + w^-2 = 1.51403220
w = 0.9735585377388802? - 0.2284376798948314?*I |w| = 1.00 w^2 + w^-2 = 1.79126491
w = 0.9735585377388802? + 0.2284376798948314?*I |w| = 1.00 w^2 + w^-2 = 1.79126491
So it is enough to understand the roots of
$$ P = t^{8} - t^{7} - 5 t^{6} + 4 t^{5} + 8 t^{4} - 5 t^{3} - 4 t^{2} + t + 2\ . $$
Now - sometimes, but only sometimes - there is an implemented luck that allows to factorize a polynomial over some smaller field. In our case there is no obvious choice, since we cannot find easy subfields of the splitting field of $P$.
sage: K.<a> = NumberField( P )
sage: for L, _, _ in K.subfields():
....: print "Subfield of degree %s and discriminant %s" % ( L.degree(), L.disc().factor() )
Subfield of degree 1 and discriminant 1
Subfield of degree 8 and discriminant -1 * 3^9 * 21157
Now i would need some more mathematical insight about the initial `W`, this in the hope that we can still solve by radicals. Sometimes, after adjoining a special element there appear subfields, and one can split over them. For instance, starting with the simple polynomial $Q=x^3-x-1$, there are no non-trivial subfields of `NumberField(Q)`. But if we adjoin $\sqrt{-23}$...
sage: _.<x> = QQ[]
sage: Q = x^3 -x -1
sage: K.<b> = NumberField( Q )
sage: for L, _, _ in K.subfields(): print L.degree(), L.disc()
1 1
3 -23
K.<b,c> = NumberField( Q, x^2+23 )
sage: for L, _, _ in K.subfields(): print L.degree(), L.disc()
1 1
2 -23
3 -23
3 -23
3 -23
6 -12167
there is a field of degree $2$, that is helping us to "solve the cubic". Of course, things would be clear, if sage could deliver in real time the Galois closure, for instance...
R.<t> = PolynomialRing( QQ )
P = t^8 - t^7 - 5*t^6 + 4*t^5 + 8*t^4 - 5*t^3 - 4*t^2 + t + 2
K.<a> = NumberField( P )
L.<b> = K.galois_closure()
(Had to abort the computation after a while.) So is there geometric insight for the initial polynomial `W`. (E.g. do we count points of some variety...?!)Sat, 29 Jul 2017 17:34:43 +0200https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/?answer=38439#post-id-38439Answer by fidbc for <p>I have a polynomial</p>
<p>w=q^32 - q^30 + 3<em>q^28 - 3</em>q^26 + 6<em>q^24 - 6</em>q^22 + 9<em>q^20 - 9</em>q^18 + 12<em>q^16 - 9</em>q^14 + 9<em>q^12 - 6</em>q^10 + 6<em>q^8 - 3</em>q^6 + 3*q^4 - q^2 + 1</p>
<p>and I tried using
solve(w==0,q).</p>
<p>But sage only returns</p>
<p>[0 == q^32 - q^30 + 3<em>q^28 - 3</em>q^26 + 6<em>q^24 - 6</em>q^22 + 9<em>q^20 - 9</em>q^18 + 12<em>q^16 - 9</em>q^14 + 9<em>q^12 - 6</em>q^10 + 6<em>q^8 - 3</em>q^6 + 3*q^4 - q^2 + 1]</p>
<p>why is this? I'm looking for complex roots.</p>
https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/?answer=38432#post-id-38432Maybe not all roots of `w` can be found exactly. You may be able to obtain approximations with the following code.
P=CC[x](x^32 - x^30 + 3*x^28 - 3*x^26 + 6*x^24 - 6*x^22 + 9*x^20 - 9*x^18 + 12*x^16 - 9*x^14 + 9*x^12 - 6*x^10 + 6*x^8 - 3*x^6 + 3*x^4 - x^2 + 1)
P.roots()
Here `CC` denotes the Complex Field and `CC[x]` denotes the Polynomial Ring over `CC`.Sat, 29 Jul 2017 08:15:40 +0200https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/?answer=38432#post-id-38432Comment by Emmanuel Charpentier for <p>Maybe not all roots of <code>w</code> can be found exactly. You may be able to obtain approximations with the following code.</p>
<pre><code>P=CC[x](x^32 - x^30 + 3*x^28 - 3*x^26 + 6*x^24 - 6*x^22 + 9*x^20 - 9*x^18 + 12*x^16 - 9*x^14 + 9*x^12 - 6*x^10 + 6*x^8 - 3*x^6 + 3*x^4 - x^2 + 1)
P.roots()
</code></pre>
<p>Here <code>CC</code> denotes the Complex Field and <code>CC[x]</code> denotes the Polynomial Ring over <code>CC</code>.</p>
https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/?comment=38447#post-id-38447To be precise :
sage: CC
Complex Field with 53 bits of precision
It is a set of numerical approximations... and therefore not exact. Hence the interestof working in QQbar, which is exact (i. e. it can hold algebraic properties if your variables and give you arbitrary precision). OTOH, if you have to explicitly use a transcendental quantity (such as $\pi$), you're SOL (unless you are willing to replace it by some algebraic approximation of precision sufficient for your needs).
HTH,Sun, 30 Jul 2017 21:15:26 +0200https://ask.sagemath.org/question/38429/sage-not-returning-roots-of-polynomimal/?comment=38447#post-id-38447