'Multivariate polynomial division using Sage
I'm just starting to learn Sage and I'm trying to find some method to do polynomial divisions in several variables. An example of the calculations that I want to do can be the division of the polynomial f(x)=x^2*y+x*y^2+y^2 with the polynomials f1(x)=x*y-1 and f2( x)=y^2-1 using lexicographic order. The result should be f(x)=(x+y)*(x*y-1)+1*(y^2-1)+(x+y+1). My interest would be to have a method in Sage to find the quotients, (x+y), (1), and the remainder, (x+y+1). Sage has many functions for similar and more complex operations, like reduce, quo_rem or groebner_basis(), but I haven't found one that does what I need.
Thanks for your help.
Solution 1:[1]
A way to obtain the result in the given sample case is as follows. Introduce the ring R = Q[x,y], and inside it build the ideal J generated by the two polynomials f1 and f2. Then the "rest" above will be a representation of f in the quotient ring, R/J. (Ring modulo ideal.) This rest can be lifted from the quotient ring to an element r of R. Then the difference f - r is an element of the ideal, and "lifting" this element is giving the two components to be multiplied with f1 and f2. Let's see:
R.<x,y> = PolynomialRing(QQ)
f = x^2*y + x*y^2 + y^2
f1 = x*y - 1
f2 = y^2 - 1
J = R.ideal([f1, f2])
Q = R.quotient(J)
r = Q(f).lift()
q1, q2 = (f - r).lift(J)
print(f'r = {r}')
print(f'q1 = {q1}')
print(f'q2 = {q2}')
And the above code delivers:
r = 2*y + 1
q1 = x*y^2 + 2*y
q2 = -x^2*y + 1
The question expects an r equal to x + y + 1, but observe that the difference x - y is in the ideal J, which has the following generators of the...
sage: J.groebner_basis()
[y^2 - 1, x - y]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | dan_fulea |
