mathlib documentation

combinatorics.simple_graph.basic

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 #

Notations #

Implementation notes #

Naming Conventions #

Todo #

theorem simple_graph.ext {V : Type u} (x y : simple_graph V) (h : x.adj = y.adj) :
x = y
theorem simple_graph.ext_iff {V : Type u} (x y : simple_graph V) :
x = y x.adj = y.adj
@[ext]
structure simple_graph (V : Type u) :
Type 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 simple_graph.from_rel {V : Type u} (r : V → V → Prop) :

Construct the simple graph induced by the given relation. It symmetrizes the relation and makes it irreflexive.

Equations
@[simp]
theorem simple_graph.from_rel_adj {V : Type u} (r : V → V → Prop) (v w : V) :
(simple_graph.from_rel r).adj v w v w (r v w r w v)
def complete_graph (V : Type u) :

The complete graph on a type V is the simple graph with all pairs of distinct vertices adjacent. In mathlib, this is usually referred to as .

Equations
def empty_graph (V : Type u) :

The graph with no edges on a given vertex type V. mathlib prefers the notation .

Equations
@[simp]
theorem simple_graph.irrefl {V : Type u} (G : simple_graph V) {v : V} :
¬G.adj v v
theorem simple_graph.adj_comm {V : Type u} (G : simple_graph V) (u v : V) :
G.adj u v G.adj v u
theorem simple_graph.adj_symm {V : Type u} (G : simple_graph V) {u v : V} (h : G.adj u v) :
G.adj v u
theorem simple_graph.ne_of_adj {V : Type u} (G : simple_graph V) {a b : V} (hab : G.adj a b) :
a b
def simple_graph.is_subgraph {V : Type u} (x y : simple_graph V) :
Prop

The relation that one simple_graph is a subgraph of another. Note that this should be spelled .

Equations
@[instance]
def simple_graph.has_le {V : Type u} :
Equations
@[instance]
def simple_graph.has_sup {V : Type u} :

The supremum of two graphs x ⊔ y has edges where either x or y have edges.

Equations
@[simp]
theorem simple_graph.sup_adj {V : Type u} (x y : simple_graph V) (v w : V) :
(x y).adj v w x.adj v w y.adj v w
@[instance]
def simple_graph.has_inf {V : Type u} :

The infinum of two graphs x ⊓ y has edges where both x and y have edges.

Equations
@[simp]
theorem simple_graph.inf_adj {V : Type u} (x y : simple_graph V) (v w : V) :
(x y).adj v w x.adj v w y.adj v w
@[instance]

We define Gᶜ to be the simple_graph V such that no two adjacent vertices in G are adjacent in the complement, and every nonadjacent pair of vertices is adjacent (still ensuring that vertices are not adjacent to themselves).

Equations
@[simp]
theorem simple_graph.compl_adj {V : Type u} (G : simple_graph V) (v w : V) :
G.adj v w v w ¬G.adj v w
@[instance]

The difference of two graphs x / y has the edges of x with the edges of y removed.

Equations
@[simp]
theorem simple_graph.sdiff_adj {V : Type u} (x y : simple_graph V) (v w : V) :
(x \ y).adj v w x.adj v w ¬y.adj v w
@[simp]
theorem simple_graph.top_adj {V : Type u} (v w : V) :
.adj v w v w
@[simp]
theorem simple_graph.bot_adj {V : Type u} (v w : V) :
@[simp]
@[simp]
theorem simple_graph.empty_graph_eq_bot (V : Type u) :
@[instance]
Equations
@[instance]
Equations
@[instance]
Equations
@[instance]
Equations
def simple_graph.neighbor_set {V : Type u} (G : simple_graph V) (v : V) :
set V

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

Equations
@[instance]
def simple_graph.neighbor_set.mem_decidable {V : Type u} (G : simple_graph V) (v : V) [decidable_rel G.adj] :
decidable_pred (λ (_x : V), _x G.neighbor_set v)
Equations
def simple_graph.edge_set {V : Type u} (G : simple_graph V) :
set (sym2 V)

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

The way edge_set is defined is such that mem_edge_set is proved by refl. (That is, ⟦(v, w)⟧ ∈ G.edge_set is definitionally equal to G.adj v w.)

Equations
def simple_graph.incidence_set {V : Type u} (G : simple_graph V) (v : V) :
set (sym2 V)

The incidence_set is the set of edges incident to a given vertex.

Equations
theorem simple_graph.incidence_set_subset {V : Type u} (G : simple_graph V) (v : V) :
@[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
@[instance]
def simple_graph.decidable_mem_incidence_set {V : Type u} (G : simple_graph V) [decidable_eq V] [decidable_rel G.adj] (v : V) :
decidable_pred (λ (_x : sym2 V), _x G.incidence_set v)
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.mem_neighbor_set {V : Type u} (G : simple_graph V) (v w : V) :
w G.neighbor_set v G.adj v w
@[simp]
theorem simple_graph.mem_incidence_set {V : Type u} (G : simple_graph V) (v w : V) :
(v, w) G.incidence_set v G.adj v w
theorem simple_graph.mem_incidence_iff_neighbor {V : Type u} (G : simple_graph V) {v w : V} :
theorem simple_graph.adj_incidence_set_inter {V : Type u} (G : simple_graph V) {v : V} {e : sym2 V} (he : e G.edge_set) (h : v e) :
def simple_graph.common_neighbors {V : Type u} (G : simple_graph V) (v w : V) :
set V

The set of common neighbors between two vertices v and w in a graph G is the intersection of the neighbor sets of v and w.

Equations
theorem simple_graph.common_neighbors_eq {V : Type u} (G : simple_graph V) (v w : V) :
theorem simple_graph.mem_common_neighbors {V : Type u} (G : simple_graph V) {u v w : V} :
u G.common_neighbors v w G.adj v u G.adj w u
theorem simple_graph.common_neighbors_symm {V : Type u} (G : simple_graph V) (v w : V) :
theorem simple_graph.not_mem_common_neighbors_left {V : Type u} (G : simple_graph V) (v w : V) :
theorem simple_graph.not_mem_common_neighbors_right {V : Type u} (G : simple_graph V) (v w : V) :
@[instance]
def simple_graph.decidable_mem_common_neighbors {V : Type u} (G : simple_graph V) [decidable_rel G.adj] (v w : V) :
decidable_pred (λ (_x : V), _x G.common_neighbors v w)
Equations
def simple_graph.other_vertex_of_incident {V : Type u} (G : simple_graph V) [decidable_eq V] {v : V} {e : sym2 V} (h : e G.incidence_set v) :
V

Given an edge incident to a particular vertex, get the other vertex on the edge.

Equations
theorem simple_graph.incidence_other_prop {V : Type u} (G : simple_graph V) [decidable_eq V] {v : V} {e : sym2 V} (h : e G.incidence_set v) :
@[simp]
theorem simple_graph.incidence_other_neighbor_edge {V : Type u} (G : simple_graph V) [decidable_eq V] {v w : V} (h : w G.neighbor_set v) :

There is an equivalence between the set of edges incident to a given vertex and the set of vertices adjacent to the vertex.

Equations

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]
theorem simple_graph.degree_pos_iff_exists_adj {V : Type u} (G : simple_graph V) (v : V) [fintype (G.neighbor_set v)] :
0 < G.degree v ∃ (w : V), G.adj v w
def simple_graph.incidence_finset {V : Type u} (G : simple_graph V) (v : V) [fintype (G.neighbor_set v)] [decidable_eq V] :

This is the finset version of incidence_set.

Equations
@[simp]
theorem simple_graph.mem_incidence_finset {V : Type u} (G : simple_graph V) (v : V) [fintype (G.neighbor_set v)] [decidable_eq V] (e : sym2 V) :
def simple_graph.locally_finite {V : Type u} (G : simple_graph V) :
Type 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] (d : ) :
Prop

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

Equations
theorem simple_graph.is_regular_of_degree_eq {V : Type u} (G : simple_graph V) [G.locally_finite] {d : } (h : G.is_regular_of_degree d) (v : V) :
G.degree v = d
@[instance]
Equations
@[simp]
theorem simple_graph.complete_graph_degree {V : Type u} [fintype V] [decidable_eq V] (v : V) :
def simple_graph.min_degree {V : Type u} (G : simple_graph V) [fintype V] [decidable_rel G.adj] :

The minimum degree of all vertices (and 0 if there are no vertices). The key properties of this are given in exists_minimal_degree_vertex, min_degree_le_degree and le_min_degree_of_forall_le_degree.

Equations
theorem simple_graph.exists_minimal_degree_vertex {V : Type u} (G : simple_graph V) [fintype V] [decidable_rel G.adj] [nonempty V] :
∃ (v : V), G.min_degree = G.degree v

There exists a vertex of minimal degree. Note the assumption of being nonempty is necessary, as the lemma implies there exists a vertex.

theorem simple_graph.min_degree_le_degree {V : Type u} (G : simple_graph V) [fintype V] [decidable_rel G.adj] (v : V) :

The minimum degree in the graph is at most the degree of any particular vertex.

theorem simple_graph.le_min_degree_of_forall_le_degree {V : Type u} (G : simple_graph V) [fintype V] [decidable_rel G.adj] [nonempty V] (k : ) (h : ∀ (v : V), k G.degree v) :

In a nonempty graph, if k is at most the degree of every vertex, it is at most the minimum degree. Note the assumption that the graph is nonempty is necessary as long as G.min_degree is defined to be a natural.

def simple_graph.max_degree {V : Type u} (G : simple_graph V) [fintype V] [decidable_rel G.adj] :

The maximum degree of all vertices (and 0 if there are no vertices). The key properties of this are given in exists_maximal_degree_vertex, degree_le_max_degree and max_degree_le_of_forall_degree_le.

Equations
theorem simple_graph.exists_maximal_degree_vertex {V : Type u} (G : simple_graph V) [fintype V] [decidable_rel G.adj] [nonempty V] :
∃ (v : V), G.max_degree = G.degree v

There exists a vertex of maximal degree. Note the assumption of being nonempty is necessary, as the lemma implies there exists a vertex.

theorem simple_graph.degree_le_max_degree {V : Type u} (G : simple_graph V) [fintype V] [decidable_rel G.adj] (v : V) :

The maximum degree in the graph is at least the degree of any particular vertex.

theorem simple_graph.max_degree_le_of_forall_degree_le {V : Type u} (G : simple_graph V) [fintype V] [decidable_rel G.adj] (k : ) (h : ∀ (v : V), G.degree v k) :

In a graph, if k is at least the degree of every vertex, then it is at least the maximum degree.

theorem simple_graph.degree_lt_card_verts {V : Type u} (G : simple_graph V) [fintype V] [decidable_rel G.adj] (v : V) :

The maximum degree of a nonempty graph is less than the number of vertices. Note that the assumption that V is nonempty is necessary, as otherwise this would assert the existence of a natural number less than zero.

theorem simple_graph.adj.card_common_neighbors_lt_degree {V : Type u} [fintype V] {G : simple_graph V} [decidable_rel G.adj] {v w : V} (h : G.adj v w) :

If the condition G.adj v w fails, then card_common_neighbors_le_degree is the best we can do in general.

def simple_graph.hom {V : Type u} {W : Type v} (G : simple_graph V) (G' : simple_graph W) :
Type (max u v)

A graph homomorphism is a map on vertex sets that respects adjacency relations.

The notation G →g G' represents the type of graph homomorphisms.

def simple_graph.embedding {V : Type u} {W : Type v} (G : simple_graph V) (G' : simple_graph W) :
Type (max u v)

A graph embedding is an embedding f such that for vertices v w : V, G.adj f(v) f(w) ↔ G.adj v w. Its image is an induced subgraph of G'.

The notation G ↪g G' represents the type of graph embeddings.

def simple_graph.iso {V : Type u} {W : Type v} (G : simple_graph V) (G' : simple_graph W) :
Type (max u v)

A graph isomorphism is an bijective map on vertex sets that respects adjacency relations.

The notation G ≃g G' represents the type of graph isomorphisms.

def simple_graph.hom.id {V : Type u} {G : simple_graph V} :
G →g G

The identity homomorphism from a graph to itself.

theorem simple_graph.hom.map_adj {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G →g G') {v w : V} (h : G.adj v w) :
G'.adj (f v) (f w)
theorem simple_graph.hom.map_mem_edge_set {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G →g G') {e : sym2 V} (h : e G.edge_set) :
theorem simple_graph.hom.apply_mem_neighbor_set {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G →g G') {v w : V} (h : w G.neighbor_set v) :
f w G'.neighbor_set (f v)
def simple_graph.hom.map_edge_set {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G →g G') (e : (G.edge_set)) :

The map between edge sets induced by a homomorphism. The underlying map on edges is given by sym2.map.

Equations
@[simp]
theorem simple_graph.hom.map_edge_set_coe {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G →g G') (e : (G.edge_set)) :
@[simp]
theorem simple_graph.hom.map_neighbor_set_coe {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G →g G') (v : V) (w : (G.neighbor_set v)) :
def simple_graph.hom.map_neighbor_set {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G →g G') (v : V) (w : (G.neighbor_set v)) :

The map between neighbor sets induced by a homomorphism.

Equations
theorem simple_graph.hom.map_edge_set.injective {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G →g G') (hinj : function.injective f) :
def simple_graph.hom.comp {V : Type u} {W : Type v} {X : Type w} {G : simple_graph V} {G' : simple_graph W} {G'' : simple_graph X} (f' : G' →g G'') (f : G →g G') :
G →g G''

Composition of graph homomorphisms.

@[simp]
theorem simple_graph.hom.coe_comp {V : Type u} {W : Type v} {X : Type w} {G : simple_graph V} {G' : simple_graph W} {G'' : simple_graph X} (f' : G' →g G'') (f : G →g G') :
(f'.comp f) = f' f
def simple_graph.embedding.refl {V : Type u} {G : simple_graph V} :
G ↪g G

The identity embedding from a graph to itself.

def simple_graph.embedding.to_hom {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ↪g G') :
G →g G'

An embedding of graphs gives rise to a homomorphism of graphs.

theorem simple_graph.embedding.map_adj_iff {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ↪g G') {v w : V} :
G'.adj (f v) (f w) G.adj v w
theorem simple_graph.embedding.map_mem_edge_set_iff {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ↪g G') {e : sym2 V} :
theorem simple_graph.embedding.apply_mem_neighbor_set_iff {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ↪g G') {v w : V} :
@[simp]
theorem simple_graph.embedding.map_edge_set_apply {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ↪g G') (e : (G.edge_set)) :
def simple_graph.embedding.map_edge_set {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ↪g G') :

A graph embedding induces an embedding of edge sets.

Equations
def simple_graph.embedding.map_neighbor_set {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ↪g G') (v : V) :

A graph embedding induces an embedding of neighbor sets.

Equations
@[simp]
theorem simple_graph.embedding.map_neighbor_set_apply_coe {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ↪g G') (v : V) (w : (G.neighbor_set v)) :
def simple_graph.embedding.comp {V : Type u} {W : Type v} {X : Type w} {G : simple_graph V} {G' : simple_graph W} {G'' : simple_graph X} (f' : G' ↪g G'') (f : G ↪g G') :
G ↪g G''

Composition of graph embeddings.

@[simp]
theorem simple_graph.embedding.coe_comp {V : Type u} {W : Type v} {X : Type w} {G : simple_graph V} {G' : simple_graph W} {G'' : simple_graph X} (f' : G' ↪g G'') (f : G ↪g G') :
(f'.comp f) = f' f
def simple_graph.iso.refl {V : Type u} {G : simple_graph V} :
G ≃g G

The identity isomorphism of a graph with itself.

def simple_graph.iso.to_embedding {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ≃g G') :
G ↪g G'

An isomorphism of graphs gives rise to an embedding of graphs.

def simple_graph.iso.to_hom {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ≃g G') :
G →g G'

An isomorphism of graphs gives rise to a homomorphism of graphs.

def simple_graph.iso.symm {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ≃g G') :
G' ≃g G

The inverse of a graph isomorphism. -

theorem simple_graph.iso.map_adj_iff {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ≃g G') {v w : V} :
G'.adj (f v) (f w) G.adj v w
theorem simple_graph.iso.map_mem_edge_set_iff {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ≃g G') {e : sym2 V} :
theorem simple_graph.iso.apply_mem_neighbor_set_iff {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ≃g G') {v w : V} :
@[simp]
theorem simple_graph.iso.map_edge_set_apply {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ≃g G') (e : (G.edge_set)) :
def simple_graph.iso.map_edge_set {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ≃g G') :

An isomorphism of graphs induces an equivalence of edge sets.

Equations
@[simp]
theorem simple_graph.iso.map_edge_set_symm_apply {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ≃g G') (e : (G'.edge_set)) :
@[simp]
theorem simple_graph.iso.map_neighbor_set_symm_apply_coe {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ≃g G') (v : V) (w : (G'.neighbor_set (f v))) :
def simple_graph.iso.map_neighbor_set {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ≃g G') (v : V) :

A graph isomorphism induces an equivalence of neighbor sets.

Equations
@[simp]
theorem simple_graph.iso.map_neighbor_set_apply_coe {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} (f : G ≃g G') (v : V) (w : (G.neighbor_set v)) :
theorem simple_graph.iso.card_eq_of_iso {V : Type u} {W : Type v} {G : simple_graph V} {G' : simple_graph W} [fintype V] [fintype W] (f : G ≃g G') :
def simple_graph.iso.comp {V : Type u} {W : Type v} {X : Type w} {G : simple_graph V} {G' : simple_graph W} {G'' : simple_graph X} (f' : G' ≃g G'') (f : G ≃g G') :
G ≃g G''

Composition of graph isomorphisms.

@[simp]
theorem simple_graph.iso.coe_comp {V : Type u} {W : Type v} {X : Type w} {G : simple_graph V} {G' : simple_graph W} {G'' : simple_graph X} (f' : G' ≃g G'') (f : G ≃g G') :
(f'.comp f) = f' f