Download data/lean/OAI/LinearAlgebra/MatrixFields/Construction/Subdivision.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 11.5 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixFields/Construction/Subdivision.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixFields/Construction/Subdivision.lean
-
curl -L -o Subdivision.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixFields/Construction/Subdivision.lean
11.5 kB
| import Mathlib | |
| import OAI.LinearAlgebra.MatrixFields.Histories.InheritedMaskMargins | |
| namespace OAI | |
| namespace MatrixAllFields | |
| open scoped BigOperators Topology Polynomial | |
| section | |
| noncomputable section | |
| namespace MatrixMultiplication.Subdivision | |
| open MatrixMultiplication.Foundation InheritedMasks | |
| open scoped BigOperators | |
| attribute [local instance] Classical.propDecidable | |
| variable {I : Type*} [Fintype I] [DecidableEq I] | |
| (P : I β Type*) [β i, Fintype (P i)] [β i, DecidableEq (P i)] | |
| def concatenate {X : Type*} (w : β i, P i β X) : (Ξ£ i, P i) β X := | |
| fun p => w p.1 p.2 | |
| def concatenateEquiv (X : Type*) : (β i, P i β X) β ((Ξ£ i, P i) β X) where | |
| toFun := concatenate P | |
| invFun := fun w i p => w β¨i, pβ© | |
| left_inv := by intro w; rfl | |
| right_inv := by intro w; rfl | |
| section Windows | |
| variable {A : Type*} [Fintype A] [DecidableEq A] | |
| omit [DecidableEq I] [β index, DecidableEq (P index)] [Fintype A] in | |
| theorem wordPopulation_concatenate (w : β i, P i β A) (a : A) : | |
| wordPopulation (concatenate P w) a = β i, wordPopulation (w i) a := by | |
| let e : {p : (Ξ£ i, P i) // concatenate P w p = a} β | |
| (Ξ£ i, {p : P i // w i p = a}) := | |
| { toFun := fun p => β¨p.val.1, β¨p.val.2, p.propertyβ©β© | |
| invFun := fun p => β¨β¨p.1, p.2.valβ©, p.2.propertyβ© | |
| left_inv := by intro p; rfl | |
| right_inv := by intro p; rfl } | |
| exact (Fintype.card_congr e).trans Fintype.card_sigma | |
| omit [DecidableEq I] [β index, DecidableEq (P index)] [Fintype A] in | |
| theorem empiricalLaw_concatenate (w : β i, P i β A) (a : A) : | |
| empiricalLaw (concatenate P w) a = | |
| β i, ((Fintype.card (P i) : β) / Fintype.card (Ξ£ i, P i)) * | |
| empiricalLaw (w i) a := by | |
| rw [empiricalLaw, wordPopulation_concatenate, Nat.cast_sum, Finset.sum_div] | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| by_cases hi : Fintype.card (P i) = 0 | |
| Β· have hp : wordPopulation (w i) a = 0 := by | |
| have hle := Fintype.card_subtype_le (fun p : P i => w i p = a) | |
| change wordPopulation (w i) a β€ Fintype.card (P i) at hle | |
| omega | |
| simp [hi, hp] | |
| Β· have hi' : (Fintype.card (P i) : β) β 0 := Nat.cast_ne_zero.mpr hi | |
| simp only [empiricalLaw, div_eq_mul_inv] | |
| calc | |
| (wordPopulation (w i) a : β) * (Fintype.card (Ξ£ i, P i) : β)β»ΒΉ = | |
| (wordPopulation (w i) a : β) * (Fintype.card (Ξ£ i, P i) : β)β»ΒΉ * | |
| ((Fintype.card (P i) : β) * (Fintype.card (P i) : β)β»ΒΉ) := by | |
| rw [mul_inv_cancelβ hi', mul_one] | |
| _ = (Fintype.card (P i) : β) * (Fintype.card (Ξ£ i, P i) : β)β»ΒΉ * | |
| ((wordPopulation (w i) a : β) * (Fintype.card (P i) : β)β»ΒΉ) := by ring | |
| def partWindows (Ξ½ : A β β) (Ξ· : I β β) (w : β i, P i β A) : Prop := | |
| β i, 0 < Fintype.card (P i) β typeWindow Ξ½ (Ξ· i) (w i) | |
| omit [DecidableEq I] [β index, DecidableEq (P index)] [Fintype A] in | |
| theorem typeWindow_concatenate (Ξ½ : A β β) (Ξ· : β) (Ξ·part : I β β) | |
| (hΞ· : 0 β€ Ξ·) (hwidth : β i, Ξ·part i β€ Ξ·) | |
| (hsize : 0 < Fintype.card (Ξ£ i, P i)) (w : β i, P i β A) | |
| (hw : partWindows P Ξ½ Ξ·part w) : typeWindow Ξ½ Ξ· (concatenate P w) := by | |
| intro a | |
| let mass : I β β := fun i => (Fintype.card (P i) : β) / Fintype.card (Ξ£ i, P i) | |
| let law : I β β := fun i => | |
| if Fintype.card (P i) = 0 then Ξ½ a else empiricalLaw (w i) a | |
| have hm : β i, 0 β€ mass i := fun i => div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) | |
| have hsum : β i, mass i = 1 := by | |
| dsimp [mass] | |
| rw [β Finset.sum_div, β Nat.cast_sum, β Fintype.card_sigma] | |
| exact div_self (by exact_mod_cast (Nat.ne_of_gt hsize)) | |
| have hl : β i, |law i - Ξ½ a| β€ Ξ· := by | |
| intro i | |
| by_cases hi : Fintype.card (P i) = 0 | |
| Β· simpa [law, hi] using hΞ· | |
| Β· simpa only [law, ite_eq_right hi] using | |
| (hw i (Nat.pos_of_ne_zero hi) a).trans (hwidth i) | |
| have heq : empiricalLaw (concatenate P w) a = β i, mass i * law i := by | |
| rw [empiricalLaw_concatenate] | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| by_cases hi : Fintype.card (P i) = 0 <;> simp [mass, law, hi] | |
| rw [heq] | |
| exact weighted_window mass law (Ξ½ a) Ξ· hm hsum hl | |
| omit [DecidableEq I] [β index, DecidableEq (P index)] [Fintype A] in | |
| theorem statisticWindow_concatenate {X : Type*} (statistic : X β A) | |
| (Ξ½ : A β β) (Ξ· : β) (Ξ·part : I β β) | |
| (hΞ· : 0 β€ Ξ·) (hwidth : β i, Ξ·part i β€ Ξ·) | |
| (hsize : 0 < Fintype.card (Ξ£ i, P i)) (w : β i, P i β X) | |
| (hw : partWindows P Ξ½ Ξ·part (fun i => statistic β w i)) : | |
| typeWindow Ξ½ Ξ· (statistic β concatenate P w) := by | |
| exact typeWindow_concatenate P Ξ½ Ξ· Ξ·part hΞ· hwidth hsize | |
| (fun index => statistic β w index) hw | |
| end Windows | |
| def positionsOfCounts (count : I β β) (n : β) (hsum : β i, count i = n) : | |
| Fin n β (Ξ£ i, Fin (count i)) := | |
| Fintype.equivOfCardEq (by simp only [Fintype.card_fin, Fintype.card_sigma, hsum]) | |
| theorem typeWindow_reindex {A Q R : Type*} | |
| [Fintype A] [DecidableEq A] [Fintype Q] [DecidableEq Q] | |
| [Fintype R] [DecidableEq R] | |
| (Ξ½ : A β β) (Ξ· : β) (w : R β A) (e : Q β R) : | |
| typeWindow Ξ½ Ξ· (w β e) β typeWindow Ξ½ Ξ· w := by | |
| simp only [typeWindow, empiricalLaw, wordPopulation_reindex, Fintype.card_congr e] | |
| omit [DecidableEq I] [β index, DecidableEq (P index)] in | |
| theorem statisticWindow_concatenate_at {A X Q : Type*} | |
| [Fintype A] [DecidableEq A] [Fintype Q] [DecidableEq Q] | |
| (e : Q β (Ξ£ i, P i)) (statistic : X β A) | |
| (Ξ½ : A β β) (Ξ· : β) (Ξ·part : I β β) | |
| (hΞ· : 0 β€ Ξ·) (hwidth : β i, Ξ·part i β€ Ξ·) | |
| (hsize : 0 < Fintype.card (Ξ£ i, P i)) (w : β i, P i β X) | |
| (hw : partWindows P Ξ½ Ξ·part (fun i => statistic β w i)) : | |
| typeWindow Ξ½ Ξ· (statistic β (concatenate P w β e)) := by | |
| change typeWindow Ξ½ Ξ· ((statistic β concatenate P w) β e) | |
| exact (typeWindow_reindex Ξ½ Ξ· _ e).mpr | |
| (statisticWindow_concatenate P statistic Ξ½ Ξ· Ξ·part hΞ· hwidth hsize w hw) | |
| section Coefficients | |
| variable {F X Y Z : Type*} [CommSemiring F] | |
| [Fintype X] [Fintype Y] [Fintype Z] | |
| def repeated (Q : Type*) [Fintype Q] (T : Tensor F X Y Z) : | |
| Tensor F (Q β X) (Q β Y) (Q β Z) := fun x y z => β p, T (x p) (y p) (z p) | |
| def allParts {U : Type*} (keep : β i, (P i β U) β Prop) (w : β i, P i β U) : Prop := | |
| β i, keep i (w i) | |
| def subdivisionMatrix {U : Type*} (keep : β i, (P i β U) β Prop) : | |
| (β i, P i β U) β ((Ξ£ i, P i) β U) β F := | |
| fun w v => if v = concatenate P w β§ allParts P keep w then 1 else 0 | |
| theorem subdivisionMatrix_apply (T : Tensor F ((Ξ£ i, P i) β X) | |
| ((Ξ£ i, P i) β Y) ((Ξ£ i, P i) β Z)) | |
| (keepX : β i, (P i β X) β Prop) (keepY : β i, (P i β Y) β Prop) | |
| (keepZ : β i, (P i β Z) β Prop) | |
| (x : β i, P i β X) (y : β i, P i β Y) (z : β i, P i β Z) : | |
| Tensor.restrict (subdivisionMatrix P keepX) (subdivisionMatrix P keepY) | |
| (subdivisionMatrix P keepZ) T x y z = | |
| if allParts P keepX x β§ allParts P keepY y β§ allParts P keepZ z then | |
| T (concatenate P x) (concatenate P y) (concatenate P z) else 0 := by | |
| by_cases hx : allParts P keepX x <;> | |
| by_cases hy : allParts P keepY y <;> | |
| by_cases hz : allParts P keepZ z <;> | |
| simp [Tensor.restrict, subdivisionMatrix, hx, hy, hz, ite_mul, mul_ite] | |
| theorem restrict_received (T : Tensor F X Y Z) | |
| (receivedX : ((Ξ£ i, P i) β X) β Prop) | |
| (receivedY : ((Ξ£ i, P i) β Y) β Prop) | |
| (receivedZ : ((Ξ£ i, P i) β Z) β Prop) | |
| (keepX : β i, (P i β X) β Prop) (keepY : β i, (P i β Y) β Prop) | |
| (keepZ : β i, (P i β Z) β Prop) | |
| (hx : β x, allParts P keepX x β receivedX (concatenate P x)) | |
| (hy : β y, allParts P keepY y β receivedY (concatenate P y)) | |
| (hz : β z, allParts P keepZ z β receivedZ (concatenate P z)) : | |
| Tensor.restrict (subdivisionMatrix P keepX) (subdivisionMatrix P keepY) | |
| (subdivisionMatrix P keepZ) | |
| (ExactRecovery.delete (repeated (Ξ£ i, P i) T) receivedX receivedY receivedZ) = | |
| fun x y z => β i, ExactRecovery.delete (repeated (P i) T) | |
| (keepX i) (keepY i) (keepZ i) (x i) (y i) (z i) := by | |
| funext x y z | |
| rw [subdivisionMatrix_apply] | |
| simp only [ExactRecovery.delete, Fintype.prod_ite_zero, forall_and] | |
| by_cases h : allParts P keepX x β§ allParts P keepY y β§ allParts P keepZ z | |
| Β· have hX := hx x h.1 | |
| have hY := hy y h.2.1 | |
| have hZ := hz z h.2.2 | |
| have hp : (β i, keepX i (x i)) β§ (β i, keepY i (y i)) β§ | |
| (β i, keepZ i (z i)) := h | |
| simp only [ite_eq_left h, ite_eq_left hp, hX, hY, hZ, and_self, ite_true] | |
| simp only [repeated, concatenate, Fintype.prod_sigma] | |
| Β· simp only [allParts] at h | |
| simp [allParts, h] | |
| def subdivisionMatrixAt {U Q : Type*} (e : Q β (Ξ£ i, P i)) | |
| (keep : β i, (P i β U) β Prop) : | |
| (β i, P i β U) β (Q β U) β F := | |
| fun w v => if v = concatenate P w β e β§ allParts P keep w then 1 else 0 | |
| omit [DecidableEq I] [β index, DecidableEq (P index)] in | |
| theorem restrict_received_at {Q : Type*} [Fintype Q] [DecidableEq Q] | |
| (e : Q β (Ξ£ i, P i)) (T : Tensor F X Y Z) | |
| (receivedX : (Q β X) β Prop) (receivedY : (Q β Y) β Prop) | |
| (receivedZ : (Q β Z) β Prop) | |
| (keepX : β i, (P i β X) β Prop) (keepY : β i, (P i β Y) β Prop) | |
| (keepZ : β i, (P i β Z) β Prop) | |
| (hx : β x, allParts P keepX x β receivedX (concatenate P x β e)) | |
| (hy : β y, allParts P keepY y β receivedY (concatenate P y β e)) | |
| (hz : β z, allParts P keepZ z β receivedZ (concatenate P z β e)) : | |
| Tensor.restrict (subdivisionMatrixAt P e keepX) (subdivisionMatrixAt P e keepY) | |
| (subdivisionMatrixAt P e keepZ) | |
| (ExactRecovery.delete (repeated Q T) receivedX receivedY receivedZ) = | |
| fun x y z => β i, ExactRecovery.delete (repeated (P i) T) | |
| (keepX i) (keepY i) (keepZ i) (x i) (y i) (z i) := by | |
| funext x y z | |
| have hcollapse : Tensor.restrict (subdivisionMatrixAt P e keepX) | |
| (subdivisionMatrixAt P e keepY) (subdivisionMatrixAt P e keepZ) | |
| (ExactRecovery.delete (repeated Q T) receivedX receivedY receivedZ) x y z = | |
| if allParts P keepX x β§ allParts P keepY y β§ allParts P keepZ z then | |
| ExactRecovery.delete (repeated Q T) receivedX receivedY receivedZ | |
| (concatenate P x β e) (concatenate P y β e) (concatenate P z β e) else 0 := by | |
| by_cases hx : allParts P keepX x <;> | |
| by_cases hy : allParts P keepY y <;> | |
| by_cases hz : allParts P keepZ z <;> | |
| simp [Tensor.restrict, subdivisionMatrixAt, hx, hy, hz, ite_mul, mul_ite] | |
| rw [hcollapse] | |
| simp only [ExactRecovery.delete, Fintype.prod_ite_zero, forall_and] | |
| by_cases h : allParts P keepX x β§ allParts P keepY y β§ allParts P keepZ z | |
| Β· have hX := hx x h.1 | |
| have hY := hy y h.2.1 | |
| have hZ := hz z h.2.2 | |
| have hp : (β i, keepX i (x i)) β§ (β i, keepY i (y i)) β§ | |
| (β i, keepZ i (z i)) := h | |
| simp only [ite_eq_left h, ite_eq_left hp, hX, hY, hZ, and_self, ite_true, repeated, | |
| Function.comp_apply] | |
| have hprod := Equiv.prod_comp e (fun p => | |
| T (concatenate P x p) (concatenate P y p) (concatenate P z p)) | |
| simpa only [concatenate, Fintype.prod_sigma] using hprod | |
| Β· simp only [allParts] at h | |
| simp [allParts, h] | |
| end Coefficients | |
| end MatrixMultiplication.Subdivision | |
| end | |
| end | |
| end MatrixAllFields | |
| end OAI | |