Documentation

Linglib.Core.Data.RoseTree.Count

Size measures on rooted nonplanar trees and their forests #

Main definitions #

Main results #

[UPSTREAM] candidate alongside the Nonplanar carrier.

Leaf statistics by predicate #

def RoseTree.leafCountP {α : Type u_1} (p : αProp) [DecidablePred p] (t : RoseTree α) :

The number of leaves whose label satisfies p.

Equations
Instances For
    def RoseTree.leafDepthsP {α : Type u_1} (p : αProp) [DecidablePred p] (t : RoseTree α) :
    Multiset

    The multiset of root-distances of the leaves whose label satisfies p.

    Equations
    Instances For
      def RoseTree.leafDepthSumP {α : Type u_1} (p : αProp) [DecidablePred p] (t : RoseTree α) :

      The sum of root-distances of the leaves whose label satisfies p.

      Equations
      Instances For
        @[simp]
        theorem RoseTree.leafCountP_leaf {α : Type u_1} (p : αProp) [DecidablePred p] (a : α) :
        leafCountP p (node a []) = if p a then 1 else 0
        @[simp]
        theorem RoseTree.leafCountP_node_cons {α : Type u_1} (p : αProp) [DecidablePred p] (a : α) (c : RoseTree α) (cs : List (RoseTree α)) :
        leafCountP p (node a (c :: cs)) = (List.map (leafCountP p) (c :: cs)).sum
        theorem RoseTree.leafCountP_node_of_ne_nil {α : Type u_1} (p : αProp) [DecidablePred p] (a : α) (cs : List (RoseTree α)) (h : cs []) :
        leafCountP p (node a cs) = (List.map (leafCountP p) cs).sum

        On a non-leaf node the count is the children's total, for any root label.

        theorem RoseTree.leafCountP_node_of_not {α : Type u_1} (p : αProp) [DecidablePred p] (a : α) (cs : List (RoseTree α)) (h : ¬p a) :
        leafCountP p (node a cs) = (List.map (leafCountP p) cs).sum

        A root failing p contributes nothing, for any child list.

        theorem RoseTree.leafCountP_pos {α : Type u_1} {p : αProp} [DecidablePred p] {t : RoseTree α} :
        0 < leafCountP p t (a : α), a t.leaves p a
        theorem RoseTree.leafCountP_eq_zero {α : Type u_1} {p : αProp} [DecidablePred p] {t : RoseTree α} :
        leafCountP p t = 0 ∀ (a : α), a t.leaves¬p a
        theorem RoseTree.leafCountP_eq_numLeaves {α : Type u_1} {p : αProp} [DecidablePred p] {t : RoseTree α} :
        leafCountP p t = t.numLeaves ∀ (a : α), a t.leavesp a

        The count exhausts the leaves exactly when every leaf label satisfies p.

        @[simp]
        theorem RoseTree.card_leafDepthsP {α : Type u_1} (p : αProp) [DecidablePred p] (t : RoseTree α) :
        (leafDepthsP p t).card = leafCountP p t

        The counted leaves are exactly the depth entries: leafCountP is their number.

        @[simp]
        theorem RoseTree.leafDepthSumP_leaf {α : Type u_1} (p : αProp) [DecidablePred p] (a : α) :
        leafDepthSumP p (node a []) = 0
        theorem RoseTree.leafDepthsP_node_cons {α : Type u_1} (p : αProp) [DecidablePred p] (a : α) (c : RoseTree α) (cs : List (RoseTree α)) :
        leafDepthsP p (node a (c :: cs)) = (List.map (fun (t : RoseTree α) => Multiset.map (fun (x : ) => x + 1) (leafDepthsP p t)) (c :: cs)).sum

        The counted-leaf depths of a node are the children's, each one edge deeper.

        @[simp]
        theorem RoseTree.leafDepthSumP_node {α : Type u_1} (p : αProp) [DecidablePred p] (a : α) (cs : List (RoseTree α)) :
        leafDepthSumP p (node a cs) = (List.map (fun (c : RoseTree α) => leafDepthSumP p c + leafCountP p c) cs).sum

        Each child contributes its own depth-weighted count plus one per counted leaf it carries (the extra edge from the node to the child).

        theorem RoseTree.leafCountP_perm {α : Type u_1} (p : αProp) [DecidablePred p] {t s : RoseTree α} (h : t.Perm s) :

        leafCountP is a Perm-invariant.

        theorem RoseTree.leafDepthsP_perm {α : Type u_1} (p : αProp) [DecidablePred p] {t s : RoseTree α} (h : t.Perm s) :

        leafDepthsP is a Perm-invariant.

        theorem RoseTree.leafDepthSumP_perm {α : Type u_1} (p : αProp) [DecidablePred p] {t s : RoseTree α} (h : t.Perm s) :

        leafDepthSumP is a Perm-invariant.

        theorem RoseTree.sum_map_leafCountP_le_node {α : Type u_1} (p : αProp) [DecidablePred p] (a : α) (cs : List (RoseTree α)) :
        (List.map (leafCountP p) cs).sum leafCountP p (node a cs)

        The children's counted leaves are bounded by the node's.

        theorem RoseTree.leafCountP_le_numNodes {α : Type u_1} (p : αProp) [DecidablePred p] (t : RoseTree α) :

        A counted leaf is a vertex: Multiset.countP_le_card through the leaf projection.

        theorem RoseTree.leafCountP_lt_numNodes_of_not {α : Type u_1} (p : αProp) [DecidablePred p] (a : α) (cs : List (RoseTree α)) (h : ¬p a) :
        leafCountP p (node a cs) < (node a cs).numNodes

        A root failing p is an uncounted vertex, so the count is strict.

        theorem RoseTree.leafCountP_le_leafDepthSumP_of_not {α : Type u_1} (p : αProp) [DecidablePred p] (a : α) (cs : List (RoseTree α)) (h : ¬p a) :

        A root failing p puts every counted leaf at depth ≥ 1, so the depth-weighted count dominates the plain count.

        def RootedTree.Nonplanar.numEdges {α : Type u_1} (t : Nonplanar α) :

        The number of edges of a rooted tree, numNodes - 1: every vertex except the root has exactly one parent edge.

        Equations
        Instances For
          @[simp]
          theorem RootedTree.Nonplanar.numEdges_leaf {α : Type u_1} (a : α) :
          (leaf a).numEdges = 0

          Euler's relation for a rooted tree: #V = 1 + #E.

          theorem RootedTree.Nonplanar.numEdges_node {α : Type u_1} (a : α) (F : Multiset (Nonplanar α)) :
          (node a F).numEdges = (Multiset.map numNodes F).sum

          The edges of a node are the root-to-child edges plus each child's own: the total vertex count of the children.

          theorem RootedTree.Nonplanar.numEdges_node_pair {α : Type u_1} (a : α) (l r : Nonplanar α) :
          (node a {l, r}).numEdges = l.numEdges + r.numEdges + 2

          Adjoining a root above a pair of trees adds two edges.

          Leaf statistics by predicate, on the quotient #

          def RootedTree.Nonplanar.leafCountP {α : Type u_1} (p : αProp) [DecidablePred p] :
          Nonplanar α

          The number of leaves whose label satisfies p.

          Equations
          Instances For
            @[simp]
            theorem RootedTree.Nonplanar.leafCountP_mk {α : Type u_1} (p : αProp) [DecidablePred p] (t : RoseTree α) :
            @[simp]
            theorem RootedTree.Nonplanar.leafCountP_leaf {α : Type u_1} (p : αProp) [DecidablePred p] (a : α) :
            leafCountP p (leaf a) = if p a then 1 else 0
            theorem RootedTree.Nonplanar.leafCountP_node_of_not {α : Type u_1} (p : αProp) [DecidablePred p] (a : α) (F : Multiset (Nonplanar α)) (h : ¬p a) :
            leafCountP p (node a F) = (Multiset.map (leafCountP p) F).sum

            A root failing p contributes nothing: the count is the children's total.

            def RootedTree.Nonplanar.leafDepthSumP {α : Type u_1} (p : αProp) [DecidablePred p] :
            Nonplanar α

            The sum of root-distances of the leaves whose label satisfies p.

            Equations
            Instances For
              @[simp]
              theorem RootedTree.Nonplanar.leafDepthSumP_mk {α : Type u_1} (p : αProp) [DecidablePred p] (t : RoseTree α) :
              @[simp]
              theorem RootedTree.Nonplanar.leafDepthSumP_leaf {α : Type u_1} (p : αProp) [DecidablePred p] (a : α) :
              @[simp]
              theorem RootedTree.Nonplanar.leafDepthSumP_node {α : Type u_1} (p : αProp) [DecidablePred p] (a : α) (F : Multiset (Nonplanar α)) :
              leafDepthSumP p (node a F) = (Multiset.map (fun (c : Nonplanar α) => leafDepthSumP p c + leafCountP p c) F).sum

              Each child contributes its own depth-weighted count plus one per counted leaf it carries.

              theorem RootedTree.Nonplanar.leafCountP_lt_numNodes_of_not_root {α : Type u_1} (p : αProp) [DecidablePred p] (t : Nonplanar α) (h : ¬p t.rootValue) :

              A root failing p is an uncounted vertex, so the count is strict.

              theorem RootedTree.Nonplanar.leafCountP_le_leafDepthSumP_of_not_root {α : Type u_1} (p : αProp) [DecidablePred p] (t : Nonplanar α) (h : ¬p t.rootValue) :

              A root failing p puts every counted leaf at depth ≥ 1.

              theorem RootedTree.Nonplanar.leafCountP_le_numEdges {α : Type u_1} (p : αProp) [DecidablePred p] (t : Nonplanar α) (h : leafCountP p t < t.numNodes) :

              Counted leaves are among the non-root vertices whenever some vertex is uncounted.

              Forest measures #

              def RootedTree.Forest.numNodes {α : Type u_1} (F : Multiset (Nonplanar α)) :

              The total vertex count of a forest.

              Equations
              Instances For
                @[simp]
                @[simp]
                theorem RootedTree.Forest.numNodes_cons {α : Type u_1} (T : Nonplanar α) (F : Multiset (Nonplanar α)) :
                numNodes (T ::ₘ F) = T.numNodes + numNodes F
                @[simp]
                @[simp]
                theorem RootedTree.Forest.numNodes_add {α : Type u_1} (F G : Multiset (Nonplanar α)) :
                numNodes (F + G) = numNodes F + numNodes G
                def RootedTree.Forest.numEdges {α : Type u_1} (F : Multiset (Nonplanar α)) :

                The total edge count of a forest.

                Equations
                Instances For
                  @[simp]
                  @[simp]
                  theorem RootedTree.Forest.numEdges_cons {α : Type u_1} (T : Nonplanar α) (F : Multiset (Nonplanar α)) :
                  numEdges (T ::ₘ F) = T.numEdges + numEdges F
                  @[simp]
                  @[simp]
                  theorem RootedTree.Forest.numEdges_add {α : Type u_1} (F G : Multiset (Nonplanar α)) :
                  numEdges (F + G) = numEdges F + numEdges G
                  theorem RootedTree.Forest.numNodes_eq_card_add_numEdges {α : Type u_1} (F : Multiset (Nonplanar α)) :
                  numNodes F = F.card + numEdges F

                  Euler's relation for forests: #V = b₀ + #E, with Multiset.card the number of component trees.