cfahlgren1's picture
download
raw
44.9 kB
import Mathlib
import OAI.Probability.ThorpRouting.HighTail.CutoffMass
namespace OAI
namespace ThorpNine.HighTail
namespace Thorp
lemma palindrome_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l)
(hs : 2*s ≤ l) {ι : Type*} [Fintype ι] (e : ι ↪ Card d)
(X : SwitchIndex d → Bool) (F : (SwitchIndex d → Bool) → ℝ)
(hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) (q : ℝ) (hq : 1 ≤ q)
(hlog : Real.log q ≤ 1/250) :
finiteMean (fun Y => F Y*q^(palindromeSlabCost l d e (Y,X))) ≤
finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by
obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd
exact adapted_mul_mean_le r s F _ hF hA _
(fun lo => palindrome_slab_partial_mgf r s l hl hs e X lo q hq hlog)
def familyEnd (L n : ℕ) : ℕ := if n = 0 then 0 else 2*(L*4^(n-1))
lemma familyEnd_two (L n : ℕ) : 2*familyEnd L n ≤ L*4^n := by
cases n with
| zero => simp [familyEnd]
| succ n => simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one,pow_succ]; nlinarith
lemma familyEnd_ge (L n j : ℕ) (hj : j < n) : 2*(L*4^j) ≤ familyEnd L n := by
cases n with
| zero => omega
| succ n =>
simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one]
apply Nat.mul_le_mul_left
exact Nat.mul_le_mul_left L (Nat.pow_le_pow_right (by decide) (by omega : j ≤ n))
noncomputable def palindromeFamilyCost (L n d : ℕ) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (ω : BenesCoins d) : ℕ :=
∑ j ∈ Finset.range n, palindromeSlabCost (L*4^j) d e ω
lemma palindromeFamilyCost_adapted (L n d : ℕ) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (X : SwitchIndex d → Bool) :
LayerAdapted d (familyEnd L n) (fun Y => palindromeFamilyCost L n d e (Y,X)) := by
apply layerAdapted_sum
intro j hj
exact layerAdapted_mono (palindromeSlabCost_adapted (L*4^j) d e X)
(familyEnd_ge L n j (Finset.mem_range.mp hj))
theorem palindrome_family_mgf (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q)
(hlog : Real.log q ≤ 1/250) :
finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤
Real.exp (Fintype.card ι * (68*∑ j ∈ Finset.range n,
Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by
induction n with
| zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero,
finiteMean_const,mul_zero,Real.exp_zero,le_refl]
| succ n ih =>
let l := L*4^n
have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _)
have hs : 2*familyEnd L n ≤ l := familyEnd_two L n
have hc : ∀ Y, palindromeFamilyCost L (n+1) d e (Y,X) =
palindromeFamilyCost L n d e (Y,X)+palindromeSlabCost l d e (Y,X) := by
intro Y
exact Finset.sum_range_succ _ _
have hm : finiteMean (fun Y => q^(palindromeFamilyCost L (n+1) d e (Y,X))) ≤
finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) *
Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by
by_cases hld : l ≤ d
· simp_rw [hc,pow_add]
exact palindrome_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hs e X _
(fun _ => pow_nonneg (by linarith) _)
(layerAdapted_comp (palindromeFamilyCost_adapted L n d e X) (fun c => q^c))
q hq hlog
· simp_rw [hc,palindromeSlabCost_gt l d (by omega) e,Nat.add_zero]
exact le_mul_of_one_le_right
(finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _))
(Real.one_le_exp_iff.mpr (by positivity))
refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_
rw [←Real.exp_add,Finset.sum_range_succ]
congr 1
dsimp [l]
ring
lemma pow_four_ge (j : ℕ) : j+1 ≤ 4^j := by
induction j with
| zero => norm_num
| succ j ih => rw [pow_succ]; omega
lemma sum_family_decay (L n : ℕ) (hL : 0 < L) :
(∑ j ∈ Finset.range n, Real.exp (-((L*4^j:ℕ):ℝ)/64)) ≤
Real.exp (-(L:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) := by
let r := Real.exp (-(1:ℝ)/64)
have hr : 0 < r := Real.exp_pos _
have hr1 : r < 1 := Real.exp_lt_one_iff.mpr (by norm_num)
have hg : (∑ j ∈ Finset.range n, r^j) ≤ 1/(1-r) := by
apply (le_div_iff₀ (by linarith : (0:ℝ)<1-r)).mpr
have hh := geom_sum_mul r n
nlinarith [pow_nonneg (le_of_lt hr) n]
calc
_ ≤ ∑ j ∈ Finset.range n, Real.exp (-(L:ℝ)/64)*r^j := by
apply Finset.sum_le_sum
intro j _
have hj := pow_four_ge j
have hlj : L+j ≤ L*4^j := by nlinarith
have hlj' : (L:ℝ)+j ≤ (L*4^j:ℕ) := by exact_mod_cast hlj
rw [←Real.exp_nat_mul,←Real.exp_add]
exact Real.exp_le_exp.mpr (by linarith)
_ = Real.exp (-(L:ℝ)/64)*(∑ j ∈ Finset.range n, r^j) := by rw [Finset.mul_sum]
_ ≤ Real.exp (-(L:ℝ)/64)*(1/(1-r)) :=
mul_le_mul_of_nonneg_left hg (Real.exp_nonneg _)
_ = _ := by ring
lemma palindromeLevelCost_step_add (t d : ℕ) {ι : Type*} [Fintype ι]
(e : ι ↪ Card (d+1)) (ω : BenesCoins (d+1)) :
palindromeLevelCost t (d+1) e ω =
let σ := benesStepEquiv d ω
let x := e.trans (headTailEquiv d).toEmbedding
let c := PairRouting.colors x σ.2.1
let hc := PairRouting.colors_compatible x σ.2.1
(if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1)
(fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) +
palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 +
palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 := by
classical
rw [palindromeLevelCost]
dsimp only
split_ifs with h
· simp only [palindromeLevelCost_gt t d (by omega),Nat.add_zero]
· simp only [Nat.zero_add]
lemma palindromeLowCost_sum (H d : ℕ) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (ω : BenesCoins d) :
palindromeLowCost H d e ω = ∑ i ∈ Finset.range H, palindromeLevelCost (i+1) d e ω := by
classical
induction d generalizing ι with
| zero => simp only [palindromeLowCost,palindromeLevelCost,Finset.sum_const_zero]
| succ d ih =>
rw [palindromeLowCost]
simp only [palindromeLevelCost_step_add,Finset.sum_add_distrib]
rw [←ih,←ih]
congr 2
simp only [Nat.add_right_cancel_iff,Finset.sum_ite_eq',Finset.mem_range,Nat.succ_le_iff]
lemma palindromeLowCost_slab (L d : ℕ) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (ω : BenesCoins d) :
palindromeLowCost L d e ω + palindromeSlabCost L d e ω = palindromeLowCost (2*L) d e ω := by
rw [palindromeLowCost_sum,palindromeLowCost_sum,show 2*L=L+L by omega,Finset.sum_range_add]
congr 1
exact Fin.sum_univ_eq_sum_range (fun i => palindromeLevelCost (L+i+1) d e ω) L
lemma palindromeCost_family (L n d : ℕ) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (ω : BenesCoins d) :
palindromeLowCost L d e ω + palindromeFamilyCost L n d e ω +
palindromeFamilyCost (2*L) n d e ω = palindromeLowCost (L*4^n) d e ω := by
induction n with
| zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero,
pow_zero,mul_one]
| succ n ih =>
have he : (2*L)*4^n = 2*(L*4^n) := by ring
have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring
simp only [palindromeFamilyCost,Finset.sum_range_succ] at ih ⊢
rw [he,he',←palindromeLowCost_slab,←palindromeLowCost_slab,←ih]
omega
lemma finiteMean_mul_sq_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) :
(finiteMean (fun ω => f ω*g ω))^2 ≤ finiteMean (fun ω => (f ω)^2)*finiteMean (fun ω => (g ω)^2) := by
have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ f g
simp only [finiteMean,div_pow,div_mul_div_comm,←pow_two]
exact div_le_div_of_nonneg_right h (sq_nonneg _)
lemma finiteMean_mul_exp_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) (A B : ℝ)
(hf : finiteMean (fun ω => (f ω)^2) ≤ Real.exp A)
(hg : finiteMean (fun ω => (g ω)^2) ≤ Real.exp B) :
finiteMean (fun ω => f ω*g ω) ≤ Real.exp ((A+B)/2) := by
have hc := finiteMean_mul_sq_le f g
have hn : 0 ≤ finiteMean (fun ω => (g ω)^2) := finiteMean_nonneg (fun _ => sq_nonneg _)
have hu := mul_le_mul hf hg hn (Real.exp_nonneg _)
have he : Real.exp A*Real.exp B = (Real.exp ((A+B)/2))^2 := by
rw [←Real.exp_add,←Real.exp_nat_mul]
congr 1
push_cast
ring
rw [he] at hu
have hh := hc.trans hu
have hep := Real.exp_pos ((A+B)/2)
nlinarith
noncomputable def heightDecay (H : ℕ) : ℝ :=
68*Real.exp (-(H:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64))
lemma heightDecay_nonneg (H : ℕ) : 0 ≤ heightDecay H := by
have h : Real.exp (-(1:ℝ)/64) < 1 := Real.exp_lt_one_iff.mpr (by norm_num)
apply div_nonneg (by positivity) (by linarith)
lemma heightDecay_antitone : Antitone heightDecay := by
intro L H h
have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by
have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0)
linarith
apply div_le_div_of_nonneg_right _ hden
apply mul_le_mul_of_nonneg_left _ (by norm_num)
apply Real.exp_le_exp.mpr
have h' : (L:ℝ) ≤ H := by exact_mod_cast h
linarith
lemma palindrome_family_mgf_decay (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q)
(hlog : Real.log q ≤ 1/250) :
finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤
Real.exp (Fintype.card ι*heightDecay L) := by
apply (palindrome_family_mgf L n d hL e X q hq hlog).trans
apply Real.exp_le_exp.mpr
apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _)
have h := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68)
simpa only [heightDecay,mul_div_assoc] using h
theorem palindrome_high_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q)
(hlog : Real.log q ≤ 1/500) :
finiteMean (fun Y => q^(palindromeFamilyCost H n d e (Y,X)+
palindromeFamilyCost (2*H) n d e (Y,X))) ≤ Real.exp (Fintype.card ι*heightDecay H) := by
have hq2 := one_le_pow₀ (n:=2) hq
have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith
have h₀ := palindrome_family_mgf_decay H n d hH e X (q^2) hq2 hlog2
have h₁ := palindrome_family_mgf_decay (2*H) n d (by omega) e X (q^2) hq2 hlog2
have h₁' := h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left
(heightDecay_antitone (show H ≤ 2*H by omega)) (Nat.cast_nonneg _)))
have hh := finiteMean_mul_exp_le (fun Y => q^(palindromeFamilyCost H n d e (Y,X)))
(fun Y => q^(palindromeFamilyCost (2*H) n d e (Y,X)))
(Fintype.card ι*heightDecay H) (Fintype.card ι*heightDecay H)
(by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁')
simpa only [←pow_add,add_self_div_two] using hh
lemma palindrome_high_full_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/500) :
finiteMean (fun ω : BenesCoins d => q^(palindromeFamilyCost H n d e ω+
palindromeFamilyCost (2*H) n d e ω)) ≤ Real.exp (Fintype.card ι*heightDecay H) := by
rw [finiteMean_prod,finiteMean_comm]
calc
_ ≤ finiteMean (fun _X : SwitchIndex d → Bool => Real.exp (Fintype.card ι*heightDecay H)) := by
apply finiteMean_mono
intro X
exact palindrome_high_mgf H n d hH e X q hq hlog
_ = _ := finiteMean_const _
theorem palindrome_cost_mgf_cutoff (r H : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι]
(e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000)
(hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H) ≤ 1/2) :
finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeCost (H+r) e ω)) ≤
Real.exp (((2:ℝ)^r*(2*((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H))^2)+
Fintype.card ι*heightDecay H)/2) := by
let d := H+r
have hd : d ≤ H*4^d := by
have hh := pow_four_ge d
nlinarith
have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost H d e ω+
(palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω) := by
have hh := palindromeCost_family H d d e ω
rw [palindromeLowCost_eq _ _ hd] at hh
simpa only [Nat.add_assoc] using hh.symm
have hq2 := one_le_pow₀ (n:=2) hq
have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith
have hlow := palindrome_low_mgf r H e (q^2) hq2 hr
have hhigh := palindrome_high_full_mgf H d d hH e (q^2) hq2 hlog2
have hh := finiteMean_mul_exp_le (fun ω : BenesCoins d => q^(palindromeLowCost H d e ω))
(fun ω : BenesCoins d => q^(palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω))
_ _ (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh)
change finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ _
simpa only [hcost,pow_add,pow_right_comm] using hh
lemma cutoffMass_le (H d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (ω : BenesCoins d) :
cutoffMass H d e ω ≤ Fintype.card ι := by
classical
induction d generalizing ι with
| zero => exact Nat.zero_le _
| succ d ih =>
rw [cutoffMass]
split_ifs
· exact crowdedMass_le _
· exact (Nat.add_le_add (ih _ _) (ih _ _)).trans_eq (PairRouting.color_card_add _)
lemma palindromeLowCost_le (H d : ℕ) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLowCost H d e ω ≤ H*Fintype.card ι :=
(palindromeLowCost_le_cutoff H d e ω).trans (Nat.mul_le_mul_left H (cutoffMass_le H d e ω))
theorem palindrome_cost_mgf_coarse (d : ℕ) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) :
finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤
Real.exp (Fintype.card ι*(1+heightDecay 1)) := by
have hd : d ≤ 1*4^d := by have hh := pow_four_ge d; omega
have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost 1 d e ω+
(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω) := by
have hh := palindromeCost_family 1 d d e ω
rw [palindromeLowCost_eq _ _ hd] at hh
simpa only [Nat.add_assoc] using hh.symm
have hq2 := one_le_pow₀ (n:=2) hq
have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith
have hlow : finiteMean (fun ω : BenesCoins d => (q^2)^(palindromeLowCost 1 d e ω)) ≤
Real.exp (Fintype.card ι) := by
calc
_ ≤ finiteMean (fun _ω : BenesCoins d => (q^2)^(Fintype.card ι)) := by
apply finiteMean_mono
intro ω
apply pow_le_pow_right₀ hq2
simpa only [one_mul] using palindromeLowCost_le 1 d e ω
_ = (q^2)^(Fintype.card ι) := finiteMean_const _
_ = Real.exp (Fintype.card ι * Real.log (q^2)) := by
rw [Real.exp_nat_mul,Real.exp_log (by positivity : 0<q^2)]
_ ≤ _ := Real.exp_le_exp.mpr (by
have hh := mul_le_mul_of_nonneg_left hlog2 (Nat.cast_nonneg (Fintype.card ι) : (0:ℝ)≤_)
nlinarith [Nat.cast_nonneg (α:=ℝ) (Fintype.card ι)])
have hhigh := palindrome_high_full_mgf 1 d d (by decide) e (q^2) hq2 hlog2
have hh := finiteMean_mul_exp_le (fun ω : BenesCoins d => q^(palindromeLowCost 1 d e ω))
(fun ω : BenesCoins d => q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω))
(Fintype.card ι) (Fintype.card ι*heightDecay 1)
(by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh)
simp only [←pow_add,←hcost] at hh
apply hh.trans (Real.exp_le_exp.mpr _)
have hk : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _
have hD := heightDecay_nonneg 1
nlinarith
noncomputable def momentBase : ℝ := (2:ℝ)^(1/1000:ℝ)
lemma momentBase_one_le : 1 ≤ momentBase := by
exact Real.one_le_rpow (by norm_num) (by norm_num)
lemma momentBase_log : Real.log momentBase ≤ 1/1000 := by
rw [momentBase,Real.log_rpow (by norm_num)]
have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2)
norm_num at hh ⊢
linarith
lemma momentBase_pow (c : ℕ) : momentBase^c = (2:ℝ)^((c:ℝ)*(1/1000:ℝ)) := by
rw [mul_comm,Real.rpow_mul_natCast (by norm_num)]
rfl
lemma palindromeRowMoment_le_cost (d : ℕ) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) :
palindromeRowMoment d e (1/1000) ≤
finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) := by
have hn : (0:ℝ) < ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity
have hn0 : (0:ℝ) ≤ ((2^d).descFactorial (Fintype.card ι):ℝ) /
((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity
have hn1 : ((2^d).descFactorial (Fintype.card ι):ℝ) /
((2^d:ℕ):ℝ)^(Fintype.card ι) ≤ 1 := by
apply (div_le_one hn).mpr
exact_mod_cast Nat.descFactorial_le_pow (2^d) (Fintype.card ι)
have hpow := Real.rpow_le_one hn0 hn1 (by norm_num : (0:ℝ)≤1/1000)
have hm := palindrome_row_density_moment d e (1/1000) (by norm_num)
simp_rw [←momentBase_pow] at hm
exact hm.trans (mul_le_of_le_one_left (finiteMean_nonneg (fun _ =>
pow_nonneg (le_trans (by norm_num) momentBase_one_le) _)) hpow)
theorem palindrome_row_moment_coarse (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) :
palindromeRowMoment d e (1/1000) ≤ Real.exp (Fintype.card ι*(1+heightDecay 1)) :=
(palindromeRowMoment_le_cost d e).trans
(palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log)
noncomputable def densityCutoff (p : ℝ) : ℕ := ⌊-Real.log p/(4*Real.log 2)⌋₊
lemma log_small_density {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) :
Real.log p ≤ -8*Real.log 2 := by
have he : Real.log (1/256:ℝ) = -8*Real.log 2 := by
rw [show (1/256:ℝ) = 1/2^8 by norm_num,
Real.log_div (by norm_num) (by positivity),Real.log_one,Real.log_pow]
ring
exact (Real.log_le_log hp hs).trans_eq he
lemma densityCutoff_bounds {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) :
0 < densityCutoff p ∧
(densityCutoff p:ℝ)*(4*Real.log 2) ≤ -Real.log p ∧
-Real.log p < ((densityCutoff p:ℝ)+1)*(4*Real.log 2) := by
have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num)
have hd : 0 < 4*Real.log 2 := by positivity
have hh := log_small_density hp hs
have hx : 1 ≤ -Real.log p/(4*Real.log 2) := by
apply (le_div_iff₀ hd).mpr
nlinarith
refine ⟨Nat.floor_pos.mpr hx,?_,?_⟩
· exact (le_div_iff₀ hd).mp (Nat.floor_le (by linarith : 0 ≤ -Real.log p/(4*Real.log 2)))
· exact (div_lt_iff₀ hd).mp (Nat.lt_floor_add_one (-Real.log p/(4*Real.log 2)))
lemma densityCutoff_decay {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) :
Real.exp (-(densityCutoff p:ℝ)/64) ≤ Real.exp (1/64) * p^(1/512:ℝ) := by
have hh := (densityCutoff_bounds hp hs).2.2
have hb : Real.log 2 ≤ 2 := by
have := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2)
linarith
have hH : 0 ≤ (densityCutoff p:ℝ)+1 := by positivity
have hu := mul_le_mul_of_nonneg_left hb hH
rw [Real.rpow_def_of_pos hp,←Real.exp_add]
apply Real.exp_le_exp.mpr
nlinarith
lemma densityCutoff_power {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256)
(hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (n : ℕ) (hn : n ≤ 4)
(hq1 : 1 ≤ q) :
p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) ≤ p^(1/2:ℝ) := by
have hcut := (densityCutoff_bounds hp hs).2.1
have hH : 0 ≤ (densityCutoff p:ℝ) := Nat.cast_nonneg _
have hn' : (n:ℝ) ≤ 4 := by exact_mod_cast hn
have hln := Real.log_nonneg hq1
have hl := mul_le_mul_of_nonneg_right hn' hln
have hnl : (n:ℝ)*Real.log q ≤ Real.log 2 := by linarith
have hm := mul_le_mul_of_nonneg_left hnl hH
have heq : p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) =
Real.exp (Real.log p+(densityCutoff p:ℝ)*Real.log 2+
(n*densityCutoff p:ℕ)*Real.log q) := by
rw [Real.exp_add,Real.exp_add,Real.exp_nat_mul,Real.exp_nat_mul,
Real.exp_log hp,Real.exp_log hq,Real.exp_log (by norm_num : (0:ℝ)<2)]
rw [heq,Real.rpow_def_of_pos hp]
apply Real.exp_le_exp.mpr
push_cast
nlinarith
lemma densityCutoff_sparse {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256)
(hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (hq1 : 1 ≤ q) :
(2:ℝ)^(densityCutoff p)*(p*(q^2)^(densityCutoff p)) ≤ 1/2 := by
have hh := densityCutoff_power hp hs hq hlog 2 (by decide) hq1
rw [←pow_mul] at ⊢
have hle : p^(1/2:ℝ) ≤ 1/2 := by
have hlogp := log_small_density hp hs
have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num)
rw [Real.rpow_def_of_pos hp]
calc
_ ≤ Real.exp (-Real.log 2) := by apply Real.exp_le_exp.mpr; nlinarith
_ = 1/2 := by rw [Real.exp_neg,Real.exp_log (by norm_num : (0:ℝ)<2)]; norm_num
nlinarith [hh.trans hle]
lemma momentBase_log_exact : Real.log momentBase = Real.log 2/1000 := by
rw [momentBase,Real.log_rpow (by norm_num)]
ring
lemma densityCutoff_le_height (d k : ℕ) (hk : 0 < k) :
densityCutoff ((k:ℝ)/(2:ℝ)^d) ≤ d := by
have hk' : (1:ℝ) ≤ k := by exact_mod_cast hk
have hp : 0 < (k:ℝ)/(2:ℝ)^d := by positivity
have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num)
have hlogk := Real.log_nonneg hk'
by_cases hx : 0 ≤ -Real.log ((k:ℝ)/(2:ℝ)^d)/(4*Real.log 2)
· have hh := (le_div_iff₀ (by positivity : 0 < 4*Real.log 2)).mp (Nat.floor_le hx)
have hd : (0:ℝ) ≤ d := Nat.cast_nonneg _
have hH : (0:ℝ) ≤ densityCutoff ((k:ℝ)/(2:ℝ)^d) := Nat.cast_nonneg _
change (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ)*(4*Real.log 2) ≤ -Real.log ((k:ℝ)/(2:ℝ)^d) at hh
rw [Real.log_div (by positivity) (by positivity),Real.log_pow] at hh
have hle : (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ) ≤ d := by nlinarith
exact_mod_cast hle
· have hz := Nat.floor_of_nonpos (le_of_not_ge hx)
simp only [densityCutoff,hz,Nat.zero_le]
noncomputable def densityTailConstant : ℝ :=
68*Real.exp (1/64)/(1-Real.exp (-(1:ℝ)/64))
lemma densityTailConstant_nonneg : 0 ≤ densityTailConstant := by
have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0)
apply div_nonneg (by positivity) (by linarith)
lemma heightDecay_cutoff {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) :
heightDecay (densityCutoff p) ≤ densityTailConstant*p^(1/512:ℝ) := by
have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by
have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0)
linarith
have hh := div_le_div_of_nonneg_right
(mul_le_mul_of_nonneg_left (densityCutoff_decay hp hs) (by norm_num : (0:ℝ)≤68)) hden
simpa only [heightDecay,densityTailConstant,mul_assoc,div_mul_eq_mul_div] using hh
lemma sparse_low_algebra (r H k : ℕ) (q : ℝ) :
(2:ℝ)^r*(2*((2:ℝ)^H*(((k:ℝ)/(2:ℝ)^(H+r))*(q^2)^H))^2) =
2*k*(((k:ℝ)/(2:ℝ)^(H+r))*(2:ℝ)^H*q^(4*H)) := by
rw [pow_add,←pow_mul,show 4*H = (2*H)*2 by omega,pow_mul]
have hH : (2:ℝ)^H ≠ 0 := by positivity
have hr : (2:ℝ)^r ≠ 0 := by positivity
field_simp
ring
lemma palindrome_row_moment_small (d : ℕ) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (hk : 0 < Fintype.card ι)
(hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256) :
palindromeRowMoment d e (1/1000) ≤
Real.exp (Fintype.card ι*(1+densityTailConstant)*
((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by
generalize hpdef : ((Fintype.card ι:ℝ)/(2:ℝ)^d) = p at hs ⊢
have hp : 0 < p := by rw [←hpdef]; positivity
have hle := densityCutoff_le_height d (Fintype.card ι) hk
rw [hpdef] at hle
obtain ⟨r,hr⟩ := Nat.exists_eq_add_of_le hle
subst d
have hH := (densityCutoff_bounds hp hs).1
have hq := momentBase_one_le
have hqp : 0 < momentBase := by linarith
have hlog : Real.log momentBase ≤ Real.log 2/4 := by
rw [momentBase_log_exact]
have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num)
linarith
have hsp := densityCutoff_sparse hp hs hqp hlog hq
rw [←hpdef] at hsp
have hh := palindrome_cost_mgf_cutoff r (densityCutoff p) hH e momentBase hq momentBase_log
(by simpa only [hpdef] using hsp)
apply (palindromeRowMoment_le_cost _ e).trans (hh.trans (Real.exp_le_exp.mpr _))
rw [sparse_low_algebra,hpdef]
have hlow := densityCutoff_power hp hs hqp hlog 4 (by decide) hq
have hp1 : p ≤ 1 := by linarith
have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1/2)
have hlow' := mul_le_mul_of_nonneg_left (hlow.trans he)
(by positivity : (0:ℝ)≤2*Fintype.card ι)
have hhigh := mul_le_mul_of_nonneg_left (heightDecay_cutoff hp hs)
(Nat.cast_nonneg (Fintype.card ι): (0:ℝ)≤_)
have hnon : 0 ≤ Fintype.card ι*densityTailConstant*p^(1/512:ℝ) :=
mul_nonneg (mul_nonneg (Nat.cast_nonneg _) densityTailConstant_nonneg)
(Real.rpow_nonneg (le_of_lt hp) _)
nlinarith
noncomputable def densityConstant : ℝ :=
256*(1+heightDecay 1)+1+densityTailConstant
lemma densityConstant_pos : 0 < densityConstant := by
dsimp [densityConstant]
have hh := heightDecay_nonneg 1
have ht := densityTailConstant_nonneg
linarith
theorem palindrome_row_moment_bound (d : ℕ) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (hk : 0 < Fintype.card ι) :
palindromeRowMoment d e (1/1000) ≤ Real.exp (densityConstant*Fintype.card ι*
((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by
have hp : 0 < (Fintype.card ι:ℝ)/(2:ℝ)^d := by positivity
have hp1 : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1 := by
apply (div_le_one (by positivity)).mpr
have h := Fintype.card_le_of_injective e e.injective
rw [card_positions] at h
exact_mod_cast h
have hk0 : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _
have hpow := Real.rpow_nonneg (le_of_lt hp) (1/512:ℝ)
by_cases hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256
· apply (palindrome_row_moment_small d e hk hs).trans (Real.exp_le_exp.mpr _)
have hD : 1+densityTailConstant ≤ densityConstant := by
dsimp [densityConstant]
have := heightDecay_nonneg 1
linarith
have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hD hk0) hpow
nlinarith
· have hlow : (1:ℝ)/256 ≤ ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by
have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1)
rw [Real.rpow_one] at he
exact (le_of_not_ge hs).trans he
have hD : 256*(1+heightDecay 1) ≤ densityConstant := by
dsimp [densityConstant]
have := densityTailConstant_nonneg
linarith
apply (palindrome_row_moment_coarse d e).trans (Real.exp_le_exp.mpr _)
have hD0 : 0 ≤ 1+heightDecay 1 := by have := heightDecay_nonneg 1; linarith
have ha := mul_le_mul_of_nonneg_left hlow (mul_nonneg (by norm_num : (0:ℝ)≤256) hD0)
have hb := mul_le_mul_of_nonneg_right hD hpow
have hc := mul_le_mul_of_nonneg_right (ha.trans hb) hk0
nlinarith
lemma palindromeRowMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (a : ℝ) : 0 ≤ palindromeRowMoment d e a := by
apply finiteMean_nonneg
intro f
exact Real.rpow_nonneg (mul_nonneg (Nat.cast_nonneg _)
(PairRouting.tupleProbability_nonneg _ _ _)) _
theorem palindrome_log_row_moment (d : ℕ) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (hk : 0 < Fintype.card ι) :
Real.log (palindromeRowMoment d e (1/1000)) ≤ densityConstant*Fintype.card ι*
((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by
by_cases hz : palindromeRowMoment d e (1/1000) = 0
· rw [hz,Real.log_zero]
exact mul_nonneg (mul_nonneg (le_of_lt densityConstant_pos) (Nat.cast_nonneg _))
(Real.rpow_nonneg (by positivity) _)
· exact (Real.log_le_iff_le_exp (lt_of_le_of_ne (palindromeRowMoment_nonneg _ _ _) (Ne.symm hz))).mpr
(palindrome_row_moment_bound d e hk)
end Thorp
namespace Thorp.HighHeight
open scoped BigOperators Classical
lemma family_weighted (L n d s : ℕ) (hL : 0<L) (hs : 2*s≤L)
{ι : Type*} [Fintype ι] (x : ι ↪ Card d) (X : SwitchIndex d → Bool)
(F : (SwitchIndex d → Bool) → ℝ) (hF : ∀ Y, 0≤F Y) (hA : LayerAdapted d s F)
(q : ℝ) (hq : 1≤q) (hlog : Real.log q≤1/250) :
finiteMean (fun Y => F Y*q^(palindromeFamilyCost L n d x (Y,X))) ≤
finiteMean F*Real.exp (Fintype.card ι*(68*∑ j ∈ Finset.range n,
Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by
induction n with
| zero =>
simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero,
mul_one,mul_zero,Real.exp_zero]
exact le_rfl
| succ n ih =>
let l := L*4^n
have hl : 0<l := Nat.mul_pos hL (pow_pos (by decide) _)
have hLl : L≤l := by dsimp [l]; exact Nat.le_mul_of_pos_right L (by positivity)
have hs' : 2*max s (familyEnd L n)≤l := by
rcases le_total s (familyEnd L n) with h | h
· simpa only [max_eq_right h] using familyEnd_two L n
· simpa only [max_eq_left h] using hs.trans hLl
have hc (Y) : palindromeFamilyCost L (n+1) d x (Y,X)=
palindromeFamilyCost L n d x (Y,X)+palindromeSlabCost l d x (Y,X) :=
Finset.sum_range_succ _ _
have hwt (Y) : 0≤F Y*q^(palindromeFamilyCost L n d x (Y,X)) :=
mul_nonneg (hF Y) (pow_nonneg (by linarith) _)
have had : LayerAdapted d (max s (familyEnd L n))
(fun Y => F Y*q^(palindromeFamilyCost L n d x (Y,X))) := by
intro Y Y' hh
dsimp only
rw [hA Y Y' (agreeThrough_mono (le_max_left _ _) hh)]
congr 2
exact palindromeFamilyCost_adapted L n d x X Y Y' (agreeThrough_mono (le_max_right _ _) hh)
have hm : finiteMean (fun Y => F Y*q^(palindromeFamilyCost L (n+1) d x (Y,X))) ≤
finiteMean (fun Y => F Y*q^(palindromeFamilyCost L n d x (Y,X)))*
Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by
by_cases hld : l≤d
· simp_rw [hc,pow_add,←mul_assoc]
simpa only [mul_assoc] using palindrome_slab_adapted_mul_le d (max s (familyEnd L n)) l (by omega)
hl hs' x X _ hwt had q hq hlog
· simp_rw [hc,palindromeSlabCost_gt l d (by omega) x,Nat.add_zero]
exact le_mul_of_one_le_right (finiteMean_nonneg hwt)
(Real.one_le_exp_iff.mpr (by positivity))
refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_
rw [mul_assoc,←Real.exp_add,Finset.sum_range_succ]
congr 2
dsimp [l]
ring
lemma low_switch_height (r s : ℕ) (j : Card r × SwitchIndex s) :
switchHeight (s+r) ((splitSwitch r s).symm (Sum.inl j)) ≤ s := by
induction r with
| zero => exact switchHeight_le s j.2
| succ r ih =>
exact ih (Fin.tail j.1,j.2)
def lowCoins (r s : ℕ) (Y : SwitchIndex (s+r) → Bool) :
Card r × SwitchIndex s → Bool :=
fun j => Y ((splitSwitch r s).symm (Sum.inl j))
lemma lowCoins_adapted (r s : ℕ) : LayerAdapted (s+r) s (lowCoins r s) := by
intro Y Y' hh
funext j
exact hh _ (low_switch_height r s j)
lemma lowCoins_assemble (r s : ℕ) (lo : Card r × SwitchIndex s → Bool)
(hi : Card s × SwitchIndex r → Bool) : lowCoins r s (assembleBits r s lo hi)=lo := by
funext j
simp only [lowCoins,assembleBits_eq,Equiv.apply_symm_apply,Sum.elim_inl]
noncomputable def lowEvent (r s : ℕ) (lo : Card r × SwitchIndex s → Bool)
(Y : SwitchIndex (s+r) → Bool) : ℝ := if lowCoins r s Y=lo then 1 else 0
lemma lowEvent_nonneg (r s : ℕ) (lo : Card r × SwitchIndex s → Bool)
(Y : SwitchIndex (s+r) → Bool) : 0≤lowEvent r s lo Y := by
unfold lowEvent; split_ifs <;> norm_num
lemma lowEvent_adapted (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) :
LayerAdapted (s+r) s (lowEvent r s lo) :=
layerAdapted_comp (lowCoins_adapted r s) (fun v => if v=lo then (1:ℝ) else 0)
lemma lowEvent_mean_mul (r s : ℕ) (lo : Card r × SwitchIndex s → Bool)
(G : (SwitchIndex (s+r) → Bool) → ℝ) :
finiteMean (fun Y => lowEvent r s lo Y*G Y)=
finiteMean (fun hi : Card s × SwitchIndex r → Bool => G (assembleBits r s lo hi))/
(Fintype.card (Card r × SwitchIndex s → Bool):ℝ) := by
rw [finiteMean_split]
simp only [lowEvent,lowCoins_assemble,ite_mul,one_mul,zero_mul,finiteMean]
simp_rw [Finset.sum_ite_irrel,Finset.sum_const_zero,ite_div,zero_div]
simp
lemma lowEvent_mean (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) :
finiteMean (lowEvent r s lo)=1/(Fintype.card (Card r × SwitchIndex s → Bool):ℝ) := by
simpa only [mul_one,finiteMean_const] using lowEvent_mean_mul r s lo (fun _ => 1)
lemma family_partial (L n r s : ℕ) (hL : 0<L) (hs : 2*s≤L)
{ι : Type*} [Fintype ι] (x : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool)
(lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1≤q) (hlog : Real.log q≤1/250) :
finiteMean (fun hi : Card s × SwitchIndex r → Bool =>
q^(palindromeFamilyCost L n (s+r) x (assembleBits r s lo hi,X))) ≤
Real.exp (Fintype.card ι*heightDecay L) := by
have hh:=family_weighted L n (s+r) s hL hs x X (lowEvent r s lo)
(lowEvent_nonneg r s lo) (lowEvent_adapted r s lo) q hq hlog
rw [lowEvent_mean_mul,lowEvent_mean,one_div,mul_comm] at hh
have hp : (0:ℝ)<Fintype.card (Card r × SwitchIndex s → Bool) := by
exact_mod_cast Fintype.card_pos
have hh': _≤Real.exp (Fintype.card ι*(68*∑ j ∈ Finset.range n,
Real.exp (-((L*4^j:ℕ):ℝ)/64))) := (div_le_div_iff_of_pos_right hp).mp hh
apply hh'.trans (Real.exp_le_exp.mpr _)
apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _)
have he:=mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68)
simpa only [heightDecay,mul_div_assoc] using he
lemma highCost_family (J d : ℕ) (hJ : 2≤J) {ι : Type*} [Fintype ι]
(x : ι ↪ Card d) (ω : BenesCoins d) :
highCost J d x ω = palindromeFamilyCost (J-1) d d x ω+
palindromeFamilyCost (2*(J-1)) d d x ω := by
have hd : d≤(J-1)*4^d := by
have hh:=pow_four_ge d
have hp : 1≤J-1 := by omega
nlinarith
have hh:=palindromeCost_family (J-1) d d x ω
rw [palindromeLowCost_eq _ _ hd] at hh
unfold highCost
omega
lemma highCost_levels (J d : ℕ) (hJ : 1≤J) {ι : Type*} [Fintype ι]
(x : ι ↪ Card d) (ω : BenesCoins d) :
highCost J d x ω = ∑ i ∈ Finset.range (d-(J-1)), palindromeLevelCost (J+i) d x ω := by
by_cases hd : J-1≤d
· have he : d=(J-1)+(d-(J-1)) := by omega
have hh := palindromeLowCost_sum d d x ω
rw [palindromeLowCost_eq _ _ le_rfl] at hh
rw [show Finset.range d=Finset.range ((J-1)+(d-(J-1))) by rw [←he],
Finset.sum_range_add] at hh
rw [←palindromeLowCost_sum] at hh
have he' (i : ℕ) : J-1+i+1=J+i := by omega
simp_rw [he'] at hh
unfold highCost
omega
· rw [highCost,palindromeLowCost_eq _ _ (by omega),Nat.sub_self,
Nat.sub_eq_zero_of_le (by omega : d≤J-1),Finset.range_zero,Finset.sum_empty]
lemma high_partial (r s J : ℕ) (hJ : 2≤J) (hs : 2*s<J)
{ι : Type*} [Fintype ι] (x : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool)
(lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1≤q) (hlog : Real.log q≤1/500) :
finiteMean (fun hi : Card s × SwitchIndex r → Bool =>
q^(highCost J (s+r) x (assembleBits r s lo hi,X))) ≤
Real.exp (Fintype.card ι*heightDecay (J-1)) := by
have hq2:=one_le_pow₀ (n:=2) hq
have hlog2 : Real.log (q^2)≤1/250 := by rw [Real.log_pow]; norm_num; linarith
have h₀:=family_partial (J-1) (s+r) r s (by omega) (by omega) x X lo (q^2) hq2 hlog2
have h₁:=family_partial (2*(J-1)) (s+r) r s (by omega) (by omega) x X lo (q^2) hq2 hlog2
have h₁':=h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left
(heightDecay_antitone (show J-1≤2*(J-1) by omega)) (Nat.cast_nonneg _)))
have hh:=finiteMean_mul_exp_le
(fun hi : Card s × SwitchIndex r → Bool =>
q^(palindromeFamilyCost (J-1) (s+r) (s+r) x (assembleBits r s lo hi,X)))
(fun hi : Card s × SwitchIndex r → Bool =>
q^(palindromeFamilyCost (2*(J-1)) (s+r) (s+r) x (assembleBits r s lo hi,X)))
(Fintype.card ι*heightDecay (J-1)) (Fintype.card ι*heightDecay (J-1))
(by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁')
simpa only [highCost_family J _ hJ,←pow_add,add_self_div_two] using hh
lemma high_unconditional (d J : ℕ) (hJ : 2≤J) {ι : Type*} [Fintype ι]
(x : ι ↪ Card d) (q : ℝ) (hq : 1≤q) (hlog : Real.log q≤1/500) :
finiteMean (fun ω : BenesCoins d => q^(highCost J d x ω)) ≤
Real.exp (Fintype.card ι*heightDecay (J-1)) := by
simpa only [highCost_family J _ hJ] using
palindrome_high_full_mgf (J-1) d d (by omega) x q hq hlog
lemma cost_small (d : ℕ) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (hk : 0 < Fintype.card ι)
(hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256) :
finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) ≤
Real.exp (Fintype.card ι*(1+densityTailConstant)*
((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by
generalize hpdef : ((Fintype.card ι:ℝ)/(2:ℝ)^d) = p at hs ⊢
have hp : 0 < p := by rw [←hpdef]; positivity
have hle := densityCutoff_le_height d (Fintype.card ι) hk
rw [hpdef] at hle
obtain ⟨r,hr⟩ := Nat.exists_eq_add_of_le hle
subst d
have hH := (densityCutoff_bounds hp hs).1
have hq := momentBase_one_le
have hqp : 0 < momentBase := by linarith
have hlog : Real.log momentBase ≤ Real.log 2/4 := by
rw [momentBase_log_exact]
have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num)
linarith
have hsp := densityCutoff_sparse hp hs hqp hlog hq
rw [←hpdef] at hsp
have hh := palindrome_cost_mgf_cutoff r (densityCutoff p) hH e momentBase hq momentBase_log
(by simpa only [hpdef] using hsp)
apply hh.trans (Real.exp_le_exp.mpr _)
rw [sparse_low_algebra,hpdef]
have hlow := densityCutoff_power hp hs hqp hlog 4 (by decide) hq
have hp1 : p ≤ 1 := by linarith
have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1/2)
have hlow' := mul_le_mul_of_nonneg_left (hlow.trans he)
(by positivity : (0:ℝ)≤2*Fintype.card ι)
have hhigh := mul_le_mul_of_nonneg_left (heightDecay_cutoff hp hs)
(Nat.cast_nonneg (Fintype.card ι): (0:ℝ)≤_)
have hnon : 0 ≤ Fintype.card ι*densityTailConstant*p^(1/512:ℝ) :=
mul_nonneg (mul_nonneg (Nat.cast_nonneg _) densityTailConstant_nonneg)
(Real.rpow_nonneg (le_of_lt hp) _)
nlinarith
theorem cost_bound_pos (d : ℕ) {ι : Type*} [Fintype ι]
(e : ι ↪ Card d) (hk : 0 < Fintype.card ι) :
finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) ≤ Real.exp (densityConstant*Fintype.card ι*
((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by
have hp : 0 < (Fintype.card ι:ℝ)/(2:ℝ)^d := by positivity
have hp1 : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1 := by
apply (div_le_one (by positivity)).mpr
have h := Fintype.card_le_of_injective e e.injective
rw [card_positions] at h
exact_mod_cast h
have hk0 : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _
have hpow := Real.rpow_nonneg (le_of_lt hp) (1/512:ℝ)
by_cases hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256
· apply (cost_small d e hk hs).trans (Real.exp_le_exp.mpr _)
have hD : 1+densityTailConstant ≤ densityConstant := by
dsimp [densityConstant]
have := heightDecay_nonneg 1
linarith
have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hD hk0) hpow
nlinarith
· have hlow : (1:ℝ)/256 ≤ ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by
have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1)
rw [Real.rpow_one] at he
exact (le_of_not_ge hs).trans he
have hD : 256*(1+heightDecay 1) ≤ densityConstant := by
dsimp [densityConstant]
have := densityTailConstant_nonneg
linarith
apply (palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log).trans (Real.exp_le_exp.mpr _)
have hD0 : 0 ≤ 1+heightDecay 1 := by have := heightDecay_nonneg 1; linarith
have ha := mul_le_mul_of_nonneg_left hlow (mul_nonneg (by norm_num : (0:ℝ)≤256) hD0)
have hb := mul_le_mul_of_nonneg_right hD hpow
have hc := mul_le_mul_of_nonneg_right (ha.trans hb) hk0
nlinarith
lemma cost_bound (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) :
finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) ≤
Real.exp (densityConstant*Fintype.card ι*((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by
by_cases hk : 0<Fintype.card ι
· exact cost_bound_pos d e hk
· have hz : Fintype.card ι=0 := by omega
simpa only [hz,Nat.cast_zero,mul_zero,zero_mul,Real.exp_zero] using
palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log
noncomputable def tailConstant : ℝ :=
68*Real.exp (1/64)/(1-Real.exp (-1/64))
lemma tailConstant_pos : 0<tailConstant := by
have hh:=Real.exp_lt_one_iff.mpr (by norm_num : (-1:ℝ)/64<0)
exact div_pos (by positivity) (by linarith)
lemma decay_bound (J : ℕ) (hJ : 1≤J) :
heightDecay (J-1) ≤ tailConstant*(2:ℝ)^(-(1/1000:ℝ)*J) := by
have hd : 0<1-Real.exp (-1/64:ℝ) := by
have h:=Real.exp_lt_one_iff.mpr (by norm_num : (-1:ℝ)/64<0)
linarith
have hlog : Real.log 2≤1 := by
have hh:=Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2)
norm_num at hh ⊢
exact hh
rw [heightDecay,tailConstant,div_mul_eq_mul_div,mul_assoc,
Real.rpow_def_of_pos (by norm_num : (0:ℝ)<2)]
apply div_le_div_of_nonneg_right _ hd.le
apply mul_le_mul_of_nonneg_left _ (by norm_num : (0:ℝ)≤68)
rw [←Real.exp_add]
apply Real.exp_le_exp.mpr
rw [Nat.cast_sub hJ,Nat.cast_one]
nlinarith [Nat.cast_nonneg (α:=ℝ) J,
mul_le_mul_of_nonneg_right hlog (Nat.cast_nonneg J)]
noncomputable def constant : ℝ := (tailConstant+densityConstant)/Real.log 2
lemma constant_pos : 0<constant := by
exact div_pos (add_pos tailConstant_pos densityConstant_pos) (Real.log_pos (by norm_num))
lemma log_mgf_le {Ω : Type*} [Fintype Ω] [Nonempty Ω] (f : Ω → ℕ) (A : ℝ)
(h : finiteMean (fun ω => momentBase^(f ω))≤Real.exp A) :
Real.log (finiteMean (fun ω => momentBase^(f ω)))≤A := by
apply (Real.log_le_iff_le_exp (finiteMean_pos (fun ω => pow_pos
(lt_of_lt_of_le zero_lt_one momentBase_one_le) _))).mpr h
lemma high_log {Ω : Type*} [Fintype Ω] [Nonempty Ω] (f : Ω → ℕ) (k J : ℕ)
(hJ : 1≤J) (h : finiteMean (fun ω => momentBase^(f ω))≤Real.exp (k*heightDecay (J-1))) :
Real.log (finiteMean (fun ω => momentBase^(f ω)))/Real.log 2 ≤
constant*k*(2:ℝ)^(-(1/1000:ℝ)*J) := by
have hl:=log_mgf_le f _ h
have hp : 0<Real.log 2 := Real.log_pos (by norm_num)
apply (div_le_iff₀ hp).mpr
have hh:=mul_le_mul_of_nonneg_left (decay_bound J hJ) (Nat.cast_nonneg k : (0:ℝ)≤_)
have hinc : (k:ℝ)*tailConstant*(2:ℝ)^(-(1/1000:ℝ)*J) ≤
(tailConstant+densityConstant)*k*(2:ℝ)^(-(1/1000:ℝ)*J) := by
have hnon : 0≤densityConstant*k*(2:ℝ)^(-(1/1000:ℝ)*J) := by
exact mul_nonneg (mul_nonneg densityConstant_pos.le (Nat.cast_nonneg _)) (Real.rpow_nonneg (by norm_num) _)
nlinarith
have hfinal:=hl.trans (hh.trans (by simpa only [mul_assoc] using hinc))
refine hfinal.trans_eq ?_
unfold constant
field_simp
lemma sparse_log (d k : ℕ) (x : Fin k ↪ Card d) :
Real.log (finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d x ω)))/Real.log 2 ≤
constant*k*((k:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by
have h:=log_mgf_le (fun ω : BenesCoins d => palindromeCost d x ω) _ (cost_bound d x)
simp only [Fintype.card_fin] at h
have hp : 0<Real.log 2 := Real.log_pos (by norm_num)
apply (div_le_iff₀ hp).mpr
have hn : 0≤tailConstant*k*((k:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by
exact mul_nonneg (mul_nonneg tailConstant_pos.le (Nat.cast_nonneg _)) (Real.rpow_nonneg (by positivity) _)
unfold constant
field_simp
nlinarith
theorem high_tail : MainStatement := by
refine ⟨1/1000,1/512,constant,by norm_num,by norm_num,constant_pos,2,by decide,?_,?_,?_⟩
· intro d k x J hJ
apply high_log _ k J (by omega)
simpa only [Fintype.card_fin] using high_unconditional d J hJ x momentBase momentBase_one_le
(by have hh:=momentBase_log; linarith)
· intro d k x
exact sparse_log d k x
· intro r s k x J hJ hs X lo
apply high_log _ k J (by omega)
simpa only [Fintype.card_fin] using high_partial r s J hJ hs x X lo momentBase momentBase_one_le
(by have hh:=momentBase_log; linarith)
end Thorp.HighHeight
end ThorpNine.HighTail
end OAI

Xet Storage Details

Size:
44.9 kB
·
Xet hash:
e14511c95af02ceddb982c50ade67acb390022aec88381d5df4c0a2247f32cbb

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.