Source-faithful native sift-down #
The existing memory program supplies the array reads, swap and order proof. A finite while view preserves its complete free-monad program. Its logarithmic cutoff is proof data, while native code tests the actual index against a charged prepared threshold. No runtime logarithm or fuel register is supplied for free. The initially-zero index exits before threshold preparation. The compiler handles the original named priority and non-strict right-child guards directly.
Main results #
finish_loop_eq: the while view is the complete original memory program.step_triple: the existing heap shape survives each body and the logarithmic rank drops.realizes_siftDown: one uniform compiler-generated emitter with charged glue and control.exec_siftDown: the original order repair, whole-memory result and frame in logarithmic unit-cost exact-basis instruction time, on the explicit allocated/word-bounded input domain.
The source heap invariants and order proof are reused, not a new heap algorithm or model.
Layout, size and one control word: a threshold inside the loop, an index at entry.
The number of handles.
The heap layout.
The number of occupied heap positions.
The control word: the prepared threshold inside the loop, the start index at entry.
The original four-write sink, returning the selected child or a stop sentinel.
Four reads, two additional right-child reads when present, and exactly the source swap.
Actual scalar native guard; the threshold is computed by preceding certified glue.
Instances For
Forgetting the final index preserves the exact source, including every query and write. The cutoff is an input-only logarithmic bound, and it never truncates on this domain.
Reached loop indices are occupied positions or the stop sentinel S+1. The original
whole-memory heap shape and allocated array block remain explicit.
The logarithmic distance to the last occupied level.
Each continuing body keeps the existing shape and strictly decreases its ghost rank. It uses at most four ordinary reads, two right reads and the original four-write swap.
The shared compiler certifies the exact physical body; all fit obligations follow from
allocated storage and the original heap shape, including the sentinel S+1.
The source cutoff suffices: rank zero stops, and every real body strictly drops rank. The actual returned index may be the fitted sentinel, never a hidden truncated continuation.
The queryful body pays each real loop iteration's control, including all early exits.
The original source storage/shape domain, admitting index zero as an immediate exit.
The existing source sift-down has one fixed native emitter before every runtime layout,
size, start index, width and memory. Zero exits before division; otherwise threshold preparation,
all guard/control operations, body glue and final Unit return are certified and charged.
The local loop certificate lets realize prepare the threshold and wire the call.
The exact source's logarithmic order repair and rearrangement lift to one uniform native code witness. The caller supplies already installed arguments, word bounds and an allocated heap; loading arbitrary external storage is outside this operation clock.