Ask Your Question
2

polynomial variable rewrite

asked 2023-01-23 18:24:57 +0200

ittayd gravatar image

Say I have a polynomial (over a ring) x^4+x^2+1. I want to change variables t=x^2 so it becomes t^2+t+1, and if possible rename back to x^2+x+1. How do I do that?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2023-01-23 18:43:10 +0200

tmonteil gravatar image

updated 2023-01-23 18:43:51 +0200

To express the fact that $t=x^2$ you can define a quotient:

sage: R.<x,t> = PolynomialRing(QQ)
sage: p = x^4+x^2+1
sage: Q = R.quotient(x^2-t)
sage: Q
Quotient of Multivariate Polynomial Ring in x, t over Rational Field by the ideal (x^2 - t)
sage: q = Q(p)
sage: q
tbar^2 + tbar + 1
sage: q.parent()
Quotient of Multivariate Polynomial Ring in x, t over Rational Field by the ideal (x^2 - t)

Tu put the result back in the ring R and letting the undeterminate t go to x, you can do:

sage: q.lift()
t^2 + t + 1
sage: q.lift().subs(t=x)
x^2 + x + 1
edit flag offensive delete link more

Comments

Is there a shorter way if I don't go through t?

ittayd gravatar imageittayd ( 2023-01-23 19:53:48 +0200 )edit

Also, I initialized the ring via

F = GF(p)
R.<x> = F['x']
f = R.lagrange_polynomial(fib)

If I try to introduce 't', I get an error that the class doesn't have lagrange_polynomial

ittayd gravatar imageittayd ( 2023-01-23 19:58:38 +0200 )edit
0

answered 2023-01-27 22:28:35 +0200

dan_fulea gravatar image

Here are two other ways to proceed, depending on context the one or the other one may be more attractive.

First, note that if we have a polynomial, element of a polynomial ring, we have full access to the monomials, and their coefficients. I will illustrate this using a polynomial ring $R=\Bbb Q[t]$ of only one variable, $t$. And the result will be a polynomial in an other ring, $S=\Bbb Q[x]$, as wanted. So far:

R.<t> = PolynomialRing(QQ)    # or just simply R.<t> = QQ[]
S.<x> = PolynomialRing(QQ)    # or just simply S.<x> = QQ[]
f = 2023*t^8 - t^6 + 77*t^2 + 8937

Then we have an iterator associated to pol, thus access to the coefficients and to the powers. Using it...

sage: for coef in f: print(coef)
8937
0
77
0
0
0
-1
0
2023
sage: f.coefficients(sparse=False)
[8937, 0, 77, 0, 0, 0, -1, 0, 2023]
sage: # but be aware of the default...
sage: f.coefficients()
[8937, 77, -1, 2023]
sage: cfs = f.coefficients(sparse=False)

And we can loop, or use list comprehension.

sage: g = sum([cfs[k]*x^(k/2) for k in range(len(cfs)) if k%2 == 0])
sage: g
2023*x^4 - x^3 + 77*x + 8937

An other idea is to use an ideal and to eliminate, in this case however the parent ring contains both unknowns.

R.<t,x> = Polynomialing(QQ)
f = 2023*t^8 - t^6 + 77*t^2 + 8937
J = R.ideal([f, t^2 - x])

And now:

sage: J.elimination_ideal(t)
Ideal (2023*x^4 - x^3 + 77*x + 8937) of Multivariate Polynomial Ring in t, x over Rational Field
sage: J.elimination_ideal(t).gens()
[2023*x^4 - x^3 + 77*x + 8937]
sage: J.elimination_ideal(t).gens()[0]
2023*x^4 - x^3 + 77*x + 8937
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

Stats

Asked: 2023-01-23 18:24:57 +0200

Seen: 302 times

Last updated: Jan 27 '23