Real RAM to tape machine: quadratic-overhead compilation
OpenSmaleNinth.ram_to_bss_quadraticThis 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 of the real pointer machine there is a tape program and a constant such that, for every input (a function , used as the initial memory of and as the initial tape of ), every and every verdict : if halts with within steps, then halts with within steps.
Why quadratic suffices. Pointer registers of start at 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 steps every pointer, and every accessed cell, lies within distance of the origin, where 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 , which is for a suitable .
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.
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`. -/
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