l3lab/ntp-mathlib huggingface dataset:
@[simp]
theorem mul_same (k : n) (d : α) :
    stdBasisMatrix i j c * stdBasisMatrix j k d = stdBasisMatrix i k (c * d) := by
  ext a b
  simp only [mul_apply, stdBasisMatrix, boole_mul]
  by_cases h₁ : i = a <;> by_cases h₂ : k = b <;> 

Proof state:
case neg
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
i j : n
c : α
i' j' : n
inst✝ : Fintype n
k : n
d : α
a b : n
h₁ : i = a
h₂ : ¬k = b
⊢ (∑ x : n, (if i = a ∧ j = x then c else 0) * if j = x ∧ k = b then d else 0) = if i = a ∧ k = b then c * d else 0

Next tactic:
simp [h₁, h₂]
@[simp]
theorem mul_same (k : n) (d : α) :
    stdBasisMatrix i j c * stdBasisMatrix j k d = stdBasisMatrix i k (c * d) := by
  ext a b
  simp only [mul_apply, stdBasisMatrix, boole_mul]
  by_cases h₁ : i = a <;> by_cases h₂ : k = b <;> 

Proof state:
case pos
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
i j : n
c : α
i' j' : n
inst✝ : Fintype n
k : n
d : α
a b : n
h₁ : ¬i = a
h₂ : k = b
⊢ (∑ x : n, (if i = a ∧ j = x then c else 0) * if j = x ∧ k = b then d else 0) = if i = a ∧ k = b then c * d else 0

Next tactic:
simp [h₁, h₂]
@[simp]
theorem mul_same (k : n) (d : α) :
    stdBasisMatrix i j c * stdBasisMatrix j k d = stdBasisMatrix i k (c * d) := by
  ext a b
  simp only [mul_apply, stdBasisMatrix, boole_mul]
  by_cases h₁ : i = a <;> by_cases h₂ : k = b <;> 

Proof state:
case neg
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
i j : n
c : α
i' j' : n
inst✝ : Fintype n
k : n
d : α
a b : n
h₁ : ¬i = a
h₂ : ¬k = b
⊢ (∑ x : n, (if i = a ∧ j = x then c else 0) * if j = x ∧ k = b then d else 0) = if i = a ∧ k = b then c * d else 0

Next tactic:
simp [h₁, h₂]
@[simp]
theorem mul_of_ne {k l : n} (h : j ≠ k) (d : α) :
    stdBasisMatrix i j c * stdBasisMatrix k l d = 0 := by
  

Proof state:
l✝ : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l✝
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
i j : n
c : α
i' j' : n
inst✝ : Fintype n
k l : n
h : j ≠ k
d : α
⊢ stdBasisMatrix i j c * stdBasisMatrix k l d = 0

Next tactic:
ext a b
@[simp]
theorem mul_of_ne {k l : n} (h : j ≠ k) (d : α) :
    stdBasisMatrix i j c * stdBasisMatrix k l d = 0 := by
  ext a b
  

Proof state:
case a.h
l✝ : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l✝
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
i j : n
c : α
i' j' : n
inst✝ : Fintype n
k l : n
h : j ≠ k
d : α
a b : n
⊢ (stdBasisMatrix i j c * stdBasisMatrix k l d) a b = OfNat.ofNat 0 a b

Next tactic:
simp only [mul_apply, boole_mul, stdBasisMatrix]
@[simp]
theorem mul_of_ne {k l : n} (h : j ≠ k) (d : α) :
    stdBasisMatrix i j c * stdBasisMatrix k l d = 0 := by
  ext a b
  simp only [mul_apply, boole_mul, stdBasisMatrix]
  

Proof state:
case a.h
l✝ : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l✝
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
i j : n
c : α
i' j' : n
inst✝ : Fintype n
k l : n
h : j ≠ k
d : α
a b : n
⊢ (∑ x : n, (if i = a ∧ j = x then c else 0) * if k = x ∧ l = b then d else 0) = OfNat.ofNat 0 a b

Next tactic:
by_cases h₁ : i = a
@[simp]
theorem mul_of_ne {k l : n} (h : j ≠ k) (d : α) :
    stdBasisMatrix i j c * stdBasisMatrix k l d = 0 := by
  ext a b
  simp only [mul_apply, boole_mul, stdBasisMatrix]
  by_cases h₁ : i = a
  -- Porting note: was `simp [h₁, h, h.symm]`
  · 

Proof state:
case pos
l✝ : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l✝
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
i j : n
c : α
i' j' : n
inst✝ : Fintype n
k l : n
h : j ≠ k
d : α
a b : n
h₁ : i = a
⊢ (∑ x : n, (if i = a ∧ j = x then c else 0) * if k = x ∧ l = b then d else 0) = OfNat.ofNat 0 a b

Next tactic:
simp only [h₁, true_and, mul_ite, ite_mul, zero_mul, mul_zero, ← ite_and, zero_apply]
@[simp]
theorem mul_of_ne {k l : n} (h : j ≠ k) (d : α) :
    stdBasisMatrix i j c * stdBasisMatrix k l d = 0 := by
  ext a b
  simp only [mul_apply, boole_mul, stdBasisMatrix]
  by_cases h₁ : i = a
  -- Porting note: was `simp [h₁, h, h.symm]`
  · simp only [h₁, true_and, mul_ite, ite_mul, zero_mul, mul_zero, ← ite_and, zero_apply]
    

Proof state:
case pos
l✝ : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l✝
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
i j : n
c : α
i' j' : n
inst✝ : Fintype n
k l : n
h : j ≠ k
d : α
a b : n
h₁ : i = a
⊢ (∑ x : n, if (k = x ∧ l = b) ∧ j = x then c * d else 0) = 0

Next tactic:
refine Finset.sum_eq_zero (fun x _ => ?_)
@[simp]
theorem mul_of_ne {k l : n} (h : j ≠ k) (d : α) :
    stdBasisMatrix i j c * stdBasisMatrix k l d = 0 := by
  ext a b
  simp only [mul_apply, boole_mul, stdBasisMatrix]
  by_cases h₁ : i = a
  -- Porting note: was `simp [h₁, h, h.symm]`
  · simp only [h₁, true_and, mul_ite, ite_mul, zero_mul, mul_zero, ← ite_and, zero_apply]
    refine Finset.sum_eq_zero (fun x _ => ?_)
    

Proof state:
case pos
l✝ : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l✝
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
i j : n
c : α
i' j' : n
inst✝ : Fintype n
k l : n
h : j ≠ k
d : α
a b : n
h₁ : i = a
x : n
x✝ : x ∈ Finset.univ
⊢ (if (k = x ∧ l = b) ∧ j = x then c * d else 0) = 0

Next tactic:
apply if_neg
@[simp]
theorem mul_of_ne {k l : n} (h : j ≠ k) (d : α) :
    stdBasisMatrix i j c * stdBasisMatrix k l d = 0 := by
  ext a b
  simp only [mul_apply, boole_mul, stdBasisMatrix]
  by_cases h₁ : i = a
  -- Porting note: was `simp [h₁, h, h.symm]`
  · simp only [h₁, true_and, mul_ite, ite_mul, zero_mul, mul_zero, ← ite_and, zero_apply]
    refine Finset.sum_eq_zero (fun x _ => ?_)
    apply if_neg
    

Proof state:
case pos.hnc
l✝ : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l✝
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
i j : n
c : α
i' j' : n
inst✝ : Fintype n
k l : n
h : j ≠ k
d : α
a b : n
h₁ : i = a
x : n
x✝ : x ∈ Finset.univ
⊢ ¬((k = x ∧ l = b) ∧ j = x)

Next tactic:
rintro ⟨⟨rfl, rfl⟩, h⟩
@[simp]
theorem mul_of_ne {k l : n} (h : j ≠ k) (d : α) :
    stdBasisMatrix i j c * stdBasisMatrix k l d = 0 := by
  ext a b
  simp only [mul_apply, boole_mul, stdBasisMatrix]
  by_cases h₁ : i = a
  -- Porting note: was `simp [h₁, h, h.symm]`
  · simp only [h₁, true_and, mul_ite, ite_mul, zero_mul, mul_zero, ← ite_and, zero_apply]
    refine Finset.sum_eq_zero (fun x _ => ?_)
    apply if_neg
    rintro ⟨⟨rfl, rfl⟩, h⟩
    

Proof state:
case pos.hnc.intro.intro
l✝ : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l✝
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
i j : n
c : α
i' j' : n
inst✝ : Fintype n
k l : n
h✝ : j ≠ k
d : α
a : n
h₁ : i = a
x✝ : k ∈ Finset.univ
h : j = k
⊢ False

Next tactic:
contradiction
@[simp]
theorem mul_of_ne {k l : n} (h : j ≠ k) (d : α) :
    stdBasisMatrix i j c * stdBasisMatrix k l d = 0 := by
  ext a b
  simp only [mul_apply, boole_mul, stdBasisMatrix]
  by_cases h₁ : i = a
  -- Porting note: was `simp [h₁, h, h.symm]`
  · simp only [h₁, true_and, mul_ite, ite_mul, zero_mul, mul_zero, ← ite_and, zero_apply]
    refine Finset.sum_eq_zero (fun x _ => ?_)
    apply if_neg
    rintro ⟨⟨rfl, rfl⟩, h⟩
    contradiction
  · 

Proof state:
case neg
l✝ : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l✝
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
i j : n
c : α
i' j' : n
inst✝ : Fintype n
k l : n
h : j ≠ k
d : α
a b : n
h₁ : ¬i = a
⊢ (∑ x : n, (if i = a ∧ j = x then c else 0) * if k = x ∧ l = b then d else 0) = OfNat.ofNat 0 a b

Next tactic:
simp only [h₁, false_and, ite_false, mul_ite, zero_mul, mul_zero, ite_self,
      Finset.sum_const_zero, zero_apply]
theorem row_eq_zero_of_commute_stdBasisMatrix {i j k : n} {M : Matrix n n α}
    (hM : Commute (stdBasisMatrix i j 1) M) (hkj : k ≠ j) : M j k = 0 := by
  

Proof state:
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
i j k : n
M : Matrix n n α
hM : Commute (stdBasisMatrix i j 1) M
hkj : k ≠ j
⊢ M j k = 0

Next tactic:
have := ext_iff.mpr hM i k
theorem row_eq_zero_of_commute_stdBasisMatrix {i j k : n} {M : Matrix n n α}
    (hM : Commute (stdBasisMatrix i j 1) M) (hkj : k ≠ j) : M j k = 0 := by
  have := ext_iff.mpr hM i k
  

Proof state:
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
i j k : n
M : Matrix n n α
hM : Commute (stdBasisMatrix i j 1) M
hkj : k ≠ j
this : (stdBasisMatrix i j 1 * M) i k = (M * stdBasisMatrix i j 1) i k
⊢ M j k = 0

Next tactic:
aesop
theorem col_eq_zero_of_commute_stdBasisMatrix {i j k : n} {M : Matrix n n α}
    (hM : Commute (stdBasisMatrix i j 1) M) (hki : k ≠ i) : M k i = 0 := by
  

Proof state:
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
i j k : n
M : Matrix n n α
hM : Commute (stdBasisMatrix i j 1) M
hki : k ≠ i
⊢ M k i = 0

Next tactic:
have := ext_iff.mpr hM k j
theorem col_eq_zero_of_commute_stdBasisMatrix {i j k : n} {M : Matrix n n α}
    (hM : Commute (stdBasisMatrix i j 1) M) (hki : k ≠ i) : M k i = 0 := by
  have := ext_iff.mpr hM k j
  

Proof state:
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
i j k : n
M : Matrix n n α
hM : Commute (stdBasisMatrix i j 1) M
hki : k ≠ i
this : (stdBasisMatrix i j 1 * M) k j = (M * stdBasisMatrix i j 1) k j
⊢ M k i = 0

Next tactic:
aesop
theorem diag_eq_of_commute_stdBasisMatrix {i j : n} {M : Matrix n n α}
    (hM : Commute (stdBasisMatrix i j 1) M) : M i i = M j j := by
  

Proof state:
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
i j : n
M : Matrix n n α
hM : Commute (stdBasisMatrix i j 1) M
⊢ M i i = M j j

Next tactic:
have := ext_iff.mpr hM i j
theorem diag_eq_of_commute_stdBasisMatrix {i j : n} {M : Matrix n n α}
    (hM : Commute (stdBasisMatrix i j 1) M) : M i i = M j j := by
  have := ext_iff.mpr hM i j
  

Proof state:
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
i j : n
M : Matrix n n α
hM : Commute (stdBasisMatrix i j 1) M
this : (stdBasisMatrix i j 1 * M) i j = (M * stdBasisMatrix i j 1) i j
⊢ M i i = M j j

Next tactic:
aesop
/-- `M` is a scalar matrix if it commutes with every non-diagonal `stdBasisMatrix`. ​-/
theorem mem_range_scalar_of_commute_stdBasisMatrix {M : Matrix n n α}
    (hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M) :
    M ∈ Set.range (Matrix.scalar n) := by
  

Proof state:
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
M : Matrix n n α
hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M
⊢ M ∈ Set.range ⇑(scalar n)

Next tactic:
cases isEmpty_or_nonempty n
/-- `M` is a scalar matrix if it commutes with every non-diagonal `stdBasisMatrix`. ​-/
theorem mem_range_scalar_of_commute_stdBasisMatrix {M : Matrix n n α}
    (hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M) :
    M ∈ Set.range (Matrix.scalar n) := by
  cases isEmpty_or_nonempty n
  · 

Proof state:
case inl
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
M : Matrix n n α
hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M
h✝ : IsEmpty n
⊢ M ∈ Set.range ⇑(scalar n)

Next tactic:
exact ⟨0, Subsingleton.elim _ _⟩
/-- `M` is a scalar matrix if it commutes with every non-diagonal `stdBasisMatrix`. ​-/
theorem mem_range_scalar_of_commute_stdBasisMatrix {M : Matrix n n α}
    (hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M) :
    M ∈ Set.range (Matrix.scalar n) := by
  cases isEmpty_or_nonempty n
  · exact ⟨0, Subsingleton.elim _ _⟩
  

Proof state:
case inr
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
M : Matrix n n α
hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M
h✝ : Nonempty n
⊢ M ∈ Set.range ⇑(scalar n)

Next tactic:
obtain ⟨i⟩ := ‹Nonempty n›
/-- `M` is a scalar matrix if it commutes with every non-diagonal `stdBasisMatrix`. ​-/
theorem mem_range_scalar_of_commute_stdBasisMatrix {M : Matrix n n α}
    (hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M) :
    M ∈ Set.range (Matrix.scalar n) := by
  cases isEmpty_or_nonempty n
  · exact ⟨0, Subsingleton.elim _ _⟩
  obtain ⟨i⟩ := ‹Nonempty n›
  

Proof state:
case inr.intro
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
M : Matrix n n α
hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M
h✝ : Nonempty n
i : n
⊢ M ∈ Set.range ⇑(scalar n)

Next tactic:
refine ⟨M i i, Matrix.ext fun j k => ?_⟩
/-- `M` is a scalar matrix if it commutes with every non-diagonal `stdBasisMatrix`. ​-/
theorem mem_range_scalar_of_commute_stdBasisMatrix {M : Matrix n n α}
    (hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M) :
    M ∈ Set.range (Matrix.scalar n) := by
  cases isEmpty_or_nonempty n
  · exact ⟨0, Subsingleton.elim _ _⟩
  obtain ⟨i⟩ := ‹Nonempty n›
  refine ⟨M i i, Matrix.ext fun j k => ?_⟩
  

Proof state:
case inr.intro
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
M : Matrix n n α
hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M
h✝ : Nonempty n
i j k : n
⊢ (scalar n) (M i i) j k = M j k

Next tactic:
simp only [scalar_apply]
/-- `M` is a scalar matrix if it commutes with every non-diagonal `stdBasisMatrix`. ​-/
theorem mem_range_scalar_of_commute_stdBasisMatrix {M : Matrix n n α}
    (hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M) :
    M ∈ Set.range (Matrix.scalar n) := by
  cases isEmpty_or_nonempty n
  · exact ⟨0, Subsingleton.elim _ _⟩
  obtain ⟨i⟩ := ‹Nonempty n›
  refine ⟨M i i, Matrix.ext fun j k => ?_⟩
  simp only [scalar_apply]
  

Proof state:
case inr.intro
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
M : Matrix n n α
hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M
h✝ : Nonempty n
i j k : n
⊢ diagonal (fun x => M i i) j k = M j k

Next tactic:
obtain rfl | hkl := Decidable.eq_or_ne j k
/-- `M` is a scalar matrix if it commutes with every non-diagonal `stdBasisMatrix`. ​-/
theorem mem_range_scalar_of_commute_stdBasisMatrix {M : Matrix n n α}
    (hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M) :
    M ∈ Set.range (Matrix.scalar n) := by
  cases isEmpty_or_nonempty n
  · exact ⟨0, Subsingleton.elim _ _⟩
  obtain ⟨i⟩ := ‹Nonempty n›
  refine ⟨M i i, Matrix.ext fun j k => ?_⟩
  simp only [scalar_apply]
  obtain rfl | hkl := Decidable.eq_or_ne j k
  · 

Proof state:
case inr.intro.inl
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
M : Matrix n n α
hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M
h✝ : Nonempty n
i j : n
⊢ diagonal (fun x => M i i) j j = M j j

Next tactic:
rw [diagonal_apply_eq]
/-- `M` is a scalar matrix if it commutes with every non-diagonal `stdBasisMatrix`. ​-/
theorem mem_range_scalar_of_commute_stdBasisMatrix {M : Matrix n n α}
    (hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M) :
    M ∈ Set.range (Matrix.scalar n) := by
  cases isEmpty_or_nonempty n
  · exact ⟨0, Subsingleton.elim _ _⟩
  obtain ⟨i⟩ := ‹Nonempty n›
  refine ⟨M i i, Matrix.ext fun j k => ?_⟩
  simp only [scalar_apply]
  obtain rfl | hkl := Decidable.eq_or_ne j k
  · rw [diagonal_apply_eq]
    

Proof state:
case inr.intro.inl
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
M : Matrix n n α
hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M
h✝ : Nonempty n
i j : n
⊢ M i i = M j j

Next tactic:
obtain rfl | hij := Decidable.eq_or_ne i j
/-- `M` is a scalar matrix if it commutes with every non-diagonal `stdBasisMatrix`. ​-/
theorem mem_range_scalar_of_commute_stdBasisMatrix {M : Matrix n n α}
    (hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M) :
    M ∈ Set.range (Matrix.scalar n) := by
  cases isEmpty_or_nonempty n
  · exact ⟨0, Subsingleton.elim _ _⟩
  obtain ⟨i⟩ := ‹Nonempty n›
  refine ⟨M i i, Matrix.ext fun j k => ?_⟩
  simp only [scalar_apply]
  obtain rfl | hkl := Decidable.eq_or_ne j k
  · rw [diagonal_apply_eq]
    obtain rfl | hij := Decidable.eq_or_ne i j
    · 

Proof state:
case inr.intro.inl.inl
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
M : Matrix n n α
hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M
h✝ : Nonempty n
i : n
⊢ M i i = M i i

Next tactic:
rfl
/-- `M` is a scalar matrix if it commutes with every non-diagonal `stdBasisMatrix`. ​-/
theorem mem_range_scalar_of_commute_stdBasisMatrix {M : Matrix n n α}
    (hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M) :
    M ∈ Set.range (Matrix.scalar n) := by
  cases isEmpty_or_nonempty n
  · exact ⟨0, Subsingleton.elim _ _⟩
  obtain ⟨i⟩ := ‹Nonempty n›
  refine ⟨M i i, Matrix.ext fun j k => ?_⟩
  simp only [scalar_apply]
  obtain rfl | hkl := Decidable.eq_or_ne j k
  · rw [diagonal_apply_eq]
    obtain rfl | hij := Decidable.eq_or_ne i j
    · rfl
    · 

Proof state:
case inr.intro.inl.inr
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
M : Matrix n n α
hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M
h✝ : Nonempty n
i j : n
hij : i ≠ j
⊢ M i i = M j j

Next tactic:
exact diag_eq_of_commute_stdBasisMatrix (hM _ _ hij)
/-- `M` is a scalar matrix if it commutes with every non-diagonal `stdBasisMatrix`. ​-/
theorem mem_range_scalar_of_commute_stdBasisMatrix {M : Matrix n n α}
    (hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M) :
    M ∈ Set.range (Matrix.scalar n) := by
  cases isEmpty_or_nonempty n
  · exact ⟨0, Subsingleton.elim _ _⟩
  obtain ⟨i⟩ := ‹Nonempty n›
  refine ⟨M i i, Matrix.ext fun j k => ?_⟩
  simp only [scalar_apply]
  obtain rfl | hkl := Decidable.eq_or_ne j k
  · rw [diagonal_apply_eq]
    obtain rfl | hij := Decidable.eq_or_ne i j
    · rfl
    · exact diag_eq_of_commute_stdBasisMatrix (hM _ _ hij)
  · 

Proof state:
case inr.intro.inr
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
M : Matrix n n α
hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M
h✝ : Nonempty n
i j k : n
hkl : j ≠ k
⊢ diagonal (fun x => M i i) j k = M j k

Next tactic:
push_neg at hkl
/-- `M` is a scalar matrix if it commutes with every non-diagonal `stdBasisMatrix`. ​-/
theorem mem_range_scalar_of_commute_stdBasisMatrix {M : Matrix n n α}
    (hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M) :
    M ∈ Set.range (Matrix.scalar n) := by
  cases isEmpty_or_nonempty n
  · exact ⟨0, Subsingleton.elim _ _⟩
  obtain ⟨i⟩ := ‹Nonempty n›
  refine ⟨M i i, Matrix.ext fun j k => ?_⟩
  simp only [scalar_apply]
  obtain rfl | hkl := Decidable.eq_or_ne j k
  · rw [diagonal_apply_eq]
    obtain rfl | hij := Decidable.eq_or_ne i j
    · rfl
    · exact diag_eq_of_commute_stdBasisMatrix (hM _ _ hij)
  · push_neg at hkl
    

Proof state:
case inr.intro.inr
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
M : Matrix n n α
hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M
h✝ : Nonempty n
i j k : n
hkl : j ≠ k
⊢ diagonal (fun x => M i i) j k = M j k

Next tactic:
rw [diagonal_apply_ne _ hkl]
/-- `M` is a scalar matrix if it commutes with every non-diagonal `stdBasisMatrix`. ​-/
theorem mem_range_scalar_of_commute_stdBasisMatrix {M : Matrix n n α}
    (hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M) :
    M ∈ Set.range (Matrix.scalar n) := by
  cases isEmpty_or_nonempty n
  · exact ⟨0, Subsingleton.elim _ _⟩
  obtain ⟨i⟩ := ‹Nonempty n›
  refine ⟨M i i, Matrix.ext fun j k => ?_⟩
  simp only [scalar_apply]
  obtain rfl | hkl := Decidable.eq_or_ne j k
  · rw [diagonal_apply_eq]
    obtain rfl | hij := Decidable.eq_or_ne i j
    · rfl
    · exact diag_eq_of_commute_stdBasisMatrix (hM _ _ hij)
  · push_neg at hkl
    rw [diagonal_apply_ne _ hkl]
    

Proof state:
case inr.intro.inr
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
M : Matrix n n α
hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M
h✝ : Nonempty n
i j k : n
hkl : j ≠ k
⊢ 0 = M j k

Next tactic:
obtain rfl | hij := Decidable.eq_or_ne i j
/-- `M` is a scalar matrix if it commutes with every non-diagonal `stdBasisMatrix`. ​-/
theorem mem_range_scalar_of_commute_stdBasisMatrix {M : Matrix n n α}
    (hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M) :
    M ∈ Set.range (Matrix.scalar n) := by
  cases isEmpty_or_nonempty n
  · exact ⟨0, Subsingleton.elim _ _⟩
  obtain ⟨i⟩ := ‹Nonempty n›
  refine ⟨M i i, Matrix.ext fun j k => ?_⟩
  simp only [scalar_apply]
  obtain rfl | hkl := Decidable.eq_or_ne j k
  · rw [diagonal_apply_eq]
    obtain rfl | hij := Decidable.eq_or_ne i j
    · rfl
    · exact diag_eq_of_commute_stdBasisMatrix (hM _ _ hij)
  · push_neg at hkl
    rw [diagonal_apply_ne _ hkl]
    obtain rfl | hij := Decidable.eq_or_ne i j
    · 

Proof state:
case inr.intro.inr.inl
l : Type u_1
m : Type u_2
n : Type u_3
R : Type u_4
α : Type u_5
inst✝⁴ : DecidableEq l
inst✝³ : DecidableEq m
inst✝² : DecidableEq n
inst✝¹ : Semiring α
inst✝ : Fintype n
M : Matrix n n α
hM : ∀ (i j : n), i ≠ j → Commute (stdBasisMatrix i j 1) M
h✝ : Nonempty n
i k : n
hkl : i ≠ k
⊢ 0 = M i k

Next tactic:
rw [col_eq_zero_of_commute_stdBasisMatrix (hM k i hkl.symm) hkl]