Skip to content

Commit

Permalink
Random lines in LineEnumCtx (#1271)
Browse files Browse the repository at this point in the history
  • Loading branch information
StevellM authored Nov 3, 2023
1 parent a043096 commit f818b32
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/QuadForm/LineOrbits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# We iterate through K by adding 1 in the prime field case and by multiplying
# with a primitive element in the general case.

function LineEnumCtx(K::T, n) where {T}
function LineEnumCtx(K::T, n::Int) where {T}
a = primitive_element(K)
v = Vector{elem_type(K)}(undef, n)
for i in 1:n
Expand All @@ -16,7 +16,7 @@ function LineEnumCtx(K::T, n) where {T}
depth = n + 1
dim = n
q = order(K)
length = divexact(q^n - 1, q - 1)
length = divexact(BigInt(q)^n - 1, q - 1)
return LineEnumCtx{T, elem_type(T)}(K, a, dim, depth, v, length)
end

Expand All @@ -29,7 +29,7 @@ function LineEnumCtx(K::T, n::Int) where {T <: Union{fpField, FpField}}
depth = n + 1
dim = n
q = order(K)
length = divexact(q^n - 1, q - 1)
length = divexact(BigInt(q)^n - 1, q - 1)
return LineEnumCtx{T, elem_type(T)}(K, a, dim, depth, v, length)
end

Expand Down Expand Up @@ -58,12 +58,26 @@ Base.length(P::LineEnumCtx) = P.length

Base.eltype(::Type{LineEnumCtx{T, S}}) where {T, S} = Vector{S}

base_field(P::LineEnumCtx) = P.K

depth(P::LineEnumCtx) = P.depth

dim(P::LineEnumCtx) = P.dim

primitive_element(P::LineEnumCtx) = P.a

function Base.rand(P::LineEnumCtx)
K = base_field(P)
n = dim(P)
v = rand(K, n)
while iszero(v)
v = rand(K, n)
end
j = findfirst(!iszero, v)
map!(x -> x*inv(v[j]), v, v)
return v
end

################################################################################
#
# Iteration
Expand Down
1 change: 1 addition & 0 deletions test/QuadForm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
include("QuadForm/indefiniteLLL.jl")
include("QuadForm/IO.jl")
include("QuadForm/Database.jl")
include("QuadForm/LineOrbits.jl")
end
11 changes: 11 additions & 0 deletions test/QuadForm/LineOrbits.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@testset "Random lines" begin
P = Hecke.enumerate_lines(GF(5), 20)
io = IOBuffer()
show(io, MIME"text/plain"(), P)
show(IOContext(io, :supercompact => true), P)
show(io, P)
for i in 1:100
v = rand(P)
@test !iszero(v) && isone(v[findfirst(!iszero, v)])
end
end

0 comments on commit f818b32

Please sign in to comment.