General Trees with Arbitrary Arities #
This file defines general tree data structures where nodes can have an arbitrary number of children (represented as lists).
We provide two main variants:
GeneralTree
: Trees where every node (including internal nodes) holds a valueGeneralLeafTree
: Trees where only leaf nodes hold values, internal nodes are structural
Both support arbitrary arities and include helper functions for common operations like finding paths, checking properties, and accessing structure information.
A general tree with arbitrary arity where every node (including internal nodes) holds a value. The children are represented as a list, allowing for any number of child nodes.
- leaf {α : Type u_1} : α → GeneralTree α
- node {α : Type u_1} : α → List (GeneralTree α) → GeneralTree α
- nil {α : Type u_1} : GeneralTree α
Instances For
Equations
- instInhabitedGeneralTree = { default := GeneralTree.nil }
Equations
- instReprGeneralTree = { reprPrec := reprGeneralTree✝ }
A general tree with arbitrary arity where only leaf nodes hold values. Internal nodes are purely structural and do not store values. Used as input to general Merkle tree construction.
- leaf {α : Type u_1} : α → GeneralLeafTree α
- node {α : Type u_1} : List (GeneralLeafTree α) → GeneralLeafTree α
- nil {α : Type u_1} : GeneralLeafTree α
Instances For
Equations
- instInhabitedGeneralLeafTree = { default := GeneralLeafTree.node default }
Equations
- instReprGeneralLeafTree = { reprPrec := reprGeneralLeafTree✝ }
Get the root value of a general tree, if it exists.
Equations
- GeneralTree.nil.getRoot = none
- (GeneralTree.leaf a).getRoot = some a
- (GeneralTree.node a a_1).getRoot = some a
Instances For
Get the number of children of a node.
Equations
- GeneralTree.nil.arity = 0
- (GeneralTree.leaf a).arity = 0
- (GeneralTree.node a a_1).arity = a_1.length
Instances For
Get the children of a node.
Equations
- GeneralTree.nil.children = []
- (GeneralTree.leaf a).children = []
- (GeneralTree.node a a_1).children = a_1
Instances For
Check if the tree is a leaf.
Instances For
Check if the tree is empty.
Instances For
Find the path from root to a leaf with the given value. The path is represented as a list of child indices.
Equations
- GeneralTree.findPath a GeneralTree.nil = none
- GeneralTree.findPath a (GeneralTree.leaf a_1) = if a = a_1 then some [] else none
- GeneralTree.findPath a (GeneralTree.node a_1 a_2) = GeneralTree.findPath.findPathInChildren a a_2 0
Instances For
Equations
- One or more equations did not get rendered due to their size.
- GeneralTree.findPath.findPathInChildren a [] idx = none
Instances For
Get the number of children of a node.
Equations
- GeneralLeafTree.nil.arity = 0
- (GeneralLeafTree.leaf a).arity = 0
- (GeneralLeafTree.node children).arity = children.length
Instances For
Get the children of a node.
Equations
- GeneralLeafTree.nil.children = []
- (GeneralLeafTree.leaf a).children = []
- (GeneralLeafTree.node children).children = children
Instances For
Check if the tree is a leaf.
Instances For
Check if the tree is empty.
Instances For
Find the path from root to a leaf with the given value. The path is represented as a list of child indices.
Equations
- GeneralLeafTree.findPath a GeneralLeafTree.nil = none
- GeneralLeafTree.findPath a (GeneralLeafTree.leaf a_1) = if a = a_1 then some [] else none
- GeneralLeafTree.findPath a (GeneralLeafTree.node children) = GeneralLeafTree.findPath.findPathInChildren a children 0
Instances For
Equations
- One or more equations did not get rendered due to their size.
- GeneralLeafTree.findPath.findPathInChildren a [] idx = none
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.