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.Sat, 27 Oct 2018 10:51:52 +0200Strange factoring in e = (x+1)^3*(x+2)^3*(x+3)^3*(x+4)^3https://ask.sagemath.org/question/44051/strange-factoring-in-e-x13x23x33x43/After reading a question about QUORA I had fun with Sage to test expressions factoring.
If I ask to factorize e = (x+1)^3*(x+2)^3*(x+3)^3 everything is ok.
But when I ask to factorize e = (x+1)^3*(x+2)^3*(x+3)^3*(x+4)^3 the result surprises me and I do not understand why!
Here is my script and the results.
var('q')
e = (x+1)^3*(x+2)^3*(x+3)^3
print e
print "solve: ", solve(e,x)
#
R = ComplexField(16)['x'] # 16 donne 3 décimales et 32 donne 8 décimales
q = R(e)
print "factor: ", factor(q)
print
e = (x+1)^3*(x+2)^3*(x+3)^3*(x+4)^3
print e
print "solve: ", solve(e,x)
#
R = ComplexField(16)['x'] # 16 donne 3 décimales
q = R(e)
print factor(q)
print
#
R = ComplexField(32)['x'] # 32 donne 8 décimales
q = R(e)
print factor(q)
Now the results
(x + 3)^3*(x + 2)^3*(x + 1)^3
solve: [
x == -3,
x == -2,
x == -1
]
factor: (x + 1.000)^3 * (x + 2.000)^3 * (x + 3.000)^3
(x + 4)^3*(x + 3)^3*(x + 2)^3*(x + 1)^3
solve: [
x == -4,
x == -3,
x == -2,
x == -1
]
(x + 0.8452 - 0.1196*I) * (x + 0.8452 + 0.1196*I) * (x + 1.115 - 0.4330*I) * (x + 1.115 + 0.4330*I) * (x
+ 1.764 - 1.048*I) * (x + 1.764 + 1.048*I) * (x + 2.528) * (x + 2.988 - 1.554*I) * (x + 2.988 + 1.554*I)
* (x + 4.457 - 1.231*I) * (x + 4.457 + 1.231*I) * (x + 5.134)
(x + 1.00000000)^3 * (x + 2.00000000)^3 * (x + 3.00000000)^3 * (x + 4.00000000)^3
As you can see when I the use of **ComplexField(16)** give me 12 roots (10 complex ans 2 false reals for me).This is totally different of **ComplexField(32)** which give the right answer.
Why? Thank you in advance for enlightening my lantern.Wed, 24 Oct 2018 14:44:40 +0200https://ask.sagemath.org/question/44051/strange-factoring-in-e-x13x23x33x43/Answer by rburing for <p>After reading a question about QUORA I had fun with Sage to test expressions factoring.
If I ask to factorize e = (x+1)^3<em>(x+2)^3</em>(x+3)^3 everything is ok.
But when I ask to factorize e = (x+1)^3<em>(x+2)^3</em>(x+3)^3*(x+4)^3 the result surprises me and I do not understand why!
Here is my script and the results.</p>
<pre><code>var('q')
e = (x+1)^3*(x+2)^3*(x+3)^3
print e
print "solve: ", solve(e,x)
#
R = ComplexField(16)['x'] # 16 donne 3 décimales et 32 donne 8 décimales
q = R(e)
print "factor: ", factor(q)
print
e = (x+1)^3*(x+2)^3*(x+3)^3*(x+4)^3
print e
print "solve: ", solve(e,x)
#
R = ComplexField(16)['x'] # 16 donne 3 décimales
q = R(e)
print factor(q)
print
#
R = ComplexField(32)['x'] # 32 donne 8 décimales
q = R(e)
print factor(q)
</code></pre>
<p>Now the results</p>
<pre><code>(x + 3)^3*(x + 2)^3*(x + 1)^3
solve: [
x == -3,
x == -2,
x == -1
]
factor: (x + 1.000)^3 * (x + 2.000)^3 * (x + 3.000)^3
(x + 4)^3*(x + 3)^3*(x + 2)^3*(x + 1)^3
solve: [
x == -4,
x == -3,
x == -2,
x == -1
]
(x + 0.8452 - 0.1196*I) * (x + 0.8452 + 0.1196*I) * (x + 1.115 - 0.4330*I) * (x + 1.115 + 0.4330*I) * (x
+ 1.764 - 1.048*I) * (x + 1.764 + 1.048*I) * (x + 2.528) * (x + 2.988 - 1.554*I) * (x + 2.988 + 1.554*I)
* (x + 4.457 - 1.231*I) * (x + 4.457 + 1.231*I) * (x + 5.134)
(x + 1.00000000)^3 * (x + 2.00000000)^3 * (x + 3.00000000)^3 * (x + 4.00000000)^3
</code></pre>
<p>As you can see when I the use of <strong>ComplexField(16)</strong> give me 12 roots (10 complex ans 2 false reals for me).This is totally different of <strong>ComplexField(32)</strong> which give the right answer.
Why? Thank you in advance for enlightening my lantern.</p>
https://ask.sagemath.org/question/44051/strange-factoring-in-e-x13x23x33x43/?answer=44053#post-id-44053The reason is that Sage's polynomial rings work with *expanded* polynomials, and the coefficients in the (latter) expanded polynomial are too big to fit in 16 bits:
sage: R.<x> = QQ[]
sage: f = (x+1)^3*(x+2)^3*(x+3)^3*(x+4)^3; f
x^12 + 30*x^11 + 405*x^10 + 3250*x^9 + 17247*x^8 + 63690*x^7 + 167615*x^6 + 316350*x^5 + 424428*x^4 + 94280*x^3 + 240480*x^2 + 86400*x + 13824
sage: f.change_ring(ComplexField(16))
x^12 + 30.00*x^11 + 405.0*x^10 + 3250.*x^9 + 17250.*x^8 + 63690.*x^7 + 167600.*x^6 + 316400.*x^5 + 424400.*x^4 + 394300.*x^3 + 240500.*x^2 + 86400.*x + 13820.
You can also see the problem by adding `print q` statements to your code.Wed, 24 Oct 2018 16:40:52 +0200https://ask.sagemath.org/question/44051/strange-factoring-in-e-x13x23x33x43/?answer=44053#post-id-44053Comment by wisher for <p>The reason is that Sage's polynomial rings work with <em>expanded</em> polynomials, and the coefficients in the (latter) expanded polynomial are too big to fit in 16 bits:</p>
<pre><code>sage: R.<x> = QQ[]
sage: f = (x+1)^3*(x+2)^3*(x+3)^3*(x+4)^3; f
x^12 + 30*x^11 + 405*x^10 + 3250*x^9 + 17247*x^8 + 63690*x^7 + 167615*x^6 + 316350*x^5 + 424428*x^4 + 94280*x^3 + 240480*x^2 + 86400*x + 13824
sage: f.change_ring(ComplexField(16))
x^12 + 30.00*x^11 + 405.0*x^10 + 3250.*x^9 + 17250.*x^8 + 63690.*x^7 + 167600.*x^6 + 316400.*x^5 + 424400.*x^4 + 394300.*x^3 + 240500.*x^2 + 86400.*x + 13820.
</code></pre>
<p>You can also see the problem by adding <code>print q</code> statements to your code.</p>
https://ask.sagemath.org/question/44051/strange-factoring-in-e-x13x23x33x43/?comment=44095#post-id-44095Thank you very much for your answer. I think I understand it and do exercises on this subject. Actually **print q** in my code would have put me on the path. But I also believe that I still have a lot of work to do in the field of SAGE. I have downloaded the free book "Calcul Mathématique avec Sage- Alexandre Casamayou Nathann Cohen ....) and I will study particularly the chapters 11 and 7 that will be very useful, I think, to understand your explanation. Not a problem because I'm retired - I'm 78 years old - and I enjoy solving the little problems that I encounter on the internet (like Euler Project, Turing Challenge, ...) Again thank you for your answer. Excuse me for my Google translation.Sat, 27 Oct 2018 10:21:52 +0200https://ask.sagemath.org/question/44051/strange-factoring-in-e-x13x23x33x43/?comment=44095#post-id-44095Comment by rburing for <p>The reason is that Sage's polynomial rings work with <em>expanded</em> polynomials, and the coefficients in the (latter) expanded polynomial are too big to fit in 16 bits:</p>
<pre><code>sage: R.<x> = QQ[]
sage: f = (x+1)^3*(x+2)^3*(x+3)^3*(x+4)^3; f
x^12 + 30*x^11 + 405*x^10 + 3250*x^9 + 17247*x^8 + 63690*x^7 + 167615*x^6 + 316350*x^5 + 424428*x^4 + 94280*x^3 + 240480*x^2 + 86400*x + 13824
sage: f.change_ring(ComplexField(16))
x^12 + 30.00*x^11 + 405.0*x^10 + 3250.*x^9 + 17250.*x^8 + 63690.*x^7 + 167600.*x^6 + 316400.*x^5 + 424400.*x^4 + 394300.*x^3 + 240500.*x^2 + 86400.*x + 13820.
</code></pre>
<p>You can also see the problem by adding <code>print q</code> statements to your code.</p>
https://ask.sagemath.org/question/44051/strange-factoring-in-e-x13x23x33x43/?comment=44097#post-id-44097You're welcome. Indeed those are the relevant chapters in that book. You can accept my answer by clicking the checkmark on the left of it. Good luck with your studies and problem solving.Sat, 27 Oct 2018 10:51:52 +0200https://ask.sagemath.org/question/44051/strange-factoring-in-e-x13x23x33x43/?comment=44097#post-id-44097