Download data/lean/OAI/Probability/CriticalPercolation/Modular/CappedDiscrepancy.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 6.83 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/CriticalPercolation/Modular/CappedDiscrepancy.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/CriticalPercolation/Modular/CappedDiscrepancy.lean
-
curl -L -o CappedDiscrepancy.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/CriticalPercolation/Modular/CappedDiscrepancy.lean
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 | |