Skip to content

Commit 77c61d5

Browse files
authored
Merge pull request #55 from ederc/zero-elements
Handling zero elements in input generators
2 parents a8a4e59 + 163d80f commit 77c61d5

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/algorithms/groebner-bases.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ function _core_groebner_basis(
147147
error("At the moment we only supports finite fields.")
148148
end
149149

150-
lens, cfs, exps = _convert_to_msolve(F)
150+
# nr_gens might change if F contains zero polynomials
151+
lens, cfs, exps, nr_gens = _convert_to_msolve(F)
151152

152153
gb_ld = Ref(Cint(0))
153154
gb_len = Ref(Ptr{Cint}(0))

src/interfaces/nemo.jl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function _convert_to_msolve(
2121
if field_char > 2^31 || degree(base_ring(R)) != 1
2222
error("At the moment we only support prime fields up to prime characteristic < 2^31.")
2323
end
24+
25+
lens = Int32[]
2426
# get coefficients
2527
if field_char == 0
2628
cfs = BigInt[]
@@ -29,15 +31,21 @@ function _convert_to_msolve(
2931
end
3032
if field_char == 0
3133
for i in 1:nr_gens
32-
for cf in coefficients(F[i])
33-
push!(cfs, BigInt(numerator(cf)))
34-
push!(cfs, BigInt(denominator(cf)))
34+
if F[i] != R(0)
35+
for cf in coefficients(F[i])
36+
push!(cfs, BigInt(numerator(cf)))
37+
push!(cfs, BigInt(denominator(cf)))
38+
end
39+
push!(lens, length(F[i]))
3540
end
3641
end
3742
else
3843
for i in 1:nr_gens
39-
for cf in coefficients(F[i])
40-
push!(cfs, Int32(lift(Nemo.ZZ, cf)))
44+
if F[i] != R(0)
45+
for cf in coefficients(F[i])
46+
push!(cfs, Int32(lift(Nemo.ZZ, cf)))
47+
end
48+
push!(lens, length(F[i]))
4149
end
4250
end
4351
end
@@ -50,7 +58,7 @@ function _convert_to_msolve(
5058
end
5159
end
5260

53-
return lens, cfs, exps
61+
return lens, cfs, exps, length(lens)
5462
end
5563

5664
@doc Markdown.doc"""

test/interfaces/nemo.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
@testset "Interfaces -> Nemo" begin
22
R, (x,y,z) = polynomial_ring(QQ,["x","y","z"], internal_ordering=:degrevlex)
33
F = [x^2+1-3, x*y-z, x*z^2-3*y^2]
4-
cmp = (Int32[2, 2, 2], BigInt[1, 1, -2, 1, 1, 1, -1, 1, 1, 1, -3, 1], Int32[2, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 2, 0, 2, 0])
4+
cmp = (Int32[2, 2, 2], BigInt[1, 1, -2, 1, 1, 1, -1, 1, 1, 1, -3, 1], Int32[2, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 2, 0, 2, 0], 3)
55
@test AlgebraicSolving._convert_to_msolve(F) == cmp
6+
# issue #54
7+
R, (x1, x2) = polynomial_ring(GF(17), ["x1", "x2"])
8+
I = Ideal([x1, R(0)])
9+
cmp = (Int32[1], BigInt[1], Int32[1, 0], 1)
10+
@test AlgebraicSolving._convert_to_msolve(I.gens) == cmp
611
for _GF in [GF, AlgebraicSolving.Nemo.Native.GF]
712
R, (x,y,z) = polynomial_ring(_GF(2147483659),["x","y","z"], internal_ordering=:degrevlex)
813
F = [x^2+1-3, x*y-z, x*z^2-3*y^2]
@@ -11,6 +16,6 @@
1116
R, (x,y,z) = polynomial_ring(_GF(101),["x","y","z"], internal_ordering=:degrevlex)
1217
F = [x^2+1-3, x*y-z, x*z^2-3*y^2]
1318
res = AlgebraicSolving._convert_to_msolve(F)
14-
@test AlgebraicSolving._convert_finite_field_array_to_abstract_algebra(Int32(3), res..., R) == F
19+
@test AlgebraicSolving._convert_finite_field_array_to_abstract_algebra(Int32(3), res[1], res[2], res[3], R) == F
1520
end
1621
end

0 commit comments

Comments
 (0)