fact
stringlengths
6
3.84k
type
stringclasses
11 values
library
stringclasses
32 values
imports
listlengths
1
14
filename
stringlengths
20
95
symbolic_name
stringlengths
1
90
docstring
stringlengths
7
20k
@[simp] zero'_eval : zero'.eval = fun v => pure (0 :: v) := by simp [eval] @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
zero'_eval
null
succ_eval : succ.eval = fun v => pure [v.headI.succ] := by simp [eval] @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
succ_eval
null
tail_eval : tail.eval = fun v => pure v.tail := by simp [eval] @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
tail_eval
null
cons_eval (f fs) : (cons f fs).eval = fun v => do { let n ← Code.eval f v let ns ← Code.eval fs v pure (n.headI :: ns) } := by simp [eval] @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
cons_eval
null
comp_eval (f g) : (comp f g).eval = fun v => g.eval v >>= f.eval := by simp [eval] @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
comp_eval
null
case_eval (f g) : (case f g).eval = fun v => v.headI.rec (f.eval v.tail) fun y _ => g.eval (y::v.tail) := by simp [eval] @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
case_eval
null
fix_eval (f) : (fix f).eval = PFun.fix fun v => (f.eval v).map fun v => if v.headI = 0 then Sum.inl v.tail else Sum.inr v.tail := by simp [eval]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
fix_eval
null
nil : Code := tail.comp succ @[simp]
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
nil
`nil` is the constant nil function: `nil v = []`.
nil_eval (v) : nil.eval v = pure [] := by simp [nil]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
nil_eval
null
id : Code := tail.comp zero' @[simp]
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
id
`id` is the identity function: `id v = v`.
id_eval (v) : id.eval v = pure v := by simp [id]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
id_eval
null
head : Code := cons id nil @[simp]
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
head
`head` gets the head of the input list: `head [] = [0]`, `head (n :: v) = [n]`.
head_eval (v) : head.eval v = pure [v.headI] := by simp [head]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
head_eval
null
zero : Code := cons zero' nil @[simp]
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
zero
`zero` is the constant zero function: `zero v = [0]`.
zero_eval (v) : zero.eval v = pure [0] := by simp [zero]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
zero_eval
null
pred : Code := case zero head @[simp]
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
pred
`pred` returns the predecessor of the head of the input: `pred [] = [0]`, `pred (0 :: v) = [0]`, `pred (n+1 :: v) = [n]`.
pred_eval (v) : pred.eval v = pure [v.headI.pred] := by simp [pred]; cases v.headI <;> simp
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
pred_eval
null
rfind (f : Code) : Code := comp pred <| comp (fix <| cons f <| cons succ tail) zero'
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
rfind
`rfind f` performs the function of the `rfind` primitive of partial recursive functions. `rfind f v` returns the smallest `n` such that `(f (n :: v)).head = 0`. It is implemented as: rfind f v = pred (fix (fun (n::v) => f (n::v) :: n+1 :: v) (0 :: v)) The idea is that the initial state is `0 :: v`, and the `fix`...
prec (f g : Code) : Code := let G := cons tail <| cons succ <| cons (comp pred tail) <| cons (comp g <| cons id <| comp tail tail) <| comp tail <| comp tail tail let F := case id <| comp (comp (comp tail tail) (fix G)) zero' cons (comp F (cons head <| cons (comp f tail) tail)) nil attr...
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
prec
`prec f g` implements the `prec` (primitive recursion) operation of partial recursive functions. `prec f g` evaluates as: * `prec f g [] = [f []]` * `prec f g (0 :: v) = [f v]` * `prec f g (n+1 :: v) = [g (n :: prec f g (n :: v) :: v)]` It is implemented as: G (a :: b :: IH :: v) = (b :: a+1 :: b-1 :: g (a :: IH...
exists_code.comp {m n} {f : List.Vector ℕ n →. ℕ} {g : Fin n → List.Vector ℕ m →. ℕ} (hf : ∃ c : Code, ∀ v : List.Vector ℕ n, c.eval v.1 = pure <$> f v) (hg : ∀ i, ∃ c : Code, ∀ v : List.Vector ℕ m, c.eval v.1 = pure <$> g i v) : ∃ c : Code, ∀ v : List.Vector ℕ m, c.eval v.1 = pure <$> ((List.Vector.m...
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
exists_code.comp
null
exists_code {n} {f : List.Vector ℕ n →. ℕ} (hf : Nat.Partrec' f) : ∃ c : Code, ∀ v : List.Vector ℕ n, c.eval v.1 = pure <$> f v := by induction hf with | prim hf => induction hf with | zero => exact ⟨zero', fun ⟨[], _⟩ => rfl⟩ | succ => exact ⟨succ, fun ⟨[v], _⟩ => rfl⟩ | get i => refine F...
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
exists_code
null
Cont | halt | cons₁ : Code → List ℕ → Cont → Cont | cons₂ : List ℕ → Cont → Cont | comp : Code → Cont → Cont | fix : Code → Cont → Cont deriving Inhabited
inductive
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
Cont
The type of continuations, built up during evaluation of a `Code` expression.
Cont.eval : Cont → List ℕ →. List ℕ | Cont.halt => pure | Cont.cons₁ fs as k => fun v => do let ns ← Code.eval fs as Cont.eval k (v.headI :: ns) | Cont.cons₂ ns k => fun v => Cont.eval k (ns.headI :: v) | Cont.comp f k => fun v => Code.eval f v >>= Cont.eval k | Cont.fix f k => fun v => if v.headI = 0...
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
Cont.eval
The semantics of a continuation.
Cfg | halt : List ℕ → Cfg | ret : Cont → List ℕ → Cfg deriving Inhabited
inductive
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
Cfg
The set of configurations of the machine: * `halt v`: The machine is about to stop and `v : List ℕ` is the result. * `ret k v`: The machine is about to pass `v : List ℕ` to continuation `k : Cont`. We don't have a state corresponding to normal evaluation because these are evaluated immediately to a `ret` "in zero ste...
stepNormal : Code → Cont → List ℕ → Cfg | Code.zero' => fun k v => Cfg.ret k (0::v) | Code.succ => fun k v => Cfg.ret k [v.headI.succ] | Code.tail => fun k v => Cfg.ret k v.tail | Code.cons f fs => fun k v => stepNormal f (Cont.cons₁ fs v k) v | Code.comp f g => fun k v => stepNormal g (Cont.comp f k) v | C...
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
stepNormal
Evaluating `c : Code` in a continuation `k : Cont` and input `v : List ℕ`. This goes by recursion on `c`, building an augmented continuation and a value to pass to it. * `zero' v = 0 :: v` evaluates immediately, so we return it to the parent continuation * `succ v = [v.headI.succ]` evaluates immediately, so we return ...
stepRet : Cont → List ℕ → Cfg | Cont.halt, v => Cfg.halt v | Cont.cons₁ fs as k, v => stepNormal fs (Cont.cons₂ v k) as | Cont.cons₂ ns k, v => stepRet k (ns.headI :: v) | Cont.comp f k, v => stepNormal f k v | Cont.fix f k, v => if v.headI = 0 then stepRet k v.tail else stepNormal f (Cont.fix f k) v.tail
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
stepRet
Evaluating a continuation `k : Cont` on input `v : List ℕ`. This is the second part of evaluation, when we receive results from continuations built by `stepNormal`. * `Cont.halt v = v`, so we are done and transition to the `Cfg.halt v` state * `Cont.cons₁ fs as k v = k (v.headI :: fs as)`, so we evaluate `fs as` now w...
step : Cfg → Option Cfg | Cfg.halt _ => none | Cfg.ret k v => some (stepRet k v)
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
step
If we are not done (in `Cfg.halt` state), then we must be still stuck on a continuation, so this main loop calls `stepRet` with the new continuation. The overall `step` function transitions from one `Cfg` to another, only halting at the `Cfg.halt` state.
Cont.then : Cont → Cont → Cont | Cont.halt => fun k' => k' | Cont.cons₁ fs as k => fun k' => Cont.cons₁ fs as (k.then k') | Cont.cons₂ ns k => fun k' => Cont.cons₂ ns (k.then k') | Cont.comp f k => fun k' => Cont.comp f (k.then k') | Cont.fix f k => fun k' => Cont.fix f (k.then k')
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
Cont.then
In order to extract a compositional semantics from the sequential execution behavior of configurations, we observe that continuations have a monoid structure, with `Cont.halt` as the unit and `Cont.then` as the multiplication. `Cont.then k₁ k₂` runs `k₁` until it halts, and then takes the result of `k₁` and passes it t...
Cont.then_eval {k k' : Cont} {v} : (k.then k').eval v = k.eval v >>= k'.eval := by induction k generalizing v with | halt => simp only [Cont.eval, Cont.then, pure_bind] | cons₁ => simp only [Cont.eval, Cont.then, bind_assoc, *] | cons₂ => simp only [Cont.eval, Cont.then, *] | comp _ _ k_ih => simp only [Cont....
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
Cont.then_eval
null
Cfg.then : Cfg → Cont → Cfg | Cfg.halt v => fun k' => stepRet k' v | Cfg.ret k v => fun k' => Cfg.ret (k.then k') v
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
Cfg.then
The `then k` function is a "configuration homomorphism". Its operation on states is to append `k` to the continuation of a `Cfg.ret` state, and to run `k` on `v` if we are in the `Cfg.halt v` state.
stepNormal_then (c) (k k' : Cont) (v) : stepNormal c (k.then k') v = (stepNormal c k v).then k' := by induction c generalizing k v with simp only [stepNormal, *] | cons c c' ih _ => rw [← ih, Cont.then] | comp c c' _ ih' => rw [← ih', Cont.then] | case => cases v.headI <;> simp only [Nat.rec_zero] | fix c...
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
stepNormal_then
The `stepNormal` function respects the `then k'` homomorphism. Note that this is an exact equality, not a simulation; the original and embedded machines move in lock-step until the embedded machine reaches the halt state.
stepRet_then {k k' : Cont} {v} : stepRet (k.then k') v = (stepRet k v).then k' := by induction k generalizing v with simp only [Cont.then, stepRet, *] | cons₁ => rw [← stepNormal_then] rfl | comp => rw [← stepNormal_then] | fix _ _ k_ih => split_ifs · rw [← k_ih] · rw [← stepNormal_then]...
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
stepRet_then
The `stepRet` function respects the `then k'` homomorphism. Note that this is an exact equality, not a simulation; the original and embedded machines move in lock-step until the embedded machine reaches the halt state.
Code.Ok (c : Code) := ∀ k v, Turing.eval step (stepNormal c k v) = Code.eval c v >>= fun v => Turing.eval step (Cfg.ret k v)
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
Code.Ok
This is a temporary definition, because we will prove in `code_is_ok` that it always holds. It asserts that `c` is semantically correct; that is, for any `k` and `v`, `eval (stepNormal c k v) = eval (Cfg.ret k (Code.eval c v))`, as an equality of partial values (so one diverges iff the other does). In particular, we c...
Code.Ok.zero {c} (h : Code.Ok c) {v} : Turing.eval step (stepNormal c Cont.halt v) = Cfg.halt <$> Code.eval c v := by rw [h, ← bind_pure_comp]; congr; funext v exact Part.eq_some_iff.2 (mem_eval.2 ⟨ReflTransGen.single rfl, rfl⟩)
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
Code.Ok.zero
null
stepNormal.is_ret (c k v) : ∃ k' v', stepNormal c k v = Cfg.ret k' v' := by induction c generalizing k v with | cons _f fs IHf _IHfs => apply IHf | comp f _g _IHf IHg => apply IHg | case f g IHf IHg => rw [stepNormal] simp only [] cases v.headI <;> [apply IHf; apply IHg] | fix f IHf => apply IHf ...
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
stepNormal.is_ret
null
cont_eval_fix {f k v} (fok : Code.Ok f) : Turing.eval step (stepNormal f (Cont.fix f k) v) = f.fix.eval v >>= fun v => Turing.eval step (Cfg.ret k v) := by refine Part.ext fun x => ?_ simp only [Part.bind_eq_bind, Part.mem_bind_iff] constructor · suffices ∀ c, x ∈ eval step c → ∀ v c', c = Cfg.then c'...
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
cont_eval_fix
null
code_is_ok (c) : Code.Ok c := by induction c with (intro k v; rw [stepNormal]) | cons f fs IHf IHfs => rw [Code.eval, IHf] simp only [bind_assoc, pure_bind]; congr; funext v rw [reaches_eval]; swap · exact ReflTransGen.single rfl rw [stepRet, IHfs]; congr; funext v' refine Eq.trans (b := eva...
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
code_is_ok
null
stepNormal_eval (c v) : eval step (stepNormal c Cont.halt v) = Cfg.halt <$> c.eval v := (code_is_ok c).zero
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
stepNormal_eval
null
stepRet_eval {k v} : eval step (stepRet k v) = Cfg.halt <$> k.eval v := by induction k generalizing v with | halt => simp only [Cont.eval, map_pure] exact Part.eq_some_iff.2 (mem_eval.2 ⟨ReflTransGen.refl, rfl⟩) | cons₁ fs as k IH => rw [Cont.eval, stepRet, code_is_ok] simp only [← bind_pure_comp,...
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.PostTuringMachine", "Mathlib.Tactic.DeriveFintype" ]
Mathlib/Computability/TMConfig.lean
stepRet_eval
null
Γ' | consₗ | cons | bit0 | bit1 deriving DecidableEq, Inhabited, Fintype @[simp] theorem default_Γ' : (default : Γ') = .consₗ := rfl
inductive
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
Γ'
The alphabet for the stacks in the program. `bit0` and `bit1` are used to represent `ℕ` values as lists of binary digits, `cons` is used to separate `List ℕ` values, and `consₗ` is used to separate `List (List ℕ)` values. See the section documentation.
K' | main | rev | aux | stack deriving DecidableEq, Inhabited open K'
inductive
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
K'
The four stacks used by the program. `main` is used to store the input value in `trNormal` mode and the output value in `Λ'.ret` mode, while `stack` is used to keep all the data for the continuations. `rev` is used to store reversed lists when transferring values between stacks, and `aux` is only used once in `cons₁`. ...
Cont' | halt | cons₁ : Code → Cont' → Cont' | cons₂ : Cont' → Cont' | comp : Code → Cont' → Cont' | fix : Code → Cont' → Cont' deriving DecidableEq, Inhabited
inductive
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
Cont'
Continuations as in `ToPartrec.Cont` but with the data removed. This is done because we want the set of all continuations in the program to be finite (so that it can ultimately be encoded into the finite state machine of a Turing machine), but a continuation can handle a potentially infinite number of data values durin...
Λ' | move (p : Γ' → Bool) (k₁ k₂ : K') (q : Λ') | clear (p : Γ' → Bool) (k : K') (q : Λ') | copy (q : Λ') | push (k : K') (s : Option Γ' → Option Γ') (q : Λ') | read (f : Option Γ' → Λ') | succ (q : Λ') | pred (q₁ q₂ : Λ') | ret (k : Cont') compile_inductive% Code compile_inductive% Cont' compile_induct...
inductive
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
Λ'
The set of program positions. We make extensive use of inductive types here to let us describe "subroutines"; for example `clear p k q` is a program that clears stack `k`, then does `q` where `q` is another label. In order to prevent this from resulting in an infinite number of distinct accessible states, we are carefu...
Λ'.instInhabited : Inhabited Λ' := ⟨Λ'.ret Cont'.halt⟩
instance
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
Λ'.instInhabited
null
Λ'.instDecidableEq : DecidableEq Λ' := fun a b => by induction a generalizing b <;> cases b <;> first | apply Decidable.isFalse; rintro ⟨⟨⟩⟩; done | exact decidable_of_iff' _ (by simp [funext_iff]; rfl)
instance
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
Λ'.instDecidableEq
null
Stmt' := TM2.Stmt (fun _ : K' => Γ') Λ' (Option Γ') deriving Inhabited
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
Stmt'
The type of TM2 statements used by this machine.
Cfg' := TM2.Cfg (fun _ : K' => Γ') Λ' (Option Γ') deriving Inhabited open TM2.Stmt
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
Cfg'
The type of TM2 configurations used by this machine.
@[simp] natEnd : Γ' → Bool | Γ'.consₗ => true | Γ'.cons => true | _ => false attribute [nolint simpNF] natEnd.eq_3
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
natEnd
A predicate that detects the end of a natural number, either `Γ'.cons` or `Γ'.consₗ` (or implicitly the end of the list), for use in predicate-taking functions like `move` and `clear`.
@[simp] pop' (k : K') : Stmt' → Stmt' := pop k fun _ v => v
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
pop'
Pop a value from the stack and place the result in local store.
@[simp] peek' (k : K') : Stmt' → Stmt' := peek k fun _ v => v
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
peek'
Peek a value from the stack and place the result in local store.
@[simp] push' (k : K') : Stmt' → Stmt' := push k fun x => x.iget
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
push'
Push the value in the local store to the given stack.
unrev := Λ'.move (fun _ => false) rev main
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
unrev
Move everything from the `rev` stack to the `main` stack (reversed).
moveExcl (p k₁ k₂ q) := Λ'.move p k₁ k₂ <| Λ'.push k₁ id q
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
moveExcl
Move elements from `k₁` to `k₂` while `p` holds, with the last element being left on `k₁`.
move₂ (p k₁ k₂ q) := moveExcl p k₁ rev <| Λ'.move (fun _ => false) rev k₂ q
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
move₂
Move elements from `k₁` to `k₂` without reversion, by performing a double move via the `rev` stack.
head (k : K') (q : Λ') : Λ' := Λ'.move natEnd k rev <| (Λ'.push rev fun _ => some Γ'.cons) <| Λ'.read fun s => (if s = some Γ'.consₗ then id else Λ'.clear (fun x => x = Γ'.consₗ) k) <| unrev q
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
head
Assuming `trList v` is on the front of stack `k`, remove it, and push `v.headI` onto `main`. See the section documentation.
@[simp] trNormal : Code → Cont' → Λ' | Code.zero', k => (Λ'.push main fun _ => some Γ'.cons) <| Λ'.ret k | Code.succ, k => head main <| Λ'.succ <| Λ'.ret k | Code.tail, k => Λ'.clear natEnd main <| Λ'.ret k | Code.cons f fs, k => (Λ'.push stack fun _ => some Γ'.consₗ) <| Λ'.move (fun _ => false) main ...
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
trNormal
The program that evaluates code `c` with continuation `k`. This expects an initial state where `trList v` is on `main`, `trContStack k` is on `stack`, and `aux` and `rev` are empty. See the section documentation for details.
tr : Λ' → Stmt' | Λ'.move p k₁ k₂ q => pop' k₁ <| branch (fun s => s.elim true p) (goto fun _ => q) (push' k₂ <| goto fun _ => Λ'.move p k₁ k₂ q) | Λ'.push k f q => branch (fun s => (f s).isSome) ((push k fun s => (f s).iget) <| goto fun _ => q) (goto fun _ => q) | Λ'.read q => goto q ...
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
tr
The main program. See the section documentation for details.
tr_move (p k₁ k₂ q) : tr (Λ'.move p k₁ k₂ q) = pop' k₁ (branch (fun s => s.elim true p) (goto fun _ => q) (push' k₂ <| goto fun _ => Λ'.move p k₁ k₂ q)) := rfl @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
tr_move
null
tr_push (k f q) : tr (Λ'.push k f q) = branch (fun s => (f s).isSome) ((push k fun s => (f s).iget) <| goto fun _ => q) (goto fun _ => q) := rfl @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
tr_push
null
tr_read (q) : tr (Λ'.read q) = goto q := rfl @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
tr_read
null
tr_clear (p k q) : tr (Λ'.clear p k q) = pop' k (branch (fun s => s.elim true p) (goto fun _ => q) (goto fun _ => Λ'.clear p k q)) := rfl @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
tr_clear
null
tr_copy (q) : tr (Λ'.copy q) = pop' rev (branch Option.isSome (push' main <| push' stack <| goto fun _ => Λ'.copy q) (goto fun _ => q)) := rfl @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
tr_copy
null
tr_succ (q) : tr (Λ'.succ q) = pop' main (branch (fun s => s = some Γ'.bit1) ((push rev fun _ => Γ'.bit0) <| goto fun _ => Λ'.succ q) <| branch (fun s => s = some Γ'.cons) ((push main fun _ => Γ'.cons) <| (push main fun _ => Γ'.bit1) <| goto fun _ => unrev q) ((push main fun _ => Γ'.bit1) <| g...
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
tr_succ
null
tr_pred (q₁ q₂) : tr (Λ'.pred q₁ q₂) = pop' main (branch (fun s => s = some Γ'.bit0) ((push rev fun _ => Γ'.bit1) <| goto fun _ => Λ'.pred q₁ q₂) <| branch (fun s => natEnd s.iget) (goto fun _ => q₁) (peek' main <| branch (fun s => natEnd s.iget) (goto fun _ => unrev q₂) ((push rev fun _...
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
tr_pred
null
tr_ret_cons₁ (fs k) : tr (Λ'.ret (Cont'.cons₁ fs k)) = goto fun _ => move₂ (fun _ => false) main aux <| move₂ (fun s => s = Γ'.consₗ) stack main <| move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k) := rfl @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
tr_ret_cons₁
null
tr_ret_cons₂ (k) : tr (Λ'.ret (Cont'.cons₂ k)) = goto fun _ => head stack <| Λ'.ret k := rfl @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
tr_ret_cons₂
null
tr_ret_comp (f k) : tr (Λ'.ret (Cont'.comp f k)) = goto fun _ => trNormal f k := rfl @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
tr_ret_comp
null
tr_ret_fix (f k) : tr (Λ'.ret (Cont'.fix f k)) = pop' main (goto fun s => cond (natEnd s.iget) (Λ'.ret k) <| Λ'.clear natEnd main <| trNormal f (Cont'.fix f k)) := rfl @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
tr_ret_fix
null
tr_ret_halt : tr (Λ'.ret Cont'.halt) = (load fun _ => none) halt := rfl
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
tr_ret_halt
null
trCont : Cont → Cont' | Cont.halt => Cont'.halt | Cont.cons₁ c _ k => Cont'.cons₁ c (trCont k) | Cont.cons₂ _ k => Cont'.cons₂ (trCont k) | Cont.comp c k => Cont'.comp c (trCont k) | Cont.fix c k => Cont'.fix c (trCont k)
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
trCont
Translating a `Cont` continuation to a `Cont'` continuation simply entails dropping all the data. This data is instead encoded in `trContStack` in the configuration.
trPosNum : PosNum → List Γ' | PosNum.one => [Γ'.bit1] | PosNum.bit0 n => Γ'.bit0 :: trPosNum n | PosNum.bit1 n => Γ'.bit1 :: trPosNum n
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
trPosNum
We use `PosNum` to define the translation of binary natural numbers. A natural number is represented as a little-endian list of `bit0` and `bit1` elements: 1 = [bit1] 2 = [bit0, bit1] 3 = [bit1, bit1] 4 = [bit0, bit0, bit1] In particular, this representation guarantees no trailing `bit0`'s at the end ...
trNum : Num → List Γ' | Num.zero => [] | Num.pos n => trPosNum n
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
trNum
We use `Num` to define the translation of binary natural numbers. Positive numbers are translated using `trPosNum`, and `trNum 0 = []`. So there are never any trailing `bit0`'s in a translated `Num`. 0 = [] 1 = [bit1] 2 = [bit0, bit1] 3 = [bit1, bit1] 4 = [bit0, bit0, bit1]
trNat (n : ℕ) : List Γ' := trNum n @[simp]
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
trNat
Because we use binary encoding, we define `trNat` in terms of `trNum`, using `Num`, which are binary natural numbers. (We could also use `Nat.binaryRecOn`, but `Num` and `PosNum` make for easy inductions.)
trNat_zero : trNat 0 = [] := by rw [trNat, Nat.cast_zero]; rfl
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
trNat_zero
null
trNat_default : trNat default = [] := trNat_zero
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
trNat_default
null
@[simp] trList : List ℕ → List Γ' | [] => [] | n::ns => trNat n ++ Γ'.cons :: trList ns
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
trList
Lists are translated with a `cons` after each encoded number. For example: [] = [] [0] = [cons] [1] = [bit1, cons] [6, 0] = [bit0, bit1, bit1, cons, cons]
@[simp] trLList : List (List ℕ) → List Γ' | [] => [] | l::ls => trList l ++ Γ'.consₗ :: trLList ls
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
trLList
Lists of lists are translated with a `consₗ` after each encoded list. For example: [] = [] [[]] = [consₗ] [[], []] = [consₗ, consₗ] [[0]] = [cons, consₗ] [[1, 2], [0]] = [bit1, cons, bit0, bit1, cons, consₗ, cons, consₗ]
@[simp] contStack : Cont → List (List ℕ) | Cont.halt => [] | Cont.cons₁ _ ns k => ns :: contStack k | Cont.cons₂ ns k => ns :: contStack k | Cont.comp _ k => contStack k | Cont.fix _ k => contStack k
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
contStack
The data part of a continuation is a list of lists, which is encoded on the `stack` stack using `trLList`.
trContStack (k : Cont) := trLList (contStack k)
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
trContStack
The data part of a continuation is a list of lists, which is encoded on the `stack` stack using `trLList`.
K'.elim (a b c d : List Γ') : K' → List Γ' | K'.main => a | K'.rev => b | K'.aux => c | K'.stack => d
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
K'.elim
This is the nondependent eliminator for `K'`, but we use it specifically here in order to represent the stack data as four lists rather than as a function `K' → List Γ'`, because this makes rewrites easier. The theorems `K'.elim_update_main` et. al. show how such a function is updated after an `update` to one of the co...
K'.elim_main (a b c d) : K'.elim a b c d K'.main = a := rfl
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
K'.elim_main
null
K'.elim_rev (a b c d) : K'.elim a b c d K'.rev = b := rfl
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
K'.elim_rev
null
K'.elim_aux (a b c d) : K'.elim a b c d K'.aux = c := rfl
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
K'.elim_aux
null
K'.elim_stack (a b c d) : K'.elim a b c d K'.stack = d := rfl attribute [simp] K'.elim @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
K'.elim_stack
null
K'.elim_update_main {a b c d a'} : update (K'.elim a b c d) main a' = K'.elim a' b c d := by funext x; cases x <;> rfl @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
K'.elim_update_main
null
K'.elim_update_rev {a b c d b'} : update (K'.elim a b c d) rev b' = K'.elim a b' c d := by funext x; cases x <;> rfl @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
K'.elim_update_rev
null
K'.elim_update_aux {a b c d c'} : update (K'.elim a b c d) aux c' = K'.elim a b c' d := by funext x; cases x <;> rfl @[simp]
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
K'.elim_update_aux
null
K'.elim_update_stack {a b c d d'} : update (K'.elim a b c d) stack d' = K'.elim a b c d' := by funext x; cases x <;> rfl
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
K'.elim_update_stack
null
halt (v : List ℕ) : Cfg' := ⟨none, none, K'.elim (trList v) [] [] []⟩
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
halt
The halting state corresponding to a `List ℕ` output value.
TrCfg : Cfg → Cfg' → Prop | Cfg.ret k v, c' => ∃ s, c' = ⟨some (Λ'.ret (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)⟩ | Cfg.halt v, c' => c' = halt v
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
TrCfg
The `Cfg` states map to `Cfg'` states almost one to one, except that in normal operation the local store contains an arbitrary garbage value. To make the final theorem cleaner we explicitly clear it in the halt state so that there is exactly one configuration corresponding to output `v`.
splitAtPred {α} (p : α → Bool) : List α → List α × Option α × List α | [] => ([], none, []) | a :: as => cond (p a) ([], some a, as) <| let ⟨l₁, o, l₂⟩ := splitAtPred p as ⟨a::l₁, o, l₂⟩
def
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
splitAtPred
This could be a general list definition, but it is also somewhat specialized to this application. `splitAtPred p L` will search `L` for the first element satisfying `p`. If it is found, say `L = l₁ ++ a :: l₂` where `a` satisfies `p` but `l₁` does not, then it returns `(l₁, some a, l₂)`. Otherwise, if there is no such ...
splitAtPred_eq {α} (p : α → Bool) : ∀ L l₁ o l₂, (∀ x ∈ l₁, p x = false) → Option.elim' (L = l₁ ∧ l₂ = []) (fun a => p a = true ∧ L = l₁ ++ a::l₂) o → splitAtPred p L = (l₁, o, l₂) | [], _, none, _, _, ⟨rfl, rfl⟩ => rfl | [], l₁, some o, l₂, _, ⟨_, h₃⟩ => by simp at h₃ | a :: L, l₁, o,...
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
splitAtPred_eq
null
splitAtPred_false {α} (L : List α) : splitAtPred (fun _ => false) L = (L, none, []) := splitAtPred_eq _ _ _ _ _ (fun _ _ => rfl) ⟨rfl, rfl⟩
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
splitAtPred_false
null
move_ok {p k₁ k₂ q s L₁ o L₂} {S : K' → List Γ'} (h₁ : k₁ ≠ k₂) (e : splitAtPred p (S k₁) = (L₁, o, L₂)) : Reaches₁ (TM2.step tr) ⟨some (Λ'.move p k₁ k₂ q), s, S⟩ ⟨some q, o, update (update S k₁ L₂) k₂ (L₁.reverseAux (S k₂))⟩ := by induction L₁ generalizing S s with | nil => rw [(_ : [].reverseAux...
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
move_ok
null
unrev_ok {q s} {S : K' → List Γ'} : Reaches₁ (TM2.step tr) ⟨some (unrev q), s, S⟩ ⟨some q, none, update (update S rev []) main (List.reverseAux (S rev) (S main))⟩ := move_ok (by decide) <| splitAtPred_false _
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
unrev_ok
null
move₂_ok {p k₁ k₂ q s L₁ o L₂} {S : K' → List Γ'} (h₁ : k₁ ≠ rev ∧ k₂ ≠ rev ∧ k₁ ≠ k₂) (h₂ : S rev = []) (e : splitAtPred p (S k₁) = (L₁, o, L₂)) : Reaches₁ (TM2.step tr) ⟨some (move₂ p k₁ k₂ q), s, S⟩ ⟨some q, none, update (update S k₁ (o.elim id List.cons L₂)) k₂ (L₁ ++ S k₂)⟩ := by refine (move_ok h₁...
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
move₂_ok
null
clear_ok {p k q s L₁ o L₂} {S : K' → List Γ'} (e : splitAtPred p (S k) = (L₁, o, L₂)) : Reaches₁ (TM2.step tr) ⟨some (Λ'.clear p k q), s, S⟩ ⟨some q, o, update S k L₂⟩ := by induction L₁ generalizing S s with | nil => refine TransGen.head' rfl ?_ rw [tr]; simp only [pop', TM2.step, Option.mem_def, TM2.s...
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
clear_ok
null
copy_ok (q s a b c d) : Reaches₁ (TM2.step tr) ⟨some (Λ'.copy q), s, K'.elim a b c d⟩ ⟨some q, none, K'.elim (List.reverseAux b a) [] c (List.reverseAux b d)⟩ := by induction b generalizing a d s with | nil => refine TransGen.single ?_ simp | cons x b IH => refine TransGen.head rfl ?_ rw...
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
copy_ok
null
trPosNum_natEnd : ∀ (n), ∀ x ∈ trPosNum n, natEnd x = false | PosNum.one, _, List.Mem.head _ => rfl | PosNum.bit0 _, _, List.Mem.head _ => rfl | PosNum.bit0 n, _, List.Mem.tail _ h => trPosNum_natEnd n _ h | PosNum.bit1 _, _, List.Mem.head _ => rfl | PosNum.bit1 n, _, List.Mem.tail _ h => trPosNum_natEnd n _ ...
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
trPosNum_natEnd
null
trNum_natEnd : ∀ (n), ∀ x ∈ trNum n, natEnd x = false | Num.pos n, x, h => trPosNum_natEnd n x h
theorem
Computability
[ "Mathlib.Computability.Halting", "Mathlib.Computability.TuringMachine", "Mathlib.Data.Num.Lemmas", "Mathlib.Tactic.DeriveFintype", "Mathlib.Computability.TMConfig" ]
Mathlib/Computability/TMToPartrec.lean
trNum_natEnd
null