File size: 18,953 Bytes
cdec422 | 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 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | import OAI.LinearAlgebra.MatrixMultiplication.CoppersmithWinograd.ComplexCW75InitialExecution
import OAI.LinearAlgebra.MatrixMultiplication.ComplexBounds.CW75ReorderedWords
import OAI.LinearAlgebra.MatrixMultiplication.ComplexBounds.CW75ReorderedGeometricValues
import OAI.LinearAlgebra.MatrixMultiplication.Entropy.ComplexConditionalHierarchyStage
import OAI.LinearAlgebra.MatrixMultiplication.Entropy.ComplexOrientedConditionalHierarchyStage
import OAI.LinearAlgebra.MatrixMultiplication.Tensor.ComplexGeometricStageCoordinates
import OAI.LinearAlgebra.MatrixMultiplication.Polynomial.ComplexPolynomialExecutionReindex
namespace OAI
/-! Explicit complex square and rectangular matrix multiplication bounds. -/
noncomputable section
namespace MatrixMultiplication.CW75ReorderedExecution
open MatrixMultiplication.Foundation
open CW75LabelHierarchy CW75ReorderedWords ConditionalPrefixWords ComplexWitness
open PolynomialKernelExecution ExecutionPairingBudget StageHierarchyResources
open scoped BigOperators Classical
attribute [local irreducible] CW75LabelHierarchy.retainedWords
abbrev Position (counts : Scalar → ℕ) (t : ℕ) := BlockPosition counts t
abbrev Coordinate (counts : Scalar → ℕ) (t : ℕ) := LongWord (Position counts t)
abbrev Prefix (counts : Scalar → ℕ) (t n : ℕ) :=
ExactPrefix counts curveLabels n t (Position counts t)
def readerPair : ℕ → ReaderPair
| 1 => .xz
| 3 | 4 => .yz
| _ => .xy
def pairingProduct (counts : Scalar → ℕ) (t : ℕ) (pair : ReaderPair) (n : ℕ) : ℕ :=
∏ i ∈ Finset.range n, if readerPair i = pair then
stageRefinementCount counts curveLabels i t else 1
@[simp] theorem pairingProduct_zero (counts : Scalar → ℕ) (t : ℕ) (pair : ReaderPair) :
pairingProduct counts t pair 0 = 1 := by simp [pairingProduct]
theorem pairingProduct_succ (counts : Scalar → ℕ) (t : ℕ) (pair : ReaderPair) (n : ℕ) :
pairingProduct counts t pair (n + 1) = pairingProduct counts t pair n *
(if readerPair n = pair then stageRefinementCount counts curveLabels n t else 1) := by
simp only [pairingProduct, Finset.prod_range_succ]
def prefixValue {PX PY PZ : Type*} (counts : Scalar → ℕ) (t n : ℕ)
(pairing : Tensor ℂ PX PY PZ) :
Tensor ℂ (Coordinate counts t × (Prefix counts t n × PX))
(Coordinate counts t × (Prefix counts t n × PY))
(Coordinate counts t × (Prefix counts t n × PZ)) :=
fun x y z => if x.2.1 = y.2.1 ∧ x.2.1 = z.2.1 ∧
eligible id x.2.1 x.1 y.1 z.1 then pairing x.2.2 y.2.2 z.2.2 else 0
structure Bundle (counts : Scalar → ℕ) (t n : ℕ) where
PX : Type
PY : Type
PZ : Type
AX : Type
AY : Type
AZ : Type
[finitePX : Fintype PX]
[finitePY : Fintype PY]
[finitePZ : Fintype PZ]
[finiteAX : Fintype AX]
[finiteAY : Fintype AY]
[finiteAZ : Fintype AZ]
execution : Execution (Coordinate counts t) (Coordinate counts t) (Coordinate counts t)
(Prefix counts t n) PX PY PZ AX AY AZ
(CW75InitialExecution.support (N := t * ∑ a, counts a))
shape : MatrixCoordinates PX PY PZ
shape_positive : shape.Positive
normal : execution.value = prefixValue counts t n shape.tensor
rank_exact : execution.rankBound = stageAuxiliaryBudget counts curveLabels n t
volume_exact : shape.volume = stagePairingProduct counts curveLabels n t
rows_exact : shape.rows = pairingProduct counts t .xz n
inner_exact : shape.inner = pairingProduct counts t .xy n
columns_exact : shape.columns = pairingProduct counts t .yz n
pairing_budget : shape.volume ≤ execution.rankBound
attribute [instance] Bundle.finitePX Bundle.finitePY Bundle.finitePZ
attribute [instance] Bundle.finiteAX Bundle.finiteAY Bundle.finiteAZ
theorem position_card (counts : Scalar → ℕ) (t : ℕ) :
Fintype.card (Position counts t) = ∑ a, t * counts a := by
simp [Position, BlockPosition, Finset.mul_sum]
def initial (counts : Scalar → ℕ) (t : ℕ) : Bundle counts t 0 := by
let E := (CW75InitialExecution.execution (t * ∑ a, counts a)).reindexOutput
(rootPrefixEquiv counts curveLabels t (Position counts t) (position_card counts t))
(Equiv.refl PUnit) (Equiv.refl PUnit) (Equiv.refl PUnit)
refine {
PX := PUnit
PY := PUnit
PZ := PUnit
AX := PUnit
AY := PUnit
AZ := PUnit
execution := E
shape := MatrixCoordinates.scalar
shape_positive := MatrixCoordinates.scalar_positive
normal := ?_
rank_exact := ?_
volume_exact := ?_
rows_exact := by simp [MatrixCoordinates.scalar]
inner_exact := by simp [MatrixCoordinates.scalar]
columns_exact := by simp [MatrixCoordinates.scalar]
pairing_budget := le_rfl
}
· funext x y z
change E.value x y z = prefixValue counts t 0 MatrixCoordinates.scalar.tensor x y z
rw [Execution.reindexOutput_value, CW75InitialExecution.value_retained]
have hxy : x.2.1 = y.2.1 := Subsingleton.elim _ _
have hxz : x.2.1 = z.2.1 := Subsingleton.elim _ _
have hguard : (x.2.1 = y.2.1 ∧ x.2.1 = z.2.1 ∧
eligible id x.2.1 x.1 y.1 z.1) ↔
∀ i, CW75Primitive.tensor (x.1 i) (y.1 i) (z.1 i) ≠ 0 := by
rw [root_eligible_iff]
exact ⟨fun h => h.2.2, fun h => ⟨hxy, hxz, h⟩⟩
simp only [prefixValue, hguard, MatrixCoordinates.scalar_tensor]
· change 1 = stageAuxiliaryBudget counts curveLabels 0 t
simp [stageAuxiliaryBudget]
· change 1 = stagePairingProduct counts curveLabels 0 t
simp [stagePairingProduct]
theorem previous_eligible {counts : Scalar → ℕ} {t n : ℕ} (B : Bundle counts t n)
(x : Coordinate counts t × (Prefix counts t n × B.PX))
(y : Coordinate counts t × (Prefix counts t n × B.PY))
(z : Coordinate counts t × (Prefix counts t n × B.PZ))
(_hs : CW75InitialExecution.support (N := t * ∑ a, counts a) x.1 y.1 z.1)
(hn : B.execution.value x y z ≠ 0) : eligible id x.2.1 x.1 y.1 z.1 := by
rw [B.normal] at hn
by_contra h
exact hn (by simp [prefixValue, h])
section Successor
variable {counts : Scalar → ℕ} {t n : ℕ} (B : Bundle counts t n)
variable {NX NY NZ BX BY BZ : Type}
variable [Fintype BX] [Fintype BY] [Fintype BZ]
def refinedExecution
(S : Stage B.execution (Fin (stageRefinementCount counts curveLabels n t))
NX NY NZ BX BY BZ) :
Execution (Coordinate counts t) (Coordinate counts t) (Coordinate counts t)
(Prefix counts t (n + 1)) (B.PX × NX) (B.PY × NY) (B.PZ × NZ)
(B.AX × BX) (B.AY × BY) (B.AZ × BZ)
(CW75InitialExecution.support (N := t * ∑ a, counts a)) :=
(B.execution.step S).reindexOutput
(nextPrefixEquiv counts curveLabels n t (Position counts t))
(Equiv.refl _) (Equiv.refl _) (Equiv.refl _)
theorem refinedExecution_normal
(S : Stage B.execution (Fin (stageRefinementCount counts curveLabels n t))
NX NY NZ BX BY BZ)
(shape : MatrixCoordinates NX NY NZ)
(hstage : ∀ p x y z, eligible id p x.1 y.1 z.1 →
S.value p x y z = if x.2.1 = y.2.1 ∧ x.2.1 = z.2.1 ∧
eligible id (appendCode p x.2.1) x.1 y.1 z.1
then shape.tensor x.2.2 y.2.2 z.2.2 else 0) :
(refinedExecution B S).value =
prefixValue counts t (n + 1) (B.shape.product shape).tensor := by
classical
funext x y z
let e := nextPrefixEquiv counts curveLabels n t (Position counts t)
let px := e x.2.1
let py := e y.2.1
let pz := e z.2.1
have hdecode (p : Prefix counts t (n + 1)) :
appendCode (e p).1 (e p).2 = p := e.symm_apply_apply p
change B.execution.value (x.1, (px.1, x.2.2.1))
(y.1, (py.1, y.2.2.1)) (z.1, (pz.1, z.2.2.1)) *
S.value px.1 (x.1, (px.2, x.2.2.2))
(y.1, (py.2, y.2.2.2)) (z.1, (pz.2, z.2.2.2)) = _
rw [B.normal]
simp only [prefixValue]
by_cases hold : px.1 = py.1 ∧ px.1 = pz.1 ∧ eligible id px.1 x.1 y.1 z.1
· rw [ite_eq_left hold]
have hguard :
(px.2 = py.2 ∧ px.2 = pz.2 ∧ eligible id (appendCode px.1 px.2) x.1 y.1 z.1) ↔
(x.2.1 = y.2.1 ∧ x.2.1 = z.2.1 ∧ eligible id x.2.1 x.1 y.1 z.1) := by
constructor
· rintro ⟨hxy, hxz, he⟩
refine ⟨e.injective (Prod.ext hold.1 hxy),
e.injective (Prod.ext hold.2.1 hxz), ?_⟩
simpa only [px, hdecode] using he
· rintro ⟨hxy, hxz, he⟩
refine ⟨congrArg (fun p => (e p).2) hxy,
congrArg (fun p => (e p).2) hxz, ?_⟩
simpa only [px, hdecode] using he
rw [hstage px.1 (x.1, (px.2, x.2.2.2))
(y.1, (py.2, y.2.2.2)) (z.1, (pz.2, z.2.2.2)) hold.2.2]
simp only [hguard,
MatrixCoordinates.product_tensor, Tensor.product, mul_ite, mul_zero]
· have hnext : ¬ (x.2.1 = y.2.1 ∧ x.2.1 = z.2.1 ∧
eligible id x.2.1 x.1 y.1 z.1) := by
rintro ⟨hxy, hxz, he⟩
apply hold
refine ⟨congrArg (fun p => (e p).1) hxy,
congrArg (fun p => (e p).1) hxz, ?_⟩
rw [← hdecode x.2.1] at he
obtain ⟨word, hw, _⟩ :=
(eligible_appendCode_iff px.1 px.2 x.1 y.1 z.1).mp he
exact ⟨word, hw⟩
rw [ite_eq_right hold, ite_eq_right hnext, zero_mul]
def extendBundle [Fintype NX] [Fintype NY] [Fintype NZ]
(S : Stage B.execution (Fin (stageRefinementCount counts curveLabels n t))
NX NY NZ BX BY BZ)
(shape : MatrixCoordinates NX NY NZ) (hpositive : shape.Positive)
(hvolume : shape.volume = stageRefinementCount counts curveLabels n t)
(hrank : S.rankBound = stageCost counts curveLabels n t)
(hrows : shape.rows = if readerPair n = .xz then
stageRefinementCount counts curveLabels n t else 1)
(hinner : shape.inner = if readerPair n = .xy then
stageRefinementCount counts curveLabels n t else 1)
(hcolumns : shape.columns = if readerPair n = .yz then
stageRefinementCount counts curveLabels n t else 1)
(hstage : ∀ p x y z, eligible id p x.1 y.1 z.1 →
S.value p x y z = if x.2.1 = y.2.1 ∧ x.2.1 = z.2.1 ∧
eligible id (appendCode p x.2.1) x.1 y.1 z.1
then shape.tensor x.2.2 y.2.2 z.2.2 else 0) : Bundle counts t (n + 1) where
PX := B.PX × NX
PY := B.PY × NY
PZ := B.PZ × NZ
AX := B.AX × BX
AY := B.AY × BY
AZ := B.AZ × BZ
execution := refinedExecution B S
shape := B.shape.product shape
shape_positive := B.shape.product_positive shape B.shape_positive hpositive
normal := refinedExecution_normal B S shape hstage
rank_exact := by
simp only [refinedExecution, Execution.reindexOutput_rankBound,
Execution.step_rankBound, B.rank_exact, hrank, stageAuxiliaryBudget_succ]
volume_exact := by
rw [MatrixCoordinates.product_volume, B.volume_exact, hvolume, stagePairingProduct_succ]
rows_exact := by
change B.shape.rows * shape.rows = _
rw [B.rows_exact, hrows, pairingProduct_succ]
inner_exact := by
change B.shape.inner * shape.inner = _
rw [B.inner_exact, hinner, pairingProduct_succ]
columns_exact := by
change B.shape.columns * shape.columns = _
rw [B.columns_exact, hcolumns, pairingProduct_succ]
pairing_budget := by
change (B.shape.product shape).volume ≤ B.execution.rankBound * S.rankBound
rw [MatrixCoordinates.product_volume]
apply Nat.mul_le_mul B.pairing_budget
rw [hvolume, hrank]
exact LabelHierarchySeparation.population_le_poolAuxiliaryCost _
end Successor
section ConcreteStages
variable {counts : Scalar → ℕ} {t n : ℕ}
def extendXY (B : Bundle counts t n) (hn : n < 5)
(hfirst : curveFirstSide n = .x) (hsecond : curveSecondSide n = .y) :
Bundle counts t (n + 1) := Classical.choice (by
have hpair : readerPair n = .xy := by
interval_cases n <;> simp_all [curveFirstSide, curveSecondSide, readerPair]
have hagree : ∀ (p : Prefix counts t n) (x y z : Coordinate counts t), eligible id p x y z →
firstRead id p x = secondRead id p y := by
intro p x y z he
simpa only [hfirst, hsecond, coordinateOf] using
readable_of_eligible id p x y z hn he
obtain ⟨S, _, hrank, _, _, _, _, hvalue⟩ :=
ConditionalHierarchyStage.exists_actualPoolStage counts curveLabels n t B.execution id
(firstRead id) (secondRead id) (eligible id) (previous_eligible B) hagree
refine ⟨extendBundle B S (GeometricStageCoordinates.xy _)
(GeometricStageCoordinates.xy_positive (stageRefinementCount_pos counts curveLabels n t))
(GeometricStageCoordinates.xy_volume _) hrank
(by simp [hpair, GeometricStageCoordinates.xy])
(by simp [hpair, GeometricStageCoordinates.xy])
(by simp [hpair, GeometricStageCoordinates.xy]) ?_⟩
intro p x y z he
rw [hvalue]
obtain ⟨word, hw⟩ := he
exact CW75ReorderedGeometricValues.raw_XY_normal p hn hfirst hsecond x y z word hw)
def extendXZ (B : Bundle counts t n) (hn : n < 5)
(hfirst : curveFirstSide n = .x) (hsecond : curveSecondSide n = .z) :
Bundle counts t (n + 1) := Classical.choice (by
have hpair : readerPair n = .xz := by
interval_cases n <;> simp_all [curveFirstSide, curveSecondSide, readerPair]
have hagree : ∀ (p : Prefix counts t n) (x y z : Coordinate counts t), eligible id p x y z →
firstRead id p x = secondRead id p z := by
intro p x y z he
simpa only [hfirst, hsecond, coordinateOf] using
readable_of_eligible id p x y z hn he
obtain ⟨S, _, hrank, _, _, _, _, hvalue⟩ :=
OrientedConditionalHierarchyStage.exists_actualPoolStage_XZ counts curveLabels n t B.execution id
(firstRead id) (secondRead id) (eligible id) (previous_eligible B) hagree
refine ⟨extendBundle B S (GeometricStageCoordinates.xz _)
(GeometricStageCoordinates.xz_positive (stageRefinementCount_pos counts curveLabels n t))
(GeometricStageCoordinates.xz_volume _) hrank
(by simp [hpair, GeometricStageCoordinates.xz])
(by simp [hpair, GeometricStageCoordinates.xz])
(by simp [hpair, GeometricStageCoordinates.xz]) ?_⟩
intro p x y z he
rw [hvalue]
obtain ⟨word, hw⟩ := he
exact CW75ReorderedGeometricValues.raw_XZ_normal p hn hfirst hsecond x y z word hw)
def extendYZ (B : Bundle counts t n) (hn : n < 5)
(hfirst : curveFirstSide n = .y) (hsecond : curveSecondSide n = .z) :
Bundle counts t (n + 1) := Classical.choice (by
have hpair : readerPair n = .yz := by
interval_cases n <;> simp_all [curveFirstSide, curveSecondSide, readerPair]
have hagree : ∀ (p : Prefix counts t n) (x y z : Coordinate counts t), eligible id p x y z →
firstRead id p y = secondRead id p z := by
intro p x y z he
simpa only [hfirst, hsecond, coordinateOf] using
readable_of_eligible id p x y z hn he
obtain ⟨S, _, hrank, _, _, _, _, hvalue⟩ :=
OrientedConditionalHierarchyStage.exists_actualPoolStage_YZ counts curveLabels n t B.execution id
(firstRead id) (secondRead id) (eligible id) (previous_eligible B) hagree
refine ⟨extendBundle B S (GeometricStageCoordinates.yz _)
(GeometricStageCoordinates.yz_positive (stageRefinementCount_pos counts curveLabels n t))
(GeometricStageCoordinates.yz_volume _) hrank
(by simp [hpair, GeometricStageCoordinates.yz])
(by simp [hpair, GeometricStageCoordinates.yz])
(by simp [hpair, GeometricStageCoordinates.yz]) ?_⟩
intro p x y z he
rw [hvalue]
obtain ⟨word, hw⟩ := he
exact CW75ReorderedGeometricValues.raw_YZ_normal p hn hfirst hsecond x y z word hw)
end ConcreteStages
def realize (counts : Scalar → ℕ) (t : ℕ) : Bundle counts t 5 :=
let B0 := initial counts t
let B1 : Bundle counts t 1 := extendXY B0 (by decide) rfl rfl
let B2 : Bundle counts t 2 := extendXZ B1 (by decide) rfl rfl
let B3 : Bundle counts t 3 := extendXY B2 (by decide) rfl rfl
let B4 : Bundle counts t 4 := extendYZ B3 (by decide) rfl rfl
extendYZ B4 (by decide) rfl rfl
theorem realize_dimensions (counts : Scalar → ℕ) (t : ℕ) :
(realize counts t).shape.rows =
ConditionalLabels.stagePairingSize counts curveLabels 5 curveReaderPair .xz t ∧
(realize counts t).shape.inner =
ConditionalLabels.stagePairingSize counts curveLabels 5 curveReaderPair .xy t ∧
(realize counts t).shape.columns =
ConditionalLabels.stagePairingSize counts curveLabels 5 curveReaderPair .yz t := by
have h (pair : ReaderPair) : pairingProduct counts t pair 5 =
ConditionalLabels.stagePairingSize counts curveLabels 5 curveReaderPair pair t := by
change (∏ i ∈ Finset.range 5,
if readerPair i = pair then stageRefinementCount counts curveLabels i t else 1) =
∏ i : Fin 5,
if readerPair i.val = pair then stageRefinementCount counts curveLabels i.val t else 1
exact (Fin.prod_univ_eq_prod_range
(fun i => if readerPair i = pair then
stageRefinementCount counts curveLabels i t else 1) 5).symm
exact ⟨(realize counts t).rows_exact.trans (h .xz),
(realize counts t).inner_exact.trans (h .xy),
(realize counts t).columns_exact.trans (h .yz)⟩
theorem realize_rankBound (counts : Scalar → ℕ) (t : ℕ) :
(realize counts t).execution.rankBound = stageAuxiliaryBudget counts curveLabels 5 t :=
(realize counts t).rank_exact
theorem realize_volume (counts : Scalar → ℕ) (t : ℕ) :
(realize counts t).shape.volume = Fintype.card (ExactWords (fun a => t * counts a)) := by
rw [(realize counts t).volume_exact]
simpa only [exactWords_card] using
(stagePairingProduct_eq_exactWords_card counts curveLabels 5 curve_completeRecord_injective t)
theorem realize_pairing_budget (counts : Scalar → ℕ) (t : ℕ) :
(realize counts t).shape.volume ≤ (realize counts t).execution.rankBound :=
(realize counts t).pairing_budget
theorem realize_value (counts : Scalar → ℕ) (t : ℕ)
(x : Coordinate counts t × (Prefix counts t 5 × (realize counts t).PX))
(y : Coordinate counts t × (Prefix counts t 5 × (realize counts t).PY))
(z : Coordinate counts t × (Prefix counts t 5 × (realize counts t).PZ)) :
(realize counts t).execution.value x y z =
if x.2.1 = y.2.1 ∧ x.2.1 = z.2.1 ∧
x.1 = longX (terminalWord x.2.1).val ∧
y.1 = longY (terminalWord x.2.1).val ∧
z.1 = longZ (terminalWord x.2.1).val
then (realize counts t).shape.tensor x.2.2 y.2.2 z.2.2 else 0 := by
rw [(realize counts t).normal]
simp only [prefixValue, terminal_eligible_iff]
theorem realize_label_card (counts : Scalar → ℕ) (t : ℕ) :
Fintype.card (Prefix counts t 5) = Fintype.card (ExactWords (fun a => t * counts a)) := by
rw [exactWords_card]
let : DecidableEq Scalar := Classical.decEq Scalar
calc
Fintype.card (Prefix counts t 5) =
Fintype.card (PopulationWords (Position counts t) (fun a => t * counts a)) :=
Fintype.card_congr
(sourcePrefixEquiv counts curveLabels 5 t (Position counts t) curve_completeRecord_injective)
_ = Nat.multinomial Finset.univ (fun a => t * counts a) :=
populationWords_card (I := Position counts t)
(fun a => t * counts a) (position_card counts t)
end MatrixMultiplication.CW75ReorderedExecution
end
end OAI
|