Fibonacci-heap decreaseKey over a record of named cells #
decreaseKey n v k lowers the key of v. If v would precede its parent, cut moves v to the
root list, and cascade walks up the ancestors: a marked ancestor is cut in turn, the first
unmarked one is marked Fredman and Tarjan
Cormen et al., Section 19.3. Then setKey stores the key and makes v the minimum
root if it precedes it. Cutting before storing the key keeps every tree valid throughout. (The
hand-stepped decreaseKeyCode stores the key first; its proof reads the forest with the old keys,
through CutsNode.withKey.)
The proof splits as in Basic.lean:
- program evaluation:
wp_unlink,wp_toRootandwp_cutproduce the effectCutsNodeof one cut on the raw view (as the hand-steppedcutNodeCode_rawdoes);wp_cascaderuns the cascade by induction on its fuel, which exceeds the number of marks;wp_setKeyandwp_decreaseKeyassemble the three cases (root, no cut, cut); - forest mathematics on
RawState nalone:cutsNode_cutState(pointer surgery of one cut),CutsNode.cascading(a cut keeps the forestCascading),Cascading.clear_rootandCascading.mark(the cascade stops),Cascading.lowerRootKeyandFibRawInv.lowerKey_noCut(storing the key), with the existingValidSubtree.exists_cut,ValidSubtree.mark_pending,ValidSubtree.lower_key_no_cutandCutInv.to_fibRawInv.
Each cascading cut costs at most 22 record operations and turns a marked non-root into an
unmarked root, which releases credit = 24, so the cascade is paid by the potential and
decreaseKey costs at most 104 operations amortized.
The module adapts Renfei Zhou's native formalization (WordRAM/FibonacciHeap, its Cut.lean) to
the record level: his cut (cutNodeCode_raw and its forest transition, with its circular-list
uniqueness argument) and cascading-cut development become cut, CutsNode.cascading,
IsCircList.tail_unique and cascade, and his forest lemmas are reused unchanged. The
hand-stepped proofs in turn now cite these lemmas.
Main definitions #
unlink,toRoot,cut,cascade,setKey,decreaseKey: record programs.CutsNode,cutState: the effect of one cut on the raw view.Cascading: the forest during cascading cuts, with one pending ancestor.
Main results #
IsCircList.tail_unique: a circular list is determined by its head.wp_cut: a cut evaluates toCutsNodein at most20operations.CutsNode.cascading: a cut keeps the forestCascading, with the parent pending.wp_cascade: the cascade costs at most53operations plus the potential it releases.wp_decreaseKey:decreaseKeyimplementsIndexedMinPQ.stepwith amortized cost104.
References #
Programs #
Unlink z from the child list of its parent p.
Make the unlinked node z an unmarked root after the minimum root.
Cut z from its parent p: unlink z from p's child list, splice it into the root list
after the minimum root, and clear its parent and mark.
Store the lowered key k of v, and make v the minimum root if it precedes it.
Lower the key of v to k on a heap of n handles: if v now precedes its parent, cut it
and cascade from the parent; then store the key and update the minimum root.
The effect of cutting cur from its parent p when the root list is m :: rtail: the facts
of the hand-stepped cutNodeCode_raw, on the raw view.
- child_two (h : Fin n) (tail : List (Fin n)) : 2 ≤ st.deg p → st.child p = ↑h + 1 → WordRAM.FibonacciHeap.IsCircList st.left st.right (h :: tail) → cur ∈ h :: tail → ∃ (r : Fin n) (rest : List (Fin n)), st'.child p = ↑r + 1 ∧ WordRAM.FibonacciHeap.IsCircList st'.left st'.right (r :: rest) ∧ (r :: rest).Perm ((h :: tail).erase cur)
The state after a cut, given the sibling pointers left₁, right₁ and p's child pointer
child₁ after unlinking cur, and the old right neighbour r' of the minimum root m.
A circular list is determined by its head: from first, the right pointers trace it.
A circular list is determined by its head.
The effect of a cut, from p's child pointer and the sibling pointers after unlinking
cur (hunlink) and the old right neighbour r' of the minimum root m.
A cut does not read or write keys: it has the same effect on states with other keys.
After cur is unlinked from its parent p, the minimum root m still has a right neighbour:
unlinking changes sibling pointers only among p's children.
Forest mathematics of cascading cuts #
The forest during cascading cuts from v: FibRawInv with one pending ancestor that may
have lost a child, and with the minimum-root comparison waived for v. With v a root, this is
the existing CutInv.
- nodup : (WordRAM.FibonacciHeap.forestNodes ts).Nodup
With v a root, Cascading is the existing CutInv.
A valid heap is Cascading with nothing pending.
In a valid subtree with distinct nodes, every node has fewer children than the tree has nodes.
A cut keeps the forest Cascading, with the parent p now pending. The cut node cur
becomes the root of a new tree; its old tree loses that subtree.
A node of the forest with a parent p is a strict descendant of its tree.
The preconditions of a cut of a non-root cur from its parent p, as wp_cut takes
them.
The cascade stops at a root: a pending root has lost nothing that matters.
The cascade stops at an unmarked node, which it marks.
Lowering the key of the root v keeps every tree valid, and with v a root the forest
satisfies the existing CutInv, ready for the minimum-root update.
Lowering a key without a cut. If v keeps its heap order with its parent p, the heap
stays valid, and v cannot precede the minimum root.
Splicing u after h, whose right neighbour is r, makes four writes.
Unlinking cur from p's children evaluates to the two cases of cutsNode_cutState.
Moving the unlinked cur to the root list after the minimum root m, whose right neighbour
is r', makes thirteen operations.
One cut. Cutting cur from its parent p evaluates to CutsNode in at most 20
operations. The hypotheses are those of the hand-stepped cutNodeCode_raw.
Cascading cuts. From a forest with z pending, the cascade leaves a forest with nothing
pending. Each cut costs at most 22 operations and releases one credit (one more root, one mark
less), so the whole cascade costs at most 53 operations plus the potential it releases.
Storing the key. With the forest ready (v a root, or v not preceding the minimum
root), storing the key and updating the minimum root restores FibRawInv.
Decreasing a key. decreaseKey n v k lowers the key of the present handle v to k,
preserves the invariant, and costs at most 104 operations amortized.