File size: 4,761 Bytes
4a56cd6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | 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
|