Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 6bb8f22

Browse files
committed
refactor(model_theory/terms_and_formulas): Improvements to basics of first-order formulas (#12091)
Improves the simp set of lemmas related to `realize_bounded_formula` and `realize_formula`, so that they simplify higher-level definitions directly, and keep bounded formulas and formulas separate. Generalizes relabelling of bounded formulas. Defines `close_with_exists` and `close_with_forall` to quantify bounded formulas into closed formulas. Defines `bd_iff` and `iff`.
1 parent d054fca commit 6bb8f22

File tree

6 files changed

+414
-240
lines changed

6 files changed

+414
-240
lines changed

src/model_theory/basic.lean

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ localized "notation A ` ≃[`:25 L `] ` B := L.equiv A B" in first_order
128128
variables {L M N} {P : Type*} [L.Structure P] {Q : Type*} [L.Structure Q]
129129

130130
instance : has_coe_t L.const M :=
131-
⟨λ c, fun_map c fin.elim0
131+
⟨λ c, fun_map c default
132132

133133
lemma fun_map_eq_coe_const {c : L.const} {x : fin 0 → M} :
134-
fun_map c x = c := congr rfl (funext fin.elim0)
134+
fun_map c x = c := congr rfl (subsingleton.elim _ _)
135135

136136
/-- Given a language with a nonempty type of constants, any structure will be nonempty. This cannot
137137
be a global instance, because `L` becomes a metavariable. -/
@@ -158,7 +158,7 @@ lemma ext_iff {f g : M →[L] N} : f = g ↔ ∀ x, f x = g x :=
158158
φ (fun_map f x) = fun_map f (φ ∘ x) := φ.map_fun' f x
159159

160160
@[simp] lemma map_const (φ : M →[L] N) (c : L.const) : φ c = c :=
161-
(φ.map_fun c fin.elim0).trans (congr rfl (funext fin.elim0))
161+
(φ.map_fun c default).trans fun_map_eq_coe_const
162162

163163
@[simp] lemma map_rel (φ : M →[L] N) {n : ℕ} (r : L.relations n) (x : fin n → M) :
164164
rel_map r x → rel_map r (φ ∘ x) := φ.map_rel' r x
@@ -197,7 +197,7 @@ instance has_coe_to_fun : has_coe_to_fun (M ↪[L] N) (λ _, M → N) := ⟨λ f
197197
φ (fun_map f x) = fun_map f (φ ∘ x) := φ.map_fun' f x
198198

199199
@[simp] lemma map_const (φ : M ↪[L] N) (c : L.const) : φ c = c :=
200-
(φ.map_fun c fin.elim0).trans (congr rfl (funext fin.elim0))
200+
(φ.map_fun c default).trans fun_map_eq_coe_const
201201

202202
@[simp] lemma map_rel (φ : M ↪[L] N) {n : ℕ} (r : L.relations n) (x : fin n → M) :
203203
rel_map r (φ ∘ x) ↔ rel_map r x := φ.map_rel' r x
@@ -300,7 +300,7 @@ lemma symm_apply_apply (f : M ≃[L] N) (a : M) : f.symm (f a) = a := f.to_equiv
300300
φ (fun_map f x) = fun_map f (φ ∘ x) := φ.map_fun' f x
301301

302302
@[simp] lemma map_const (φ : M ≃[L] N) (c : L.const) : φ c = c :=
303-
(φ.map_fun c fin.elim0).trans (congr rfl (funext fin.elim0))
303+
(φ.map_fun c default).trans fun_map_eq_coe_const
304304

305305
@[simp] lemma map_rel (φ : M ≃[L] N) {n : ℕ} (r : L.relations n) (x : fin n → M) :
306306
rel_map r (φ ∘ x) ↔ rel_map r x := φ.map_rel' r x

src/model_theory/definability.lean

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ variables (L) {α : Type} [fintype α]
3636
/-- A subset of a finite Cartesian product of a structure is definable when membership in
3737
the set is given by a first-order formula. -/
3838
structure is_definable (s : set (α → M)) : Prop :=
39-
(exists_formula : ∃ (φ : L.formula α), s = set_of (realize_formula M φ))
39+
(exists_formula : ∃ (φ : L.formula α), s = set_of φ.realize)
4040

4141
variables {L}
4242

@@ -67,17 +67,16 @@ lemma is_definable.union {f g : set (α → M)} (hf : L.is_definable f) (hg : L.
6767
rcases hg.exists_formula with ⟨θ, hθ⟩,
6868
refine ⟨φ ⊔ θ, _⟩,
6969
ext,
70-
simp only [hφ, hθ, set.sup_eq_union, realize_not, realize_bounded_formula,
71-
bounded_formula.has_sup_sup, set.mem_union_eq, set.mem_set_of_eq],
72-
tauto,
70+
rw [hφ, hθ, set.mem_set_of_eq, formula.realize_sup, set.mem_union_eq, set.mem_set_of_eq,
71+
set.mem_set_of_eq],
7372
end
7473

7574
@[simp]
7675
lemma is_definable.compl {s : set (α → M)} (hf : L.is_definable s) :
7776
L.is_definable sᶜ :=
7877
begin
7978
rcases hf.exists_formula with ⟨φ, hφ⟩,
80-
refine ⟨bd_not φ, _⟩,
79+
refine ⟨φ.not, _⟩,
8180
rw hφ,
8281
refl,
8382
end

src/model_theory/direct_limit.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ This file constructs the direct limit of a directed system of first-order embedd
1616
first-order embeddings between the structures indexed by `G`.
1717
-/
1818

19-
2019
universes v w u₁ u₂
2120

2221
open_locale first_order

src/model_theory/elementary_maps.lean

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ variables [L.Structure M] [L.Structure N] [L.Structure P] [L.Structure Q]
3131
structure elementary_embedding :=
3232
(to_fun : M → N)
3333
(map_formula' : ∀{n} (φ : L.formula (fin n)) (x : fin n → M),
34-
realize_formula N φ (to_fun ∘ x) ↔ realize_formula M φ x . obviously)
34+
φ.realize (to_fun ∘ x) ↔ φ.realize x . obviously)
3535

3636
localized "notation A ` ↪ₑ[`:25 L `] ` B := L.elementary_embedding A B" in first_order
3737

@@ -42,14 +42,13 @@ namespace elementary_embedding
4242
instance has_coe_to_fun : has_coe_to_fun (M ↪ₑ[L] N) (λ _, M → N) :=
4343
⟨λ f, f.to_fun⟩
4444

45-
@[simp] lemma map_formula (f : M ↪ₑ[L] N) {α : Type} [fintype α] (φ : L.formula α)
46-
(x : α → M) :
47-
realize_formula N φ (f ∘ x) ↔ realize_formula M φ x :=
45+
@[simp] lemma map_formula (f : M ↪ₑ[L] N) {α : Type} [fintype α] (φ : L.formula α) (x : α → M) :
46+
φ.realize (f ∘ x) ↔ φ.realize x :=
4847
begin
4948
have g := fintype.equiv_fin α,
5049
have h := f.map_formula' (φ.relabel g) (x ∘ g.symm),
51-
rw [realize_formula_relabel, realize_formula_relabel,
52-
function.comp.assoc x g.symm g, g.symm_comp_self, function.comp.right_id] at h,
50+
rw [formula.realize_relabel, formula.realize_relabel, function.comp.assoc x g.symm g,
51+
g.symm_comp_self, function.comp.right_id] at h,
5352
rw [← h, iff_eq_eq],
5453
congr,
5554
ext y,
@@ -59,29 +58,28 @@ end
5958
@[simp] lemma map_fun (φ : M ↪ₑ[L] N) {n : ℕ} (f : L.functions n) (x : fin n → M) :
6059
φ (fun_map f x) = fun_map f (φ ∘ x) :=
6160
begin
62-
have h := φ.map_formula (formula.graph f) (fin.snoc x (fun_map f x)),
63-
rw [realize_graph, fin.comp_snoc, realize_graph] at h,
61+
have h := φ.map_formula (formula.graph f) (fin.cons (fun_map f x) x),
62+
rw [formula.realize_graph, fin.comp_cons, formula.realize_graph] at h,
6463
rw [eq_comm, h]
6564
end
6665

6766
@[simp] lemma map_const (φ : M ↪ₑ[L] N) (c : L.const) : φ c = c :=
68-
(φ.map_fun c fin.elim0).trans (congr rfl (funext fin.elim0))
67+
(φ.map_fun c default).trans fun_map_eq_coe_const
6968

7069
@[simp] lemma map_rel (φ : M ↪ₑ[L] N) {n : ℕ} (r : L.relations n) (x : fin n → M) :
7170
rel_map r (φ ∘ x) ↔ rel_map r x :=
7271
begin
73-
have h := φ.map_formula (bd_rel r (var ∘ sum.inl)) x,
72+
have h := φ.map_formula (r.formula var) x,
7473
exact h
7574
end
7675

7776
@[simp] lemma injective (φ : M ↪ₑ[L] N) :
7877
function.injective φ :=
7978
begin
8079
intros x y,
81-
have h := φ.map_formula (formula.equal (var 0) (var 1) : L.formula (fin 2))
82-
(λ i, if i = 0 then x else y),
83-
rw [realize_equal, realize_equal] at h,
84-
simp only [nat.one_ne_zero, realize_term, fin.one_eq_zero_iff, if_true, eq_self_iff_true,
80+
have h := φ.map_formula ((var 0).equal (var 1) : L.formula (fin 2)) (λ i, if i = 0 then x else y),
81+
rw [formula.realize_equal, formula.realize_equal] at h,
82+
simp only [nat.one_ne_zero, term.realize, fin.one_eq_zero_iff, if_true, eq_self_iff_true,
8583
function.comp_app, if_false] at h,
8684
exact h.1,
8785
end
@@ -158,26 +156,32 @@ def to_elementary_embedding (f : M ≃[L] N) : M ↪ₑ[L] N :=
158156

159157
end equiv
160158

161-
@[simp] lemma realize_term_substructure {α : Type} {S : L.substructure M} (v : α → S)
159+
@[simp] lemma realize_term_substructure {α : Type*} {S : L.substructure M} (v : α → S)
162160
(t : L.term α) :
163-
realize_term (coe ∘ v) t = (↑(realize_term v t) : M) :=
164-
S.subtype.realize_term v t
161+
t.realize (coe ∘ v) = (↑(t.realize v) : M) :=
162+
S.subtype.realize_term t
165163

166-
@[simp] lemma realize_bounded_formula_top {α : Type} {n : ℕ} (v : α → (⊤ : L.substructure M))
167-
(xs : fin n → (⊤ : L.substructure M)) (φ : L.bounded_formula α n) :
168-
realize_bounded_formula (⊤ : L.substructure M) φ v xs ↔
169-
realize_bounded_formula M φ (coe ∘ v) (coe ∘ xs) :=
164+
namespace substructure
165+
166+
@[simp] lemma realize_bounded_formula_top {α : Type*} {n : ℕ} {φ : L.bounded_formula α n}
167+
{v : α → (⊤ : L.substructure M)} {xs : fin n → (⊤ : L.substructure M)} :
168+
φ.realize v xs ↔ φ.realize ((coe : _ → M) ∘ v) (coe ∘ xs) :=
170169
begin
171-
rw ← substructure.top_equiv.realize_bounded_formula v xs φ,
170+
rw ← substructure.top_equiv.realize_bounded_formula φ,
172171
simp,
173172
end
174173

175-
namespace substructure
174+
@[simp] lemma realize_formula_top {α : Type*} {φ : L.formula α} {v : α → (⊤ : L.substructure M)} :
175+
φ.realize v ↔ φ.realize ((coe : (⊤ : L.substructure M) → M) ∘ v) :=
176+
begin
177+
rw ← substructure.top_equiv.realize_formula φ,
178+
simp,
179+
end
176180

177181
/-- A substructure is elementary when every formula applied to a tuple in the subtructure
178182
agrees with its value in the overall structure. -/
179183
def is_elementary (S : L.substructure M) : Prop :=
180-
∀{n} (φ : L.formula (fin n)) (x : fin n → S), realize_formula M φ (coe ∘ x) ↔ realize_formula S φ x
184+
∀{n} (φ : L.formula (fin n)) (x : fin n → S), φ.realize ((coe : _ → M) ∘ x) ↔ φ.realize x
181185

182186
end substructure
183187

@@ -213,11 +217,7 @@ def subtype (S : L.elementary_substructure M) : S ↪ₑ[L] M :=
213217

214218
/-- The substructure `M` of the structure `M` is elementary. -/
215219
instance : has_top (L.elementary_substructure M) :=
216-
⟨⟨⊤, λ n φ x, begin
217-
rw formula at φ,
218-
rw [realize_formula, realize_formula, realize_bounded_formula_top, iff_eq_eq],
219-
exact congr rfl (funext fin_zero_elim),
220-
end⟩⟩
220+
⟨⟨⊤, λ n φ x, substructure.realize_formula_top.symm⟩⟩
221221

222222
instance : inhabited (L.elementary_substructure M) := ⟨⊤⟩
223223

src/model_theory/quotients.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ begin
6262
rw [quotient.fin_choice_eq, quotient.lift_mk],
6363
end
6464

65-
lemma realize_term_quotient_mk {β : Type*} (x : β → M) (t : L.term β) :
66-
realize_term (λ i, ⟦x i⟧) t = ⟦@realize_term _ _ ps.to_structure _ x t⟧ :=
65+
lemma term.realize_quotient_mk {β : Type*} (t : L.term β) (x : β → M) :
66+
t.realize (λ i, ⟦x i⟧) = ⟦@term.realize _ _ ps.to_structure _ x t⟧ :=
6767
begin
68-
induction t with a1 a2 a3 a4 ih a6 a7 a8 a9 a0,
68+
induction t with _ _ _ _ ih,
6969
{ refl },
70-
simp only [ih, fun_map_quotient_mk, realize_term],
70+
{ simp only [ih, fun_map_quotient_mk, term.realize] },
7171
end
7272

7373
end language

0 commit comments

Comments
 (0)