Skip to content

Commit

Permalink
fix the bug fix zero input to normalform
Browse files Browse the repository at this point in the history
  • Loading branch information
sumiya11 committed Jul 3, 2023
1 parent 97d44ca commit e0eddc3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,19 @@ function normalform(
#= check and set algorithm parameters =#
metainfo = set_metaparameters(ring, ordering, false, :exact, rng)

iszerobasis = remove_zeros_from_input!(ring, basisexps, basiscoeffs)
iszerobasis &&
(return convert_to_output(ring, tobereduced, tbrexps, tbrcoeffs, metainfo))
# remove zeros from input
input_sz = length(tbrexps)
nonzero_indices = filter(i -> !isempty(tbrexps[i]), 1:input_sz)
tbrexps = tbrexps[nonzero_indices]
tbrcoeffs = tbrcoeffs[nonzero_indices]

if isempty(tbrexps)
for i in 1:input_sz
push!(tbrexps, empty(basisexps[1]))
push!(tbrcoeffs, empty(basiscoeffs[1]))
end
return convert_to_output(ring, tobereduced, tbrexps, tbrcoeffs, metainfo)
end

#= change input ordering if needed =#
newring = assure_ordering!(ring, basisexps, basiscoeffs, metainfo.targetord)
Expand All @@ -286,6 +296,17 @@ function normalform(
bexps, bcoeffs =
normal_form_f4(newring, basisexps, basiscoeffs, tbrexps, tbrcoeffs, rng)

# bring back zeros
bexps_with_zeros = Vector{eltype(bexps)}(undef, input_sz)
bcoeffs_with_zeros = Vector{eltype(bcoeffs)}(undef, input_sz)
bexps_with_zeros[nonzero_indices] = bexps
bcoeffs_with_zeros[nonzero_indices] = bcoeffs
for i in 1:input_sz
if !(i in nonzero_indices)
bexps_with_zeros[i] = empty(basisexps[1])
bcoeffs_with_zeros[i] = empty(basiscoeffs[1])
end
end
#=
Assuming ordering of `bexps` here matches `newring.ord`
=#
Expand All @@ -295,7 +316,7 @@ function normalform(

# ring contains ordering of computation, it is the requested ordering
#= convert result back to representation of input =#
convert_to_output(newring, tobereduced, bexps, bcoeffs, metainfo)
convert_to_output(newring, tobereduced, bexps_with_zeros, bcoeffs_with_zeros, metainfo)
end

"""
Expand Down
6 changes: 6 additions & 0 deletions test/array_normalform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ using AbstractAlgebra
for field in [GF(17), GF(2^31 - 1), ZZ, QQ]
R, (x, y) = PolynomialRing(field, ["x", "y"])
gb = [x, y]

@test Groebner.normalform(gb, [R(0)]) == [R(0)]
@test Groebner.normalform(gb, [R(0), R(1), R(0), R(0)]) == [R(0), R(1), R(0), R(0)]
@test Groebner.normalform(gb, [R(0), R(0), R(0), R(0)]) == [R(0), R(0), R(0), R(0)]
@test Groebner.normalform(gb, [R(0), x, R(0), x + 1, y, R(0)]) == [R(0), R(0), R(0), R(1), R(0), R(0)]

@test Groebner.normalform(gb, [x, y + 1]) == [R(0), R(1)]
@test Groebner.normalform(gb, [y + 1, x]) == [R(1), R(0)]
@test Groebner.normalform(
Expand Down

0 comments on commit e0eddc3

Please sign in to comment.