Binary tree #
Provides binary tree storage for values of any type, with O(lg n) retrieval.
See also Lean.Data.RBTree for red-black trees - this version allows more operations
to be defined and is better suited for in-kernel computation.
We also specialize for BinaryTree Unit, which is a binary tree without any
additional data. We provide the notation a △ b for making a BinaryTree Unit with children
a and b.
References #
https://leanprover-community.github.io/archive/stream/113488-general/topic/tactic.20question.html
A binary tree with values stored in non-leaf nodes.
- nil {α : Type u} : BinaryTree α
- node {α : Type u} (value : α) (left right : BinaryTree α) : BinaryTree α
Instances For
Equations
- One or more equations did not get rendered due to their size.
- instDecidableEqBinaryTree.decEq BinaryTree.nil BinaryTree.nil = isTrue ⋯
- instDecidableEqBinaryTree.decEq BinaryTree.nil (BinaryTree.node value left right) = isFalse ⋯
- instDecidableEqBinaryTree.decEq (BinaryTree.node value left right) BinaryTree.nil = isFalse ⋯
Instances For
Equations
- instReprBinaryTree = { reprPrec := instReprBinaryTree.repr }
Equations
- One or more equations did not get rendered due to their size.
- instReprBinaryTree.repr BinaryTree.nil prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "BinaryTree.nil")).group prec✝
Instances For
Alias of BinaryTree.
A binary tree with values stored in non-leaf nodes.
Equations
Instances For
Alias of BinaryTree.nil.
Equations
Instances For
Alias of BinaryTree.node.
Equations
- Tree.node value left right = BinaryTree.node value left right
Instances For
Equations
- BinaryTree.instInhabited = { default := BinaryTree.nil }
Do an action for every node of the tree.
Actions are taken in node -> left subtree -> right subtree recursive order.
This function is the traverse function for the Traversable BinaryTree instance.
Equations
- BinaryTree.traverse f BinaryTree.nil = pure BinaryTree.nil
- BinaryTree.traverse f (BinaryTree.node a l r) = BinaryTree.node <$> f a <*> BinaryTree.traverse f l <*> BinaryTree.traverse f r
Instances For
Alias of BinaryTree.traverse.
Equations
- Tree.traverse f t = BinaryTree.traverse f t
Instances For
Apply a function to each value in the BinaryTree.
This is the map function for the BinaryTree functor.
Equations
- BinaryTree.map f BinaryTree.nil = BinaryTree.nil
- BinaryTree.map f (BinaryTree.node a l r) = BinaryTree.node (f a) (BinaryTree.map f l) (BinaryTree.map f r)
Instances For
Alias of BinaryTree.map.
Equations
- Tree.map f t = BinaryTree.map f t
Instances For
The number of internal nodes (i.e. not including leaves) of a binary tree
Equations
- BinaryTree.nil.numNodes = 0
- (BinaryTree.node a l r).numNodes = l.numNodes + r.numNodes + 1
Instances For
Alias of BinaryTree.numNodes.
Equations
Instances For
The number of leaves of a binary tree
Equations
- BinaryTree.nil.numLeaves = 1
- (BinaryTree.node a l r).numLeaves = l.numLeaves + r.numLeaves
Instances For
Alias of BinaryTree.numLeaves.
Equations
Instances For
The height - length of the longest path from the root - of a binary tree
Equations
- BinaryTree.nil.height = 0
- (BinaryTree.node a l r).height = max l.height r.height + 1
Instances For
Alias of BinaryTree.height.
Equations
- t.height = BinaryTree.height t
Instances For
The left child of the tree, or nil if the tree is nil
Equations
- BinaryTree.nil.left = BinaryTree.nil
- (BinaryTree.node a l r).left = l
Instances For
Alias of BinaryTree.left.
Equations
- t.left = BinaryTree.left t
Instances For
The right child of the tree, or nil if the tree is nil
Equations
- BinaryTree.nil.right = BinaryTree.nil
- (BinaryTree.node a l r).right = r
Instances For
Alias of BinaryTree.right.
Equations
- t.right = BinaryTree.right t
Instances For
A node with Unit data
Equations
- BinaryTree.«term_△_» = Lean.ParserDescr.trailingNode `BinaryTree.«term_△_» 65 66 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " △ ") (Lean.ParserDescr.cat `term 65))
Instances For
Induction principle for BinaryTree Units
Equations
- BinaryTree.unitRecOn t base ind = BinaryTree.recOn t base fun (_u : Unit) => ind
Instances For
Alias of BinaryTree.unitRecOn.
Equations
- Tree.unitRecOn t base ind = BinaryTree.unitRecOn t base ind