Dot products, matrices, and many equations at once
Dot products
Start with two vectors of the same length:
The dot product multiplies matching entries and adds the results:
The notation is:
A dot product only makes sense when the two vectors have the same length. You can take the dot product of two length-2 vectors, or two length-256 vectors, but not a length-2 vector with a length-3 vector.
The general rule
For two vectors:
their dot product is:
i.e we multiply each matching entry, then add all the products.
Dot products as linear equations
A dot product can be read as one linear equation.
Suppose:
Then:
So here we can see that the vector gives the coefficients, and the vector gives the unknown/secret values. Let's say we are told that , well now only someone who knows can solve the equation. In lattice cryptography, this pattern appears constantly. A public vector or matrix is multiplied by a secret vector. The result gives equations involving the secret.
A matrix is a stack of row vectors
A matrix is a rectangular array of numbers. For example:
This matrix has 3 rows and 2 columns. Each row is a vector; . So the matrix is a stack of three length-2 row vectors.
Matrix-vector multiplication
Let:
and:
The product is:
Each row of takes a dot product with
First row:
Second row:
Third row:
So:
The output is a vector with one entry per row of .
This is the main idea: matrix-vector multiplication is a batch of dot products.
The dimensions much match
The number of columns in the matrix must match the number of entries in the vector.
For example:
has 2 columns. So it cab be multiplied by a vector of length 2:
The result has 3 entries because A has 3 rows. So a 3 x 2 matrix times a length-2 vector gives a length-3 vector. As a general guide, the inner dimensions must match, and the outer dimensions give the output shape.
Generalising
Let be a matrix with rows and columns. Let be a vector with entries. Then is a vector with entries:
Read this as "the first output entry is row 1 of A dotted with s, the second output entry is row 2 of A dotted with s, and so on". Where means the i-th row of , if:
then:
Which is read as "entry of the matrix multiplies entry of the vector, then all those products are added". Again, for completeness, the notation means "the entry of A in row i, column j".
Why this appears in lattice cryptography
Lattice cryptography uses many linear equations at once. A common notation we will see is:
Which is "matrix time secret vector equals vector ".
This means:
So is compact notation for many dot product equations.
In real lattice schemes, the entries are usually reduced modulo some number q, and there is often noise added. That gives expressions like:
Both noise and modulo are coming up so don't worry. For now, the important part is that means many dot products between rows of and the vector .
Row vectors and column vectors
In many texts, vectors are written horizontally:
But in matrix multiplication, the vector is often written vertically:
These are not identical written objects. One is a row vector and one is a column vector.
For this chapter, when we write , treat as a column vector. That is the shape needed for a matrix to multiply it on the left.
The horizontal notation is often used because it is easier to read inline. When the shape matters, we will write the vector vertically.
What to remember
- A dot product multiplies matching entries of two vectors and adds the results.
- A dot product produces one number.
- A matrix is a stack of row vectors.
- Matrix-vector multiplication is a batch of dot products.
- If has rows, then has entries.
- The expression means operating on many linear equations at once.
- Lattice cryptography uses this idea constantly, usually with modular arithmetic and noise.