Documentation

BasicLeanDatastructures.FiniteTree

Finite Trees #

This file defines finite trees as a nested inductive type FiniteTree. The tree can have different types for the contents of its leafs and inner nodes.

inductive FiniteTree (α : Type u) (β : Type v) :
Type (max u v)

An InductiveTree is either a leaf or a node that features a list of children that are again trees.

Instances For
    @[irreducible]
    def FiniteTree.rec' {α : Type u_1} {β : Type u_2} {motive : FiniteTree α βSort u} (leaf : (l : β) → motive (leaf l)) (inner : (label : α) → (ts : List (FiniteTree α β)) → ((t : FiniteTree α β) → t tsmotive t)motive (inner label ts)) (t : FiniteTree α β) :
    motive t

    A simplified recursor for proving properties of finite trees via induction. (The default recursor generated for the nested inductive type was not very useful for me.)

    Equations
    Instances For
      def finiteTreeEq {α : Type u_1} {β : Type u_2} [DecidableEq α] [DecidableEq β] (a b : FiniteTree α β) :
      Decidable (a = b)
      Equations
      Instances For
        def finiteTreeListEq {α : Type u_1} {β : Type u_2} [DecidableEq α] [DecidableEq β] (a b : List (FiniteTree α β)) :
        Decidable (a = b)
        Equations
        Instances For
          @[irreducible]
          def FiniteTree.depth {α : Type u_1} {β : Type u_2} :
          FiniteTree α βNat

          Returns the depth of the tree where a leaf is defined to have depth 1.

          Equations
          Instances For
            @[irreducible]
            def FiniteTree.leaves {α : Type u_1} {β : Type u_2} :
            FiniteTree α βList β

            Returns all leaf nodes of the tree as a single list. (Intuitively you simply read all leaves from left to right).

            Equations
            Instances For
              @[irreducible]
              def FiniteTree.innerLabels {α : Type u_1} {β : Type u_2} :
              FiniteTree α βList α

              Returns all nodes that are not leaves as a single list. You can imagine going branch by branch from left to right while avoiding using the same node twice.

              Equations
              Instances For
                @[irreducible]
                def FiniteTree.mapLeaves {β : Type u_1} {α : Type u_2} {γ : Type u_3} (f : βFiniteTree α γ) :
                FiniteTree α βFiniteTree α γ

                Returns the tree there we leaf nodes have been replaced according to the function f.

                Equations
                Instances For
                  theorem FiniteTree.mapLeaves_eq_of_map_leaves_eq {β : Type u_1} {α : Type u_2} {γ : Type u_3} {f g : βFiniteTree α γ} {t : FiniteTree α β} :

                  The trees resulting from two different leaf mappings are the same of applying the functions only on the list of leaves yields the same list.

                  def FiniteTree.nodeLabel {α : Type u_1} :
                  FiniteTree α αα

                  Returns the root label of a given tree. This only works if the types for leaf and inner nodes are the same.

                  Equations
                  Instances For
                    def FiniteTree.forEach {α : Type u_1} {β : Type u_2} (f : FiniteTree α βProp) :
                    FiniteTree α βProp

                    Check that f holds for each subtree of a given tree.

                    Equations
                    Instances For
                      def FiniteTree.treesInDepth {α : Type u_1} {β : Type u_2} (t : FiniteTree α β) (depth : Nat) :

                      For a given depth, returns all subtrees of the given tree t that have their root at this depth in t.

                      Equations
                      Instances For
                        theorem FiniteTree.tree_eq_while_contained_is_impossible {α : Type u_1} {β : Type u_2} [DecidableEq α] [DecidableEq β] (t : FiniteTree α β) (ts : List (FiniteTree α β)) (a : α) (h_eq : inner a ts = t) (h_contains : t ts) :

                        A tree cannot occur as its own child.