math / data /lean /OAI /LinearAlgebra /MatrixMultiplication /Separation /ComplexLabelHierarchySeparation.lean
Download data/lean/OAI/LinearAlgebra/MatrixMultiplication/Separation/ComplexLabelHierarchySeparation.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 26.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/Separation/ComplexLabelHierarchySeparation.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixMultiplication/Separation/ComplexLabelHierarchySeparation.lean
-
curl -L -o ComplexLabelHierarchySeparation.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/Separation/ComplexLabelHierarchySeparation.lean
26.7 kB
| import OAI.LinearAlgebra.MatrixMultiplication.Separation.ComplexFiniteSeparation | |
| import OAI.LinearAlgebra.MatrixMultiplication.Separation.ComplexAuxiliarySeparation | |
| import OAI.LinearAlgebra.MatrixMultiplication.Separation.ComplexFiniteControl | |
| import OAI.LinearAlgebra.MatrixMultiplication.Tensor.ComplexLocalMaps | |
| import OAI.LinearAlgebra.MatrixMultiplication.Tensor.ComplexSharedAuxiliaryBank | |
| namespace OAI | |
| /-! Finite type counts, hierarchy separation and tensor execution bounds. -/ | |
| open scoped BigOperators | |
| namespace MatrixMultiplication.Foundation | |
| namespace LabelHierarchySeparation | |
| section Bank | |
| variable {K I : Type*} [CommSemiring K] [Fintype I] | |
| variable {X Y Z : I β Type*} | |
| variable {Node : Type*} [Fintype Node] | |
| def populationCoordinateEquiv {J : Type*} (D : Node β Type*) | |
| (pool : I β Node) (reference : J β Node) (e : I β J) | |
| (same : β i, reference (e i) = pool i) : | |
| (β i, D (pool i)) β (β j, D (reference j)) := | |
| e.piCongr (fun i => Equiv.cast (congrArg D (same i).symm)) | |
| omit [CommSemiring K] [Fintype Node] in | |
| theorem tensor_transport {AX AY AZ : Node β Type*} | |
| (T : β node, Tensor K (AX node) (AY node) (AZ node)) | |
| {node node' : Node} (h : node = node') (x : AX node) (y : AY node) (z : AZ node) : | |
| T node' (Equiv.cast (congrArg AX h) x) (Equiv.cast (congrArg AY h) y) | |
| (Equiv.cast (congrArg AZ h) z) = T node x y z := by | |
| cases h | |
| rfl | |
| omit [Fintype Node] in | |
| theorem bankTensor_population_reindex {J : Type*} [Fintype J] | |
| {AX AY AZ : Node β Type*} | |
| (T : β node, Tensor K (AX node) (AY node) (AZ node)) | |
| (pool : I β Node) (reference : J β Node) (e : I β J) | |
| (same : β i, reference (e i) = pool i) : | |
| Tensor.pullback (populationCoordinateEquiv AX pool reference e same) | |
| (populationCoordinateEquiv AY pool reference e same) | |
| (populationCoordinateEquiv AZ pool reference e same) | |
| (bankTensor (fun j => T (reference j))) = bankTensor (fun i => T (pool i)) := by | |
| unfold populationCoordinateEquiv | |
| apply bankTensor_reindex e | |
| intro i x y z | |
| exact tensor_transport T (same i).symm x y z | |
| omit [Fintype Node] in | |
| theorem bankTensor_population_rankAtMost {J : Type*} [Fintype J] | |
| {AX AY AZ : Node β Type*} | |
| (T : β node, Tensor K (AX node) (AY node) (AZ node)) | |
| (pool : I β Node) (reference : J β Node) (e : I β J) | |
| (same : β i, reference (e i) = pool i) | |
| {r : β} (hT : Tensor.RankAtMost (bankTensor (fun j => T (reference j))) r) : | |
| Tensor.RankAtMost (bankTensor (fun i => T (pool i))) r := by | |
| rw [β bankTensor_population_reindex T pool reference e same] | |
| exact hT.pullback _ _ _ | |
| abbrev BankOccurrences (population : Node β β) := | |
| (node : Node) Γ Fin (population node) | |
| theorem canonical_bank_product {M : Type*} [CommMonoid M] | |
| (population : Node β β) (cost : Node β M) : | |
| (β i : BankOccurrences population, cost i.1) = | |
| β node, cost node ^ population node := by | |
| simp [BankOccurrences, Fintype.prod_sigma] | |
| theorem canonical_pairing_card [DecidableEq Node] (population dimension : Node β β) : | |
| Fintype.card (β i : BankOccurrences population, Fin (dimension i.1)) = | |
| β node, dimension node ^ population node := by | |
| classical | |
| simp only [Fintype.card_pi, Fintype.card_fin, canonical_bank_product] | |
| theorem canonical_bank_rankAtMost | |
| {AX AY AZ : Node β Type*} | |
| (E : β node, Tensor K (AX node) (AY node) (AZ node)) | |
| (population rank : Node β β) | |
| (hE : β node, Tensor.RankAtMost (E node) (rank node)) : | |
| Tensor.RankAtMost | |
| (bankTensor (fun i : BankOccurrences population => E i.1)) | |
| (β node, rank node ^ population node) := by | |
| simpa only [canonical_bank_product] using | |
| bankTensor_rankAtMost | |
| (fun i : BankOccurrences population => E i.1) | |
| (fun i => rank i.1) (fun i => hE i.1) | |
| theorem occurrence_product {M : Type*} [CommMonoid M] [DecidableEq Node] | |
| (pool : I β Node) (cost : Node β M) : | |
| (β i, cost (pool i)) = | |
| β node, cost node ^ Fintype.card {i // pool i = node} := by | |
| rw [β Fintype.prod_fiberwise' pool cost] | |
| simp | |
| theorem exact_population_product {M : Type*} [CommMonoid M] [DecidableEq Node] | |
| (pool : I β Node) (population : Node β β) | |
| (exactPopulation : β node, | |
| Fintype.card {i // pool i = node} = population node) (cost : Node β M) : | |
| (β i, cost (pool i)) = β node, cost node ^ population node := by | |
| rw [occurrence_product] | |
| simp only [exactPopulation] | |
| omit [Fintype Node] in | |
| theorem exact_population_bank_equiv [DecidableEq Node] | |
| (pool : I β Node) (population : Node β β) | |
| (exactPopulation : β node, | |
| Fintype.card {i // pool i = node} = population node) : | |
| β e : I β BankOccurrences population, β i, (e i).1 = pool i := by | |
| classical | |
| let ef : β node, {i // pool i = node} β Fin (population node) := | |
| fun node => Fintype.equivOfCardEq (by simp [exactPopulation node]) | |
| refine β¨(Equiv.sigmaFiberEquiv pool).symm.trans | |
| (Equiv.sigmaCongrRight ef), ?_β© | |
| intro i | |
| rfl | |
| end Bank | |
| section PrefixSeparation | |
| variable {X Y Z Prefix Label Pairing G : Type*} | |
| variable [AddCommGroup G] [Fintype G] [DecidableEq G] | |
| variable [DecidableEq Label] [DecidableEq Pairing] | |
| omit [Fintype G] in | |
| theorem prefix_separation_identity | |
| (T : Tensor β X Y Z) | |
| (px : X β Prefix) (py : Y β Prefix) (pz : Z β Prefix) | |
| (lx : X β Label) (ly : Y β Label) | |
| (tag : Prefix β Label β G) (point : Prefix β Label β Pairing β G) | |
| (prefixes : β x y z, T x y z β 0 β px x = py y β§ px x = pz z) | |
| (labels : β x y z, T x y z β 0 β lx x = ly y) | |
| (collision : β p s s' i j, | |
| point p s i + (tag p s - point p s j) = tag p s' β | |
| s = s' β§ i = j) : | |
| Tensor.pullback | |
| (fun x : X Γ Pairing => (x.1, point (px x.1) (lx x.1) x.2)) | |
| (fun y : Y Γ Pairing => | |
| (y.1, tag (py y.1) (ly y.1) - point (py y.1) (ly y.1) y.2)) | |
| (fun z : Z Γ Label => (z.1, tag (pz z.1) z.2)) | |
| (Tensor.product T (groupTensor G)) = separatedTensor lx T := by | |
| funext x y z | |
| by_cases hzero : T x.1 y.1 z.1 = 0 | |
| Β· simp [Tensor.pullback, Tensor.product, separatedTensor, hzero] | |
| Β· obtain β¨hxy, hxzβ© := prefixes x.1 y.1 z.1 hzero | |
| have hl := labels x.1 y.1 z.1 hzero | |
| simp only [Tensor.pullback, Tensor.product, groupTensor, separatedTensor] | |
| simp only [β hxy, β hxz, β hl, collision, mul_ite, mul_one, mul_zero] | |
| theorem prefix_separation_rankAtMost | |
| (T : Tensor β X Y Z) | |
| (px : X β Prefix) (py : Y β Prefix) (pz : Z β Prefix) | |
| (lx : X β Label) (ly : Y β Label) | |
| (tag : Prefix β Label β G) (point : Prefix β Label β Pairing β G) | |
| {r : β} (hT : Tensor.RankAtMost T r) | |
| (prefixes : β x y z, T x y z β 0 β px x = py y β§ px x = pz z) | |
| (labels : β x y z, T x y z β 0 β lx x = ly y) | |
| (collision : β p s s' i j, | |
| point p s i + (tag p s - point p s j) = tag p s' β | |
| s = s' β§ i = j) : | |
| Tensor.RankAtMost (separatedTensor (U := Pairing) lx T) | |
| (r * Fintype.card G) := by | |
| rw [β prefix_separation_identity T px py pz lx ly tag point | |
| prefixes labels collision] | |
| exact (hT.product (groupTensor_rankAtMost G)).pullback _ _ _ | |
| @[simp] theorem separated_coefficient | |
| (T : Tensor β X Y Z) (lx : X β Label) | |
| (x : X) (y : Y) (z : Z) (u : Pairing) : | |
| separatedTensor lx T (x, u) (y, u) (z, lx x) = T x y z := by | |
| simp [separatedTensor] | |
| theorem deterministic_separation_identity | |
| [Subsingleton Label] [Subsingleton Pairing] [Nonempty Pairing] | |
| (T : Tensor β X Y Z) (lx : X β Label) : | |
| separatedTensor (U := Pairing) lx T = | |
| Tensor.pullback Prod.fst Prod.fst Prod.fst T := by | |
| funext x y z | |
| simp [separatedTensor, Tensor.pullback, Subsingleton.elim (lx x.1) z.2, | |
| Subsingleton.elim x.2 y.2] | |
| theorem separated_prefix_synchronized | |
| (T : Tensor β X Y Z) | |
| (px : X β Prefix) (py : Y β Prefix) (pz : Z β Prefix) | |
| (lx : X β Label) (ly : Y β Label) | |
| (prefixes : β x y z, T x y z β 0 β px x = py y β§ px x = pz z) | |
| (labels : β x y z, T x y z β 0 β lx x = ly y) | |
| (x : X Γ Pairing) (y : Y Γ Pairing) (z : Z Γ Label) | |
| (h : separatedTensor lx T x y z β 0) : | |
| (px x.1, lx x.1) = (py y.1, ly y.1) β§ | |
| (px x.1, lx x.1) = (pz z.1, z.2) := by | |
| have hguard : lx x.1 = z.2 β§ x.2 = y.2 := by | |
| by_contra hn | |
| exact h (by simp [separatedTensor, hn]) | |
| have hT : T x.1 y.1 z.1 β 0 := by | |
| simpa [separatedTensor, hguard] using h | |
| obtain β¨hxy, hxzβ© := prefixes x.1 y.1 z.1 hT | |
| exact β¨Prod.ext hxy (labels x.1 y.1 z.1 hT), Prod.ext hxz hguard.1β© | |
| end PrefixSeparation | |
| section ExactPools | |
| variable {X Y Z Prefix Label : Type*} [DecidableEq Label] | |
| noncomputable def poolEnumeration (pool : Prefix β Finset Label) (k : β) | |
| (counts : β p, (pool p).card = k) : β p, β₯(pool p) β Fin k := | |
| fun p => Finset.equivFinOfCardEq (counts p) | |
| def poolCode (pool : Prefix β Finset Label) {k : β} | |
| (enumerate : β p, β₯(pool p) β Fin k) | |
| (prior : X β Prefix) (label : X β Label) | |
| (allowed : β x, label x β pool (prior x)) : X β Fin k := | |
| fun x => enumerate (prior x) β¨label x, allowed xβ© | |
| omit [DecidableEq Label] in | |
| @[simp] theorem poolCode_decode (pool : Prefix β Finset Label) {k : β} | |
| (enumerate : β p, β₯(pool p) β Fin k) | |
| (prior : X β Prefix) (label : X β Label) | |
| (allowed : β x, label x β pool (prior x)) (x : X) : | |
| ((enumerate (prior x)).symm (poolCode pool enumerate prior label allowed x)).val = | |
| label x := by | |
| simp [poolCode] | |
| omit [DecidableEq Label] in | |
| theorem poolCode_agree (pool : Prefix β Finset Label) {k : β} | |
| (enumerate : β p, β₯(pool p) β Fin k) | |
| (px : X β Prefix) (py : Y β Prefix) (lx : X β Label) (ly : Y β Label) | |
| (ax : β x, lx x β pool (px x)) (ay : β y, ly y β pool (py y)) | |
| (x : X) (y : Y) (hp : px x = py y) (hl : lx x = ly y) : | |
| poolCode pool enumerate px lx ax x = poolCode pool enumerate py ly ay y := by | |
| have congr_code : β (p q : Prefix) (a : β₯(pool p)) (b : β₯(pool q)), | |
| p = q β a.val = b.val β enumerate p a = enumerate q b := by | |
| intro p q a b hp hl | |
| cases hp | |
| exact congrArg (enumerate p) (Subtype.ext hl) | |
| exact congr_code _ _ β¨lx x, ax xβ© β¨ly y, ay yβ© hp hl | |
| noncomputable def poolAuxiliaryCost (k : β) : β := | |
| if k = 1 then 1 else Separation.gridGroupOrder k | |
| abbrev PoolAuxiliaryGroup (k : β) := | |
| Separation.AuxiliaryGroup (Separation.gridDimension k) (Separation.gridWidth k) | |
| noncomputable def poolAuxiliaryTensor (k : β) : | |
| Tensor β (PoolAuxiliaryGroup k) (PoolAuxiliaryGroup k) (PoolAuxiliaryGroup k) := | |
| if k = 1 then Tensor.rankOne (fun _ => 1) (fun _ => 1) (fun _ => 1) | |
| else groupTensor (PoolAuxiliaryGroup k) | |
| theorem poolAuxiliaryTensor_rankAtMost (k : β) : | |
| Tensor.RankAtMost (poolAuxiliaryTensor k) (poolAuxiliaryCost k) := by | |
| classical | |
| by_cases hk : k = 1 | |
| Β· simpa only [poolAuxiliaryTensor, poolAuxiliaryCost, ite_eq_left hk] using | |
| Tensor.rankOne_rankAtMost (fun _ : PoolAuxiliaryGroup k => (1 : β)) | |
| (fun _ : PoolAuxiliaryGroup k => (1 : β)) | |
| (fun _ : PoolAuxiliaryGroup k => (1 : β)) | |
| Β· simpa only [poolAuxiliaryTensor, poolAuxiliaryCost, ite_eq_right hk, | |
| PoolAuxiliaryGroup, Separation.card_auxiliaryGroup, Separation.gridGroupOrder] | |
| using groupTensor_rankAtMost (PoolAuxiliaryGroup k) | |
| omit [DecidableEq Label] in | |
| theorem exact_pool_mem_restrictionOrbit | |
| [Fintype X] [Fintype Y] [Fintype Z] | |
| (pool : Prefix β Finset Label) (k : β) (counts : β p, (pool p).card = k) | |
| (T : Tensor β X Y Z) (px : X β Prefix) (py : Y β Prefix) | |
| (lx : X β Label) (ly : Y β Label) | |
| (ax : β x, lx x β pool (px x)) (ay : β y, ly y β pool (py y)) | |
| (prefixes : β x y z, T x y z β 0 β px x = py y) | |
| (labels : β x y z, T x y z β 0 β lx x = ly y) : | |
| separatedTensor (U := Fin k) | |
| (poolCode pool (poolEnumeration pool k counts) px lx ax) T β | |
| Tensor.restrictionOrbit (Tensor.product T | |
| (groupTensor (Separation.AuxiliaryGroup | |
| (Separation.gridDimension k) (Separation.gridWidth k)))) := by | |
| classical | |
| have hagree : β x y z, T x y z β 0 β | |
| poolCode pool (poolEnumeration pool k counts) px lx ax x = | |
| poolCode pool (poolEnumeration pool k counts) py ly ay y := by | |
| intro x y z h | |
| exact poolCode_agree pool _ px py lx ly ax ay x y | |
| (prefixes x y z h) (labels x y z h) | |
| exact finite_grid_separation_mem_restrictionOrbit T | |
| (poolCode pool (poolEnumeration pool k counts) px lx ax) | |
| (poolCode pool (poolEnumeration pool k counts) py ly ay) | |
| (d := Separation.gridDimension k) (Q := Separation.gridWidth k) (m := k) | |
| (by simpa only [Fintype.card_fin] using Separation.grid_population_bound k) | |
| (Separation.grid_population_bound k) hagree | |
| omit [DecidableEq Label] in | |
| theorem exact_pool_raw_prefix_synchronized | |
| (pool : Prefix β Finset Label) {k : β} | |
| (enumerate : β p, β₯(pool p) β Fin k) | |
| (T : Tensor β X Y Z) (px : X β Prefix) (py : Y β Prefix) (pz : Z β Prefix) | |
| (lx : X β Label) (ly : Y β Label) | |
| (ax : β x, lx x β pool (px x)) (_ay : β y, ly y β pool (py y)) | |
| (prefixes : β x y z, T x y z β 0 β px x = py y β§ px x = pz z) | |
| (labels : β x y z, T x y z β 0 β lx x = ly y) | |
| {Pairing : Type*} [DecidableEq Pairing] | |
| (x : X Γ Pairing) (y : Y Γ Pairing) (z : Z Γ Fin k) | |
| (h : separatedTensor (poolCode pool enumerate px lx ax) T x y z β 0) : | |
| (px x.1, lx x.1) = (py y.1, ly y.1) β§ | |
| (px x.1, lx x.1) = (pz z.1, ((enumerate (pz z.1)).symm z.2).val) := by | |
| have guard : poolCode pool enumerate px lx ax x.1 = z.2 β§ x.2 = y.2 := by | |
| by_contra hn | |
| exact h (by simp [separatedTensor, hn]) | |
| have hT : T x.1 y.1 z.1 β 0 := by | |
| simpa [separatedTensor, guard] using h | |
| obtain β¨hxy, hxzβ© := prefixes x.1 y.1 z.1 hT | |
| have hz : lx x.1 = ((enumerate (pz z.1)).symm z.2).val := by | |
| rw [β hxz, β guard.1] | |
| exact (poolCode_decode pool enumerate px lx ax x.1).symm | |
| exact β¨Prod.ext hxy (labels x.1 y.1 z.1 hT), Prod.ext hxz hzβ© | |
| omit [DecidableEq Label] in | |
| theorem exact_pool_rankAtMost | |
| (pool : Prefix β Finset Label) (k : β) (counts : β p, (pool p).card = k) | |
| (T : Tensor β X Y Z) (px : X β Prefix) (py : Y β Prefix) | |
| (lx : X β Label) (ly : Y β Label) | |
| (ax : β x, lx x β pool (px x)) (ay : β y, ly y β pool (py y)) | |
| {r : β} (hT : Tensor.RankAtMost T r) | |
| (prefixes : β x y z, T x y z β 0 β px x = py y) | |
| (labels : β x y z, T x y z β 0 β lx x = ly y) : | |
| Tensor.RankAtMost | |
| (separatedTensor (U := Fin k) | |
| (poolCode pool (poolEnumeration pool k counts) px lx ax) T) | |
| (r * poolAuxiliaryCost k) := by | |
| classical | |
| by_cases hk : k = 1 | |
| Β· subst k | |
| have hcost : poolAuxiliaryCost 1 = 1 := by simp [poolAuxiliaryCost] | |
| rw [hcost, mul_one, deterministic_separation_identity] | |
| exact hT.pullback (fun x : X Γ Fin 1 => x.1) | |
| (fun y : Y Γ Fin 1 => y.1) (fun z : Z Γ Fin 1 => z.1) | |
| Β· have hagree : β x y z, T x y z β 0 β | |
| poolCode pool (poolEnumeration pool k counts) px lx ax x = | |
| poolCode pool (poolEnumeration pool k counts) py ly ay y := by | |
| intro x y z h | |
| exact poolCode_agree pool _ px py lx ly ax ay x y | |
| (prefixes x y z h) (labels x y z h) | |
| have hr := finite_grid_separation_rankAtMost T | |
| (poolCode pool (poolEnumeration pool k counts) px lx ax) | |
| (poolCode pool (poolEnumeration pool k counts) py ly ay) | |
| (d := Separation.gridDimension k) (Q := Separation.gridWidth k) (m := k) | |
| (lt_of_lt_of_le (by decide : 0 < 2) (Separation.gridWidth_ge_two k)) | |
| (by simpa only [Fintype.card_fin] using Separation.grid_population_bound k) | |
| (Separation.grid_population_bound k) hT hagree | |
| simpa only [poolAuxiliaryCost, ite_eq_right hk, Separation.gridGroupOrder] using hr | |
| omit [DecidableEq Label] in | |
| theorem exact_pool_borderRankAtMost | |
| [Fintype X] [Fintype Y] [Fintype Z] | |
| (pool : Prefix β Finset Label) (k : β) (counts : β p, (pool p).card = k) | |
| (T : Tensor β X Y Z) (px : X β Prefix) (py : Y β Prefix) | |
| (lx : X β Label) (ly : Y β Label) | |
| (ax : β x, lx x β pool (px x)) (ay : β y, ly y β pool (py y)) | |
| {r : β} (hT : Tensor.BorderRankAtMost T r) | |
| (prefixes : β x y z, T x y z β 0 β px x = py y) | |
| (labels : β x y z, T x y z β 0 β lx x = ly y) : | |
| Tensor.BorderRankAtMost | |
| (separatedTensor (U := Fin k) | |
| (poolCode pool (poolEnumeration pool k counts) px lx ax) T) | |
| (r * poolAuxiliaryCost k) := by | |
| classical | |
| by_cases hk : k = 1 | |
| Β· subst k | |
| have hcost : poolAuxiliaryCost 1 = 1 := by simp [poolAuxiliaryCost] | |
| rw [hcost, mul_one, deterministic_separation_identity] | |
| rw [Tensor.pullback_eq_restrict (fun x : X Γ Fin 1 => x.1) | |
| (fun y : Y Γ Fin 1 => y.1) (fun z : Z Γ Fin 1 => z.1) T] | |
| exact hT.restrict (fun (x : X Γ Fin 1) (original : X) => | |
| if original = x.1 then 1 else 0) | |
| (fun (y : Y Γ Fin 1) (original : Y) => if original = y.1 then 1 else 0) | |
| (fun (z : Z Γ Fin 1) (original : Z) => if original = z.1 then 1 else 0) | |
| Β· have hagree : β x y z, T x y z β 0 β | |
| poolCode pool (poolEnumeration pool k counts) px lx ax x = | |
| poolCode pool (poolEnumeration pool k counts) py ly ay y := by | |
| intro x y z h | |
| exact poolCode_agree pool _ px py lx ly ax ay x y | |
| (prefixes x y z h) (labels x y z h) | |
| have hr := finite_grid_separation_borderRankAtMost T | |
| (poolCode pool (poolEnumeration pool k counts) px lx ax) | |
| (poolCode pool (poolEnumeration pool k counts) py ly ay) | |
| (d := Separation.gridDimension k) (Q := Separation.gridWidth k) (m := k) | |
| (lt_of_lt_of_le (by decide : 0 < 2) (Separation.gridWidth_ge_two k)) | |
| (by simpa only [Fintype.card_fin] using Separation.grid_population_bound k) | |
| (Separation.grid_population_bound k) hT hagree | |
| simpa only [poolAuxiliaryCost, ite_eq_right hk, Separation.gridGroupOrder] using hr | |
| omit [DecidableEq Label] in | |
| theorem exact_pool_optimized_pullback | |
| (pool : Prefix β Finset Label) (k : β) (counts : β p, (pool p).card = k) | |
| (T : Tensor β X Y Z) (px : X β Prefix) (py : Y β Prefix) | |
| (lx : X β Label) (ly : Y β Label) | |
| (ax : β x, lx x β pool (px x)) (ay : β y, ly y β pool (py y)) | |
| (prefixes : β x y z, T x y z β 0 β px x = py y) | |
| (labels : β x y z, T x y z β 0 β lx x = ly y) : | |
| β (fx : X Γ Fin k β PoolAuxiliaryGroup k) | |
| (fy : Y Γ Fin k β PoolAuxiliaryGroup k) | |
| (fz : Z Γ Fin k β PoolAuxiliaryGroup k), | |
| Tensor.pullback (fun x => (x.1, fx x)) (fun y => (y.1, fy y)) | |
| (fun z => (z.1, fz z)) (Tensor.product T (poolAuxiliaryTensor k)) = | |
| separatedTensor | |
| (poolCode pool (poolEnumeration pool k counts) px lx ax) T := by | |
| classical | |
| by_cases hk : k = 1 | |
| Β· subst k | |
| refine β¨fun _ => 0, fun _ => 0, fun _ => 0, ?_β© | |
| funext x y z | |
| simp [Tensor.pullback, Tensor.product, poolAuxiliaryTensor, Tensor.rankOne, | |
| separatedTensor, Subsingleton.elim x.2 y.2, | |
| Subsingleton.elim (poolCode pool (poolEnumeration pool 1 counts) px lx ax x.1) z.2] | |
| Β· obtain β¨tag, point, collisionβ© := Separation.exists_modular_separation | |
| (Separation.grid_population_bound k) (Separation.grid_population_bound k) | |
| have hagree : β x y z, T x y z β 0 β | |
| poolCode pool (poolEnumeration pool k counts) px lx ax x = | |
| poolCode pool (poolEnumeration pool k counts) py ly ay y := by | |
| intro x y z h | |
| exact poolCode_agree pool _ px py lx ly ax ay x y | |
| (prefixes x y z h) (labels x y z h) | |
| refine β¨fun x => point | |
| (poolCode pool (poolEnumeration pool k counts) px lx ax x.1) x.2, | |
| fun y => tag (poolCode pool (poolEnumeration pool k counts) py ly ay y.1) - | |
| point (poolCode pool (poolEnumeration pool k counts) py ly ay y.1) y.2, | |
| fun z => tag z.2, ?_β© | |
| simpa only [poolAuxiliaryTensor, ite_eq_right hk] using finite_separation_identity T | |
| (poolCode pool (poolEnumeration pool k counts) px lx ax) | |
| (poolCode pool (poolEnumeration pool k counts) py ly ay) tag point hagree collision | |
| omit [DecidableEq Label] in | |
| theorem exact_pool_optimized_mem_restrictionOrbit | |
| [Fintype X] [Fintype Y] [Fintype Z] | |
| (pool : Prefix β Finset Label) (k : β) (counts : β p, (pool p).card = k) | |
| (T : Tensor β X Y Z) (px : X β Prefix) (py : Y β Prefix) | |
| (lx : X β Label) (ly : Y β Label) | |
| (ax : β x, lx x β pool (px x)) (ay : β y, ly y β pool (py y)) | |
| (prefixes : β x y z, T x y z β 0 β px x = py y) | |
| (labels : β x y z, T x y z β 0 β lx x = ly y) : | |
| separatedTensor (U := Fin k) | |
| (poolCode pool (poolEnumeration pool k counts) px lx ax) T β | |
| Tensor.restrictionOrbit (Tensor.product T (poolAuxiliaryTensor k)) := by | |
| classical | |
| obtain β¨fx, fy, fz, heqβ© := | |
| exact_pool_optimized_pullback pool k counts T px py lx ly ax ay prefixes labels | |
| rw [β heq] | |
| exact β¨_, _, _, Tensor.pullback_eq_restrict _ _ _ _β© | |
| end ExactPools | |
| section SharedBranches | |
| variable {K X Y Z A B C A' B' C' Label : Type*} | |
| variable [CommSemiring K] [Fintype X] [Fintype Y] [Fintype Z] | |
| variable [Fintype A] [Fintype B] [Fintype C] [Fintype Label] | |
| theorem shared_branch_rankAtMost | |
| (lx : X β Label) (ly : Y β Label) (lz : Z β Label) | |
| (MX : Label β X β A' β A β K) (MY : Label β Y β B' β B β K) | |
| (MZ : Label β Z β C' β C β K) | |
| (T : Tensor K (X Γ A) (Y Γ B) (Z Γ C)) {r : β} | |
| (hT : Tensor.RankAtMost T r) | |
| (synchronized : LocalMaps.SupportedOn (LocalMaps.Synchronized lx ly lz) T) : | |
| Tensor.RankAtMost | |
| (fun x y z => β label, | |
| LocalMaps.fiberTransform (MX label) (MY label) (MZ label) | |
| (LocalMaps.originalMask (LocalMaps.InBranch lx ly lz label) T) x y z) | |
| r := by | |
| classical | |
| rw [β LocalMaps.controlled_eq_sum_branches_of_supported | |
| lx ly lz MX MY MZ T synchronized] | |
| rw [LocalMaps.fiberTransform_eq_restrict] | |
| exact hT.restrict _ _ _ | |
| end SharedBranches | |
| section FiniteAssembly | |
| universe u | |
| variable {K : Type*} [CommSemiring K] | |
| variable {X Y Z A B C : β β Type*} | |
| def AuxiliaryCoordinates (A : β β Type u) : β β Type u | |
| | 0 => PUnit | |
| | n + 1 => AuxiliaryCoordinates A n Γ A n | |
| instance auxiliaryCoordinatesFintype [β n, Fintype (A n)] (n : β) : | |
| Fintype (AuxiliaryCoordinates A n) := by | |
| induction n with | |
| | zero => exact inferInstanceAs (Fintype PUnit) | |
| | succ n ih => | |
| letI : Fintype (AuxiliaryCoordinates A n) := ih | |
| exact inferInstanceAs (Fintype (AuxiliaryCoordinates A n Γ A n)) | |
| def auxiliaryTensor (E : β n, Tensor K (A n) (B n) (C n)) : | |
| β n, Tensor K (AuxiliaryCoordinates A n) | |
| (AuxiliaryCoordinates B n) (AuxiliaryCoordinates C n) | |
| | 0 => fun _ _ _ => 1 | |
| | n + 1 => Tensor.product (auxiliaryTensor E n) (E n) | |
| def sourceCoordinate (step : β n, X (n + 1) β X n Γ A n) : | |
| β n, X n β X 0 | |
| | 0 => id | |
| | n + 1 => fun x => sourceCoordinate step n (step n x).1 | |
| def auxiliaryCoordinate (step : β n, X (n + 1) β X n Γ A n) : | |
| β n, X n β AuxiliaryCoordinates A n | |
| | 0 => fun _ => PUnit.unit | |
| | n + 1 => fun x => (auxiliaryCoordinate step n (step n x).1, (step n x).2) | |
| def stageTensor (T : Tensor K (X 0) (Y 0) (Z 0)) | |
| (E : β n, Tensor K (A n) (B n) (C n)) | |
| (fx : β n, X (n + 1) β X n Γ A n) | |
| (fy : β n, Y (n + 1) β Y n Γ B n) | |
| (fz : β n, Z (n + 1) β Z n Γ C n) : | |
| β n, Tensor K (X n) (Y n) (Z n) | |
| | 0 => T | |
| | n + 1 => Tensor.pullback (fx n) (fy n) (fz n) | |
| (Tensor.product (stageTensor T E fx fy fz n) (E n)) | |
| theorem stageTensor_eq_shared_bank | |
| (T : Tensor K (X 0) (Y 0) (Z 0)) | |
| (E : β n, Tensor K (A n) (B n) (C n)) | |
| (fx : β n, X (n + 1) β X n Γ A n) | |
| (fy : β n, Y (n + 1) β Y n Γ B n) | |
| (fz : β n, Z (n + 1) β Z n Γ C n) (n : β) : | |
| stageTensor T E fx fy fz n = | |
| Tensor.pullback | |
| (fun x => (sourceCoordinate fx n x, auxiliaryCoordinate fx n x)) | |
| (fun y => (sourceCoordinate fy n y, auxiliaryCoordinate fy n y)) | |
| (fun z => (sourceCoordinate fz n z, auxiliaryCoordinate fz n z)) | |
| (Tensor.product T (auxiliaryTensor E n)) := by | |
| induction n with | |
| | zero => | |
| funext x y z | |
| simp [stageTensor, Tensor.pullback, Tensor.product, sourceCoordinate, | |
| auxiliaryTensor] | |
| | succ n ih => | |
| funext x y z | |
| simp only [stageTensor, Tensor.pullback, Tensor.product] | |
| rw [ih] | |
| simp only [Tensor.pullback, Tensor.product, sourceCoordinate, | |
| auxiliaryCoordinate, auxiliaryTensor, mul_assoc] | |
| theorem auxiliaryTensor_rankAtMost | |
| (E : β n, Tensor K (A n) (B n) (C n)) (r : β β β) | |
| (hE : β n, Tensor.RankAtMost (E n) (r n)) (n : β) : | |
| Tensor.RankAtMost (auxiliaryTensor E n) (β j β Finset.range n, r j) := by | |
| induction n with | |
| | zero => | |
| rw [Finset.prod_range_zero] | |
| refine β¨fun _ _ => 1, fun _ _ => 1, fun _ _ => 1, ?_β© | |
| funext x y z | |
| simp [auxiliaryTensor, Tensor.rankOne] | |
| | succ n ih => | |
| rw [Finset.prod_range_succ] | |
| exact ih.product (hE n) | |
| theorem stageTensor_rankAtMost | |
| (T : Tensor K (X 0) (Y 0) (Z 0)) {rT : β} | |
| (hT : Tensor.RankAtMost T rT) | |
| (E : β n, Tensor K (A n) (B n) (C n)) (r : β β β) | |
| (hE : β n, Tensor.RankAtMost (E n) (r n)) | |
| (fx : β n, X (n + 1) β X n Γ A n) | |
| (fy : β n, Y (n + 1) β Y n Γ B n) | |
| (fz : β n, Z (n + 1) β Z n Γ C n) (n : β) : | |
| Tensor.RankAtMost (stageTensor T E fx fy fz n) | |
| (rT * β j β Finset.range n, r j) := by | |
| rw [stageTensor_eq_shared_bank] | |
| exact (hT.product (auxiliaryTensor_rankAtMost E r hE n)).pullback _ _ _ | |
| theorem stageTensor_borderRankAtMost | |
| [β n, Fintype (X n)] [β n, Fintype (Y n)] [β n, Fintype (Z n)] | |
| [β n, Fintype (A n)] [β n, Fintype (B n)] [β n, Fintype (C n)] | |
| (T : Tensor β (X 0) (Y 0) (Z 0)) {rT : β} | |
| (hT : Tensor.BorderRankAtMost T rT) | |
| (E : β n, Tensor β (A n) (B n) (C n)) (r : β β β) | |
| (hE : β n, Tensor.RankAtMost (E n) (r n)) | |
| (fx : β n, X (n + 1) β X n Γ A n) | |
| (fy : β n, Y (n + 1) β Y n Γ B n) | |
| (fz : β n, Z (n + 1) β Z n Γ C n) (n : β) : | |
| Tensor.BorderRankAtMost (stageTensor T E fx fy fz n) | |
| (rT * β j β Finset.range n, r j) := by | |
| classical | |
| rw [stageTensor_eq_shared_bank, Tensor.pullback_eq_restrict] | |
| exact (hT.product (auxiliaryTensor_rankAtMost E r hE n).borderRankAtMost).restrict _ _ _ | |
| end FiniteAssembly | |
| end LabelHierarchySeparation | |
| end MatrixMultiplication.Foundation | |
| end OAI | |