Simulating Complexitylib machines on CSLib multi-tape machines #
This file defines a CSLib multi-tape machine (Turing.MultiTapeTM) over the
binary alphabet that simulates a Complexitylib machine tm : TM n step for
step.
The two models differ in four ways, and the simulator handles each:
- Left-end markers. Our tapes carry
▷in cell 0, but CSLib's binary tapes hold only0,1, and blank. Each of our work tapes and our output tape is therefore simulated by two CSLib tapes whose heads move together: a data tape holding cells1, 2, …and a marker tape holding a single1at position 0, written in the simulator's first step. The marker tape reads1exactly when the head is on our cell 0, where writes are no-ops and left moves stay put. - Output. Our output tape is read-write, while CSLib emits output symbols
one at a time. When
tmhalts, the simulator rewinds its copy of the output tape to cell 1, reads the verdict there, and emits it as a single bit. - Input head range. CSLib's input head stops one cell past the input, but
ours can run arbitrarily far into the blank tail. The last CSLib work tape
counts how far our head is past that last cell. It holds
1at position 0 and is never written again, so it reads1exactly when the count is zero. - The left input boundary. CSLib reads a blank both before and after the
input. An
InputZoneflag in the state records whether our input head is on▷. After a left move from inside the input the flag isprobe, and the next read settles it: the only position left of the input's end that reads blank is position 0.
Main definitions #
Complexity.TM.MultiTapeState— the simulator's statesComplexity.TM.toMultiTape— the CSLib machine simulatingtmComplexity.TM.toMultiTapeFun— the variant whose final phase copies the whole output string instead of the verdict bit, for function computation
A head direction as a CSLib head movement.
Equations
Instances For
Read a binary CSLib cell as one of our symbols, with CSLib's blank as □.
Equations
Instances For
Store a writable symbol in a binary CSLib cell, with □ as CSLib's blank.
Equations
Instances For
Equations
Whether the input head is on the left-end marker, given the zone flag and the CSLib input symbol under the head.
Equations
Instances For
The states of the simulator for a machine with states Q.
- init
{Q : Type}
: MultiTapeState Q
Write the position-0 markers.
- run
{Q : Type}
(q : Q)
(zone : InputZone)
: MultiTapeState Q
Simulate state
qof the original machine. - rewind
{Q : Type}
: MultiTapeState Q
Move the simulated output head back to the left-end marker.
- verdict
{Q : Type}
: MultiTapeState Q
Read the verdict in output cell 1 and halt.
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Complexity.TM.instDecidableEqMultiTapeState.decEq Complexity.TM.MultiTapeState.init Complexity.TM.MultiTapeState.init = isTrue ⋯
- Complexity.TM.instDecidableEqMultiTapeState.decEq Complexity.TM.MultiTapeState.init (Complexity.TM.MultiTapeState.run q zone) = isFalse ⋯
- Complexity.TM.instDecidableEqMultiTapeState.decEq Complexity.TM.MultiTapeState.init Complexity.TM.MultiTapeState.rewind = isFalse ⋯
- Complexity.TM.instDecidableEqMultiTapeState.decEq Complexity.TM.MultiTapeState.init Complexity.TM.MultiTapeState.verdict = isFalse ⋯
- Complexity.TM.instDecidableEqMultiTapeState.decEq (Complexity.TM.MultiTapeState.run q zone) Complexity.TM.MultiTapeState.init = isFalse ⋯
- Complexity.TM.instDecidableEqMultiTapeState.decEq (Complexity.TM.MultiTapeState.run q zone) Complexity.TM.MultiTapeState.rewind = isFalse ⋯
- Complexity.TM.instDecidableEqMultiTapeState.decEq (Complexity.TM.MultiTapeState.run q zone) Complexity.TM.MultiTapeState.verdict = isFalse ⋯
- Complexity.TM.instDecidableEqMultiTapeState.decEq Complexity.TM.MultiTapeState.rewind Complexity.TM.MultiTapeState.init = isFalse ⋯
- Complexity.TM.instDecidableEqMultiTapeState.decEq Complexity.TM.MultiTapeState.rewind (Complexity.TM.MultiTapeState.run q zone) = isFalse ⋯
- Complexity.TM.instDecidableEqMultiTapeState.decEq Complexity.TM.MultiTapeState.rewind Complexity.TM.MultiTapeState.rewind = isTrue ⋯
- Complexity.TM.instDecidableEqMultiTapeState.decEq Complexity.TM.MultiTapeState.rewind Complexity.TM.MultiTapeState.verdict = isFalse ⋯
- Complexity.TM.instDecidableEqMultiTapeState.decEq Complexity.TM.MultiTapeState.verdict Complexity.TM.MultiTapeState.init = isFalse ⋯
- Complexity.TM.instDecidableEqMultiTapeState.decEq Complexity.TM.MultiTapeState.verdict (Complexity.TM.MultiTapeState.run q zone) = isFalse ⋯
- Complexity.TM.instDecidableEqMultiTapeState.decEq Complexity.TM.MultiTapeState.verdict Complexity.TM.MultiTapeState.rewind = isFalse ⋯
- Complexity.TM.instDecidableEqMultiTapeState.decEq Complexity.TM.MultiTapeState.verdict Complexity.TM.MultiTapeState.verdict = isTrue ⋯
Instances For
Equations
The number of CSLib work tapes simulating a machine with n work tapes: a
data tape and a marker tape for each of our n + 1 read-write tapes, and the
input overshoot counter.
Instances For
CSLib data tape of our read-write tape i; tape Fin.last n is our
output tape.
Equations
- Complexity.TM.dataIdx i = Fin.castAdd 1 (Fin.castAdd (n + 1) i)
Instances For
CSLib marker tape of our read-write tape i.
Equations
- Complexity.TM.markIdx i = Fin.castAdd 1 (Fin.natAdd (n + 1) i)
Instances For
CSLib work tape counting how far the input head is past the input.
Equations
- Complexity.TM.overIdx = Fin.natAdd (n + 1 + (n + 1)) 0
Instances For
Assemble per-tape actions into CSLib's tape order.
Equations
- Complexity.TM.tapeLayout data mark over = Fin.append (Fin.append data mark) ![over]
Instances For
Our symbol under the head of simulated tape i, from the CSLib symbols
w under all heads.
Equations
Instances For
The CSLib head move simulating move d on a one-sided tape. On ▷
(cell 0) a left move stays put, matching Tape.move.
Equations
Instances For
The CSLib write simulating a write of w on a one-sided tape. On ▷
(cell 0) the write is dropped, matching Tape.write.
Instances For
The moves simulating an input-head move d: the CSLib input head move,
the overshoot counter move, and the next zone. atLeft says the head is on
▷, i is the CSLib input symbol, and ov is the counter tape's symbol,
which is 1 exactly when the counter is zero.
Equations
- One or more equations did not get rendered due to their size.
- Complexity.TM.inputAction atLeft i ov Complexity.Dir3.right = if (!atLeft && i.isNone) = true then (0, 1, Complexity.TM.InputZone.inner) else (1, 0, Complexity.TM.InputZone.inner)
- Complexity.TM.inputAction atLeft i ov Complexity.Dir3.stay = (0, 0, if atLeft = true then Complexity.TM.InputZone.left else Complexity.TM.InputZone.inner)
Instances For
The simulator's transition function.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The CSLib multi-tape machine simulating tm. Our work tape i and our
output tape (i = n) each use a data tape and a marker tape, and the last tape
counts input-head overshoot. It emits the single bit true to accept and
false to reject.
Equations
- tm.toMultiTape = { q₀ := Complexity.TM.MultiTapeState.init, tr := tm.toMultiTapeTr }
Instances For
The transition function of the function-computing simulator: the decision simulator's, except that the final state copies the simulated output cell under the head to CSLib's output and moves right, halting at the first blank.
Equations
- One or more equations did not get rendered due to their size.
- tm.toMultiTapeFunTr q i w = tm.toMultiTapeTr q i w
Instances For
The CSLib multi-tape machine computing the function tm computes: it
simulates tm, rewinds the simulated output tape, and copies the output string
to CSLib's output.
Equations
- tm.toMultiTapeFun = { q₀ := Complexity.TM.MultiTapeState.init, tr := tm.toMultiTapeFunTr }