Native realization of the memory heap's sift-up #
The source is the existing memory-oracle sift-up, including its four reads and four-write swap.
A finite while view uses an input logarithmic cutoff only to prove termination; the native loop
exits on its actual index guard. This primitive supports the binary-heap migration; it does not
by itself supply the complete heap interface or its initialization contract. Bounds count
unit-cost .exact word-RAM instructions, with fitting words and the explicit installed-argument
ABI. They are not bit-operation bounds.
Main results #
finish_loop_eq: the finite while view is the original free-monad program, not only an equal-result implementation. Its complete operation history and memory charge are preserved.realizes_siftUp: shared compiler and while rules supply one uniform native realization.exec_siftUp: native instruction time is logarithmic, with the source's order repair, exact whole-memory state and caller-register frame.
The heap source and its invariant proofs are reused from BinaryHeap.Memory; no heap algorithm
or machine semantics is redefined here.
The loop environment: the runtime layout and a prepared constant-one word.
The number of handles.
The heap layout.
Four original reads, followed by the original priority test, swap or stop index.
The loop state is a one-based position; returning 1 terminates without another read.
Instances For
The while view preserves the entire existing siftUp free-monad program.
The existing heap-shape invariant is sufficient for each sift step. Order repair remains
in the source's siftUp_triple, rather than being reproved for a native implementation.
One real step preserves heap shape and drops the logarithmic rank. Its eight-unit bound uses the original four-read/four-write source trace, including the no-swap early exit.
Eight source-memory units and one continuing-control unit per logarithmic rank level. Unused cutoff steps are not charged as iterations; exit potential is retained.
One fixed compiler-generated step body before all runtime layouts, widths and indices. Local straight-line computation is absorbed into the uniform realization factor.
The actual index guard selects a native early exit; the logarithmic cutoff is proof data.
No register contains a fuel counter or a computed logarithm. The source guard 2 ≤ k is tested
as 1 < k, using the prepared constant-one word.
Actual reached loop controls, plus two binds. Constant preparation and the Unit return are certified native glue, absorbed into the same fixed exchange factor.
The queryful source pays every executed loop control. Bounded preparation/finish work is
absorbed into one fixed factor, so call sites may use the standard zero-work certificate.
This does not discard a query-free or arbitrary grading. The local loop certificate lets
realize prepare the constant-one word and wire the call.
The actual combined currency is logarithmic. The premise is admissibility of the original program's complete history, not an assumed cost of a different implementation.
One fixed native emitter repairs a sift-up defect in logarithmic instruction time. The
complete whole-memory result and live-register frame come from Realizes; order repair and
history admissibility come from the original source theorem. Arguments are already installed
in the stated register ABI. This bound does not include loading an arbitrary external heap.