Skip to content

Commit

Permalink
Do not store the degree in the hash-value
Browse files Browse the repository at this point in the history
  • Loading branch information
Sasha Demin committed Apr 17, 2024
1 parent 2e5740f commit 3f690f5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/f4/basis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ end
if !basis.isredundant[i] &&
!monom_is_gcd_const(ht.monoms[basis.monoms[i][1]], ht.monoms[new_lead])
lcms[i] = hashtable_get_lcm!(basis.monoms[i][1], new_lead, ht, update_ht)
degs[newidx] = update_ht.hashdata[lcms[i]].deg
degs[newidx] = monom_totaldeg(update_ht.monoms[lcms[i]])
ps[newidx] = CriticalPair(Int32(i), Int32(idx), lcms[i])
else
lcms[i] = CRITICAL_PAIR_REDUNDANT
Expand Down Expand Up @@ -627,7 +627,7 @@ function basis_is_new_polynomial_redundant!(
pairset_resize_if_needed!(pairset, 1)
lcm_new = hashtable_get_lcm!(lead_i, lead_new, ht, ht)
ps[pairset.load + 1] = CriticalPair(Int32(i), Int32(idx), lcm_new)
degs[pairset.load + 1] = ht.hashdata[lcm_new].deg
degs[pairset.load + 1] = monom_totaldeg(ht.monoms[lcm_new])
pairset.load += 1

# Mark the polynomial as redundant.
Expand Down Expand Up @@ -830,7 +830,7 @@ function insert_lcms_in_basis_hashtable!(

uhd = update_ht.hashdata
ll = plcm[l]
ht.hashdata[ht.load + 1] = Hashvalue(0, h, uhd[ll].divmask, uhd[ll].deg)
ht.hashdata[ht.load + 1] = Hashvalue(0, h, uhd[ll].divmask)

ht.load += 1
ps[m] = CriticalPair(ps[m].poly1, ps[m].poly2, MonomId(pos))
Expand Down
11 changes: 5 additions & 6 deletions src/f4/f4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ end

hashval = symbol_ht.hashdata[i]
symbol_ht.hashdata[i] =
Hashvalue(UNKNOWN_PIVOT_COLUMN, hashval.hash, hashval.divmask, hashval.deg)
Hashvalue(UNKNOWN_PIVOT_COLUMN, hashval.hash, hashval.divmask)
matrix.ncols_left += 1
f4_find_multiplied_reducer!(basis, matrix, ht, symbol_ht, MonomId(i))
i += 1
Expand Down Expand Up @@ -183,7 +183,7 @@ function f4_autoreduce!(
matrix.upper_to_mult[row_idx] = hashtable_insert!(ht, etmp)
hv = symbol_ht.hashdata[uprows[row_idx][1]]
symbol_ht.hashdata[uprows[row_idx][1]] =
Hashvalue(UNKNOWN_PIVOT_COLUMN, hv.hash, hv.divmask, hv.deg)
Hashvalue(UNKNOWN_PIVOT_COLUMN, hv.hash, hv.divmask)
end

# needed for correct column count in symbol hashtable
Expand All @@ -193,7 +193,7 @@ function f4_autoreduce!(
# set all pivots to unknown
@inbounds for i in (symbol_ht.offset):(symbol_ht.load)
hv = symbol_ht.hashdata[i]
symbol_ht.hashdata[i] = Hashvalue(UNKNOWN_PIVOT_COLUMN, hv.hash, hv.divmask, hv.deg)
symbol_ht.hashdata[i] = Hashvalue(UNKNOWN_PIVOT_COLUMN, hv.hash, hv.divmask)
end

matrix_fill_column_to_monom_map!(matrix, symbol_ht)
Expand Down Expand Up @@ -359,7 +359,6 @@ function f4_find_multiplied_reducer!(
PIVOT_COLUMN,
monom_hashval.hash,
monom_hashval.divmask,
monom_hashval.deg
)
matrix.nrows_filled_upper += 1

Expand Down Expand Up @@ -549,7 +548,7 @@ function f4_add_critical_pairs_to_matrix!(
# Mark the matrix column that corresponds to the lcm as a pivot.
hv = symbol_ht.hashdata[uprows[row_idx][1]]
symbol_ht.hashdata[uprows[row_idx][1]] =
Hashvalue(PIVOT_COLUMN, hv.hash, hv.divmask, hv.deg)
Hashvalue(PIVOT_COLUMN, hv.hash, hv.divmask)

# Add all polynomials with the same lcm to the lower part of matrix (to
# be reduced).
Expand Down Expand Up @@ -584,7 +583,7 @@ function f4_add_critical_pairs_to_matrix!(

hv = symbol_ht.hashdata[lowrows[row_idx][1]]
symbol_ht.hashdata[lowrows[row_idx][1]] =
Hashvalue(PIVOT_COLUMN, hv.hash, hv.divmask, hv.deg)
Hashvalue(PIVOT_COLUMN, hv.hash, hv.divmask)
end

i = j
Expand Down
8 changes: 3 additions & 5 deletions src/f4/hashtable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ struct Hashvalue
hash::MonomHash
# corresponding divmask to speed up divisibility checks,
divmask::DivisionMask
# total degree of the monomial
deg::MonomHash
end

# Hashtable implements open addressing with linear scan.
Expand Down Expand Up @@ -393,7 +391,7 @@ function hashtable_insert!(ht::MonomialHashtable{M}, e::M) where {M <: Monom}
ht.ndivbits,
ht.compress_divmask
)
@inbounds ht.hashdata[vidx] = Hashvalue(0, he, divmask, monom_totaldeg(e))
@inbounds ht.hashdata[vidx] = Hashvalue(0, he, divmask)

ht.load += 1

Expand Down Expand Up @@ -485,7 +483,7 @@ function hashtable_fill_divmasks!(ht::MonomialHashtable)
ht.ndivbits,
ht.compress_divmask
)
ht.hashdata[vidx] = Hashvalue(0, unmasked.hash, divmask, monom_totaldeg(e))
ht.hashdata[vidx] = Hashvalue(0, unmasked.hash, divmask)
end

nothing
Expand Down Expand Up @@ -648,7 +646,7 @@ function hashtable_insert_polynomial_multiple!(
symbol_ht.compress_divmask
)
symbol_ht.hashdata[vidx] =
Hashvalue(NON_PIVOT_COLUMN, newhash, divmask, monom_totaldeg(newmonom))
Hashvalue(NON_PIVOT_COLUMN, newhash, divmask)

row[j] = vidx
symbol_ht.load += 1
Expand Down
14 changes: 7 additions & 7 deletions src/f4/learn_apply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function f4_reducegb_learn!(
# set lead index as 1
hv = symbol_ht.hashdata[uprows[row_idx][1]]
symbol_ht.hashdata[uprows[row_idx][1]] =
Hashvalue(UNKNOWN_PIVOT_COLUMN, hv.hash, hv.divmask, hv.deg)
Hashvalue(UNKNOWN_PIVOT_COLUMN, hv.hash, hv.divmask)
end
trace.nonredundant_indices_before_reduce = basis.nonredundant[1:(basis.nnonredundant)]

Expand All @@ -137,7 +137,7 @@ function f4_reducegb_learn!(
# set all pivots to unknown
@inbounds for i in (symbol_ht.offset):(symbol_ht.load)
hv = symbol_ht.hashdata[i]
symbol_ht.hashdata[i] = Hashvalue(UNKNOWN_PIVOT_COLUMN, hv.hash, hv.divmask, hv.deg)
symbol_ht.hashdata[i] = Hashvalue(UNKNOWN_PIVOT_COLUMN, hv.hash, hv.divmask)
end

matrix_fill_column_to_monom_map!(matrix, symbol_ht)
Expand Down Expand Up @@ -306,7 +306,7 @@ function matrix_fill_column_to_monom_map!(
# hash -> column
@inbounds for k in 1:length(column_to_monom)
hv = hdata[column_to_monom[k]]
hdata[column_to_monom[k]] = Hashvalue(k, hv.hash, hv.divmask, hv.deg)
hdata[column_to_monom[k]] = Hashvalue(k, hv.hash, hv.divmask)
end

@inbounds for k in 1:(matrix.nrows_filled_upper)
Expand Down Expand Up @@ -426,7 +426,7 @@ function f4_symbolic_preprocessing!(

hv = symbol_ht.hashdata[matrix.lower_rows[i][1]]
symbol_ht.hashdata[matrix.lower_rows[i][1]] =
Hashvalue(PIVOT_COLUMN, hv.hash, hv.divmask, hv.deg)
Hashvalue(PIVOT_COLUMN, hv.hash, hv.divmask)

matrix.lower_to_coeffs[i] = poly_idx
end
Expand All @@ -453,7 +453,7 @@ function f4_symbolic_preprocessing!(

hv = symbol_ht.hashdata[matrix.upper_rows[i][1]]
symbol_ht.hashdata[matrix.upper_rows[i][1]] =
Hashvalue(PIVOT_COLUMN, hv.hash, hv.divmask, hv.deg)
Hashvalue(PIVOT_COLUMN, hv.hash, hv.divmask)

matrix.upper_to_coeffs[i] = poly_idx
end
Expand All @@ -467,7 +467,7 @@ function f4_symbolic_preprocessing!(
if iszero(symbol_ht.hashdata[i].idx)
hv = symbol_ht.hashdata[i]
symbol_ht.hashdata[i] =
Hashvalue(UNKNOWN_PIVOT_COLUMN, hv.hash, hv.divmask, hv.deg)
Hashvalue(UNKNOWN_PIVOT_COLUMN, hv.hash, hv.divmask)
end
i += MonomId(1)
end
Expand Down Expand Up @@ -533,7 +533,7 @@ function autoreduce_f4_apply!(
# set all pivots to unknown
@inbounds for i in (symbol_ht.offset):(symbol_ht.load)
hv = symbol_ht.hashdata[i]
symbol_ht.hashdata[i] = Hashvalue(UNKNOWN_PIVOT_COLUMN, hv.hash, hv.divmask, hv.deg)
symbol_ht.hashdata[i] = Hashvalue(UNKNOWN_PIVOT_COLUMN, hv.hash, hv.divmask)
end

matrix.nrows_filled_lower = nlow
Expand Down
4 changes: 2 additions & 2 deletions src/f4/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ end
# hash -> column
@inbounds for k in 1:length(column_to_monom)
hv = hdata[column_to_monom[k]]
hdata[column_to_monom[k]] = Hashvalue(k, hv.hash, hv.divmask, hv.deg)
hdata[column_to_monom[k]] = Hashvalue(k, hv.hash, hv.divmask)
end

@inbounds for k in 1:(matrix.nrows_filled_upper)
Expand Down Expand Up @@ -532,7 +532,7 @@ function matrix_insert_in_basis_hashtable_pivots!(
row[l] = pos
l += 1

bdata[pos] = Hashvalue(sdata[hidx].idx, h, sdata[hidx].divmask, sdata[hidx].deg)
bdata[pos] = Hashvalue(sdata[hidx].idx, h, sdata[hidx].divmask)

ht.load += 1
end
Expand Down

0 comments on commit 3f690f5

Please sign in to comment.