Balanced aggregation trees for dynamic prefix sums #
An array of 2 ^ h natural numbers is represented by a complete binary aggregation tree.
The logical operations are addition at one position and summation of a prefix. Nodes are
laid out in preorder in a contiguous region of 2 * 2 ^ h - 1 words. These definitions do
not assign unit cost to a Lean operation: the concrete Word-RAM client supplies the execution
and cost proofs.
Main definitions #
Tree,Tree.leaves,Tree.total,Tree.zero: a complete binary tree with natural-number leaves, its leaf array, root aggregate, and all-zero tree.increment: the shared point incrementPrefixSums.addAton natural-number arrays.Tree.words,Tree.Rep: word count and contiguous memory representation, including every internal sum.Tree.prefixSum,Tree.add: prefix queries and point increments.
Main results #
Tree.prefixSum_eq_sum_take: the query is the sum of the corresponding leaf prefix.Tree.leaves_add: the tree update isPrefixSums.addAton the leaf array.Tree.Rep.congr: representation depends only on its owned region.
References #
- T. H. Cormen, C. E. Leiserson, R. L. Rivest and C. Stein, Introduction to Algorithms for balanced trees and aggregation invariants.
Point increment on the natural-number array of the word-RAM interface: the shared
PrefixSums.addAt. The name remains only for Dynamic.spec, which will use addAt directly once
it moves to PrefixSums.spec.
The aggregate stored at the root.
Number of words occupied by a complete aggregation tree.
A leaf tree of height zero occupies one word.
The all-zero array has a concrete, nonempty representation in zero memory.