math / data /lean /OAI /Probability /CriticalPercolation /Modular /CappedDiscrepancy.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
6.83 kB
import Mathlib
import OAI.Probability.CriticalPercolation.ProductMeasure.ExpectClosedFlip
import OAI.Probability.CriticalPercolation.Entropy.BinaryLaw
import OAI.Probability.CriticalPercolation.Modular.ClusterDiscrepancy
namespace OAI
section
section
noncomputable section
open Set
open scoped Classical
namespace CriticalPercolation
lemma capped_gap_nonneg {a b : ℝ} (ha : 0≀a) (hb : 0≀b) :
0 ≀ min a 1 + min b 1 - min (a+b) 1 := by
rcases le_total a 1 with ha1|ha1 <;> rcases le_total b 1 with hb1|hb1
Β· rw [min_eq_left ha1,min_eq_left hb1]
exact sub_nonneg.mpr (min_le_left _ _)
Β· rw [min_eq_left ha1,min_eq_right hb1]
linarith [min_le_right (a+b) 1]
Β· rw [min_eq_right ha1,min_eq_left hb1]
linarith [min_le_right (a+b) 1]
Β· rw [min_eq_right ha1,min_eq_right hb1]
linarith [min_le_right (a+b) 1]
def cappedMass (s m : β„•) : ℝ := min ((m:ℝ)/s) 1
lemma cappedMass_nonneg (s m : β„•) : 0≀cappedMass s m := by
unfold cappedMass
positivity
lemma cappedMass_gap (s a b : β„•) (hs : 0<s) :
(if s≀a ∧ s≀b then (1:ℝ) else 0) ≀
cappedMass s a + cappedMass s b - cappedMass s (a+b) := by
have hs' : 0<(s:ℝ) := Nat.cast_pos.mpr hs
simp only [cappedMass,Nat.cast_add,add_div]
split_ifs with h
Β· have ha : 1 ≀ (a:ℝ)/s := (le_div_iffβ‚€ hs').mpr (by simpa only [one_mul] using (Nat.cast_le.mpr h.1 : (s:ℝ)≀a))
have hb : 1 ≀ (b:ℝ)/s := (le_div_iffβ‚€ hs').mpr (by simpa only [one_mul] using (Nat.cast_le.mpr h.2 : (s:ℝ)≀b))
rw [min_eq_right ha,min_eq_right hb]
linarith [min_le_right ((a:ℝ)/s+(b:ℝ)/s) 1]
Β· exact capped_gap_nonneg (by positivity) (by positivity)
namespace BondGraph
open FiniteProduct
variable {V E : Type*} [Fintype V] (G : BondGraph V E)
def edgeClusterMass (f : β„• β†’ ℝ) (Ο‰ : Set E) (e : E) : ℝ :=
βˆ‘ v, if e ∈ G.incidentEdges (G.cluster Ο‰ v) then G.rootMass f Ο‰ v else 0
lemma edgeClusterMass_insert_gap (f : β„• β†’ ℝ) (Ο‰ : Set E) (e : E) (x y : V)
(he : G.ends e = s(x,y)) :
G.edgeClusterMass f Ο‰ e - G.edgeClusterMass f (insert e Ο‰) e =
if (G.openGraph Ο‰).Reachable x y then 0 else
f (G.clusterSize Ο‰ x) + f (G.clusterSize Ο‰ y) -
f (G.clusterSize Ο‰ x + G.clusterSize Ο‰ y) := by
have hopen : (G.openGraph (insert e Ο‰)).Reachable x y :=
LazyDFS.prop_openEdge_reachable G (insert e Ο‰) (Set.mem_insert e Ο‰) he
simp only [edgeClusterMass,G.sum_incident_rootMass f Ο‰ e x y he,
G.sum_incident_rootMass f (insert e Ο‰) e x y he,ite_eq_left hopen,add_zero]
by_cases hc : (G.openGraph Ο‰).Reachable x y
Β· rw [ite_eq_left hc,G.clusterSize_insert_of_connected Ο‰ e x y he hc]
simp only [ite_eq_left hc,add_zero,sub_self]
Β· rw [ite_eq_right hc,G.clusterSize_insert_of_disconnected Ο‰ e x y he hc,ite_eq_right hc]
lemma capped_edge_gap (Ο‰ : Set E) (e : E) (x y : V) (he : G.ends e = s(x,y))
(s : β„•) (hs : 0<s) :
(if BinaryLaw.endpointEvent G x y s Ο‰ then (1:ℝ) else 0) ≀
G.edgeClusterMass (cappedMass s) Ο‰ e - G.edgeClusterMass (cappedMass s) (insert e Ο‰) e := by
rw [G.edgeClusterMass_insert_gap _ Ο‰ e x y he]
by_cases hc : (G.openGraph Ο‰).Reachable x y
Β· simp [BinaryLaw.endpointEvent,hc]
Β· have hh := cappedMass_gap s (G.clusterSize Ο‰ x) (G.clusterSize Ο‰ y) hs
simp only [BinaryLaw.endpointEvent,hc,not_false_eq_true,true_and,ite_false,clusterSize,
← Set.ncard_eq_toFinset_card'] at hh ⊒
exact hh
variable [Fintype E]
def clusterDiscrepancy (p : ℝ) (Ο‰ : Set E) (v : V) : ℝ :=
βˆ‘ e, if e ∈ G.incidentEdges (G.cluster Ο‰ v) then (if Ο‰ e then -(1-p)/p else 1) else 0
def edgeDiscrepancy (f : β„• β†’ ℝ) (p : ℝ) (Ο‰ : Set E) (e : E) : ℝ :=
(if Ο‰ e then -(1-p)/p else 1) * G.edgeClusterMass f Ο‰ e
lemma expect_edgeDiscrepancy (f : β„• β†’ ℝ) (p : ℝ) (hp : p ∈ Set.Ioo 0 1)
(w : E β†’ Prop β†’ ℝ) (hw : βˆ€ e, βˆ‘ b, w e b=1)
(e : E) (h0 : w e False=1-p) (h1 : w e True=p) :
expect w (fun Ο‰ => G.edgeDiscrepancy f p Ο‰ e) =
expect w (fun Ο‰ => if ¬ω e then
G.edgeClusterMass f Ο‰ e - G.edgeClusterMass f (insert e Ο‰) e else 0) := by
let : DecidableEq E := Classical.decEq E
have hflip := expect_closed_flip_decidable w hw e hp h0 h1 (fun Ο‰ => G.edgeClusterMass f Ο‰ e / p)
have hu (Ο‰ : Set E) : {a | Function.update Ο‰ e True a} = insert e Ο‰ := by
ext a
change Function.update (fun a => Ο‰ a) e True a ↔ a=e ∨ aβˆˆΟ‰
by_cases ha : a=e
Β· subst a; simp [Function.update]
Β· simp only [Function.update_of_ne ha,ha,false_or]; rfl
have hleft : (fun Ο‰ : Set E => if ¬ω e then p*(G.edgeClusterMass f (Function.update Ο‰ e True) e / p) else 0) =
(fun Ο‰ => if ¬ω e then G.edgeClusterMass f (insert e Ο‰) e else 0) := by
funext Ο‰
rw [show (Function.update Ο‰ e True : Set E) = insert e Ο‰ from hu Ο‰]
split_ifs <;> field_simp [hp.1.ne']
erw [hleft] at hflip
have heq (Ο‰ : Set E) : G.edgeDiscrepancy f p Ο‰ e =
(if ¬ω e then G.edgeClusterMass f Ο‰ e else 0) -
(if Ο‰ e then (1-p)*(G.edgeClusterMass f Ο‰ e / p) else 0) := by
change (if Ο‰ e then -(1-p)/p else 1) * G.edgeClusterMass f Ο‰ e = _
by_cases hb : Ο‰ e <;> simp only [hb,ite_true,ite_false,not_true_eq_false,not_false_eq_true,sub_zero,zero_sub,one_mul]
ring
have hfunc : (fun Ο‰ : Set E => G.edgeDiscrepancy f p Ο‰ e) =
(fun Ο‰ => (if ¬ω e then G.edgeClusterMass f Ο‰ e else 0) -
(if Ο‰ e then (1-p)*(G.edgeClusterMass f Ο‰ e / p) else 0)) := funext heq
erw [hfunc]
erw [expect_sub,← hflip,← expect_sub]
congr 1
funext Ο‰
by_cases hb : Ο‰ e <;> simp [hb]
lemma endpoint_prob_le_discrepancy (p : ℝ) (hp : p ∈ Set.Ioo 0 1)
(w : E β†’ Prop β†’ ℝ) (hw : βˆ€ e, βˆ‘ b, w e b=1) (hn : βˆ€ e b, 0≀w e b)
(e : E) (x y : V) (he : G.ends e = s(x,y))
(h0 : w e False=1-p) (h1 : w e True=p) (s : β„•) (hs : 0<s) :
prob w (BinaryLaw.endpointEvent G x y s) ≀
expect w (fun Ο‰ => G.edgeDiscrepancy (cappedMass s) p Ο‰ e) := by
rw [G.expect_edgeDiscrepancy _ p hp w hw e h0 h1]
apply expect_mono hn
intro Ο‰
by_cases hb : Ο‰ e
Β· have hconn : (G.openGraph Ο‰).Reachable x y := LazyDFS.prop_openEdge_reachable G Ο‰ hb he
simp [hb,BinaryLaw.endpointEvent,hconn]
Β· simp only [hb,not_false_eq_true,ite_true]
exact G.capped_edge_gap Ο‰ e x y he s hs
lemma sum_edgeDiscrepancy (f : β„• β†’ ℝ) (p : ℝ) (Ο‰ : Set E) :
(βˆ‘ e, G.edgeDiscrepancy f p Ο‰ e) =
βˆ‘ v, G.rootMass f Ο‰ v * G.clusterDiscrepancy p Ο‰ v := by
simp only [edgeDiscrepancy,edgeClusterMass,clusterDiscrepancy,Finset.mul_sum]
rw [Finset.sum_comm]
apply Finset.sum_congr rfl
intro v _
apply Finset.sum_congr rfl
intro e _
split_ifs <;> ring
end BondGraph
end CriticalPercolation
end
end
end
end OAI