@@ -3,24 +3,30 @@ Copyright (c) 2025 Dexin Zhang. All rights reserved.
33Released under Apache 2.0 license as described in the file LICENSE.
44Authors: Dexin Zhang
55-/
6+ module
7+
8+ public import Mathlib.ModelTheory.Arithmetic.Presburger.Basic
9+ public import Mathlib.ModelTheory.Arithmetic.Presburger.Semilinear.Basic
10+ public import Mathlib.ModelTheory.Definability
11+
612import Mathlib.Algebra.GCDMonoid.Finset
713import Mathlib.Algebra.GCDMonoid.Nat
8- import Mathlib.ModelTheory.Arithmetic.Presburger.Basic
9- import Mathlib.ModelTheory.Arithmetic.Presburger.Semilinear.Basic
10- import Mathlib.ModelTheory.Definability
14+ import Mathlib.Algebra.Group.Submonoid.Finsupp
15+ import Mathlib.LinearAlgebra.Matrix.Notation
1116
1217/-!
1318# Presburger definability and semilinear sets
1419
1520This file formalizes the equivalence between Presburger definable sets and semilinear sets. As an
16- application, we prove that the graph of multiplication is not Presburger definable.
21+ application of this result , we show that the graph of multiplication is not Presburger definable.
1722
1823## Main Results
1924
20- - `presburger.definable_iff_semilinear`: a set is Presburger definable in `ℕ` if and only if it is
21- semilinear.
22- - `definable₁_iff_ultimately_periodic`: in the 1-dimensional case, a set is Presburger arithmetic
23- definable in `ℕ` if and only if it is ultimately periodic, i.e. periodic after some number `k`.
25+ - `presburger.definable_iff_isSemilinearSet`: a set is Presburger definable in `ℕ` if and only if it
26+ is semilinear.
27+ - `presburger.definable₁_iff_ultimately_periodic`: in the 1-dimensional case, a set is Presburger
28+ arithmetic definable in `ℕ` if and only if it is ultimately periodic, i.e. periodic after some
29+ number `k`.
2430- `presburger.mul_not_definable`: the graph of multiplication is not Presburger definable in `ℕ`.
2531
2632 ## References
@@ -31,36 +37,33 @@ application, we prove that the graph of multiplication is not Presburger definab
3137* [ Samuel Eilenberg and M. P. Schützenberger, *Rational Sets in Commutative Monoids* ] [eilenberg1969 ]
3238 -/
3339
34- universe u v w
35-
36- variable {α : Type u} {β : Type v} {ι : Type w}
37-
38- namespace Set
40+ @[expose] public section
3941
40- variable {α : Type u } [Fintype α] {s : Set (α → ℕ)} {A : Set ℕ}
42+ variable {α : Type * } [Fintype α] {s : Set (α → ℕ)} {A : Set ℕ}
4143
42- open Submodule FirstOrder Language
44+ open Set Submodule FirstOrder Language
4345
44- theorem Linear .definable (hs : s.Linear ) : A.Definable presburger s := by
45- classical
46+ theorem IsLinearSet .definable (hs : IsLinearSet s ) : A.Definable presburger s := by
47+ rw [isLinearSet_iff] at hs
4648 rcases hs with ⟨v, t, rfl⟩
4749 refine ⟨Formula.iExs t (Formula.iInf fun i : α =>
4850 (Term.var (Sum.inl i)).equal
4951 (Term.varsToConstants
5052 ((v i : presburger.Term _) + presburger.sum Finset.univ fun x : t =>
5153 x.1 i • Term.var (Sum.inr (Sum.inr x))))), ?_⟩
5254 ext x
53- simp only [mem_vadd_set, SetLike.mem_coe, mem_span_finset ', Finset.univ_eq_attach, nsmul_eq_mul ,
54- vadd_eq_add, exists_exists_eq_and, mem_setOf_eq, Formula.realize_iExs , Formula.realize_iInf ,
55- Formula.realize_equal, Term.realize_var, Sum.elim_inl, Term.realize_varsToConstants, coe_con ,
56- presburger.realize_add, presburger.realize_natCast, Nat.cast_id , presburger.realize_sum ,
57- presburger.realize_nsmul, Sum.elim_inr, smul_eq_mul]
55+ simp only [mem_vadd_set, SetLike.mem_coe, AddSubmonoid.mem_closure_finset ', Finset.univ_eq_attach,
56+ nsmul_eq_mul, vadd_eq_add, ↓existsAndEq, true_and, mem_setOf_eq , Formula.realize_iExs ,
57+ Formula.realize_iInf, Formula. realize_equal, Term.realize_var, Sum.elim_inl,
58+ Term.realize_varsToConstants, coe_con, presburger.realize_add , presburger.realize_natCast ,
59+ Nat.cast_id, presburger.realize_sum, presburger.realize_nsmul, Sum.elim_inr, smul_eq_mul]
5860 congr! with a
5961 simp_rw [Eq.comm (b := x), fun x : t => mul_comm (a x : α → ℕ) x, funext_iff]
6062 congr! 1 with i
6163 simp
6264
63- theorem Semilinear.definable (hs : s.Semilinear) : A.Definable presburger s := by
65+ theorem IsSemilinearSet.definable (hs : IsSemilinearSet s) : A.Definable presburger s := by
66+ rw [isSemilinearSet_iff] at hs
6467 rcases hs with ⟨S, hS, rfl⟩
6568 choose φ hφ using fun s : S => (hS s.1 s.2 ).definable
6669 refine ⟨Formula.iSup φ, ?_⟩
@@ -69,19 +72,15 @@ theorem Semilinear.definable (hs : s.Semilinear) : A.Definable presburger s := b
6972 simp only [mem_setOf_eq] at this
7073 simp [this]
7174
72- end Set
73-
7475namespace FirstOrder.Language.presburger
7576
76- open Set Matrix
77-
78- variable {A : Set ℕ} [Fintype α]
79-
8077lemma term_realize_eq_add_dotProduct (t : presburger[[A]].Term α) :
8178 ∃ (k : ℕ) (u : α → ℕ), ∀ (v : α → ℕ), t.realize v = k + u ⬝ᵥ v := by
8279 classical
8380 induction t with simp only [Term.realize]
84- | var i => refine ⟨0 , Pi.single i 1 , ?_⟩; simp
81+ | var i =>
82+ refine ⟨0 , Pi.single i 1 , ?_⟩
83+ simp
8584 | @func l f ts ih =>
8685 cases f with
8786 | inl f =>
@@ -109,22 +108,22 @@ lemma term_realize_eq_add_dotProduct (t : presburger[[A]].Term α) :
109108 rfl
110109 | succ => nomatch f
111110
112- lemma boundedFormula_realize_semilinear {n} (φ : presburger[[A]].BoundedFormula α n) :
113- {v : α ⊕ Fin n → ℕ | φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr)}.Semilinear := by
111+ lemma isSemilinearSet_boundedFormula_realize {n} (φ : presburger[[A]].BoundedFormula α n) :
112+ IsSemilinearSet {v : α ⊕ Fin n → ℕ | φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr)} := by
114113 induction φ with simp only [BoundedFormula.Realize]
115114 | equal t₁ t₂ =>
116115 rcases term_realize_eq_add_dotProduct t₁ with ⟨k₁, u₁, ht₁⟩
117116 rcases term_realize_eq_add_dotProduct t₂ with ⟨k₂, u₂, ht₂⟩
118- convert Semilinear.of_linear_equation_nat ![k₁] ![k₂] (.of ![u₁]) (.of ![u₂])
117+ convert Nat.isSemilinearSet_setOf_mulVec_eq ![k₁] ![k₂] (.of ![u₁]) (.of ![u₂])
119118 simp [ht₁, ht₂]
120119 | rel f => nomatch f
121- | falsum => exact Semilinear .empty
120+ | falsum => exact .empty
122121 | imp _ _ ih₁ ih₂ =>
123122 convert (ih₂.compl.inter ih₁).compl using 1
124123 simp [setOf_inter_eq_sep, imp_iff_not_or, compl_setOf]
125124 | @all n φ ih =>
126125 let e := (Equiv.sumAssoc α (Fin n) (Fin 1 )).trans (Equiv.sumCongr (.refl α) finSumFinEquiv)
127- rw [← Semilinear.image_iff (LinearEquiv.funCongrLeft ℕ ℕ e)] at ih
126+ rw [← isSemilinearSet_image_iff (LinearEquiv.funCongrLeft ℕ ℕ e)] at ih
128127 convert ih.compl.proj.compl using 1
129128 simp_rw [compl_setOf, not_exists, Fin.forall_fin_succ_pi, Fin.forall_fin_zero_pi,
130129 mem_compl_iff, mem_image, not_not, ← LinearEquiv.eq_symm_apply, LinearEquiv.funCongrLeft_symm,
@@ -134,35 +133,37 @@ lemma boundedFormula_realize_semilinear {n} (φ : presburger[[A]].BoundedFormula
134133 ext i
135134 cases i using Fin.lastCases <;> simp [e]
136135
137- lemma formula_realize_semilinear (φ : presburger[[A]].Formula α) :
138- (setOf φ.Realize : Set (α → ℕ)).Semilinear := by
136+ lemma isSemilinearSet_formula_realize_semilinear (φ : presburger[[A]].Formula α) :
137+ IsSemilinearSet (setOf φ.Realize : Set (α → ℕ)) := by
139138 let e := Equiv.sumEmpty α (Fin 0 )
140- convert (boundedFormula_realize_semilinear φ).image (LinearMap.funLeft ℕ ℕ e.symm)
139+ convert (isSemilinearSet_boundedFormula_realize φ).image (LinearMap.funLeft ℕ ℕ e.symm)
141140 ext x
142141 simp only [mem_setOf_eq, mem_image]
143142 rw [(e.arrowCongr (.refl ℕ)).exists_congr_left]
144143 simp [Formula.Realize, Unique.eq_default, Function.comp_def, LinearMap.funLeft, e]
145144
146145/-- A set is Presburger definable in `ℕ` if and only if it is semilinear. -/
147- theorem definable_iff_semilinear {s : Set (α → ℕ)} :
148- A.Definable presburger s ↔ s.Semilinear :=
149- ⟨fun ⟨φ, hφ⟩ => hφ ▸ formula_realize_semilinear φ, Semilinear .definable⟩
146+ theorem definable_iff_isSemilinearSet {s : Set (α → ℕ)} :
147+ A.Definable presburger s ↔ IsSemilinearSet s :=
148+ ⟨fun ⟨φ, hφ⟩ => hφ ▸ isSemilinearSet_formula_realize_semilinear φ, IsSemilinearSet .definable⟩
150149
151150/-- In the 1-dimensional case, a set is Presburger arithmetic definable in `ℕ` if and only if it
152151 is ultimately periodic, i.e. periodic after some number `k`. -/
153152theorem definable₁_iff_ultimately_periodic {s : Set ℕ} :
154153 A.Definable₁ presburger s ↔ ∃ k, ∃ p > 0 , ∀ x ≥ k, x ∈ s ↔ x + p ∈ s := by
155- rw [Definable₁, definable_iff_semilinear ,
156- ← Semilinear.image_iff (LinearEquiv.funUnique (Fin 1 ) ℕ ℕ), ← preimage_setOf_eq]
154+ rw [Definable₁, definable_iff_isSemilinearSet ,
155+ ← isSemilinearSet_image_iff (LinearEquiv.funUnique (Fin 1 ) ℕ ℕ), ← preimage_setOf_eq]
157156 simp only [LinearEquiv.funUnique_apply, Function.eval, Fin.default_eq_zero, setOf_mem_eq]
158157 rw [image_preimage_eq s fun x => ⟨![x], rfl⟩]
159158 constructor
160159 · intro hs
161- apply Semilinear.proper_semilinear at hs
160+ apply IsSemilinearSet.isProperSemilinearSet at hs
161+ rw [isProperSemilinearSet_iff] at hs
162162 rcases hs with ⟨S, hS, rfl⟩
163163 replace hS : ∀ t ∈ S, ∃ k, ∃ p > 0 , ∀ x ≥ k, x ∈ t ↔ x + p ∈ t := by
164164 intro t ht
165165 apply hS at ht
166+ rw [isProperLinearSet_iff] at ht
166167 rcases ht with ⟨a, t, ht, rfl⟩
167168 have hcard : t.card ≤ 1 := by
168169 by_contra hcard
@@ -188,7 +189,7 @@ theorem definable₁_iff_ultimately_periodic {s : Set ℕ} :
188189 rw [Nat.ne_zero_iff_zero_lt] at hb
189190 refine ⟨a, b, hb, fun x hx => ?_⟩
190191 simp only [Finset.coe_singleton, mem_vadd_set, SetLike.mem_coe,
191- Submodule.mem_span_singleton , smul_eq_mul, vadd_eq_add, exists_exists_eq_and]
192+ AddSubmonoid.mem_closure_singleton , smul_eq_mul, vadd_eq_add, exists_exists_eq_and]
192193 constructor
193194 · rintro ⟨x, rfl⟩
194195 refine ⟨x + 1 , ?_⟩
@@ -222,10 +223,10 @@ theorem definable₁_iff_ultimately_periodic {s : Set ℕ} :
222223 have h₁ : {x ∈ s | x < k}.Finite := (Set.finite_lt_nat k).subset (sep_subset_setOf _ _)
223224 have h₂ : {x ∈ s | k ≤ x ∧ x < k + p}.Finite :=
224225 (Set.finite_Ico k (k + p)).subset (sep_subset_setOf _ _)
225- convert h₁.semilinear. union (h₂.semilinear. add (Semilinear.span_finset {p}))
226+ convert (IsSemilinearSet.of_finite h₁). union (. add (.of_finite h₂) (.closure_finset {p}))
226227 ext x
227228 simp only [sep_and, Finset.coe_singleton, mem_union, mem_setOf_eq, mem_add, mem_inter_iff,
228- SetLike.mem_coe, Submodule.mem_span_singleton , smul_eq_mul, exists_exists_eq_and]
229+ SetLike.mem_coe, AddSubmonoid.mem_closure_singleton , smul_eq_mul, exists_exists_eq_and]
229230 constructor
230231 · intro hx
231232 by_cases hx' : x < k
0 commit comments