Documentation

CslibFrontier.DataStructure.HashFamily.WordRAM.Tabulation

Self-contained Word-RAM random tables and tabulated odd-stride generation #

This file provides two self-contained Word-RAM hashing primitives over Cslib.WordRAM.Basis.exact, built on a shared uniform word-slice sampler (randFillLoop):

  1. RandomTable: resampleCode populates an array Z[0 .. 2 ^ M - 1] of m = 2 ^ M independent uniform M-bit words in 5 * 2 ^ M + 7 instructions and 2 ^ M calls to Code.rand, inducing PMF.uniformOfFintype (Fin (2 ^ M) → Fin (2 ^ M)). lookupCode reads Z[idx] in 2 deterministic instructions, and xorLookupCode evaluates the XOR-shifted hash f(u) ^^^ Z[g(u)] in 3 deterministic instructions Carter and Wegman; Mitzenmacher and Upfal.
  2. TabulatedOddStride: simpleTab splits the low d * b bits of an input key u into d characters of b = max 1 (Nat.log 2 (max n_max 2) / 2) bits (2 ^ b ≤ max 2 n_max words per character table) and XORs their table entries (following the simple tabulation scheme of Zobrist 1970 and Pătraşcu and Thorup 2012). initCode d samples the d character tables via Code.rand in 4 * Nat.log 2 (max n_max 2) + 5 * (d * 2 ^ b) + 30 instructions (O(d * 2 ^ b + log n_max), which is O(n_max) for fixed d), and evalCode d evaluates oddStride M (simpleTab b d M T u).val = (2 * (simpleTab b d M T u).val + 1) &&& (2 ^ M - 1) in 8 * d + 21 deterministic instructions (O(d)). When M > 0, this stride h₂(u) is odd (at M = 0 it is 0 on Fin 1), and for every M it is coprime to 2 ^ M, so for any initial slot h₁(u) : Fin (2 ^ M) the linear probe sequence probeSeq M h₁(u) tab i = (h₁(u) + i * h₂(u)) % 2 ^ M is a bijection on Fin (2 ^ M) (bijective_probeSeq) Cormen, Leiserson, Rivest, and Stein, Section 11.4. Only this full-cycle permutation property is proved here: no k-wise or 3-wise independence theorem for simple tabulation is claimed in this module, and simpleTab inspects only the low d * b bits of u.

Main definitions #

Main results #

References #

Section 1: Uniform random word-slice filler (randFillLoop) #

@[reducible, inline]

Register 0 of randFillLoop: write pointer ptr.

@[reducible, inline]

Register 1 of randFillLoop: end pointer arrBase + len.

@[reducible, inline]

Register 2 of randFillLoop: random bitmask 2 ^ bits - 1.

@[reducible, inline]

Register 3 of randFillLoop: constant 1.

@[reducible, inline]

Register 4 of randFillLoop: sampled value scratch register.

@[reducible, inline]

Register 5 of randFillLoop: caller-preserved register.

Structured Word-RAM loop that fills [regPtr, regEnd) with independent uniform draws in [0, regMask].

Single-iteration state update of randFillBody when Code.rand draws v.

Explicit ProbComp (Data 6 × ℕ) induced by randFillLoop over len words starting at arrBase.

def Cslib.DataStructure.HashFamily.WordRAM.Tabulation.extractSlice (arrBase bits len : ℕ) (mem : ℕ → ℕ) :
Fin len → Fin (2 ^ bits)

Extract a contiguous slice of len words at arrBase as a tuple Fin len → Fin (2 ^ bits).

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.randFillBody_execRand {w bits arrBase : ℕ} {x : WordRAM.Data 6} (hptr : x.regs regPtr = arrBase) (hmask : x.regs regMask = 2 ^ bits - 1) (hone : x.regs regOne = 1) (hfit_ptr : WordRAM.Fits w (arrBase + 1)) (hfit_mask : WordRAM.Fits w (2 ^ bits - 1)) :
WordRAM.ExecRand w randFillBody x do let k ← ProbComp.unifFin (2 ^ bits - 1) pure (randFillStepData arrBase (↑k) x, 3)

One iteration of randFillBody executes in 3 instructions and 1 rand call.

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.randFillLoop_execRand {w bits arrBase : ℕ} (len : ℕ) {x : WordRAM.Data 6} (hptr : x.regs regPtr = arrBase) (hend : x.regs regEnd = arrBase + len) (hmask : x.regs regMask = 2 ^ bits - 1) (hone : x.regs regOne = 1) (hfit_end : WordRAM.Fits w (arrBase + len)) (hfit_mask : WordRAM.Fits w (2 ^ bits - 1)) :
WordRAM.ExecRand w randFillLoop x (randFillComp bits arrBase len x)

Exact ExecRand semantics of randFillLoop over len words starting at arrBase.

randFillComp bits arrBase len x makes at most len rand calls.

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.mem_support_randFillComp {bits arrBase len : ℕ} {x : WordRAM.Data 6} {z : WordRAM.Data 6 × ℕ} (hz : z ∈ OracleComp.support (randFillComp bits arrBase len x)) :
z.2 = 5 * len + 2 ∧ (z.1.regs regPtr = if len = 0 then x.regs regPtr else arrBase + len) ∧ z.1.regs regEnd = x.regs regEnd ∧ z.1.regs regMask = x.regs regMask ∧ z.1.regs regOne = x.regs regOne ∧ z.1.regs regExtra = x.regs regExtra ∧ (∀ i < len, z.1.mem (arrBase + i) < 2 ^ bits) ∧ ∀ (a : ℕ), a < arrBase ∨ arrBase + len ≤ a → z.1.mem a = x.mem a

Pathwise postcondition of randFillComp: takes 5 * len + 2 instructions, preserves registers regEnd, regMask, regOne, regExtra, fills [arrBase, arrBase + len) with < 2 ^ bits words, and preserves all memory outside [arrBase, arrBase + len).

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.map_extractSlice_eval_randFillComp (bits arrBase len : ℕ) (x : WordRAM.Data 6) :
PMF.map (fun (z : WordRAM.Data 6 × ℕ) => extractSlice arrBase bits len z.1.mem) (randFillComp bits arrBase len x).eval = Probability.PMF.uniformOfFintype (Fin len → Fin (2 ^ bits))

Uniformity of randFillComp: the slice extractSlice arrBase bits len z.1.mem produced by randFillComp bits arrBase len x has the exact product uniform distribution PMF.uniformOfFintype (Fin len → Fin (2 ^ bits)).

Section 2: RandomTable — 1-D random table for Cuckoo Hashing #

Footprint size of RandomTable M: 2 ^ M words at [base, base + 2 ^ M).

@[reducible, inline]

Register 0: holds the base memory address base of the table.

@[reducible, inline]

Register 1: holds M during resampleCode, or index idx < 2 ^ M during lookupCode.

@[reducible, inline]

Alias for register 1 when used as the lookup index idx < 2 ^ M.

@[reducible, inline]

Register 2: receives Z[idx] in lookupCode or fx ^^^ Z[idx] in xorLookupCode.

@[reducible, inline]

Register 3: scratch register 1.

@[reducible, inline]

Register 4: scratch register 2.

@[reducible, inline]

Register 5: scratch register 3.

def Cslib.DataStructure.HashFamily.WordRAM.Tabulation.RandomTable.Rep (base M : ℕ) (Z : Fin (2 ^ M) → Fin (2 ^ M)) (mem : ℕ → ℕ) :

Memory representation invariant: [base, base + 2 ^ M) holds the entries of Z : Fin (2 ^ M) → Fin (2 ^ M).

Extract the random table Z : Fin (2 ^ M) → Fin (2 ^ M) from memory at base.

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.RandomTable.rep_extractTable {base M : ℕ} {mem : ℕ → ℕ} (h : ∀ i < 2 ^ M, mem (base + i) < 2 ^ M) :
Rep base M (extractTable base M mem) mem

If every word in [base, base + 2 ^ M) is < 2 ^ M, then Rep base M (extractTable base M mem) mem holds.

Injective register permutation mapping randFillLoop's registers into RandomTable so that regExtra maps to regBase (preserving regBase).

Deterministic setup before randFillLoop in resampleCode: computes 2 ^ M, 2 ^ M - 1, base + 2 ^ M, and initializes the loop registers.

Structured Word-RAM program that initializes or resamples Z[0 .. 2 ^ M - 1] at base using 2 ^ M calls to Code.rand on 2 ^ M - 1.

@[reducible, inline]

Alias for resampleCode when used for initial table construction.

Explicit ProbComp (Data 6 × ℕ) induced by resampleCode at (base, M) from x.

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.RandomTable.setupCode_exec {w base M : ℕ} {x : WordRAM.Data 6} (hbase : x.regs regBase = base) (hM : x.regs regM = M) (hfit_end : WordRAM.Fits w (base + 2 ^ M)) (hfit_pow : WordRAM.Fits w (2 ^ M)) :

setupCode executes deterministically in 5 instructions when Fits w (base + 2 ^ M) and Fits w (2 ^ M).

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.RandomTable.resampleCode_execRand {w base M : ℕ} {x : WordRAM.Data 6} (hbase : x.regs regBase = base) (hM : x.regs regM = M) (hfit_end : WordRAM.Fits w (base + 2 ^ M)) (hfit_pow : WordRAM.Fits w (2 ^ M)) :

Exact ExecRand execution of RandomTable.resampleCode: runs in 5 * 2 ^ M + 7 instructions and 2 ^ M rand calls.

Uniformity of RandomTable.resampleComp: the extracted table extractTable base M z.1.mem is distributed according to PMF.uniformOfFintype (Fin (2 ^ M) → Fin (2 ^ M)).

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.RandomTable.resampleCode_execRandWithin {w base M : ℕ} {x : WordRAM.Data 6} (hbase : x.regs regBase = base) (hM : x.regs regM = M) (hfit_end : WordRAM.Fits w (base + 2 ^ M)) (hfit_pow : WordRAM.Fits w (2 ^ M)) :
WordRAM.ExecRandWithin w resampleCode x (fun (y : WordRAM.Data 6) => Rep base M (extractTable base M y.mem) y.mem ∧ y.regs regBase = base ∧ ∀ (a : ℕ), a < base ∨ base + 2 ^ M ≤ a → y.mem a = x.mem a) (5 * 2 ^ M + 7) (2 ^ M)

Hoare-style ExecRandWithin specification for RandomTable.resampleCode: runs in 5 * 2 ^ M + 7 steps and 2 ^ M rand calls, establishing Rep, preserving regBase, and modifying only [base, base + 2 ^ M).

Structured Word-RAM program that reads Z[regIdx] at regBase + regIdx into regOut in 2 deterministic instructions.

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.RandomTable.lookupCode_exec {w base M : ℕ} {Z : Fin (2 ^ M) → Fin (2 ^ M)} {x : WordRAM.Data 6} (hrep : Rep base M Z x.mem) (idx : Fin (2 ^ M)) (hbase : x.regs regBase = base) (hidx : x.regs regIdx = ↑idx) (hfit_end : WordRAM.Fits w (base + 2 ^ M)) :

lookupCode executes in 2 deterministic instructions, preserving memory and regBase and writing (Z idx).val into regOut.

Structured Word-RAM program that computes regOut ← regOut ^^^ Z[regIdx] in 3 deterministic instructions (computing f(u) ^^^ Z[g(u)] when regOut holds f(u) and regIdx holds g(u)).

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.RandomTable.xorLookupCode_exec {w base M : ℕ} {Z : Fin (2 ^ M) → Fin (2 ^ M)} {x : WordRAM.Data 6} (hrep : Rep base M Z x.mem) (idx fx : Fin (2 ^ M)) (hbase : x.regs regBase = base) (hidx : x.regs regIdx = ↑idx) (hfx : x.regs regOut = ↑fx) (hfit_end : WordRAM.Fits w (base + 2 ^ M)) (hfit_pow : WordRAM.Fits w (2 ^ M)) :

xorLookupCode executes in 3 deterministic instructions, preserving memory and regBase and writing fx.val ^^^ (Z idx).val < 2 ^ M into regOut.

Section 3: TabulatedOddStride #

Character bit-width b = max 1 (⌊log₂ (max n_max 2)⌋ / 2) for d-character simple tabulation, ensuring 1 ≤ b and 2 ^ b ≤ max 2 n_max (2 ^ (2 * b) ≤ max 4 n_max).

The character alphabet size 2 ^ charBits n_max is at most max 2 n_max.

Odd stride (2 * tab + 1) &&& (2 ^ M - 1) = (2 * tab + 1) % 2 ^ M in Fin (2 ^ M).

When 0 < M, (oddStride M tab).val is odd (% 2 = 1).

(oddStride M tab).val is always coprime to 2 ^ M.

Double-hashing probe sequence probeSeq M h₁ tab i = (h₁ + i * oddStride M tab) mod 2 ^ M on Fin (2 ^ M).

Because oddStride M tab is coprime to 2 ^ M, probeSeq M h₁ tab is a full-cycle bijection (permutation) of Fin (2 ^ M) for every M, initial probe h₁, and raw table sum tab.

def Cslib.DataStructure.HashFamily.WordRAM.Tabulation.TabulatedOddStride.simpleTabAux (b d M : ℕ) (T : Fin (d * 2 ^ b) → Fin (2 ^ M)) :
ℕ → ℕ → ℕ → Fin (2 ^ M) → Fin (2 ^ M)

Tail-recursive d-character simple tabulation accumulator from character offset j across rem remaining characters: XORs T[(j + k) * 2 ^ b + ((u >>> (k * b)) &&& (2 ^ b - 1))] into acc.

d-character simple tabulation hash simpleTab b d M T u : Fin (2 ^ M), XORing the table entries for the first d base-2 ^ b characters of u.

Tabulated odd stride tabulatedOddStride b d M T u : Fin (2 ^ M) obtained by mapping the d-character simple tabulation hash through oddStride M.

Memory footprint 4 + d * 2 ^ b words for a d-character simple tabulation table with character bit-width b (4 header words (b, 2 ^ b, 2 ^ b - 1, 2 ^ M - 1) followed by d * 2 ^ b random < 2 ^ M words).

Memory footprint 4 + d * 2 ^ (charBits n_max) words at capacity parameter n_max.

def Cslib.DataStructure.HashFamily.WordRAM.Tabulation.TabulatedOddStride.Rep (base b d M : ℕ) (T : Fin (d * 2 ^ b) → Fin (2 ^ M)) (mem : ℕ → ℕ) :

Memory representation predicate for TabulatedOddStride at [base, base + 4 + d * 2 ^ b): header words b, 2 ^ b, 2 ^ b - 1, 2 ^ M - 1 at base + 0 .. base + 3, and table entries (T i).val at base + 4 + i.val for i : Fin (d * 2 ^ b).

Extract the flat character table Fin (d * 2 ^ b) → Fin (2 ^ M) from [base + 4, ...).

@[reducible, inline]

Register 0 of TabulatedOddStride: base memory address base.

@[reducible, inline]

Register 1 of TabulatedOddStride: holds n_max in initCode or input key u in evalCode.

@[reducible, inline]

Register 2 of TabulatedOddStride: holds M in initCode or receives the odd stride in evalCode.

@[reducible, inline]

Register 3 of TabulatedOddStride: table pointer scratch register.

@[reducible, inline]

Register 4 of TabulatedOddStride: end pointer / mask scratch register.

@[reducible, inline]

Register 5 of TabulatedOddStride: character bit-width b / loop bound register.

@[reducible, inline]

Register 6 of TabulatedOddStride: character alphabet size 2 ^ b / sampled value register.

@[reducible, inline]

Register 7 of TabulatedOddStride: character mask 2 ^ b - 1 register.

@[reducible, inline]

Register 8 of TabulatedOddStride: general scratch register.

Register injection Fin 3 → Fin 9 mapping log2Loop's (rem, acc, one) to (regPtr, regB, regTmp).

Register injection Fin 6 → Fin 9 mapping randFillLoop's (ptr, end, mask, one, val, extra) to (regPtr, regB, regEnd, regTmp, regPowB, regBase).

Structured Word-RAM program that computes regB ← charBits n_max (= max 1 (⌊log₂ (max n_max 2)⌋ / 2)) at runtime from n_max in regKey, using regPtr, regB, regTmp as scratch registers and preserving regBase, regOut, and all memory.

charBitsCode executes deterministically in 4 * Nat.log 2 (max n_max 2) + 12 instructions, setting regB = charBits n_max while preserving regBase, regOut, and all memory.

Deterministic 16-instruction setup prefix of initFromBCode d: writes the 4 header words (b, 2 ^ b, 2 ^ b - 1, 2 ^ M - 1) to base + 0 .. base + 3 and sets registers for randFillLoop.rename fillMap9 on [base + 4, base + 4 + d * 2 ^ b).

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.TabulatedOddStride.setupFromBCode_exec {w base b d M : ℕ} {x : WordRAM.Data 9} (hbase : x.regs regBase = base) (hb : x.regs regB = b) (hM : x.regs regOut = M) (hfit_space : WordRAM.Fits w (base + spaceFromB b d)) (hfit_powB : WordRAM.Fits w (2 ^ b)) (hfit_powM : WordRAM.Fits w (2 ^ M)) (hfit_d : WordRAM.Fits w d) :
WordRAM.Exec w (setupFromBCode d) x (setupFromBData base b d M x) 16

setupFromBCode d executes in 16 deterministic steps.

Structured Word-RAM program that initializes a d-character simple tabulation table from (base, M, b) in (regBase, regOut, regB).

Explicit ProbComp (Data 9 × ℕ) produced by initFromBCode d.

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.TabulatedOddStride.initFromBCode_execRand {w base b d M : ℕ} {x : WordRAM.Data 9} (hbase : x.regs regBase = base) (hb : x.regs regB = b) (hM : x.regs regOut = M) (hfit_space : WordRAM.Fits w (base + spaceFromB b d)) (hfit_powB : WordRAM.Fits w (2 ^ b)) (hfit_powM : WordRAM.Fits w (2 ^ M)) (hfit_d : WordRAM.Fits w d) :

Exact ExecRand semantics of initFromBCode d.

The character table extractTable base b d M z.1.mem produced by initFromBComp is uniformly distributed over Fin (d * 2 ^ b) → Fin (2 ^ M).

Self-contained initCode d that computes b = charBits n_max from n_max in regKey and initializes the d-character simple tabulation table at base (regBase) with M-bit entries (regOut = M).

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.TabulatedOddStride.mem_support_initFromBComp {base b d M : ℕ} {x : WordRAM.Data 9} {z : WordRAM.Data 9 × ℕ} (hbase : x.regs regBase = base) (hz : z ∈ OracleComp.support (initFromBComp base b d M x)) :
z.2 = 5 * (d * 2 ^ b) + 18 ∧ Rep base b d M (extractTable base b d M z.1.mem) z.1.mem ∧ z.1.regs regBase = base ∧ ∀ (a : ℕ), a < base ∨ base + spaceFromB b d ≤ a → z.1.mem a = x.mem a

Pathwise postcondition of initFromBComp: runs in 5 * (d * 2 ^ b) + 18 instructions and establishes Rep base b d M (extractTable base b d M z.1.mem) z.1.mem, z.1.regs regBase = base, and frame preservation outside [base, base + spaceFromB b d).

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.TabulatedOddStride.initFromBCode_execRandWithin {w base b d M : ℕ} {x : WordRAM.Data 9} (hbase : x.regs regBase = base) (hb : x.regs regB = b) (hM : x.regs regOut = M) (hfit_space : WordRAM.Fits w (base + spaceFromB b d)) (hfit_powB : WordRAM.Fits w (2 ^ b)) (hfit_powM : WordRAM.Fits w (2 ^ M)) (hfit_d : WordRAM.Fits w d) :
WordRAM.ExecRandWithin w (initFromBCode d) x (fun (y : WordRAM.Data 9) => Rep base b d M (extractTable base b d M y.mem) y.mem ∧ y.regs regBase = base ∧ ∀ (a : ℕ), a < base ∨ base + spaceFromB b d ≤ a → y.mem a = x.mem a) (5 * (d * 2 ^ b) + 18) (d * 2 ^ b)

Hoare-style ExecRandWithin specification for initFromBCode d.

Explicit ProbComp (Data 9 × ℕ) produced by initCode d from (base, n_max, M).

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.TabulatedOddStride.initCode_execRand {w base n_max d M : ℕ} {x : WordRAM.Data 9} (hbase : x.regs regBase = base) (hn : x.regs regKey = n_max) (hM : x.regs regOut = M) (hfit_n : WordRAM.Fits w (max n_max 2)) (hfit_space : WordRAM.Fits w (base + space n_max d)) (hfit_powM : WordRAM.Fits w (2 ^ M)) (hfit_d : WordRAM.Fits w d) :
WordRAM.ExecRand w (initCode d) x (initComp base n_max d M x)

Exact ExecRand semantics of initCode d.

Uniformity of TabulatedOddStride.initComp: the character table extracted from final memory has the exact uniform distribution over Fin (d * 2 ^ (charBits n_max)) → Fin (2 ^ M).

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.TabulatedOddStride.initCode_execRandWithin {w base n_max d M : ℕ} {x : WordRAM.Data 9} (hbase : x.regs regBase = base) (hn : x.regs regKey = n_max) (hM : x.regs regOut = M) (hfit_n : WordRAM.Fits w (max n_max 2)) (hfit_space : WordRAM.Fits w (base + space n_max d)) (hfit_powM : WordRAM.Fits w (2 ^ M)) (hfit_d : WordRAM.Fits w d) :
WordRAM.ExecRandWithin w (initCode d) x (fun (y : WordRAM.Data 9) => Rep base (charBits n_max) d M (extractTable base (charBits n_max) d M y.mem) y.mem ∧ y.regs regBase = base ∧ ∀ (a : ℕ), a < base ∨ base + space n_max d ≤ a → y.mem a = x.mem a) (4 * Nat.log 2 (max n_max 2) + 5 * (d * 2 ^ charBits n_max) + 30) (d * 2 ^ charBits n_max)

Hoare-style ExecRandWithin specification for TabulatedOddStride.initCode d.

12-instruction deterministic setup before tabLoop in evalCode d: loads b, 2 ^ b, 2 ^ b - 1 from base + 0 .. base + 2, sets regPtr = base + 4 and regEnd = base + 4 + d * 2 ^ b, and zeros regOut.

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.TabulatedOddStride.evalSetupCode_exec {w base b d M : ℕ} {T : Fin (d * 2 ^ b) → Fin (2 ^ M)} {x : WordRAM.Data 9} (hrep : Rep base b d M T x.mem) (hbase : x.regs regBase = base) (hfit_space : WordRAM.Fits w (base + spaceFromB b d)) (hfit_d : WordRAM.Fits w d) :
WordRAM.Exec w (evalSetupCode d) x (evalSetupData base b d x) 12

evalSetupCode d executes in 12 deterministic steps when Rep base b d M T x.mem holds.

Body of tabLoop (6 instructions): extracts ch = regKey &&& regMaskB, loads T[regPtr + ch], XORs into regOut, shifts regKey right by regB, and advances regPtr by regPowB.

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.TabulatedOddStride.tabLoop_exec {w base b d M : ℕ} {T : Fin (d * 2 ^ b) → Fin (2 ^ M)} {x : WordRAM.Data 9} (hrep : Rep base b d M T x.mem) (hfit_space : WordRAM.Fits w (base + spaceFromB b d)) (hfit_powM : WordRAM.Fits w (2 ^ M)) (rem j u : ℕ) (acc : Fin (2 ^ M)) (d0 : WordRAM.Data 9) :
j + rem = d → d0.mem = x.mem → d0.regs regBase = base → d0.regs regPtr = base + 4 + j * 2 ^ b → d0.regs regEnd = base + 4 + d * 2 ^ b → d0.regs regB = b → d0.regs regPowB = 2 ^ b → d0.regs regMaskB = 2 ^ b - 1 → d0.regs regKey = u → d0.regs regOut = ↑acc → WordRAM.Fits w u → ∃ (y : WordRAM.Data 9), WordRAM.Exec w tabLoop d0 y (8 * rem + 2) ∧ y.regs regOut = ↑(simpleTabAux b d M T rem j u acc) ∧ y.regs regBase = base ∧ y.mem = x.mem

tabLoop executes deterministically in 8 * rem + 2 instructions from character offset j with j + rem = d, accumulating (simpleTabAux b d M T rem j u acc).val into regOut and preserving regBase and all memory.

7-instruction finishing suffix of evalCode d: loads 2 ^ M - 1 from base + 3 and maps acc in regOut to (2 * acc + 1) &&& (2 ^ M - 1).

Complete d-character simple tabulation odd-stride evaluation program evalCode d.

theorem Cslib.DataStructure.HashFamily.WordRAM.Tabulation.TabulatedOddStride.evalCode_execWithin {w base b d M u : ℕ} {T : Fin (d * 2 ^ b) → Fin (2 ^ M)} {x : WordRAM.Data 9} (hrep : Rep base b d M T x.mem) (hbase : x.regs regBase = base) (hu : x.regs regKey = u) (hfit_space : WordRAM.Fits w (base + spaceFromB b d)) (hfit_powM : WordRAM.Fits w (2 * 2 ^ M)) (hfit_d : WordRAM.Fits w d) (hfit_u : WordRAM.Fits w u) :
∃ (y : WordRAM.Data 9), WordRAM.ExecWithin w (evalCode d) x y (8 * d + 21) ∧ y.regs regOut = ↑(tabulatedOddStride b d M T u) ∧ y.regs regBase = base ∧ y.mem = x.mem

TabulatedOddStride.evalCode d correctness and complexity: for any character table T : Fin (d * 2 ^ b) → Fin (2 ^ M) represented at base and key u with Fits w u, evalCode d halts deterministically in 8 * d + 21 = O(d) instructions, preserving regBase and all memory and writing (tabulatedOddStride b d M T u).val into regOut.