File: Mathlib/Combinatorics/SimpleGraph/LapMatrix.lean

full_name: SimpleGraph.degMatrix
code: /-- The diagonal matrix consisting of the degrees of the vertices in the graph. -/
def degMatrix [AddMonoidWithOne R] : Matrix V V R 
goal: Matrix V V R

full_name: SimpleGraph.lapMatrix
code: /-- The *Laplacian matrix* `lapMatrix G R` of a graph `G`
is the matrix `L = D - A` where `D` is the degree and `A` the adjacency matrix of `G`. -/
def lapMatrix [AddGroupWithOne R] : Matrix V V R 
goal: Matrix V V R

full_name: SimpleGraph.isSymm_degMatrix
code: theorem isSymm_degMatrix [AddMonoidWithOne R] : (G.degMatrix R).IsSymm 
goal: (SimpleGraph.degMatrix R G).IsSymm

full_name: SimpleGraph.isSymm_lapMatrix
code: theorem isSymm_lapMatrix [AddGroupWithOne R] : (G.lapMatrix R).IsSymm 
goal: (SimpleGraph.lapMatrix R G).IsSymm

full_name: SimpleGraph.degMatrix_mulVec_apply
code: theorem degMatrix_mulVec_apply [NonAssocSemiring R] (v : V) (vec : V → R) :
    (G.degMatrix R *ᵥ vec) v = G.degree v * vec v 
goal: (SimpleGraph.degMatrix R G *ᵥ vec) v = ↑(G.degree v) * vec v

full_name: SimpleGraph.lapMatrix_mulVec_apply
code: theorem lapMatrix_mulVec_apply [NonAssocRing R] (v : V) (vec : V → R) :
    (G.lapMatrix R *ᵥ vec) v = G.degree v * vec v - ∑ u ∈ G.neighborFinset v, vec u 
goal: (SimpleGraph.lapMatrix R G *ᵥ vec) v = ↑(G.degree v) * vec v - ∑ u ∈ G.neighborFinset v, vec u

full_name: SimpleGraph.lapMatrix_mulVec_const_eq_zero
code: theorem lapMatrix_mulVec_const_eq_zero [Ring R] : mulVec (G.lapMatrix R) (fun _ ↦ 1) = 0 
goal: (SimpleGraph.lapMatrix R G *ᵥ fun x => 1) = 0

full_name: SimpleGraph.dotProduct_mulVec_degMatrix
code: theorem dotProduct_mulVec_degMatrix [CommRing R] (x : V → R) :
    x ⬝ᵥ (G.degMatrix R *ᵥ x) = ∑ i : V, G.degree i * x i * x i 
goal: x ⬝ᵥ SimpleGraph.degMatrix R G *ᵥ x = ∑ i : V, ↑(G.degree i) * x i * x i

full_name: SimpleGraph.degree_eq_sum_if_adj
code: theorem degree_eq_sum_if_adj [AddCommMonoidWithOne R] (i : V) :
    (G.degree i : R) = ∑ j : V, if G.Adj i j then 1 else 0 
goal: ↑(G.degree i) = ∑ j : V, if G.Adj i j then 1 else 0

full_name: SimpleGraph.lapMatrix_toLinearMap₂'
code: /-- Let $L$ be the graph Laplacian and let $x \in \mathbb{R}$, then
$$x^{\top} L x = \sum_{i \sim j} (x_{i}-x_{j})^{2}$$,
where $\sim$ denotes the adjacency relation -/
theorem lapMatrix_toLinearMap₂' [Field R] [CharZero R] (x : V → R) :
    toLinearMap₂' R (G.lapMatrix R) x x =
    (∑ i : V, ∑ j : V, if G.Adj i j then (x i - x j)^2 else 0) / 2 
goal: (((Matrix.toLinearMap₂' R) (SimpleGraph.lapMatrix R G)) x) x =
  (∑ i : V, ∑ j : V, if G.Adj i j then (x i - x j) ^ 2 else 0) / 2

full_name: SimpleGraph.posSemidef_lapMatrix
code: /-- The Laplacian matrix is positive semidefinite -/
theorem posSemidef_lapMatrix [LinearOrderedField R] [StarRing R]
    [TrivialStar R] : PosSemidef (G.lapMatrix R) 
goal: (SimpleGraph.lapMatrix R G).PosSemidef

full_name: SimpleGraph.lapMatrix_toLinearMap₂'_apply'_eq_zero_iff_forall_adj
code: theorem lapMatrix_toLinearMap₂'_apply'_eq_zero_iff_forall_adj [LinearOrderedField R] (x : V → R) :
    Matrix.toLinearMap₂' R (G.lapMatrix R) x x = 0 ↔ ∀ i j : V, G.Adj i j → x i = x j 
goal: (((Matrix.toLinearMap₂' R) (SimpleGraph.lapMatrix R G)) x) x = 0 ↔ ∀ (i j : V), G.Adj i j → x i = x j

full_name: SimpleGraph.lapMatrix_toLin'_apply_eq_zero_iff_forall_adj
code: theorem lapMatrix_toLin'_apply_eq_zero_iff_forall_adj (x : V → ℝ) :
    Matrix.toLin' (G.lapMatrix ℝ) x = 0 ↔ ∀ i j : V, G.Adj i j → x i = x j 
goal: (Matrix.toLin' (SimpleGraph.lapMatrix ℝ G)) x = 0 ↔ ∀ (i j : V), G.Adj i j → x i = x j

full_name: SimpleGraph.lapMatrix_toLinearMap₂'_apply'_eq_zero_iff_forall_reachable
code: theorem lapMatrix_toLinearMap₂'_apply'_eq_zero_iff_forall_reachable (x : V → ℝ) :
    Matrix.toLinearMap₂' ℝ (G.lapMatrix ℝ) x x = 0 ↔
      ∀ i j : V, G.Reachable i j → x i = x j 
goal: (((Matrix.toLinearMap₂' ℝ) (SimpleGraph.lapMatrix ℝ G)) x) x = 0 ↔ ∀ (i j : V), G.Reachable i j → x i = x j

full_name: SimpleGraph.lapMatrix_toLin'_apply_eq_zero_iff_forall_reachable
code: theorem lapMatrix_toLin'_apply_eq_zero_iff_forall_reachable (x : V → ℝ) :
    Matrix.toLin' (G.lapMatrix ℝ) x = 0 ↔ ∀ i j : V, G.Reachable i j → x i = x j 
goal: (Matrix.toLin' (SimpleGraph.lapMatrix ℝ G)) x = 0 ↔ ∀ (i j : V), G.Reachable i j → x i = x j

full_name: SimpleGraph.mem_ker_toLin'_lapMatrix_of_connectedComponent
code: lemma mem_ker_toLin'_lapMatrix_of_connectedComponent {G : SimpleGraph V} [DecidableRel G.Adj]
    [DecidableEq G.ConnectedComponent] (c : G.ConnectedComponent) :
    (fun i ↦ if connectedComponentMk G i = c then 1 else 0) ∈
      LinearMap.ker (toLin' (lapMatrix ℝ G)) 
goal: (fun i => if G.connectedComponentMk i = c then 1 else 0) ∈ LinearMap.ker (Matrix.toLin' (SimpleGraph.lapMatrix ℝ G))

full_name: SimpleGraph.lapMatrix_ker_basis_aux
code: /-- Given a connected component `c` of a graph `G`, `lapMatrix_ker_basis_aux c` is the map
`V → ℝ` which is `1` on the vertices in `c` and `0` elsewhere.
The family of these maps indexed by the connected components of `G` proves to be a basis
of the kernel of `lapMatrix G R` -/
def lapMatrix_ker_basis_aux (c : G.ConnectedComponent) :
    LinearMap.ker (Matrix.toLin' (G.lapMatrix ℝ)) 
goal: ↥(LinearMap.ker (Matrix.toLin' (SimpleGraph.lapMatrix ℝ G)))

full_name: SimpleGraph.linearIndependent_lapMatrix_ker_basis_aux
code: lemma linearIndependent_lapMatrix_ker_basis_aux :
    LinearIndependent ℝ (lapMatrix_ker_basis_aux G) 
goal: LinearIndependent ℝ G.lapMatrix_ker_basis_aux

full_name: SimpleGraph.top_le_span_range_lapMatrix_ker_basis_aux
code: lemma top_le_span_range_lapMatrix_ker_basis_aux :
    ⊤ ≤ Submodule.span ℝ (Set.range (lapMatrix_ker_basis_aux G)) 
goal: ⊤ ≤ Submodule.span ℝ (Set.range G.lapMatrix_ker_basis_aux)

full_name: SimpleGraph.lapMatrix_ker_basis
code: /-- `lapMatrix_ker_basis G` is a basis of the nullspace indexed by its connected components,
the basis is made up of the functions `V → ℝ` which are `1` on the vertices of the given
connected component and `0` elsewhere. -/
noncomputable def lapMatrix_ker_basis 
goal: Basis G.ConnectedComponent ℝ ↥(LinearMap.ker (Matrix.toLin' (SimpleGraph.lapMatrix ℝ G)))

full_name: SimpleGraph.card_ConnectedComponent_eq_rank_ker_lapMatrix
code: /-- The number of connected components in `G` is the dimension of the nullspace its Laplacian. -/
theorem card_ConnectedComponent_eq_rank_ker_lapMatrix : Fintype.card G.ConnectedComponent =
    FiniteDimensional.finrank ℝ (LinearMap.ker (Matrix.toLin' (G.lapMatrix ℝ))) 
goal: Fintype.card G.ConnectedComponent =
  FiniteDimensional.finrank ℝ ↥(LinearMap.ker (Matrix.toLin' (SimpleGraph.lapMatrix ℝ G)))