Download data/lean/OAI/Probability/BinarySweep/Conditional/WeightedCycle.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 6.23 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/BinarySweep/Conditional/WeightedCycle.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/BinarySweep/Conditional/WeightedCycle.lean
-
curl -L -o WeightedCycle.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/BinarySweep/Conditional/WeightedCycle.lean
6.23 kB
| import Mathlib | |
| import OAI.Probability.BinarySweep.Trajectories.Trajectory | |
| namespace OAI | |
| noncomputable section | |
| open scoped BigOperators Classical | |
| namespace BinaryCoordinateSweeps | |
| lemma weighted_entry_bound (n : β) {p C a : β} (hp : 0 β€ p) | |
| (hbound : 0 < p β p β€ Real.exp (C + a)) : | |
| p * Real.exp (-C / (n+1 : β)) β€ | |
| Real.exp (a / (n+1 : β)) * p ^ ((n : β) / (n+1 : β)) := by | |
| rcases hp.eq_or_lt with hp | hp | |
| Β· subst p | |
| simp only [zero_mul] | |
| positivity | |
| have hn : (0 : β) < n+1 := by positivity | |
| have hl : Real.log p β€ C + a := (Real.log_le_iff_le_exp hp).mpr (hbound hp) | |
| have he : Real.log p + -C / (n+1 : β) β€ | |
| a / (n+1 : β) + Real.log p * ((n : β) / (n+1 : β)) := by | |
| apply (mul_le_mul_iff_leftβ hn).mp | |
| field_simp | |
| nlinarith [hl] | |
| calc | |
| _ = Real.exp (Real.log p + -C / (n+1 : β)) := by | |
| rw [Real.exp_add, Real.exp_log hp] | |
| _ β€ Real.exp (a / (n+1 : β) + Real.log p * ((n : β) / (n+1 : β))) := | |
| Real.exp_le_exp.mpr he | |
| _ = _ := by rw [Real.exp_add, Real.rpow_def_of_pos hp] | |
| theorem weighted_cycle_le_card {A : Type*} [Fintype A] (n : β) | |
| (p C : Fin (n+1) β A β A β β) (a : β) | |
| (hp : β i x y, 0 β€ p i x y) | |
| (hsum : β i y, β x, p i x y = 1) | |
| (hbound : β i x y, 0 < p i x y β p i x y β€ Real.exp (C i x y + a)) : | |
| (β x : Fin (n+1) β A, | |
| β i, p i (x i) (x (finRotate (n+1) i)) * | |
| Real.exp (-C i (x i) (x (finRotate (n+1) i)) / (n+1 : β))) β€ | |
| Real.exp a * (Fintype.card A : β) := by | |
| have hconstant : (β _i : Fin (n+1), Real.exp (a / (n+1 : β))) = Real.exp a := by | |
| rw [Finset.prod_const, Finset.card_univ, Fintype.card_fin, β Real.exp_nat_mul] | |
| congr 1 | |
| push_cast | |
| field_simp | |
| calc | |
| _ β€ β x : Fin (n+1) β A, | |
| β i, Real.exp (a / (n+1 : β)) * | |
| (p i (x i) (x (finRotate (n+1) i))) ^ ((n : β) / (n+1 : β)) := by | |
| apply Finset.sum_le_sum | |
| intro x _ | |
| apply Finset.prod_le_prodβ | |
| Β· intro i _; exact mul_nonneg (hp _ _ _) (Real.exp_pos _).le | |
| Β· intro i _; exact weighted_entry_bound n (hp _ _ _) (hbound _ _ _) | |
| _ = Real.exp a * (β x : Fin (n+1) β A, | |
| β i, (p i (x i) (x (finRotate (n+1) i))) ^ ((n : β) / (n+1 : β))) := by | |
| simp_rw [Finset.prod_mul_distrib, hconstant] | |
| rw [Finset.mul_sum] | |
| _ β€ _ := mul_le_mul_of_nonneg_left (Cyclic.sum_cycle_rpow_le_card n p hp hsum) | |
| (Real.exp_pos a).le | |
| def placementEdgeCost {b h : β} {bits : Fin b β β} (H : PathFamily bits h) | |
| (z : β) (reverse : Bool) {k : β} (x y : Placement H k 0) : β := | |
| if reverse then placementTransitionCost H z y (placementIdentification H k x) | |
| else placementTransitionCost H z x (placementIdentification H k y) | |
| lemma placementEdge_bound {b h r : β} {bits : Fin b β β} | |
| (H : PathFamily bits h) (hd : β j, bits j β€ 2*r) {z : β} | |
| (hz : 0 β€ z) (hzr : z β€ linePerturbationRadius r) | |
| (reverse : Bool) {k : β} (x y : Placement H k 0) | |
| (hp : 0 < placementEdge H z reverse x y) : | |
| placementEdge H z reverse x y β€ | |
| Real.exp (placementEdgeCost H z reverse x y + | |
| (-(k : β) * Real.log (gridSize bits) - pathCost H + Real.log 4 * k * b)) := by | |
| have hsingle (x y : Placement H k 0) (hp : 0 < placementKernel H z x y) : | |
| placementKernel H z x y β€ Real.exp ( | |
| placementTransitionCost H z x (placementIdentification H k y) + | |
| (-(k : β) * Real.log (gridSize bits) - pathCost H + Real.log 4 * k * b)) := by | |
| have hc := placement_probability_cost_of_pos H hd hz hzr x | |
| (placementIdentification H k y) hp | |
| have hs : (0 : β) < gridSize bits := by exact_mod_cast gridSize_pos bits | |
| rw [Real.rpow_def_of_pos hs, β Real.exp_add] at hc | |
| convert hc using 1 <;> congr 1 | |
| ring | |
| cases reverse with | |
| | false => exact hsingle x y hp | |
| | true => exact hsingle y x hp | |
| lemma linePerturbationRadius_lt_one (r : β) : linePerturbationRadius r < 1 := by | |
| have hf : (1 : β) β€ ((2 ^ (2 * r)).factorial : β) := by | |
| exact_mod_cast Nat.factorial_pos (2 ^ (2 * r)) | |
| unfold linePerturbationRadius | |
| apply (div_lt_one (by positivity)).mpr | |
| linarith | |
| theorem placement_weighted_cycle_bound {b h r : β} {bits : Fin b β β} | |
| (H : PathFamily bits h) (hd : β j, bits j β€ 2*r) {z : β} | |
| (hz : 0 β€ z) (hzr : z β€ linePerturbationRadius r) | |
| (k n : β) (reverse : Fin (n+1) β Bool) : | |
| (β x : Fin (n+1) β Placement H k 0, | |
| β i, placementEdge H z (reverse i) (x i) (x (finRotate (n+1) i)) * | |
| Real.exp (-placementEdgeCost H z (reverse i) (x i) (x (finRotate (n+1) i)) / | |
| (n+1 : β))) β€ Real.exp (-pathCost H + Real.log 4 * k * b) := by | |
| have hz1 := hzr.trans_lt (linePerturbationRadius_lt_one r) | |
| have hc := weighted_cycle_le_card (A := Placement H k 0) n | |
| (fun i => placementEdge H z (reverse i)) | |
| (fun i => placementEdgeCost H z (reverse i)) | |
| (-(k : β) * Real.log (gridSize bits) - pathCost H + Real.log 4 * k * b) | |
| (by | |
| intro i x y | |
| unfold placementEdge | |
| split_ifs <;> exact placementKernel_nonneg H hz hz1 _ _) | |
| (by | |
| intro i y | |
| unfold placementEdge | |
| cases reverse i with | |
| | false => exact placementKernel_colSum H hz hz1 y | |
| | true => exact placementKernel_rowSum H hz hz1 y) | |
| (by intro i x y hp; exact placementEdge_bound H hd hz hzr (reverse i) x y hp) | |
| rw [card_placement] at hc | |
| apply hc.trans | |
| have hcard : ((gridSize bits - h).descFactorial k : β) β€ (gridSize bits : β) ^ k := by | |
| exact_mod_cast (Nat.descFactorial_le_pow (gridSize bits - h) k).trans | |
| (Nat.pow_le_pow_left (Nat.sub_le (gridSize bits) h) k) | |
| have hs : (0 : β) < gridSize bits := by exact_mod_cast gridSize_pos bits | |
| calc | |
| _ β€ Real.exp (-(k : β) * Real.log (gridSize bits) - pathCost H + Real.log 4 * k * b) * | |
| (gridSize bits : β) ^ k := | |
| mul_le_mul_of_nonneg_left hcard (Real.exp_pos _).le | |
| _ = _ := by | |
| have he : (gridSize bits : β) ^ k = | |
| Real.exp ((k : β) * Real.log (gridSize bits)) := by | |
| rw [Real.exp_nat_mul, Real.exp_log hs] | |
| rw [he, β Real.exp_add] | |
| congr 1 | |
| ring | |
| end BinaryCoordinateSweeps | |
| end | |
| end OAI | |