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

Commit 3baad3b

Browse files
feat(model_theory/syntax): Swapping between constants and variables (#14018)
`term.constants_vars_equiv` and `bounded_formula.constants_vars_equiv` send terms/formulas with constants to terms/formulas with extra variables and back. Co-authored-by: Rob Lewis <Rob.y.lewis@gmail.com>
1 parent 8a03229 commit 3baad3b

File tree

5 files changed

+165
-9
lines changed

5 files changed

+165
-9
lines changed

src/model_theory/language_map.lean

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ the continuum hypothesis*][flypitch_itp]
2727
2828
-/
2929

30-
universes u v u' v' w
30+
universes u v u' v' w w'
3131

3232
namespace first_order
3333
namespace language
@@ -179,7 +179,17 @@ class is_expansion_on (M : Type*) [L.Structure M] [L'.Structure M] : Prop :=
179179
(map_on_relation : ∀ {n} (R : L.relations n) (x : fin n → M),
180180
rel_map (ϕ.on_relation R) x = rel_map R x)
181181

182-
attribute [simp] is_expansion_on.map_on_function is_expansion_on.map_on_relation
182+
@[simp] lemma map_on_function {M : Type*}
183+
[L.Structure M] [L'.Structure M] [ϕ.is_expansion_on M]
184+
{n} (f : L.functions n) (x : fin n → M) :
185+
fun_map (ϕ.on_function f) x = fun_map f x :=
186+
is_expansion_on.map_on_function f x
187+
188+
@[simp] lemma map_on_relation {M : Type*}
189+
[L.Structure M] [L'.Structure M] [ϕ.is_expansion_on M]
190+
{n} (R : L.relations n) (x : fin n → M) :
191+
rel_map (ϕ.on_relation R) x = rel_map R x :=
192+
is_expansion_on.map_on_relation R x
183193

184194
instance id_is_expansion_on (M : Type*) [L.Structure M] : is_expansion_on (Lhom.id L) M :=
185195
⟨λ _ _ _, rfl, λ _ _ _, rfl⟩
@@ -211,6 +221,18 @@ instance sum_inr_is_expansion_on (M : Type*)
211221
(Lhom.sum_inr : L' →ᴸ L.sum L').is_expansion_on M :=
212222
⟨λ _ f _, rfl, λ _ R _, rfl⟩
213223

224+
@[simp] lemma fun_map_sum_inl [(L.sum L').Structure M]
225+
[(Lhom.sum_inl : L →ᴸ L.sum L').is_expansion_on M]
226+
{n} {f : L.functions n} {x : fin n → M} :
227+
@fun_map (L.sum L') M _ n (sum.inl f) x = fun_map f x :=
228+
(Lhom.sum_inl : L →ᴸ L.sum L').map_on_function f x
229+
230+
@[simp] lemma fun_map_sum_inr [(L'.sum L).Structure M]
231+
[(Lhom.sum_inr : L →ᴸ L'.sum L).is_expansion_on M]
232+
{n} {f : L.functions n} {x : fin n → M} :
233+
@fun_map (L'.sum L) M _ n (sum.inr f) x = fun_map f x :=
234+
(Lhom.sum_inr : L →ᴸ L'.sum L).map_on_function f x
235+
214236
@[priority 100] instance is_expansion_on_reduct (ϕ : L →ᴸ L') (M : Type*) [L'.Structure M] :
215237
@is_expansion_on L L' ϕ M (ϕ.reduct M) _ :=
216238
begin
@@ -307,15 +329,15 @@ section with_constants
307329
variable (L)
308330

309331
section
310-
variables (α : Type w)
332+
variables (α : Type w')
311333

312334
/-- Extends a language with a constant for each element of a parameter set in `M`. -/
313-
def with_constants : language.{(max u w) v} := L.sum (constants_on α)
335+
def with_constants : language.{(max u w') v} := L.sum (constants_on α)
314336

315337
localized "notation L`[[`:95 α`]]`:90 := L.with_constants α" in first_order
316338

317339
@[simp] lemma card_with_constants :
318-
(L[[α]]).card = cardinal.lift.{w} L.card + cardinal.lift.{max u v} (# α) :=
340+
(L[[α]]).card = cardinal.lift.{w'} L.card + cardinal.lift.{max u v} (# α) :=
319341
by rw [with_constants, card_sum, card_constants_on]
320342

321343
/-- The language map adding constants. -/
@@ -346,6 +368,18 @@ variables (L) (α)
346368

347369
variables {α} {β : Type*}
348370

371+
@[simp] lemma with_constants_fun_map_sum_inl [L[[α]].Structure M]
372+
[(Lhom_with_constants L α).is_expansion_on M]
373+
{n} {f : L.functions n} {x : fin n → M} :
374+
@fun_map (L[[α]]) M _ n (sum.inl f) x = fun_map f x :=
375+
(Lhom_with_constants L α).map_on_function f x
376+
377+
@[simp] lemma with_constants_rel_map_sum_inl [L[[α]].Structure M]
378+
[(Lhom_with_constants L α).is_expansion_on M]
379+
{n} {R : L.relations n} {x : fin n → M} :
380+
@rel_map (L[[α]]) M _ n (sum.inl R) x = rel_map R x :=
381+
(Lhom_with_constants L α).map_on_relation R x
382+
349383
/-- The language map extending the constant set. -/
350384
def Lhom_with_constants_map (f : α → β) : L[[α]] →ᴸ L[[β]] :=
351385
Lhom.sum_map (Lhom.id L) (Lhom.constants_on_map f)
@@ -388,6 +422,13 @@ instance add_constants_expansion {L' : language} [L'.Structure M] (φ : L →ᴸ
388422
(φ.add_constants α).is_expansion_on M :=
389423
Lhom.sum_map_is_expansion_on _ _ M
390424

425+
@[simp] lemma with_constants_fun_map_sum_inr {a : α} {x : fin 0 → M} :
426+
@fun_map (L[[α]]) M _ 0 (sum.inr a : L[[α]].functions 0) x = L.con a :=
427+
begin
428+
rw unique.eq_default x,
429+
exact (Lhom.sum_inr : (constants_on α) →ᴸ L.sum _).map_on_function _ _,
430+
end
431+
391432
variables {α} (A : set M)
392433

393434
@[simp] lemma coe_con {a : A} : ((L.con a) : M) = a := rfl

src/model_theory/order.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ variables [is_ordered L] [L.Structure M]
169169
@[simp] lemma rel_map_le_symb [has_le M] [L.is_ordered_structure M] {a b : M} :
170170
rel_map (le_symb : L.relations 2) ![a, b] ↔ a ≤ b :=
171171
begin
172-
rw [← order_Lhom_le_symb, Lhom.is_expansion_on.map_on_relation],
172+
rw [← order_Lhom_le_symb, Lhom.map_on_relation],
173173
refl,
174174
end
175175

src/model_theory/semantics.lean

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,48 @@ begin
134134
exact congr rfl (funext (λ i, ih i (h i (finset.mem_univ i)))) },
135135
end
136136

137+
@[simp] lemma realize_constants_to_vars [L[[α]].Structure M]
138+
[(Lhom_with_constants L α).is_expansion_on M]
139+
{t : L[[α]].term β} {v : β → M} :
140+
t.constants_to_vars.realize (sum.elim (λ a, ↑(L.con a)) v) = t.realize v :=
141+
begin
142+
induction t with _ n f _ ih,
143+
{ simp },
144+
{ cases n,
145+
{ cases f,
146+
{ simp [ih], },
147+
{ simp only [realize, constants_to_vars, sum.elim_inl, fun_map_eq_coe_constants],
148+
refl } },
149+
{ cases f,
150+
{ simp [ih] },
151+
{ exact is_empty_elim f } } }
152+
end
153+
154+
@[simp] lemma realize_vars_to_constants [L[[α]].Structure M]
155+
[(Lhom_with_constants L α).is_expansion_on M]
156+
{t : L.term (α ⊕ β)} {v : β → M} :
157+
t.vars_to_constants.realize v = t.realize (sum.elim (λ a, ↑(L.con a)) v) :=
158+
begin
159+
induction t with ab n f ts ih,
160+
{ cases ab;
161+
simp [language.con], },
162+
{ simp [ih], }
163+
end
164+
165+
lemma realize_constants_vars_equiv_left [L[[α]].Structure M]
166+
[(Lhom_with_constants L α).is_expansion_on M]
167+
{n} {t : L[[α]].term (β ⊕ fin n)} {v : β → M} {xs : fin n → M} :
168+
(constants_vars_equiv_left t).realize (sum.elim (sum.elim (λ a, ↑(L.con a)) v) xs) =
169+
t.realize (sum.elim v xs) :=
170+
begin
171+
simp only [constants_vars_equiv_left, realize_relabel, equiv.coe_trans, function.comp_app,
172+
constants_vars_equiv_apply, relabel_equiv_symm_apply],
173+
refine trans _ (realize_constants_to_vars),
174+
rcongr,
175+
rcases x with (a | (b | i));
176+
simp,
177+
end
178+
137179
end term
138180

139181
namespace Lhom
@@ -144,7 +186,7 @@ namespace Lhom
144186
begin
145187
induction t with _ n f ts ih,
146188
{ refl },
147-
{ simp only [term.realize, Lhom.on_term, Lhom.is_expansion_on.map_on_function, ih] }
189+
{ simp only [term.realize, Lhom.on_term, Lhom.map_on_function, ih] }
148190
end
149191

150192
end Lhom
@@ -393,6 +435,20 @@ begin
393435
{ simp [restrict_free_var, realize, ih3] },
394436
end
395437

438+
lemma realize_constants_vars_equiv [L[[α]].Structure M]
439+
[(Lhom_with_constants L α).is_expansion_on M]
440+
{n} {φ : L[[α]].bounded_formula β n} {v : β → M} {xs : fin n → M} :
441+
(constants_vars_equiv φ).realize (sum.elim (λ a, ↑(L.con a)) v) xs ↔ φ.realize v xs :=
442+
begin
443+
refine realize_map_term_rel_id (λ n t xs, realize_constants_vars_equiv_left) (λ n R xs, _),
444+
rw ← (Lhom_with_constants L α).map_on_relation (equiv.sum_empty (L.relations n)
445+
((constants_on α).relations n) R) xs,
446+
rcongr,
447+
cases R,
448+
{ simp, },
449+
{ exact is_empty_elim R }
450+
end
451+
396452
variables [nonempty M]
397453

398454
lemma realize_all_lift_at_one_self {n : ℕ} {φ : L.bounded_formula α n}
@@ -486,7 +542,7 @@ begin
486542
{ refl },
487543
{ simp only [on_bounded_formula, realize_bd_equal, realize_on_term],
488544
refl, },
489-
{ simp only [on_bounded_formula, realize_rel, realize_on_term, is_expansion_on.map_on_relation],
545+
{ simp only [on_bounded_formula, realize_rel, realize_on_term, Lhom.map_on_relation],
490546
refl, },
491547
{ simp only [on_bounded_formula, ih1, ih2, realize_imp], },
492548
{ simp only [on_bounded_formula, ih3, realize_all], },

src/model_theory/substructures.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def substructure_reduct : L'.substructure M ↪o L.substructure M :=
577577
{ to_fun := λ S, { carrier := S,
578578
fun_mem := λ n f x hx, begin
579579
have h := S.fun_mem (φ.on_function f) x hx,
580-
simp only [is_expansion_on.map_on_function, substructure.mem_carrier] at h,
580+
simp only [Lhom.map_on_function, substructure.mem_carrier] at h,
581581
exact h,
582582
end },
583583
inj' := λ S T h, begin

src/model_theory/syntax.lean

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ above a particular index.
3131
variables with given terms.
3232
* Language maps can act on syntactic objects with functions such as
3333
`first_order.language.Lhom.on_formula`.
34+
* `first_order.language.term.constants_vars_equiv` and
35+
`first_order.language.bounded_formula.constants_vars_equiv` switch terms and formulas between having
36+
constants in the language and having extra variables indexed by the same type.
3437
3538
## Implementation Notes
3639
* Formulas use a modified version of de Bruijn variables. Specifically, a `L.bounded_formula α n`
@@ -112,6 +115,10 @@ end
112115
(term.relabel g ∘ term.relabel f : L.term α → L.term γ) = term.relabel (g ∘ f) :=
113116
funext (relabel_relabel f g)
114117

118+
/-- Relabels a term's variables along a bijection. -/
119+
@[simps] def relabel_equiv (g : α ≃ β) : L.term α ≃ L.term β :=
120+
⟨relabel g, relabel g.symm, λ t, by simp, λ t, by simp⟩
121+
115122
/-- Restricts a term to use only a set of the given variables. -/
116123
def restrict_var [decidable_eq α] : Π (t : L.term α) (f : t.var_finset → β), L.term β
117124
| (var a) f := var (f ⟨a, mem_singleton_self a⟩)
@@ -140,6 +147,54 @@ def functions.apply₂ (f : L.functions 2) (t₁ t₂ : L.term α) : L.term α :
140147

141148
namespace term
142149

150+
/-- Sends a term with constants to a term with extra variables. -/
151+
@[simp] def constants_to_vars : L[[γ]].term α → L.term (γ ⊕ α)
152+
| (var a) := var (sum.inr a)
153+
| (@func _ _ 0 f ts) := sum.cases_on f (λ f, func f (λ i, (ts i).constants_to_vars))
154+
(λ c, var (sum.inl c))
155+
| (@func _ _ (n + 1) f ts) := sum.cases_on f (λ f, func f (λ i, (ts i).constants_to_vars))
156+
(λ c, is_empty_elim c)
157+
158+
/-- Sends a term with extra variables to a term with constants. -/
159+
@[simp] def vars_to_constants : L.term (γ ⊕ α) → L[[γ]].term α
160+
| (var (sum.inr a)) := var a
161+
| (var (sum.inl c)) := constants.term (sum.inr c)
162+
| (func f ts) := func (sum.inl f) (λ i, (ts i).vars_to_constants)
163+
164+
/-- A bijection between terms with constants and terms with extra variables. -/
165+
@[simps] def constants_vars_equiv : L[[γ]].term α ≃ L.term (γ ⊕ α) :=
166+
⟨constants_to_vars, vars_to_constants, begin
167+
intro t,
168+
induction t with _ n f _ ih,
169+
{ refl },
170+
{ cases n,
171+
{ cases f,
172+
{ simp [constants_to_vars, vars_to_constants, ih] },
173+
{ simp [constants_to_vars, vars_to_constants, constants.term] } },
174+
{ cases f,
175+
{ simp [constants_to_vars, vars_to_constants, ih] },
176+
{ exact is_empty_elim f } } }
177+
end, begin
178+
intro t,
179+
induction t with x n f _ ih,
180+
{ cases x;
181+
refl },
182+
{ cases n;
183+
{ simp [vars_to_constants, constants_to_vars, ih] } }
184+
end
185+
186+
/-- A bijection between terms with constants and terms with extra variables. -/
187+
def constants_vars_equiv_left : L[[γ]].term (α ⊕ β) ≃ L.term ((γ ⊕ α) ⊕ β) :=
188+
constants_vars_equiv.trans (relabel_equiv (equiv.sum_assoc _ _ _)).symm
189+
190+
@[simp] lemma constants_vars_equiv_left_apply (t : L[[γ]].term (α ⊕ β)) :
191+
constants_vars_equiv_left t = (constants_to_vars t).relabel (equiv.sum_assoc _ _ _).symm :=
192+
rfl
193+
194+
@[simp] lemma constants_vars_equiv_left_symm_apply (t : L.term ((γ ⊕ α) ⊕ β)) :
195+
constants_vars_equiv_left.symm t = vars_to_constants (t.relabel (equiv.sum_assoc _ _ _)) :=
196+
rfl
197+
143198
instance inhabited_of_var [inhabited α] : inhabited (L.term α) :=
144199
⟨var default⟩
145200

@@ -485,6 +540,10 @@ end
485540
φ.map_term_rel (λ _ t, t.subst (sum.elim (term.relabel sum.inl ∘ f) (var ∘ sum.inr)))
486541
(λ _, id) (λ _, id)
487542

543+
/-- A bijection sending formulas with constants to formulas with extra variables. -/
544+
def constants_vars_equiv : L[[γ]].bounded_formula α n ≃ L.bounded_formula (γ ⊕ α) n :=
545+
map_term_rel_equiv (λ _, term.constants_vars_equiv_left) (λ _, equiv.sum_empty _ _)
546+
488547
/-- Turns the extra variables of a bounded formula into free variables. -/
489548
@[simp] def to_formula : ∀ {n : ℕ}, L.bounded_formula α n → L.formula (α ⊕ fin n)
490549
| n falsum := falsum

0 commit comments

Comments
 (0)