Documentation

Examples.Language.ProgramCompiled

Uniform RAM time and space of native record programs #

The program is the same program% NativeAppend.append selected in the source example. Shared composition follows its actual generated packing, projections and calls. The existing array append supplies allocation, copying and their linear cost. No second append implementation, register proof or host conversion is provided.

The complete time theorem covers every mathematical input at every admitted word width. The shared width rules discharge input ranges, output allocation, code and stack capacity without adding them to the task's precondition.

For append, the preloaded input reservation is linear in the two array lengths. The actual instruction bound therefore also bounds the union of that reservation and all addresses accessed by the same invocation. The combined theorem retains its mathematical output, time and physical space in one execution. This is a conservative distinct-address footprint, not exact peak-live storage or a charge for input loading.

The lookup consumer combines two defaulted scalar reads and a branch at the actual intermediate heap. Its constant bound is for the preloaded invocation, including generated packing and calls, not for loading an entire input array.

theorem Complexity.Examples.TypedProgram.append_timeO :
append.TimeO (fun (x : AppendInput) => True) (fun (input : AppendInput) => input.left.size + input.right.size) fun (n : ℕ) => n

The actual high-level record program, including its packing entry, has uniform linear word-RAM time on all inputs, with no finite-capacity precondition.

theorem Complexity.Examples.TypedProgram.append_spaceO :
append.SpaceO (fun (x : AppendInput) => True) (fun (input : AppendInput) => input.left.size + input.right.size) fun (n : ℕ) => n

The original record append has uniform linear physical space, including its preloaded input prefix and every address touched by the actual invocation. The bound counts distinct addresses, not the capacity of the word address space.

theorem Complexity.Examples.TypedProgram.append_time_space_correct :
∃ (overhead : ℕ) (timeBound : ℕ → ℕ) (spaceBound : ℕ → ℕ), ((fun (n : ℕ) => ↑(timeBound n)) =O[Filter.atTop] fun (n : ℕ) => ↑n) ∧ ((fun (n : ℕ) => ↑(spaceBound n)) =O[Filter.atTop] fun (n : ℕ) => ↑n) ∧ ∀ (input : AppendInput) (w : ℕ), Program.width overhead input ≤ w → ∃ (depth : ℕ) (execution : append.Execution input w depth), (∃ (output : AppendOutput), execution.Represents output ∧ output.values = input.left ++ input.right) ∧ execution.result.steps ≤ timeBound (input.left.size + input.right.size) ∧ execution.spaceWords ≤ spaceBound (input.left.size + input.right.size)

Correctness and both uniform resource bounds hold for the same original append invocation and its actual returned value and final heap. No additional input-range, capacity or termination promise is required.

theorem Complexity.Examples.TypedProgram.lookup_timeO :
lookup.TimeO (fun (x : LookupInput) => True) (fun (input : LookupInput) => input.values.size + input.enabled.size) fun (x : ℕ) => 1

The existing high-level lookup has constant uniform word-RAM invocation time, including both defaulted reads and generated wrapper calls. Input arrays are preloaded by Program.TimeO; parsing or constructing them is not free work claimed by this theorem. No valid-index or extra element-range promise is used.

Borrowed row selection followed by scalar lookup has constant invocation time, even for empty or missing rows. Packing, calls, the branch and final arithmetic are included; constructing the preloaded input is not.