Skip to content

Commit

Permalink
fix: saturation at large primes (#1661)
Browse files Browse the repository at this point in the history
Use baby-step-giant-step algorithm for large primes to make
the complexity not linear in the order.
  • Loading branch information
thofma authored Oct 25, 2024
1 parent 66ab098 commit 34fb045
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/NumFieldOrd/NfOrd/Clgp/Saturate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ function mod_p(R::Vector{FacElem{AbsSimpleNumFieldElem, AbsSimpleNumField}}, Q::
pp, e = Hecke.ppio(oF, p)
#We now want the discrete logarithm of the images of the elements of R in F
#We don't need the full group, just the quotient by p
#We compute a generator and cache the powers in dl
#Then we will compute the discrete logarithms by checking the values in dl
#We compute a generator and
# - cache the powers in dl if pp is small
# - we will compute the discrete logarithms by checking the values in dl
# or via BSGS
dl = Dict{Hecke.Nemo.fpFieldElem, Int}()
dl[F(1)] = 0
exp_to_test = divexact(pp, p)
x = rand(F)
while true
Expand All @@ -28,12 +29,21 @@ function mod_p(R::Vector{FacElem{AbsSimpleNumFieldElem, AbsSimpleNumField}}, Q::
end
x = rand(F)
end
y = x
for i = 1:pp-1
dl[y] = i
y *= x
if nbits(pp) < 19 # seems to be a reasonable cutoff
y = one(F)
for i = 0:pp-1
dl[y] = i
y *= x
end
end
ma = Vector{Int}(undef, length(R))
for i in 1:length(R)
imgd = image(mF1, R[i], D[i], cached, pp)^e
ma[i] = get!(dl, imgd) do
Hecke.baby_step_giant_step(x, pp, imgd, dl) % p
end
end
return matrix(T, 1, length(R), Int[dl[image(mF1, R[i], D[i], cached, pp)^e] % p for i in 1:length(R)])
return matrix(T, 1, length(R), ma)
end

#= idea
Expand Down
2 changes: 2 additions & 0 deletions src/NumFieldOrd/NfOrd/ResidueRingMultGrp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,8 @@ of the first step. This allows to speed up subsequent calls with
the same $g$ and $n$.
"""
function baby_step_giant_step(g, n, h, cache::Dict)
# if cache is given, it must be empty or contain
# *all* big steps
@assert typeof(g) == typeof(h)
m = ZZRingElem(isqrt(n) + 1)
if isempty(cache)
Expand Down
7 changes: 7 additions & 0 deletions test/NfOrd/Clgp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,11 @@ end
@test order(c) == 892
end
end

# saturation at large primes

# the cyclotomic units are saturated at any prime l, since the class number h_149^+ is one.
K, = cyclotomic_real_subfield(149, "a")
u = Hecke._cyclotomic_units_totally_real_prime_conductor(K, 149)
@test nrows(Hecke.RelSaturate.compute_candidates_for_saturate(FacElem.(u[2:end]), next_prime(2^25))) == 0
end

0 comments on commit 34fb045

Please sign in to comment.