Documentation

CslibFrontier.Algorithms.WordRAM.AKS.PolyArray

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 #

Main results #

@[reducible, inline]

Base address of the block.

@[reducible, inline]

The number r of coefficients.

@[reducible, inline]

The modulus n.

@[reducible, inline]

The index e mod r of the monomial.

@[reducible, inline]

The constant term a.

@[reducible, inline]

Loop index.

@[reducible, inline]

Address scratch.

@[reducible, inline]

Value scratch.

@[reducible, inline]

Constant one.

@[reducible, inline]

Constant zero.

Store a mod n at index 0, then add 1 at index e mod r.

Clear the block, then write the two nonzero coefficients.

theorem Cslib.Algorithms.WordRAM.AKS.Fill.exec {w : ℕ} (x : WordRAM.Data 10) {b r n e a : ℕ} (hb : x.regs base = b) (hr : x.regs rr = r) (hn : x.regs nn = n) (her : x.regs er = e % r) (ha : x.regs aa = a) (hr0 : 0 < r) (hn0 : 0 < n) (hfb : WordRAM.Fits w (b + r)) (hfa : WordRAM.Fits w a) (hfn : WordRAM.Fits w (n + 1)) :
∃ (y : WordRAM.Data 10), WordRAM.ExecWithin w program x y (5 * r + 13) ∧ (∀ k < r, y.mem (b + k) = AKS.powAddCoeff n r e a k) ∧ (∀ (a' : ℕ), ¬(b ≤ a' ∧ a' < b + r) → y.mem a' = x.mem a') ∧ y.regs base = b ∧ y.regs rr = r ∧ y.regs nn = n

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.

@[reducible, inline]

Base address of the first block.

@[reducible, inline]

Base address of the second block.

@[reducible, inline]

The number r of coefficients.

@[reducible, inline]

Loop index.

@[reducible, inline]

Address scratch.

@[reducible, inline]

Coefficient of the first block.

@[reducible, inline]

Coefficient of the second block.

@[reducible, inline]

The answer: 1 when the blocks agree.

@[reducible, inline]

Constant one.

theorem Cslib.Algorithms.WordRAM.AKS.Compare.exec {w : ℕ} (x : WordRAM.Data 9) {a b r : ℕ} (ha : x.regs p = a) (hb : x.regs q = b) (hr : x.regs rr = r) (hfa : WordRAM.Fits w (a + r)) (hfb : WordRAM.Fits w (b + r)) (h1 : WordRAM.Fits w 1) :
∃ (y : WordRAM.Data 9), WordRAM.ExecWithin w program x y (11 * r + 5) ∧ y.regs flag ≤ 1 ∧ (y.regs flag = 1 ↔ ∀ k' < r, x.mem (a + k') = x.mem (b + k')) ∧ y.mem = x.mem

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.