math / data /lean /OAI /Combinatorics /MatchingPSD /MatrixInterpolation.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
6.23 kB
import OAI.Combinatorics.MatchingPSD.PolynomialInterpolation
namespace OAI
universe u_1 u_2
namespace MatchingInterpolation
open MatchingSmoothing Matrix PerfectMatchingPSD
open scoped BigOperators MatrixOrder
attribute [local instance] Classical.propDecidable
noncomputable def specialPoint : Fin 5 β†’ Point :=
![origin, origin+dirP, origin+dirStar, origin+dirA, origin+dirB]
def specialCoeff : Fin 5 β†’ ℝ := ![1,-2,-1,1,1]
noncomputable def scaledNode {d : β„•} (L : ℝ) (g : GridIndex d) : Point :=
fun a => origin a+L*(g a:ℝ)
noncomputable def weightMass (d : β„•) (L : ℝ) : ℝ := βˆ‘ g, |weight d L g|
lemma weightMass_nonneg (d : β„•) (L : ℝ) : 0 ≀ weightMass d L :=
Finset.sum_nonneg (fun _ _ => abs_nonneg _)
lemma sum_abs_specialCoeff : (βˆ‘ j, |specialCoeff j|) = 6 := by
norm_num [specialCoeff, Fin.sum_univ_succ]
lemma five_interpolation {d : β„•} (P : Point β†’ ℝ) (hP : P ∈ lowDegree coord d)
{L : ℝ} (hL : L β‰  0) :
(βˆ‘ j, specialCoeff j * P (specialPoint j)) = βˆ‘ g, weight d L g * P (scaledNode L g) := by
have h := weighted_interpolation d P hP L hL
simp only [specialCoeff, specialPoint, Fin.sum_univ_succ, Matrix.cons_val_zero,
Matrix.cons_val_succ, one_mul, neg_mul, Fin.sum_univ_zero, add_zero] at *
change _ = βˆ‘ g, weight d L g * P (fun a => origin a+L*(g a:ℝ))
linarith
lemma finite_weighted_error {X : Type u_1} [Fintype X]
(c e : X β†’ ℝ) {Ξ· : ℝ} (he : βˆ€ x, |e x| ≀ Ξ·) :
|βˆ‘ x, c x*e x| ≀ (βˆ‘ x, |c x|)*Ξ· := by
calc
_ ≀ βˆ‘ x, |c x*e x| := Finset.abs_sum_le_sum_abs _ _
_ ≀ βˆ‘ x, |c x| *Ξ· := by
apply Finset.sum_le_sum
intro x _
rw [abs_mul]
exact mul_le_mul_of_nonneg_left (he x) (abs_nonneg _)
_ = _ := (Finset.sum_mul _ _ _).symm
lemma interpolation_error {d : β„•} (F P : Point β†’ ℝ)
(hP : P ∈ lowDegree coord d) {L Ξ· : ℝ} (hL : L β‰  0)
(hs : βˆ€ j, |F (specialPoint j)-P (specialPoint j)| ≀ Ξ·)
(hg : βˆ€ g : GridIndex d, |F (scaledNode L g)-P (scaledNode L g)| ≀ Ξ·) :
|(βˆ‘ j, specialCoeff j*F (specialPoint j)) -
βˆ‘ g, weight d L g*F (scaledNode L g)| ≀ (6+weightMass d L)*Ξ· := by
have hidentity : (βˆ‘ j, specialCoeff j*F (specialPoint j)) -
βˆ‘ g, weight d L g*F (scaledNode L g) =
(βˆ‘ j, specialCoeff j*(F (specialPoint j)-P (specialPoint j))) -
βˆ‘ g, weight d L g*(F (scaledNode L g)-P (scaledNode L g)) := by
simp only [mul_sub, Finset.sum_sub_distrib, five_interpolation P hP hL]
ring
rw [hidentity]
have h1 := finite_weighted_error specialCoeff (fun j => F (specialPoint j)-P (specialPoint j)) hs
have h2 := finite_weighted_error (weight d L) (fun g => F (scaledNode L g)-P (scaledNode L g)) hg
rw [sum_abs_specialCoeff] at h1
calc
_ ≀ |βˆ‘ j, specialCoeff j*(F (specialPoint j)-P (specialPoint j))| +
|βˆ‘ g, weight d L g*(F (scaledNode L g)-P (scaledNode L g))| := abs_sub _ _
_ ≀ 6*Ξ· + weightMass d L*Ξ· := add_le_add h1 h2
_ = _ := by ring
section Matrices
variable {R : Type u_2} [Fintype R] [DecidableEq R]
lemma interpolation_matrix_domination (d : β„•)
(B : Point β†’ Matrix R R ℝ) (hB : βˆ€ x, (B x).PosSemidef)
(P : R β†’ R β†’ Point β†’ ℝ) (hP : βˆ€ u v, P u v ∈ lowDegree coord d)
{L Ξ· : ℝ} (hL : L β‰  0) (hΞ· : 0 ≀ Ξ·)
(hs : βˆ€ j u v, |B (specialPoint j) u v-P u v (specialPoint j)| ≀ Ξ·)
(hg : βˆ€ g : GridIndex d, βˆ€ u v, |B (scaledNode L g) u v-P u v (scaledNode L g)| ≀ Ξ·) :
βˆƒ E : Matrix R R ℝ, E.PosSemidef ∧
B (origin+dirA)+B (origin+dirB) ≀ B (origin+dirStar)+(2:ℝ) β€’ B (origin+dirP)+E ∧
βˆ€ (Q : Matrix R R ℝ) (m k : ℝ), Q.trace ≀ m β†’
(βˆ€ g : GridIndex d, (Q*B (scaledNode L g)).trace ≀ k) β†’
(Q*E).trace ≀ weightMass d L*k +
(Fintype.card R : ℝ)*(6+weightMass d L)*Ξ·*m := by
let H := (βˆ‘ j, specialCoeff j β€’ B (specialPoint j)) -
βˆ‘ g, weight d L g β€’ B (scaledNode L g)
let b := (6+weightMass d L)*Ξ·
let c := (Fintype.card R : ℝ)*b
let W := βˆ‘ g, |weight d L g| β€’ B (scaledNode L g)
have hb : 0 ≀ b := mul_nonneg (by linarith [weightMass_nonneg d L]) hΞ·
have hc : 0 ≀ c := mul_nonneg (Nat.cast_nonneg _) hb
have hH : H.IsHermitian := by
have hh (x : Point) := (hB x).isHermitian.eq
simp only [H, Matrix.IsHermitian, Matrix.conjTranspose_sub, Matrix.conjTranspose_sum,
Matrix.conjTranspose_smul, star_trivial, hh]
have hentry (u v : R) : |H u v| ≀ b := by
simpa only [H, Matrix.sub_apply, Matrix.sum_apply, Matrix.smul_apply, smul_eq_mul] using
interpolation_error (fun x => B x u v) (P u v) (hP u v) hL (fun j => hs j u v) (fun g => hg g u v)
have hbound : H ≀ c β€’ (1 : Matrix R R ℝ) := le_card_entry_bound hH hb hentry
have hW : W.PosSemidef := matrix_sum_psd _ _ (fun g _ => (hB _).smul (abs_nonneg _))
let E := W+c β€’ (1 : Matrix R R ℝ)
have hE : E.PosSemidef := hW.add (Matrix.PosSemidef.one.smul hc)
refine ⟨E,hE,?_,?_⟩
Β· apply sub_nonneg.mp
apply Matrix.PosSemidef.nonneg
have hdiff : (βˆ‘ g : GridIndex d, (|weight d L g|-weight d L g) β€’ B (scaledNode L g)).PosSemidef :=
matrix_sum_psd _ _ (fun g _ => (hB _).smul (sub_nonneg.mpr (le_abs_self _)))
convert ((sub_nonneg.mpr hbound).posSemidef.add (hB origin)).add hdiff using 1
dsimp [E,W,H]
simp only [sub_smul, Finset.sum_sub_distrib, specialPoint, specialCoeff, Fin.sum_univ_succ,
Matrix.cons_val_zero, Matrix.cons_val_succ, one_smul, neg_smul,
Fin.sum_univ_zero, add_zero]
module
Β· intro Q m k hm hk
change (Q*(W+c β€’ (1 : Matrix R R ℝ))).trace ≀ _
rw [mul_add, Matrix.trace_add, mul_smul_comm, Matrix.trace_smul, mul_one]
have hWt : (Q*W).trace ≀ weightMass d L*k := by
dsimp [W,weightMass]
rw [Finset.mul_sum, Matrix.trace_sum, Finset.sum_mul]
apply Finset.sum_le_sum
intro g _
rw [mul_smul_comm, Matrix.trace_smul]
exact mul_le_mul_of_nonneg_left (hk g) (abs_nonneg _)
have he := add_le_add hWt (mul_le_mul_of_nonneg_left hm hc)
calc
_ ≀ weightMass d L*k + c*m := he
_ = _ := by dsimp [c,b]; ring
end Matrices
end MatchingInterpolation
end OAI