Skip to content

Commit e0a40fd

Browse files
ctchouchenson2018
andauthored
feat: add Cslib/Computability/Languages/OmegaLanguage.lean (#92)
This is the first version of OmegaLanguage, which is an analogue of Mathlib.Computability.Language, but for infinite sequences. We now have a more satisfactory definition of omegaPow, which enables more algebraic and much shorter proofs of the harder results (see the "main theorems" section of the main comment in OmegaLanguage.lean) than in: https://github.com/ctchou/AutomataTheory/blob/main/AutomataTheory/Languages/Basic.lean The results proved so far are sufficient for starting the development of the theory of omega-automata. The main TODOs are results about omegaPow and map, which are not needed for now. As part of this work, we added several new definitions and theorems about Language and OmegaSequence.flatten. We also took this opportunity to change some infelicitous theorem names in Flatten.lean and Segment.lean and to use `namespace Nat` to remove the prefix `Nat.` from many places in Segment.lean. --------- Co-authored-by: Chris Henson <[email protected]>
1 parent 8c1748c commit e0a40fd

File tree

6 files changed

+632
-73
lines changed

6 files changed

+632
-73
lines changed

Cslib.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Cslib.Computability.Automata.EpsilonNFAToNFA
66
import Cslib.Computability.Automata.NA
77
import Cslib.Computability.Automata.NFA
88
import Cslib.Computability.Automata.NFAToDFA
9+
import Cslib.Computability.Languages.Language
10+
import Cslib.Computability.Languages.OmegaLanguage
911
import Cslib.Foundations.Control.Monad.Free
1012
import Cslib.Foundations.Control.Monad.Free.Effects
1113
import Cslib.Foundations.Control.Monad.Free.Fold
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
-- This section will be removed once the following PR gets into mathlib:
25+
-- https://github.com/leanprover-community/mathlib4/pull/30913
26+
section from_mathlib4_30913
27+
28+
/-- The subtraction of two languages is their difference. -/
29+
instance : Sub (Language α) where
30+
sub := SDiff.sdiff
31+
32+
theorem sub_def (l m : Language α) : l - m = (l \ m : Set (List α)) :=
33+
rfl
34+
35+
theorem mem_sub (l m : Language α) (x : List α) : x ∈ l - m ↔ x ∈ l ∧ x ∉ m :=
36+
Iff.rfl
37+
38+
instance : OrderedSub (Language α) where
39+
tsub_le_iff_right _ _ _ := sdiff_le_iff'
40+
41+
end from_mathlib4_30913
42+
43+
theorem le_one_iff_eq : l ≤ 1 ↔ l = 0 ∨ l = 1 :=
44+
subset_singleton_iff_eq
45+
46+
@[simp, scoped grind =]
47+
theorem mem_sub_one (x : List α) : x ∈ (l - 1) ↔ x ∈ l ∧ x ≠ [] :=
48+
Iff.rfl
49+
50+
@[simp, scoped grind =]
51+
theorem reverse_sub (l m : Language α) : (l - m).reverse = l.reverse - m.reverse := by
52+
ext x ; simp [mem_sub]
53+
54+
@[scoped grind =]
55+
theorem sub_one_mul : (l - 1) * l = l * l - 1 := by
56+
ext x ; constructor
57+
· rintro ⟨u, h_u, v, h_v, rfl⟩
58+
rw [mem_sub, mem_one] at h_u ⊢
59+
constructor
60+
· refine ⟨u, ?_, v, ?_⟩ <;> grind
61+
· grind [append_eq_nil_iff]
62+
· rintro ⟨⟨u, h_u, v, h_v, rfl⟩, h_x⟩
63+
rcases eq_or_ne u [] with (rfl | h_u')
64+
· refine ⟨v, ?_, [], ?_⟩ <;> grind [mem_sub, mem_one]
65+
· refine ⟨u, ?_, v, ?_⟩ <;> grind
66+
67+
@[scoped grind =]
68+
theorem mul_sub_one : l * (l - 1) = l * l - 1 := by
69+
calc
70+
_ = (l * (l - 1)).reverse.reverse := by rw [reverse_reverse]
71+
_ = ((l.reverse - 1) * l.reverse).reverse := by rw [reverse_mul, reverse_sub, reverse_one]
72+
_ = (l.reverse * l.reverse - 1).reverse := by rw [sub_one_mul]
73+
_ = _ := by rw [reverse_sub, reverse_one, reverse_mul, reverse_reverse]
74+
75+
@[scoped grind =]
76+
theorem kstar_sub_one : l∗ - 1 = (l - 1) * l∗ := by
77+
ext x ; constructor
78+
· rintro ⟨h1, h2⟩
79+
obtain ⟨xl, rfl, h_xl⟩ := kstar_def_nonempty l ▸ h1
80+
have h3 : ¬ xl = [] := by grind [one_def]
81+
obtain ⟨x, xl', h_xl'⟩ := exists_cons_of_ne_nil h3
82+
have := h_xl x
83+
refine ⟨x, ?_, xl'.flatten, ?_, ?_⟩ <;> grind [join_mem_kstar]
84+
· rintro ⟨y, ⟨h_y, h_1⟩, z, h_z, rfl⟩
85+
refine ⟨?_, ?_⟩
86+
· apply (show l * l∗ ≤ l∗ by exact mul_kstar_le_kstar)
87+
exact ⟨y, h_y, z, h_z, rfl⟩
88+
· grind [one_def, append_eq_nil_iff]
89+
90+
end Language

0 commit comments

Comments
 (0)