Ask Your Question

Performing substitutions on powers of a variable

asked 2016-03-20 15:03:35 -0500

Jernej gravatar image

updated 2016-03-20 16:07:14 -0500

I have some polynomials of degree $d$ and I would like to obtain the monomial where all exponents greater than $1$ are reduced to $1$. For example $x_1^2 x_3^4 x_2 + x_1^7x_3^3 x_2^8 + \cdots$ would become $2x_1 x_3 x_2 + \cdots $

Naively, I thought an approach along the following lines would work:

sage: x = PolynomialRing(QQ, 1, 'x').objgens()[1][0]
sage: s = 2*x^2
sage: s.substitute({x^2:x})

Unfortunately, this does not give the proper result. Hence I am wondering

What is the proper way to perform the described substitution on the powers of a given monomial?

Edit. It seems that I can do ss = symbolic_expression(s).substitute({x^2:x}) and then convert ss to a polynomial. However, this seems to be extremely inefficient.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-03-20 17:23:42 -0500

tmonteil gravatar image

You should work modulo the ideal generated by the $x_i^2-x_i$:

sage: R = PolynomialRing(QQ,3,'x') ; R
Multivariate Polynomial Ring in x0, x1, x2 over Rational Field
sage: R.inject_variables()
Defining x0, x1, x2
sage: I = R.ideal([m^2-m for m in R.gens()]) ; I
Ideal (x0^2 - x0, x1^2 - x1, x2^2 - x2) of Multivariate Polynomial Ring in x0, x1, x2 over Rational Field
sage: P = x1^2*x2^4 + 7*x0*x1^4*x2^5 - 12*x0*x2^7 ; P
7*x0*x1^4*x2^5 - 12*x0*x2^7 + x1^2*x2^4
sage: P.mod(I)
7*x0*x1*x2 - 12*x0*x2 + x1*x2
edit flag offensive delete link more


Thanks. Just out of curiosity - is there a reason in the different behavior of substitute on symbolic expressions and polynomials?

Jernej gravatar imageJernej ( 2016-03-21 05:13:27 -0500 )edit

Polynomials and symbolic expressions are not the same objects at all, in particular they are not implemented the same way. Also, quotient ring does not makes much sense for general symbolic expressions.

If you have to deal with polynomials, i strongly encourage you to work with polynomial rings instead of symbolic expressions. They are more reliable and much faster.

tmonteil gravatar imagetmonteil ( 2016-03-21 08:04:02 -0500 )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


Asked: 2016-03-20 15:03:35 -0500

Seen: 66 times

Last updated: Mar 20 '16