Schoolbook multiplication of integer items in quadratic time
ProvedNLogN.smul_runsLet be seven pairwise distinct item stacks (in an arbitrary item-language program with stacks). Assume has and then on top (over ). Then the schoolbook procedure smul A X Y W Q R T runs from to
with cost at most
where is the bit length of . The loop repeatedly splits off the lowest bit of , adds to the accumulator when it is nonzero, and shifts left by one bit.
This is the base case of FM: for with bit length below the threshold , the product is computed by smul and reduced with fred; its cost is then bounded by a constant.
Formalization Note. Item states IState S have item stacks G (head = top), input pointer ip and output out; s.upd X L replaces stack X. IRuns asserts the exact final state and an upper bound on the cost. Unlike the other FM lemmas this one is stated for any number of stacks .
-- 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
variable {S P : ℕ} {I : List Sym} {iprog : Fin P → IStmt S P}
theorem NLogN.smul_runs {A X Y W Q R T : Fin S} (hd : [A, X, Y, W, Q, R, T].Nodup)
(s : IState S) (x y : ℤ) (L : List Item) (hA : s.G A = .int x :: .int y :: L) :
IRuns I iprog (smul A X Y W Q R T) s (s.upd A (.int (x * y) :: L))
(smulCost (zsz x + zsz y)) := by sorry