Skip to content

Commit 5c1ba82

Browse files
authored
Merge pull request #76 from rprebet/specialcaseGB
Handle zero ideal cases
2 parents 2768ecb + 9053d9b commit 5c1ba82

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/algorithms/groebner-bases.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,13 @@ function _core_groebner_basis(
150150
)
151151

152152
F = I.gens
153-
R = first(F).parent
154153

155-
if F == repeat([R(0)], length(F))
156-
I.gb[eliminate] = F
157-
return F
154+
if iszero(F)
155+
I.gb[eliminate] = length(F)==0 ? F : F[1:1]
156+
return I.gb[eliminate]
158157
end
158+
159+
R = first(F).parent
159160
nr_vars = nvars(R)
160161
nr_gens = length(F)
161162
field_char = Int(characteristic(R))
@@ -206,6 +207,11 @@ function _core_groebner_basis(
206207
nr_thrds, max_nr_pairs, 0, la_option, reduce_gb, 0, info_level)
207208
end
208209

210+
if nr_terms == 0
211+
I.gb[eliminate] = [R(0)]
212+
return I.gb[eliminate]
213+
end
214+
209215
# convert to julia array, also give memory management to julia
210216
jl_ld = gb_ld[]
211217
jl_len = Base.unsafe_wrap(Array, gb_len[], jl_ld)
@@ -214,7 +220,7 @@ function _core_groebner_basis(
214220
# coefficient handling depending on field characteristic
215221
if field_char == 0
216222
ptr = reinterpret(Ptr{BigInt}, gb_cf[])
217-
jl_cf = [QQFieldElem(unsafe_load(ptr, i)) for i in 1:nr_terms]
223+
jl_cf = QQFieldElem[QQFieldElem(unsafe_load(ptr, i)) for i in 1:nr_terms]
218224
else
219225
ptr = reinterpret(Ptr{Int32}, gb_cf[])
220226
jl_cf = Base.unsafe_wrap(Array, ptr, nr_terms)

0 commit comments

Comments
 (0)