Schönhage–Strassen FM procedure: one recursion level is correct within its cost
ProvedNLogN.fmMain_runsLet pF, pD, pT, pP be procedure indices, where pD, pT, pP have bodies difBody pD, ditBody pT, pow2Body pP (forward FFT, inverse FFT, powers of two). Let and write = fmL N (bit length of ), = fmB N (bit length of ), , , , and . Assume
- (recursion hypothesis)
FMSpec pF iprog I N' C: callingpFmultiplies modulo any two inputs in within cost ; - the parameter conditions , , , and ;
ARGhas then on top (over ) with ;PRMhas ,RNhas ,RFhas on top.
Then
All other stacks are restored exactly.
fmMain folds the inputs, computes the parameters, splits each input into pieces of bits, twists them by powers of , applies the forward FFT over , multiplies pointwise by recursive calls, applies the inverse FFT, untwists, lifts to signed coefficients, propagates carries and recombines. The bound is ; solving the resulting recurrence gives the potential bound .
Formalization Note. States are IState NS records with item stacks G : Fin NS → List Item (head = top), input pointer ip and output out; s.upd X L replaces stack X by L; ints A is the list of integer items of A. The named stacks (ARG, PRM, RN, RF, DX, DL, …) are fixed indices in Fin 32. IRuns I iprog p s s' c means that p executes from s to exactly s' with some cost , so costs are upper bounds; the program text iprog and input I are arbitrary unless constrained.
-- Schönhage–Strassen multitape-TM development (NLogN), generated by skeleton subtraction.
import Definitions.Def_IntMul_SS_Defs2
set_option autoImplicit false
set_option relaxedAutoImplicit false
set_option maxHeartbeats 1000000
open NLogN
open IntMul
variable {P : ℕ} {I : List Sym} {iprog : Fin P → IStmt NS P}
set_option maxHeartbeats 4000000
theorem NLogN.fmMain_runs (pF pD pT pP : Fin P) (hPD : iprog pD = difBody pD)
(hPT : iprog pT = ditBody pT) (hPP : iprog pP = pow2Body pP) (N C : ℕ)
(hFM : FMSpec pF iprog I (fmN' N) C)
(hN1 : 1 ≤ N) (hB : fmB N ≤ fmL N / 2) (hKM : 2 ^ fmK N * fmM N = N) (hM1 : 1 ≤ fmM N)
(hnt : 2 * fmM N + 2 * fmK N + 4 ≤ fmN' N) (hnN : fmN' N ≤ N) (hℓ : fmL N ≤ N)
(s : IState NS) (a b : ℤ) (LA LP LN LF : List Item) (ha : 0 ≤ a ∧ a ≤ 2 ^ N)
(hb : 0 ≤ b ∧ b ≤ 2 ^ N) (hA : s.G ARG = .int a :: .int b :: LA)
(hP : s.G PRM = .int N :: LP) (hN : s.G RN = .int (2 ^ N) :: LN)
(hF : s.G RF = .int (2 ^ N + 1) :: LF) :
IRuns I iprog (fmMain pF pD pT pP) s (s.upd ARG (.int ((a * b) % (2 ^ N + 1)) :: LA))
(2 ^ fmK N * C + fmLevelCost N) := by sorry