Download data/lean/OAI/Dynamics/ConditionalShuffle/ResetEnergy.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 9.73 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Dynamics/ConditionalShuffle/ResetEnergy.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Dynamics/ConditionalShuffle/ResetEnergy.lean
-
curl -L -o ResetEnergy.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Dynamics/ConditionalShuffle/ResetEnergy.lean
9.73 kB
| import OAI.Dynamics.ConditionalShuffle.OverlayConditioning | |
| namespace OAI | |
| noncomputable section | |
| open scoped BigOperators Classical | |
| open Filter Topology | |
| namespace Thorp.Conditional | |
| theorem halfDensity_after_step_rho (d : β) (v : RawState (d + 1)) | |
| (c : Coins (d + 1)) (h : Bool) | |
| (Ο : β) (hm : Ο * Fintype.card (Position (d + 1)) β€ freeCount v.free) | |
| (hc : freeCount v.free β€ 4 * pairHalfCount (v.free β (splitPosition d).symm) c h) : | |
| (Ο / 2) β€ startHalfDensity d (rawNext d v c) h := by | |
| unfold startHalfDensity | |
| rw [halfCount_after_step] | |
| have hn : Fintype.card (Position (d + 1)) = 2 * Fintype.card (Position d) := by | |
| simp [Fintype.card_pi, Fintype.card_bool, Fintype.card_fin, pow_succ, Nat.mul_comm] | |
| rw [hn, Nat.cast_mul, Nat.cast_ofNat] at hm | |
| have hc' : (freeCount v.free : β) β€ | |
| 4 * (pairHalfCount (v.free β (splitPosition d).symm) c h : β) := by exact_mod_cast hc | |
| apply (le_div_iffβ (by exact_mod_cast Fintype.card_pos (Ξ± := Position d))).mpr | |
| nlinarith | |
| theorem expectedNoise_dimension_rho (d : β) (v : CenteredState (d + 2)) | |
| (Ο : β) (hΟ : 0 < Ο) (hΟβ : Ο β€ 1) | |
| (hm : Ο * Fintype.card (Position (d + 2)) β€ freeCount v.free) : | |
| expectedNoise (d + 1) v (d + 2) β€ (1 - Ο / 2) * expectedEnergy (d + 1) v (d + 2) + | |
| 2 * (9 / 10 : β) ^ freeCount v.free := by | |
| let B := v.free β (splitPosition (d + 1)).symm | |
| let bad (c : Coins (d + 2)) : Prop := | |
| 4 * pairHalfCount B c false < pairFreeCount B β¨ | |
| 4 * pairHalfCount B c true < pairFreeCount B | |
| have hlocal (c : Coins (d + 2)) : | |
| expectedNoise (d + 1) (nextState (d + 1) v c) (d + 1) β€ | |
| (1 - Ο / 2) * expectedEnergy (d + 1) (nextState (d + 1) v c) (d + 1) + | |
| (if bad c then 1 else 0) := by | |
| by_cases hc : bad c | |
| Β· rw [ite_eq_left hc] | |
| have hle := expectedNoise_le_energy (d + 1) (nextState (d + 1) v c) (d + 1) | |
| have hone := expectedEnergy_le_one (d + 1) (nextState (d + 1) v c) (d + 1) | |
| have hnon := expectedEnergy_nonneg (d + 1) (nextState (d + 1) v c) (d + 1) | |
| nlinarith | |
| Β· rw [ite_eq_right hc, add_zero] | |
| have hb (h : Bool) : (Ο / 2) β€ | |
| startHalfDensity (d + 1) (nextState (d + 1) v c).raw h := by | |
| apply halfDensity_after_step_rho (d + 1) v.raw c h Ο hm | |
| have hf : Β¬ 4 * pairHalfCount B c false < freeCount v.free := by | |
| simpa only [B, pairFreeCount_physical] using not_or.mp hc |>.1 | |
| have ht : Β¬ 4 * pairHalfCount B c true < freeCount v.free := by | |
| simpa only [B, pairFreeCount_physical] using not_or.mp hc |>.2 | |
| change freeCount v.free β€ 4 * pairHalfCount B c h | |
| cases h | |
| Β· exact Nat.le_of_not_gt hf | |
| Β· exact Nat.le_of_not_gt ht | |
| convert noise_bound_balanced_state d (nextState (d + 1) v c) (Ο / 2) hb using 1 | |
| have hmean := mean_le_mean hlocal | |
| rw [mean_add, mean_const_mul, β expectedNoise_first, β expectedEnergy_first] at hmean | |
| have hbad := pair_both_half_balance B | |
| have hbad' : mean (fun c : Coins (d + 2) => if bad c then (1 : β) else 0) β€ | |
| 2 * (9 / 10 : β) ^ freeCount v.free := by | |
| change mean (fun c : Position (d + 1) β Bool => if bad c then (1 : β) else 0) β€ _ | |
| simpa only [bad, B, pairFreeCount_physical] using hbad | |
| exact hmean.trans (add_le_add (le_refl _) hbad') | |
| theorem expectedNoise_bound_rho (d : β) (v : CenteredState (d + 2)) | |
| (Ο : β) (hΟ : 0 < Ο) (hΟβ : Ο β€ 1) | |
| (hm : Ο * Fintype.card (Position (d + 2)) β€ freeCount v.free) | |
| (s : β) (hs : d + 2 β€ s) : | |
| expectedNoise (d + 1) v s β€ (1 - Ο / 2) * expectedEnergy (d + 1) v s + | |
| 2 * (9 / 10 : β) ^ freeCount v.free := by | |
| obtain β¨a, rflβ© := Nat.exists_eq_add_of_le hs | |
| rw [Nat.add_comm (d + 2) a, expectedNoise_add, expectedEnergy_add] | |
| have he := mean_le_mean (fun Ο : History (d + 2) a => | |
| expectedNoise_dimension_rho d (iterateState (d + 1) v a Ο) Ο hΟ hΟβ | |
| (by simpa only [iterateState_freeCount] using hm)) | |
| simpa only [iterateState_freeCount, mean_add, mean_const_mul, mean_const] using he | |
| theorem expectedEnergy_decay_rho (d : β) (v : CenteredState (d + 2)) | |
| (Ο : β) (hΟ : 0 < Ο) (hΟβ : Ο β€ 1) | |
| (hm : Ο * Fintype.card (Position (d + 2)) β€ freeCount v.free) (t : β) : | |
| expectedEnergy (d + 1) v t β€ | |
| (1 - Ο / 4) ^ t / (1 - Ο / 4) ^ (2 * (d + 2)) + | |
| (4 / Ο) * (9 / 10 : β) ^ freeCount v.free := by | |
| have he := scalar_decay (d + 2) (expectedEnergy (d + 1) v) | |
| (expectedNoise (d + 1) v) (Ο / 2) (1 - Ο / 4) | |
| (2 * (9 / 10 : β) ^ freeCount v.free) | |
| (by linarith) (by linarith) (by linarith) (by linarith) | |
| (by linarith) (by positivity) (expectedEnergy_le_one (d + 1) v) | |
| (expectedEnergy_recurrence (d + 1) v) | |
| (by intro s hs; exact expectedNoise_bound_rho d v Ο hΟ hΟβ hm s hs) t | |
| convert he using 1 ; ring | |
| def resetS (Ο : β) : β := β320 / Οββ | |
| lemma resetS_large (Ο : β) (hΟ : 0 < Ο) (hΟβ : Ο β€ 1) : 2 β€ resetS Ο := by | |
| have hh := Nat.le_ceil (320 / Ο) | |
| have hdiv : (320 : β) β€ 320 / Ο := (le_div_iffβ hΟ).mpr (by nlinarith) | |
| have : (2 : β) β€ (resetS Ο : β) := by dsimp [resetS]; linarith | |
| exact_mod_cast this | |
| lemma reset_gamma_power (Ο : β) (hΟ : 0 < Ο) (hΟβ : Ο β€ 1) : | |
| (1 - Ο / 4) ^ (2 * resetS Ο - 2) β€ (1/2 : β)^32 := by | |
| have hs := resetS_large Ο hΟ hΟβ | |
| have hc : (320 : β) β€ Ο * (resetS Ο : β) := by | |
| have := (div_le_iffβ hΟ).mp (Nat.le_ceil (320 / Ο)) | |
| dsimp [resetS]; nlinarith | |
| have hcast : ((2 * resetS Ο - 2 : β) : β) = 2 * (resetS Ο : β) - 2 := by | |
| rw [Nat.cast_sub (by omega), Nat.cast_mul]; norm_num | |
| have hbase : 1 - Ο / 4 β€ Real.exp (-Ο / 4) := by | |
| convert Real.add_one_le_exp (-Ο / 4) using 1 ; ring | |
| have ht : -(Ο / 4) * (2 * (resetS Ο : β) - 2) β€ -32 := by nlinarith | |
| have he : Real.exp (-1) β€ (1/2 : β) := by | |
| rw [Real.exp_neg] | |
| apply (inv_le_commβ (Real.exp_pos _) (by norm_num)).mpr | |
| have := Real.add_one_le_exp (1 : β) | |
| norm_num at this β’ | |
| exact this | |
| calc | |
| _ β€ Real.exp (-Ο / 4) ^ (2 * resetS Ο - 2) := | |
| pow_le_pow_leftβ (by linarith) hbase _ | |
| _ = Real.exp (-(Ο / 4) * (2 * (resetS Ο : β) - 2)) := by | |
| rw [β Real.exp_nat_mul, hcast]; congr 1; ring | |
| _ β€ Real.exp (-32) := Real.exp_le_exp.mpr ht | |
| _ = Real.exp (-1) ^ 32 := by rw [β Real.exp_nat_mul]; norm_num | |
| _ β€ _ := pow_le_pow_leftβ (Real.exp_pos _).le he _ | |
| lemma reset_energy_bound (d : β) (v : CenteredState (d + 2)) | |
| (Ο : β) (hΟ : 0 < Ο) (hΟβ : Ο β€ 1) | |
| (hm : Ο * Fintype.card (Position (d + 2)) β€ freeCount v.free) : | |
| expectedEnergy (d + 1) v (2 * resetS Ο * (d + 2)) β€ | |
| (1/2 : β)^(32*(d+2)) + (4 / Ο) * ((9/10 : β)^Ο)^((2 : β)^(d+2)) := by | |
| have hΞ³ : 0 < 1 - Ο / 4 := by linarith | |
| have hs := resetS_large Ο hΟ hΟβ | |
| have he := expectedEnergy_decay_rho d v Ο hΟ hΟβ hm (2 * resetS Ο * (d+2)) | |
| have hp : (1-Ο/4)^(2*resetS Ο*(d+2)) / (1-Ο/4)^(2*(d+2)) = | |
| ((1-Ο/4)^(2*resetS Ο-2))^(d+2) := by | |
| rw [β pow_mul] | |
| have hn : 2*resetS Ο*(d+2) = (2*resetS Ο-2)*(d+2)+2*(d+2) := by | |
| rw [β Nat.add_mul]; congr 1; omega | |
| rw [hn, pow_add, mul_div_cancel_rightβ _ (ne_of_gt (pow_pos hΞ³ _))] | |
| rw [hp] at he | |
| have hpow := pow_le_pow_leftβ (pow_nonneg hΞ³.le _) (reset_gamma_power Ο hΟ hΟβ) (d+2) | |
| rw [pow_mul] | |
| apply he.trans (add_le_add hpow (mul_le_mul_of_nonneg_left ?_ (by positivity))) | |
| rw [β Real.rpow_natCast (9/10 : β), β Real.rpow_natCast ((9/10 : β)^Ο), β Real.rpow_mul (by norm_num : (0 : β) β€ 9/10)] | |
| apply Real.rpow_le_rpow_of_exponent_ge (by norm_num) (by norm_num) | |
| simpa only [card_position] using hm | |
| lemma reset_noise_scaled_tendsto (Ο : β) (hΟ : 0 < Ο) : | |
| Tendsto (fun D : β => (2^D : β)^20 * | |
| ((4/Ο) * ((9/10 : β)^Ο)^((2 : β)^D))) atTop (nhds 0) := by | |
| have ha : 0 β€ (9/10 : β)^Ο := Real.rpow_nonneg (by norm_num) _ | |
| have haβ : (9/10 : β)^Ο < 1 := Real.rpow_lt_one (by norm_num) (by norm_num) hΟ | |
| have hh := ((tendsto_pow_const_mul_const_pow_of_lt_one 20 ha haβ).comp | |
| (tendsto_pow_atTop_atTop_of_one_lt (by norm_num : (1 : β) < 2))).const_mul (4/Ο) | |
| simpa only [Function.comp_def, Nat.cast_pow, Nat.cast_ofNat, mul_zero, | |
| mul_left_comm] using hh | |
| lemma reset_energy_eventually (Ο : β) (hΟ : 0 < Ο) (hΟβ : Ο β€ 1) : | |
| βαΆ d : β in atTop, β v : CenteredState (d+2), | |
| Ο * Fintype.card (Position (d+2)) β€ freeCount v.free β | |
| expectedEnergy (d+1) v (2*resetS Ο*(d+2)) β€ (1/2 : β)^(20*(d+2)) := by | |
| obtain β¨D, hDβ© := eventually_atTop.mp | |
| ((tendsto_order.mp (reset_noise_scaled_tendsto Ο hΟ)).2 (1/2) (by norm_num)) | |
| filter_upwards [eventually_ge_atTop D] with d hd | |
| intro v hm | |
| have hn := (hD (d+2) (by omega)).le | |
| have hlead : (2^(d+2) : β)^20 * (1/2 : β)^(32*(d+2)) β€ 1/2 := by | |
| have he : (2^(d+2) : β)^20 * (1/2 : β)^(32*(d+2)) = (1/2 : β)^(12*(d+2)) := by | |
| rw [β pow_mul, Nat.mul_comm (d+2) 20, pow_mul, pow_mul, β mul_pow, pow_mul] | |
| norm_num | |
| rw [he] | |
| simpa only [pow_one] using pow_le_pow_of_le_one (by norm_num : (0 : β) β€ 1/2) | |
| (by norm_num : (1/2 : β) β€ 1) (show 1 β€ 12*(d+2) by omega) | |
| have he := mul_le_mul_of_nonneg_left (reset_energy_bound d v Ο hΟ hΟβ hm) | |
| (by positivity : (0 : β) β€ (2^(d+2) : β)^20) | |
| have hone : (2^(d+2) : β)^20 * (1/2 : β)^(20*(d+2)) = 1 := by | |
| rw [β pow_mul, Nat.mul_comm (d+2) 20, pow_mul, pow_mul, β mul_pow] | |
| norm_num | |
| apply (mul_le_mul_iff_rightβ (by positivity : (0 : β) < (2^(d+2) : β)^20)).mp | |
| rw [hone]; nlinarith | |
| end Thorp.Conditional | |
| end | |
| end OAI | |