Skip to content

Commit 04c4aa1

Browse files
8e7ReemMelamed
authored andcommitted
feat(Combinatorics/SimpleGraph/Star): define star graphs (leanprover-community#38027)
Add a new definition `starGraph` and several key lemmas. Star graphs are a trivial class of tree, often used in constructive proofs regarding trees. An example use case is shown in leanprover-community#38334.
1 parent 72a2712 commit 04c4aa1

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3662,6 +3662,7 @@ public import Mathlib.Combinatorics.SimpleGraph.Regularity.Equitabilise
36623662
public import Mathlib.Combinatorics.SimpleGraph.Regularity.Increment
36633663
public import Mathlib.Combinatorics.SimpleGraph.Regularity.Lemma
36643664
public import Mathlib.Combinatorics.SimpleGraph.Regularity.Uniform
3665+
public import Mathlib.Combinatorics.SimpleGraph.Star
36653666
public import Mathlib.Combinatorics.SimpleGraph.StronglyRegular
36663667
public import Mathlib.Combinatorics.SimpleGraph.Subgraph
36673668
public import Mathlib.Combinatorics.SimpleGraph.Sum
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/-
2+
Copyright (c) 2026 Justin Lai. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Justin Lai
5+
-/
6+
module
7+
8+
public import Mathlib.Combinatorics.SimpleGraph.Acyclic
9+
10+
/-!
11+
12+
# Star Graphs
13+
14+
## Main definitions
15+
16+
* `SimpleGraph.starGraph r` is the star graph on V centered at r. Every non-center vertex is
17+
adjacent to r.
18+
19+
## Main statements
20+
21+
* `SimpleGraph.isTree_starGraph` proves the star graph is a tree.
22+
23+
24+
## Tags
25+
26+
star graph
27+
-/
28+
29+
@[expose] public section
30+
31+
namespace SimpleGraph
32+
33+
variable {V V' : Type*} (G : SimpleGraph V) (G' : SimpleGraph V')
34+
35+
/-- The star graph on `V` centered at `r`: every non-center vertex is adjacent to `r`. -/
36+
def starGraph (r : V) : SimpleGraph V :=
37+
.fromRel fun v _ ↦ v = r
38+
39+
instance [DecidableEq V] (r : V) : DecidableRel (starGraph r).Adj :=
40+
inferInstanceAs (DecidableRel fun x y ↦ x ≠ y ∧ (x = r ∨ y = r))
41+
42+
@[simp]
43+
lemma starGraph_adj {r x y : V} : (starGraph r).Adj x y ↔ x ≠ y ∧ (x = r ∨ y = r) := by
44+
simp [starGraph, fromRel]
45+
46+
/-- On (starGraph r), r is adjacent to v iff v ≠ r. -/
47+
lemma starGraph_adj_center_iff {r v : V} : (starGraph r).Adj r v ↔ r ≠ v := by simp
48+
49+
lemma starGraph_center_adj {r v : V} (h : r ≠ v) : (starGraph r).Adj r v :=
50+
starGraph_adj_center_iff.mpr h
51+
52+
lemma starGraph_center_adj' {r v : V} (h : r ≠ v) : (starGraph r).Adj v r :=
53+
(starGraph_center_adj h).symm
54+
55+
lemma connected_starGraph (r : V) : (starGraph r).Connected := by
56+
have (v : V) : (starGraph r).Reachable r v := by
57+
by_cases! h : r = v
58+
· exact h ▸ Reachable.rfl
59+
· exact (starGraph_center_adj h).reachable
60+
exact connected_iff _ |>.mpr ⟨fun u v ↦ (this u).symm.trans (this v), ⟨r⟩⟩
61+
62+
lemma isAcyclic_starGraph (r : V) : (starGraph r).IsAcyclic := by
63+
refine isAcyclic_iff_forall_adj_isBridge.mpr fun v w hadj ↦ isBridge_iff.mpr ⟨hadj, ?_⟩
64+
rw [starGraph_adj] at hadj
65+
wlog! h : v = r
66+
· rw [reachable_comm, Sym2.eq_swap]
67+
exact this r w v ⟨hadj.1.symm, hadj.2.symm⟩ (hadj.2.resolve_left h)
68+
· subst h
69+
apply not_reachable_of_neighborSet_right_eq_empty hadj.1
70+
ext x
71+
aesop
72+
73+
lemma isTree_starGraph (r : V) : (starGraph r).IsTree :=
74+
⟨connected_starGraph r, isAcyclic_starGraph r⟩
75+
76+
/-- Every non-center vertex of a starGraph has degree one. -/
77+
lemma degree_starGraph_of_ne_center [Fintype V] [DecidableEq V] {r v : V} (h : v ≠ r) :
78+
(starGraph r).degree v = 1 :=
79+
degree_eq_one_iff_existsUnique_adj.mpr ⟨r, by simp [h], by grind [starGraph_adj]⟩
80+
81+
/-- The center vertex of a starGraph has degree (card V) - 1. -/
82+
lemma degree_starGraph_center [Fintype V] [DecidableEq V] {r : V} :
83+
(starGraph r).degree r = Fintype.card V - 1 := by
84+
simp [degree, neighborFinset_eq_filter (starGraph r), starGraph_adj, Finset.univ.filter_ne r]
85+
86+
end SimpleGraph

0 commit comments

Comments
 (0)