File size: 14,783 Bytes
f18e7de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import OAI.LinearAlgebra.MatrixMultiplication.Polynomial.ComplexPolynomialLocalConstruction
import OAI.LinearAlgebra.MatrixMultiplication.Tensor.ComplexTensorRestrictionComposition

namespace OAI

/-! Polynomial tensor restrictions and exact coefficient extraction. -/

noncomputable section

namespace MatrixMultiplication.Foundation
namespace PolynomialControlledKernel

open Tensor LocalMaps PolynomialLocalConstruction
open scoped BigOperators

section ScalarCoefficients

variable {F : Type*} [Field F]

theorem expanded_mul_coeff_window (P Q : Polynomial F) (d k : ℕ) (a : F)
    (hP : ∀ j, j < d → P.coeff j = 0) (hPa : P.coeff d = a)
    (j : ℕ) (hj : j ≤ d * (k + 1) + k) :
    (Polynomial.expand F (k + 1) P * Q).coeff j =
      if d * (k + 1) ≤ j then a * Q.coeff (j - d * (k + 1)) else 0 := by
  obtain ⟨P₀, hP₀⟩ := Polynomial.X_pow_dvd_iff.mpr hP
  have hconstant : P₀.coeff 0 = a := by
    rw [hP₀] at hPa
    simpa only [Polynomial.coeff_X_pow_mul', le_refl, ite_true, Nat.sub_self] using hPa
  have hfactor : Polynomial.expand F (k + 1) P * Q =
      Polynomial.X ^ (d * (k + 1)) *
        (Q * Polynomial.expand F (k + 1) P₀) := by
    rw [hP₀, map_mul, map_pow, Polynomial.expand_X]
    simp only [← pow_mul]
    rw [Nat.mul_comm (k + 1) d]
    ring
  rw [hfactor, Polynomial.coeff_X_pow_mul']
  split_ifs with hdj
  · have hsmall : j - d * (k + 1) ≤ k := by omega
    rw [Tensor.coeff_mul_expand_eq_constant Q P₀ a hconstant k _ hsmall,
      Polynomial.coeff_mul_C, mul_comm]
  · rfl

theorem expanded_mul_vanishes_of_leading_support (P Q : Polynomial F)
    (d k : ℕ) (a : F)
    (hP : ∀ j, j < d → P.coeff j = 0) (hPa : P.coeff d = a)
    (hQ : a ≠ 0 → ∀ j, j < k → Q.coeff j = 0)
    (j : ℕ) (hj : j < d * (k + 1) + k) :
    (Polynomial.expand F (k + 1) P * Q).coeff j = 0 := by
  rw [expanded_mul_coeff_window P Q d k a hP hPa j (Nat.le_of_lt hj)]
  split_ifs with hdj
  · by_cases ha : a = 0
    · simp [ha]
    · rw [hQ ha _ (by omega), mul_zero]
  · rfl

theorem expanded_mul_leading_of_leading_support (P Q : Polynomial F)
    (d k : ℕ) (a b : F)
    (hP : ∀ j, j < d → P.coeff j = 0) (hPa : P.coeff d = a)
    (hQb : a ≠ 0 → Q.coeff k = b) :
    (Polynomial.expand F (k + 1) P * Q).coeff (d * (k + 1) + k) = a * b := by
  rw [expanded_mul_coeff_window P Q d k a hP hPa _ le_rfl]
  simp only [Nat.le_add_right, ite_true, Nat.add_sub_cancel_left]
  by_cases ha : a = 0
  · simp [ha]
  · rw [hQb ha]

end ScalarCoefficients

abbrev Output (Prefix New OldCoord NewCoord : Type*) :=
  (Prefix × OldCoord) × (New × NewCoord)

section ActualMatrices

variable {X Y Z Prefix New PX PY PZ NX NY NZ AP BP CP AS BS CS : Type*}
variable [Fintype AP] [Fintype BP] [Fintype CP]
variable [Fintype AS] [Fintype BS] [Fintype CS]

def expandMap {O A : Type*} (factor : ℕ) (M : X → O → A → Polynomial ℂ) :
    X → O → A → Polynomial ℂ :=
  fun x output input => Polynomial.expand ℂ factor (M x output input)

def controlledMap (kStep : ℕ)
    (previous : X → (Prefix × PX) → AP → Polynomial ℂ)
    (step : Prefix → X → (New × NX) → AS → Polynomial ℂ) :
    X → Output Prefix New PX NX → (AP × AS) → Polynomial ℂ :=
  fun x output input =>
    Polynomial.expand ℂ (kStep + 1) (previous x output.1 input.1) *
      step output.1.1 x output.2 input.2

omit [Fintype AP] [Fintype AS] in
theorem controlledMap_degree (kStep dPrevious dStep : ℕ)
    (previous : X → (Prefix × PX) → AP → Polynomial ℂ)
    (step : Prefix → X → (New × NX) → AS → Polynomial ℂ)
    (hp : ∀ x output input, (previous x output input).degree ≤ dPrevious)
    (hs : ∀ prior x output input, (step prior x output input).degree ≤ dStep)
    (x : X) (output : Output Prefix New PX NX) (input : AP × AS) :
    (controlledMap kStep previous step x output input).degree ≤
      dPrevious * (kStep + 1) + dStep := by
  apply Polynomial.degree_le_of_natDegree_le
  apply Polynomial.natDegree_mul_le_of_le
  · rw [Polynomial.natDegree_expand]
    exact Nat.mul_le_mul_right (kStep + 1)
      (Polynomial.natDegree_le_of_degree_le (hp x output.1 input.1))
  · exact Polynomial.natDegree_le_of_degree_le
      (hs output.1.1 x output.2 input.2)

theorem kernel_expandMap (factor : ℕ) (auxiliary : Tensor ℂ AP BP CP)
    (MX : X → (Prefix × PX) → AP → Polynomial ℂ)
    (MY : Y → (Prefix × PY) → BP → Polynomial ℂ)
    (MZ : Z → (Prefix × PZ) → CP → Polynomial ℂ)
    (x : X × (Prefix × PX)) (y : Y × (Prefix × PY)) (z : Z × (Prefix × PZ)) :
    kernel auxiliary (expandMap factor MX) (expandMap factor MY) (expandMap factor MZ)
        x y z = Polynomial.expand ℂ factor (kernel auxiliary MX MY MZ x y z) := by
  simp only [kernel, fiberTransform, expandMap, map_sum, map_mul, Polynomial.expand_C]

def mixedStageKernel (auxiliary : Tensor ℂ AS BS CS)
    (SX : Prefix → X → (New × NX) → AS → Polynomial ℂ)
    (SY : Prefix → Y → (New × NY) → BS → Polynomial ℂ)
    (SZ : Prefix → Z → (New × NZ) → CS → Polynomial ℂ) :
    Tensor (Polynomial ℂ) (X × Output Prefix New PX NX)
      (Y × Output Prefix New PY NY) (Z × Output Prefix New PZ NZ) :=
  fun x y z => kernel auxiliary (SX x.2.1.1) (SY y.2.1.1) (SZ z.2.1.1)
    (x.1, x.2.2) (y.1, y.2.2) (z.1, z.2.2)

def controlledKernel (kStep : ℕ)
    (previousAuxiliary : Tensor ℂ AP BP CP) (stepAuxiliary : Tensor ℂ AS BS CS)
    (MX : X → (Prefix × PX) → AP → Polynomial ℂ)
    (MY : Y → (Prefix × PY) → BP → Polynomial ℂ)
    (MZ : Z → (Prefix × PZ) → CP → Polynomial ℂ)
    (SX : Prefix → X → (New × NX) → AS → Polynomial ℂ)
    (SY : Prefix → Y → (New × NY) → BS → Polynomial ℂ)
    (SZ : Prefix → Z → (New × NZ) → CS → Polynomial ℂ) :
    Tensor (Polynomial ℂ) (X × Output Prefix New PX NX)
      (Y × Output Prefix New PY NY) (Z × Output Prefix New PZ NZ) :=
  kernel (Tensor.product previousAuxiliary stepAuxiliary)
    (controlledMap kStep MX SX) (controlledMap kStep MY SY) (controlledMap kStep MZ SZ)

theorem controlledKernel_factor (kStep : ℕ)
    (previousAuxiliary : Tensor ℂ AP BP CP) (stepAuxiliary : Tensor ℂ AS BS CS)
    (MX : X → (Prefix × PX) → AP → Polynomial ℂ)
    (MY : Y → (Prefix × PY) → BP → Polynomial ℂ)
    (MZ : Z → (Prefix × PZ) → CP → Polynomial ℂ)
    (SX : Prefix → X → (New × NX) → AS → Polynomial ℂ)
    (SY : Prefix → Y → (New × NY) → BS → Polynomial ℂ)
    (SZ : Prefix → Z → (New × NZ) → CS → Polynomial ℂ)
    (x : X × Output Prefix New PX NX) (y : Y × Output Prefix New PY NY)
    (z : Z × Output Prefix New PZ NZ) :
    controlledKernel kStep previousAuxiliary stepAuxiliary MX MY MZ SX SY SZ x y z =
      Polynomial.expand ℂ (kStep + 1)
        (kernel previousAuxiliary MX MY MZ (x.1, x.2.1) (y.1, y.2.1) (z.1, z.2.1)) *
      mixedStageKernel stepAuxiliary SX SY SZ x y z := by
  have h := congrFun (congrFun (congrFun
    (Tensor.restrict_product (expandMap (kStep + 1) MX x.1)
      (expandMap (kStep + 1) MY y.1) (expandMap (kStep + 1) MZ z.1)
      (SX x.2.1.1 x.1) (SY y.2.1.1 y.1) (SZ z.2.1.1 z.1)
      (fun a b c => Polynomial.C (previousAuxiliary a b c))
      (fun a b c => Polynomial.C (stepAuxiliary a b c))) x.2) y.2) z.2
  have hproduct :
      controlledKernel kStep previousAuxiliary stepAuxiliary MX MY MZ SX SY SZ x y z =
        kernel previousAuxiliary (expandMap (kStep + 1) MX)
          (expandMap (kStep + 1) MY) (expandMap (kStep + 1) MZ)
          (x.1, x.2.1) (y.1, y.2.1) (z.1, z.2.1) *
        mixedStageKernel stepAuxiliary SX SY SZ x y z := by
    simpa only [controlledKernel, kernel, fiberTransform, Tensor.restrict, Tensor.product,
      controlledMap, expandMap, mixedStageKernel, map_mul] using h
  rw [hproduct, kernel_expandMap]

theorem controlledKernel_substitution (kStep : ℕ)
    (previousAuxiliary : Tensor ℂ AP BP CP) (stepAuxiliary : Tensor ℂ AS BS CS)
    (MX : X → (Prefix × PX) → AP → Polynomial ℂ)
    (MY : Y → (Prefix × PY) → BP → Polynomial ℂ)
    (MZ : Z → (Prefix × PZ) → CP → Polynomial ℂ)
    (SX : Prefix → X → (New × NX) → AS → Polynomial ℂ)
    (SY : Prefix → Y → (New × NY) → BS → Polynomial ℂ)
    (SZ : Prefix → Z → (New × NZ) → CS → Polynomial ℂ)
    (original : Tensor ℂ X Y Z) :
    fiberTransform (controlledMap kStep MX SX) (controlledMap kStep MY SY)
        (controlledMap kStep MZ SZ)
        (fun x y z => Polynomial.C
          (Tensor.product original (Tensor.product previousAuxiliary stepAuxiliary) x y z)) =
      originalScale (fun x y z => Polynomial.C (original x y z))
        (controlledKernel kStep previousAuxiliary stepAuxiliary MX MY MZ SX SY SZ) := by
  have h := fiberTransform_originalScale (controlledMap kStep MX SX)
    (controlledMap kStep MY SY) (controlledMap kStep MZ SZ)
    (fun x y z => Polynomial.C (original x y z))
    (fun x y z => Polynomial.C (Tensor.product previousAuxiliary stepAuxiliary x.2 y.2 z.2))
  have hinput :
      (fun x y z => Polynomial.C
        (Tensor.product original (Tensor.product previousAuxiliary stepAuxiliary) x y z)) =
        originalScale (fun x y z => Polynomial.C (original x y z))
          (fun x y z => Polynomial.C
            (Tensor.product previousAuxiliary stepAuxiliary x.2 y.2 z.2)) := by
    funext x y z
    simp only [Tensor.product, originalScale, map_mul]
  rw [hinput]
  simpa only [controlledKernel, kernel] using h

def controlledLeading
    (previous : Tensor ℂ (X × (Prefix × PX)) (Y × (Prefix × PY)) (Z × (Prefix × PZ)))
    (step : Prefix → Tensor ℂ (X × (New × NX)) (Y × (New × NY)) (Z × (New × NZ))) :
    Tensor ℂ (X × Output Prefix New PX NX) (Y × Output Prefix New PY NY)
      (Z × Output Prefix New PZ NZ) :=
  fun x y z => previous (x.1, x.2.1) (y.1, y.2.1) (z.1, z.2.1) *
    step x.2.1.1 (x.1, x.2.2) (y.1, y.2.2) (z.1, z.2.2)

theorem controlledKernel_coefficients (dPrevious kStep : ℕ)
    (previousAuxiliary : Tensor ℂ AP BP CP) (stepAuxiliary : Tensor ℂ AS BS CS)
    (MX : X → (Prefix × PX) → AP → Polynomial ℂ)
    (MY : Y → (Prefix × PY) → BP → Polynomial ℂ)
    (MZ : Z → (Prefix × PZ) → CP → Polynomial ℂ)
    (SX : Prefix → X → (New × NX) → AS → Polynomial ℂ)
    (SY : Prefix → Y → (New × NY) → BS → Polynomial ℂ)
    (SZ : Prefix → Z → (New × NZ) → CS → Polynomial ℂ)
    (previous : Tensor ℂ (X × (Prefix × PX)) (Y × (Prefix × PY)) (Z × (Prefix × PZ)))
    (step : Prefix → Tensor ℂ (X × (New × NX)) (Y × (New × NY)) (Z × (New × NZ)))
    (support : X → Y → Z → Prop) (eligible : Prefix → X → Y → Z → Prop)
    (hprevious_low : ∀ x y z, support x.1 y.1 z.1 → ∀ j, j < dPrevious →
      (kernel previousAuxiliary MX MY MZ x y z).coeff j = 0)
    (hprevious_leading : ∀ x y z, support x.1 y.1 z.1 →
      (kernel previousAuxiliary MX MY MZ x y z).coeff dPrevious = previous x y z)
    (hprevious_support : ∀ x y z, support x.1 y.1 z.1 → previous x y z ≠ 0 →
      x.2.1 = y.2.1 ∧ x.2.1 = z.2.1 ∧ eligible x.2.1 x.1 y.1 z.1)
    (hstep_low : ∀ prior x y z, eligible prior x.1 y.1 z.1 →
      ∀ j, j < kStep →
      (kernel stepAuxiliary (SX prior) (SY prior) (SZ prior) x y z).coeff j = 0)
    (hstep_leading : ∀ prior x y z, eligible prior x.1 y.1 z.1 →
      (kernel stepAuxiliary (SX prior) (SY prior) (SZ prior) x y z).coeff kStep =
        step prior x y z) :
    (∀ x y z, support x.1 y.1 z.1 → ∀ j, j < dPrevious * (kStep + 1) + kStep →
      (controlledKernel kStep previousAuxiliary stepAuxiliary MX MY MZ SX SY SZ x y z).coeff j = 0) ∧
    (∀ x y z, support x.1 y.1 z.1 →
      (controlledKernel kStep previousAuxiliary stepAuxiliary MX MY MZ SX SY SZ x y z).coeff
        (dPrevious * (kStep + 1) + kStep) = controlledLeading previous step x y z) := by
  have hselected : ∀ (x : X × Output Prefix New PX NX)
      (y : Y × Output Prefix New PY NY) (z : Z × Output Prefix New PZ NZ),
      support x.1 y.1 z.1 →
      previous (x.1, x.2.1) (y.1, y.2.1) (z.1, z.2.1) ≠ 0 →
      (∀ j, j < kStep → (mixedStageKernel stepAuxiliary SX SY SZ x y z).coeff j = 0) ∧
        (mixedStageKernel stepAuxiliary SX SY SZ x y z).coeff kStep =
          step x.2.1.1 (x.1, x.2.2) (y.1, y.2.2) (z.1, z.2.2) := by
    intro x y z hs hn
    obtain ⟨hxy, hxz, he⟩ :=
      hprevious_support (x.1, x.2.1) (y.1, y.2.1) (z.1, z.2.1) hs hn
    have hy : y.2.1.1 = x.2.1.1 := hxy.symm
    have hz : z.2.1.1 = x.2.1.1 := hxz.symm
    constructor
    · intro j hj
      simpa only [mixedStageKernel, hy, hz] using
        hstep_low x.2.1.1 (x.1, x.2.2) (y.1, y.2.2) (z.1, z.2.2) he j hj
    · simpa only [mixedStageKernel, hy, hz] using
        hstep_leading x.2.1.1 (x.1, x.2.2) (y.1, y.2.2) (z.1, z.2.2) he
  constructor
  · intro x y z hs j hj
    rw [controlledKernel_factor]
    exact expanded_mul_vanishes_of_leading_support _ _ dPrevious kStep
      (previous (x.1, x.2.1) (y.1, y.2.1) (z.1, z.2.1))
      (hprevious_low _ _ _ hs) (hprevious_leading _ _ _ hs)
      (fun hn => (hselected x y z hs hn).1) j hj
  · intro x y z hs
    rw [controlledKernel_factor]
    exact expanded_mul_leading_of_leading_support _ _ dPrevious kStep
      (previous (x.1, x.2.1) (y.1, y.2.1) (z.1, z.2.1))
      (step x.2.1.1 (x.1, x.2.2) (y.1, y.2.2) (z.1, z.2.2))
      (hprevious_low _ _ _ hs) (hprevious_leading _ _ _ hs)
      (fun hn => (hselected x y z hs hn).2)

theorem controlledKernel_rank [Fintype X] [Fintype Y] [Fintype Z]
    (kStep : ℕ) (previousAuxiliary : Tensor ℂ AP BP CP) (stepAuxiliary : Tensor ℂ AS BS CS)
    (MX : X → (Prefix × PX) → AP → Polynomial ℂ)
    (MY : Y → (Prefix × PY) → BP → Polynomial ℂ)
    (MZ : Z → (Prefix × PZ) → CP → Polynomial ℂ)
    (SX : Prefix → X → (New × NX) → AS → Polynomial ℂ)
    (SY : Prefix → Y → (New × NY) → BS → Polynomial ℂ)
    (SZ : Prefix → Z → (New × NZ) → CS → Polynomial ℂ)
    {rPrevious rStep : ℕ} (hp : RankAtMost previousAuxiliary rPrevious)
    (hs : RankAtMost stepAuxiliary rStep) :
    RankAtMost (controlledKernel kStep previousAuxiliary stepAuxiliary MX MY MZ SX SY SZ)
      (rPrevious * rStep) := by
  classical
  have hsource := ((hp.product hs).map Polynomial.C).pullback
    (fun x : X × (AP × AS) => x.2) (fun y : Y × (BP × BS) => y.2)
    (fun z : Z × (CP × CS) => z.2)
  unfold controlledKernel kernel
  rw [fiberTransform_eq_restrict]
  exact hsource.restrict _ _ _

end ActualMatrices

end PolynomialControlledKernel
end MatrixMultiplication.Foundation

end

end OAI