Traversing a newly allocated native list #
The existing NativeLists.reverseSum first allocates an actual reversed list,
then traverses that returned list with the existing addition callback. Source
correctness transports the mathematical List observation across the first call;
the same observation selects the second call's length-dependent cost certificate.
No decoder, second implementation or per-consumer register proof is introduced.
The final RAM theorem retains the same actual heap and allocation cursor. The original list remains observable. A final-sum range supplies all addition ranges; the additional arena allowance is three words per original element.
The shared fold envelope uses the original addition callback's proved cost. Call-frame and traversal coefficients belong to the library, not this consumer.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Select the actual sum-fold certificate at its mathematical input length. The callback's ordinary range domain is retained, separately from correctness.
Infer both actual calls' costs, carrying the first call's source postcondition to the new list's cost proof. The source declaration itself and its mathematical correctness theorem remain unchanged.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The inferred body envelope adds the actual outer invocation and final halt once. Both inner traversals and their callbacks are already included.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The inferred complete invocation bound is affine in length. This identity states that fact without introducing another set of compiler coefficients.
The proved whole-invocation envelope is linear in the input length,
using mathlib's ordinary IsBigO, not a separate complexity predicate.
Compose existing measured calls at their actual returned heap and cursor. The independent reverse specification supplies the List observed by the fold.
Compose the actual allocating reverse with the scalar fold at its actual returned heap and cursor. The second traversal reserves no additional words.
The native allocation-then-traversal program halts on RAM with values.sum.
The original List remains observable in the same final heap. The instruction
bound covers both traversals, initialization, calls, returns and halt; input
loading is excluded. The cursor bound concerns cumulative fresh allocation,
not exact peak live storage or reclamation.