Skip to content

Commit 2badb0c

Browse files
committed
fix(SetTheory/ZFC/Basic): fix diamond for Membership ZFSet ZFSet (leanprover-community#36734)
This PR removes the manual instance of `Membership ZFSet ZFSet` in favour of the instance that comes from the `SetLike` instance. The two instances are not defeq in `implicit_reducible` transparency, hence causing a diamond (it relies on the defeq of `{x | x ∈ s}` with `s`). This change also helps remove a lot of the `respectTransparency` options. I've extended the PR with a little more defeq-abuse cleanup.
1 parent e960b84 commit 2badb0c

4 files changed

Lines changed: 24 additions & 45 deletions

File tree

Mathlib/SetTheory/ZFC/Basic.lean

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -167,32 +167,30 @@ theorem sound {x y : PSet} (h : PSet.Equiv x y) : mk x = mk y :=
167167
theorem exact {x y : PSet} : mk x = mk y → PSet.Equiv x y :=
168168
Quotient.exact
169169

170-
/-- The membership relation for ZFC sets is inherited from the membership relation for pre-sets. -/
171-
protected def Mem : ZFSet → ZFSet → Prop :=
172-
Quotient.lift₂ (· ∈ ·) fun _ _ _ _ hx hy =>
173-
propext ((Mem.congr_left hx).trans (Mem.congr_right hy))
170+
/-- Convert a ZFC set into a `Set` of ZFC sets -/
171+
def toSet (x : ZFSet) : Set ZFSet :=
172+
{y | Quotient.lift₂ (· ∈ ·) (fun _ _ _ _ hx hy =>
173+
propext ((Mem.congr_left hx).trans (Mem.congr_right hy))) y x}
174+
175+
private lemma ext_aux : (∀ z : ZFSet.{u}, z ∈ x.toSet ↔ z ∈ y.toSet) → x = y :=
176+
Quotient.inductionOn₂ x y fun _ _ h => Quotient.sound (Mem.ext fun w => h ⟦w⟧)
177+
178+
instance : SetLike ZFSet.{u} ZFSet.{u} where
179+
coe := toSet
180+
coe_injective' x y hxy := by apply ext_aux; intro z; exact congr(z ∈ $hxy)
174181

175-
instance : Membership ZFSet ZFSet where
176-
mem t s := ZFSet.Mem s t
182+
/-- The membership relation for ZFC sets is inherited from the membership relation for pre-sets. -/
183+
@[deprecated "use `∈` notation" (since := "2026-03-16")]
184+
protected def Mem : ZFSet → ZFSet → Prop := (· ∈ ·)
177185

178186
@[simp]
179187
theorem mk_mem_iff {x y : PSet} : mk x ∈ mk y ↔ x ∈ y :=
180188
Iff.rfl
181189

182-
@[ext] lemma ext : (∀ z : ZFSet.{u}, z ∈ x ↔ z ∈ y) → x = y :=
183-
Quotient.inductionOn₂ x y fun _ _ h => Quotient.sound (Mem.ext fun w => h ⟦w⟧)
184-
185-
instance : SetLike ZFSet.{u} ZFSet.{u} where
186-
coe x := {y | y ∈ x}
187-
coe_injective' x y hxy := by ext z; exact congr(z ∈ $hxy)
190+
@[ext] lemma ext : (∀ z : ZFSet.{u}, z ∈ x ↔ z ∈ y) → x = y := ext_aux
188191

189192
instance : PartialOrder ZFSet.{u} := .ofSetLike ZFSet.{u} ZFSet.{u}
190193

191-
/-- Convert a ZFC set into a `Set` of ZFC sets -/
192-
@[deprecated SetLike.coe (since := "2025-11-05")]
193-
def toSet (u : ZFSet.{u}) : Set ZFSet.{u} :=
194-
{ x | x ∈ u }
195-
196194
@[deprecated SetLike.mem_coe (since := "2025-11-05")]
197195
theorem mem_toSet (a u : ZFSet.{u}) : a ∈ (u : Set ZFSet.{u}) ↔ a ∈ u :=
198196
Iff.rfl
@@ -279,7 +277,6 @@ instance : Inhabited ZFSet :=
279277
theorem notMem_empty (x) : x ∉ (∅ : ZFSet.{u}) :=
280278
Quotient.inductionOn x PSet.notMem_empty
281279

282-
set_option backward.isDefEq.respectTransparency false in
283280
@[simp, norm_cast] lemma coe_empty : ((∅ : ZFSet.{u}) : Set ZFSet.{u}) = ∅ := by ext; simp
284281

285282
@[deprecated (since := "2025-11-05")] alias toSet_empty := coe_empty
@@ -341,7 +338,6 @@ theorem mem_insert (x y : ZFSet) : x ∈ insert x y :=
341338
theorem mem_insert_of_mem {y z : ZFSet} (x) (h : z ∈ y) : z ∈ insert x y :=
342339
mem_insert_iff.2 <| Or.inr h
343340

344-
set_option backward.isDefEq.respectTransparency false in
345341
@[simp, norm_cast]
346342
lemma coe_insert (x y : ZFSet) : ↑(insert x y) = (insert x ↑y : Set ZFSet) := by ext; simp
347343

@@ -354,7 +350,6 @@ theorem mem_singleton {x y : ZFSet.{u}} : x ∈ ({y} : ZFSet.{u}) ↔ x = y :=
354350
theorem notMem_singleton {x y : ZFSet.{u}} : x ∉ ({y} : ZFSet.{u}) ↔ x ≠ y :=
355351
mem_singleton.not
356352

357-
set_option backward.isDefEq.respectTransparency false in
358353
@[simp, norm_cast]
359354
lemma coe_singleton (x : ZFSet) : (({x} : ZFSet) : Set ZFSet) = {x} := by ext; simp
360355

@@ -432,7 +427,6 @@ theorem sep_empty (p : ZFSet → Prop) : (∅ : ZFSet).sep p = ∅ :=
432427
theorem sep_subset {x p} : ZFSet.sep p x ⊆ x :=
433428
fun _ h => (mem_sep.1 h).1
434429

435-
set_option backward.isDefEq.respectTransparency false in
436430
@[simp, norm_cast]
437431
lemma coe_sep (a : ZFSet) (p : ZFSet → Prop) : (ZFSet.sep p a : Set ZFSet) = {x ∈ a | p x} := by
438432
ext
@@ -534,15 +528,13 @@ theorem sUnion_singleton {x : ZFSet.{u}} : ⋃₀ ({x} : ZFSet) = x :=
534528
theorem sInter_singleton {x : ZFSet.{u}} : ⋂₀ ({x} : ZFSet) = x :=
535529
ext fun y => by simp_rw [mem_sInter (singleton_nonempty x), mem_singleton, forall_eq]
536530

537-
set_option backward.isDefEq.respectTransparency false in
538531
@[simp, norm_cast]
539532
lemma coe_sUnion (x : ZFSet.{u}) : (⋃₀ x : Set ZFSet) = ⋃₀ (SetLike.coe '' (x : Set ZFSet)) := by
540533
ext
541534
simp
542535

543536
@[deprecated (since := "2025-11-05")] alias toSet_sUnion := coe_sUnion
544537

545-
set_option backward.isDefEq.respectTransparency false in
546538
@[simp, norm_cast]
547539
lemma coe_sInter (h : x.Nonempty) : (⋂₀ x : Set ZFSet) = ⋂₀ (SetLike.coe '' (x : Set ZFSet)) := by
548540
ext
@@ -590,19 +582,16 @@ instance : SDiff ZFSet :=
590582

591583
@[deprecated (since := "2025-11-06")] alias mem_diff := mem_sdiff
592584

593-
set_option backward.isDefEq.respectTransparency false in
594585
@[simp, norm_cast]
595586
lemma coe_union (x y : ZFSet.{u}) : ↑(x ∪ y) = (↑x ∪ ↑y : Set ZFSet) := by ext; simp
596587

597588
@[deprecated (since := "2025-11-05")] alias toSet_union := coe_union
598589

599-
set_option backward.isDefEq.respectTransparency false in
600590
@[simp, norm_cast]
601591
lemma coe_inter (x y : ZFSet.{u}) : ↑(x ∩ y) = (↑x ∩ ↑y : Set ZFSet) := by ext; simp
602592

603593
@[deprecated (since := "2025-11-05")] alias toSet_inter := coe_inter
604594

605-
set_option backward.isDefEq.respectTransparency false in
606595
@[simp, norm_cast]
607596
lemma coe_sdiff (x y : ZFSet.{u}) : ↑(x \ y) = (↑x \ ↑y : Set ZFSet) := by ext; simp
608597

@@ -611,7 +600,6 @@ lemma coe_sdiff (x y : ZFSet.{u}) : ↑(x \ y) = (↑x \ ↑y : Set ZFSet) := by
611600
@[simp] lemma inter_eq_left_of_subset (hxy : x ⊆ y) : x ∩ y = x := by ext; simpa using @hxy _
612601
@[simp] lemma inter_eq_right_of_subset (hyx : y ⊆ x) : x ∩ y = y := by ext; simpa using @hyx _
613602

614-
set_option backward.isDefEq.respectTransparency false in
615603
/-- `ZFSet.powerset` is equivalent to `Set.powerset`. -/
616604
def powersetEquiv (x : ZFSet.{u}) : x.powerset ≃ 𝒫 (x : Set ZFSet) where
617605
toFun y := ⟨y.1, Set.mem_powerset (mem_powerset.1 y.2)⟩
@@ -681,7 +669,6 @@ theorem mem_image {f : ZFSet.{u} → ZFSet.{u}} [Definable₁ f] {x y : ZFSet.{u
681669
fun ⟨a, ya⟩ => ⟨⟦A a⟧, Mem.mk A a, ((Quotient.sound ya).trans Definable₁.mk_out).symm⟩,
682670
fun ⟨_, hz, e⟩ => e ▸ image.mk _ _ hz⟩
683671

684-
set_option backward.isDefEq.respectTransparency false in
685672
@[simp, norm_cast]
686673
lemma coe_image (f : ZFSet → ZFSet) [Definable₁ f] (x : ZFSet) :
687674
(image f x : Set ZFSet) = f '' x := by ext; simp
@@ -706,7 +693,6 @@ theorem mem_range {f : α → ZFSet.{u}} {x : ZFSet.{u}} : x ∈ range f ↔ ∃
706693
use equivShrink α z
707694
simpa [hz] using PSet.Equiv.symm (Quotient.mk_out y)
708695

709-
set_option backward.isDefEq.respectTransparency false in
710696
@[simp, norm_cast]
711697
lemma coe_range (f : α → ZFSet.{u}) : (range f : Set ZFSet) = .range f := by ext; simp
712698

@@ -724,7 +710,6 @@ noncomputable def iUnion (f : α → ZFSet.{u}) : ZFSet.{u} :=
724710
theorem mem_iUnion {f : α → ZFSet.{u}} {x : ZFSet.{u}} : x ∈ ⋃ i, f i ↔ ∃ i, x ∈ f i := by
725711
simp [iUnion]
726712

727-
set_option backward.isDefEq.respectTransparency false in
728713
@[simp, norm_cast]
729714
lemma coe_iUnion (f : α → ZFSet.{u}) : ↑(⋃ i, f i) = ⋃ i, (f i : Set ZFSet) := by
730715
ext

Mathlib/SetTheory/ZFC/Cardinal.lean

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,15 @@ theorem cardinalMk_coe_sort : #x = lift.{u + 1, u} (card x) := by
3939
theorem card_mono (h : x ⊆ y) : card x ≤ card y := by
4040
simpa [cardinalMk_coe_sort] using mk_le_mk_of_subset (coe_subset_coe.2 h)
4141

42-
set_option backward.isDefEq.respectTransparency false in
4342
@[simp]
4443
theorem card_empty : card ∅ = 0 := by
4544
rw [← lift_inj, ← cardinalMk_coe_sort]
4645
simp
4746

48-
set_option backward.isDefEq.respectTransparency false in
4947
theorem card_insert_le : card (insert x y) ≤ card y + 1 := by
5048
rw [← lift_le.{u + 1}]
5149
simpa [← cardinalMk_coe_sort] using mk_insert_le
5250

53-
set_option backward.isDefEq.respectTransparency false in
5451
theorem card_insert (h : x ∉ y) : card (insert x y) = card y + 1 := by
5552
rw [← lift_inj.{u, u + 1}]
5653
simpa [← cardinalMk_coe_sort] using mk_insert (SetLike.mem_coe.not.2 h)
@@ -63,7 +60,6 @@ theorem card_pair_of_ne (h : x ≠ y) : card {x, y} = 2 := by
6360
convert card_insert (notMem_singleton.2 h)
6461
rw [card_singleton, one_add_one_eq_two]
6562

66-
set_option backward.isDefEq.respectTransparency false in
6763
theorem card_union_le : card (x ∪ y) ≤ card x + card y := by
6864
rw [← lift_le.{u + 1}]
6965
simpa [← cardinalMk_coe_sort] using mk_union_le (x : Set ZFSet) y

Mathlib/SetTheory/ZFC/Class.lean

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ instance : Coe ZFSet Class :=
6262
def univ : Class :=
6363
Set.univ
6464

65+
instance : Top Class := ⟨univ⟩
66+
67+
deriving instance CompleteLattice for Class
68+
6569
/-- Assert that `A` is a ZFC set satisfying `B` -/
6670
def ToSet (B : Class.{u}) (A : Class.{u}) : Prop :=
6771
∃ x : ZFSet, ↑x = A ∧ B x
@@ -148,15 +152,15 @@ def powerset (x : Class) : Class :=
148152
/-- The union of a class is the class of all members of ZFC sets in the class. Uses `⋃₀` notation,
149153
scoped under the `Class` namespace. -/
150154
def sUnion (x : Class) : Class :=
151-
⋃₀ classToCong x
155+
sSup (classToCong x)
152156

153157
@[inherit_doc]
154158
scoped prefix:110 "⋃₀ " => Class.sUnion
155159

156160
/-- The intersection of a class is the class of all members of ZFC sets in the class .
157161
Uses `⋂₀` notation, scoped under the `Class` namespace. -/
158162
def sInter (x : Class) : Class :=
159-
⋂₀ classToCong x
163+
sInf (classToCong x)
160164

161165
@[inherit_doc]
162166
scoped prefix:110 "⋂₀ " => Class.sInter
@@ -263,10 +267,9 @@ theorem sUnion_empty : ⋃₀ (∅ : Class.{u}) = (∅ : Class.{u}) := by
263267
ext
264268
simp
265269

266-
set_option backward.isDefEq.respectTransparency false in
267270
@[simp]
268271
theorem sInter_empty : ⋂₀ (∅ : Class.{u}) = univ := by
269-
rw [sInter, classToCong_empty, Set.sInter_empty, univ]
272+
simp [sInter, Top.top]
270273

271274
/-- An induction principle for sets. If every subset of a class is a member, then the class is
272275
universal. -/
@@ -345,8 +348,6 @@ theorem choice_mem (h : ∅ ∉ x) (y : ZFSet.{u}) (yx : y ∈ x) :
345348
rw [@map_fval _ (Classical.allZFSetDefinable _) x y yx, Class.coe_mem, Class.coe_apply]
346349
exact choice_mem_aux x h y yx
347350

348-
set_option backward.isDefEq.respectTransparency false in
349-
set_option backward.privateInPublic true in
350351
private lemma coe_equiv_aux {s : Set ZFSet.{u}} (hs : Small.{u} s) :
351352
(mk <| PSet.mk (Shrink s) fun x ↦ ((equivShrink s).symm x).1.out) = s := by
352353
ext x
@@ -357,16 +358,14 @@ private lemma coe_equiv_aux {s : Set ZFSet.{u}} (hs : Small.{u} s) :
357358
simp [h2]
358359
· simp [PSet.Equiv.refl]
359360

360-
set_option backward.privateInPublic true in
361-
set_option backward.privateInPublic.warn false in
362361
/-- `SetLike.coe` as an equivalence. -/
363362
@[simps apply_coe]
364363
noncomputable def coeEquiv : ZFSet.{u} ≃ {s : Set ZFSet.{u} // Small.{u, u+1} s} where
365364
toFun x := ⟨x, x.small_coe⟩
366365
invFun := fun ⟨s, _⟩ ↦ mk <| PSet.mk (Shrink s) fun x ↦ ((equivShrink.{u, u + 1} s).symm x).1.out
367-
left_inv := Function.rightInverse_of_injective_of_leftInverse (by intro _ _; simp)
366+
left_inv := private Function.rightInverse_of_injective_of_leftInverse (by intro _ _; simp)
368367
fun s ↦ Subtype.coe_injective <| coe_equiv_aux s.2
369-
right_inv s := Subtype.coe_injective <| coe_equiv_aux s.2
368+
right_inv s := private Subtype.coe_injective <| coe_equiv_aux s.2
370369

371370
@[deprecated (since := "2025-11-05")] alias toSet_equiv := coeEquiv
372371

Mathlib/SetTheory/ZFC/Ordinal.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ theorem mem_toZFSet_iff {o : Ordinal} {x : ZFSet} : x ∈ o.toZFSet ↔ ∃ a <
321321
theorem rank_toZFSet (o : Ordinal) : o.toZFSet.rank = o :=
322322
rank_toPSet o
323323

324-
set_option backward.isDefEq.respectTransparency false in
325324
@[simp]
326325
theorem coe_toZFSet {o : Ordinal} : o.toZFSet = toZFSet '' Iio o := by
327326
ext

0 commit comments

Comments
 (0)