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.
Execute a partial transition function for exactly the specified number of steps.
Equations
- Complexity.RationalHitting.TMTime.exec step 0 x✝ = some x✝
- Complexity.RationalHitting.TMTime.exec step t.succ x✝ = (step x✝).bind (Complexity.RationalHitting.TMTime.exec step t)
Instances For
Syntactic statement bound, fixed once the finite machine is fixed.
Equations
- One or more equations did not get rendered due to their size.
- Complexity.RationalHitting.TMTime.OneToZero.weight (Turing.TM1.Stmt.move a q) = Complexity.RationalHitting.TMTime.OneToZero.weight q + 1
- Complexity.RationalHitting.TMTime.OneToZero.weight (Turing.TM1.Stmt.write a q) = Complexity.RationalHitting.TMTime.OneToZero.weight q + 1
- Complexity.RationalHitting.TMTime.OneToZero.weight (Turing.TM1.Stmt.load a q) = Complexity.RationalHitting.TMTime.OneToZero.weight q + 1
- Complexity.RationalHitting.TMTime.OneToZero.weight (Turing.TM1.Stmt.goto a) = 1
- Complexity.RationalHitting.TMTime.OneToZero.weight Turing.TM1.Stmt.halt = 1
Instances For
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.
Linear transition overhead for a finitely supported TM1 program.
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
- One or more equations did not get rendered due to their size.
- Complexity.RationalHitting.StackLanguage.instDecidableEqProgram.decEq Complexity.RationalHitting.StackLanguage.Program.skip Complexity.RationalHitting.StackLanguage.Program.skip = isTrue ⋯
- Complexity.RationalHitting.StackLanguage.instDecidableEqProgram.decEq Complexity.RationalHitting.StackLanguage.Program.skip (Complexity.RationalHitting.StackLanguage.Program.drop a) = isFalse ⋯
- Complexity.RationalHitting.StackLanguage.instDecidableEqProgram.decEq Complexity.RationalHitting.StackLanguage.Program.skip (a.seq a_1) = isFalse ⋯
- Complexity.RationalHitting.StackLanguage.instDecidableEqProgram.decEq (Complexity.RationalHitting.StackLanguage.Program.push a a_1) (a_2.seq a_3) = isFalse ⋯
- Complexity.RationalHitting.StackLanguage.instDecidableEqProgram.decEq (Complexity.RationalHitting.StackLanguage.Program.drop a) Complexity.RationalHitting.StackLanguage.Program.skip = isFalse ⋯
- Complexity.RationalHitting.StackLanguage.instDecidableEqProgram.decEq (Complexity.RationalHitting.StackLanguage.Program.drop a) (a_1.seq a_2) = isFalse ⋯
- Complexity.RationalHitting.StackLanguage.instDecidableEqProgram.decEq (Complexity.RationalHitting.StackLanguage.Program.transfer a a_1) (a_2.seq a_3) = isFalse ⋯
- Complexity.RationalHitting.StackLanguage.instDecidableEqProgram.decEq (a.seq a_1) Complexity.RationalHitting.StackLanguage.Program.skip = isFalse ⋯
- Complexity.RationalHitting.StackLanguage.instDecidableEqProgram.decEq (a.seq a_1) (Complexity.RationalHitting.StackLanguage.Program.push a_2 a_3) = isFalse ⋯
- Complexity.RationalHitting.StackLanguage.instDecidableEqProgram.decEq (a.seq a_1) (Complexity.RationalHitting.StackLanguage.Program.drop a_2) = isFalse ⋯
- Complexity.RationalHitting.StackLanguage.instDecidableEqProgram.decEq (a.seq a_1) (Complexity.RationalHitting.StackLanguage.Program.transfer a_2 a_3) = isFalse ⋯
- Complexity.RationalHitting.StackLanguage.instDecidableEqProgram.decEq (a.seq a_1) (Complexity.RationalHitting.StackLanguage.Program.branch a_2 a_3 a_4 a_5) = isFalse ⋯
- Complexity.RationalHitting.StackLanguage.instDecidableEqProgram.decEq (a.seq a_1) (Complexity.RationalHitting.StackLanguage.Program.loop a_2 a_3) = isFalse ⋯
- Complexity.RationalHitting.StackLanguage.instDecidableEqProgram.decEq (Complexity.RationalHitting.StackLanguage.Program.branch a a_1 a_2 a_3) (a_4.seq a_5) = isFalse ⋯
- Complexity.RationalHitting.StackLanguage.instDecidableEqProgram.decEq (Complexity.RationalHitting.StackLanguage.Program.loop a a_1) (a_2.seq a_3) = isFalse ⋯
Instances For
The Boolean word stored in each register.
Equations
Instances For
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.
- skip
{K : Type}
[DecidableEq K]
(s : Store K)
: Eval Program.skip s s 1
Skipping costs one transition.
- push
{K : Type}
[DecidableEq K]
(k : K)
(b : Bool)
(s : Store K)
: Eval (Program.push k b) s (Function.update s k (b :: s k)) 1
Pushing a symbol costs one transition.
- drop
{K : Type}
[DecidableEq K]
(k : K)
(s : Store K)
: Eval (Program.drop k) s (Function.update s k (s k).tail) 1
Dropping a symbol costs one transition.
- transfer
{K : Type}
[DecidableEq K]
(a b : K)
(s : Store K)
: Eval (Program.transfer a b) s (StackLanguage.transfer a b s) 1
A symbol transfer costs one transition.
- seq
{K : Type}
[DecidableEq K]
{p q : Program K}
{s u v : Store K}
{t w : ℕ}
: Eval p s u t → Eval q u v w → Eval (p.seq q) s v (1 + t + w)
Sequential composition adds both execution times and one control transition.
- branchNone
{K : Type}
[DecidableEq K]
{k : K}
{p q r : Program K}
{s v : Store K}
{t : ℕ}
: s k = [] → Eval p s v t → Eval (Program.branch k p q r) s v (1 + t)
Take the empty-register branch after one control transition.
- branchFalse
{K : Type}
[DecidableEq K]
{k : K}
{p q r : Program K}
{s v : Store K}
{t : ℕ}
{ls : List Bool}
: s k = false :: ls → Eval q s v t → Eval (Program.branch k p q r) s v (1 + t)
Take the false-symbol branch after one control transition.
- branchTrue
{K : Type}
[DecidableEq K]
{k : K}
{p q r : Program K}
{s v : Store K}
{t : ℕ}
{ls : List Bool}
: s k = true :: ls → Eval r s v t → Eval (Program.branch k p q r) s v (1 + t)
Take the true-symbol branch after one control transition.
- whileNil
{K : Type}
[DecidableEq K]
{k : K}
{p : Program K}
{s : Store K}
: s k = [] → Eval (Program.loop k p) s s 1
An empty loop register terminates the loop in one transition.
- whileCons
{K : Type}
[DecidableEq K]
{k : K}
{p : Program K}
{s u v : Store K}
{t w : ℕ}
: s k ≠ [] → Eval p s u t → Eval (Program.loop k p) u v w → Eval (Program.loop k p) s v (1 + t + w)
A nonempty loop register executes the body and repeats.
Instances For
Mathlib stack-machine statements used to compile the finite program.
Equations
- Complexity.RationalHitting.StackLanguage.Stmt K = Turing.TM2.Stmt (fun (x : K) => Bool) (Complexity.RationalHitting.StackLanguage.Labels K) (Option Bool)
Instances For
Reset the temporary symbol and continue with the remaining commands.
Equations
- Complexity.RationalHitting.StackLanguage.jump ps = Turing.TM2.Stmt.load (fun (x : Option Bool) => none) (Turing.TM2.Stmt.goto fun (x : Option Bool) => some ps)
Instances For
Compile the next program command into stack-machine instructions.
Equations
- One or more equations did not get rendered due to their size.
- Complexity.RationalHitting.StackLanguage.instruction [] = Turing.TM2.Stmt.halt
- Complexity.RationalHitting.StackLanguage.instruction (Complexity.RationalHitting.StackLanguage.Program.skip :: ps) = Complexity.RationalHitting.StackLanguage.jump ps
- Complexity.RationalHitting.StackLanguage.instruction (p.seq q :: ps) = Complexity.RationalHitting.StackLanguage.jump (p :: q :: ps)
Instances For
The stack-machine transition map for a finite program.
Equations
Instances For
The stack-machine configuration for a continuation and register store.
Equations
Instances For
Exact big-step correctness in real TM2 steps, with no unbounded internal state or alphabet.
Possible jump targets; inspecting a head has only three finite cases.
Equations
- Complexity.RationalHitting.StackLanguage.successors [] = ∅
- Complexity.RationalHitting.StackLanguage.successors (Complexity.RationalHitting.StackLanguage.Program.skip :: ps) = {ps}
- Complexity.RationalHitting.StackLanguage.successors (Complexity.RationalHitting.StackLanguage.Program.push k b :: ps) = {ps}
- Complexity.RationalHitting.StackLanguage.successors (Complexity.RationalHitting.StackLanguage.Program.drop k :: ps) = {ps}
- Complexity.RationalHitting.StackLanguage.successors (Complexity.RationalHitting.StackLanguage.Program.transfer a b :: ps) = {ps}
- Complexity.RationalHitting.StackLanguage.successors (p.seq q :: ps) = {p :: q :: ps}
- Complexity.RationalHitting.StackLanguage.successors (Complexity.RationalHitting.StackLanguage.Program.branch k p q r :: ps) = {p :: ps, q :: ps, r :: ps}
- Complexity.RationalHitting.StackLanguage.successors (Complexity.RationalHitting.StackLanguage.Program.loop k p :: ps) = {ps, p :: Complexity.RationalHitting.StackLanguage.Program.loop k p :: ps}
Instances For
Finite control locations, computed structurally, despite unbounded loop iteration counts.
Equations
- One or more equations did not get rendered due to their size.
- Complexity.RationalHitting.StackLanguage.locations Complexity.RationalHitting.StackLanguage.Program.skip x✝ = {Complexity.RationalHitting.StackLanguage.Program.skip :: x✝, x✝}
- Complexity.RationalHitting.StackLanguage.locations (Complexity.RationalHitting.StackLanguage.Program.push a a_1) x✝ = {Complexity.RationalHitting.StackLanguage.Program.push a a_1 :: x✝, x✝}
- Complexity.RationalHitting.StackLanguage.locations (Complexity.RationalHitting.StackLanguage.Program.drop a) x✝ = {Complexity.RationalHitting.StackLanguage.Program.drop a :: x✝, x✝}
Instances For
The finite set of control labels used by the compiled program.
Equations
Instances For
Entry and halting are one actual macrostep apiece.