Skip to content

Commit 70c19ec

Browse files
committed
feat(Combinatorics/SimpleGraph): a trivial graph has zero degree (#31116)
Add helper theorems for #29309 Co-authored-by: LLaurance <laurancelau.2022@berkeley.edu>
1 parent 8a3dc61 commit 70c19ec

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

Mathlib/Combinatorics/SimpleGraph/Finite.lean

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,23 @@ theorem degree_eq_zero_iff_notMem_support : G.degree v = 0 ↔ v ∉ G.support :
203203
@[deprecated (since := "2025-05-23")]
204204
alias degree_eq_zero_iff_not_mem_support := degree_eq_zero_iff_notMem_support
205205

206+
@[simp]
207+
theorem degree_eq_zero_of_subsingleton {G : SimpleGraph V} (v : V) [Fintype (G.neighborSet v)]
208+
[Subsingleton V] : G.degree v = 0 := by
209+
have := G.degree_pos_iff_exists_adj v
210+
simp_all [subsingleton_iff_forall_eq v]
211+
212+
theorem degree_eq_one_iff_existsUnique_adj {G : SimpleGraph V} {v : V} [Fintype (G.neighborSet v)] :
213+
G.degree v = 1 ↔ ∃! w : V, G.Adj v w := by
214+
rw [degree, Finset.card_eq_one, Finset.singleton_iff_unique_mem]
215+
simp only [mem_neighborFinset]
216+
217+
theorem nontrivial_of_degree_ne_zero {G : SimpleGraph V} {v : V} [Fintype (G.neighborSet v)]
218+
(h : G.degree v ≠ 0) : Nontrivial V := by
219+
apply not_subsingleton_iff_nontrivial.mp
220+
by_contra
221+
simp_all [degree_eq_zero_of_subsingleton]
222+
206223
theorem degree_compl [Fintype (Gᶜ.neighborSet v)] [Fintype V] :
207224
Gᶜ.degree v = Fintype.card V - 1 - G.degree v := by
208225
classical

Mathlib/Combinatorics/SimpleGraph/Matching.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ theorem IsMatching.support_eq_verts (h : M.IsMatching) : M.support = M.verts :=
214214

215215
theorem isMatching_iff_forall_degree [∀ v, Fintype (M.neighborSet v)] :
216216
M.IsMatching ↔ ∀ v : V, v ∈ M.verts → M.degree v = 1 := by
217-
simp only [degree_eq_one_iff_unique_adj, IsMatching]
217+
simp only [degree_eq_one_iff_existsUnique_adj, IsMatching]
218218

219219
theorem IsMatching.even_card [Fintype M.verts] (h : M.IsMatching) : Even M.verts.toFinset.card := by
220220
classical
@@ -232,7 +232,7 @@ theorem isPerfectMatching_iff : M.IsPerfectMatching ↔ ∀ v, ∃! w, M.Adj v w
232232

233233
theorem isPerfectMatching_iff_forall_degree [∀ v, Fintype (M.neighborSet v)] :
234234
M.IsPerfectMatching ↔ ∀ v, M.degree v = 1 := by
235-
simp [degree_eq_one_iff_unique_adj, isPerfectMatching_iff]
235+
simp [degree_eq_one_iff_existsUnique_adj, isPerfectMatching_iff]
236236

237237
theorem IsPerfectMatching.even_card [Fintype V] (h : M.IsPerfectMatching) :
238238
Even (Fintype.card V) := by

Mathlib/Combinatorics/SimpleGraph/Subgraph.lean

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,13 @@ theorem finset_card_neighborSet_eq_degree {G' : Subgraph G} {v : V} [Fintype (G'
772772
(G'.neighborSet v).toFinset.card = G'.degree v := by
773773
rw [degree, Set.toFinset_card]
774774

775+
theorem degree_of_notMem_verts {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)]
776+
(h : v ∉ G'.verts) : G'.degree v = 0 := by
777+
rw [degree, Fintype.card_eq_zero_iff, isEmpty_subtype]
778+
intro w
779+
by_contra hw
780+
exact h hw.fst_mem
781+
775782
theorem degree_le (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)]
776783
[Fintype (G.neighborSet v)] : G'.degree v ≤ G.degree v := by
777784
rw [← card_neighborSet_eq_degree]
@@ -793,11 +800,32 @@ theorem degree_spanningCoe {G' : G.Subgraph} (v : V) [Fintype (G'.neighborSet v)
793800
rw [← card_neighborSet_eq_degree, Subgraph.degree]
794801
congr!
795802

796-
theorem degree_eq_one_iff_unique_adj {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] :
803+
theorem degree_pos_iff_exists_adj {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] :
804+
0 < G'.degree v ↔ ∃ w, G'.Adj v w := by
805+
simp only [degree, Fintype.card_pos_iff, nonempty_subtype, mem_neighborSet]
806+
807+
theorem degree_eq_zero_of_subsingleton (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)]
808+
(hG : G'.verts.Subsingleton) : G'.degree v = 0 := by
809+
by_cases hv : v ∈ G'.verts
810+
· rw [← G'.coe_degree ⟨v, hv⟩]
811+
have := (Set.subsingleton_coe _).mpr hG
812+
exact G'.coe.degree_eq_zero_of_subsingleton ⟨v, hv⟩
813+
· exact degree_of_notMem_verts hv
814+
815+
theorem degree_eq_one_iff_existsUnique_adj {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] :
797816
G'.degree v = 1 ↔ ∃! w : V, G'.Adj v w := by
798817
rw [← finset_card_neighborSet_eq_degree, Finset.card_eq_one, Finset.singleton_iff_unique_mem]
799818
simp only [Set.mem_toFinset, mem_neighborSet]
800819

820+
@[deprecated (since := "2025-10-31")]
821+
alias degree_eq_one_iff_unique_adj := degree_eq_one_iff_existsUnique_adj
822+
823+
theorem nontrivial_verts_of_degree_ne_zero {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)]
824+
(h : G'.degree v ≠ 0) : Nontrivial G'.verts := by
825+
apply not_subsingleton_iff_nontrivial.mp
826+
by_contra
827+
simp_all [G'.degree_eq_zero_of_subsingleton v]
828+
801829
lemma neighborSet_eq_of_equiv {v : V} {H : Subgraph G}
802830
(h : G.neighborSet v ≃ H.neighborSet v) (hfin : (G.neighborSet v).Finite) :
803831
H.neighborSet v = G.neighborSet v := by
@@ -814,6 +842,20 @@ lemma adj_iff_of_neighborSet_equiv {v : V} {H : Subgraph G}
814842

815843
end Subgraph
816844

845+
@[simp]
846+
theorem card_neighborSet_toSubgraph (G H : SimpleGraph V) (h : H ≤ G)
847+
(v : V) [Fintype ↑((toSubgraph H h).neighborSet v)] [Fintype ↑(H.neighborSet v)] :
848+
Fintype.card ↑((toSubgraph H h).neighborSet v) = H.degree v := by
849+
refine (Finset.card_eq_of_equiv_fintype ?_).symm
850+
simp only [mem_neighborFinset]
851+
rfl
852+
853+
@[simp]
854+
lemma degree_toSubgraph (G H : SimpleGraph V) (h : H ≤ G) {v : V}
855+
[Fintype ↑((toSubgraph H h).neighborSet v)] [Fintype ↑(H.neighborSet v)] :
856+
(toSubgraph H h).degree v = H.degree v := by
857+
simp [Subgraph.degree]
858+
817859
section MkProperties
818860

819861
/-! ### Properties of `singletonSubgraph` and `subgraphOfAdj` -/

0 commit comments

Comments
 (0)