Documentation

CslibFrontier.Computability.WordRAM.Turing.Overhead

Explicit overhead of the word-RAM simulation by Turing machines #

Program.ComputesInTime.turingComputableInPolyTime_of_width simulates a word-RAM program by a multi-tape Turing machine in polynomial time of unnamed degree. Here the degree is explicit. If every primitive of the basis has degree d (Model.NativePrimitives.HasDegree), a run of at most T instructions on n input words at word size w costs O((T + 1) · ((n + T + 1)(w + 1)) ^ max 3 d) machine steps, on top of computing the word size, the input words and the step budget. Only the constant factor is hidden. For Basis.additive, whose primitives are quadratic (Basis.additive.quadraticPrimitives), the exponent is 3. The cube comes from scanning the association-list memory of the simulator (SparseMemory.scanTime_le_cube), not from the word-RAM model.

The simulation is the same as in CslibFrontier.Computability.WordRAM.Turing. The new ingredients are the degree-tracking certificates of CslibFrontier.Computability.GenericRAM.Simulation.Degree, a cubic initialization certificate (initMemory_degree, a counted fold), and quadratic certificates for the conventions of CslibFrontier.Computability.WordRAM.Invariance with logarithmic word size: the bit list of the input as words (bitsToNats_degree) and the word size k (size n + 1) (logWidthBound_degree).

Main results #

References #

Encoded lengths #

A word list that fits w-bit words has encoded length at most n (2 w + 1).

theorem Cslib.WordRAM.stateBound_le (r L w E : ℕ) :
stateBound r L w E ≤ (2 * (Turing.MultiTapeTM.encNat L).length + 4 * r + 14) * ((E + 1) * (w + 1))

stateBound is linear in the number of stored cells and in the word size.

Initialization with an explicit degree #

One step of the counted fold that builds the stored cells of State.init.

theorem Cslib.WordRAM.foldl_initStep (l : List ℕ) (k : ℕ) (acc : List (ℕ × ℕ)) :
List.foldl initStep (k, acc) l = (k + l.length, acc ++ List.map (fun (e : ℕ × ℕ) => (e.2 + 1, e.1)) (l.zipIdx k))

The stored cells of State.init as the result of the counted fold.

The simulation with an explicit degree #

theorem Cslib.WordRAM.Program.ComputesInTime.computableInO_of_width {B : Basis} {r : ℕ} {α : Type} {encIn : α ↪ List Bool} {N : B.genericModel.NativePrimitives B.encoding} {d : ℕ} (hN : N.HasDegree d) {p : Program B r} {encode : ℕ → α → List ℕ} {time : α → ℕ → ℕ} {allowed : α → ℕ → Prop} {f : α → ℕ} (h : p.ComputesInTime encode time allowed f) {width steps Tw Sw Te Se Ts Ss : α → ℕ} (hwidth : Turing.MultiTapeTM.ComputableInO width encIn Turing.MultiTapeTM.encUnary Tw Sw) (hallowed : ∀ (a : α), allowed a (width a)) (hfits : ∀ (a : α), InputFits (width a) (encode (width a) a)) (hencode : Turing.MultiTapeTM.ComputableInO (fun (a : α) => encode (width a) a) encIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encNat) Te Se) (hsteps : Turing.MultiTapeTM.ComputableInO steps encIn Turing.MultiTapeTM.encNat Ts Ss) (htime : ∀ (a : α), time a (width a) ≤ steps a) :
Turing.MultiTapeTM.ComputableInO f encIn Turing.MultiTapeTM.encNat (fun (a : α) => (encIn a).length + Tw a + Te a + Ts a + (steps a + 1) * (((encode (width a) a).length + steps a + 1) * (width a + 1)) ^ max 3 d) fun (a : α) => (encIn a).length + Sw a + Se a + Ss a + (((encode (width a) a).length + steps a + 1) * (width a + 1)) ^ max 3 d

Word-RAM time gives Turing-machine time with an explicit polynomial overhead.

Let every primitive of the basis have degree d (Model.NativePrimitives.HasDegree), and let p compute f (Program.ComputesInTime). Suppose a machine computes the word size width a in unary in time O(Tw a), the input words encode (width a) a in time O(Te a) and a step budget steps a ≥ time a (width a) in binary in time O(Ts a); the word size must be admitted and the input words must fit it. Then f is computable with binary output in time O(|encIn a| + Tw a + Te a + Ts a + (steps a + 1) · R ^ max 3 d), where R = (n + steps a + 1) · (width a + 1) and n is the number of input words. The degree is explicit; only the constant factor is hidden.

theorem Cslib.WordRAM.Program.ComputesInTime.computableInO_of_width_additive {r : ℕ} {α : Type} {encIn : α ↪ List Bool} {p : Program Basis.additive r} {encode : ℕ → α → List ℕ} {time : α → ℕ → ℕ} {allowed : α → ℕ → Prop} {f : α → ℕ} (h : p.ComputesInTime encode time allowed f) {width steps Tw Sw Te Se Ts Ss : α → ℕ} (hwidth : Turing.MultiTapeTM.ComputableInO width encIn Turing.MultiTapeTM.encUnary Tw Sw) (hallowed : ∀ (a : α), allowed a (width a)) (hfits : ∀ (a : α), InputFits (width a) (encode (width a) a)) (hencode : Turing.MultiTapeTM.ComputableInO (fun (a : α) => encode (width a) a) encIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encNat) Te Se) (hsteps : Turing.MultiTapeTM.ComputableInO steps encIn Turing.MultiTapeTM.encNat Ts Ss) (htime : ∀ (a : α), time a (width a) ≤ steps a) :
Turing.MultiTapeTM.ComputableInO f encIn Turing.MultiTapeTM.encNat (fun (a : α) => (encIn a).length + Tw a + Te a + Ts a + (steps a + 1) * (((encode (width a) a).length + steps a + 1) * (width a + 1)) ^ 3) fun (a : α) => (encIn a).length + Sw a + Se a + Ss a + (((encode (width a) a).length + steps a + 1) * (width a + 1)) ^ 3

The additive word RAM, with the exponent 3. A run of Basis.additive within steps a instructions on n input words at word size w costs O(|encIn a| + Tw a + Te a + Ts a + (steps a + 1) · ((n + steps a + 1)(w + 1)) ^ 3) Turing-machine steps; see Program.ComputesInTime.computableInO_of_width.

The bit-list convention with logarithmic word size #

Multiplying a unary number by a constant is linear.

The word size k (size n + 1) of an input of length n, in unary, in quadratic time. It is at least the logarithmic threshold logWidth k n.

The logarithmic threshold is at most the word size k (size n + 1).

The bits of an input of length n fit words of k (size n + 1) bits when k ≥ 1.