These are the human proofs of Schönhage-Strassen multiplication, at full length.
SSA-MULMOD returns the product modulo 2^n + 1 full
This proof shows: correctness, termination.
Fix n and residues 0≤A,B≤2n. Write Rm=Z/(2m+1). In Rm, 2m=−1 and 22m=1, and since 2m+1 is odd, 2 is a unit.
Base cases. If A=2n then A≡−1 and AB≡−B, and symmetrically for B; line L1 returns these. If n is small, the product is computed directly and reduced, which is correct. From now on 0≤A,B<2n.
Lemma 1 (negacyclic convolution). Let K=2k divide n, M=n/K, and A=∑j<Kaj2jM, B=∑j<Kbj2jM with 0≤aj,bj<2M. Define
cj=i+l=j∑aibl−i+l=j+K∑aibl(0≤j<K).
Then AB≡∑j<Kcj2jM(mod2n+1), and −(K−1−j)22M<cj<(j+1)22M when cj has a nonzero term, and cj=0 otherwise.
Proof.AB=∑i,l<Kaibl2(i+l)M. A term with i+l=j+K has 2(j+K)M=2jM2n≡−2jM. The first sum has j+1 terms, each less than 22M, and the second has K−1−j terms. □
Lemma 2 (roots of unity). Let K∣n′, θ=2n′/K and ω=θ2 in Rn′. Then θK=−1, ωK/2=−1, and for 0<s<K, ∑j<Kωsj=0.
Proof.θK=2n′=−1, and ωK/2=θK. For 0<s<K write s=2eu with u odd and e<k. Then ωsK/2e+1=(ωK/2)u=(−1)u=−1. Split the indices j<K into pairs j and j+K/2e+1 within each block of length K/2e; the two terms of a pair are ωsj and ωsj⋅(−1), so each pair sums to 0. □
Lemma 2 is all the convolution theorem needs: for sequences x,y of length K over Rn′ and DFTω(x)s=∑jxjωsj,
because expanding the left side gives ∑i,lxiyl∑sωs(i+l−j), and the inner sum is K if i+l≡j and 0 otherwise by Lemma 2. The radix-2 recursion of _fft computes DFTω by the usual split into even and odd indices, which is valid in any commutative ring with ωK/2=−1.
Lemma 3 (weights). With xi=θiai and yl=θlbl, ∑i+l≡j(modK)xiyl=θjcj in Rn′.
Proof. A pair with i+l=j contributes θjaibl, and a pair with i+l=j+K contributes θj+Kaibl=−θjaibl, since θK=−1. □
Lemma 4 (recovery). If n′≥2M+k+1, line L9 turns the residue of cj in Rn′ into the integer cj.
Proof. By Lemmas 2 and 3 and the induction hypothesis on line L6 (below), line L7 gives Kθjcj in Rn′, and line L8 multiplies by the inverse of Kθj=2k+jn′/K, which is 22n′−k−jn′/K since 22n′=1; so it gives rj=cjmod(2n′+1) in [0,2n′]. By Lemma 1, cj lies in the open interval (−(K−1−j)22M,(j+1)22M) or is 0, whose length K22M≤2n′−1 is less than the modulus. If cj≥0, then rj=cj<(j+1)22M and line L9 keeps it. If cj<0, then rj=cj+2n′+1>2n′+1−K22M≥2n′−1≥K22M≥(j+1)22M, and line L9 subtracts the modulus, giving cj. □
Theorem. SSA-MULMOD returns ABmod(2n+1), and terminates.
Proof. By strong induction on n. The base cases were treated above. Otherwise, the recursive calls of line L6 are on residues in Rn′ with n′<n (the implementation takes the base case whenever its choice gives n′≥n), so by the induction hypothesis they return a^jb^j in Rn′. By Lemma 4 the values after line L9 are the integers cj, and by Lemma 1 line L10 returns ∑jcj2jMmod(2n+1)=ABmod(2n+1). Since each call either is a base case or recurses on a strictly smaller n′, the recursion terminates. ■
Remark (depth). With K about n, n′≤2n/K+k+1+K is O(n), so the bit length of the size halves at each level, up to a constant, and the depth of the recursion is log2log2n+O(1).