D-2.10 Application: Matrix Multiplication

BFV has no clean way to do a homomorphic dot product between two vectors (i.e., v1 v2), because the last step of a vector dot product requires summation of all slot-wise intermediate values (i.e., v1,1v2,1 + v1,2v2,2 + + v1,nv2,n). However, each slot in BFV’s batch encoding is independent from each other, which cannot be simply added up across slots (i.e., input vector elements). Instead, we need n copies of the multiplied ciphertexts and properly align their slots by many rotation operations before adding them up. Meanwhile, the homomorphic input vector slot rotation scheme can be effectively used when we homomorphically multiply a plaintext matrix with an encrypted vector. Remember that given a matrix A and vector x (Definition A-10.3 in §A-10.3):

A = [ a0,0 a0,1 a0,2 a0,n1 a1,0 a1,1 a1,2 a1,n1 a2,0 a2,1 a2,2 a2,n1 a m1,0 am1,1 am1,2 am1,n1 ] = [ a0, a1, a2, a m1, ], x = (x0,x1,,xn1)

The result of A x is an m-dimensional vector computed as:

Ax = (a0,x, a1,x, , am1,x) = ( i=0n1a0,i xi,  i=0n1a1,i xi,  ,  i=0n1am1,i xi)

Let’s define ρ(v,h) as the rotation of v by h positions to the left. And remember that the Hadamard dot product (Definition A-10.1 in §A-10.1) is defined as slot-wise multiplication of two vectors:

a b = (a0b0, a1b1,   , an1bn1)

Let’s define n distinct diagonal vector ui extracted from matrix A as follows:

ui = {ajmodm, i+jmodn}j=0n1

Then, the original matrix-to-vector multiplication formula can be equivalently constructed as follows:

A x = u0 ρ(x,0)  +  u1 ρ(x,1)  +    +  un1 ρ(x,n 1)

, whose computation result is equivalent to A x. The above formula is compatible with homomorphic computation, because BFV supports Hadamard dot product between input vectors as a ciphertext-to-plaintext multiplication between their polynomial-encoded forms (§D-3.6), and BFV also supports ρ(v,h) as homomorphic input vector slot rotation (§D-3.9). After homomorphically computing the above formula, we can consider only the first m (out of n) resulting input vector slots to store the result of A x.