Indexed binary heap: sift-up correctness and running time
ProvedBinaryModuleAnalysis.sift_up_loopLet heap contain an allocated indexed min-heap object queue with valid storage layout, mutually inverse vertex/position arrays on its active prefix, and an index , where is the active size. Sifting upward terminates from any configuration at the corresponding loop location. It preserves that layout, indexing, membership, keys, unrelated storage, and every clock except heap comparisons and swaps. If UpInvariant holds initially, the final heap is ordered.
Writing , each of heap_comparisons and heap_swaps increases by at most . The public CallFrom conclusion permits an arbitrary caller stack. This local loop theorem is the proof boundary reused by insertion.
Costs count the named source ticks over mathematical integers and total integer-indexed sequences. They are not wall-clock time, bit complexity, or a count of every arithmetic operation, access, allocation, or compiler transition. Counters may start at arbitrary values; bounds refer to the increments during this call.
<!-- algo2lean-provenance-v0.1.4 -->Algo2Lean provenance and reproduction. These definitions target Algo2Lean v0.1.4, using the compiler source at public commit 0f79d5e4242e6477531c9ee4410409f5b1c92f76, and Lean 4.33.1. The versioned compiler location is Algo2Lean v0.1.4. Compile all supplied .algo files and imports to reproduce the raw generated definitions. Release publication and exact website parity require their separately recorded checks; this metadata alone does not assert them. Prove2Me imports and declaration packaging are mechanically adapted, with original hashes, compiler-reported source ranges, and adaptations recorded in transplant provenance. Exact reproduction does not prove the compiler correct.
import Definitions.Def_Algo_indexed_heap_Analysis set_option autoImplicit true set_option backward.isDefEq.respectTransparency false set_option backward.defeqAttrib.useBackward true set_option autoImplicit false
theorem BinaryModuleAnalysis.sift_up_loop :
∀ (heap : Algo2LeanGenerated.Heap) (queue : Algo.indexed_heap.Algo2LeanGenerated.Ref_MinHeap)
(layout : BinaryModuleAnalysis.Layout) (index : Int),
layout.Valid heap queue →
BinaryModuleAnalysis.Indexed (heap.read layout.vertices) (heap.read layout.positions)
layout.size →
LE.le.{0} (0 : Int) index →
LT.lt.{0} index layout.size →
Exists.{1} fun after =>
(∀ (state : Algo.indexed_heap.Algo2LeanGenerated.Configuration),
BinaryModuleAnalysis.AtSiftUp state queue index →
Eq.{1} (Algo2LeanCore.Config.heap.{0, 0, 0} state) heap →
Algo.indexed_heap.MinHeap.sift_up.CallFrom state after ()) ∧
layout.Valid after queue ∧
BinaryModuleAnalysis.Indexed (after.read layout.vertices)
(after.read layout.positions) layout.size ∧
LE.le.{0} (after.clocks "heap_comparisons")
(HAdd.hAdd.{0, 0, 0} (heap.clocks "heap_comparisons")
(BinaryModuleAnalysis.depth index)) ∧
LE.le.{0} (after.clocks "heap_swaps")
(HAdd.hAdd.{0, 0, 0} (heap.clocks "heap_swaps")
(BinaryModuleAnalysis.depth index)) ∧
(BinaryModuleAnalysis.UpInvariant
(fun position =>
heap.read layout.keys (heap.read layout.vertices position))
layout.size index →
BinaryModuleAnalysis.Ordered
(fun position =>
after.read layout.keys (after.read layout.vertices position))
layout.size) ∧
(∀ (ref : Algo2LeanGenerated.SeqRef),
Ne.{1} ref layout.vertices →
Ne.{1} ref layout.positions →
∀ (position : Int),
Eq.{1} (after.read ref position) (heap.read ref position)) ∧
(∀ (vertex : Int),
LE.le.{0} (0 : Int) (after.read layout.positions vertex) ↔
LE.le.{0} (0 : Int) (heap.read layout.positions vertex)) ∧
(∀ (name : String),
Ne.{1} name "heap_comparisons" →
Ne.{1} name "heap_swaps" →
Eq.{1} (after.clocks name) (heap.clocks name)) ∧
BinaryModuleAnalysis.OtherStoragePreserved heap after := by
sorry