Documentation

Complexitylib.RationalHitting.Internal.StackLanguage

Rational hitting lists: stack language #

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

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

def Complexity.RationalHitting.TMTime.exec {α : Type u_1} (step : α → Option α) :
ℕ → α → Option α

Execute a partial transition function for exactly the specified number of steps.

Equations
Instances For
    @[simp]
    theorem Complexity.RationalHitting.TMTime.exec_zero {α : Type u_1} (step : α → Option α) (a : α) :
    exec step 0 a = some a
    theorem Complexity.RationalHitting.TMTime.exec_add {α : Type u_1} (step : α → Option α) (s t : ℕ) (a : α) :
    exec step (s + t) a = (exec step s a).bind (exec step t)
    theorem Complexity.RationalHitting.TMTime.exec_trans {α : Type u_1} {step : α → Option α} {s t : ℕ} {a b c : α} (h : exec step s a = some b) (h' : exec step t b = some c) :
    exec step (s + t) a = some c
    theorem Complexity.RationalHitting.TMTime.exec_positive_congr {α : Type u_1} {step : α → Option α} {t : ℕ} (ht : 0 < t) {a b : α} (h : step a = step b) :
    exec step t a = exec step t b
    theorem Complexity.RationalHitting.TMTime.OneToZero.weight_pos {Γ : Type v_1} {Λ : Type v_2} {σ : Type v_3} (q : Turing.TM1.Stmt Γ Λ σ) :
    0 < weight q
    theorem Complexity.RationalHitting.TMTime.OneToZero.statement_time {Γ : Type u_1} {Λ : Type u_2} {σ : Type u_3} [Inhabited Γ] [Inhabited Λ] [Inhabited σ] (M : Λ → Turing.TM1.Stmt Γ Λ σ) (q : Turing.TM1.Stmt Γ Λ σ) (v : σ) (T : Turing.Tape Γ) :
    ∃ (t : ℕ), 0 < t ∧ t ≤ weight q ∧ exec (Turing.TM0.step (Turing.TM1to0.tr M)) t { q := (some q, v), Tape := T } = some (Turing.TM1to0.trCfg M (Turing.TM1.stepAux q v T))

    Each TM1 macro-step takes at most its statement size in real TM0 steps. Load and branch are absorbed into the next primitive step by Mathlib's compiler.

    theorem Complexity.RationalHitting.TMTime.OneToZero.execution_time {Γ : Type u_1} {Λ : Type u_2} {σ : Type u_3} [Inhabited Γ] [Inhabited Λ] [Inhabited σ] (M : Λ → Turing.TM1.Stmt Γ Λ σ) (S : Finset Λ) (hs : Turing.TM1.Supports M S) (C : ℕ) (hC : ∀ l ∈ S, weight (M l) ≤ C) (t : ℕ) (a b : Turing.TM1.Cfg Γ Λ σ) (ha : a.l ∈ Finset.insertNone S) (hr : exec (Turing.TM1.step M) t a = some b) :

    Linear transition overhead for a finitely supported TM1 program.

    @[simp]
    theorem Complexity.RationalHitting.TMTime.OneToZero.halts {Γ : Type u_1} {Λ : Type u_2} {σ : Type u_3} [Inhabited Γ] [Inhabited Λ] [Inhabited σ] (M : Λ → Turing.TM1.Stmt Γ Λ σ) (a : Turing.TM1.Cfg Γ Λ σ) (h : Turing.TM1.step M a = none) :

    Finite Boolean-stack programs with branching, composition, and while loops.

    • skip {K : Type} : Program K

      Leave all registers unchanged.

    • push {K : Type} : K → Bool → Program K

      Push one Boolean symbol onto a register.

    • drop {K : Type} : K → Program K

      Discard the head of a register, if present.

    • transfer {K : Type} : K → K → Program K

      Move one head symbol between registers.

    • seq {K : Type} : Program K → Program K → Program K

      Execute two programs in sequence.

    • branch {K : Type} : K → Program K → Program K → Program K → Program K

      Choose a program for an empty, false-headed, or true-headed register.

    • loop {K : Type} : K → Program K → Program K

      Repeat a program while the specified register is nonempty.

    Instances For
      Equations
      Instances For
        @[reducible, inline]

        The Boolean word stored in each register.

        Equations
        Instances For
          @[reducible, inline]

          The initial label or a list of remaining program commands.

          Equations
          Instances For

            Move one head symbol if present, popping the first register before updating the second, including when both registers coincide.

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

              Big-step execution with an exact count of stack-program transitions.

              Instances For
                @[reducible, inline]

                Mathlib stack-machine statements used to compile the finite program.

                Equations
                Instances For

                  Reset the temporary symbol and continue with the remaining commands.

                  Equations
                  Instances For

                    The stack-machine configuration for a continuation and register store.

                    Equations
                    Instances For
                      theorem Complexity.RationalHitting.StackLanguage.eval_compiles {K : Type} [DecidableEq K] {p : Program K} {s v : Store K} {t : ℕ} (h : Eval p s v t) (main : Program K) (ps : List (Program K)) :
                      TMTime.exec (Turing.TM2.step (machine main)) t (cfg (p :: ps) s) = some (cfg ps v)

                      Exact big-step correctness in real TM2 steps, with no unbounded internal state or alphabet.

                      theorem Complexity.RationalHitting.StackLanguage.root_closed {K : Type} [DecidableEq K] (p : Program K) (ps : List (Program K)) (S : Finset (List (Program K))) (hs : locations p ps ⊆ S) :
                      successors (p :: ps) ⊆ S
                      theorem Complexity.RationalHitting.StackLanguage.locations_closed {K : Type} [DecidableEq K] (p : Program K) (ps : List (Program K)) (S : Finset (List (Program K))) (hs : locations p ps ⊆ S) (hk : successors ps ⊆ S) (l : List (Program K)) :
                      l ∈ locations p ps → successors l ⊆ S
                      theorem Complexity.RationalHitting.StackLanguage.complete_run {K : Type} [DecidableEq K] {p : Program K} {s v : Store K} {t : ℕ} (h : Eval p s v t) :
                      TMTime.exec (Turing.TM2.step (machine p)) (t + 2) { l := some none, var := none, stk := s } = some { l := none, var := none, stk := v }

                      Entry and halting are one actual macrostep apiece.