Ask Your Question
0

Sage convert SymbolicRing equation to symbolic expression

asked 2023-12-03 08:58:23 +0100

narodnik gravatar image

updated 2023-12-03 09:37:05 +0100

Often I want to group terms in different ways. Say for example, I wish to view my equation in terms of some variables $u, v, w$.

R.<u, v, w> = SR[]; var("α a13 a21 a23 a1 a3 a2 a4 a6")
x = α^2*u + a13*w;   y = a21*u + α^3*v + a23*w;  z = w
e = y^2*z + a1*x*y*z + a3*y*z^2 - (x^3 + a2*x^2*z + a4*x*z^2 + a6*z^3)
e

which gives me an expression expressed in terms of the generators $u, v, w$ as desired:

$$(-α^6)u^3 + (-3a_{13}α^4 - a_2α^4 + a_1a_{21}α^2 + a_{21}^2)u^2w + (a_1α^5 + 2a_{21}α^3)uvw + α^6v^2w + (-3a_{13}^2α^2 - 2a_{13}a_2α^2 + a_1a_{23}α^2 + a_1a_{13}a_{21} - a_4α^2 + 2a_{21}a_{23} + a_{21}a_3)uw^2 + (a_1a_{13}α^3 + 2a_{23}α^3 + a_3α^3)vw^2 + (-a_{13}^3 - a_{13}^2a_2 + a_1a_{13}a_{23} + a_{23}^2 + a_{23}a_3 - a_{13}a_4 - a_6)w^3 $$

However $\alpha^6 = 1$, so I want some way of expressing this, so I construct a quotient extension ring (please let me know if there's a better way):

R.<u, v, w> = SR[]; var("a13 a21 a23 a1 a3 a2 a4 a6")
S.<p> = R[]
T.<α> = S.quotient(p^6 - 1)
x = α^2*u + a13*w;   y = a21*u + α^3*v + a23*w;  z = w
e = y^2*z + a1*x*y*z + a3*y*z^2 - (x^3 + a2*x^2*z + a4*x*z^2 + a6*z^3)
e

$$a_1uvwα^5 + ((-3a_{13} - a_2)u^2w)α^4 + (2a_{21}uvw + (a_1a_{13} + 2a_{23} + a_3)vw^2)α^3 + (a_1a_{21}u^2w + (-3a_{13}^2 - 2a_{13}a_2 + a_1a_{23} - a_4)uw^2)α^2 - u^3 + a_{21}^2u^2w + v^2w + (a_1a_{13}a_{21} + 2a_{21}a_{23} + a_{21}a_3)uw^2 + (-a_{13}^3 - a_{13}^2a_2 + a_1a_{13}a_{23} + a_{23}^2 + a_{23}a_3 - a_{13}a_4 - a_6)w^3$$ which now consists of expressions in $u, v, w$ in $\alpha$, whereas I just want the expression in $u, v, w$.

I now try coercing $\alpha$ to a generic variable:

sage: var("q")
sage: e(α=q)
TypeError: 'PolynomialQuotientRing_generic_with_category.element_class' object is not callable
sage: e.lift()(p=S.coerce(q))

but the resulting expression still consists of expressions in $a_i$ over $u, v, w$ over $q$. Maybe I have to now convert it to a purely symbolic expression, and then convert it back to R.<u, v, w>?

var("u1 v1 w1")
e.lift()(p=S.coerce(q), u=u1, v=v1, w=w1)(u1=u, v1=v, w1=w)

Unfortunately this does not work for me. I just get an expression in u1, v1, w1... Any ideas?

EDIT: after playing around some more, here's what I came up with. Plz lmk if there's a better way:

sage: var("q")
sage: sum(a*q^i for i, a in enumerate(e.lift().coefficients(sparse=False)))
edit retag flag offensive close merge delete

Comments

As your expressions are polynomial, it's unclear why you insist on using symbolic ring. It'd be more functional and efficient to use polynomial rings over appropriate numerical rings, while rather inefficient symbolic ring should be used only as a "last resort" (when other rings are not sufficient). As for α, it's more natural to define K.<α> = CyclotomicField(6) upfront and then build other rings on the top of it.

Max Alekseyev gravatar imageMax Alekseyev ( 2023-12-03 17:04:31 +0100 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2023-12-03 10:05:51 +0100

narodnik gravatar image

Here's my solution in the end:

Convert equation to symbolic form. Make it homogenous. Then use the expr.coefficient(), expr.coefficients() and expr.monomials() methods.

edit flag offensive delete link more

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

Stats

Asked: 2023-12-03 08:58:23 +0100

Seen: 159 times

Last updated: Dec 03 '23