These are some notes on how to efficiently multiply a Toeplitz matrix by a vector.
I was writing these for myself while implementing the new amortized KZG proofs by Feist and Khovratovich, but I thought they might be useful for you too.
Preliminaries
We use column vector notation for all vectors.
If [a,b,c] is a row vector, then [a,b,c]T denotes its transpose: i.e., the column vector abc.
What’s a Toeplitz (and a circulant) matrix?
A Toeplitz matrix (e.g. of size $4\times 4$) looks like this:
Note the odd use of negative indices here, since typically we usually use positive numbers to index.
It’s just convenient for notation to use negative indices.
In other words, it’s a square matrix where the entries “repeat diagonally.”
A concrete example would be:
7381117385117365117
A circulant matrixC is a special form of Toeplitz matrix:
What we’re saying is that a circulant matrix Cn of size n×n can be written as:
Cn=(Fn)−1diag(Fnan)Fn
Here, an=[a0,…,an−1] is the vector representation of Cn as discussed before (see above).
Also, diag(Fna) is the n×n diagonal matrix whose diagonal entries are the entries from Fnan (i.e., the entry at position (i,i) is the ith entry in Fnan) and all other entries are 0.
Multiplying a circulant matrix by a vector
Let y=DFT(x)=Fnx denote the DFT of a vector x and let x=DFT−1(y)=Fn−1y denote the inverse DFT.
If Cn is circulant with vector representation an, then multiplying it by a size-n vector x can be written as:
Compute v by doing a DFT on an (in Θ(nlogn) time)
Compute the Hadamard product u=v∘y,
(Since that’s what happens when you multiply a diagonal matrix by a vector.)
Do an inverse DFT on u (in Θ(nlogn) time).
Thus, we can compute Cnx in Θ(nlogn) time.
Multiplying a Toeplitz matrix by a vector
To multiply a Toeplitz matrix Tn by a vector x, we’ll embed the matrix in a circulant matrix C2n in such a manner that the first n entries of C2nx will equal exactly Tnx.
We want to build a circulant matrix C8 from T4 such that:
C8x0=T4x?
Note that we don’t care what we get in the last n entries of the result, which we denote with a question mark.
Also, 0 denotes the vector of n=4 zeros.
If we had such a C8, then we could multiply it with x0 using the Θ(nlogn) multiplication algorithm from the previous section and efficiently compute T4x.
We’ll build C8 from T4 and some other, to be determined matrix which we denote using B4.
C8=T4B4B4T4
Note that this gives us what we want:
(C_8 \begin{bmatrix}\vec{x}\\\ \vec{0}\end{bmatrix} =
\begin{bmatrix}
T_4 & B_4 \\\
B_4 & T_4
\end{bmatrix}
\begin{bmatrix}\vec{x}\\\ \vec{0}\end{bmatrix}=
\begin{bmatrix}T_4\vec{x}\\\ B_4\vec{x}\end{bmatrix})
In other words, the first n entries of the product are indeed equal to T4x, independent of what we pick for B4.
But for us to efficiently compute the product, we’ll need to pick a B4 that makes C8 circulant.
So let’s look at what C8 looks like with just the two T4’s in it:
The question that remains to be answered is what is the vector representationa8 of C8, since that’s what we’ll need to efficiently evaluate C8x and thus T4x.
The answer is, as before, the elements in the first columns of C8, which are:
a8=[a0,a1,a2,a3,a0,a−3,a−2,a−1]T
Thus, applying the algorithm for circulant matrices from before, what we must do is:
Build a2n from the entries {an−1,an−2,…,a1,a0,a−1,…,a−(n−1)} of the Toeplitz matrix Tn
Compute y by doing a DFT on [x,0]T
Compute v by doing a DFT on a2n (e.g., on a8 from above)
Compute the Hadamard product u=v∘y,
Do an inverse DFT on u
The product Tnx consists of the first n entries of the resulting vector