Simulating CSLib multi-tape machines on Complexitylib machines #
This file defines a Complexitylib machine (TM k) that simulates a binary
CSLib multi-tape machine (Turing.MultiTapeTM k Bool S) with the same number
of work tapes. It is the converse direction of
Complexitylib.Interop.Cslib.MultiTape.
The simulator bridges the two models as follows.
- Symbols. CSLib cells hold
Option Bool; the blanknonebecomes□andsome bbecomes the bitb. - Two-way work tapes. Each CSLib work tape is folded onto one of our
one-sided work tapes: CSLib cell
z ≥ 0lives in our cell2 z + 1, and CSLib cellz < 0in our cell-2 z. Our cell0(▷) is never used. A sign flag in the control state records which half the head is on. A CSLib head move becomes a move by two cells, or by one cell across the fold; the fold is detected by bumping into▷. - Phases. Each CSLib step takes three of our steps: phase
0(run) reads all heads, applies CSLib's transition, writes, and starts the head moves; phases1and2(mid1,mid2) finish them. - Input head. Our input head sits on the cell with CSLib's input position:
cell
0(▷) is CSLib's left blank and cell|x| + 1its right blank. CSLib clamps moves past either blank. Since our head must leave▷at once, staying on position0is simulated by moving right and then back left. - Output. CSLib emits output symbols one at a time. The simulator writes
each emitted bit on its output tape and moves right, so the first emitted
bit (CSLib's verdict) lands in output cell
1.
Main definitions #
Complexity.FromMultiTape.St— the simulator's statesComplexity.FromMultiTape.toTM— the Complexitylib machine simulating a CSLib machine
Read one of our symbols as a binary CSLib cell: □ and ▷ are blank.
Equations
Instances For
Store a binary CSLib cell as a writable symbol, with CSLib's blank as □.
Equations
Instances For
The writable symbol that rewrites s unchanged (off the left-end marker).
Equations
Instances For
Guard a head direction: a head reading ▷ moves right, as TM.δ_right_of_start
requires; otherwise it moves in direction d.
Equations
Instances For
What a folded work tape still has to do in phases 1 and 2 of a
simulated step.
- idle : Plan
Nothing more; the head is in place.
- out : Plan
One more move right (a move away from the fold, begun in phase
0). - inPos : Plan
On the nonnegative half, moving toward the fold: one more left move, unless the head bumped into
▷, in which case it crosses the fold. - inNeg : Plan
On the negative half, moving toward the fold: one more left move, then a check for
▷in phase2. - cross : Plan
Crossing from CSLib cell
0to cell-1: one more move right.
Instances For
Equations
- One or more equations did not get rendered due to their size.
The simulator's states, for a CSLib machine with k work tapes and state
type S. The sign flags say, for each work tape, whether the CSLib head is at
a negative position.
- init
{k : ℕ}
{S : Type}
: St k S
Move every head off
▷. - run
{k : ℕ}
{S : Type}
(q : S)
(sign : Fin k → Bool)
: St k S
Phase
0: simulate one step of CSLib stateq. - mid1
{k : ℕ}
{S : Type}
(q : S)
(sign : Fin k → Bool)
(plan : Fin k → Plan)
(inDir : Dir3)
: St k S
Phase
1: continue the moves; CSLib is now in stateq. - mid2
{k : ℕ}
{S : Type}
(q : S)
(sign : Fin k → Bool)
(plan : Fin k → Plan)
(inDir : Dir3)
: St k S
Phase
2: finish the moves, including the input head moveinDir. - halt
{k : ℕ}
{S : Type}
: St k S
CSLib halted.
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Complexity.FromMultiTape.instDecidableEqSt.decEq Complexity.FromMultiTape.St.init Complexity.FromMultiTape.St.init = isTrue ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq Complexity.FromMultiTape.St.init (Complexity.FromMultiTape.St.run q sign) = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq Complexity.FromMultiTape.St.init (Complexity.FromMultiTape.St.mid1 q sign plan inDir) = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq Complexity.FromMultiTape.St.init (Complexity.FromMultiTape.St.mid2 q sign plan inDir) = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq Complexity.FromMultiTape.St.init Complexity.FromMultiTape.St.halt = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq (Complexity.FromMultiTape.St.run q sign) Complexity.FromMultiTape.St.init = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq (Complexity.FromMultiTape.St.run q sign) (Complexity.FromMultiTape.St.mid1 q_1 sign_1 plan inDir) = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq (Complexity.FromMultiTape.St.run q sign) (Complexity.FromMultiTape.St.mid2 q_1 sign_1 plan inDir) = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq (Complexity.FromMultiTape.St.run q sign) Complexity.FromMultiTape.St.halt = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq (Complexity.FromMultiTape.St.mid1 q sign plan inDir) Complexity.FromMultiTape.St.init = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq (Complexity.FromMultiTape.St.mid1 q sign plan inDir) (Complexity.FromMultiTape.St.run q_1 sign_1) = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq (Complexity.FromMultiTape.St.mid1 q sign plan inDir) (Complexity.FromMultiTape.St.mid2 q_1 sign_1 plan_1 inDir_1) = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq (Complexity.FromMultiTape.St.mid1 q sign plan inDir) Complexity.FromMultiTape.St.halt = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq (Complexity.FromMultiTape.St.mid2 q sign plan inDir) Complexity.FromMultiTape.St.init = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq (Complexity.FromMultiTape.St.mid2 q sign plan inDir) (Complexity.FromMultiTape.St.run q_1 sign_1) = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq (Complexity.FromMultiTape.St.mid2 q sign plan inDir) (Complexity.FromMultiTape.St.mid1 q_1 sign_1 plan_1 inDir_1) = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq (Complexity.FromMultiTape.St.mid2 q sign plan inDir) Complexity.FromMultiTape.St.halt = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq Complexity.FromMultiTape.St.halt Complexity.FromMultiTape.St.init = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq Complexity.FromMultiTape.St.halt (Complexity.FromMultiTape.St.run q sign) = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq Complexity.FromMultiTape.St.halt (Complexity.FromMultiTape.St.mid1 q sign plan inDir) = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq Complexity.FromMultiTape.St.halt (Complexity.FromMultiTape.St.mid2 q sign plan inDir) = isFalse ⋯
- Complexity.FromMultiTape.instDecidableEqSt.decEq Complexity.FromMultiTape.St.halt Complexity.FromMultiTape.St.halt = isTrue ⋯
Instances For
The simulator's states as a sum of finite types.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Phase 0 of a folded work-tape move m, on the negative half when s
holds: the remaining plan and the first head move.
Equations
- Complexity.FromMultiTape.plan0 s SignType.zero = (Complexity.FromMultiTape.Plan.idle, Complexity.Dir3.stay)
- Complexity.FromMultiTape.plan0 s SignType.pos = if s = true then (Complexity.FromMultiTape.Plan.inNeg, Complexity.Dir3.left) else (Complexity.FromMultiTape.Plan.out, Complexity.Dir3.right)
- Complexity.FromMultiTape.plan0 s SignType.neg = if s = true then (Complexity.FromMultiTape.Plan.out, Complexity.Dir3.right) else (Complexity.FromMultiTape.Plan.inPos, Complexity.Dir3.left)
Instances For
Phase 1 of a folded work-tape move with plan p, sign flag s, and
symbol r under the head: the next plan, the next sign flag, and the move.
Equations
- One or more equations did not get rendered due to their size.
- Complexity.FromMultiTape.plan1 Complexity.FromMultiTape.Plan.out s r = (Complexity.FromMultiTape.Plan.idle, s, Complexity.Dir3.right)
- Complexity.FromMultiTape.plan1 Complexity.FromMultiTape.Plan.inNeg s r = (Complexity.FromMultiTape.Plan.inNeg, s, Complexity.Dir3.left)
- Complexity.FromMultiTape.plan1 Complexity.FromMultiTape.Plan.idle s r = (Complexity.FromMultiTape.Plan.idle, s, Complexity.Dir3.stay)
- Complexity.FromMultiTape.plan1 Complexity.FromMultiTape.Plan.cross s r = (Complexity.FromMultiTape.Plan.cross, s, Complexity.Dir3.stay)
Instances For
Phase 2 of a folded work-tape move with plan p, sign flag s, and
symbol r under the head: the next sign flag and the move.
Equations
- Complexity.FromMultiTape.plan2 Complexity.FromMultiTape.Plan.cross s r = (s, Complexity.Dir3.right)
- Complexity.FromMultiTape.plan2 Complexity.FromMultiTape.Plan.inNeg s r = if r = Complexity.Γ.start then (false, Complexity.Dir3.right) else (s, Complexity.Dir3.stay)
- Complexity.FromMultiTape.plan2 p s r = (s, Complexity.Dir3.stay)
Instances For
The input head move made in phase 2 to simulate CSLib input move m,
where r is the input symbol read in phase 0. On ▷ the head already moved
right in phase 0; elsewhere a right move off the right blank is clamped.
Equations
- One or more equations did not get rendered due to their size.
- Complexity.FromMultiTape.inputPlan r SignType.neg = if r = Complexity.Γ.start then if SignType.neg = SignType.pos then Complexity.Dir3.stay else Complexity.Dir3.left else Complexity.Dir3.left
- Complexity.FromMultiTape.inputPlan r SignType.zero = if r = Complexity.Γ.start then if SignType.zero = SignType.pos then Complexity.Dir3.stay else Complexity.Dir3.left else Complexity.Dir3.stay
Instances For
The symbol written in phase 0 for a CSLib write wr over symbol r.
Equations
Instances For
The symbol written on our output tape over symbol o when CSLib emits e.
Equations
Instances For
The output head move when CSLib emits e: right after each emitted bit.
Equations
Instances For
The simulator's transition function. Every direction is passed through
Dir3.guard, so heads on ▷ always move right.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Guarded directions move right off ▷.
The Complexitylib machine simulating the binary CSLib machine M, with one
folded work tape per CSLib work tape.
Equations
- One or more equations did not get rendered due to their size.