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 ⌀ |
|---|---|---|---|---|---|---|
trNat_natEnd (n) : ∀ x ∈ trNat n, natEnd x = false :=
trNum_natEnd _ | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | trNat_natEnd | null |
trList_ne_consₗ : ∀ (l), ∀ x ∈ trList l, x ≠ Γ'.consₗ
| a :: l, x, h => by
simp only [trList, List.mem_append, List.mem_cons] at h
obtain h | rfl | h := h
· rintro rfl
cases trNat_natEnd _ _ h
· rintro ⟨⟩
· exact trList_ne_consₗ l _ h | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | trList_ne_consₗ | null |
head_main_ok {q s L} {c d : List Γ'} :
Reaches₁ (TM2.step tr) ⟨some (head main q), s, K'.elim (trList L) [] c d⟩
⟨some q, none, K'.elim (trList [L.headI]) [] c d⟩ := by
let o : Option Γ' := List.casesOn L none fun _ _ => some Γ'.cons
refine
(move_ok (by decide)
(splitAtPred_eq _ _ (trNat L.headI) o (trList L.tail) (trNat_natEnd _) ?_)).trans
(TransGen.head rfl (TransGen.head rfl ?_))
· cases L <;> simp [o]
rw [tr]
simp only [TM2.step, Option.mem_def, TM2.stepAux, elim_update_main, elim_rev, elim_update_rev,
Function.update_self, trList]
rw [if_neg (show o ≠ some Γ'.consₗ by cases L <;> simp [o])]
refine (clear_ok (splitAtPred_eq _ _ _ none [] ?_ ⟨rfl, rfl⟩)).trans ?_
· exact fun x h => Bool.decide_false (trList_ne_consₗ _ _ h)
convert unrev_ok using 2; simp [List.reverseAux_eq] | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | head_main_ok | null |
head_stack_ok {q s L₁ L₂ L₃} :
Reaches₁ (TM2.step tr)
⟨some (head stack q), s, K'.elim (trList L₁) [] [] (trList L₂ ++ Γ'.consₗ :: L₃)⟩
⟨some q, none, K'.elim (trList (L₂.headI :: L₁)) [] [] L₃⟩ := by
rcases L₂ with - | ⟨a, L₂⟩
· refine
TransGen.trans
(move_ok (by decide)
(splitAtPred_eq _ _ [] (some Γ'.consₗ) L₃ (by rintro _ ⟨⟩) ⟨rfl, rfl⟩))
(TransGen.head rfl (TransGen.head rfl ?_))
rw [tr]
simp only [TM2.step, Option.mem_def, TM2.stepAux, ite_true, id_eq, trList, List.nil_append,
elim_update_stack, elim_rev, List.reverseAux_nil, elim_update_rev, Function.update_self,
List.headI_nil, trNat_default]
convert unrev_ok using 2
simp
· refine
TransGen.trans
(move_ok (by decide)
(splitAtPred_eq _ _ (trNat a) (some Γ'.cons) (trList L₂ ++ Γ'.consₗ :: L₃)
(trNat_natEnd _) ⟨rfl, by simp⟩))
(TransGen.head rfl (TransGen.head rfl ?_))
simp only [TM2.step, Option.mem_def, trList, List.append_assoc,
List.cons_append, elim_update_stack, elim_rev, elim_update_rev, Function.update_self,
List.headI_cons]
refine
TransGen.trans
(clear_ok
(splitAtPred_eq _ _ (trList L₂) (some Γ'.consₗ) L₃
(fun x h => Bool.decide_false (trList_ne_consₗ _ _ h)) ⟨rfl, by simp⟩))
?_
convert unrev_ok using 2
simp [List.reverseAux_eq] | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | head_stack_ok | null |
succ_ok {q s n} {c d : List Γ'} :
Reaches₁ (TM2.step tr) ⟨some (Λ'.succ q), s, K'.elim (trList [n]) [] c d⟩
⟨some q, none, K'.elim (trList [n.succ]) [] c d⟩ := by
simp only [trList, trNat.eq_1, Nat.cast_succ, Num.add_one]
rcases (n : Num) with - | a
· refine TransGen.head rfl ?_
simp only [Option.mem_def]
convert unrev_ok using 1
simp only [elim_update_rev, elim_rev, elim_main, List.reverseAux_nil, elim_update_main]
rfl
simp only [trNum, Num.succ, Num.succ']
suffices ∀ l₁, ∃ l₁' l₂' s',
List.reverseAux l₁ (trPosNum a.succ) = List.reverseAux l₁' l₂' ∧
Reaches₁ (TM2.step tr) ⟨some q.succ, s, K'.elim (trPosNum a ++ [Γ'.cons]) l₁ c d⟩
⟨some (unrev q), s', K'.elim (l₂' ++ [Γ'.cons]) l₁' c d⟩ by
obtain ⟨l₁', l₂', s', e, h⟩ := this []
simp only [List.reverseAux] at e
refine h.trans ?_
convert unrev_ok using 2
simp [e, List.reverseAux_eq]
induction a generalizing s with intro l₁
| one =>
refine ⟨Γ'.bit0 :: l₁, [Γ'.bit1], some Γ'.cons, rfl, TransGen.head rfl (TransGen.single ?_)⟩
simp [trPosNum]
| bit1 m IH =>
obtain ⟨l₁', l₂', s', e, h⟩ := IH (Γ'.bit0 :: l₁)
refine ⟨l₁', l₂', s', e, TransGen.head ?_ h⟩
simp [trPosNum]
rfl
| bit0 m _ =>
refine ⟨l₁, _, some Γ'.bit0, rfl, TransGen.single ?_⟩
simp only [TM2.step]; rw [tr]
simp only [TM2.stepAux, pop', elim_main, elim_update_main,
elim_rev, elim_update_rev, Function.update_self, Option.mem_def, Option.some.injEq]
rfl | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | succ_ok | null |
pred_ok (q₁ q₂ s v) (c d : List Γ') : ∃ s',
Reaches₁ (TM2.step tr) ⟨some (Λ'.pred q₁ q₂), s, K'.elim (trList v) [] c d⟩
(v.headI.rec ⟨some q₁, s', K'.elim (trList v.tail) [] c d⟩ fun n _ =>
⟨some q₂, s', K'.elim (trList (n::v.tail)) [] c d⟩) := by
rcases v with (_ | ⟨_ | n, v⟩)
· refine ⟨none, TransGen.single ?_⟩
simp
· refine ⟨some Γ'.cons, TransGen.single ?_⟩
simp
refine ⟨none, ?_⟩
simp only [trList, trNat.eq_1, trNum, Nat.cast_succ, Num.add_one, Num.succ,
List.tail_cons, List.headI_cons]
rcases (n : Num) with - | a
· simp only [trPosNum, Num.succ', List.singleton_append, List.nil_append]
refine TransGen.head rfl ?_
rw [tr]; simp only [pop', TM2.stepAux]
convert unrev_ok using 2
simp
simp only [Num.succ']
suffices ∀ l₁, ∃ l₁' l₂' s',
List.reverseAux l₁ (trPosNum a) = List.reverseAux l₁' l₂' ∧
Reaches₁ (TM2.step tr)
⟨some (q₁.pred q₂), s, K'.elim (trPosNum a.succ ++ Γ'.cons :: trList v) l₁ c d⟩
⟨some (unrev q₂), s', K'.elim (l₂' ++ Γ'.cons :: trList v) l₁' c d⟩ by
obtain ⟨l₁', l₂', s', e, h⟩ := this []
simp only [List.reverseAux] at e
refine h.trans ?_
convert unrev_ok using 2
simp [e, List.reverseAux_eq]
induction a generalizing s with intro l₁
| one =>
refine ⟨Γ'.bit1::l₁, [], some Γ'.cons, rfl, TransGen.head rfl (TransGen.single ?_)⟩
simp [trPosNum, show PosNum.one.succ = PosNum.one.bit0 from rfl]
| bit1 m IH =>
obtain ⟨l₁', l₂', s', e, h⟩ := IH (some Γ'.bit0) (Γ'.bit1 :: l₁)
refine ⟨l₁', l₂', s', e, TransGen.head ?_ h⟩
simp
rfl
| bit0 m IH =>
obtain ⟨a, l, e, h⟩ : ∃ a l, (trPosNum m = a::l) ∧ natEnd a = false := by
cases m <;> refine ⟨_, _, rfl, rfl⟩
refine ⟨Γ'.bit0 :: l₁, _, some a, rfl, TransGen.single ?_⟩
simp [trPosNum, PosNum.succ, e, h, show some Γ'.bit1 ≠ some Γ'.bit0 by decide,
Option.iget, -natEnd]
rfl | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | pred_ok | null |
trNormal_respects (c k v s) :
∃ b₂,
TrCfg (stepNormal c k v) b₂ ∧
Reaches₁ (TM2.step tr)
⟨some (trNormal c (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)⟩ b₂ := by
induction c generalizing k v s with
| zero' => refine ⟨_, ⟨s, rfl⟩, TransGen.single ?_⟩; simp
| succ => refine ⟨_, ⟨none, rfl⟩, head_main_ok.trans succ_ok⟩
| tail =>
let o : Option Γ' := List.casesOn v none fun _ _ => some Γ'.cons
refine ⟨_, ⟨o, rfl⟩, ?_⟩; convert clear_ok _ using 2
· simp; rfl
swap
refine splitAtPred_eq _ _ (trNat v.headI) _ _ (trNat_natEnd _) ?_
cases v <;> simp [o]
| cons f fs IHf _ =>
obtain ⟨c, h₁, h₂⟩ := IHf (Cont.cons₁ fs v k) v none
refine ⟨c, h₁, TransGen.head rfl <| (move_ok (by decide) (splitAtPred_false _)).trans ?_⟩
simp only [TM2.step, Option.mem_def, elim_stack, elim_update_stack, elim_update_main,
elim_main, elim_rev, elim_update_rev]
refine (copy_ok _ none [] (trList v).reverse _ _).trans ?_
convert h₂ using 2
simp [List.reverseAux_eq, trContStack]
| comp f _ _ IHg => exact IHg (Cont.comp f k) v s
| case f g IHf IHg =>
rw [stepNormal]
simp only
obtain ⟨s', h⟩ := pred_ok _ _ s v _ _
revert h; rcases v.headI with - | n <;> intro h
· obtain ⟨c, h₁, h₂⟩ := IHf k _ s'
exact ⟨_, h₁, h.trans h₂⟩
· obtain ⟨c, h₁, h₂⟩ := IHg k _ s'
exact ⟨_, h₁, h.trans h₂⟩
| fix f IH => apply IH | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | trNormal_respects | null |
tr_ret_respects (k v s) : ∃ b₂,
TrCfg (stepRet k v) b₂ ∧
Reaches₁ (TM2.step tr)
⟨some (Λ'.ret (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)⟩ b₂ := by
induction k generalizing v s with
| halt => exact ⟨_, rfl, TransGen.single rfl⟩
| cons₁ fs as k _ =>
obtain ⟨s', h₁, h₂⟩ := trNormal_respects fs (Cont.cons₂ v k) as none
refine ⟨s', h₁, TransGen.head rfl ?_⟩; simp
refine (move₂_ok (by decide) ?_ (splitAtPred_false _)).trans ?_; · rfl
simp only [TM2.step, Option.mem_def, Option.elim, id_eq, elim_update_main, elim_main, elim_aux,
List.append_nil, elim_update_aux]
refine (move₂_ok (L₁ := ?_) (o := ?_) (L₂ := ?_) (by decide) rfl ?_).trans ?_
pick_goal 4
· exact splitAtPred_eq _ _ _ (some Γ'.consₗ) _
(fun x h => Bool.decide_false (trList_ne_consₗ _ _ h)) ⟨rfl, rfl⟩
refine (move₂_ok (by decide) ?_ (splitAtPred_false _)).trans ?_; · rfl
simp only [TM2.step, Option.mem_def, Option.elim, elim_update_stack, elim_main,
List.append_nil, elim_update_main, id_eq, elim_update_aux,
elim_aux, elim_stack]
exact h₂
| cons₂ ns k IH =>
obtain ⟨c, h₁, h₂⟩ := IH (ns.headI :: v) none
exact ⟨c, h₁, TransGen.head rfl <| head_stack_ok.trans h₂⟩
| comp f k _ =>
obtain ⟨s', h₁, h₂⟩ := trNormal_respects f k v s
exact ⟨_, h₁, TransGen.head rfl h₂⟩
| fix f k IH =>
rw [stepRet]
have :
if v.headI = 0 then natEnd (trList v).head?.iget = true ∧ (trList v).tail = trList v.tail
else
natEnd (trList v).head?.iget = false ∧
(trList v).tail = (trNat v.headI).tail ++ Γ'.cons :: trList v.tail := by
obtain - | n := v
· exact ⟨rfl, rfl⟩
rcases n with - | n
· simp
rw [trList, List.headI, trNat, Nat.cast_succ, Num.add_one, Num.succ, List.tail]
cases (n : Num).succ' <;> exact ⟨rfl, rfl⟩
by_cases h : v.headI = 0 <;> simp only [h, ite_true, ite_false] at this ⊢
· obtain ⟨c, h₁, h₂⟩ := IH v.tail (trList v).head?
refine ⟨c, h₁, TransGen.head rfl ?_⟩
rw [trCont, tr]; simp only [pop', TM2.stepAux, elim_main, this, elim_update_main]
exact h₂
· obtain ⟨s', h₁, h₂⟩ := trNormal_respects f (Cont.fix f k) v.tail (some Γ'.cons)
refine ⟨_, h₁, TransGen.head rfl <| TransGen.trans ?_ h₂⟩
rw [trCont, tr]; simp only [pop', TM2.stepAux, elim_main, this.1]
convert clear_ok (splitAtPred_eq _ _ (trNat v.headI).tail (some Γ'.cons) _ _ _) using 2
· simp
convert 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_respects | null |
tr_respects : Respects step (TM2.step tr) TrCfg
| Cfg.ret _ _, _, ⟨_, rfl⟩ => tr_ret_respects _ _ _
| Cfg.halt _, _, rfl => rfl | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | tr_respects | null |
init (c : Code) (v : List ℕ) : Cfg' :=
⟨some (trNormal c Cont'.halt), 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 | init | The initial state, evaluating function `c` on input `v`. |
tr_init (c v) :
∃ b, TrCfg (stepNormal c Cont.halt v) b ∧ Reaches₁ (TM2.step tr) (init c v) b :=
trNormal_respects _ _ _ _ | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | tr_init | null |
tr_eval (c v) : eval (TM2.step tr) (init c v) = halt <$> Code.eval c v := by
obtain ⟨i, h₁, h₂⟩ := tr_init c v
refine Part.ext fun x => ?_
rw [reaches_eval h₂.to_reflTransGen]; simp only [Part.map_eq_map, Part.mem_map_iff]
refine ⟨fun h => ?_, ?_⟩
· obtain ⟨c, hc₁, hc₂⟩ := tr_eval_rev tr_respects h₁ h
simp [stepNormal_eval] at hc₂
obtain ⟨v', hv, rfl⟩ := hc₂
exact ⟨_, hv, hc₁.symm⟩
· rintro ⟨v', hv, rfl⟩
have := Turing.tr_eval (b₁ := Cfg.halt v') tr_respects h₁
simp only [stepNormal_eval, Part.map_eq_map, Part.mem_map_iff, Cfg.halt.injEq,
exists_eq_right] at this
obtain ⟨_, ⟨⟩, h⟩ := this hv
exact h | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | tr_eval | null |
trStmts₁ : Λ' → Finset Λ'
| Q@(Λ'.move _ _ _ q) => insert Q <| trStmts₁ q
| Q@(Λ'.push _ _ q) => insert Q <| trStmts₁ q
| Q@(Λ'.read q) => insert Q <| Finset.univ.biUnion fun s => trStmts₁ (q s)
| Q@(Λ'.clear _ _ q) => insert Q <| trStmts₁ q
| Q@(Λ'.copy q) => insert Q <| trStmts₁ q
| Q@(Λ'.succ q) => insert Q <| insert (unrev q) <| trStmts₁ q
| Q@(Λ'.pred q₁ q₂) => insert Q <| trStmts₁ q₁ ∪ insert (unrev q₂) (trStmts₁ q₂)
| Q@(Λ'.ret _) => {Q} | def | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | trStmts₁ | The set of machine states reachable via downward label jumps, discounting jumps via `ret`. |
trStmts₁_trans {q q'} : q' ∈ trStmts₁ q → trStmts₁ q' ⊆ trStmts₁ q := by
induction q with
| move _ _ _ q q_ih => _ | clear _ _ q q_ih => _ | copy q q_ih => _ | push _ _ q q_ih => _
| read q q_ih => _ | succ q q_ih => _ | pred q₁ q₂ q₁_ih q₂_ih => _ | ret => _ <;>
all_goals
simp +contextual only [trStmts₁, Finset.mem_insert, Finset.mem_union,
or_imp, Finset.mem_singleton, Finset.Subset.refl, imp_true_iff, true_and]
repeat exact fun h => Finset.Subset.trans (q_ih h) (Finset.subset_insert _ _)
· simp
intro s h x h'
simp only [Finset.mem_biUnion, Finset.mem_univ, true_and, Finset.mem_insert]
exact Or.inr ⟨_, q_ih s h h'⟩
· constructor
· rintro rfl
apply Finset.subset_insert
· intro h x h'
simp only [Finset.mem_insert]
exact Or.inr (Or.inr <| q_ih h h')
· refine ⟨fun h x h' => ?_, fun _ x h' => ?_, fun h x h' => ?_⟩ <;> simp
· exact Or.inr (Or.inr <| Or.inl <| q₁_ih h h')
· rcases Finset.mem_insert.1 h' with h' | h' <;> simp [h', unrev]
· exact Or.inr (Or.inr <| Or.inr <| q₂_ih h h') | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | trStmts₁_trans | null |
trStmts₁_self (q) : q ∈ trStmts₁ q := by
induction q <;> · first |apply Finset.mem_singleton_self|apply Finset.mem_insert_self | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | trStmts₁_self | null |
codeSupp' : Code → Cont' → Finset Λ'
| c@Code.zero', k => trStmts₁ (trNormal c k)
| c@Code.succ, k => trStmts₁ (trNormal c k)
| c@Code.tail, k => trStmts₁ (trNormal c k)
| c@(Code.cons f fs), k =>
trStmts₁ (trNormal c k) ∪
(codeSupp' f (Cont'.cons₁ fs k) ∪
(trStmts₁
(move₂ (fun _ => false) main aux <|
move₂ (fun s => s = Γ'.consₗ) stack main <|
move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k)) ∪
(codeSupp' fs (Cont'.cons₂ k) ∪ trStmts₁ (head stack <| Λ'.ret k))))
| c@(Code.comp f g), k =>
trStmts₁ (trNormal c k) ∪
(codeSupp' g (Cont'.comp f k) ∪ (trStmts₁ (trNormal f k) ∪ codeSupp' f k))
| c@(Code.case f g), k => trStmts₁ (trNormal c k) ∪ (codeSupp' f k ∪ codeSupp' g k)
| c@(Code.fix f), k =>
trStmts₁ (trNormal c k) ∪
(codeSupp' f (Cont'.fix f k) ∪
(trStmts₁ (Λ'.clear natEnd main <| trNormal f (Cont'.fix f k)) ∪ {Λ'.ret k}))
@[simp] | def | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | codeSupp' | The (finite!) set of machine states visited during the course of evaluation of `c`,
including the state `ret k` but not any states after that (that is, the states visited while
evaluating `k`). |
codeSupp'_self (c k) : trStmts₁ (trNormal c k) ⊆ codeSupp' c k := by
cases c <;> first | rfl | exact Finset.union_subset_left (fun _ a ↦ a) | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | codeSupp'_self | null |
contSupp : Cont' → Finset Λ'
| Cont'.cons₁ fs k =>
trStmts₁
(move₂ (fun _ => false) main aux <|
move₂ (fun s => s = Γ'.consₗ) stack main <|
move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k)) ∪
(codeSupp' fs (Cont'.cons₂ k) ∪ (trStmts₁ (head stack <| Λ'.ret k) ∪ contSupp k))
| Cont'.cons₂ k => trStmts₁ (head stack <| Λ'.ret k) ∪ contSupp k
| Cont'.comp f k => codeSupp' f k ∪ contSupp k
| Cont'.fix f k => codeSupp' (Code.fix f) k ∪ contSupp k
| Cont'.halt => ∅ | def | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | contSupp | The (finite!) set of machine states visited during the course of evaluation of a continuation
`k`, not including the initial state `ret k`. |
codeSupp (c : Code) (k : Cont') : Finset Λ' :=
codeSupp' c k ∪ contSupp k
@[simp] | def | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | codeSupp | The (finite!) set of machine states visited during the course of evaluation of `c` in
continuation `k`. This is actually closed under forward simulation (see `tr_supports`), and the
existence of this set means that the machine constructed in this section is in fact a proper
Turing machine, with a finite set of states. |
codeSupp_self (c k) : trStmts₁ (trNormal c k) ⊆ codeSupp c k :=
Finset.Subset.trans (codeSupp'_self _ _) (Finset.union_subset_left fun _ a ↦ a)
@[simp] | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | codeSupp_self | null |
codeSupp_zero (k) : codeSupp Code.zero' k = trStmts₁ (trNormal Code.zero' k) ∪ contSupp 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 | codeSupp_zero | null |
codeSupp_succ (k) : codeSupp Code.succ k = trStmts₁ (trNormal Code.succ k) ∪ contSupp 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 | codeSupp_succ | null |
codeSupp_tail (k) : codeSupp Code.tail k = trStmts₁ (trNormal Code.tail k) ∪ contSupp 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 | codeSupp_tail | null |
codeSupp_cons (f fs k) :
codeSupp (Code.cons f fs) k =
trStmts₁ (trNormal (Code.cons f fs) k) ∪ codeSupp f (Cont'.cons₁ fs k) := by
simp [codeSupp, codeSupp', contSupp, Finset.union_assoc]
@[simp] | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | codeSupp_cons | null |
codeSupp_comp (f g k) :
codeSupp (Code.comp f g) k =
trStmts₁ (trNormal (Code.comp f g) k) ∪ codeSupp g (Cont'.comp f k) := by
simp only [codeSupp, codeSupp', trNormal, Finset.union_assoc, contSupp]
rw [← Finset.union_assoc _ _ (contSupp k),
Finset.union_eq_right.2 (codeSupp'_self _ _)]
@[simp] | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | codeSupp_comp | null |
codeSupp_case (f g k) :
codeSupp (Code.case f g) k =
trStmts₁ (trNormal (Code.case f g) k) ∪ (codeSupp f k ∪ codeSupp g k) := by
simp [codeSupp, codeSupp', Finset.union_assoc, Finset.union_left_comm]
@[simp] | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | codeSupp_case | null |
codeSupp_fix (f k) :
codeSupp (Code.fix f) k = trStmts₁ (trNormal (Code.fix f) k) ∪ codeSupp f (Cont'.fix f k) := by
simp [codeSupp, codeSupp', contSupp, Finset.union_assoc, Finset.union_left_comm,
Finset.union_left_idem]
@[simp] | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | codeSupp_fix | null |
contSupp_cons₁ (fs k) :
contSupp (Cont'.cons₁ fs k) =
trStmts₁
(move₂ (fun _ => false) main aux <|
move₂ (fun s => s = Γ'.consₗ) stack main <|
move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k)) ∪
codeSupp fs (Cont'.cons₂ k) := by
simp [codeSupp, contSupp]
@[simp] | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | contSupp_cons₁ | null |
contSupp_cons₂ (k) :
contSupp (Cont'.cons₂ k) = trStmts₁ (head stack <| Λ'.ret k) ∪ contSupp 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 | contSupp_cons₂ | null |
contSupp_comp (f k) : contSupp (Cont'.comp f k) = codeSupp f k :=
rfl | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | contSupp_comp | null |
contSupp_fix (f k) : contSupp (Cont'.fix f k) = codeSupp f (Cont'.fix f k) := by
simp +contextual [codeSupp, codeSupp', contSupp, Finset.union_assoc,
Finset.subset_iff, -Finset.singleton_union, -Finset.union_singleton]
@[simp] | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | contSupp_fix | null |
contSupp_halt : contSupp Cont'.halt = ∅ :=
rfl | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | contSupp_halt | null |
Λ'.Supports (S : Finset Λ') : Λ' → Prop
| Λ'.move _ _ _ q => Λ'.Supports S q
| Λ'.push _ _ q => Λ'.Supports S q
| Λ'.read q => ∀ s, Λ'.Supports S (q s)
| Λ'.clear _ _ q => Λ'.Supports S q
| Λ'.copy q => Λ'.Supports S q
| Λ'.succ q => Λ'.Supports S q
| Λ'.pred q₁ q₂ => Λ'.Supports S q₁ ∧ Λ'.Supports S q₂
| Λ'.ret k => contSupp k ⊆ S | def | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | Λ'.Supports | The statement `Λ'.Supports S q` means that `contSupp k ⊆ S` for any `ret k`
reachable from `q`.
(This is a technical condition used in the proof that the machine is supported.) |
Supports (K S : Finset Λ') :=
∀ q ∈ K, TM2.SupportsStmt S (tr q) | def | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | Supports | A shorthand for the predicate that we are proving in the main theorems `trStmts₁_supports`,
`codeSupp'_supports`, `contSupp_supports`, `codeSupp_supports`. The set `S` is fixed throughout
the proof, and denotes the full set of states in the machine, while `K` is a subset that we are
currently proving a property about. The predicate asserts that every state in `K` is closed in `S`
under forward simulation, i.e. stepping forward through evaluation starting from any state in `K`
stays entirely within `S`. |
supports_insert {K S q} :
Supports (insert q K) S ↔ TM2.SupportsStmt S (tr q) ∧ Supports K S := by simp [Supports] | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | supports_insert | null |
supports_singleton {S q} : Supports {q} S ↔ TM2.SupportsStmt S (tr q) := by simp [Supports] | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | supports_singleton | null |
supports_union {K₁ K₂ S} : Supports (K₁ ∪ K₂) S ↔ Supports K₁ S ∧ Supports K₂ S := by
simp [Supports, or_imp, forall_and] | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | supports_union | null |
supports_biUnion {K : Option Γ' → Finset Λ'} {S} :
Supports (Finset.univ.biUnion K) S ↔ ∀ a, Supports (K a) S := by
simpa [Supports] using forall_swap | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | supports_biUnion | null |
head_supports {S k q} (H : (q : Λ').Supports S) : (head k q).Supports S := fun _ => by
dsimp only; split_ifs <;> exact H | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | head_supports | null |
ret_supports {S k} (H₁ : contSupp k ⊆ S) : TM2.SupportsStmt S (tr (Λ'.ret k)) := by
have W := fun {q} => trStmts₁_self q
cases k with
| halt => trivial
| cons₁ => rw [contSupp_cons₁, Finset.union_subset_iff] at H₁; exact fun _ => H₁.1 W
| cons₂ => rw [contSupp_cons₂, Finset.union_subset_iff] at H₁; exact fun _ => H₁.1 W
| comp => rw [contSupp_comp] at H₁; exact fun _ => H₁ (codeSupp_self _ _ W)
| fix =>
rw [contSupp_fix] at H₁
have L := @Finset.mem_union_left; have R := @Finset.mem_union_right
intro s; dsimp only; cases natEnd s.iget
· refine H₁ (R _ <| L _ <| R _ <| R _ <| L _ W)
· exact H₁ (R _ <| L _ <| R _ <| R _ <| R _ <| Finset.mem_singleton_self _) | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | ret_supports | null |
trStmts₁_supports {S q} (H₁ : (q : Λ').Supports S) (HS₁ : trStmts₁ q ⊆ S) :
Supports (trStmts₁ q) S := by
have W := fun {q} => trStmts₁_self q
induction q with
| move _ _ _ q q_ih => _ | clear _ _ q q_ih => _ | copy q q_ih => _ | push _ _ q q_ih => _
| read q q_ih => _ | succ q q_ih => _ | pred q₁ q₂ q₁_ih q₂_ih => _ | ret => _ <;>
simp [trStmts₁, -Finset.singleton_subset_iff] at HS₁ ⊢
any_goals
obtain ⟨h₁, h₂⟩ := Finset.insert_subset_iff.1 HS₁
first | have h₃ := h₂ W | try simp [Finset.subset_iff] at h₂
· exact supports_insert.2 ⟨⟨fun _ => h₃, fun _ => h₁⟩, q_ih H₁ h₂⟩ -- move
· exact supports_insert.2 ⟨⟨fun _ => h₃, fun _ => h₁⟩, q_ih H₁ h₂⟩ -- clear
· exact supports_insert.2 ⟨⟨fun _ => h₁, fun _ => h₃⟩, q_ih H₁ h₂⟩ -- copy
· exact supports_insert.2 ⟨⟨fun _ => h₃, fun _ => h₃⟩, q_ih H₁ h₂⟩ -- push
· refine supports_insert.2 ⟨fun _ => h₂ _ W, ?_⟩ -- read
exact supports_biUnion.2 fun _ => q_ih _ (H₁ _) fun _ h => h₂ _ h
· refine supports_insert.2 ⟨⟨fun _ => h₁, fun _ => h₂.1, fun _ => h₂.1⟩, ?_⟩ -- succ
exact supports_insert.2 ⟨⟨fun _ => h₂.2 _ W, fun _ => h₂.1⟩, q_ih H₁ h₂.2⟩
· refine -- pred
supports_insert.2 ⟨⟨fun _ => h₁, fun _ => h₂.2 _ (Or.inl W),
fun _ => h₂.1, fun _ => h₂.1⟩, ?_⟩
refine supports_insert.2 ⟨⟨fun _ => h₂.2 _ (Or.inr W), fun _ => h₂.1⟩, ?_⟩
refine supports_union.2 ⟨?_, ?_⟩
· exact q₁_ih H₁.1 fun _ h => h₂.2 _ (Or.inl h)
· exact q₂_ih H₁.2 fun _ h => h₂.2 _ (Or.inr h)
· exact supports_singleton.2 (ret_supports H₁) -- ret | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | trStmts₁_supports | null |
trStmts₁_supports' {S q K} (H₁ : (q : Λ').Supports S) (H₂ : trStmts₁ q ∪ K ⊆ S)
(H₃ : K ⊆ S → Supports K S) : Supports (trStmts₁ q ∪ K) S := by
simp only [Finset.union_subset_iff] at H₂
exact supports_union.2 ⟨trStmts₁_supports H₁ H₂.1, H₃ H₂.2⟩ | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | trStmts₁_supports' | null |
trNormal_supports {S c k} (Hk : codeSupp c k ⊆ S) : (trNormal c k).Supports S := by
induction c generalizing k with simp [Λ'.Supports, head]
| zero' => exact Finset.union_subset_right Hk
| succ => intro; split_ifs <;> exact Finset.union_subset_right Hk
| tail => exact Finset.union_subset_right Hk
| cons f fs IHf _ =>
apply IHf
rw [codeSupp_cons] at Hk
exact Finset.union_subset_right Hk
| comp f g _ IHg => apply IHg; rw [codeSupp_comp] at Hk; exact Finset.union_subset_right Hk
| case f g IHf IHg =>
simp only [codeSupp_case, Finset.union_subset_iff] at Hk
exact ⟨IHf Hk.2.1, IHg Hk.2.2⟩
| fix f IHf => apply IHf; rw [codeSupp_fix] at Hk; exact Finset.union_subset_right Hk | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | trNormal_supports | null |
codeSupp'_supports {S c k} (H : codeSupp c k ⊆ S) : Supports (codeSupp' c k) S := by
induction c generalizing k with
| cons f fs IHf IHfs =>
have H' := H; simp only [codeSupp_cons, Finset.union_subset_iff] at H'
refine trStmts₁_supports' (trNormal_supports H) (Finset.union_subset_left H) fun h => ?_
refine supports_union.2 ⟨IHf H'.2, ?_⟩
refine trStmts₁_supports' (trNormal_supports ?_) (Finset.union_subset_right h) fun h => ?_
· simp only [codeSupp, Finset.union_subset_iff, contSupp] at h H ⊢
exact ⟨h.2.2.1, h.2.2.2, H.2⟩
refine supports_union.2 ⟨IHfs ?_, ?_⟩
· rw [codeSupp, contSupp_cons₁] at H'
exact Finset.union_subset_right (Finset.union_subset_right H'.2)
exact
trStmts₁_supports (head_supports <| Finset.union_subset_right H)
(Finset.union_subset_right h)
| comp f g IHf IHg =>
have H' := H; rw [codeSupp_comp] at H'; have H' := Finset.union_subset_right H'
refine trStmts₁_supports' (trNormal_supports H) (Finset.union_subset_left H) fun h => ?_
refine supports_union.2 ⟨IHg H', ?_⟩
refine trStmts₁_supports' (trNormal_supports ?_) (Finset.union_subset_right h) fun _ => ?_
· simp only [codeSupp', codeSupp, Finset.union_subset_iff] at h H ⊢
exact ⟨h.2.2, H.2⟩
exact IHf (Finset.union_subset_right H')
| case f g IHf IHg =>
have H' := H; simp only [codeSupp_case, Finset.union_subset_iff] at H'
refine trStmts₁_supports' (trNormal_supports H) (Finset.union_subset_left H) fun _ => ?_
exact supports_union.2 ⟨IHf H'.2.1, IHg H'.2.2⟩
| fix f IHf =>
have H' := H; simp only [codeSupp_fix, Finset.union_subset_iff] at H'
refine trStmts₁_supports' (trNormal_supports H) (Finset.union_subset_left H) fun h => ?_
refine supports_union.2 ⟨IHf H'.2, ?_⟩
refine trStmts₁_supports' (trNormal_supports ?_) (Finset.union_subset_right h) fun _ => ?_
· simp only [codeSupp', codeSupp, Finset.union_subset_iff, contSupp, trStmts₁,
Finset.insert_subset_iff] at h H ⊢
exact ⟨h.1, ⟨H.1.1, h⟩, H.2⟩
exact supports_singleton.2 (ret_supports <| Finset.union_subset_right H)
| _ => exact trStmts₁_supports (trNormal_supports H) (Finset.Subset.trans (codeSupp_self _ _) H) | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | codeSupp'_supports | null |
contSupp_supports {S k} (H : contSupp k ⊆ S) : Supports (contSupp k) S := by
induction k with
| halt => simp [contSupp_halt, Supports]
| cons₁ f k IH =>
have H₁ := H; rw [contSupp_cons₁] at H₁; have H₂ := Finset.union_subset_right H₁
refine trStmts₁_supports' (trNormal_supports H₂) H₁ fun h => ?_
refine supports_union.2 ⟨codeSupp'_supports H₂, ?_⟩
simp only [codeSupp, contSupp_cons₂, Finset.union_subset_iff] at H₂
exact trStmts₁_supports' (head_supports H₂.2.2) (Finset.union_subset_right h) IH
| cons₂ k IH =>
have H' := H; rw [contSupp_cons₂] at H'
exact trStmts₁_supports' (head_supports <| Finset.union_subset_right H') H' IH
| comp f k IH =>
have H' := H; rw [contSupp_comp] at H'; have H₂ := Finset.union_subset_right H'
exact supports_union.2 ⟨codeSupp'_supports H', IH H₂⟩
| fix f k IH =>
rw [contSupp] at H
exact supports_union.2 ⟨codeSupp'_supports H, IH (Finset.union_subset_right H)⟩ | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | contSupp_supports | null |
codeSupp_supports {S c k} (H : codeSupp c k ⊆ S) : Supports (codeSupp c k) S :=
supports_union.2 ⟨codeSupp'_supports H, contSupp_supports (Finset.union_subset_right H)⟩ | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | codeSupp_supports | null |
tr_supports (c k) : @TM2.Supports _ _ _ _ ⟨trNormal c k⟩ tr (codeSupp c k) :=
⟨codeSupp_self _ _ (trStmts₁_self _), fun _ => codeSupp_supports (Finset.Subset.refl _) _⟩ | theorem | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.TuringMachine",
"Mathlib.Data.Num.Lemmas",
"Mathlib.Tactic.DeriveFintype",
"Mathlib.Computability.TMConfig"
] | Mathlib/Computability/TMToPartrec.lean | tr_supports | The set `codeSupp c k` is a finite set that witnesses the effective finiteness of the `tr`
Turing machine. Starting from the initial state `trNormal c k`, forward simulation uses only
states in `codeSupp c k`, so this is a finite state machine. Even though the underlying type of
state labels `Λ'` is infinite, for a given partial recursive function `c` and continuation `k`,
only finitely many states are accessed, corresponding roughly to subterms of `c`. |
RecursiveIn (O : Set (ℕ →. ℕ)) : (ℕ →. ℕ) → Prop
| zero : RecursiveIn O fun _ => 0
| succ : RecursiveIn O Nat.succ
| left : RecursiveIn O fun n => (Nat.unpair n).1
| right : RecursiveIn O fun n => (Nat.unpair n).2
| oracle : ∀ g ∈ O, RecursiveIn O g
| pair {f h : ℕ →. ℕ} (hf : RecursiveIn O f) (hh : RecursiveIn O h) :
RecursiveIn O fun n => (Nat.pair <$> f n <*> h n)
| comp {f h : ℕ →. ℕ} (hf : RecursiveIn O f) (hh : RecursiveIn O h) :
RecursiveIn O fun n => h n >>= f
| prec {f h : ℕ →. ℕ} (hf : RecursiveIn O f) (hh : RecursiveIn O h) :
RecursiveIn O fun p =>
let (a, n) := Nat.unpair p
n.rec (f a) fun y IH => do
let i ← IH
h (Nat.pair a (Nat.pair y i))
| rfind {f : ℕ →. ℕ} (hf : RecursiveIn O f) :
RecursiveIn O fun a =>
Nat.rfind fun n => (fun m => m = 0) <$> f (Nat.pair a n) | inductive | Computability | [
"Mathlib.Computability.Partrec",
"Mathlib.Order.Antisymmetrization"
] | Mathlib/Computability/TuringDegree.lean | RecursiveIn | The type of partial functions recursive in a set of oracles `O` is the smallest type containing
the constant zero, the successor, left and right projections, each oracle `g ∈ O`,
and is closed under pairing, composition, primitive recursion, and μ-recursion. |
TuringReducible (f g : ℕ →. ℕ) : Prop :=
RecursiveIn {g} f | abbrev | Computability | [
"Mathlib.Computability.Partrec",
"Mathlib.Order.Antisymmetrization"
] | Mathlib/Computability/TuringDegree.lean | TuringReducible | `f` is Turing reducible to `g` if `f` is partial recursive given access to the oracle `g` |
TuringEquivalent (f g : ℕ →. ℕ) : Prop :=
AntisymmRel TuringReducible f g
@[inherit_doc] scoped[Computability] infix:50 " ≤ᵀ " => TuringReducible
@[inherit_doc] scoped[Computability] infix:50 " ≡ᵀ " => TuringEquivalent
open scoped Computability | abbrev | Computability | [
"Mathlib.Computability.Partrec",
"Mathlib.Order.Antisymmetrization"
] | Mathlib/Computability/TuringDegree.lean | TuringEquivalent | `f` is Turing equivalent to `g` if `f` is reducible to `g` and `g` is reducible to `f`. |
Nat.Partrec.turingReducible (pF : Nat.Partrec f) : f ≤ᵀ g := by
induction pF with repeat {constructor}
| pair _ _ ih₁ ih₂ => exact RecursiveIn.pair ih₁ ih₂
| comp _ _ ih₁ ih₂ => exact RecursiveIn.comp ih₁ ih₂
| prec _ _ ih₁ ih₂ => exact RecursiveIn.prec ih₁ ih₂
| rfind _ ih => exact RecursiveIn.rfind ih | lemma | Computability | [
"Mathlib.Computability.Partrec",
"Mathlib.Order.Antisymmetrization"
] | Mathlib/Computability/TuringDegree.lean | Nat.Partrec.turingReducible | If a function is partial recursive, then it is recursive in every partial function. |
TuringReducible.partrec_of_zero (fRecInZero : f ≤ᵀ fun _ => Part.some 0) : Nat.Partrec f := by
induction fRecInZero with repeat {constructor}
| oracle _ hg => rw [Set.mem_singleton_iff] at hg; rw [hg]; exact Nat.Partrec.zero
| pair | comp | prec | rfind => repeat {constructor; assumption; try assumption} | lemma | Computability | [
"Mathlib.Computability.Partrec",
"Mathlib.Order.Antisymmetrization"
] | Mathlib/Computability/TuringDegree.lean | TuringReducible.partrec_of_zero | If a function is recursive in the constant zero function,
then it is partial recursive. |
partrec_iff_forall_turingReducible : Nat.Partrec f ↔ ∀ g, f ≤ᵀ g :=
⟨fun hf _ ↦ hf.turingReducible, (· _ |>.partrec_of_zero)⟩ | theorem | Computability | [
"Mathlib.Computability.Partrec",
"Mathlib.Order.Antisymmetrization"
] | Mathlib/Computability/TuringDegree.lean | partrec_iff_forall_turingReducible | A partial function `f` is partial recursive if and only if it is recursive in
every partial function `g`. |
protected TuringReducible.refl (f : ℕ →. ℕ) : f ≤ᵀ f := .oracle _ <| by simp | theorem | Computability | [
"Mathlib.Computability.Partrec",
"Mathlib.Order.Antisymmetrization"
] | Mathlib/Computability/TuringDegree.lean | TuringReducible.refl | null |
protected TuringReducible.rfl : f ≤ᵀ f := .refl _ | theorem | Computability | [
"Mathlib.Computability.Partrec",
"Mathlib.Order.Antisymmetrization"
] | Mathlib/Computability/TuringDegree.lean | TuringReducible.rfl | null |
TuringReducible.trans (hg : f ≤ᵀ g) (hh : g ≤ᵀ h) : f ≤ᵀ h := by
induction hg with repeat {constructor}
| oracle _ hg => rw [Set.mem_singleton_iff] at hg; rw [hg]; exact hh
| pair _ _ ih₁ ih₂ => exact RecursiveIn.pair ih₁ ih₂
| comp _ _ ih₁ ih₂ => exact RecursiveIn.comp ih₁ ih₂
| prec _ _ ih₁ ih₂ => exact RecursiveIn.prec ih₁ ih₂
| rfind _ ih => exact RecursiveIn.rfind ih | theorem | Computability | [
"Mathlib.Computability.Partrec",
"Mathlib.Order.Antisymmetrization"
] | Mathlib/Computability/TuringDegree.lean | TuringReducible.trans | null |
TuringEquivalent.equivalence : Equivalence TuringEquivalent :=
(AntisymmRel.setoid _ _).iseqv
@[refl] | theorem | Computability | [
"Mathlib.Computability.Partrec",
"Mathlib.Order.Antisymmetrization"
] | Mathlib/Computability/TuringDegree.lean | TuringEquivalent.equivalence | null |
protected TuringEquivalent.refl (f : ℕ →. ℕ) : f ≡ᵀ f :=
Equivalence.refl equivalence f
@[symm] | theorem | Computability | [
"Mathlib.Computability.Partrec",
"Mathlib.Order.Antisymmetrization"
] | Mathlib/Computability/TuringDegree.lean | TuringEquivalent.refl | null |
TuringEquivalent.symm {f g : ℕ →. ℕ} (h : f ≡ᵀ g) : g ≡ᵀ f :=
Equivalence.symm equivalence h
@[trans] | theorem | Computability | [
"Mathlib.Computability.Partrec",
"Mathlib.Order.Antisymmetrization"
] | Mathlib/Computability/TuringDegree.lean | TuringEquivalent.symm | null |
TuringEquivalent.trans (f g h : ℕ →. ℕ) (h₁ : f ≡ᵀ g) (h₂ : g ≡ᵀ h) : f ≡ᵀ h :=
Equivalence.trans equivalence h₁ h₂ | theorem | Computability | [
"Mathlib.Computability.Partrec",
"Mathlib.Order.Antisymmetrization"
] | Mathlib/Computability/TuringDegree.lean | TuringEquivalent.trans | null |
TuringDegree :=
Antisymmetrization _ TuringReducible | abbrev | Computability | [
"Mathlib.Computability.Partrec",
"Mathlib.Order.Antisymmetrization"
] | Mathlib/Computability/TuringDegree.lean | TuringDegree | Turing degrees are the equivalence classes of partial functions under Turing equivalence. |
TuringDegree.instPartialOrder : PartialOrder TuringDegree :=
instPartialOrderAntisymmetrization
@[simp] lemma recursiveIn_empty_iff_partrec : RecursiveIn {} f ↔ Nat.Partrec f where
mp fRecInNone := by
induction fRecInNone with repeat {constructor}
| oracle _ hg => simp at hg
| pair | comp | prec | rfind =>
repeat {constructor; assumption; try assumption}
mpr pF := by
induction pF with repeat {constructor}
| pair _ _ ih₁ ih₂ => exact RecursiveIn.pair ih₁ ih₂
| comp _ _ ih₁ ih₂ => exact RecursiveIn.comp ih₁ ih₂
| prec _ _ ih₁ ih₂ => exact RecursiveIn.prec ih₁ ih₂
| rfind _ ih => exact RecursiveIn.rfind ih | instance | Computability | [
"Mathlib.Computability.Partrec",
"Mathlib.Order.Antisymmetrization"
] | Mathlib/Computability/TuringDegree.lean | TuringDegree.instPartialOrder | null |
Stmt
| push : ∀ k, (σ → Γ k) → Stmt → Stmt
| peek : ∀ k, (σ → Option (Γ k) → σ) → Stmt → Stmt
| pop : ∀ k, (σ → Option (Γ k) → σ) → Stmt → Stmt
| load : (σ → σ) → Stmt → Stmt
| branch : (σ → Bool) → Stmt → Stmt → Stmt
| goto : (σ → Λ) → Stmt
| halt : Stmt
open Stmt | inductive | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | Stmt | The TM2 model removes the tape entirely from the TM1 model,
replacing it with an arbitrary (finite) collection of stacks.
The operation `push` puts an element on one of the stacks,
and `pop` removes an element from a stack (and modifying the
internal state based on the result). `peek` modifies the
internal state but does not remove an element. |
Stmt.inhabited : Inhabited (Stmt Γ Λ σ) :=
⟨halt⟩ | instance | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | Stmt.inhabited | null |
Cfg where
/-- The current label to run (or `none` for the halting state) -/
l : Option Λ
/-- The internal state -/
var : σ
/-- The (finite) collection of internal stacks -/
stk : ∀ k, List (Γ k) | structure | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | Cfg | A configuration in the TM2 model is a label (or `none` for the halt state), the state of
local variables, and the stacks. (Note that the stacks are not `ListBlank`s, they have a definite
size.) |
Cfg.inhabited [Inhabited σ] : Inhabited (Cfg Γ Λ σ) :=
⟨⟨default, default, default⟩⟩
variable {Γ Λ σ} | instance | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | Cfg.inhabited | null |
stepAux : Stmt Γ Λ σ → σ → (∀ k, List (Γ k)) → Cfg Γ Λ σ
| push k f q, v, S => stepAux q v (update S k (f v :: S k))
| peek k f q, v, S => stepAux q (f v (S k).head?) S
| pop k f q, v, S => stepAux q (f v (S k).head?) (update S k (S k).tail)
| load a q, v, S => stepAux q (a v) S
| branch f q₁ q₂, v, S => cond (f v) (stepAux q₁ v S) (stepAux q₂ v S)
| goto f, v, S => ⟨some (f v), v, S⟩
| halt, v, S => ⟨none, v, S⟩ | def | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | stepAux | The step function for the TM2 model. |
step (M : Λ → Stmt Γ Λ σ) : Cfg Γ Λ σ → Option (Cfg Γ Λ σ)
| ⟨none, _, _⟩ => none
| ⟨some l, v, S⟩ => some (stepAux (M l) v S)
attribute [simp] stepAux.eq_1 stepAux.eq_2 stepAux.eq_3
stepAux.eq_4 stepAux.eq_5 stepAux.eq_6 stepAux.eq_7 step.eq_1 step.eq_2 | def | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | step | The step function for the TM2 model. |
Reaches (M : Λ → Stmt Γ Λ σ) : Cfg Γ Λ σ → Cfg Γ Λ σ → Prop :=
ReflTransGen fun a b ↦ b ∈ step M a | def | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | Reaches | The (reflexive) reachability relation for the TM2 model. |
SupportsStmt (S : Finset Λ) : Stmt Γ Λ σ → Prop
| push _ _ q => SupportsStmt S q
| peek _ _ q => SupportsStmt S q
| pop _ _ q => SupportsStmt S q
| load _ q => SupportsStmt S q
| branch _ q₁ q₂ => SupportsStmt S q₁ ∧ SupportsStmt S q₂
| goto l => ∀ v, l v ∈ S
| halt => True | def | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | SupportsStmt | Given a set `S` of states, `SupportsStmt S q` means that `q` only jumps to states in `S`. |
noncomputable stmts₁ : Stmt Γ Λ σ → Finset (Stmt Γ Λ σ)
| Q@(push _ _ q) => insert Q (stmts₁ q)
| Q@(peek _ _ q) => insert Q (stmts₁ q)
| Q@(pop _ _ q) => insert Q (stmts₁ q)
| Q@(load _ q) => insert Q (stmts₁ q)
| Q@(branch _ q₁ q₂) => insert Q (stmts₁ q₁ ∪ stmts₁ q₂)
| Q@(goto _) => {Q}
| Q@halt => {Q} | def | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | stmts₁ | The set of subtree statements in a statement. |
stmts₁_self {q : Stmt Γ Λ σ} : q ∈ stmts₁ q := by
cases q <;> simp only [Finset.mem_insert_self, Finset.mem_singleton_self, stmts₁] | theorem | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.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_singleton, Finset.mem_union] at h₁₂)
| branch f q₁ q₂ IH₁ IH₂ =>
rcases h₁₂ with (rfl | h₁₂ | h₁₂)
· unfold stmts₁ at h₀₁
exact h₀₁
· exact Finset.mem_insert_of_mem (Finset.mem_union_left _ (IH₁ h₁₂))
· exact Finset.mem_insert_of_mem (Finset.mem_union_right _ (IH₂ h₁₂))
| goto l => subst h₁₂; exact h₀₁
| halt => subst h₁₂; exact h₀₁
| load _ q IH | _ _ _ q IH =>
rcases h₁₂ with (rfl | h₁₂)
· unfold stmts₁ at h₀₁
exact h₀₁
· exact Finset.mem_insert_of_mem (IH h₁₂) | theorem | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.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 f q₁ q₂ IH₁ IH₂ => rcases h with (rfl | h | h); exacts [hs, IH₁ h hs.1, IH₂ h hs.2]
| goto l => subst h; exact hs
| halt => subst h; trivial
| load _ _ IH | _ _ _ _ IH => rcases h with (rfl | h) <;> [exact hs; exact IH h hs]
open scoped Classical in | theorem | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.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.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | stmts | The set of statements accessible from initial set `S` of labels. |
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₁_trans h₂ h₁⟩ | theorem | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | stmts_trans | null |
Supports (M : Λ → Stmt Γ Λ σ) (S : Finset Λ) :=
default ∈ S ∧ ∀ q ∈ S, SupportsStmt S (M q) | def | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | Supports | Given a TM2 machine `M` and a set `S` of states, `Supports M S` means that all states in
`S` jump only to other states 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_mono h (ss.2 _ ls)
variable [DecidableEq K] | theorem | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.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] at h₁; subst c'
revert h₂; induction M l₁ generalizing v T with intro hs
| branch p q₁' q₂' IH₁ IH₂ =>
unfold stepAux; cases p v
· exact IH₂ _ _ hs.2
· exact IH₁ _ _ hs.1
| goto => exact Finset.some_mem_insertNone.2 (hs _)
| halt => apply Multiset.mem_cons_self
| load _ _ IH | _ _ _ _ IH => exact IH _ _ hs
variable [Inhabited σ] | theorem | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | step_supports | null |
init (k : K) (L : List (Γ k)) : Cfg Γ Λ σ :=
⟨some default, default, update (fun _ ↦ []) k L⟩ | def | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | init | The initial state of the TM2 model. The input is provided on a designated stack. |
eval (M : Λ → Stmt Γ Λ σ) (k : K) (L : List (Γ k)) : Part (List (Γ k)) :=
(Turing.eval (step M) (init k L)).map fun c ↦ c.stk k | def | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | eval | Evaluates a TM2 program to completion, with the output on the same stack as the input. |
stk_nth_val {K : Type*} {Γ : K → Type*} {L : ListBlank (∀ k, Option (Γ k))} {k S} (n)
(hL : ListBlank.map (proj k) L = ListBlank.mk (List.map some S).reverse) :
L.nth n k = S.reverse[n]? := by
rw [← proj_map_nth, hL, ← List.map_reverse, ListBlank.nth_mk,
List.getI_eq_iget_getElem?, List.getElem?_map]
cases S.reverse[n]? <;> rfl
variable (K : Type*)
variable (Γ : K → Type*)
variable {Λ σ : Type*} | theorem | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | stk_nth_val | null |
Γ' :=
Bool × ∀ k, Option (Γ k)
variable {K Γ} | def | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | Γ' | The alphabet of the TM2 simulator on TM1 is a marker for the stack bottom,
plus a vector of stack elements for each stack, or none if the stack does not extend this far. |
Γ'.inhabited : Inhabited (Γ' K Γ) :=
⟨⟨false, fun _ ↦ none⟩⟩ | instance | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | Γ'.inhabited | null |
Γ'.fintype [DecidableEq K] [Fintype K] [∀ k, Fintype (Γ k)] : Fintype (Γ' K Γ) :=
instFintypeProd _ _ | instance | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | Γ'.fintype | null |
addBottom (L : ListBlank (∀ k, Option (Γ k))) : ListBlank (Γ' K Γ) :=
ListBlank.cons (true, L.head) (L.tail.map ⟨Prod.mk false, rfl⟩) | def | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | addBottom | The bottom marker is fixed throughout the calculation, so we use the `addBottom` function
to express the program state in terms of a tape with only the stacks themselves. |
addBottom_map (L : ListBlank (∀ k, Option (Γ k))) :
(addBottom L).map ⟨Prod.snd, by rfl⟩ = L := by
simp only [addBottom, ListBlank.map_cons]
convert ListBlank.cons_head_tail L
generalize ListBlank.tail L = L'
refine L'.induction_on fun l ↦ ?_; simp | theorem | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | addBottom_map | null |
addBottom_modifyNth (f : (∀ k, Option (Γ k)) → ∀ k, Option (Γ k))
(L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) :
(addBottom L).modifyNth (fun a ↦ (a.1, f a.2)) n = addBottom (L.modifyNth f n) := by
cases n <;>
simp only [addBottom, ListBlank.head_cons, ListBlank.modifyNth, ListBlank.tail_cons]
congr; symm; apply ListBlank.map_modifyNth; intro; rfl | theorem | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | addBottom_modifyNth | null |
addBottom_nth_snd (L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) :
((addBottom L).nth n).2 = L.nth n := by
conv => rhs; rw [← addBottom_map L, ListBlank.nth_map] | theorem | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | addBottom_nth_snd | null |
addBottom_nth_succ_fst (L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) :
((addBottom L).nth (n + 1)).1 = false := by
rw [ListBlank.nth_succ, addBottom, ListBlank.tail_cons, ListBlank.nth_map] | theorem | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | addBottom_nth_succ_fst | null |
addBottom_head_fst (L : ListBlank (∀ k, Option (Γ k))) : (addBottom L).head.1 = true := by
rw [addBottom, ListBlank.head_cons]
variable (K Γ σ) in | theorem | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | addBottom_head_fst | null |
StAct (k : K)
| push : (σ → Γ k) → StAct k
| peek : (σ → Option (Γ k) → σ) → StAct k
| pop : (σ → Option (Γ k) → σ) → StAct k | inductive | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | StAct | A stack action is a command that interacts with the top of a stack. Our default position
is at the bottom of all the stacks, so we have to hold on to this action while going to the end
to modify the stack. |
StAct.inhabited {k : K} : Inhabited (StAct K Γ σ k) :=
⟨StAct.peek fun s _ ↦ s⟩ | instance | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | StAct.inhabited | null |
stRun {k : K} : StAct K Γ σ k → TM2.Stmt Γ Λ σ → TM2.Stmt Γ Λ σ
| push f => TM2.Stmt.push k f
| peek f => TM2.Stmt.peek k f
| pop f => TM2.Stmt.pop k f | def | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | stRun | The TM2 statement corresponding to a stack action. |
stVar {k : K} (v : σ) (l : List (Γ k)) : StAct K Γ σ k → σ
| push _ => v
| peek f => f v l.head?
| pop f => f v l.head? | def | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | stVar | The effect of a stack action on the local variables, given the value of the stack. |
stWrite {k : K} (v : σ) (l : List (Γ k)) : StAct K Γ σ k → List (Γ k)
| push f => f v :: l
| peek _ => l
| pop _ => l.tail | def | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | stWrite | The effect of a stack action on the stack. |
@[elab_as_elim]
stmtStRec.{l} {motive : TM2.Stmt Γ Λ σ → Sort l}
(run : ∀ (k) (s : StAct K Γ σ k) (q) (_ : motive q), motive (stRun s q))
(load : ∀ (a q) (_ : motive q), motive (TM2.Stmt.load a q))
(branch : ∀ (p q₁ q₂) (_ : motive q₁) (_ : motive q₂), motive (TM2.Stmt.branch p q₁ q₂))
(goto : ∀ l, motive (TM2.Stmt.goto l)) (halt : motive TM2.Stmt.halt) : ∀ n, motive n
| TM2.Stmt.push _ f q => run _ (push f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.peek _ f q => run _ (peek f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.pop _ f q => run _ (pop f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.load _ q => load _ _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.branch _ q₁ q₂ =>
branch _ _ _ (stmtStRec run load branch goto halt q₁) (stmtStRec run load branch goto halt q₂)
| TM2.Stmt.goto _ => goto _
| TM2.Stmt.halt => halt | def | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | stmtStRec. | We have partitioned the TM2 statements into "stack actions", which require going to the end
of the stack, and all other actions, which do not. This is a modified recursor which lumps the
stack actions into one. |
supports_run (S : Finset Λ) {k : K} (s : StAct K Γ σ k) (q : TM2.Stmt Γ Λ σ) :
TM2.SupportsStmt S (stRun s q) ↔ TM2.SupportsStmt S q := by
cases s <;> rfl | theorem | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | supports_run | null |
Λ'
| normal : Λ → Λ'
| go (k : K) : StAct K Γ σ k → TM2.Stmt Γ Λ σ → Λ'
| ret : TM2.Stmt Γ Λ σ → Λ'
variable {K Γ Λ σ}
open Λ' | inductive | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | Λ' | The machine states of the TM2 emulator. We can either be in a normal state when waiting for the
next TM2 action, or we can be in the "go" and "return" states to go to the top of the stack and
return to the bottom, respectively. |
Λ'.inhabited [Inhabited Λ] : Inhabited (Λ' K Γ Λ σ) :=
⟨normal default⟩
open TM1.Stmt | instance | Computability | [
"Mathlib.Computability.Tape",
"Mathlib.Data.Fintype.Option",
"Mathlib.Data.Fintype.Prod",
"Mathlib.Data.Fintype.Pi",
"Mathlib.Data.PFun",
"Mathlib.Computability.PostTuringMachine"
] | Mathlib/Computability/TuringMachine.lean | Λ'.inhabited | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.