Documentation

Complexity.Algorithms.WordRAM.PrefixSums.Query

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 #

Main results #

References #

Fixed prefix-query loop. Its answer is added to the initial accumulator.

Instances For

    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)) :
      ∃ (y : WordRAM.Data 14), WordRAM.ExecWithin w queryLoop x y (13 * (h + 1) + 2) ∧ y.regs Reg.ans = a + t.prefixSum i ∧ y.mem = x.mem

      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.