A nested countdown loop with a proved quadratic machine budget #
The fixed program reads n, executes inner loops of lengths n, n-1, ..., 1,
and outputs their total. Mathematical finite sums occur only in specifications
and proofs. The executed accumulator is incremented by actual RAM operations.
The inner loop uses the linear rule; the outer loop uses the finite-sum rule
because its body budget depends on the current counter.
Equations
- Ram.Examples.TriangularLoop.tri n = ∑ i ∈ Finset.range n, (i + 1)
Instances For
Instances For
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
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 inner loop adds its entry count to the accumulator without wrapping, and preserves the outer counter and I/O.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A complete outer iteration has a nonconstant body budget: the current outer counter is copied to the inner counter and determines the inner work.
Equations
Instances For
Equations
- Ram.Examples.TriangularLoop.StartInv n s = (Ram.Examples.TriangularLoop.OuterInv n s ∧ BitVec.toNat (s.regs 0) = n)
Instances For
Equations
- Ram.Examples.TriangularLoop.Post n s = (s.output = [BitVec.ofNat w (Ram.Examples.TriangularLoop.tri n)] ∧ s.input = [])
Instances For
The complete checked program outputs the mathematical triangular number. The explicit affine-in-the-sum bound includes its input, output, prologue, and halt.
A polynomial upper bound follows from mathlib's finite-sum comparison; no closed form with natural-number division is needed for the algorithm proof.
The published task takes the numeric value n as its size, not its binary
encoding length. Its fixed minimum word width and representable mathematical
input/output domain do not refer to any submission or instruction-list size.
The input contains only the zero heap header and n, never a precomputed sum.
Equations
- One or more equations did not get rendered due to their size.
Instances For
One fixed executable solves every legal input under a concrete quadratic transition budget, retaining its mathematical result and termination.
Equations
Instances For
A genuine mathlib-backed O((n+1)^2) certificate for this same machine
on the unbounded published domain. This is a numeric-size word-RAM claim,
not a bit-complexity or bit-linear claim.