|
| 1 | +/- |
| 2 | +Copyright (c) 2025 Ching-Tsun Chou. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Ching-Tsun Chou |
| 5 | +-/ |
| 6 | + |
| 7 | +import Mathlib.Computability.Language |
| 8 | +import Mathlib.Tactic |
| 9 | + |
| 10 | +/-! |
| 11 | +# Language (additional definitions and theorems) |
| 12 | +
|
| 13 | +This file contains additional definitions and theorems about `Language` |
| 14 | +as defined and developed in `Mathlib.Computability.Language`. |
| 15 | +-/ |
| 16 | + |
| 17 | +namespace Language |
| 18 | + |
| 19 | +open Set List |
| 20 | +open scoped Computability |
| 21 | + |
| 22 | +variable {α : Type _} {l : Language α} |
| 23 | + |
| 24 | +/-- A language is trivial iff it contains at most the empty list `[]`. -/ |
| 25 | +def Trivial (l : Language α) := l \ 1 = 0 |
| 26 | + |
| 27 | +@[simp] |
| 28 | +theorem zero_trivial : (0 : Language α).Trivial := |
| 29 | + empty_diff _ |
| 30 | + |
| 31 | +@[simp] |
| 32 | +theorem one_trivial : (1 : Language α).Trivial := |
| 33 | + diff_self |
| 34 | + |
| 35 | +theorem trivial_eq_zero_or_one |
| 36 | + (h : l.Trivial) : l = 0 ∨ l = 1 := |
| 37 | + subset_singleton_iff_eq.mp <| diff_eq_empty.mp h |
| 38 | + |
| 39 | +theorem trivial_iff : |
| 40 | + l.Trivial ↔ l = 0 ∨ l = 1 := by |
| 41 | + constructor |
| 42 | + · intro h |
| 43 | + exact trivial_eq_zero_or_one h |
| 44 | + · rintro (rfl | rfl) |
| 45 | + · exact zero_trivial |
| 46 | + · exact one_trivial |
| 47 | + |
| 48 | +@[simp, scoped grind =] |
| 49 | +theorem mem_sdiff_one (x : List α) : |
| 50 | + x ∈ (l \ 1) ↔ x ∈ l ∧ x ≠ [] := |
| 51 | + Iff.rfl |
| 52 | + |
| 53 | +@[simp] |
| 54 | +theorem one_sdiff_one : |
| 55 | + 1 \ 1 = (0 : Language α) := by |
| 56 | + ext x |
| 57 | + simp only [sdiff_self, notMem_zero, iff_false] |
| 58 | + exact id |
| 59 | + |
| 60 | +@[simp, scoped grind =] |
| 61 | +theorem sdiff_one_mul : |
| 62 | + (l \ 1) * l = l * (l \ 1) := by |
| 63 | + ext x ; constructor |
| 64 | + · rintro ⟨u, h_u, v, h_v, rfl⟩ |
| 65 | + rcases Classical.em (v = []) with rfl | h |
| 66 | + · refine ⟨[], h_v, u, h_u, by simp⟩ |
| 67 | + · refine ⟨u, by grind, v, ?_, by simp⟩ |
| 68 | + rw [mem_sdiff_one] |
| 69 | + simp_all |
| 70 | + · rintro ⟨u, h_u, v, h_v, rfl⟩ |
| 71 | + rcases Classical.em (u = []) with rfl | h |
| 72 | + · refine ⟨v, h_v, [], h_u, by simp⟩ |
| 73 | + · refine ⟨u, ?_, v, by grind, by simp⟩ |
| 74 | + rw [mem_sdiff_one] |
| 75 | + simp_all |
| 76 | + |
| 77 | +@[simp, scoped grind =] |
| 78 | +theorem kstar_sdiff_one : |
| 79 | + l∗ \ 1 = (l \ 1) * l∗ := by |
| 80 | + ext x ; constructor |
| 81 | + · rintro ⟨h1, h2⟩ |
| 82 | + obtain ⟨xl, rfl, h_xl⟩ := kstar_def_nonempty l ▸ h1 |
| 83 | + have h3 : ¬ xl = [] := by intro h ; simp [h, one_def] at h2 |
| 84 | + obtain ⟨x, xl', h_xl'⟩ := exists_cons_of_ne_nil h3 |
| 85 | + refine ⟨x, ?_, xl'.flatten, ?_, by grind⟩ |
| 86 | + · specialize h_xl x (by grind) |
| 87 | + exact h_xl |
| 88 | + · apply join_mem_kstar |
| 89 | + intro y h_y |
| 90 | + specialize h_xl y (by grind) |
| 91 | + grind |
| 92 | + · rintro ⟨y, ⟨h_y, h_1⟩, z, h_z, rfl⟩ |
| 93 | + refine ⟨?_, ?_⟩ |
| 94 | + · apply (show l * l∗ ≤ l∗ by exact mul_kstar_le_kstar) |
| 95 | + refine ⟨y, h_y, z, h_z, rfl⟩ |
| 96 | + · simp only [one_def, mem_singleton_iff, append_eq_nil_iff] at h_1 ⊢ |
| 97 | + tauto |
| 98 | + |
| 99 | +end Language |
0 commit comments