Ask Your Question
1

Multiply polynomials from different rings

asked 2021-01-19 10:36:55 +0100

Sri1729 gravatar image

updated 2021-01-19 11:53:48 +0100

slelievre gravatar image

Suppose I take a polynomial from $K[x]$, say $x^2 + 5x$, and another polynomial from $K[y]$, say $y^3$. I want to formally multiply them and get $x^2y^3 + 5xy^3$ as the output.

How can I do that?

Note: K is the finite field of size 4 in a.

My efforts:

sage: K.<a> = FiniteField(4)

sage: R_1 = PolynomialRing(K, ['z%s' % p for p in range(1, 3)])
sage: R_2 = PolynomialRing(K, ['x%s' % p for p in range(1, 3)])

sage: pp = R_1.random_element()
sage: pp
(a + 1)*z1^2 + (a)*z1*z2 + (a + 1)*z2 + (a)

sage: qq = R_2.random_element()
sage: qq
x1*x2 + (a + 1)*x2^2 + x1 + 1

When I do pp*qq I get the following output

unsupported operand parent(s) for *: 'Multivariate Polynomial Ring
in z1, z2 over Finite Field in a of size 2^2' and 'Multivariate Polynomial
Ring in x1, x2 over Finite Field in a of size 2^2'
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-01-19 10:53:05 +0100

tmonteil gravatar image

Ther is not coercion (see the doc) defined between the two polynomial rings, so you have to construct a common parent by yourself and convert the polynomials. Here is a possible way:

First, you can get the names of the variables of both polynomial rings as follows:

sage: R_1.variable_names() + R_2.variable_names()
('z1', 'z2', 'x1', 'x2')

Then you can construct the polynomial ring with this new list of variable names:

sage: R = PolynomialRing(K, R_1.variable_names() + R_2.variable_names())
sage: R
Multivariate Polynomial Ring in z1, z2, x1, x2 over Finite Field in a of size 2^2

Then, you can convert a polynomial from R_1 to R:

sage: pp
(a)*z1^2 + (a)*z2^2 + z1 + z2
sage: pp.parent()
Multivariate Polynomial Ring in z1, z2 over Finite Field in a of size 2^2

sage: R(pp)
(a)*z1^2 + (a)*z2^2 + z1 + z2
sage: R(pp).parent()
Multivariate Polynomial Ring in z1, z2, x1, x2 over Finite Field in a of size 2^2

Now, you can add the converted polynomials within the new larger parent:

sage: R(pp) + R(qq)
(a)*z1^2 + (a)*z2^2 + (a)*x1^2 + x1*x2 + (a + 1)*x2^2 + z1 + z2 + 1
sage: rr = R(pp) + R(qq)
sage: rr
(a)*z1^2 + (a)*z2^2 + (a)*x1^2 + x1*x2 + (a + 1)*x2^2 + z1 + z2 + 1
sage: rr.parent()
Multivariate Polynomial Ring in z1, z2, x1, x2 over Finite Field in a of size 2^2
edit flag offensive delete link more

Comments

Don't have words to thank you. I spent a lot of time on this but still was not able to think about it. Have a good day :)

Sri1729 gravatar imageSri1729 ( 2021-01-19 10:57:55 +0100 )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: 2021-01-19 10:36:55 +0100

Seen: 297 times

Last updated: Jan 19 '21