Download data/lean/OAI/Probability/BinarySweep/Processes/IndependentHistory.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.95 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/BinarySweep/Processes/IndependentHistory.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/BinarySweep/Processes/IndependentHistory.lean
-
curl -L -o IndependentHistory.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/BinarySweep/Processes/IndependentHistory.lean
8.95 kB
| import Mathlib | |
| import OAI.Probability.BinarySweep.Processes.PointMassOne | |
| namespace OAI | |
| noncomputable section | |
| open scoped BigOperators | |
| namespace BinaryCoordinateSweeps | |
| section IndependentLaw | |
| variable {G Ξ© Ξ : Type*} [Fintype G] [Group G] [Fintype Ξ©] [Fintype Ξ] | |
| def independentHistory (f : Ξ© β G) (n : β) (c : Fin n β Ξ©) : G := | |
| (List.ofFn (fun i => f (c i))).reverse.prod | |
| omit [Fintype G] [Fintype Ξ©] in | |
| lemma independentHistory_succ (f : Ξ© β G) (n : β) (a : Ξ©) (c : Fin n β Ξ©) : | |
| independentHistory f (n + 1) (Fin.snoc c a) = f a * independentHistory f n c := by | |
| unfold independentHistory | |
| rw [List.ofFn_succ'] | |
| simp | |
| lemma finiteLaw_independentHistory [Nonempty Ξ©] (f : Ξ© β G) (n : β) : | |
| finiteLaw (independentHistory f n) = convolutionPower (finiteLaw f) n := by | |
| induction n with | |
| | zero => | |
| classical | |
| funext g | |
| simp [finiteLaw, independentHistory, convolutionPower, pointMassOne, eq_comm] | |
| | succ n ih => | |
| let e : Ξ© Γ (Fin n β Ξ©) β (Fin (n + 1) β Ξ©) := Fin.snocEquiv (fun _ => Ξ©) | |
| rw [β finiteLaw_reindex e] | |
| have he : (independentHistory f (n + 1)) β e = | |
| fun a : Ξ© Γ (Fin n β Ξ©) => f a.1 * independentHistory f n a.2 := by | |
| funext a | |
| exact independentHistory_succ f n a.1 a.2 | |
| rw [he, finiteLaw_independent_mul, ih] | |
| rfl | |
| end IndependentLaw | |
| section Assignments | |
| attribute [local instance] Classical.propDecidable | |
| variable {X I : Type*} [Fintype X] [Fintype I] | |
| def Assigns (A B : I βͺ X) (Ο : Equiv.Perm X) : Prop := β i, Ο (A i) = B i | |
| lemma card_assignment_completions (A B : I βͺ X) : | |
| Fintype.card {Ο : Equiv.Perm X // Assigns A B Ο} = | |
| (Fintype.card X - Fintype.card I).factorial := by | |
| classical | |
| let eA := Equiv.ofInjective A A.injective | |
| let eB := Equiv.ofInjective B B.injective | |
| let eβ : Set.range A β Set.range B := eA.symm.trans eB | |
| have ha : Fintype.card (Set.range A) = Fintype.card I := Fintype.card_congr eA.symm | |
| have hb : Fintype.card (Set.range B) = Fintype.card I := Fintype.card_congr eB.symm | |
| let e : {Ο : Equiv.Perm X // Assigns A B Ο} β | |
| {Ο : X β X // β x : Set.range A, Ο x = eβ x} := | |
| Equiv.subtypeEquiv (Equiv.refl _) (by | |
| intro Ο | |
| constructor | |
| Β· intro h x | |
| obtain β¨i, hiβ© := x.property | |
| have hx : x = eA i := Subtype.ext hi.symm | |
| rw [hx] | |
| simpa [eβ, eA, eB] using h i | |
| Β· intro h i | |
| simpa [eβ, eA, eB] using h (eA i)) | |
| let c : β₯((Set.range A)αΆ) β β₯((Set.range B)αΆ) := Fintype.equivOfCardEq (by | |
| change Fintype.card {x : X // x β Set.range A} = Fintype.card {x : X // x β Set.range B} | |
| rw [Fintype.card_subtype_compl, Fintype.card_subtype_compl, ha, hb]) | |
| rw [Fintype.card_congr (e.trans (Equiv.Set.compl eβ)), Fintype.card_equiv c] | |
| change (Fintype.card {x : X // x β Set.range A}).factorial = _ | |
| rw [Fintype.card_subtype_compl, ha] | |
| lemma uniform_assignment_probability (A B : I βͺ X) : | |
| (β Ο : Equiv.Perm X, if Assigns A B Ο then | |
| (Fintype.card (Equiv.Perm X) : β)β»ΒΉ else 0) = | |
| (Nat.descFactorial (Fintype.card X) (Fintype.card I) : β)β»ΒΉ := by | |
| classical | |
| have hn : Fintype.card I β€ Fintype.card X := Fintype.card_le_of_injective A A.injective | |
| have hcard : (Fintype.card {Ο : Equiv.Perm X // Assigns A B Ο} : β) = | |
| ((Fintype.card X - Fintype.card I).factorial : β) := by | |
| exact_mod_cast card_assignment_completions A B | |
| have hsum : (β Ο : Equiv.Perm X, if Assigns A B Ο then | |
| (Fintype.card (Equiv.Perm X) : β)β»ΒΉ else 0) = | |
| (Fintype.card {Ο : Equiv.Perm X // Assigns A B Ο} : β) * | |
| (Fintype.card (Equiv.Perm X) : β)β»ΒΉ := by | |
| simp [Fintype.card_subtype, Finset.sum_ite] | |
| rw [hsum, hcard, Fintype.card_perm, | |
| β Nat.factorial_mul_descFactorial hn, Nat.cast_mul, mul_inv_rev] | |
| have hf : (((Fintype.card X - Fintype.card I).factorial : β) : β) β 0 := by | |
| exact_mod_cast (Nat.factorial_ne_zero (Fintype.card X - Fintype.card I)) | |
| field_simp | |
| end Assignments | |
| lemma physicalLaw_eq_convolutionPower (d t : β) : | |
| physicalLaw d t = convolutionPower (finiteLaw (physical d)) t := | |
| finiteLaw_independentHistory (physical d) t | |
| def sweepHistory (d t : β) (coins : Fin t β SweepCoins d) : Equiv.Perm (Slot d) := | |
| independentHistory (binarySweep d) t coins | |
| lemma sweepLaw_eq_finiteLaw (d t : β) : sweepLaw d t = finiteLaw (sweepHistory d t) := | |
| (finiteLaw_independentHistory (binarySweep d) t).symm | |
| def fromInitial {G : Type*} [Group G] (p : G β β) (initial : G) : G β β := | |
| fun g => p (g * initialβ»ΒΉ) | |
| lemma totalVariation_fromInitial {G : Type*} [Fintype G] [Group G] | |
| (p : G β β) (initial : G) : | |
| totalVariation (fromInitial p initial) (uniformLaw G) = totalVariation p (uniformLaw G) := by | |
| unfold totalVariation fromInitial uniformLaw | |
| congr 1 | |
| exact Equiv.sum_comp (Equiv.mulRight initialβ»ΒΉ) | |
| (fun g => |p g - (Fintype.card G : β)β»ΒΉ|) | |
| theorem fixed_dimension_sweep_convergence_fromInitial (d : β) | |
| (initial : Equiv.Perm (Slot d)) : | |
| Filter.Tendsto (fun t => totalVariation (fromInitial (sweepLaw d t) initial) | |
| (uniformLaw (Equiv.Perm (Slot d)))) Filter.atTop (nhds 0) := by | |
| simp only [totalVariation_fromInitial] | |
| exact fixed_dimension_sweep_convergence d | |
| def ConstantSweepMixingTarget : Prop := | |
| β w : β, β Ξ΅ : β, 0 < Ξ΅ β β dβ : β, β d β₯ dβ, | |
| β initial : Equiv.Perm (Slot d), | |
| totalVariation (fromInitial (sweepLaw d w) initial) | |
| (uniformLaw (Equiv.Perm (Slot d))) < Ξ΅ | |
| def fallingCost (m u : β) : β := Real.log ((m : β) ^ u / (m.descFactorial u : β)) | |
| lemma fallingCost_sum {m u : β} (hm : 0 < m) (hu : u β€ m) : | |
| fallingCost m u = β j β Finset.range u, Real.log ((m : β) / (m - j : β)) := by | |
| have hmp : (0 : β) < m := by exact_mod_cast hm | |
| have hdf : (0 : β) < m.descFactorial u := by exact_mod_cast (Nat.descFactorial_pos.mpr hu) | |
| have hdiff (j : β) (hj : j β Finset.range u) : (m - j : β) β 0 := by | |
| simp only [Finset.mem_range] at hj | |
| omega | |
| have hlog (j : β) (hj : j β Finset.range u) : | |
| Real.log ((m : β) / (m - j : β)) = Real.log m - Real.log (m - j : β) := | |
| Real.log_div hmp.ne' (by exact_mod_cast hdiff j hj) | |
| rw [fallingCost, Real.log_div (pow_ne_zero _ hmp.ne') hdf.ne', Real.log_pow, | |
| Nat.descFactorial_eq_prod_range, Nat.cast_prod, Real.log_prod (fun j hj => by exact_mod_cast hdiff j hj)] | |
| rw [Finset.sum_congr rfl hlog, Finset.sum_sub_distrib] | |
| simp | |
| lemma fallingCost_nonneg {m u : β} (hm : 0 < m) (hu : u β€ m) : 0 β€ fallingCost m u := by | |
| rw [fallingCost_sum hm hu] | |
| apply Finset.sum_nonneg | |
| intro j hj | |
| have hdiff : (0 : β) < (m - j : β) := by | |
| exact_mod_cast (Nat.sub_pos_of_lt ((Finset.mem_range.mp hj).trans_le hu)) | |
| apply Real.log_nonneg | |
| exact (le_div_iffβ hdiff).mpr (by simp) | |
| lemma prefix_sum_le_of_full_sum_le {m u : β} (hm : 0 < m) (hu : u β€ m) (f : β β β) | |
| (hf : β i < u, β j, u β€ j β j < m β f i β€ f j) | |
| (hfull : β j β Finset.range m, f j β€ m) : | |
| β j β Finset.range u, f j β€ u := by | |
| have hc : ((m : β) - u) * (β i β Finset.range u, f i) β€ | |
| (u : β) * β j β Finset.Ico u m, f j := by | |
| calc | |
| _ = β i β Finset.range u, β _j β Finset.Ico u m, f i := by | |
| simp [Nat.cast_sub hu, Finset.mul_sum] | |
| _ β€ β i β Finset.range u, β j β Finset.Ico u m, f j := by | |
| apply Finset.sum_le_sum | |
| intro i hi | |
| apply Finset.sum_le_sum | |
| intro j hj | |
| exact hf i (Finset.mem_range.mp hi) j (Finset.mem_Ico.mp hj).1 (Finset.mem_Ico.mp hj).2 | |
| _ = _ := by simp | |
| have hsplit := Finset.sum_range_add_sum_Ico f hu | |
| have hmp : (0 : β) < m := by exact_mod_cast hm | |
| have hu0 : (0 : β) β€ u := by positivity | |
| nlinarith | |
| lemma fallingCost_le {m u : β} (hm : 0 < m) (hu : u β€ m) : fallingCost m u β€ u := by | |
| have hmp : (0 : β) < m := by exact_mod_cast hm | |
| have hfull : fallingCost m m β€ m := by | |
| have hst := Stirling.le_log_factorial_stirling hm.ne' | |
| have hlog : 0 β€ Real.log (m : β) := Real.log_nonneg (by exact_mod_cast hm) | |
| have hpi : 0 β€ Real.log (2 * Real.pi) := Real.log_nonneg (by linarith [Real.pi_gt_three]) | |
| rw [fallingCost, Nat.descFactorial_self, Real.log_div (pow_ne_zero _ hmp.ne') (by positivity), Real.log_pow] | |
| linarith | |
| rw [fallingCost_sum hm hu] | |
| apply prefix_sum_le_of_full_sum_le hm hu | |
| Β· intro i hi j huj hjm | |
| apply Real.log_le_log | |
| Β· exact div_pos hmp (by exact_mod_cast Nat.sub_pos_of_lt (hi.trans_le hu)) | |
| Β· apply div_le_div_of_nonneg_left hmp.le | |
| Β· exact_mod_cast Nat.sub_pos_of_lt hjm | |
| Β· exact_mod_cast Nat.sub_le_sub_left (hi.le.trans huj) m | |
| Β· rwa [β fallingCost_sum hm le_rfl] | |
| attribute [local instance] Classical.propDecidable | |
| variable {X I J : Type*} [Fintype X] [Fintype I] [Fintype J] | |
| end BinaryCoordinateSweeps | |
| end | |
| end OAI | |