Skip to content

Commit c5797bd

Browse files
committed
feat(Combinatorics/SimpleGraph): use Sym2.diagSet instead of explicit sets (#32255)
1 parent b6b88ca commit c5797bd

File tree

6 files changed

+28
-23
lines changed

6 files changed

+28
-23
lines changed

Mathlib/Combinatorics/SimpleGraph/Basic.lean

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,12 @@ theorem edgeSet_bot : (⊥ : SimpleGraph V).edgeSet = ∅ :=
462462
Sym2.fromRel_bot
463463

464464
@[simp]
465-
theorem edgeSet_top : (⊤ : SimpleGraph V).edgeSet = {e | ¬e.IsDiag} :=
466-
Sym2.fromRel_ne
465+
theorem edgeSet_top : (⊤ : SimpleGraph V).edgeSet = Sym2.diagSetᶜ :=
466+
Sym2.diagSet_compl_eq_fromRel_ne.symm
467467

468468
@[simp]
469-
theorem edgeSet_subset_setOf_not_isDiag : G.edgeSet ⊆ {e | ¬e.IsDiag} :=
470-
fun _ h => (Sym2.fromRel_irreflexive (sym := G.symm)).mp G.loopless h
469+
theorem edgeSet_subset_setOf_not_isDiag : G.edgeSet ⊆ Sym2.diagSetᶜ :=
470+
Sym2.irreflexive_iff_fromRel_subset_diagSet_compl G.symm |>.mp G.loopless
471471

472472
@[simp]
473473
theorem edgeSet_sup : (G₁ ⊔ G₂).edgeSet = G₁.edgeSet ∪ G₂.edgeSet := by
@@ -495,15 +495,12 @@ variable {G G₁ G₂}
495495
@[simp] lemma edgeSet_nonempty : G.edgeSet.Nonempty ↔ G ≠ ⊥ := by
496496
rw [Set.nonempty_iff_ne_empty, edgeSet_eq_empty.ne]
497497

498-
/-- This lemma, combined with `edgeSet_sdiff` and `edgeSet_from_edgeSet`,
499-
allows proving `(G \ from_edgeSet s).edge_set = G.edgeSet \ s` by `simp`. -/
498+
/-- This lemma, combined with `edgeSet_sdiff` and `edgeSet_fromEdgeSet`,
499+
allows proving `(G \ fromEdgeSet s).edgeSet = G.edgeSet \ s` by `simp`. -/
500500
@[simp]
501501
theorem edgeSet_sdiff_sdiff_isDiag (G : SimpleGraph V) (s : Set (Sym2 V)) :
502-
G.edgeSet \ (s \ { e | e.IsDiag }) = G.edgeSet \ s := by
503-
ext e
504-
simp only [Set.mem_diff, Set.mem_setOf_eq, not_and, not_not, and_congr_right_iff]
505-
intro h
506-
simp only [G.not_isDiag_of_mem_edgeSet h, imp_false]
502+
G.edgeSet \ (s \ Sym2.diagSet) = G.edgeSet \ s := by
503+
grind [Sym2.mem_diagSet_iff_isDiag, not_isDiag_of_mem_edgeSet]
507504

508505
/-- Two vertices are adjacent iff there is an edge between them. The
509506
condition `v ≠ w` ensures they are different endpoints of the edge,
@@ -579,7 +576,7 @@ theorem fromEdgeSet_adj : (fromEdgeSet s).Adj v w ↔ s(v, w) ∈ s ∧ v ≠ w
579576
-- Note: we need to make sure `fromEdgeSet_adj` and this lemma are confluent.
580577
-- In particular, both yield `s(u, v) ∈ (fromEdgeSet s).edgeSet` ==> `s(v, w) ∈ s ∧ v ≠ w`.
581578
@[simp]
582-
theorem edgeSet_fromEdgeSet : (fromEdgeSet s).edgeSet = s \ { e | e.IsDiag } := by
579+
theorem edgeSet_fromEdgeSet : (fromEdgeSet s).edgeSet = s \ Sym2.diagSet := by
583580
ext e
584581
exact Sym2.ind (by simp) e
585582

@@ -589,9 +586,9 @@ theorem fromEdgeSet_edgeSet : fromEdgeSet G.edgeSet = G := by
589586
exact ⟨fun h => h.1, fun h => ⟨h, G.ne_of_adj h⟩⟩
590587

591588
@[simp] lemma fromEdgeSet_le {s : Set (Sym2 V)} :
592-
fromEdgeSet s ≤ G ↔ s \ {e | e.IsDiag} ⊆ G.edgeSet := by simp [← edgeSet_subset_edgeSet]
589+
fromEdgeSet s ≤ G ↔ s \ Sym2.diagSet ⊆ G.edgeSet := by simp [← edgeSet_subset_edgeSet]
593590

594-
lemma edgeSet_eq_iff : G.edgeSet = s ↔ G = fromEdgeSet s ∧ Disjoint s {e | e.IsDiag} where
591+
lemma edgeSet_eq_iff : G.edgeSet = s ↔ G = fromEdgeSet s ∧ Disjoint s Sym2.diagSet where
595592
mp := by rintro rfl; simp +contextual [Set.disjoint_right]
596593
mpr := by rintro ⟨rfl, hs⟩; simp [hs]
597594

@@ -600,7 +597,7 @@ theorem fromEdgeSet_empty : fromEdgeSet (∅ : Set (Sym2 V)) = ⊥ := by
600597
ext v w
601598
simp only [fromEdgeSet_adj, Set.mem_empty_iff_false, false_and, bot_adj]
602599

603-
@[simp] lemma fromEdgeSet_not_isDiag : fromEdgeSet {e : Sym2 V | ¬ e.IsDiag} = ⊤ := by ext; simp
600+
@[simp] lemma fromEdgeSet_not_isDiag : @fromEdgeSet V Sym2.diagSetᶜ = ⊤ := by ext; simp
604601

605602
@[simp]
606603
theorem fromEdgeSet_univ : fromEdgeSet (Set.univ : Set (Sym2 V)) = ⊤ := by
@@ -634,9 +631,9 @@ theorem fromEdgeSet_mono {s t : Set (Sym2 V)} (h : s ⊆ t) : fromEdgeSet s ≤
634631
exact fun vws _ => h vws
635632

636633
@[simp] lemma disjoint_fromEdgeSet : Disjoint G (fromEdgeSet s) ↔ Disjoint G.edgeSet s := by
637-
conv_rhs => rw [← Set.diff_union_inter s {e : Sym2 V | e.IsDiag}]
638-
rw [← disjoint_edgeSet, edgeSet_fromEdgeSet, Set.disjoint_union_right, and_iff_left]
639-
exact Set.disjoint_left.2 fun e he he' ↦ not_isDiag_of_mem_edgeSet _ he he'.2
634+
conv_rhs => rw [← Set.diff_union_inter s Sym2.diagSet]
635+
rw [← disjoint_edgeSet, edgeSet_fromEdgeSet]
636+
grind [edgeSet_subset_setOf_not_isDiag]
640637

641638
@[simp] lemma fromEdgeSet_disjoint : Disjoint (fromEdgeSet s) G ↔ Disjoint s G.edgeSet := by
642639
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
@@ -110,7 +110,7 @@ lemma deleteIncidenceSet_le (G : SimpleGraph V) (x : V) : G.deleteIncidenceSet x
110110

111111
lemma edgeSet_fromEdgeSet_incidenceSet (G : SimpleGraph V) (x : V) :
112112
(fromEdgeSet (G.incidenceSet x)).edgeSet = G.incidenceSet x := by
113-
rw [edgeSet_fromEdgeSet, sdiff_eq_left, ← Set.subset_compl_iff_disjoint_right, Set.compl_setOf]
113+
rw [edgeSet_fromEdgeSet, sdiff_eq_left, ← Set.subset_compl_iff_disjoint_right]
114114
exact (incidenceSet_subset G x).trans G.edgeSet_subset_setOf_not_isDiag
115115

116116
/-- The edge set of `G.deleteIncidenceSet x` is the edge set of `G` set difference the incidence

Mathlib/Combinatorics/SimpleGraph/Finite.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ variable [Fintype V]
120120

121121
@[simp]
122122
theorem edgeFinset_top [DecidableEq V] :
123-
(⊤ : SimpleGraph V).edgeFinset = ({e | ¬e.IsDiag} : Finset _) := by simp [← coe_inj]
123+
(⊤ : SimpleGraph V).edgeFinset = Sym2.diagSetᶜ.toFinset := by simp [← coe_inj]
124124

125125
/-- The complete graph on `n` vertices has `n.choose 2` edges. -/
126126
theorem card_edgeFinset_top_eq_card_choose_two [DecidableEq V] :
127127
#(⊤ : SimpleGraph V).edgeFinset = (Fintype.card V).choose 2 := by
128-
simp_rw [Set.toFinset_card, edgeSet_top, Set.coe_setOf, ← Sym2.card_subtype_not_diag]
128+
simp_rw [Set.toFinset_card, edgeSet_top, ← Sym2.card_diagSet_compl]
129129

130130
/-- Any graph on `n` vertices has at most `n.choose 2` edges. -/
131131
theorem card_edgeFinset_le_card_choose_two : #G.edgeFinset ≤ (Fintype.card V).choose 2 := by

Mathlib/Combinatorics/SimpleGraph/Operations.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ lemma edge_le_iff {v w : V} : edge v w ≤ G ↔ v = w ∨ G.Adj v w := by
169169
variable {s t}
170170

171171
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, Set.mem_setOf_eq,
173-
Sym2.isDiag_iff_proj_eq]
172+
rwa [edge, edgeSet_fromEdgeSet, sdiff_eq_left, Set.disjoint_singleton_left,
173+
Sym2.mem_diagSet_iff_eq]
174174

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

Mathlib/Data/Sym/Card.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ 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]
180+
rfl
181+
177182
/-- Type **stars and bars** for the case `n = 2`. -/
178183
protected theorem card {α} [Fintype α] : card (Sym2 α) = Nat.choose (card α + 1) 2 :=
179184
Finset.card_sym2 _

Mathlib/Data/Sym/Sym2.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,9 @@ theorem diagSet_eq_univ_of_subsingleton [Subsingleton α] : @diagSet α = Set.un
535535
instance IsDiag.decidablePred (α : Type u) [DecidableEq α] : DecidablePred (@IsDiag α) :=
536536
fun z => z.recOnSubsingleton fun a => decidable_of_iff' _ (isDiag_iff_proj_eq a)
537537

538+
instance diagSet_decidablePred (α : Type u) [DecidableEq α] : DecidablePred (· ∈ @diagSet α) :=
539+
diagSet_eq_setOf_isDiag ▸ IsDiag.decidablePred _
540+
538541
theorem other_ne {a : α} {z : Sym2 α} (hd : ¬IsDiag z) (h : a ∈ z) : Mem.other h ≠ a := by
539542
contrapose! hd
540543
have h' := Sym2.other_spec h

0 commit comments

Comments
 (0)