Top-level program tail: call FM and write the 2n-bit product
ProvedNLogN.main_tailLet , a state, and . Let (mainN0 n, where is the bit length). Assume ARG is exactly , T1 and T2 are both exactly , PRM has , RN has and RF has on top. Run, in the Schönhage–Strassen program ssProg, the statement: call procedure (the FM procedure); shift T1 left by the ruler T2; write ARG with ruler T1. Then there is a final state with
where = fmPhi is the potential ( = bit length of , = bit length of ).
Since , the residue equals , so the output is the -bit product. The cost bound for the FM call is the potential-function bound proved by induction on the recursion; this lemma combines it with output to finish the top-level analysis.
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. The input word is arbitrary here because the tail performs no reads.
-- 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 set_option maxHeartbeats 2000000
theorem NLogN.main_tail {I : List Sym} (n : ℕ) (s : IState NS) (a b : ℕ) (ha : a < 2 ^ n)
(hb : b < 2 ^ n) (LP LN LF : List Item) (hA : s.G ARG = [.int (b : ℤ), .int (a : ℤ)])
(hT1 : s.G T1 = [.int (2 ^ n)]) (hT2 : s.G T2 = [.int (2 ^ n)])
(hP : s.G PRM = .int (mainN0 n) :: LP) (hN : s.G RN = .int (2 ^ mainN0 n) :: LN)
(hF : s.G RF = .int (2 ^ mainN0 n + 1) :: LF) :
∃ t, IRuns I ssProg (.seq (.call 1) (.seq (.op (.shl T1 T2)) (.op (.write ARG T1)))) s t
(fmPhi (mainN0 n) + shlCost n + outRCost (2 * n)) ∧ t.out = s.out ++ bin (2 * n) (a * b) := by sorry