Multiplication modulo X^r - 1 and n on the word RAM #
Polynomials modulo X^r - 1 with coefficients modulo n are stored as arrays of r words. The
program clears the destination array and then, for every pair i, j < r, adds p i * q j into
cell (i + j) mod r, reducing modulo n after each addition: schoolbook multiplication, with
O(r²) instructions. Every product and sum stays below n² + n. The result has the coefficients
Cslib.AKS.mulCoeff n r p q, so its class is the product of the classes of the factors
(Cslib.AKS.toQuot_mulCoeff). The factors may coincide, which is how a polynomial is squared; the
destination must be disjoint from both.
Main definitions #
Cslib.Algorithms.WordRAM.AKS.PolyMul.program: the multiplication program.
Main results #
Cslib.Algorithms.WordRAM.AKS.PolyMul.exec: the destination receivesCslib.AKS.mulCoeffwithin14 (r + 1)²instructions, and no other memory cell changes.
References #
Base address of the first factor.
Base address of the second factor.
Base address of the product.
The number r of coefficients.
The modulus n of the coefficients.
Index into the first factor.
Index into the second factor.
Index (i + j) mod r into the product.
The updated product coefficient.
Clear one cell of the product.
Add the product into its cell, reducing modulo n, and advance j.
Add the products of p i with every coefficient of q.
Clear the product, then accumulate every pair of coefficients.
Multiplication modulo X^r - 1 and n. If the product block [t, t + r) is disjoint
from both factor blocks, the factors' coefficients are below n ≥ 1, and the word size holds the
block ends, 2 r and n² + n, then the product block receives the coefficients
Cslib.AKS.mulCoeff n r p q within 14 (r + 1)² instructions, and no other cell changes.