Generic domain-to-trie tabulation and pointwise product on the word RAM #
Allocates a fresh depth-d binary trie and evaluates either an arbitrary cell body (tabulateDom)
or pointwise signed multiplication (tabulateMul) over an interleaved (mask, size) domain array.
Main definitions #
Cslib.Algorithms.WordRAM.TrimmedYates.IsCellMod,IsTabMod: modified-register footprints for a cell body and the enclosing tabulation loop.Cslib.Algorithms.WordRAM.TrimmedYates.tabulateDom,tabulateMul: generic domain-tabulation loop and pointwise trie product over an active domain.
Main results #
Cslib.Algorithms.WordRAM.TrimmedYates.tabulateDom_preserves,exec_tabulateDom,tabulateMul_preserves,exec_tabulateMul: register frames andExecWithinspecifications.
@[reducible, inline]
Registers potentially modified by a single cell body inside tabulateDom.
@[reducible, inline]
Registers potentially modified by tabulateDom.
def Cslib.Algorithms.WordRAM.TrimmedYates.tabulateDom (cellBody : WordRAM.Code WordRAM.Basis.standard numRegs) :
Allocate a fresh depth-Reg.dim trie and populate cellBody at each (mask, size) entry in
Reg.entryPtr[0 .. Reg.entryCount - 1], leaving the root in Reg.builtRoot.
theorem Cslib.Algorithms.WordRAM.TrimmedYates.tabulateDom_preserves {cellBody : WordRAM.Code WordRAM.Basis.standard numRegs} (i : Fin numRegs) (hcell : ¬IsCellMod i → WordRAM.Code.Preserves i cellBody) (hi : ¬IsTabMod i) :
WordRAM.Code.Preserves i (tabulateDom cellBody)
theorem Cslib.Algorithms.WordRAM.TrimmedYates.exec_tabulateDom {w d domPtr free T_cell : ℕ} {cellBody : WordRAM.Code WordRAM.Basis.standard numRegs} {dom : List (Finset (Fin d))} {cellFn : Finset (Fin d) → ℕ} {Inv : WordRAM.Data numRegs → Prop} (x : WordRAM.Data numRegs) (hz : x.regs rZero = 0) (ho : x.regs rOne = 1) (hd : x.regs Reg.dim = d) (hdp : x.regs Reg.entryPtr = domPtr) (hdl : x.regs Reg.entryCount = dom.length) (hfree : x.regs Reg.free = free) (hfree_pos : 1 ≤ free) (hnd : dom.Nodup) (hdom : HoldsDom x.mem domPtr dom) (hdom_below : domPtr + 2 * dom.length ≤ free) (hInv_init : Inv x) (hInv_congr :
∀ (s₁ s₂ : WordRAM.Data numRegs),
(∀ a < free, s₁.mem a = s₂.mem a) → (∀ (i : Fin numRegs), ¬IsTabMod i → s₁.regs i = s₂.regs i) → Inv s₁ → Inv s₂) (hcell :
∀ (s : WordRAM.Data numRegs) (p : ℕ) (hp : p < dom.length),
s.regs rZero = 0 →
s.regs rOne = 1 →
s.regs Reg.dim = d →
Inv s →
(∀ a < free, s.mem a = x.mem a) →
s.regs rCellKey = setMask dom[p] →
s.regs rCellCard = dom[p].card →
∃ (u : WordRAM.Data numRegs),
WordRAM.ExecWithin w cellBody s u T_cell ∧ u.regs rTrieVal = cellFn dom[p] ∧ u.mem = s.mem ∧ ∀ (i : Fin numRegs), ¬IsCellMod i → u.regs i = s.regs i) (hfit_free : WordRAM.Fits w (free + 2 + 2 * d * dom.length)) (hfit_mask : WordRAM.Fits w (2 ^ d)) :
∃ (y : WordRAM.Data numRegs) (free' : ℕ) (S' : Set ℕ) (outFn : ℕ → ℕ),
WordRAM.ExecWithin w (tabulateDom cellBody) x y (dom.length * (14 * d + T_cell + 16) + 9) ∧ y.regs Reg.builtRoot = free ∧ y.regs Reg.free = free' ∧ free + 2 ≤ free' ∧ free' ≤ free + 2 + 2 * d * dom.length ∧ S' ⊆ Set.Ico free free' ∧ TrieRep y.mem d free S' outFn ∧ (∀ X ∈ dom, outFn (setMask X) = cellFn X) ∧ ∀ (a : ℕ), a < free ∨ free' ≤ a → y.mem a = x.mem a
Tabulate the pointwise signed product of tries rStageCurRoot and rStageFbRoot across
Reg.entryPtr[0 .. Reg.entryCount - 1], leaving the product trie root in Reg.builtRoot.
theorem Cslib.Algorithms.WordRAM.TrimmedYates.exec_tabulateMul {w d domPtr free rootF rootG B : ℕ} {dom : List (Finset (Fin d))} {fnF fnG : ℕ → ℕ} {valF valG : Finset (Fin d) → ℤ} (x : WordRAM.Data numRegs) (hz : x.regs rZero = 0) (ho : x.regs rOne = 1) (hd : x.regs Reg.dim = d) (hdp : x.regs Reg.entryPtr = domPtr) (hdl : x.regs Reg.entryCount = dom.length) (hfree : x.regs Reg.free = free) (hfree_pos : 1 ≤ free) (hrF : x.regs rStageCurRoot = rootF) (hrG : x.regs rStageFbRoot = rootG) (hnd : dom.Nodup) (hdom : HoldsDom x.mem domPtr dom) (hdom_below : domPtr + 2 * dom.length ≤ free) (htrieF : HoldsTrie x.mem free d rootF fnF) (htrieG : HoldsTrie x.mem free d rootG fnG) (hvalF : ∀ X ∈ dom, fnF (setMask X) = WordRAM.Signed.encode (valF X) ∧ (valF X).natAbs ≤ B) (hvalG : ∀ X ∈ dom, fnG (setMask X) = WordRAM.Signed.encode (valG X) ∧ (valG X).natAbs ≤ B) (hvalFG : ∀ X ∈ dom, (valF X * valG X).natAbs ≤ B) (hfit_val : WordRAM.Fits w (8 * B + 4)) (hfit_free : WordRAM.Fits w (free + 2 + 2 * d * dom.length)) (hfit_mask : WordRAM.Fits w (2 ^ d)) :
∃ (y : WordRAM.Data numRegs) (free' : ℕ) (outFn : ℕ → ℕ),
WordRAM.ExecWithin w tabulateMul x y (dom.length * (32 * d + 53) + 9) ∧ y.regs Reg.builtRoot = free ∧ y.regs Reg.free = free' ∧ free + 2 ≤ free' ∧ free' ≤ free + 2 + 2 * d * dom.length ∧ HoldsTrie y.mem free' d free outFn ∧ (∀ X ∈ dom, outFn (setMask X) = WordRAM.Signed.encode (valF X * valG X)) ∧ (∀ (a : ℕ), a < free ∨ free' ≤ a → y.mem a = x.mem a) ∧ ∀ (i : Fin numRegs), ¬IsTabMod i → y.regs i = x.regs i