Documentation

CslibFrontier.Algorithms.WordRAM.TrimmedYates.Enumeration

Bounded-cardinality subset enumeration and coordinate extraction on the word RAM #

Coordinate-by-coordinate generation of subsets of size at most k (prefixesUpTo, genLowSubsets), bit-scanning coordinate extraction (extractCoords), in-place complementation into high-cardinality subsets of C (flipHighDom), and identity coordinate-buffer initialization (initIdentityCoords).

Main definitions #

Main results #

Pure model of coordinate-by-coordinate subset enumeration #

Subsets of coords of cardinality at most k, built coordinate by coordinate in the exact order produced by genLowSubsets.

theorem Cslib.Algorithms.WordRAM.TrimmedYates.prefixesUpTo_spec {d : ℕ} (k : ℕ) {coords : List (Fin d)} :
coords.Nodup → (prefixesUpTo k coords).Nodup ∧ ∀ (S : Finset (Fin d)), S ∈ prefixesUpTo k coords ↔ S ⊆ coords.toFinset ∧ S.card ≤ k
theorem Cslib.Algorithms.WordRAM.TrimmedYates.length_prefixesUpTo {d : ℕ} (k : ℕ) {coords : List (Fin d)} :
coords.Nodup → (prefixesUpTo k coords).length = ∑ j ∈ Finset.range (k + 1), coords.length.choose j

Generate all subsets of coords[0 .. rCoordsLen - 1] of size ≤ rMaxCard at rDomPtr.

theorem Cslib.Algorithms.WordRAM.TrimmedYates.exec_genLowSubsets {w d coordsPtr domPtr k : ℕ} (coords : List (Fin d)) (x : WordRAM.Data numRegs) (hz : x.regs rZero = 0) (ho : x.regs rOne = 1) (hcptr : x.regs rCoordsPtr = coordsPtr) (hclen : x.regs rCoordsLen = coords.length) (hk : x.regs rMaxCard = k) (hdptr : x.regs rDomPtr = domPtr) (hnd : coords.Nodup) (hcoords_mem : ∀ (j : ℕ) (hj : j < coords.length), x.mem (coordsPtr + j) = ↑coords[j]) (hdisj : coordsPtr + coords.length ≤ domPtr) (hfit_mem : WordRAM.Fits w (domPtr + 2 * ∑ j ∈ Finset.range (k + 1), coords.length.choose j)) (hfit_mask : WordRAM.Fits w (2 ^ d)) :
have outList := prefixesUpTo k coords; ∃ (y : WordRAM.Data numRegs), WordRAM.ExecWithin w genLowSubsets x y (coords.length * (20 * ∑ j ∈ Finset.range (k + 1), coords.length.choose j + 12) + 8) ∧ y.regs rDomLen = outList.length ∧ HoldsDom y.mem domPtr outList ∧ (∀ (a : ℕ), a < domPtr ∨ domPtr + 2 * outList.length ≤ a → y.mem a = x.mem a) ∧ ∀ (i : Fin numRegs), i ≠ rTrieTmp ∧ i ≠ Reg.builtRoot ∧ (↑i < 27 ∨ 33 ≤ ↑i) → y.regs i = x.regs i

Scan bits 0 .. Reg.dim - 1 of rTrieKey and write set indices to rCoordsPtr.

theorem Cslib.Algorithms.WordRAM.TrimmedYates.exec_extractCoords {w d coordsPtr : ℕ} (C : Finset (Fin d)) (x : WordRAM.Data numRegs) (hz : x.regs rZero = 0) (ho : x.regs rOne = 1) (hd : x.regs Reg.dim = d) (hk : x.regs rTrieKey = setMask C) (hcptr : x.regs rCoordsPtr = coordsPtr) (hfit_mem : WordRAM.Fits w (coordsPtr + d)) (hfit_mask : WordRAM.Fits w (2 ^ d)) :
have cList := List.filter (fun (x : Fin d) => decide (x ∈ C)) (List.finRange d); ∃ (y : WordRAM.Data numRegs), WordRAM.ExecWithin w extractCoords x y (11 * d + 5) ∧ y.regs rCoordsLen = cList.length ∧ (∀ (j : ℕ) (hj : j < cList.length), y.mem (coordsPtr + j) = ↑cList[j]) ∧ (∀ (a : ℕ), a < coordsPtr ∨ coordsPtr + d ≤ a → y.mem a = x.mem a) ∧ ∀ (i : Fin numRegs), i ≠ rTrieRem ∧ i ≠ rCoordsLen ∧ i ≠ rGenIdx ∧ i ≠ rGenTmp → y.regs i = x.regs i

Complement every subset in rDomPtr[0 .. rDomLen - 1] inside rTrieKey = setMask C.

theorem Cslib.Algorithms.WordRAM.TrimmedYates.exec_flipHighDom {w d domPtr : ℕ} (C : Finset (Fin d)) (ys : List (Finset (Fin d))) (x : WordRAM.Data numRegs) (ho : x.regs rOne = 1) (hk : x.regs rTrieKey = setMask C) (hcl : x.regs rCoordsLen = C.card) (hdptr : x.regs rDomPtr = domPtr) (hdlen : x.regs rDomLen = ys.length) (hys_sub : ∀ Y ∈ ys, Y ⊆ C) (hdom : HoldsDom x.mem domPtr ys) (hfit_mem : WordRAM.Fits w (domPtr + 2 * ys.length)) (hfit_mask : WordRAM.Fits w (2 ^ d)) :
∃ (y : WordRAM.Data numRegs), WordRAM.ExecWithin w flipHighDom x y (12 * ys.length + 3) ∧ HoldsDom y.mem domPtr (List.map (fun (x : Finset (Fin d)) => C \ x) ys) ∧ (∀ (a : ℕ), a < domPtr ∨ domPtr + 2 * ys.length ≤ a → y.mem a = x.mem a) ∧ ∀ (i : Fin numRegs), i ≠ rTrieTmp ∧ i ≠ rGenPos ∧ i ≠ rGenTmp → y.regs i = x.regs i

Initialize rCoordsPtr[0 .. Reg.dim - 1] with the identity coordinate list [0 .. d - 1].

theorem Cslib.Algorithms.WordRAM.TrimmedYates.exec_initIdentityCoords {w d coordsPtr : ℕ} (x : WordRAM.Data numRegs) (ho : x.regs rOne = 1) (hd : x.regs Reg.dim = d) (hcptr : x.regs rCoordsPtr = coordsPtr) (hfit_mem : WordRAM.Fits w (coordsPtr + d)) (hfit_d : WordRAM.Fits w d) :
∃ (y : WordRAM.Data numRegs), WordRAM.ExecWithin w initIdentityCoords x y (5 * d + 3) ∧ (∀ (j : ℕ) (hj : j < (List.finRange d).length), y.mem (coordsPtr + j) = ↑(List.finRange d)[j]) ∧ (∀ (a : ℕ), a < coordsPtr ∨ coordsPtr + d ≤ a → y.mem a = x.mem a) ∧ ∀ (i : Fin numRegs), i ≠ rGenIdx ∧ i ≠ rGenTmp → y.regs i = x.regs i