Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

substitution of variable in the result of monomials()

asked 5 years ago

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+y2; the list of its monomials (in some ordering) is (1,x,y2). My function should be able e.g. to take that list and substitute y with x, namely return [1,x,x2].

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 5 years ago

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]
Preview: (hide)
link

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: 5 years ago

Seen: 386 times

Last updated: Dec 20 '19