Download data/lean/OAI/MathematicalPhysics/RapidForcing/RationalProfiles.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 10.4 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/MathematicalPhysics/RapidForcing/RationalProfiles.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/MathematicalPhysics/RapidForcing/RationalProfiles.lean
-
curl -L -o RationalProfiles.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/MathematicalPhysics/RapidForcing/RationalProfiles.lean
10.4 kB
| import OAI.MathematicalPhysics.RapidForcing.EffectiveProfiles | |
| namespace OAI | |
| section | |
| open scoped BigOperators Topology | |
| open Filter | |
| namespace RapidForcing.EffectiveProfile | |
| structure Ball where | |
| center : β | |
| radius : β | |
| deriving DecidableEq | |
| def Ball.exact (q : β) : Ball := β¨q, 0β© | |
| def Ball.add (a b : Ball) : Ball := β¨a.center + b.center, a.radius + b.radiusβ© | |
| def Ball.mul (a b : Ball) : Ball := | |
| β¨a.center * b.center, | |
| |a.center| * b.radius + |b.center| * a.radius + a.radius * b.radiusβ© | |
| def Ball.pow (a : Ball) : β β Ball | |
| | 0 => Ball.exact 1 | |
| | n + 1 => (a.pow n).mul a | |
| def Ball.denInv (a : Ball) : Ball := | |
| β¨(max (1 / 16) a.center)β»ΒΉ, 256 * a.radiusβ© | |
| def Ball.Covers (a : Ball) (x : β) : Prop := |(a.center : β) - x| β€ (a.radius : β) | |
| lemma Ball.Covers.radius_nonneg {a : Ball} {x : β} (h : a.Covers x) : 0 β€ a.radius := by | |
| exact_mod_cast (abs_nonneg _).trans h | |
| lemma Ball.covers_exact (q : β) : (Ball.exact q).Covers q := by | |
| simp [Ball.exact, Covers] | |
| lemma Ball.Covers.add {a b : Ball} {x y : β} (ha : a.Covers x) (hb : b.Covers y) : | |
| (a.add b).Covers (x + y) := by | |
| dsimp [Covers, Ball.add] at * | |
| push_cast | |
| calc | |
| |(a.center : β) + b.center - (x + y)| = |(a.center - x) + (b.center - y)| := by congr 1; ring | |
| _ β€ |(a.center : β) - x| + |(b.center : β) - y| := abs_add_le _ _ | |
| _ β€ _ := add_le_add ha hb | |
| lemma Ball.Covers.mul {a b : Ball} {x y : β} (ha : a.Covers x) (hb : b.Covers y) : | |
| (a.mul b).Covers (x * y) := by | |
| have he1 : (0 : β) β€ a.radius := by exact_mod_cast ha.radius_nonneg | |
| have he2 : (0 : β) β€ b.radius := by exact_mod_cast hb.radius_nonneg | |
| change |((a.center * b.center : β) : β) - x * y| β€ _ | |
| simp only [Ball.mul, Rat.cast_mul, Rat.cast_add, Rat.cast_abs] | |
| calc | |
| |(a.center : β) * b.center - x*y| = | |
| |(a.center : β) * (b.center - y) + (b.center : β) * (a.center - x) - | |
| (a.center - x) * (b.center - y)| := by congr 1; ring | |
| _ β€ |(a.center : β) * (b.center - y)| + |(b.center : β) * (a.center - x)| + | |
| |((a.center : β) - x) * (b.center - y)| := | |
| (abs_sub _ _).trans (add_le_add (abs_add_le _ _) le_rfl) | |
| _ β€ _ := by | |
| simp only [abs_mul] | |
| gcongr | |
| Β· exact hb | |
| Β· exact ha | |
| Β· exact ha | |
| Β· exact hb | |
| lemma Ball.Covers.pow {a : Ball} {x : β} (ha : a.Covers x) (n : β) : | |
| (a.pow n).Covers (x ^ n) := by | |
| induction n with | |
| | zero => simpa [Ball.pow] using Ball.covers_exact 1 | |
| | succ n ih => simpa only [Ball.pow, pow_succ] using ih.mul ha | |
| lemma clamp_dist (c x : β) (hx : (1 / 16 : β) β€ x) : | |
| |max (1 / 16) c - x| β€ |c - x| := by | |
| by_cases hc : (1 / 16 : β) β€ c | |
| Β· rw [max_eq_right hc] | |
| Β· rw [max_eq_left (le_of_not_ge hc), abs_of_nonpos (by linarith), | |
| abs_of_nonpos (by linarith)] | |
| linarith | |
| lemma Ball.Covers.denInv {a : Ball} {x : β} (ha : a.Covers x) (hx : (1 / 16 : β) β€ x) : | |
| a.denInv.Covers xβ»ΒΉ := by | |
| have hz : (1 / 16 : β) β€ max (1 / 16) (a.center : β) := le_max_left _ _ | |
| have hp : 0 < max (1 / 16) (a.center : β) := lt_of_lt_of_le (by norm_num) hz | |
| have hxp : 0 < x := by linarith | |
| have hprod : (1 / 256 : β) β€ max (1 / 16) (a.center : β) * x := by nlinarith | |
| change |(((max (1 / 16) a.center)β»ΒΉ : β) : β) - xβ»ΒΉ| β€ _ | |
| simp only [Ball.denInv, Rat.cast_inv, Rat.cast_max, Rat.cast_div, Rat.cast_one, | |
| Rat.cast_ofNat, Rat.cast_mul] | |
| rw [inv_sub_inv hp.ne' hxp.ne', abs_div, abs_mul, abs_of_pos hp, abs_of_pos hxp, | |
| (div_le_iffβ (mul_pos hp hxp))] | |
| calc | |
| |x - max (1 / 16) (a.center : β)| = |max (1 / 16) (a.center : β) - x| := abs_sub_comm _ _ | |
| _ β€ |(a.center : β) - x| := clamp_dist _ _ hx | |
| _ β€ (a.radius : β) := ha | |
| _ β€ 256 * (a.radius : β) * (max (1 / 16) (a.center : β) * x) := by | |
| have hnon : (0 : β) β€ a.radius := by exact_mod_cast ha.radius_nonneg | |
| nlinarith | |
| def Encloses (b : β β Ball) (x : β) : Prop := | |
| (β k, (b k).Covers x) β§ Tendsto (fun k => ((b k).radius : β)) atTop (π 0) | |
| lemma Encloses.centers {b : β β Ball} {x : β} (h : Encloses b x) : | |
| Tendsto (fun k => ((b k).center : β)) atTop (π x) := by | |
| apply tendsto_iff_norm_sub_tendsto_zero.2 | |
| exact squeeze_zero (fun _ => norm_nonneg _) (fun k => by simpa only [Real.norm_eq_abs, Ball.Covers] using h.1 k) h.2 | |
| lemma encloses_exact (q : β) : Encloses (fun _ => Ball.exact q) q := | |
| β¨fun _ => Ball.covers_exact _, by simp [Ball.exact]β© | |
| lemma Encloses.add {a b : β β Ball} {x y : β} (ha : Encloses a x) (hb : Encloses b y) : | |
| Encloses (fun k => (a k).add (b k)) (x + y) := | |
| β¨fun k => (ha.1 k).add (hb.1 k), by simpa only [Ball.add, Rat.cast_add, add_zero] using ha.2.add hb.2β© | |
| lemma Encloses.mul {a b : β β Ball} {x y : β} (ha : Encloses a x) (hb : Encloses b y) : | |
| Encloses (fun k => (a k).mul (b k)) (x * y) := by | |
| refine β¨fun k => (ha.1 k).mul (hb.1 k), ?_β© | |
| simpa only [Ball.mul, Rat.cast_add, Rat.cast_mul, Rat.cast_abs, mul_zero, add_zero] | |
| using ((ha.centers.abs.mul hb.2).add (hb.centers.abs.mul ha.2)).add (ha.2.mul hb.2) | |
| lemma Encloses.pow {a : β β Ball} {x : β} (ha : Encloses a x) (n : β) : | |
| Encloses (fun k => (a k).pow n) (x ^ n) := by | |
| induction n with | |
| | zero => simpa [Ball.pow] using encloses_exact 1 | |
| | succ n ih => simpa [Ball.pow, pow_succ] using ih.mul ha | |
| lemma Encloses.denInv {a : β β Ball} {x : β} (ha : Encloses a x) (hx : (1 / 16 : β) β€ x) : | |
| Encloses (fun k => (a k).denInv) xβ»ΒΉ := | |
| β¨fun k => (ha.1 k).denInv hx, by simpa [Ball.denInv] using ha.2.const_mul 256β© | |
| def expTerms (q : β) (k : β) : β := k + β2 * |q|ββ + 1 | |
| def expBall (q : β) (k : β) : Ball := | |
| let n := expTerms q k | |
| β¨β j β Finset.range n, q ^ j / (j.factorial : β), | |
| |q| ^ n / (n.factorial : β) * 2β© | |
| lemma expTerms_large (q : β) (k : β) : |(q : β)| / (expTerms q k + 1) β€ 1 / 2 := by | |
| have h : 2 * |(q : β)| β€ (β2 * |q|ββ : β) := by | |
| exact_mod_cast (Nat.le_ceil (2 * |q|)) | |
| have hp : (0 : β) < expTerms q k + 1 := by positivity | |
| apply (div_le_iffβ hp).2 | |
| dsimp [expTerms] | |
| push_cast | |
| have : (0 : β) β€ k := Nat.cast_nonneg _ | |
| linarith | |
| lemma expBall_covers (q : β) (k : β) : (expBall q k).Covers (Real.exp q) := by | |
| have h := @Complex.exp_bound' (q : β) (expTerms q k) (by | |
| simpa only [β Complex.ofReal_ratCast, Complex.norm_real, Real.norm_eq_abs, Nat.cast_succ] | |
| using expTerms_large q k) | |
| have heq : (Complex.exp (q : β) - β j β Finset.range (expTerms q k), | |
| (q : β) ^ j / (j.factorial : β)) = | |
| ((Real.exp (q : β) - β j β Finset.range (expTerms q k), | |
| (q : β) ^ j / (j.factorial : β)) : β) := by | |
| simp | |
| rw [heq, Complex.norm_real, Real.norm_eq_abs] at h | |
| simpa [Ball.Covers, expBall, Complex.norm_real, Real.norm_eq_abs, abs_sub_comm, | |
| β Complex.ofReal_ratCast, Rat.norm_cast_real] using h | |
| lemma expBall_encloses (q : β) : Encloses (expBall q) (Real.exp q) := by | |
| refine β¨expBall_covers q, ?_β© | |
| have hN : Tendsto (expTerms q) atTop atTop := by | |
| exact (tendsto_add_atTop_nat (β2 * |q|ββ + 1)).congr (fun n => by simp [expTerms, Nat.add_assoc]) | |
| have h := (FloorSemiring.tendsto_pow_div_factorial_atTop |(q : β)|).comp hN | |
| simpa [expBall] using h.mul_const 2 | |
| def monoBall (n : β) (q : β) (k : β) : Ball := | |
| if q β€ 0 then Ball.exact 0 else | |
| (Ball.exact (qβ»ΒΉ ^ n)).mul (expBall (-qβ»ΒΉ) k) | |
| def glueBall : GluePoly β β β β β Ball | |
| | [], _, _ => Ball.exact 0 | |
| | (a, n) :: p, q, k => ((Ball.exact a).mul (monoBall n q k)).add (glueBall p q k) | |
| lemma monoBall_encloses (n : β) (q : β) : Encloses (monoBall n q) (monoGlue n q) := by | |
| by_cases hq : q β€ 0 | |
| Β· have hx : (q : β) β€ 0 := by exact_mod_cast hq | |
| unfold monoBall | |
| simpa [hq, monoGlue, expNegInvGlue.zero_of_nonpos hx] using encloses_exact 0 | |
| Β· have hx : Β¬ (q : β) β€ 0 := by exact_mod_cast hq | |
| unfold monoBall | |
| simpa [hq, monoGlue, expNegInvGlue, hx] using | |
| (encloses_exact (qβ»ΒΉ ^ n)).mul (expBall_encloses (-qβ»ΒΉ)) | |
| lemma glueBall_encloses (p : GluePoly) (q : β) : Encloses (glueBall p q) (glue p q) := by | |
| induction p with | |
| | nil => simpa [glueBall, glue] using encloses_exact 0 | |
| | cons a p ih => | |
| rcases a with β¨a, nβ© | |
| exact ((encloses_exact a).mul (monoBall_encloses n q)).add ih | |
| def Expr.numeric : Expr β β β β β Ball | |
| | .const a, _, _ => Ball.exact a | |
| | .left p, q, k => glueBall p q k | |
| | .right p, q, k => glueBall p (1 - q) k | |
| | .invDen n, q, k => | |
| ((glueBall [(1, 0)] q k).add (glueBall [(1, 0)] (1 - q) k)).denInv.pow n | |
| | .add a b, q, k => (a.numeric q k).add (b.numeric q k) | |
| | .mul a b, q, k => (a.numeric q k).mul (b.numeric q k) | |
| lemma Expr.numeric_encloses (e : Expr) (q : β) : Encloses (e.numeric q) (e.value q) := by | |
| induction e with | |
| | const a => exact encloses_exact a | |
| | left p => exact glueBall_encloses p q | |
| | right p => simpa [Expr.value, Expr.numeric] using glueBall_encloses p (1 - q) | |
| | invDen n => | |
| have hd : Encloses (fun k => (glueBall [(1, 0)] q k).add (glueBall [(1, 0)] (1 - q) k)) | |
| (expNegInvGlue q + expNegInvGlue (1 - q)) := by | |
| simpa only [glue_one, Rat.cast_sub, Rat.cast_one] using | |
| (glueBall_encloses [(1, 0)] q).add (glueBall_encloses [(1, 0)] (1 - q)) | |
| exact (hd.denInv (denominator_lower q)).pow n | |
| | add a b ha hb => exact ha.add hb | |
| | mul a b ha hb => exact ha.mul hb | |
| def Expr.numericError (e : Expr) (q : β) (k : β) (inputError : β) : β := | |
| (e.numeric q k).radius + e.diff.bound * inputError | |
| lemma Expr.numeric_error_le (e : Expr) (q : β) (k : β) (r : β) (x : β) | |
| (hx : |(q : β) - x| β€ (r : β)) : | |
| |((e.numeric q k).center : β) - e.value x| β€ (e.numericError q k r : β) := by | |
| have he := (e.numeric_encloses q).1 k | |
| have hd : |e.value q - e.value x| β€ (e.diff.bound : β) * |(q : β) - x| := by | |
| exact e.lipschitz.dist_le_mul (q : β) x | |
| calc | |
| _ β€ |((e.numeric q k).center : β) - e.value q| + |e.value q - e.value x| := abs_sub_le _ _ _ | |
| _ β€ (e.numeric q k).radius + (e.diff.bound : β) * (r : β) := | |
| add_le_add he (hd.trans (mul_le_mul_of_nonneg_left hx (by exact_mod_cast e.diff.bound_nonneg))) | |
| _ = _ := by simp [numericError] | |
| end RapidForcing.EffectiveProfile | |
| end | |
| end OAI | |