I'm looking for al algorithm to try to implement simplification of a fraction of two multivariate polynomials. Here's an example of one:
$$\frac{(3xy^2+x^2y^2+7yx^2+21xy+2y^2+12x^2+14y+36x+24) }{(4xy^2+x^2y^2+6yx^2+24xy+3y^2+8x^2+18y+32x+24)}$$
This can be simplified to:
$$\frac{(xy+3x+2y+6) }{(xy+2x+3y+6)}$$
Because the shared factors of the numerator and denominator in the example are $(x+1)$ and $(y+4)$, in other words the gcd is $(xy + y + 4x + 4)$.
So the numerator and denominoator can both be divided through $(xy + y + 4x + 4)$ to get the above simplified form.
Of course I constructed this example myself by on purpose multiplying $(x+1)$, $(y+4)$ and other such factors together to create the numerator and denominator with the shared factors in there on purpose. But I'd like to find the simplification for arbitrary multivariate polynomials with an algorithm.
This is just an example, I'd also like it to support more variables, higher powers than the 2 in this example, etc..., any random polynomials you could type, if they happen to have a gcd, simplify it. Also, the coefficients can be any complex numbers, doesn't have to be restricted to integers.
But to implement this as an algorithm requires two things:
find the $\gcd$ of two multivariate polynomials
implement division (with remainder that's know to be zero, so we don't need to support getting the remainder) of the numerator, and denominator, through this gcd, to get the simplified result.
When I search for how to do the $\gcd$ and especially division of multivariate polynomials, the answer points to using groebner basis, but I've not found anything that says how to actually do the division of two multivariate polynomials with groebner basis.
If I try it in wolfram alpha, and if I type in there the two involved polynomials of the example:
groebnerbasis[{3*x*y^2+x^2*y^2+7*y*x^2+21*x*y+2*y^2+12*x^2+14*y+36*x+24,4*x*y^2+x^2*y^2+6*y*x^2+24*x*y+3*y^2+8*x^2+18*y+32*x+24},{x,y}]
It outputs:
{x y^3 + 9 x y^2 + 26 x y + 24 x + y^3 + 9 y^2 + 26 y + 24, x^2 y + 4 x^2 - x y^2 - 3 x y + 4 x - y^2 - 4 y}
So it outputs two polynomials:
$xy^3 + 9xy^2 + 26xy + 24x + y^3 + 9y^2 + 26y + 24$
$x^2y + 4x^2 - xy^2 - 3xy + 4x - y^2 - 4y$
And neither of these two polynomials looks either like the gcd $(xy + y + 4x + 4)$, nor like the simplified result of $(xy+3x+2y+6) / (xy+2x+3y+6)$.
So how can I use this groebner basis for the desired purpose? Does this bring one any closer to the desired solution of simplifying the two input polynomials? Is there an algorithm that operates on this groebner basis result?
What's the correct algorithm to look for (with or without groebner basis) to do the gcd, and divisions with known remainder zero, to do what I want?
Also, separate from that, I have a few questions about groebner basis too:
most examples involving polynomial division and groebner basis (including other questions here on stackoverflow, and wikipedia), is dividing a polynomial through multiple polynomials at the same time. Why this focus on dividing through multiple polynomials? That seems to be for a different application than my simplification example above, why is dividing though multiple polynomials so common and dividing through a single one not findable in any examples?
the term "ideal" and "generator" come up all the time in information about the groebner basis. In my example above with the two big polynomials getting divided and simplified, what are the ideal and generator there exactly, or is this not relevant here?
I saw some explanation on groebner basis that said there'd always be one polynomial in them with only one variable. Is that correct? In the wolfram alpha above, both have x and y in it. What could have gone wrong here?
Thanks!
If $R$ is the polynomial ring, and $p, q \in R$ are the polynomials in question, then consider the morphism of $R$-modules $R^2 \to R$ defined by $e_1 \mapsto p$, $e_2 \mapsto q$. Then the kernel of this morphism will be generated by $(-q/g, p/g)$ where $g = \gcd(p, q)$ in the UFD $R$. From this, it will be trivial to extract $p/g$ and $q/g$ which are the numerator and denominator of $p/q$ in lowest terms. The calculation of this kernel, in turn, can be done using Groebner bases.
For the example from one of the comments, I used this sequence of commands in Singular:
Here, you can read off the kernel from the first entry (in more general situations with more generators, the kernel could be read off from the entries with 0 in the first coordinate(s)).
Of course, as you can see, the intermediate calculation could potentially end up being fairly expensive in larger examples with higher degree and/or more variables. I'm not sure whether there's a more efficient way to do the calculation.