File size: 5,046 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 122 123 124 125 126 127 | import Mathlib
import OAI.Probability.CriticalPercolation.ProductMeasure.QueryMartingale
import OAI.Probability.CriticalPercolation.Exploration.IncidenceSearch
namespace OAI
section
section
noncomputable section
open Set
open scoped Classical
namespace CriticalPercolation.IncidenceSearch
variable {V E : Type*}
def readSum (p : β) (Ο : Set E) (st : State E) : β :=
β e β st.read, if eβΟ then 1-p else -p
lemma compile_trace (G : BondGraph V E) (v : V) (n : β) (st : State E)
(Ο : Set E) (p : β) :
let t := compile G v n st
let out := t.run (fun e => decide (eβΟ))
t.queryCount Ο + st.read.card = out.read.card β§
t.centeredSum p Ο + readSum p Ο st = readSum p Ο out := by
induction n generalizing st with
| zero => simp [compile,SearchTree.run,SearchTree.queryCount,SearchTree.centeredSum]
| succ n ih =>
rw [compile]
split_ifs with h
Β· let e := h.choose
have he : eβst.read := h.choose_spec.1
have hopen := ih (st.open e)
have hclosed := ih (st.closed e)
have hcard : (insert e st.read).card = st.read.card + 1 := Finset.card_insert_of_notMem he
have hsum : readSum p Ο (st.open e) =
(if eβΟ then 1-p else -p)+readSum p Ο st := by
simp only [readSum,State.open,Finset.sum_insert he]
have hsum' : readSum p Ο (st.closed e) =
(if eβΟ then 1-p else -p)+readSum p Ο st := by
simp only [readSum,State.closed,Finset.sum_insert he]
change (let out := if decide (eβΟ) then
(compile G v n (st.open e)).run (fun a => decide (aβΟ)) else
(compile G v n (st.closed e)).run (fun a => decide (aβΟ));
(1 + if Ο e then (compile G v n (st.open e)).queryCount Ο else
(compile G v n (st.closed e)).queryCount Ο) + st.read.card = out.read.card β§
(if Ο e then (1-p)+(compile G v n (st.open e)).centeredSum p Ο else
-p+(compile G v n (st.closed e)).centeredSum p Ο) + readSum p Ο st = readSum p Ο out)
by_cases hΟ : eβΟ
Β· have hΟ' : Ο e := hΟ
simp only [hΟ,hΟ',decide_true,ite_true]
dsimp only at hopen
constructor
Β· have hh := hopen.1
change _ + (insert e st.read).card = _ at hh
rw [hcard] at hh
omega
Β· rw [hsum,ite_eq_left hΟ] at hopen
linarith [hopen.2]
Β· have hΟ' : Β¬Ο e := hΟ
simp only [hΟ,hΟ',decide_false,Bool.false_eq_true,ite_false]
dsimp only at hclosed
constructor
Β· have hh := hclosed.1
change _ + (insert e st.read).card = _ at hh
rw [hcard] at hh
omega
Β· rw [hsum',ite_eq_right hΟ] at hclosed
linarith [hclosed.2]
Β· simp [SearchTree.run,SearchTree.queryCount,SearchTree.centeredSum]
variable [Fintype E]
def tree (G : BondGraph V E) (v : V) : SearchTree E (State E) :=
compile G v (Fintype.card E + 1) β¨β
,β
β©
lemma tree_valid (G : BondGraph V E) (v : V) : (tree G v).Valid β
:=
compile_valid G v _ _
lemma tree_read (G : BondGraph V E) (v : V) (Ο : Set E) :
(((tree G v).run (fun e => decide (eβΟ))).read : Set E) =
G.incidentEdges (G.cluster Ο v) := by
have hg : Good G v Ο (β¨β
,β
β© : State E) := by simp [Good]
have hh := compile_terminal G v Ο (Fintype.card E+1) β¨β
,β
β© hg (by simp)
exact (terminal_cluster G v Ο _ hh.1 hh.2).2
lemma tree_mem_read (G : BondGraph V E) (v : V) (Ο : Set E) (e : E) :
e β ((tree G v).run (fun a => decide (aβΟ))).read β
e β G.incidentEdges (G.cluster Ο v) := by
exact Set.ext_iff.mp (tree_read G v Ο) e
lemma tree_count (G : BondGraph V E) (v : V) (Ο : Set E) :
(tree G v).queryCount Ο = (G.incidentEdges (G.cluster Ο v)).toFinset.card := by
have h := (compile_trace G v (Fintype.card E+1) β¨β
,β
β© Ο (0:β)).1
change (tree G v).queryCount Ο + (β
: Finset E).card =
((tree G v).run (fun e => decide (eβΟ))).read.card at h
simp only [Finset.card_empty,add_zero] at h
refine h.trans (congrArg Finset.card ?_)
ext e
rw [Set.mem_toFinset]
exact tree_mem_read G v Ο e
lemma tree_centered (G : BondGraph V E) (v : V) (Ο : Set E) (p : β) :
(tree G v).centeredSum p Ο = β e,
if eβG.incidentEdges (G.cluster Ο v) then (if eβΟ then 1-p else -p) else 0 := by
have h := (compile_trace G v (Fintype.card E+1) β¨β
,β
β© Ο p).2
change (tree G v).centeredSum p Ο + readSum p Ο β¨β
,β
β© =
readSum p Ο ((tree G v).run (fun e => decide (eβΟ))) at h
simp only [readSum,Finset.sum_empty,add_zero] at h
rw [h]
calc
_ = β e, if eβ((tree G v).run (fun a => decide (aβΟ))).read then
(if eβΟ then 1-p else -p) else 0 := by
simp only [β Finset.sum_filter]
congr 1
ext e
simp only [Finset.mem_filter,Finset.mem_univ,true_and]
_ = _ := by
apply Finset.sum_congr rfl
intro e _
simp only [tree_mem_read]
end CriticalPercolation.IncidenceSearch
end
end
end
end OAI
|