Download data/lean/OAI/LinearAlgebra/MatrixMultiplication/FieldParameters/HalfLaws.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 10.9 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/FieldParameters/HalfLaws.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixMultiplication/FieldParameters/HalfLaws.lean
-
curl -L -o HalfLaws.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/FieldParameters/HalfLaws.lean
10.9 kB
| import OAI.LinearAlgebra.MatrixMultiplication.FieldParameters.Compatibility | |
| import OAI.LinearAlgebra.MatrixMultiplication.FieldParameters.Traversal | |
| namespace OAI | |
| /-! Fixed rational distributions and their entropy and capacity formulas. -/ | |
| namespace MatrixMultiplication.AllFieldParameters | |
| open scoped BigOperators | |
| theorem stageBLaw_nonnegative (t u : Shape) : 0 β€ stageBLaw t u := by | |
| by_cases hu : u β below t | |
| Β· exact (stageBLaw_positive t u hu).le | |
| Β· simp [stageBLaw, splitLaw, hu] | |
| theorem orderedPairs_mem_iff (t : Shape) (i j : Fin 6) : | |
| (i,j) β orderedPairs t β statisticWeight i + statisticWeight j = shapeMax t := by | |
| constructor | |
| Β· exact orderedPairs_support t (i,j) | |
| Β· intro h | |
| apply List.mem_flatMap.mpr | |
| refine β¨i, by simp, ?_β© | |
| apply List.mem_filterMap.mpr | |
| exact β¨j, by simp, by simp [h]β© | |
| theorem zeroPairLaw_nonnegative (t : Shape) (i j : Fin 6) : 0 β€ zeroPairLaw t i j := by | |
| unfold zeroPairLaw | |
| split_ifs | |
| Β· exact div_nonneg (orderedPairWeight_positive t i j).le | |
| (list_sum_map_nonnegative _ _ (fun ij _ => (orderedPairWeight_positive t ij.1 ij.2).le)) | |
| Β· exact le_rfl | |
| theorem zeroPairLaw_full_normalized (t : Shape) (ht : t β zeroSecond) : | |
| β ij : PairSlot, zeroPairLaw t ij.1 ij.2 = 1 := by | |
| calc | |
| _ = β ij β (orderedPairs t).toFinset, zeroPairLaw t ij.1 ij.2 := by | |
| symm | |
| apply Finset.sum_subset (Finset.subset_univ _) | |
| intro ij _ hij | |
| have hs : statisticWeight ij.1 + statisticWeight ij.2 β shapeMax t := by | |
| intro h | |
| exact hij (List.mem_toFinset.mpr ((orderedPairs_mem_iff t ij.1 ij.2).mpr h)) | |
| simp [zeroPairLaw, hs] | |
| _ = ((orderedPairs t).map (fun ij => zeroPairLaw t ij.1 ij.2)).sum := | |
| List.sum_toFinset _ (ordered_pairs_nodup t ht) | |
| _ = 1 := zeroPairLaw_normalized t ht | |
| def positiveHalfLaw (t : Shape) (w : Fin 3) (ij : PairSlot) : β := | |
| ((below t).map fun u => stageBLaw t u * littleLaw t u w ij.1 * | |
| littleLaw t (complement t u) w ij.2).sum | |
| theorem positiveHalfLaw_nonnegative (t : Shape) (w : Fin 3) (ij : PairSlot) : | |
| 0 β€ positiveHalfLaw t w ij := by | |
| apply list_sum_map_nonnegative | |
| intro u _ | |
| exact mul_nonneg (mul_nonneg (stageBLaw_nonnegative t u) | |
| (littleLaw_nonnegative t u w ij.1)) | |
| (littleLaw_nonnegative t (complement t u) w ij.2) | |
| theorem sum_pair_mixture {A : Type*} (xs : List A) (mass : A β β) | |
| (left right : A β Fin 6 β β) | |
| (hl : β x β xs, β i, left x i = 1) | |
| (hr : β x β xs, β i, right x i = 1) : | |
| (β ij : PairSlot, (xs.map fun x => mass x * left x ij.1 * right x ij.2).sum) = | |
| (xs.map mass).sum := by | |
| induction xs with | |
| | nil => simp | |
| | cons x xs ih => | |
| have hleft := hl x (by simp) | |
| have hright := hr x (by simp) | |
| have hhead : (β ij : PairSlot, mass x * left x ij.1 * right x ij.2) = mass x := by | |
| simp [Fintype.sum_prod_type, β Finset.mul_sum, hleft, hright] | |
| have htail := ih (fun y hy => hl y (by simp [hy])) (fun y hy => hr y (by simp [hy])) | |
| simpa only [List.map_cons, List.sum_cons, Finset.sum_add_distrib, hhead] using | |
| congrArg (fun q : β => mass x + q) htail | |
| theorem positiveHalfLaw_normalized (t : Shape) (ht : t β positiveSecond) (w : Fin 3) : | |
| β ij : PairSlot, positiveHalfLaw t w ij = 1 := by | |
| unfold positiveHalfLaw | |
| rw [sum_pair_mixture _ _ _ _ (fun u _ => littleLaw_normalized t u w) | |
| (fun u _ => littleLaw_normalized t (complement t u) w)] | |
| exact stageBLaw_normalized t ht | |
| theorem stageB_complement_permutation : β t β positiveSecond, | |
| ((below t).map (complement t)).Perm (below t) := by decide +kernel | |
| theorem stageB_complement_involution (t : Shape) (ht : t β positiveSecond) | |
| (u : Shape) (hu : u β below t) : complement t (complement t u) = u := by | |
| funext w | |
| exact Nat.sub_sub_self ((stageB_support_complement t ht u hu).2 w) | |
| theorem positiveHalfLaw_swap (t : Shape) (ht : t β positiveSecond) | |
| (w : Fin 3) (i j : Fin 6) : positiveHalfLaw t w (i,j) = positiveHalfLaw t w (j,i) := by | |
| let f := fun u => stageBLaw t u * littleLaw t u w i * littleLaw t (complement t u) w j | |
| let g := fun u => stageBLaw t u * littleLaw t u w j * littleLaw t (complement t u) w i | |
| have hp := (stageB_complement_permutation t ht).map f | |
| have hm : ((below t).map (complement t)).map f = (below t).map g := by | |
| rw [List.map_map] | |
| apply List.map_congr_left | |
| intro u hu | |
| dsimp only [Function.comp_def, f, g] | |
| rw [stageBLaw_complement t u ht hu, stageB_complement_involution t ht u hu] | |
| ring | |
| change ((below t).map f).sum = ((below t).map g).sum | |
| rw [β hp.sum_eq, hm] | |
| def halfMaxAxis (t : Shape) : Fin 3 := | |
| (([0,1,2] : List (Fin 3)).find? (fun w => t w == shapeMax t)).getD 0 | |
| def halfLaw (t : Shape) (w : Fin 3) (ij : PairSlot) : β := | |
| if positive t then positiveHalfLaw t w ij | |
| else if t w = 0 then if ij = (0,0) then 1 else 0 | |
| else if w = halfMaxAxis t then zeroPairLaw t ij.1 ij.2 | |
| else zeroPairLaw t (kappa ij.1) (kappa ij.2) | |
| theorem halfLaw_positive_parent (t : Shape) (ht : t β positiveSecond) | |
| (w : Fin 3) (ij : PairSlot) : halfLaw t w ij = positiveHalfLaw t w ij := by | |
| have hp : positive t = true := (List.mem_filter.mp ht).2 | |
| simp [halfLaw, hp] | |
| theorem halfLaw_swap (t : Shape) (ht : t β shapes 8) (w : Fin 3) (i j : Fin 6) : | |
| halfLaw t w (i,j) = halfLaw t w (j,i) := by | |
| by_cases hp : positive t = true | |
| Β· simp only [halfLaw, hp, ite_true] | |
| exact positiveHalfLaw_swap t (List.mem_filter.mpr β¨ht, hpβ©) w i j | |
| Β· unfold halfLaw | |
| simp only [hp, Bool.false_eq_true, ite_false] | |
| by_cases hw : t w = 0 | |
| Β· simp [hw, Prod.mk.injEq, and_comm] | |
| Β· simp only [hw, ite_false] | |
| by_cases hm : w = halfMaxAxis t | |
| Β· simpa only [hm, ite_true] using zeroPairLaw_swap t i j | |
| Β· simpa only [hm, ite_false] using zeroPairLaw_swap t (kappa i) (kappa j) | |
| theorem halfLaw_nonnegative (t : Shape) (w : Fin 3) (ij : PairSlot) : | |
| 0 β€ halfLaw t w ij := by | |
| unfold halfLaw | |
| split_ifs | |
| Β· exact positiveHalfLaw_nonnegative t w ij | |
| Β· norm_num | |
| Β· exact le_rfl | |
| Β· exact zeroPairLaw_nonnegative t ij.1 ij.2 | |
| Β· exact zeroPairLaw_nonnegative t (kappa ij.1) (kappa ij.2) | |
| def kappaEquiv : Fin 6 β Fin 6 where | |
| toFun := kappa | |
| invFun := kappa | |
| left_inv := kappa_involution | |
| right_inv := kappa_involution | |
| theorem sum_pair_kappa (f : PairSlot β β) : | |
| (β ij : PairSlot, f (kappa ij.1, kappa ij.2)) = β ij, f ij := | |
| (Equiv.prodCongr kappaEquiv kappaEquiv).sum_comp f | |
| theorem halfLaw_normalized (t : Shape) (ht : t β shapes 8) (w : Fin 3) : | |
| β ij : PairSlot, halfLaw t w ij = 1 := by | |
| by_cases hp : positive t = true | |
| Β· simp only [halfLaw, hp, ite_true] | |
| exact positiveHalfLaw_normalized t (List.mem_filter.mpr β¨ht, hpβ©) w | |
| Β· have hz : t β zeroSecond := by simp [zeroSecond, ht, hp] | |
| simp only [halfLaw, hp, Bool.false_eq_true, ite_false] | |
| by_cases hw : t w = 0 | |
| Β· simp [hw] | |
| Β· simp only [hw, ite_false] | |
| by_cases hm : w = halfMaxAxis t | |
| Β· simpa only [hm, ite_true] using zeroPairLaw_full_normalized t hz | |
| Β· simp only [hm, ite_false] | |
| rw [sum_pair_kappa (fun ij => zeroPairLaw t ij.1 ij.2)] | |
| exact zeroPairLaw_full_normalized t hz | |
| theorem positiveHalfLaw_outside_support (t : Shape) (ht : t β positiveSecond) | |
| (w : Fin 3) (ij : PairSlot) | |
| (h : statisticWeight ij.1 + statisticWeight ij.2 β t w) : | |
| positiveHalfLaw t w ij = 0 := by | |
| unfold positiveHalfLaw | |
| have he : (below t).map (fun u => stageBLaw t u * littleLaw t u w ij.1 * | |
| littleLaw t (complement t u) w ij.2) = (below t).map (fun _ => (0 : β)) := by | |
| apply List.map_congr_left | |
| intro u hu | |
| obtain β¨hc, hbβ© := stageB_support_complement t ht u hu | |
| by_cases hi : statisticWeight ij.1 = u w | |
| Β· have hj : statisticWeight ij.2 β complement t u w := by | |
| intro hj | |
| apply h | |
| rw [hi, hj] | |
| change u w + (t w - u w) = t w | |
| have hw := hb w | |
| omega | |
| rw [littleLaw_outside_support t (complement t u) w | |
| (child_statistic_weight_bounded t ht (complement t u) hc w) ij.2 hj, mul_zero] | |
| Β· rw [littleLaw_outside_support t u w | |
| (child_statistic_weight_bounded t ht u hu w) ij.1 hi, mul_zero, zero_mul] | |
| rw [he] | |
| simp | |
| theorem halfMaxAxis_spec : β t β shapes 8, t (halfMaxAxis t) = shapeMax t := by | |
| decide +kernel | |
| theorem zero_other_axis_spec : β t β zeroSecond, β w : Fin 3, | |
| t w β 0 β w β halfMaxAxis t β t w + shapeMax t = 8 := by decide +kernel | |
| theorem statisticWeight_le_four (i : Fin 6) : statisticWeight i β€ 4 := by | |
| revert i | |
| decide +kernel | |
| theorem halfLaw_outside_support (t : Shape) (ht : t β shapes 8) | |
| (w : Fin 3) (ij : PairSlot) | |
| (h : statisticWeight ij.1 + statisticWeight ij.2 β t w) : | |
| halfLaw t w ij = 0 := by | |
| by_cases hp : positive t = true | |
| Β· simp only [halfLaw, hp, ite_true] | |
| exact positiveHalfLaw_outside_support t (List.mem_filter.mpr β¨ht, hpβ©) w ij h | |
| Β· have hz : t β zeroSecond := by simp [zeroSecond, ht, hp] | |
| simp only [halfLaw, hp, Bool.false_eq_true, ite_false] | |
| by_cases hw : t w = 0 | |
| Β· have hij : ij β (0,0) := by | |
| intro hij | |
| apply h | |
| rw [hij, hw] | |
| rfl | |
| rw [ite_eq_left hw, ite_eq_right hij] | |
| Β· simp only [hw, ite_false] | |
| by_cases hm : w = halfMaxAxis t | |
| Β· have hs : statisticWeight ij.1 + statisticWeight ij.2 β shapeMax t := by | |
| simpa only [hm, halfMaxAxis_spec t ht] using h | |
| simp [hm, zeroPairLaw, hs] | |
| Β· have hs : statisticWeight (kappa ij.1) + statisticWeight (kappa ij.2) β | |
| shapeMax t := by | |
| have htotal := zero_other_axis_spec t hz w hw hm | |
| have hi := statisticWeight_le_four ij.1 | |
| have hj := statisticWeight_le_four ij.2 | |
| simp only [statisticWeight_kappa] | |
| omega | |
| simp [hm, zeroPairLaw, hs] | |
| theorem zero_nonzero_axes_distinguished : β t β zeroSecond, β w v : Fin 3, | |
| t w β 0 β t v β 0 β w β v β | |
| (w = halfMaxAxis t β v β halfMaxAxis t) := by decide +kernel | |
| theorem halfLaw_zero_complement (t : Shape) (ht : t β zeroSecond) | |
| (w v : Fin 3) (hw : t w β 0) (hv : t v β 0) (hwv : w β v) (ij : PairSlot) : | |
| halfLaw t w (kappa ij.1, kappa ij.2) = halfLaw t v ij := by | |
| have hp : positive t β true := by | |
| have h := (List.mem_filter.mp ht).2 | |
| simpa using h | |
| have hm := zero_nonzero_axes_distinguished t ht w v hw hv hwv | |
| by_cases ha : w = halfMaxAxis t | |
| Β· have hb : v β halfMaxAxis t := hm.mp ha | |
| have hmax : t (halfMaxAxis t) β 0 := by simpa only [ha] using hw | |
| simp [halfLaw, hp, hv, ha, hb, hmax] | |
| Β· have hb : v = halfMaxAxis t := by | |
| by_contra hne | |
| exact ha (hm.mpr hne) | |
| have hmax : t (halfMaxAxis t) β 0 := by simpa only [hb] using hv | |
| simp [halfLaw, hp, hw, ha, hb, hmax, kappa_involution] | |
| end MatrixMultiplication.AllFieldParameters | |
| end OAI | |