ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 11 May 2015 12:30:22 -0500Demonstrating Cubic Formula to a Studenthttps://ask.sagemath.org/question/26795/demonstrating-cubic-formula-to-a-student/I'm trying to demonstrate the Lagrange approach to solving a cubic to a student.
w = CyclotomicField(3).gen()
x0 = var('x0')
x1 = var('x1')
x2 = var('x2')
s0 = x0 + x1 + x2
s1 = x0 + x1*w + x2*w^2
s2 = x0 + x1*w^2 + x2*w
After expanding `s1^3 + s2^3`, the output is cluttered with cube roots of unity (these _should_ cancel out).
I would like to treat `w` abstractly, where the only relevant constraints are `w^2 + w + 1 == 0` and `w^3 == 1`.
When simplifying, I would like it to collect all coefficients of powers of `w` and automatically apply the above rules (e.g: `w^2 + w == -1`).
Or -- is there some other way to do this?
Specifically, at least for the sake of readability, I would like to the roots to be represented only by `w`.Mon, 11 May 2015 06:36:30 -0500https://ask.sagemath.org/question/26795/demonstrating-cubic-formula-to-a-student/Answer by tmonteil for <p>I'm trying to demonstrate the Lagrange approach to solving a cubic to a student.</p>
<pre><code>w = CyclotomicField(3).gen()
x0 = var('x0')
x1 = var('x1')
x2 = var('x2')
s0 = x0 + x1 + x2
s1 = x0 + x1*w + x2*w^2
s2 = x0 + x1*w^2 + x2*w
</code></pre>
<p>After expanding <code>s1^3 + s2^3</code>, the output is cluttered with cube roots of unity (these _should_ cancel out).</p>
<p>I would like to treat <code>w</code> abstractly, where the only relevant constraints are <code>w^2 + w + 1 == 0</code> and <code>w^3 == 1</code>.</p>
<p>When simplifying, I would like it to collect all coefficients of powers of <code>w</code> and automatically apply the above rules (e.g: <code>w^2 + w == -1</code>).</p>
<p>Or -- is there some other way to do this?</p>
<p>Specifically, at least for the sake of readability, I would like to the roots to be represented only by <code>w</code>.</p>
https://ask.sagemath.org/question/26795/demonstrating-cubic-formula-to-a-student/?answer=26796#post-id-26796If you want to work on the symbolic ring (this is what you did with the way to define the variables `xi`), you should ask for simplification:
sage: (s1^3 + s2^3).full_simplify()
2*x0^3 - 3*x0^2*x1 - 3*x0*x1^2 + 2*x1^3 - 3*(x0 + x1)*x2^2 + 2*x2^3 - 3*(x0^2 - 4*x0*x1 + x1^2)*x2
This works in this case, but you will never be sure how far will the simplification be done. Otherwise, you should define the `xi` as indeterminates in a well-defined polynomial ring, not as elements of the symbolic ring:
sage: F = CyclotomicField(3)
sage: w = F.gen()
sage: R = PolynomialRing(F,3,'x') ; R
Multivariate Polynomial Ring in x0, x1, x2 over Cyclotomic Field of order 3 and degree 2
sage: R.inject_variables()
Defining x0, x1, x2
sage: s0 = x0 + x1 + x2
sage: s1 = x0 + x1*w + x2*w^2
sage: s2 = x0 + x1*w^2 + x2*w
sage: s1^3 + s2^3
2*x0^3 - 3*x0^2*x1 - 3*x0*x1^2 + 2*x1^3 - 3*x0^2*x2 + 12*x0*x1*x2 - 3*x1^2*x2 - 3*x0*x2^2 - 3*x1*x2^2 + 2*x2^3
Mon, 11 May 2015 08:30:59 -0500https://ask.sagemath.org/question/26795/demonstrating-cubic-formula-to-a-student/?answer=26796#post-id-26796Comment by coconuts for <p>If you want to work on the symbolic ring (this is what you did with the way to define the variables <code>xi</code>), you should ask for simplification:</p>
<pre><code>sage: (s1^3 + s2^3).full_simplify()
2*x0^3 - 3*x0^2*x1 - 3*x0*x1^2 + 2*x1^3 - 3*(x0 + x1)*x2^2 + 2*x2^3 - 3*(x0^2 - 4*x0*x1 + x1^2)*x2
</code></pre>
<p>This works in this case, but you will never be sure how far will the simplification be done. Otherwise, you should define the <code>xi</code> as indeterminates in a well-defined polynomial ring, not as elements of the symbolic ring:</p>
<pre><code>sage: F = CyclotomicField(3)
sage: w = F.gen()
sage: R = PolynomialRing(F,3,'x') ; R
Multivariate Polynomial Ring in x0, x1, x2 over Cyclotomic Field of order 3 and degree 2
sage: R.inject_variables()
Defining x0, x1, x2
sage: s0 = x0 + x1 + x2
sage: s1 = x0 + x1*w + x2*w^2
sage: s2 = x0 + x1*w^2 + x2*w
sage: s1^3 + s2^3
2*x0^3 - 3*x0^2*x1 - 3*x0*x1^2 + 2*x1^3 - 3*x0^2*x2 + 12*x0*x1*x2 - 3*x1^2*x2 - 3*x0*x2^2 - 3*x1*x2^2 + 2*x2^3
</code></pre>
https://ask.sagemath.org/question/26795/demonstrating-cubic-formula-to-a-student/?comment=26798#post-id-26798Thanks for the help! As you can see, I'm quite new at this. Is there anywhere I can get a "birds eye view" of the whole API? The documentation seems cluttered with test cases...Mon, 11 May 2015 12:30:22 -0500https://ask.sagemath.org/question/26795/demonstrating-cubic-formula-to-a-student/?comment=26798#post-id-26798