Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multivariate polynomial division #20640

Open
kuzand opened this issue Dec 21, 2020 · 4 comments
Open

Multivariate polynomial division #20640

kuzand opened this issue Dec 21, 2020 · 4 comments
Labels

Comments

@kuzand
Copy link

kuzand commented Dec 21, 2020

x, y = symbols('x y')
p = Poly(x**2+y, x, y, domain=QQ)
p0 = Poly(y, x, y, domain=QQ)
div(p, p0)  # or p.div(p0)

gives me 0 and x**2 + y as quotient and remainder respectively, whereas I was expecting 1 and x**2. I can get the correct result using e.g. reduced, but was wondering why it doesn't work using div on polynomials.

I have sympy 1.7.1.

@jksuom
Copy link
Member

jksuom commented Dec 21, 2020

Division of multivariate polynomials depends on the ordering of the generators.

In [1]: p = Poly(x**2+y, y, x, domain=QQ)

In [2]: p0 = Poly(y, y, x, domain=QQ)

In [3]: div(p, p0)
Out[3]: (Poly(1, y, x, domain='QQ'), Poly(x**2, y, x, domain='QQ'))

skirpichev added a commit to skirpichev/diofant that referenced this issue Dec 21, 2020
@oscarbenjamin
Copy link
Contributor

Should anything be changed here?

@kuzand
Copy link
Author

kuzand commented Dec 21, 2020

Division of multivariate polynomials depends on the ordering of the generators.

In both cases the remainder should be x**2.

Have a look at the following:

_, x, y = ring('x y', domain=QQ, order='lex')  # or ilex
p =  x**2+y
p0 = y
p.div(p0)

(1, x**2)

or by using reduced we also get (1, x**2).

@kuzand
Copy link
Author

kuzand commented Dec 21, 2020

_, x, y = ring('x y', domain=QQ, order='lex')
f =  x**2+y
f0 = y
f.div(f0)

(1, x**2)
_, x, y = ring('x y', domain=QQ, order='ilex')
f =  x**2+y
f0 = y
f.div(f0)

(1, x**2)

Both give the same result. Whereas

x, y = symbols('x y')
p = Poly(x**2+y, x, y)
p0 = Poly(y, x, y)
p.div(p0)

(0, x**2 + y)

x, y = symbols('x y')
p = Poly(x**2+y, y, x)
p0 = Poly(y, y, x)
p.div(p0)

(1, x**2)

However if we consider e.g. p = x**2+y and p0 = x - y, the results are consistent:

_, x, y = ring('x y', domain=QQ, order='lex')
p =  x**2+y
p0 = x - y
p.div(p0)

(x + y, y**2 + y)
x, y = symbols('x y')
p = Poly(x**2+y, x, y)
p0 = Poly(x - y, x, y)
p.div(p0)

(x + y, y**2 + y)

And for ilex:

_, x, y = ring('x y', domain=QQ, order='ilex')
p =  x**2+y
p0 = x - y
p.div(p0)

(-1, x + x**2)
x, y = symbols('x y')
p = Poly(x**2+y, y, x)
p0 = Poly(x - y, y, x)
p.div(p0)

(-1, x + x**2)

skirpichev added a commit to skirpichev/diofant that referenced this issue Dec 30, 2020
skirpichev added a commit to skirpichev/diofant that referenced this issue Jan 6, 2021
skirpichev added a commit to skirpichev/diofant that referenced this issue Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants