Documentation

CslibFrontier.Foundations.Data.Bracketing

Bracketings of a list #

A bracketing of a nonempty list is a way of grouping its entries by nested pairs of brackets: a binary tree whose leaves, read from left to right, are the entries of the list (Cslib.Bracketing). Every nonempty list of length n has a bracketing of height at most ⌈lg n⌉ (Cslib.Bracketing.exists_leaves_eq), obtained by halving. Divide-and-conquer arguments over a product of n factors in a fixed order go by induction on the height of the subtrees of such a bracketing (Cslib.Bracketing.subtrees).

Main definitions #

Main results #

inductive Cslib.Bracketing (σ : Type u_1) :
Type u_1

A bracketing: a binary tree with leaves labelled in σ.

def Cslib.Bracketing.leaves {σ : Type u_1} :
Bracketing σ → List σ

The entries of a bracketing, from left to right.

The height of a bracketing: the largest number of brackets around an entry.

The subtrees of a bracketing, itself included.

The subtrees of a subtree are subtrees.

theorem Cslib.Bracketing.mem_subtrees_of_node {σ : Type u_1} {t l r : Bracketing σ} (h : l.node r ∈ t.subtrees) :

The two halves of a subtree are subtrees.

A bracketing of n entries has 2 n - 1 subtrees.

The entries of a subtree form a sublist of the entries of the bracketing.

theorem Cslib.Bracketing.exists_leaves_eq {σ : Type u_1} (l : List σ) (hl : l ≠ []) :
∃ (t : Bracketing σ), t.leaves = l ∧ t.height ≤ Nat.clog 2 l.length

Every nonempty list of length n has a bracketing of height at most ⌈lg n⌉.