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 ⌀ |
|---|---|---|---|---|---|---|
ListBlank.ext {Γ} [i : Inhabited Γ] {L₁ L₂ : ListBlank Γ} :
(∀ i, L₁.nth i = L₂.nth i) → L₁ = L₂ := by
refine ListBlank.induction_on L₁ fun l₁ ↦ ListBlank.induction_on L₂ fun l₂ H ↦ ?_
wlog h : l₁.length ≤ l₂.length
· cases le_total l₁.length l₂.length <;> [skip; symm] <;> apply this <;> try assumption
intro
rw [H]
refine Quotient.sound' (Or.inl ⟨l₂.length - l₁.length, ?_⟩)
refine List.ext_getElem ?_ fun i h h₂ ↦ Eq.symm ?_
· simp only [Nat.add_sub_cancel' h, List.length_append, List.length_replicate]
simp only [ListBlank.nth_mk] at H
rcases lt_or_ge i l₁.length with h' | h'
· simp [h', List.getElem_append h₂, ← List.getI_eq_getElem _ h, ← List.getI_eq_getElem _ h', H]
· rw [List.getElem_append_right h', List.getElem_replicate,
← List.getI_eq_default _ h', H, List.getI_eq_getElem _ h] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | ListBlank.ext | null |
@[simp]
ListBlank.modifyNth {Γ} [Inhabited Γ] (f : Γ → Γ) : ℕ → ListBlank Γ → ListBlank Γ
| 0, L => L.tail.cons (f L.head)
| n + 1, L => (L.tail.modifyNth f n).cons L.head | def | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | ListBlank.modifyNth | Apply a function to a value stored at the nth position of the list. |
ListBlank.nth_modifyNth {Γ} [Inhabited Γ] (f : Γ → Γ) (n i) (L : ListBlank Γ) :
(L.modifyNth f n).nth i = if i = n then f (L.nth i) else L.nth i := by
induction n generalizing i L with
| zero =>
cases i <;> simp only [ListBlank.nth_zero, if_true, ListBlank.head_cons, ListBlank.modifyNth,
ListBlank.nth_succ, if_false, ListBlank.tail_cons, reduceCtorEq]
| succ n IH =>
cases i
· rw [if_neg (Nat.succ_ne_zero _).symm]
simp only [ListBlank.nth_zero, ListBlank.head_cons, ListBlank.modifyNth]
· simp only [IH, ListBlank.modifyNth, ListBlank.nth_succ, ListBlank.tail_cons, Nat.succ.injEq] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | ListBlank.nth_modifyNth | null |
PointedMap.{u, v} (Γ : Type u) (Γ' : Type v) [Inhabited Γ] [Inhabited Γ'] :
Type max u v where
/-- The map underlying this instance. -/
f : Γ → Γ'
map_pt' : f default = default | structure | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | PointedMap. | A pointed map of `Inhabited` types is a map that sends one default value to the other. |
PointedMap.mk_val {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : Γ → Γ') (pt) :
(PointedMap.mk f pt : Γ → Γ') = f :=
rfl
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | PointedMap.mk_val | null |
PointedMap.map_pt {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') :
f default = default :=
PointedMap.map_pt' _
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | PointedMap.map_pt | null |
PointedMap.headI_map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ')
(l : List Γ) : (l.map f).headI = f l.headI := by
cases l <;> [exact (PointedMap.map_pt f).symm; rfl] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | PointedMap.headI_map | null |
ListBlank.map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : ListBlank Γ) :
ListBlank Γ' := by
apply l.liftOn (fun l ↦ ListBlank.mk (List.map f l))
rintro l _ ⟨i, rfl⟩; refine Quotient.sound' (Or.inl ⟨i, ?_⟩)
simp only [PointedMap.map_pt, List.map_append, List.map_replicate]
@[simp] | def | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | ListBlank.map | The `map` function on lists is well defined on `ListBlank`s provided that the map is
pointed. |
ListBlank.map_mk {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : List Γ) :
(ListBlank.mk l).map f = ListBlank.mk (l.map f) :=
rfl
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | ListBlank.map_mk | null |
ListBlank.head_map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ')
(l : ListBlank Γ) : (l.map f).head = f l.head := by
conv => lhs; rw [← ListBlank.cons_head_tail l]
exact Quotient.inductionOn' l fun a ↦ rfl
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | ListBlank.head_map | null |
ListBlank.tail_map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ')
(l : ListBlank Γ) : (l.map f).tail = l.tail.map f := by
conv => lhs; rw [← ListBlank.cons_head_tail l]
exact Quotient.inductionOn' l fun a ↦ rfl
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | ListBlank.tail_map | null |
ListBlank.map_cons {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ')
(l : ListBlank Γ) (a : Γ) : (l.cons a).map f = (l.map f).cons (f a) := by
refine (ListBlank.cons_head_tail _).symm.trans ?_
simp only [ListBlank.head_map, ListBlank.head_cons, ListBlank.tail_map, ListBlank.tail_cons]
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | ListBlank.map_cons | null |
ListBlank.nth_map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ')
(l : ListBlank Γ) (n : ℕ) : (l.map f).nth n = f (l.nth n) := by
refine l.induction_on fun l ↦ ?_
simp only [ListBlank.map_mk, ListBlank.nth_mk, ← List.getD_default_eq_getI]
rw [← List.getD_map _ _ f]
simp | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | ListBlank.nth_map | null |
proj {ι : Type*} {Γ : ι → Type*} [∀ i, Inhabited (Γ i)] (i : ι) :
PointedMap (∀ i, Γ i) (Γ i) :=
⟨fun a ↦ a i, rfl⟩ | def | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | proj | The `i`-th projection as a pointed map. |
proj_map_nth {ι : Type*} {Γ : ι → Type*} [∀ i, Inhabited (Γ i)] (i : ι) (L n) :
(ListBlank.map (@proj ι Γ _ i) L).nth n = L.nth n i := by
rw [ListBlank.nth_map]; rfl | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | proj_map_nth | null |
ListBlank.map_modifyNth {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (F : PointedMap Γ Γ')
(f : Γ → Γ) (f' : Γ' → Γ') (H : ∀ x, F (f x) = f' (F x)) (n) (L : ListBlank Γ) :
(L.modifyNth f n).map F = (L.map F).modifyNth f' n := by
induction n generalizing L <;>
simp only [*, ListBlank.head_map, ListBlank.modifyNth, ListBlank.map_cons, ListBlank.tail_map] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | ListBlank.map_modifyNth | null |
@[simp]
ListBlank.append {Γ} [Inhabited Γ] : List Γ → ListBlank Γ → ListBlank Γ
| [], L => L
| a :: l, L => ListBlank.cons a (ListBlank.append l L)
@[simp] | def | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | ListBlank.append | Append a list on the left side of a `ListBlank`. |
ListBlank.append_mk {Γ} [Inhabited Γ] (l₁ l₂ : List Γ) :
ListBlank.append l₁ (ListBlank.mk l₂) = ListBlank.mk (l₁ ++ l₂) := by
induction l₁ <;>
simp only [*, ListBlank.append, List.nil_append, List.cons_append, ListBlank.cons_mk] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | ListBlank.append_mk | null |
ListBlank.append_assoc {Γ} [Inhabited Γ] (l₁ l₂ : List Γ) (l₃ : ListBlank Γ) :
ListBlank.append (l₁ ++ l₂) l₃ = ListBlank.append l₁ (ListBlank.append l₂ l₃) := by
refine l₃.induction_on fun l ↦ ?_
simp only [ListBlank.append_mk, List.append_assoc] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | ListBlank.append_assoc | null |
ListBlank.flatMap {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (l : ListBlank Γ) (f : Γ → List Γ')
(hf : ∃ n, f default = List.replicate n default) : ListBlank Γ' := by
apply l.liftOn (fun l ↦ ListBlank.mk (l.flatMap f))
rintro l _ ⟨i, rfl⟩; obtain ⟨n, e⟩ := hf; refine Quotient.sound' (Or.inl ⟨i * n, ?_⟩)
rw [List.flatMap_append, mul_comm]; congr
induction i with
| zero => rfl
| succ i IH =>
simp only [IH, e, List.replicate_add, Nat.mul_succ, add_comm, List.replicate_succ,
List.flatMap_cons]
@[simp] | def | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | ListBlank.flatMap | The `flatMap` function on lists is well defined on `ListBlank`s provided that the default
element is sent to a sequence of default elements. |
ListBlank.flatMap_mk
{Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (l : List Γ) (f : Γ → List Γ') (hf) :
(ListBlank.mk l).flatMap f hf = ListBlank.mk (l.flatMap f) :=
rfl
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | ListBlank.flatMap_mk | null |
ListBlank.cons_flatMap {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (a : Γ) (l : ListBlank Γ)
(f : Γ → List Γ') (hf) : (l.cons a).flatMap f hf = (l.flatMap f hf).append (f a) := by
refine l.induction_on fun l ↦ ?_
simp only [ListBlank.append_mk, ListBlank.flatMap_mk, ListBlank.cons_mk, List.flatMap_cons] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | ListBlank.cons_flatMap | null |
Tape (Γ : Type*) [Inhabited Γ] where
/-- The current position of the head. -/
head : Γ
/-- The portion of the tape going off to the left. -/
left : ListBlank Γ
/-- The portion of the tape going off to the right. -/
right : ListBlank Γ | structure | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape | The tape of a Turing machine is composed of a head element (which we imagine to be the
current position of the head), together with two `ListBlank`s denoting the portions of the tape
going off to the left and right. When the Turing machine moves right, an element is pulled from the
right side and becomes the new head, while the head element is `cons`ed onto the left side. |
Tape.inhabited {Γ} [Inhabited Γ] : Inhabited (Tape Γ) :=
⟨by constructor <;> apply default⟩ | instance | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.inhabited | null |
Dir
| left
| right
deriving DecidableEq, Inhabited | inductive | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Dir | A direction for the Turing machine `move` command, either
left or right. |
Tape.left₀ {Γ} [Inhabited Γ] (T : Tape Γ) : ListBlank Γ :=
T.left.cons T.head | def | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.left₀ | The "inclusive" left side of the tape, including both `left` and `head`. |
Tape.right₀ {Γ} [Inhabited Γ] (T : Tape Γ) : ListBlank Γ :=
T.right.cons T.head | def | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.right₀ | The "inclusive" right side of the tape, including both `right` and `head`. |
Tape.move {Γ} [Inhabited Γ] : Dir → Tape Γ → Tape Γ
| Dir.left, ⟨a, L, R⟩ => ⟨L.head, L.tail, R.cons a⟩
| Dir.right, ⟨a, L, R⟩ => ⟨R.head, L.cons a, R.tail⟩
@[simp] | def | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.move | Move the tape in response to a motion of the Turing machine. Note that `T.move Dir.left` makes
`T.left` smaller; the Turing machine is moving left and the tape is moving right. |
Tape.move_left_right {Γ} [Inhabited Γ] (T : Tape Γ) :
(T.move Dir.left).move Dir.right = T := by
simp [Tape.move]
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.move_left_right | null |
Tape.move_right_left {Γ} [Inhabited Γ] (T : Tape Γ) :
(T.move Dir.right).move Dir.left = T := by
simp [Tape.move] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.move_right_left | null |
Tape.mk' {Γ} [Inhabited Γ] (L R : ListBlank Γ) : Tape Γ :=
⟨R.head, L, R.tail⟩
@[simp] | def | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.mk' | Construct a tape from a left side and an inclusive right side. |
Tape.mk'_left {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).left = L :=
rfl
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.mk'_left | null |
Tape.mk'_head {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).head = R.head :=
rfl
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.mk'_head | null |
Tape.mk'_right {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).right = R.tail :=
rfl
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.mk'_right | null |
Tape.mk'_right₀ {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).right₀ = R :=
ListBlank.cons_head_tail _
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.mk'_right₀ | null |
Tape.mk'_left_right₀ {Γ} [Inhabited Γ] (T : Tape Γ) : Tape.mk' T.left T.right₀ = T := by
simp only [Tape.right₀, Tape.mk', ListBlank.head_cons, ListBlank.tail_cons] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.mk'_left_right₀ | null |
Tape.exists_mk' {Γ} [Inhabited Γ] (T : Tape Γ) : ∃ L R, T = Tape.mk' L R :=
⟨_, _, (Tape.mk'_left_right₀ _).symm⟩
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.exists_mk' | null |
Tape.move_left_mk' {Γ} [Inhabited Γ] (L R : ListBlank Γ) :
(Tape.mk' L R).move Dir.left = Tape.mk' L.tail (R.cons L.head) := by
simp only [Tape.move, Tape.mk', ListBlank.head_cons, ListBlank.cons_head_tail,
ListBlank.tail_cons]
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.move_left_mk' | null |
Tape.move_right_mk' {Γ} [Inhabited Γ] (L R : ListBlank Γ) :
(Tape.mk' L R).move Dir.right = Tape.mk' (L.cons R.head) R.tail := by
simp only [Tape.move, Tape.mk'] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.move_right_mk' | null |
Tape.mk₂ {Γ} [Inhabited Γ] (L R : List Γ) : Tape Γ :=
Tape.mk' (ListBlank.mk L) (ListBlank.mk R) | def | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.mk₂ | Construct a tape from a left side and an inclusive right side. |
Tape.mk₁ {Γ} [Inhabited Γ] (l : List Γ) : Tape Γ :=
Tape.mk₂ [] l | def | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.mk₁ | Construct a tape from a list, with the head of the list at the TM head and the rest going
to the right. |
Tape.nth {Γ} [Inhabited Γ] (T : Tape Γ) : ℤ → Γ
| 0 => T.head
| (n + 1 : ℕ) => T.right.nth n
| -(n + 1 : ℕ) => T.left.nth n
@[simp] | def | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.nth | The `nth` function of a tape is integer-valued, with index `0` being the head, negative indexes
on the left and positive indexes on the right. (Picture a number line.) |
Tape.nth_zero {Γ} [Inhabited Γ] (T : Tape Γ) : T.nth 0 = T.1 :=
rfl | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.nth_zero | null |
Tape.right₀_nth {Γ} [Inhabited Γ] (T : Tape Γ) (n : ℕ) : T.right₀.nth n = T.nth n := by
cases n <;> simp only [Tape.nth, Tape.right₀, ListBlank.nth_zero,
ListBlank.nth_succ, ListBlank.head_cons, ListBlank.tail_cons]
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.right₀_nth | null |
Tape.mk'_nth_nat {Γ} [Inhabited Γ] (L R : ListBlank Γ) (n : ℕ) :
(Tape.mk' L R).nth n = R.nth n := by
rw [← Tape.right₀_nth, Tape.mk'_right₀]
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.mk'_nth_nat | null |
Tape.move_left_nth {Γ} [Inhabited Γ] :
∀ (T : Tape Γ) (i : ℤ), (T.move Dir.left).nth i = T.nth (i - 1)
| ⟨_, _, _⟩, -(_ + 1 : ℕ) => (ListBlank.nth_succ _ _).symm
| ⟨_, _, _⟩, 0 => (ListBlank.nth_zero _).symm
| ⟨_, _, _⟩, 1 => (ListBlank.nth_zero _).trans (ListBlank.head_cons _ _)
| ⟨a, L, R⟩, (n + 1 : ℕ) + 1 => by
rw [add_sub_cancel_right]
change (R.cons a).nth (n + 1) = R.nth n
rw [ListBlank.nth_succ, ListBlank.tail_cons]
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.move_left_nth | null |
Tape.move_right_nth {Γ} [Inhabited Γ] (T : Tape Γ) (i : ℤ) :
(T.move Dir.right).nth i = T.nth (i + 1) := by
conv => rhs; rw [← T.move_right_left]
rw [Tape.move_left_nth, add_sub_cancel_right]
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.move_right_nth | null |
Tape.move_right_n_head {Γ} [Inhabited Γ] (T : Tape Γ) (i : ℕ) :
((Tape.move Dir.right)^[i] T).head = T.nth i := by
induction i generalizing T
· rfl
· simp only [*, Tape.move_right_nth, Int.natCast_succ, iterate_succ, Function.comp_apply] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.move_right_n_head | null |
Tape.write {Γ} [Inhabited Γ] (b : Γ) (T : Tape Γ) : Tape Γ :=
{ T with head := b }
@[simp] | def | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.write | Replace the current value of the head on the tape. |
Tape.write_self {Γ} [Inhabited Γ] : ∀ T : Tape Γ, T.write T.1 = T := by
rintro ⟨⟩; rfl
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.write_self | null |
Tape.write_nth {Γ} [Inhabited Γ] (b : Γ) :
∀ (T : Tape Γ) {i : ℤ}, (T.write b).nth i = if i = 0 then b else T.nth i
| _, 0 => rfl
| _, (_ + 1 : ℕ) => rfl
| _, -(_ + 1 : ℕ) => rfl
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.write_nth | null |
Tape.write_mk' {Γ} [Inhabited Γ] (a b : Γ) (L R : ListBlank Γ) :
(Tape.mk' L (R.cons a)).write b = Tape.mk' L (R.cons b) := by
simp only [Tape.write, Tape.mk', ListBlank.head_cons, ListBlank.tail_cons] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.write_mk' | null |
Tape.map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (T : Tape Γ) : Tape Γ' :=
⟨f T.1, T.2.map f, T.3.map f⟩
@[simp] | def | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.map | Apply a pointed map to a tape to change the alphabet. |
Tape.map_fst {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') :
∀ T : Tape Γ, (T.map f).1 = f T.1 := by
rintro ⟨⟩; rfl
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.map_fst | null |
Tape.map_write {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (b : Γ) :
∀ T : Tape Γ, (T.write b).map f = (T.map f).write (f b) := by
rintro ⟨⟩; rfl
@[simp] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.map_write | null |
Tape.write_move_right_n {Γ} [Inhabited Γ] (f : Γ → Γ) (L R : ListBlank Γ) (n : ℕ) :
((Tape.move Dir.right)^[n] (Tape.mk' L R)).write (f (R.nth n)) =
(Tape.move Dir.right)^[n] (Tape.mk' L (R.modifyNth f n)) := by
induction n generalizing L R with
| zero =>
simp only [ListBlank.nth_zero, ListBlank.modifyNth, iterate_zero_apply]
rw [← Tape.write_mk', ListBlank.cons_head_tail]
| succ n IH =>
simp only [ListBlank.head_cons, ListBlank.nth_succ, ListBlank.modifyNth, Tape.move_right_mk',
ListBlank.tail_cons, iterate_succ_apply, IH] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.write_move_right_n | null |
Tape.map_move {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (T : Tape Γ) (d) :
(T.move d).map f = (T.map f).move d := by
cases T
cases d <;> simp only [Tape.move, Tape.map, ListBlank.head_map,
ListBlank.map_cons, ListBlank.tail_map] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.map_move | null |
Tape.map_mk' {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (L R : ListBlank Γ) :
(Tape.mk' L R).map f = Tape.mk' (L.map f) (R.map f) := by
simp only [Tape.mk', Tape.map, ListBlank.head_map,
ListBlank.tail_map] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.map_mk' | null |
Tape.map_mk₂ {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (L R : List Γ) :
(Tape.mk₂ L R).map f = Tape.mk₂ (L.map f) (R.map f) := by
simp only [Tape.mk₂, Tape.map_mk', ListBlank.map_mk] | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.map_mk₂ | null |
Tape.map_mk₁ {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : List Γ) :
(Tape.mk₁ l).map f = Tape.mk₁ (l.map f) :=
Tape.map_mk₂ _ _ _ | theorem | Computability | [
"Mathlib.Data.Vector.Basic",
"Mathlib.Logic.Function.Iterate",
"Mathlib.Tactic.ApplyFun",
"Mathlib.Data.List.GetD"
] | Mathlib/Computability/Tape.lean | Tape.map_mk₁ | null |
FinTM2 where
/-- index type of stacks -/
{K : Type} [kDecidableEq : DecidableEq K]
/-- A TM2 machine has finitely many stacks. -/
[kFin : Fintype K]
/-- input resp. output stack -/
(k₀ k₁ : K)
/-- type of stack elements -/
(Γ : K → Type)
/-- type of function labels -/
(Λ : Type)
/-- a main function: the initial function that is executed, given by its label -/
(main : Λ)
/-- A TM2 machine has finitely many function labels. -/
[ΛFin : Fintype Λ]
/-- type of states of the machine -/
(σ : Type)
/-- the initial state of the machine -/
(initialState : σ)
/-- a TM2 machine has finitely many internal states. -/
[σFin : Fintype σ]
/-- Each internal stack is finite. -/
[Γk₀Fin : Fintype (Γ k₀)]
/-- the program itself, i.e. one function for every function label -/
(m : Λ → Turing.TM2.Stmt Γ Λ σ)
attribute [nolint docBlame] FinTM2.kDecidableEq | structure | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | FinTM2 | A bundled TM2 (an equivalent of the classical Turing machine, defined starting from
the namespace `Turing.TM2` in `TuringMachine.lean`), with an input and output stack,
a main function, an initial state and some finiteness guarantees. |
decidableEqK : DecidableEq tm.K :=
tm.kDecidableEq | instance | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | decidableEqK | null |
inhabitedσ : Inhabited tm.σ :=
⟨tm.initialState⟩ | instance | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | inhabitedσ | null |
Stmt : Type :=
Turing.TM2.Stmt tm.Γ tm.Λ tm.σ | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | Stmt | The type of statements (functions) corresponding to this TM. |
inhabitedStmt : Inhabited (Stmt tm) :=
inferInstanceAs (Inhabited (Turing.TM2.Stmt tm.Γ tm.Λ tm.σ)) | instance | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | inhabitedStmt | null |
Cfg : Type :=
Turing.TM2.Cfg tm.Γ tm.Λ tm.σ | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | Cfg | The type of configurations (functions) corresponding to this TM. |
inhabitedCfg : Inhabited (Cfg tm) :=
Turing.TM2.Cfg.inhabited _ _ _ | instance | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | inhabitedCfg | null |
@[simp]
step : tm.Cfg → Option tm.Cfg :=
Turing.TM2.step tm.m | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | step | The step function corresponding to this TM. |
initList (tm : FinTM2) (s : List (tm.Γ tm.k₀)) : tm.Cfg where
l := Option.some tm.main
var := tm.initialState
stk k :=
@dite (List (tm.Γ k)) (k = tm.k₀) (tm.kDecidableEq k tm.k₀) (fun h => by rw [h]; exact s)
fun _ => [] | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | initList | The initial configuration corresponding to a list in the input alphabet. |
haltList (tm : FinTM2) (s : List (tm.Γ tm.k₁)) : tm.Cfg where
l := Option.none
var := tm.initialState
stk k :=
@dite (List (tm.Γ k)) (k = tm.k₁) (tm.kDecidableEq k tm.k₁) (fun h => by rw [h]; exact s)
fun _ => [] | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | haltList | The final configuration corresponding to a list in the output alphabet. |
EvalsTo {σ : Type*} (f : σ → Option σ) (a : σ) (b : Option σ) where
/-- number of steps taken -/
steps : ℕ
evals_in_steps : (flip bind f)^[steps] a = b | structure | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | EvalsTo | A "proof" of the fact that `f` eventually reaches `b` when repeatedly evaluated on `a`,
remembering the number of steps it takes. |
EvalsToInTime {σ : Type*} (f : σ → Option σ) (a : σ) (b : Option σ) (m : ℕ) extends
EvalsTo f a b where
steps_le_m : steps ≤ m | structure | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | EvalsToInTime | A "proof" of the fact that `f` eventually reaches `b` in at most `m` steps when repeatedly
evaluated on `a`, remembering the number of steps it takes. |
EvalsTo.refl {σ : Type*} (f : σ → Option σ) (a : σ) : EvalsTo f a (some a) :=
⟨0, rfl⟩ | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | EvalsTo.refl | Reflexivity of `EvalsTo` in 0 steps. |
@[trans]
EvalsTo.trans {σ : Type*} (f : σ → Option σ) (a : σ) (b : σ) (c : Option σ)
(h₁ : EvalsTo f a b) (h₂ : EvalsTo f b c) : EvalsTo f a c :=
⟨h₂.steps + h₁.steps, by rw [Function.iterate_add_apply, h₁.evals_in_steps, h₂.evals_in_steps]⟩ | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | EvalsTo.trans | Transitivity of `EvalsTo` in the sum of the numbers of steps. |
EvalsToInTime.refl {σ : Type*} (f : σ → Option σ) (a : σ) : EvalsToInTime f a (some a) 0 :=
⟨EvalsTo.refl f a, le_refl 0⟩ | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | EvalsToInTime.refl | Reflexivity of `EvalsToInTime` in 0 steps. |
@[trans]
EvalsToInTime.trans {σ : Type*} (f : σ → Option σ) (m₁ : ℕ) (m₂ : ℕ) (a : σ) (b : σ)
(c : Option σ) (h₁ : EvalsToInTime f a b m₁) (h₂ : EvalsToInTime f b c m₂) :
EvalsToInTime f a c (m₂ + m₁) :=
⟨EvalsTo.trans f a b c h₁.toEvalsTo h₂.toEvalsTo, add_le_add h₂.steps_le_m h₁.steps_le_m⟩ | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | EvalsToInTime.trans | Transitivity of `EvalsToInTime` in the sum of the numbers of steps. |
TM2Outputs (tm : FinTM2) (l : List (tm.Γ tm.k₀)) (l' : Option (List (tm.Γ tm.k₁))) :=
EvalsTo tm.step (initList tm l) ((Option.map (haltList tm)) l') | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | TM2Outputs | A proof of tm outputting l' when given l. |
TM2OutputsInTime (tm : FinTM2) (l : List (tm.Γ tm.k₀)) (l' : Option (List (tm.Γ tm.k₁)))
(m : ℕ) :=
EvalsToInTime tm.step (initList tm l) ((Option.map (haltList tm)) l') m | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | TM2OutputsInTime | A proof of tm outputting l' when given l in at most m steps. |
TM2OutputsInTime.toTM2Outputs {tm : FinTM2} {l : List (tm.Γ tm.k₀)}
{l' : Option (List (tm.Γ tm.k₁))} {m : ℕ} (h : TM2OutputsInTime tm l l' m) :
TM2Outputs tm l l' :=
h.toEvalsTo | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | TM2OutputsInTime.toTM2Outputs | The forgetful map, forgetting the upper bound on the number of steps. |
TM2ComputableAux (Γ₀ Γ₁ : Type) where
/-- the underlying bundled TM2 -/
tm : FinTM2
/-- the input alphabet is equivalent to `Γ₀` -/
inputAlphabet : tm.Γ tm.k₀ ≃ Γ₀
/-- the output alphabet is equivalent to `Γ₁` -/
outputAlphabet : tm.Γ tm.k₁ ≃ Γ₁ | structure | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | TM2ComputableAux | A (bundled TM2) Turing machine
with input alphabet equivalent to `Γ₀` and output alphabet equivalent to `Γ₁`. |
TM2Computable {α β : Type} (ea : FinEncoding α) (eb : FinEncoding β) (f : α → β) extends
TM2ComputableAux ea.Γ eb.Γ where
/-- a proof this machine outputs `f` -/
outputsFun :
∀ a,
TM2Outputs tm (List.map inputAlphabet.invFun (ea.encode a))
(Option.some ((List.map outputAlphabet.invFun) (eb.encode (f a)))) | structure | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | TM2Computable | A Turing machine + a proof it outputs `f`. |
TM2ComputableInTime {α β : Type} (ea : FinEncoding α) (eb : FinEncoding β)
(f : α → β) extends TM2ComputableAux ea.Γ eb.Γ where
/-- a time function -/
time : ℕ → ℕ
/-- proof this machine outputs `f` in at most `time(input.length)` steps -/
outputsFun :
∀ a,
TM2OutputsInTime tm (List.map inputAlphabet.invFun (ea.encode a))
(Option.some ((List.map outputAlphabet.invFun) (eb.encode (f a))))
(time (ea.encode a).length) | structure | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | TM2ComputableInTime | A Turing machine + a time function +
a proof it outputs `f` in at most `time(input.length)` steps. |
TM2ComputableInPolyTime {α β : Type} (ea : FinEncoding α) (eb : FinEncoding β)
(f : α → β) extends TM2ComputableAux ea.Γ eb.Γ where
/-- a polynomial time function -/
time : Polynomial ℕ
/-- proof that this machine outputs `f` in at most `time(input.length)` steps -/
outputsFun :
∀ a,
TM2OutputsInTime tm (List.map inputAlphabet.invFun (ea.encode a))
(Option.some ((List.map outputAlphabet.invFun) (eb.encode (f a))))
(time.eval (ea.encode a).length) | structure | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | TM2ComputableInPolyTime | A Turing machine + a polynomial time function +
a proof it outputs `f` in at most `time(input.length)` steps. |
TM2ComputableInTime.toTM2Computable {α β : Type} {ea : FinEncoding α} {eb : FinEncoding β}
{f : α → β} (h : TM2ComputableInTime ea eb f) : TM2Computable ea eb f :=
⟨h.toTM2ComputableAux, fun a => TM2OutputsInTime.toTM2Outputs (h.outputsFun a)⟩ | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | TM2ComputableInTime.toTM2Computable | A forgetful map, forgetting the time bound on the number of steps. |
TM2ComputableInPolyTime.toTM2ComputableInTime {α β : Type} {ea : FinEncoding α}
{eb : FinEncoding β} {f : α → β} (h : TM2ComputableInPolyTime ea eb f) :
TM2ComputableInTime ea eb f :=
⟨h.toTM2ComputableAux, fun n => h.time.eval n, h.outputsFun⟩
open Turing.TM2.Stmt | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | TM2ComputableInPolyTime.toTM2ComputableInTime | A forgetful map, forgetting that the time function is polynomial. |
idComputer {α : Type} (ea : FinEncoding α) : FinTM2 where
K := Unit
k₀ := ⟨⟩
k₁ := ⟨⟩
Γ _ := ea.Γ
Λ := Unit
main := ⟨⟩
σ := Unit
initialState := ⟨⟩
Γk₀Fin := ea.ΓFin
m _ := halt | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | idComputer | A Turing machine computing the identity on α. |
inhabitedFinTM2 : Inhabited FinTM2 :=
⟨idComputer Computability.inhabitedFinEncoding.default⟩
noncomputable section | instance | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | inhabitedFinTM2 | null |
idComputableInPolyTime {α : Type} (ea : FinEncoding α) :
@TM2ComputableInPolyTime α α ea ea id where
tm := idComputer ea
inputAlphabet := Equiv.cast rfl
outputAlphabet := Equiv.cast rfl
time := 1
outputsFun _ :=
{ steps := 1
evals_in_steps := rfl
steps_le_m := by simp only [Polynomial.eval_one, le_refl] } | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | idComputableInPolyTime | A proof that the identity map on α is computable in polytime. |
inhabitedTM2ComputableInPolyTime :
Inhabited (TM2ComputableInPolyTime (default : FinEncoding Bool) default id) :=
⟨idComputableInPolyTime Computability.inhabitedFinEncoding.default⟩ | instance | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | inhabitedTM2ComputableInPolyTime | null |
inhabitedTM2OutputsInTime :
Inhabited
(TM2OutputsInTime (idComputer finEncodingBoolBool) (List.map (Equiv.cast rfl).invFun [false])
(some (List.map (Equiv.cast rfl).invFun [false])) (Polynomial.eval 1 1)) :=
⟨(idComputableInPolyTime finEncodingBoolBool).outputsFun false⟩ | instance | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | inhabitedTM2OutputsInTime | null |
inhabitedTM2Outputs :
Inhabited
(TM2Outputs (idComputer finEncodingBoolBool) (List.map (Equiv.cast rfl).invFun [false])
(some (List.map (Equiv.cast rfl).invFun [false]))) :=
⟨TM2OutputsInTime.toTM2Outputs Turing.inhabitedTM2OutputsInTime.default⟩ | instance | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | inhabitedTM2Outputs | null |
inhabitedEvalsToInTime :
Inhabited (EvalsToInTime (fun _ : Unit => some ⟨⟩) ⟨⟩ (some ⟨⟩) 0) :=
⟨EvalsToInTime.refl _ _⟩ | instance | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | inhabitedEvalsToInTime | null |
inhabitedTM2EvalsTo : Inhabited (EvalsTo (fun _ : Unit => some ⟨⟩) ⟨⟩ (some ⟨⟩)) :=
⟨EvalsTo.refl _ _⟩ | instance | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | inhabitedTM2EvalsTo | null |
idComputableInTime {α : Type} (ea : FinEncoding α) : @TM2ComputableInTime α α ea ea id :=
TM2ComputableInPolyTime.toTM2ComputableInTime <| idComputableInPolyTime ea | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | idComputableInTime | A proof that the identity map on α is computable in time. |
inhabitedTM2ComputableInTime :
Inhabited (TM2ComputableInTime finEncodingBoolBool finEncodingBoolBool id) :=
⟨idComputableInTime Computability.inhabitedFinEncoding.default⟩ | instance | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | inhabitedTM2ComputableInTime | null |
idComputable {α : Type} (ea : FinEncoding α) : @TM2Computable α α ea ea id :=
TM2ComputableInTime.toTM2Computable <| idComputableInTime ea | def | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | idComputable | A proof that the identity map on α is computable. |
inhabitedTM2Computable :
Inhabited (TM2Computable finEncodingBoolBool finEncodingBoolBool id) :=
⟨idComputable Computability.inhabitedFinEncoding.default⟩ | instance | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | inhabitedTM2Computable | null |
inhabitedTM2ComputableAux : Inhabited (TM2ComputableAux Bool Bool) :=
⟨(default : TM2Computable finEncodingBoolBool finEncodingBoolBool id).toTM2ComputableAux⟩ | instance | Computability | [
"Mathlib.Algebra.Polynomial.Eval.Defs",
"Mathlib.Computability.Encoding",
"Mathlib.Computability.TuringMachine"
] | Mathlib/Computability/TMComputable.lean | inhabitedTM2ComputableAux | null |
Code
| zero'
| succ
| tail
| cons : Code → Code → Code
| comp : Code → Code → Code
| case : Code → Code → Code
| fix : Code → Code
deriving DecidableEq, Inhabited | inductive | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.PostTuringMachine",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/TMConfig.lean | Code | The type of codes for primitive recursive functions. Unlike `Nat.Partrec.Code`, this uses a set
of operations on `List ℕ`. See `Code.eval` for a description of the behavior of the primitives. |
Code.eval : Code → List ℕ →. List ℕ
| Code.zero' => fun v => pure (0 :: v)
| Code.succ => fun v => pure [v.headI.succ]
| Code.tail => fun v => pure v.tail
| Code.cons f fs => fun v => do
let n ← Code.eval f v
let ns ← Code.eval fs v
pure (n.headI :: ns)
| Code.comp f g => fun v => g.eval v >>= f.eval
| Code.case f g => fun v => v.headI.rec (f.eval v.tail) fun y _ => g.eval (y::v.tail)
| Code.fix f =>
PFun.fix fun v => (f.eval v).map fun v => if v.headI = 0 then Sum.inl v.tail else Sum.inr v.tail | def | Computability | [
"Mathlib.Computability.Halting",
"Mathlib.Computability.PostTuringMachine",
"Mathlib.Tactic.DeriveFintype"
] | Mathlib/Computability/TMConfig.lean | Code.eval | The semantics of the `Code` primitives, as partial functions `List ℕ →. List ℕ`. By convention
we functions that return a single result return a singleton `[n]`, or in some cases `n :: v` where
`v` will be ignored by a subsequent function.
* `zero'` appends a `0` to the input. That is, `zero' v = 0 :: v`.
* `succ` returns the successor of the head of the input, defaulting to zero if there is no head:
* `succ [] = [1]`
* `succ (n :: v) = [n + 1]`
* `tail` returns the tail of the input
* `tail [] = []`
* `tail (n :: v) = v`
* `cons f fs` calls `f` and `fs` on the input and conses the results:
* `cons f fs v = (f v).head :: fs v`
* `comp f g` calls `f` on the output of `g`:
* `comp f g v = f (g v)`
* `case f g` cases on the head of the input, calling `f` or `g` depending on whether it is zero or
a successor (similar to `Nat.casesOn`).
* `case f g [] = f []`
* `case f g (0 :: v) = f v`
* `case f g (n+1 :: v) = g (n :: v)`
* `fix f` calls `f` repeatedly, using the head of the result of `f` to decide whether to call `f`
again or finish:
* `fix f v = []` if `f v = []`
* `fix f v = w` if `f v = 0 :: w`
* `fix f v = fix f w` if `f v = n+1 :: w` (the exact value of `n` is discarded) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.