Fibonacci heap
InductiveFibonacci tree#✓fully proved
A Fibonacci tree over a type \(\alpha\) is a rose tree: a node carrying a stored degree \(d \in \mathbb{N}\), a root value in \(\alpha\), and a finite list of child Fibonacci trees.
Heap order and the equality of the stored degree with the number of children are not part of the type; they are imposed by the validity predicate on trees.
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
Used by 83
DefinitionDegree of a Fibonacci tree#✓fully proved
The degree of the Fibonacci tree with stored degree \(d\), root value \(r\) and list of children \(c\) is the stored natural number \(d\); it is not computed from the children.
@[expose] public def degree : FibonacciTree α → Nat
| .node degree _ _ => degree
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 1 · Used by 13
DefinitionRoot of a Fibonacci tree#✓fully proved
The root of a Fibonacci tree is the value stored at its top node.
@[expose] public def root : FibonacciTree α → α
| .node _ root _ => root
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 1 · Used by 32
DefinitionChildren of a Fibonacci tree#✓fully proved
The children of the Fibonacci tree with stored degree \(d\), root value \(r\) and list of subtrees \(c\) are the trees of the list \(c\), in order.
@[expose] public def children : FibonacciTree α → List (FibonacciTree α)
| .node _ _ children => children
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 1 · Used by 17
DefinitionMultiset of a Fibonacci tree#✓fully proved
The multiset \(M(t)\) of values stored in a Fibonacci tree \(t\), defined recursively: if \(t\) has root value \(r\) and children \(t_1, \dots, t_k\), then \(M(t) = \{r\} + M(t_1) + \cdots + M(t_k)\). The stored degree plays no role.
@[expose] public def elements : FibonacciTree α → Multiset α
| .node _ root children => root ::ₘ (children.map elements).sum
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 1 · Used by 38
TheoremThe root of a Fibonacci tree is one of its elements#✓fully proved
For every Fibonacci tree, its root value belongs to the multiset of elements the tree represents.
public theorem root_mem_elements (tree : FibonacciTree α) : tree.root ∈ tree.elements
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 3 · Used by 7
TheoremFibonacci trees are nonempty#✓fully proved
Every Fibonacci tree represents at least one element: the multiset of elements of any Fibonacci tree has positive size.
public theorem card_elements_pos (tree : FibonacciTree α) : 0 < tree.elements.card
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 2 · Used by 1
InductiveValid Fibonacci trees#✓fully proved
Let \(\alpha\) carry a relation \(\le\). A Fibonacci tree with stored degree \(d\), root \(r \in \alpha\) and list of children \(c\) is valid when every tree in \(c\) is valid, \(d\) equals the length of \(c\), and \(r \le x\) for every element \(x\) of the multiset represented by the tree (the root together with the elements of all children).
public inductive Valid {α : Type u} [LE α] : FibonacciTree α → Prop
| node {degree : Nat} {root : α} {children : List (FibonacciTree α)}
(children_valid : ∀ child ∈ children, Valid child)
(degree_eq : degree = children.length)
(root_le : ∀ value ∈ elements (.node degree root children), root ≤ value) :
Valid (.node degree root children)
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def elements : FibonacciTree α → Multiset α
| .node _ root children => root ::ₘ (children.map elements).sum
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:65
Uses 2 · Used by 27
DefinitionOne-element Fibonacci heap#✓fully proved
For a value \(x\) of a linearly ordered type, the one-element Fibonacci heap on \(x\) has as its only tree the single-node tree with root \(x\), and its cached minimum is \(x\).
@[expose] public def singleton (value : α) : FibonacciTree α :=
.node 0 value []
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 1 · Used by 4
DefinitionLinking two Fibonacci trees#✓fully proved
Let \(s\) and \(t\) be Fibonacci trees over a linearly ordered type. If the root of \(s\) is at most the root of \(t\), the link of \(s\) and \(t\) is the tree with the root of \(s\), stored degree one more than that of \(s\), and children \(t\) followed by the children of \(s\). Otherwise it is the tree with the root of \(t\), stored degree one more than that of \(t\), and children \(s\) followed by the children of \(t\).
@[expose] public def link [LinearOrder α] (left right : FibonacciTree α) : FibonacciTree α :=
if left.root ≤ right.root then
.node (left.degree + 1) left.root (right :: left.children)
else
.node (right.degree + 1) right.root (left :: right.children)
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 4 · Used by 7
TheoremDegree of the link of two trees of equal degree#✓fully proved
If two Fibonacci trees \(s\) and \(t\) over a linearly ordered type have the same degree \(d\), then their link has degree \(d + 1\).
public theorem degree_link_of_eq [LinearOrder α] {left right : FibonacciTree α}
(degrees : left.degree = right.degree) :
(link left right).degree = left.degree + 1
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def link [LinearOrder α] (left right : FibonacciTree α) : FibonacciTree α :=
if left.root ≤ right.root then
.node (left.degree + 1) left.root (right :: left.children)
else
.node (right.degree + 1) right.root (left :: right.children)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:93
Uses 5 · Used by 1
TheoremLinking adds the elements#✓fully proved
For any two Fibonacci trees \(S\) and \(T\) over a linearly ordered type, the tree obtained by linking \(S\) and \(T\) represents the sum of the multisets represented by \(S\) and by \(T\).
public theorem elements_link [LinearOrder α] (left right : FibonacciTree α) :
(link left right).elements = left.elements + right.elements
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def link [LinearOrder α] (left right : FibonacciTree α) : FibonacciTree α :=
if left.root ≤ right.root then
.node (left.degree + 1) left.root (right :: left.children)
else
.node (right.degree + 1) right.root (left :: right.children)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:93
Uses 6 · Used by 2
TheoremSingleton Fibonacci trees are valid#✓fully proved
Let \(\alpha\) be a linearly ordered type. For every \(v \in \alpha\), the Fibonacci tree of degree \(0\) with root \(v\) and no children is valid.
public theorem valid_singleton [LinearOrder α] (value : α) : Valid (singleton value)
public inductive Valid {α : Type u} [LE α] : FibonacciTree α → Prop
| node {degree : Nat} {root : α} {children : List (FibonacciTree α)}
(children_valid : ∀ child ∈ children, Valid child)
(degree_eq : degree = children.length)
(root_le : ∀ value ∈ elements (.node degree root children), root ≤ value) :
Valid (.node degree root children)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:80
@[expose] public def singleton (value : α) : FibonacciTree α :=
.node 0 value []
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:88
Uses 4 · Used by 1
TheoremChildren of a valid Fibonacci tree are valid#✓fully proved
Every child of a valid Fibonacci tree is itself a valid Fibonacci tree.
public theorem Valid.child_valid [LE α] {tree child : FibonacciTree α}
(valid : Valid tree) (member : child ∈ tree.children) : Valid child
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
public inductive Valid {α : Type u} [LE α] : FibonacciTree α → Prop
| node {degree : Nat} {root : α} {children : List (FibonacciTree α)}
(children_valid : ∀ child ∈ children, Valid child)
(degree_eq : degree = children.length)
(root_le : ∀ value ∈ elements (.node degree root children), root ≤ value) :
Valid (.node degree root children)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:80
Uses 4 · Used by 11
TheoremThe degree of a valid Fibonacci tree is its number of children#✓fully proved
For every valid Fibonacci tree, its stored degree equals the number of its children.
public theorem Valid.degree_eq [LE α] {tree : FibonacciTree α} (valid : Valid tree) :
tree.degree = tree.children.length
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
public inductive Valid {α : Type u} [LE α] : FibonacciTree α → Prop
| node {degree : Nat} {root : α} {children : List (FibonacciTree α)}
(children_valid : ∀ child ∈ children, Valid child)
(degree_eq : degree = children.length)
(root_le : ∀ value ∈ elements (.node degree root children), root ≤ value) :
Valid (.node degree root children)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:80
Uses 5 · Used by 3
TheoremRoots of valid Fibonacci trees are lower bounds#✓fully proved
The root of a valid Fibonacci tree is no greater than every element of the multiset the tree represents.
public theorem Valid.root_le [LE α] {tree : FibonacciTree α} (valid : Valid tree)
{value : α} (member : value ∈ tree.elements) : tree.root ≤ value
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
public inductive Valid {α : Type u} [LE α] : FibonacciTree α → Prop
| node {degree : Nat} {root : α} {children : List (FibonacciTree α)}
(children_valid : ∀ child ∈ children, Valid child)
(degree_eq : degree = children.length)
(root_le : ∀ value ∈ elements (.node degree root children), root ≤ value) :
Valid (.node degree root children)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:80
Uses 4 · Used by 5
TheoremThe degree of a valid Fibonacci tree is less than its size#✓fully proved
For every valid Fibonacci tree over a type with a relation \(\le\), the degree of the tree is strictly less than the number of elements, counted with multiplicity, of the multiset the tree represents, since every child contributes at least one element.
public theorem Valid.degree_lt_card [LE α] {tree : FibonacciTree α} (valid : Valid tree) :
tree.degree < tree.elements.card
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
public inductive Valid {α : Type u} [LE α] : FibonacciTree α → Prop
| node {degree : Nat} {root : α} {children : List (FibonacciTree α)}
(children_valid : ∀ child ∈ children, Valid child)
(degree_eq : degree = children.length)
(root_le : ∀ value ∈ elements (.node degree root children), root ≤ value) :
Valid (.node degree root children)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:80
Uses 7 · Used by 1
TheoremLinking preserves validity of Fibonacci trees#✓fully proved
If \(s\) and \(t\) are valid Fibonacci trees over a linearly ordered type, then the link of \(s\) and \(t\) is a valid Fibonacci tree.
public theorem Valid.link [LinearOrder α] {left right : FibonacciTree α}
(left_valid : Valid left) (right_valid : Valid right) : Valid (link left right)
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
public inductive Valid {α : Type u} [LE α] : FibonacciTree α → Prop
| node {degree : Nat} {root : α} {children : List (FibonacciTree α)}
(children_valid : ∀ child ∈ children, Valid child)
(degree_eq : degree = children.length)
(root_le : ∀ value ∈ elements (.node degree root children), root ≤ value) :
Valid (.node degree root children)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:80
@[expose] public def link [LinearOrder α] (left right : FibonacciTree α) : FibonacciTree α :=
if left.root ≤ right.root then
.node (left.degree + 1) left.root (right :: left.children)
else
.node (right.degree + 1) right.root (left :: right.children)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:93
Uses 11 · Used by 1
DefinitionValid Fibonacci forests#✓fully proved
Let \(\alpha\) carry a relation \(\le\). A Fibonacci forest, a list of Fibonacci trees with values in \(\alpha\), is valid when every tree in it is a valid Fibonacci tree.
Root degrees may repeat; consolidation is what makes them distinct.
@[expose] public def FibonacciForest.Valid {α : Type u} [LE α]
(trees : List (FibonacciTree α)) : Prop :=
∀ tree ∈ trees, tree.Valid
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 2 · Used by 24
DefinitionMultiset of a Fibonacci forest#✓fully proved
Write \(M(t)\) for the multiset of values stored in a Fibonacci tree \(t\). The multiset represented by a Fibonacci forest, a list of Fibonacci trees \(t_1, \dots, t_k\), is the sum \(M(t_1) + \cdots + M(t_k)\); the empty forest represents the empty multiset.
@[expose] public def elements (trees : List (FibonacciTree α)) : Multiset α :=
(trees.map FibonacciTree.elements).sum
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def elements : FibonacciTree α → Multiset α
| .node _ root children => root ::ₘ (children.map elements).sum
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:65
Uses 2 · Used by 21
DefinitionForests with strictly increasing degrees#✓fully proved
A Fibonacci forest, a list of Fibonacci trees \(t_1, \dots, t_k\), has sorted degrees when the stored degrees of its trees strictly increase along the list: \(\deg t_i < \deg t_j\) whenever \(i < j\).
@[expose] public def SortedDegrees (trees : List (FibonacciTree α)) : Prop :=
trees.Pairwise fun a b => a.degree < b.degree
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
TheoremThe empty Fibonacci forest is valid#✓fully proved
Let \(\alpha\) carry a relation \(\le\). The empty forest, containing no Fibonacci trees with values in \(\alpha\), is valid.
public theorem valid_nil [LE α] : Valid ([] : List (FibonacciTree α))
@[expose] public def FibonacciForest.Valid {α : Type u} [LE α]
(trees : List (FibonacciTree α)) : Prop :=
∀ tree ∈ trees, tree.Valid
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:228
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 3 · Used by 1
TheoremConcatenation preserves validity of Fibonacci forests#✓fully proved
Let \(\alpha\) carry a relation \(\le\). If \(F\) and \(G\) are valid Fibonacci forests with values in \(\alpha\), then the forest consisting of the trees of \(F\) followed by the trees of \(G\) is valid.
public theorem valid_append [LE α] {left right : List (FibonacciTree α)}
(left_valid : Valid left) (right_valid : Valid right) : Valid (left ++ right)
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def FibonacciForest.Valid {α : Type u} [LE α]
(trees : List (FibonacciTree α)) : Prop :=
∀ tree ∈ trees, tree.Valid
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:228
Uses 3 · Used by 8
TheoremSublists of valid Fibonacci forests are valid#✓fully proved
If a list of Fibonacci trees is a valid forest, then every sublist of it (a subsequence, not necessarily contiguous) is a valid forest.
public theorem Valid.sublist [LE α] {left right : List (FibonacciTree α)}
(sublist : left.Sublist right) (valid : Valid right) : Valid left
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def FibonacciForest.Valid {α : Type u} [LE α]
(trees : List (FibonacciTree α)) : Prop :=
∀ tree ∈ trees, tree.Valid
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:228
Uses 2 · Used by 7
TheoremElements of a concatenated forest#✓fully proved
For any two lists \(L\) and \(R\) of Fibonacci trees, the forest made of the trees of \(L\) followed by the trees of \(R\) represents the sum of the multisets represented by \(L\) and by \(R\).
public theorem elements_append (left right : List (FibonacciTree α)) :
elements (left ++ right) = elements left + elements right
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def elements (trees : List (FibonacciTree α)) : Multiset α :=
(trees.map FibonacciTree.elements).sum
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:237
Uses 3 · Used by 3
DefinitionMinimum root of a forest#✓fully proved
The minimum root of a forest of Fibonacci trees over a linearly ordered type is an optional value: it is absent for the empty forest, and for a nonempty forest it is the least of the roots of its trees.
@[expose] public def minRoot [LinearOrder α] : List (FibonacciTree α) → Option α
| [] => none
| tree :: trees =>
match minRoot trees with
| none => some tree.root
| some minimum => some (min tree.root minimum)
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 2 · Used by 21
DefinitionMinimum of two optional values#✓fully proved
For optional values \(x\) and \(y\) of a linearly ordered type, their combined minimum is defined as follows: if \(x\) and \(y\) are both present, with values \(a\) and \(b\), it is \(\min(a, b)\); if exactly one of \(x\) and \(y\) is present, it is that value; and if both are absent, it is absent.
@[expose] public def minOption [LinearOrder α] (left right : Option α) : Option α :=
match left, right with
| some a, some b => some (min a b)
| some a, none => some a
| none, some b => some b
| none, none => none
Used by 2
TheoremOnly the empty forest has no minimum root#✓fully proved
A forest of Fibonacci trees over a linearly ordered type has no minimum root exactly when it is empty.
public theorem minRoot_eq_none_iff [LinearOrder α] (trees : List (FibonacciTree α)) :
minRoot trees = none ↔ trees = []
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def minRoot [LinearOrder α] : List (FibonacciTree α) → Option α
| [] => none
| tree :: trees =>
match minRoot trees with
| none => some tree.root
| some minimum => some (min tree.root minimum)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:301
Uses 3 · Used by 6
TheoremThe minimum root is a least root#✓fully proved
If a forest \(F\) of Fibonacci trees over a linearly ordered type has minimum root \(m\), then \(m\) is the root of some tree of \(F\) and \(m\) is at most the root of every tree of \(F\).
public theorem minRoot_spec [LinearOrder α] {trees : List (FibonacciTree α)} {minimum : α}
(result : minRoot trees = some minimum) :
(∃ tree ∈ trees, tree.root = minimum) ∧ ∀ tree ∈ trees, minimum ≤ tree.root
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def minRoot [LinearOrder α] : List (FibonacciTree α) → Option α
| [] => none
| tree :: trees =>
match minRoot trees with
| none => some tree.root
| some minimum => some (min tree.root minimum)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:301
Uses 4 · Used by 2
TheoremMinimum root of a concatenated forest#✓fully proved
For forests \(F\) and \(G\) of Fibonacci trees over a linearly ordered type, the minimum root of \(F\) followed by \(G\) is the combined minimum of the optional minimum roots of \(F\) and of \(G\): their minimum if both exist, the one that exists if only one does, and absent if neither does.
public theorem minRoot_append [LinearOrder α] (left right : List (FibonacciTree α)) :
minRoot (left ++ right) = minOption (minRoot left) (minRoot right)
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def minRoot [LinearOrder α] : List (FibonacciTree α) → Option α
| [] => none
| tree :: trees =>
match minRoot trees with
| none => some tree.root
| some minimum => some (min tree.root minimum)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:301
@[expose] public def minOption [LinearOrder α] (left right : Option α) : Option α :=
match left, right with
| some a, some b => some (min a b)
| some a, none => some a
| none, some b => some b
| none, none => none
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:309
Uses 4 · Used by 1
DefinitionInserting a tree into a forest#✓fully proved
Given a Fibonacci tree \(t\) and a list of Fibonacci trees, the insertion of \(t\) into the list is defined recursively. Inserting \(t\) into the empty list gives the one-tree list \([t]\). For a list with first tree \(s\) and remaining list \(L\): if the stored degree of \(t\) is less than the stored degree of \(s\), the result is \(t\) followed by \(s\) and then \(L\); if the two stored degrees are equal, the result is the insertion of the link of \(t\) and \(s\) into \(L\); otherwise the result is \(s\) followed by the insertion of \(t\) into \(L\).
On a list whose stored degrees strictly increase, this links \(t\) with any tree of equal degree and carries the linked tree forward, as in binary addition.
@[expose] public def addTree [LinearOrder α] (tree : FibonacciTree α) :
List (FibonacciTree α) → List (FibonacciTree α)
| [] => [tree]
| other :: trees =>
if tree.degree < other.degree then
tree :: other :: trees
else if tree.degree = other.degree then
addTree (tree.link other) trees
else
other :: addTree tree trees
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 3 · Used by 4
DefinitionConsolidation of a forest#✓fully proved
The consolidation of a list of Fibonacci trees is defined recursively: the consolidation of the empty list is the empty list, and the consolidation of a list with first tree \(t\) and remaining list \(L\) is the insertion of \(t\) into the consolidation of \(L\).
Each insertion links trees of equal stored degree as in binary addition, so the result has strictly increasing, hence distinct, stored root degrees, as in the consolidate step of CLRS.
@[expose] public def consolidate [LinearOrder α] :
List (FibonacciTree α) → List (FibonacciTree α)
| [] => []
| tree :: trees => addTree tree (consolidate trees)
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def addTree [LinearOrder α] (tree : FibonacciTree α) :
List (FibonacciTree α) → List (FibonacciTree α)
| [] => [tree]
| other :: trees =>
if tree.degree < other.degree then
tree :: other :: trees
else if tree.degree = other.degree then
addTree (tree.link other) trees
else
other :: addTree tree trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:379
Uses 2 · Used by 12
TheoremConsolidation preserves the elements#✓fully proved
For every list of Fibonacci trees over a linearly ordered type, its consolidation represents the same multiset as the original list.
public theorem elements_consolidate [LinearOrder α] (trees : List (FibonacciTree α)) :
elements (consolidate trees) = elements trees
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def elements (trees : List (FibonacciTree α)) : Multiset α :=
(trees.map FibonacciTree.elements).sum
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:237
@[expose] public def consolidate [LinearOrder α] :
List (FibonacciTree α) → List (FibonacciTree α)
| [] => []
| tree :: trees => addTree tree (consolidate trees)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:499
Uses 8 · Used by 2
TheoremConsolidation preserves validity#✓fully proved
Let \(\alpha\) be a linearly ordered type. If a Fibonacci forest with values in \(\alpha\) is valid, then its consolidation is valid.
public theorem valid_consolidate [LinearOrder α] {trees : List (FibonacciTree α)}
(valid : Valid trees) : Valid (consolidate trees)
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def FibonacciForest.Valid {α : Type u} [LE α]
(trees : List (FibonacciTree α)) : Prop :=
∀ tree ∈ trees, tree.Valid
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:228
@[expose] public def consolidate [LinearOrder α] :
List (FibonacciTree α) → List (FibonacciTree α)
| [] => []
| tree :: trees => addTree tree (consolidate trees)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:499
Uses 8 · Used by 7
TheoremConsolidation sorts root degrees#✓fully proved
For every list of Fibonacci trees, the stored degrees of the trees in its consolidation are strictly increasing in list order.
public theorem consolidate_sorted [LinearOrder α] (trees : List (FibonacciTree α)) :
SortedDegrees (consolidate trees)
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def SortedDegrees (trees : List (FibonacciTree α)) : Prop :=
trees.Pairwise fun a b => a.degree < b.degree
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:241
@[expose] public def consolidate [LinearOrder α] :
List (FibonacciTree α) → List (FibonacciTree α)
| [] => []
| tree :: trees => addTree tree (consolidate trees)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:499
Uses 7 · Used by 2
TheoremConsolidation yields distinct root degrees#✓fully proved
For every list of Fibonacci trees, the trees in its consolidation have pairwise distinct stored degrees.
public theorem consolidate_degrees_nodup [LinearOrder α]
(trees : List (FibonacciTree α)) :
((consolidate trees).map FibonacciTree.degree).Nodup
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def consolidate [LinearOrder α] :
List (FibonacciTree α) → List (FibonacciTree α)
| [] => []
| tree :: trees => addTree tree (consolidate trees)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:499
@[expose] public def degree : FibonacciTree α → Nat
| .node degree _ _ => degree
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:53
Uses 4
TheoremDegree-sorted forests have at most as many trees as elements#✓fully proved
Let \(F\) be a valid forest of Fibonacci trees whose degrees are strictly increasing along the list. Then the number of trees in \(F\) is at most the number of elements, counted with multiplicity, that \(F\) represents.
Every degree is smaller than the total element count and the degrees are distinct.
public theorem length_le_card_of_sorted [LE α] {trees : List (FibonacciTree α)}
(valid : Valid trees) (sorted : SortedDegrees trees) :
trees.length ≤ (elements trees).card
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def FibonacciForest.Valid {α : Type u} [LE α]
(trees : List (FibonacciTree α)) : Prop :=
∀ tree ∈ trees, tree.Valid
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:228
@[expose] public def SortedDegrees (trees : List (FibonacciTree α)) : Prop :=
trees.Pairwise fun a b => a.degree < b.degree
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:241
@[expose] public def elements (trees : List (FibonacciTree α)) : Multiset α :=
(trees.map FibonacciTree.elements).sum
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:237
Uses 7 · Used by 1
DefinitionRemoving a minimum tree from a Fibonacci forest#✓fully proved
For a list of Fibonacci trees over a linearly ordered type, this returns nothing on the empty list. Otherwise it returns the first tree whose root is minimal among all roots in the list, so earlier trees win ties, together with the list of the remaining trees in their original order.
@[expose] public def removeMinTree [LinearOrder α] :
List (FibonacciTree α) → Option (FibonacciTree α × List (FibonacciTree α))
| [] => none
| tree :: trees =>
match removeMinTree trees with
| none => some (tree, [])
| some (minimum, rest) =>
if minimum.root < tree.root then
some (minimum, tree :: rest)
else
some (tree, trees)
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 2 · Used by 9
TheoremMinimum-tree removal in a Fibonacci forest#✓fully proved
Let \(T\) be a list of Fibonacci trees over a linearly ordered type. If removing a minimum tree from \(T\) returns a tree \(m\) and a list \(R\), then the multiset of elements of \(m\) plus the multiset of elements of \(R\) equals the multiset of elements of \(T\), the tree \(m\) belongs to \(T\), the list \(R\) is a sublist of \(T\), and the root of \(m\) is at most the root of every tree in \(T\).
public theorem removeMinTree_spec [LinearOrder α]
{trees : List (FibonacciTree α)} {minimum : FibonacciTree α}
{rest : List (FibonacciTree α)} (result : removeMinTree trees = some (minimum, rest)) :
minimum.elements + elements rest = elements trees ∧
minimum ∈ trees ∧ rest.Sublist trees ∧
∀ tree ∈ trees, minimum.root ≤ tree.root
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def removeMinTree [LinearOrder α] :
List (FibonacciTree α) → Option (FibonacciTree α × List (FibonacciTree α))
| [] => none
| tree :: trees =>
match removeMinTree trees with
| none => some (tree, [])
| some (minimum, rest) =>
if minimum.root < tree.root then
some (minimum, tree :: rest)
else
some (tree, trees)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:554
@[expose] public def elements (trees : List (FibonacciTree α)) : Multiset α :=
(trees.map FibonacciTree.elements).sum
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:237
Uses 5 · Used by 7
StructureFibonacci heap#✓fully proved
A Fibonacci min-heap over a linearly ordered type consists of a list of Fibonacci trees, each valid (heap-ordered, and at every node the stored degree equals the number of children), together with a cached minimum equal to the least root value of these trees, absent when the list is empty.
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def FibonacciForest.Valid {α : Type u} [LE α]
(trees : List (FibonacciTree α)) : Prop :=
∀ tree ∈ trees, tree.Valid
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:228
trees : List (FibonacciTree α)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:646
cachedMin : Option α
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:648
@[expose] public def minRoot [LinearOrder α] : List (FibonacciTree α) → Option α
| [] => none
| tree :: trees =>
match minRoot trees with
| none => some tree.root
| some minimum => some (min tree.root minimum)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:301
Uses 3 · Used by 34
DefinitionMultiset of a Fibonacci heap#✓fully proved
The multiset represented by a Fibonacci heap over a linearly ordered type is the multiset of its list of trees: the sum, over the trees in the list, of the multisets of values stored in them. The cached minimum plays no role.
@[expose] public def elements [LinearOrder α] (heap : FibonacciHeap α) : Multiset α :=
FibonacciForest.elements heap.trees
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
@[expose] public def elements (trees : List (FibonacciTree α)) : Multiset α :=
(trees.map FibonacciTree.elements).sum
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:237
Uses 3 · Used by 21
DefinitionEmpty Fibonacci heap#✓fully proved
The Fibonacci heap over a linearly ordered type whose list of trees is empty and whose cached minimum is absent.
@[expose] public def empty [LinearOrder α] : FibonacciHeap α :=
⟨[], none, FibonacciForest.valid_nil, rfl⟩
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
public theorem valid_nil [LE α] : Valid ([] : List (FibonacciTree α))
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:267
Uses 5 · Used by 1
DefinitionSingleton Fibonacci heap#✓fully proved
For a value \(x\) of a linearly ordered type, the singleton Fibonacci heap on \(x\) has as its only tree the single-node tree with root \(x\), stored degree \(0\) and no children, and its cached minimum is \(x\).
@[expose] public def singleton [LinearOrder α] (value : α) : FibonacciHeap α :=
⟨[FibonacciTree.singleton value], some value, by
intro tree member
simp only [List.mem_singleton] at member
subst member
exact FibonacciTree.valid_singleton value, by
simp [FibonacciForest.minRoot, FibonacciTree.singleton, FibonacciTree.root]⟩
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
@[expose] public def singleton (value : α) : FibonacciTree α :=
.node 0 value []
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:88
Uses 7 · Used by 3
DefinitionMelding Fibonacci heaps#✓fully proved
The meld of Fibonacci heaps \(H_1\) and \(H_2\) is the Fibonacci heap whose root list is the root list of \(H_1\) followed by that of \(H_2\), and whose cached minimum is the smaller of the two cached minima when both heaps have one, and otherwise the cached minimum of whichever heap has one (none if neither does).
No linking happens until the next minimum deletion.
@[expose] public def meld [LinearOrder α] (left right : FibonacciHeap α) : FibonacciHeap α :=
⟨left.trees ++ right.trees,
FibonacciForest.minOption left.cachedMin right.cachedMin,
FibonacciForest.valid_append left.valid right.valid,
by rw [FibonacciForest.minRoot_append, left.min_eq, right.min_eq]⟩
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
@[expose] public def minOption [LinearOrder α] (left right : Option α) : Option α :=
match left, right with
| some a, some b => some (min a b)
| some a, none => some a
| none, some b => some b
| none, none => none
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:309
public theorem valid_append [LE α] {left right : List (FibonacciTree α)}
(left_valid : Valid left) (right_valid : Valid right) : Valid (left ++ right)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:272
Uses 7 · Used by 5
DefinitionUnion of Fibonacci heaps#✓fully proved
The union of Fibonacci heaps \(H_1\) and \(H_2\) is their meld: the heap whose trees are those of \(H_1\) followed by those of \(H_2\), and whose cached minimum is the smaller of the two cached minima (the one that exists if a heap is empty, none if both are).
CLRS calls this operation union.
@[expose] public def union [LinearOrder α] (left right : FibonacciHeap α) : FibonacciHeap α :=
left.meld right
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
Uses 2 · Used by 1
DefinitionInsertion into a Fibonacci heap#✓fully proved
Inserting a value \(x\) into a Fibonacci heap \(H\) gives the meld of the one-element Fibonacci heap containing \(x\) with \(H\), the one-element heap coming first.
@[expose] public def insert [LinearOrder α] (heap : FibonacciHeap α) (value : α) :
FibonacciHeap α :=
(singleton value).meld heap
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
@[expose] public def singleton [LinearOrder α] (value : α) : FibonacciHeap α :=
⟨[FibonacciTree.singleton value], some value, by
intro tree member
simp only [List.mem_singleton] at member
subst member
exact FibonacciTree.valid_singleton value, by
simp [FibonacciForest.minRoot, FibonacciTree.singleton, FibonacciTree.root]⟩
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:665
Uses 3 · Used by 2
DefinitionFind-min for Fibonacci heaps#✓fully proved
Find-min on a Fibonacci heap returns its cached minimum without modifying the heap: the least root value of its trees, or no value when the heap has no trees.
@[expose] public def findMin [LinearOrder α] (heap : FibonacciHeap α) : Option α :=
heap.cachedMin
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
Uses 1 · Used by 8
DefinitionMinimum deletion on a forest#✓fully proved
Given a list of Fibonacci trees over a linearly ordered type, the result is nothing if the list is empty. Otherwise the first tree whose root is minimal is removed, and the result is its root value together with the consolidation of the forest made of the removed tree's children followed by the remaining trees.
This is the forest-level computation behind deleting the minimum of a Fibonacci heap, without the validity proofs.
@[expose] public def deleteMinTrees [LinearOrder α]
(trees : List (FibonacciTree α)) : Option (α × List (FibonacciTree α)) :=
match FibonacciForest.removeMinTree trees with
| none => none
| some (minimum, rest) =>
some (minimum.root, FibonacciForest.consolidate (minimum.children ++ rest))
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def removeMinTree [LinearOrder α] :
List (FibonacciTree α) → Option (FibonacciTree α × List (FibonacciTree α))
| [] => none
| tree :: trees =>
match removeMinTree trees with
| none => some (tree, [])
| some (minimum, rest) =>
if minimum.root < tree.root then
some (minimum, tree :: rest)
else
some (tree, trees)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:554
@[expose] public def consolidate [LinearOrder α] :
List (FibonacciTree α) → List (FibonacciTree α)
| [] => []
| tree :: trees => addTree tree (consolidate trees)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:499
Uses 5 · Used by 1
DefinitionDeleting the minimum of a Fibonacci heap#✓fully proved
If the root list of the heap is empty, the result is nothing. Otherwise the first tree of the root list whose root is minimal is removed, and the result is its root value together with the heap whose root list is the consolidation of the removed tree's children followed by the remaining trees, and whose cached minimum is the minimum root of this consolidated forest.
Cslib.Algorithms.Lean.FibonacciHeap.deleteMin · 16 lines
public def deleteMin [LinearOrder α]
(heap : FibonacciHeap α) : Option (α × FibonacciHeap α) :=
match found : FibonacciForest.removeMinTree heap.trees with
| none => none
| some (minimum, rest) =>
have spec := FibonacciForest.removeMinTree_spec found
have minimum_valid : minimum.Valid := heap.valid minimum spec.2.1
have rest_valid : FibonacciForest.Valid rest := heap.valid.sublist spec.2.2.1
have children_valid : FibonacciForest.Valid minimum.children :=
fun _ member => minimum_valid.child_valid member
have combined_valid : FibonacciForest.Valid (minimum.children ++ rest) :=
FibonacciForest.valid_append children_valid rest_valid
let trees := FibonacciForest.consolidate (minimum.children ++ rest)
have trees_valid : FibonacciForest.Valid trees :=
FibonacciForest.valid_consolidate combined_valid
some (minimum.root, ⟨trees, FibonacciForest.minRoot trees, trees_valid, rfl⟩)
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
@[expose] public def removeMinTree [LinearOrder α] :
List (FibonacciTree α) → Option (FibonacciTree α × List (FibonacciTree α))
| [] => none
| tree :: trees =>
match removeMinTree trees with
| none => some (tree, [])
| some (minimum, rest) =>
if minimum.root < tree.root then
some (minimum, tree :: rest)
else
some (tree, trees)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:554
public theorem removeMinTree_spec [LinearOrder α]
{trees : List (FibonacciTree α)} {minimum : FibonacciTree α}
{rest : List (FibonacciTree α)} (result : removeMinTree trees = some (minimum, rest)) :
minimum.elements + elements rest = elements trees ∧
minimum ∈ trees ∧ rest.Sublist trees ∧
∀ tree ∈ trees, minimum.root ≤ tree.root
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:579
@[expose] public def FibonacciForest.Valid {α : Type u} [LE α]
(trees : List (FibonacciTree α)) : Prop :=
∀ tree ∈ trees, tree.Valid
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:228
public theorem valid_append [LE α] {left right : List (FibonacciTree α)}
(left_valid : Valid left) (right_valid : Valid right) : Valid (left ++ right)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:272
@[expose] public def consolidate [LinearOrder α] :
List (FibonacciTree α) → List (FibonacciTree α)
| [] => []
| tree :: trees => addTree tree (consolidate trees)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:499
public theorem valid_consolidate [LinearOrder α] {trees : List (FibonacciTree α)}
(valid : Valid trees) : Valid (consolidate trees)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:514
@[expose] public def minRoot [LinearOrder α] : List (FibonacciTree α) → Option α
| [] => none
| tree :: trees =>
match minRoot trees with
| none => some tree.root
| some minimum => some (min tree.root minimum)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:301
Uses 16 · Used by 7
TheoremFibonacci heap minimum deletion agrees with its root-list version#✓fully proved
For every Fibonacci heap \(H\), deleting the minimum of \(H\) and keeping only the returned value and the root list of the resulting heap gives the same result as the root-list minimum deletion applied to the root list of \(H\): either both fail, or both return the same value and the same list of trees.
public theorem deleteMin_trees [LinearOrder α] (heap : FibonacciHeap α) :
heap.deleteMin.map (fun result => (result.1, result.2.trees)) =
deleteMinTrees heap.trees
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
@[expose] public def deleteMinTrees [LinearOrder α]
(trees : List (FibonacciTree α)) : Option (α × List (FibonacciTree α)) :=
match FibonacciForest.removeMinTree trees with
| none => none
| some (minimum, rest) =>
some (minimum.root, FibonacciForest.consolidate (minimum.children ++ rest))
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:696
Uses 18
TheoremThe empty Fibonacci heap has no elements#✓fully proved
The empty Fibonacci heap represents the empty multiset.
public theorem elements_empty [LinearOrder α] : (empty : FibonacciHeap α).elements = 0
@[expose] public def empty [LinearOrder α] : FibonacciHeap α :=
⟨[], none, FibonacciForest.valid_nil, rfl⟩
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:661
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
Uses 5
TheoremMultiset of a singleton Fibonacci heap#✓fully proved
For every value \(x\) of a linearly ordered type, the singleton Fibonacci heap on \(x\), whose only tree is the single-node tree with root \(x\), represents the multiset \(\{x\}\).
public theorem elements_singleton [LinearOrder α] (value : α) :
(singleton value).elements = {value}
@[expose] public def singleton [LinearOrder α] (value : α) : FibonacciHeap α :=
⟨[FibonacciTree.singleton value], some value, by
intro tree member
simp only [List.mem_singleton] at member
subst member
exact FibonacciTree.valid_singleton value, by
simp [FibonacciForest.minRoot, FibonacciTree.singleton, FibonacciTree.root]⟩
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:665
Uses 6
TheoremMelding adds the elements#✓fully proved
For any two Fibonacci heaps \(H_1\) and \(H_2\) over a linearly ordered type, the meld of \(H_1\) and \(H_2\) represents the sum of the multisets represented by \(H_1\) and by \(H_2\).
public theorem elements_meld [LinearOrder α] (left right : FibonacciHeap α) :
(left.meld right).elements = left.elements + right.elements
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
Uses 5 · Used by 3
TheoremThe union of Fibonacci heaps adds their multisets#✓fully proved
For Fibonacci heaps \(H_1\) and \(H_2\) over a linearly ordered type, the multiset represented by the union of \(H_1\) and \(H_2\) is the sum of the multisets represented by \(H_1\) and by \(H_2\).
public theorem elements_union [LinearOrder α] (left right : FibonacciHeap α) :
(left.union right).elements = left.elements + right.elements
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
Uses 4
TheoremInsertion adds one occurrence#✓fully proved
For every Fibonacci heap \(H\) over a linearly ordered type and every value \(x\), the heap obtained by inserting \(x\) into \(H\) represents the multiset of \(H\) with one more occurrence of \(x\).
public theorem elements_insert [LinearOrder α] (heap : FibonacciHeap α) (value : α) :
(heap.insert value).elements = value ::ₘ heap.elements
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
Uses 9 · Used by 1
TheoremMelding adds the sizes of Fibonacci heaps#✓fully proved
For Fibonacci heaps \(H_1\) and \(H_2\), the number of elements of the meld of \(H_1\) and \(H_2\), counted with multiplicity, is the number of elements of \(H_1\) plus the number of elements of \(H_2\).
public theorem card_elements_meld [LinearOrder α] (left right : FibonacciHeap α) :
(left.meld right).elements.card = left.elements.card + right.elements.card
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
Uses 4
TheoremInsertion increases the size of a Fibonacci heap by one#✓fully proved
For every Fibonacci heap \(H\) and every value \(x\), the number of elements of the heap obtained by inserting \(x\) into \(H\), counted with multiplicity, is the number of elements of \(H\) plus one.
public theorem card_elements_insert [LinearOrder α] (heap : FibonacciHeap α) (value : α) :
(heap.insert value).elements.card = heap.elements.card + 1
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
Uses 4
TheoremFind-min fails exactly on the empty Fibonacci heap#✓fully proved
For a Fibonacci heap \(H\) over a linearly ordered type, find-min on \(H\) returns no value if and only if \(H\) has no trees.
public theorem findMin_eq_none_iff [LinearOrder α] (heap : FibonacciHeap α) :
heap.findMin = none ↔ heap.trees = []
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
Uses 5 · Used by 5
TheoremFind-min returns an element of the Fibonacci heap#✓fully proved
Let \(H\) be a Fibonacci heap over a linearly ordered type. If find-min on \(H\) returns \(m\), then \(m\) belongs to the multiset represented by \(H\).
public theorem findMin_mem [LinearOrder α] {heap : FibonacciHeap α} {minimum : α}
(result : heap.findMin = some minimum) : minimum ∈ heap.elements
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
Uses 10 · Used by 5
TheoremFind-min returns a lower bound of the Fibonacci heap#✓fully proved
Let \(H\) be a Fibonacci heap over a linearly ordered type. If find-min on \(H\) returns \(m\), then \(m \le v\) for every value \(v\) in the multiset represented by \(H\).
public theorem findMin_le [LinearOrder α] {heap : FibonacciHeap α} {minimum value : α}
(result : heap.findMin = some minimum) (member : value ∈ heap.elements) :
minimum ≤ value
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
Uses 11 · Used by 5
TheoremFibonacci heap minimum deletion fails exactly on the empty heap#✓fully proved
Deleting the minimum of a Fibonacci heap fails if and only if the heap's list of root trees is empty.
public theorem deleteMin_eq_none_iff [LinearOrder α] (heap : FibonacciHeap α) :
heap.deleteMin = none ↔ heap.trees = []
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
Uses 17
TheoremFibonacci heap minimum deletion removes one copy of the minimum#✓fully proved
If deleting the minimum of a Fibonacci heap \(H\) succeeds and returns the value \(m\) and the heap \(H'\), then the multiset of elements of \(H'\) is the multiset of elements of \(H\) with one occurrence of \(m\) removed.
public theorem deleteMin_elements [LinearOrder α] {heap : FibonacciHeap α} {minimum : α}
{rest : FibonacciHeap α} (result : heap.deleteMin = some (minimum, rest)) :
rest.elements = heap.elements.erase minimum
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
Uses 20
TheoremFibonacci heap minimum deletion splits off the minimum#✓fully proved
If deleting the minimum of a Fibonacci heap \(H\) succeeds and returns the value \(m\) and the heap \(H'\), then the multiset of elements of \(H\) is the multiset of elements of \(H'\) with one copy of \(m\) added.
public theorem deleteMin_cons_elements [LinearOrder α] {heap : FibonacciHeap α}
{minimum : α} {rest : FibonacciHeap α}
(result : heap.deleteMin = some (minimum, rest)) :
minimum ::ₘ rest.elements = heap.elements
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
Uses 20
TheoremFibonacci heap minimum deletion returns a lower bound#✓fully proved
If deleting the minimum of a Fibonacci heap \(H\) succeeds and returns the value \(m\), then \(m \le v\) for every element \(v\) of \(H\).
public theorem deleteMin_le [LinearOrder α] {heap : FibonacciHeap α} {minimum value : α}
{rest : FibonacciHeap α} (result : heap.deleteMin = some (minimum, rest))
(member : value ∈ heap.elements) : minimum ≤ value
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
Uses 19
TheoremMinimum deletion leaves a Fibonacci heap with strictly increasing root degrees#✓fully proved
If deleting the minimum of a Fibonacci heap succeeds and returns the heap \(H'\), then the degrees of the root trees of \(H'\), in list order, are strictly increasing; consolidation is what makes them so.
public theorem deleteMin_sortedDegrees [LinearOrder α] {heap : FibonacciHeap α}
{minimum : α} {rest : FibonacciHeap α}
(result : heap.deleteMin = some (minimum, rest)) :
FibonacciForest.SortedDegrees rest.trees
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
@[expose] public def SortedDegrees (trees : List (FibonacciTree α)) : Prop :=
trees.Pairwise fun a b => a.degree < b.degree
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:241
Uses 19 · Used by 1
TheoremAfter minimum deletion a Fibonacci heap has at most as many roots as elements#✓fully proved
If deleting the minimum of a Fibonacci heap succeeds and returns the heap \(H'\), then the number of root trees of \(H'\) is at most the number of elements of \(H'\), counted with multiplicity.
public theorem deleteMin_length_le_card [LinearOrder α] {heap : FibonacciHeap α}
{minimum : α} {rest : FibonacciHeap α}
(result : heap.deleteMin = some (minimum, rest)) :
rest.trees.length ≤ rest.elements.card
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
Uses 7
DefinitionSubtree of a Fibonacci tree at a path#✓fully proved
For a list \(p = (i_1, \dots, i_n)\) of natural numbers and a Fibonacci tree \(t\), the subtree of \(t\) at \(p\) is found by starting at the root and moving to the child with zero-based index \(i_1\), then to its child with index \(i_2\), and so on. The result is absent when some index is at least the number of children of the current node. The empty path addresses the whole tree \(t\).
@[expose] public def subtreeAt : List Nat → FibonacciTree α → Option (FibonacciTree α)
| [], t => some t
| i :: p, .node _ _ children => (children[i]?).bind (subtreeAt p)
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
DefinitionCutting a subtree out of a Fibonacci tree#✓fully proved
For a path \(p\) of child indices and a Fibonacci tree \(t\), the cut of \(t\) at \(p\) is either undefined or a pair of an extracted subtree and an optional remainder tree. For the empty path, the extracted subtree is \(t\) and there is no remainder. For a path consisting of an index \(i\) followed by a path \(q\), where \(t\) has root \(r\) and children \(c_0, \dots, c_{k-1}\), the cut is undefined if \(i \ge k\) or if the cut of \(c_i\) at \(q\) is undefined. Otherwise, with \(s\) the subtree extracted from \(c_i\), the extracted subtree is \(s\) and the remainder is the tree with root \(r\) whose children are those of \(t\) with \(c_i\) removed (if the cut of \(c_i\) left no remainder) or with \(c_i\) replaced by that remainder (otherwise), and whose stored degree is its new number of children.
When the cut is defined, there is no remainder exactly when \(p\) is empty.
Cslib.Algorithms.Lean.FibonacciTree.cutAt · 15 lines
@[expose] public def cutAt : List Nat → FibonacciTree α →
Option (FibonacciTree α × Option (FibonacciTree α))
| [], t => some (t, none)
| i :: p, .node _ root children =>
match children[i]? with
| none => none
| some child =>
match cutAt p child with
| none => none
| some (sub, none) =>
some (sub, some (.node (children.eraseIdx i).length root
(children.eraseIdx i)))
| some (sub, some child') =>
some (sub, some (.node (children.set i child').length root
(children.set i child')))
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 1 · Used by 14
DefinitionReplacing the root key of a Fibonacci tree#✓fully proved
For a Fibonacci tree \(t\) and a key \(k\), this is the tree whose root value is \(k\) and whose stored degree and list of children are those of \(t\).
It is used on an extracted subtree with a key no larger than the old root.
@[expose] public def decreaseRoot (t : FibonacciTree α) (newKey : α) : FibonacciTree α :=
match t with
| .node degree _ children => .node degree newKey children
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 1 · Used by 8
TheoremElements after replacing the root key#✓fully proved
For a Fibonacci tree \(t\) and any key \(k\), the multiset of elements represented by the tree obtained from \(t\) by replacing its root value with \(k\) equals the multiset of elements of \(t\) with one occurrence of the root of \(t\) removed and \(k\) added.
public theorem elements_decreaseRoot [DecidableEq α] (t : FibonacciTree α) (newKey : α) :
(t.decreaseRoot newKey).elements = newKey ::ₘ t.elements.erase t.root
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 4 · Used by 5
TheoremLowering the root keeps a Fibonacci tree valid#✓fully proved
Let \(T\) be a valid Fibonacci tree over a preordered type and let \(k\) be a key that is at most the root of \(T\). Then the tree obtained from \(T\) by replacing its root by \(k\), keeping its degree and children, is valid: the new root is still no greater than every represented element.
public theorem Valid.decreaseRoot [Preorder α] {t : FibonacciTree α} (hv : Valid t)
{newKey : α} (hle : newKey ≤ t.root) : Valid (t.decreaseRoot newKey)
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
public inductive Valid {α : Type u} [LE α] : FibonacciTree α → Prop
| node {degree : Nat} {root : α} {children : List (FibonacciTree α)}
(children_valid : ∀ child ∈ children, Valid child)
(degree_eq : degree = children.length)
(root_le : ∀ value ∈ elements (.node degree root children), root ≤ value) :
Valid (.node degree root children)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:80
Uses 8 · Used by 4
TheoremSubtrees of a valid Fibonacci tree are valid#✓fully proved
If a Fibonacci tree \(t\) is valid and a path \(p\) of child indices addresses a subtree \(s\) of \(t\), then \(s\) is valid.
public theorem Valid.subtreeAt [LE α] {t sub : FibonacciTree α} (hv : Valid t)
{p : List Nat} (h : subtreeAt p t = some sub) : Valid sub
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
public inductive Valid {α : Type u} [LE α] : FibonacciTree α → Prop
| node {degree : Nat} {root : α} {children : List (FibonacciTree α)}
(children_valid : ∀ child ∈ children, Valid child)
(degree_eq : degree = children.length)
(root_le : ∀ value ∈ elements (.node degree root children), root ≤ value) :
Valid (.node degree root children)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:80
@[expose] public def subtreeAt : List Nat → FibonacciTree α → Option (FibonacciTree α)
| [], t => some t
| i :: p, .node _ _ children => (children[i]?).bind (subtreeAt p)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:133
Uses 5 · Used by 1
TheoremA cut extracts the addressed subtree#✓fully proved
Let \(t\) be a Fibonacci tree and \(p\) a path of child indices. If cutting \(t\) at \(p\) extracts a subtree \(s\) (with or without a remainder), then \(s\) is the subtree of \(t\) at \(p\).
public theorem cutAt_subtreeAt {p : List Nat} {t sub : FibonacciTree α}
{rem : Option (FibonacciTree α)} (h : cutAt p t = some (sub, rem)) :
subtreeAt p t = some sub
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def cutAt : List Nat → FibonacciTree α →
Option (FibonacciTree α × Option (FibonacciTree α))
| [], t => some (t, none)
| i :: p, .node _ root children =>
match children[i]? with
| none => none
| some child =>
match cutAt p child with
| none => none
| some (sub, none) =>
some (sub, some (.node (children.eraseIdx i).length root
(children.eraseIdx i)))
⋯
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:146
@[expose] public def subtreeAt : List Nat → FibonacciTree α → Option (FibonacciTree α)
| [], t => some t
| i :: p, .node _ _ children => (children[i]?).bind (subtreeAt p)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:133
Uses 3 · Used by 1
TheoremEvery addressed subtree can be cut out#✓fully proved
If a path \(p\) of child indices addresses a subtree \(s\) of a Fibonacci tree \(t\), then cutting \(t\) at \(p\) succeeds and extracts exactly \(s\), together with some remainder, which may be absent.
public theorem subtreeAt_cutAt {p : List Nat} {t sub : FibonacciTree α}
(h : subtreeAt p t = some sub) : ∃ rem, cutAt p t = some (sub, rem)
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def subtreeAt : List Nat → FibonacciTree α → Option (FibonacciTree α)
| [], t => some t
| i :: p, .node _ _ children => (children[i]?).bind (subtreeAt p)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:133
@[expose] public def cutAt : List Nat → FibonacciTree α →
Option (FibonacciTree α × Option (FibonacciTree α))
| [], t => some (t, none)
| i :: p, .node _ root children =>
match children[i]? with
| none => none
| some child =>
match cutAt p child with
| none => none
| some (sub, none) =>
some (sub, some (.node (children.eraseIdx i).length root
(children.eraseIdx i)))
⋯
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:146
Uses 3 · Used by 1
TheoremA cut without remainder extracts the whole tree#✓fully proved
Let \(t\) be a Fibonacci tree and \(p\) a path of child indices. If cutting \(t\) at \(p\) extracts a subtree \(s\) and leaves no remainder, then \(s = t\).
public theorem cutAt_eq_self {p : List Nat} {t sub : FibonacciTree α}
(h : cutAt p t = some (sub, none)) : sub = t
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def cutAt : List Nat → FibonacciTree α →
Option (FibonacciTree α × Option (FibonacciTree α))
| [], t => some (t, none)
| i :: p, .node _ root children =>
match children[i]? with
| none => none
| some child =>
match cutAt p child with
| none => none
| some (sub, none) =>
some (sub, some (.node (children.eraseIdx i).length root
(children.eraseIdx i)))
⋯
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:146
Uses 2 · Used by 2
TheoremCutting a subtree splits the elements of a Fibonacci tree#✓fully proved
Let \(t\) be a Fibonacci tree and \(p\) a path of child indices. If cutting \(t\) at \(p\) extracts a subtree \(s\) and leaves a remainder tree \(t'\), then the multiset of elements of \(t\) is the sum of the multisets of elements of \(t'\) and of \(s\).
public theorem cutAt_elements {p : List Nat} {t sub t' : FibonacciTree α}
(h : cutAt p t = some (sub, some t')) :
t.elements = t'.elements + sub.elements
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def cutAt : List Nat → FibonacciTree α →
Option (FibonacciTree α × Option (FibonacciTree α))
| [], t => some (t, none)
| i :: p, .node _ root children =>
match children[i]? with
| none => none
| some child =>
match cutAt p child with
| none => none
| some (sub, none) =>
some (sub, some (.node (children.eraseIdx i).length root
(children.eraseIdx i)))
⋯
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:146
Uses 4 · Used by 2
TheoremThe subtree extracted by a cut from a valid tree is valid#✓fully proved
Let \(t\) be a valid Fibonacci tree over a type with a relation \(\le\), and \(p\) a path of child indices. If cutting \(t\) at \(p\) extracts a subtree \(s\) (with or without a remainder), then \(s\) is valid.
public theorem cutAt_sub_valid [LE α] {p : List Nat} {t sub : FibonacciTree α}
{rem : Option (FibonacciTree α)} (hv : Valid t)
(h : cutAt p t = some (sub, rem)) : Valid sub
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
public inductive Valid {α : Type u} [LE α] : FibonacciTree α → Prop
| node {degree : Nat} {root : α} {children : List (FibonacciTree α)}
(children_valid : ∀ child ∈ children, Valid child)
(degree_eq : degree = children.length)
(root_le : ∀ value ∈ elements (.node degree root children), root ≤ value) :
Valid (.node degree root children)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:80
@[expose] public def cutAt : List Nat → FibonacciTree α →
Option (FibonacciTree α × Option (FibonacciTree α))
| [], t => some (t, none)
| i :: p, .node _ root children =>
match children[i]? with
| none => none
| some child =>
match cutAt p child with
| none => none
| some (sub, none) =>
some (sub, some (.node (children.eraseIdx i).length root
(children.eraseIdx i)))
⋯
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:146
Uses 5 · Used by 1
TheoremThe remainder of a cut from a valid tree is valid#✓fully proved
Let \(t\) be a valid Fibonacci tree over a type with a relation \(\le\), and \(p\) a path of child indices. If cutting \(t\) at \(p\) extracts a subtree and leaves a remainder tree \(t'\), then \(t'\) is valid: its children are valid, its stored degree equals its number of children, and its root is \(\le\) every element of \(t'\).
public theorem cutAt_remainder_valid [LE α] {p : List Nat} {t sub t' : FibonacciTree α}
(hv : Valid t) (h : cutAt p t = some (sub, some t')) : Valid t'
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
public inductive Valid {α : Type u} [LE α] : FibonacciTree α → Prop
| node {degree : Nat} {root : α} {children : List (FibonacciTree α)}
(children_valid : ∀ child ∈ children, Valid child)
(degree_eq : degree = children.length)
(root_le : ∀ value ∈ elements (.node degree root children), root ≤ value) :
Valid (.node degree root children)
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:80
@[expose] public def cutAt : List Nat → FibonacciTree α →
Option (FibonacciTree α × Option (FibonacciTree α))
| [], t => some (t, none)
| i :: p, .node _ root children =>
match children[i]? with
| none => none
| some child =>
match cutAt p child with
| none => none
| some (sub, none) =>
some (sub, some (.node (children.eraseIdx i).length root
(children.eraseIdx i)))
⋯
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:146
Uses 8 · Used by 1
DefinitionCutting a subtree out of a Fibonacci forest#✓fully proved
For a forest given as a list of Fibonacci trees, an index \(i\) and a path \(p\) of child indices, the cut is undefined if the list has no tree at position \(i\) (counting from \(0\)) or if cutting that tree \(t\) at \(p\) is undefined. Otherwise, if cutting \(t\) at \(p\) extracts the subtree \(s\), the result is \(s\) together with the list in which the tree at position \(i\) is removed (if the cut of \(t\) left no remainder) or replaced by the remainder (otherwise).
@[expose] public def cutTreeAt (trees : List (FibonacciTree α)) (i : Nat) (p : List Nat) :
Option (FibonacciTree α × List (FibonacciTree α)) :=
match trees[i]? with
| none => none
| some t =>
match t.cutAt p with
| none => none
| some (sub, none) => some (sub, trees.eraseIdx i)
| some (sub, some t') => some (sub, trees.set i t')
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
Uses 2 · Used by 11
TheoremCutting a subtree splits the elements of a Fibonacci forest#✓fully proved
Let \(F\) be a forest of Fibonacci trees, \(i\) an index and \(p\) a path of child indices. If cutting \(F\) at the \(i\)-th tree and path \(p\) extracts a subtree \(s\) and leaves the forest \(F'\), then the multiset of elements of \(F\) is the sum of the multisets of elements of \(F'\) and of \(s\).
public theorem cutTreeAt_elements {trees : List (FibonacciTree α)} {i : Nat} {p : List Nat}
{sub : FibonacciTree α} {rest : List (FibonacciTree α)}
(h : cutTreeAt trees i p = some (sub, rest)) :
elements trees = elements rest + sub.elements
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def cutTreeAt (trees : List (FibonacciTree α)) (i : Nat) (p : List Nat) :
Option (FibonacciTree α × List (FibonacciTree α)) :=
match trees[i]? with
| none => none
| some t =>
match t.cutAt p with
| none => none
| some (sub, none) => some (sub, trees.eraseIdx i)
| some (sub, some t') => some (sub, trees.set i t')
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:387
@[expose] public def elements (trees : List (FibonacciTree α)) : Multiset α :=
(trees.map FibonacciTree.elements).sum
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:237
Uses 7 · Used by 6
TheoremCutting a valid forest leaves valid parts#✓fully proved
Let \(F\) be a valid forest of Fibonacci trees over a type with a relation \(\le\), \(i\) an index and \(p\) a path of child indices. If cutting \(F\) at index \(i\) and path \(p\) extracts a subtree \(s\) and leaves the forest \(F'\), then \(s\) is a valid tree and \(F'\) is a valid forest.
public theorem cutTreeAt_valid [LE α] {trees : List (FibonacciTree α)} {i : Nat}
{p : List Nat} {sub : FibonacciTree α} {rest : List (FibonacciTree α)}
(hv : Valid trees) (h : cutTreeAt trees i p = some (sub, rest)) :
sub.Valid ∧ Valid rest
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def FibonacciForest.Valid {α : Type u} [LE α]
(trees : List (FibonacciTree α)) : Prop :=
∀ tree ∈ trees, tree.Valid
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:228
@[expose] public def cutTreeAt (trees : List (FibonacciTree α)) (i : Nat) (p : List Nat) :
Option (FibonacciTree α × List (FibonacciTree α)) :=
match trees[i]? with
| none => none
| some t =>
match t.cutAt p with
| none => none
| some (sub, none) => some (sub, trees.eraseIdx i)
| some (sub, some t') => some (sub, trees.set i t')
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:387
Uses 7 · Used by 4
TheoremEvery addressed subtree of a forest can be cut out#✓fully proved
Let \(F\) be a forest of Fibonacci trees whose tree at position \(i\) is \(t\), and let \(p\) be a path of child indices such that the subtree of \(t\) at \(p\) is \(s\). Then cutting \(F\) at index \(i\) and path \(p\) is defined and extracts \(s\), together with some remaining forest.
public theorem cutTreeAt_of_subtreeAt {trees : List (FibonacciTree α)} {i : Nat}
{p : List Nat} {t sub : FibonacciTree α} (htree : trees[i]? = some t)
(hpath : t.subtreeAt p = some sub) :
∃ rest, cutTreeAt trees i p = some (sub, rest)
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def cutTreeAt (trees : List (FibonacciTree α)) (i : Nat) (p : List Nat) :
Option (FibonacciTree α × List (FibonacciTree α)) :=
match trees[i]? with
| none => none
| some t =>
match t.cutAt p with
| none => none
| some (sub, none) => some (sub, trees.eraseIdx i)
| some (sub, some t') => some (sub, trees.set i t')
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:387
Uses 5 · Used by 1
DefinitionDecrease-key in a Fibonacci heap#✓fully proved
Given a Fibonacci heap \(H\) over a linearly ordered type, a root index \(i\), a path \(p\) of child indices and a key \(k\), decrease-key cuts the subtree \(S\) at path \(p\) out of the \(i\)-th tree of the root list of \(H\), replaces the root of \(S\) by \(k\), and puts the resulting tree in front of the remaining forest (the root list with the \(i\)-th tree replaced by what is left of it after the cut, or removed when \(S\) is that whole tree). The cached minimum of the result is the smaller of \(k\) and the previous cached minimum, computed without rescanning the root list. When the cut fails (the address does not resolve) or \(k\) is greater than the root of \(S\), the heap \(H\) is returned unchanged.
Unlike CLRS decrease-key, this performs no cascading cuts: the trees carry no mark field.
Cslib.Algorithms.Lean.FibonacciHeap.decreaseKey · 70 lines
public def decreaseKey [LinearOrder α] (heap : FibonacciHeap α) (i : Nat) (p : List Nat)
(newKey : α) : FibonacciHeap α :=
match found : FibonacciForest.cutTreeAt heap.trees i p with
| none => heap
| some (sub, rest) =>
if hle : newKey ≤ sub.root then
have hv := FibonacciForest.cutTreeAt_valid heap.valid found
let trees := sub.decreaseRoot newKey :: rest
have trees_valid : FibonacciForest.Valid trees := by
intro t ht
have ht' : t ∈ sub.decreaseRoot newKey :: rest := ht
rw [List.mem_cons] at ht'
rcases ht' with rfl | ht'
· exact hv.1.decreaseRoot hle
· exact hv.2 t ht'
let newMin : Option α := match heap.cachedMin with
| none => some newKey
| some m => some (min newKey m)
have hmin : newMin = FibonacciForest.minRoot trees := by
have hElemTrees : FibonacciForest.elements trees =
newKey ::ₘ (FibonacciForest.elements heap.trees).erase sub.root := by
have hElem := FibonacciForest.cutTreeAt_elements found
show FibonacciForest.elements (sub.decreaseRoot newKey :: rest) = _
rw [hElem,
Multiset.erase_add_right_pos _ (FibonacciTree.root_mem_elements sub)]
change (sub.decreaseRoot newKey).elements +
FibonacciForest.elements rest = _
rw [FibonacciTree.elements_decreaseRoot, Multiset.cons_add,
Multiset.add_comm (sub.elements.erase sub.root)]
cases hc : heap.cachedMin with
| none =>
exfalso
have hfind : heap.findMin = none := hc
have htrees : heap.trees = [] := (findMin_eq_none_iff heap).mp hfind
rw [htrees] at found
simp [FibonacciForest.cutTreeAt] at found
| some m =>
have hnew : newMin = some (min newKey m) := by
show (match heap.cachedMin with
| none => some newKey
| some m' => some (min newKey m')) = some (min newKey m)
rw [hc]
have hfind : heap.findMin = some m := hc
have hmMem : m ∈ heap.elements := findMin_mem hfind
change m ∈ FibonacciForest.elements heap.trees at hmMem
have hmem : min newKey m ∈ FibonacciForest.elements trees := by
by_cases hm : m = sub.root
· have hmin' : min newKey m = newKey :=
min_eq_left (hm ▸ hle)
rw [hElemTrees, hmin']
exact Multiset.mem_cons_self _ _
· rw [hElemTrees]
rcases le_total newKey m with hnm | hnm
· rw [min_eq_left hnm]
exact Multiset.mem_cons_self _ _
· rw [min_eq_right hnm]
exact Multiset.mem_cons_of_mem
((Multiset.mem_erase_of_ne hm).mpr hmMem)
have hleast : ∀ y ∈ FibonacciForest.elements trees,
min newKey m ≤ y := by
intro y hy
rw [hElemTrees] at hy
rcases Multiset.mem_cons.mp hy with rfl | hy
· exact min_le_left _ _
· exact (min_le_right newKey m).trans
(findMin_le hfind (Multiset.mem_of_mem_erase hy))
rw [hnew]
exact (minRoot_eq_some_of_least trees_valid hmem hleast).symm
⟨trees, newMin, trees_valid, hmin⟩
else heap
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
@[expose] public def cutTreeAt (trees : List (FibonacciTree α)) (i : Nat) (p : List Nat) :
Option (FibonacciTree α × List (FibonacciTree α)) :=
match trees[i]? with
| none => none
| some t =>
match t.cutAt p with
| none => none
| some (sub, none) => some (sub, trees.eraseIdx i)
| some (sub, some t') => some (sub, trees.set i t')
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:387
public theorem cutTreeAt_valid [LE α] {trees : List (FibonacciTree α)} {i : Nat}
{p : List Nat} {sub : FibonacciTree α} {rest : List (FibonacciTree α)}
(hv : Valid trees) (h : cutTreeAt trees i p = some (sub, rest)) :
sub.Valid ∧ Valid rest
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:431
@[expose] public def FibonacciForest.Valid {α : Type u} [LE α]
(trees : List (FibonacciTree α)) : Prop :=
∀ tree ∈ trees, tree.Valid
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:228
Uses 22 · Used by 8
TheoremRoot list after decrease-key#✓fully proved
Let \(H\) be a Fibonacci heap, \(i\) a root index, \(p\) a path of child indices and \(k\) a key. Suppose that cutting the subtree at path \(p\) out of the \(i\)-th tree of the root list of \(H\) succeeds, extracting the subtree \(S\) and leaving the forest \(R\), and that \(k\) is at most the root of \(S\). Then the root list of the heap obtained from \(H\) by decreasing the key at root index \(i\) and path \(p\) to \(k\) consists of \(S\) with its root replaced by \(k\), followed by the trees of \(R\) in order.
public theorem decreaseKey_trees_of_cut [LinearOrder α] {heap : FibonacciHeap α}
{i : Nat} {p : List Nat} {newKey : α} {sub : FibonacciTree α}
{rest : List (FibonacciTree α)}
(hcut : FibonacciForest.cutTreeAt heap.trees i p = some (sub, rest))
(hle : newKey ≤ sub.root) :
(heap.decreaseKey i p newKey).trees = sub.decreaseRoot newKey :: rest
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def cutTreeAt (trees : List (FibonacciTree α)) (i : Nat) (p : List Nat) :
Option (FibonacciTree α × List (FibonacciTree α)) :=
match trees[i]? with
| none => none
| some t =>
match t.cutAt p with
| none => none
| some (sub, none) => some (sub, trees.eraseIdx i)
| some (sub, some t') => some (sub, trees.set i t')
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:387
Uses 23 · Used by 2
TheoremDecrease-key at an unresolved address does nothing#✓fully proved
Let \(H\) be a Fibonacci heap, \(i\) a root index and \(p\) a path of child indices. If cutting the subtree at path \(p\) out of the \(i\)-th tree of the root list of \(H\) fails, then for every key \(k\), decreasing the key at root index \(i\) and path \(p\) to \(k\) returns \(H\) unchanged.
public theorem decreaseKey_eq_self_of_cut_none [LinearOrder α] {heap : FibonacciHeap α}
{i : Nat} {p : List Nat} {newKey : α}
(hcut : FibonacciForest.cutTreeAt heap.trees i p = none) :
heap.decreaseKey i p newKey = heap
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
@[expose] public def cutTreeAt (trees : List (FibonacciTree α)) (i : Nat) (p : List Nat) :
Option (FibonacciTree α × List (FibonacciTree α)) :=
match trees[i]? with
| none => none
| some t =>
match t.cutAt p with
| none => none
| some (sub, none) => some (sub, trees.eraseIdx i)
| some (sub, some t') => some (sub, trees.set i t')
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:387
Uses 23
TheoremDecrease-key with a larger key does nothing#✓fully proved
Let \(H\) be a Fibonacci heap, \(i\) a root index, \(p\) a path of child indices and \(k\) a key. Suppose that cutting the subtree at path \(p\) out of the \(i\)-th tree of the root list of \(H\) succeeds and extracts the subtree \(S\), and that \(k\) is not at most the root of \(S\) (keys are linearly ordered, so \(k\) is greater than that root). Then decreasing the key at root index \(i\) and path \(p\) to \(k\) returns \(H\) unchanged.
public theorem decreaseKey_eq_self_of_not_le [LinearOrder α] {heap : FibonacciHeap α}
{i : Nat} {p : List Nat} {newKey : α} {sub : FibonacciTree α}
{rest : List (FibonacciTree α)}
(hcut : FibonacciForest.cutTreeAt heap.trees i p = some (sub, rest))
(hle : ¬ newKey ≤ sub.root) :
heap.decreaseKey i p newKey = heap
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def cutTreeAt (trees : List (FibonacciTree α)) (i : Nat) (p : List Nat) :
Option (FibonacciTree α × List (FibonacciTree α)) :=
match trees[i]? with
| none => none
| some t =>
match t.cutAt p with
| none => none
| some (sub, none) => some (sub, trees.eraseIdx i)
| some (sub, some t') => some (sub, trees.set i t')
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:387
Uses 23
TheoremDecrease-key replaces one key#✓fully proved
Let \(H\) be a Fibonacci heap, \(i\) a root index, \(p\) a path of child indices and \(k\) a key. Suppose that cutting the subtree at path \(p\) out of the \(i\)-th tree of the root list of \(H\) succeeds and extracts the subtree \(S\), and that \(k\) is at most the root of \(S\). Then the multiset represented by the heap obtained from \(H\) by decreasing the key at root index \(i\) and path \(p\) to \(k\) is the multiset represented by \(H\) with one occurrence of the root of \(S\) removed and one occurrence of \(k\) added.
public theorem decreaseKey_elements [LinearOrder α] {heap : FibonacciHeap α} {i : Nat}
{p : List Nat} {newKey : α} {sub : FibonacciTree α} {rest : List (FibonacciTree α)}
(hcut : FibonacciForest.cutTreeAt heap.trees i p = some (sub, rest))
(hle : newKey ≤ sub.root) :
(heap.decreaseKey i p newKey).elements =
newKey ::ₘ heap.elements.erase sub.root
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def cutTreeAt (trees : List (FibonacciTree α)) (i : Nat) (p : List Nat) :
Option (FibonacciTree α × List (FibonacciTree α)) :=
match trees[i]? with
| none => none
| some t =>
match t.cutAt p with
| none => none
| some (sub, none) => some (sub, trees.eraseIdx i)
| some (sub, some t') => some (sub, trees.set i t')
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:387
Uses 13 · Used by 3
TheoremDecrease-key replaces one key, stated by address#✓fully proved
Let \(H\) be a Fibonacci heap, let \(T\) be the \(i\)-th tree of its root list, and let \(S\) be the subtree of \(T\) at the path \(p\) of child indices. If the key \(k\) is at most the root of \(S\), then the multiset represented by the heap obtained from \(H\) by decreasing the key at root index \(i\) and path \(p\) to \(k\) is the multiset represented by \(H\) with one occurrence of the root of \(S\) removed and one occurrence of \(k\) added.
public theorem decreaseKey_elements_of_subtreeAt [LinearOrder α]
{heap : FibonacciHeap α} {i : Nat} {p : List Nat} {newKey : α}
{t sub : FibonacciTree α} (htree : heap.trees[i]? = some t)
(hpath : t.subtreeAt p = some sub) (hle : newKey ≤ sub.root) :
(heap.decreaseKey i p newKey).elements =
newKey ::ₘ heap.elements.erase sub.root
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
TheoremDecrease-key preserves the number of elements#✓fully proved
Let \(H\) be a Fibonacci heap, \(i\) a root index, \(p\) a path of child indices and \(k\) a key. Suppose that cutting the subtree at path \(p\) out of the \(i\)-th tree of the root list of \(H\) succeeds and extracts the subtree \(S\), and that \(k\) is at most the root of \(S\). Then the multiset represented by the heap obtained from \(H\) by decreasing the key at root index \(i\) and path \(p\) to \(k\) has the same number of elements, counted with multiplicity, as the multiset represented by \(H\).
public theorem decreaseKey_card_elements [LinearOrder α] {heap : FibonacciHeap α}
{i : Nat} {p : List Nat} {newKey : α} {sub : FibonacciTree α}
{rest : List (FibonacciTree α)}
(hcut : FibonacciForest.cutTreeAt heap.trees i p = some (sub, rest))
(hle : newKey ≤ sub.root) :
(heap.decreaseKey i p newKey).elements.card = heap.elements.card
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def cutTreeAt (trees : List (FibonacciTree α)) (i : Nat) (p : List Nat) :
Option (FibonacciTree α × List (FibonacciTree α)) :=
match trees[i]? with
| none => none
| some t =>
match t.cutAt p with
| none => none
| some (sub, none) => some (sub, trees.eraseIdx i)
| some (sub, some t') => some (sub, trees.set i t')
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:387
TheoremMinimum after decrease-key#✓fully proved
Let \(H\) be a Fibonacci heap whose minimum, as returned by find-min, is \(m\), and let \(i\) be a root index, \(p\) a path of child indices and \(k\) a key. Suppose that cutting the subtree at path \(p\) out of the \(i\)-th tree of the root list of \(H\) succeeds and extracts the subtree \(S\), and that \(k\) is at most the root of \(S\). Then find-min on the heap obtained from \(H\) by decreasing the key at root index \(i\) and path \(p\) to \(k\) returns \(\min(k, m)\).
public theorem decreaseKey_findMin [LinearOrder α] {heap : FibonacciHeap α} {i : Nat}
{p : List Nat} {newKey m : α} {sub : FibonacciTree α}
{rest : List (FibonacciTree α)}
(hcut : FibonacciForest.cutTreeAt heap.trees i p = some (sub, rest))
(hle : newKey ≤ sub.root) (hmin : heap.findMin = some m) :
(heap.decreaseKey i p newKey).findMin = some (min newKey m)
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
public inductive FibonacciTree (α : Type u) where
| node (degree : Nat) (root : α) (children : List (FibonacciTree α))
deriving Repr
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:44
@[expose] public def cutTreeAt (trees : List (FibonacciTree α)) (i : Nat) (p : List Nat) :
Option (FibonacciTree α × List (FibonacciTree α)) :=
match trees[i]? with
| none => none
| some t =>
match t.cutAt p with
| none => none
| some (sub, none) => some (sub, trees.eraseIdx i)
| some (sub, some t') => some (sub, trees.set i t')
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap/DecreaseKey.lean:387
Uses 13
TheoremDecrease-key yields a valid forest#✓fully proved
For every Fibonacci heap \(H\), root index \(i\), path \(p\) of child indices and key \(k\), the root list of the heap obtained from \(H\) by decreasing the key at root index \(i\) and path \(p\) to \(k\) is a valid forest, that is, every tree in it is valid.
This holds by construction: every Fibonacci heap carries a valid forest.
public theorem decreaseKey_valid [LinearOrder α] (heap : FibonacciHeap α) (i : Nat)
(p : List Nat) (newKey : α) :
FibonacciForest.Valid (heap.decreaseKey i p newKey).trees
public structure FibonacciHeap (α : Type u) [LinearOrder α] where
/-- The heap-ordered trees; root degrees may repeat between deletions. -/
trees : List (FibonacciTree α)
/-- The cached minimum element. -/
cachedMin : Option α
valid : FibonacciForest.Valid trees
min_eq : cachedMin = FibonacciForest.minRoot trees
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:644
@[expose] public def FibonacciForest.Valid {α : Type u} [LE α]
(trees : List (FibonacciTree α)) : Prop :=
∀ tree ∈ trees, tree.Valid
CSLibExt/Algorithms/Lean/DataStructures/FibonacciHeap.lean:228
Uses 4
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.