Download data/lean/OAI/Probability/CriticalPercolation/Exploration/QueryTree.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.08 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/CriticalPercolation/Exploration/QueryTree.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/CriticalPercolation/Exploration/QueryTree.lean
-
curl -L -o QueryTree.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/CriticalPercolation/Exploration/QueryTree.lean
8.08 kB
| import Mathlib | |
| import OAI.Probability.CriticalPercolation.Entropy.MulLogDivScaled | |
| namespace OAI | |
| section | |
| section | |
| open Set MeasureTheory ProbabilityTheory | |
| open Set | |
| open scoped BigOperators | |
| open scoped Classical | |
| open Real | |
| open Set Real | |
| open scoped Topology | |
| namespace CriticalPercolation | |
| open FiniteEntropy | |
| universe u | |
| inductive QueryTree (E : Type u) : Type u where | |
| | stop : QueryTree E | |
| | ask (e : E) (left right : QueryTree E) : QueryTree E | |
| namespace QueryTree | |
| variable {E : Type u} | |
| @[reducible] def Leaf : QueryTree E β Type u | |
| | .stop => PUnit | |
| | .ask _ left right => Sum left.Leaf right.Leaf | |
| instance leafFintype : (t : QueryTree E) β Fintype t.Leaf | |
| | .stop => inferInstanceAs (Fintype PUnit) | |
| | .ask _ left right => @instFintypeSum _ _ left.leafFintype right.leafFintype | |
| def run : (t : QueryTree E) β (E β Bool) β t.Leaf | |
| | .stop, _ => PUnit.unit | |
| | .ask e left right, Ο => if Ο e then Sum.inr (right.run Ο) else Sum.inl (left.run Ο) | |
| def reads : (t : QueryTree E) β (E β Bool) β List E | |
| | .stop, _ => [] | |
| | .ask e left right, Ο => e :: if Ο e then right.reads Ο else left.reads Ο | |
| def Valid [DecidableEq E] : QueryTree E β Finset E β Prop | |
| | .stop, _ => True | |
| | .ask e left right, used => e β used β§ left.Valid (insert e used) β§ right.Valid (insert e used) | |
| noncomputable def reference (p : β) : (t : QueryTree E) β t.Leaf β β | |
| | .stop, _ => 1 | |
| | .ask _ left _, Sum.inl x => (1-p)*left.reference p x | |
| | .ask _ _ right, Sum.inr x => p*right.reference p x | |
| lemma reference_pos {p : β} (hp : p β Set.Ioo 0 1) : | |
| β (t : QueryTree E) (x : t.Leaf), 0 < t.reference p x := by | |
| intro t | |
| induction t with | |
| | stop => intro x; exact zero_lt_one | |
| | ask e left right hl hr => | |
| intro x | |
| cases x with | |
| | inl x => exact mul_pos (sub_pos.mpr hp.2) (hl x) | |
| | inr x => exact mul_pos hp.1 (hr x) | |
| lemma reference_sum (p : β) (t : QueryTree E) : β x, t.reference p x = 1 := by | |
| induction t with | |
| | stop => simp [reference, Leaf] | |
| | ask e left right hl hr => | |
| change (β x : Sum left.Leaf right.Leaf, (ask e left right).reference p x) = 1 | |
| rw [Fintype.sum_sum_type] | |
| simp only [reference, β Finset.mul_sum, hl, hr, mul_one] | |
| ring | |
| noncomputable def charge (F : β β β) : (t : QueryTree E) β (t.Leaf β β) β β | |
| | .stop, _ => 0 | |
| | .ask _ left right, P => | |
| let l := β x, P (Sum.inl x) | |
| let r := β x, P (Sum.inr x) | |
| (l+r)*F (r/(l+r)) + left.charge F (fun x => P (Sum.inl x)) + | |
| right.charge F (fun x => P (Sum.inr x)) | |
| lemma charge_mono {F H : β β β} (hFH : β r β Set.Icc (0:β) 1, F r β€ H r) | |
| (t : QueryTree E) (P : t.Leaf β β) (hP : β x, 0 β€ P x) : | |
| t.charge F P β€ t.charge H P := by | |
| induction t with | |
| | stop => rfl | |
| | ask e left right hl hr => | |
| let l := β x, P (Sum.inl x) | |
| let r := β x, P (Sum.inr x) | |
| have hn : 0 β€ l+r := add_nonneg (Finset.sum_nonneg fun x _ => hP (.inl x)) | |
| (Finset.sum_nonneg fun x _ => hP (.inr x)) | |
| have hb : r/(l+r) β Set.Icc (0:β) 1 := by | |
| constructor | |
| Β· exact div_nonneg (Finset.sum_nonneg fun x _ => hP (.inr x)) hn | |
| Β· by_cases hz : l+r = 0 | |
| Β· simp [hz] | |
| Β· apply (div_le_one (lt_of_le_of_ne hn (Ne.symm hz))).mpr | |
| have : 0 β€ l := Finset.sum_nonneg fun x _ => hP (.inl x) | |
| linarith | |
| exact add_le_add (add_le_add (mul_le_mul_of_nonneg_left (hFH _ hb) hn) | |
| (hl _ fun x => hP (.inl x))) (hr _ fun x => hP (.inr x)) | |
| lemma charge_const_mul (F : β β β) (c : β) (t : QueryTree E) (P : t.Leaf β β) : | |
| t.charge (fun r => c*F r) P = c*t.charge F P := by | |
| induction t with | |
| | stop => simp [charge] | |
| | ask e left right hl hr => simp only [charge, hl, hr]; ring | |
| theorem divergence_reference_eq_charge {p : β} (hp : p β Set.Ioo 0 1) | |
| (t : QueryTree E) (P : t.Leaf β β) (hP : β x, 0 β€ P x) : | |
| divergence P (t.reference p) = | |
| t.charge (fun r => binaryDivergence r p) P + (β x, P x)*Real.log (β x, P x) := by | |
| induction t with | |
| | stop => simp [divergence, reference, charge, Leaf] | |
| | ask e left right hl hr => | |
| let Pβ : left.Leaf β β := fun x => P (Sum.inl x) | |
| let Pβ : right.Leaf β β := fun x => P (Sum.inr x) | |
| have hb := binaryDivergence_mass_split | |
| (Finset.sum_nonneg (s := Finset.univ) (fun x _ => hP (.inl x))) | |
| (Finset.sum_nonneg (s := Finset.univ) (fun x _ => hP (.inr x))) hp | |
| change (β x : Sum left.Leaf right.Leaf, P x*Real.log (P x/(ask e left right).reference p x)) = _ | |
| rw [Fintype.sum_sum_type] | |
| change divergence Pβ (fun x => (1-p)*left.reference p x) + | |
| divergence Pβ (fun x => p*right.reference p x) = _ | |
| rw [divergence_scale_reference Pβ (left.reference p) (fun x => hP (.inl x)) | |
| (fun x _ => reference_pos hp left x) (sub_pos.mpr hp.2), | |
| divergence_scale_reference Pβ (right.reference p) (fun x => hP (.inr x)) | |
| (fun x _ => reference_pos hp right x) hp.1, | |
| hl Pβ (fun x => hP (.inl x)), hr Pβ (fun x => hP (.inr x))] | |
| change _ = _ + (β x : Sum left.Leaf right.Leaf, P x)*Real.log (β x : Sum left.Leaf right.Leaf, P x) | |
| rw [Fintype.sum_sum_type] | |
| dsimp only [charge, Pβ, Pβ] | |
| linarith | |
| theorem divergence_reference_bounds {p : β} (hp : p β Set.Ioo 0 1) | |
| (t : QueryTree E) (P : t.Leaf β β) (hP : β x, 0 β€ P x) (hMass : β x, P x = 1) : | |
| 2*t.charge (fun r => (r-p)^2) P β€ divergence P (t.reference p) β§ | |
| divergence P (t.reference p) β€ (p*(1-p))β»ΒΉ*t.charge (fun r => (r-p)^2) P := by | |
| rw [divergence_reference_eq_charge hp t P hP, hMass, Real.log_one, mul_zero, add_zero] | |
| constructor | |
| Β· have h := charge_mono (fun r hr => binaryDivergence_lower hp hr) t P hP | |
| rwa [charge_const_mul] at h | |
| Β· have h := charge_mono (fun r hr => binaryDivergence_upper hp hr) t P hP | |
| have heq : (fun r => (r-p)^2/(p*(1-p))) = | |
| (fun r => (p*(1-p))β»ΒΉ*(r-p)^2) := by | |
| funext r; simp only [div_eq_mul_inv, mul_comm] | |
| rwa [heq, charge_const_mul] at h | |
| lemma valid_mono [DecidableEq E] (t : QueryTree E) {s u : Finset E} (hsu : s β u) | |
| (hv : t.Valid u) : t.Valid s := by | |
| induction t generalizing s u with | |
| | stop => trivial | |
| | ask e left right hl hr => | |
| exact β¨fun he => hv.1 (hsu he), hl (Finset.insert_subset_insert e hsu) hv.2.1, | |
| hr (Finset.insert_subset_insert e hsu) hv.2.2β© | |
| lemma run_dependsOn [DecidableEq E] (t : QueryTree E) (used : Finset E) (hv : t.Valid used) : | |
| DependsOn t.run (βused : Set E)αΆ := by | |
| intro Ο Ο' hΟ | |
| induction t generalizing used with | |
| | stop => rfl | |
| | ask e left right hl hr => | |
| have he : Ο e = Ο' e := hΟ e hv.1 | |
| have hc : β i β (β(insert e used) : Set E)αΆ, Ο i = Ο' i := by | |
| intro i hi | |
| exact hΟ i (fun hu => hi (Finset.mem_insert_of_mem hu)) | |
| simp only [run, he] | |
| split_ifs | |
| Β· exact congrArg Sum.inr (hr _ hv.2.2 hc) | |
| Β· exact congrArg Sum.inl (hl _ hv.2.1 hc) | |
| lemma reads_disjoint [DecidableEq E] (t : QueryTree E) (used : Finset E) | |
| (hv : t.Valid used) (Ο : E β Bool) : β e β t.reads Ο, e β used := by | |
| induction t generalizing used with | |
| | stop => simp [reads] | |
| | ask e left right hl hr => | |
| intro f hf | |
| simp only [reads, List.mem_cons] at hf | |
| rcases hf with rfl | hf | |
| Β· exact hv.1 | |
| Β· split_ifs at hf with he | |
| Β· exact fun hu => hr _ hv.2.2 _ hf (Finset.mem_insert_of_mem hu) | |
| Β· exact fun hu => hl _ hv.2.1 _ hf (Finset.mem_insert_of_mem hu) | |
| lemma reads_nodup [DecidableEq E] (t : QueryTree E) (used : Finset E) | |
| (hv : t.Valid used) (Ο : E β Bool) : (t.reads Ο).Nodup := by | |
| induction t generalizing used with | |
| | stop => simp [reads] | |
| | ask e left right hl hr => | |
| simp only [reads, List.nodup_cons] | |
| split_ifs | |
| Β· exact β¨fun he => reads_disjoint right _ hv.2.2 Ο e he (Finset.mem_insert_self _ _), | |
| hr _ hv.2.2β© | |
| Β· exact β¨fun he => reads_disjoint left _ hv.2.1 Ο e he (Finset.mem_insert_self _ _), | |
| hl _ hv.2.1β© | |
| end QueryTree | |
| end CriticalPercolation | |
| open scoped BigOperators | |
| open Set | |
| end | |
| end | |
| end OAI | |