math / data /lean /OAI /Dynamics /ConditionalShuffle /CycleEnergy.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
6.56 kB
import OAI.Dynamics.ConditionalShuffle.PrepEnergy
namespace OAI
noncomputable section
open scoped Classical
namespace Thorp.Conditional
lemma mean_fintype_irrel {Ξ© : Type*} (A B : Fintype Ξ©) (f : Ξ© β†’ ℝ) :
@mean Ξ© A f = @mean Ξ© B f := by
have h : A = B := Subsingleton.elim _ _
cases h
rfl
lemma rawPermute_mass {d : β„•} (v : RawState d) (g : State d) :
(βˆ‘ x, (rawPermute v g).weight x) = βˆ‘ x, v.weight x := Equiv.sum_comp g.symm v.weight
lemma rawPermute_support {d : β„•} (v : RawState d)
(hw : βˆ€ x, v.free x = false β†’ v.weight x = 0) (g : State d) :
βˆ€ x, (rawPermute v g).free x = false β†’ (rawPermute v g).weight x = 0 :=
fun x hx => hw (g.symm x) hx
lemma rawPermute_count {d : β„•} (v : RawState d) (g : State d) :
freeCount (rawPermute v g).free = freeCount v.free := freeCount_comp_equiv v.free g.symm
lemma rawIterate_mass (d : β„•) (v : RawState (d+1)) (t : β„•) (Ο‰ : SweepHistory d t) :
(βˆ‘ x, (rawIterate d v t Ο‰).weight x) = βˆ‘ x, v.weight x := by
induction t with
| zero => rfl
| succ t ih => exact (physicalFlow_sum d _ _ _).trans (ih (Fin.init Ο‰))
lemma rawIterate_support (d : β„•) (v : RawState (d+1))
(hw : βˆ€ x, v.free x = false β†’ v.weight x = 0) (t : β„•) (Ο‰ : SweepHistory d t) :
βˆ€ x, (rawIterate d v t Ο‰).free x = false β†’ (rawIterate d v t Ο‰).weight x = 0 := by
induction t with
| zero => exact hw
| succ t ih => exact physicalFlow_support d _ _ (ih (Fin.init Ο‰)) _
lemma rawIterate_count (d : β„•) (v : RawState (d+1)) (t : β„•) (Ο‰ : SweepHistory d t) :
freeCount (rawIterate d v t Ο‰).free = freeCount v.free := by
have hf : (rawIterate d v t Ο‰).free = v.free ∘ (run (d+1) t Ο‰).symm := by
funext x; exact rawIterate_free d v t Ο‰ x
rw [hf]
exact freeCount_comp_equiv _ _
namespace OverlayEnergy
abbrev Bits (g : β„•) := Position (g+2) β†’ Bool
abbrev Prep9 (g : β„•) := Fin (9*(g+3)) β†’ Bits g
abbrev Prep200 (g : β„•) := Fin (200*(g+3)) β†’ Bits g
abbrev Active (g : β„•) := Fin (g+3) β†’ Bits g
abbrev CycleCoins (g : β„•) := (Prep9 g Γ— Prep200 g) Γ— Active g
def cycle (g : β„•) (v : RawState (g+3)) (Ο‰ : CycleCoins g) : RawState (g+3) :=
rawIterate (g+2)
(rawPermute (rawPermute v (run (g+3) (9*(g+3)) Ο‰.1.1))
(run (g+3) (200*(g+3)) Ο‰.1.2)) (g+3) Ο‰.2
def cyclePerm (g : β„•) (Ο‰ : CycleCoins g) : State (g+3) :=
run (g+3) (g+3) Ο‰.2 * run (g+3) (200*(g+3)) Ο‰.1.2 * run (g+3) (9*(g+3)) Ο‰.1.1
lemma cycle_free (g : β„•) (v : RawState (g+3)) (Ο‰ : CycleCoins g) (y) :
(cycle g v Ο‰).free y = v.free ((cyclePerm g Ο‰).symm y) := by
unfold cycle
erw [rawIterate_free]
simp only [cyclePerm, ← Equiv.Perm.inv_def, mul_inv_rev, Equiv.Perm.coe_mul, Function.comp_apply, rawPermute]
lemma cycle_count (g : β„•) (v : RawState (g+3)) (Ο‰ : CycleCoins g) :
freeCount (cycle g v Ο‰).free = freeCount v.free := by
exact (rawIterate_count (g+2) _ _ _).trans
((rawPermute_count _ _).trans (rawPermute_count v _))
lemma cycle_mass (g : β„•) (v : RawState (g+3)) (Ο‰ : CycleCoins g) :
(βˆ‘ x, (cycle g v Ο‰).weight x) = βˆ‘ x, v.weight x := by
unfold cycle
rw [rawIterate_mass, rawPermute_mass, rawPermute_mass]
lemma cycle_support (g : β„•) (v : RawState (g+3))
(hw : βˆ€ x, v.free x = false β†’ v.weight x = 0) (Ο‰ : CycleCoins g) :
βˆ€ x, (cycle g v Ο‰).free x = false β†’ (cycle g v Ο‰).weight x = 0 :=
rawIterate_support (g+2) _ (rawPermute_support _ (rawPermute_support _ hw _) _) _ _
lemma cycle_energy_le (g : β„•) (v : RawState (g+3)) (Ο‰ : CycleCoins g) :
rawEnergy (cycle g v Ο‰) ≀ rawEnergy v := by
refine (rawIterate_energy_le (g+2) _ _ _).trans_eq ?_
rw [rawPermute_energy, rawPermute_energy]
def coefficient (g : β„•) : ℝ := (255/256 : ℝ)^(g+3) + (2^g : ℝ) *
Real.sqrt ((Fintype.card (Position (g+3)) : ℝ) *
((1/2 : ℝ)^(8*(g+3)) + 32*(9/10 : ℝ)^(2^g)) )
lemma coefficient_nonneg (g : β„•) : 0 ≀ coefficient g := by unfold coefficient; positivity
lemma cycle_expected_energy (g : β„•) (v : RawState (g+3))
(hw : βˆ€ x, v.free x = false β†’ v.weight x = 0) (hz : βˆ‘ x, v.weight x = 0)
(hf : Fintype.card (Position (g+3)) ≀ 64 * freeCount v.free)
(hk : freeCount v.free ≀ 2^g)
(hs : 256*(g+4) ≀ Fintype.card (Position (g+3))) :
mean (fun Ο‰ : CycleCoins g => rawEnergy (cycle g v Ο‰)) ≀
rawEnergy v * coefficient g := by
rw [mean_prod]
change mean (fun Ο‰ : Prep9 g Γ— Prep200 g => mean (fun Ξ· : Active g =>
rawEnergy (cycle g v (Ο‰,Ξ·)))) ≀ _
rw [mean_prod]
apply mean_le_const; intro Ο‰
let u := rawPermute v (run (g+3) (9*(g+3)) Ο‰)
have hN : Fintype.card (Position (g+3)) = 8*2^g := by simp [pow_add]; omega
have hh := prep_sweep_energy (g+1) (2^g) (g+3) (by omega) u
(rawPermute_support v hw _) ((rawPermute_mass v _).trans hz)
(by simpa only [show g+1+2 = g+3 by omega, hN] using (le_refl (8*2^g)))
(by rw [rawPermute_count, hN]; omega)
(by rwa [rawPermute_count]) hs
have he : rawEnergy u = rawEnergy v := rawPermute_energy _ _
have hc : (freeCount u.free : ℝ) ≀ (2^g : ℝ) := by
rw [rawPermute_count]; exact_mod_cast hk
have hE := rawEnergy_nonneg v
have hr : 0 ≀ Real.sqrt ((Fintype.card (Position (g+3)) : ℝ) *
((1/2 : ℝ)^(8*(g+3)) + 32*(9/10 : ℝ)^(2^g))) := Real.sqrt_nonneg _
change mean (fun c : Prep200 g => mean (fun Ξ· : Active g =>
rawEnergy (rawIterate (g+2) (rawPermute u (run (g+3) (200*(g+3)) c)) (g+3) Ξ·))) ≀ _
change _ ≀ rawEnergy v * ((255/256 : ℝ)^(g+3) + (2^g : ℝ) * _)
have hh' : mean (fun c : Prep200 g => mean (fun Ξ· : Active g =>
rawEnergy (rawIterate (g+2) (rawPermute u (run (g+3) (200*(g+3)) c)) (g+3) Ξ·))) ≀
rawEnergy v * ((255/256 : ℝ)^(g+3) + (freeCount u.free : ℝ)*
Real.sqrt ((Fintype.card (Position (g+3)) : ℝ) *
((1/2 : ℝ)^(8*(g+3)) + 32*(9/10 : ℝ)^(2^g)))) := by
have heq : mean (fun c : Prep200 g => mean (fun Ξ· : Active g =>
rawEnergy (rawIterate (g+2) (rawPermute u (run (g+3) (200*(g+3)) c)) (g+3) Ξ·))) =
mean (fun c : History (g+1+2) (200*(g+1+2)) =>
mean (fun Ξ· : SweepHistory (g+1+1) (g+3) =>
rawEnergy (rawIterate (g+1+1) (rawPermute u (run (g+1+2) (200*(g+1+2)) c)) (g+3) Ξ·))) := by
exact mean_fintype_irrel _ _ _
rw [heq]
simpa only [show g+1+2 = g+3 by omega, he] using hh
exact hh'.trans (mul_le_mul_of_nonneg_left
(add_le_add_right (mul_le_mul_of_nonneg_right hc hr) _) hE)
end OverlayEnergy
end Thorp.Conditional
end
end OAI