Documentation

Algolean.Models.SingleTapeTM.Composition.Oracle

Asking an assumed solver questions #

This file lets a tape program ask an assumed solver for answers to a yes/no problem. Such a solver is called an oracle. The program asks about the word under the tape head, ending at the first blank. Its answer is recorded in the machine state, so later branches and loops can depend on it.

A request costs one time step and leaves the tape and head unchanged. Head moves also cost one time step. Every instruction and loop test uses fuel. The solver's own work is outside this count.

Main definitions and results #

This interface chooses three distinct machine states for issuing a request and recording a yes or no answer.

  • request : tm.State

    Setting this state with an update instruction asks the solver about the word under the head.

  • yes : tm.State

    The interpreter sets this state when the solver answers yes.

  • no : tm.State

    The interpreter sets this state when the solver answers no.

  • request_ne_yes : self.request ≠ self.yes

    The request state differs from the yes state.

  • request_ne_no : self.request ≠ self.no

    The request state differs from the no state.

  • yes_ne_no : self.yes ≠ self.no

    The yes and no states differ, so the program can distinguish the answers.

Instances For

    The question is the word starting under the head and ending before the first blank.

    Equations
    Instances For
      @[simp]

      Reading a word placed on the initial tape gives back exactly that word.

      This program issues a request and leaves the answer in the machine state.

      Equations
      Instances For
        def Algolean.Algorithms.OracleInterface.step {tm : Cslib.Turing.SingleTapeTM Bool} [DecidableEq tm.State] {α β : Type} (interface : OracleInterface tm) (oracle : List Bool → Bool) (q : TMQuery tm α) (next : α → Prog (TMQuery tm) β) (s : TMState tm) :

        One instruction follows the ordinary rules, except that setting the request state obtains an answer from the solver.

        Equations
        Instances For
          @[reducible, inline]

          These execution rules use the shared runner to handle fuel, program sequencing, and costs. Requests work inside branches and loops.

          Equations
          Instances For
            @[reducible, inline]

            This model records the results and costs of executing programs with access to the solver.

            Equations
            Instances For
              @[reducible, inline]

              The shared execution function runs the program with the supplied solver, starting state, and fuel.

              Equations
              Instances For
                @[simp]
                theorem Algolean.Algorithms.OracleInterface.execute_ask_succ {tm : Cslib.Turing.SingleTapeTM Bool} [DecidableEq tm.State] (interface : OracleInterface tm) (oracle : List Bool → Bool) (fuel : ℕ) (s : TMState tm) :
                interface.execute oracle (fuel + 1) interface.ask s = have answer := if oracle (queryWord s.config.BiTape) = true then interface.yes else interface.no; some ({ ret := (), tell := { steps := 1, cellsAllocated := 0 } }, { machine := { config := have __src := s.config; { state := some answer, BiTape := __src.BiTape }, headPos := s.headPos, cellsAllocated := s.cellsAllocated, cellsVisited := s.cellsVisited }, fuel := fuel })

                A request costs one time step and one unit of fuel. The answer is recorded in the machine state, while the tape and head position stay unchanged.

                theorem Algolean.Algorithms.OracleInterface.step_cellsAllocated {tm : Cslib.Turing.SingleTapeTM Bool} [DecidableEq tm.State] {α β : Type} (interface : OracleInterface tm) (oracle : List Bool → Bool) (q : TMQuery tm α) (next : α → Prog (TMQuery tm) β) (s : TMState tm) :
                s.cellsAllocated.card + (interface.step oracle q next s).cost.cellsAllocated = (interface.step oracle q next s).machine.cellsAllocated.card

                One instruction counts exactly the cells it adds to the recorded tape range.

                theorem Algolean.Algorithms.OracleInterface.execute_cellsAllocated {tm : Cslib.Turing.SingleTapeTM Bool} [DecidableEq tm.State] {α : Type} (interface : OracleInterface tm) (oracle : List Bool → Bool) (fuel : ℕ) (p : Prog (TMQuery tm) α) (s : TMState tm) (result : AddWriter TMCost α) (final : TMQuery.ExecutionState tm) (h : interface.execute oracle fuel p s = some (result, final)) :

                The final number of recorded tape cells is the initial number plus the cells newly counted during execution. Requests preserve this accounting.