import Euler.PacketCorrectionConstants import Mathlib.Analysis.Real.Sqrt import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics /-! The literal source truncation floor(k^ϑ), ϑ=10⁻⁶, meets the packet and correction guards from finitely many fixed-cost bounds. -/ /-! ## From `Euler/PacketCorrectionScalar.lean` The text of `Euler/PacketCorrectionScalar.lean`, folded into this file, which was its only importer. -/ section /-! Explicit scalar choices for the actual drift-aware correction budget. The error target is exp(-sqrt X), with X=k^ϑ in the source construction. -/ noncomputable section namespace EulerPacketCorrectionScalar open Set def delta (X : ℝ) : ℝ := Real.exp (-Real.sqrt X) def residual (k X : ℝ) : ℝ := 2*Real.exp (-(7/10)*X*Real.log k) def initialRadius (R M Rc : ℝ) : ℝ := 1/(1+8*R+4*M*Rc+Rc) theorem delta_pos (X : ℝ) : 0 < delta X := Real.exp_pos _ theorem delta_le_one (X : ℝ) : delta X ≤ 1 := Real.exp_le_one_iff.mpr (neg_nonpos.mpr (Real.sqrt_nonneg X)) /-- One polynomial inverse radius meets both packet-series and pressure- inverse absorption requirements. -/ theorem initialRadius_bounds (R M Rc : ℝ) (hR : 0 ≤ R) (hM : 0 ≤ M) (hRc : 0 ≤ Rc) : 0 < initialRadius R M Rc ∧ initialRadius R M Rc*(4*R) ≤ 1/2 ∧ 4*M*(initialRadius R M Rc*Rc) ≤ 1 ∧ initialRadius R M Rc*Rc ≤ 1 := by have hd : 0 < 1+8*R+4*M*Rc+Rc := by positivity have hmc : 0 ≤ M*Rc := mul_nonneg hM hRc unfold initialRadius refine ⟨one_div_pos.mpr hd, ?_, ?_, ?_⟩ · rw [div_mul_eq_mul_div,one_mul,div_le_iff₀ hd] linarith · rw [show 4*M*(1/(1+8*R+4*M*Rc+Rc)*Rc) = (4*M*Rc)/(1+8*R+4*M*Rc+Rc) by ring, div_le_iff₀ hd] linarith · rw [div_mul_eq_mul_div,one_mul,div_le_iff₀ hd] linarith /-- The actual residual envelope wins over the Gronwall factor with an explicit linear bound on the source growth cost. -/ theorem residual_small (C T k X : ℝ) (hX : 64 ≤ X) (hk : 1 ≤ Real.log k) (hgrowth : 3*C*T ≤ X/4) : 2*residual k X*Real.exp (3*C*T) ≤ delta X/2 := by have hX0 : 0 ≤ X := by linarith have hs : Real.sqrt X ≤ X/8 := (Real.sqrt_le_left (by linarith)).mpr (by nlinarith) have hl : Real.log 8 ≤ X/8 := (Real.log_le_sub_one_of_pos (by norm_num : (0 : ℝ) < 8)).trans (by linarith) have hxlog : X ≤ X*Real.log k := le_mul_of_one_le_right hX0 hk have he : Real.log 8 + (-(7/10)*X*Real.log k+3*C*T) ≤ -Real.sqrt X := by linarith only [hX0,hs,hl,hxlog,hgrowth] have hh := Real.exp_le_exp.mpr he rw [Real.exp_add,Real.exp_log (by norm_num : (0 : ℝ) < 8),Real.exp_add] at hh unfold residual delta linarith only [hh] /-- The two elementary frequency guards control the radius loss caused by the actual O(1/k) drift and the chosen error target. -/ theorem radius_decay (C T D ρ0 k X : ℝ) (hk : 0 < k) (hfrequency : 8*C*T*D ≤ ρ0*k) (herror : 8*C*T ≤ ρ0*Real.exp (Real.sqrt X)) : 2*C*(D/k+delta X)*T ≤ ρ0/2 := by have hf : 8*C*T*(D/k) ≤ ρ0 := by calc _ = (8*C*T*D)/k := by ring _ ≤ ρ0 := (div_le_iff₀ hk).mpr hfrequency have he : 8*C*T*delta X ≤ ρ0 := by rw [delta,Real.exp_neg,← div_eq_mul_inv] exact (div_le_iff₀ (Real.exp_pos _)).mpr herror linarith only [hf,he] def radius (T C D ρ0 k X : ℝ) : C(Icc (0 : ℝ) T,ℝ) := ⟨fun t => ρ0-2*C*(D/k+delta X)*t.val, continuous_const.sub (continuous_const.mul continuous_subtype_val)⟩ theorem radius_bounds (T C D ρ0 k X : ℝ) (hC : 0 ≤ C) (hD : 0 ≤ D) (hk : 0 < k) (hdecay : 2*C*(D/k+delta X)*T ≤ ρ0/2) (t : Icc (0 : ℝ) T) : ρ0/2 ≤ radius T C D ρ0 k X t ∧ radius T C D ρ0 k X t ≤ ρ0 := by have hs : 0 ≤ 2*C*(D/k+delta X) := by exact mul_nonneg (mul_nonneg (by norm_num) hC) (add_nonneg (div_nonneg hD hk.le) (delta_pos X).le) have hu := mul_nonneg hs t.property.1 have hl := (mul_le_mul_of_nonneg_left t.property.2 hs).trans hdecay change ρ0/2 ≤ ρ0-2*C*(D/k+delta X)*t.val ∧ ρ0-2*C*(D/k+delta X)*t.val ≤ ρ0 constructor <;> linarith end EulerPacketCorrectionScalar end end noncomputable section namespace EulerPacketSourceFrequency open Real Filter EulerPacketCoarseMajorant EulerPacketCorrectionScalar def theta : ℝ := 1/1000000 def expansion (k : ℝ) : ℝ := k^theta def truncation (k : ℝ) : ℕ := Nat.floor (expansion k) def smallPower (k : ℝ) : ℝ := k^(theta/100) theorem expansion_pos (k : ℝ) (hk : 0 < k) : 0 < expansion k := Real.rpow_pos_of_pos hk _ theorem truncation_bounds (k : ℝ) (hk : 1 ≤ k) : 1 ≤ truncation k ∧ expansion k-1 ≤ (truncation k : ℝ) ∧ (truncation k : ℝ) ≤ expansion k := by have hx : 1 ≤ expansion k := Real.one_le_rpow hk (by norm_num [theta]) exact ⟨(Nat.one_le_floor_iff _).mpr hx,(Nat.sub_one_lt_floor _).le, Nat.floor_le (zero_le_one.trans hx)⟩ theorem smallPower_le_expansion (k : ℝ) (hk : 1 ≤ k) : smallPower k ≤ expansion k := Real.rpow_le_rpow_of_exponent_le hk (by norm_num [theta]) theorem smallPower_le_frequency (k : ℝ) (hk : 1 ≤ k) : smallPower k ≤ k := by simpa only [Real.rpow_one,smallPower] using Real.rpow_le_rpow_of_exponent_le (x := k) hk (by norm_num [theta] : theta/100 ≤ 1) theorem smallPower_le_gradeCap (k : ℝ) (hk : 1 ≤ k) : smallPower k ≤ k^(1/100 : ℝ) := Real.rpow_le_rpow_of_exponent_le hk (by norm_num [theta]) theorem tailBase_frequency (R H C k : ℝ) (hC : 0 ≤ C) (hk : 1 ≤ k) (hc : tailPolynomialConstant R H C ≤ smallPower k) : tailBase R H C (truncation k) ≤ k^(1/100 : ℝ) := by have hk0 : 0 < k := zero_lt_one.trans_le hk obtain ⟨hn,_,hnx⟩ := truncation_bounds k hk calc _ ≤ tailPolynomialConstant R H C*(truncation k : ℝ)^222 := tailBase_polynomial_bound R H C hC _ hn _ ≤ smallPower k*(expansion k)^222 := mul_le_mul hc (pow_le_pow_left₀ (Nat.cast_nonneg _) hnx 222) (by positivity) (Real.rpow_pos_of_pos hk0 _).le _ = k^(theta/100+theta*222) := by unfold smallPower expansion rw [← Real.rpow_mul_natCast hk0.le,← Real.rpow_add hk0] norm_num _ ≤ k^(1/100 : ℝ) := Real.rpow_le_rpow_of_exponent_le hk (by norm_num [theta]) /-- The source's very small power is below the exponential margin in the error target exp(-sqrt(k^ϑ)). -/ theorem smallPower_le_exp_sqrt (k : ℝ) (hk : 0 < k) : smallPower k ≤ Real.exp (Real.sqrt (expansion k)) := by have hx : 0 ≤ expansion k := (expansion_pos k hk).le have hl := Real.log_le_rpow_div hx (by norm_num : (0 : ℝ) < 1/2) rw [← Real.sqrt_eq_rpow] at hl have hlog : Real.log (expansion k)=theta*Real.log k := Real.log_rpow hk theta have hs := Real.sqrt_nonneg (expansion k) unfold smallPower rw [Real.rpow_def_of_pos hk] apply Real.exp_le_exp.mpr rw [hlog] at hl linarith only [hl,hs] theorem correction_guards (C T D ρ0 k : ℝ) (hk : 1 ≤ k) (hρ : 0 < ρ0) (hX : 64 ≤ expansion k) (hlog : 1 ≤ Real.log k) (hgrowth : 12*C*T ≤ smallPower k) (hdrift : 8*C*T*D/ρ0 ≤ smallPower k) (herror : 8*C*T/ρ0 ≤ smallPower k) : 2*residual k (expansion k)*Real.exp (3*C*T) ≤ delta (expansion k)/2 ∧ 2*C*(D/k+delta (expansion k))*T ≤ ρ0/2 := by have hk0 : 0 < k := zero_lt_one.trans_le hk constructor · apply residual_small C T k (expansion k) hX hlog have hh := hgrowth.trans (smallPower_le_expansion k hk) linarith · apply radius_decay C T D ρ0 k (expansion k) hk0 · have hh := (div_le_iff₀ hρ).mp (hdrift.trans (smallPower_le_frequency k hk)) linarith only [hh] · have hh := (div_le_iff₀ hρ).mp (herror.trans (smallPower_le_exp_sqrt k hk0)) linarith only [hh] /-- Every finite list of fixed source costs fits the required very small power after one sufficiently large frequency choice. -/ theorem fixed_costs_eventually (cost : Finset ℝ) : ∀ᶠ k : ℝ in atTop, 4 ≤ k ∧ 64 ≤ expansion k ∧ 1 ≤ Real.log k ∧ ∀ c ∈ cost, c ≤ smallPower k := by have hpow := _root_.tendsto_rpow_atTop (by norm_num [theta] : 0 < theta/100) have hcost : ∀ᶠ k : ℝ in atTop, ∀ c ∈ cost, c ≤ smallPower k := by apply (Finset.eventually_all cost).mpr intro c _ exact hpow.eventually_ge_atTop c filter_upwards [eventually_ge_atTop (4 : ℝ), (_root_.tendsto_rpow_atTop (by norm_num [theta] : 0 < theta)).eventually_ge_atTop 64, Real.tendsto_log_atTop.eventually_ge_atTop 1,hcost] with k hk hx hl hc exact ⟨hk,hx,hl,hc⟩ end EulerPacketSourceFrequency