Fixed Word-RAM prefix queries #
The query descends through an aggregation tree, adding the complete left subtree whenever it descends right. It stops at an empty prefix or a complete subtree. The program is fixed; the array size, query position and tree pointer are register inputs.
Main definitions #
queryLoop: a fixed program for prefix queries.
Main results #
queryLoop_spec: the answer equals the mathematical prefix sum within13 (h + 1) + 2instructions, with all memory preserved.
References #
One prefix-query iteration.
Instances For
Fixed prefix-query loop. Its answer is added to the initial accumulator.
Instances For
def Cslib.Algorithms.WordRAM.PrefixSums.queryNext (x : WordRAM.Data 14) (b n i a : ℕ) :
WordRAM.Data 14
Mathematical description of one query iteration, used only in the proof.
Instances For
theorem Cslib.Algorithms.WordRAM.PrefixSums.queryBody_exec {w b n i δ a : ℕ} {x : WordRAM.Data 14} (hx : Entry b n i δ x) (hi : i ≤ n) (hn : 0 < n) (hxans : x.regs Reg.ans = a) (ha : WordRAM.Fits w (b + 2 * n)) (hv : WordRAM.Fits w (a + x.mem b)) (hl : i ≠ n → n / 2 ≤ i → WordRAM.Fits w (a + x.mem (b + 1))) :
WordRAM.ExecWithin w queryBody x (queryNext x b n i a) 11
@[simp]
theorem Cslib.Algorithms.WordRAM.PrefixSums.queryLoop_full {w b n δ a : ℕ} {x : WordRAM.Data 14} (hx : Entry b n n δ x) (hn : 0 < n) (hxans : x.regs Reg.ans = a) (ha : WordRAM.Fits w (b + 2 * n)) (hv : WordRAM.Fits w (a + x.mem b)) :
theorem Cslib.Algorithms.WordRAM.PrefixSums.queryLoop_spec {w h b i δ a : ℕ} {x : WordRAM.Data 14} (t : Tree h) (hx : Entry b (2 ^ h) i δ x) (hi : i ≤ 2 ^ h) (hxans : x.regs Reg.ans = a) (hr : t.Rep b x.mem) (ha : WordRAM.Fits w (b + 2 * 2 ^ h)) (hv : WordRAM.Fits w (a + t.total)) :
A query adds precisely the first i leaf values to its initial accumulator, using at
most 13 (h + 1) + 2 instructions. The whole memory is unchanged. Bounds include the loop
tests and jumps, but entry-register installation and tree construction are separate.