2

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:

  1. find the $\gcd$ of two multivariate polynomials

  2. 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:

  1. $xy^3 + 9xy^2 + 26xy + 24x + y^3 + 9y^2 + 26y + 24$

  2. $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:

  1. 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?

  2. 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?

  3. 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!

floomp
  • 21
  • 1
    In this particular case it is enough to notice that both numerator and denominator are quadratics in either variable, and the respective discriminants are perfect squares, so they both have nice factorizations. – dxiv Jul 23 '23 at 22:16
  • I don't want to be restricted to the example, I just gave one to have something actual tangible, but if I should make the example use 5th powers instead to not be limited to squares, then I would. E.g. $(y^3x^5 + x^6 + 2*x^5 + y^3 + x + 2) / (yx^5 + x^4y^4 + 2yx^4 + xy + y^4 + 2y)$ should become: $(x^5+1) / (x^4y+y)$ – floomp Jul 23 '23 at 22:48
  • 1
    The reason people care about dividing by multiple polynomials at once is to capture the idea of reducing a polynomial modulo several polynomials at once. This doesn't happen in familiar cases, like say, the integers, where every ideal is principal. But in polynomial rings with several variables, most ideals are not principal, so finding representatives of a polynomial in a quotient ring is analogous to doing this "generalized long division." This is ultimately what Buchberger's algorithm does. – A. Thomas Yerger Jul 23 '23 at 23:18
  • 1
    @floomp The example in the comment still has roots in x independent of y so it's not truly general. It's not clear whether that's a coincidence or some pattern in your use case. About using Gröbner basis for multivariate gcd calculation, you can find a step-by-step worked-out example here. Related: Computing lcm with Groebner basis, Product of gcd and lcm for multivariate polynomials. – dxiv Jul 24 '23 at 01:17
  • Regarding the polynomial rings: I think this is not applicable to my current use case, but why does little seem to talk about my use case, am I missing something trivial? The lcm link looks interesting, thanks! The roots in the example is a coincidence because I try to make some examples that don't become a too big expression to post here but now I made sure it has all variables in the roots too: $(6yx ^ 6 + 6zx ^ 5 + 15yx ^ 4 + 5xy ^ 2 + 5yz + 18x ^ 9) / (2xyz + 6zx ^ 4 + yx ^ 4 + zx ^ 3 + 3x ^ 7 + 2z ^ 2) --> (6x^5+5y) / (x^3+2z)$ – floomp Jul 24 '23 at 07:33
  • Well, in the worked-out lcm example, it still requires a multivariate polynomial division: $(g * h) / lcm$ to find the gcd, and it only explains univariate division (which I also already have implemented with euclid's algorithm!) above. Can the division also be done with groebner bases? – floomp Jul 24 '23 at 08:24
  • 1
    Maybe if you use Groebner bases to find the kernel of the module homomorphism $R^2 \to I$ defined by $e_1 \mapsto p_1 = 3xy^2 + \cdots, e_2 \mapsto p_2 = 4xy^2 + \cdots$? Then I would expect that kernel to be generated by one element $(-q_2, q_1)$ where $q_1 / q_2$ is the reduction of $p_1 / p_2$. – Daniel Schepler Jul 24 '23 at 16:15
  • 3
    @floomp You can do exact division via repeated reductions. In your case, you don't need to explicitly calculate the $,\gcd,$ but you still need two exact divisions for $,p \big/ q ,=, (\operatorname{lcm} / q) ,\big/, (\operatorname{lcm} / p),$. – dxiv Jul 24 '23 at 16:41
  • 1
    Or, it might be a bit more lightweight to use the version of Buchberger's algorithm that also finds relations between original generators at the same time it finds a Groebner basis. I'm not sure what software packages support that, though, and how you would use that feature in those packages. – Daniel Schepler Jul 24 '23 at 16:51
  • @dxiv: about "you can do division via repeated reductions": I'm trying on a simple example: f = xy+2y+x+2 reduced by g = x+2. Dividing these two should give y+1. If I do "red1" I get: choose term xy from f, and the leading term of g is x. So c*m/lc(g)/lm(g) equals xy/x = y. yg is then yx+2y, and then computing f - yg (the full red1 formula) gives: xy+2y+x+2 -(yx+2y) = x+2. But now I got x+2, which is g itself, after this reduction! I would have expected to get y+1 here if reductions would give the division. Also, doing red1 a second time then gives 0. What could have gone wrong here? Thanks! – floomp Jul 26 '23 at 12:22
  • hmm, potentially I found it: I did two red1 steps above. In the first one, the division of the two terms was 'y' as I said above. In the second red1 step, the one that was outputting 0 (the remainder), that division of two terms was '1'. And the sum of this y and 1 are the y+1 I was looking for. Does that sound right? But then why doesn't wikipedia, or the answers in this thread, tell that?! It's not that obvious I think :) – floomp Jul 26 '23 at 13:28
  • 1
    @floomp Right. Each reduction step eliminates the highest degree monomial in the chosen order. In general, the remainder left at the end (when no further reduction is possible) depends on the chosen monomial order, but in the case of exact division the remainder is $0$ regardless of the order. – dxiv Jul 26 '23 at 19:05

2 Answers2

3

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:

ring R=QQ,(x,y,z),(c,lp);
module M=[6yx6+6zx5+15yx4+5xy2+5yz+18x9,1,0],[2xyz+6zx4+yx4+zx3+3x7+2z2,0,1];
groebner(M);
==>
_[1]=[0,x3+2z,-6x5-5y]
_[2]=[375x4y3-20736x4z5+125xy4-6912xyz5+125y3z-6912z6,60x2yz-288xz3+25y2,-360x4yz+1728x3z3-150x2y2+720xyz2-3456z4]
_[3]=[864x5z3+75x4y2+288x2yz3+25xy3+288xz4+25y2z,12x2z+5y,-72x4z-30x2y+144xz2]
_[4]=[15x5y+72x4z2+5x2y2+24xyz2+5xyz+24z3,x,-6x3+12z]
_[5]=[36x6z-15x4y+12x3yz+12x2z2-5xy2-5yz,-1,6x2]
_[6]=[3x7+x4y+6x4z+x3z+2xyz+2z2,0,1]

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.

  • I have a bit of trouble understanding what the morphism means, as well as what "generated" means (in the original question I also asked what the "generator" is in the example). But the result looks interesting! There seem to be multiple lists of polynomials returned by groebner in Singular, what does this mean? I understand that groebner basis is a list of polynomials, but here it's a list of lists of polynomials... Thanks! – floomp Jul 24 '23 at 17:55
  • 1
    A bit more explicitly, the morphism takes $(a, b) \in R^2$ to $ap + bq \in R$. To say the kernel of this morphism is generated by $(-q/g, p/g)$ means that for any $(a, b)$ in the kernel, $(a, b)$ is a scalar multiple of $(-q/g, p/g)$; and conversely $(-q/g, p/g)$ is in the kernel. i.e. if $ap + bq = 0$, then there exists $c \in R$ such that $a = c(-q/g), b = c(p/g)$. – Daniel Schepler Jul 24 '23 at 17:59
  • 1
    I'm defining $M$ to be the submodule of $R^3$ generated by $(6yx^6+6zx^5+15yx^4+5xy^2+5yz+18x^9, 1, 0)$ and $(2xyz+6zx^4+yx^4+zx^3+3x^7+2z^2, 0, 1)$; and Singular is returning a Groebner basis for that submodule. So for example, $(0, x^3+2z, -6x^5-5y) \in M$, etc. (Groebner bases and Buchberger's algorithm apply just as well to submodules of finitely generated free modules over a polynomial ring, as they do to ideals of a polynomial ring. The ideal case is just the special case where you look at submodules of $R^1$.) – Daniel Schepler Jul 24 '23 at 18:02
  • Is a submodule the same as a list of polynomials, or does it have different properties or restrictions? I'm just trying to divide two polynomials (no fancy ones, just variables with integer powers and complex coefficients), division at least is a pretty basic concept, but submodules, generators, kernels, morphisms etc... seem so advanced instead. Is there a way to explain multivariate polynomial gcd (and then dividing through it) with more basic terms, or are multivatiate polynomials so complicated that there's really no way around it? Thanks! – floomp Jul 24 '23 at 18:09
  • 1
    You might think of it as an "annotated" version of Buchberger's algorithm, where in addition to the members of the ideal, we also keep track of exactly how each member is a combination of $p$ and $q$. And along the way, if we find a remainder of 0, then we get a combination of $p$ and $q$ which gives 0, and often that combination will be nontrivial. In this case, we happen to be primarily interested in the combinations of $p$ and $q$ which give 0. – Daniel Schepler Jul 24 '23 at 18:19
0

Here is a different approach which does not require Groebner bases.

As an analogy, let us think of how we would calculate the gcd of two polynomials in $\mathbb{Z}[x]$, which is also not a UFD. The procedure here would be: first, treat the two polynomials as polynomials in $\mathbb{Q}[x]$, and use the Euclidean algorithm to find the gcd in $\mathbb{Q}[x]$. This will possibly have some denominators; however, then you can reduce all the coefficients to fractions in lowest terms, and then calculate the lcm of all the denominators, and finally multiply through by that lcm.

By an argument along the lines of Gauss' lemma and the proof that $R$ being a UFD implies $R[x]$ is a UFD, then, the gcd of the two original polynomials in $\mathbb{Z}[x]$ will be this polynomial, times the gcd in $\mathbb{Z}$ of all the coefficients of the two original polynomials.

In fact, this same calculation will work for any UFD in place of $\mathbb{Z}$. In the case of multivariate polynomials $f, g \in F[x_1, \ldots, x_n]$ for some field $F$, the resulting algorithm will look like:

  • Use the Euclidean algorithm to calculate $\gcd(f, g)$ in $F(x_1, \ldots, x_{n-1}) [x_n]$.
  • Recursively use the gcd algorithm for $F[x_1, \ldots, x_{n-1}]$ to reduce each coefficient of this gcd to lowest terms; find the lcm of the denominators; and multiply through by this lcm.
  • Recursively use the gcd algorithm for $F[x_1, \ldots, x_{n-1}]$ to find the gcd of all coefficients of $f$ and $g$ in $F[x_1, \ldots, x_{n-1}]$.
  • Multiply the results of the previous two steps.

(Note that the second step above does require some exact division of polynomials in $F[x_1, \ldots, x_n]$. This can be done via the reduction algorithm which is mentioned in a comment by dxiv: https://en.wikipedia.org/wiki/Gr%C3%B6bner_basis#Reduction .)