Spans of subtrees in the frontier #
The frontier of a subtree is a slice of the frontier of the tree. RoseTree.leafIndex t p is
where the slice for the subtree at the address p begins, the number of leaves of t to its
left, and the slice has as many entries as the subtree has leaves. These are the lemmas
List.take_sum_flatten, List.drop_sum_flatten and List.drop_take_succ_flatten_eq_getElem
of mathlib one level up: a list of lists is a tree of height two, and the index of its ith
member in the flattened list is the sum of the lengths before it.
Dominance and precedence of positions become containment and order of spans. A position below
another begins no earlier and ends no later, a position that precedes another ends before the
other begins, and two positions are left-aligned (TreePath.LeftAligned) exactly when they
begin at the same leaf.
Main definitions #
RoseTree.leafIndex: the number of leaves left of the subtree at an address.
Main results #
RoseTree.drop_take_leafList: the frontier of a subtree is the slice of the frontier that begins at its index.RoseTree.leafList_replaceAt: replacing a subtree replaces its slice.RoseTree.leafIndex_add_numLeaves_le_of_precedes: a subtree ends before one it precedes begins.RoseTree.leftAligned_iff_leafIndex_eq: left-aligned positions are those with one index.
The index of a subtree #
t.leafIndex p is the number of leaves of t to the left of the subtree at the address p,
the index in the frontier at which the frontier of that subtree begins.
Equations
- x✝.leafIndex [] = 0
- (RoseTree.node value cs).leafIndex (i :: p) = (List.map RoseTree.numLeaves (List.take i cs)).sum + cs[i]?.elim 0 fun (x : RoseTree α) => x.leafIndex p
Instances For
The slice of a subtree #
The frontier of a tree is the leaves left of a subtree, the frontier of the subtree, and the leaves to its right.
The frontier of the subtree at p is the slice of the frontier of the tree that begins at
t.leafIndex p.
Replacing the subtree at p replaces its slice of the frontier.
Dominance and precedence #
The frontier of a subtree ends before the frontier of any subtree it precedes begins.
Left-alignment #
Two positions of a tree are left-aligned exactly when their frontiers begin at the same leaf.