sumiya11 / Groebner.jl

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

Reduce a Polynomial by a Groebner Basis #135

Closed polka125 closed 1 week ago

polka125 commented 5 months ago

Hi, is there a way to reduce a polynomial by a Groebner basis?

Say, I have

using Groebner
@polyvar x y
basis = Groebner.groebner([x - y, x*y])
p = x^2

Now I want to check whether $p$ belongs to the ideal, and want to have something like Groebner.reduce(p, basis) == 0, is there any way to express this?

sumiya11 commented 5 months ago

Hi! There is Groebner.normalform. You can try normalform(basis, p).

Unfortunately, I think in your example it would not work, due to a bug in the way Groebner handles DynamicPolynomials.

Until I fix it, I would recommend using Groebner with AbstractAlgebra, it should be more stable and tested.

julia> using Groebner, AbstractAlgebra
julia> R, (x,y) = QQ["x","y"]
julia> basis = groebner([x - y, x*y])
julia> p = x^2
julia> normalform(basis, p)
0

PS. you can still trick DynamicPolynomials into doing the right thing by something like:

julia> @polyvar x y
julia> basis = Groebner.groebner([x - y, x*y])
julia> p = x^2
julia> normalform(basis, p)                # will fail
julia> normalform(basis, p + 0*x*y)
0

So you can add a fictional term 0*[product of all variables] to your polynomials to make it work.

Let me know if you have further questions.

linus-md commented 4 months ago

I guess this is the same bug @sumiya11

using Groebner
using DynamicPolynomials
@polyvar x y u v l;
normalform([x^2+y^2-1], x)

with output DimensionMismatch: all inputs to eachindex must have the same indices, got Base.OneTo(2) and Base.OneTo(3).

sumiya11 commented 1 week ago

With the new version of Groebner (0.8.0) this is fixed.