Download data/lean/OAI/Probability/BinarySweep/Processes/GridSweepPath.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 9.64 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/BinarySweep/Processes/GridSweepPath.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/BinarySweep/Processes/GridSweepPath.lean
-
curl -L -o GridSweepPath.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/BinarySweep/Processes/GridSweepPath.lean
9.64 kB
| import Mathlib | |
| import OAI.Probability.BinarySweep.Processes.CoordinateLayerEdgeSwap | |
| namespace OAI | |
| noncomputable section | |
| open scoped BigOperators | |
| namespace BinaryCoordinateSweeps | |
| lemma gridSweep_path {b h : β} {bits : Fin b β β} (H : PathFamily bits h) | |
| (g : GridChoices bits) (hg : pathEvent H g) (k : Fin h) : | |
| gridSweep bits g (H.position 0 k) = H.position (Fin.last b) k := | |
| chronological_trajectory b (gridLayer bits g) (fun t => H.position t k) (fun j => hg j k) | |
| abbrev FreeSlot {b h : β} {bits : Fin b β β} (H : PathFamily bits h) | |
| (t : Fin (b + 1)) := {x : GridSlot bits // x β Set.range (H.position t)} | |
| instance freeSlotFintype {b h : β} {bits : Fin b β β} (H : PathFamily bits h) | |
| (t : Fin (b + 1)) : Fintype (FreeSlot H t) := Fintype.ofFinite _ | |
| lemma card_freeSlot {b h : β} {bits : Fin b β β} (H : PathFamily bits h) | |
| (t : Fin (b + 1)) : Fintype.card (FreeSlot H t) = gridSize bits - h := by | |
| classical | |
| rw [show Fintype.card (FreeSlot H t) = | |
| Fintype.card (GridSlot bits) - Fintype.card (Set.range (H.position t)) from | |
| Fintype.card_subtype_compl (fun x => x β Set.range (H.position t))] | |
| rw [card_gridSlot] | |
| have hr : Fintype.card (Set.range (H.position t)) = h := by | |
| let e : Fin h βͺ GridSlot bits := β¨H.position t, H.disjoint tβ© | |
| simpa [e] using Fintype.card_range e | |
| rw [hr] | |
| def freeIdentification {b h : β} {bits : Fin b β β} (H : PathFamily bits h) : | |
| FreeSlot H 0 β FreeSlot H (Fin.last b) := | |
| Fintype.equivOfCardEq (by rw [card_freeSlot, card_freeSlot]) | |
| def remainingBijection {b h : β} {bits : Fin b β β} (H : PathFamily bits h) | |
| (g : GridChoices bits) (hg : pathEvent H g) : | |
| FreeSlot H 0 β FreeSlot H (Fin.last b) where | |
| toFun x := β¨gridSweep bits g x, by | |
| rintro β¨k, hkβ© | |
| exact x.property β¨k, (gridSweep bits g).injective ((gridSweep_path H g hg k).trans hk)β©β© | |
| invFun y := β¨(gridSweep bits g).symm y, by | |
| rintro β¨k, hkβ© | |
| apply y.property | |
| refine β¨k, ?_β© | |
| rw [β gridSweep_path H g hg k, hk] | |
| exact (gridSweep bits g).apply_symm_apply yβ© | |
| left_inv x := by apply Subtype.ext; exact (gridSweep bits g).symm_apply_apply x | |
| right_inv y := by apply Subtype.ext; exact (gridSweep bits g).apply_symm_apply y | |
| def remainingPerm {b h : β} {bits : Fin b β β} (H : PathFamily bits h) | |
| (g : GridChoices bits) (hg : pathEvent H g) : Equiv.Perm (FreeSlot H 0) := | |
| (remainingBijection H g hg).trans (freeIdentification H).symm | |
| def conditionalNormalizer {b h : β} {bits : Fin b β β} (H : PathFamily bits h) | |
| (z : β) : β := by | |
| classical | |
| exact β g : GridChoices bits, if pathEvent H g then gridWeight bits z g else 0 | |
| def conditionalOperator {b h D : β} {bits : Fin b β β} (H : PathFamily bits h) | |
| (z : β) (Ο : Representation β (Equiv.Perm (FreeSlot H 0)) (RepSpace D)) : | |
| RepSpace D βL[β] RepSpace D := by | |
| classical | |
| exact LinearMap.toContinuousLinearMap | |
| ((conditionalNormalizer H z : β)β»ΒΉ β’ β g : GridChoices bits, | |
| if hg : pathEvent H g then (gridWeight bits z g : β) β’ Ο (remainingPerm H g hg) | |
| else 0) | |
| def lineHoles {b h : β} {bits : Fin b β β} (H : PathFamily bits h) | |
| (j : Fin b) (y : GridOutside bits j) : β := by | |
| classical | |
| exact Fintype.card {k : Fin h // (fun i : {i : Fin b // i β j} => | |
| H.position j.castSucc k i) = y} | |
| def pathCost {b h : β} {bits : Fin b β β} (H : PathFamily bits h) : β := | |
| β j, β y : GridOutside bits j, | |
| Real.log (((2 ^ bits j : β) : β) ^ lineHoles H j y / | |
| (Nat.descFactorial (2 ^ bits j) (lineHoles H j y) : β)) | |
| def ConditionalMomentTarget : Prop := | |
| β r : β, 0 < r β§ β q : β, 0 < q β§ β zStar : β, 0 < zStar β§ | |
| β b : β, 1 β€ b β β bits : Fin b β β, (β j, r β€ bits j β§ bits j β€ 2 * r) β | |
| β h : β, β H : PathFamily bits h, β z : β, 0 β€ z β z β€ zStar β | |
| β D : β, β Ο : Representation β (Equiv.Perm (FreeSlot H 0)) (RepSpace D), | |
| Ο.IsIrreducible β IsUnitaryRep Ο β | |
| logMoment (traceMoment q (conditionalOperator H z Ο)) β€ | |
| ((-cExponent (gridSize bits) * Real.log D + | |
| eExponent (gridSize bits) * h * Real.log (gridSize bits) - pathCost H : β) : EReal) | |
| theorem pathEvent_nonempty {b h : β} {bits : Fin b β β} (H : PathFamily bits h) : | |
| β g : GridChoices bits, pathEvent H g := by | |
| classical | |
| let A (j : Fin b) (y : GridOutside bits j) := | |
| {k : Fin h // (fun i : {i : Fin b // i β j} => H.position j.castSucc k i) = y} | |
| have hp (j : Fin b) (y : GridOutside bits j) : | |
| β Ο : Equiv.Perm (Slot (bits j)), β k : A j y, | |
| Ο (H.position j.castSucc k.val j) = H.position j.succ k.val j := by | |
| apply Equiv.Perm.exists_extending_pair | |
| Β· intro k l he | |
| apply Subtype.ext | |
| apply H.disjoint j.castSucc | |
| funext i | |
| by_cases hi : i = j | |
| Β· subst i; exact he | |
| Β· exact (congrFun k.property β¨i, hiβ©).trans (congrFun l.property β¨i, hiβ©).symm | |
| Β· intro k l he | |
| apply Subtype.ext | |
| apply H.disjoint j.succ | |
| funext i | |
| by_cases hi : i = j | |
| Β· subst i; exact he | |
| Β· rw [H.changes_only_stage j k.val i hi, H.changes_only_stage j l.val i hi] | |
| exact (congrFun k.property β¨i, hiβ©).trans (congrFun l.property β¨i, hiβ©).symm | |
| choose g hg using hp | |
| refine β¨g, ?_β© | |
| intro j k | |
| apply (Equiv.piSplitAt j (fun i => Slot (bits i))).injective | |
| simp only [gridLayer, Equiv.trans_apply, Equiv.apply_symm_apply, | |
| Equiv.piSplitAt_apply, Equiv.prodCongrLeft_apply] | |
| apply Prod.ext | |
| Β· exact hg j _ β¨k, rflβ© | |
| Β· funext i | |
| exact (H.changes_only_stage j k i.val i.property).symm | |
| lemma lineLaw_pos (d : β) {z : β} (hz : 0 β€ z) (hz1 : z < 1) | |
| (g : Equiv.Perm (Slot d)) : 0 < lineLaw d z g := by | |
| have hu : 0 < uniformLaw (Equiv.Perm (Slot d)) g := by | |
| unfold uniformLaw | |
| have hc : (0 : β) < Fintype.card (Equiv.Perm (Slot d)) := by exact_mod_cast Fintype.card_pos | |
| exact inv_pos.mpr hc | |
| exact add_pos_of_pos_of_nonneg (mul_pos (sub_pos.mpr hz1) hu) | |
| (mul_nonneg hz (finiteLaw_nonneg (binarySweep d) g)) | |
| lemma lineLaw_sum (d : β) (z : β) : β g, lineLaw d z g = 1 := by | |
| simp only [lineLaw, Finset.sum_add_distrib, β Finset.mul_sum, | |
| uniformLaw_sum, binaryLaw, finiteLaw_sum] | |
| ring | |
| lemma gridWeight_pos {b : β} (bits : Fin b β β) {z : β} (hz : 0 β€ z) (hz1 : z < 1) | |
| (g : GridChoices bits) : 0 < gridWeight bits z g := by | |
| apply Finset.prod_pos | |
| intro j _ | |
| exact Finset.prod_pos (fun y _ => lineLaw_pos (bits j) hz hz1 (g j y)) | |
| lemma gridWeight_sum {b : β} (bits : Fin b β β) (z : β) : | |
| β g : GridChoices bits, gridWeight bits z g = 1 := by | |
| classical | |
| unfold gridWeight | |
| rw [β Fintype.prod_sum (fun (j : Fin b) | |
| (g : GridOutside bits j β Equiv.Perm (Slot (bits j))) => β y, lineLaw (bits j) z (g y))] | |
| have hj (j : Fin b) : β g : GridOutside bits j β Equiv.Perm (Slot (bits j)), | |
| β y, lineLaw (bits j) z (g y) = 1 := by | |
| rw [β Fintype.prod_sum (fun (_ : GridOutside bits j) | |
| (g : Equiv.Perm (Slot (bits j))) => lineLaw (bits j) z g)] | |
| simp [lineLaw_sum] | |
| simp [hj] | |
| theorem conditionalNormalizer_pos {b h : β} {bits : Fin b β β} (H : PathFamily bits h) | |
| {z : β} (hz : 0 β€ z) (hz1 : z < 1) : 0 < conditionalNormalizer H z := by | |
| classical | |
| obtain β¨g, hgβ© := pathEvent_nonempty H | |
| apply Finset.sum_pos' | |
| Β· intro g' _ | |
| split_ifs | |
| Β· exact (gridWeight_pos bits hz hz1 g').le | |
| Β· exact le_rfl | |
| Β· exact β¨g, Finset.mem_univ _, by simpa [hg] using gridWeight_pos bits hz hz1 gβ© | |
| variable {G : Type*} [Fintype G] [Group G] | |
| lemma uniformLaw_probability : IsProbability (uniformLaw G) := | |
| β¨fun _ => by unfold uniformLaw; positivity, uniformLaw_sumβ© | |
| lemma convolution_sub_left (p q r : G β β) : | |
| convolution (fun g => p g - q g) r = fun g => convolution p r g - convolution q r g := by | |
| funext g | |
| simp [convolution, sub_mul, Finset.sum_sub_distrib] | |
| lemma convolution_smul_left (a : β) (p q : G β β) : | |
| convolution (fun g => a * p g) q = fun g => a * convolution p q g := by | |
| funext g | |
| simp [convolution, mul_assoc, Finset.mul_sum] | |
| lemma convolution_uniform_right_mass (p : G β β) : | |
| convolution p (uniformLaw G) = fun g => (β x, p x) * uniformLaw G g := by | |
| funext g | |
| simp [convolution, uniformLaw, Finset.sum_mul] | |
| lemma convolution_minorization {p q : G β β} (hp : IsProbability p) (hq : IsProbability q) | |
| (Ξ΄ : β) (hΞ΄ : β g, Ξ΄ * uniformLaw G g β€ p g) : | |
| totalVariation (convolution p q) (uniformLaw G) β€ | |
| (1 - Ξ΄) * totalVariation q (uniformLaw G) := by | |
| let r : G β β := fun g => p g - Ξ΄ * uniformLaw G g | |
| have hr : β g, 0 β€ r g := fun g => sub_nonneg.mpr (hΞ΄ g) | |
| have hmass : β g, r g = 1 - Ξ΄ := by | |
| simp [r, Finset.sum_sub_distrib, β Finset.mul_sum, hp.2, uniformLaw_sum] | |
| have he : totalVariation (convolution p q) (uniformLaw G) = | |
| totalVariation (convolution r q) (convolution r (uniformLaw G)) := by | |
| have hdiff (g : G) : convolution r q g - convolution r (uniformLaw G) g = | |
| convolution p q g - uniformLaw G g := by | |
| rw [show r = (fun g => p g - Ξ΄ * uniformLaw G g) from rfl, | |
| convolution_sub_left, convolution_smul_left, convolution_uniform_left hq.2] | |
| rw [β show r = (fun g => p g - Ξ΄ * uniformLaw G g) from rfl, | |
| convolution_uniform_right_mass, hmass] | |
| ring | |
| simp only [totalVariation, hdiff] | |
| rw [he] | |
| simpa only [hmass] using convolution_tv_contract hr q (uniformLaw G) | |
| end BinaryCoordinateSweeps | |
| end | |
| end OAI | |