forked from leanprover-community/mathlib4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefinability.lean
More file actions
524 lines (421 loc) · 19.3 KB
/
Definability.lean
File metadata and controls
524 lines (421 loc) · 19.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
/-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
module
public import Mathlib.Data.SetLike.Basic
public import Mathlib.Data.Rel
public import Mathlib.ModelTheory.Semantics
public import Mathlib.Tactic.FunProp
/-!
# Definable Sets
This file defines what it means for a set over a first-order structure to be definable.
## Main Definitions
- `Set.Definable` is defined so that `A.Definable L s` indicates that the
set `s` of a finite Cartesian power of `M` is definable with parameters in `A`.
- `Set.Definable₁` is defined so that `A.Definable₁ L s` indicates that
`(s : Set M)` is definable with parameters in `A`.
- `Set.Definable₂` is defined so that `A.Definable₂ L s` indicates that
`(s : Set (M × M))` is definable with parameters in `A`.
- A `FirstOrder.Language.DefinableSet` is defined so that `L.DefinableSet A α` is the Boolean
algebra of subsets of `α → M` defined by formulas with parameters in `A`.
- `Set.TermDefinable` functions are those equivalent to some term expressible in the language.
- `Set.TermDefinable₁` specialize this to case of unary functions.
## Main Results
- `L.DefinableSet A α` forms a `BooleanAlgebra`
- `Set.Definable.image_comp` shows that definability is closed under projections in finite
dimensions.
- The `Set.TermDefinable` property is transitive, and `TermDefinable` functions are closed under
composition.
-/
@[expose] public section
universe u v w u₁
namespace Set
variable {M : Type w} (A : Set M) (L : FirstOrder.Language.{u, v}) [L.Structure M]
open FirstOrder FirstOrder.Language FirstOrder.Language.Structure
variable {α : Type u₁} {β : Type*}
/-- A subset of a finite Cartesian product of a structure is definable over a set `A` when
membership in the set is given by a first-order formula with parameters from `A`. -/
def Definable (s : Set (α → M)) : Prop :=
∃ φ : L[[A]].Formula α, s = setOf φ.Realize
variable {L} {A} {B : Set M} {s : Set (α → M)}
theorem Definable.map_expansion {L' : FirstOrder.Language} [L'.Structure M] (h : A.Definable L s)
(φ : L →ᴸ L') [φ.IsExpansionOn M] : A.Definable L' s := by
obtain ⟨ψ, rfl⟩ := h
refine ⟨(φ.addConstants A).onFormula ψ, ?_⟩
ext x
simp only [mem_setOf_eq, LHom.realize_onFormula]
theorem definable_iff_exists_formula_sum :
A.Definable L s ↔ ∃ φ : L.Formula (A ⊕ α), s = {v | φ.Realize (Sum.elim (↑) v)} := by
rw [Definable, Equiv.exists_congr_left (BoundedFormula.constantsVarsEquiv)]
refine exists_congr (fun φ => iff_iff_eq.2 (congr_arg (s = ·) ?_))
ext
simp only [BoundedFormula.constantsVarsEquiv, constantsOn,
BoundedFormula.mapTermRelEquiv_symm_apply, mem_setOf_eq, Formula.Realize]
refine BoundedFormula.realize_mapTermRel_id ?_ (fun _ _ _ => rfl)
intros
simp only [Term.constantsVarsEquivLeft_symm_apply, Term.realize_varsToConstants,
coe_con, Term.realize_relabel]
congr 1 with a
rcases a with (_ | _) | _ <;> rfl
set_option backward.isDefEq.respectTransparency false in
theorem empty_definable_iff :
(∅ : Set M).Definable L s ↔ ∃ φ : L.Formula α, s = setOf φ.Realize := by
rw [Definable, Equiv.exists_congr_left (LEquiv.addEmptyConstants L (∅ : Set M)).onFormula]
simp
theorem definable_iff_empty_definable_with_params :
A.Definable L s ↔ (∅ : Set M).Definable L[[A]] s :=
empty_definable_iff.symm
theorem Definable.mono (hAs : A.Definable L s) (hAB : A ⊆ B) : B.Definable L s := by
rw [definable_iff_empty_definable_with_params] at *
exact hAs.map_expansion (L.lhomWithConstantsMap (Set.inclusion hAB))
@[simp]
theorem definable_empty : A.Definable L (∅ : Set (α → M)) :=
⟨⊥, by
ext
simp⟩
@[simp]
theorem definable_univ : A.Definable L (univ : Set (α → M)) :=
⟨⊤, by
ext
simp⟩
@[simp]
theorem Definable.inter {f g : Set (α → M)} (hf : A.Definable L f) (hg : A.Definable L g) :
A.Definable L (f ∩ g) := by
rcases hf with ⟨φ, rfl⟩
rcases hg with ⟨θ, rfl⟩
refine ⟨φ ⊓ θ, ?_⟩
ext
simp
@[simp]
theorem Definable.union {f g : Set (α → M)} (hf : A.Definable L f) (hg : A.Definable L g) :
A.Definable L (f ∪ g) := by
rcases hf with ⟨φ, hφ⟩
rcases hg with ⟨θ, hθ⟩
refine ⟨φ ⊔ θ, ?_⟩
ext
rw [hφ, hθ, mem_setOf_eq, Formula.realize_sup, mem_union, mem_setOf_eq, mem_setOf_eq]
theorem definable_finset_inf {ι : Type*} {f : ι → Set (α → M)} (hf : ∀ i, A.Definable L (f i))
(s : Finset ι) : A.Definable L (s.inf f) := by
classical
refine Finset.induction definable_univ (fun i s _ h => ?_) s
rw [Finset.inf_insert]
exact (hf i).inter h
theorem definable_finset_sup {ι : Type*} {f : ι → Set (α → M)} (hf : ∀ i, A.Definable L (f i))
(s : Finset ι) : A.Definable L (s.sup f) := by
classical
refine Finset.induction definable_empty (fun i s _ h => ?_) s
rw [Finset.sup_insert]
exact (hf i).union h
theorem definable_biInter_finset {ι : Type*} {f : ι → Set (α → M)}
(hf : ∀ i, A.Definable L (f i)) (s : Finset ι) : A.Definable L (⋂ i ∈ s, f i) := by
rw [← Finset.inf_set_eq_iInter]
exact definable_finset_inf hf s
theorem definable_biUnion_finset {ι : Type*} {f : ι → Set (α → M)}
(hf : ∀ i, A.Definable L (f i)) (s : Finset ι) : A.Definable L (⋃ i ∈ s, f i) := by
rw [← Finset.sup_set_eq_biUnion]
exact definable_finset_sup hf s
@[simp]
theorem Definable.compl {s : Set (α → M)} (hf : A.Definable L s) : A.Definable L sᶜ := by
rcases hf with ⟨φ, hφ⟩
refine ⟨φ.not, ?_⟩
ext v
rw [hφ, compl_setOf, mem_setOf, mem_setOf, Formula.realize_not]
@[simp]
theorem Definable.sdiff {s t : Set (α → M)} (hs : A.Definable L s) (ht : A.Definable L t) :
A.Definable L (s \ t) :=
hs.inter ht.compl
@[simp] lemma Definable.himp {s t : Set (α → M)} (hs : A.Definable L s) (ht : A.Definable L t) :
A.Definable L (s ⇨ t) := by rw [himp_eq]; exact ht.union hs.compl
theorem Definable.preimage_comp (f : α → β) {s : Set (α → M)} (h : A.Definable L s) :
A.Definable L ((fun g : β → M => g ∘ f) ⁻¹' s) := by
obtain ⟨φ, rfl⟩ := h
refine ⟨φ.relabel f, ?_⟩
ext
simp only [Set.preimage_setOf_eq, mem_setOf_eq, Formula.realize_relabel]
theorem Definable.image_comp_equiv {s : Set (β → M)} (h : A.Definable L s) (f : α ≃ β) :
A.Definable L ((fun g : β → M => g ∘ f) '' s) := by
refine (congr rfl ?_).mp (h.preimage_comp f.symm)
rw [image_eq_preimage_of_inverse]
· intro i
ext b
simp only [Function.comp_apply, Equiv.apply_symm_apply]
· intro i
ext a
simp
theorem definable_iff_finitely_definable :
A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
(A0 : Set M).Definable L s := by
classical
constructor
· simp only [definable_iff_exists_formula_sum]
rintro ⟨φ, rfl⟩
let A0 := (φ.freeVarFinset.toLeft).image Subtype.val
refine ⟨A0, by simp [A0], (φ.restrictFreeVar <| fun x => Sum.casesOn x.1
(fun x hx => Sum.inl ⟨x, by simp [A0, hx]⟩) (fun x _ => Sum.inr x) x.2), ?_⟩
ext
simp only [Formula.Realize, mem_setOf_eq, Finset.coe_sort_coe]
exact iff_comm.1 <| BoundedFormula.realize_restrictFreeVar _ (by simp)
· rintro ⟨A0, hA0, hd⟩
exact Definable.mono hd hA0
/-- This lemma is only intended as a helper for `Definable.image_comp`. -/
theorem Definable.image_comp_sumInl_fin (m : ℕ) {s : Set (Sum α (Fin m) → M)}
(h : A.Definable L s) : A.Definable L ((fun g : Sum α (Fin m) → M => g ∘ Sum.inl) '' s) := by
obtain ⟨φ, rfl⟩ := h
refine ⟨(BoundedFormula.relabel id φ).exs, ?_⟩
ext x
simp only [Set.mem_image, mem_setOf_eq, BoundedFormula.realize_exs,
BoundedFormula.realize_relabel, Function.comp_id, Fin.castAdd_zero, Fin.cast_refl]
constructor
· rintro ⟨y, hy, rfl⟩
exact
⟨y ∘ Sum.inr, (congr (congr rfl (Sum.elim_comp_inl_inr y).symm) (funext finZeroElim)).mp hy⟩
· rintro ⟨y, hy⟩
exact ⟨Sum.elim x y, (congr rfl (funext finZeroElim)).mp hy, Sum.elim_comp_inl _ _⟩
/-- Shows that definability is closed under finite projections. -/
theorem Definable.image_comp_embedding {s : Set (β → M)} (h : A.Definable L s) (f : α ↪ β)
[Finite β] : A.Definable L ((fun g : β → M => g ∘ f) '' s) := by
classical
cases nonempty_fintype β
refine
(congr rfl (ext fun x => ?_)).mp
(((h.image_comp_equiv (Equiv.Set.sumCompl (range f))).image_comp_equiv
(Equiv.sumCongr (Equiv.ofInjective f f.injective)
(Fintype.equivFin (↥(range f)ᶜ)).symm)).image_comp_sumInl_fin
_)
simp only [mem_image, exists_exists_and_eq_and]
refine exists_congr fun y => and_congr_right fun _ => Eq.congr_left (funext fun a => ?_)
simp
/-- Shows that definability is closed under finite projections. -/
theorem Definable.image_comp {s : Set (β → M)} (h : A.Definable L s) (f : α → β) [Finite α]
[Finite β] : A.Definable L ((fun g : β → M => g ∘ f) '' s) := by
classical
cases nonempty_fintype α
cases nonempty_fintype β
have h :=
(((h.image_comp_equiv (Equiv.Set.sumCompl (range f))).image_comp_equiv
(Equiv.sumCongr (_root_.Equiv.refl _)
(Fintype.equivFin _).symm)).image_comp_sumInl_fin
_).preimage_comp
(rangeSplitting f)
have h' :
A.Definable L { x : α → M | ∀ a, x a = x (rangeSplitting f (rangeFactorization f a)) } := by
have h' : ∀ a,
A.Definable L { x : α → M | x a = x (rangeSplitting f (rangeFactorization f a)) } := by
refine fun a => ⟨(var a).equal (var (rangeSplitting f (rangeFactorization f a))), ext ?_⟩
simp
refine (congr rfl (ext ?_)).mp (definable_biInter_finset h' Finset.univ)
simp
refine (congr rfl (ext fun x => ?_)).mp (h.inter h')
simp only [mem_inter_iff, mem_preimage, mem_image, exists_exists_and_eq_and,
mem_setOf_eq]
constructor
· rintro ⟨⟨y, ys, hy⟩, hx⟩
refine ⟨y, ys, ?_⟩
ext a
rw [hx a, ← Function.comp_apply (f := x), ← hy]
simp
· rintro ⟨y, ys, rfl⟩
refine ⟨⟨y, ys, ?_⟩, fun a => ?_⟩
· ext
simp [Set.apply_rangeSplitting f]
· rw [Function.comp_apply, Function.comp_apply, apply_rangeSplitting f,
rangeFactorization_coe]
variable (L A)
/-- A 1-dimensional version of `Definable`, for `Set M`. -/
def Definable₁ (s : Set M) : Prop :=
A.Definable L { x : Fin 1 → M | x 0 ∈ s }
/-- A 2-dimensional version of `Definable`, for `Set (M × M)`. -/
def Definable₂ (s : Set (M × M)) : Prop :=
A.Definable L { x : Fin 2 → M | (x 0, x 1) ∈ s }
end Set
namespace FirstOrder
namespace Language
open Set
variable (L : FirstOrder.Language.{u, v}) {M : Type w} [L.Structure M] (A : Set M) (α : Type u₁)
/-- Definable sets are subsets of finite Cartesian products of a structure such that membership is
given by a first-order formula. -/
def DefinableSet :=
{ s : Set (α → M) // A.Definable L s }
namespace DefinableSet
variable {L A α}
variable {s t : L.DefinableSet A α} {x : α → M}
instance instSetLike : SetLike (L.DefinableSet A α) (α → M) where
coe := Subtype.val
coe_injective' := Subtype.val_injective
instance : PartialOrder (L.DefinableSet A α) := fast_instance% .ofSetLike (L.DefinableSet A α) (α → M)
instance instTop : Top (L.DefinableSet A α) :=
⟨⟨⊤, definable_univ⟩⟩
instance instBot : Bot (L.DefinableSet A α) :=
⟨⟨⊥, definable_empty⟩⟩
instance instSup : Max (L.DefinableSet A α) :=
⟨fun s t => ⟨s ∪ t, s.2.union t.2⟩⟩
instance instInf : Min (L.DefinableSet A α) :=
⟨fun s t => ⟨s ∩ t, s.2.inter t.2⟩⟩
instance instCompl : Compl (L.DefinableSet A α) :=
⟨fun s => ⟨sᶜ, s.2.compl⟩⟩
instance instSDiff : SDiff (L.DefinableSet A α) :=
⟨fun s t => ⟨s \ t, s.2.sdiff t.2⟩⟩
-- Why does it complain that `s ⇨ t` is noncomputable?
noncomputable instance instHImp : HImp (L.DefinableSet A α) where
himp s t := ⟨s ⇨ t, s.2.himp t.2⟩
instance instInhabited : Inhabited (L.DefinableSet A α) :=
⟨⊥⟩
theorem le_iff : s ≤ t ↔ (s : Set (α → M)) ≤ (t : Set (α → M)) :=
Iff.rfl
@[simp]
theorem mem_top : x ∈ (⊤ : L.DefinableSet A α) :=
mem_univ x
@[simp]
theorem notMem_bot {x : α → M} : x ∉ (⊥ : L.DefinableSet A α) :=
notMem_empty x
@[simp]
theorem mem_sup : x ∈ s ⊔ t ↔ x ∈ s ∨ x ∈ t :=
Iff.rfl
@[simp]
theorem mem_inf : x ∈ s ⊓ t ↔ x ∈ s ∧ x ∈ t :=
Iff.rfl
@[simp]
theorem mem_compl : x ∈ sᶜ ↔ x ∉ s :=
Iff.rfl
@[simp]
theorem mem_sdiff : x ∈ s \ t ↔ x ∈ s ∧ x ∉ t :=
Iff.rfl
@[simp, norm_cast]
theorem coe_top : ((⊤ : L.DefinableSet A α) : Set (α → M)) = univ :=
rfl
@[simp, norm_cast]
theorem coe_bot : ((⊥ : L.DefinableSet A α) : Set (α → M)) = ∅ :=
rfl
@[simp, norm_cast]
theorem coe_sup (s t : L.DefinableSet A α) :
((s ⊔ t : L.DefinableSet A α) : Set (α → M)) = (s : Set (α → M)) ∪ (t : Set (α → M)) :=
rfl
@[simp, norm_cast]
theorem coe_inf (s t : L.DefinableSet A α) :
((s ⊓ t : L.DefinableSet A α) : Set (α → M)) = (s : Set (α → M)) ∩ (t : Set (α → M)) :=
rfl
@[simp, norm_cast]
theorem coe_compl (s : L.DefinableSet A α) :
((sᶜ : L.DefinableSet A α) : Set (α → M)) = (s : Set (α → M))ᶜ :=
rfl
@[simp, norm_cast]
theorem coe_sdiff (s t : L.DefinableSet A α) :
((s \ t : L.DefinableSet A α) : Set (α → M)) = (s : Set (α → M)) \ (t : Set (α → M)) :=
rfl
@[simp, norm_cast]
lemma coe_himp (s t : L.DefinableSet A α) : ↑(s ⇨ t) = (s ⇨ t : Set (α → M)) := rfl
noncomputable instance instBooleanAlgebra : BooleanAlgebra (L.DefinableSet A α) :=
Function.Injective.booleanAlgebra _ Subtype.coe_injective .rfl .rfl
coe_sup coe_inf coe_top coe_bot coe_compl coe_sdiff coe_himp
end DefinableSet
end Language
end FirstOrder
namespace Set
variable {M : Type w} (A : Set M) (L : FirstOrder.Language.{u, v}) {L' : FirstOrder.Language}
variable [L.Structure M] [L'.Structure M]
variable {α : Type u₁} {β : Type*}
open FirstOrder FirstOrder.Language FirstOrder.Language.Structure
/-- A function from a Cartesian power of a structure to that structure is term-definable over
a set `A` when the value of the function is given by a term with constants `A`. -/
@[fun_prop]
def TermDefinable (f : (α → M) → M) : Prop :=
∃ φ : L[[A]].Term α, f = φ.realize
/-- Every TermDefinable function has a tupleGraph that is definable. -/
theorem TermDefinable.definable_tupleGraph {f : (α → M) → M} (h : A.TermDefinable L f) :
A.Definable L f.tupleGraph := by
obtain ⟨φ, rfl⟩ := h
use (φ.relabel some).equal (Term.var none)
ext
simp [Function.tupleGraph]
variable {L} {A B} {f : (α → M) → M}
@[fun_prop]
theorem TermDefinable.map_expansion (h : A.TermDefinable L f) (φ : L →ᴸ L') [φ.IsExpansionOn M] :
A.TermDefinable L' f := by
obtain ⟨ψ, rfl⟩ := h
use (φ.addConstants A).onTerm ψ
simp
set_option backward.isDefEq.respectTransparency false in
theorem termDefinable_empty_iff :
(∅ : Set M).TermDefinable L f ↔ ∃ φ : L.Term α, f = φ.realize := by
rw [TermDefinable, Equiv.exists_congr_left (LEquiv.addEmptyConstants L (∅ : Set M)).onTerm]
simp
theorem termDefinable_empty_withConstants_iff :
(∅ : Set M).TermDefinable L[[A]] f ↔ A.TermDefinable L f :=
termDefinable_empty_iff
@[fun_prop]
theorem TermDefinable.mono {f : (α → M) → M} (h : A.TermDefinable L f) (hAB : A ⊆ B) :
B.TermDefinable L f := by
rw [← termDefinable_empty_withConstants_iff] at h ⊢
exact h.map_expansion (L.lhomWithConstantsMap (Set.inclusion hAB))
/-- TermDefinable is transitive. If f is TermDefinable in a structure S on L, and all of the
functions' realizations on S are TermDefinable on a structure T on L', then f is
TermDefinable on T in L'. -/
@[fun_prop]
theorem TermDefinable.trans {f : (β → M) → M} (h₁ : A.TermDefinable L f)
(h₂ : ∀ {n} (g : L[[A]].Functions n), A.TermDefinable L' g.term.realize) :
A.TermDefinable L' f := by
obtain ⟨x, rfl⟩ := h₁
choose c hc using @h₂
simp only [funext_iff] at hc
use x.substFunc c
simp_rw [Term.realize_substFunc hc]
variable (L) in
/-- A function from a structure to itself is term-definable over a set `A` when the
value of the function is given by a term with constants `A`. Like `TermDefinable`
but specialized for unary functions in order to write `M → M` instead of `(Unit → M) → M`. -/
@[fun_prop]
def TermDefinable₁ (f : M → M) : Prop :=
A.TermDefinable L fun x ↦ (f (x ()))
/-- `TermDefinable₁` is defined as `TermDefinable` on the `Unit` index type. -/
theorem termDefinable₁_iff_termDefinable (f : M → M) : A.TermDefinable₁ L f ↔
A.TermDefinable L (fun v ↦ f (v ())) := by
rfl
alias ⟨TermDefinable₁.termDefinable, TermDefinable.termDefinable₁⟩ :=
termDefinable₁_iff_termDefinable
attribute [fun_prop] TermDefinable.termDefinable₁
theorem termDefinable₁_iff_exists_term {f : M → M} : A.TermDefinable₁ L f ↔
∃ φ : L[[A]].Term Unit, f = φ.realize ∘ Function.const _ := by
refine exists_congr fun φ ↦ ?_
rw [funext_iff, funext_iff, (Equiv.funUnique Unit M).forall_congr']
simp only [Equiv.funUnique_symm_apply, uniqueElim_const, Function.comp_apply]
congr!
/-- A `TermDefinable₁` function has a graph that's `Definable₂`. -/
theorem TermDefinable₁.definable₂_graph {f : M → M} (h : A.TermDefinable₁ L f) :
A.Definable₂ L f.graph := by
obtain ⟨t, h⟩ := h.termDefinable.definable_tupleGraph A L
use t.relabel (Option.elim · 1 (fun _ ↦ 0))
ext v
convert Set.ext_iff.1 h (v ∘ (Option.elim · 1 (fun _ ↦ 0)))
simp
/-- The identity function is `TermDefinable₁` -/
@[fun_prop]
theorem TermDefinable₁.id : A.TermDefinable₁ L id :=
⟨Term.var (), rfl⟩
/-- Constant functions are `TermDefinable`, assuming the constant value is a language constant. -/
@[fun_prop]
theorem TermDefinable.const (C : L[[A]].Constants) : A.TermDefinable L (Function.const (α → M) C) :=
⟨C.term, by simp only [Term.realize_constants]; rfl⟩
/-- Constant functions are `TermDefinable₁`, assuming the constant value is a language constant. -/
@[fun_prop]
theorem TermDefinable₁.const (C : L[[A]].Constants) : A.TermDefinable₁ L (Function.const M C) :=
(TermDefinable.const C).termDefinable₁
/-- A k-ary `TermDefinable` function composed with k `TermDefinable` others is `TermDefinable`. -/
theorem TermDefinable.comp {f : (α → M) → M} {g : α → (β → M) → M} (hf : A.TermDefinable L f)
(hg : ∀ i, A.TermDefinable L (g i)) : A.TermDefinable L (fun b ↦ f (g · b)) := by
obtain ⟨φ, rfl⟩ := hf
choose ψ hψ using hg
use φ.subst ψ
simp [hψ]
/-- `TermDefinable₁` functions are closed under composition. -/
@[fun_prop]
theorem TermDefinable₁.comp {f g : M → M} (hf : A.TermDefinable₁ L f) (hg : A.TermDefinable₁ L g) :
A.TermDefinable₁ L (f ∘ g) :=
(hf.termDefinable.comp fun _ ↦ hg.termDefinable).termDefinable₁
/-- A `TermDefinable` function postcomposed with `TermDefinable₁` is `TermDefinable`. -/
@[fun_prop]
theorem TermDefinable₁.comp_termDefinable {f : M → M} {g : (α → M) → M}
(hf : A.TermDefinable₁ L f) (hg : A.TermDefinable L g) : A.TermDefinable L (f ∘ g) :=
hf.termDefinable.comp fun _ ↦ hg
end Set