math / data /lean /OAI /Dynamics /ConditionalShuffle /HybridRaw.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
5.83 kB
import OAI.Dynamics.ConditionalShuffle.CycleEnergy
namespace OAI
noncomputable section
open scoped Classical
namespace Thorp.Conditional.Hybrid
def publicHistory {d t : β„•} (s : Fin t β†’ Bool) (Ο‰ : History d t) : Fin t β†’ Option (Coins d) :=
fun i => if s i then none else some (Ο‰ i)
def raw (d : β„•) (v : RawState (d+1)) :
(t : β„•) β†’ (Fin t β†’ Bool) β†’ History (d+1) t β†’ RawState (d+1)
| 0, _, _ => v
| t+1, s, Ο‰ =>
let u := raw d v t (Fin.init s) (Fin.init Ο‰)
if s (Fin.last t) then rawNext d u (Ο‰ (Fin.last t))
else rawPermute u (step (d+1) (Ο‰ (Fin.last t)))
lemma publicHistory_snoc {d t : β„•} (s : Fin t β†’ Bool) (b : Bool)
(Ο‰ : History d t) (c : Coins d) :
publicHistory (Fin.snoc s b) (Fin.snoc Ο‰ c) =
Fin.snoc (publicHistory s Ο‰) (if b then none else some c) := by
funext i
refine Fin.lastCases ?_ (fun j => ?_) i <;> simp [publicHistory]
lemma raw_snoc (d : β„•) (v : RawState (d+1)) (t : β„•) (s : Fin t β†’ Bool) (b : Bool)
(Ο‰ : History (d+1) t) (c : Coins (d+1)) :
raw d v (t+1) (Fin.snoc s b) (Fin.snoc Ο‰ c) =
if b then rawNext d (raw d v t s Ο‰) c else rawPermute (raw d v t s Ο‰) (step (d+1) c) := by
simp only [raw, Fin.init_snoc, Fin.snoc_last]
lemma raw_free (d : β„•) (v : RawState (d+1)) (t : β„•) (s : Fin t β†’ Bool)
(Ο‰ : History (d+1) t) (y) :
(raw d v t s Ο‰).free y = v.free ((run (d+1) t Ο‰).symm y) := by
induction t generalizing y with
| zero => rfl
| succ t ih =>
rw [raw]; split_ifs
Β· change (raw d v t (Fin.init s) (Fin.init Ο‰)).free
((step (d+1) (Ο‰ (Fin.last t))).symm y) = _
rw [ih, run_succ]
rfl
Β· change (raw d v t (Fin.init s) (Fin.init Ο‰)).free
((step (d+1) (Ο‰ (Fin.last t))).symm y) = _
rw [ih, run_succ]
rfl
lemma raw_energy_le (d : β„•) (v : RawState (d+1)) (t : β„•) (s : Fin t β†’ Bool)
(Ο‰ : History (d+1) t) : rawEnergy (raw d v t s Ο‰) ≀ rawEnergy v := by
induction t with
| zero => exact le_rfl
| succ t ih =>
rw [raw]; split_ifs
Β· exact (physicalFlow_energy_le d _ _ _).trans (ih _ _)
Β· rw [rawPermute_energy]; exact ih _ _
lemma permute_test {d : β„•} (v : RawState d) (g : State d) (f : Position d β†’ ℝ) :
(βˆ‘ y, (rawPermute v g).weight y * f y) = βˆ‘ x, v.weight x * f (g x) := by
change (βˆ‘ y, v.weight (g.symm y) * f y) = _
have h := Equiv.sum_comp g (fun y => v.weight (g.symm y) * f y)
simpa only [Equiv.symm_apply_apply] using h.symm
theorem flow_joint {ΞΉ : Type*} (d : β„•) (v : RawState (d+1))
(e : ΞΉ β†’ Position (d+1)) (he : βˆ€ i, v.free (e i) = false)
(t : β„•) (s : Fin t β†’ Bool)
(f : (Fin t β†’ Option (Coins (d+1))) β†’ (Fin (t+1) β†’ ΞΉ β†’ Position (d+1)) β†’ Position (d+1) β†’ ℝ) :
mean (fun Ο‰ : History (d+1) t => βˆ‘ x, v.weight x *
f (publicHistory s Ο‰) (exposedPath (d+1) e t Ο‰) (run (d+1) t Ο‰ x)) =
mean (fun Ο‰ : History (d+1) t => βˆ‘ y, (raw d v t s Ο‰).weight y *
f (publicHistory s Ο‰) (exposedPath (d+1) e t Ο‰) y) := by
induction t with
| zero => simp only [run_zero, raw]; rfl
| succ t ih =>
let b := s (Fin.last t)
let sβ‚€ := Fin.init s
have hs : s = Fin.snoc sβ‚€ b := (Fin.snoc_init_self s).symm
rw [hs]
let F (q : Fin t β†’ Option (Coins (d+1))) (p : Fin (t+1) β†’ ΞΉ β†’ Position (d+1)) (x : Position (d+1)) :=
mean (fun c : Coins (d+1) => f (Fin.snoc q (if b then none else some c))
(Fin.snoc p (step (d+1) c ∘ p (Fin.last t))) (step (d+1) c x))
have hl : mean (fun Ο‰ : History (d+1) (t+1) => βˆ‘ x, v.weight x *
f (publicHistory (Fin.snoc sβ‚€ b) Ο‰) (exposedPath (d+1) e (t+1) Ο‰) (run (d+1) (t+1) Ο‰ x)) =
mean (fun Ο‰ : History (d+1) t => βˆ‘ x, v.weight x *
F (publicHistory sβ‚€ Ο‰) (exposedPath (d+1) e t Ο‰) (run (d+1) t Ο‰ x)) := by
rw [mean_history_succ]
apply mean_congr; intro Ο‰
simp only [publicHistory_snoc, exposedPath_snoc, run_snoc]
rw [mean_sum]
simp_rw [mean_const_mul]
simp only [F, exposedPath_last]
rfl
have hr : mean (fun Ο‰ : History (d+1) (t+1) => βˆ‘ y,
(raw d v (t+1) (Fin.snoc sβ‚€ b) Ο‰).weight y *
f (publicHistory (Fin.snoc sβ‚€ b) Ο‰) (exposedPath (d+1) e (t+1) Ο‰) y) =
mean (fun Ο‰ : History (d+1) t => βˆ‘ y, (raw d v t sβ‚€ Ο‰).weight y *
F (publicHistory sβ‚€ Ο‰) (exposedPath (d+1) e t Ο‰) y) := by
rw [mean_history_succ]
apply mean_congr; intro Ο‰
simp only [raw_snoc, publicHistory_snoc, exposedPath_snoc]
cases hb : b
Β· simp only [Bool.false_eq_true, ite_false]
simp_rw [permute_test]
rw [mean_sum]
simp_rw [mean_const_mul]
simp only [F, hb, Bool.false_eq_true, ite_false, exposedPath_last]
rfl
Β· simp only [ite_true]
change mean (fun c : Position d β†’ Bool => βˆ‘ y,
physicalFlow d (raw d v t sβ‚€ Ο‰).free (raw d v t sβ‚€ Ο‰).weight c y *
f (Fin.snoc (publicHistory sβ‚€ Ο‰) none)
(Fin.snoc (exposedPath (d+1) e t Ο‰) ((step (d+1) c) ∘ ((run (d+1) t Ο‰) ∘ e))) y) = _
rw [physicalFlow_joint d (raw d v t sβ‚€ Ο‰).free (raw d v t sβ‚€ Ο‰).weight
((run (d+1) t Ο‰) ∘ e) (by
intro i
simp only [Function.comp_apply, raw_free, Equiv.symm_apply_apply]
exact he i)
(fun e' y => f (Fin.snoc (publicHistory sβ‚€ Ο‰) none)
(Fin.snoc (exposedPath (d+1) e t Ο‰) e') y)]
rw [mean_sum]
simp_rw [mean_const_mul]
simp only [F, hb, ite_true, exposedPath_last]
rfl
exact hl.trans ((ih sβ‚€ F).trans hr.symm)
end Thorp.Conditional.Hybrid
end
end OAI