sumiya11 / Groebner.jl

Groebner bases in (almost) pure Julia
https://sumiya11.github.io/Groebner.jl/
GNU General Public License v2.0
59 stars 13 forks source link

groebner does not return leading coefficient 1 #128

Open KenZhenLin opened 4 months ago

KenZhenLin commented 4 months ago

Hi,

The groebner returns the unique Reduced Gröbner bases by default, for any ordering, correct? Then why does the example below NOT have leading coefficient 1 ? This is an example from the documentation. Thanks!

I'm using this version if that matters: [0b43b601] Groebner v0.6.4

using DynamicPolynomials

@polyvar x1 x2
system = [10*x1*x2^2 - 11*x1 + 10,
        10*x1^2*x2 - 11*x2 + 10]

groebner(system)

3-element Vector{DynamicPolynomials.Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, MultivariatePolynomials.Graded{MultivariatePolynomials.LexOrder}, Int64}}:
 10x2 - 10x1 - 11x2² + 11x1²
 110 - 121x2 - 100x2² + 100x1x2 + 110x2³
 10 - 11x1 + 10x1x2²
sumiya11 commented 4 months ago

Hi @KenZhenLin ,

Thanks for reporting this. You are correct, groebner should always return a reduced basis, and it clearly fails in this case.

However, here, the situation is a bit subtle: groebner tries to return polynomials in the same type as they were given in the input.

system has Int coefficients. It is not possible to construct the reduced basis and preserve the type, so it chooses a normalization where denominators are equal to 1.

The current situation is not ideal. It would perhaps make sense to return polynomials with rational numbers as coefficients here. Hmm..

sumiya11 commented 4 months ago

To illustrate what I mean consider this:

@polyvar x1 x2
system = [10*x1*x2^2 - 11*x1 + 10,
        10*x1^2*x2 - 11*x2 + 10 // 1]

groebner(system)

3-element Vector{Polynomial{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}, Rational{Int64}}}:
 10//11x2 - 10//11x1 - x2² + x1²
 1//1 - 11//10x2 - 10//11x2² + 10//11x1x2 + x2³
 1//1 - 11//10x1 + x1x2²

But you are right, this behavior seems questionable to me. Also the example in the documentation could be updated.

KenZhenLin commented 4 months ago

@sumiya11 Thanks for your answer! It makes sense to me!

I tried that documentation example and indeed it returned the same results as in the documentation. To make sure I understand your point: groebner returns the unique reduced Gröbner bases, but up to the multiplication by some nonzero constant, is that right?

sumiya11 commented 4 months ago

To make sure I understand your point: groebner returns the unique reduced Gröbner bases, but up to the multiplication by some nonzero constant, is that right?

Yes.

For now, to get a trully reduced basis with DynamicPolynomials.jl, you can make polynomial coefficients rational, as in my example above.

KenZhenLin commented 4 months ago

For now, to get a trully reduced basis with DynamicPolynomials.jl, you can make polynomial coefficients rational, as in my example above.

I see, that's a good way! I do have some codes for which it's better not to change the type, so if I do not make it rational, the groebner will give me the reduced Gröbner bases or the reduced Gröbner bases multiplied by a nonzero constant, correct?

Thanks!

sumiya11 commented 4 months ago

so if I do not make it rational, the groebner will give me the reduced Gröbner bases or the reduced Gröbner bases multiplied by a nonzero constant, correct?

Yep !

EDIT: and this constant may be different for each polynomial in the basis. Is this sufficient for your application at the moment ?