Documentation

Linglib.Core.Data.RoseTree.Leaves

Leaf projections of a rose tree #

leavesWithDepth collects the leaves of a rose tree as a multiset of (label, root-distance) pairs; leaves forgets the depths. Leaf statistics are then Multiset computations — counts are Multiset.countP, bounds are inherited from Multiset.countP_le_card — instead of one bespoke fold per statistic.

Main definitions #

Main results #

[UPSTREAM] candidate alongside the RoseTree carrier.

The projections #

def RoseTree.leavesWithDepth {α : Type u_1} :
RoseTree αMultiset (α × )

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
    def RoseTree.leaves {α : Type u_1} (t : RoseTree α) :
    Multiset α

    The multiset of leaf labels of a rose tree.

    Equations
    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
      @[simp]
      theorem RoseTree.leaves_leaf {α : Type u_1} (a : α) :
      (node a []).leaves = {a}
      @[simp]
      theorem RoseTree.leaves_node_cons {α : Type u_1} (a : α) (c : RoseTree α) (cs : List (RoseTree α)) :
      (node a (c :: cs)).leaves = (List.map leaves (c :: cs)).sum

      Depth-forgetting collapses the shift: the leaf labels of a node are the children's leaf labels.

      Cardinality #

      theorem RoseTree.card_leavesWithDepth {α : Type u_1} (t : RoseTree α) :

      The projection has one element per leaf.

      theorem RoseTree.card_leaves {α : Type u_1} (t : RoseTree α) :
      t.leaves.card = t.numLeaves

      The number of leaf labels is the number of leaves.

      A leaf is a vertex.

      Perm invariance #

      theorem RoseTree.leavesWithDepth_perm {α : Type u_1} {t s : RoseTree α} (h : t.Perm s) :

      leavesWithDepth is a Perm-invariant: the fold algebra reads its arguments only through a nil test and a sum.

      theorem RoseTree.leaves_perm {α : Type u_1} {t s : RoseTree α} (h : t.Perm s) :

      leaves is a Perm-invariant.

      Descent to Nonplanar #

      def RootedTree.Nonplanar.leavesWithDepth {α : Type u_1} :
      Nonplanar αMultiset (α × )

      The leaves of a nonplanar tree, each paired with its distance from the root.

      Equations
      Instances For
        def RootedTree.Nonplanar.leaves {α : Type u_1} (t : Nonplanar α) :
        Multiset α

        The multiset of leaf labels of a nonplanar tree.

        Equations
        Instances For
          @[simp]
          theorem RootedTree.Nonplanar.leaves_mk {α : Type u_1} (t : RoseTree α) :
          (mk t).leaves = t.leaves
          @[simp]
          theorem RootedTree.Nonplanar.leavesWithDepth_leaf {α : Type u_1} (a : α) :
          (leaf a).leavesWithDepth = {(a, 0)}
          @[simp]
          theorem RootedTree.Nonplanar.leaves_leaf {α : Type u_1} (a : α) :
          (leaf a).leaves = {a}

          The projection has one element per leaf.

          theorem RootedTree.Nonplanar.card_leaves {α : Type u_1} (t : Nonplanar α) :
          t.leaves.card = t.numLeaves

          The number of leaf labels is the number of leaves.

          A leaf is a vertex.