Skip to content

Commit

Permalink
feat: number of edges in a complete graph (#8631)
Browse files Browse the repository at this point in the history
  • Loading branch information
Parcly-Taxel committed Nov 30, 2023
1 parent fb9a01e commit d9c853b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
26 changes: 25 additions & 1 deletion Mathlib/Combinatorics/SimpleGraph/Basic.lean
Expand Up @@ -6,7 +6,7 @@ Authors: Aaron Anderson, Jalex Stark, Kyle Miller, Alena Gusakov, Hunter Monroe
import Mathlib.Combinatorics.SimpleGraph.Init
import Mathlib.Data.Rel
import Mathlib.Data.Set.Finite
import Mathlib.Data.Sym.Sym2
import Mathlib.Data.Sym.Card

#align_import combinatorics.simple_graph.basic from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b"

Expand Down Expand Up @@ -539,6 +539,14 @@ theorem edgeSet_bot : (⊥ : SimpleGraph V).edgeSet = ∅ :=
Sym2.fromRel_bot
#align simple_graph.edge_set_bot SimpleGraph.edgeSet_bot

@[simp]
theorem edgeSet_top : (⊤ : SimpleGraph V).edgeSet = {e | ¬e.IsDiag} :=
Sym2.fromRel_ne

@[simp]
theorem edgeSet_subset_setOf_not_isDiag : G.edgeSet ⊆ {e | ¬e.IsDiag} :=
fun _ h => (Sym2.fromRel_irreflexive (sym := G.symm)).mp G.loopless h

@[simp]
theorem edgeSet_sup : (G₁ ⊔ G₂).edgeSet = G₁.edgeSet ∪ G₂.edgeSet := by
ext ⟨x, y⟩
Expand Down Expand Up @@ -967,6 +975,22 @@ theorem edgeSet_univ_card : (univ : Finset G.edgeSet).card = G.edgeFinset.card :
Fintype.card_of_subtype G.edgeFinset fun _ => mem_edgeFinset
#align simple_graph.edge_set_univ_card SimpleGraph.edgeSet_univ_card

variable [Fintype V] [DecidableEq V]

@[simp]
theorem edgeFinset_top : (⊤ : SimpleGraph V).edgeFinset = univ.filter fun e => ¬e.IsDiag := by
rw [← coe_inj]; simp

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

/-- Any graph on `n` vertices has at most `n.choose 2` edges. -/
theorem card_edgeFinset_le_card_choose_two : G.edgeFinset.card ≤ (Fintype.card V).choose 2 := by
rw [← card_edgeFinset_top_eq_card_choose_two]
exact card_le_of_subset (edgeFinset_mono le_top)

end EdgeFinset

@[simp]
Expand Down
3 changes: 1 addition & 2 deletions Mathlib/Combinatorics/SimpleGraph/DegreeSum.lean
Expand Up @@ -39,8 +39,7 @@ simple graphs, sums, degree-sum formula, handshaking lemma


open Finset

open BigOperators
open scoped BigOperators

namespace SimpleGraph

Expand Down
3 changes: 3 additions & 0 deletions Mathlib/Data/Sym/Sym2.lean
Expand Up @@ -515,6 +515,9 @@ theorem fromRel_top : fromRel (fun (x y : α) z => z : Symmetric ⊤) = Set.univ
simp [-Set.top_eq_univ, Prop.top_eq_true]
#align sym2.from_rel_top Sym2.fromRel_top

theorem fromRel_ne : fromRel (fun (x y : α) z => z.symm : Symmetric Ne) = {z | ¬IsDiag z} := by
ext z; exact z.ind (by simp)

theorem fromRel_irreflexive {sym : Symmetric r} :
Irreflexive r ↔ ∀ {z}, z ∈ fromRel sym → ¬IsDiag z :=
{ mp := by intro h; apply Sym2.ind; aesop
Expand Down

0 comments on commit d9c853b

Please sign in to comment.