Forest invariants and pure state transitions for a Fibonacci heap #
This file lifts the single-tree model of Trees.lean to the full multi-root forest invariant
FibRawInv and proves the structural transitions required by all priority-queue operations:
- Subtree cutting (
exists_parent_info,ValidSubtree.exists_cut): Severing a non-root nodecurfrom its parentpsplitsTinto a new valid root treeT_cutrooted atcurand a modified treeT'withpending = some pwhile preserving the multiset of tree nodes. - Full heap invariant (
FibRawInv): Relatess : IndexedMinPQ.State ntost : RawState nwith exact domain, key, size, root-count, marked-count,minRoot, andcons-zeroing invariants, provingIndexedMinPQ.findMinagreement (FibRawInv.findMin_eq_some) and scalar bounds. - Transient cut invariant (
CutInv): Loop invariant for cascading cuts duringdecreaseKey, allowing a singlependingancestor whose child was just severed. - Lowering a key (
ValidSubtree.lower_key_no_cut,CutInv.to_fibRawInv): a lowered key keeps a subtree valid while it does not precede its parent, andCutInvwithout a pending node becomesFibRawInvonceminRootis updated. - Consolidation table invariant (
SlotInv): the trees stored incons[0..maxDeg]while consolidating at mostsznodes, with pairwise-distinct degrees,maxDeg ≤ 2 * Nat.log 2 sz + 1, and every unoccupied entrycons[d](d ≤ n) zero.
Main definitions #
Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.FibRawInv: full multi-root forest representation invariant relatingIndexedMinPQ.State ntoRawState n.Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.CutInv: transient forest invariant during cascading cuts indecreaseKey.Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.SlotInv: consolidation-table invariant tracking distinct-degree root trees incons[0..maxDeg].
Main results #
Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.ValidSubtree.exists_cut: severing a non-root node splits its enclosing tree into a valid root tree and apending-parent tree.Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.FibRawInv.findMin_eq_some:minRootidentifies the exactIndexedMinPQ.findMinelement.
References #
List surgery lemmas for child removal and replacement #
Parent witnesses and subtree cutting #
Every strict descendant x of T has st.par x = q.val + 1 for some q ∈ T.nodes.
Updating only the root's mark to a value ≤ 1 while keeping all other subtree fields fixed
preserves ValidSubtree.
Pre-cut structural properties of cur and its parent p inside any valid subtree containing
cur as a strict descendant.
Cutting a strict descendant cur (with st.par cur = p.val + 1) from T splits T into a
new root tree T_cut (T_cut.root = cur) and a pruned tree T' (T'.root = T.root,
p ∈ T'.nodes) satisfying ValidRoot st' none T_cut and ValidSubtree st' (some p) T'.
Marking an unmarked pending = some z node (st.mark z = 0, st'.mark z = 1) absorbs the
transient rank slack and restores ValidSubtree st' none T.
Full heap representation invariant and core consequences #
Full structural, key, counter, and root-list invariant relating s : IndexedMinPQ.State n to
st : RawState n.
Transient forest invariant during decreaseKey v k while cascading cuts propagate from
pending.
FibRawInv holds on the empty priority queue whenever inHeap and cons[0..n] are zeroed and
the four scalar counters are 0.
All scalar counters of a valid Fibonacci heap are bounded by n.
Concrete state uniquely determines the represented IndexedMinPQ.State n.
When st.minRoot = 0, dom s = ∅ and IndexedMinPQ.findMin s = none.
When st.minRoot = z.val + 1, IndexedMinPQ.findMin s = some (z, st.key z).
Forest facts used by several operations #
In any Nodup forest ts, no strict descendant x ∈ forestNodes T.children (T ∈ ts) can
equal the root of any tree R ∈ ts.
Framing and pure-ℕ degree bounds during consolidation #
Framing ValidRoot st none T across a state transition preserving node fields on T.nodes and
pointer fields on strict descendants forestNodes T.children.
Framing ValidRoot st none T when all eight vertex arrays agree on T.nodes.
Every valid subtree T with T.size ≤ sz disjoint from at least one other handle z : Fin n
satisfies both T.deg ≤ 2 * Nat.log 2 sz + 1 and T.deg + 2 ≤ n.
Framing SlotInv across a transition preserving cons and ValidRoot on slotTrees.
Lookup in st.cons d (d ≤ n): either st.cons d = 0 and no tree in slotTrees has degree
d, or a unique index i < slotTrees.length has (slotTrees[i]).deg = d and
st.cons d = (slotTrees[i]).root.val + 1.
Clearing slot d = (slotTrees[i]).deg (d ≤ n) removes slotTrees[i] from SlotInv.
Storing a consolidated tree T_cur of unoccupied degree d into st.cons d and updating
maxDeg to max maxDeg d inserts T_cur into SlotInv.
Once every degree < maxDeg + 1 has been cleared from SlotInv, slotTrees = [] and all
entries st.cons d (d ≤ n) are 0.
Lemmas for decreaseKey #
In a valid subtree with Nodup nodes, no strict descendant v is its own parent.
Lowering key[v] to k ≤ st.key v preserves ValidSubtree st' none T whenever v = T.root or
v has parent p (st.par v = p.val + 1) with ¬IndexedMinPQ.PrioLT (v, k) (p, st.key p).
Once cascading cuts finish (pending = none) and minRoot is updated against (v, st.key v),
CutInv upgrades back to FibRawInv.