Documentation

CslibFrontier.DataStructure.FusionTree.WordRAM.LowerRank

Strict packed sketch ranks #

The zero-bit branch of arbitrary-query correction requires a strict rank. Subtracting the number of sketches at least the query from the node occupancy handles equality and zero queries directly.

Main definitions #

Main results #

References #

@[reducible, inline]

The input register layout agrees with RankProgram, except register seven is occupancy and register one contains the original sketches rather than their complements.

@[reducible, inline]

Packed guarded sketches.

@[reducible, inline]

Replication multiplier.

@[reducible, inline]

Mask of field guards.

@[reducible, inline]

Payload width.

@[reducible, inline]

Middle digit divisor.

@[reducible, inline]

Number of stored sketches.

@[reducible, inline]

Scratch for the replicated query.

@[reducible, inline]

Final strict rank.

Count guards for q ≤ sᵢ, then subtract the count from the occupancy.

Exact state after all eight instructions.

theorem Cslib.DataStructure.FusionTree.WordRAM.LowerRankProgram.countGuards_complement {b n q : ℕ} (s : ℕ → ℕ) (hn : 0 < n) (hb : n < 2 ^ (b + 1)) (hs : ∀ i < n, s i < 2 ^ b) (hq : q < 2 ^ b) :
n - countGuards b n s q = {i ∈ Finset.range n | s i < q}.card

Subtracting the number of sketches at least q from n counts the sketches strictly below q.

theorem Cslib.DataStructure.FusionTree.WordRAM.LowerRankProgram.exec {w b n q : ℕ} (s : ℕ → ℕ) (x : WordRAM.Data 10) (hn : 0 < n) (hb : n < 2 ^ (b + 1)) (hs : ∀ i < n, s i < 2 ^ b) (hq : q < 2 ^ b) (hw : 2 * ((b + 1) * n) ≤ w) (hxq : x.regs query = q) (hxn : x.regs node = packedNode b n s) (hxc : x.regs copies = queryMultiplier b n) (hxg : x.regs guards = guardMask b n) (hxb : x.regs bits = b) (hxm : x.regs middle = 2 ^ ((b + 1) * (n - 1))) (hxr : x.regs base = 2 ^ (b + 1)) (hxn' : x.regs count = n) :
WordRAM.Exec w code x (result x b n s q) 8 ∧ (result x b n s q).regs out = {i ∈ Finset.range n | s i < q}.card ∧ (result x b n s q).mem = x.mem

Eight checked instructions return the strict rank, including zero and equality queries. The node parameters and memory are preserved; query compression and constant loading are separate. The full guard-count product fits under the stated packed-width bound.