Documentation

Complexitylib.Models.TuringMachine.Subroutines.ParkRewind

Putting every head back where a stage expects it #

A simulated machine leaves its heads wherever its run ended — possibly on the left marker, since a machine may halt immediately after stepping left onto it. Everything downstream wants heads parked past the marker, and the tapes a stage will read again want them back at cell one.

TM.parkRewindTM does both: one parking step for every tape, then a rewind of the input tape and of each named work tape. It is the stage that separates a simulation from whatever reads its results.

Main results #

def Complexity.TM.parkRewindTM {n : } (targets : List (Fin n)) :
TM n

Park every head past the marker, then rewind the input tape and the named work tapes to cell one.

Equations
  • One or more equations did not get rendered due to their size.
Instances For

    A tape with its marker only at cell zero, parked at max head 1.

    Equations
    Instances For
      theorem Complexity.TM.parkTape_eq_self {t : Tape} (h : 1 t.head) :

      Parking a tape whose head is already off the left marker changes nothing.

      theorem Complexity.TM.rewound_parked {t : Tape} (h : t.StartInvariant) :
      Parked { head := 1, cells := t.cells }
      theorem Complexity.TM.parkRewindTM_hoareTime {n : } (targets : List (Fin n)) (hnodup : targets.Nodup) (B : ) (hB : 1 B) (I₀ : Tape) (W₀ : Fin nTape) (O₀ : Tape) (hI : I₀.StartInvariant) (hW : ∀ (i : Fin n), (W₀ i).StartInvariant) (hO : O₀.StartInvariant) (hIB : I₀.head B) (hWB : jtargets, (W₀ j).head B) :
      (parkRewindTM targets).HoareTime (fun (inp : Tape) (work : Fin nTape) (out : Tape) => inp = I₀ work = W₀ out = O₀) (fun (inp : Tape) (work : Fin nTape) (out : Tape) => inp = { head := 1, cells := I₀.cells } (work = fun (j : Fin n) => if j targets then { head := 1, cells := (W₀ j).cells } else parkTape (W₀ j)) out = parkTape O₀) (1 + 1 + (2 * (max (B + 2) (targets.length * (B + 3) + 1) + 1) + 1))

      The cleanup stage's contract. Every head ends parked; the input tape and the named work tapes end at cell one, with their contents untouched. Only Tape.StartInvariant is asked of the starting tapes — a head may still be sitting on the marker, which is exactly the state a halted simulation can leave behind.

      def Complexity.TM.parkRewindWorkTM {n : } (targets : List (Fin n)) :
      TM n

      Park every head past the marker, then rewind only the named work tapes. The input tape keeps its head — a stage whose input head is itself part of the state being simulated cannot afford to have it rewound.

      Equations
      Instances For
        theorem Complexity.TM.parkRewindWorkTM_hoareTime {n : } (targets : List (Fin n)) (hnodup : targets.Nodup) (B : ) (hB : 1 B) (I₀ : Tape) (W₀ : Fin nTape) (O₀ : Tape) (hI : I₀.StartInvariant) (hW : ∀ (i : Fin n), (W₀ i).StartInvariant) (hO : O₀.StartInvariant) (hWB : jtargets, (W₀ j).head B) :
        (parkRewindWorkTM targets).HoareTime (fun (inp : Tape) (work : Fin nTape) (out : Tape) => inp = I₀ work = W₀ out = O₀) (fun (inp : Tape) (work : Fin nTape) (out : Tape) => inp = parkTape I₀ (work = fun (j : Fin n) => if j targets then { head := 1, cells := (W₀ j).cells } else parkTape (W₀ j)) out = parkTape O₀) (1 + 1 + (targets.length * (B + 3) + 1))

        The work-only cleanup stage's contract. The named work tapes end at cell one with their contents untouched; every other head ends merely parked.