FiniteDegreeTree #
This file defines a FiniteDegreeTree which is a PossiblyInfiniteTree where each node has only finitely many children.
The offered functions are similar to the ones of PossiblyInfiniteTree.
The tree can now only infinite in one dimensions, i.e. it can have infinite depth but
each node has only finitely many children by definition.
However, note that there is no (global) bound for the number of children.
The number of children might grow arbitrarily along the tree as long as it is finite everywhere.
A PossiblyInfiniteTree has finitely_many_children if for each subtree, the list of PossiblyInfiniteTree.childTrees is PossiblyInfiniteList.finite.
Equations
- t.finitely_many_children = ∀ (subtree : PossiblyInfiniteTree α), subtree <:+ t → subtree.childTrees.finite
Instances For
The PossiblyInfiniteTree.empty tree has finitely_many_children.
A FiniteDegreeTree is a PossiblyInfiniteTree with the finitely_many_children property.
- tree : PossiblyInfiniteTree α
- finitely_many_children : self.tree.finitely_many_children
Instances For
Basics #
The essential functions on infinite trees, mainly get, drop, and root.
The childTrees function is defined separately here as for the PossiblyInfiniteTree.
Obtains the subtree at the given address (by dropping everything else).
Instances For
Get the element at the root of the tree (i.e. at the empty address).
Instances For
Equations
- FiniteDegreeTree.instMembership = { mem := fun (t : FiniteDegreeTree α) (a : α) => a ∈ t.tree }
Two FiniteDegreeTrees are the same if they agree on all addresses.
Dropping the empty address changes nothing.
The root is equal to getting the empty address.
The root is in the tree.
The root of the dropped tree at address ns is exactly the element at address ns.
Empty Infinite Trees #
The empty FiniteDegreeTree is simply the FiniteDegreeTree that is none on all addresses. That is, its underlying PossiblyInfiniteTree is PossiblyInfiniteTree.empty.
The empty FiniteDegreeTree is essentially PossiblyInfiniteTree.empty.
Equations
- FiniteDegreeTree.empty = { tree := PossiblyInfiniteTree.empty, finitely_many_children := ⋯ }
Instances For
Child Trees #
Defining the childTrees function requires a bit of machinery.
We only want to return the child trees that are not already empty.
Then all returned trees have a non-none root, which we aim to capture directly in the return type.
The FiniteDegreeTreeWithRoot is a FiniteDegreeTree where the root is not none.
Equations
Instances For
FiniteDegreeTreeWithRoot #
For the FiniteDegreeTreeWithRoot we mainly provide some functions to convert FiniteDegreeTree to and from Option FiniteDegreeTreeWithRoot. Clearly, if a FiniteDegreeTree has a non-none root, we can convert it directly into a FiniteDegreeTreeWithRoot, otherwise, we simply convert it to none. Also in the other direction, none can just be converted to PossiblyInfiniteTree.empty and any FiniteDegreeTreeWithRoot is already a FiniteDegreeTree.
So far this is similar to PossiblyInfiniteTreeWithRoot and mainly implemented using its existing methods.
For this purpose, we also provide methods from_possibly_infinite and to_possibly_infinite that allow to convert
between FiniteDegreeTreeWithRoot and PossiblyInfiniteTreeWithRoot.
Equations
Instances For
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
The actual childTrees definition #
With FiniteDegreeTreeWithRoot in place, we can now define the actual childTrees function.
The childTrees of a FiniteDegreeTree are the List of all child trees that are not empty, i.e. it only consists of FiniteDegreeTreeWithRoot. Note that we can indeed build a finite List since we have finitely_many_children in place.
Equations
- One or more equations did not get rendered due to their size.
Instances For
FiniteDegreeTree.childTrees can be expressed through PossiblyInfiniteTree.childTrees.
Getting a child tree is the same as dropping the corresponding singleton address.
Getting a child tree is the same as dropping the corresponding singleton address.
Getting at an address in a child tree can be combined into a single get call.
The childTrees of the empty tree are exactly [].
Node Constructor #
Similar to the PossiblyInfiniteTree, we can also define a node constructor on the FiniteDegreeTree.
Construct a FiniteDegreeTree from a List of FiniteDegreeTreeWithRoot and a new root element.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Getting any address != [] on node yields the respective element from the previous FiniteDegreeTreeWithRoot.
Dropping from node with an address of the form n::ns is the same as getting the n child from the child trees used in the construction and then dropping ns there.
The childTrees of node are the childTrees used in the construction.
Any FiniteDegreeTree where the root is not none can be written using the node constructor.
ChildNodes #
It can be convenient to obtain a list of the immediate child nodes of a given tree. This is equivalent to mapping each child tree to its root.
Getting the nth childNodes is the root of the nth childTrees.
The childNodes are the roots of the childTrees.
The childNodes have the same length as the childTrees.
Getting the nth childNodes is the root of the nth childTrees.
Each child node is a tree member.
The childNodes of the empty tree are [].
Suffixes #
Here, we define a suffix relation on FiniteDegreeTree inspired by List.IsSuffix.
For t1 and t2, t1 <:+ t2 denotes that t1 is a subtree of t2.
The suffix relation is reflexive and transitive but not necesarrily antisymmetric!
Note also that InfiniteList.suffix_or_suffix_of_suffix has no equivalent statement here, i.e.
just because two trees are subtrees of the same parent tree, we cannot say anything about their relation to one another.
They might be totally "disconnected".
A suffix relation on infinite trees. This is inspired by List.IsSuffix. Read t1 <:+ t2 as: t1 is a subtree of t2.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
The suffix relation is reflexive.
The suffix relation is transitive.
A member of a subtree is also a member of the current tree.
Dropping elements yields a subtree.
Each child tree is a subtree.
Every suffix of the empty tree is empty.
We can express the PossiblyInfiniteTree.no_orphans' condition directly on FiniteDegreeTree.
Recursor for Members #
We define a recursion (induction) principle for members (Elements) of an FiniteDegreeTree called mem_rec.
This can be used with the induction tactic to prove a property for each Element of an FiniteDegreeTree.
Note that for using this coveniently, the goal needs to expressed (rewritten) using an Element.
A recursor for proving properties about tree members (Elements) via induction.
Branches #
Branches are essentially PossiblyInfiniteLists in a FiniteDegreeTree
and can be characterizes by an infinite "address", i.e. InfiniteList Nat.
Here, we merely define them as the branches of the underlying PossiblyInfiniteTree.
The branches in the FiniteDegreeTree are exactly the branches in the underlying PossiblyInfiniteTree.
Instances For
The set of branches can equivalently be expressed as the set of all PossiblyInfiniteLists where the head equals the root of the tree and the tail occurs in the branches of some childTree. If there are no childTrees, then the tail needs to be empty.
Branch Generation #
We can use PossiblyInfiniteList.generate to construct branches in a FiniteDegreeTree.
Here, we just proxy the existing function PossiblyInfiniteTree.generate_branch.
First of all, this requires that the mapper function produces a FiniteDegreeTreeWithRoot.
Intuitively, using all the roots of these trees gives us a branch.
But this is only true if the generate trees are always child trees of each other and the generation indeed creates a maximal branch, meaning that once the generation stops, there would indeed by no childTrees to continue.
This condition is used in the generate_branch_mem_branches theorem to proof that a PossiblyInfiniteList
from the generate_branch function is indeed in branches.
Given a generator and a mapper that maps generated elements to FiniteDegreeTreeWithRoot, construct an PossiblyInfiniteList with the goal of constructing a branch in a tree.
Equations
- FiniteDegreeTree.generate_branch start generator mapper = PossiblyInfiniteTree.generate_branch start generator fun (b : β) => (mapper b).to_possibly_infinite
Instances For
If the generated trees are childTrees of each other and the generated branch is maximal, i.e. the generation only stops if there are no childTrees available anymore, then the generated PossiblyInfiniteList is indeed a branch.
The PossiblyInfiniteList.head of generate_branch is the root of the first tree.
Getting the nth element from a generate_branch result is the root of the nth generated tree.
The PossiblyInfiniteList.tail of generate_branch is the branch generated when applying the generator function once on the starting element before the actual generation.
Leaves #
The leaves of a FiniteDegreeTree is the set of elements that occur in a node that has no childNodes.
The function is simply defined via PossiblyInfiniteTree.leaves for the underlying tree.
Instances For
Constructing a Tree from a Branch #
A PossiblyInfiniteList directly corresponds to the FiniteDegreeTree
where the list is the "first" branch (with the address that only consists of zeros) and all other nodes are none.
Equations
- FiniteDegreeTree.from_branch b = { tree := PossiblyInfiniteTree.from_branch b, finitely_many_children := ⋯ }