-- Mathlib/RingTheory/MatrixAlgebra.lean
theorem right_inv (M : Matrix n n A) : (toFunAlgHom n R A) (invFun n R A M) = M

Proof state:
case h.e'_3
n : Type u_1
R : Type u_2
A : Type u_3
inst✝⁴ : CommSemiring R
inst✝³ : Semiring A
inst✝² : Algebra R A
inst✝¹ : DecidableEq n
inst✝ : Fintype n
M : Matrix n n A
⊢ ∑ i : n, ∑ j : n, stdBasisMatrix i j (M i j) =
    ∑ x : n, ∑ y : n, M (x, y).1 (x, y).2 • (stdBasisMatrix (x, y).1 (x, y).2 1).map ⇑(algebraMap R A)

Tactic:
refine Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun j _ => Matrix.ext fun a b => ?_

Result:
case h.e'_3
n : Type u_1
R : Type u_2
A : Type u_3
inst✝⁴ : CommSemiring R
inst✝³ : Semiring A
inst✝² : Algebra R A
inst✝¹ : DecidableEq n
inst✝ : Fintype n
M : Matrix n n A
i : n
x✝¹ : i ∈ Finset.univ
j : n
x✝ : j ∈ Finset.univ
a b : n
⊢ stdBasisMatrix i j (M i j) a b =
    (M (i, j).1 (i, j).2 • (stdBasisMatrix (i, j).1 (i, j).2 1).map ⇑(algebraMap R A)) a b

Proof state:
case h.e'_3
n : Type u_1
R : Type u_2
A : Type u_3
inst✝⁴ : CommSemiring R
inst✝³ : Semiring A
inst✝² : Algebra R A
inst✝¹ : DecidableEq n
inst✝ : Fintype n
M : Matrix n n A
i : n
x✝¹ : i ∈ Finset.univ
j : n
x✝ : j ∈ Finset.univ
a b : n
⊢ stdBasisMatrix i j (M i j) a b =
    (M (i, j).1 (i, j).2 • (stdBasisMatrix (i, j).1 (i, j).2 1).map ⇑(algebraMap R A)) a b

Tactic:
dsimp [stdBasisMatrix]

Result:
case h.e'_3
n : Type u_1
R : Type u_2
A : Type u_3
inst✝⁴ : CommSemiring R
inst✝³ : Semiring A
inst✝² : Algebra R A
inst✝¹ : DecidableEq n
inst✝ : Fintype n
M : Matrix n n A
i : n
x✝¹ : i ∈ Finset.univ
j : n
x✝ : j ∈ Finset.univ
a b : n
⊢ (if i = a ∧ j = b then M i j else 0) = M i j * (algebraMap R A) (if i = a ∧ j = b then 1 else 0)

Proof state:
case h.e'_3
n : Type u_1
R : Type u_2
A : Type u_3
inst✝⁴ : CommSemiring R
inst✝³ : Semiring A
inst✝² : Algebra R A
inst✝¹ : DecidableEq n
inst✝ : Fintype n
M : Matrix n n A
i : n
x✝¹ : i ∈ Finset.univ
j : n
x✝ : j ∈ Finset.univ
a b : n
⊢ (if i = a ∧ j = b then M i j else 0) = M i j * (algebraMap R A) (if i = a ∧ j = b then 1 else 0)

Tactic:
split_ifs <;> aesop

Result:
no goals

Proof state:
n : Type u_1
R : Type u_2
A : Type u_3
inst✝⁴ : CommSemiring R
inst✝³ : Semiring A
inst✝² : Algebra R A
inst✝¹ : DecidableEq n
inst✝ : Fintype n
M : Matrix n n A
⊢ (toFunAlgHom n R A) (invFun n R A M) = M

Tactic:
simp only [invFun, map_sum, toFunAlgHom_apply]

Result:
n : Type u_1
R : Type u_2
A : Type u_3
inst✝⁴ : CommSemiring R
inst✝³ : Semiring A
inst✝² : Algebra R A
inst✝¹ : DecidableEq n
inst✝ : Fintype n
M : Matrix n n A
⊢ ∑ x : n × n, M x.1 x.2 • (stdBasisMatrix x.1 x.2 1).map ⇑(algebraMap R A) = M

Proof state:
case h.e'_3
n : Type u_1
R : Type u_2
A : Type u_3
inst✝⁴ : CommSemiring R
inst✝³ : Semiring A
inst✝² : Algebra R A
inst✝¹ : DecidableEq n
inst✝ : Fintype n
M : Matrix n n A
⊢ M = ∑ x : n, ∑ y : n, M (x, y).1 (x, y).2 • (stdBasisMatrix (x, y).1 (x, y).2 1).map ⇑(algebraMap R A)

Tactic:
conv_lhs => rw [matrix_eq_sum_stdBasisMatrix M]

Result:
case h.e'_3
n : Type u_1
R : Type u_2
A : Type u_3
inst✝⁴ : CommSemiring R
inst✝³ : Semiring A
inst✝² : Algebra R A
inst✝¹ : DecidableEq n
inst✝ : Fintype n
M : Matrix n n A
⊢ ∑ i : n, ∑ j : n, stdBasisMatrix i j (M i j) =
    ∑ x : n, ∑ y : n, M (x, y).1 (x, y).2 • (stdBasisMatrix (x, y).1 (x, y).2 1).map ⇑(algebraMap R A)

Proof state:
n : Type u_1
R : Type u_2
A : Type u_3
inst✝⁴ : CommSemiring R
inst✝³ : Semiring A
inst✝² : Algebra R A
inst✝¹ : DecidableEq n
inst✝ : Fintype n
M : Matrix n n A
⊢ ∑ x : n × n, M x.1 x.2 • (stdBasisMatrix x.1 x.2 1).map ⇑(algebraMap R A) = M

Tactic:
convert Finset.sum_product (β := Matrix n n A) ..

Result:
case h.e'_3
n : Type u_1
R : Type u_2
A : Type u_3
inst✝⁴ : CommSemiring R
inst✝³ : Semiring A
inst✝² : Algebra R A
inst✝¹ : DecidableEq n
inst✝ : Fintype n
M : Matrix n n A
⊢ M = ∑ x : n, ∑ y : n, M (x, y).1 (x, y).2 • (stdBasisMatrix (x, y).1 (x, y).2 1).map ⇑(algebraMap R A)