math / data /lean /OAI /Probability /CriticalPercolation /Exploration /IncidenceIdentity.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
5.05 kB
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