introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
4.76 kB
import Mathlib
import OAI.Probability.CriticalPercolation.Exploration.ClosedFresh
namespace OAI
section
section
noncomputable section
namespace CriticalPercolation.SearchTree
open scoped Classical
open FiniteProduct
variable {E R : Type*}
def queryCount : SearchTree E R β†’ (E β†’ Prop) β†’ β„•
| .done _, _ => 0
| .ask e l r, Ο‰ => 1 + if Ο‰ e then queryCount r Ο‰ else queryCount l Ο‰
def centeredSum (p : ℝ) : SearchTree E R β†’ (E β†’ Prop) β†’ ℝ
| .done _, _ => 0
| .ask e l r, Ο‰ => if Ο‰ e then (1-p)+centeredSum p r Ο‰ else -p+centeredSum p l Ο‰
def truncate : SearchTree E R β†’ β„• β†’ SearchTree E Unit
| _, 0 => .done ()
| .done _, _+1 => .done ()
| .ask e l r, n+1 => .ask e (truncate l n) (truncate r n)
lemma truncate_valid [DecidableEq E] (t : SearchTree E R) (n : β„•) (used : Finset E)
(h : t.Valid used) : (t.truncate n).Valid used := by
induction n generalizing t used with
| zero => simp [truncate,Valid]
| succ n ih =>
cases t with
| done r => trivial
| ask e l r => exact ⟨h.1, ih l _ h.2.1, ih r _ h.2.2⟩
lemma queryCount_truncate_le (t : SearchTree E R) (n : β„•) (Ο‰ : E β†’ Prop) :
(t.truncate n).queryCount Ο‰ ≀ n := by
induction n generalizing t with
| zero => simp [truncate,queryCount]
| succ n ih =>
cases t with
| done r => simp [truncate,queryCount]
| ask e l r =>
simp only [truncate,queryCount]
split_ifs <;> have := ih r <;> have := ih l <;> omega
lemma centeredSum_truncate_eq (t : SearchTree E R) (n : β„•) (Ο‰ : E β†’ Prop)
(h : t.queryCount Ο‰ ≀ n) (p : ℝ) :
(t.truncate n).centeredSum p Ο‰ = t.centeredSum p Ο‰ := by
induction n generalizing t with
| zero =>
cases t with
| done r => rfl
| ask e l r => simp [queryCount] at h
| succ n ih =>
cases t with
| done r => rfl
| ask e l r =>
by_cases he : Ο‰ e
Β· simp only [queryCount,ite_eq_left he] at h
simp only [truncate,centeredSum,ite_eq_left he]
rw [ih r (by omega)]
Β· simp only [queryCount,ite_eq_right he] at h
simp only [truncate,centeredSum,ite_eq_right he]
rw [ih l (by omega)]
variable [Fintype E] [DecidableEq E]
lemma centeredSum_moments (t : SearchTree E R) (used : Finset E) (ht : t.Valid used)
(p : ℝ) (w : E β†’ Prop β†’ ℝ) (hw : βˆ€ e, βˆ‘ b, w e b = 1)
(hf : LazyDFS.Fresh w p used) :
expect w (t.centeredSum p) = 0 ∧
expect w (fun Ο‰ => (t.centeredSum p Ο‰)^2) =
p*(1-p)*expect w (fun Ο‰ => (t.queryCount Ο‰ : ℝ)) := by
induction t generalizing used w with
| done r => simp [centeredSum,queryCount,expect_const w hw]
| ask e l r hl hr =>
have h0 := hl (insert e used) ht.2.1 (pin w e False)
(pin_normalized w hw e False) (LazyDFS.fresh_pin w p used hf e False)
have h1 := hr (insert e used) ht.2.2 (pin w e True)
(pin_normalized w hw e True) (LazyDFS.fresh_pin w p used hf e True)
have he := hf e ht.1
constructor
Β· simp only [centeredSum]
erw [expect_prop_ite]
simp only [expect_add, expect_const _ (pin_normalized w hw e False),
expect_const _ (pin_normalized w hw e True),h0.1,h1.1,he.1,he.2]
ring
Β· have hx : (fun Ο‰ => ((.ask e l r : SearchTree E R).centeredSum p Ο‰)^2) =
(fun Ο‰ => if Ο‰ e then ((1-p)+r.centeredSum p Ο‰)^2
else (-p+l.centeredSum p Ο‰)^2) := by funext Ο‰; simp only [centeredSum]; split_ifs <;> rfl
rw [hx]
erw [expect_prop_ite,
expect_square_add_const _ (pin_normalized w hw e False),
expect_square_add_const _ (pin_normalized w hw e True),h0.1,h1.1,h0.2,h1.2,he.1,he.2]
have hc : (fun Ο‰ => ((.ask e l r : SearchTree E R).queryCount Ο‰ : ℝ)) =
(fun Ο‰ => 1+(if Ο‰ e then (r.queryCount Ο‰ : ℝ) else (l.queryCount Ο‰ : ℝ))) := by
funext Ο‰; simp only [queryCount]; split_ifs <;> simp
rw [hc,expect_add]
erw [expect_prop_ite,expect_const w hw,he.1,he.2]
ring
lemma truncated_second_le (t : SearchTree E R) (used : Finset E) (ht : t.Valid used)
(p : ℝ) (hp : p ∈ Set.Icc 0 1) (w : E β†’ Prop β†’ ℝ)
(hw : βˆ€ e, βˆ‘ b, w e b = 1) (hn : βˆ€ e b, 0 ≀ w e b)
(hf : LazyDFS.Fresh w p used) (n : β„•) :
expect w (fun Ο‰ => ((t.truncate n).centeredSum p Ο‰)^2) ≀ p*(1-p)*n := by
rw [(t.truncate n).centeredSum_moments used (t.truncate_valid n used ht) p w hw hf |>.2]
apply mul_le_mul_of_nonneg_left _ (mul_nonneg hp.1 (sub_nonneg.mpr hp.2))
calc expect w (fun Ο‰ => ((t.truncate n).queryCount Ο‰ : ℝ)) ≀ expect w (fun _ => (n:ℝ)) :=
expect_mono hn (fun Ο‰ => Nat.cast_le.mpr (t.queryCount_truncate_le n Ο‰))
_ = n := expect_const w hw _
end CriticalPercolation.SearchTree
end
end
end
end OAI