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.

Each subroutine has a corresponding HoareTime specification in Complexitylib.Models.TuringMachine.Subroutines.Internal.

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
            @[implicit_reducible]
            Equations
            • One or more equations did not get rendered due to their size.
            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. Preserves tape contents.

                  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 of copyInputToWorkTM/copyWorkToWorkTM: 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
                            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