-- Mathlib/LinearAlgebra/Matrix/Diagonal.lean
theorem rank_diagonal [DecidableEq m] [DecidableEq K] (w : m → K) :
    LinearMap.rank (toLin' (diagonal w)) = Fintype.card { i // w i ≠ 0 }

Proof state:
m : Type u_1
inst✝³ : Fintype m
K : Type u
inst✝² : Field K
inst✝¹ : DecidableEq m
inst✝ : DecidableEq K
w : m → K
hu : univ ⊆ {i | w i = 0}ᶜ ∪ {i | w i = 0}
hd : Disjoint {i | w i ≠ 0} {i | w i = 0}
⊢ (toLin' (Matrix.diagonal w)).rank = ↑(Fintype.card { i // w i ≠ 0 })

Tactic:
have B₁ := iSup_range_single_eq_iInf_ker_proj K (fun _ : m => K) hd hu (Set.toFinite _)

Result:
m : Type u_1
inst✝³ : Fintype m
K : Type u
inst✝² : Field K
inst✝¹ : DecidableEq m
inst✝ : DecidableEq K
w : m → K
hu : univ ⊆ {i | w i = 0}ᶜ ∪ {i | w i = 0}
hd : Disjoint {i | w i ≠ 0} {i | w i = 0}
B₁ : ⨆ i ∈ {i | w i ≠ 0}, range (single K (fun x => K) i) = ⨅ i ∈ {i | w i = 0}, ker (proj i)
⊢ (toLin' (Matrix.diagonal w)).rank = ↑(Fintype.card { i // w i ≠ 0 })

Proof state:
m : Type u_1
inst✝³ : Fintype m
K : Type u
inst✝² : Field K
inst✝¹ : DecidableEq m
inst✝ : DecidableEq K
w : m → K
hu : univ ⊆ {i | w i = 0}ᶜ ∪ {i | w i = 0}
hd : Disjoint {i | w i ≠ 0} {i | w i = 0}
B₁ : ⨆ i ∈ {i | w i ≠ 0}, range (single K (fun x => K) i) = ⨅ i ∈ {i | w i = 0}, ker (proj i)
B₂ : ↥(⨅ i ∈ {i | w i = 0}, ker (proj i)) ≃ₗ[K] (i : ↑{i | w i ≠ 0}) → (fun x => K) ↑i
⊢ (toLin' (Matrix.diagonal w)).rank = ↑(Fintype.card { i // w i ≠ 0 })

Tactic:
rw [LinearMap.rank, range_diagonal, B₁, ← @rank_fun' K]

Result:
m : Type u_1
inst✝³ : Fintype m
K : Type u
inst✝² : Field K
inst✝¹ : DecidableEq m
inst✝ : DecidableEq K
w : m → K
hu : univ ⊆ {i | w i = 0}ᶜ ∪ {i | w i = 0}
hd : Disjoint {i | w i ≠ 0} {i | w i = 0}
B₁ : ⨆ i ∈ {i | w i ≠ 0}, range (single K (fun x => K) i) = ⨅ i ∈ {i | w i = 0}, ker (proj i)
B₂ : ↥(⨅ i ∈ {i | w i = 0}, ker (proj i)) ≃ₗ[K] (i : ↑{i | w i ≠ 0}) → (fun x => K) ↑i
⊢ Module.rank K ↥(⨅ i ∈ {i | w i = 0}, ker (proj i)) = Module.rank K ({ i // w i ≠ 0 } → K)

Proof state:
m : Type u_1
inst✝³ : Fintype m
K : Type u
inst✝² : Field K
inst✝¹ : DecidableEq m
inst✝ : DecidableEq K
w : m → K
⊢ univ ⊆ {i | w i = 0}ᶜ ∪ {i | w i = 0}

Tactic:
rw [Set.compl_union_self]

Result:
no goals

Proof state:
m : Type u_1
inst✝³ : Fintype m
K : Type u
inst✝² : Field K
inst✝¹ : DecidableEq m
inst✝ : DecidableEq K
w : m → K
⊢ (toLin' (Matrix.diagonal w)).rank = ↑(Fintype.card { i // w i ≠ 0 })

Tactic:
have hu : univ ⊆ { i : m | w i = 0 }ᶜ ∪ { i : m | w i = 0 } := by rw [Set.compl_union_self]

Result:
m : Type u_1
inst✝³ : Fintype m
K : Type u
inst✝² : Field K
inst✝¹ : DecidableEq m
inst✝ : DecidableEq K
w : m → K
hu : univ ⊆ {i | w i = 0}ᶜ ∪ {i | w i = 0}
⊢ (toLin' (Matrix.diagonal w)).rank = ↑(Fintype.card { i // w i ≠ 0 })

Proof state:
m : Type u_1
inst✝³ : Fintype m
K : Type u
inst✝² : Field K
inst✝¹ : DecidableEq m
inst✝ : DecidableEq K
w : m → K
hu : univ ⊆ {i | w i = 0}ᶜ ∪ {i | w i = 0}
hd : Disjoint {i | w i ≠ 0} {i | w i = 0}
B₁ : ⨆ i ∈ {i | w i ≠ 0}, range (single K (fun x => K) i) = ⨅ i ∈ {i | w i = 0}, ker (proj i)
B₂ : ↥(⨅ i ∈ {i | w i = 0}, ker (proj i)) ≃ₗ[K] (i : ↑{i | w i ≠ 0}) → (fun x => K) ↑i
⊢ Module.rank K ↥(⨅ i ∈ {i | w i = 0}, ker (proj i)) = Module.rank K ({ i // w i ≠ 0 } → K)

Tactic:
apply LinearEquiv.rank_eq

Result:
case f
m : Type u_1
inst✝³ : Fintype m
K : Type u
inst✝² : Field K
inst✝¹ : DecidableEq m
inst✝ : DecidableEq K
w : m → K
hu : univ ⊆ {i | w i = 0}ᶜ ∪ {i | w i = 0}
hd : Disjoint {i | w i ≠ 0} {i | w i = 0}
B₁ : ⨆ i ∈ {i | w i ≠ 0}, range (single K (fun x => K) i) = ⨅ i ∈ {i | w i = 0}, ker (proj i)
B₂ : ↥(⨅ i ∈ {i | w i = 0}, ker (proj i)) ≃ₗ[K] (i : ↑{i | w i ≠ 0}) → (fun x => K) ↑i
⊢ ↥(⨅ i ∈ {i | w i = 0}, ker (proj i)) ≃ₗ[K] { i // w i ≠ 0 } → K

Proof state:
m : Type u_1
inst✝³ : Fintype m
K : Type u
inst✝² : Field K
inst✝¹ : DecidableEq m
inst✝ : DecidableEq K
w : m → K
hu : univ ⊆ {i | w i = 0}ᶜ ∪ {i | w i = 0}
⊢ (toLin' (Matrix.diagonal w)).rank = ↑(Fintype.card { i // w i ≠ 0 })

Tactic:
have hd : Disjoint { i : m | w i ≠ 0 } { i : m | w i = 0 } := disjoint_compl_left

Result:
m : Type u_1
inst✝³ : Fintype m
K : Type u
inst✝² : Field K
inst✝¹ : DecidableEq m
inst✝ : DecidableEq K
w : m → K
hu : univ ⊆ {i | w i = 0}ᶜ ∪ {i | w i = 0}
hd : Disjoint {i | w i ≠ 0} {i | w i = 0}
⊢ (toLin' (Matrix.diagonal w)).rank = ↑(Fintype.card { i // w i ≠ 0 })

Proof state:
m : Type u_1
inst✝³ : Fintype m
K : Type u
inst✝² : Field K
inst✝¹ : DecidableEq m
inst✝ : DecidableEq K
w : m → K
hu : univ ⊆ {i | w i = 0}ᶜ ∪ {i | w i = 0}
hd : Disjoint {i | w i ≠ 0} {i | w i = 0}
B₁ : ⨆ i ∈ {i | w i ≠ 0}, range (single K (fun x => K) i) = ⨅ i ∈ {i | w i = 0}, ker (proj i)
⊢ (toLin' (Matrix.diagonal w)).rank = ↑(Fintype.card { i // w i ≠ 0 })

Tactic:
have B₂ := iInfKerProjEquiv K (fun _ ↦ K) hd hu

Result:
m : Type u_1
inst✝³ : Fintype m
K : Type u
inst✝² : Field K
inst✝¹ : DecidableEq m
inst✝ : DecidableEq K
w : m → K
hu : univ ⊆ {i | w i = 0}ᶜ ∪ {i | w i = 0}
hd : Disjoint {i | w i ≠ 0} {i | w i = 0}
B₁ : ⨆ i ∈ {i | w i ≠ 0}, range (single K (fun x => K) i) = ⨅ i ∈ {i | w i = 0}, ker (proj i)
B₂ : ↥(⨅ i ∈ {i | w i = 0}, ker (proj i)) ≃ₗ[K] (i : ↑{i | w i ≠ 0}) → (fun x => K) ↑i
⊢ (toLin' (Matrix.diagonal w)).rank = ↑(Fintype.card { i // w i ≠ 0 })

Proof state:
case f
m : Type u_1
inst✝³ : Fintype m
K : Type u
inst✝² : Field K
inst✝¹ : DecidableEq m
inst✝ : DecidableEq K
w : m → K
hu : univ ⊆ {i | w i = 0}ᶜ ∪ {i | w i = 0}
hd : Disjoint {i | w i ≠ 0} {i | w i = 0}
B₁ : ⨆ i ∈ {i | w i ≠ 0}, range (single K (fun x => K) i) = ⨅ i ∈ {i | w i = 0}, ker (proj i)
B₂ : ↥(⨅ i ∈ {i | w i = 0}, ker (proj i)) ≃ₗ[K] (i : ↑{i | w i ≠ 0}) → (fun x => K) ↑i
⊢ ↥(⨅ i ∈ {i | w i = 0}, ker (proj i)) ≃ₗ[K] { i // w i ≠ 0 } → K

Tactic:
apply B₂

Result:
no goals