Ask Your Question
2

substitute x*y by u

asked 2015-02-28 19:00:54 +0200

mimoo gravatar image

updated 2017-04-20 00:58:23 +0200

tmonteil gravatar image

Hi there!

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

I want to substitute $x*y$ instances by a new unknown $u$ (s.t. $u = x * y$)

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?

edit retag flag offensive close merge delete

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 ( 2015-02-28 21:44:34 +0200 )edit

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 ( 2015-03-01 00:13:31 +0200 )edit
mimoo gravatar imagemimoo ( 2015-03-01 02:16:06 +0200 )edit

Maybe with wildcards?

kcrisman gravatar imagekcrisman ( 2015-03-01 03:02:20 +0200 )edit

2 Answers

Sort by ยป oldest newest most voted
4

answered 2015-03-01 14:42:05 +0200

tmonteil gravatar image

updated 2015-03-01 14:43:12 +0200

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
edit flag offensive delete link more

Comments

it works! magic

mimoo gravatar imagemimoo ( 2015-03-03 18:26:45 +0200 )edit
2

answered 2015-03-01 09:03:23 +0200

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

edit flag offensive delete link more

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 ( 2015-03-02 22:21:57 +0200 )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

Stats

Asked: 2015-02-28 19:00:54 +0200

Seen: 1,653 times

Last updated: Mar 01 '15