Download data/lean/OAI/Probability/SKGap/Matrix/DiscreteMatrixCalculus.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 16.1 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/SKGap/Matrix/DiscreteMatrixCalculus.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/SKGap/Matrix/DiscreteMatrixCalculus.lean
-
curl -L -o DiscreteMatrixCalculus.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/SKGap/Matrix/DiscreteMatrixCalculus.lean
16.1 kB
| import Mathlib | |
| import OAI.Probability.SKGap.Matrix.OpNormDiagonal | |
| import OAI.Probability.SKGap.Matrix.MatrixSeminorm | |
| import OAI.Probability.SKGap.Gaussian.SquaredGaussianFourth | |
| import OAI.Probability.SKGap.Localization.PreparationGrowth | |
| namespace OAI | |
| section | |
| noncomputable section | |
| open scoped BigOperators Matrix.Norms.Frobenius | |
| namespace SKGapCutoff.Primary | |
| open SKGap Matrix | |
| variable {n : β} | |
| local instance : Fact (1β€(4:ENNReal)) := β¨by norm_numβ© | |
| def derivativeMatrix (F : VectorFields n) (x : Spin n) : Interaction n := | |
| fun i k => halfDiff k (fun y => F y i) x | |
| def ShapeBound (M : Interaction n) (C : β) : Prop := | |
| SKGap.opNorm M β€ C β§ SKGap.diagonalSeminorm M β€ C β§ SKGap.offDiagonalSeminorm M β€ C | |
| lemma opNorm_eq (M : Interaction n) : | |
| SKGap.opNorm M = βMatrix.toEuclideanCLM (n := Fin n) (π := β) Mβ := rfl | |
| lemma opNorm_le_frobenius (M : Interaction n) : SKGap.opNorm M β€ βMβ := by | |
| apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg M) | |
| simp only [β sq] | |
| rw [SKGap.frobenius_sq,opNorm_eq] | |
| exact RandomMatrix.matrix_opNorm_sq_le_frobenius M | |
| lemma opNorm_add (M N : Interaction n) : SKGap.opNorm (M+N) β€ SKGap.opNorm M+SKGap.opNorm N := by | |
| simp only [opNorm_eq,map_add] | |
| exact norm_add_le _ _ | |
| lemma opNorm_smul (c : β) (M : Interaction n) : SKGap.opNorm (c β’ M) = |c| * SKGap.opNorm M := by | |
| simp only [opNorm_eq,map_smul,norm_smul,Real.norm_eq_abs] | |
| lemma ShapeBound.mono {M : Interaction n} {C D : β} (h : ShapeBound M C) (hCD : Cβ€D) : | |
| ShapeBound M D := β¨h.1.trans hCD,h.2.1.trans hCD,h.2.2.trans hCDβ© | |
| lemma ShapeBound.add {M N : Interaction n} {C D : β} | |
| (hM : ShapeBound M C) (hN : ShapeBound N D) : ShapeBound (M+N) (C+D) := by | |
| exact β¨(opNorm_add M N).trans (add_le_add hM.1 hN.1), | |
| (SKGap.diagonalSeminorm_add M N).trans (add_le_add hM.2.1 hN.2.1), | |
| (SKGap.offDiagonalSeminorm_add M N).trans (add_le_add hM.2.2 hN.2.2)β© | |
| lemma shapeBound_of_frobenius {M : Interaction n} {C : β} (h : βMββ€C) : ShapeBound M C := | |
| β¨(opNorm_le_frobenius M).trans h,(SKGap.diagonalSeminorm_le M).trans h, | |
| (SKGap.offDiagonalSeminorm_le M).trans hβ© | |
| lemma ShapeBound.perturb {M H : Interaction n} {C E : β} | |
| (hH : ShapeBound H C) (hE : βM-Hββ€E) : ShapeBound M (C+E) := by | |
| simpa only [add_sub_cancel] using hH.add (shapeBound_of_frobenius hE) | |
| lemma fourth_sum (M : Interaction n) : | |
| (β i,β k,(M i k)^4) = (β i,(M i i)^4)+SKGap.offDiagonalSeminorm M^4 := by | |
| rw [SKGap.offDiagonalSeminorm_fourth,Fintype.sum_prod_type,β Finset.sum_add_distrib] | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| have hs : (M i i)^4 = β k : Fin n, if i=k then (M i k)^4 else 0 := by simp | |
| rw [hs,β Finset.sum_add_distrib] | |
| apply Finset.sum_congr rfl | |
| intro k _ | |
| by_cases h : i=k <;> simp [h] | |
| lemma fourth_sum_le {M : Interaction n} {C : β} (hC : 0β€C) (hM : ShapeBound M C) : | |
| (β i,β k,(M i k)^4) β€ 2*C^4 := by | |
| rw [fourth_sum] | |
| have hd : (β i,(M i i)^4) β€ SKGap.diagonalSeminorm M^4 := by | |
| rw [show (4:β)=2*2 by rfl,pow_mul,SKGap.diagonalSeminorm_sq] | |
| simpa only [pow_mul] using | |
| (Finset.sum_sq_le_sq_sum_of_nonneg (s:=Finset.univ) (f:=fun i => (M i i)^2) | |
| (fun i _ => sq_nonneg _)) | |
| have hdC := (pow_le_pow_iff_leftβ (norm_nonneg (SKGap.diagonalVector M)) hC | |
| (by decide : 4 β 0)).2 hM.2.1 | |
| have hoC := pow_le_pow_leftβ (norm_nonneg (SKGap.offDiagonalVector M)) hM.2.2 4 | |
| dsimp only [SKGap.diagonalSeminorm,SKGap.offDiagonalSeminorm] at hd β’ | |
| nlinarith | |
| lemma quadratic_entry_error {D R : Interaction n} {C A : β} (hC : 0β€C) (hA : 0β€A) | |
| (hD : ShapeBound D C) (he : β i k, |R i k|β€A*(D i k)^2) : | |
| βRβ β€ 2*A*C^2 := by | |
| have hs : βRβ^2 β€ A^2*(2*C^4) := by | |
| rw [SKGap.frobenius_sq] | |
| calc | |
| _ β€ β i,β k,A^2*(D i k)^4 := by | |
| apply Finset.sum_le_sum | |
| intro i _ | |
| apply Finset.sum_le_sum | |
| intro k _ | |
| have h := pow_le_pow_leftβ (abs_nonneg (R i k)) (he i k) 2 | |
| nlinarith only [h,sq_abs (R i k)] | |
| _ = A^2*(β i,β k,(D i k)^4) := by simp_rw [β Finset.mul_sum] | |
| _ β€ A^2*(2*C^4) := mul_le_mul_of_nonneg_left (fourth_sum_le hC hD) (sq_nonneg _) | |
| have hp : 0β€2*A*C^2 := by positivity | |
| nlinarith [sq_nonneg (A*C^2)] | |
| lemma diagonal_mul_shape {M : Interaction n} {C : β} {a : Fin nββ} | |
| (ha : β i,|a i|β€1) (hM : ShapeBound M C) : | |
| ShapeBound (Matrix.diagonal a*M) C := by | |
| have haN : SKGap.opNorm (Matrix.diagonal a)β€1 := SKGap.opNorm_diagonal_le (by norm_num) ha | |
| refine β¨(SKGap.opNorm_mul _ _).trans ?_,?_,?_β© | |
| Β· calc | |
| _ β€ 1*SKGap.opNorm M := mul_le_mul_of_nonneg_right haN (norm_nonneg _) | |
| _ = SKGap.opNorm M := one_mul _ | |
| _ β€ C := hM.1 | |
| Β· apply le_trans ?_ hM.2.1 | |
| apply le_of_pow_le_pow_leftβ (by decide : 2β 0) (norm_nonneg _) | |
| change SKGap.diagonalSeminorm _ ^2 β€ SKGap.diagonalSeminorm M ^2 | |
| simp only [SKGap.diagonalSeminorm_sq,Matrix.diagonal_mul] | |
| apply Finset.sum_le_sum | |
| intro i _ | |
| have hi := pow_le_pow_leftβ (abs_nonneg (a i)) (ha i) 2 | |
| simp only [sq_abs,one_pow] at hi | |
| simpa only [mul_pow,one_mul] using mul_le_mul_of_nonneg_right hi (sq_nonneg (M i i)) | |
| Β· apply le_trans ?_ hM.2.2 | |
| apply le_of_pow_le_pow_leftβ (by decide : 4β 0) (norm_nonneg _) | |
| change SKGap.offDiagonalSeminorm _ ^4 β€ SKGap.offDiagonalSeminorm M ^4 | |
| simp only [SKGap.offDiagonalSeminorm_fourth] | |
| apply Finset.sum_le_sum | |
| intro p _ | |
| split_ifs | |
| Β· exact le_rfl | |
| Β· simp only [Matrix.diagonal_mul,mul_pow] | |
| have hi := pow_le_pow_leftβ (abs_nonneg (a p.1)) (ha p.1) 4 | |
| rw [β abs_pow,abs_of_nonneg (by positivity : 0β€a p.1^4)] at hi | |
| simpa only [one_pow,one_mul] using mul_le_mul_of_nonneg_right hi | |
| (by positivity : 0β€(M p.1 p.2)^4) | |
| lemma tanh_derivative_error {F : VectorFields n} {x : Spin n} {C : β} | |
| (hC : 0β€C) (hD : ShapeBound (derivativeMatrix F x) C) : | |
| βderivativeMatrix (fun y i => Real.tanh (F y i)) x- | |
| Matrix.diagonal (fun i => scalarVariance (F x i))*derivativeMatrix F xβ β€ 8*C^2 := by | |
| convert quadratic_entry_error hC (by norm_num : (0:β)β€4) hD ?_ using 1 <;> try norm_num | |
| intro i k | |
| simpa only [derivativeMatrix,Matrix.sub_apply,Matrix.diagonal_mul,mul_comm, | |
| refreshInfluence] using refreshInfluence_error_le F x k i | |
| lemma tanh_derivative_shape {F : VectorFields n} {x : Spin n} {C : β} | |
| (hC : 0β€C) (hD : ShapeBound (derivativeMatrix F x) C) : | |
| ShapeBound (derivativeMatrix (fun y i => Real.tanh (F y i)) x) (C+8*C^2) := by | |
| apply ShapeBound.perturb _ (tanh_derivative_error hC hD) | |
| apply diagonal_mul_shape ?_ hD | |
| intro i | |
| rw [abs_of_pos (scalarVariance_pos _)] | |
| exact scalarVariance_le_one _ | |
| def derivativeVector (f : Spin nββ) (x : Spin n) : EuclideanSpace β (Fin n) := | |
| WithLp.toLp 2 (fun k => halfDiff k f x) | |
| def siteMean (F : VectorFields n) (x : Spin n) : β := (β i,F x i)/(n:β) | |
| lemma siteMean_derivative (F : VectorFields n) (x : Spin n) : | |
| derivativeVector (siteMean F) x = (n:β)β»ΒΉ β’ | |
| (Matrix.toEuclideanCLM (n := Fin n) (π := β) ((derivativeMatrix F x)α΅)) | |
| (WithLp.toLp 2 (fun _ => 1)) := by | |
| ext k | |
| change halfDiff k (siteMean F) x = (n:β)β»ΒΉ*(β i,halfDiff k (fun y => F y i) x*1) | |
| simp only [mul_one,halfDiff,siteMean] | |
| rw [β Finset.sum_div,Finset.sum_sub_distrib] | |
| ring | |
| lemma euclidean_ones_norm_sq : | |
| β(WithLp.toLp 2 (fun _ : Fin n => (1:β)) : EuclideanSpace β (Fin n))β^2 = n := by | |
| simp [EuclideanSpace.real_norm_sq_eq] | |
| lemma siteMean_derivative_square (F : VectorFields n) (x : Spin n) (hn : 0<n) : | |
| (n:β)*βderivativeVector (siteMean F) xβ^2 β€ SKGap.opNorm (derivativeMatrix F x)^2 := by | |
| have hnR : (0:β)<n := Nat.cast_pos.mpr hn | |
| have h := (Matrix.toEuclideanCLM (n := Fin n) (π := β) ((derivativeMatrix F x)α΅)).le_opNorm | |
| (WithLp.toLp 2 (fun _ : Fin n => (1:β))) | |
| change β(Matrix.toEuclideanCLM (n := Fin n) (π := β) ((derivativeMatrix F x)α΅)) | |
| (WithLp.toLp 2 (fun _ : Fin n => (1:β)))β β€ | |
| SKGap.opNorm ((derivativeMatrix F x)α΅) * β(WithLp.toLp 2 (fun _ : Fin n => (1:β)) : EuclideanSpace β (Fin n))β at h | |
| rw [SKGap.opNorm_transpose] at h | |
| have hs := pow_le_pow_leftβ (norm_nonneg _) h 2 | |
| rw [mul_pow,euclidean_ones_norm_sq] at hs | |
| rw [siteMean_derivative,norm_smul,Real.norm_eq_abs,abs_inv,abs_of_pos hnR,mul_pow] | |
| field_simp | |
| nlinarith | |
| lemma siteMean_derivative_square_bound {F : VectorFields n} {x : Spin n} {B : β} | |
| (hn : 0<n) (hB : SKGap.opNorm (derivativeMatrix F x)β€B) : | |
| (n:β)*βderivativeVector (siteMean F) xβ^2 β€ B^2 := | |
| (siteMean_derivative_square F x hn).trans | |
| (pow_le_pow_leftβ (norm_nonneg _) hB 2) | |
| lemma derivative_norm_of_mean_square {f : Spin nββ} {x : Spin n} {B : β} | |
| (hn : 0<n) (hB : 0β€B) (h : (n:β)*βderivativeVector f xβ^2β€B^2) : | |
| βderivativeVector f xββ€B := by | |
| have hn1 : (1:β)β€n := by exact_mod_cast hn | |
| nlinarith [sq_nonneg βderivativeVector f xβ,norm_nonneg (derivativeVector f x)] | |
| lemma outer_frobenius_bound {v : Fin nββ} {f : Spin nββ} {x : Spin n} {B : β} | |
| (hv : β i,|v i|β€1) (hB : 0β€B) | |
| (h : (n:β)*βderivativeVector f xβ^2β€B^2) : | |
| βMatrix.of (fun i k => v i*halfDiff k f x)ββ€B := by | |
| apply nonneg_le_nonneg_of_sq_le_sq hB | |
| simp only [β sq] | |
| rw [SKGap.frobenius_sq] | |
| calc | |
| _ β€ β _i : Fin n,β k,(halfDiff k f x)^2 := by | |
| apply Finset.sum_le_sum | |
| intro i _ | |
| apply Finset.sum_le_sum | |
| intro k _ | |
| have hi := pow_le_pow_leftβ (abs_nonneg (v i)) (hv i) 2 | |
| simp only [sq_abs,one_pow] at hi | |
| change (v i*halfDiff k f x)^2 β€ _ | |
| rw [mul_pow] | |
| nlinarith [sq_nonneg (halfDiff k f x)] | |
| _ = (n:β)*βderivativeVector f xβ^2 := by | |
| simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul, | |
| EuclideanSpace.real_norm_sq_eq,derivativeVector] | |
| _ β€ B^2 := h | |
| lemma spin_diagonal_frobenius (f : Spin nββ) (x : Spin n) : | |
| βMatrix.diagonal (fun k => spin x k*halfDiff k f x)β = βderivativeVector f xβ := by | |
| apply (sq_eq_sqβ (norm_nonneg _) (norm_nonneg _)).mp | |
| rw [SKGap.frobenius_sq,EuclideanSpace.real_norm_sq_eq] | |
| simp [Matrix.diagonal_apply,derivativeVector,mul_pow,spin_sq] | |
| lemma derivativeMatrix_product (f : Spin nββ) (F : VectorFields n) (x : Spin n) : | |
| derivativeMatrix (fun y i => f y*F y i) x = f x β’ derivativeMatrix F x + | |
| Matrix.of (fun i k => F x i*halfDiff k f x) - | |
| (2:β) β’ (derivativeMatrix F x*Matrix.diagonal (fun k => spin x k*halfDiff k f x)) := by | |
| ext i k | |
| simp only [derivativeMatrix,Matrix.sub_apply,Matrix.add_apply,Matrix.smul_apply, | |
| smul_eq_mul,Matrix.mul_diagonal,halfDiff_mul,Matrix.of_apply] | |
| ring | |
| lemma product_derivative_error {f : Spin nββ} {F : VectorFields n} {x : Spin n} {B C : β} | |
| (hn : 0<n) (hB : 0β€B) (hC : SKGap.opNorm (derivativeMatrix F x)β€C) | |
| (hF : β i,|F x i|β€1) (hf : (n:β)*βderivativeVector f xβ^2β€B^2) : | |
| βderivativeMatrix (fun y i => f y*F y i) x-f x β’ derivativeMatrix F xβ β€ B+2*C*B := by | |
| have hdb := derivative_norm_of_mean_square hn hB hf | |
| have hC0 : 0β€C := (norm_nonneg _).trans hC | |
| rw [derivativeMatrix_product] | |
| have he (A R T : Interaction n) : A+R-T-A=R-T := by abel | |
| rw [he] | |
| calc | |
| _ β€ βMatrix.of (fun i k => F x i*halfDiff k f x)β+ | |
| β(2:β) β’ (derivativeMatrix F x*Matrix.diagonal (fun k => spin x k*halfDiff k f x))β := norm_sub_le _ _ | |
| _ β€ B+2*C*B := by | |
| apply add_le_add (outer_frobenius_bound hF hB hf) | |
| rw [norm_smul,Real.norm_eq_abs,abs_of_pos (by norm_num : (0:β)<2)] | |
| calc | |
| _ β€ 2*(SKGap.opNorm (derivativeMatrix F x)*βMatrix.diagonal (fun k => spin x k*halfDiff k f x)β) := | |
| mul_le_mul_of_nonneg_left (SKGap.frobenius_mul_le_opNorm _ _) (by norm_num) | |
| _ β€ 2*(C*B) := by | |
| rw [spin_diagonal_frobenius] | |
| exact mul_le_mul_of_nonneg_left (mul_le_mul hC hdb (norm_nonneg _) hC0) (by norm_num) | |
| _ = _ := by ring | |
| lemma derivativeMatrix_linear (J : Interaction n) (F : VectorFields n) (h : Fin nββ) | |
| (x : Spin n) : | |
| derivativeMatrix (fun y i => h i+β k,J i k*F y k) x = J*derivativeMatrix F x := by | |
| ext i l | |
| simp only [derivativeMatrix,Matrix.mul_apply,halfDiff] | |
| simp_rw [β mul_div_assoc,mul_sub] | |
| rw [β Finset.sum_div,Finset.sum_sub_distrib] | |
| ring | |
| lemma derivativeMatrix_sub (F G : VectorFields n) (x : Spin n) : | |
| derivativeMatrix (fun y i => F y i-G y i) x=derivativeMatrix F x-derivativeMatrix G x := by | |
| ext i k | |
| exact halfDiff_sub k (fun y => F y i) (fun y => G y i) x | |
| lemma derivativeMatrix_smul (c : β) (F : VectorFields n) (x : Spin n) : | |
| derivativeMatrix (fun y i => c*F y i) x=c β’ derivativeMatrix F x := by | |
| ext i k | |
| simp only [derivativeMatrix,halfDiff,Matrix.smul_apply,smul_eq_mul] | |
| ring | |
| lemma derivativeMatrix_spin (x : Spin n) : derivativeMatrix spin x=1 := by | |
| ext i k | |
| simp [derivativeMatrix,Matrix.one_apply,eq_comm] | |
| lemma variance_derivative_error {F : VectorFields n} {x : Spin n} {C : β} | |
| (hC : 0β€C) (hD : ShapeBound (derivativeMatrix F x) C) : | |
| βderivativeMatrix (fun y i => 1-(F y i)^2) x- | |
| (-2:β) β’ (Matrix.diagonal (F x)*derivativeMatrix F x)β β€ 4*C^2 := by | |
| convert quadratic_entry_error hC (by norm_num : (0:β)β€2) hD ?_ using 1 <;> try norm_num | |
| intro i k | |
| have hs : halfDiff k (fun y => 1-(F y i)^2) x = | |
| -2*F x i*halfDiff k (fun y => F y i) x+ | |
| 2*spin x k*(halfDiff k (fun y => F y i) x)^2 := by | |
| have hh := halfDiff_mul k (fun y => F y i) (fun y => F y i) x | |
| rw [halfDiff_sub,halfDiff_const] | |
| simpa only [pow_two,zero_sub] using (show -(halfDiff k (fun y => F y i*F y i) x) = | |
| -2*F x i*halfDiff k (fun y => F y i) x+ | |
| 2*spin x k*(halfDiff k (fun y => F y i) x)^2 by rw [hh]; ring) | |
| simp only [derivativeMatrix,hs] | |
| have he (a b c : β) : -2*a*b+2*c*b^2+2*(a*b)=2*c*b^2 := by ring | |
| rw [he,abs_mul,abs_mul,abs_spin_eq_one,mul_one] | |
| norm_num [abs_of_nonneg (sq_nonneg (halfDiff k (fun y => F y i) x))] | |
| lemma variance_derivative_opNorm {F : VectorFields n} {x : Spin n} {C : β} | |
| (hC : 0β€C) (hF : β i,|F x i|β€1) (hD : ShapeBound (derivativeMatrix F x) C) : | |
| SKGap.opNorm (derivativeMatrix (fun y i => 1-(F y i)^2) x) β€ 2*C+4*C^2 := by | |
| let A := (-2:β) β’ (Matrix.diagonal (F x)*derivativeMatrix F x) | |
| have hA : SKGap.opNorm Aβ€2*C := by | |
| dsimp only [A] | |
| rw [opNorm_smul] | |
| norm_num only [abs_neg,abs_of_nonneg (by norm_num : (0:β)β€2)] | |
| exact mul_le_mul_of_nonneg_left (diagonal_mul_shape hF hD).1 (by norm_num) | |
| have hE := (opNorm_le_frobenius | |
| (derivativeMatrix (fun y i => 1-(F y i)^2) x-A)).trans (variance_derivative_error hC hD) | |
| have he : derivativeMatrix (fun y i => 1-(F y i)^2) x = | |
| A+(derivativeMatrix (fun y i => 1-(F y i)^2) x-A) := by abel | |
| rw [he] | |
| exact (opNorm_add _ _).trans (add_le_add hA hE) | |
| lemma tanh_derivative_formal_error {F : VectorFields n} {x : Spin n} | |
| {H : Interaction n} {C E : β} (hC : 0β€C) (hD : ShapeBound (derivativeMatrix F x) C) | |
| (hE : βderivativeMatrix F x-Hββ€E) : | |
| βderivativeMatrix (fun y i => Real.tanh (F y i)) x- | |
| Matrix.diagonal (fun i => scalarVariance (F x i))*Hβ β€ 8*C^2+E := by | |
| let V := Matrix.diagonal (fun i => scalarVariance (F x i)) | |
| have hV : SKGap.opNorm Vβ€1 := by | |
| apply SKGap.opNorm_diagonal_le (by norm_num) | |
| intro i | |
| rw [abs_of_pos (scalarVariance_pos _)] | |
| exact scalarVariance_le_one _ | |
| have he : derivativeMatrix (fun y i => Real.tanh (F y i)) x-V*H = | |
| (derivativeMatrix (fun y i => Real.tanh (F y i)) x-V*derivativeMatrix F x)+ | |
| V*(derivativeMatrix F x-H) := by noncomm_ring | |
| change βderivativeMatrix (fun y i => Real.tanh (F y i)) x-V*Hββ€_ | |
| rw [he] | |
| apply (norm_add_le _ _).trans | |
| apply add_le_add (tanh_derivative_error hC hD) | |
| exact (SKGap.frobenius_mul_le_opNorm _ _).trans | |
| ((mul_le_mul_of_nonneg_right hV (norm_nonneg _)).trans (by simpa using hE)) | |
| end SKGapCutoff.Primary | |
| end | |
| end | |
| end OAI | |