Download data/lean/OAI/Probability/GaussianPropeller/Taylor.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 4.9 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/GaussianPropeller/Taylor.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/GaussianPropeller/Taylor.lean
-
curl -L -o Taylor.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/GaussianPropeller/Taylor.lean
4.9 kB
| import OAI.Probability.GaussianPropeller.Mills | |
| namespace OAI | |
| open MeasureTheory ProbabilityTheory | |
| open scoped ENNReal | |
| open scoped RealInnerProductSpace | |
| open scoped RealInnerProductSpace | |
| open MeasureTheory ProbabilityTheory Set | |
| open scoped ENNReal RealInnerProductSpace | |
| open Filter | |
| open scoped Topology | |
| open MeasureTheory ProbabilityTheory Set Filter | |
| open scoped Topology | |
| open scoped RealInnerProductSpace | |
| open Set Filter | |
| open scoped Topology RealInnerProductSpace | |
| open scoped NNReal | |
| open Set Filter | |
| open scoped Topology RealInnerProductSpace NNReal | |
| open MeasureTheory ProbabilityTheory Set Filter | |
| open scoped Topology RealInnerProductSpace | |
| open MeasureTheory Set Filter | |
| open scoped Topology BigOperators | |
| namespace GaussianPropeller.Taylor | |
| noncomputable def E (n : β) (x : β) : β := | |
| β k β Finset.range (n+1), (-1:β)^k*x^k/(Nat.factorial k) | |
| noncomputable def J (n : β) (x : β) : β := | |
| β k β Finset.range (n+1), (-1:β)^k*x^(2*k+1)/((2:β)^k*(Nat.factorial k)*(2*k+1)) | |
| lemma E_zero (n : β) : E n 0 = 1 := by | |
| unfold E | |
| rw [Finset.sum_eq_single 0] | |
| Β· norm_num | |
| Β· intro k hk hk0 | |
| simp [zero_pow hk0] | |
| Β· simp | |
| lemma exp_remainder {x : β} (hx : 0 < x) (n : β) : | |
| β c : β, Real.exp (-x)-E n x = | |
| (-1:β)^(n+1)*Real.exp (-c)*x^(n+1)/(Nat.factorial (n+1)) := by | |
| obtain β¨c,hc,hβ© := taylor_mean_remainder_lagrange_iteratedDeriv | |
| (f := fun t : β => Real.exp ((-1)*t)) (xβ := 0) (x := x) (n := n) hx.ne | |
| (by fun_prop) | |
| refine β¨c, ?_β© | |
| have he : taylorWithinEval (fun t : β => Real.exp ((-1)*t)) n (uIcc 0 x) 0 x = E n x := by | |
| rw [taylor_within_apply] | |
| apply Finset.sum_congr rfl | |
| intro k hk | |
| rw [iteratedDerivWithin_eq_iteratedDeriv (uniqueDiffOn_uIcc hx.ne) | |
| (by fun_prop) (by simp), iteratedDeriv_exp_const_mul] | |
| simp only [mul_zero, Real.exp_zero, mul_one, sub_zero, smul_eq_mul] | |
| ring | |
| rw [he, iteratedDeriv_exp_const_mul] at h | |
| simpa only [neg_one_mul, sub_zero, mul_assoc] using h | |
| lemma exp_le_E_even (n : β) {x : β} (hx : 0 β€ x) : Real.exp (-x) β€ E (2*n) x := by | |
| obtain rfl | hp := hx.eq_or_lt | |
| Β· simp [E_zero] | |
| obtain β¨c,hβ© := exp_remainder hp (2*n) | |
| have hn : (-1:β)^(2*n+1) = -1 := by rw [pow_add, pow_mul]; norm_num | |
| rw [hn] at h | |
| have : (-1:β)*Real.exp (-c)*x^(2*n+1)/(Nat.factorial (2*n+1)) β€ 0 := by | |
| apply div_nonpos_of_nonpos_of_nonneg | |
| Β· exact mul_nonpos_of_nonpos_of_nonneg (by linarith [Real.exp_pos (-c)]) (pow_nonneg hx _) | |
| Β· positivity | |
| linarith only [h,this] | |
| lemma E_odd_le_exp (n : β) {x : β} (hx : 0 β€ x) : E (2*n+1) x β€ Real.exp (-x) := by | |
| obtain rfl | hp := hx.eq_or_lt | |
| Β· simp [E_zero] | |
| obtain β¨c,hβ© := exp_remainder hp (2*n+1) | |
| have hn : (-1:β)^(2*n+1+1) = 1 := by rw [show 2*n+1+1=2*(n+1) by omega, pow_mul]; norm_num | |
| rw [hn] at h | |
| have : 0 β€ (1:β)*Real.exp (-c)*x^(2*n+1+1)/(Nat.factorial (2*n+1+1)) := by positivity | |
| linarith only [h,this] | |
| lemma hasDerivAt_J (n : β) (x : β) : HasDerivAt (J n) (E n (x^2/2)) x := by | |
| unfold J E | |
| convert! HasDerivAt.sum (u := Finset.range (n+1)) (fun k hk => | |
| (((hasDerivAt_pow (2*k+1) x).const_mul ((-1:β)^k)).div_const | |
| ((2:β)^k*(Nat.factorial k)*(2*k+1)))) using 1 | |
| Β· funext y | |
| simp only [Finset.sum_apply] | |
| Β· apply Finset.sum_congr rfl | |
| intro k hk | |
| have hfact : (Nat.factorial k : β) β 0 := by positivity | |
| have hk' : (2*(k:β)+1) β 0 := by positivity | |
| simp only [Nat.add_sub_cancel, Nat.cast_add, Nat.cast_mul, Nat.cast_ofNat, Nat.cast_one] | |
| rw [div_pow, pow_mul] | |
| field_simp | |
| lemma J_zero (n : β) : J n 0 = 0 := by simp [J] | |
| lemma integral_E (n : β) (x : β) : | |
| β« t in (0:β)..x, E n (t^2/2) = J n x := by | |
| have h := intervalIntegral.integral_eq_sub_of_hasDerivAt | |
| (fun t _ => hasDerivAt_J n t) | |
| (show IntervalIntegrable (fun t : β => E n (t^2/2)) volume 0 x from | |
| (by unfold E; exact (by fun_prop : Continuous _).intervalIntegrable _ _)) | |
| simpa only [J_zero, sub_zero] using h | |
| lemma integral_exp_bounds (n : β) {x : β} (hx : 0 β€ x) : | |
| J (2*n+1) x β€ (β« t in (0:β)..x, Real.exp (-t^2/2)) β§ | |
| (β« t in (0:β)..x, Real.exp (-t^2/2)) β€ J (2*n) x := by | |
| have hi (k : β) : IntervalIntegrable (fun t : β => E k (t^2/2)) volume 0 x := by | |
| unfold E; exact (by fun_prop : Continuous _).intervalIntegrable _ _ | |
| have he : IntervalIntegrable (fun t : β => Real.exp (-t^2/2)) volume 0 x := (by fun_prop : Continuous _).intervalIntegrable _ _ | |
| constructor | |
| Β· rw [β integral_E] | |
| apply intervalIntegral.integral_mono_on hx (hi _) he | |
| intro t ht | |
| simpa only [neg_div] using E_odd_le_exp n (show (0:β) β€ t^2/2 by positivity) | |
| Β· rw [β integral_E] | |
| apply intervalIntegral.integral_mono_on hx he (hi _) | |
| intro t ht | |
| simpa only [neg_div] using exp_le_E_even n (show (0:β) β€ t^2/2 by positivity) | |
| end GaussianPropeller.Taylor | |
| end OAI | |