Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Real RAM to tape machine: quadratic-overhead compilation

Open
SmaleNinth.ram_to_bss_quadratic

by Zexuan Liu · Sep 7, 2026 · Mathlib 0df444a (Lean v4.33.1)

bss-machinecomputational-complexityreal-computation

This theorem says that the random-access model and the tape model of the mission are polynomially equivalent in the direction that matters for the goal: an algorithm written for the real pointer machine can be run on the tape machine with at most quadratic slowdown.

The assertion. For every program RRR of the real pointer machine there is a tape program PPP and a constant KKK such that, for every input xxx (a function Z→R\mathbb{Z} \to \mathbb{R}Z→R, used as the initial memory of RRR and as the initial tape of PPP), every TTT and every verdict bbb: if RRR halts with bbb within TTT steps, then PPP halts with bbb within K (T+1)2K\,(T+1)^2K(T+1)2 steps.

Why quadratic suffices. Pointer registers of RRR start at 000 and change by at most one per step, apart from being set to one of the finitely many constants of the program; hence during a run of TTT steps every pointer, and every accessed cell, lies within distance T+K0T + K_0T+K0​ of the origin, where K0K_0K0​ is the largest pointer constant. The tape program keeps the real registers and the pointer registers (as reals) in a fixed window of cells next to its head, together with the current position of its head; a memory access load or store is simulated by walking the head to the pointer's cell, which costs a number of shifts proportional to the distance, each shift accompanied by a fixed number of copies that slide the register window along without destroying the tape contents. Every other instruction is simulated by a constant number of tape instructions. The total is O(T⋅(T+K0))O(T \cdot (T + K_0))O(T⋅(T+K0​)), which is K(T+1)2K(T+1)^2K(T+1)2 for a suitable KKK.

Purpose. Combined with a strongly polynomial algorithm in the random-access model (SmaleNinth.smale_ninth_real_ram), this theorem yields the goal theorem of the mission; conversely it shows that the choice of the tape machine as the mission's model costs at most a squaring of the running time relative to the model in which algorithms are normally written.

Retired. This formulation quantifies over inputs with arbitrary contents on the negative cells, where the simulating tape program must place its register window; on a tape whose every cell carries live input the program has no scratch space, so the statement as written is not the intended one. It is replaced by SmaleNinth.ram_to_bss_quadratic_nonneg, which assumes the input vanishes on negative cells (as encodeLP does) and suffices for the reduction of the goal theorem.

Preamble
import Definitions.Def_SmaleNinth_BSSMachine
import Definitions.Def_SmaleNinth_RealRAM

/-!
Compilation of the real pointer machine to the tape machine with quadratic
overhead.

Source: the standard simulation of a random-access machine by a one-tape
machine (cf. J. E. Hopcroft, J. D. Ullman, *Introduction to Automata Theory,
Languages, and Computation*, Addison-Wesley 1979, §7.6, and L. Blum,
F. Cucker, M. Shub, S. Smale, *Complexity and Real Computation*, Springer
1998, Chapter 3, on machines over `ℝ` with and without indirect addressing),
adapted to the fixed-address tape machine `Definitions.Def_SmaleNinth_BSSMachine`.
Pointers move by at most one per step, so a run of `T` steps accesses only
cells within distance `T` plus the largest pointer constant of the program;
the tape machine keeps the registers in a window next to its head and walks
to each accessed cell, costing `O(T)` per access and `O(T²)` in total.
-/

open Matrix

/-- **Compilation theorem.** Every program of the real pointer machine is
simulated by a tape program with quadratic overhead: if `R` halts on input
memory `x` with verdict `b` within `T` steps, the tape program `P` halts on
the tape `x` with the same verdict within `K·(T+1)²` steps, for a constant
`K` depending only on `R`. -/
Formal statement
theorem SmaleNinth.ram_to_bss_quadratic (R : RAMProgram) :
    ∃ (P : BSSProgram) (K : ℕ), ∀ (x : ℤ → ℝ) (T : ℕ) (b : Bool),
      RAMDecidesInTime R x T b → BSSDecidesInTime P x (K * (T + 1) ^ 2) b := by sorry
Source
Simulation of random-access machines by one-tape machines: Hopcroft-Ullman, Introduction to Automata Theory, Languages, and Computation, 1979, Section 7.6; Blum-Cucker-Shub-Smale, Complexity and Real Computation, 1998, Chapter 3 (machines over R with indirect addressing); adapted to Definitions.Def_SmaleNinth_BSSMachine and Definitions.Def_SmaleNinth_RealRAM.

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me