Skip to content

Commit be04ab2

Browse files
committed
chore(Data/Sym2): improve defeq of diagSet (leanprover-community#32679)
leanprover-community#30559 introduced a regression on the defeqs in the `SimpleGraph` API. This PR fixes it. From LeanCamCombi
1 parent e9d4384 commit be04ab2

6 files changed

Lines changed: 52 additions & 45 deletions

File tree

Mathlib/Combinatorics/SimpleGraph/Acyclic.lean

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,11 @@ theorem maximal_isAcyclic_iff_reachable_eq {F : SimpleGraph V} (hF : F ≤ G) (h
426426
refine sup_le_iff.mpr ⟨by grind, ?_⟩
427427
rw [← F'.fromEdgeSet_edgeSet]
428428
grind [fromEdgeSet_mono]
429-
have e_ndiag : ¬ e.IsDiag := by
430-
suffices e ∈ Sym2.diagSetᶜ by simpa using this
431-
exact F'.edgeSet_subset_setOf_not_isDiag he.1
432429
have F_sdiff_eq : (F ⊔ fromEdgeSet {e}) \ fromEdgeSet {e} = F := by
433430
simpa using he.2
434431
have h_bridge : (F ⊔ fromEdgeSet {e}).IsBridge e := by
435432
apply isAcyclic_iff_forall_edge_isBridge.mp this
436-
simpa using Or.inr e_ndiag
433+
simp [F'.not_isDiag_of_mem_edgeSet he.1]
437434
simp only [IsBridge, F_sdiff_eq] at h_bridge
438435
cases e
439436
case h u v =>

Mathlib/Combinatorics/SimpleGraph/Basic.lean

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,11 @@ theorem edgeSet_top : (⊤ : SimpleGraph V).edgeSet = Sym2.diagSetᶜ :=
508508
Sym2.diagSet_compl_eq_fromRel_ne.symm
509509

510510
@[simp]
511-
theorem edgeSet_subset_setOf_not_isDiag : G.edgeSet ⊆ Sym2.diagSetᶜ :=
512-
Sym2.irreflexive_iff_fromRel_subset_diagSet_compl G.symm |>.mp G.loopless
511+
theorem edgeSet_subset_compl_diagSet : G.edgeSet ⊆ Sym2.diagSetᶜ := by
512+
simpa [Set.subset_compl_iff_disjoint_left, edgeSet, edgeSetEmbedding] using G.loopless
513+
514+
@[deprecated (since := "2025-12-10")]
515+
alias edgeSet_subset_setOf_not_isDiag := edgeSet_subset_compl_diagSet
513516

514517
@[simp]
515518
theorem edgeSet_sup : (G₁ ⊔ G₂).edgeSet = G₁.edgeSet ∪ G₂.edgeSet := by
@@ -542,7 +545,7 @@ allows proving `(G \ fromEdgeSet s).edgeSet = G.edgeSet \ s` by `simp`. -/
542545
@[simp]
543546
theorem edgeSet_sdiff_sdiff_isDiag (G : SimpleGraph V) (s : Set (Sym2 V)) :
544547
G.edgeSet \ (s \ Sym2.diagSet) = G.edgeSet \ s := by
545-
grind [Sym2.mem_diagSet_iff_isDiag, not_isDiag_of_mem_edgeSet]
548+
grind [Sym2.mem_diagSet, not_isDiag_of_mem_edgeSet]
546549

547550
/-- Two vertices are adjacent iff there is an edge between them. The
548551
condition `v ≠ w` ensures they are different endpoints of the edge,
@@ -666,7 +669,7 @@ theorem fromEdgeSet_mono {s t : Set (Sym2 V)} (h : s ⊆ t) : fromEdgeSet s ≤
666669
@[simp] lemma disjoint_fromEdgeSet : Disjoint G (fromEdgeSet s) ↔ Disjoint G.edgeSet s := by
667670
conv_rhs => rw [← Set.diff_union_inter s Sym2.diagSet]
668671
rw [← disjoint_edgeSet, edgeSet_fromEdgeSet]
669-
grind [edgeSet_subset_setOf_not_isDiag]
672+
grind [edgeSet_subset_compl_diagSet]
670673

671674
@[simp] lemma fromEdgeSet_disjoint : Disjoint (fromEdgeSet s) G ↔ Disjoint s G.edgeSet := by
672675
rw [disjoint_comm, disjoint_fromEdgeSet, disjoint_comm]

Mathlib/Combinatorics/SimpleGraph/DeleteEdges.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ lemma deleteIncidenceSet_le (G : SimpleGraph V) (x : V) : G.deleteIncidenceSet x
118118
lemma edgeSet_fromEdgeSet_incidenceSet (G : SimpleGraph V) (x : V) :
119119
(fromEdgeSet (G.incidenceSet x)).edgeSet = G.incidenceSet x := by
120120
rw [edgeSet_fromEdgeSet, sdiff_eq_left, ← Set.subset_compl_iff_disjoint_right]
121-
exact (incidenceSet_subset G x).trans G.edgeSet_subset_setOf_not_isDiag
121+
exact (incidenceSet_subset G x).trans G.edgeSet_subset_compl_diagSet
122122

123123
/-- The edge set of `G.deleteIncidenceSet x` is the edge set of `G` set difference the incidence
124124
set of the vertex `x`. -/

Mathlib/Combinatorics/SimpleGraph/Operations.lean

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ lemma edge_le_iff {v w : V} : edge v w ≤ G ↔ v = w ∨ G.Adj v w := by
168168

169169
variable {s t}
170170

171-
lemma edge_edgeSet_of_ne (h : s ≠ t) : (edge s t).edgeSet = {s(s, t)} := by
172-
rwa [edge, edgeSet_fromEdgeSet, sdiff_eq_left, Set.disjoint_singleton_left,
173-
Sym2.mem_diagSet_iff_eq]
171+
lemma edge_edgeSet_of_ne (h : s ≠ t) : (edge s t).edgeSet = {s(s, t)} := by simpa [edge]
174172

175173
lemma sup_edge_of_adj (h : G.Adj s t) : G ⊔ edge s t = G := by
176174
rwa [sup_eq_left, ← edgeSet_subset_edgeSet, edge_edgeSet_of_ne h.ne, Set.singleton_subset_iff,

Mathlib/Data/Sym/Card.lean

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,8 @@ theorem card_subtype_not_diag [Fintype α] :
174174
obtain ⟨a, ha⟩ := Quot.exists_rep x
175175
exact and_iff_right ⟨a, mem_univ _, ha⟩
176176

177-
theorem card_diagSet_compl [Fintype α] :
178-
Fintype.card ((@Sym2.diagSet α)ᶜ : Set _) = (card α).choose 2 := by
179-
simp only [← card_subtype_not_diag, Sym2.diagSet_compl_eq_setOf_not_isDiag, Set.coe_setOf]
177+
lemma card_diagSet_compl [Fintype α] : card (diagSetᶜ : Set (Sym2 α)) = (card α).choose 2 :=
178+
card_subtype_not_diag
180179

181180
/-- Type **stars and bars** for the case `n = 2`. -/
182181
protected theorem card {α} [Fintype α] : card (Sym2 α) = Nat.choose (card α + 1) 2 :=

Mathlib/Data/Sym/Sym2.lean

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ lemma attachWith_map_subtypeVal {s : Sym2 α} {P : α → Prop} (h : ∀ a ∈ s
483483

484484
/-! ### Diagonal -/
485485

486-
variable {e : Sym2 α} {f : α → β}
486+
variable {z : Sym2 α} {f : α → β}
487487

488488
/-- A type `α` is naturally included in the diagonal of `α × α`, and this function gives the image
489489
of this diagonal in `Sym2 α`.
@@ -505,49 +505,51 @@ theorem mk_isDiag_iff {x y : α} : IsDiag s(x, y) ↔ x = y :=
505505
theorem isDiag_iff_proj_eq (z : α × α) : IsDiag (Sym2.mk z) ↔ z.1 = z.2 :=
506506
Prod.recOn z fun _ _ => mk_isDiag_iff
507507

508-
protected lemma IsDiag.map : e.IsDiag → (e.map f).IsDiag := Sym2.ind (fun _ _ ↦ congr_arg f) e
508+
protected lemma IsDiag.map : z.IsDiag → (z.map f).IsDiag := Sym2.ind (fun _ _ ↦ congr_arg f) z
509509

510-
lemma isDiag_map (hf : Injective f) : (e.map f).IsDiag ↔ e.IsDiag :=
511-
Sym2.ind (fun _ _ ↦ hf.eq_iff) e
510+
lemma isDiag_map (hf : Injective f) : (z.map f).IsDiag ↔ z.IsDiag :=
511+
Sym2.ind (fun _ _ ↦ hf.eq_iff) z
512512

513513
@[simp]
514514
theorem diag_isDiag (a : α) : IsDiag (diag a) :=
515515
Eq.refl a
516516

517-
theorem isDiag_of_subsingleton [Subsingleton α] (z : Sym2 α) : z.IsDiag :=
518-
z.ind Subsingleton.elim
517+
@[simp, nontriviality]
518+
lemma isDiag_of_subsingleton [Subsingleton α] (z : Sym2 α) : z.IsDiag := z.ind Subsingleton.elim
519519

520520
/-- The set of all `Sym2 α` elements on the diagonal. -/
521-
def diagSet : Set (Sym2 α) :=
522-
Set.range diag
521+
def diagSet : Set (Sym2 α) := {z | z.IsDiag}
523522

524-
@[simp]
525-
theorem mem_diagSet_iff_isDiag (z : Sym2 α) : z ∈ diagSet ↔ z.IsDiag :=
526-
fun ⟨_, h⟩ ↦ h ▸ rfl, z.ind fun a b (h : a = b) ↦ ⟨a, h ▸ rfl⟩⟩
523+
@[simp] lemma mem_diagSet : z ∈ diagSet ↔ z.IsDiag := .rfl
524+
525+
@[deprecated mem_diagSet (since := "2025-12-10")]
526+
theorem mem_diagSet_iff_isDiag (z : Sym2 α) : z ∈ diagSet ↔ z.IsDiag := .rfl
527+
528+
@[simp] lemma range_diag : .range (diag : α → Sym2 α) = diagSet := by
529+
ext ⟨a, b⟩; simp [diag, eq_comm]
527530

528531
@[deprecated (since := "2025-11-05")] alias ⟨_, IsDiag.mem_range_diag⟩ := mem_diagSet_iff_isDiag
529532

530-
@[deprecated mem_diagSet_iff_isDiag (since := "2025-11-05")]
531-
theorem isDiag_iff_mem_range_diag (z : Sym2 α) : IsDiag z ↔ z ∈ Set.range (@diag α) :=
532-
z.mem_diagSet_iff_isDiag.symm
533+
@[deprecated range_diag (since := "2025-11-05")]
534+
theorem isDiag_iff_mem_range_diag (z : Sym2 α) : IsDiag z ↔ z ∈ Set.range (@diag α) := by simp
533535

534-
theorem mem_diagSet_iff_eq {a b : α} : s(a, b) ∈ diagSet ↔ a = b := by
535-
simp
536+
@[deprecated mem_diagSet (since := "2025-11-05")]
537+
theorem mem_diagSet_iff_eq {a b : α} : s(a, b) ∈ diagSet ↔ a = b := by simp
536538

537-
theorem diagSet_eq_setOf_isDiag : diagSet = {z : Sym2 α | z.IsDiag} :=
538-
Set.ext mem_diagSet_iff_isDiag
539+
theorem diagSet_eq_setOf_isDiag : diagSet = {z : Sym2 α | z.IsDiag} := rfl
539540

541+
set_option linter.deprecated false in
542+
@[deprecated Set.compl_setOf (since := "2025-12-10")]
540543
theorem diagSet_compl_eq_setOf_not_isDiag : diagSetᶜ = {z : Sym2 α | ¬z.IsDiag} :=
541544
congrArg _ diagSet_eq_setOf_isDiag
542545

543-
theorem diagSet_eq_univ_of_subsingleton [Subsingleton α] : @diagSet α = Set.univ :=
544-
Set.ext fun z ↦ ⟨fun _ ↦ trivial, z.ind fun a b _ ↦ Subsingleton.elim a b ▸ ⟨_, rfl⟩⟩
546+
theorem diagSet_eq_univ_of_subsingleton [Subsingleton α] : @diagSet α = Set.univ := by ext; simp
545547

546548
instance IsDiag.decidablePred (α : Type u) [DecidableEq α] : DecidablePred (@IsDiag α) :=
547549
fun z => z.recOnSubsingleton fun a => decidable_of_iff' _ (isDiag_iff_proj_eq a)
548550

549-
instance diagSet_decidablePred (α : Type u) [DecidableEq α] : DecidablePred (· ∈ @diagSet α) :=
550-
diagSet_eq_setOf_isDiag ▸ IsDiag.decidablePred _
551+
instance decidablePred_mem_diagSet (α : Type u) [DecidableEq α] : DecidablePred (· ∈ @diagSet α) :=
552+
IsDiag.decidablePred _
551553

552554
theorem other_ne {a : α} {z : Sym2 α} (hd : ¬IsDiag z) (h : a ∈ z) : Mem.other h ≠ a := by
553555
contrapose! hd
@@ -600,20 +602,28 @@ theorem fromRel_ne : fromRel (fun (_ _ : α) z => z.symm : Symmetric Ne) = {z |
600602
ext z; exact z.ind (by simp)
601603

602604
lemma diagSet_eq_fromRel_eq : diagSet = fromRel (α := α) eq_equivalence.symmetric := by
603-
ext z
604-
exact z.ind fun _ _ ↦ mem_diagSet_iff_eq
605+
ext ⟨a, b⟩; simp
605606

606607
lemma diagSet_compl_eq_fromRel_ne : diagSetᶜ = fromRel (α := α) (r := Ne) (fun _ _ ↦ Ne.symm) := by
607-
ext z
608-
exact z.ind fun _ _ ↦ mem_diagSet_iff_eq.not
608+
ext ⟨a, b⟩; simp
609+
610+
@[simp] lemma diagSet_subset_fromRel (hr : Symmetric r) : diagSet ⊆ fromRel hr ↔ Reflexive r := by
611+
simp [Set.subset_def, Sym2.forall, Reflexive]
612+
613+
@[simp] lemma disjoint_diagSet_fromRel (hr : Symmetric r) :
614+
Disjoint diagSet (fromRel hr) ↔ Irreflexive r := by
615+
simp [Set.disjoint_left, Sym2.forall, Irreflexive]
616+
617+
@[simp] lemma fromRel_subset_compl_diagSet (hr : Symmetric r) :
618+
fromRel hr ⊆ diagSetᶜ ↔ Irreflexive r := by simp [Set.subset_compl_iff_disjoint_left]
609619

620+
@[deprecated diagSet_subset_fromRel (since := "2025-12-10")]
610621
theorem reflexive_iff_diagSet_subset_fromRel (sym : Symmetric r) :
611-
Reflexive r ↔ diagSet ⊆ fromRel sym :=
612-
fun hr _ ⟨_, hd⟩ ↦ hd ▸ hr _, fun h _ ↦ h ⟨_, rfl⟩⟩
622+
Reflexive r ↔ diagSet ⊆ fromRel sym := by simp
613623

624+
@[deprecated fromRel_subset_compl_diagSet (since := "2025-12-10")]
614625
theorem irreflexive_iff_fromRel_subset_diagSet_compl (sym : Symmetric r) :
615-
Irreflexive r ↔ fromRel sym ⊆ diagSetᶜ :=
616-
fun hr _ hz ⟨_, hd⟩ ↦ hr _ <| fromRel_prop.mp <| hd ▸ hz, fun h _ ha ↦ h ha ⟨_, rfl⟩⟩
626+
Irreflexive r ↔ fromRel sym ⊆ diagSetᶜ := by simp
617627

618628
theorem fromRel_irreflexive {sym : Symmetric r} :
619629
Irreflexive r ↔ ∀ {z}, z ∈ fromRel sym → ¬IsDiag z :=

0 commit comments

Comments
 (0)