Documentation

Complexitylib.Models.TuringMachine.Subroutines

TM Subroutines #

Small concrete Turing machines used as composable building blocks for constructing larger machines via seqTM, ifTM, and loopTM.

Subroutine correctness theorems live in the proof modules under Complexitylib.Models.TuringMachine.Subroutines.Internal; reusable public statements are re-exported by focused surface modules when needed.

Main definitions #

State space of writeTM: rewind the output head to , step right to cell 1, write the symbol, then halt.

Instances For
    @[implicit_reducible]
    Equations
    @[implicit_reducible]
    Equations
    • One or more equations did not get rendered due to their size.
    def Complexity.TM.writeTM {n : } (sym : Γw) :
    TM n

    Write sym to output cell 1 and halt. Phases: rewind output to ▷ → move right to cell 1 → write → halt.

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

      writeTM specialized to write Γw.one to output cell 1 (accept).

      Equations
      Instances For
        @[reducible, inline]

        writeTM specialized to write Γw.zero to output cell 1 (reject).

        Equations
        Instances For

          State space of rewindWorkTM/rewindInputTM: move the head left until it reads , then move right once to land on cell 1 and halt.

          Instances For
            @[implicit_reducible]
            Equations
            def Complexity.TM.rewindWorkTM {n : } (idx : Fin n) :
            TM n

            Rewind work tape idx to cell 1 (first data cell after ▷).

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

              Rewind the input tape to cell 1 (first data cell after ▷). Work and output tapes are only written with readBackWrite, so their contents are preserved under the usual no-start-under-head side conditions.

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

                State space of scanRightTM/blankWorkTM: scan right until reading Γ.blank, then halt.

                Instances For
                  @[implicit_reducible]
                  Equations
                  def Complexity.TM.scanRightTM {n : } (idx : Fin n) :
                  TM n

                  Scan work tape idx right until finding Γ.blank. On canonical binary tapes, its exact content- and frame-preserving behavior is specified by scanRightTM_reachesIn_frame and scanRightTM_hoareTime_frame.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    def Complexity.TM.blankWorkTM {n : } (idx : Fin n) :
                    TM n

                    Scan work tape idx right until finding Γ.blank, overwriting every visited nonblank cell with Γ.blank. This consumes a started Boolean string and leaves the tape blank to the right of the current head.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      def Complexity.TM.clearWorkTM {n : } (idx : Fin n) :
                      TM n

                      Blank a started work tape and rewind it to cell 1, yielding the standard started blank tape shape.

                      Equations
                      Instances For

                        State space shared by the input/work/output copy machines: copy symbols rightward until the source reads Γ.blank, then halt.

                        Instances For
                          @[implicit_reducible]
                          Equations
                          def Complexity.TM.copyInputToWorkTM {n : } (idx : Fin n) :
                          TM n

                          Copy input tape data to work tape idx. Reads input right, writes to work tape. Stops when input reads Γ.blank. Skips ▷ at cell 0.

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

                            Copy the Boolean input to the output tape while scanning both tapes rightward. The first transition skips the left-end markers, each subsequent nonblank input symbol is written to the output, and the machine halts at the first input blank. Work-tape contents are preserved; heads reading the left-end marker take their required one-cell rightward bounce.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              def Complexity.TM.copyWorkToWorkTM {n : } (src dst : Fin n) :
                              TM n

                              Copy the contents of work tape src to work tape dst. Reads src right, writes the same bits to dst, and stops when src reads Γ.blank. The source tape contents are preserved by writing the currently read symbol back before moving right.

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

                                State space of compareWorkTapesTM: compare cells while both tapes agree, ending in matchDone (equal) or mismatch (unequal) before halting.

                                Instances For
                                  @[implicit_reducible]
                                  Equations
                                  @[implicit_reducible]
                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  def Complexity.TM.compareWorkTapesTM {n : } (idx₁ idx₂ : Fin n) :
                                  TM n

                                  Compare work tapes idx₁ and idx₂ cell by cell. Both advance right together. Stops when both read Γ.blank. Writes Γ.one to output if match, Γ.zero if mismatch. Assumes output head is at cell 1.

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