mathlib3 documentation

combinatorics.simple_graph.adj_matrix

Adjacency Matrices #

THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.

This module defines the adjacency matrix of a graph, and provides theorems connecting graph properties to computational properties of the matrix.

Main definitions #

structure matrix.is_adj_matrix {V : Type u_1} {α : Type u_2} [has_zero α] [has_one α] (A : matrix V V α) :
Prop
  • zero_or_one : ( (i j : V), A i j = 0 A i j = 1) . "obviously"
  • symm : A.is_symm . "obviously"
  • apply_diag : ( (i : V), A i i = 0) . "obviously"

A : matrix V V α is qualified as an "adjacency matrix" if (1) every entry of A is 0 or 1, (2) A is symmetric, (3) every diagonal entry of A is 0.

@[simp]
theorem matrix.is_adj_matrix.apply_diag_ne {V : Type u_1} {α : Type u_2} {A : matrix V V α} [mul_zero_one_class α] [nontrivial α] (h : A.is_adj_matrix) (i : V) :
¬A i i = 1
@[simp]
theorem matrix.is_adj_matrix.apply_ne_one_iff {V : Type u_1} {α : Type u_2} {A : matrix V V α} [mul_zero_one_class α] [nontrivial α] (h : A.is_adj_matrix) (i j : V) :
¬A i j = 1 A i j = 0
@[simp]
theorem matrix.is_adj_matrix.apply_ne_zero_iff {V : Type u_1} {α : Type u_2} {A : matrix V V α} [mul_zero_one_class α] [nontrivial α] (h : A.is_adj_matrix) (i j : V) :
¬A i j = 0 A i j = 1
@[simp]
theorem matrix.is_adj_matrix.to_graph_adj {V : Type u_1} {α : Type u_2} {A : matrix V V α} [mul_zero_one_class α] [nontrivial α] (h : A.is_adj_matrix) (i j : V) :
h.to_graph.adj i j = (A i j = 1)
def matrix.is_adj_matrix.to_graph {V : Type u_1} {α : Type u_2} {A : matrix V V α} [mul_zero_one_class α] [nontrivial α] (h : A.is_adj_matrix) :

For A : matrix V V α and h : is_adj_matrix A, h.to_graph is the simple graph whose adjacency matrix is A.

Equations
@[protected, instance]
Equations
def matrix.compl {V : Type u_1} {α : Type u_2} [has_zero α] [has_one α] [decidable_eq α] [decidable_eq V] (A : matrix V V α) :
matrix V V α

For A : matrix V V α, A.compl is supposed to be the adjacency matrix of the complement graph of the graph induced by A.adj_matrix.

Equations
@[simp]
theorem matrix.compl_apply_diag {V : Type u_1} {α : Type u_2} [decidable_eq α] [decidable_eq V] (A : matrix V V α) [has_zero α] [has_one α] (i : V) :
A.compl i i = 0
@[simp]
theorem matrix.compl_apply {V : Type u_1} {α : Type u_2} [decidable_eq α] [decidable_eq V] (A : matrix V V α) [has_zero α] [has_one α] (i j : V) :
A.compl i j = 0 A.compl i j = 1
@[simp]
theorem matrix.is_symm_compl {V : Type u_1} {α : Type u_2} [decidable_eq α] [decidable_eq V] (A : matrix V V α) [has_zero α] [has_one α] (h : A.is_symm) :
@[simp]
theorem matrix.is_adj_matrix_compl {V : Type u_1} {α : Type u_2} [decidable_eq α] [decidable_eq V] (A : matrix V V α) [has_zero α] [has_one α] (h : A.is_symm) :
@[simp]
theorem matrix.is_adj_matrix.compl {V : Type u_1} {α : Type u_2} [decidable_eq α] [decidable_eq V] {A : matrix V V α} [has_zero α] [has_one α] (h : A.is_adj_matrix) :
def simple_graph.adj_matrix {V : Type u_1} (α : Type u_2) (G : simple_graph V) [decidable_rel G.adj] [has_zero α] [has_one α] :
matrix V V α

adj_matrix G α is the matrix A such that A i j = (1 : α) if i and j are adjacent in the simple graph G, and otherwise A i j = 0.

Equations
@[simp]
theorem simple_graph.adj_matrix_apply {V : Type u_1} {α : Type u_2} (G : simple_graph V) [decidable_rel G.adj] (v w : V) [has_zero α] [has_one α] :
simple_graph.adj_matrix α G v w = ite (G.adj v w) 1 0
@[simp]
@[simp]

The adjacency matrix of G is an adjacency matrix.

The graph induced by the adjacency matrix of G is G itself.

@[simp]
theorem simple_graph.adj_matrix_dot_product {V : Type u_1} {α : Type u_2} (G : simple_graph V) [decidable_rel G.adj] [fintype V] [non_assoc_semiring α] (v : V) (vec : V α) :
matrix.dot_product (simple_graph.adj_matrix α G v) vec = (G.neighbor_finset v).sum (λ (u : V), vec u)
@[simp]
theorem simple_graph.dot_product_adj_matrix {V : Type u_1} {α : Type u_2} (G : simple_graph V) [decidable_rel G.adj] [fintype V] [non_assoc_semiring α] (v : V) (vec : V α) :
matrix.dot_product vec (simple_graph.adj_matrix α G v) = (G.neighbor_finset v).sum (λ (u : V), vec u)
@[simp]
theorem simple_graph.adj_matrix_mul_vec_apply {V : Type u_1} {α : Type u_2} (G : simple_graph V) [decidable_rel G.adj] [fintype V] [non_assoc_semiring α] (v : V) (vec : V α) :
(simple_graph.adj_matrix α G).mul_vec vec v = (G.neighbor_finset v).sum (λ (u : V), vec u)
@[simp]
theorem simple_graph.adj_matrix_vec_mul_apply {V : Type u_1} {α : Type u_2} (G : simple_graph V) [decidable_rel G.adj] [fintype V] [non_assoc_semiring α] (v : V) (vec : V α) :
matrix.vec_mul vec (simple_graph.adj_matrix α G) v = (G.neighbor_finset v).sum (λ (u : V), vec u)
@[simp]
theorem simple_graph.adj_matrix_mul_apply {V : Type u_1} {α : Type u_2} (G : simple_graph V) [decidable_rel G.adj] [fintype V] [non_assoc_semiring α] (M : matrix V V α) (v w : V) :
(simple_graph.adj_matrix α G).mul M v w = (G.neighbor_finset v).sum (λ (u : V), M u w)
@[simp]
theorem simple_graph.mul_adj_matrix_apply {V : Type u_1} {α : Type u_2} (G : simple_graph V) [decidable_rel G.adj] [fintype V] [non_assoc_semiring α] (M : matrix V V α) (v w : V) :
M.mul (simple_graph.adj_matrix α G) v w = (G.neighbor_finset w).sum (λ (u : V), M v u)
@[simp]
@[simp]
theorem simple_graph.adj_matrix_mul_vec_const_apply {V : Type u_1} {α : Type u_2} {G : simple_graph V} [decidable_rel G.adj] [fintype V] [semiring α] {a : α} {v : V} :
theorem simple_graph.adj_matrix_mul_vec_const_apply_of_regular {V : Type u_1} {α : Type u_2} {G : simple_graph V} [decidable_rel G.adj] [fintype V] [semiring α] {d : } {a : α} (hd : G.is_regular_of_degree d) {v : V} :
theorem simple_graph.adj_matrix_pow_apply_eq_card_walk {V : Type u_1} {α : Type u_2} {G : simple_graph V} [decidable_rel G.adj] [fintype V] [decidable_eq V] [semiring α] (n : ) (u v : V) :
(simple_graph.adj_matrix α G ^ n) u v = (fintype.card {p : G.walk u v | p.length = n})

If A is qualified as an adjacency matrix, then the adjacency matrix of the graph induced by A is itself.