chars
int64
40
24k
content_type
stringclasses
9 values
id
stringlengths
13
64
source
stringclasses
5 values
subset
stringclasses
31 values
text
stringlengths
40
24k
233
leanexplore_declaration
leanexplore:386702
leanexplore_sqlite
leanexplore_declarations
theorem le_omegaPow_congr [Inhabited α] {l1 l2 : Language α} (h : l1 ≤ l2) : l1^ω ≤ l2^ω := by rintro s ⟨xs, rfl, h_xs⟩ refine ⟨xs, rfl, ?_⟩ intro k; specialize h_xs k simp only [Language.mem_sub_one, ne_eq] at h_xs ⊢ tauto
103
leanexplore_declaration
leanexplore:386703
leanexplore_sqlite
leanexplore_declarations
@[simp, scoped grind =] theorem omegaPow_of_sub_one [Inhabited α] : (l - 1)^ω = l^ω := by ext s; simp
103
leanexplore_declaration
leanexplore:386704
leanexplore_sqlite
leanexplore_declarations
@[simp, nolint simpNF] theorem zero_omegaPow [Inhabited α] : (0 : Language α)^ω = ⊥ := by ext s; simp
143
leanexplore_declaration
leanexplore:386705
leanexplore_sqlite
leanexplore_declarations
@[simp, nolint simpNF] theorem one_omegaPow [Inhabited α] : (1 : Language α)^ω = ⊥ := by rw [← omegaPow_of_sub_one, tsub_self, zero_omegaPow]
143
leanexplore_declaration
leanexplore:386706
leanexplore_sqlite
leanexplore_declarations
@[simp, scoped grind =] theorem omegaPow_of_le_one [Inhabited α] (h : l ≤ 1) : l^ω = ⊥ := by cases (Language.le_one_iff_eq.mp h) <;> simp_all
212
leanexplore_declaration
leanexplore:386707
leanexplore_sqlite
leanexplore_declarations
theorem omegaPow_eq_empty [Inhabited α] (h : l^ω = ⊥) : l ≤ 1 := by intro x h_x by_contra h_contra suffices h' : (const x).flatten ∈ l^ω by simp [h] at h' use const x, rfl exact fun _ => ⟨h_x, h_contra⟩
359
leanexplore_declaration
leanexplore:386708
leanexplore_sqlite
leanexplore_declarations
/-- An alternative characterization of `l * p`. -/ theorem hmul_seq_prop : l * p = { s | ∃ k, s.take k ∈ l ∧ s.drop k ∈ p } := by ext s; constructor · rintro ⟨x, h_x, t, h_t, rfl⟩ refine ⟨x.length, ?_, ?_⟩ · simpa [take_append_of_le_length] · simpa [drop_append_ωSequence] · rintro ⟨k, h1, h2⟩ exac...
692
leanexplore_declaration
leanexplore:386709
leanexplore_sqlite
leanexplore_declarations
/-- An alternative characterization of `l^ω`. -/ theorem omegaPow_seq_prop [Inhabited α] : l^ω = { s | ∃ f : ℕ → ℕ, StrictMono f ∧ f 0 = 0 ∧ ∀ m, s.extract (f m) (f (m + 1)) ∈ l } := by ext s; constructor · rintro ⟨xs, rfl, h_xs⟩ simp [forall_and, List.ne_nil_iff_length_pos] at h_xs refine ⟨xs.cumLen, b...
861
leanexplore_declaration
leanexplore:386710
leanexplore_sqlite
leanexplore_declarations
theorem omegaPow_coind' [Inhabited α] (h_nn : [] ∉ l) (h_le : p ≤ l * p) : p ≤ l^ω := by intro s h_s have h_nxt m (hm : s.drop m ∈ p) : ∃ n > m, s.extract m n ∈ l ∧ s.drop n ∈ p := by obtain ⟨k, _⟩ := hmul_seq_prop ▸ h_le hm grind [extract_eq_drop_take] choose nxt_n nxt_p using h_nxt let f := iter_helpe...
212
leanexplore_declaration
leanexplore:386711
leanexplore_sqlite
leanexplore_declarations
/-- A "coinductive" rule for proving `p` is a subset of `l^ω`. -/ theorem omegaPow_coind [Inhabited α] (h_le : p ≤ (l - 1) * p) : p ≤ l^ω := by rw [← omegaPow_of_sub_one] refine omegaPow_coind' ?_ h_le simp
220
leanexplore_declaration
leanexplore:386712
leanexplore_sqlite
leanexplore_declarations
theorem omegaPow_le_hmul_omegaPow' [Inhabited α] (l : Language α) : l^ω ≤ (l - 1) * l^ω := by rintro s ⟨xs, rfl, h_xs⟩ refine ⟨xs.head, h_xs 0, xs.tail.flatten, ⟨xs.tail, rfl, ?_⟩, ?_⟩ <;> grind [l.mem_sub_one]
218
leanexplore_declaration
leanexplore:386713
leanexplore_sqlite
leanexplore_declarations
theorem omegaPow_le_hmul_omegaPow [Inhabited α] (l : Language α) : l^ω ≤ l * l^ω := by have h1 := omegaPow_le_hmul_omegaPow' l refine le_trans h1 ?_ refine le_hmul_congr ?_ ?_ · apply sdiff_le · apply le_refl
315
leanexplore_declaration
leanexplore:386714
leanexplore_sqlite
leanexplore_declarations
theorem hmul_omegaPow_le_omegaPow [Inhabited α] (l : Language α) : l * l^ω ≤ l^ω := by suffices h : l * l^ω ≤ (l - 1) * (l * l^ω) by exact omegaPow_coind h rw [← mul_hmul, Language.sub_one_mul, ← Language.mul_sub_one, mul_hmul] refine le_hmul_congr ?_ ?_ · apply le_refl · apply omegaPow_le_hmul_omegaPow'
202
leanexplore_declaration
leanexplore:386715
leanexplore_sqlite
leanexplore_declarations
@[simp, scoped grind =] theorem hmul_omegaPow_eq_omegaPow [Inhabited α] (l : Language α) : l * l^ω = l^ω := by apply le_antisymm · apply hmul_omegaPow_le_omegaPow · apply omegaPow_le_hmul_omegaPow
113
leanexplore_declaration
leanexplore:386716
leanexplore_sqlite
leanexplore_declarations
theorem omegaPow_le_kstar_omegaPow [Inhabited α] (l : Language α) : l^ω ≤ (l∗)^ω := by simp [le_omegaPow_congr]
349
leanexplore_declaration
leanexplore:386717
leanexplore_sqlite
leanexplore_declarations
theorem kstar_omegaPow_le_omegaPow [Inhabited α] (l : Language α) : (l∗)^ω ≤ l^ω := by suffices h : (l∗)^ω ≤ (l - 1) * (l∗)^ω by exact omegaPow_coind h calc _ ≤ (l∗ - 1) * (l∗)^ω := omegaPow_le_hmul_omegaPow' _ _ = (l - 1) * l∗ * (l∗)^ω := by simp [Language.kstar_sub_one] _ = (l - 1) * (l∗ * (l∗)^ω) := ...
204
leanexplore_declaration
leanexplore:386718
leanexplore_sqlite
leanexplore_declarations
@[simp, scoped grind =] theorem kstar_omegaPow_eq_omegaPow [Inhabited α] (l : Language α) : (l∗)^ω = l^ω := by apply le_antisymm · apply kstar_omegaPow_le_omegaPow · apply omegaPow_le_kstar_omegaPow
228
leanexplore_declaration
leanexplore:386719
leanexplore_sqlite
leanexplore_declarations
@[simp, scoped grind =] theorem kstar_hmul_omegaPow_eq_omegaPow [Inhabited α] (l : Language α) : l∗ * l^ω = l^ω := by calc _ = l∗ * (l∗)^ω := by simp _ = (l∗)^ω := by rw [hmul_omegaPow_eq_omegaPow] _ = _ := by simp
72
leanexplore_declaration
leanexplore:386720
leanexplore_sqlite
leanexplore_declarations
@[simp] theorem omegaLim_zero : (0 : Language α)↗ω = ⊥ := by ext; simp
90
leanexplore_declaration
leanexplore:386721
leanexplore_sqlite
leanexplore_declarations
@[simp, scoped grind =] theorem map_id (p : ωLanguage α) : map id p = p := by simp [map]
141
leanexplore_declaration
leanexplore:386722
leanexplore_sqlite
leanexplore_declarations
@[scoped grind =] theorem map_map (g : β → γ) (f : α → β) (p : ωLanguage α) : map g (map f p) = map (g ∘ f) p := by simp [map, image_image]
228
leanexplore_declaration
leanexplore:386723
leanexplore_sqlite
leanexplore_declarations
/-- An ω-language is ω-regular iff it is accepted by a finite-state nondeterministic Buchi automaton. -/ def IsRegular (p : ωLanguage Symbol) := ∃ (State : Type) (_ : Finite State) (na : NA.Buchi State Symbol), language na = p
309
leanexplore_declaration
leanexplore:386724
leanexplore_sqlite
leanexplore_declarations
/-- The state space of the accepting finite-state nondeterministic Buchi automaton can in fact be universe-polymorphic. -/ theorem isRegular_iff {p : ωLanguage Symbol} : p.IsRegular ↔ ∃ (σ : Type v) (_ : Finite σ) (na : NA.Buchi σ Symbol), language na = p := ⟨isRegular_iff.helper, isRegular_iff.helper⟩
285
leanexplore_declaration
leanexplore:386725
leanexplore_sqlite
leanexplore_declarations
/-- The ω-language accepted by a finite-state deterministic Buchi automaton is ω-regular. -/ theorem IsRegular.of_da_buchi {State : Type} [Finite State] (da : DA.Buchi State Symbol) : (language da).IsRegular := ⟨State, inferInstance, da.toNABuchi, DA.Buchi.toNABuchi_language_eq⟩
604
leanexplore_declaration
leanexplore:386726
leanexplore_sqlite
leanexplore_declarations
/-- There is an ω-regular language that is not accepted by any deterministic Buchi automaton, where the automaton is not even required to be finite-state. -/ theorem IsRegular.not_da_buchi : ∃ (Symbol : Type) (p : ωLanguage Symbol), p.IsRegular ∧ ¬ ∃ (State : Type) (da : DA.Buchi State Symbol), language da = p :=...
300
leanexplore_declaration
leanexplore:386727
leanexplore_sqlite
leanexplore_declarations
/-- The ω-limit of a regular language is ω-regular. -/ @[simp] theorem IsRegular.regular_omegaLim {l : Language Symbol} (h : l.IsRegular) : (l↗ω).IsRegular := by obtain ⟨State, _, ⟨da, acc⟩, rfl⟩ := Language.IsRegular.iff_dfa.mp h grind [IsRegular.of_da_buchi, =_ DA.buchi_eq_finAcc_omegaLim]
264
leanexplore_declaration
leanexplore:386728
leanexplore_sqlite
leanexplore_declarations
/-- The empty language is ω-regular. -/ @[simp] theorem IsRegular.bot : (⊥ : ωLanguage Symbol).IsRegular := by let na : NA.Buchi Unit Symbol := { Tr _ _ _ := False start := ∅ accept := ∅ } use Unit, inferInstance, na ext xs simp +instances [na]
440
leanexplore_declaration
leanexplore:386729
leanexplore_sqlite
leanexplore_declarations
/-- The language of all ω-sequences is ω-regular. -/ @[simp] theorem IsRegular.top : (⊤ : ωLanguage Symbol).IsRegular := by let na : NA.Buchi Unit Symbol := { Tr _ _ _ := True start := univ accept := univ } use Unit, inferInstance, na ext xs simp +instances only [na, NA.Buchi.instωAcceptor, mem_lang...
733
leanexplore_declaration
leanexplore:386730
leanexplore_sqlite
leanexplore_declarations
/-- The union of two ω-regular languages is ω-regular. -/ @[simp] theorem IsRegular.sup {p1 p2 : ωLanguage Symbol} (h1 : p1.IsRegular) (h2 : p2.IsRegular) : (p1 ⊔ p2).IsRegular := by obtain ⟨State1, h_fin1, ⟨na1, acc1⟩, rfl⟩ := h1 obtain ⟨State2, h_fin1, ⟨na2, acc2⟩, rfl⟩ := h2 let State : Fin 2 → Type | ...
745
leanexplore_declaration
leanexplore:386731
leanexplore_sqlite
leanexplore_declarations
/-- The intersection of two ω-regular languages is ω-regular. -/ @[simp] theorem IsRegular.inf {p1 p2 : ωLanguage Symbol} (h1 : p1.IsRegular) (h2 : p2.IsRegular) : (p1 ⊓ p2).IsRegular := by obtain ⟨State1, h_fin1, ⟨na1, acc1⟩, rfl⟩ := h1 obtain ⟨State2, h_fin1, ⟨na2, acc2⟩, rfl⟩ := h2 let State : Bool → Type ...
510
leanexplore_declaration
leanexplore:386732
leanexplore_sqlite
leanexplore_declarations
/-- The union of any finite number of ω-regular languages is ω-regular. -/ @[simp] theorem IsRegular.iSup {I : Type*} [Finite I] {s : Set I} {p : I → ωLanguage Symbol} (h : ∀ i ∈ s, (p i).IsRegular) : (⨆ i ∈ s, p i).IsRegular := by generalize h_n : s.ncard = n induction n generalizing s case zero => have ...
517
leanexplore_declaration
leanexplore:386733
leanexplore_sqlite
leanexplore_declarations
/-- The intersection of any finite number of ω-regular languages is ω-regular. -/ @[simp] theorem IsRegular.iInf {I : Type*} [Finite I] {s : Set I} {p : I → ωLanguage Symbol} (h : ∀ i ∈ s, (p i).IsRegular) : (⨅ i ∈ s, p i).IsRegular := by generalize h_n : s.ncard = n induction n generalizing s case zero => ...
475
leanexplore_declaration
leanexplore:386734
leanexplore_sqlite
leanexplore_declarations
/-- The concatenation of a regular language and an ω-regular language is ω-regular. -/ @[simp] theorem IsRegular.hmul {l : Language Symbol} {p : ωLanguage Symbol} (h1 : l.IsRegular) (h2 : p.IsRegular) : (l * p).IsRegular := by obtain ⟨State1, h_fin1, ⟨na1, acc1⟩, rfl⟩ := Language.IsRegular.iff_nfa.mp h1 obtain ...
345
leanexplore_declaration
leanexplore:386735
leanexplore_sqlite
leanexplore_declarations
/-- The ω-power of a regular language is an ω-regular language. -/ @[simp] theorem IsRegular.omegaPow [Inhabited Symbol] {l : Language Symbol} (h : l.IsRegular) : (l^ω).IsRegular := by obtain ⟨State, h_fin, na, rfl⟩ := Language.IsRegular.iff_nfa.mp h use Unit ⊕ State, inferInstance, ⟨na.loop, {inl ()}⟩ exact ...
1,131
leanexplore_declaration
leanexplore:386736
leanexplore_sqlite
leanexplore_declarations
/-- An ω-language is regular iff it is the finite union of ω-languages of the form `L * M^ω`, where all `L`s and `M`s are regular languages. -/ theorem IsRegular.eq_fin_iSup_hmul_omegaPow [Inhabited Symbol] (p : ωLanguage Symbol) : p.IsRegular ↔ ∃ n : ℕ, ∃ l m : Fin n → Language Symbol, (∀ i, (l i).IsRegular ...
389
leanexplore_declaration
leanexplore:386737
leanexplore_sqlite
leanexplore_declarations
/-- If an ω-language has a finite saturating cover made of ω-regular languages, then it is an ω-regular language. -/ theorem IsRegular.fin_cover_saturates {I : Type*} [Finite I] {p : I → ωLanguage Symbol} {q : ωLanguage Symbol} (hs : Saturates p q) (hc : ⨆ i, p i = ⊤) (hr : ∀ i, (p i).IsRegular) : q.IsRegular :...
401
leanexplore_declaration
leanexplore:386738
leanexplore_sqlite
leanexplore_declarations
/-- If an ω-language has a finite saturating cover made of ω-regular languages, then its complement is an ω-regular language. -/ theorem IsRegular.fin_cover_saturates_compl {I : Type*} [Finite I] {p : I → ωLanguage Symbol} {q : ωLanguage Symbol} (hs : Saturates p q) (hc : ⨆ i, p i = ⊤) (hr : ∀ i, (p i).IsRegula...
596
leanexplore_declaration
leanexplore:386739
leanexplore_sqlite
leanexplore_declarations
/-- The complementation of an ω-regular language is ω-regular. -/ @[simp] theorem IsRegular.compl {Symbol : Type} [Inhabited Symbol] {p : ωLanguage Symbol} (h : p.IsRegular) : (pᶜ).IsRegular := by obtain ⟨State, h_fin, na, rfl⟩ := h have : Finite (Quotient na.BuchiCongruence.eq) := buchiCongruence_fin_index h...
629
leanexplore_declaration
leanexplore:386740
leanexplore_sqlite
leanexplore_declarations
/-- A characterization of `Language.IsRegular` in terms of `DA`. This is the only theorem in Cslib in which Mathlib's definition of `Language.IsRegular` is used. -/ theorem IsRegular.iff_dfa {l : Language Symbol} : l.IsRegular ↔ ∃ State : Type, ∃ _ : Finite State, ∃ dfa : DA.FinAcc State Symbol, language dfa ...
444
leanexplore_declaration
leanexplore:386741
leanexplore_sqlite
leanexplore_declarations
/-- A characterization of Language.IsRegular in terms of NA. -/ theorem IsRegular.iff_nfa {l : Language Symbol} : l.IsRegular ↔ ∃ State : Type, ∃ _ : Finite State, ∃ nfa : NA.FinAcc State Symbol, language nfa = l := by rw [IsRegular.iff_dfa]; constructor · rintro ⟨State, h_fin, ⟨da, acc⟩, rfl⟩ use Sta...
411
leanexplore_declaration
leanexplore:386742
leanexplore_sqlite
leanexplore_declarations
/-- The complementation of a regular language is regular. -/ theorem IsRegular.compl {l : Language Symbol} (h : l.IsRegular) : (lᶜ).IsRegular := by rw [IsRegular.iff_dfa] at h ⊢ obtain ⟨State, _, ⟨da, acc⟩, rfl⟩ := h use State, inferInstance, ⟨da, accᶜ⟩ #adaptation_note /-- A grind regression found moving to ...
380
leanexplore_declaration
leanexplore:386743
leanexplore_sqlite
leanexplore_declarations
/-- The empty language is regular. -/ @[simp] theorem IsRegular.zero : (0 : Language Symbol).IsRegular := by rw [IsRegular.iff_dfa] let flts := FLTS.mk (fun () (_ : Symbol) ↦ ()) use Unit, inferInstance, ⟨DA.mk flts (), ∅⟩ #adaptation_note /-- A grind regression found moving to nightly-2026-03-31 (changes fro...
512
leanexplore_declaration
leanexplore:386744
leanexplore_sqlite
leanexplore_declarations
/-- The language containing only the empty word is regular. -/ @[simp] theorem IsRegular.one : (1 : Language Symbol).IsRegular := by rw [IsRegular.iff_dfa] let flts := FLTS.mk (fun (_ : Fin 2) (_ : Symbol) ↦ 1) use Fin 2, inferInstance, ⟨DA.mk flts 0, {0}⟩ ext; constructor #adaptation_note /-- A grind regre...
220
leanexplore_declaration
leanexplore:386745
leanexplore_sqlite
leanexplore_declarations
/-- The language of all finite words is regular. -/ @[simp] theorem IsRegular.top : (⊤ : Language Symbol).IsRegular := by have : (⊥ᶜ : Language Symbol).IsRegular := IsRegular.compl <| IsRegular.zero rwa [← compl_bot]
555
leanexplore_declaration
leanexplore:386746
leanexplore_sqlite
leanexplore_declarations
/-- The intersection of two regular languages is regular. -/ @[simp] theorem IsRegular.inf {l1 l2 : Language Symbol} (h1 : l1.IsRegular) (h2 : l2.IsRegular) : (l1 ⊓ l2).IsRegular := by rw [IsRegular.iff_dfa] at h1 h2 ⊢ obtain ⟨State1, h_fin1, ⟨da1, acc1⟩, rfl⟩ := h1 obtain ⟨State2, h_fin1, ⟨da2, acc2⟩, rfl⟩ :...
548
leanexplore_declaration
leanexplore:386747
leanexplore_sqlite
leanexplore_declarations
/-- The union of two regular languages is regular. -/ @[simp] theorem IsRegular.add {l1 l2 : Language Symbol} (h1 : l1.IsRegular) (h2 : l2.IsRegular) : (l1 + l2).IsRegular := by rw [IsRegular.iff_dfa] at h1 h2 ⊢ obtain ⟨State1, h_fin1, ⟨da1, acc1⟩, rfl⟩ := h1 obtain ⟨State2, h_fin1, ⟨da2, acc2⟩, rfl⟩ := h2 ...
484
leanexplore_declaration
leanexplore:386748
leanexplore_sqlite
leanexplore_declarations
/-- The intersection of any finite number of regular languages is regular. -/ @[simp] theorem IsRegular.iInf {I : Type*} [Finite I] {s : Set I} {l : I → Language Symbol} (h : ∀ i ∈ s, (l i).IsRegular) : (⨅ i ∈ s, l i).IsRegular := by generalize h_n : s.ncard = n induction n generalizing s case zero => simp_al...
603
leanexplore_declaration
leanexplore:386749
leanexplore_sqlite
leanexplore_declarations
/-- The union of any finite number of regular languages is regular. -/ @[simp] theorem IsRegular.iSup {I : Type*} [Finite I] {s : Set I} {l : I → Language Symbol} (h : ∀ i ∈ s, (l i).IsRegular) : (⨆ i ∈ s, l i).IsRegular := by generalize h_n : s.ncard = n induction n generalizing s case zero => obtain ⟨rf...
471
leanexplore_declaration
leanexplore:386750
leanexplore_sqlite
leanexplore_declarations
/-- The concatenation of two regular languages is regular. -/ @[simp] theorem IsRegular.mul [Inhabited Symbol] {l1 l2 : Language Symbol} (h1 : l1.IsRegular) (h2 : l2.IsRegular) : (l1 * l2).IsRegular := by rw [IsRegular.iff_nfa] at h1 h2 ⊢ obtain ⟨State1, h_fin1, nfa1, rfl⟩ := h1 obtain ⟨State2, h_fin1, nfa2, ...
379
leanexplore_declaration
leanexplore:386751
leanexplore_sqlite
leanexplore_declarations
/-- The Kleene star of a regular language is regular. -/ @[simp] theorem IsRegular.kstar [Inhabited Symbol] {l : Language Symbol} (h : l.IsRegular) : (l∗).IsRegular := by by_cases h_l : l = 0 · simp [h_l] · rw [IsRegular.iff_nfa] at h ⊢ obtain ⟨State, h_fin, nfa, rfl⟩ := h use Unit ⊕ (State ⊕ Unit), i...
377
leanexplore_declaration
leanexplore:386752
leanexplore_sqlite
leanexplore_declarations
/-- If a right congruence is of finite index, then each of its equivalence classes is regular. -/ @[simp] theorem IsRegular.congr_fin_index {Symbol : Type} [c : RightCongruence Symbol] [Finite (Quotient c.eq)] (a : Quotient c.eq) : (eqvCls a).IsRegular := by rw [IsRegular.iff_dfa] use Quotient c.eq, inferIn...
390
leanexplore_declaration
leanexplore:386753
leanexplore_sqlite
leanexplore_declarations
/-- A Turing machine "statement" is just a `Option`al command to move left or right, and write a symbol (i.e. an `Option Symbol`, where `none` is the blank symbol) on the `BiTape` -/ structure Stmt (Symbol : Type) where /-- The symbol to write at the current head position -/ symbol : Option Symbol /-- The directi...
582
leanexplore_declaration
leanexplore:386756
leanexplore_sqlite
leanexplore_declarations
/-- A single-tape Turing machine over the alphabet of `Option Symbol` (where `none` is the blank `BiTape` symbol). -/ structure SingleTapeTM Symbol [Inhabited Symbol] [Fintype Symbol] where /-- type of state labels -/ (State : Type) /-- finiteness of the state type -/ [stateFintype : Fintype State] /-- Initia...
40
leanexplore_declaration
leanexplore:386757
leanexplore_sqlite
leanexplore_declarations
instance : Inhabited tm.State := ⟨tm.q₀⟩
46
leanexplore_declaration
leanexplore:386758
leanexplore_sqlite
leanexplore_declarations
instance : Fintype tm.State := tm.stateFintype
65
leanexplore_declaration
leanexplore:386759
leanexplore_sqlite
leanexplore_declarations
instance inhabitedStmt : Inhabited (Stmt Symbol) := inferInstance
344
leanexplore_declaration
leanexplore:386760
leanexplore_sqlite
leanexplore_declarations
/-- The configurations of a Turing machine consist of: an `Option`al state (or none for the halting state), and a `BiTape` representing the tape contents. -/ structure Cfg : Type where /-- the state of the TM (or none for the halting state) -/ state : Option tm.State /-- the BiTape contents -/ BiTape : BiTape S...
493
leanexplore_declaration
leanexplore:386763
leanexplore_sqlite
leanexplore_declarations
/-- The step function corresponding to a `SingleTapeTM`. -/ @[simp] def step : tm.Cfg → Option tm.Cfg | ⟨none, _⟩ => -- If in the halting state, there is no next configuration none | ⟨some q', t⟩ => -- If in state q', perform look up in the transition function match tm.tr q' t.head with -- and e...
338
leanexplore_declaration
leanexplore:386764
leanexplore_sqlite
leanexplore_declarations
/-- The initial configuration corresponding to a list in the input alphabet. Note that the entries of the tape constructed by `BiTape.mk₁` are all `some` values. This is to ensure that distinct lists map to distinct initial configurations. -/ def initCfg (tm : SingleTapeTM Symbol) (s : List Symbol) : tm.Cfg := ⟨some tm...
240
leanexplore_declaration
leanexplore:386765
leanexplore_sqlite
leanexplore_declarations
/-- The final configuration corresponding to a list in the output alphabet. (We demand that the head halts at the leftmost position of the output.) -/ def haltCfg (tm : SingleTapeTM Symbol) (s : List Symbol) : tm.Cfg := ⟨none, BiTape.mk₁ s⟩
161
leanexplore_declaration
leanexplore:386766
leanexplore_sqlite
leanexplore_declarations
/-- The space used by a configuration is the space used by its tape. -/ def Cfg.space_used (tm : SingleTapeTM Symbol) (cfg : tm.Cfg) : ℕ := cfg.BiTape.space_used
167
leanexplore_declaration
leanexplore:386767
leanexplore_sqlite
leanexplore_declarations
@[scoped grind =] lemma Cfg.space_used_initCfg (tm : SingleTapeTM Symbol) (s : List Symbol) : (tm.initCfg s).space_used = max 1 s.length := BiTape.space_used_mk₁ s
167
leanexplore_declaration
leanexplore:386768
leanexplore_sqlite
leanexplore_declarations
@[scoped grind =] lemma Cfg.space_used_haltCfg (tm : SingleTapeTM Symbol) (s : List Symbol) : (tm.haltCfg s).space_used = max 1 s.length := BiTape.space_used_mk₁ s
592
leanexplore_declaration
leanexplore:386769
leanexplore_sqlite
leanexplore_declarations
lemma Cfg.space_used_step {tm : SingleTapeTM Symbol} (cfg cfg' : tm.Cfg) (hstep : tm.step cfg = some cfg') : cfg'.space_used ≤ cfg.space_used + 1 := by obtain ⟨_ | q, tape⟩ := cfg · simp [step] at hstep · simp only [step] at hstep generalize hM : tm.tr q tape.head = result at hstep obtain ⟨⟨wr, dir⟩, ...
291
leanexplore_declaration
leanexplore:386770
leanexplore_sqlite
leanexplore_declarations
/-- The `TransitionRelation` corresponding to a `SingleTapeTM Symbol` is defined by the `step` function, which maps a configuration to its next configuration, if it exists. -/ @[scoped grind =] def TransitionRelation (tm : SingleTapeTM Symbol) (c₁ c₂ : tm.Cfg) : Prop := tm.step c₁ = some c₂
190
leanexplore_declaration
leanexplore:386771
leanexplore_sqlite
leanexplore_declarations
/-- A proof of `tm` outputting `l'` on input `l`. -/ def Outputs (tm : SingleTapeTM Symbol) (l l' : List Symbol) : Prop := ReflTransGen tm.TransitionRelation (initCfg tm l) (haltCfg tm l')
230
leanexplore_declaration
leanexplore:386772
leanexplore_sqlite
leanexplore_declarations
/-- A proof of `tm` outputting `l'` on input `l` in at most `m` steps. -/ def OutputsWithinTime (tm : SingleTapeTM Symbol) (l l' : List Symbol) (m : ℕ) := RelatesWithinSteps tm.TransitionRelation (initCfg tm l) (haltCfg tm l') m
722
leanexplore_declaration
leanexplore:386773
leanexplore_sqlite
leanexplore_declarations
/-- This lemma bounds the size blow-up of the output of a Turing machine. It states that the increase in length of the output over the input is bounded by the runtime. This is important for guaranteeing that composition of polynomial time Turing machines remains polynomial time, as the input to the second machine is bo...
156
leanexplore_declaration
leanexplore:386774
leanexplore_sqlite
leanexplore_declarations
/-- A Turing machine computing the identity. -/ def idComputer : SingleTapeTM Symbol where State := PUnit q₀ := PUnit.unit tr _ b := ⟨⟨b, none⟩, none⟩
1,534
leanexplore_declaration
leanexplore:386775
leanexplore_sqlite
leanexplore_declarations
/-- A Turing machine computing the composition of two other Turing machines. If f and g are computed by Turing machines `tm1` and `tm2` then we can construct a Turing machine which computes g ∘ f by first running `tm1` and then, when `tm1` halts, transitioning to the start state of `tm2` and running `tm2`. -/ def comp...
76
leanexplore_declaration
leanexplore:386776
leanexplore_sqlite
leanexplore_declarations
lemma compComputer_q₀_eq : (compComputer tm1 tm2).q₀ = Sum.inl tm1.q₀ := rfl
449
leanexplore_declaration
leanexplore:386777
leanexplore_sqlite
leanexplore_declarations
/-- A Turing machine + a time function + a proof it outputs `f` in at most `time(input.length)` steps. -/ structure TimeComputable (f : List Symbol → List Symbol) where /-- the underlying bundled SingleTapeTM -/ tm : SingleTapeTM Symbol /-- a bound on runtime -/ time_bound : ℕ → ℕ /-- proof this machine outpu...
234
leanexplore_declaration
leanexplore:386778
leanexplore_sqlite
leanexplore_declarations
/-- The identity map on Symbol is computable in constant time. -/ def TimeComputable.id : TimeComputable (Symbol := Symbol) id where tm := idComputer time_bound _ := 1 outputsFunInTime _ := ⟨1, le_rfl, RelatesInSteps.single rfl⟩
2,564
leanexplore_declaration
leanexplore:386779
leanexplore_sqlite
leanexplore_declarations
/-- Time bounds for `compComputer`. The `compComputer` of two machines which have time bounds is bounded by * The time taken by the first machine on the input size * added to the time taken by the second machine on the output size of the first machine (which is itself bounded by the time taken by the first machine)...
389
leanexplore_declaration
leanexplore:386780
leanexplore_sqlite
leanexplore_declarations
/-- A Turing machine + a polynomial time function + a proof it outputs `f` in at most `time(input.length)` steps. -/ structure PolyTimeComputable (f : List Symbol → List Symbol) extends TimeComputable f where /-- a polynomial time bound -/ poly : Polynomial ℕ /-- proof that this machine outputs `f` in at most `ti...
256
leanexplore_declaration
leanexplore:386781
leanexplore_sqlite
leanexplore_declarations
/-- A proof that the identity map on Symbol is computable in polytime. -/ noncomputable def PolyTimeComputable.id : PolyTimeComputable (Symbol := Symbol) id where toTimeComputable := TimeComputable.id poly := 1 bounds _ := by simp [TimeComputable.id]
665
leanexplore_declaration
leanexplore:386782
leanexplore_sqlite
leanexplore_declarations
/-- A proof that the composition of two polytime computable functions is polytime computable. -/ noncomputable def PolyTimeComputable.comp {f g : List Symbol → List Symbol} (hf : PolyTimeComputable f) (hg : PolyTimeComputable g) (h_mono : Monotone hg.time_bound) : PolyTimeComputable (g ∘ f) where toTimeCo...
149
leanexplore_declaration
leanexplore:386783
leanexplore_sqlite
leanexplore_declarations
@[simp, scoped grind =] theorem write_read_self (σ : Regs) (n v : ℕ) : (σ.write n v).read n = v := by simp only [write, read, Function.update_self]
178
leanexplore_declaration
leanexplore:386784
leanexplore_sqlite
leanexplore_declarations
@[simp, scoped grind =] theorem write_read_of_ne (σ : Regs) (m n v : ℕ) (h : m ≠ n) : (σ.write n v).read m = σ.read m := by simp only [write, read, Function.update_of_ne h]
98
leanexplore_declaration
leanexplore:386785
leanexplore_sqlite
leanexplore_declarations
@[simp] theorem isHalted_iff (s : State) (p : Program) : s.isHalted p ↔ p.length ≤ s.pc := Iff.rfl
250
leanexplore_declaration
leanexplore:386786
leanexplore_sqlite
leanexplore_declarations
/-- Extensionality for State: two states are equal iff their components are equal. -/ @[ext] theorem ext {s₁ s₂ : State} (hpc : s₁.pc = s₂.pc) (hregs : s₁.regs = s₂.regs) : s₁ = s₂ := by cases s₁; cases s₂; simp only at hpc hregs; simp [hpc, hregs]
100
leanexplore_declaration
leanexplore:386787
leanexplore_sqlite
leanexplore_declarations
@[ext] theorem ext {s₁ s₂ : State} (hpc : s₁.pc = s₂.pc) (hregs : s₁.regs = s₂.regs) : s₁ = s₂ := by
105
leanexplore_declaration
leanexplore:386788
leanexplore_sqlite
leanexplore_declarations
/-- An instruction is a jump instruction. -/ def IsJump : Instr → Prop | J _ _ _ => True | _ => False
111
leanexplore_declaration
leanexplore:386789
leanexplore_sqlite
leanexplore_declarations
instance (instr : Instr) : Decidable instr.IsJump := by cases instr <;> simp only [IsJump] <;> infer_instance
98
leanexplore_declaration
leanexplore:386790
leanexplore_sqlite
leanexplore_declarations
/-- Z instruction is not a jump. -/ @[simp] theorem Z_nonJump (n : ℕ) : ¬(Z n).IsJump := not_false
98
leanexplore_declaration
leanexplore:386791
leanexplore_sqlite
leanexplore_declarations
/-- S instruction is not a jump. -/ @[simp] theorem S_nonJump (n : ℕ) : ¬(S n).IsJump := not_false
102
leanexplore_declaration
leanexplore:386792
leanexplore_sqlite
leanexplore_declarations
/-- T instruction is not a jump. -/ @[simp] theorem T_nonJump (m n : ℕ) : ¬(T m n).IsJump := not_false
98
leanexplore_declaration
leanexplore:386793
leanexplore_sqlite
leanexplore_declarations
/-- J instruction is a jump. -/ @[simp] theorem J_IsJump (m n q : ℕ) : (J m n q).IsJump := trivial
268
leanexplore_declaration
leanexplore:386794
leanexplore_sqlite
leanexplore_declarations
/-- shiftJumps is identity for non-jumping instructions. -/ theorem shiftJumps_of_nonJump {instr : Instr} (h : ¬instr.IsJump) (offset : ℕ) : instr.shiftJumps offset = instr := by cases instr with | Z _ | S _ | T _ _ => rfl | J _ _ _ => exact absurd trivial h
192
leanexplore_declaration
leanexplore:386795
leanexplore_sqlite
leanexplore_declarations
/-- An instruction's jump target is bounded by a given length. Non-jump instructions trivially satisfy this. -/ def JumpsBoundedBy (len : ℕ) : Instr → Prop | J _ _ q => q ≤ len | _ => True
143
leanexplore_declaration
leanexplore:386796
leanexplore_sqlite
leanexplore_declarations
instance (len : ℕ) (instr : Instr) : Decidable (instr.JumpsBoundedBy len) := by cases instr <;> simp only [JumpsBoundedBy] <;> infer_instance
257
leanexplore_declaration
leanexplore:386797
leanexplore_sqlite
leanexplore_declarations
/-- Non-jumping instructions have bounded jumps for any length. -/ theorem jumpsBoundedBy_of_nonJump {instr : Instr} (h : ¬instr.IsJump) (len : ℕ) : instr.JumpsBoundedBy len := by cases instr with | J _ _ _ => exact absurd trivial h | _ => trivial
269
leanexplore_declaration
leanexplore:386798
leanexplore_sqlite
leanexplore_declarations
/-- JumpsBoundedBy is monotonic: if bounded for len1, then bounded for any len2 ≥ len1. -/ theorem JumpsBoundedBy.mono {instr : Instr} {len1 len2 : ℕ} (h : instr.JumpsBoundedBy len1) (hle : len1 ≤ len2) : instr.JumpsBoundedBy len2 := by grind [JumpsBoundedBy]
342
leanexplore_declaration
leanexplore:386799
leanexplore_sqlite
leanexplore_declarations
/-- shiftJumps preserves bounded jumps with adjusted bound. -/ theorem JumpsBoundedBy.shiftJumps {instr : Instr} {len offset : ℕ} (h : instr.JumpsBoundedBy len) : (instr.shiftJumps offset).JumpsBoundedBy (offset + len) := by cases instr with | J _ _ q => simp only [Instr.shiftJumps, JumpsBoundedBy] at h ⊢; ...
220
leanexplore_declaration
leanexplore:386800
leanexplore_sqlite
leanexplore_declarations
/-- Cap a jump target to be at most `len`. Non-jump instructions are unchanged. -/ @[scoped grind =] def capJump (len : ℕ) : Instr → Instr | Z n => Z n | S n => S n | T m n => T m n | J m n q => J m n (min q len)
70
leanexplore_declaration
leanexplore:386801
leanexplore_sqlite
leanexplore_declarations
@[simp] theorem capJump_Z (len n : ℕ) : (Z n).capJump len = Z n := rfl
70
leanexplore_declaration
leanexplore:386802
leanexplore_sqlite
leanexplore_declarations
@[simp] theorem capJump_S (len n : ℕ) : (S n).capJump len = S n := rfl
76
leanexplore_declaration
leanexplore:386803
leanexplore_sqlite
leanexplore_declarations
@[simp] theorem capJump_T (len m n : ℕ) : (T m n).capJump len = T m n := rfl
96
leanexplore_declaration
leanexplore:386804
leanexplore_sqlite
leanexplore_declarations
@[simp] theorem capJump_J (len m n q : ℕ) : (J m n q).capJump len = J m n (min q len) := rfl
252
leanexplore_declaration
leanexplore:386805
leanexplore_sqlite
leanexplore_declarations
/-- capJump always produces an instruction with bounded jump. -/ theorem JumpsBoundedBy.capJump (len : ℕ) (instr : Instr) : (instr.capJump len).JumpsBoundedBy len := by cases instr with | J _ _ q => exact Nat.min_le_right q len | _ => trivial