FM recombination: Horner evaluation of M-bit digits by concatenation
ProvedNLogN.fmHorner_runsLet with and , and let be a list of integers with . Assume stack DG holds the items of in reverse order (last digit on top) followed by , DL has on top and RM has on top. Then fmHorner runs from to the state where DG is and
(i.e. ) is pushed on ZZ, with cost at most .
The loop starts from the sentinel and concatenates one -bit digit per iteration (cat), so each step costs regardless of the size of the accumulated number; this keeps recombination linear in .
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}
theorem NLogN.fmHorner_runs (s : IState NS) (n M k : ℕ) (Dg : List ℤ) (LG LL LM : List Item)
(hM : M ≤ n) (hk : k + 1 ≤ n) (hDl : Dg.length = 2 ^ k)
(hDg : ∀ b ∈ Dg, 0 ≤ b ∧ b < 2 ^ M)
(hG : s.G DG = (ints Dg).reverse ++ LG) (hDL : s.G DL = .int (2 ^ k) :: LL)
(hRM : s.G RM = .int (2 ^ M) :: LM) :
IRuns I iprog fmHorner s
((s.upd DG LG).upd ZZ (.int (2 ^ (2 ^ k * M) + zev (2 ^ M) Dg) :: s.G ZZ))
(2 ^ k * (2000 * (n + 3) + 30) + 1000 * (n + 3)) := by sorry