Download data/lean/OAI/Probability/CriticalPercolation/Entropy/BinaryForest.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 12.3 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/CriticalPercolation/Entropy/BinaryForest.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/CriticalPercolation/Entropy/BinaryForest.lean
-
curl -L -o BinaryForest.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/CriticalPercolation/Entropy/BinaryForest.lean
12.3 kB
| import Mathlib | |
| import OAI.Probability.CriticalPercolation.Entropy.BinarySupport | |
| import OAI.Probability.CriticalPercolation.Exploration.AncestryForest | |
| namespace OAI | |
| section | |
| section | |
| namespace CriticalPercolation.BinaryLaw | |
| open scoped Classical | |
| open FiniteProduct BondGraph BinaryInterpolation InterpolationForest | |
| variable {V E : Type*} (G : BondGraph V E) | |
| noncomputable def nodeParent (d : β) (x : β β V) (Ο : Set E) : | |
| (n : β) β History E n β β β β | |
| | 0, _, i => if i=1 then 1 else 0 | |
| | n+1, h, i => if i=n+2 then | |
| let j := parent G (anchors d x n h.1) (x (nextIndex d n h.1)) Ο h.2.2 | |
| if j<n+2 then j else 0 | |
| else nodeParent d x Ο n h.1 i | |
| lemma nodeParent_lt (d : β) (x : β β V) (Ο : Set E) (n : β) (h : History E n) | |
| (i : β) (hi : 2 β€ i) : nodeParent G d x Ο n h i < i := by | |
| induction n with | |
| | zero => simp only [nodeParent,ite_eq_right (by omega : iβ 1)]; omega | |
| | succ n ih => | |
| by_cases he : i = n+2 | |
| Β· subst i | |
| simp only [nodeParent,ite_true] | |
| split_ifs with hp | |
| Β· exact hp | |
| Β· omega | |
| Β· rw [nodeParent,ite_eq_right he] | |
| exact ih h.1 | |
| noncomputable def historyForest (d : β) (x : β β V) (Ο : Set E) | |
| (n : β) (h : History E n) : Forest := | |
| β¨nodeParent G d x Ο n h, nodeParent_lt G d x Ο n hβ© | |
| lemma nodeParent_old (d : β) (x : β β V) (Ο : Set E) (n : β) (h : History E (n+1)) | |
| (i : β) (hi : i < n+2) : nodeParent G d x Ο (n+1) h i = nodeParent G d x Ο n h.1 i := by | |
| rw [nodeParent,ite_eq_right (by omega : iβ n+2)] | |
| def node (d : β) (x : β β V) (n : β) (h : History E n) (i : β) : V Γ Bool := | |
| (anchors d x n h)[i]?.getD (x 0,true) | |
| lemma node_old (d : β) (x : β β V) (n : β) (h : History E (n+1)) | |
| (i : β) (hi : i < n+2) : node d x (n+1) h i = node d x n h.1 i := by | |
| change ((anchors d x n h.1 ++ [_])[i]?).getD _ = _ | |
| rw [List.getElem?_append_left (by simpa only [anchors_length] using hi)] | |
| rfl | |
| lemma node_current (d : β) (x : β β V) (n : β) (h : History E (n+1)) : | |
| node d x (n+1) h (n+2) = (x (nextIndex d n h.1),h.2.1) := by | |
| unfold node anchors | |
| rw [List.getElem?_append_right (by simp [anchors_length])] | |
| simp only [anchors_length,Nat.sub_self,List.getElem?_cons_zero,Option.getD_some] | |
| lemma node_getElem? (d : β) (x : β β V) (n : β) (h : History E n) (i : β) (hi : i < n+2) : | |
| (anchors d x n h)[i]? = some (node d x n h i) := by | |
| have hil : i<(anchors d x n h).length := by simpa only [anchors_length] using hi | |
| simp only [node,List.getElem?_eq_getElem hil,Option.getD_some] | |
| lemma node_mem (d : β) (x : β β V) (n : β) (h : History E n) (i : β) (hi : i < n+2) : | |
| node d x n h i β anchors d x n h := List.mem_of_getElem? (node_getElem? d x n h i hi) | |
| lemma node_bases (d : β) (x : β β V) (n : β) (h : History E n) : | |
| node d x n h 0 = (x 0,true) β§ node d x n h 1 = (x d,false) := by | |
| induction n with | |
| | zero => exact β¨rfl,rflβ© | |
| | succ n ih => | |
| rw [node_old d x n h 0 (by omega),node_old d x n h 1 (by omega)] | |
| exact ih h.1 | |
| section Support | |
| 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) β β) | |
| lemma nodeParent_current (n : β) (h : History E (n+1)) (Ο : E β Prop) | |
| (hr : density G order d x p w rβ (n+1) h Ο β 0) : | |
| nodeParent G d x Ο (n+1) h (n+2) = | |
| parent G (anchors d x n h.1) (x (nextIndex d n h.1)) Ο h.2.2 := by | |
| have hk := (density_step_support G order d x p w rβ n h Ο hr).2.1 | |
| have hp := parent_lt_of_exists G _ _ Ο _ | |
| (kernel_parent_exists G order d x n h.1 _ p w Ο _ hk) | |
| rw [anchors_length] at hp | |
| simp only [nodeParent,ite_true,ite_eq_left hp] | |
| lemma node_colour_parent (n : β) (h : History E n) (Ο : E β Prop) | |
| (hr : density G order d x p w rβ n h Ο β 0) (i : β) (hi : 2 β€ i) (hin : i < n+2) : | |
| (node d x n h i).2 = (node d x n h (nodeParent G d x Ο n h i)).2 := by | |
| induction n with | |
| | zero => omega | |
| | succ n ih => | |
| obtain β¨hprev,hk,hsβ© := density_step_support G order d x p w rβ n h Ο hr | |
| by_cases he : i=n+2 | |
| Β· subst i | |
| rw [node_current,nodeParent_current G order d x p w rβ n h Ο hr] | |
| have hp := parent_lt_of_exists G _ _ Ο _ | |
| (kernel_parent_exists G order d x n h.1 _ p w Ο _ hk) | |
| rw [anchors_length] at hp | |
| rw [node_old d x n h _ hp] | |
| rw [β hs] | |
| simp only [side,node_getElem? d x n h.1 _ hp,Option.getD_some] | |
| Β· have hio : i < n+2 := by omega | |
| rw [node_old d x n h i hio,nodeParent_old G d x Ο n h i hio, | |
| node_old d x n h _ ((nodeParent_lt G d x Ο n h.1 i hi).trans hio)] | |
| exact ih h.1 hprev hio | |
| lemma node_root_colour (n : β) (h : History E n) (Ο : E β Prop) | |
| (hr : density G order d x p w rβ n h Ο β 0) (i : β) (hin : i < n+2) : | |
| (node d x n h i).2 = if (historyForest G d x Ο n h).root i = 0 then true else false := by | |
| induction i using Nat.strong_induction_on with | |
| | h i ih => | |
| by_cases hi : i < 2 | |
| Β· rw [Forest.root_base _ hi] | |
| have hb := node_bases d x n h | |
| interval_cases i <;> simp only [hb.1,hb.2,ite_true,one_ne_zero,ite_false] | |
| Β· have hi2 : 2 β€ i := by omega | |
| rw [Forest.root_step _ hi2] | |
| rw [node_colour_parent G order d x p w rβ n h Ο hr i hi2 hin] | |
| exact ih _ (nodeParent_lt G d x Ο n h i hi2) | |
| ((nodeParent_lt G d x Ο n h i hi2).trans hin) | |
| end Support | |
| def Canonical (L : List (V Γ Bool)) (Ο : Set E) (i : β) : Prop := | |
| β j z t, j < i β L[j]? = some z β L[i]? = some t β | |
| Β¬(G.openGraph Ο).Reachable z.1 t.1 | |
| lemma parent_canonical (L : List (V Γ Bool)) (a : V) (Ο : Set E) (m : Option E) | |
| (hex : β i, parentPredicate G L a Ο m i) : Canonical G L Ο (parent G L a Ο m) := by | |
| intro j z t hj hz ht hr | |
| have hs := firstIndex_spec hex | |
| obtain β¨v,hv,hpredβ© := hs | |
| have hvt : v=t := Option.some.inj (hv.symm.trans ht) | |
| subst v | |
| have hP : parentPredicate G L a Ο m j := by | |
| refine β¨z,hz,?_β© | |
| cases m with | |
| | none => exact hpred.trans hr.symm | |
| | some e => | |
| obtain β¨u,hu,htuβ© := hpred | |
| exact β¨u,hu,hr.trans htuβ© | |
| have hle := firstIndex_le hP | |
| exact (Nat.not_le_of_gt hj) hle | |
| lemma canonical_append (L M : List (V Γ Bool)) (Ο : Set E) (i : β) (hi : i < L.length) | |
| (hC : Canonical G L Ο i) : Canonical G (L++M) Ο i := by | |
| intro j z t hj hz ht | |
| rw [List.getElem?_append_left (hj.trans hi)] at hz | |
| rw [List.getElem?_append_left hi] at ht | |
| exact hC j z t hj hz ht | |
| lemma canonical_distinct (L : List (V Γ Bool)) (Ο : Set E) (i j : β) | |
| (hi : Canonical G L Ο i) (hj : Canonical G L Ο j) | |
| (z t : V Γ Bool) (hz : L[i]? = some z) (ht : L[j]? = some t) | |
| (hr : (G.openGraph Ο).Reachable z.1 t.1) : i=j := by | |
| rcases lt_trichotomy i j with hij|hij|hij | |
| Β· exact (hj i z t hij hz ht hr).elim | |
| Β· exact hij | |
| Β· exact (hi j t z hij ht hz hr.symm).elim | |
| section CanonicalSupport | |
| 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) β β) | |
| lemma nodeParent_canonical (n : β) (h : History E n) (Ο : E β Prop) | |
| (hr : density G order d x p w rβ n h Ο β 0) | |
| (i : β) (hi : 2 β€ i) (hin : i < n+2) : | |
| Canonical G (anchors d x n h) Ο (nodeParent G d x Ο n h i) := by | |
| induction n with | |
| | zero => omega | |
| | succ n ih => | |
| obtain β¨hprev,hk,hsβ© := density_step_support G order d x p w rβ n h Ο hr | |
| by_cases he : i = n+2 | |
| Β· subst i | |
| rw [nodeParent_current G order d x p w rβ n h Ο hr] | |
| have hex := kernel_parent_exists G order d x n h.1 _ p w Ο _ hk | |
| apply canonical_append | |
| Β· exact parent_lt_of_exists G _ _ Ο _ hex | |
| Β· exact parent_canonical G _ _ Ο _ hex | |
| Β· have hio : i < n+2 := by omega | |
| rw [nodeParent_old G d x Ο n h i hio] | |
| apply canonical_append | |
| Β· rw [anchors_length] | |
| exact (nodeParent_lt G d x Ο n h.1 i hi).trans hio | |
| Β· exact ih h.1 hprev hio | |
| lemma lineage_canonical (n : β) (h : History E n) (Ο : E β Prop) | |
| (hr : density G order d x p w rβ n h Ο β 0) | |
| (j : β) (hjn : j < n+2) (hj : Canonical G (anchors d x n h) Ο j) | |
| (i : β) (hi : i β (historyForest G d x Ο n h).lineage j) : | |
| Canonical G (anchors d x n h) Ο i := by | |
| induction j using Nat.strong_induction_on with | |
| | h j ih => | |
| by_cases hj2 : j < 2 | |
| Β· have he : i=j := by simpa only [Forest.lineage_base _ hj2,List.mem_singleton] using hi | |
| exact he βΈ hj | |
| Β· have hj2' : 2 β€ j := by omega | |
| rw [Forest.lineage_step _ hj2',List.mem_cons] at hi | |
| rcases hi with rfl|hi | |
| Β· exact hj | |
| Β· exact ih _ (nodeParent_lt G d x Ο n h j hj2') | |
| ((nodeParent_lt G d x Ο n h j hj2').trans hjn) | |
| (nodeParent_canonical G order d x p w rβ n h Ο hr j hj2' hjn) hi | |
| end CanonicalSupport | |
| noncomputable def owner (d : β) (x : β β V) (n : β) (h : History E n) | |
| (Ο : Set E) (a : V) : β := parent G (anchors d x n h) a Ο none | |
| lemma owner_exists (d : β) (x : β β V) (n : β) (h : History E n) | |
| (Ο : Set E) (a : V) (ha : β b, (a,b) β anchors d x n h) : | |
| β i, parentPredicate G (anchors d x n h) a Ο none i := by | |
| obtain β¨b,hbβ© := ha | |
| obtain β¨i,hiβ© := List.mem_iff_getElem?.mp hb | |
| exact β¨i,(a,b),hi,.refl _β© | |
| lemma owner_lt (d : β) (x : β β V) (n : β) (h : History E n) | |
| (Ο : Set E) (a : V) (ha : β b, (a,b) β anchors d x n h) : | |
| owner G d x n h Ο a < n+2 := by | |
| have hp := parent_lt_of_exists G _ _ Ο none (owner_exists G d x n h Ο a ha) | |
| simpa only [anchors_length,owner] using hp | |
| lemma owner_canonical (d : β) (x : β β V) (n : β) (h : History E n) | |
| (Ο : Set E) (a : V) (ha : β b, (a,b) β anchors d x n h) : | |
| Canonical G (anchors d x n h) Ο (owner G d x n h Ο a) := | |
| parent_canonical G _ _ Ο none (owner_exists G d x n h Ο a ha) | |
| lemma owner_reachable (d : β) (x : β β V) (n : β) (h : History E n) | |
| (Ο : Set E) (a : V) (ha : β b, (a,b) β anchors d x n h) : | |
| (G.openGraph Ο).Reachable a (node d x n h (owner G d x n h Ο a)).1 := by | |
| obtain β¨z,hz,hrβ© := firstIndex_spec (owner_exists G d x n h Ο a ha) | |
| have he : z = node d x n h (owner G d x n h Ο a) := Option.some.inj | |
| (hz.symm.trans (node_getElem? d x n h _ (owner_lt G d x n h Ο a ha))) | |
| exact he βΈ hr | |
| lemma owner_colour (d : β) (x : β β V) (n : β) (h : History E n) | |
| (Ο : Set E) (a : V) (b : Bool) (ha : (a,b) β anchors d x n h) | |
| (hL : Consistent G (anchors d x n h) Ο) : | |
| (node d x n h (owner G d x n h Ο a)).2 = b := | |
| (hL (a,b) ha _ (node_mem d x n h _ (owner_lt G d x n h Ο a β¨b,haβ©)) | |
| (owner_reachable G d x n h Ο a β¨b,haβ©)).symm | |
| section Owners | |
| variable [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] | |
| lemma terminal_roots (order : List (LazyDFS.Dart V E)) (d : β) (x : β β V) | |
| (p : β) (w : E β Prop β β) (s n : β) (h : History E n) (Ο : E β Prop) | |
| (hr : density G order d x p w (seed G w (x 0) (x d) s) n h Ο β 0) : | |
| (historyForest G d x Ο n h).root (owner G d x n h Ο (x (interval d n h).1)) = 0 β§ | |
| (historyForest G d x Ο n h).root (owner G d x n h Ο (x (interval d n h).2)) = 1 := by | |
| have hL := density_consistent G order d x p w s n h Ο hr | |
| have he := endpoint_labels d x n h | |
| have hl := owner_colour G d x n h Ο _ true he.1 hL | |
| have hr' := owner_colour G d x n h Ο _ false he.2 hL | |
| rw [node_root_colour G order d x p w _ n h Ο hr _ | |
| (owner_lt G d x n h Ο _ β¨true,he.1β©)] at hl | |
| rw [node_root_colour G order d x p w _ n h Ο hr _ | |
| (owner_lt G d x n h Ο _ β¨false,he.2β©)] at hr' | |
| constructor | |
| Β· by_contra hz | |
| simp only [ite_eq_right hz] at hl | |
| cases hl | |
| Β· have hn := (historyForest G d x Ο n h).root_lt_two | |
| (owner G d x n h Ο (x (interval d n h).2)) | |
| have hz : (historyForest G d x Ο n h).root | |
| (owner G d x n h Ο (x (interval d n h).2)) β 0 := by | |
| intro hz | |
| simp only [ite_eq_left hz] at hr' | |
| cases hr' | |
| omega | |
| end Owners | |
| end CriticalPercolation.BinaryLaw | |
| end | |
| end | |
| end OAI | |