# Adjacency Matrices #

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

## Main definitions #

• Matrix.IsAdjMatrix: 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.

• Matrix.IsAdjMatrix.to_graph: for A : Matrix V V α and h : A.IsAdjMatrix, h.to_graph is the simple graph induced by A.

• Matrix.compl: for A : Matrix V V α, A.compl is supposed to be the adjacency matrix of the complement graph of the graph induced by A.

• SimpleGraph.adjMatrix: the adjacency matrix of a SimpleGraph.

• SimpleGraph.adjMatrix_pow_apply_eq_card_walk: each entry of the nth power of a graph's adjacency matrix counts the number of length-n walks between the corresponding pair of vertices.

structure Matrix.IsAdjMatrix {V : Type u_1} {α : Type u_2} [Zero α] [One α] (A : Matrix V V α) :

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.

• zero_or_one : ∀ (i j : V), A i j = 0 A i j = 1
• symm : A.IsSymm
• apply_diag : ∀ (i : V), A i i = 0
Instances For
theorem Matrix.IsAdjMatrix.zero_or_one {V : Type u_1} {α : Type u_2} [Zero α] [One α] {A : Matrix V V α} (self : A.IsAdjMatrix) (i : V) (j : V) :
A i j = 0 A i j = 1
theorem Matrix.IsAdjMatrix.symm {V : Type u_1} {α : Type u_2} [Zero α] [One α] {A : Matrix V V α} (self : A.IsAdjMatrix) :
A.IsSymm
theorem Matrix.IsAdjMatrix.apply_diag {V : Type u_1} {α : Type u_2} [Zero α] [One α] {A : Matrix V V α} (self : A.IsAdjMatrix) (i : V) :
A i i = 0
@[simp]
theorem Matrix.IsAdjMatrix.apply_diag_ne {V : Type u_1} {α : Type u_2} {A : Matrix V V α} [] [] (h : A.IsAdjMatrix) (i : V) :
¬A i i = 1
@[simp]
theorem Matrix.IsAdjMatrix.apply_ne_one_iff {V : Type u_1} {α : Type u_2} {A : Matrix V V α} [] [] (h : A.IsAdjMatrix) (i : V) (j : V) :
¬A i j = 1 A i j = 0
@[simp]
theorem Matrix.IsAdjMatrix.apply_ne_zero_iff {V : Type u_1} {α : Type u_2} {A : Matrix V V α} [] [] (h : A.IsAdjMatrix) (i : V) (j : V) :
¬A i j = 0 A i j = 1
@[simp]
theorem Matrix.IsAdjMatrix.toGraph_adj {V : Type u_1} {α : Type u_2} {A : Matrix V V α} [] [] (h : A.IsAdjMatrix) (i : V) (j : V) :
h.toGraph.Adj i j = (A i j = 1)
def Matrix.IsAdjMatrix.toGraph {V : Type u_1} {α : Type u_2} {A : Matrix V V α} [] [] (h : A.IsAdjMatrix) :

For A : Matrix V V α and h : IsAdjMatrix A, h.toGraph is the simple graph whose adjacency matrix is A.

Equations
• h.toGraph = { Adj := fun (i j : V) => A i j = 1, symm := , loopless := }
Instances For
instance Matrix.IsAdjMatrix.instDecidableRelAdjToGraphOfDecidableEq {V : Type u_1} {α : Type u_2} {A : Matrix V V α} [] [] [] (h : A.IsAdjMatrix) :
DecidableRel h.toGraph.Adj
Equations
• h.instDecidableRelAdjToGraphOfDecidableEq = id inferInstance
def Matrix.compl {V : Type u_1} {α : Type u_2} [Zero α] [One α] [] [] (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.adjMatrix.

Equations
• A.compl i j = if i = j then 0 else if A i j = 0 then 1 else 0
Instances For
@[simp]
theorem Matrix.compl_apply_diag {V : Type u_1} {α : Type u_2} [] [] (A : Matrix V V α) [Zero α] [One α] (i : V) :
A.compl i i = 0
@[simp]
theorem Matrix.compl_apply {V : Type u_1} {α : Type u_2} [] [] (A : Matrix V V α) [Zero α] [One α] (i : V) (j : V) :
A.compl i j = 0 A.compl i j = 1
@[simp]
theorem Matrix.isSymm_compl {V : Type u_1} {α : Type u_2} [] [] (A : Matrix V V α) [Zero α] [One α] (h : A.IsSymm) :
A.compl.IsSymm
@[simp]
theorem Matrix.isAdjMatrix_compl {V : Type u_1} {α : Type u_2} [] [] (A : Matrix V V α) [Zero α] [One α] (h : A.IsSymm) :
A.compl.IsAdjMatrix
@[simp]
theorem Matrix.IsAdjMatrix.compl {V : Type u_1} {α : Type u_2} [] [] {A : Matrix V V α} [Zero α] [One α] (h : A.IsAdjMatrix) :
A.compl.IsAdjMatrix
theorem Matrix.IsAdjMatrix.toGraph_compl_eq {V : Type u_1} {α : Type u_2} [] [] {A : Matrix V V α} [] [] (h : A.IsAdjMatrix) :
.toGraph = h.toGraph
def SimpleGraph.adjMatrix {V : Type u_1} (α : Type u_2) (G : ) [DecidableRel G.Adj] [Zero α] [One α] :
Matrix V V α

adjMatrix 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
• = Matrix.of fun (i j : V) => if G.Adj i j then 1 else 0
Instances For
@[simp]
theorem SimpleGraph.adjMatrix_apply {V : Type u_1} {α : Type u_2} (G : ) [DecidableRel G.Adj] (v : V) (w : V) [Zero α] [One α] :
= if G.Adj v w then 1 else 0
@[simp]
theorem SimpleGraph.transpose_adjMatrix {V : Type u_1} {α : Type u_2} (G : ) [DecidableRel G.Adj] [Zero α] [One α] :
().transpose =
@[simp]
theorem SimpleGraph.isSymm_adjMatrix {V : Type u_1} {α : Type u_2} (G : ) [DecidableRel G.Adj] [Zero α] [One α] :
().IsSymm
@[simp]
theorem SimpleGraph.isAdjMatrix_adjMatrix {V : Type u_1} (α : Type u_2) (G : ) [DecidableRel G.Adj] [Zero α] [One α] :
().IsAdjMatrix

The adjacency matrix of G is an adjacency matrix.

theorem SimpleGraph.toGraph_adjMatrix_eq {V : Type u_1} (α : Type u_2) (G : ) [DecidableRel G.Adj] [] [] :
.toGraph = G

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

@[simp]
theorem SimpleGraph.adjMatrix_dotProduct {V : Type u_1} {α : Type u_2} (G : ) [DecidableRel G.Adj] [] [] (v : V) (vec : Vα) :
Matrix.dotProduct () vec = uG.neighborFinset v, vec u
@[simp]
theorem SimpleGraph.dotProduct_adjMatrix {V : Type u_1} {α : Type u_2} (G : ) [DecidableRel G.Adj] [] [] (v : V) (vec : Vα) :
Matrix.dotProduct vec () = uG.neighborFinset v, vec u
@[simp]
theorem SimpleGraph.adjMatrix_mulVec_apply {V : Type u_1} {α : Type u_2} (G : ) [DecidableRel G.Adj] [] [] (v : V) (vec : Vα) :
().mulVec vec v = uG.neighborFinset v, vec u
@[simp]
theorem SimpleGraph.adjMatrix_vecMul_apply {V : Type u_1} {α : Type u_2} (G : ) [DecidableRel G.Adj] [] [] (v : V) (vec : Vα) :
Matrix.vecMul vec () v = uG.neighborFinset v, vec u
@[simp]
theorem SimpleGraph.adjMatrix_mul_apply {V : Type u_1} {α : Type u_2} (G : ) [DecidableRel G.Adj] [] [] (M : Matrix V V α) (v : V) (w : V) :
() v w = uG.neighborFinset v, M u w
@[simp]
theorem SimpleGraph.mul_adjMatrix_apply {V : Type u_1} {α : Type u_2} (G : ) [DecidableRel G.Adj] [] [] (M : Matrix V V α) (v : V) (w : V) :
() v w = uG.neighborFinset w, M v u
@[simp]
theorem SimpleGraph.trace_adjMatrix {V : Type u_1} (α : Type u_2) (G : ) [DecidableRel G.Adj] [] [] [One α] :
().trace = 0
theorem SimpleGraph.adjMatrix_mul_self_apply_self {V : Type u_1} {α : Type u_2} (G : ) [DecidableRel G.Adj] [] [] (i : V) :
() i i = (G.degree i)
theorem SimpleGraph.adjMatrix_mulVec_const_apply {V : Type u_1} {α : Type u_2} {G : } [DecidableRel G.Adj] [] [] {a : α} {v : V} :
().mulVec () v = (G.degree v) * a
theorem SimpleGraph.adjMatrix_mulVec_const_apply_of_regular {V : Type u_1} {α : Type u_2} {G : } [DecidableRel G.Adj] [] [] {d : } {a : α} (hd : G.IsRegularOfDegree d) {v : V} :
().mulVec () v = d * a
theorem SimpleGraph.adjMatrix_pow_apply_eq_card_walk {V : Type u_1} {α : Type u_2} {G : } [DecidableRel G.Adj] [] [] [] (n : ) (u : V) (v : V) :
() u v = (Fintype.card {p : G.Walk u v | p.length = n})
theorem SimpleGraph.one_add_adjMatrix_add_compl_adjMatrix_eq_allOnes {V : Type u_1} {α : Type u_2} {G : } [DecidableRel G.Adj] [] [] [] :
+ ().compl = Matrix.of fun (x x : V) => 1

The sum of the identity, the adjacency matrix, and its complement is the all-ones matrix.

theorem SimpleGraph.dotProduct_mulVec_adjMatrix {V : Type u_1} {α : Type u_2} {G : } [DecidableRel G.Adj] [] [] (x : Vα) (y : Vα) :
Matrix.dotProduct x (().mulVec y) = i : V, j : V, if G.Adj i j then x i * y j else 0
theorem Matrix.IsAdjMatrix.adjMatrix_toGraph_eq {V : Type u_1} {α : Type u_2} [] [] {A : Matrix V V α} (h : A.IsAdjMatrix) [] :
SimpleGraph.adjMatrix α h.toGraph = A

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