introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
17.4 kB
import Mathlib
import OAI.Probability.CriticalPercolation.Exploration.SequentialExposure
import OAI.Probability.CriticalPercolation.Entropy.BinaryInterpolation
import OAI.Probability.CriticalPercolation.Exploration.ReachableIncidenceImp
namespace OAI
section
section
namespace CriticalPercolation.BinaryLaw
open scoped Classical
open FiniteProduct BondGraph BinaryInterpolation
universe uE
def History (E : Type uE) : β„• β†’ Type uE
| 0 => PUnit
| n+1 => History E n Γ— Bool Γ— Option E
instance historyFintype {E : Type*} [Fintype E] : (n : β„•) β†’ Fintype (History E n)
| 0 => inferInstanceAs (Fintype PUnit)
| n+1 => by
letI := historyFintype (E := E) n
exact inferInstanceAs (Fintype (History E n Γ— Bool Γ— Option E))
def interval {E : Type*} (d : β„•) : (n : β„•) β†’ History E n β†’ β„• Γ— β„•
| 0, _ => (0,d)
| n+1, h => bisect (interval d n h.1).1 (interval d n h.1).2 h.2.1
lemma interval_bounds {E : Type*} {d : β„•} (hd : 0<d) (n : β„•) (h : History E n) :
(interval d n h).1 < (interval d n h).2 ∧ (interval d n h).2 ≀ d := by
induction n with
| zero => exact ⟨hd,le_rfl⟩
| succ n ih =>
have hi := ih h.1
have hb := bisect_bounds hi.1 h.2.1
exact ⟨hb.2.1,hb.2.2.trans hi.2⟩
def nextIndex {E : Type*} (d : β„•) (n : β„•) (h : History E n) : β„• :=
if (interval d n h).2 ≀ (interval d n h).1+1 then (interval d n h).1
else midpoint (interval d n h).1 (interval d n h).2
lemma nextIndex_bounds {E : Type*} {d : β„•} (hd : 0<d) (n : β„•) (h : History E n) :
(interval d n h).1 ≀ nextIndex d n h ∧ nextIndex d n h < (interval d n h).2 := by
have hi := (interval_bounds hd n h).1
unfold nextIndex
split_ifs with ht
· exact ⟨le_rfl,hi⟩
Β· have hm := midpoint_strict (by omega : (interval d n h).1+1 < (interval d n h).2)
exact ⟨hm.1.le,hm.2⟩
def anchors {V E : Type*} (d : β„•) (x : β„• β†’ V) : (n : β„•) β†’ History E n β†’ List (V Γ— Bool)
| 0, _ => [(x 0,true),(x d,false)]
| n+1, h => anchors d x n h.1 ++ [(x (nextIndex d n h.1),h.2.1)]
def anchorSet {V E : Type*} (d : β„•) (x : β„• β†’ V) (n : β„•) (h : History E n) : Set V :=
{v | βˆƒ b, (v,b) ∈ anchors d x n h}
lemma anchors_length {V E : Type*} (d : β„•) (x : β„• β†’ V) (n : β„•) (h : History E n) :
(anchors d x n h).length = n+2 := by
induction n with
| zero => rfl
| succ n ih => simp only [anchors,List.length_append,List.length_singleton,ih]
lemma anchorSet_step {V E : Type*} (d : β„•) (x : β„• β†’ V) (n : β„•) (h : History E (n+1)) :
anchorSet d x (n+1) h = insert (x (nextIndex d n h.1)) (anchorSet d x n h.1) := by
ext v
constructor
· rintro ⟨b,hb⟩
rcases List.mem_append.mp hb with hb | hb
· exact Or.inr ⟨b,hb⟩
Β· exact Or.inl (congrArg Prod.fst (List.mem_singleton.mp hb))
· rintro (rfl | ⟨b,hb⟩)
· exact ⟨h.2.1,List.mem_append_right _ (List.mem_singleton_self _)⟩
· exact ⟨b,List.mem_append_left _ hb⟩
lemma endpoint_mem {V E : Type*} {d : β„•} (_hd : 0<d) (x : β„• β†’ V) (n : β„•) (h : History E n) :
x (interval d n h).1 ∈ anchorSet d x n h ∧
x (interval d n h).2 ∈ anchorSet d x n h := by
induction n with
| zero => constructor <;> simp [interval,anchorSet,anchors]
| succ n ih =>
have hi := ih h.1
rw [anchorSet_step]
change x (bisect _ _ _).1 ∈ _ ∧ x (bisect _ _ _).2 ∈ _
unfold bisect
split_ifs with ht hb
· exact ⟨Or.inr hi.1,Or.inr hi.2⟩
Β· have ha : nextIndex d n h.1 = midpoint (interval d n h.1).1 (interval d n h.1).2 := by
rw [nextIndex,ite_eq_right ht]
exact ⟨Or.inl (congrArg x ha.symm),Or.inr hi.2⟩
Β· have ha : nextIndex d n h.1 = midpoint (interval d n h.1).1 (interval d n h.1).2 := by
rw [nextIndex,ite_eq_right ht]
exact ⟨Or.inr hi.1,Or.inl (congrArg x ha.symm)⟩
noncomputable def firstIndex (P : β„• β†’ Prop) : β„• :=
if h : βˆƒ j, P j then Nat.find h else 0
lemma firstIndex_spec {P : β„• β†’ Prop} (h : βˆƒ j, P j) : P (firstIndex P) := by
rw [firstIndex,dite_eq_left h]
exact Nat.find_spec h
lemma firstIndex_le {P : β„• β†’ Prop} {j : β„•} (hj : P j) : firstIndex P ≀ j := by
rw [firstIndex,dite_eq_left ⟨j,hj⟩]
exact Nat.find_min' _ hj
variable {V E : Type*} (G : BondGraph V E)
def parentPredicate (L : List (V Γ— Bool)) (a : V) (Ο‰ : Set E) (m : Option E) (j : β„•) : Prop :=
βˆƒ z, L[j]? = some z ∧ match m with
| none => (G.openGraph Ο‰).Reachable a z.1
| some e => βˆƒ v ∈ G.ends e, (G.openGraph Ο‰).Reachable z.1 v
noncomputable def parent (L : List (V Γ— Bool)) (a : V) (Ο‰ : Set E) (m : Option E) : β„• :=
firstIndex (parentPredicate G L a Ο‰ m)
noncomputable def side (L : List (V Γ— Bool)) (a : V) (Ο‰ : Set E) (m : Option E) : Bool :=
((L[parent G L a Ο‰ m]?).getD (a,true)).2
lemma parentPredicate_congr (L : List (V Γ— Bool)) (S : Set V) (a : V)
(hL : βˆ€ z ∈ L, z.1 ∈ S) (ha : a ∈ S) (Ο‰ Ξ· : Set E)
(h : G.clusterObject Ο‰ S = G.clusterObject Ξ· S) (m : Option E) (j : β„•) :
parentPredicate G L a Ο‰ m j ↔ parentPredicate G L a Ξ· m j := by
have hr (v : V) (hv : v ∈ S) (u : V) :
(G.openGraph Ο‰).Reachable v u ↔ (G.openGraph Ξ·).Reachable v u := by
apply G.reachable_incidence_congr
rintro e ⟨r,her,hvr⟩
have hib : (G.clusterObject Ο‰ S).2 e ↔ (G.clusterObject Ξ· S).2 e := by rw [h]
have hei : e ∈ G.incidentEdges (G.clusterObject Ο‰ S).1 := ⟨r,⟨v,hv,hvr⟩,her⟩
have hei' : e ∈ G.incidentEdges (G.clusterObject Ξ· S).1 := h β–Έ hei
change (Ο‰ e ∧ e ∈ G.incidentEdges (G.clusterObject Ο‰ S).1) ↔
(η e ∧ e ∈ G.incidentEdges (G.clusterObject η S).1) at hib
simpa only [hei,hei',and_true] using hib
unfold parentPredicate
apply exists_congr
intro z
by_cases hz : L[j]? = some z
· have hzmem : z ∈ L := List.mem_of_getElem? hz
simp only [hz,true_and]
cases m with
| none => exact hr a ha z.1
| some e => exact exists_congr (fun v => and_congr_right (fun _ => hr z.1 (hL z hzmem) v))
Β· simp only [hz,false_and]
lemma side_record (L : List (V Γ— Bool)) (S : Set V) (a : V)
(hL : βˆ€ z ∈ L, z.1 ∈ S) (ha : a ∈ S) (Ο‰ Ξ· : Set E)
(h : G.clusterObject Ο‰ S = G.clusterObject Ξ· S) (m : Option E) :
side G L a Ο‰ m = side G L a Ξ· m := by
have he : parentPredicate G L a Ο‰ m = parentPredicate G L a Ξ· m :=
funext (fun j => propext (parentPredicate_congr G L S a hL ha Ο‰ Ξ· h m j))
simp only [side,parent,he]
section Density
variable [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E]
variable (order : List (LazyDFS.Dart V E)) (d : β„•) (x : β„• β†’ V)
variable (p : ℝ) (w : E β†’ Prop β†’ ℝ) (rβ‚€ : (E β†’ Prop) β†’ ℝ)
noncomputable def density : (n : β„•) β†’ History E n β†’ (E β†’ Prop) β†’ ℝ
| 0, _, Ο‰ => rβ‚€ Ο‰
| n+1, h, Ο‰ =>
if side G (anchors d x n h.1) (x (nextIndex d n h.1)) Ο‰ h.2.2 = h.2.1 then
density n h.1 Ο‰ * G.contactKernel order (anchorSet d x n h.1)
(x (nextIndex d n h.1)) p w (G.clusterObject Ο‰ (anchorSet d x n h.1)) Ο‰ h.2.2
else 0
lemma density_nonneg (hp : p ∈ Set.Ioo 0 1) (h0 : βˆ€ e, w e False = 1-p)
(h1 : βˆ€ e, w e True = p) (hrβ‚€ : βˆ€ Ο‰, 0 ≀ rβ‚€ Ο‰) (n : β„•) (h : History E n)
(Ο‰ : E β†’ Prop) : 0 ≀ density G order d x p w rβ‚€ n h Ο‰ := by
induction n with
| zero => exact hrβ‚€ Ο‰
| succ n ih =>
rw [density]
split_ifs
Β· exact mul_nonneg (ih h.1) (G.contactKernel_nonneg order _ _ hp w h0 h1 _ Ο‰ _)
Β· exact le_rfl
lemma density_record
(hrβ‚€ : βˆ€ Ο‰ Ξ·, G.clusterObject Ο‰ ({x 0,x d} : Set V) =
G.clusterObject Ξ· {x 0,x d} β†’ rβ‚€ Ο‰ = rβ‚€ Ξ·)
(n : β„•) (h : History E n) (Ο‰ Ξ· : E β†’ Prop)
(he : G.clusterObject Ο‰ (anchorSet d x n h) = G.clusterObject Ξ· (anchorSet d x n h)) :
density G order d x p w rβ‚€ n h Ο‰ = density G order d x p w rβ‚€ n h Ξ· := by
induction n with
| zero =>
apply hrβ‚€
convert he using 2 <;> ext v <;> simp [anchorSet,anchors,or_comm]
| succ n ih =>
have hST : anchorSet d x n h.1 βŠ† anchorSet d x (n+1) h := by
rw [anchorSet_step]
exact Set.subset_insert _ _
have ha : x (nextIndex d n h.1) ∈ anchorSet d x (n+1) h := by
rw [anchorSet_step]
exact Set.mem_insert _ _
have hs := side_record G (anchors d x n h.1) _ _
(fun z hz => hST ⟨z.2,hz⟩) ha Ο‰ Ξ· he h.2.2
rw [density,density,hs]
split_ifs
Β· rw [ih h.1 (G.clusterObject_refines hST Ο‰ Ξ· he)]
rw [G.contactKernel_record order _ _ _ _ hST ha p w Ο‰ Ξ· he]
Β· rfl
theorem density_normalized (ho : LazyDFS.Exhaustive G order)
(hp : p ∈ Set.Ioo 0 1) (h0 : βˆ€ e, w e False = 1-p) (h1 : βˆ€ e, w e True = p)
(hrβ‚€ : βˆ€ Ο‰ Ξ·, G.clusterObject Ο‰ ({x 0,x d} : Set V) =
G.clusterObject Ξ· {x 0,x d} β†’ rβ‚€ Ο‰ = rβ‚€ Ξ·)
(hZ : expect w rβ‚€ = 1)
(hh : βˆ€ n (h : History E n), 0 < prob w (fun Οƒ => βˆƒ b ∈ anchorSet d x n h,
(G.openGraph Οƒ).Reachable (x (nextIndex d n h)) b)) (n : β„•) :
βˆ‘ h : History E n, expect w (density G order d x p w rβ‚€ n h) = 1 := by
induction n with
| zero =>
change (βˆ‘ _h : PUnit, expect w rβ‚€) = 1
simpa only [Fintype.sum_unique] using hZ
| succ n ih =>
have hs := G.adaptive_marked_step order ho (anchorSet d x n) (anchorSet d x n)
(fun _ => Set.Subset.rfl) (fun h => x (nextIndex d n h)) hp w h0 h1 (hh n)
(density G order d x p w rβ‚€ n)
(fun h Ο‰ Ξ· he => density_record G order d x p w rβ‚€ hrβ‚€ n h Ο‰ Ξ· he)
(fun h Ο‰ m => side G (anchors d x n h) (x (nextIndex d n h)) Ο‰ m)
change (βˆ‘ h : History E n Γ— Bool Γ— Option E, _) = 1
rw [Fintype.sum_prod_type]
calc
_ = βˆ‘ h : History E n, expect w (fun Ο‰ => βˆ‘ m : Option E, βˆ‘ b : Bool,
if side G (anchors d x n h) (x (nextIndex d n h)) Ο‰ m = b then
density G order d x p w rβ‚€ n h Ο‰ * G.contactKernel order (anchorSet d x n h)
(x (nextIndex d n h)) p w (G.clusterObject Ο‰ (anchorSet d x n h)) Ο‰ m else 0) := by
apply Finset.sum_congr rfl
intro h _
rw [Fintype.sum_prod_type]
simp_rw [←expect_sum]
congr 1
funext Ο‰
exact Finset.sum_comm
_ = βˆ‘ h : History E n, expect w (density G order d x p w rβ‚€ n h) := hs
_ = 1 := ih
end Density
lemma base_left_mem {V E : Type*} (d : β„•) (x : β„• β†’ V) (n : β„•) (h : History E n) :
x 0 ∈ anchorSet d x n h := by
induction n with
| zero => exact ⟨true,by simp [anchors]⟩
| succ n ih => rw [anchorSet_step]; exact Or.inr (ih h.1)
lemma root_bound [Fintype E] {d : β„•} (hd : 0<d) (x : β„• β†’ V)
(w : E β†’ Prop β†’ ℝ) (hw : βˆ€ e, βˆ‘ b, w e b = 1) (hn : βˆ€ e b, 0 ≀ w e b)
{c : ℝ} (hc1 : c≀1)
(hc : βˆ€ j, 0<j β†’ j<d β†’ c ≀ prob w (fun Ο‰ => (G.openGraph Ο‰).Reachable (x 0) (x j)))
(n : β„•) (h : History E n) :
c ≀ prob w (fun Ο‰ => βˆƒ b ∈ anchorSet d x n h,
(G.openGraph Ο‰).Reachable (x (nextIndex d n h)) b) := by
let j := nextIndex d n h
have hj : j<d := (nextIndex_bounds hd n h).2.trans_le (interval_bounds hd n h).2
by_cases hj0 : j=0
Β· have he : prob w (fun Ο‰ => βˆƒ b ∈ anchorSet d x n h,
(G.openGraph Ο‰).Reachable (x j) b) = 1 := by
calc
_ = prob w (fun _ => True) := prob_congr w (fun Ο‰ => ⟨fun _ => True.intro,
fun _ => ⟨x 0,base_left_mem d x n h,hj0 β–Έ SimpleGraph.Reachable.refl _⟩⟩)
_ = 1 := prob_true w hw
exact hc1.trans_eq he.symm
Β· exact (hc j (by omega) hj).trans (prob_mono w hn (fun Ο‰ hr =>
⟨x 0,base_left_mem d x n h,hr.symm⟩))
lemma reachable_record {S : Set V} {a b : V} (ha : a ∈ S) {Ο‰ Ξ· : Set E}
(h : G.clusterObject Ο‰ S = G.clusterObject Ξ· S) :
(G.openGraph Ο‰).Reachable a b ↔ (G.openGraph Ξ·).Reachable a b := by
calc
_ ↔ (G.openGraph (G.clusterObject Ο‰ S).2).Reachable a b :=
(G.reachable_clusterObject ha).symm
_ ↔ (G.openGraph (G.clusterObject Ξ· S).2).Reachable a b := by rw [h]
_ ↔ _ := G.reachable_clusterObject ha
lemma cluster_record {S : Set V} {a : V} (ha : a ∈ S) {Ο‰ Ξ· : Set E}
(h : G.clusterObject Ο‰ S = G.clusterObject Ξ· S) : G.cluster Ο‰ a = G.cluster Ξ· a := by
ext b
exact reachable_record G ha h
section Seed
variable [Fintype V] [Fintype E]
def endpointEvent (u v : V) (s : β„•) (Ο‰ : Set E) : Prop :=
Β¬ (G.openGraph Ο‰).Reachable u v ∧
s ≀ (G.cluster Ο‰ u).toFinset.card ∧ s ≀ (G.cluster Ο‰ v).toFinset.card
noncomputable def seed (w : E β†’ Prop β†’ ℝ) (u v : V) (s : β„•) (Ο‰ : E β†’ Prop) : ℝ :=
(prob w (endpointEvent G u v s))⁻¹ * if endpointEvent G u v s Ο‰ then 1 else 0
omit [Fintype E] in
lemma endpointEvent_record (u v : V) (s : β„•) (Ο‰ Ξ· : Set E)
(h : G.clusterObject Ο‰ {u,v} = G.clusterObject Ξ· {u,v}) :
endpointEvent G u v s Ο‰ ↔ endpointEvent G u v s Ξ· := by
unfold endpointEvent
rw [reachable_record G (Set.mem_insert u {v}) h,
cluster_record G (Set.mem_insert u {v}) h,
cluster_record G (Set.mem_insert_of_mem u (Set.mem_singleton v)) h]
lemma seed_record (w : E β†’ Prop β†’ ℝ) (u v : V) (s : β„•) (Ο‰ Ξ· : E β†’ Prop)
(h : G.clusterObject Ο‰ {u,v} = G.clusterObject Ξ· {u,v}) :
seed G w u v s Ο‰ = seed G w u v s Ξ· := by
simp only [seed,endpointEvent_record G u v s Ο‰ Ξ· h]
lemma seed_normalized (w : E β†’ Prop β†’ ℝ) (u v : V) (s : β„•)
(hΞ΄ : 0 < prob w (endpointEvent G u v s)) : expect w (seed G w u v s) = 1 := by
unfold seed
rw [expect_const_mul]
change (prob w (endpointEvent G u v s))⁻¹ * prob w (endpointEvent G u v s) = 1
exact inv_mul_cancelβ‚€ hΞ΄.ne'
lemma seed_nonneg (w : E β†’ Prop β†’ ℝ) (u v : V) (s : β„•)
(hΞ΄ : 0 < prob w (endpointEvent G u v s)) (Ο‰ : E β†’ Prop) : 0 ≀ seed G w u v s Ο‰ := by
unfold seed
apply mul_nonneg (inv_nonneg.mpr hΞ΄.le)
split_ifs <;> norm_num
end Seed
section ExactLaw
variable [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E]
theorem endpoint_density_normalized (order : List (LazyDFS.Dart V E))
(ho : LazyDFS.Exhaustive G order) {d : β„•} (hd : 2≀d) (x : β„• β†’ V)
{p : ℝ} (hp : p ∈ Set.Ioo 0 1) (w : E β†’ Prop β†’ ℝ)
(h0 : βˆ€ e, w e False = 1-p) (h1 : βˆ€ e, w e True = p)
{c : ℝ} (hc : 0<c)
(hconn : βˆ€ j k, j<k β†’ k≀d β†’ k-j<d β†’
c ≀ prob w (fun Ο‰ => (G.openGraph Ο‰).Reachable (x j) (x k)))
(s : β„•) (hΞ΄ : 0 < prob w (endpointEvent G (x 0) (x d) s)) (n : β„•) :
βˆ‘ h : History E n, expect w
(density G order d x p w (seed G w (x 0) (x d) s) n h) = 1 := by
have hw := homogeneous_normalized w p h0 h1
have hn : βˆ€ e b, 0 ≀ w e b := fun e b => (homogeneous_positive w hp h0 h1 e b).le
apply density_normalized G order d x p w _ ho hp h0 h1
(seed_record G w (x 0) (x d) s) (seed_normalized G w (x 0) (x d) s hΞ΄)
intro k h
apply hc.trans_le
exact root_bound G (by omega : 0<d) x w hw hn
((hconn 0 1 (by omega) (by omega) (by omega)).trans (prob_le_one w hw hn _))
(fun j hj hjd => hconn 0 j hj hjd.le (by simpa using hjd)) k h
lemma kernel_parent_exists (order : List (LazyDFS.Dart V E))
(d : β„•) (x : β„• β†’ V) (n : β„•) (h : History E n) (a : V)
(p : ℝ) (w : E β†’ Prop β†’ ℝ) (Ο‰ : E β†’ Prop) (m : Option E)
(hk : G.contactKernel order (anchorSet d x n h) a p w
(G.clusterObject Ο‰ (anchorSet d x n h)) Ο‰ m β‰  0) :
βˆƒ j, parentPredicate G (anchors d x n h) a Ο‰ m j := by
by_cases ha : a ∈ (G.clusterObject Ο‰ (anchorSet d x n h)).1
Β· have hm : m=none := by
by_contra hm
simp only [contactKernel,ite_eq_left ha,ite_eq_right hm] at hk
exact hk rfl
subst m
obtain ⟨v,⟨b,hb⟩,hr⟩ := ha
obtain ⟨j,hj⟩ := List.mem_iff_getElem?.mp hb
exact ⟨j,(v,b),hj,hr.symm⟩
Β· cases m with
| none => simp only [contactKernel,ite_eq_right ha] at hk; exact (hk rfl).elim
| some e =>
have he : e ∈ G.cutEdges (G.clusterObject Ο‰ (anchorSet d x n h)).1 := by
by_contra he
simp only [contactKernel,ite_eq_right ha,contactWeight,ite_eq_right he,zero_div] at hk
exact hk rfl
obtain ⟨u,v,heq,-,z,⟨b,hb⟩,hr⟩ := he
obtain ⟨j,hj⟩ := List.mem_iff_getElem?.mp hb
refine ⟨j,(z,b),hj,v,?_,hr⟩
simp [heq]
omit [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] in
lemma parent_lt_of_exists (L : List (V Γ— Bool)) (a : V) (Ο‰ : Set E) (m : Option E)
(h : βˆƒ j, parentPredicate G L a Ο‰ m j) : parent G L a Ο‰ m < L.length := by
obtain ⟨z,hz,-⟩ := firstIndex_spec h
exact (List.getElem?_eq_some_iff.mp hz).1
lemma density_step_support (order : List (LazyDFS.Dart V E))
(d : β„•) (x : β„• β†’ V) (p : ℝ) (w : E β†’ Prop β†’ ℝ) (rβ‚€ : (E β†’ Prop) β†’ ℝ)
(n : β„•) (h : History E (n+1)) (Ο‰ : E β†’ Prop)
(hr : density G order d x p w rβ‚€ (n+1) h Ο‰ β‰  0) :
density G order d x p w rβ‚€ n h.1 Ο‰ β‰  0 ∧
G.contactKernel order (anchorSet d x n h.1) (x (nextIndex d n h.1)) p w
(G.clusterObject Ο‰ (anchorSet d x n h.1)) Ο‰ h.2.2 β‰  0 ∧
side G (anchors d x n h.1) (x (nextIndex d n h.1)) Ο‰ h.2.2 = h.2.1 := by
rw [density] at hr
split_ifs at hr with hs
· exact ⟨(mul_ne_zero_iff.mp hr).1,(mul_ne_zero_iff.mp hr).2,hs⟩
Β· exact (hr rfl).elim
end ExactLaw
end CriticalPercolation.BinaryLaw
end
end
end OAI