Documentation

Complexitylib.RationalHitting.Internal.OutputAdapter

Rational hitting lists: output adapter #

Adapted from OpenAI's formalization at revision adc7f1241b42e322a6451854ab7e4b4c146bf78a. Source: https://github.com/openai/math/blob/adc7f1241b42e322a6451854ab7e4b4c146bf78a/lean/OAI/Computability/RationalHitting/OutputAdapter.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]

      A fixed-width encoded block stored in the finite control.

      Equations
      Instances For
        @[reducible, inline]

        Finite auxiliary storage used by the tape adapter.

        Equations
        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
            @[reducible, inline]

            A configuration of the tape adapter.

            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

                      Read the designated block coordinates into the finite auxiliary storage.

                      Equations
                      Instances For

                        Copy the designated coordinates from one stored block to another.

                        Equations
                        Instances For
                          theorem Complexity.RationalHitting.TMTime.OutputAdapter.fill_apply {b : ℕ} (is : List (Fin b)) (w v : Word b) (j : Fin b) :
                          fill is w v j = if j ∈ is then w j else v j

                          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.OutputAdapter.scan_right {b : ℕ} (F : Q → Stmt b) (q : Q) (v : V b) (l L R : List A) (h : ∀ a ∈ l, ∀ (L R : List A), Turing.TM1.step F (state q v L (a :: R)) = some (state q v (a :: L) R)) :
                              exec (Turing.TM1.step F) l.length (state q v L (l ++ R)) = some (state q v (l.reverse ++ L) R)
                              theorem Complexity.RationalHitting.TMTime.OutputAdapter.scan_left {b : ℕ} (F : Q → Stmt b) (q r : Q) (v : V b) (l L R : List A) (hF : F q = leftTo q r) (hl : ∀ a ∈ l, a ≠ 3) :
                              exec (Turing.TM1.step F) (l.length + 1) (state q v (l ++ 3 :: L) R) = some (state r v L (3 :: l.reverse ++ R))
                              theorem Complexity.RationalHitting.TMTime.OutputAdapter.consume_some {b : ℕ} (get : Word b → Option Bool) (w : Word b) (x : Bool) (hx : get w = some x) (gap : ℕ) (out : List Bool) (R : List A) (v : V b) :
                              exec (Turing.TM1.step (machine get)) 1 (invariant gap out (block w ++ R) v) = some (state 2 (w, some x) (List.replicate (gap + b) 0 ++ 3 :: List.map raw out.reverse ++ [3]) (3 :: R))
                              theorem Complexity.RationalHitting.TMTime.OutputAdapter.emit_one {b : ℕ} (hb : 1 ≤ b) (get : Word b → Option Bool) (w : Word b) (x : Bool) (hx : get w = some x) (gap : ℕ) (out : List Bool) (R : List A) (v : V b) :
                              exec (Turing.TM1.step (machine get)) (2 * (gap + b) + 3) (invariant gap out (block w ++ R) v) = some (invariant (gap + b - 1) (out ++ [x]) R (w, some x))
                              theorem Complexity.RationalHitting.TMTime.OutputAdapter.consume_none {b : ℕ} (get : Word b → Option Bool) (w : Word b) (hx : get w = none) (gap : ℕ) (out : List Bool) (v : V b) :
                              exec (Turing.TM1.step (machine get)) 1 (invariant gap out (block w) v) = some (state 5 (w, none) (List.replicate (gap + b + 1) 0 ++ 3 :: List.map raw out.reverse ++ [3]) [])
                              theorem Complexity.RationalHitting.TMTime.OutputAdapter.finish {b : ℕ} (get : Word b → Option Bool) (w : Word b) (hx : get w = none) (gap : ℕ) (out : List Bool) (v : V b) :
                              exec (Turing.TM1.step (machine get)) (gap + b + out.length + 6) (invariant gap out (block w) v) = some { l := none, var := (w, none), Tape := Turing.Tape.mk₁ (List.map raw out) }
                              def Complexity.RationalHitting.TMTime.OutputAdapter.stream {b : ℕ} (code : Bool → Bool → Word b) (stop : Bool → Word b) :
                              Bool → List Bool → List A

                              Encode a sequence of bits and its terminal block.

                              Equations
                              Instances For

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

                                Equations
                                Instances For
                                  theorem Complexity.RationalHitting.TMTime.OutputAdapter.decode_stream {b : ℕ} (hb : 1 ≤ b) (get : Word b → Option Bool) (code : Bool → Bool → Word b) (stop : Bool → Word b) (hc : ∀ (f x : Bool), get (code f x) = some x) (hs : ∀ (f : Bool), get (stop f) = none) (xs : List Bool) (f : Bool) (gap : ℕ) (out : List Bool) (v : V b) :
                                  ∃ (u : V b), exec (Turing.TM1.step (machine get)) (cost b gap out.length xs.length) (invariant gap out (stream code stop f xs) v) = some { l := none, var := u, Tape := Turing.Tape.mk₁ (List.map raw (out ++ xs)) }
                                  theorem Complexity.RationalHitting.TMTime.OutputAdapter.cost_bound (b gap len n : ℕ) :
                                  cost b gap len n ≤ (n + 1) * (3 * (gap + b * (n + 1) + len + n + 10))
                                  theorem Complexity.RationalHitting.TMTime.OutputAdapter.start {b : ℕ} (get : Word b → Option Bool) (R : List A) (v : V b) :
                                  exec (Turing.TM1.step (machine get)) 1 { l := some 0, var := v, Tape := Turing.Tape.mk₁ R } = some (invariant 0 [] R v)
                                  theorem Complexity.RationalHitting.TMTime.OutputAdapter.prepare {b : ℕ} (hb : 1 ≤ b) (get : Word b → Option Bool) (code : Bool → Bool → Word b) (stop : Bool → Word b) (hc : ∀ (f x : Bool), get (code f x) = some x) (hs : ∀ (f : Bool), get (stop f) = none) (xs : List Bool) :
                                  ∃ t ≤ (3 * b + 34) * (xs.length + 1) ^ 2, ∃ (u : V b), exec (Turing.TM1.step (machine get)) t (Turing.TM1.init (stream code stop true xs)) = some { l := none, var := u, Tape := Turing.Tape.mk₁ (List.map raw xs) }

                                  Literal block input to literal digit output; both head position and blank outside the output are guaranteed, with quadratic bit-time.

                                  theorem Complexity.RationalHitting.TMTime.OutputAdapter.finite_output {b : ℕ} (hb : 1 ≤ b) (get : Word b → Option Bool) (code : Bool → Bool → Word b) (stop : Bool → Word b) (hc : ∀ (f x : Bool), get (code f x) = some x) (hs : ∀ (f : Bool), get (stop f) = none) :
                                  ∃ (m : ℕ) (G : Turing.TM0.Machine A (Fin (m + 1))) (C : ℕ), 0 < C ∧ ∀ (xs : List Bool), ∃ t ≤ C * (xs.length + 1) ^ 2, ∃ (a : Turing.TM0.Cfg A (Fin (m + 1))), exec (Turing.TM0.step G) t (Turing.TM0.init (stream code stop true xs)) = some a ∧ Turing.TM0.step G a = none ∧ a.Tape = Turing.Tape.mk₁ (List.map raw xs)

                                  A genuine Fin4 finite TM0 output transducer; the encoding/decoding functions are fixed finite tables and no unbounded state or oracle is used.

                                  theorem Complexity.RationalHitting.TMTime.StackTape.unique {K : Type u_1} {Λ : Type u_2} {σ : Type u_3} {Γ : K → Type u_4} {a b : Turing.TM2.Cfg Γ Λ σ} {c d : Turing.TM1.Cfg (Turing.TM2to1.Γ' K Γ) (Turing.TM2to1.Λ' K Γ Λ σ) σ} (h : Turing.TM2to1.TrCfg a c) (h' : Turing.TM2to1.TrCfg b d) (hs : a.stk = b.stk) :
                                  c.Tape = d.Tape

                                  At the boundary of a stack macrostep, the simulator's tape is determined by the actual stack contents. There is no junk-cell assumption.

                                  theorem Complexity.RationalHitting.TMTime.StackTape.clean {K : Type u_1} {Λ : Type u_2} {σ : Type u_3} [DecidableEq K] [Inhabited Λ] [Inhabited σ] (k : K) (w : List Bool) {c : Turing.TM1.Cfg (Turing.TM2to1.Γ' K fun (x : K) => Bool) (Turing.TM2to1.Λ' K (fun (x : K) => Bool) Λ σ) σ} (h : Turing.TM2to1.TrCfg { l := none, var := default, stk := Function.update (fun (x : K) => []) k w } c) :
                                  @[reducible, inline]

                                  The tape alphabet encoding a marked family of Boolean stacks.

                                  Equations
                                  Instances For

                                    Encode a stack cell holding one bit in the selected register.

                                    Equations
                                    Instances For

                                      Encode a terminal cell with all stacks empty.

                                      Equations
                                      Instances For

                                        Decode the selected stack's bit from a fixed-width encoded block.

                                        Equations
                                        Instances For
                                          theorem Complexity.RationalHitting.TMTime.OutputAdapter.getter_code {K : Type} [DecidableEq K] {b : ℕ} (k : K) (enc : StackAlphabet K → List.Vector Bool b) (dec : List.Vector Bool b → StackAlphabet K) (hd : ∀ (a : StackAlphabet K), dec (enc a) = a) (f x : Bool) :
                                          getter k dec (code k enc f x) = some x
                                          theorem Complexity.RationalHitting.TMTime.OutputAdapter.getter_stop {K : Type} {b : ℕ} (k : K) (enc : StackAlphabet K → List.Vector Bool b) (dec : List.Vector Bool b → StackAlphabet K) (hd : ∀ (a : StackAlphabet K), dec (enc a) = a) (f : Bool) :
                                          getter k dec (stop enc f) = none
                                          theorem Complexity.RationalHitting.TMTime.OutputAdapter.stream_false {K : Type} [DecidableEq K] {b : ℕ} (k : K) (enc : StackAlphabet K → List.Vector Bool b) (xs : List Bool) :
                                          stream (code k enc) (stop enc) false xs = List.map bit (List.flatMap (fun (x : (fun (x : K) => Bool) k) => (enc (false, Function.update (fun (x : K) => none) k (some x))).toList) xs) ++ block (stop enc false)
                                          theorem Complexity.RationalHitting.TMTime.OutputAdapter.width_pos {K : Type} {b : ℕ} (enc : StackAlphabet K → List.Vector Bool b) (dec : List.Vector Bool b → StackAlphabet K) (hd : ∀ (a : StackAlphabet K), dec (enc a) = a) :
                                          1 ≤ b
                                          theorem Complexity.RationalHitting.TMTime.OutputAdapter.raw_stack_output {K : Type} [DecidableEq K] {b : ℕ} (k : K) (enc : StackAlphabet K → List.Vector Bool b) (dec : List.Vector Bool b → StackAlphabet K) (h0 : enc default = List.Vector.replicate b false) (hd : ∀ (a : StackAlphabet K), dec (enc a) = a) :
                                          ∃ (m : ℕ) (G : Turing.TM0.Machine A (Fin (m + 1))) (C : ℕ), 0 < C ∧ ∀ (xs : List Bool), ∃ t ≤ C * (xs.length + 1) ^ 2, ∃ (a : Turing.TM0.Cfg A (Fin (m + 1))), exec (Turing.TM0.step G) t (Turing.TM0.init (List.map bit (List.flatMap (fun (z : StackAlphabet K) => (enc z).toList) (Turing.TM2to1.trInit k xs.reverse)))) = some a ∧ Turing.TM0.step G a = none ∧ a.Tape = Turing.Tape.mk₁ (List.map raw xs)

                                          Exact inverse interface for a clean output stack, including the bottom marker, right-side blank padding and output order.