Documentation

CslibFrontier.Computability.WordRAM.Turing.ListOutput

Word-RAM list outputs give Turing-machine polynomial time #

A fixed word-RAM program that returns a list (Program.ComputesListInTime: halt returns the address of a length-prefixed array) within polynomially many instructions gives a multi-tape Turing machine computing the same list-valued function in polynomial time, with output encList encNat. This extends CslibFrontier.Computability.WordRAM.Turing from word outputs to list outputs.

Construction #

The simulating machine runs the parked program p.parkHalts for its full step budget with the clocked finite-state simulator FiniteState.run, whose native certificate is polynomial by Cslib.GenericRAM.FiniteState.runCertificateOf_isPolynomial. Since the parked program never halts, the run ends in a continuing state holding the memory just before p halted, and its control label p.length + i records the output register i (ExecutesList.runs_parkHalts). The machine then selects that register by comparing labels (parkedRegister), reads the array length L at the returned address and iterates L single-cell reads (readRound), each a scan of the sparse memory. Everything is charged: the step budget, word size, input words and initial memory as in the word-output simulation, then the run, the selection and the L reads.

Conventions and limits #

The cost model, input convention and word-size choice are those of CslibFrontier.Computability.WordRAM.Turing. The output length must be polynomially bounded in the encoded input length (hlen). This hypothesis is necessary, since a polynomial-time machine writes polynomially many output bits, and it does not follow from the instruction bound: the returned array may consist of cells that are never written and read as 0, so its length is bounded only by 2 ^ w.

Main definitions #

Main results #

References #

Reading the output of a parked state #

The register recorded by a parked control label: register i at label L + i, the first match among l, or 0 if none matches.

theorem Cslib.WordRAM.parkedRegister_eq {B : Basis} {r L : ℕ} {s : GenericRAM.FiniteState B.genericModel r} {i : Fin r} (hpc : s.pc = L + ↑i) {l : List (Fin r)} :
i ∈ l → parkedRegister L s l = s.regs i
theorem Cslib.WordRAM.parkedRegister_lt {B : Basis} {r L w : ℕ} {s : GenericRAM.FiniteState B.genericModel r} (hs : ∀ (i : Fin r), s.regs i < 2 ^ w) (l : List (Fin r)) :
parkedRegister L s l < 2 ^ w

The output list of a parked finite state of a program of length L: the array at the address in the register recorded by the control label.

theorem Cslib.WordRAM.parkedOutput_eq {B : Basis} {r L : ℕ} {s : GenericRAM.FiniteState B.genericModel r} {i : Fin r} (hpc : s.pc = L + ↑i) :

A parked state at label L + i outputs the array at the address in register i.

One round of reading consecutive memory cells: on ((fill, memory), (address, values)), where fill is the value of unwritten cells, append the cell at address to values and advance address.

theorem Cslib.WordRAM.iterate_readRound (j fill : ℕ) (memory : GenericRAM.SparseMemory ℕ ℕ) (address : ℕ) (values : List ℕ) :
readRound^[j] ((fill, memory), address, values) = ((fill, memory), address + j, values ++ List.map (fun (i : ℕ) => GenericRAM.SparseMemory.read fill (address + i) memory) (List.range j))

j reading rounds append the j cells from address on.

@[reducible, inline]

The encoding of the reading loop state.

One reading round is cubic, with linear output: one sparse-memory scan and linear copying.

The native certificate of one reading round, cubic in the encoded loop state.

Select the register recorded by the control label among l, by label comparisons.

The initial reading loop state ((default, memory), (v + 1, [])) for the output address v.

The reader of a parked state: select the output register, read the array length L' at its address, then read L' consecutive cells.

theorem Cslib.WordRAM.parkedOutputCertificate_isPolynomial {B : Basis} {r : ℕ} {α : Type} {encIn : α ↪ List Bool} {s : α → GenericRAM.FiniteState B.genericModel r} (L : ℕ) (c : GenericRAM.NativeCertificate s encIn (GenericRAM.FiniteState.encoding B.encoding)) (hc : c.IsPolynomial) {W : α → ℕ} (hW : Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encIn a).length) W) (hs : ∀ (a : α), WordBounded (W a) (s a)) (hlen : Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encIn a).length) fun (a : α) => (parkedOutput L (s a)).length) :

The reader is polynomial when its input state is, its states hold W-bit words with W polynomially bounded, and the output length is polynomially bounded.

Word RAM with list outputs ⇒ Turing machine #

theorem Cslib.WordRAM.Program.ComputesListInTime.turingComputableInPolyTime_of_width {B : Basis} {r : ℕ} {α : Type} {encIn : α ↪ List Bool} (hop : ∀ (op : B.Op), Turing.MultiTapeTM.ComputableInPolyTime (B.genericModel.checkedOp op) encWidthOperands (Turing.MultiTapeTM.encOption Turing.MultiTapeTM.encNat)) {p : Program B r} {encode : ℕ → α → List ℕ} {time : α → ℕ → ℕ} {allowed : α → ℕ → Prop} {f : α → List ℕ} (h : p.ComputesListInTime encode time allowed f) {width : α → ℕ} (hwidth : Turing.MultiTapeTM.ComputableInPolyTime width encIn Turing.MultiTapeTM.encUnary) (hallowed : ∀ (a : α), allowed a (width a)) (hfits : ∀ (a : α), InputFits (width a) (encode (width a) a)) (hencode : Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => encode (width a) a) encIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encNat)) (htime : Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encIn a).length) fun (a : α) => time a (width a)) (hlen : Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encIn a).length) fun (a : α) => (f a).length) :

Word-RAM time with a list output, at a polynomial-time width schedule, gives Turing-machine polynomial time.

Let p be a fixed program over a basis whose checked operations are polynomial-time on a unary width and binary operands. Suppose width a is computable in unary in polynomial time, is an admitted width for a, and the word list encode (width a) a fits it and is computable in polynomial time from encIn a. If p returns the list f a (Program.ComputesListInTime) within a time bound at width a polynomial in |encIn a|, and the length of f a is polynomially bounded in |encIn a|, then f is computable in polynomial time with output encList encNat.

theorem Cslib.WordRAM.Program.ComputesListInTime.turingComputableInPolyTime {B : Basis} {r : ℕ} {α : Type} {encIn : α ↪ List Bool} (hop : ∀ (op : B.Op), Turing.MultiTapeTM.ComputableInPolyTime (B.genericModel.checkedOp op) encWidthOperands (Turing.MultiTapeTM.encOption Turing.MultiTapeTM.encNat)) {p : Program B r} {encode : α → List ℕ} {size : α → ℕ} {f : α → List ℕ} {T : ℕ → ℕ} {k : ℕ} (hT : PolynomiallyBounded T) (hsize : Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encIn a).length) size) (hencode : Turing.MultiTapeTM.ComputableInPolyTime encode encIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encNat)) (hlen : Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encIn a).length) fun (a : α) => (f a).length) (h : p.ComputesListInTime (fun (x : ℕ) => encode) (fun (a : α) (x : ℕ) => T (size a)) (fun (a : α) (w : ℕ) => logWidth k (size a) ≤ w) f) :

Polynomial word-RAM time with a list output gives Turing-machine polynomial time for a fixed program.

Let p be a fixed program over a basis whose checked operations are polynomial-time on a unary width and binary operands. Suppose that on every input a whose words fit, at every word size of at least logWidth k (size a), p returns the list f a from State.init (encode a) within T (size a) instructions, where T is polynomially bounded. If the word list encode a is computable in polynomial time from the bit string encIn a, and size a and the length of f a are polynomially bounded in |encIn a|, then f is computable in polynomial time with output encList encNat.

Uniform polynomial word-RAM time with a list output gives Turing-machine polynomial time, for a width-independent word encoding computable in polynomial time, a size measure and an output length polynomially bounded in the encoded input length.