mathlib documentation

combinatorics.simple_graph

Simple graphs

This module defines simple graphs on a vertex type V as an irreflexive symmetric relation.

There is a basic API for locally finite graphs and for graphs with finitely many vertices.

Main definitions

Implementation notes

TODO: This is the simplest notion of an unoriented graph. This should eventually fit into a more complete combinatorics hierarchy which includes multigraphs and directed graphs. We begin with simple graphs in order to start learning what the combinatorics hierarchy should look like.

TODO: Part of this would include defining, for example, subgraphs of a simple graph.

structure simple_graph  :
Type uType u

A simple graph is an irreflexive symmetric relation adj on a vertex type V. The relation describes which pairs of vertices are adjacent. There is exactly one edge for every pair of adjacent edges; see simple_graph.edge_set for the corresponding edge set.

def complete_graph (V : Type u) :

The complete graph on a type V is the simple graph with all pairs of distinct vertices adjacent.

Equations
@[instance]

Equations
@[instance]

Equations
def simple_graph.neighbor_set {V : Type u} :
simple_graph VV → set V

G.neighbor_set v is the set of vertices adjacent to v in G.

Equations
theorem simple_graph.ne_of_adj {V : Type u} (G : simple_graph V) {a b : V} :
G.adj a ba b

def simple_graph.edge_set {V : Type u} :

The edges of G consist of the unordered pairs of vertices related by G.adj.

Equations
@[simp]
theorem simple_graph.mem_edge_set {V : Type u} (G : simple_graph V) {v w : V} :
(v, w) G.edge_set G.adj v w

theorem simple_graph.adj_iff_exists_edge {V : Type u} (G : simple_graph V) {v w : V} :
G.adj v w v w ∃ (e : sym2 V) (H : e G.edge_set), v e w e

Two vertices are adjacent iff there is an edge between them. The condition v ≠ w ensures they are different endpoints of the edge, which is necessary since when v = w the existential ∃ (e ∈ G.edge_set), v ∈ e ∧ w ∈ e is satisfied by every edge incident to v.

theorem simple_graph.edge_other_ne {V : Type u} (G : simple_graph V) {e : sym2 V} (he : e G.edge_set) {v : V} (h : v e) :

@[instance]

Equations

The edge_set of the graph as a finset.

Equations
@[simp]
theorem simple_graph.mem_edge_finset {V : Type u} (G : simple_graph V) [decidable_eq V] [fintype V] [decidable_rel G.adj] (e : sym2 V) :

@[simp]
theorem simple_graph.irrefl {V : Type u} (G : simple_graph V) {v : V} :
¬G.adj v v

theorem simple_graph.edge_symm {V : Type u} (G : simple_graph V) (u v : V) :
G.adj u v G.adj v u

@[simp]
theorem simple_graph.mem_neighbor_set {V : Type u} (G : simple_graph V) (v w : V) :
w G.neighbor_set v G.adj v w

Finiteness at a vertex

This section contains definitions and lemmas concerning vertices that have finitely many adjacent vertices. We denote this condition by fintype (G.neighbor_set v).

We define G.neighbor_finset v to be the finset version of G.neighbor_set v. Use neighbor_finset_eq_filter to rewrite this definition as a filter.

def simple_graph.neighbor_finset {V : Type u} (G : simple_graph V) (v : V) [fintype (G.neighbor_set v)] :

G.neighbors v is the finset version of G.adj v in case G is locally finite at v.

Equations
@[simp]
theorem simple_graph.mem_neighbor_finset {V : Type u} (G : simple_graph V) (v : V) [fintype (G.neighbor_set v)] (w : V) :

def simple_graph.degree {V : Type u} (G : simple_graph V) (v : V) [fintype (G.neighbor_set v)] :

G.degree v is the number of vertices adjacent to v.

Equations
@[simp]

def simple_graph.locally_finite {V : Type u} :
simple_graph VType u

A graph is locally finite if every vertex has a finite neighbor set.

Equations
def simple_graph.is_regular_of_degree {V : Type u} (G : simple_graph V) [G.locally_finite] :
→ Prop

A locally finite simple graph is regular of degree d if every vertex has degree d.

Equations
@[instance]

Equations
@[simp]
theorem simple_graph.complete_graph_degree {V : Type u} [fintype V] [decidable_eq V] (v : V) :