Simulation of SingleTapeTM by MultiTapeTM #
This file simulates any single-tape Turing machine (Cslib.Turing.SingleTapeTM Symbol) on a
1-work-tape multi-tape Turing machine (Turing.MultiTapeTM 1 Symbol ...) in three sequential
phases:
copyInputToWork: copy the read-only inputxonto work tape0and rewind work tape0to cell0in2 * x.length + 4steps (reusingInputReader.appendOne).runOnWork: execute the single-tape transitions oftmdirectly on work tape0. ByBiTape.Represents.step,nsteps oftmcorrespond tonsteps ofrunOnWork tm.emitWork: starting from the final head position on work tape0, walk right and emit each non-blank symbol to the output tape until the first blank cell, takingy.length + 1steps when the final tape representsBiTape.mk₁ y.
Main definitions #
Turing.MultiTapeTM.copyInputToWork: copy the input tape to work tape0and rewind to0.Turing.MultiTapeTM.runOnWork: run aSingleTapeTMon work tape0.Turing.MultiTapeTM.emitWork: emit the word on work tape0to the output tape until blank.Turing.MultiTapeTM.ofSingleTapeTM: the composed 3-phaseMultiTapeTM 1 Symbolsimulating aSingleTapeTM Symbol.
Main results #
Turing.MultiTapeTM.computesInTimeAndSpace_ofSingleTapeTM: iftm.OutputsWithinTime x y t, thenofSingleTapeTM tmcomputesyfromxin2 * x.length + 4 + (t + (y.length + 1))steps (and in3 * x.length + 2 * t + 6steps).Turing.MultiTapeTM.computes_ofSingleTapeTM: iftm.Outputs x y, then(ofSingleTapeTM tm).Computes x y.Cslib.Turing.SingleTapeTM.TimeComputable.computableInTimeAndSpace: transfersSingleTapeTM.TimeComputabletoMultiTapeTM.ComputableInTimeAndSpace.Cslib.Turing.SingleTapeTM.PolyTimeComputable.computableTidilyInPolyTime: transfersSingleTapeTM.PolyTimeComputabletoMultiTapeTM.ComputableTidilyInPolyTime.
References #
Phase 1: Copy input to work tape 0 and rewind #
The InputReader that copies every input symbol verbatim.
Instances For
Phase 1 machine: copies the input tape onto work tape 0 and rewinds work tape 0 to cell 0.
Instances For
BiTape.mk₁ xs represents tapeOfList xs with head at 0.
Phase 2: Run SingleTapeTM transitions on work tape 0 #
Convert an optional Turing.Dir to a SignType head movement.
Instances For
Phase 2 machine: executes the transitions of tm : SingleTapeTM Symbol on work tape 0,
leaving the input head and output tape untouched.
Instances For
Simulation relation between a SingleTapeTM configuration and a 1-work-tape MultiTapeTM
configuration.
- work : scfg.BiTape.Represents (mcfg.workTapes 0) (mcfg.workTapePos 0)
Instances For
Phase 3: Emit work tape 0 until blank #
Phase 3 machine: walks right along work tape 0, emitting each symbol to the output tape, and
halts on the first blank cell.
Instances For
Composed 3-phase SingleTapeTM simulator #
State type of ofSingleTapeTM tm.
Instances For
Simulate a SingleTapeTM Symbol on a 1-work-tape MultiTapeTM:
copy input to work tape 0, run tm on work tape 0, and emit work tape 0 to output.
Instances For
If tm.OutputsWithinTime x y t, then ofSingleTapeTM tm computes y from x in
2 * x.length + 4 + (t + (y.length + 1)) steps.
Input-only time bound for ofSingleTapeTM tm: since y.length ≤ max 1 x.length + t,
3 * x.length + 2 * t + 6 steps always suffice.
If tm.Outputs x y, then (ofSingleTapeTM tm).Computes x y.
Any Mathlib TM0.Machine supported on S is simulated on a 1-work-tape MultiTapeTM in
2 * x.length + 4 + ((t + 1) + (y.length + 1)) steps.
Any Mathlib TM0.Machine supported on S is simulated on a 1-work-tape MultiTapeTM.
A SingleTapeTM.TimeComputable function is computed by ofSingleTapeTM hf.tm in
3 * n + 2 * hf.timeBound n + 6 steps.
A SingleTapeTM.TimeComputable function over Bool gives
MultiTapeTM.ComputableInTimeAndSpace.
A SingleTapeTM.PolyTimeComputable function over Bool is tidily computable in polynomial
time on a multi-tape Turing machine (MultiTapeTM.ComputableTidilyInPolyTime).
Special case of PolyTimeComputable.computableTidilyInPolyTime for f : List Bool → List Bool
under the identity encoding.