Skip to content

Commit 3fd2f54

Browse files
committed
chore(Data/Matroid): refactoring ext lemmas (#19664)
Co-authored-by: madvorak <dvorakmartinbridge@seznam.cz>
1 parent 0137f52 commit 3fd2f54

File tree

6 files changed

+53
-32
lines changed

6 files changed

+53
-32
lines changed

Mathlib/Data/Matroid/Basic.lean

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def Matroid.ExistsMaximalSubsetProperty {α : Type _} (P : Set α → Prop) (X :
189189
use `Matroid.ofBase` or a variant. If just the independent sets are known,
190190
define an `IndepMatroid`, and then use `IndepMatroid.matroid`.
191191
-/
192-
@[ext] structure Matroid (α : Type _) where
192+
structure Matroid (α : Type _) where
193193
/-- `M` has a ground set `E`. -/
194194
(E : Set α)
195195
/-- `M` has a predicate `Base` defining its bases. -/
@@ -209,6 +209,8 @@ def Matroid.ExistsMaximalSubsetProperty {α : Type _} (P : Set α → Prop) (X :
209209
/-- Every base is contained in the ground set. -/
210210
(subset_ground : ∀ B, Base B → B ⊆ E)
211211

212+
attribute [local ext] Matroid
213+
212214
namespace Matroid
213215

214216
variable {α : Type*} {M : Matroid α}
@@ -460,13 +462,19 @@ theorem Base.diff_infinite_comm (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) :
460462
(B₁ \ B₂).Infinite ↔ (B₂ \ B₁).Infinite :=
461463
infinite_iff_infinite_of_encard_eq_encard (hB₁.encard_diff_comm hB₂)
462464

463-
theorem eq_of_base_iff_base_forall {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E)
465+
theorem ext_base {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E)
464466
(h : ∀ ⦃B⦄, B ⊆ M₁.E → (M₁.Base B ↔ M₂.Base B)) : M₁ = M₂ := by
465467
have h' : ∀ B, M₁.Base B ↔ M₂.Base B :=
466468
fun B ↦ ⟨fun hB ↦ (h hB.subset_ground).1 hB,
467469
fun hB ↦ (h <| hB.subset_ground.trans_eq hE.symm).2 hB⟩
468470
ext <;> simp [hE, M₁.indep_iff', M₂.indep_iff', h']
469471

472+
@[deprecated (since := "2024-12-25")] alias eq_of_base_iff_base_forall := ext_base
473+
474+
theorem ext_iff_base {M₁ M₂ : Matroid α} :
475+
M₁ = M₂ ↔ M₁.E = M₂.E ∧ ∀ ⦃B⦄, B ⊆ M₁.E → (M₁.Base B ↔ M₂.Base B) :=
476+
fun h ↦ by simp [h], fun ⟨hE, h⟩ ↦ ext_base hE h⟩
477+
470478
theorem base_compl_iff_maximal_disjoint_base (hB : B ⊆ M.E := by aesop_mat) :
471479
M.Base (M.E \ B) ↔ Maximal (fun I ↦ I ⊆ M.E ∧ ∃ B, M.Base B ∧ Disjoint I B) B := by
472480
simp_rw [maximal_iff, and_iff_right hB, and_imp, forall_exists_index]
@@ -663,22 +671,35 @@ theorem ground_indep_iff_base : M.Indep M.E ↔ M.Base M.E :=
663671

664672
theorem Base.exists_insert_of_ssubset (hB : M.Base B) (hIB : I ⊂ B) (hB' : M.Base B') :
665673
∃ e ∈ B' \ I, M.Indep (insert e I) :=
666-
(hB.indep.subset hIB.subset).exists_insert_of_not_base
674+
(hB.indep.subset hIB.subset).exists_insert_of_not_base
667675
(fun hI ↦ hIB.ne (hI.eq_of_subset_base hB hIB.subset)) hB'
668676

669-
theorem eq_of_indep_iff_indep_forall {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E)
670-
(h : ∀ I, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I)) : M₁ = M₂ :=
677+
@[ext] theorem ext_indep {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E)
678+
(h : ∀ ⦃I⦄, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I)) : M₁ = M₂ :=
671679
have h' : M₁.Indep = M₂.Indep := by
672680
ext I
673681
by_cases hI : I ⊆ M₁.E
674682
· rwa [h]
675683
exact iff_of_false (fun hi ↦ hI hi.subset_ground)
676684
(fun hi ↦ hI (hi.subset_ground.trans_eq hE.symm))
677-
eq_of_base_iff_base_forall hE (fun B _ ↦ by simp_rw [base_iff_maximal_indep, h'])
685+
ext_base hE (fun B _ ↦ by simp_rw [base_iff_maximal_indep, h'])
686+
687+
@[deprecated (since := "2024-12-25")] alias eq_of_indep_iff_indep_forall := ext_indep
678688

679-
theorem eq_iff_indep_iff_indep_forall {M₁ M₂ : Matroid α} :
680-
M₁ = M₂ ↔ (M₁.E = M₂.E) ∧ ∀ I, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I) :=
681-
fun h ↦ by (subst h; simp), fun h ↦ eq_of_indep_iff_indep_forall h.1 h.2
689+
theorem ext_iff_indep {M₁ M₂ : Matroid α} :
690+
M₁ = M₂ ↔ (M₁.E = M₂.E) ∧ ∀ ⦃I⦄, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I) :=
691+
fun h ↦ by (subst h; simp), fun h ↦ ext_indep h.1 h.2
692+
693+
@[deprecated (since := "2024-12-25")] alias eq_iff_indep_iff_indep_forall := ext_iff_indep
694+
695+
/-- If every base of `M₁` is independent in `M₂` and vice versa, then `M₁ = M₂`. -/
696+
lemma ext_base_indep {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E) (hM₁ : ∀ ⦃B⦄, M₁.Base B → M₂.Indep B)
697+
(hM₂ : ∀ ⦃B⦄, M₂.Base B → M₁.Indep B) : M₁ = M₂ := by
698+
refine ext_indep hE fun I hIE ↦ ⟨fun hI ↦ ?_, fun hI ↦ ?_⟩
699+
· obtain ⟨B, hB, hIB⟩ := hI.exists_base_superset
700+
exact (hM₁ hB).subset hIB
701+
obtain ⟨B, hB, hIB⟩ := hI.exists_base_superset
702+
exact (hM₂ hB).subset hIB
682703

683704
/-- A `Finitary` matroid is one where a set is independent if and only if it all
684705
its finite subsets are independent, or equivalently a matroid whose circuits are finite. -/
@@ -1003,7 +1024,7 @@ theorem finite_setOf_matroid {E : Set α} (hE : E.Finite) : {M : Matroid α | M.
10031024
have hf : f.Injective := by
10041025
refine fun M M' hMM' ↦ ?_
10051026
rw [Prod.mk.injEq, and_comm, Set.ext_iff, and_comm] at hMM'
1006-
exact eq_of_base_iff_base_forall hMM'.1 (fun B _ ↦ hMM'.2 B)
1027+
exact ext_base hMM'.1 (fun B _ ↦ hMM'.2 B)
10071028
rw [← Set.finite_image_iff hf.injOn]
10081029
refine (hE.finite_subsets.prod hE.finite_subsets.finite_subsets).subset ?_
10091030
rintro _ ⟨M, hE : M.E ⊆ E, rfl⟩

Mathlib/Data/Matroid/Closure.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ lemma mem_closure_diff_singleton_iff_closure (he : e ∈ X) (heE : e ∈ M.E :=
637637
end insert
638638

639639
lemma ext_closure {M₁ M₂ : Matroid α} (h : ∀ X, M₁.closure X = M₂.closure X) : M₁ = M₂ :=
640-
eq_of_indep_iff_indep_forall (by simpa using h univ)
640+
ext_indep (by simpa using h univ)
641641
(fun _ _ ↦ by simp_rw [indep_iff_forall_closure_diff_ne, h])
642642

643643

@@ -745,7 +745,7 @@ lemma ext_spanning {M M' : Matroid α} (h : M.E = M'.E)
745745
refine (em (S ⊆ M.E)).elim (fun hSE ↦ by rw [hsp _ hSE] )
746746
(fun hSE ↦ iff_of_false (fun h ↦ hSE h.subset_ground)
747747
(fun h' ↦ hSE (h'.subset_ground.trans h.symm.subset)))
748-
rw [← dual_inj, eq_iff_indep_iff_indep_forall, dual_ground, dual_ground, and_iff_right h]
748+
rw [← dual_inj, ext_iff_indep, dual_ground, dual_ground, and_iff_right h]
749749
intro I hIE
750750
rw [← coindep_def, ← coindep_def, coindep_iff_compl_spanning, coindep_iff_compl_spanning, hsp', h]
751751

Mathlib/Data/Matroid/Constructions.lean

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def emptyOn (α : Type*) : Matroid α where
5555
@[simp] theorem emptyOn_indep_iff : (emptyOn α).Indep I ↔ I = ∅ := Iff.rfl
5656

5757
theorem ground_eq_empty_iff : (M.E = ∅) ↔ M = emptyOn α := by
58-
simp only [emptyOn, eq_iff_indep_iff_indep_forall, iff_self_and]
58+
simp only [emptyOn, ext_iff_indep, iff_self_and]
5959
exact fun h ↦ by simp [h, subset_empty_iff]
6060

6161
@[simp] theorem emptyOn_dual_eq : (emptyOn α)✶ = emptyOn α := by
@@ -92,9 +92,9 @@ def loopyOn (E : Set α) : Matroid α := emptyOn α ↾ E
9292
rintro rfl; apply empty_subset
9393

9494
theorem eq_loopyOn_iff : M = loopyOn E ↔ M.E = E ∧ ∀ X ⊆ M.E, M.Indep X → X = ∅ := by
95-
simp only [eq_iff_indep_iff_indep_forall, loopyOn_ground, loopyOn_indep_iff, and_congr_right_iff]
95+
simp only [ext_iff_indep, loopyOn_ground, loopyOn_indep_iff, and_congr_right_iff]
9696
rintro rfl
97-
refine ⟨fun h I hI ↦ (h I hI).1, fun h I hIE ↦ ⟨h I hIE, by rintro rfl; simp⟩⟩
97+
refine ⟨fun h I hI ↦ (h hI).1, fun h I hIE ↦ ⟨h I hIE, by rintro rfl; simp⟩⟩
9898

9999
@[simp] theorem loopyOn_base_iff : (loopyOn E).Base B ↔ B = ∅ := by
100100
simp [Maximal, base_iff_maximal_indep]
@@ -110,15 +110,15 @@ theorem Finite.loopyOn_finite (hE : E.Finite) : Matroid.Finite (loopyOn E) :=
110110
⟨hE⟩
111111

112112
@[simp] theorem loopyOn_restrict (E R : Set α) : (loopyOn E) ↾ R = loopyOn R := by
113-
refine eq_of_indep_iff_indep_forall rfl ?_
113+
refine ext_indep rfl ?_
114114
simp only [restrict_ground_eq, restrict_indep_iff, loopyOn_indep_iff, and_iff_left_iff_imp]
115115
exact fun _ h _ ↦ h
116116

117117
theorem empty_base_iff : M.Base ∅ ↔ M = loopyOn M.E := by
118118
simp only [base_iff_maximal_indep, Maximal, empty_indep, le_eq_subset, empty_subset,
119-
subset_empty_iff, true_implies, true_and, eq_iff_indep_iff_indep_forall, loopyOn_ground,
119+
subset_empty_iff, true_implies, true_and, ext_iff_indep, loopyOn_ground,
120120
loopyOn_indep_iff]
121-
exact ⟨fun h I _ ↦ ⟨@h _, fun hI ↦ by simp [hI]⟩, fun h I hI ↦ (h I hI.subset_ground).1 hI⟩
121+
exact ⟨fun h I _ ↦ ⟨@h _, fun hI ↦ by simp [hI]⟩, fun h I hI ↦ (h hI.subset_ground).1 hI⟩
122122

123123
theorem eq_loopyOn_or_rkPos (M : Matroid α) : M = loopyOn M.E ∨ RkPos M := by
124124
rw [← empty_base_iff, rkPos_iff_empty_not_base]; apply em
@@ -165,7 +165,7 @@ theorem freeOn_indep (hIE : I ⊆ E) : (freeOn E).Indep I :=
165165
theorem eq_freeOn_iff : M = freeOn E ↔ M.E = E ∧ M.Indep E := by
166166
refine ⟨?_, fun h ↦ ?_⟩
167167
· rintro rfl; simp [Subset.rfl]
168-
simp only [eq_iff_indep_iff_indep_forall, freeOn_ground, freeOn_indep_iff, h.1, true_and]
168+
simp only [ext_iff_indep, freeOn_ground, freeOn_indep_iff, h.1, true_and]
169169
exact fun I hIX ↦ iff_of_true (h.2.subset hIX) hIX
170170

171171
theorem ground_indep_iff_eq_freeOn : M.Indep M.E ↔ M = freeOn M.E := by
@@ -219,7 +219,7 @@ theorem uniqueBaseOn_inter_basis (hX : X ⊆ E) : (uniqueBaseOn I E).Basis (X
219219
@[simp] theorem uniqueBaseOn_dual_eq (I E : Set α) :
220220
(uniqueBaseOn I E)✶ = uniqueBaseOn (E \ I) E := by
221221
rw [← uniqueBaseOn_inter_ground_eq]
222-
refine eq_of_base_iff_base_forall rfl (fun B (hB : B ⊆ E) ↦ ?_)
222+
refine ext_base rfl (fun B (hB : B ⊆ E) ↦ ?_)
223223
rw [dual_base_iff, uniqueBaseOn_base_iff inter_subset_right, uniqueBaseOn_base_iff diff_subset,
224224
uniqueBaseOn_ground]
225225
exact ⟨fun h ↦ by rw [← diff_diff_cancel_left hB, h, diff_inter_self_eq_diff],
@@ -233,7 +233,7 @@ theorem uniqueBaseOn_inter_basis (hX : X ⊆ E) : (uniqueBaseOn I E).Basis (X
233233

234234
theorem uniqueBaseOn_restrict' (I E R : Set α) :
235235
(uniqueBaseOn I E) ↾ R = uniqueBaseOn (I ∩ R ∩ E) R := by
236-
simp_rw [eq_iff_indep_iff_indep_forall, restrict_ground_eq, uniqueBaseOn_ground, true_and,
236+
simp_rw [ext_iff_indep, restrict_ground_eq, uniqueBaseOn_ground, true_and,
237237
restrict_indep_iff, uniqueBaseOn_indep_iff', subset_inter_iff]
238238
tauto
239239

Mathlib/Data/Matroid/Dual.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ theorem setOf_dual_base_eq : {B | M✶.Base B} = (fun X ↦ M.E \ X) '' {B | M.B
149149
rwa [← h, diff_diff_cancel_left hB'.subset_ground]
150150

151151
@[simp] theorem dual_dual (M : Matroid α) : M✶✶ = M :=
152-
eq_of_base_iff_base_forall rfl (fun B (h : B ⊆ M.E) ↦
152+
ext_base rfl (fun B (h : B ⊆ M.E) ↦
153153
by rw [dual_base_iff, dual_base_iff, dual_ground, diff_diff_cancel_left h])
154154

155155
theorem dual_involutive : Function.Involutive (dual : Matroid α → Matroid α) := dual_dual

Mathlib/Data/Matroid/Map.lean

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def comap (N : Matroid β) (f : α → β) : Matroid α :=
174174
simpa using hI.1.subset_ground
175175

176176
@[simp] lemma comap_id (N : Matroid β) : N.comap id = N :=
177-
eq_of_indep_iff_indep_forall rfl <| by simp [injective_id.injOn]
177+
ext_indep rfl <| by simp [injective_id.injOn]
178178

179179
lemma comap_indep_iff_of_injOn (hf : InjOn f (f ⁻¹' N.E)) :
180180
(N.comap f).Indep I ↔ N.Indep (f '' I) := by
@@ -276,7 +276,7 @@ lemma comapOn_base_iff_of_bijOn (h : BijOn f E N.E) :
276276

277277
lemma comapOn_dual_eq_of_bijOn (h : BijOn f E N.E) :
278278
(N.comapOn E f)✶ = N✶.comapOn E f := by
279-
refine eq_of_base_iff_base_forall (by simp) (fun B hB ↦ ?_)
279+
refine ext_base (by simp) (fun B hB ↦ ?_)
280280
rw [comapOn_base_iff_of_bijOn (by simpa), dual_base_iff, comapOn_base_iff_of_bijOn h,
281281
dual_base_iff _, comapOn_ground_eq, and_iff_left diff_subset, and_iff_left (by simpa),
282282
h.injOn.image_diff_subset (by simpa), h.image_eq]
@@ -438,7 +438,7 @@ lemma map_basis_iff' {I X : Set β} {hf} :
438438
exact hIX.map hf
439439

440440
@[simp] lemma map_dual {hf} : (M.map f hf)✶ = M✶.map f hf := by
441-
apply eq_of_base_iff_base_forall (by simp)
441+
apply ext_base (by simp)
442442
simp only [dual_ground, map_ground, subset_image_iff, forall_exists_index, and_imp,
443443
forall_apply_eq_imp_iff₂, dual_base_iff']
444444
intro B hB
@@ -456,18 +456,18 @@ lemma map_basis_iff' {I X : Set β} {hf} :
456456
rw [← dual_inj]; simp
457457

458458
@[simp] lemma map_id : M.map id (injOn_id M.E) = M := by
459-
simp [eq_iff_indep_iff_indep_forall]
459+
simp [ext_iff_indep]
460460

461461
lemma map_comap {f : α → β} (h_range : N.E ⊆ range f) (hf : InjOn f (f ⁻¹' N.E)) :
462462
(N.comap f).map f hf = N := by
463-
refine eq_of_indep_iff_indep_forall (by simpa [image_preimage_eq_iff]) ?_
463+
refine ext_indep (by simpa [image_preimage_eq_iff]) ?_
464464
simp only [map_ground, comap_ground_eq, map_indep_iff, comap_indep_iff, forall_subset_image_iff]
465465
refine fun I hI ↦ ⟨fun ⟨I₀, ⟨hI₀, _⟩, hII₀⟩ ↦ ?_, fun h ↦ ⟨_, ⟨h, hf.mono hI⟩, rfl⟩⟩
466466
suffices h : I₀ ⊆ f ⁻¹' N.E by rw [InjOn.image_eq_image_iff hf hI h] at hII₀; rwa [hII₀]
467467
exact (subset_preimage_image f I₀).trans <| preimage_mono (f := f) hI₀.subset_ground
468468

469469
lemma comap_map {f : α → β} (hf : f.Injective) : (M.map f hf.injOn).comap f = M := by
470-
simp [eq_iff_indep_iff_indep_forall, preimage_image_eq _ hf, and_iff_left hf.injOn,
470+
simp [ext_iff_indep, preimage_image_eq _ hf, and_iff_left hf.injOn,
471471
image_eq_image hf]
472472

473473
instance [M.Nonempty] {f : α → β} (hf) : (M.map f hf).Nonempty :=
@@ -672,7 +672,7 @@ lemma restrictSubtype_base_iff {B : Set X} : (M.restrictSubtype X).Base B ↔ M.
672672
lemma eq_of_restrictSubtype_eq {N : Matroid α} (hM : M.E = E) (hN : N.E = E)
673673
(h : M.restrictSubtype E = N.restrictSubtype E) : M = N := by
674674
subst hM
675-
refine eq_of_indep_iff_indep_forall (by rw [hN]) (fun I hI ↦ ?_)
675+
refine ext_indep (by rw [hN]) (fun I hI ↦ ?_)
676676
rwa [← restrictSubtype_indep_iff_of_subset hI, h, restrictSubtype_indep_iff_of_subset]
677677

678678
@[simp] lemma restrictSubtype_dual : (M.restrictSubtype M.E)✶ = M✶.restrictSubtype M.E := by

Mathlib/Data/Matroid/Restrict.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ theorem restrict_finite {R : Set α} (hR : R.Finite) : (M ↾ R).Finite :=
138138
rw [Dep, restrict_indep_iff, restrict_ground_eq]; tauto
139139

140140
@[simp] theorem restrict_ground_eq_self (M : Matroid α) : (M ↾ M.E) = M := by
141-
refine eq_of_indep_iff_indep_forall rfl ?_; aesop
141+
refine ext_indep rfl ?_; aesop
142142

143143
theorem restrict_restrict_eq {R₁ R₂ : Set α} (M : Matroid α) (hR : R₂ ⊆ R₁) :
144144
(M ↾ R₁) ↾ R₂ = M ↾ R₂ := by
145-
refine eq_of_indep_iff_indep_forall rfl ?_
145+
refine ext_indep rfl ?_
146146
simp only [restrict_ground_eq, restrict_indep_iff, and_congr_left_iff, and_iff_left_iff_imp]
147147
exact fun _ h _ _ ↦ h.trans hR
148148

@@ -195,7 +195,7 @@ theorem basis_restrict_iff (hR : R ⊆ M.E := by aesop_mat) :
195195

196196
theorem restrict_eq_restrict_iff (M M' : Matroid α) (X : Set α) :
197197
M ↾ X = M' ↾ X ↔ ∀ I, I ⊆ X → (M.Indep I ↔ M'.Indep I) := by
198-
refine ⟨fun h I hIX ↦ ?_, fun h ↦ eq_of_indep_iff_indep_forall rfl fun I (hI : I ⊆ X) ↦ ?_⟩
198+
refine ⟨fun h I hIX ↦ ?_, fun h ↦ ext_indep rfl fun I (hI : I ⊆ X) ↦ ?_⟩
199199
· rw [← and_iff_left (a := (M.Indep I)) hIX, ← and_iff_left (a := (M'.Indep I)) hIX,
200200
← restrict_indep_iff, h, restrict_indep_iff]
201201
rw [restrict_indep_iff, and_iff_left hI, restrict_indep_iff, and_iff_left hI, h _ hI]

0 commit comments

Comments
 (0)