πŸ›οΈ Atlasβœ’οΈFormalizations.AlgebraicGeometry.SegrePersistence.GramUnique view on GitHub β†—8 theorems
/-Copyright (c) 2026 Carles MarΓ­n. All rights reserved.Released under Apache 2.0 license as described in the file LICENSE.Authors: Carles MarΓ­n, Claude (AI assistant)-/module -- encaje: nΓΊcleo de la prueba del Teorema 6 (thm:Q) de la nota qp_bsr: unicidad de la Gram PSD.public import Mathlib.LinearAlgebra.Matrix.PosDefpublic import Mathlib.LinearAlgebra.Matrix.Rankpublic import Mathlib.Analysis.Real.Sqrtpublic import Mathlib.Algebra.Order.Star.Realpublic import Mathlib.Tactic.Ring /-!# Uniqueness of the positive semidefinite Gram matrix This file formalizes the linear-algebra core of the proof of Theorem 6 (`thm:Q`) ofC. MarΓ­n, *Quadratic persistence of Segre varieties and a linear gap between biquadratic SOS rankand Zarankiewicz bounds* (2026): if the points `p i` make the map `D ↦ (D p_i)_i` injective on asubspace `π’Ÿ` of matrices, then a positive semidefinite Gram matrix that vanishes on the `p i` isunique modulo `π’Ÿ`; and the Gram matrix `G = βˆ‘ j, c j β€’ u j u jα΅€` (`c j > 0`, `u j ⬝ p i = 0`) of`F = βˆ‘ j c j u_jΒ²` (in the note `c = (1, …, 1, 7)`) is positive semidefinite, kills the `p i`,and has rank `e` (the number of `u j`) when the `u j` are linearly independent. Everything is over `ℝ` with an arbitrary finite index type `n` (in the note `n = Fin (m * n)`). ## Main results * `SegrePersistence.GramUnique.mulVec_eq_zero`: `G` PSD and `pα΅€ G p = 0` give `G p = 0`  (this is Mathlib's `Matrix.PosSemidef.dotProduct_mulVec_zero_iff`, specialised to `ℝ`).* `SegrePersistence.GramUnique.eq_of_posSemidef`: two PSD matrices whose difference lies in `π’Ÿ`  and whose quadratic forms vanish at every `p i` are equal.* `SegrePersistence.GramUnique.eq_of_posSemidef_of_form_eq`: the same, assuming only that the two  quadratic forms agree at the `p i` and that one of them vanishes there.* `SegrePersistence.GramUnique.gramOf_posSemidef`, `gramOf_mulVec_eq_zero`,  `dotProduct_gramOf_mulVec`, `gramOf_rank`: the Gram matrix of `βˆ‘ j c j u_jΒ²`.* `SegrePersistence.GramUnique.gramOf_unique`: the combination used in the note. ## What is not covered That `π’Ÿ` is the space of Gram relations of the Segre variety (`β‹€Β²A* βŠ— β‹€Β²B*`), the existence of`qp(X)` rational simple tensors `p i` making the map injective (a Zariski-density argument), theidentification of a Gram matrix of the biquadratic form `F` with a matrix whose difference with`gramOf c u` lies in `π’Ÿ`, and the rational count `β„“_β„š(F) = e + 3` (Witt cancellation and`7` not a sum of three rational squares, which goes through `seven_embedding` in Isabelle) arenot formalized here.-/ @[expose] public section open Matrix Finset namespace SegrePersistence namespace GramUnique variable {n ΞΉ ΞΊ : Type*} [Fintype n] /-- A positive semidefinite real matrix whose quadratic form vanishes at `p` kills `p`. -/theorem mulVec_eq_zero {G : Matrix n n ℝ} (hG : G.PosSemidef) {p : n β†’ ℝ}    (hp : p ⬝α΅₯ G *α΅₯ p = 0) : G *α΅₯ p = 0 :=  hG.dotProduct_mulVec_zero_iff.mp (by simpa using hp) /-- **Uniqueness of the PSD Gram matrix.** If `D ↦ (D *α΅₯ p i)_i` is injective on `π’Ÿ`, twopositive semidefinite matrices `G, G'` with `G - G' ∈ π’Ÿ` whose quadratic forms vanish at every`p i` are equal. -/theorem eq_of_posSemidef (π’Ÿ : Submodule ℝ (Matrix n n ℝ)) (p : ΞΉ β†’ n β†’ ℝ)    (hinj : βˆ€ D ∈ π’Ÿ, (βˆ€ i, D *α΅₯ p i = 0) β†’ D = 0)    {G G' : Matrix n n ℝ} (hG : G.PosSemidef) (hG' : G'.PosSemidef) (hD : G - G' ∈ π’Ÿ)    (h0 : βˆ€ i, p i ⬝α΅₯ G *α΅₯ p i = 0) (h0' : βˆ€ i, p i ⬝α΅₯ G' *α΅₯ p i = 0) : G = G' := by  refine sub_eq_zero.mp (hinj _ hD fun i => ?_)  rw [sub_mulVec, mulVec_eq_zero hG (h0 i), mulVec_eq_zero hG' (h0' i), sub_zero] /-- Variant of `eq_of_posSemidef`: it suffices that the two quadratic forms agree at the `p i`and that one of them vanishes there. -/theorem eq_of_posSemidef_of_form_eq (π’Ÿ : Submodule ℝ (Matrix n n ℝ)) (p : ΞΉ β†’ n β†’ ℝ)    (hinj : βˆ€ D ∈ π’Ÿ, (βˆ€ i, D *α΅₯ p i = 0) β†’ D = 0)    {G G' : Matrix n n ℝ} (hG : G.PosSemidef) (hG' : G'.PosSemidef) (hD : G - G' ∈ π’Ÿ)    (h0 : βˆ€ i, p i ⬝α΅₯ G *α΅₯ p i = 0)    (hform : βˆ€ i, p i ⬝α΅₯ G' *α΅₯ p i = p i ⬝α΅₯ G *α΅₯ p i) : G = G' :=  eq_of_posSemidef π’Ÿ p hinj hG hG' hD h0 fun i => (hform i).trans (h0 i) variable [Fintype ΞΊ] /-- The Gram matrix `βˆ‘ j, c j β€’ u j u jα΅€` of the quadratic form `βˆ‘ j, c j (u j ⬝ x)Β²`. -/noncomputable def gramOf (c : ΞΊ β†’ ℝ) (u : ΞΊ β†’ n β†’ ℝ) : Matrix n n ℝ :=  βˆ‘ j, c j β€’ vecMulVec (u j) (u j) /-- `gramOf c u` is the Gram matrix of `x ↦ βˆ‘ j, c j (u j ⬝ x)Β²`. -/theorem dotProduct_gramOf_mulVec (c : ΞΊ β†’ ℝ) (u : ΞΊ β†’ n β†’ ℝ) (x : n β†’ ℝ) :    x ⬝α΅₯ gramOf c u *α΅₯ x = βˆ‘ j, c j * (u j ⬝α΅₯ x) ^ 2 := by  simp only [gramOf, Matrix.sum_mulVec, smul_mulVec, dotProduct_sum, dotProduct_smul,    vecMulVec_mulVec, smul_eq_mul]  refine Finset.sum_congr rfl fun j _ => ?_  rw [op_smul_eq_mul, dotProduct_comm x (u j)]  ring theorem gramOf_posSemidef {c : ΞΊ β†’ ℝ} (hc : βˆ€ j, 0 ≀ c j) (u : ΞΊ β†’ n β†’ ℝ) :    (gramOf c u).PosSemidef :=  posSemidef_sum _ fun j _ => by    simpa using (posSemidef_vecMulVec_self_star (u j)).smul (hc j) /-- If every `u j` annihilates `p`, the Gram matrix kills `p`. -/theorem gramOf_mulVec_eq_zero (c : ΞΊ β†’ ℝ) (u : ΞΊ β†’ n β†’ ℝ) {p : n β†’ ℝ}    (hp : βˆ€ j, u j ⬝α΅₯ p = 0) : gramOf c u *α΅₯ p = 0 := by  simp [gramOf, Matrix.sum_mulVec, smul_mulVec, vecMulVec_mulVec, hp] /-- With `c j > 0` and the `u j` linearly independent, `rank (gramOf c u) = card ΞΊ`. -/theorem gramOf_rank {c : ΞΊ β†’ ℝ} (hc : βˆ€ j, 0 < c j) {u : ΞΊ β†’ n β†’ ℝ}    (hu : LinearIndependent ℝ u) : (gramOf c u).rank = Fintype.card ΞΊ := by  set B : Matrix n ΞΊ ℝ := Matrix.of fun a j => Real.sqrt (c j) * u j a with hB  have hG : gramOf c u = B * Bα΅€ := by    ext a b    simp only [gramOf, Matrix.sum_apply, Matrix.smul_apply, vecMulVec_apply, smul_eq_mul,      Matrix.mul_apply, transpose_apply, hB, Matrix.of_apply]    refine Finset.sum_congr rfl fun j _ => ?_    have := Real.mul_self_sqrt (hc j).le    calc c j * (u j a * u j b) = (Real.sqrt (c j) * Real.sqrt (c j)) * (u j a * u j b) := by          rw [this]      _ = _ := by ring  have hcols : Bα΅€ = fun j => (Units.mk0 (Real.sqrt (c j))      (Real.sqrt_ne_zero'.mpr (hc j))) β€’ u j := by    ext j a    simp [hB, Units.smul_def]  have hli : LinearIndependent ℝ Bα΅€ := by    rw [hcols]    exact hu.units_smul _  rw [hG, rank_self_mul_transpose, rank_eq_finrank_span_cols]  exact finrank_span_eq_card hli /-- **The combination used in the note.** For `G = gramOf c u` with `c j > 0` and `u j ⬝ p i = 0`:`G` is PSD, kills every `p i`, every PSD `G'` with `G - G' ∈ π’Ÿ` and the same quadratic form at the`p i` equals `G` (when `D ↦ (D p_i)_i` is injective on `π’Ÿ`), and `rank G = card ΞΊ` when the `u j`are linearly independent. -/theorem gramOf_unique (π’Ÿ : Submodule ℝ (Matrix n n ℝ)) (p : ΞΉ β†’ n β†’ ℝ)    (hinj : βˆ€ D ∈ π’Ÿ, (βˆ€ i, D *α΅₯ p i = 0) β†’ D = 0)    {c : ΞΊ β†’ ℝ} (hc : βˆ€ j, 0 < c j) {u : ΞΊ β†’ n β†’ ℝ} (hup : βˆ€ j i, u j ⬝α΅₯ p i = 0)    {G' : Matrix n n ℝ} (hG' : G'.PosSemidef) (hD : gramOf c u - G' ∈ π’Ÿ)    (hform : βˆ€ i, p i ⬝α΅₯ G' *α΅₯ p i = p i ⬝α΅₯ gramOf c u *α΅₯ p i) :    (gramOf c u).PosSemidef ∧ (βˆ€ i, gramOf c u *α΅₯ p i = 0) ∧ gramOf c u = G' ∧      (LinearIndependent ℝ u β†’ (gramOf c u).rank = Fintype.card ΞΊ) := by  have hG := gramOf_posSemidef (fun j => (hc j).le) u  have hk : βˆ€ i, gramOf c u *α΅₯ p i = 0 := fun i => gramOf_mulVec_eq_zero c u (hup Β· i)  refine ⟨hG, hk, ?_, fun hu => gramOf_rank hc hu⟩  exact eq_of_posSemidef_of_form_eq π’Ÿ p hinj hG hG' hD (fun i => by rw [hk i, dotProduct_zero])    hform end GramUnique end SegrePersistence