Skip to content

Commit

Permalink
Add tests for generic coeffss, fix a regression
Browse files Browse the repository at this point in the history
The commit adds basic tests for generic
coefficients for some Nemo fields.

It also fixes a regression in multi-modular
when randomized linear algebra was not
used for guessing a prime.
  • Loading branch information
sumiya11 committed Nov 18, 2024
1 parent 7ee1e11 commit 5741d23
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/groebner/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ function AlgorithmParameters(ring::PolyRing, kwargs::KeywordArguments; hint=:non
end
end

# Over Z_p, linalg = :randomized signals randomized linear algebra.
# Over Q, linalg = :randomized has almost no effect since multi-modular
# tracing is used by default. Still, we say "almost" since some routines in
# multi-modular tracing may compute Groebner bases in Zp for
# checking/verification, and they benefit from linalg = :randomized.
linalg = kwargs.linalg
if ring.ground === :zp && (linalg === :randomized || linalg === :auto)
# Do not use randomized linear algebra if the field characteristic is
Expand All @@ -257,7 +262,8 @@ function AlgorithmParameters(ring::PolyRing, kwargs::KeywordArguments; hint=:non
end
linalg = :deterministic
end
else
end
if ring.ground == :generic
linalg = :deterministic
end
if linalg === :auto
Expand Down
4 changes: 3 additions & 1 deletion src/input_output/AbstractAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ function io_extract_ring(polynomials)
else
# Detect that K is either AbstractAlgebra.QQ or Nemo.QQ
base = AbstractAlgebra.base_ring(K)
if !(AbstractAlgebra.base_ring(base) == Union{})
if !(hasmethod(AbstractAlgebra.base_ring, typeof(base)))
ground = :generic
elseif !(AbstractAlgebra.base_ring(base) == Union{})
ground = :generic
end
end
Expand Down
14 changes: 9 additions & 5 deletions test/groebner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,18 @@ end
# - Zp
# - Zp for large p
# - QQ
n = 5
syss = [
Groebner.Examples.cyclicn(5, k=GF(2^40 + 15)),
Groebner.Examples.cyclicn(5, k=GF(2)),
Groebner.Examples.cyclicn(5, k=GF(nextprime(big(2)^1000))),
Groebner.Examples.cyclicn(5, k=QQ)
Groebner.Examples.cyclicn(n, k=GF(2^40 + 15)),
Groebner.Examples.cyclicn(n, k=GF(2^40 + 15), internal_ordering=:lex),
Groebner.Examples.cyclicn(n, k=GF(2)),
Groebner.Examples.cyclicn(n, k=GF(nextprime(big(2)^1000))),
Groebner.Examples.cyclicn(n, k=GF(nextprime(big(2)^1000)), internal_ordering=:lex),
Groebner.Examples.cyclicn(n, k=QQ)
]
for sys in syss
ring = Groebner.PolyRing(5, Groebner.DegRevLex(), 0, :generic)
ord = internal_ordering(parent(sys[1])) == :lex ? Groebner.Lex() : Groebner.DegRevLex()
ring = Groebner.PolyRing(n, ord, 0, :generic)
exps, cfs = get_data(sys, Groebner.CoeffGeneric)
gbexps, gbcfs = groebner(ring, exps, cfs)
gb = groebner(sys)
Expand Down
15 changes: 15 additions & 0 deletions test/input_output/Nemo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import Nemo, Primes
end

@testset "Nemo.jl, generic" begin
# Test generic coefficients with some interesting fields from Nemo.jl.

# Single extension
K, a = Nemo.finite_field(3, 2, "a")
R, (X, Y) = K["X", "Y"]
Expand All @@ -39,6 +41,19 @@ end
# sys = [a * b * X - Y, X * Y - 1]
# res = [Y^2 + b^5 + b^4 + 2*b^2 + 2*b + 2, X + (b^3 + 2*b^2 + b)*Y]
# @test groebner(sys) == res

# Q bar
Q_bar = Nemo.algebraic_closure(Nemo.QQ)
R, (X, Y) = Q_bar["X", "Y"]
e2 = Nemo.root_of_unity(Q_bar, 5, 2)
e3 = Nemo.root_of_unity(Q_bar, 5, 3)
e4 = Nemo.root_of_unity(Q_bar, 5, 4)
@test groebner([e3*X - e2*Y]) == [X - e4*Y]

# Cyclic extension
K, a = Nemo.cyclotomic_field(5)
R, (X, Y) = K["X", "Y"]
@test groebner([a*X + 1]) == [X - a^3 - a^2 - a - 1]
end

@testset "Nemo.jl, input-output" begin
Expand Down

0 comments on commit 5741d23

Please sign in to comment.