Documentation

CslibFrontier.DataStructure.PrefixSums.WordRAM.Update

Fixed Word-RAM point updates for aggregation trees #

The program walks from the root to the updated leaf. Every visited node is incremented, and the next subtree is selected by the position relative to half the current length. The same code handles every height, position and increment. Its arithmetic and all its loads, stores, tests and jumps are actual bounded-word instructions.

Main definitions #

Main results #

References #

@[reducible, inline]

Constant zero.

@[reducible, inline]

Constant one.

@[reducible, inline]

Constant two.

@[reducible, inline]

Current subtree pointer.

@[reducible, inline]

Current subtree length.

@[reducible, inline]

Position relative to the current subtree.

@[reducible, inline]

Increment supplied to an update.

@[reducible, inline]

Loaded value and arithmetic scratch.

@[reducible, inline]

Address scratch.

@[reducible, inline]

Query answer.

@[reducible, inline]

Operation tag, zero for update and nonzero for query.

@[reducible, inline]

Persistent root pointer.

@[reducible, inline]

Persistent array capacity.

@[reducible, inline]

External operation position.

Registers used by both tree traversals.

Increment one node and move to the selected child. A leaf has half-length zero; the resulting length stops the loop before another access.

Fixed update code, independent of array size, position and increment.

The data after one update iteration; this is a mathematical description, not an additional instruction in the machine.

@[simp]
theorem Cslib.DataStructure.PrefixSums.WordRAM.updateNext_mem {b n i δ : ℕ} {x : WordRAM.Data 14} (a : ℕ) :
(updateNext x b n i δ).mem a = Function.update x.mem b (x.mem b + δ) a

One update iteration increments the memory word at the current node pointer b by δ and leaves all other addresses unchanged.

theorem Cslib.DataStructure.PrefixSums.WordRAM.updateLoop_spec {w h b i δ : ℕ} {x : WordRAM.Data 14} (t : Tree h) (hx : Entry b (2 ^ h) i δ x) (hi : i < 2 ^ h) (hr : t.Rep b x.mem) (ha : WordRAM.Fits w (b + 2 * 2 ^ h)) (hv : WordRAM.Fits w (t.total + δ)) :
∃ (y : WordRAM.Data 14), WordRAM.ExecWithin w updateLoop x y (11 * (h + 1) + 2) ∧ (t.add i δ).Rep b y.mem ∧ ∀ (a : ℕ), a < b ∨ b + Tree.words h ≤ a → y.mem a = x.mem a

The fixed update loop runs in at most 11 (h + 1) + 2 instructions. It restores the complete aggregation invariant and preserves every word outside the original footprint. The bound assumes the existing tree is supplied in memory; it does not include construction.