Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
2

substitute x*y by u

asked 9 years ago

mimoo gravatar image

updated 7 years ago

tmonteil gravatar image

Hi there!

I have a polynomial $f(x,y) = xy + x^2y^2 + x*y^2$

I want to substitute xy instances by a new unknown u (s.t. u=xy)

This is how I proceeded:

# this is the default code
P.<x, y> = PolynomialRing(Zmod(5))
f = x*y + x^2*y^2 + x*y^2
# now I want to introduce the substitution so I have a f(x,y,u)
new_ring.<x,y,u> = PolynomialRing(ZZ)
ff = f.sub(x*y = u)

Of course this code doesn't work... Any idea what I could do?

Preview: (hide)

Comments

It doesn't look like there's support for substituting products. Instead you can do

ff = f.subs(x = u/y)
SL gravatar imageSL ( 9 years ago )

What exactly do you want to replace? Do you want x^2 y^3 -> u^2 y and x^3 y^2 -> x u^2?

vdelecroix gravatar imagevdelecroix ( 9 years ago )
mimoo gravatar imagemimoo ( 9 years ago )

Maybe with wildcards?

kcrisman gravatar imagekcrisman ( 9 years ago )

2 Answers

Sort by » oldest newest most voted
4

answered 9 years ago

tmonteil gravatar image

updated 9 years ago

Perhaps what you are looking for is not a substitution but a quotient ring where u and x*y are identified:

sage: P.<x, y, u> = PolynomialRing(Zmod(5)) ; P
Multivariate Polynomial Ring in x, y, u over Ring of integers modulo 5
sage: f = x*y + x^2*y^2 + x*y^2
sage: f.parent()
Multivariate Polynomial Ring in x, y, u over Ring of integers modulo 5
sage: Q = P.quotient(x*y-u) ; Q
Quotient of Multivariate Polynomial Ring in x, y, u over Ring of integers modulo 5 by the ideal (x*y - u)
sage: ff = Q(f) ; ff
ybar*ubar + ubar^2 + ubar
sage: ff.parent()
Quotient of Multivariate Polynomial Ring in x, y, u over Ring of integers modulo 5 by the ideal (x*y - u)

Now, if you want your polynomial back in P, you can do:

sage: fff = ff.lift() ; fff
y*u + u^2 + u
sage: fff.parent()
Multivariate Polynomial Ring in x, y, u over Ring of integers modulo 5
Preview: (hide)
link

Comments

it works! magic

mimoo gravatar imagemimoo ( 9 years ago )
2

answered 9 years ago

rws gravatar image

It's better to use the equality sign with subs: f.subs(x*y==u) or a dictionary:

sage: P.<x, y> = PolynomialRing(Zmod(5))
sage: f = x*y + x^2*y^2 + x*y^2
sage: f.subs({x*y:u})
u^2*y^2 + u*y^2 + u*y

Note this different from

sage: x,y = var('x,y')
sage: f = x*y + x^2*y^2 + x*y^2
sage: f.subs({x*y:u})
x^2*y^2 + x*y^2 + u

because of the ring. But certainly, we would want u+u^2+u*yas result and Sage cannot do that at the moment. I've opened a ticket for it: http://trac.sagemath.org/ticket/17879

Preview: (hide)
link

Comments

Also interesting, using the above Symbolic ring example, if one factors first to expose two instances of x*y, the subs() function will only replace one.

sage: _ = var('x,y,u')
sage: f = x*y + x^2*y^2 + x*y^2
sage: f.factor()
sage: f.factor().subs({x*y:u})
(x*y + y + 1)*x*y
(u + y + 1)*x*y
JesterEE gravatar imageJesterEE ( 9 years ago )

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

Seen: 1,862 times

Last updated: Mar 01 '15