File size: 5,926 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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | import Mathlib
import OAI.Probability.GaussianRegression.Main
import OAI.Probability.MemoryPrecision.SuccessArithmetic
namespace OAI
open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry
open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
noncomputable section
universe u v
open MeasureTheory ProbabilityTheory Set Filter
open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise
namespace MemoryPrecision
def StreamConstant : β := 3*(SuccessConstant+21)
lemma streamConstant_pos : 0 < StreamConstant := by
have h := successConstant_one
dsimp [StreamConstant]
linarith
lemma blockCount_antitone {p q : β} (hq : 0 < q) (hqp : q β€ p) (T : β) :
BlockCount T p β€ BlockCount T q := by
apply Nat.ceil_mono
exact div_le_div_of_nonneg_left (by positivity) (by exact_mod_cast hq) (by exact_mod_cast hqp)
lemma power_le_exp {x : β} (hx : 0 β€ x) (d : β) : x^d β€ Real.exp (x*d) := by
have hl : x β€ Real.exp x := by linarith [Real.add_one_le_exp x]
have h := pow_le_pow_leftβ hx hl d
simpa only [β Real.rpow_natCast, β Real.exp_mul] using h
lemma stream_root_exp {d M : β} (hd : 32 β€ d) :
(((d/8+2)*2^M:β):β)^(1/((d/8:β):β)) β€ Real.exp ((d:β)+16*M/d) := by
have hn : (d/8+2)*2^M β€ 2^(d+M) := by
have h : d/8+2 β€ 2^d := (show d/8+2 β€ d+1 by omega).trans Nat.lt_two_pow_self
simpa [pow_add] using Nat.mul_le_mul_right (2^M) h
have ht : (2:β) β€ Real.exp 1 := by linarith [Real.add_one_le_exp (1:β)]
have hnum : (((d/8+2)*2^M:β):β) β€ Real.exp ((d:β)+M) := by
calc
_ β€ (2:β)^(d+M) := by exact_mod_cast hn
_ β€ (Real.exp 1)^(d+M) := pow_le_pow_leftβ (by norm_num) ht _
_ = _ := by rw [β Real.rpow_natCast, β Real.exp_mul]; simp
have hdp : (d:β)/16 β€ (d/8:β) := by
apply (div_le_iffβ (by norm_num : (0:β) < 16)).2
exact_mod_cast (show d β€ (d/8)*16 by omega)
have hd0 : (0:β) < d := by exact_mod_cast (show 0 < d by omega)
have hr : ((d:β)+M)/((d/8:β):β) β€ (d:β)+16*M/d := by
calc
_ β€ ((d:β)+M)/((d:β)/16) := div_le_div_of_nonneg_left (by positivity) (by positivity) hdp
_ = 16+16*M/d := by field_simp
_ β€ _ := by
have : (16:β) β€ d := by exact_mod_cast (show 16 β€ d by omega)
linarith
calc
_ β€ (Real.exp ((d:β)+M))^(1/((d/8:β):β)) :=
Real.rpow_le_rpow (by positivity) hnum (by positivity)
_ = Real.exp (((d:β)+M)/((d/8:β):β)) := by rw [β Real.exp_mul]; congr 1; ring
_ β€ _ := Real.exp_le_exp.mpr hr
lemma stream_step_exp {d M : β} (hd : 32 β€ d) :
SuccessConstant^d * (((d/8+2)*2^M:β):β)^(1/((d/8:β):β)) β€
Real.exp ((d:β)*(SuccessConstant+1)+16*M/d) := by
have hS := successConstant_one
calc
_ β€ Real.exp (SuccessConstant*d) * Real.exp ((d:β)+16*M/d) :=
mul_le_mul (power_le_exp (by linarith) d) (stream_root_exp hd) (by positivity) (by positivity)
_ = _ := by rw [β Real.exp_add]; congr 1; ring
lemma stream_step_one (d M : β) :
1 β€ SuccessConstant^d * (((d/8+2)*2^M:β):β)^(1/((d/8:β):β)) := by
apply one_le_mul_of_one_le_of_one_le (one_le_powβ successConstant_one)
apply Real.one_le_rpow _ (by positivity)
exact_mod_cast (show 1 β€ (d/8+2)*2^M by
exact Nat.succ_le_iff.mpr (Nat.mul_pos (by omega) (by positivity)))
lemma stream_exponent_bound {d M : β} (hd : 32 β€ d) :
(d:β)*(SuccessConstant+5)+16*M/d β€
(((d:β)-1)/2)*StreamConstant*(1+(M:β)/(d:β)^2) := by
have hS := successConstant_one
have hd0 : (0:β) < d := by exact_mod_cast (show 0 < d by omega)
have hd3 : (d:β)/3 β€ ((d:β)-1)/2 := by
have : (32:β) β€ d := by exact_mod_cast hd
linarith
have hc : 0 β€ StreamConstant := streamConstant_pos.le
calc
_ β€ (SuccessConstant+21)*(d:β)+(SuccessConstant+21)*(M/d) := by
have hM : 0 β€ (M:β)/d := by positivity
have hm := mul_le_mul_of_nonneg_right (show (16:β) β€ SuccessConstant+21 by linarith) hM
have hn : (d:β)*(SuccessConstant+5) β€ (SuccessConstant+21)*(d:β) := by nlinarith
simpa only [mul_div_assoc] using add_le_add hn hm
_ = (d:β)/3*StreamConstant*(1+(M:β)/(d:β)^2) := by
dsimp [StreamConstant]
field_simp
_ β€ _ := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hd3 hc) (by positivity)
lemma stream_full_factor {d M T : β} (hd : 32 β€ d) (hT : 0 < T) :
(4:β)^d * (SuccessConstant^d * (((d/8+2)*2^M:β):β)^(1/((d/8:β):β)))^BlockCount T (d/8) β€
Real.exp ((((d:β)-1)/2)*StreamConstant*(1+(M:β)/(d:β)^2)*(BlockCount T ((d-1)/8):β)) := by
let b := BlockCount T ((d-1)/8)
let K := SuccessConstant^d * (((d/8+2)*2^M:β):β)^(1/((d/8:β):β))
have hK : 1 β€ K := stream_step_one d M
have hb : 1 β€ b := blockCount_pos hT (by omega)
have hbp : BlockCount T (d/8) β€ b := blockCount_antitone (by omega) (by omega) T
have h4 : (4:β)^d β€ Real.exp (4*d*(b:β)) := by
apply (power_le_exp (by norm_num : (0:β) β€ 4) d).trans
apply Real.exp_le_exp.mpr
exact le_mul_of_one_le_right (by positivity) (by exact_mod_cast hb)
have hpow : K^b β€ Real.exp (((d:β)*(SuccessConstant+1)+16*M/d)*(b:β)) := by
have h := pow_le_pow_leftβ (by linarith : 0 β€ K) (stream_step_exp hd) b
simpa only [β Real.rpow_natCast, β Real.exp_mul, K] using h
calc
_ β€ (4:β)^d * K^b := mul_le_mul_of_nonneg_left (pow_le_pow_rightβ hK hbp) (by positivity)
_ β€ Real.exp (4*d*(b:β)) * Real.exp (((d:β)*(SuccessConstant+1)+16*M/d)*(b:β)) :=
mul_le_mul h4 hpow (by positivity) (by positivity)
_ = Real.exp (((d:β)*(SuccessConstant+5)+16*M/d)*(b:β)) := by rw [β Real.exp_add]; congr 1; ring
_ β€ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right (stream_exponent_bound hd) (by positivity))
end MemoryPrecision
end
end OAI
|