File size: 5,605 Bytes
4a56cd6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | import OAI.Dynamics.ConditionalShuffle.HybridCycles
namespace OAI
noncomputable section
open scoped Classical
open Filter Topology
namespace Thorp.Conditional.OverlayEnergy
def prepError (g : β) : β := (2^g : β) * Real.sqrt
((Fintype.card (Position (g+3)) : β) *
((1/2 : β)^(8*(g+3)) + 32*(9/10 : β)^(2^g)))
lemma prepError_nonneg (g : β) : 0 β€ prepError g := by unfold prepError; positivity
lemma error_scaled_sq (g : β) : ((2^g : β) * prepError g)^2 =
(8 / 2^24 : β) * (1/8 : β)^g + 256 * (2^g : β)^5 * (9/10 : β)^(2^g) := by
unfold prepError
rw [mul_pow, mul_pow, Real.sq_sqrt (by positivity)]
have hN : (Fintype.card (Position (g+3)) : β) = 8 * (2^g : β) := by
rw [card_position]; push_cast; rw [pow_add]; norm_num; ring
rw [hN]
have hp : (1/2 : β)^(8*(g+3)) = (1/2 : β)^(8*g) * (1/2 : β)^24 := by
rw [show 8*(g+3) = 8*g+24 by omega, pow_add]
have he : (2^g : β)^5 * (1/2 : β)^(8*g) = (1/8 : β)^g := by
rw [β pow_mul, Nat.mul_comm g 5, pow_mul, pow_mul, β mul_pow]
norm_num
rw [hp]
calc
_ = 8 * ((2^g : β)^5 * (1/2 : β)^(8*g)) * (1/2 : β)^24 +
256 * (2^g : β)^5 * (9/10 : β)^(2^g) := by ring
_ = _ := by rw [he]; norm_num; ring
lemma error_scaled_tendsto : Tendsto (fun g : β => (2^g : β) * prepError g) atTop (nhds 0) := by
have hβ := (tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num : (0 : β) β€ 1/8)
(by norm_num : (1/8 : β) < 1)).const_mul (8/2^24 : β)
have hβ := ((tendsto_pow_const_mul_const_pow_of_lt_one 5
(by norm_num : (0 : β) β€ 9/10) (by norm_num : (9/10 : β) < 1)).comp
(tendsto_pow_atTop_atTop_of_one_lt (by norm_num : (1 : β) < 2))).const_mul (256 : β)
have hh := (hβ.add hβ).sqrt
have he (g : β) : Real.sqrt ((8/2^24 : β)*(1/8 : β)^g +
256*(2^g : β)^5*(9/10 : β)^(2^g)) = (2^g : β)*prepError g := by
rw [β error_scaled_sq, Real.sqrt_sq (mul_nonneg (by positivity) (prepError_nonneg g))]
simpa only [Function.comp_def, Nat.cast_pow, Nat.cast_ofNat, mul_zero,
add_zero, Real.sqrt_zero, β mul_assoc, he] using hh
lemma prepError_tendsto : Tendsto prepError atTop (nhds 0) := by
apply squeeze_zero prepError_nonneg (fun g => ?_) error_scaled_tendsto
exact le_mul_of_one_le_left (prepError_nonneg g) (one_le_powβ (by norm_num : (1 : β) β€ 2))
lemma pow_add_bound (a b : β) (ha : 0 β€ a) (hb : 0 β€ b) (n : β) :
(a+b)^n β€ (2 : β)^n * (a^n+b^n) := by
rcases le_total a b with hab | hba
Β· calc
_ β€ (2*b)^n := pow_le_pow_leftβ (add_nonneg ha hb) (by linarith) n
_ = (2 : β)^n*b^n := mul_pow _ _ _
_ β€ _ := mul_le_mul_of_nonneg_left (le_add_of_nonneg_left (pow_nonneg ha _)) (by positivity)
Β· calc
_ β€ (2*a)^n := pow_le_pow_leftβ (add_nonneg ha hb) (by linarith) n
_ = (2 : β)^n*a^n := mul_pow _ _ _
_ β€ _ := mul_le_mul_of_nonneg_left (le_add_of_nonneg_right (pow_nonneg hb _)) (by positivity)
lemma gamma_power : 2*(255/256 : β)^200 < 1 := by norm_num
lemma coefficient_scaled_tendsto :
Tendsto (fun g : β => (2^g : β) * coefficient g ^ 200) atTop (nhds 0) := by
have ha : Tendsto (fun g : β => (2^g : β) * ((255/256 : β)^(g+3))^200) atTop (nhds 0) := by
have hh := (tendsto_pow_atTop_nhds_zero_of_lt_one
(by positivity : (0 : β) β€ 2*(255/256 : β)^200) gamma_power).mul_const ((255/256 : β)^600)
convert hh using 1
Β· funext g
rw [β pow_mul, Nat.add_mul, pow_add, Nat.mul_comm g 200, pow_mul, mul_pow]
generalize (255/256 : β)^600 = C
ring
Β· simp only [zero_mul]
have hb : Tendsto (fun g : β => (2^g : β) * prepError g ^ 200) atTop (nhds 0) := by
apply squeeze_zero' (Filter.Eventually.of_forall (fun g => by positivity)) ?_ error_scaled_tendsto
filter_upwards [(tendsto_order.1 prepError_tendsto).2 1 (by norm_num)] with g hg
exact mul_le_mul_of_nonneg_left
(by simpa only [pow_one] using pow_le_pow_of_le_one (prepError_nonneg g) (le_of_lt hg) (by norm_num : 1 β€ 200)) (by positivity)
have hh := (ha.add hb).const_mul ((2 : β)^200)
have hc : Tendsto (fun g : β => (2 : β)^200 *
((2^g : β)*((255/256 : β)^(g+3))^200 + (2^g : β)*prepError g^200)) atTop (nhds 0) := by
simpa only [add_zero, mul_zero] using hh
apply squeeze_zero (fun g => by positivity) (fun g => ?_) hc
have hh := mul_le_mul_of_nonneg_left (pow_add_bound ((255/256 : β)^(g+3))
(prepError g) (by positivity) (prepError_nonneg g) 200) (by positivity : (0 : β) β€ 2^g)
change (2^g : β) * (((255/256 : β)^(g+3)) + prepError g)^200 β€ _
exact hh.trans_eq (by ring)
lemma total_energy_tendsto :
Tendsto (fun g : β => (2^g : β)^3 * coefficient g^800) atTop (nhds 0) := by
have hh := coefficient_scaled_tendsto.pow 4
simp only [zero_pow (by norm_num : 4 β 0)] at hh
apply squeeze_zero (fun g => by positivity) (fun g => ?_) hh
rw [mul_pow, β pow_mul (coefficient g), show 200*4=800 by omega]
apply mul_le_mul_of_nonneg_right _ (pow_nonneg (coefficient_nonneg g) _)
exact pow_le_pow_rightβ (one_le_powβ (by norm_num : (1 : β) β€ 2)) (by norm_num : 3 β€ 4)
def marginalRate (g : β) : β := Real.sqrt (8 * (2^g : β)^3 * coefficient g^800)
lemma marginalRate_tendsto : Tendsto marginalRate atTop (nhds 0) := by
change Tendsto (fun g : β => Real.sqrt (8 * (2^g : β)^3 * coefficient g^800)) atTop (nhds 0)
simpa only [mul_assoc, mul_zero, Real.sqrt_zero] using
(total_energy_tendsto.const_mul 8).sqrt
end Thorp.Conditional.OverlayEnergy
end
end OAI
|