/-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