InfiniteTreeSkeleton #
This file defines an InfiniteTreeSkeleton as a function from the a list of naturals into the desired type.
Note that this is very similar to an InfiniteList only replacing Nat for List Nat.
In this way, the InfiniteTreeSkeleton is infinite in both dimensions, i.e.
it has infinite depth and each node has infinitely many (direct) children.
Similar to InfiniteList, we offer many convenience functions, some of which have different names.
For example, the equivalent to InfiniteList.head would be root
and the equivalent to InfiniteList.tail would be childTrees.
The functions get and drop behave analogously to their InfiniteList counterparts.
As for the InfiniteList, we also implement a mem_rec recursor that allows showing properties of tree members via induction.
We also allow generating branches of a tree using the generate_branch function, which yields an InfiniteList.
The convenience of this function lies in the theorem generate_branch_mem_branches that immediately allows us to verify
that the generated InfiniteList is indeed a branch in the InfiniteTreeSkeleton.
An InfiniteTreeSkeleton is a function from a list of naturals (representing an address in the tree) into the desired type.
Equations
- InfiniteTreeSkeleton α = (List Nat → α)
Instances For
Basics #
The essential functions on infinite trees, mainly get, drop, root, and childTrees.
Obtains the element of the tree at the given address.
Instances For
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
Get the InfiniteList of immediate child trees of the current tree.
Equations
- t.childTrees n ns = t.get (n :: ns)
Instances For
Construct an InfiniteTreeSkeleton from an InfiniteList of InfiniteTreeSkeletons and a new root element.
Equations
- InfiniteTreeSkeleton.node root childTrees [] = root
- InfiniteTreeSkeleton.node root childTrees (hd :: tl) = childTrees hd tl
Instances For
Two InfiniteTreeSkeletons are the same if they agree on all addresses.
Each element we can get is in the tree.
Dropping the empty address changes nothing.
The root is in the tree.
The root of the dropped tree at address ns is exactly the element at address ns.
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.
Getting the element at address [] on node is the new root.
Getting any address != [] on node yields the respective element from the previous InfiniteTreeSkeleton.
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 InfiniteTreeSkeleton 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 and actually just defined via mapping each child tree to its root.
When getting the nth child node, we can instead get the tree element at the singleton address [n].
Each child node is a tree member.
Suffixes #
Here, we define a suffix relation on InfiniteTreeSkeleton 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".
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.
Recursor for Members #
We define a recursion (induction) principle for members (Elements) of an InfiniteTreeSkeleton called mem_rec.
This can be used with the induction tactic to prove a property for each Element of an InfiniteTreeSkeleton.
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 InfiniteLists in an InfiniteTreeSkeleton
and can be characterizes by an infinite "address", i.e. InfiniteList Nat.
This function defines the InfiniteList of tree elements that corresponds to a given infinite address.
Equations
- t.branchForAddress ns n = t.get (ns.take n)
Instances For
The branches in the InfiniteTreeSkeleton are exactly the InfiniteLists for which an infinite address exists.
Instances For
Getting from the branch corresponding to an infinite address corresponds to getting from the tree at the corresponding finite part of the address. This essentially unfold the definition of branchForAddress.
The InfiniteList.head of branchForAddress is the tree's root.
The InfiniteList.tail of branchForAddress corresponds to a branch in a child tree.
The branchForAddress for an InfiniteList.cons address can be decomposed accordingly.
The branches of a tree constructed through node are exactly the ones who's head is the root from the construction and who's tail occurs in the branches of one of the child trees.
Branch Generation #
We can use InfiniteList.generate to construct branches in a InfiniteTreeSkeleton.
First of all, this requires that the mapper function produces an InfiniteTreeSkeleton.
By that InfiniteList.generate gives us an InfiniteList of InfiniteTreeSkeletons.
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.
This condition is used in the generate_branch_mem_branches theorem to proof that an InfiniteList
from the generate_branch function is indeed in branches.
Given a generator and a mapper that maps generated elements to InfiniteTreeSkeletons, construct an InfiniteList with the goal of constructing a branch in a tree.
Equations
- InfiniteTreeSkeleton.generate_branch start generator mapper = (InfiniteList.generate start generator mapper).map InfiniteTreeSkeleton.root
Instances For
If the generated trees are childTrees of each other, then the generated InfiniteList is indeed a branch.
The InfiniteList.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 InfiniteList.tail of generate_branch is the branch generated when applying the generator function once on the starting element before the actual generation.