Skip to content

Commit 9c0adca

Browse files
committed
more cleanup
1 parent 9e8147a commit 9c0adca

1 file changed

Lines changed: 12 additions & 52 deletions

File tree

Mathlib/LinearAlgebra/Matrix/PosDef.lean

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -273,42 +273,34 @@ protected alias ⟨_, PosSemidef.nonneg⟩ := nonneg_iff
273273

274274
instance : PartialOrder (Matrix n n 𝕜) where
275275
le_antisymm A B h₁ h₂ := by
276-
have foo := neg_sub A B ▸ h₁.trace_nonneg
277-
rw [trace_neg, neg_nonneg] at foo
276+
have foo := neg_nonneg.mp <| trace_neg (A - B) ▸ neg_sub A B ▸ h₁.trace_nonneg
278277
have : (A - B).trace = 0 := le_antisymm foo h₂.trace_nonneg
279278
classical
280-
rw [← sub_eq_zero, ← h₂.isHermitian.eigenvalues_eq_zero_iff]
281-
ext i
282-
rw [h₂.isHermitian.trace_eq_sum_eigenvalues, ← RCLike.ofReal_sum] at this
283-
norm_cast at this
284-
rw [← (Finset.univ (α := n)).sum_const_zero, eq_comm,
285-
Finset.sum_eq_sum_iff_of_le (by simpa using h₂.eigenvalues_nonneg)] at this
286-
exact this i (by simp) |>.symm
279+
simp_rw [h₂.isHermitian.trace_eq_sum_eigenvalues, ← RCLike.ofReal_sum,
280+
RCLike.ofReal_eq_zero, Finset.sum_eq_zero_iff_of_nonneg (s := Finset.univ)
281+
(by simpa using h₂.eigenvalues_nonneg), Finset.mem_univ, true_imp_iff] at this
282+
exact sub_eq_zero.mp <| funext_iff.eq ▸ h₂.isHermitian.eigenvalues_eq_zero_iff.mp <| this
287283

288284
instance : IsOrderedAddMonoid (Matrix n n 𝕜) where
289285
add_le_add_left _ _ _ _ := by rwa [le_iff, add_sub_add_left_eq_sub]
290286

291287
instance : NonnegSpectrumClass ℝ (Matrix n n 𝕜) where
292288
quasispectrum_nonneg_of_nonneg A hA := by
293289
classical
294-
rw [nonneg_iff, posSemidef_iff_isHermitian_and_spectrum_nonneg] at hA
295290
simp only [quasispectrum_eq_spectrum_union_zero ℝ A, Set.union_singleton, Set.mem_insert_iff,
296291
forall_eq_or_imp, le_refl, true_and]
297292
intro x hx
298-
simpa using @hA.2 (x : 𝕜) hx
293+
simpa using posSemidef_iff_isHermitian_and_spectrum_nonneg.mp (nonneg_iff.mp hA) |>.2 hx
299294

300295
instance : StarOrderedRing (Matrix n n 𝕜) :=
301296
.of_nonneg_iff' add_le_add_left fun A ↦
302297
fun hA ↦ by
303-
have := QuasispectrumRestricts.nnreal_of_nonneg hA
304-
rw [nonneg_iff] at hA
305298
classical
306299
obtain ⟨X, hX, -, rfl⟩ :=
307-
CFC.exists_sqrt_of_isSelfAdjoint_of_quasispectrumRestricts hA.isHermitian this
308-
exact ⟨X, by rw [hX.star_eq]⟩,
309-
fun ⟨A, hA⟩ => by
310-
rw [nonneg_iff, hA, star_eq_conjTranspose]
311-
exact posSemidef_conjTranspose_mul_self A⟩
300+
sub_zero A ▸ CFC.exists_sqrt_of_isSelfAdjoint_of_quasispectrumRestricts hA.isHermitian
301+
(QuasispectrumRestricts.nnreal_of_nonneg hA.nonneg)
302+
exact ⟨X, hX.star_eq.symm ▸ rfl⟩,
303+
fun ⟨A, hA⟩ => hA ▸ (posSemidef_conjTranspose_mul_self A).nonneg⟩
312304

313305
end PartialOrder
314306

@@ -337,40 +329,8 @@ lemma sqrt_mul_self : CFC.sqrt A * CFC.sqrt A = A := CFC.sqrt_mul_sqrt_self A hA
337329

338330
include hA in
339331
lemma eq_of_sq_eq_sq {B : Matrix n n 𝕜} (hB : PosSemidef B) (hAB : A ^ 2 = B ^ 2) : A = B := by
340-
/- This is deceptively hard, much more difficult than the positive *definite* case. We follow a
341-
clever proof due to Koeber and Schäfer. The idea is that if `A ≠ B`, then `A - B` has a nonzero
342-
real eigenvalue, with eigenvector `v`. Then a manipulation using the identity
343-
`A ^ 2 - B ^ 2 = A * (A - B) + (A - B) * B` leads to the conclusion that
344-
`⟨v, A v⟩ + ⟨v, B v⟩ = 0`. Since `A, B` are positive semidefinite, both terms must be zero. Thus
345-
`⟨v, (A - B) v⟩ = 0`, but this is a nonzero scalar multiple of `⟨v, v⟩`, contradiction. -/
346-
by_contra h_ne
347-
let ⟨v, t, ht, hv, hv'⟩ := (hA.1.sub hB.1).exists_eigenvector_of_ne_zero (sub_ne_zero.mpr h_ne)
348-
have h_sum : 0 = t * (star v ⬝ᵥ A *ᵥ v + star v ⬝ᵥ B *ᵥ v) := calc
349-
0 = star v ⬝ᵥ (A ^ 2 - B ^ 2) *ᵥ v := by rw [hAB, sub_self, zero_mulVec, dotProduct_zero]
350-
_ = star v ⬝ᵥ A *ᵥ (A - B) *ᵥ v + star v ⬝ᵥ (A - B) *ᵥ B *ᵥ v := by
351-
rw [mulVec_mulVec, mulVec_mulVec, ← dotProduct_add, ← add_mulVec, mul_sub, sub_mul,
352-
add_sub, sub_add_cancel, pow_two, pow_two]
353-
_ = t * (star v ⬝ᵥ A *ᵥ v) + (star v) ᵥ* (A - B)ᴴ ⬝ᵥ B *ᵥ v := by
354-
rw [hv', mulVec_smul, dotProduct_smul, RCLike.real_smul_eq_coe_mul,
355-
dotProduct_mulVec _ (A - B), hA.1.sub hB.1]
356-
_ = t * (star v ⬝ᵥ A *ᵥ v + star v ⬝ᵥ B *ᵥ v) := by
357-
simp_rw [← star_mulVec, hv', mul_add, ← RCLike.real_smul_eq_coe_mul, ← smul_dotProduct]
358-
congr 2 with i
359-
simp only [Pi.star_apply, Pi.smul_apply, RCLike.real_smul_eq_coe_mul, star_mul',
360-
RCLike.star_def, RCLike.conj_ofReal]
361-
replace h_sum : star v ⬝ᵥ A *ᵥ v + star v ⬝ᵥ B *ᵥ v = 0 := by
362-
rw [eq_comm, ← mul_zero (t : 𝕜)] at h_sum
363-
exact mul_left_cancel₀ (RCLike.ofReal_ne_zero.mpr ht) h_sum
364-
have h_van : star v ⬝ᵥ A *ᵥ v = 0 ∧ star v ⬝ᵥ B *ᵥ v = 0 := by
365-
refine ⟨le_antisymm ?_ (hA.2 v), le_antisymm ?_ (hB.2 v)⟩
366-
· rw [add_comm, add_eq_zero_iff_eq_neg] at h_sum
367-
simpa only [h_sum, neg_nonneg] using hB.2 v
368-
· simpa only [add_eq_zero_iff_eq_neg.mp h_sum, neg_nonneg] using hA.2 v
369-
have aux : star v ⬝ᵥ (A - B) *ᵥ v = 0 := by
370-
rw [sub_mulVec, dotProduct_sub, h_van.1, h_van.2, sub_zero]
371-
rw [hv', dotProduct_smul, RCLike.real_smul_eq_coe_mul, ← mul_zero ↑t] at aux
372-
exact hv <| dotProduct_star_self_eq_zero.mp <| mul_left_cancel₀
373-
(RCLike.ofReal_ne_zero.mpr ht) aux
332+
rw [← CFC.sqrt_sq A hA.nonneg]
333+
exact (CFC.sqrt_unique (sq B ▸ hAB.symm) hB.nonneg)
374334

375335
include hA in
376336
lemma sq_eq_sq_iff {B : Matrix n n 𝕜} (hB : PosSemidef B) : A ^ 2 = B ^ 2 ↔ A = B :=

0 commit comments

Comments
 (0)