Documentation

CslibFrontier.DataStructure.FusionTree.WordRAM.Neighbors

Loading and selecting sketch neighbors #

An inclusive sketch cut has at most two neighboring full keys. Clamp the two indices to a nonempty array, load both keys, and compare their exclusive or with the query. Clamping allows the same bounded program to handle cuts at either end of the array.

Main definitions #

Main results #

References #

@[reducible, inline]

Query word, preserved.

@[reducible, inline]

Inclusive sketch cut, preserved.

@[reducible, inline]

Nonzero node occupancy, preserved.

@[reducible, inline]

Address of the first full key, preserved.

@[reducible, inline]

Distance between full keys, preserved.

@[reducible, inline]

Constant one.

@[reducible, inline]

Clamped predecessor index.

@[reducible, inline]

Clamped successor index.

@[reducible, inline]

Clamping scratch.

@[reducible, inline]

Memory address scratch.

@[reducible, inline]

First candidate key.

@[reducible, inline]

Second candidate key.

@[reducible, inline]

First candidate's exclusive or with the query.

@[reducible, inline]

Second candidate's exclusive or with the query.

@[reducible, inline]

Selected key's exclusive or with the query.

@[reducible, inline]

Selected array index.

Clamped successor position, expressed using two saturating subtractions.

Thirteen instructions load the candidates. Selection adds four or five instructions, including control flow, and prefers the left candidate when exclusive-or values tie.

State after loading, before the one comparison selecting a candidate.

Final state, choosing the smaller full-word exclusive or.

theorem Cslib.DataStructure.FusionTree.WordRAM.NeighborProgram.result_sketchNeighbor {w n q a d : ℕ} (x : WordRAM.Data 17) (keys : Fin n → ℕ) (hn : 0 < n) (hkeys : ∀ (i : Fin n), x.mem (a + ↑i * d) = keys i) :
∃ (j : Fin n), (result x q n (sketchRank w keys q) a d).regs index = ↑j ∧ (result x q n (sketchRank w keys q) a d).regs chosen = keys j ∧ (result x q n (sketchRank w keys q) a d).regs divergence = keys j ^^^ q ∧ IsSketchNeighbor w keys q j ∧ ∀ (i : Fin n), IsSketchNeighbor w keys q i → keys j ^^^ q ≤ keys i ^^^ q

With an actual sketch cut and an encoded full-key array, the output identifies a sketch neighbor with minimum exclusive-or value among the neighbors. No full-key scan supplies the answer. The statement is separate from the checked execution and can be composed with it.

theorem Cslib.DataStructure.FusionTree.WordRAM.NeighborProgram.exec {w q n t a d : ℕ} (x : WordRAM.Data 17) (hn : 0 < n) (ht : t ≤ n) (hq : WordRAM.Fits w q) (hnfit : WordRAM.Fits w n) (ha : WordRAM.Fits w (a + (n - 1) * d)) (hkeys : ∀ i < n, WordRAM.Fits w (x.mem (a + i * d))) (hxq : x.regs query = q) (hxt : x.regs cut = t) (hxn : x.regs count = n) (hxa : x.regs base = a) (hxd : x.regs stride = d) :
WordRAM.ExecWithin w code x (result x q n t a d) 18 ∧ (result x q n t a d).mem = x.mem

Loading two clamped neighbors and selecting one takes at most eighteen actual checked instructions. The address premise covers the last array key; every accessed address and intermediate product lies below it. The query, cut, occupancy, base, stride, and memory are preserved. Constant preparation and the sketch cut itself are separate.