Documentation

BGW.Tree

Finite plane trees #

A plane tree is a finite rooted tree whose children are ordered. We use Mathlib's WType, with Fin n indexing the children of a vertex of outdegree n. PlaneTree.node and PlaneTree.children provide the list interface. The induction and cases tactics produce a single node ts case, and PlaneTree.fold defines functions by bottom-up recursion, so the WType encoding is not used outside this file.

Addresses are zero-based lists of child indices; the root has address []. These are implementation coordinates, independent of the paper's one-based numbering of vertices in depth-first order. Size counts vertices, including the root.

Finite rooted ordered trees, with no vertex labels.

Equations
Instances For
    @[reducible, inline]

    Finite ordered forests. The empty forest is allowed.

    Equations
    Instances For

      A tree is determined by the ordered list of subtrees attached to its root.

      Equations
      Instances For

        Attach an ordered list of trees to a new root.

        Equations
        Instances For

          The ordered subtrees attached to the root.

          Equations
          Instances For
            theorem BGW.PlaneTree.ext {s t : PlaneTree} (h : s.children = t.children) :
            s = t

            Two plane trees are equal when their ordered lists of root subtrees agree.

            @[simp]
            theorem BGW.PlaneTree.node_inj {ts ss : List PlaneTree} :
            node ts = node ss ↔ ts = ss
            theorem BGW.PlaneTree.induction_on {motive : PlaneTree → Prop} (t : PlaneTree) (node : ∀ (ts : List PlaneTree), (∀ s ∈ ts, motive s) → motive (node ts)) :
            motive t

            Induction over all the children of a root. This is the default induction principle.

            def BGW.PlaneTree.casesOn {motive : PlaneTree → Sort u_1} (t : PlaneTree) (node : (ts : List PlaneTree) → motive (node ts)) :
            motive t

            Case analysis on the children of the root. This is the default cases principle.

            Equations
            Instances For
              @[simp]
              theorem BGW.PlaneTree.casesOn_node {motive : PlaneTree → Sort u_1} (ts : List PlaneTree) (node : (ts : List PlaneTree) → motive (node ts)) :
              casesOn (PlaneTree.node ts) node = node ts
              def BGW.PlaneTree.fold {β : Type u_1} (g : List β → β) :
              PlaneTree → β

              Bottom-up recursion: fold g applies g to the values already computed at the children of the root, in child order.

              Equations
              Instances For
                @[simp]
                theorem BGW.PlaneTree.fold_node {β : Type u_1} (g : List β → β) (ts : List PlaneTree) :
                fold g (node ts) = g (List.map (fold g) ts)

                The tree consisting only of its root.

                Equations
                Instances For

                  The number of children of the root.

                  Equations
                  Instances For

                    The number of vertices, including the root.

                    Equations
                    Instances For
                      @[simp]

                      Lookup of a fringe subtree. none means that the address is not a vertex. The returned tree is re-rooted: its addresses start at [] again.

                      Equations
                      Instances For

                        An address belongs to the tree exactly when fringe lookup succeeds.

                        Equations
                        Instances For

                          A leaf is a vertex whose fringe subtree consists only of its root.

                          Equations
                          Instances For
                            @[simp]
                            theorem BGW.PlaneTree.fringe?_cons (t : PlaneTree) (i : ℕ) (u : List ℕ) :
                            t.fringe? (i :: u) = t.children[i]?.bind fun (s : PlaneTree) => s.fringe? u
                            theorem BGW.PlaneTree.fringe?_node_cons (ts : List PlaneTree) (i : ℕ) (u : List ℕ) :
                            (node ts).fringe? (i :: u) = ts[i]?.bind fun (s : PlaneTree) => s.fringe? u