Processing math: 100%
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Sage convert SymbolicRing equation to symbolic expression

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)u3+(3a13α4a2α4+a1a21α2+a221)u2w+(a1α5+2a21α3)uvw+α6v2w+(3a213α22a13a2α2+a1a23α2+a1a13a21a4α2+2a21a23+a21a3)uw2+(a1a13α3+2a23α3+a3α3)vw2+(a313a213a2+a1a13a23+a223+a23a3a13a4a6)w3

However α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

a1uvwα5+((3a13a2)u2w)α4+(2a21uvw+(a1a13+2a23+a3)vw2)α3+(a1a21u2w+(3a2132a13a2+a1a23a4)uw2)α2u3+a221u2w+v2w+(a1a13a21+2a21a23+a21a3)uw2+(a313a213a2+a1a13a23+a223+a23a3a13a4a6)w3 which now consists of expressions in u,v,w in α, whereas I just want the expression in u,v,w.

I now try coercing α 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 ai 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?

Sage convert SymbolicRing equation to symbolic expression

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)u3+(3a13α4a2α4+a1a21α2+a221)u2w+(a1α5+2a21α3)uvw+α6v2w+(3a213α22a13a2α2+a1a23α2+a1a13a21a4α2+2a21a23+a21a3)uw2+(a1a13α3+2a23α3+a3α3)vw2+(a313a213a2+a1a13a23+a223+a23a3a13a4a6)w3

However α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

a1uvwα5+((3a13a2)u2w)α4+(2a21uvw+(a1a13+2a23+a3)vw2)α3+(a1a21u2w+(3a2132a13a2+a1a23a4)uw2)α2u3+a221u2w+v2w+(a1a13a21+2a21a23+a21a3)uw2+(a313a213a2+a1a13a23+a223+a23a3a13a4a6)w3 which now consists of expressions in u,v,w in α, whereas I just want the expression in u,v,w.

I now try coercing α 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 ai 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="">?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?

Sage convert SymbolicRing equation to symbolic expression

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)u3+(3a13α4a2α4+a1a21α2+a221)u2w+(a1α5+2a21α3)uvw+α6v2w+(3a213α22a13a2α2+a1a23α2+a1a13a21a4α2+2a21a23+a21a3)uw2+(a1a13α3+2a23α3+a3α3)vw2+(a313a213a2+a1a13a23+a223+a23a3a13a4a6)w3

However α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

a1uvwα5+((3a13a2)u2w)α4+(2a21uvw+(a1a13+2a23+a3)vw2)α3+(a1a21u2w+(3a2132a13a2+a1a23a4)uw2)α2u3+a221u2w+v2w+(a1a13a21+2a21a23+a21a3)uw2+(a313a213a2+a1a13a23+a223+a23a3a13a4a6)w3 which now consists of expressions in u,v,w in α, whereas I just want the expression in u,v,w.

I now try coercing α 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 ai 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)))