Ask Your Question
1

substitution of variable in the result of monomials()

asked 2019-12-19 20:18:18 +0100

rue82 gravatar image

Given a polynomial in n variables, I'd like to extract the list of its monomials, and then manipulate that list by substituting certain variables for others. Simple example: in $Z[x,y]$ consider the polynomial $1+x+y^2$; the list of its monomials (in some ordering) is $(1,x,y^2)$. My function should be able e.g. to take that list and substitute $y$ with $x$, namely return $[1,x,x^2]$.

At the moment, my code gives error, but I do not understand how to fix it.

N.<x1,x2> = PolynomialRing(ZZ, 2)
f = 1+x1+x2
g = f.monomials()
for i in range(3):
   g[i] = g[i].substitute_expression(x2==x1)

Namely, how do I make a variable in the polynomial ring also have the substitute attribute? or is there a better way to achieve this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-12-20 00:56:24 +0100

tmonteil gravatar image

Substitutions can be explicitely defined through dictionaries. How about:

sage: R.<x,y> = ZZ[]
sage: f = 1+x+y^2
sage: [p.substitute({y:x}) for p in f.monomials()]
[x^2, x, 1]
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: 2019-12-19 20:18:18 +0100

Seen: 362 times

Last updated: Dec 20 '19