Writing and comparing coefficient arrays on the word RAM #
Two linear-time array routines for polynomials modulo X^r - 1 and n, stored as r words:
Fill writes the coefficients Cslib.AKS.powAddCoeff n r e a of X^e + a (it clears the block
and then adds a at index 0 and 1 at index e mod r), and Compare tests two blocks for
equality.
Main definitions #
Cslib.Algorithms.WordRAM.AKS.Fill.program: write the coefficients ofX^e + a.Cslib.Algorithms.WordRAM.AKS.Compare.program: compare two blocks.
Main results #
Cslib.Algorithms.WordRAM.AKS.Fill.exec: the block receivesCslib.AKS.powAddCoeffwithin5 r + 13instructions, and no other cell changes.Cslib.Algorithms.WordRAM.AKS.Compare.exec: the flag is1exactly when the blocks agree, within11 r + 5instructions, and memory is unchanged.
Base address of the block.
The number r of coefficients.
The index e mod r of the monomial.
Clear one cell.
Store a mod n at index 0.
Add 1 at index e mod r, modulo n.
Store a mod n at index 0, then add 1 at index e mod r.
Clear the block, then write the two nonzero coefficients.
Writing X^e + a. For r ≥ 1 and n ≥ 1, with e mod r in er and the block end,
a, n and n + 1 fitting a word, the block [b, b + r) receives the coefficients
Cslib.AKS.powAddCoeff n r e a within 5 r + 13 instructions, and no other cell changes.
Base address of the first block.
Base address of the second block.
The number r of coefficients.
Coefficient of the first block.
Coefficient of the second block.
The answer: 1 when the blocks agree.
Compare one pair of coefficients.
Compare two blocks of r words.
Comparing blocks. With both block ends fitting a word, the program leaves 1 in flag
exactly when the blocks [a, a + r) and [b, b + r) agree, and 0 otherwise, within
11 r + 5 instructions, without changing memory.