Documentation

Complexitylib.RationalHitting.Internal.InputAdapter

Rational hitting lists: input adapter #

Adapted from OpenAI's formalization at revision adc7f1241b42e322a6451854ab7e4b4c146bf78a. Source: https://github.com/openai/math/blob/adc7f1241b42e322a6451854ab7e4b4c146bf78a/lean/OAI/Computability/RationalHitting/InputAdapter.lean

Imports, namespaces, module visibility, documentation, and formatting are adapted for complexitylib. The source theorem statements and mathematical arguments are retained.

@[reducible, inline]

The fixed four-symbol alphabet of the tape adapter.

Equations
Instances For
    @[reducible, inline]

    The ten control states used by the tape adapter.

    Equations
    Instances For
      @[reducible, inline]

      Finite auxiliary storage used by the tape adapter.

      Equations
      Instances For
        @[reducible, inline]

        A configuration of the tape adapter.

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

          A tape-adapter instruction with finite auxiliary storage.

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

            Encode a literal output or input bit by a nonblank tape symbol.

            Equations
            Instances For

              Encode a bit inside the compiler's binary tape representation.

              Equations
              Instances For

                Jump to the specified adapter control state.

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

                  Move left and branch according to whether the delimiter was reached.

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

                    Write a finite encoded block before continuing with the next instruction.

                    Equations
                    Instances For
                      theorem Complexity.RationalHitting.TMTime.InputAdapter.scan_right (F : Q → Stmt) (q : Q) (v : V) (l L R : List A) (h : ∀ a ∈ l, ∀ (L R : List A), Turing.TM1.step F { l := some q, var := v, Tape := Turing.Tape.mk₂ L (a :: R) } = some { l := some q, var := v, Tape := Turing.Tape.mk₂ (a :: L) R }) :
                      exec (Turing.TM1.step F) l.length { l := some q, var := v, Tape := Turing.Tape.mk₂ L (l ++ R) } = some { l := some q, var := v, Tape := Turing.Tape.mk₂ (l.reverse ++ L) R }
                      theorem Complexity.RationalHitting.TMTime.InputAdapter.scan_left (F : Q → Stmt) (q r : Q) (v : V) (l L R : List A) (hF : F q = leftTo q r) (hl : ∀ a ∈ l, a ≠ 3) :
                      exec (Turing.TM1.step F) (l.length + 1) { l := some q, var := v, Tape := Turing.Tape.mk₂ (l ++ 3 :: L) R } = some { l := some r, var := v, Tape := Turing.Tape.mk₂ L (3 :: l.reverse ++ R) }

                      Assemble a configuration from the control state and the two tape halves.

                      Equations
                      Instances For

                        The tape layout preserved by the adapter's main scanning loop.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          theorem Complexity.RationalHitting.TMTime.InputAdapter.process (code : Bool → Bool → List Bool) (x f b : Bool) (xs out : List Bool) (k : ℕ) :
                          exec (Turing.TM1.step (machine code)) (2 * k + 2 * out.length + (code f x).length + 7) (invariant (x :: xs) k out f b) = some (invariant xs (k + 1) (out ++ code f x) false x)

                          Encode all literal input bits, using a distinguished first-block marker.

                          Equations
                          Instances For

                            Exact recursive step bound for the adapter's scanning loop.

                            Equations
                            Instances For
                              theorem Complexity.RationalHitting.TMTime.InputAdapter.all_process (code : Bool → Bool → List Bool) (xs out : List Bool) (k : ℕ) (f b : Bool) :
                              ∃ (f' : Bool) (b' : Bool), exec (Turing.TM1.step (machine code)) (cost code f xs k out.length) (invariant xs k out f b) = some (invariant [] (k + xs.length) (out ++ emit code f xs) f' b')
                              theorem Complexity.RationalHitting.TMTime.InputAdapter.emit_length (code : Bool → Bool → List Bool) (B : ℕ) (hb : ∀ (f x : Bool), (code f x).length ≤ B) (f : Bool) (xs : List Bool) :
                              (emit code f xs).length ≤ B * xs.length
                              theorem Complexity.RationalHitting.TMTime.InputAdapter.cost_bound (code : Bool → Bool → List Bool) (B : ℕ) (hb : ∀ (f x : Bool), (code f x).length ≤ B) (f : Bool) (xs : List Bool) (k L : ℕ) :
                              cost code f xs k L ≤ xs.length * (2 * (k + xs.length) + 2 * (L + B * xs.length) + B + 7)
                              theorem Complexity.RationalHitting.TMTime.InputAdapter.scan_six_zero (code : Bool → Bool → List Bool) (f b : Bool) (L R : List A) :
                              Turing.TM1.step (machine code) (state 6 f b L (0 :: R)) = some (state 6 f b (0 :: L) R)
                              theorem Complexity.RationalHitting.TMTime.InputAdapter.enter_finish (code : Bool → Bool → List Bool) (out : List Bool) (k : ℕ) (f b : Bool) :
                              exec (Turing.TM1.step (machine code)) 1 (invariant [] k out f b) = some (state 6 f b [] (List.replicate (k + 2) 0 ++ 3 :: List.map bit out ++ [3]))
                              theorem Complexity.RationalHitting.TMTime.InputAdapter.finish (code : Bool → Bool → List Bool) (out : List Bool) (k : ℕ) (f b : Bool) :
                              exec (Turing.TM1.step (machine code)) (k + 2 * out.length + 7) (invariant [] k out f b) = some { l := none, var := (f, b), Tape := Turing.Tape.mk₁ (List.map bit out) }
                              theorem Complexity.RationalHitting.TMTime.InputAdapter.scan_zero_raw (code : Bool → Bool → List Bool) (x : Bool) (v : V) (L R : List A) :
                              Turing.TM1.step (machine code) { l := some 0, var := v, Tape := Turing.Tape.mk₂ L (raw x :: R) } = some { l := some 0, var := v, Tape := Turing.Tape.mk₂ (raw x :: L) R }
                              theorem Complexity.RationalHitting.TMTime.InputAdapter.prepare (code : Bool → Bool → List Bool) (B : ℕ) (hb : ∀ (f x : Bool), (code f x).length ≤ B) (w : List Bool) (v : V) :
                              ∃ t ≤ (4 * B + 12) * (w.length + 1) ^ 2, ∃ (v' : V), exec (Turing.TM1.step (machine code)) t { l := some 0, var := v, Tape := Turing.Tape.mk₁ (List.map raw w) } = some { l := none, var := v', Tape := Turing.Tape.mk₁ (List.map bit (emit code true w.reverse)) }

                              Literal Fin4 raw input is physically erased; no hidden encoded-input precondition is used. The macrotransition charge is quadratic; TM1 compilation adds a fixed multiplicative constant for this one fixed adapter machine.

                              theorem Complexity.RationalHitting.TMTime.InputAdapter.stack_encoding {K : Type} [DecidableEq K] (k : K) (b : ℕ) (enc : (Turing.TM2to1.Γ' K fun (x : K) => Bool) → List.Vector Bool b) (w : List Bool) (hw : w ≠ []) :
                              emit (fun (f x : Bool) => (enc (f, Function.update (fun (x : K) => none) k (some x))).toList) true w.reverse = List.flatMap (fun (a : Turing.TM2to1.Γ' K fun (x : K) => Bool) => (enc a).toList) (Turing.TM2to1.trInit k w)
                              theorem Complexity.RationalHitting.TMTime.InputAdapter.raw_stack_input {K : Type} [DecidableEq K] (k : K) (b : ℕ) (enc : (Turing.TM2to1.Γ' K fun (x : K) => Bool) → List.Vector Bool b) :
                              ∃ (m : ℕ) (G : Turing.TM0.Machine A (Fin (m + 1))) (C : ℕ), 0 < C ∧ ∀ (w : List Bool), w ≠ [] → ∃ t ≤ C * (w.length + 1) ^ 2, ∃ (a : Turing.TM0.Cfg A (Fin (m + 1))), exec (Turing.TM0.step G) t (Turing.TM0.init (List.map raw w)) = some a ∧ Turing.TM0.step G a = none ∧ a.Tape = Turing.Tape.mk₁ (List.map bit (List.flatMap (fun (z : Turing.TM2to1.Γ' K fun (x : K) => Bool) => (enc z).toList) (Turing.TM2to1.trInit k w)))

                              Real finite TM0 raw-input adapter, at quadratic bit cost, reaching exactly Mathlib's initial tape for the binary stack simulator, not an assumed encoding.