Skip to content

Commit

Permalink
1 euro bet
Browse files Browse the repository at this point in the history
  • Loading branch information
sumiya11 committed Jan 10, 2024
1 parent ee9f647 commit 08d269d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
43 changes: 21 additions & 22 deletions src/f4/hashtable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -280,31 +280,30 @@ function hashtable_resize_if_needed!(ht::MonomialHashtable, added::Int)
while hashtable_needs_resize(newsize, ht.load, added)
newsize *= 2
end
if newsize != ht.size
@invariant !ht.frozen
newsize == ht.size && return nothing

ht.size = newsize
@assert ispow2(ht.size)
@invariant !ht.frozen
ht.size = newsize
@invariant ispow2(ht.size)

resize!(ht.hashdata, ht.size)
resize!(ht.monoms, ht.size)
resize!(ht.hashtable, ht.size)
@inbounds for i in 1:(ht.size)
ht.hashtable[i] = zero(MonomId)
end
resize!(ht.hashdata, ht.size)
resize!(ht.monoms, ht.size)
resize!(ht.hashtable, ht.size)
@inbounds for i in 1:(ht.size)
ht.hashtable[i] = zero(MonomId)
end

mod = MonomHash(ht.size - 1)

@inbounds for i in (ht.offset):(ht.load)
# hash for this elem is already computed
he = ht.hashdata[i].hash
hidx = he
for j in MonomHash(1):MonomHash(ht.size)
hidx = hashtable_next_lookup_index(he, j, mod)
!iszero(ht.hashtable[hidx]) && continue
ht.hashtable[hidx] = i
break
end
mod = MonomHash(ht.size - 1)

@inbounds for i in (ht.offset):(ht.load)
# hash for this elem is already computed
he = ht.hashdata[i].hash
hidx = he
for j in MonomHash(1):MonomHash(ht.size)
hidx = hashtable_next_lookup_index(he, j, mod)
!iszero(ht.hashtable[hidx]) && continue
ht.hashtable[hidx] = i
break
end
end
nothing
Expand Down
9 changes: 9 additions & 0 deletions src/fglm/fglm_internal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ function enumerator_produce_next_monomials!(
while m.load + ht.nvars >= length(m.monoms)
resize!(m.monoms, length(m.monoms) * 2)
end
# TODO: maybe an error, uncomment this line later
# hashtable_resize_if_needed!(ht, ht.nvars)

emonom = ht.monoms[monom]
@inbounds for i in 1:(ht.nvars)
Expand Down Expand Up @@ -80,6 +82,8 @@ function staircase_divides_monom(monom, staircase, ht)
false
end

const _seen = Dict()

function fglm_main!(
ring::PolyRing,
basis::Basis{C},
Expand All @@ -92,6 +96,7 @@ function fglm_main!(
from ordering: $(ring.ord)
to ordering: $ord"""

empty!(_seen)
monom_enumerator = enumerator_initialize(ht, ord)
new_basis = basis_initialize(ring, basis.nfilled, C)
matrix = wide_matrix_initialize(basis)
Expand All @@ -110,6 +115,10 @@ function fglm_main!(
continue
end

if haskey(_seen, monom)
throw("This monomial has been processed before !")
end
_seen[monom] = 1
# Compute the normal form of the monomial w.r.t. by constructing and
# echelonizing the F4 matrix.
to_be_reduced = basis_initialize(ring, [[monom]], [C[1]])
Expand Down

0 comments on commit 08d269d

Please sign in to comment.