roseking's picture
Add lean source and binary files (part 120)
f205175 verified
Raw History Blame Contribute Delete
5.2 kB
import Mathlib
import OAI.Probability.CriticalPercolation.Entropy.BinaryDescriptor
namespace OAI
section
section
namespace CriticalPercolation.InterpolationForest.Forest
open scoped Classical
variable (F : Forest)
lemma parent_eq_previous (u v a : ℕ) (huv : F.root u ≠ F.root v)
(ha : a ∈ F.active u v) :
F.parent a = ((Finset.range a).filter fun b =>
(b<2 ∨ b ∈ F.active u v) ∧ F.root b = F.root a).sup id := by
have ha2 := (F.mem_active.mp ha).2
apply le_antisymm
· apply Finset.le_sup (f := id)
exact Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (F.parent_lt a ha2),
F.active_parent ha,(F.root_step ha2).symm⟩
· apply Finset.sup_le
intro b hb
obtain ⟨hba,hb,hroot⟩ := Finset.mem_filter.mp hb
have hba' := Finset.mem_range.mp hba
rcases hb with hb|hb
· have hr := F.mem_lineage_le (F.root_mem_lineage (F.parent a))
rw [← F.root_step ha2,← hroot,F.root_base hb] at hr
exact hr
· exact F.previous_active_le_parent huv ha hb hroot.symm hba'
end CriticalPercolation.InterpolationForest.Forest
namespace CriticalPercolation.BinaryLaw
open scoped Classical
open FiniteProduct BondGraph BinaryInterpolation InterpolationForest
variable {V E : Type*}
def descriptorActive (n : ℕ) (D : FixedDescriptor n) : Finset ℕ :=
((Finset.univ : Finset (Fin n)).filter fun i => (D i).2.2 = true).image (fun i => i.val+2)
lemma activeNodes_eq_descriptor (G : BondGraph V E) (d : ℕ) (x : ℕ → V)
(n : ℕ) (h : History E n) (ω : Set E) (D : FixedDescriptor n)
(hD : descriptor G d x n h ω = D) :
activeNodes G d x n h ω = descriptorActive n D := by
ext i
constructor
· intro hi
have hi2 := (Forest.mem_active _).mp hi |>.2
have hin := active_lt G d x n h ω i hi
let j : Fin n := ⟨i-2,by omega⟩
have hj : j.val+2=i := by dsimp [j]; omega
refine Finset.mem_image.mpr ⟨j,Finset.mem_filter.mpr ⟨Finset.mem_univ _,?_⟩,hj⟩
rw [← hD]
simpa only [descriptor,hj,decide_eq_true_eq] using hi
· intro hi
obtain ⟨j,hj,rfl⟩ := Finset.mem_image.mp hi
have ht := (Finset.mem_filter.mp hj).2
rw [← hD] at ht
simpa only [descriptor,decide_eq_true_eq] using ht
def descriptorNode (d : ℕ) (x : ℕ → V) (n : ℕ) (D : FixedDescriptor n) (i : ℕ) : V × Bool :=
node d x n (fromWords (E := E) n (fun j => (D j).1) (fun _ => none)) i
lemma node_eq_descriptor (G : BondGraph V E) (d : ℕ) (x : ℕ → V)
(n : ℕ) (h : History E n) (ω : Set E) (D : FixedDescriptor n)
(hD : descriptor G d x n h ω = D) (i : ℕ) :
node d x n h i = descriptorNode (E := E) d x n D i := by
have hs := descriptor_sides G d x n h ω D hD
unfold node descriptorNode
rw [anchors_sides d x n h (fromWords n (fun j => (D j).1) (fun _ => (none : Option E)))
(hs.trans (sides_fromWords n _ _).symm)]
rfl
def descriptorParent (d : ℕ) (x : ℕ → V) (n : ℕ) (D : FixedDescriptor n) (i : ℕ) : ℕ :=
((Finset.range i).filter fun j => (j<2 ∨ j ∈ descriptorActive n D) ∧
(descriptorNode (E := E) d x n D j).2 = (descriptorNode (E := E) d x n D i).2).sup id
section Finite
variable [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E]
variable (G : BondGraph V E) (order : List (LazyDFS.Dart V E)) (d : ℕ) (x : ℕ → V)
variable (p : ℝ) (w : E → Prop → ℝ) (s n : ℕ) (h : History E n) (ω : E → Prop)
variable (hr : density G order d x p w (seed G w (x 0) (x d) s) n h ω ≠ 0)
include hr in
lemma node_colour_eq_iff_root (i j : ℕ) (hi : i<n+2) (hj : j<n+2) :
(node d x n h i).2 = (node d x n h j).2 ↔
(historyForest G d x ω n h).root i = (historyForest G d x ω n h).root j := by
rw [node_root_colour G order d x p w _ n h ω hr i hi,
node_root_colour G order d x p w _ n h ω hr j hj]
have hi2 := (historyForest G d x ω n h).root_lt_two i
have hj2 := (historyForest G d x ω n h).root_lt_two j
split_ifs <;> simp_all <;> omega
include hr in
theorem active_parent_eq_descriptor (D : FixedDescriptor n)
(hD : descriptor G d x n h ω = D) (i : ℕ)
(hi : i ∈ activeNodes G d x n h ω) :
nodeParent G d x ω n h i = descriptorParent (E := E) d x n D i := by
have ht := terminal_roots G order d x p w s n h ω hr
have hne : (historyForest G d x ω n h).root
(owner G d x n h ω (x (interval d n h).1)) ≠
(historyForest G d x ω n h).root
(owner G d x n h ω (x (interval d n h).2)) := by rw [ht.1,ht.2]; omega
have he := (historyForest G d x ω n h).parent_eq_previous _ _ i hne hi
change nodeParent G d x ω n h i = _ at he
rw [he]
unfold descriptorParent
congr 1
ext j
simp only [Finset.mem_filter]
by_cases hj : j ∈ Finset.range i
· simp only [hj,true_and]
have hji := Finset.mem_range.mp hj
have hin := active_lt G d x n h ω i hi
rw [← activeNodes_eq_descriptor G d x n h ω D hD,
← node_eq_descriptor G d x n h ω D hD j,← node_eq_descriptor G d x n h ω D hD i]
exact and_congr_right fun _ => (node_colour_eq_iff_root G order d x p w s n h ω hr j i
(hji.trans hin) hin).symm
· simp only [hj,false_and]
end Finite
end CriticalPercolation.BinaryLaw
end
end
end OAI