Ask Your Question
1

Converting polynomials between rings

asked 2014-09-19 14:44:21 +0200

Alasdair gravatar image

I have two polynomials, each one explicitly created as members of different multivariate polynomial rings. So for example I might have

R1.<a,b,c,t> = PolynomialRing(QQ) 
L = (a*t^2+b*t+c).subs(a=2,b=3,c=4)

R2.<A,B,C,D,t> = PolynomialRing(QQ)
p = (A*t+B)^2+(C*t+D)^2

Now I want to compare the coefficients of the two polynomials, which means converting L to be a polynomial in the ring R2.

However, I'm not sure (or more to the point, can't remember) how to do this. Is there some simple, canonical way to do this? Thanks!

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2014-09-19 16:39:45 +0200

slelievre gravatar image

In your example, having defined

sage: R1.<a,b,c,t> = PolynomialRing(QQ)
sage: L = (a*t^2+b*t+c).subs(a=2,b=3,c=4)

we get

sage: L
2*t^2 + 3*t + 4

(did you mean L = a*t^2+b*t+c without substituting values for a, b, c?)

Having then defined

sage: R2.<A,B,C,D,t> = PolynomialRing(QQ)
sage: p = (A*t+B)^2+(C*t+D)^2

you can convert polynomials from one ring to the other

sage: R2(L)
2*D^2 + 3*D + 4

Here, the order of the variables matters, more than their names: t, the fourth variable in R1, is mapped to D, the fourth variable in R2.

If you want a, b,c, t to be mapped to A, B, C, t, you might want to include an extra variable d in R1 and not use it.

Or you could compare string representations of your polynomials, applying string replacements as necessary. Or you could use p.monomials() and p.coefficients().

You could also define a ring homomorphism from R1 to R2 mapping the variables to the variables of your choice, see the reference manual.

edit flag offensive delete link more

Comments

Thank you very much. It seems as long as I have the same number of variables in each ring, then when I move from one to the other, the variables will be mapped in the order I've defined them. This makes perfect sense, not that I see how it works!

Alasdair gravatar imageAlasdair ( 2014-09-21 11:11:12 +0200 )edit

The variables for a polynomial ring `R` are just `R.0`, `R.1`, etc, (and `a`, `b`, `t`, `x`, `y`, or other, are just display names), so it's easy to map them to the variables `S.0`, `S.1` of another polynomial ring `S`.

slelievre gravatar imageslelievre ( 2014-09-21 11:24:23 +0200 )edit
0

answered 2014-09-19 16:25:39 +0200

Luca gravatar image

Because of the order you've defined the objects, L(t=t) will be an element of R2. Slightly more robustly, in your example you can do any of the following.

sage: L(t=R2.gen(4)).parent()
Multivariate Polynomial Ring in A, B, C, D, t over Rational Field
sage: L(t=R2.4).parent()
Multivariate Polynomial Ring in A, B, C, D, t over Rational Field
edit flag offensive delete link more

Comments

Thank you - this should work, and I'll check it later.

Alasdair gravatar imageAlasdair ( 2014-09-21 11:11:35 +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

Stats

Asked: 2014-09-19 14:44:21 +0200

Seen: 1,366 times

Last updated: Sep 19 '14