Download data/lean/OAI/Probability/LogConcave/OraclePrograms/PairDistBounds.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 13.9 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/LogConcave/OraclePrograms/PairDistBounds.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/LogConcave/OraclePrograms/PairDistBounds.lean
-
curl -L -o PairDistBounds.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/LogConcave/OraclePrograms/PairDistBounds.lean
13.9 kB
| import Mathlib | |
| import OAI.Probability.LogConcave.OraclePrograms.CircuitParameters | |
| import OAI.Probability.LogConcave.OraclePrograms.MeanTreeBase | |
| import OAI.Probability.LogConcave.OraclePrograms.CalibratedMeanCircuit | |
| import OAI.Probability.LogConcave.Numerics.BaseVariationCenters | |
| import OAI.Probability.LogConcave.Numerics.EvalLipschitz | |
| namespace OAI | |
| section | |
| noncomputable section | |
| namespace LogConcaveSampling.OracleCompiler.CircuitParameters | |
| open MeanTree MeasureTheory Quadrature | |
| open scoped Classical NNReal | |
| variable (C : CircuitParameters) {d : β} | |
| lemma pair_dist_bounds (z w : Point d Γ Point d) : | |
| βz.1-w.1ββ€dist z w β§ βz.2-w.2ββ€dist z w := by | |
| change βz.1-w.1ββ€ max (dist z.1 w.1) (dist z.2 w.2) β§ | |
| βz.2-w.2ββ€ max (dist z.1 w.1) (dist z.2 w.2) | |
| simp only [dist_eq_norm] | |
| exact β¨le_max_left _ _,le_max_right _ _β© | |
| lemma meanTree_anchorVariation {r Ο : β} (hr : 0β€r) (x : Point d) (z w : Point d Γ Point d) : | |
| BaseVariation ((2*r+|Ο/2|)*dist z w) (x,z) (x,w) (C.meanTree r Ο) := by | |
| have hg := literalMean_geometry (d:=d) (r:=r) (Ο:=Ο) (N:=C.N) (nc:=C.nc) (Nc:=C.Nc) | |
| (by linarith [C.T_lower]) C.T_upper C.h_pos C.v_nonneg C.angle_bound C.meanEndpoint | |
| have hd := pair_dist_bounds z w | |
| apply baseVariation_of_centers | |
| Β· rw [C.meanTree_base] | |
| simp only [βsmul_sub,norm_smul,Real.norm_eq_abs] | |
| nlinarith [mul_le_mul_of_nonneg_left hd.2 (abs_nonneg (Ο/2)),mul_nonneg hr (dist_nonneg (x:=z) (y:=w))] | |
| Β· exact centers_mono _ (fun r' b hb => by | |
| have he := hb.variation hr C.T_upper.le (x,z) (x,w) | |
| simp only [sub_self,norm_zero,zero_add] at he | |
| nlinarith [mul_le_mul_of_nonneg_left (add_le_add hd.1 hd.2) hr, | |
| mul_nonneg (abs_nonneg (Ο/2)) (dist_nonneg (x:=z) (y:=w))]) hg.2 | |
| lemma sampleTree_anchorVariation {r Ξ· : β} (hr : 0β€r) (hΞ· : 0<Ξ·) (hΞ·1 : Ξ·β€1) | |
| (x z w : Point d) : | |
| BaseVariation ((r+|(sampleCorrelation Ξ·)β»ΒΉ|)*dist z w) (x,z) (x,w) | |
| (C.sampleTree r Ξ· hΞ· hΞ·1) := by | |
| have hp := sampleCorrelation_properties hΞ· hΞ·1 | |
| have hg := literalSample_geometry (d:=d) (r:=r) (N:=C.N) (Nat.succ_pos C.n) | |
| (by linarith [hp.1]) hp.2.1 C.h_pos (C.sampleEndpoint Ξ· hΞ· hΞ·1) | |
| apply baseVariation_of_centers | |
| Β· unfold sampleTree | |
| rw [hg.1] | |
| simp only [βsmul_sub,norm_smul,Real.norm_eq_abs,dist_eq_norm] | |
| nlinarith [mul_nonneg hr (norm_nonneg (z-w))] | |
| Β· exact centers_mono _ (fun r' b hb => by | |
| have he := hb.variation hr hp.2.1.le (x,z) (x,w) | |
| simp only [sub_self,norm_zero,zero_add,add_zero] at he | |
| rw [dist_eq_norm] | |
| nlinarith [mul_nonneg (abs_nonneg ((sampleCorrelation Ξ·)β»ΒΉ)) (norm_nonneg (z-w))]) hg.2 | |
| lemma meanTree_anchor_lipschitz {F : Point d β β} {lam : ββ₯0} (hF : Primitive F lam) | |
| {r Ο : β} (hr : 0<r) (hl : (lam:β)*r^2β€1/4) (x : Point d) : | |
| βK : ββ₯0,LipschitzWith K (fun z : Point d Γ Point d => (C.meanTree r Ο).eval F (x,z)) := by | |
| have hg := literalMean_geometry (d:=d) (r:=r) (Ο:=Ο) (N:=C.N) (nc:=C.nc) (Nc:=C.Nc) | |
| (by linarith [C.T_lower]) C.T_upper C.h_pos C.v_nonneg C.angle_bound C.meanEndpoint | |
| apply eval_exists_lipschitz hF (C.meanTree r Ο) (fun z => (x,z)) | |
| Β· rw [C.meanTree_base] | |
| exact β¨_,(lipschitzWith_smul (Ο/2)).comp LipschitzWith.prod_sndβ© | |
| Β· apply centers_mono _ (fun r' b hb => ?_) hg.2 | |
| have hr' := hb.radius_pos hr (by linarith [C.T_lower]) C.T_upper | |
| have hb' := hb.radius hr.le (by linarith [C.T_lower]) C.T_upper | |
| have hs := mul_le_mul_of_nonneg_left (pow_le_pow_leftβ hr'.le hb'.2 2) lam.coe_nonneg | |
| refine β¨hr',hs.trans hl,?_β© | |
| obtain β¨Ο,hΟ,ΞΈ,hΞΈ,he,rflβ© := hb | |
| exact β¨_,(LipschitzWith.const x).add ((lipschitzWith_smul (r*Ο)).comp | |
| (((lipschitzWith_smul (Real.cos ΞΈ)).comp LipschitzWith.prod_fst).add | |
| ((lipschitzWith_smul (Real.sin ΞΈ)).comp LipschitzWith.prod_snd)))β© | |
| lemma sampleTree_anchor_lipschitz {F : Point d β β} {lam : ββ₯0} (hF : Primitive F lam) | |
| {r Ξ· : β} (hr : 0<r) (hΞ· : 0<Ξ·) (hΞ·1 : Ξ·β€1) (hl : (lam:β)*r^2β€1/4) (x : Point d) : | |
| βK : ββ₯0,LipschitzWith K (fun z : Point d => (C.sampleTree r Ξ· hΞ· hΞ·1).eval F (x,z)) := by | |
| have hp := sampleCorrelation_properties hΞ· hΞ·1 | |
| have hg := literalSample_geometry (d:=d) (r:=r) (N:=C.N) (Nat.succ_pos C.n) | |
| (by linarith [hp.1]) hp.2.1 C.h_pos (C.sampleEndpoint Ξ· hΞ· hΞ·1) | |
| apply eval_exists_lipschitz hF (C.sampleTree r Ξ· hΞ· hΞ·1) (fun z => (x,z)) | |
| Β· unfold sampleTree | |
| rw [hg.1] | |
| exact β¨_,lipschitzWith_smul ((sampleCorrelation Ξ·)β»ΒΉ)β© | |
| Β· apply centers_mono _ (fun r' b hb => ?_) hg.2 | |
| have hr' := hb.radius_pos hr (by linarith [hp.1]) hp.2.1 | |
| have hb' := hb.radius hr.le (by linarith [hp.1]) hp.2.1 | |
| have hs := mul_le_mul_of_nonneg_left (pow_le_pow_leftβ hr'.le hb'.2 2) lam.coe_nonneg | |
| refine β¨hr',hs.trans hl,?_β© | |
| obtain β¨Ο,hΟ,ΞΈ,hΞΈ,he,rflβ© := hb | |
| exact β¨_,(LipschitzWith.const x).add ((lipschitzWith_smul (r*Ο)).comp | |
| ((lipschitzWith_smul (Real.cos ΞΈ)).add ((lipschitzWith_smul (Real.sin ΞΈ)).comp (LipschitzWith.const 0))))β© | |
| lemma meanCompiled_anchor_lipschitz {r Ο Lf Li : β} (hr : 0<r) (hΟ : 0<Ο) | |
| (hΟ : 0β€C.Ο) (hA : C.A=C.actualA) (hAf : C.Af=C.actualAf) | |
| (hLf : 0β€Lf) (hLi : 0β€Li) (hsmall : Li*C.meanCenterBudget r Οβ€1) | |
| (V : Point d β β) (P : Bool β β β β β Prop) (M : Bool β β β β β SeedProgram d) | |
| (hm : βr Ο,P true r Ο β βu v g,β(M true r Ο).program.run V (u,g)-(M true r Ο).program.run V (v,g)ββ€Lf*βu-vβ) | |
| (hmi : βr Ο,P false r Ο β βu v g,β(M false r Ο).program.run V (u,g)-(M false r Ο).program.run V (v,g)ββ€Li*βu-vβ) | |
| (n : β) (hready : RootShiftReady C.D (C.meanCenterBudget r Ο) C.Af | |
| (P true) (P false) (C.meanTree (d:=d) r Ο) n) (x : Point d) : | |
| let E := compileDeclaredRoot C.D (C.meanCenterBudget r Ο) C.Af | |
| (M true) (M false) (C.meanTree (d:=d) r Ο) n | |
| βK : β,0β€K β§ βz w g,βE.eval V (x,z) g-E.eval V (x,w) gββ€K*dist z w := by | |
| have hw := C.meanTree_actual_weights (d:=d) hr hΟ hΟ | |
| rw [βhAf,βhA] at hw | |
| have hAf0 : 0β€C.Af := by rw [hAf]; exact C.actualAf_pos.le | |
| let b := 2*r+|Ο/2| | |
| refine β¨C.Af*Lf*(depth (C.meanTree (d:=d) r Ο):β)*b+b,by dsimp [b]; positivity,?_β© | |
| intro z w g | |
| have hv := C.meanTree_anchorVariation (Ο:=Ο) hr.le x z w | |
| have hb : βbase (C.meanTree r Ο) (x,z)-base (C.meanTree r Ο) (x,w)ββ€b*dist z w := by | |
| generalize C.meanTree (d:=d) r Ο=E at hv β’ | |
| cases E | |
| exact hv.1 | |
| have he := compileDeclaredRoot_variation hLf hLi (show 0β€b*dist z w by dsimp [b]; positivity) | |
| hsmall V P M hm hmi (C.meanTree r Ο) n (x,z) (x,w) hv hb hw.1 hw.2 hready g | |
| convert he using 1 | |
| dsimp [b] | |
| ring | |
| lemma sampleCompiled_anchor_lipschitz {r Ξ· Lf Li : β} (hr : 0<r) (hΞ· : 0<Ξ·) (hΞ·1 : Ξ·β€1) | |
| (hA : C.A=C.actualA) (hAf : C.Af=C.actualAf) | |
| (hLf : 0β€Lf) (hLi : 0β€Li) (hsmall : Li*C.sampleCenterBudget rβ€1) | |
| (V : Point d β β) (P : Bool β β β β β Prop) (M : Bool β β β β β SeedProgram d) | |
| (hm : βr Ο,P true r Ο β βu v g,β(M true r Ο).program.run V (u,g)-(M true r Ο).program.run V (v,g)ββ€Lf*βu-vβ) | |
| (hmi : βr Ο,P false r Ο β βu v g,β(M false r Ο).program.run V (u,g)-(M false r Ο).program.run V (v,g)ββ€Li*βu-vβ) | |
| (n : β) (hready : RootShiftReady C.D (C.sampleCenterBudget r) (C.sampleFinalBudget r) | |
| (P true) (P false) (C.sampleTree (d:=d) r Ξ· hΞ· hΞ·1) n) (x : Point d) : | |
| let E := compileDeclaredRoot C.D (C.sampleCenterBudget r) (C.sampleFinalBudget r) | |
| (M true) (M false) (C.sampleTree (d:=d) r Ξ· hΞ· hΞ·1) n | |
| βK : β,0β€K β§ βz w g,βE.eval V (x,z) g-E.eval V (x,w) gββ€K*dist z w := by | |
| have hw := C.sampleTree_actual_weights (d:=d) hr hΞ· hΞ·1 | |
| rw [βhAf,βhA] at hw | |
| have hAf0 : 0β€C.sampleFinalBudget r := by unfold sampleFinalBudget; rw [hAf]; positivity [C.actualAf_pos] | |
| let b := r+|(sampleCorrelation Ξ·)β»ΒΉ| | |
| refine β¨C.sampleFinalBudget r*Lf*(depth (C.sampleTree (d:=d) r Ξ· hΞ· hΞ·1):β)*b+b,by dsimp [b]; positivity,?_β© | |
| intro z w g | |
| have hv := C.sampleTree_anchorVariation hr.le hΞ· hΞ·1 x z w | |
| have hb : βbase (C.sampleTree r Ξ· hΞ· hΞ·1) (x,z)-base (C.sampleTree r Ξ· hΞ· hΞ·1) (x,w)ββ€b*dist z w := by | |
| generalize C.sampleTree (d:=d) r Ξ· hΞ· hΞ·1=E at hv β’ | |
| cases E | |
| exact hv.1 | |
| have he := compileDeclaredRoot_variation hLf hLi (show 0β€b*dist z w by dsimp [b]; positivity) | |
| hsmall V P M hm hmi (C.sampleTree r Ξ· hΞ· hΞ·1) n (x,z) (x,w) hv hb hw.1 hw.2 hready g | |
| convert he using 1 <;> (try simp only [sampleFinalBudget]) | |
| dsimp [b] | |
| ring | |
| end LogConcaveSampling.OracleCompiler.CircuitParameters | |
| end | |
| end | |
| section | |
| noncomputable section | |
| namespace LogConcaveSampling.OracleCompiler.CircuitParameters | |
| open MeasureTheory ProbabilityTheory MeanTree Quadrature Function | |
| open scoped Classical NNReal | |
| variable (C : CircuitParameters) {d : β} | |
| lemma meanTree_eval {F : Point d β β} {lam : ββ₯0} (hF : Primitive F lam) | |
| (r Ο : β) (x : Point d) (y : Point d Γ Point d) : | |
| (C.meanTree r Ο).eval F (x,y)= | |
| centeringMeanCircuit F x r C.T C.h C.Ο (Ο/2) C.n C.m C.N C.nc C.Nc C.meanEndpoint | |
| ((productPointEquiv d d).symm y) := by | |
| unfold meanTree literalMean | |
| rw [eval_meanCircuit hF (by linarith [C.T_lower]) C.T_upper C.h_pos] | |
| simp only [eval_anchor] | |
| lemma sampleTree_eval {F : Point d β β} {lam : ββ₯0} (hF : Primitive F lam) | |
| (r Ξ· : β) (hΞ· : 0<Ξ·) (hΞ·1 : Ξ·β€1) (x Y : Point d) : | |
| (C.sampleTree r Ξ· hΞ· hΞ·1).eval F (x,Y)= | |
| sampleMeanCircuit F x r (sampleCorrelation Ξ·) C.h (C.n+1) C.N (C.sampleEndpoint Ξ· hΞ· hΞ·1) Y := by | |
| unfold sampleTree literalSample | |
| rw [eval_scale,eval_forward hF (Nat.succ_pos C.n) | |
| (by linarith [(sampleCorrelation_properties hΞ· hΞ·1).1]) | |
| (sampleCorrelation_properties hΞ· hΞ·1).2.1 C.h_pos] | |
| simp only [eval_anchor,sampleMeanCircuit] | |
| theorem meanTree_numerical {F : Point d β β} {lam : ββ₯0} (hF : Primitive F lam) | |
| (x : Point d) {r Ο err : β} (hr : 0<r) (hl : (lam:β)*r^2β€1/4) | |
| (hm : C.m=C.n) (hnc : C.nc=C.n) (hNc : C.Nc=C.N) | |
| (hcert : CalibratedMeanCircuit (r:=r) (T:=C.T) (h:=C.h) (Ο:=C.Ο) (s:=Ο/2) | |
| hF x hr (by linarith : (lam:β)*r^2β€1/2) (by linarith [C.T_lower]) C.T_upper | |
| C.h_pos C.n C.N err) : | |
| βw : Point d Γ Point d β Point d,Measurable w β§ | |
| ((interpolationLaw F x r C.T).prod (stdGaussian (Point d))).map w= | |
| (stdGaussian (Point d)).map (fun z => primitiveExpectedField F x r+(Ο/2) β’ z) β§ | |
| Integrable (fun z => β(C.meanTree r Ο).eval F (x,z)-w zβ^2) | |
| ((interpolationLaw F x r C.T).prod (stdGaussian (Point d))) β§ | |
| (β«z,β(C.meanTree r Ο).eval F (x,z)-w zβ^2 | |
| β(interpolationLaw F x r C.T).prod (stdGaussian (Point d)))β€ | |
| ((Ο/2)*circuitD F x)^2*err := by | |
| obtain β¨X,hsi,hsb,hw,hlaw,hi,hnumβ© := hcert | |
| let wβ := stationaryMeanTarget hF x hr (by linarith : (lam:β)*r^2β€1/2) | |
| (by linarith [C.T_lower] : 0β€C.T) C.T_upper X | |
| let w : Point d Γ Point d β Point d := fun z => wβ ((productPointEquiv d d).symm z) | |
| have hw' : Measurable w := hw.comp (productPointEquiv d d).symm.continuous.measurable | |
| have hjoint := centering_joint_law hF x hr.le (by linarith : (lam:β)*r^2β€1/2) | |
| (by linarith [C.T_lower]) C.T_upper | |
| obtain β¨K,hKβ© := C.meanTree_anchor_lipschitz hF hr hl x | |
| have hg : Measurable (fun z => (C.meanTree r Ο).eval F (x,z)) := hK.continuous.measurable | |
| have hid : βy : Point (d+d), | |
| (C.meanTree r Ο).eval F (x,productPointEquiv d d y)-w (productPointEquiv d d y)= | |
| centeringMeanCircuit F x r C.T C.h C.Ο (Ο/2) C.n C.n C.N C.n C.N C.meanEndpoint y-wβ y := by | |
| intro y | |
| rw [C.meanTree_eval hF] | |
| simp only [hm,hnc,hNc,w,ContinuousLinearEquiv.symm_apply_apply] | |
| refine β¨w,hw',?_,?_,?_β© | |
| Β· rw [βhjoint,Measure.map_map hw' (productPointEquiv d d).continuous.measurable] | |
| simpa only [comp_def,w,ContinuousLinearEquiv.symm_apply_apply] using hlaw | |
| Β· rw [βhjoint] | |
| apply (integrable_map_measure (by fun_prop) (productPointEquiv d d).continuous.measurable.aemeasurable).mpr | |
| simpa only [hid,comp_def,meanEndpoint,wβ] using hi | |
| Β· rw [βhjoint,integral_map (productPointEquiv d d).continuous.measurable.aemeasurable (by fun_prop)] | |
| simpa only [hid,meanEndpoint,wβ] using hnum | |
| lemma meanTree_numerical_noisy {F : Point d β β} {lam : ββ₯0} (hF : Primitive F lam) | |
| (x : Point d) {r Ο err : β} (hr : 0<r) (hl : (lam:β)*r^2β€1/4) | |
| (hm : C.m=C.n) (hnc : C.nc=C.n) (hNc : C.Nc=C.N) | |
| (hcert : CalibratedMeanCircuit (r:=r) (T:=C.T) (h:=C.h) (Ο:=C.Ο) (s:=Ο/2) | |
| hF x hr (by linarith : (lam:β)*r^2β€1/2) (by linarith [C.T_lower]) C.T_upper | |
| C.h_pos C.n C.N err) : | |
| βw : Point d Γ Point d β Point d,Measurable w β§ | |
| (((interpolationLaw F x r C.T).prod (stdGaussian (Point d))).prod (stdGaussian (Point d))).map | |
| (fun z => w z.1+(Real.sqrt 3*Ο/2) β’ z.2)= | |
| (stdGaussian (Point d)).map (fun z => primitiveExpectedField F x r+Ο β’ z) β§ | |
| Integrable (fun z => β(C.meanTree r Ο).eval F (x,z)-w zβ^2) | |
| ((interpolationLaw F x r C.T).prod (stdGaussian (Point d))) β§ | |
| (β«z,β(C.meanTree r Ο).eval F (x,z)-w zβ^2 | |
| β(interpolationLaw F x r C.T).prod (stdGaussian (Point d)))β€ | |
| ((Ο/2)*circuitD F x)^2*err := by | |
| obtain β¨w,hw,hlaw,hi,hnumβ© := C.meanTree_numerical hF x hr hl hm hnc hNc hcert | |
| let := interpolationLaw_probability hF x hr.le (by linarith : (lam:β)*r^2<1) C.T | |
| refine β¨w,hw,?_,hi,hnumβ© | |
| apply law_add_gaussian _ w hw (primitiveExpectedField F x r) (Ο/2) (Real.sqrt 3*Ο/2) Ο _ hlaw | |
| rw [div_pow,div_pow,mul_pow,Real.sq_sqrt (by norm_num : (0:β)β€3)] | |
| ring | |
| end LogConcaveSampling.OracleCompiler.CircuitParameters | |
| end | |
| end | |
| end OAI | |