Download lean/OAI/Combinatorics/MatchingPSD/MatrixInterpolation.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 6.23 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/MatchingPSD/MatrixInterpolation.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Combinatorics/MatchingPSD/MatrixInterpolation.lean
-
curl -L -o MatrixInterpolation.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/MatchingPSD/MatrixInterpolation.lean
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 | |