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 CustomBasicDatastructures.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 CustomBasicDatastructures.FiniteTree.rec' {α : Type u} {β : Type v} {motive : FiniteTree α β → Sort w} (leaf : (l : β) → motive (leaf l)) (inner : (label : α) → (ts : List (FiniteTree α β)) → ((t : FiniteTree α β) → t ∈ ts → motive 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
      Equations
      Instances For
        @[irreducible]

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

        Equations
        Instances For
          @[irreducible]

          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]

            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 CustomBasicDatastructures.FiniteTree.mapLeaves {α : Type u} {β : Type v} {γ : Type v'} (f : β → FiniteTree α γ) :
              FiniteTree α β → FiniteTree α γ

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

              Equations
              Instances For
                theorem CustomBasicDatastructures.FiniteTree.mapLeaves_eq_of_map_leaves_eq {α : Type u} {β : Type v} {γ : Type v'} {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.

                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
                  theorem CustomBasicDatastructures.FiniteTree.tree_eq_while_contained_is_impossible {α : Type u} {β : Type v} [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.