1- import LogicFormalization.Chapter2.Section1.Arity
2- import Mathlib.Data.Set.Defs
3- import Mathlib.Data.Set.Operations
4- import Mathlib.Logic.Basic
1+ import LogicFormalization.Chapter2.Section3.Elab
52import Mathlib.Algebra.Group.Hom.Defs
63import Mathlib.Data.Set.Image
74
8- universe u v
9-
10- structure Language where
11- /-- The relational symbols. -/
12- ρ: Type u
13- /-- The functional symbols. -/
14- ϝ: Type v
15- [instArityRel: Arity ρ]
16- [instArityFun: Arity ϝ]
17-
18- namespace Language
19-
20- -- TODO: automate basically all this for Gr as well as Ab, O, Ring, etc.
21- namespace Gr
22-
23- inductive ρ
24- deriving Repr, DecidableEq
25-
26- instance : Arity ρ :=
27- ⟨(nomatch ·)⟩
28-
29- inductive ϝ where
30- | one | inv | mul
31- deriving Repr, DecidableEq
32-
33- instance : Arity ϝ where
34- arity
35- | .one => 0
36- | .inv => 1
37- | .mul => 2
38-
39- /-! These instances make it possible to write e.g. `f 0` for
40- `f: Fin (arity Language.Gr.ϝ.inv) → G` (the `0` is a `Fin`). -/
41- instance : NeZero (arity Language.Gr.ϝ.inv) :=
42- ⟨by decide⟩
43-
44- instance : NeZero (arity Language.Gr.ϝ.mul) :=
45- ⟨by decide⟩
46-
47- end Gr
48-
49- @[reducible]
50- def Gr := Language.mk Gr.ρ Gr.ϝ
51-
52- end Language
53-
54- instance (L: Language): Arity L.ρ := L.instArityRel
55- instance (L: Language): Arity L.ϝ := L.instArityFun
56-
57- universe w
58-
59- structure Structure (L: Language) (A: Type u) [Nonempty A] where
60- /-- The interpretation `R^𝒜` of the relational symbol `R` in `𝒜`. -/
61- interpRel: (R: L.ρ) → Set (Fin (arity R) → A)
62- /-- The interpretation `F^𝒜` of the functional symbol `F` in `𝒜`.
63- See also `interpConst`. -/
64- interpFun: (F: L.ϝ) → (Fin (arity F) → A) → A
5+ universe u v w
656
667namespace Structure
67- variable {L: Language}
68- variable {A: Type u} [Nonempty A] {B: Type v} [Nonempty B]
698
70- @[inherit_doc]
71- scoped notation :max R "^" 𝒜 => Structure.interpRel 𝒜 R
9+ section
7210
73- @[inherit_doc]
74- scoped notation :max F "^" 𝒜 => Structure.interpFun 𝒜 F
11+ variable (A G: Type *) [Nonempty A] [Nonempty G]
12+ def Gr [Mul G] [Inv G] [One G] : Structure Language.Gr G where
13+ interpRel := nofun
14+ interpFun
15+ | .one, _ => 1
16+ | .inv, f => (f 0 )⁻¹
17+ | .mul, f => f 0 * f 1
7518
76- /-- We identify the interpretation `h^𝒜` for
77- constant symbol `c`, `h: arity c = 0`, with the value in `A`. -/
78- def interpConst (𝒜: Structure L A) {c: L.ϝ} (h: arity c = 0 ) :=
79- 𝒜.interpFun c fun f => (h ▸ f).elim0
19+ def Ab [Nonempty A] [Add A] [Neg A] [Zero A] : Structure Language.Ab A where
20+ interpRel := nofun
21+ interpFun
22+ | .zero, _ => 0
23+ | .add, f => f 0 + f 1
24+ | .neg, f => -(f 0 )
8025
81- @[inherit_doc]
82- scoped notation :max h "^" 𝒜 => Structure.interpConst 𝒜 h
26+ def O [LT A] : Structure Language.O A where
27+ interpRel | .lt, f => f 0 < f 1
28+ interpFun := nofun
8329
84- def Gr {G: Type *} [Nonempty G ] [Group G] : Structure Language.Gr G where
85- interpRel := ( nomatch ·)
30+ def OAb [LT A] [Zero A ] [Neg A] [Add A] : Structure Language.OAb A where
31+ interpRel | .lt, f => f 0 < f 1
8632 interpFun
87- | .one , _ => 1
88- | .inv, f => (f 0 )⁻¹
89- | .mul, f => ( f 0 ) * ( f 1 )
33+ | .zero , _ => 0
34+ | .neg, f => - (f 0 )
35+ | .add, f => f 0 + f 1
9036
91- section Substructure
37+ def Rig [Zero A] [One A] [Add A] [Mul A] : Structure Language.Rig A where
38+ interpRel := nofun
39+ interpFun
40+ | .zero, _ => 0
41+ | .one, _ => 1
42+ | .add, f => f 0 + f 1
43+ | .mul, f => f 0 * f 1
9244
93- /-- `Substructure A ℬ h` is the substructure in `ℬ` with underlying set `A`. -/
94- @[reducible, simp]
95- def Substructure (A: Set B) [Nonempty A] (ℬ: Structure L B)
96- (h: ∀ F (a: Fin (arity F) → A), interpFun ℬ F (a ↑·) ∈ A) : Structure L A where
97- interpRel R := { a | (R^ℬ) (a ↑·) }
98- interpFun F a := ⟨(F^ℬ) (a ↑·), h ..⟩
45+ def Ring [Zero A] [One A] [Neg A] [Add A] [Mul A] : Structure Language.Ring A where
46+ interpRel := nofun
47+ interpFun
48+ | .zero, _ => 0
49+ | .one, _ => 1
50+ | .neg, f => -(f 0 )
51+ | .add, f => f 0 + f 1
52+ | .mul, f => f 0 * f 1
9953
100- variable {A: Set B} [Nonempty A]
101- /-- `IsSubstructure 𝒜 ℬ`, written `A ⊆ B`, means `A` is a substructure of `B`. -/
102- structure IsSubstructure (𝒜: Structure L A) (ℬ: Structure L B): Prop where
103- h₁: ∀ F (a: Fin (arity F) → A), interpFun ℬ F (a ↑·) ∈ A
104- h₂: 𝒜 = Substructure A ℬ h₁
54+ end
10555
106- @[inherit_doc]
107- scoped infix :50 " ⊆ " => IsSubstructure
56+ variable {L: Language} {B: Type v} [Nonempty B]
10857
10958lemma substructure_is_substructure {A: Set B} [Nonempty A] {ℬ: Structure L B}
11059 {h: ∀ F (a: Fin (arity F) → A), interpFun ℬ F (a ↑·) ∈ A}: Substructure A ℬ h ⊆ ℬ :=
11160 ⟨h, rfl⟩
11261
113- end Substructure
114-
11562section Hom
11663
117- variable {A: Type u} [Nonempty A] {B: Type v} [Nonempty B]
64+ variable {A: Type u} [Nonempty A]
11865variable (𝒜: Structure L A) (ℬ: Structure L B) (h: A → B)
11966
120- structure Hom where
121- hRel: ∀ R a, a ∈ 𝒜.interpRel R → h ∘ a ∈ ℬ.interpRel R
122- hFun: ∀ F a, h ((𝒜.interpFun F) a) = (ℬ.interpFun F) (h ∘ a)
123-
124- structure StrongHom where
125- hRel: ∀ R a, a ∈ 𝒜.interpRel R ↔ h ∘ a ∈ ℬ.interpRel R
126- hFun: ∀ F a, h ((𝒜.interpFun F) a) = (ℬ.interpFun F) (h ∘ a)
127-
12867lemma StrongHom.mk' (hom: Hom 𝒜 ℬ h) (hh: ∀ R a, h ∘ a ∈ ℬ.interpRel R → a ∈ 𝒜.interpRel R):
12968 StrongHom 𝒜 ℬ h where
13069 hRel R a := ⟨hom.hRel R a, hh R a⟩
@@ -133,14 +72,6 @@ lemma StrongHom.mk' (hom: Hom 𝒜 ℬ h) (hh: ∀ R a, h ∘ a ∈ ℬ.interpRe
13372lemma StrongHom.toHom : StrongHom 𝒜 ℬ h → Hom 𝒜 ℬ h
13473| {hRel, hFun} => ⟨fun R a => (hRel R a).mp, hFun⟩
13574
136- structure Emb extends StrongHom 𝒜 ℬ h where
137- inj: Function.Injective h
138-
139- structure Iso extends StrongHom 𝒜 ℬ h where
140- bij: Function.Bijective h
141-
142- abbrev Auto h := Iso 𝒜 𝒜 h
143-
14475lemma emb_inclusion_map {A: Set B} [Nonempty ↑A] {𝒜: Structure L A} {ℬ: Structure L B}
14576 (h: 𝒜 ⊆ ℬ): Emb 𝒜 ℬ (fun a => a) :=
14677 have ⟨hR, hF⟩ := Structure.mk.inj h.h₂
@@ -257,14 +188,14 @@ noncomputable instance Aut: Group {i: A → A // Auto 𝒜 i} where
257188-- TODO: examples
258189
259190-- Somewhat clunky since `MonoidHom` is a `Type`
260- lemma group_hom_iff [Group A] [Group B] {h: A → B}: (∃ h': A →* B, ↑h' = h) ↔ Hom Gr Gr h := by
191+ lemma group_hom_iff [Group A] [Group B] {h: A → B}: (∃ h': A →* B, ↑h' = h) ↔ Hom ( Gr A) (Gr B) h := by
261192 constructor
262193 · intro ⟨⟨⟨h', h₁⟩, h₂⟩, hcoe⟩
263194 replace hcoe: h' = h := hcoe
264195 subst h'
265196 replace h₂: ∀ (x y : A), h (x * y) = h x * h y := h₂
266197 constructor
267- · exact ( nomatch ·)
198+ · nofun
268199 · rintro (_|_) <;> intro as
269200 · simpa only [Gr, forall_const]
270201 · simp only [Gr, Function.comp_apply]
0 commit comments