Ask Your Question

Demonstrating Cubic Formula to a Student

asked 2015-05-11 13:36:30 +0200

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.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2015-05-11 15:30:59 +0200

tmonteil gravatar image

updated 2015-05-11 15:37:03 +0200

If 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
edit flag offensive delete link more


Thanks 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...

coconuts gravatar imagecoconuts ( 2015-05-11 19:30:22 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-05-11 13:36:30 +0200

Seen: 204 times

Last updated: May 11 '15