Documentation

Complexitylib.Models.TuringMachine.SingleTape.Internal.Sim

Single-tape simulation — simulator state type #

The state type SimQ k Q of NTM.singleTapeSim (for a source machine with state type Q and k work tapes) and its Fintype/DecidableEq instances. See docs/A4-SingleTapeSimulation.md §4–5 for the phase semantics.

The instances are noncomputable by design: singleTapeSim is a noncomputable def, and synthesizing computable DecidableEq for the function-typed phase data (Fin k → Γ, Fin k → Γw × Dir3) hits Lean's product/Pi synthesis-size limit. Finite is a Prop and composes with no such limit, so we route through it (Fintype.ofFinite / Classical.decEq).

@[reducible, inline]

A sweep position: which tape's triple (Fin k) and which of its 3 cells (head-bit / sym-hi / sym-lo, as Fin 3). The tape index is Fin (k+1) — a finite type (so the state stays Finite) whose 0 is constructible even when k = 0; the slack index k is unused in normal sweeps, and updates into Fin k-indexed data are guarded by if h : t.val < k.

Equations
Instances For
    @[reducible, inline]

    GATHER-phase data: the simulated state q, the head symbols accumulated so far (acc), the input/output symbols read at macro-step start (kept for the δ computation and the -dodge), the current sweep position, a flag for whether the current tape's head marker was seen in this triple, and the pending high symbol cell read.

    Equations
    Instances For
      @[reducible, inline]

      REWIND-phase data (between GATHER and SCATTER): the next state q', the δ results carried leftward back to cell 1 — per-tape write+move action, the deferred output write/dir, input dir, original input/output symbols — and the initial rightCarry marking heads that were at position 0 (acc = ▷, forced right off ), whose new marker must be deposited at block 1 by SCATTER.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        @[reducible, inline]

        SCATTER sweep-1 data (rightward: write new symbols, place stay/right markers, materialize): the carried δ results, the sweep position, the per-tape rightCarry (markers to deposit at the next block), isLeftMover (recorded for sweep 2), and a writeFlag (currently overwriting a head's symbol).

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          @[reducible, inline]

          SCATTER sweep-2 data (leftward: deposit left-movers, rewind to cell 1): the deferred commit info, the sweep position, the isLeftMover set (from sweep

          1. and the per-tape leftCarry (markers to deposit at the next-left block).
          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            @[reducible, inline]

            COMMIT-phase data: the next simulated state and the deferred input/output actions (output write+dir, input dir) with the symbols originally read.

            Equations
            Instances For
              @[reducible, inline]

              The simulator's state type. Phases (see docs/A4): rungatherrewindscatter1scatter2commitrun, plus halt.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                @[match_pattern]
                def Complexity.NTM.SingleTape.SimQ.run {k : } {Q : Type} (q : Q) :
                SimQ k Q

                Between macro-steps, about to simulate an N-step from state q.

                Equations
                Instances For
                  @[match_pattern]

                  Rightward read sweep, gathering head symbols.

                  Equations
                  Instances For
                    @[match_pattern]

                    Leftward rewind back to cell 1, carrying the δ results.

                    Equations
                    Instances For
                      @[match_pattern]

                      Rightward write/marker sweep (stay/right moves + materialize).

                      Equations
                      Instances For
                        @[match_pattern]

                        Leftward marker sweep (left moves) + final rewind.

                        Equations
                        Instances For
                          @[match_pattern]

                          Applying the deferred input/output actions.

                          Equations
                          Instances For
                            @[match_pattern]

                            The halt state.

                            Equations
                            Instances For

                              Finite composes freely (a Prop), so this synthesizes despite the function-typed phase data — the seven wide summands just need a raised instance-search size.

                              @[implicit_reducible]
                              noncomputable instance Complexity.NTM.SingleTape.instFintypeSimQ (k : ) (Q : Type) [Fintype Q] :

                              Noncomputable Fintype via Finite — sidesteps the product/Pi DecidableEq synthesis limit.

                              Equations
                              @[implicit_reducible]
                              noncomputable instance Complexity.NTM.SingleTape.instDecidableEqSimQ (k : ) (Q : Type) :

                              Noncomputable decidable equality — only used inside proofs (trace/step reduce c.state = qhalt in Prop), never executed.

                              Equations