An optional stream driver for factorial #
This program reads one word, calls the independently defined factorial function, and writes its result. It reuses that function's correctness and time theorems without changing its declaration or requiring a second implementation.
The whole-program execution includes the input header, input/output instructions, call overhead and halt. Its result is factorial modulo the word range; an exact natural-number result additionally requires that factorial fits in one word. The linear time bound uses the numeric input, not its binary encoding length.
An optional stream adapter around the independently defined function.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
The actual input/call/output program uses the callable mathematical model without an instruction budget. The word result retains its modular meaning.
Verify the complete input/call/output workflow using only the recursive contract and WP rules. No measured-execution constructor is used here.
The complete source program consumes one input and emits one result.
One fixed finite instruction list is used for every runtime input.
Equations
Instances For
The code contains one recursive function body, not k unrolled copies.
The independent contract proof compiles to the same halted executable and whole-program budget as the exact trace proof below.
Exact whole-program execution, including argument evaluation, individual
frame saves/restores, return jumps, the stack-header read, and the final halt.
The input starts with the ABI stack header H, followed by the user's k.
There are no heap reads in this program, so any nonnegative boundary works.
The emitted word decodes to exactly factorial modulo 2^w, for every
legal input, including inputs whose factorial does not fit in one word.
If the mathematical factorial fits as well, the same execution returns that exact natural number, without a modular reduction in its specification.
External input representation: an empty-heap stack header, then the input number as one unsigned word. Encoding is not an extra machine instruction.
Equations
- Ram.Examples.FactorialStream.encode w k = [0#w, BitVec.ofNat w k]
Instances For
Space for the fixed code and all simultaneously live recursive frames. This also ensures that the input number itself has an exact word encoding.
Instances For
A uniform bound for the same code at every admissible input and width, with the ordinary terminating RAM execution judgment as its meaning.
Linear time in the numeric value k, uniformly over admissible widths.
This is not linear time in the binary encoding length of k (nor in the
number of input words, which is constant for this particular interface).