l3lab/ntp-mathlib huggingface dataset:
theorem submatrix {M : Matrix n n R} (hM : M.PosSemidef) (e : m → n) :
    (M.submatrix e e).PosSemidef := by
  classical
  

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁵ : Fintype m
inst✝⁴ : Fintype n
inst✝³ : CommRing R
inst✝² : PartialOrder R
inst✝¹ : StarOrderedRing R
inst✝ : IsROrC 𝕜
M : Matrix n n R
hM : PosSemidef M
e : m → n
⊢ PosSemidef (Matrix.submatrix M e e)

Next tactic:
rw [(by simp : M = 1 * M * 1), submatrix_mul (he₂ := Function.bijective_id),
    submatrix_mul (he₂ := Function.bijective_id), submatrix_id_id]
theorem submatrix {M : Matrix n n R} (hM : M.PosSemidef) (e : m → n) :
    (M.submatrix e e).PosSemidef := by
  classical
  rw [(by 

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁵ : Fintype m
inst✝⁴ : Fintype n
inst✝³ : CommRing R
inst✝² : PartialOrder R
inst✝¹ : StarOrderedRing R
inst✝ : IsROrC 𝕜
M : Matrix n n R
hM : PosSemidef M
e : m → n
⊢ M = 1 * M * 1

Next tactic:
simp
theorem submatrix {M : Matrix n n R} (hM : M.PosSemidef) (e : m → n) :
    (M.submatrix e e).PosSemidef := by
  classical
  rw [(by simp : M = 1 * M * 1), submatrix_mul (he₂ := Function.bijective_id),
    submatrix_mul (he₂ := Function.bijective_id), submatrix_id_id]
  

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁵ : Fintype m
inst✝⁴ : Fintype n
inst✝³ : CommRing R
inst✝² : PartialOrder R
inst✝¹ : StarOrderedRing R
inst✝ : IsROrC 𝕜
M : Matrix n n R
hM : PosSemidef M
e : m → n
⊢ PosSemidef (Matrix.submatrix 1 e id * M * Matrix.submatrix 1 id e)

Next tactic:
simpa only [conjTranspose_submatrix, conjTranspose_one] using
    conjTranspose_mul_mul_same hM (Matrix.submatrix 1 id e)
theorem transpose {M : Matrix n n R} (hM : M.PosSemidef) : Mᵀ.PosSemidef := by
  

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁵ : Fintype m
inst✝⁴ : Fintype n
inst✝³ : CommRing R
inst✝² : PartialOrder R
inst✝¹ : StarOrderedRing R
inst✝ : IsROrC 𝕜
M : Matrix n n R
hM : PosSemidef M
⊢ PosSemidef Mᵀ

Next tactic:
refine ⟨IsHermitian.transpose hM.1, fun x => ?_⟩
theorem transpose {M : Matrix n n R} (hM : M.PosSemidef) : Mᵀ.PosSemidef := by
  refine ⟨IsHermitian.transpose hM.1, fun x => ?_⟩
  

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁵ : Fintype m
inst✝⁴ : Fintype n
inst✝³ : CommRing R
inst✝² : PartialOrder R
inst✝¹ : StarOrderedRing R
inst✝ : IsROrC 𝕜
M : Matrix n n R
hM : PosSemidef M
x : n → R
⊢ 0 ≤ star x ⬝ᵥ mulVec Mᵀ x

Next tactic:
convert hM.2 (star x) using 1
theorem transpose {M : Matrix n n R} (hM : M.PosSemidef) : Mᵀ.PosSemidef := by
  refine ⟨IsHermitian.transpose hM.1, fun x => ?_⟩
  convert hM.2 (star x) using 1
  

Proof state:
case h.e'_4
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁵ : Fintype m
inst✝⁴ : Fintype n
inst✝³ : CommRing R
inst✝² : PartialOrder R
inst✝¹ : StarOrderedRing R
inst✝ : IsROrC 𝕜
M : Matrix n n R
hM : PosSemidef M
x : n → R
⊢ star x ⬝ᵥ mulVec Mᵀ x = star (star x) ⬝ᵥ mulVec M (star x)

Next tactic:
rw [mulVec_transpose, Matrix.dotProduct_mulVec, star_star, dotProduct_comm]
protected lemma zero : PosSemidef (0 : Matrix n n R) :=
  ⟨isHermitian_zero, by 

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁵ : Fintype m
inst✝⁴ : Fintype n
inst✝³ : CommRing R
inst✝² : PartialOrder R
inst✝¹ : StarOrderedRing R
inst✝ : IsROrC 𝕜
⊢ ∀ (x : n → R), 0 ≤ star x ⬝ᵥ mulVec 0 x

Next tactic:
simp
protected lemma one [DecidableEq n] : PosSemidef (1 : Matrix n n R) :=
  ⟨isHermitian_one, fun x => by
    

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
x : n → R
⊢ 0 ≤ star x ⬝ᵥ mulVec 1 x

Next tactic:
rw [one_mulVec]
protected lemma one [DecidableEq n] : PosSemidef (1 : Matrix n n R) :=
  ⟨isHermitian_one, fun x => by
    rw [one_mulVec]; 

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
x : n → R
⊢ 0 ≤ star x ⬝ᵥ x

Next tactic:
exact Fintype.sum_nonneg fun i => star_mul_self_nonneg _
protected lemma pow [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) (k : ℕ) :
    PosSemidef (M ^ k) :=
  match k with
  | 0 => .one
  | 1 => by 

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
M : Matrix n n R
hM : PosSemidef M
k : ℕ
⊢ PosSemidef (M ^ 1)

Next tactic:
simpa using hM
protected lemma pow [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) (k : ℕ) :
    PosSemidef (M ^ k) :=
  match k with
  | 0 => .one
  | 1 => by simpa using hM
  | (k + 2) => by
    

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
M : Matrix n n R
hM : PosSemidef M
k✝ k : ℕ
⊢ PosSemidef (M ^ (k + 2))

Next tactic:
rw [pow_succ', pow_succ]
protected lemma pow [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) (k : ℕ) :
    PosSemidef (M ^ k) :=
  match k with
  | 0 => .one
  | 1 => by simpa using hM
  | (k + 2) => by
    rw [pow_succ', pow_succ]
    

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
M : Matrix n n R
hM : PosSemidef M
k✝ k : ℕ
⊢ PosSemidef (M * M ^ k * M)

Next tactic:
simpa only [hM.isHermitian.eq] using (hM.pow k).mul_mul_conjTranspose_same M
protected lemma inv [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) : M⁻¹.PosSemidef := by
  

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
M : Matrix n n R
hM : PosSemidef M
⊢ PosSemidef M⁻¹

Next tactic:
by_cases h : IsUnit M.det
protected lemma inv [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) : M⁻¹.PosSemidef := by
  by_cases h : IsUnit M.det
  · 

Proof state:
case pos
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
M : Matrix n n R
hM : PosSemidef M
h : IsUnit (det M)
⊢ PosSemidef M⁻¹

Next tactic:
have := (conjTranspose_mul_mul_same hM M⁻¹).conjTranspose
protected lemma inv [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) : M⁻¹.PosSemidef := by
  by_cases h : IsUnit M.det
  · have := (conjTranspose_mul_mul_same hM M⁻¹).conjTranspose
    

Proof state:
case pos
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
M : Matrix n n R
hM : PosSemidef M
h : IsUnit (det M)
this : PosSemidef (M⁻¹ᴴ * M * M⁻¹)ᴴ
⊢ PosSemidef M⁻¹

Next tactic:
rwa [mul_nonsing_inv_cancel_right _ _ h, conjTranspose_conjTranspose] at this
protected lemma inv [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) : M⁻¹.PosSemidef := by
  by_cases h : IsUnit M.det
  · have := (conjTranspose_mul_mul_same hM M⁻¹).conjTranspose
    rwa [mul_nonsing_inv_cancel_right _ _ h, conjTranspose_conjTranspose] at this
  · 

Proof state:
case neg
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
M : Matrix n n R
hM : PosSemidef M
h : ¬IsUnit (det M)
⊢ PosSemidef M⁻¹

Next tactic:
rw [nonsing_inv_apply_not_isUnit _ h]
protected lemma inv [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) : M⁻¹.PosSemidef := by
  by_cases h : IsUnit M.det
  · have := (conjTranspose_mul_mul_same hM M⁻¹).conjTranspose
    rwa [mul_nonsing_inv_cancel_right _ _ h, conjTranspose_conjTranspose] at this
  · rw [nonsing_inv_apply_not_isUnit _ h]
    

Proof state:
case neg
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
M : Matrix n n R
hM : PosSemidef M
h : ¬IsUnit (det M)
⊢ PosSemidef 0

Next tactic:
exact .zero
protected lemma zpow [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) (z : ℤ) :
    (M ^ z).PosSemidef := by
  

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
M : Matrix n n R
hM : PosSemidef M
z : ℤ
⊢ PosSemidef (M ^ z)

Next tactic:
obtain ⟨n, rfl | rfl⟩ := z.eq_nat_or_neg
protected lemma zpow [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) (z : ℤ) :
    (M ^ z).PosSemidef := by
  obtain ⟨n, rfl | rfl⟩ := z.eq_nat_or_neg
  · 

Proof state:
case intro.inl
m : Type u_1
n✝ : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n✝
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n✝
M : Matrix n✝ n✝ R
hM : PosSemidef M
n : ℕ
⊢ PosSemidef (M ^ ↑n)

Next tactic:
simpa using hM.pow n
protected lemma zpow [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) (z : ℤ) :
    (M ^ z).PosSemidef := by
  obtain ⟨n, rfl | rfl⟩ := z.eq_nat_or_neg
  · simpa using hM.pow n
  · 

Proof state:
case intro.inr
m : Type u_1
n✝ : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n✝
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n✝
M : Matrix n✝ n✝ R
hM : PosSemidef M
n : ℕ
⊢ PosSemidef (M ^ (-↑n))

Next tactic:
simpa using (hM.pow n).inv
lemma posSemidef_sqrt : PosSemidef hA.sqrt := by
  

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
⊢ PosSemidef hA.sqrt

Next tactic:
apply PosSemidef.mul_mul_conjTranspose_same
lemma posSemidef_sqrt : PosSemidef hA.sqrt := by
  apply PosSemidef.mul_mul_conjTranspose_same
  

Proof state:
case hA
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
⊢ PosSemidef (diagonal (IsROrC.ofReal ∘ Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A)))

Next tactic:
refine posSemidef_diagonal_iff.mpr fun i ↦ ?_
lemma posSemidef_sqrt : PosSemidef hA.sqrt := by
  apply PosSemidef.mul_mul_conjTranspose_same
  refine posSemidef_diagonal_iff.mpr fun i ↦ ?_
  

Proof state:
case hA
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
i : n
⊢ 0 ≤ (IsROrC.ofReal ∘ Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A)) i

Next tactic:
rw [Function.comp_apply, IsROrC.nonneg_iff]
lemma posSemidef_sqrt : PosSemidef hA.sqrt := by
  apply PosSemidef.mul_mul_conjTranspose_same
  refine posSemidef_diagonal_iff.mpr fun i ↦ ?_
  rw [Function.comp_apply, IsROrC.nonneg_iff]
  

Proof state:
case hA
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
i : n
⊢ 0 ≤ IsROrC.re ↑((Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A)) i) ∧
    IsROrC.im ↑((Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A)) i) = 0

Next tactic:
constructor
lemma posSemidef_sqrt : PosSemidef hA.sqrt := by
  apply PosSemidef.mul_mul_conjTranspose_same
  refine posSemidef_diagonal_iff.mpr fun i ↦ ?_
  rw [Function.comp_apply, IsROrC.nonneg_iff]
  constructor
  · 

Proof state:
case hA.left
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
i : n
⊢ 0 ≤ IsROrC.re ↑((Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A)) i)

Next tactic:
simp only [IsROrC.ofReal_re]
lemma posSemidef_sqrt : PosSemidef hA.sqrt := by
  apply PosSemidef.mul_mul_conjTranspose_same
  refine posSemidef_diagonal_iff.mpr fun i ↦ ?_
  rw [Function.comp_apply, IsROrC.nonneg_iff]
  constructor
  · simp only [IsROrC.ofReal_re]
    

Proof state:
case hA.left
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
i : n
⊢ 0 ≤ (Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A)) i

Next tactic:
exact Real.sqrt_nonneg _
lemma posSemidef_sqrt : PosSemidef hA.sqrt := by
  apply PosSemidef.mul_mul_conjTranspose_same
  refine posSemidef_diagonal_iff.mpr fun i ↦ ?_
  rw [Function.comp_apply, IsROrC.nonneg_iff]
  constructor
  · simp only [IsROrC.ofReal_re]
    exact Real.sqrt_nonneg _
  · 

Proof state:
case hA.right
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
i : n
⊢ IsROrC.im ↑((Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A)) i) = 0

Next tactic:
simp only [IsROrC.ofReal_im]
@[simp]
lemma sq_sqrt : hA.sqrt ^ 2 = A := by
  

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
⊢ hA.sqrt ^ 2 = A

Next tactic:
let C := hA.1.eigenvectorMatrix
@[simp]
lemma sq_sqrt : hA.sqrt ^ 2 = A := by
  let C := hA.1.eigenvectorMatrix
  

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
C : Matrix n n 𝕜 := IsHermitian.eigenvectorMatrix (_ : IsHermitian A)
⊢ hA.sqrt ^ 2 = A

Next tactic:
let E := diagonal ((↑) ∘ Real.sqrt ∘ hA.1.eigenvalues : n → 𝕜)
@[simp]
lemma sq_sqrt : hA.sqrt ^ 2 = A := by
  let C := hA.1.eigenvectorMatrix
  let E := diagonal ((↑) ∘ Real.sqrt ∘ hA.1.eigenvalues : n → 𝕜)
  

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
C : Matrix n n 𝕜 := IsHermitian.eigenvectorMatrix (_ : IsHermitian A)
E : Matrix n n 𝕜 := diagonal (IsROrC.ofReal ∘ Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A))
⊢ hA.sqrt ^ 2 = A

Next tactic:
suffices : C * (E * (Cᴴ * C) * E) * Cᴴ = A
@[simp]
lemma sq_sqrt : hA.sqrt ^ 2 = A := by
  let C := hA.1.eigenvectorMatrix
  let E := diagonal ((↑) ∘ Real.sqrt ∘ hA.1.eigenvalues : n → 𝕜)
  suffices : C * (E * (Cᴴ * C) * E) * Cᴴ = A
  · 

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
C : Matrix n n 𝕜 := IsHermitian.eigenvectorMatrix (_ : IsHermitian A)
E : Matrix n n 𝕜 := diagonal (IsROrC.ofReal ∘ Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A))
this : C * (E * (Cᴴ * C) * E) * Cᴴ = A
⊢ hA.sqrt ^ 2 = A

Next tactic:
rw [Matrix.PosSemidef.sqrt, pow_two]
@[simp]
lemma sq_sqrt : hA.sqrt ^ 2 = A := by
  let C := hA.1.eigenvectorMatrix
  let E := diagonal ((↑) ∘ Real.sqrt ∘ hA.1.eigenvalues : n → 𝕜)
  suffices : C * (E * (Cᴴ * C) * E) * Cᴴ = A
  · rw [Matrix.PosSemidef.sqrt, pow_two]
    

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
C : Matrix n n 𝕜 := IsHermitian.eigenvectorMatrix (_ : IsHermitian A)
E : Matrix n n 𝕜 := diagonal (IsROrC.ofReal ∘ Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A))
this : C * (E * (Cᴴ * C) * E) * Cᴴ = A
⊢ IsHermitian.eigenvectorMatrix (_ : IsHermitian A) *
          diagonal (IsROrC.ofReal ∘ Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A)) *
        (IsHermitian.eigenvectorMatrix (_ : IsHermitian A))ᴴ *
      (IsHermitian.eigenvectorMatrix (_ : IsHermitian A) *
          diagonal (IsROrC.ofReal ∘ Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A)) *
        (IsHermitian.eigenvectorMatrix (_ : IsHermitian A))ᴴ) =
    A

Next tactic:
change (C * E * Cᴴ) * (C * E * Cᴴ) = A
@[simp]
lemma sq_sqrt : hA.sqrt ^ 2 = A := by
  let C := hA.1.eigenvectorMatrix
  let E := diagonal ((↑) ∘ Real.sqrt ∘ hA.1.eigenvalues : n → 𝕜)
  suffices : C * (E * (Cᴴ * C) * E) * Cᴴ = A
  · rw [Matrix.PosSemidef.sqrt, pow_two]
    change (C * E * Cᴴ) * (C * E * Cᴴ) = A
    

Proof state:
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
C : Matrix n n 𝕜 := IsHermitian.eigenvectorMatrix (_ : IsHermitian A)
E : Matrix n n 𝕜 := diagonal (IsROrC.ofReal ∘ Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A))
this : C * (E * (Cᴴ * C) * E) * Cᴴ = A
⊢ C * E * Cᴴ * (C * E * Cᴴ) = A

Next tactic:
simpa only [← mul_assoc] using this
@[simp]
lemma sq_sqrt : hA.sqrt ^ 2 = A := by
  let C := hA.1.eigenvectorMatrix
  let E := diagonal ((↑) ∘ Real.sqrt ∘ hA.1.eigenvalues : n → 𝕜)
  suffices : C * (E * (Cᴴ * C) * E) * Cᴴ = A
  · rw [Matrix.PosSemidef.sqrt, pow_two]
    change (C * E * Cᴴ) * (C * E * Cᴴ) = A
    simpa only [← mul_assoc] using this
  

Proof state:
case this
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
C : Matrix n n 𝕜 := IsHermitian.eigenvectorMatrix (_ : IsHermitian A)
E : Matrix n n 𝕜 := diagonal (IsROrC.ofReal ∘ Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A))
⊢ C * (E * (Cᴴ * C) * E) * Cᴴ = A

Next tactic:
have : Cᴴ * C = 1
@[simp]
lemma sq_sqrt : hA.sqrt ^ 2 = A := by
  let C := hA.1.eigenvectorMatrix
  let E := diagonal ((↑) ∘ Real.sqrt ∘ hA.1.eigenvalues : n → 𝕜)
  suffices : C * (E * (Cᴴ * C) * E) * Cᴴ = A
  · rw [Matrix.PosSemidef.sqrt, pow_two]
    change (C * E * Cᴴ) * (C * E * Cᴴ) = A
    simpa only [← mul_assoc] using this
  have : Cᴴ * C = 1
  · 

Proof state:
case this
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
C : Matrix n n 𝕜 := IsHermitian.eigenvectorMatrix (_ : IsHermitian A)
E : Matrix n n 𝕜 := diagonal (IsROrC.ofReal ∘ Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A))
⊢ Cᴴ * C = 1

Next tactic:
rw [Matrix.IsHermitian.conjTranspose_eigenvectorMatrix, mul_eq_one_comm]
@[simp]
lemma sq_sqrt : hA.sqrt ^ 2 = A := by
  let C := hA.1.eigenvectorMatrix
  let E := diagonal ((↑) ∘ Real.sqrt ∘ hA.1.eigenvalues : n → 𝕜)
  suffices : C * (E * (Cᴴ * C) * E) * Cᴴ = A
  · rw [Matrix.PosSemidef.sqrt, pow_two]
    change (C * E * Cᴴ) * (C * E * Cᴴ) = A
    simpa only [← mul_assoc] using this
  have : Cᴴ * C = 1
  · rw [Matrix.IsHermitian.conjTranspose_eigenvectorMatrix, mul_eq_one_comm]
    

Proof state:
case this
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
C : Matrix n n 𝕜 := IsHermitian.eigenvectorMatrix (_ : IsHermitian A)
E : Matrix n n 𝕜 := diagonal (IsROrC.ofReal ∘ Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A))
⊢ C * IsHermitian.eigenvectorMatrixInv (_ : IsHermitian A) = 1

Next tactic:
exact hA.1.eigenvectorMatrix_mul_inv
@[simp]
lemma sq_sqrt : hA.sqrt ^ 2 = A := by
  let C := hA.1.eigenvectorMatrix
  let E := diagonal ((↑) ∘ Real.sqrt ∘ hA.1.eigenvalues : n → 𝕜)
  suffices : C * (E * (Cᴴ * C) * E) * Cᴴ = A
  · rw [Matrix.PosSemidef.sqrt, pow_two]
    change (C * E * Cᴴ) * (C * E * Cᴴ) = A
    simpa only [← mul_assoc] using this
  have : Cᴴ * C = 1
  · rw [Matrix.IsHermitian.conjTranspose_eigenvectorMatrix, mul_eq_one_comm]
    exact hA.1.eigenvectorMatrix_mul_inv
  

Proof state:
case this
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
C : Matrix n n 𝕜 := IsHermitian.eigenvectorMatrix (_ : IsHermitian A)
E : Matrix n n 𝕜 := diagonal (IsROrC.ofReal ∘ Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A))
this : Cᴴ * C = 1
⊢ C * (E * (Cᴴ * C) * E) * Cᴴ = A

Next tactic:
rw [this, mul_one]
@[simp]
lemma sq_sqrt : hA.sqrt ^ 2 = A := by
  let C := hA.1.eigenvectorMatrix
  let E := diagonal ((↑) ∘ Real.sqrt ∘ hA.1.eigenvalues : n → 𝕜)
  suffices : C * (E * (Cᴴ * C) * E) * Cᴴ = A
  · rw [Matrix.PosSemidef.sqrt, pow_two]
    change (C * E * Cᴴ) * (C * E * Cᴴ) = A
    simpa only [← mul_assoc] using this
  have : Cᴴ * C = 1
  · rw [Matrix.IsHermitian.conjTranspose_eigenvectorMatrix, mul_eq_one_comm]
    exact hA.1.eigenvectorMatrix_mul_inv
  rw [this, mul_one]
  

Proof state:
case this
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
C : Matrix n n 𝕜 := IsHermitian.eigenvectorMatrix (_ : IsHermitian A)
E : Matrix n n 𝕜 := diagonal (IsROrC.ofReal ∘ Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A))
this : Cᴴ * C = 1
⊢ C * (E * E) * Cᴴ = A

Next tactic:
have : E * E = diagonal ((↑) ∘ hA.1.eigenvalues)
@[simp]
lemma sq_sqrt : hA.sqrt ^ 2 = A := by
  let C := hA.1.eigenvectorMatrix
  let E := diagonal ((↑) ∘ Real.sqrt ∘ hA.1.eigenvalues : n → 𝕜)
  suffices : C * (E * (Cᴴ * C) * E) * Cᴴ = A
  · rw [Matrix.PosSemidef.sqrt, pow_two]
    change (C * E * Cᴴ) * (C * E * Cᴴ) = A
    simpa only [← mul_assoc] using this
  have : Cᴴ * C = 1
  · rw [Matrix.IsHermitian.conjTranspose_eigenvectorMatrix, mul_eq_one_comm]
    exact hA.1.eigenvectorMatrix_mul_inv
  rw [this, mul_one]
  have : E * E = diagonal ((↑) ∘ hA.1.eigenvalues)
  · 

Proof state:
case this
m : Type u_1
n : Type u_2
R : Type u_3
𝕜 : Type u_4
inst✝⁶ : Fintype m
inst✝⁵ : Fintype n
inst✝⁴ : CommRing R
inst✝³ : PartialOrder R
inst✝² : StarOrderedRing R
inst✝¹ : IsROrC 𝕜
inst✝ : DecidableEq n
A : Matrix n n 𝕜
hA : PosSemidef A
C : Matrix n n 𝕜 := IsHermitian.eigenvectorMatrix (_ : IsHermitian A)
E : Matrix n n 𝕜 := diagonal (IsROrC.ofReal ∘ Real.sqrt ∘ IsHermitian.eigenvalues (_ : IsHermitian A))
this : Cᴴ * C = 1
⊢ E * E = diagonal (IsROrC.ofReal ∘ IsHermitian.eigenvalues (_ : IsHermitian A))

Next tactic:
rw [diagonal_mul_diagonal]