import LinkedTower.Links import Mathlib.LinearAlgebra.Matrix.Trace import Mathlib.LinearAlgebra.Matrix.Symmetric import Mathlib.LinearAlgebra.Matrix.Diagonal import Mathlib.LinearAlgebra.Matrix.Notation import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Tactic.FinCases import Mathlib.Tactic.Linarith import Mathlib.Tactic.Positivity import Mathlib.Tactic.Ring import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.NoncommRing /-! # 3D Matrix Algebra, Loewner Order, PSD Trace Inequalities, and Traceless Spectral Bounds This module supplies the core three-dimensional symmetric/PSD matrix algebra used throughout F02 (`manuscript.tex` Sections 1, 4.2, 5, 9; `CP1`--`CP18`; `U1`--`U10`): - Outer products `outer v = v vᵀ`, Frobenius/Hilbert--Schmidt inner product and norm, symmetric/skew parts, positive semidefiniteness `IsPSD`, and Loewner order `⪯ₗ`. - Complete 3×3 symmetric PSD Cholesky / sum-of-rank-one decomposition `isPSD_eq_sum_three_outers`: every 3×3 real symmetric PSD matrix is a sum of three outer products `outer v₁ + outer v₂ + outer v₃`. - Noncommuting PSD trace positivity `trace_mul_nonneg_of_isPSD` (`tr(A B) ≥ 0` for any symmetric PSD `A, B`, without assuming `A` and `B` commute). - Physical coercivity `coercivity_omega_fourth_le_trace_sq` (`|ω|⁴ ≤ tr(A²)` for `A = ωωᵀ + P`, `P ⪰ 0`, without commutativity; `eq:rev-energy`). - Noncommuting PSD quadratic comparison `trace_sq_le_of_sub_isPSD` (`tr(U²) - tr(A²) = tr(L(U + A)) ≥ 0`; `prop:rev-abc`, `CP14`). - Sharp traceless symmetric bound `traceless_sym_quadratic_bound`: `⟨e, L e⟩ ≤ √(2/3) ‖L‖_HS ‖e‖²` for every symmetric traceless `L` and every `e ∈ ℝ³`, with explicit attainment witness `tracelessExtremizer_props` (`prop:signed-shell`, Section 4.2). - Inverse Loewner lower bound `inv_loewner_lower_bound` (`0 ⪯ M ⪯ c I`, `M J = J M = I`, `c > 0 ⇒ c⁻¹ I ⪯ J`; `prop:rev-abc`, `CP12`) via PSD Cauchy--Schwarz in arbitrary dimension. - Orthogonal overlap conjugation invariance connecting directly to `LinkedTower.Links`. -/ namespace F02NavierStokes.LinearAlgebra3D open scoped Matrix BigOperators open Matrix noncomputable section abbrev Vec3 := Fin 3 → ℝ abbrev Mat3 := Matrix (Fin 3) (Fin 3) ℝ /-- Squared Euclidean norm of a 3-vector. -/ def vecSqNorm (v : Vec3) : ℝ := ∑ i : Fin 3, (v i) ^ 2 /-- Euclidean inner product of two 3-vectors. -/ def vecDot (u v : Vec3) : ℝ := ∑ i : Fin 3, u i * v i /-- Rank-at-most-one outer product `v vᵀ`. -/ def outer (v : Vec3) : Mat3 := Matrix.of fun i j => v i * v j /-- Hilbert--Schmidt (Frobenius) inner product `tr(Aᵀ B)`. -/ def hsInner (A B : Mat3) : ℝ := (Aᵀ * B).trace /-- Squared Hilbert--Schmidt (Frobenius) norm `tr(Aᵀ A) = ∑ᵢⱼ Aᵢⱼ²`. -/ def hsNormSq (A : Mat3) : ℝ := hsInner A A /-- Symmetric part `(A + Aᵀ) / 2`. -/ def symPart (A : Mat3) : Mat3 := (1 / 2 : ℝ) • (A + Aᵀ) /-- Skew-symmetric part `(A - Aᵀ) / 2`. -/ def skewPart (A : Mat3) : Mat3 := (1 / 2 : ℝ) • (A - Aᵀ) /-- Real symmetric positive semidefiniteness in arbitrary finite dimension `n`. -/ def IsPSD {n : Type*} [Fintype n] (A : Matrix n n ℝ) : Prop := Aᵀ = A ∧ ∀ x : n → ℝ, 0 ≤ x ⬝ᵥ (A *ᵥ x) /-- Loewner partial order `A ⪯ₗ B` defined by `IsPSD (B - A)`. -/ def LoewnerLE {n : Type*} [Fintype n] (A B : Matrix n n ℝ) : Prop := IsPSD (B - A) scoped infix:50 " ⪯ₗ " => LoewnerLE theorem vecSqNorm_nonneg (v : Vec3) : 0 ≤ vecSqNorm v := Finset.sum_nonneg fun i _ => sq_nonneg (v i) theorem vecDot_self (v : Vec3) : vecDot v v = vecSqNorm v := by simp [vecDot, vecSqNorm, pow_two] theorem vecDot_comm (u v : Vec3) : vecDot u v = vecDot v u := by simp [vecDot, mul_comm] theorem vecDot_eq_dotProduct (u v : Vec3) : vecDot u v = u ⬝ᵥ v := rfl theorem vecSqNorm_eq_dotProduct (v : Vec3) : vecSqNorm v = v ⬝ᵥ v := by simp [vecSqNorm, dotProduct, pow_two] theorem symPart_add_skewPart (A : Mat3) : symPart A + skewPart A = A := by ext i j simp [symPart, skewPart] ring theorem symPart_transpose (A : Mat3) : (symPart A)ᵀ = symPart A := by ext i j simp [symPart, add_comm] ring theorem skewPart_transpose (A : Mat3) : (skewPart A)ᵀ = -skewPart A := by ext i j simp [skewPart] ring theorem isPSD_zero {n : Type*} [Fintype n] : IsPSD (0 : Matrix n n ℝ) := by refine ⟨by simp, fun x => by simp⟩ theorem isPSD_one {n : Type*} [Fintype n] [DecidableEq n] : IsPSD (1 : Matrix n n ℝ) := by refine ⟨Matrix.transpose_one, fun x => ?_⟩ simp only [Matrix.one_mulVec, dotProduct] exact Finset.sum_nonneg fun i _ => mul_self_nonneg (x i) theorem isPSD_add {n : Type*} [Fintype n] {A B : Matrix n n ℝ} (hA : IsPSD A) (hB : IsPSD B) : IsPSD (A + B) := by refine ⟨by rw [Matrix.transpose_add, hA.1, hB.1], fun x => ?_⟩ rw [Matrix.add_mulVec, dotProduct_add] exact add_nonneg (hA.2 x) (hB.2 x) theorem isPSD_smul {n : Type*} [Fintype n] {A : Matrix n n ℝ} {c : ℝ} (hc : 0 ≤ c) (hA : IsPSD A) : IsPSD (c • A) := by refine ⟨by rw [Matrix.transpose_smul, hA.1], fun x => ?_⟩ rw [Matrix.smul_mulVec, dotProduct_smul, smul_eq_mul] exact mul_nonneg hc (hA.2 x) theorem isPSD_congruence {n : Type*} [Fintype n] {A : Matrix n n ℝ} (hA : IsPSD A) (P : Matrix n n ℝ) : IsPSD (P * A * Pᵀ) := by refine ⟨?_, fun x => ?_⟩ · rw [Matrix.transpose_mul, Matrix.transpose_mul, Matrix.transpose_transpose, hA.1, Matrix.mul_assoc] · have hquad : x ⬝ᵥ ((P * A * Pᵀ) *ᵥ x) = (Pᵀ *ᵥ x) ⬝ᵥ (A *ᵥ (Pᵀ *ᵥ x)) := by calc x ⬝ᵥ ((P * A * Pᵀ) *ᵥ x) = x ⬝ᵥ (P *ᵥ (A *ᵥ (Pᵀ *ᵥ x))) := by simp only [Matrix.mulVec_mulVec, Matrix.mul_assoc] _ = (Pᵀ *ᵥ x) ⬝ᵥ (A *ᵥ (Pᵀ *ᵥ x)) := by rw [Matrix.dotProduct_mulVec, ← Matrix.mulVec_transpose] rw [hquad] exact hA.2 (Pᵀ *ᵥ x) theorem loewnerLE_refl {n : Type*} [Fintype n] (A : Matrix n n ℝ) : A ⪯ₗ A := by simpa [LoewnerLE] using isPSD_zero theorem loewnerLE_trans {n : Type*} [Fintype n] {A B C : Matrix n n ℝ} (h1 : A ⪯ₗ B) (h2 : B ⪯ₗ C) : A ⪯ₗ C := by have heq : C - A = (C - B) + (B - A) := by abel rw [LoewnerLE, heq] exact isPSD_add h2 h1 theorem outer_transpose (v : Vec3) : (outer v)ᵀ = outer v := by ext i j simp [outer, mul_comm] theorem outer_dotProduct (v x : Vec3) : x ⬝ᵥ (outer v *ᵥ x) = (vecDot v x) ^ 2 := by simp only [outer, dotProduct, mulVec, vecDot, Matrix.of_apply] have h : ∀ i : Fin 3, x i * ∑ j : Fin 3, v i * v j * x j = (v i * x i) * ∑ j : Fin 3, v j * x j := by intro i rw [Finset.mul_sum, Finset.mul_sum] apply Finset.sum_congr rfl intro j _ ring simp_rw [h, ← Finset.sum_mul, pow_two] theorem outer_isPSD (v : Vec3) : IsPSD (outer v) := ⟨outer_transpose v, fun x => by rw [outer_dotProduct]; exact sq_nonneg _⟩ theorem outer_trace (v : Vec3) : (outer v).trace = vecSqNorm v := by simp [outer, Matrix.trace, Matrix.diag, vecSqNorm, pow_two] theorem outer_mul_outer (u v : Vec3) : outer u * outer v = (vecDot u v) • Matrix.of (fun i j => u i * v j) := by ext i j simp only [outer, Matrix.mul_apply, Matrix.smul_apply, Matrix.of_apply, smul_eq_mul, vecDot] rw [Finset.sum_mul] apply Finset.sum_congr rfl intro k _ ring theorem outer_sq (v : Vec3) : outer v * outer v = vecSqNorm v • outer v := by rw [outer_mul_outer, vecDot_self] rfl theorem trace_outer_sq (v : Vec3) : (outer v * outer v).trace = (vecSqNorm v) ^ 2 := by rw [outer_sq, Matrix.trace_smul, outer_trace, smul_eq_mul, pow_two] theorem trace_outer_mul (v : Vec3) (B : Mat3) : (outer v * B).trace = v ⬝ᵥ (B *ᵥ v) := by simp only [outer, Matrix.trace, Matrix.diag, Matrix.mul_apply, Matrix.of_apply, dotProduct, mulVec] trans (∑ i : Fin 3, ∑ j : Fin 3, v i * (B i j * v j)) · rw [Finset.sum_comm] apply Finset.sum_congr rfl intro i _ apply Finset.sum_congr rfl intro j _ ring · apply Finset.sum_congr rfl intro i _ rw [Finset.mul_sum] theorem hsNormSq_eq_sum (A : Mat3) : hsNormSq A = ∑ i : Fin 3, ∑ j : Fin 3, (A i j) ^ 2 := by simp only [hsNormSq, hsInner, Matrix.trace, Matrix.diag, Matrix.mul_apply, Matrix.transpose_apply, pow_two] rw [Finset.sum_comm] theorem hsNormSq_nonneg (A : Mat3) : 0 ≤ hsNormSq A := by rw [hsNormSq_eq_sum] exact Finset.sum_nonneg fun i _ => Finset.sum_nonneg fun j _ => sq_nonneg _ theorem hsInner_eq_sum (A B : Mat3) : hsInner A B = ∑ i : Fin 3, ∑ j : Fin 3, A i j * B i j := by simp only [hsInner, Matrix.trace, Matrix.diag, Matrix.mul_apply, Matrix.transpose_apply] rw [Finset.sum_comm] theorem hsInner_symm (A B : Mat3) : hsInner A B = hsInner B A := by simp [hsInner_eq_sum, mul_comm] /-- Cauchy--Schwarz inequality for the 3×3 Frobenius inner product. -/ theorem hsInner_sq_le (A B : Mat3) : (hsInner A B) ^ 2 ≤ hsNormSq A * hsNormSq B := by have h : ∀ t : ℝ, 0 ≤ hsNormSq (A + t • B) := fun t => hsNormSq_nonneg _ have hexp : ∀ t : ℝ, hsNormSq (A + t • B) = hsNormSq A + 2 * t * hsInner A B + t ^ 2 * hsNormSq B := by intro t simp only [hsNormSq_eq_sum, hsInner_eq_sum, Matrix.add_apply, Matrix.smul_apply, smul_eq_mul] have h1 : ∀ i j : Fin 3, (A i j + t * B i j) ^ 2 = (A i j) ^ 2 + 2 * t * (A i j * B i j) + t ^ 2 * (B i j) ^ 2 := fun i j => by ring simp_rw [h1, Finset.sum_add_distrib, ← Finset.mul_sum] by_cases hB : hsNormSq B = 0 · have hzero : hsInner A B = 0 := by by_contra hne have hspec := h (-(hsNormSq A + 1) / (2 * hsInner A B)) rw [hexp, hB, mul_zero, add_zero] at hspec have hsimp : 2 * (-(hsNormSq A + 1) / (2 * hsInner A B)) * hsInner A B = -(hsNormSq A + 1) := by field_simp linarith rw [hzero, hB] norm_num · have hBpos : 0 < hsNormSq B := lt_of_le_of_ne (hsNormSq_nonneg B) (Ne.symm hB) have hspec := h (-hsInner A B / hsNormSq B) rw [hexp] at hspec have hmul : hsNormSq B * (hsNormSq A + 2 * (-hsInner A B / hsNormSq B) * hsInner A B + (-hsInner A B / hsNormSq B) ^ 2 * hsNormSq B) = hsNormSq A * hsNormSq B - (hsInner A B) ^ 2 := by field_simp ring nlinarith /-- PSD Cauchy--Schwarz inequality in any finite dimension `n`: for any symmetric PSD `M`, `(uᵀ M w)² ≤ (uᵀ M u)(wᵀ M w)`. -/ theorem isPSD_cauchy_schwarz {n : Type*} [Fintype n] {M : Matrix n n ℝ} (hM : IsPSD M) (u w : n → ℝ) : (u ⬝ᵥ (M *ᵥ w)) ^ 2 ≤ (u ⬝ᵥ (M *ᵥ u)) * (w ⬝ᵥ (M *ᵥ w)) := by have hsym : ∀ a b : n → ℝ, a ⬝ᵥ (M *ᵥ b) = b ⬝ᵥ (M *ᵥ a) := by intro a b calc a ⬝ᵥ (M *ᵥ b) = (a ᵥ* M) ⬝ᵥ b := Matrix.dotProduct_mulVec a M b _ = (Mᵀ *ᵥ a) ⬝ᵥ b := by rw [← Matrix.mulVec_transpose] _ = (M *ᵥ a) ⬝ᵥ b := by rw [hM.1] _ = b ⬝ᵥ (M *ᵥ a) := dotProduct_comm _ _ have hexp : ∀ t : ℝ, (u + t • w) ⬝ᵥ (M *ᵥ (u + t • w)) = u ⬝ᵥ (M *ᵥ u) + 2 * t * (u ⬝ᵥ (M *ᵥ w)) + t ^ 2 * (w ⬝ᵥ (M *ᵥ w)) := by intro t simp only [Matrix.mulVec_add, Matrix.mulVec_smul, dotProduct_add, add_dotProduct, dotProduct_smul, smul_dotProduct, smul_eq_mul, hsym w u] ring have hnn : ∀ t : ℝ, 0 ≤ u ⬝ᵥ (M *ᵥ u) + 2 * t * (u ⬝ᵥ (M *ᵥ w)) + t ^ 2 * (w ⬝ᵥ (M *ᵥ w)) := by intro t rw [← hexp t] exact hM.2 (u + t • w) set a := u ⬝ᵥ (M *ᵥ u) set b := u ⬝ᵥ (M *ᵥ w) set c := w ⬝ᵥ (M *ᵥ w) have hc_nn : 0 ≤ c := hM.2 w by_cases hc0 : c = 0 · have hb0 : b = 0 := by by_contra hne have hspec := hnn (-(a + 1) / (2 * b)) rw [hc0, mul_zero, add_zero] at hspec have hsimp : 2 * (-(a + 1) / (2 * b)) * b = -(a + 1) := by field_simp linarith rw [hb0, hc0]; norm_num · have hc_pos : 0 < c := lt_of_le_of_ne hc_nn (Ne.symm hc0) have hspec := hnn (-b / c) have hmul : c * (a + 2 * (-b / c) * b + (-b / c) ^ 2 * c) = a * c - b ^ 2 := by field_simp ring nlinarith /-! ## Complete 3×3 Cholesky / rank-one sum decomposition for symmetric PSD matrices -/ private lemma psd_diag_nonneg {A : Mat3} (hA : IsPSD A) (i : Fin 3) : 0 ≤ A i i := by have h := hA.2 (Pi.single i (1 : ℝ)) simpa [dotProduct, mulVec, Pi.single_apply] using h private lemma psd_offdiag_zero_of_diag_zero {A : Mat3} (hA : IsPSD A) {i j : Fin 3} (hii : A i i = 0) : A i j = 0 := by have hcs := isPSD_cauchy_schwarz hA (Pi.single i (1 : ℝ)) (Pi.single j (1 : ℝ)) have h1 : (Pi.single i (1 : ℝ)) ⬝ᵥ (A *ᵥ Pi.single i (1 : ℝ)) = A i i := by simp [dotProduct, mulVec, Pi.single_apply] have h2 : (Pi.single i (1 : ℝ)) ⬝ᵥ (A *ᵥ Pi.single j (1 : ℝ)) = A i j := by simp [dotProduct, mulVec, Pi.single_apply] rw [h1, h2, hii, zero_mul] at hcs exact sq_eq_zero_iff.mp (le_antisymm hcs (sq_nonneg _)) private lemma sym_entry {A : Mat3} (hSym : Aᵀ = A) (i j : Fin 3) : A j i = A i j := by have h := congrArg (fun M : Mat3 => M i j) hSym simpa [Matrix.transpose_apply] using h /-- Every 3×3 real symmetric PSD matrix is a sum of three rank-one outer products `outer v₁ + outer v₂ + outer v₃` (Lagrange/Cholesky decomposition, zero spectral-theorem dependency). -/ theorem isPSD_eq_sum_three_outers {A : Mat3} (hA : IsPSD A) : ∃ v₁ v₂ v₃ : Vec3, A = outer v₁ + outer v₂ + outer v₃ := by -- Step 1: Peel off pivot 0 have hstep0 : ∃ v₁ : Vec3, ∃ B : Mat3, A = outer v₁ + B ∧ IsPSD B ∧ ∀ j : Fin 3, B 0 j = 0 ∧ B j 0 = 0 := by have ha00 : 0 ≤ A 0 0 := psd_diag_nonneg hA 0 by_cases h0 : A 0 0 = 0 · refine ⟨0, A, by ext i j; simp [outer], hA, fun j => ?_⟩ have h0j : A 0 j = 0 := psd_offdiag_zero_of_diag_zero hA h0 exact ⟨h0j, by rw [sym_entry hA.1 0 j]; exact h0j⟩ · have ha00_pos : 0 < A 0 0 := lt_of_le_of_ne ha00 (Ne.symm h0) let s0 := Real.sqrt (A 0 0) have hs0_pos : 0 < s0 := Real.sqrt_pos.mpr ha00_pos have hs0_sq : s0 ^ 2 = A 0 0 := Real.sq_sqrt ha00 let v₁ : Vec3 := fun i => A 0 i / s0 let B : Mat3 := A - outer v₁ have hAB : A = outer v₁ + B := by ext i j; simp [B] have hBsym : Bᵀ = B := by rw [Matrix.transpose_sub, hA.1, outer_transpose] have hB0 : ∀ j : Fin 3, B 0 j = 0 ∧ B j 0 = 0 := by intro j have h0j : B 0 j = 0 := by simp only [B, outer, v₁, Matrix.sub_apply, Matrix.of_apply] have : A 0 0 / s0 * (A 0 j / s0) = A 0 0 * A 0 j / s0 ^ 2 := by ring rw [this, hs0_sq] field_simp [ne_of_gt ha00_pos] ring exact ⟨h0j, by rw [sym_entry hBsym 0 j]; exact h0j⟩ have hBpsd : IsPSD B := by refine ⟨hBsym, fun x => ?_⟩ -- Choose y = ![-(A 0 1 * x 1 + A 0 2 * x 2) / A 0 0, x 1, x 2], so yᵀ A y = xᵀ B x let y : Vec3 := ![-(A 0 1 * x 1 + A 0 2 * x 2) / A 0 0, x 1, x 2] have hyA : 0 ≤ y ⬝ᵥ (A *ᵥ y) := hA.2 y have hEq : x ⬝ᵥ (B *ᵥ x) = y ⬝ᵥ (A *ᵥ y) := by have hs10 : A 1 0 = A 0 1 := sym_entry hA.1 0 1 have hs20 : A 2 0 = A 0 2 := sym_entry hA.1 0 2 have hs21 : A 2 1 = A 1 2 := sym_entry hA.1 1 2 simp only [B, outer, v₁, y, dotProduct, mulVec, Fin.sum_univ_three, Matrix.sub_apply, Matrix.of_apply, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, Matrix.tail_cons] rw [hs10, hs20, hs21] have ha0 : A 0 0 ≠ 0 := ne_of_gt ha00_pos have hs0_ne : s0 ≠ 0 := ne_of_gt hs0_pos field_simp [ha0, hs0_ne] rw [hs0_sq] ring linarith exact ⟨v₁, B, hAB, hBpsd, hB0⟩ rcases hstep0 with ⟨v₁, B, hAB, hBpsd, hB0⟩ -- Step 2: Peel off pivot 1 from B (whose row/col 0 are zero) have hstep1 : ∃ v₂ : Vec3, ∃ C : Mat3, B = outer v₂ + C ∧ IsPSD C ∧ (∀ j : Fin 3, C 0 j = 0 ∧ C j 0 = 0) ∧ (∀ j : Fin 3, C 1 j = 0 ∧ C j 1 = 0) := by have hb11 : 0 ≤ B 1 1 := psd_diag_nonneg hBpsd 1 by_cases h1 : B 1 1 = 0 · refine ⟨0, B, by ext i j; simp [outer], hBpsd, hB0, fun j => ?_⟩ have h1j : B 1 j = 0 := psd_offdiag_zero_of_diag_zero hBpsd h1 exact ⟨h1j, by rw [sym_entry hBpsd.1 1 j]; exact h1j⟩ · have hb11_pos : 0 < B 1 1 := lt_of_le_of_ne hb11 (Ne.symm h1) let s1 := Real.sqrt (B 1 1) have hs1_pos : 0 < s1 := Real.sqrt_pos.mpr hb11_pos have hs1_sq : s1 ^ 2 = B 1 1 := Real.sq_sqrt hb11 let v₂ : Vec3 := fun i => B 1 i / s1 have hv20 : v₂ 0 = 0 := by simp [v₂, (hB0 1).2] let C : Mat3 := B - outer v₂ have hBC : B = outer v₂ + C := by ext i j; simp [C] have hCsym : Cᵀ = C := by rw [Matrix.transpose_sub, hBpsd.1, outer_transpose] have hC0 : ∀ j : Fin 3, C 0 j = 0 ∧ C j 0 = 0 := by intro j have h0j : C 0 j = 0 := by simp [C, outer, hv20, (hB0 j).1] exact ⟨h0j, by rw [sym_entry hCsym 0 j]; exact h0j⟩ have hC1 : ∀ j : Fin 3, C 1 j = 0 ∧ C j 1 = 0 := by intro j have h1j : C 1 j = 0 := by simp only [C, outer, v₂, Matrix.sub_apply, Matrix.of_apply] have : B 1 1 / s1 * (B 1 j / s1) = B 1 1 * B 1 j / s1 ^ 2 := by ring rw [this, hs1_sq] field_simp [ne_of_gt hb11_pos] ring exact ⟨h1j, by rw [sym_entry hCsym 1 j]; exact h1j⟩ have hCpsd : IsPSD C := by refine ⟨hCsym, fun x => ?_⟩ let y : Vec3 := ![0, -(B 1 2 * x 2) / B 1 1, x 2] have hyB : 0 ≤ y ⬝ᵥ (B *ᵥ y) := hBpsd.2 y have hEq : x ⬝ᵥ (C *ᵥ x) = y ⬝ᵥ (B *ᵥ y) := by have hb21 : B 2 1 = B 1 2 := sym_entry hBpsd.1 1 2 simp only [C, outer, v₂, y, dotProduct, mulVec, Fin.sum_univ_three, Matrix.sub_apply, Matrix.of_apply, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, Matrix.tail_cons, (hB0 0).1, (hB0 1).1, (hB0 2).1, (hB0 1).2, (hB0 2).2, hb21] have hb1 : B 1 1 ≠ 0 := ne_of_gt hb11_pos have hs1_ne : s1 ≠ 0 := ne_of_gt hs1_pos field_simp [hb1, hs1_ne] rw [hs1_sq] ring linarith exact ⟨v₂, C, hBC, hCpsd, hC0, hC1⟩ rcases hstep1 with ⟨v₂, C, hBC, hCpsd, hC0, hC1⟩ -- Step 3: C is supported only at (2, 2) with C 2 2 ≥ 0 have hc22 : 0 ≤ C 2 2 := psd_diag_nonneg hCpsd 2 let v₃ : Vec3 := ![0, 0, Real.sqrt (C 2 2)] have hCv3 : C = outer v₃ := by ext i j fin_cases i <;> fin_cases j <;> simp [outer, v₃, (hC0 0).1, (hC0 1).1, (hC0 2).1, (hC0 1).2, (hC0 2).2, (hC1 1).1, (hC1 2).1, (hC1 2).2, Real.mul_self_sqrt hc22] refine ⟨v₁, v₂, v₃, ?_⟩ rw [hAB, hBC, hCv3, add_assoc] /-- Noncommuting PSD trace positivity (`prop:rev-abc`, `eq:rev-energy`, `CP14`): for ANY two 3×3 real symmetric PSD matrices `A` and `B`, `0 ≤ tr(A B)`, without assuming `A` and `B` commute. -/ theorem trace_mul_nonneg_of_isPSD {A B : Mat3} (hA : IsPSD A) (hB : IsPSD B) : 0 ≤ (A * B).trace := by obtain ⟨v₁, v₂, v₃, rfl⟩ := isPSD_eq_sum_three_outers hA simp only [Matrix.add_mul, Matrix.trace_add, trace_outer_mul] exact add_nonneg (add_nonneg (hB.2 v₁) (hB.2 v₂)) (hB.2 v₃) /-- Physical coercivity (`eq:rev-energy`, line 1551): if `A = ωωᵀ + P` with `P ⪰ 0`, then `|ω|⁴ ≤ tr(A²)`, without commutativity. -/ theorem coercivity_omega_fourth_le_trace_sq (ω : Vec3) (P : Mat3) (hP : IsPSD P) : (vecSqNorm ω) ^ 2 ≤ ((outer ω + P) * (outer ω + P)).trace := by have hΩ : IsPSD (outer ω) := outer_isPSD ω have hexp : (outer ω + P) * (outer ω + P) = outer ω * outer ω + outer ω * P + P * outer ω + P * P := by noncomm_ring rw [hexp, Matrix.trace_add, Matrix.trace_add, Matrix.trace_add, trace_outer_sq] have h1 : 0 ≤ (outer ω * P).trace := trace_mul_nonneg_of_isPSD hΩ hP have h2 : 0 ≤ (P * outer ω).trace := trace_mul_nonneg_of_isPSD hP hΩ have h3 : 0 ≤ (P * P).trace := trace_mul_nonneg_of_isPSD hP hP linarith /-- Noncommuting quadratic identity and comparison (`prop:rev-abc`, `CP14`): `tr((A + L)²) - tr(A²) = tr(L(A + L + A))` identically, and for `A, L ⪰ 0`, `tr(A²) ≤ tr((A + L)²)`. -/ theorem trace_sq_sub_eq {n : Type*} [Fintype n] [DecidableEq n] (A L : Matrix n n ℝ) : ((A + L) * (A + L)).trace - (A * A).trace = (L * ((A + L) + A)).trace := by have h1 : (A + L) * (A + L) = A * A + A * L + L * A + L * L := by noncomm_ring have h2 : L * ((A + L) + A) = L * A + L * L + L * A := by noncomm_ring rw [h1, h2] simp only [Matrix.trace_add] have hcyc : (A * L).trace = (L * A).trace := Matrix.trace_mul_comm A L linarith theorem trace_sq_le_of_sub_isPSD {A L : Mat3} (hA : IsPSD A) (hL : IsPSD L) : (A * A).trace ≤ ((A + L) * (A + L)).trace := by have hdiff := trace_sq_sub_eq A L have hsum : IsPSD ((A + L) + A) := isPSD_add (isPSD_add hA hL) hA have hnn : 0 ≤ (L * ((A + L) + A)).trace := trace_mul_nonneg_of_isPSD hL hsum linarith /-- Eigenvalue form of the sharp 3D traceless bound: `λ₁ + λ₂ + λ₃ = 0 ⇒ λ₁² ≤ (2/3)(λ₁² + λ₂² + λ₃²)`. -/ theorem traceless_eigenvalue_sq_le (a b c : ℝ) (htr : a + b + c = 0) : a ^ 2 ≤ (2 / 3 : ℝ) * (a ^ 2 + b ^ 2 + c ^ 2) := by have ha : a = -(b + c) := by linarith rw [ha] nlinarith [sq_nonneg (b - c)] /-- Sharp traceless symmetric quadratic-form bound (`prop:signed-shell`, Section 4.2): for every symmetric traceless `L ∈ M₃(ℝ)` and every `e ∈ ℝ³`, `⟨e, L e⟩² ≤ (2/3) ‖L‖_HS² ‖e‖⁴`. -/ theorem traceless_sym_quadratic_sq_le (L : Mat3) (hSym : Lᵀ = L) (hTr : L.trace = 0) (e : Vec3) : (e ⬝ᵥ (L *ᵥ e)) ^ 2 ≤ (2 / 3 : ℝ) * hsNormSq L * (vecSqNorm e) ^ 2 := by let B : Mat3 := outer e - ((vecSqNorm e / 3) : ℝ) • (1 : Mat3) have hquad : e ⬝ᵥ (L *ᵥ e) = hsInner L B := by have h1 : hsInner L (outer e) = e ⬝ᵥ (L *ᵥ e) := by rw [hsInner, hSym, Matrix.trace_mul_comm, trace_outer_mul] have h2 : hsInner L (1 : Mat3) = 0 := by simp [hsInner, hSym, hTr] have hsub : hsInner L B = hsInner L (outer e) - (vecSqNorm e / 3) * hsInner L (1 : Mat3) := by simp only [hsInner, B, Matrix.mul_sub, Matrix.mul_smul, Matrix.trace_sub, Matrix.trace_smul, smul_eq_mul] rw [hsub, h1, h2, mul_zero, sub_zero] have hBnorm : hsNormSq B = (2 / 3 : ℝ) * (vecSqNorm e) ^ 2 := by have hBsym : Bᵀ = B := by simp [B, outer_transpose] have hBsq : hsNormSq B = (B * B).trace := by simp [hsNormSq, hsInner, hBsym] rw [hBsq] have hmul : B * B = outer e * outer e - (2 * (vecSqNorm e / 3)) • outer e + ((vecSqNorm e / 3) ^ 2) • (1 : Mat3) := by dsimp [B] ext i j simp [Matrix.sub_mul, Matrix.mul_sub] ring rw [hmul, Matrix.trace_add, Matrix.trace_sub, Matrix.trace_smul, Matrix.trace_smul, trace_outer_sq, outer_trace, Matrix.trace_one, Fintype.card_fin] simp only [smul_eq_mul, Nat.cast_ofNat] ring rw [hquad] have hcs := hsInner_sq_le L B rw [hBnorm] at hcs linarith /-- Linear form of the sharp traceless symmetric bound: `⟨e, L e⟩ ≤ √(2/3) √(‖L‖_HS²) ‖e‖²`. -/ theorem traceless_sym_quadratic_bound (L : Mat3) (hSym : Lᵀ = L) (hTr : L.trace = 0) (e : Vec3) : e ⬝ᵥ (L *ᵥ e) ≤ Real.sqrt (2 / 3 : ℝ) * Real.sqrt (hsNormSq L) * vecSqNorm e := by have hsq := traceless_sym_quadratic_sq_le L hSym hTr e have hrhs_nn : 0 ≤ Real.sqrt (2 / 3 : ℝ) * Real.sqrt (hsNormSq L) * vecSqNorm e := by have := vecSqNorm_nonneg e positivity have hrhs_sq : (Real.sqrt (2 / 3 : ℝ) * Real.sqrt (hsNormSq L) * vecSqNorm e) ^ 2 = (2 / 3 : ℝ) * hsNormSq L * (vecSqNorm e) ^ 2 := by have h1 : Real.sqrt (2 / 3 : ℝ) ^ 2 = 2 / 3 := Real.sq_sqrt (by norm_num) have h2 : Real.sqrt (hsNormSq L) ^ 2 = hsNormSq L := Real.sq_sqrt (hsNormSq_nonneg L) rw [mul_pow, mul_pow, h1, h2] nlinarith /-- Explicit attainment of `√(2/3)` by `diag(cρ, -cρ/2, -cρ/2)` with `c = √(2/3)`. -/ def tracelessExtremizer (ρ : ℝ) : Mat3 := let c := Real.sqrt (2 / 3 : ℝ) Matrix.diagonal ![c * ρ, -(c * ρ) / 2, -(c * ρ) / 2] theorem tracelessExtremizer_props (ρ : ℝ) : (tracelessExtremizer ρ)ᵀ = tracelessExtremizer ρ ∧ (tracelessExtremizer ρ).trace = 0 ∧ hsNormSq (tracelessExtremizer ρ) = ρ ^ 2 ∧ (![(1 : ℝ), 0, 0] ⬝ᵥ (tracelessExtremizer ρ *ᵥ ![1, 0, 0])) = Real.sqrt (2 / 3 : ℝ) * ρ := by have h2 : Real.sqrt 2 ^ 2 = 2 := Real.sq_sqrt (by norm_num) have h3 : Real.sqrt 3 ^ 2 = 3 := Real.sq_sqrt (by norm_num) refine ⟨?_, ?_, ?_, ?_⟩ · simp [tracelessExtremizer] · simp [tracelessExtremizer, Matrix.trace_diagonal, Fin.sum_univ_three] ring · simp only [tracelessExtremizer, hsNormSq_eq_sum, Fin.sum_univ_three, Matrix.diagonal_apply] norm_num simp only [neg_sq, mul_pow, div_pow, h2, h3] ring · simp [tracelessExtremizer, dotProduct, mulVec, Fin.sum_univ_three] /-- Scalar Loewner bound on an invertible PSD matrix yields the reciprocal Loewner lower bound on its inverse (`prop:rev-abc`, `CP12`), in arbitrary finite dimension `n`: if `0 ⪯ M ⪯ c I` (`c > 0`) and `M J = I`, then `c⁻¹ I ⪯ J`. -/ theorem inv_loewner_lower_bound {n : Type*} [Fintype n] [DecidableEq n] {M J : Matrix n n ℝ} {c : ℝ} (hc : 0 < c) (hMpsd : IsPSD M) (hMle : M ⪯ₗ c • (1 : Matrix n n ℝ)) (hMJ : M * J = 1) : (c⁻¹ • (1 : Matrix n n ℝ)) ⪯ₗ J := by have hJsym : Jᵀ = J := by have h1 : Jᵀ * M = 1 := by calc Jᵀ * M = Jᵀ * Mᵀ := by rw [hMpsd.1] _ = (M * J)ᵀ := (Matrix.transpose_mul M J).symm _ = 1 := by rw [hMJ, Matrix.transpose_one] calc Jᵀ = Jᵀ * (M * J) := by rw [hMJ, Matrix.mul_one] _ = (Jᵀ * M) * J := by rw [Matrix.mul_assoc] _ = J := by rw [h1, Matrix.one_mul] refine ⟨by rw [Matrix.transpose_sub, hJsym, Matrix.transpose_smul, Matrix.transpose_one], fun x => ?_⟩ let y : n → ℝ := J *ᵥ x have hxy : M *ᵥ y = x := by simp only [y, Matrix.mulVec_mulVec, hMJ, Matrix.one_mulVec] have hcs := isPSD_cauchy_schwarz hMpsd x y have hMupper : x ⬝ᵥ (M *ᵥ x) ≤ c * (x ⬝ᵥ x) := by have hq := hMle.2 x simp only [Matrix.sub_mulVec, Matrix.smul_mulVec, Matrix.one_mulVec, dotProduct_sub, dotProduct_smul, smul_eq_mul] at hq linarith have hyMy : y ⬝ᵥ (M *ᵥ y) = x ⬝ᵥ (J *ᵥ x) := by rw [hxy, dotProduct_comm] rw [hyMy, hxy] at hcs have hxx_nn : 0 ≤ x ⬝ᵥ x := Finset.sum_nonneg fun i _ => mul_self_nonneg (x i) have hxJx_nn : 0 ≤ x ⬝ᵥ (J *ᵥ x) := by rw [← hyMy] exact hMpsd.2 y have hquad : x ⬝ᵥ ((J - c⁻¹ • (1 : Matrix n n ℝ)) *ᵥ x) = x ⬝ᵥ (J *ᵥ x) - c⁻¹ * (x ⬝ᵥ x) := by simp only [Matrix.sub_mulVec, Matrix.smul_mulVec, Matrix.one_mulVec, dotProduct_sub, dotProduct_smul, smul_eq_mul] rw [hquad] by_cases hxx0 : x ⬝ᵥ x = 0 · rw [hxx0, mul_zero, sub_zero]; exact hxJx_nn · have hxx_pos : 0 < x ⬝ᵥ x := lt_of_le_of_ne hxx_nn (Ne.symm hxx0) have hprod : (x ⬝ᵥ x) ^ 2 ≤ (c * (x ⬝ᵥ x)) * (x ⬝ᵥ (J *ᵥ x)) := hcs.trans (mul_le_mul_of_nonneg_right hMupper hxJx_nn) have hle : x ⬝ᵥ x ≤ c * (x ⬝ᵥ (J *ᵥ x)) := by nlinarith have hinv : c⁻¹ * (x ⬝ᵥ x) ≤ x ⬝ᵥ (J *ᵥ x) := by have := mul_le_mul_of_nonneg_left hle (inv_nonneg.mpr (le_of_lt hc)) rwa [← mul_assoc, inv_mul_cancel₀ (ne_of_gt hc), one_mul] at this linarith /-- Orthogonal overlap conjugation preserves outer products (`Q (v vᵀ) Qᵀ = (Qv)(Qv)ᵀ`). -/ theorem outer_orthogonal_congruence (Q : Mat3) (v : Vec3) : Q * outer v * Qᵀ = outer (Q *ᵥ v) := by ext i j simp only [outer, Matrix.mul_apply, Matrix.transpose_apply, Matrix.of_apply, mulVec, dotProduct] calc ∑ k : Fin 3, (∑ l : Fin 3, Q i l * (v l * v k)) * Q j k = ∑ k : Fin 3, (∑ l : Fin 3, Q i l * v l) * (Q j k * v k) := by apply Finset.sum_congr rfl intro k _ rw [Finset.sum_mul, Finset.sum_mul] apply Finset.sum_congr rfl intro l _ ring _ = (∑ l : Fin 3, Q i l * v l) * (∑ k : Fin 3, Q j k * v k) := by rw [← Finset.mul_sum] /-- Frame-change checkpoint recovery for 3×3 physical matrices directly reusing `LinkedTower.Links.checkpoint_effect_arbitrary`. -/ theorem matrix_overlap_recovery (Qa Qb E : Mat3) (hQb : Qb * Qbᵀ = 1) : Qb * ((Qbᵀ * Qa) * E * (Qaᵀ * Qb)) * Qbᵀ = Qa * E * Qaᵀ := LinkedTower.Links.checkpoint_effect_arbitrary Qa Qaᵀ Qb Qbᵀ E hQb end end F02NavierStokes.LinearAlgebra3D