Leaf projections of a rose tree #
RoseTree.leavesWithDepth collects the leaves of a rose tree as a multiset of pairs of a label
and its distance from the root. RoseTree.leaves forgets the distances, which leaves the
frontier RoseTree.leafList without its order. The number of leaves satisfying a predicate is
Multiset.countP on leaves.
Main definitions #
RoseTree.leavesWithDepth,RoseTree.leaves: the projections.
Main results #
RoseTree.card_leavesWithDepth: the projection hasnumLeaveselements.RoseTree.coe_leafList: the leaf labels are the frontier with its order forgotten.RoseTree.numLeaves_le_numNodes: a leaf is a vertex.RoseTree.countP_leaves_lt_numNodes_of_not: when the root fails the predicate, the counted leaves are among the non-root vertices.RoseTree.leavesWithDepth_perm,RoseTree.leaves_perm: both projections arePerm-invariant.
The projections #
The leaves of a rose tree, each paired with its distance from the root.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The multiset of leaf labels of a rose tree.
Equations
- t.leaves = Multiset.map Prod.fst t.leavesWithDepth
Instances For
@[simp]
theorem
RoseTree.leavesWithDepth_leaf
{α : Type u_1}
(a : α)
:
(node a []).leavesWithDepth = {(a, 0)}
@[simp]
theorem
RoseTree.leavesWithDepth_node_cons
{α : Type u_1}
(a : α)
(c : RoseTree α)
(cs : List (RoseTree α))
:
(node a (c :: cs)).leavesWithDepth = (List.map (fun (t : RoseTree α) => Multiset.map (fun (p : α × ℕ) => (p.1, p.2 + 1)) t.leavesWithDepth) (c :: cs)).sum
Cardinality #
theorem
RoseTree.card_leavesWithDepth
{α : Type u_1}
(t : RoseTree α)
:
t.leavesWithDepth.card = t.numLeaves
The projection has one element per leaf.
Perm invariance #
leavesWithDepth is Perm-invariant, since the fold algebra reads its arguments only
through a nil test and a sum.
Leaf statistics by predicate #
@[simp]
theorem
RoseTree.card_filter_leavesWithDepth
{α : Type u_1}
(p : α → Prop)
[DecidablePred p]
(t : RoseTree α)
:
(Multiset.filter (fun (q : α × ℕ) => p q.1) t.leavesWithDepth).card = Multiset.countP p t.leaves