Measure-bounded memory-client while loops #
The source is finite recursion in the existing Memory.Prog. Its cutoff depends only on the
explicit initial input. A reached-state measure proves that the guard becomes false before the
cutoff, so the native code can use a genuine Code.loop without computing or storing that cutoff.
The native guard is an existing Cond on the faithfully encoded environment and mutable state;
an arbitrary semantic predicate is not granted executable code by a body certificate.
Local work counts only executed iterations. Every native guard, body, register copy and control instruction is charged, including the initial/final false guard and iterations without queries. Rank and potential may inspect reached memory as proof data; they never secretly select the source program or its initial cutoff from unencoded memory.
Main definitions #
boundedWhile: an early-exit loop represented by an ordinary finite memory program.whileSafe,whileWork: reached body domains, nontruncation and local iteration charges.
Main results #
whileSafe_of_measure: invariant and decreasing rank establish the nontruncating domain.boundedWhile_stops: the returned source value has a false guard.while_charge_le_potential: a potential pays memory and local work and retains exit credit.Realizes.whileBounded: one native emitter before every runtime input and width.Realizes.whileMeasure: semantic invariant/rank conditions discharge the native entry domain.
Finite source representation of a while loop. whileSafe excludes cutoff truncation.
Instances For
Only continuing states require the body domain. At the cutoff the guard must be false.
Instances For
Local body work and one control unit for each executed iteration. The final guard is paid by the existing realization overhead, even when no body executes.
Instances For
An initially false guard does not execute the body, independently of the ghost cutoff.
Every real continuation splits its exact memory cost and local control charge.
An invariant supplies the genuine body domain and a strictly decreasing reached-state rank. The source cutoff is sufficient when it initially bounds that rank. No rank is executed.
The reached-state domain guarantees a false guard at the actual returned source value, not merely a value obtained by truncating an unfinished loop.
The charged source cost telescopes while preserving the remaining exit potential. This can pay query-free iterations because local work and control are included in every step.
One native while emitter genuinely exits on the existing encoded condition. The pure source cutoff depends only on explicit initial input and is not computed or stored by this emitter. The domain excludes truncation; every executed guard/body/copy/control and final exit is charged.
Semantic invariants and a decreasing rank establish the native while's complete reached-state
domain. The rank/cutoff comparison is proof data; the emitted code still tests only cond.
Frontier-bounded native while realization.
Measure-bounded frontier-bounded while realization.