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: a complete binary tree with natural-number leaves.Tree.Rep: the contiguous memory representation, including every internal sum.Tree.prefixSumandTree.add: prefix queries and point increments.
Main results #
Tree.prefixSum_eq_sum_take: the query is the sum of the corresponding leaf prefix.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.
@[instance_reducible]
@[instance_reducible]
Instances For
The aggregate stored at the root.
Instances For
Number of words occupied by a complete aggregation tree.
Instances For
The all-zero array has a concrete, nonempty representation in zero memory.