Download data/lean/OAI/Probability/Perceptron/Control/StepControlTail.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 13.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Perceptron/Control/StepControlTail.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/Perceptron/Control/StepControlTail.lean
-
curl -L -o StepControlTail.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Perceptron/Control/StepControlTail.lean
13.7 kB
| import Mathlib | |
| import OAI.Probability.Perceptron.Control.StepControl | |
| namespace OAI | |
| noncomputable section | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction | |
| namespace SphericalPerceptronFreeEnergy | |
| def linearStepIntervals : (n : β) β (Fin (n+1)ββ) β (Fin (n+1)ββ) β | |
| (Fin nβββ₯0) β List HeatIntervalParam | |
| | 0,_,_,_ => [] | |
| | n+1,q,r,d => | |
| { duration := fun t => (1-t)*(q 1-q 0)+t*(r 1-r 0) | |
| rate := (r 1-q 1)-(r 0-q 0) | |
| coefficient := d 0 } :: | |
| linearStepIntervals n (fun i => q i.succ) (fun i => r i.succ) (fun i => d i.succ) | |
| def stepBoundaryWeights : (n : β) β (Fin (n+1)ββ) β (Fin nβββ₯0) β List β | |
| | 0,_,_ => [] | |
| | 1,_,_ => [] | |
| | n+2,v,d => ((d 1:β)-(d 0:β))*v 1 :: | |
| stepBoundaryWeights (n+1) (fun i => v i.succ) (fun i => d i.succ) | |
| lemma linearStepIntervals_start (g : Jet3) (n : β) | |
| (q r : Fin (n+1)βTime) (d : Fin nβββ₯0) : | |
| parametricHeatJet g (linearStepIntervals n (fun i => q i) (fun i => r i) d) 0= | |
| finiteStepControlJet g n q d := by | |
| induction n with | |
| | zero => rfl | |
| | succ n ih => | |
| simp only [linearStepIntervals,parametricHeatJet,finiteStepControlJet, | |
| sub_zero,one_mul,zero_mul,add_zero,timeSpan] | |
| rw [ih] | |
| lemma linearStepIntervals_end (g : Jet3) (n : β) | |
| (q r : Fin (n+1)βTime) (d : Fin nβββ₯0) : | |
| parametricHeatJet g (linearStepIntervals n (fun i => q i) (fun i => r i) d) 1= | |
| finiteStepControlJet g n r d := by | |
| induction n with | |
| | zero => rfl | |
| | succ n ih => | |
| simp only [linearStepIntervals,parametricHeatJet,finiteStepControlJet, | |
| sub_self,zero_mul,one_mul,zero_add,timeSpan] | |
| rw [ih] | |
| lemma linearStepIntervals_boundary (g : Jet3) (ΞΈ : β) (n : β) | |
| (q r : Fin (n+1)ββ) (d : Fin nβββ₯0) : | |
| (heatBoundaryTerms g ΞΈ (linearStepIntervals n q r d) (r 0-q 0)).map Prod.fst= | |
| stepBoundaryWeights n (fun i => r i-q i) d := by | |
| induction n with | |
| | zero => rfl | |
| | succ n ih => | |
| cases n with | |
| | zero => rfl | |
| | succ n => | |
| simp only [linearStepIntervals,heatBoundaryTerms,List.map_cons,List.map_map, | |
| Function.comp_def,stepBoundaryWeights] | |
| have he : r 0-q 0+((r 1-q 1)-(r 0-q 0))=r 1-q 1 := by ring | |
| rw [he] | |
| congr 1 | |
| exact ih (fun i => q i.succ) (fun i => r i.succ) (fun i => d i.succ) | |
| lemma linearStepIntervals_rate (n : β) (q r : Fin (n+1)ββ) (d : Fin nβββ₯0) : | |
| ((linearStepIntervals n q r d).map HeatIntervalParam.rate).sum= | |
| (r (Fin.last n)-q (Fin.last n))-(r 0-q 0) := by | |
| induction n with | |
| | zero => simp [linearStepIntervals] | |
| | succ n ih => | |
| simp only [linearStepIntervals,List.map_cons,List.sum_cons] | |
| rw [ih] | |
| simp only [Fin.succ_last,Fin.succ_zero_eq_one] | |
| ring | |
| lemma linearStepIntervals_continuous (n : β) (q r : Fin (n+1)ββ) (d : Fin nβββ₯0) : | |
| β pβlinearStepIntervals n q r d, Continuous p.duration := by | |
| induction n with | |
| | zero => simp [linearStepIntervals] | |
| | succ n ih => | |
| intro p hp | |
| rcases List.mem_cons.mp hp with rfl | hp | |
| Β· exact ((continuous_const.sub continuous_id).mul continuous_const).add | |
| (continuous_id.mul continuous_const) | |
| Β· exact ih _ _ _ p hp | |
| lemma linearStepIntervals_deriv (n : β) (q r : Fin (n+1)ββ) (d : Fin nβββ₯0) | |
| (hq : StrictMono q) (hr : StrictMono r) (ΞΈ : β) (hΞΈ : ΞΈβIoo (0:β) 1) : | |
| β pβlinearStepIntervals n q r d, HasDerivAt p.duration p.rate ΞΈ β§ 0<p.duration ΞΈ := by | |
| induction n with | |
| | zero => simp [linearStepIntervals] | |
| | succ n ih => | |
| intro p hp | |
| rcases List.mem_cons.mp hp with rfl | hp | |
| Β· constructor | |
| Β· convert! (((hasDerivAt_const ΞΈ 1).sub (hasDerivAt_id ΞΈ)).mul_const (q 1-q 0)).add | |
| ((hasDerivAt_id ΞΈ).mul_const (r 1-r 0)) using 1 | |
| dsimp | |
| ring | |
| Β· exact add_pos (mul_pos (sub_pos.mpr hΞΈ.2) (sub_pos.mpr (hq (by simp)))) | |
| (mul_pos hΞΈ.1 (sub_pos.mpr (hr (by simp)))) | |
| Β· exact ih _ _ _ (hq.comp Fin.strictMono_succ) (hr.comp Fin.strictMono_succ) p hp | |
| lemma finiteStepControlJet_tail_order_strict (g : Jet3) (n : β) | |
| (q r : Fin (n+1)βTime) (d : Fin nβββ₯0) (hq : StrictMono q) (hr : StrictMono r) | |
| (h0 : q 0=r 0) (h1 : q (Fin.last n)=r (Fin.last n)) | |
| (ht : β zs : List β, zs.IsSuffix (stepBoundaryWeights n (fun i => (r i:β)-q i) d) β | |
| 0β€zs.sum) (x : β) : | |
| (finiteStepControlJet g n r d).f xβ€(finiteStepControlJet g n q d).f x := by | |
| rw [β linearStepIntervals_start g n q r d,β linearStepIntervals_end g n q r d] | |
| apply parametricHeatJet_tail_order | |
| Β· exact linearStepIntervals_continuous n _ _ d | |
| Β· intro ΞΈ hΞΈ | |
| exact linearStepIntervals_deriv n _ _ d ((Subtype.strictMono_coe _).comp hq) | |
| ((Subtype.strictMono_coe _).comp hr) ΞΈ hΞΈ | |
| Β· rw [linearStepIntervals_rate,h0,h1] | |
| ring | |
| Β· intro ΞΈ _ zs hz | |
| apply ht | |
| have hb := linearStepIntervals_boundary g ΞΈ n (fun i => (q i:β)) (fun i => (r i:β)) d | |
| rw [h0,sub_self] at hb | |
| rw [β hb] | |
| exact hz.map _ | |
| def uniformControlNodes (n : β) (i : Fin (n+1)) : Time := | |
| β¨(i:β)/(n+1),div_nonneg (Nat.cast_nonneg _) (by positivity), | |
| (div_le_one (by positivity : (0:β)<n+1)).mpr (by exact_mod_cast i.isLt.le)β© | |
| lemma uniformControlNodes_strict (n : β) : StrictMono (uniformControlNodes n) := by | |
| intro i j hij | |
| change (i:β)/(n+1)<(j:β)/(n+1) | |
| exact div_lt_div_of_pos_right (by exact_mod_cast hij) (by positivity) | |
| def blendControlNodes {n : β} (q e : Fin (n+1)βTime) (t : Time) (i : Fin (n+1)) : Time := | |
| β¨(1-(t:β))*(q i:β)+(t:β)*(e i:β), | |
| add_nonneg (mul_nonneg (sub_nonneg.mpr t.2.2) (q i).2.1) (mul_nonneg t.2.1 (e i).2.1),by | |
| nlinarith [mul_nonneg (sub_nonneg.mpr t.2.2) (sub_nonneg.mpr (q i).2.2), | |
| mul_nonneg t.2.1 (sub_nonneg.mpr (e i).2.2)]β© | |
| lemma blendControlNodes_strict {n : β} (q e : Fin (n+1)βTime) (t : Time) | |
| (hq : Monotone q) (he : StrictMono e) (ht : 0<(t:β)) : StrictMono (blendControlNodes q e t) := by | |
| intro i j hij | |
| change (1-(t:β))*(q i:β)+(t:β)*(e i:β)<(1-(t:β))*(q j:β)+(t:β)*(e j:β) | |
| exact add_lt_add_of_le_of_lt (mul_le_mul_of_nonneg_left (hq hij.le) (sub_nonneg.mpr t.2.2)) | |
| (mul_lt_mul_of_pos_left (he hij) ht) | |
| lemma linearStepIntervals_eval (g : Jet3) (n : β) (q e : Fin (n+1)βTime) | |
| (d : Fin nβββ₯0) (t : Time) : | |
| parametricHeatJet g (linearStepIntervals n (fun i => q i) (fun i => e i) d) t= | |
| finiteStepControlJet g n (blendControlNodes q e t) d := by | |
| induction n with | |
| | zero => rfl | |
| | succ n ih => | |
| simp only [linearStepIntervals,parametricHeatJet,finiteStepControlJet] | |
| rw [ih] | |
| congr 1 | |
| unfold timeSpan blendControlNodes | |
| congr 1 | |
| ring | |
| lemma stepBoundaryWeights_scale (n : β) (v : Fin (n+1)ββ) (d : Fin nβββ₯0) (c : β) : | |
| stepBoundaryWeights n (fun i => c*v i) d=(stepBoundaryWeights n v d).map (c*Β·) := by | |
| induction n with | |
| | zero => rfl | |
| | succ n ih => | |
| cases n with | |
| | zero => rfl | |
| | succ n => | |
| simp only [stepBoundaryWeights,List.map_cons] | |
| rw [ih] | |
| congr 1 | |
| ring | |
| lemma stepBoundaryWeights_blend {n : β} (q r e : Fin (n+1)βTime) (d : Fin nβββ₯0) (t : Time) : | |
| stepBoundaryWeights n (fun i => (blendControlNodes r e t i:β)-blendControlNodes q e t i) d= | |
| (stepBoundaryWeights n (fun i => (r i:β)-q i) d).map ((1-(t:β))*Β·) := by | |
| rw [β stepBoundaryWeights_scale] | |
| congr 1 | |
| funext i | |
| simp only [blendControlNodes] | |
| ring | |
| theorem finiteStepControlJet_tail_order (g : Jet3) (n : β) | |
| (q r : Fin (n+1)βTime) (d : Fin nβββ₯0) (hq : Monotone q) (hr : Monotone r) | |
| (h0 : q 0=r 0) (h1 : q (Fin.last n)=r (Fin.last n)) | |
| (ht : β zs : List β, zs.IsSuffix (stepBoundaryWeights n (fun i => (r i:β)-q i) d) β | |
| 0β€zs.sum) (x : β) : | |
| (finiteStepControlJet g n r d).f xβ€(finiteStepControlJet g n q d).f x := by | |
| let e := uniformControlNodes n | |
| have he : StrictMono e := uniformControlNodes_strict n | |
| let F := fun s : β => (parametricHeatJet g | |
| (linearStepIntervals n (fun i => q i) (fun i => e i) d) s).f x | |
| let G := fun s : β => (parametricHeatJet g | |
| (linearStepIntervals n (fun i => r i) (fun i => e i) d) s).f x | |
| have hF : ContinuousAt F 0 := | |
| (BoundedContinuousFunction.evalCLM β x).continuous.continuousAt.comp | |
| (parametricHeatJet_continuousAt _ _ _ (fun p hp => | |
| (linearStepIntervals_continuous n _ _ d p hp).continuousAt)) | |
| have hG : ContinuousAt G 0 := | |
| (BoundedContinuousFunction.evalCLM β x).continuous.continuousAt.comp | |
| (parametricHeatJet_continuousAt _ _ _ (fun p hp => | |
| (linearStepIntervals_continuous n _ _ d p hp).continuousAt)) | |
| have hi (s : β) (hs : sβIoo (0:β) 1) : G sβ€F s := by | |
| let t : Time := β¨s,hs.1.le,hs.2.leβ© | |
| change (parametricHeatJet g _ (t:β)).f xβ€(parametricHeatJet g _ (t:β)).f x | |
| rw [linearStepIntervals_eval,linearStepIntervals_eval] | |
| apply finiteStepControlJet_tail_order_strict g n _ _ d | |
| (blendControlNodes_strict q e t hq he hs.1) (blendControlNodes_strict r e t hr he hs.1) | |
| Β· apply Subtype.ext | |
| simp only [blendControlNodes,h0] | |
| Β· apply Subtype.ext | |
| simp only [blendControlNodes,h1] | |
| Β· intro zs hz | |
| rw [stepBoundaryWeights_blend] at hz | |
| obtain β¨ys,hy,rflβ© := List.suffix_map_iff.mp hz | |
| rw [List.sum_map_mul_left] | |
| simpa using mul_nonneg (sub_nonneg.mpr hs.2.le) (ht ys hy) | |
| let : NeBot (π[Ioo (0:β) 1] 0) := left_nhdsWithin_Ioo_neBot zero_lt_one | |
| have hlim : G 0β€F 0 := le_of_tendsto_of_tendsto hG.continuousWithinAt.tendsto | |
| hF.continuousWithinAt.tendsto (eventually_mem_nhdsWithin.mono fun s hs => hi s hs) | |
| simpa only [F,G,linearStepIntervals_start] using hlim | |
| lemma stepBoundaryWeights_ofFn (n : β) (v : Fin (n+2)ββ) (d : Fin (n+1)βββ₯0) : | |
| stepBoundaryWeights (n+1) v d= | |
| List.ofFn (fun i : Fin n => ((d i.succ:β)-(d i.castSucc:β))*v i.succ.castSucc) := by | |
| induction n with | |
| | zero => simp [stepBoundaryWeights] | |
| | succ n ih => | |
| rw [stepBoundaryWeights,List.ofFn_succ,ih] | |
| rfl | |
| lemma weightedControlCoefficient_gap (n : β) (w : Fin (n+2)ββ) (hw : β i, 0β€w i) (i : Fin n) : | |
| (weightedControlCoefficient (n+1) w hw i.succ:β)- | |
| weightedControlCoefficient (n+1) w hw i.castSucc=w i.succ.castSucc := by | |
| have he (j : Fin (n+2)) : | |
| (if j β€ i.succ.castSucc then w j else 0)= | |
| (if j β€ i.castSucc.castSucc then w j else 0)+(if j=i.succ.castSucc then w j else 0) := by | |
| by_cases hj : j=i.succ.castSucc | |
| Β· subst j | |
| have hn : Β¬i.succ.castSucc β€ i.castSucc.castSucc := by | |
| simp only [Fin.le_iff_val_le_val,Fin.val_castSucc,Fin.val_succ] | |
| omega | |
| simp only [le_refl,ite_true,hn,ite_false,zero_add] | |
| Β· have hle : j β€ i.succ.castSucc β j β€ i.castSucc.castSucc := by | |
| simp only [Fin.le_iff_val_le_val,Fin.val_castSucc,Fin.val_succ] | |
| have hne : j.valβ i.val+1 := by simpa [Fin.ext_iff] using hj | |
| omega | |
| simp only [hj,hle,ite_false,add_zero] | |
| change (β j, if j β€ i.succ.castSucc then w j else 0)- | |
| (β j, if j β€ i.castSucc.castSucc then w j else 0)=_ | |
| simp_rw [he] | |
| rw [Finset.sum_add_distrib] | |
| simp | |
| lemma paddedControl_boundaryWeights (n : β) (w : Fin (n+1)ββ) (hw : β i, 0β€w i) | |
| (q r : Fin (n+1)βTime) : | |
| stepBoundaryWeights (n+2) | |
| (fun i => (paddedControlNodes r i:β)-paddedControlNodes q i) | |
| (weightedControlCoefficient (n+2) (paddedControlWeights w) (paddedControlWeights_nonneg w hw))= | |
| List.ofFn (fun i => w i*((r i:β)-q i)) := by | |
| rw [stepBoundaryWeights_ofFn] | |
| congr 1 | |
| funext i | |
| rw [weightedControlCoefficient_gap] | |
| simp [paddedControlWeights,paddedControlNodes,Fin.castSucc_succ] | |
| lemma listOfFn_suffix_sum_nonneg (n : β) (v : Fin nββ) | |
| (ht : β k : β, 0β€β i, if k β€ i.val then v i else 0) : | |
| β zs : List β, zs.IsSuffix (List.ofFn v) β 0β€zs.sum := by | |
| induction n with | |
| | zero => | |
| intro zs hz | |
| simpa using (show zs=[] from by simpa using hz) βΈ (le_refl (0:β)) | |
| | succ n ih => | |
| intro zs hz | |
| rw [List.ofFn_succ] at hz | |
| obtain β¨ys,hysβ© := hz | |
| cases ys with | |
| | nil => | |
| have he : zs=v 0 ::List.ofFn (fun i => v i.succ) := by simpa using hys | |
| rw [he,β List.ofFn_succ,List.sum_ofFn] | |
| simpa using ht 0 | |
| | cons a ys => | |
| have he : ys++zs=List.ofFn (fun i => v i.succ) := (List.cons.inj hys).2 | |
| apply ih (fun i => v i.succ) ?_ zs β¨ys,heβ© | |
| intro k | |
| have H := ht (k+1) | |
| rw [Fin.sum_univ_succ] at H | |
| simpa only [Fin.val_zero,(show Β¬k+1β€0 by omega),ite_false,zero_add,Fin.val_succ, | |
| Nat.add_le_add_iff_right] using H | |
| theorem sourceWeightedTrial_control_tail_order (n : β) (w : Fin (n+1)ββ) | |
| (q r : Fin (n+1)βTime) (hw : β i, 0β€w i) (hw1 : β i, w i=1) | |
| (hq : Monotone q) (hr : Monotone r) | |
| (ht : β k : β, 0β€β i, if k β€ i.val then w i*((r i:β)-q i) else 0) | |
| (g : Jet3) (P : Measure BrownianPath) [IsProbabilityMeasure P] | |
| (hB : IsBrownianReal brownianEval P) : | |
| controlValue P g.f (weightedStepTrial w r hw hw1)β€ | |
| controlValue P g.f (weightedStepTrial w q hw hw1) := by | |
| rw [sourceWeightedTrial_controlValue n w r hw hw1 hr g P hB, | |
| sourceWeightedTrial_controlValue n w q hw hw1 hq g P hB] | |
| apply finiteStepControlJet_tail_order g (n+2) _ _ _ (paddedControlNodes_mono q hq) | |
| (paddedControlNodes_mono r hr) | |
| Β· simp [paddedControlNodes] | |
| Β· simp [paddedControlNodes] | |
| Β· rw [paddedControl_boundaryWeights n w hw q r] | |
| exact listOfFn_suffix_sum_nonneg (n+1) _ ht | |
| end SphericalPerceptronFreeEnergy | |
| end | |
| end OAI | |