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.Mon, 26 Sep 2011 18:46:32 +0200Simplification of expression with exponentials.https://ask.sagemath.org/question/8344/simplification-of-expression-with-exponentials/Hello,
I am looking at expanding the product:
(a+b\*g+c\*g^2+d\*g^3)\*(a+b\*g^2+c\*g^4+d\*g)\*(a+b\*g^3+c\*g+d\*g^4)\*(a+b\*g^4+c\*g^3+d\*g^2)
where $g=e^{2\pi i /5}$ is a fifth root of unity. The problem is, after expanding, and telling sage the value of $g$, it does not collect terms according to the rule $1+g+g^2+g^3+g^4=0$ so there are over 5 times too many terms.
Is there any way to make this simplification automatic? For degrees higher then $5$ going through manually will not be an option. (It is almost faster to multiply everything myself then figure out the collection of the terms)
Thank you very much for any help on this, I have been stuck for the last whileMon, 26 Sep 2011 14:31:17 +0200https://ask.sagemath.org/question/8344/simplification-of-expression-with-exponentials/Answer by Dirk Danckaert for <p>Hello,</p>
<p>I am looking at expanding the product:</p>
<p>(a+b*g+c*g^2+d*g^3)*(a+b*g^2+c*g^4+d*g)*(a+b*g^3+c*g+d*g^4)*(a+b*g^4+c*g^3+d*g^2)</p>
<p>where $g=e^{2\pi i /5}$ is a fifth root of unity. The problem is, after expanding, and telling sage the value of $g$, it does not collect terms according to the rule $1+g+g^2+g^3+g^4=0$ so there are over 5 times too many terms.</p>
<p>Is there any way to make this simplification automatic? For degrees higher then $5$ going through manually will not be an option. (It is almost faster to multiply everything myself then figure out the collection of the terms)</p>
<p>Thank you very much for any help on this, I have been stuck for the last while</p>
https://ask.sagemath.org/question/8344/simplification-of-expression-with-exponentials/?answer=12690#post-id-12690Coincidentally, something like this was the first thing I did with SAGE. Glad I can help you. It's really magic, but here's how it goes. Try to copy this in a SAGE notebook cell:
R=PolynomialRing(ZZ,'x,a,b,c,d')
x,a,b,c,d=R.gens()
S=R.quotient(1+x+x^2+x^3+x^4,'g,a,b,c,d')
g,a,b,c,d=S.gens()
Just to make sure, evaluate
g^5-1
(it should work out to 0). Then evaluate
(a+b*g+c*g^2+d*g^3)*(a+b*g^2+c*g^4+d*g)*(a+b*g^3+c*g+d*g^4)*(a+b*g^4+c*g^3+d*g^2)
and sure enough, the answer follows:
a^4 - a^3*b + a^2*b^2 - a*b^3 + b^4 - a^3*c + 2*a^2*b*c - 3*a*b^2*c -
b^3*c + a^2*c^2 + 2*a*b*c^2 + b^2*c^2 - a*c^3 - b*c^3 + c^4 - a^3*d +
2*a^2*b*d + 2*a*b^2*d - b^3*d - 3*a^2*c*d - a*b*c*d + 2*b^2*c*d +
2*a*c^2*d - 3*b*c^2*d - c^3*d + a^2*d^2 - 3*a*b*d^2 + b^2*d^2 +
2*a*c*d^2 + 2*b*c*d^2 + c^2*d^2 - a*d^3 - b*d^3 - c*d^3 + d^4
Mon, 26 Sep 2011 18:36:53 +0200https://ask.sagemath.org/question/8344/simplification-of-expression-with-exponentials/?answer=12690#post-id-12690Comment by Eric Naslund for <p>Coincidentally, something like this was the first thing I did with SAGE. Glad I can help you. It's really magic, but here's how it goes. Try to copy this in a SAGE notebook cell:</p>
<pre><code>R=PolynomialRing(ZZ,'x,a,b,c,d')
x,a,b,c,d=R.gens()
S=R.quotient(1+x+x^2+x^3+x^4,'g,a,b,c,d')
g,a,b,c,d=S.gens()
</code></pre>
<p>Just to make sure, evaluate</p>
<pre><code>g^5-1
</code></pre>
<p>(it should work out to 0). Then evaluate</p>
<pre><code>(a+b*g+c*g^2+d*g^3)*(a+b*g^2+c*g^4+d*g)*(a+b*g^3+c*g+d*g^4)*(a+b*g^4+c*g^3+d*g^2)
</code></pre>
<p>and sure enough, the answer follows:</p>
<pre><code>a^4 - a^3*b + a^2*b^2 - a*b^3 + b^4 - a^3*c + 2*a^2*b*c - 3*a*b^2*c -
b^3*c + a^2*c^2 + 2*a*b*c^2 + b^2*c^2 - a*c^3 - b*c^3 + c^4 - a^3*d +
2*a^2*b*d + 2*a*b^2*d - b^3*d - 3*a^2*c*d - a*b*c*d + 2*b^2*c*d +
2*a*c^2*d - 3*b*c^2*d - c^3*d + a^2*d^2 - 3*a*b*d^2 + b^2*d^2 +
2*a*c*d^2 + 2*b*c*d^2 + c^2*d^2 - a*d^3 - b*d^3 - c*d^3 + d^4
</code></pre>
https://ask.sagemath.org/question/8344/simplification-of-expression-with-exponentials/?comment=21197#post-id-21197Excellent Thank you!!! I had resorted to what I call a "half clever work around". I found $e^{2\pi i/5}$ to 16 decimal places, and expand as a polynomial with $g$ as a variable, and in the last step I substituted the numerical value for $g$. I then had to manually go through and remove the terms of the form 1.2123123 e^{-16} which was a major pain. This is so much better, thanks! Mon, 26 Sep 2011 18:46:32 +0200https://ask.sagemath.org/question/8344/simplification-of-expression-with-exponentials/?comment=21197#post-id-21197