File size: 6,267 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
import OAI.LinearAlgebra.MatrixMultiplication.Tensor.ComplexDotPairing
import OAI.LinearAlgebra.MatrixMultiplication.Tensor.ComplexTensorSymmetrization
import Mathlib.Tactic

namespace OAI

/-!
# The polynomial multiplication tensor

The coefficient tensor `convolution a b` represents multiplication of binary forms
of degrees `a - 1` and `b - 1`, or equivalently ordinary coefficient convolution.
The output leg has `a + b - 1` coordinates.  The definitions also make sense when
an input dimension is zero, while the nonzero and full-output-support statements
use the positive dimensions assumed in Section 5 of the paper.
-/

open scoped BigOperators

namespace MatrixMultiplication.AuxiliarySeparation

open MatrixMultiplication.Foundation

/-- The tensor `C(a,b)` of Section 5, in monomial coefficient coordinates. -/
def convolution (a b : ℕ) : Tensor ℂ (Fin a) (Fin b) (Fin (a + b - 1)) :=
  fun i j k => if i.val + j.val = k.val then 1 else 0

@[simp] theorem convolution_apply (a b : ℕ)
    (i : Fin a) (j : Fin b) (k : Fin (a + b - 1)) :
    convolution a b i j k = if i.val + j.val = k.val then 1 else 0 := rfl

@[simp] theorem convolution_ne_zero_iff {a b : ℕ}
    (i : Fin a) (j : Fin b) (k : Fin (a + b - 1)) :
    convolution a b i j k ≠ 0 ↔ i.val + j.val = k.val := by
  simp only [convolution]
  split_ifs <;> simp_all

@[simp] theorem convolution_eq_one_iff {a b : ℕ}
    (i : Fin a) (j : Fin b) (k : Fin (a + b - 1)) :
    convolution a b i j k = 1 ↔ i.val + j.val = k.val := by
  simp only [convolution]
  split_ifs <;> simp_all

@[simp] theorem convolution_eq_zero_iff {a b : ℕ}
    (i : Fin a) (j : Fin b) (k : Fin (a + b - 1)) :
    convolution a b i j k = 0 ↔ i.val + j.val ≠ k.val := by
  simp only [convolution]
  split_ifs <;> simp_all

/-- Every pair of input monomials has a valid output coordinate. -/
def convolutionOutput {a b : ℕ} (i : Fin a) (j : Fin b) : Fin (a + b - 1) :=
  ⟨i.val + j.val, by have hi := i.isLt; have hj := j.isLt; omega⟩

@[simp] theorem convolution_at_output {a b : ℕ} (i : Fin a) (j : Fin b) :
    convolution a b i j (convolutionOutput i j) = 1 := by
  simp [convolutionOutput]

/-- Every output monomial of the expected degree occurs in the product. -/
theorem convolution_output_supported {a b : ℕ} (ha : 0 < a) (hb : 0 < b)
    (k : Fin (a + b - 1)) :
    ∃ (i : Fin a) (j : Fin b), convolution a b i j k = 1 := by
  by_cases hk : k.val < a
  · exact ⟨⟨k.val, hk⟩, ⟨0, hb⟩, by simp⟩
  · have hk' := k.isLt
    refine ⟨⟨a - 1, by omega⟩, ⟨k.val - (a - 1), by omega⟩, ?_⟩
    apply (convolution_eq_one_iff _ _ _).mpr
    dsimp
    omega

theorem convolution_nonzero {a b : ℕ} (ha : 0 < a) (hb : 0 < b) :
    convolution a b ≠ 0 := by
  intro hz
  have hc := congrFun (congrFun (congrFun hz ⟨0, ha⟩) ⟨0, hb⟩)
    (convolutionOutput ⟨0, ha⟩ ⟨0, hb⟩)
  change convolution a b ⟨0, ha⟩ ⟨0, hb⟩
    (convolutionOutput ⟨0, ha⟩ ⟨0, hb⟩) = 0 at hc
  rw [convolution_at_output] at hc
  exact one_ne_zero hc

theorem convolution_nonzero_iff (a b : ℕ) :
    convolution a b ≠ 0 ↔ 0 < a ∧ 0 < b := by
  constructor
  · intro h
    constructor
    · by_contra ha
      have ha' : a = 0 := by omega
      subst a
      apply h
      funext i
      exact Fin.elim0 i
    · by_contra hb
      have hb' : b = 0 := by omega
      subst b
      apply h
      funext i j
      exact Fin.elim0 j
  · rintro ⟨ha, hb⟩
    exact convolution_nonzero ha hb

/-- Commuting the two inputs only casts the equal output dimensions. -/
theorem convolution_comm (a b : ℕ) (i : Fin a) (j : Fin b)
    (k : Fin (a + b - 1)) :
    convolution a b i j k =
      convolution b a j i (Fin.cast (by omega) k) := by
  simp only [convolution, Fin.val_cast, Nat.add_comm]

/-- The boundary tensor `C(1,b)` has the coefficient matrix of a dot product. -/
theorem convolution_one_left (b : ℕ) (i : Fin 1) (j : Fin b)
    (k : Fin (1 + b - 1)) :
    convolution 1 b i j k = if j.val = k.val then 1 else 0 := by
  simp [convolution]

/-- The other boundary tensor has the same coordinate identity. -/
theorem convolution_one_right (a : ℕ) (i : Fin a) (j : Fin 1)
    (k : Fin (a + 1 - 1)) :
    convolution a 1 i j k = if i.val = k.val then 1 else 0 := by
  simp [convolution]

/-- Relabel the output of `C(1,b)` by its actual dimension `b`. -/
def convolutionOneOutputEquiv (b : ℕ) : Fin b ≃ Fin (1 + b - 1) :=
  finCongr (by omega)

/-- Relabel the single input coordinate of `C(1,b)` by `Unit`. -/
def convolutionOneInputEquiv : Unit ≃ Fin 1 where
  toFun _ := 0
  invFun _ := ()
  left_inv _ := rfl
  right_inv _i := Subsingleton.elim _ _

/-- `C(1,b)` is the dot-product tensor with the singleton on the first leg. -/
theorem convolution_one_left_dotPairing (b : ℕ) :
    Tensor.pullback convolutionOneInputEquiv (Equiv.refl (Fin b))
      (convolutionOneOutputEquiv b) (convolution 1 b) =
      Tensor.cyclic (Tensor.cyclic (Tensor.dotPairing (K := ℂ) (Fin b))) := by
  funext i j k
  simp [Tensor.pullback, convolutionOneInputEquiv, convolutionOneOutputEquiv,
    Tensor.cyclic, Tensor.dotPairing, convolution, Fin.ext_iff]

/-- Relabel the output of `C(a,1)` by its actual dimension `a`. -/
def convolutionRightOneOutputEquiv (a : ℕ) : Fin a ≃ Fin (a + 1 - 1) :=
  finCongr (by omega)

/-- `C(a,1)` is the dot-product tensor with the singleton on the second leg. -/
theorem convolution_one_right_dotPairing (a : ℕ) :
    Tensor.pullback (Equiv.refl (Fin a)) convolutionOneInputEquiv
      (convolutionRightOneOutputEquiv a) (convolution a 1) =
      Tensor.cyclic (Tensor.dotPairing (K := ℂ) (Fin a)) := by
  funext i j k
  simp [Tensor.pullback, convolutionOneInputEquiv, convolutionRightOneOutputEquiv,
    Tensor.cyclic, Tensor.dotPairing, convolution, Fin.ext_iff, eq_comm]

/-- Contracting the coefficient tensor computes ordinary finite convolution. -/
theorem contract_convolution {a b : ℕ} (x : Fin a → ℂ) (y : Fin b → ℂ)
    (k : Fin (a + b - 1)) :
    Tensor.contract (convolution a b) x y k =
      ∑ i : Fin a, ∑ j : Fin b,
        if i.val + j.val = k.val then x i * y j else 0 := by
  simp [Tensor.contract, convolution, ite_mul]

end MatrixMultiplication.AuxiliarySeparation

end OAI