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 #
queryBody,queryLoop,queryNext: one iteration of a prefix query, the fixed prefix-query loop, and the state transition of one iteration.
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
@[simp]
One prefix-query iteration leaves RAM memory unchanged.
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.