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
primrec_rfind' : Primrec rfind' := ofNat_iff.2 <| encode_iff.1 <| nat_add.comp (nat_double_succ.comp <| nat_double_succ.comp <| encode_iff.2 <| Primrec.ofNat Code) (const 4) @[deprecated (since := "2025-05-12")] alias rfind_prim := primrec_rfind'
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
primrec_rfind'
null
primrec_recOn' {α σ} [Primcodable α] [Primcodable σ] {c : α → Code} (hc : Primrec c) {z : α → σ} (hz : Primrec z) {s : α → σ} (hs : Primrec s) {l : α → σ} (hl : Primrec l) {r : α → σ} (hr : Primrec r) {pr : α → Code × Code × σ × σ → σ} (hpr : Primrec₂ pr) {co : α → Code × Code × σ × σ → σ} (hco : Primre...
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
primrec_recOn'
null
primrec_recOn {α σ} [Primcodable α] [Primcodable σ] {c : α → Code} (hc : Primrec c) {z : α → σ} (hz : Primrec z) {s : α → σ} (hs : Primrec s) {l : α → σ} (hl : Primrec l) {r : α → σ} (hr : Primrec r) {pr : α → Code → Code → σ → σ → σ} (hpr : Primrec fun a : α × Code × Code × σ × σ => pr a.1 a.2.1 a.2.2....
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
primrec_recOn
Recursion on `Nat.Partrec.Code` is primitive recursive.
computable_recOn {α σ} [Primcodable α] [Primcodable σ] {c : α → Code} (hc : Computable c) {z : α → σ} (hz : Computable z) {s : α → σ} (hs : Computable s) {l : α → σ} (hl : Computable l) {r : α → σ} (hr : Computable r) {pr : α → Code × Code × σ × σ → σ} (hpr : Computable₂ pr) {co : α → Code × Code × σ × σ → ...
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
computable_recOn
Recursion on `Nat.Partrec.Code` is computable.
eval : Code → ℕ →. ℕ | zero => pure 0 | succ => Nat.succ | left => ↑fun n : ℕ => n.unpair.1 | right => ↑fun n : ℕ => n.unpair.2 | pair cf cg => fun n => Nat.pair <$> eval cf n <*> eval cg n | comp cf cg => fun n => eval cg n >>= eval cf | prec cf cg => Nat.unpaired fun a n => n.rec (eval cf a) f...
def
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
eval
The interpretation of a `Nat.Partrec.Code` as a partial function. * `Nat.Partrec.Code.zero`: The constant zero function. * `Nat.Partrec.Code.succ`: The successor function. * `Nat.Partrec.Code.left`: Left unpairing of a pair of ℕ (encoded by `Nat.pair`) * `Nat.Partrec.Code.right`: Right unpairing of a pair of ℕ (encoded...
@[simp] eval_prec_zero (cf cg : Code) (a : ℕ) : eval (prec cf cg) (Nat.pair a 0) = eval cf a := by rw [eval, Nat.unpaired, Nat.unpair_pair] simp (config := { Lean.Meta.Simp.neutralConfig with proj := true }) only [] rw [Nat.rec_zero]
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
eval_prec_zero
Helper lemma for the evaluation of `prec` in the base case.
eval_prec_succ (cf cg : Code) (a k : ℕ) : eval (prec cf cg) (Nat.pair a (Nat.succ k)) = do {let ih ← eval (prec cf cg) (Nat.pair a k); eval cg (Nat.pair a (Nat.pair k ih))} := by rw [eval, Nat.unpaired, Part.bind_eq_bind, Nat.unpair_pair] simp
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
eval_prec_succ
Helper lemma for the evaluation of `prec` in the recursive case.
@[simp] eval_const : ∀ n m, eval (Code.const n) m = Part.some n | 0, _ => rfl | n + 1, m => by simp! [eval_const n m] @[simp]
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
eval_const
null
eval_id (n) : eval Code.id n = Part.some n := by simp! [Seq.seq, Code.id] @[simp]
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
eval_id
null
eval_curry (c n x) : eval (curry c n) x = eval c (Nat.pair n x) := by simp! [Seq.seq, curry]
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
eval_curry
null
primrec_const : Primrec Code.const := (_root_.Primrec.id.nat_iterate (_root_.Primrec.const zero) (primrec₂_comp.comp (_root_.Primrec.const succ) Primrec.snd).to₂).of_eq fun n => by simp; induction n <;> simp [*, Code.const, Function.iterate_succ', -Function.iterate_succ] @[deprecated (since := "2025-05-...
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
primrec_const
null
primrec₂_curry : Primrec₂ curry := primrec₂_comp.comp Primrec.fst <| primrec₂_pair.comp (primrec_const.comp Primrec.snd) (_root_.Primrec.const Code.id) @[deprecated (since := "2025-05-12")] alias curry_prim := primrec₂_curry
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
primrec₂_curry
null
curry_inj {c₁ c₂ n₁ n₂} (h : curry c₁ n₁ = curry c₂ n₂) : c₁ = c₂ ∧ n₁ = n₂ := ⟨by injection h, by injection h with h₁ h₂ injection h₂ with h₃ h₄ exact const_inj h₃⟩
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
curry_inj
null
smn : ∃ f : Code → ℕ → Code, Computable₂ f ∧ ∀ c n x, eval (f c n) x = eval c (Nat.pair n x) := ⟨curry, Primrec₂.to_comp primrec₂_curry, eval_curry⟩
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
smn
The $S_n^m$ theorem: There is a computable function, namely `Nat.Partrec.Code.curry`, that takes a program and a ℕ `n`, and returns a new program using `n` as the first argument.
exists_code {f : ℕ →. ℕ} : Nat.Partrec f ↔ ∃ c : Code, eval c = f := by refine ⟨fun h => ?_, ?_⟩ · induction h with | zero => exact ⟨zero, rfl⟩ | succ => exact ⟨succ, rfl⟩ | left => exact ⟨left, rfl⟩ | right => exact ⟨right, rfl⟩ | pair pf pg hf hg => rcases hf with ⟨cf, rfl⟩; rcases hg wi...
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
exists_code
A function is partial recursive if and only if there is a code implementing it. Therefore, `eval` is a **universal partial recursive function**.
evaln : ℕ → Code → ℕ → Option ℕ | 0, _ => fun _ => Option.none | k + 1, zero => fun n => do guard (n ≤ k) return 0 | k + 1, succ => fun n => do guard (n ≤ k) return (Nat.succ n) | k + 1, left => fun n => do guard (n ≤ k) return n.unpair.1 | k + 1, right => fun n => do guard (n ≤ k)...
def
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
evaln
A modified evaluation for the code which returns an `Option ℕ` instead of a `Part ℕ`. To avoid undecidability, `evaln` takes a parameter `k` and fails if it encounters a number ≥ k in the course of its execution. Other than this, the semantics are the same as in `Nat.Partrec.Code.eval`.
evaln_bound : ∀ {k c n x}, x ∈ evaln k c n → n < k | 0, c, n, x, h => by simp [evaln] at h | k + 1, c, n, x, h => by suffices ∀ {o : Option ℕ}, x ∈ do { guard (n ≤ k); o } → n < k + 1 by cases c <;> rw [evaln] at h <;> exact this h simpa [Option.bind_eq_some_iff] using Nat.lt_succ_of_le
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
evaln_bound
null
evaln_mono : ∀ {k₁ k₂ c n x}, k₁ ≤ k₂ → x ∈ evaln k₁ c n → x ∈ evaln k₂ c n | 0, k₂, c, n, x, _, h => by simp [evaln] at h | k + 1, k₂ + 1, c, n, x, hl, h => by have hl' := Nat.le_of_succ_le_succ hl have : ∀ {k k₂ n x : ℕ} {o₁ o₂ : Option ℕ}, k ≤ k₂ → (x ∈ o₁ → x ∈ o₂) → x ∈ do { gua...
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
evaln_mono
null
evaln_sound : ∀ {k c n x}, x ∈ evaln k c n → x ∈ eval c n | 0, _, n, x, h => by simp [evaln] at h | k + 1, c, n, x, h => by induction c generalizing x n <;> simp [eval, evaln, Option.bind_eq_some_iff, Seq.seq] at h ⊢ <;> obtain ⟨_, h⟩ := h iterate 4 simpa [pure, PFun.pure, eq_comm] using h case pa...
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
evaln_sound
null
evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n := by refine ⟨fun h => ?_, fun ⟨k, h⟩ => evaln_sound h⟩ rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n · exact ⟨k + 1, h⟩ induction c generalizing n x with simp [eval, evaln, pure, PFun.pure, Seq.seq, Option.bind_eq_some_iff] at h ⊢ | pair cf c...
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
evaln_complete
null
private lup (L : List (List (Option ℕ))) (p : ℕ × Code) (n : ℕ) := do let l ← L[encode p]? let o ← l[n]? o
def
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
lup
null
private hlup : Primrec fun p : _ × (_ × _) × _ => lup p.1 p.2.1 p.2.2 := Primrec.option_bind (Primrec.list_getElem?.comp Primrec.fst (Primrec.encode.comp <| Primrec.fst.comp Primrec.snd)) (Primrec.option_bind (Primrec.list_getElem?.comp Primrec.snd <| Primrec.snd.comp <| Primrec.snd.comp Primrec.fst) Pr...
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
hlup
null
private G (L : List (List (Option ℕ))) : Option (List (Option ℕ)) := Option.some <| let a := ofNat (ℕ × Code) L.length let k := a.1 let c := a.2 (List.range k).map fun n => k.casesOn Option.none fun k' => Nat.Partrec.Code.recOn c (some 0) -- zero (some (Nat.succ n)) ...
def
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
G
null
private hG : Primrec G := by have a := (Primrec.ofNat (ℕ × Code)).comp (Primrec.list_length (α := List (Option ℕ))) have k := Primrec.fst.comp a refine Primrec.option_some.comp (Primrec.list_map (Primrec.list_range.comp k) (?_ : Primrec _)) replace k := k.comp (Primrec.fst (β := ℕ)) have n := Primrec.snd (α :...
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
hG
null
private evaln_map (k c n) : ((List.range k)[n]?.bind fun a ↦ evaln k c a) = evaln k c n := by by_cases kn : n < k · simp [List.getElem?_range kn] · rw [List.getElem?_eq_none] · cases e : evaln k c n · rfl exact kn.elim (evaln_bound e) simpa using kn
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
evaln_map
null
primrec_evaln : Primrec fun a : (ℕ × Code) × ℕ => evaln a.1.1 a.1.2 a.2 := have : Primrec₂ fun (_ : Unit) (n : ℕ) => let a := ofNat (ℕ × Code) n (List.range a.1).map (evaln a.1 a.2) := Primrec.nat_strong_rec _ (hG.comp Primrec.snd).to₂ fun _ p => by simp only [G, prod_ofNat_val, ofNat_nat, L...
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
primrec_evaln
The `Nat.Partrec.Code.evaln` function is primitive recursive.
eval_eq_rfindOpt (c n) : eval c n = Nat.rfindOpt fun k => evaln k c n := Part.ext fun x => by refine evaln_complete.trans (Nat.rfindOpt_mono ?_).symm intro a m n hl; apply evaln_mono hl
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
eval_eq_rfindOpt
null
eval_part : Partrec₂ eval := (Partrec.rfindOpt (primrec_evaln.to_comp.comp ((Computable.snd.pair (fst.comp fst)).pair (snd.comp fst))).to₂).of_eq fun a => by simp [eval_eq_rfindOpt]
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
eval_part
null
fixed_point {f : Code → Code} (hf : Computable f) : ∃ c : Code, eval (f c) = eval c := let g (x y : ℕ) : Part ℕ := eval (ofNat Code x) x >>= fun b => eval (ofNat Code b) y have : Partrec₂ g := (eval_part.comp ((Computable.ofNat _).comp fst) fst).bind (eval_part.comp ((Computable.ofNat _).comp snd) (snd.co...
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
fixed_point
**Roger's fixed-point theorem**: any total, computable `f` has a fixed point. That is, under the interpretation given by `Nat.Partrec.Code.eval`, there is a code `c` such that `c` and `f c` have the same evaluation.
fixed_point₂ {f : Code → ℕ →. ℕ} (hf : Partrec₂ f) : ∃ c : Code, eval c = f c := let ⟨cf, ef⟩ := exists_code.1 hf (fixed_point (primrec₂_curry.comp (_root_.Primrec.const cf) Primrec.encode).to_comp).imp fun c e => funext fun n => by simp [e.symm, ef, Part.map_id']
theorem
Computability
[ "Mathlib.Computability.Partrec", "Mathlib.Data.Option.Basic" ]
Mathlib/Computability/PartrecCode.lean
fixed_point₂
**Kleene's second recursion theorem**
eval {σ} (f : σ → Option σ) : σ → Part σ := PFun.fix fun s ↦ Part.some <| (f s).elim (Sum.inl s) Sum.inr
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
eval
Run a state transition function `σ → Option σ` "to completion". The return value is the last state returned before a `none` result. If the state transition function always returns `some`, then the computation diverges, returning `Part.none`.
Reaches {σ} (f : σ → Option σ) : σ → σ → Prop := ReflTransGen fun a b ↦ b ∈ f a
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Reaches
The reflexive transitive closure of a state transition function. `Reaches f a b` means there is a finite sequence of steps `f a = some a₁`, `f a₁ = some a₂`, ... such that `aₙ = b`. This relation permits zero steps of the state transition function.
Reaches₁ {σ} (f : σ → Option σ) : σ → σ → Prop := TransGen fun a b ↦ b ∈ f a
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Reaches₁
The transitive closure of a state transition function. `Reaches₁ f a b` means there is a nonempty finite sequence of steps `f a = some a₁`, `f a₁ = some a₂`, ... such that `aₙ = b`. This relation does not permit zero steps of the state transition function.
reaches₁_eq {σ} {f : σ → Option σ} {a b c} (h : f a = f b) : Reaches₁ f a c ↔ Reaches₁ f b c := TransGen.head'_iff.trans (TransGen.head'_iff.trans <| by rw [h]).symm
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
reaches₁_eq
null
reaches_total {σ} {f : σ → Option σ} {a b c} (hab : Reaches f a b) (hac : Reaches f a c) : Reaches f b c ∨ Reaches f c b := ReflTransGen.total_of_right_unique (fun _ _ _ ↦ Option.mem_unique) hab hac
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
reaches_total
null
reaches₁_fwd {σ} {f : σ → Option σ} {a b c} (h₁ : Reaches₁ f a c) (h₂ : b ∈ f a) : Reaches f b c := by rcases TransGen.head'_iff.1 h₁ with ⟨b', hab, hbc⟩ cases Option.mem_unique hab h₂; exact hbc
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
reaches₁_fwd
null
Reaches₀ {σ} (f : σ → Option σ) (a b : σ) : Prop := ∀ c, Reaches₁ f b c → Reaches₁ f a c
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Reaches₀
A variation on `Reaches`. `Reaches₀ f a b` holds if whenever `Reaches₁ f b c` then `Reaches₁ f a c`. This is a weaker property than `Reaches` and is useful for replacing states with equivalent states without taking a step.
Reaches₀.trans {σ} {f : σ → Option σ} {a b c : σ} (h₁ : Reaches₀ f a b) (h₂ : Reaches₀ f b c) : Reaches₀ f a c | _, h₃ => h₁ _ (h₂ _ h₃) @[refl]
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Reaches₀.trans
null
Reaches₀.refl {σ} {f : σ → Option σ} (a : σ) : Reaches₀ f a a | _, h => h
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Reaches₀.refl
null
Reaches₀.single {σ} {f : σ → Option σ} {a b : σ} (h : b ∈ f a) : Reaches₀ f a b | _, h₂ => h₂.head h
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Reaches₀.single
null
Reaches₀.head {σ} {f : σ → Option σ} {a b c : σ} (h : b ∈ f a) (h₂ : Reaches₀ f b c) : Reaches₀ f a c := (Reaches₀.single h).trans h₂
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Reaches₀.head
null
Reaches₀.tail {σ} {f : σ → Option σ} {a b c : σ} (h₁ : Reaches₀ f a b) (h : c ∈ f b) : Reaches₀ f a c := h₁.trans (Reaches₀.single h)
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Reaches₀.tail
null
reaches₀_eq {σ} {f : σ → Option σ} {a b} (e : f a = f b) : Reaches₀ f a b | _, h => (reaches₁_eq e).2 h
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
reaches₀_eq
null
Reaches₁.to₀ {σ} {f : σ → Option σ} {a b : σ} (h : Reaches₁ f a b) : Reaches₀ f a b | _, h₂ => h.trans h₂
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Reaches₁.to₀
null
Reaches.to₀ {σ} {f : σ → Option σ} {a b : σ} (h : Reaches f a b) : Reaches₀ f a b | _, h₂ => h₂.trans_right h
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Reaches.to₀
null
Reaches₀.tail' {σ} {f : σ → Option σ} {a b c : σ} (h : Reaches₀ f a b) (h₂ : c ∈ f b) : Reaches₁ f a c := h _ (TransGen.single h₂)
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Reaches₀.tail'
null
@[elab_as_elim] evalInduction {σ} {f : σ → Option σ} {b : σ} {C : σ → Sort*} {a : σ} (h : b ∈ eval f a) (H : ∀ a, b ∈ eval f a → (∀ a', f a = some a' → C a') → C a) : C a := PFun.fixInduction h fun a' ha' h' ↦ H _ ha' fun b' e ↦ h' _ <| Part.mem_some_iff.2 <| by rw [e]; rfl
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
evalInduction
(co-)Induction principle for `eval`. If a property `C` holds of any point `a` evaluating to `b` which is either terminal (meaning `a = b`) or where the next point also satisfies `C`, then it holds of any point where `eval f a` evaluates to `b`. This formalizes the notion that if `eval f a` evaluates to `b` then it reac...
mem_eval {σ} {f : σ → Option σ} {a b} : b ∈ eval f a ↔ Reaches f a b ∧ f b = none := by refine ⟨fun h ↦ ?_, fun ⟨h₁, h₂⟩ ↦ ?_⟩ · refine evalInduction h fun a h IH ↦ ?_ rcases e : f a with - | a' · rw [Part.mem_unique h (PFun.mem_fix_iff.2 <| Or.inl <| Part.mem_some_iff.2 <| by rw [e]; rfl)] ...
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
mem_eval
null
eval_maximal₁ {σ} {f : σ → Option σ} {a b} (h : b ∈ eval f a) (c) : ¬Reaches₁ f b c | bc => by let ⟨_, b0⟩ := mem_eval.1 h let ⟨b', h', _⟩ := TransGen.head'_iff.1 bc cases b0.symm.trans h'
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
eval_maximal₁
null
eval_maximal {σ} {f : σ → Option σ} {a b} (h : b ∈ eval f a) {c} : Reaches f b c ↔ c = b := let ⟨_, b0⟩ := mem_eval.1 h reflTransGen_iff_eq fun b' h' ↦ by cases b0.symm.trans h'
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
eval_maximal
null
reaches_eval {σ} {f : σ → Option σ} {a b} (ab : Reaches f a b) : eval f a = eval f b := by refine Part.ext fun _ ↦ ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · have ⟨ac, c0⟩ := mem_eval.1 h exact mem_eval.2 ⟨(or_iff_left_of_imp fun cb ↦ (eval_maximal h).1 cb ▸ ReflTransGen.refl).1 (reaches_total ab ac), c0⟩ · have ⟨bc, c...
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
reaches_eval
null
Respects {σ₁ σ₂} (f₁ : σ₁ → Option σ₁) (f₂ : σ₂ → Option σ₂) (tr : σ₁ → σ₂ → Prop) := ∀ ⦃a₁ a₂⦄, tr a₁ a₂ → (match f₁ a₁ with | some b₁ => ∃ b₂, tr b₁ b₂ ∧ Reaches₁ f₂ a₂ b₂ | none => f₂ a₂ = none : Prop)
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Respects
Given a relation `tr : σ₁ → σ₂ → Prop` between state spaces, and state transition functions `f₁ : σ₁ → Option σ₁` and `f₂ : σ₂ → Option σ₂`, `Respects f₁ f₂ tr` means that if `tr a₁ a₂` holds initially and `f₁` takes a step to `a₂` then `f₂` will take one or more steps before reaching a state `b₂` satisfying `tr a₂ b₂`...
tr_reaches₁ {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ a₂} (aa : tr a₁ a₂) {b₁} (ab : Reaches₁ f₁ a₁ b₁) : ∃ b₂, tr b₁ b₂ ∧ Reaches₁ f₂ a₂ b₂ := by induction ab with | single ac => have := H aa rwa [show f₁ a₁ = _ from ac] at this | @tail c₁ d₁ _ cd IH => rcases IH with ⟨c₂, c...
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
tr_reaches₁
null
tr_reaches {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ a₂} (aa : tr a₁ a₂) {b₁} (ab : Reaches f₁ a₁ b₁) : ∃ b₂, tr b₁ b₂ ∧ Reaches f₂ a₂ b₂ := by rcases reflTransGen_iff_eq_or_transGen.1 ab with (rfl | ab) · exact ⟨_, aa, ReflTransGen.refl⟩ · have ⟨b₂, bb, h⟩ := tr_reaches₁ H aa ab exa...
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
tr_reaches
null
tr_reaches_rev {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ a₂} (aa : tr a₁ a₂) {b₂} (ab : Reaches f₂ a₂ b₂) : ∃ c₁ c₂, Reaches f₂ b₂ c₂ ∧ tr c₁ c₂ ∧ Reaches f₁ a₁ c₁ := by induction ab with | refl => exact ⟨_, _, ReflTransGen.refl, aa, ReflTransGen.refl⟩ | tail _ cd IH => rcases IH...
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
tr_reaches_rev
null
tr_eval {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ b₁ a₂} (aa : tr a₁ a₂) (ab : b₁ ∈ eval f₁ a₁) : ∃ b₂, tr b₁ b₂ ∧ b₂ ∈ eval f₂ a₂ := by obtain ⟨ab, b0⟩ := mem_eval.1 ab rcases tr_reaches H aa ab with ⟨b₂, bb, ab⟩ refine ⟨_, bb, mem_eval.2 ⟨ab, ?_⟩⟩ have := H bb; rwa [b0] at this
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
tr_eval
null
tr_eval_rev {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ b₂ a₂} (aa : tr a₁ a₂) (ab : b₂ ∈ eval f₂ a₂) : ∃ b₁, tr b₁ b₂ ∧ b₁ ∈ eval f₁ a₁ := by obtain ⟨ab, b0⟩ := mem_eval.1 ab rcases tr_reaches_rev H aa ab with ⟨c₁, c₂, bc, cc, ac⟩ cases (reflTransGen_iff_eq (Option.eq_none_iff_forall_not_...
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
tr_eval_rev
null
tr_eval_dom {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ a₂} (aa : tr a₁ a₂) : (eval f₂ a₂).Dom ↔ (eval f₁ a₁).Dom := ⟨fun h ↦ let ⟨_, _, h, _⟩ := tr_eval_rev H aa ⟨h, rfl⟩ h, fun h ↦ let ⟨_, _, h, _⟩ := tr_eval H aa ⟨h, rfl⟩ h⟩
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
tr_eval_dom
null
FRespects {σ₁ σ₂} (f₂ : σ₂ → Option σ₂) (tr : σ₁ → σ₂) (a₂ : σ₂) : Option σ₁ → Prop | some b₁ => Reaches₁ f₂ a₂ (tr b₁) | none => f₂ a₂ = none
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
FRespects
A simpler version of `Respects` when the state transition relation `tr` is a function.
frespects_eq {σ₁ σ₂} {f₂ : σ₂ → Option σ₂} {tr : σ₁ → σ₂} {a₂ b₂} (h : f₂ a₂ = f₂ b₂) : ∀ {b₁}, FRespects f₂ tr a₂ b₁ ↔ FRespects f₂ tr b₂ b₁ | some _ => reaches₁_eq h | none => by unfold FRespects; rw [h]
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
frespects_eq
null
fun_respects {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂} : (Respects f₁ f₂ fun a b ↦ tr a = b) ↔ ∀ ⦃a₁⦄, FRespects f₂ tr (tr a₁) (f₁ a₁) := forall_congr' fun a₁ ↦ by cases f₁ a₁ <;> simp only [FRespects, exists_eq_left', forall_eq']
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
fun_respects
null
tr_eval' {σ₁ σ₂} (f₁ : σ₁ → Option σ₁) (f₂ : σ₂ → Option σ₂) (tr : σ₁ → σ₂) (H : Respects f₁ f₂ fun a b ↦ tr a = b) (a₁) : eval f₂ (tr a₁) = tr <$> eval f₁ a₁ := Part.ext fun b₂ ↦ ⟨fun h ↦ let ⟨b₁, bb, hb⟩ := tr_eval_rev H rfl h (Part.mem_map_iff _).2 ⟨b₁, hb, bb⟩, fun h ↦ by rcases (P...
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
tr_eval'
null
Stmt | move : Dir → Stmt | write : Γ → Stmt
inductive
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Stmt
A Turing machine "statement" is just a command to either move left or right, or write a symbol on the tape.
Stmt.inhabited [Inhabited Γ] : Inhabited (Stmt Γ) := ⟨Stmt.write default⟩
instance
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Stmt.inhabited
null
Cfg [Inhabited Γ] where /-- The current machine state. -/ q : Λ /-- The current state of the tape: current symbol, left and right parts. -/ Tape : Tape Γ variable {Γ Λ} variable [Inhabited Λ]
structure
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Cfg
A Post-Turing machine with symbol type `Γ` and label type `Λ` is a function which, given the current state `q : Λ` and the tape head `a : Γ`, either halts (returns `none`) or returns a new state `q' : Λ` and a `Stmt` describing what to do, either a move left or right, or a write command. Both `Λ` and `Γ` are...
Cfg.inhabited : Inhabited (Cfg Γ Λ) := ⟨⟨default, default⟩⟩
instance
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Cfg.inhabited
null
step (M : Machine Γ Λ) : Cfg Γ Λ → Option (Cfg Γ Λ) := fun ⟨q, T⟩ ↦ (M q T.1).map fun ⟨q', a⟩ ↦ ⟨q', match a with | Stmt.move d => T.move d | Stmt.write a => T.write a⟩
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
step
Execution semantics of the Turing machine.
Reaches (M : Machine Γ Λ) : Cfg Γ Λ → Cfg Γ Λ → Prop := ReflTransGen fun a b ↦ b ∈ step M a
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Reaches
The statement `Reaches M s₁ s₂` means that `s₂` is obtained starting from `s₁` after a finite number of steps from `s₂`.
init (l : List Γ) : Cfg Γ Λ := ⟨default, Tape.mk₁ l⟩
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
init
The initial configuration.
eval (M : Machine Γ Λ) (l : List Γ) : Part (ListBlank Γ) := (Turing.eval (step M) (init l)).map fun c ↦ c.Tape.right₀
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
eval
Evaluate a Turing machine on initial input to a final state, if it terminates.
Supports (M : Machine Γ Λ) (S : Set Λ) := default ∈ S ∧ ∀ {q a q' s}, (q', s) ∈ M q a → q ∈ S → q' ∈ S
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Supports
The raw definition of a Turing machine does not require that `Γ` and `Λ` are finite, and in practice we will be interested in the infinite `Λ` case. We recover instead a notion of "effectively finite" Turing machines, which only make use of a finite subset of their states. We say that a set `S ⊆ Λ` supports a...
step_supports (M : Machine Γ Λ) {S : Set Λ} (ss : Supports M S) : ∀ {c c' : Cfg Γ Λ}, c' ∈ step M c → c.q ∈ S → c'.q ∈ S := by intro ⟨q, T⟩ c' h₁ h₂ rcases Option.map_eq_some_iff.1 h₁ with ⟨⟨q', a⟩, h, rfl⟩ exact ss.2 h h₂
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
step_supports
null
univ_supports (M : Machine Γ Λ) : Supports M Set.univ := by constructor <;> intros <;> apply Set.mem_univ
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
univ_supports
null
Stmt.map (f : PointedMap Γ Γ') : Stmt Γ → Stmt Γ' | Stmt.move d => Stmt.move d | Stmt.write a => Stmt.write (f a)
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Stmt.map
Map a TM statement across a function. This does nothing to move statements and maps the write values.
Cfg.map (f : PointedMap Γ Γ') (g : Λ → Λ') : Cfg Γ Λ → Cfg Γ' Λ' | ⟨q, T⟩ => ⟨g q, T.map f⟩ variable (M : Machine Γ Λ) (f₁ : PointedMap Γ Γ') (f₂ : PointedMap Γ' Γ) (g₁ : Λ → Λ') (g₂ : Λ' → Λ)
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Cfg.map
Map a configuration across a function, given `f : Γ → Γ'` a map of the alphabets and `g : Λ → Λ'` a map of the machine states.
Machine.map : Machine Γ' Λ' | q, l => (M (g₂ q) (f₂ l)).map (Prod.map g₁ (Stmt.map f₁))
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Machine.map
Because the state transition function uses the alphabet and machine states in both the input and output, to map a machine from one alphabet and machine state space to another we need functions in both directions, essentially an `Equiv` without the laws.
Machine.map_step {S : Set Λ} (f₂₁ : Function.RightInverse f₁ f₂) (g₂₁ : ∀ q ∈ S, g₂ (g₁ q) = q) : ∀ c : Cfg Γ Λ, c.q ∈ S → (step M c).map (Cfg.map f₁ g₁) = step (M.map f₁ f₂ g₁ g₂) (Cfg.map f₁ g₁ c) | ⟨q, T⟩, h => by unfold step Machine.map Cfg.map simp only [Turing.Tape.map_fst, g₂₁ q h, f₂₁ _]...
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Machine.map_step
null
map_init (g₁ : PointedMap Λ Λ') (l : List Γ) : (init l).map f₁ g₁ = init (l.map f₁) := congr (congr_arg Cfg.mk g₁.map_pt) (Tape.map_mk₁ _ _)
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
map_init
null
Machine.map_respects (g₁ : PointedMap Λ Λ') (g₂ : Λ' → Λ) {S} (ss : Supports M S) (f₂₁ : Function.RightInverse f₁ f₂) (g₂₁ : ∀ q ∈ S, g₂ (g₁ q) = q) : Respects (step M) (step (M.map f₁ f₂ g₁ g₂)) fun a b ↦ a.q ∈ S ∧ Cfg.map f₁ g₁ a = b := by intro c _ ⟨cs, rfl⟩ cases e : step M c · rw [← M.map_step f₁ f₂ ...
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Machine.map_respects
null
Stmt | move : Dir → Stmt → Stmt | write : (Γ → σ → Γ) → Stmt → Stmt | load : (Γ → σ → σ) → Stmt → Stmt | branch : (Γ → σ → Bool) → Stmt → Stmt → Stmt | goto : (Γ → σ → Λ) → Stmt | halt : Stmt open Stmt
inductive
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Stmt
The TM1 model is a simplification and extension of TM0 (Post-Turing model) in the direction of Wang B-machines. The machine's internal state is extended with a (finite) store `σ` of variables that may be accessed and updated at any time. A machine is given by a `Λ` indexed set of procedures or functions. Each...
Stmt.inhabited : Inhabited (Stmt Γ Λ σ) := ⟨halt⟩
instance
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Stmt.inhabited
null
Cfg [Inhabited Γ] where /-- The statement (if any) which is currently evaluated -/ l : Option Λ /-- The current value of the variable store -/ var : σ /-- The current state of the tape -/ Tape : Tape Γ
structure
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Cfg
The configuration of a TM1 machine is given by the currently evaluating statement, the variable store value, and the tape.
Cfg.inhabited [Inhabited Γ] [Inhabited σ] : Inhabited (Cfg Γ Λ σ) := ⟨⟨default, default, default⟩⟩ variable {Γ Λ σ}
instance
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Cfg.inhabited
null
stepAux [Inhabited Γ] : Stmt Γ Λ σ → σ → Tape Γ → Cfg Γ Λ σ | move d q, v, T => stepAux q v (T.move d) | write a q, v, T => stepAux q v (T.write (a T.1 v)) | load s q, v, T => stepAux q (s T.1 v) T | branch p q₁ q₂, v, T => cond (p T.1 v) (stepAux q₁ v T) (stepAux q₂ v T) | goto l, v, T => ⟨some (l T.1 v), v,...
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
stepAux
The semantics of TM1 evaluation.
step [Inhabited Γ] (M : Λ → Stmt Γ Λ σ) : Cfg Γ Λ σ → Option (Cfg Γ Λ σ) | ⟨none, _, _⟩ => none | ⟨some l, v, T⟩ => some (stepAux (M l) v T)
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
step
The state transition function.
SupportsStmt (S : Finset Λ) : Stmt Γ Λ σ → Prop | move _ q => SupportsStmt S q | write _ q => SupportsStmt S q | load _ q => SupportsStmt S q | branch _ q₁ q₂ => SupportsStmt S q₁ ∧ SupportsStmt S q₂ | goto l => ∀ a v, l a v ∈ S | halt => True open scoped Classical in
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
SupportsStmt
A set `S` of labels supports the statement `q` if all the `goto` statements in `q` refer only to other functions in `S`.
noncomputable stmts₁ : Stmt Γ Λ σ → Finset (Stmt Γ Λ σ) | Q@(move _ q) => insert Q (stmts₁ q) | Q@(write _ q) => insert Q (stmts₁ q) | Q@(load _ q) => insert Q (stmts₁ q) | Q@(branch _ q₁ q₂) => insert Q (stmts₁ q₁ ∪ stmts₁ q₂) | Q => {Q}
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
stmts₁
The subterm closure of a statement.
stmts₁_self {q : Stmt Γ Λ σ} : q ∈ stmts₁ q := by cases q <;> simp only [stmts₁, Finset.mem_insert_self, Finset.mem_singleton_self]
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
stmts₁_self
null
stmts₁_trans {q₁ q₂ : Stmt Γ Λ σ} : q₁ ∈ stmts₁ q₂ → stmts₁ q₁ ⊆ stmts₁ q₂ := by classical intro h₁₂ q₀ h₀₁ induction q₂ with ( simp only [stmts₁] at h₁₂ ⊢ simp only [Finset.mem_insert, Finset.mem_union, Finset.mem_singleton] at h₁₂) | branch p q₁ q₂ IH₁ IH₂ => rcases h₁₂ with (rfl | h₁₂ | h₁₂) ...
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
stmts₁_trans
null
stmts₁_supportsStmt_mono {S : Finset Λ} {q₁ q₂ : Stmt Γ Λ σ} (h : q₁ ∈ stmts₁ q₂) (hs : SupportsStmt S q₂) : SupportsStmt S q₁ := by induction q₂ with simp only [stmts₁, SupportsStmt, Finset.mem_insert, Finset.mem_union, Finset.mem_singleton] at h hs | branch p q₁ q₂ IH₁ IH₂ => rcases h with (rfl | h ...
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
stmts₁_supportsStmt_mono
null
noncomputable stmts (M : Λ → Stmt Γ Λ σ) (S : Finset Λ) : Finset (Option (Stmt Γ Λ σ)) := Finset.insertNone (S.biUnion fun q ↦ stmts₁ (M q))
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
stmts
The set of all statements in a Turing machine, plus one extra value `none` representing the halt state. This is used in the TM1 to TM0 reduction.
stmts_trans {M : Λ → Stmt Γ Λ σ} {S : Finset Λ} {q₁ q₂ : Stmt Γ Λ σ} (h₁ : q₁ ∈ stmts₁ q₂) : some q₂ ∈ stmts M S → some q₁ ∈ stmts M S := by simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq, forall_eq', exists_imp, and_imp] exact fun l ls h₂ ↦ ⟨_, ls, stmts₁_tra...
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
stmts_trans
null
Supports (M : Λ → Stmt Γ Λ σ) (S : Finset Λ) := default ∈ S ∧ ∀ q ∈ S, SupportsStmt S (M q)
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
Supports
A set `S` of labels supports machine `M` if all the `goto` statements in the functions in `S` refer only to other functions in `S`.
stmts_supportsStmt {M : Λ → Stmt Γ Λ σ} {S : Finset Λ} {q : Stmt Γ Λ σ} (ss : Supports M S) : some q ∈ stmts M S → SupportsStmt S q := by simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq, forall_eq', exists_imp, and_imp] exact fun l ls h ↦ stmts₁_supportsStmt_mo...
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
stmts_supportsStmt
null
step_supports (M : Λ → Stmt Γ Λ σ) {S : Finset Λ} (ss : Supports M S) : ∀ {c c' : Cfg Γ Λ σ}, c' ∈ step M c → c.l ∈ Finset.insertNone S → c'.l ∈ Finset.insertNone S | ⟨some l₁, v, T⟩, c', h₁, h₂ => by replace h₂ := ss.2 _ (Finset.some_mem_insertNone.1 h₂) simp only [step, Option.mem_def, Option.some.injEq...
theorem
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
step_supports
null
init (l : List Γ) : Cfg Γ Λ σ := ⟨some default, default, Tape.mk₁ l⟩
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
init
The initial state, given a finite input that is placed on the tape starting at the TM head and going to the right.
eval (M : Λ → Stmt Γ Λ σ) (l : List Γ) : Part (ListBlank Γ) := (Turing.eval (step M) (init l)).map fun c ↦ c.Tape.right₀
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
eval
Evaluate a TM to completion, resulting in an output list on the tape (with an indeterminate number of blanks on the end).
trAux (s : Γ) : TM1.Stmt Γ Λ σ → σ → Λ' M × TM0.Stmt Γ | TM1.Stmt.move d q, v => ((some q, v), move d) | TM1.Stmt.write a q, v => ((some q, v), write (a s v)) | TM1.Stmt.load a q, v => trAux s q (a s v) | TM1.Stmt.branch p q₁ q₂, v => cond (p s v) (trAux s q₁ v) (trAux s q₂ v) | TM1.Stmt.goto l, v => ((some (...
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
trAux
The base machine state space is a pair of an `Option Stmt₁` representing the current program to be executed, or `none` for the halt state, and a `σ` which is the local state (stored in the TM, not the tape). Because there are an infinite number of programs, this state space is infinite, but for a finitely supported TM1...
tr : TM0.Machine Γ (Λ' M) | (none, _), _ => none | (some q, v), s => some (trAux M s q v)
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
tr
The translated TM0 machine (given the TM1 machine input).
trCfg [Inhabited Γ] : TM1.Cfg Γ Λ σ → TM0.Cfg Γ (Λ' M) | ⟨l, v, T⟩ => ⟨(l.map M, v), T⟩
def
Computability
[ "Mathlib.Computability.Tape", "Mathlib.Data.Finset.Prod", "Mathlib.Data.Finset.Option", "Mathlib.Data.Fintype.Defs", "Mathlib.Data.PFun" ]
Mathlib/Computability/PostTuringMachine.lean
trCfg
Translate configurations from TM1 to TM0.