The Ben-Or and Tiwari algorithm recovers every polynomial with at most T terms from 2T values full
This proof shows: correctness, termination.
Let K=Q and f=∑j=1tcjxej∈K[x1,…,xn] with cj=0, distinct ej∈Nn, and t≤T. Let p1,…,pn be the first n primes, mj=∏kpkejk, and ai=f(p1i,…,pni)=∑jcjmji for 0≤i<2T, the values computed at lines L1 and L2. Let Λ(z)=∏j(z−mj).
A recurrence of length L for a0,…,aN−1 is a monic polynomial Γ(z)=∑k=0Lγkzk of degree L with ∑k=0Lγkas+k=0 for 0≤s≤N−1−L. In terms of the connection polynomial C(z)=1+C1z+⋯+CLzL used by Berlekamp-Massey, Γ(z)=zLC(1/z).
We use one known theorem. Massey's theorem (Massey 1969; MCA Section 12.3 gives an equivalent form through Padé approximation): on input a0,…,aN−1, the Berlekamp-Massey algorithm terminates after N steps and returns a recurrence of the least possible length L for this prefix.
Lemma 1 (distinct nodes). The mj are distinct positive integers.
Proof. Each mj is a product of positive primes, so it is a positive integer. If mj=mk, uniqueness of prime factorization gives ejℓ=ekℓ for every ℓ, so ej=ek and j=k. □
Lemma 2 (the recurrence found is Λ). The polynomial Γ computed at line L3 equals Λ, and t=degΓ.
Proof. First, Λ is a recurrence of length t for the whole prefix: for every s, ∑kλkas+k=∑jcjmjsΛ(mj)=0. By Massey's theorem, line L3 returns a recurrence Γ of least length L, so L≤t.
Now let Γ be any recurrence of length L≤t for a0,…,a2T−1. Since L≤t≤T, the defining relations hold for 0≤s≤2T−1−L, which includes 0≤s≤t−1 because 2T−1−L≥2t−1−t=t−1. For these s,
0=k=0∑Lγkas+k=j=1∑t(cjΓ(mj))mjs. This is a homogeneous linear system in the t unknowns uj=cjΓ(mj) whose matrix (mjs)0≤s<t, 1≤j≤t is a Vandermonde matrix with distinct nodes by Lemma 1, hence nonsingular. So uj=0, and since cj=0, Γ(mj)=0 for every j. The mj are distinct, so Λ divides Γ. Then t≤L, so L=t, and two monic polynomials of the same degree, one dividing the other, are equal: Γ=Λ.
If t=0, the argument says L=0 and Γ=1, and line L4 returns the zero polynomial, which is f. □
Lemma 3 (the roots). If t≥1, line L5 terminates and returns m1,…,mt.
Proof. Λ is monic with integer coefficients and the distinct integer roots mj, so its discriminant Δ=∏j<k(mj−mk)2 is a nonzero integer. The implementation tries primes q in increasing order. For a prime q∤Δ, the mj are distinct modulo q, so Λmodq=∏j(z−mj) has exactly the t roots mjmodq, and Λ′(mj)=∏k=j(mj−mk) is a unit modulo q. Only finitely many primes divide Δ, so such a q is reached and the loop over q terminates. For an earlier prime q the test fails when the number of roots is not t or a root is a root of Λ′; if it passes, the lifted values are still checked by exact evaluation at the end, so a wrong answer is never returned.
Fix a prime q that passes the test and a root r0 of Λ modulo q with Λ′(r0)≡0. Since Λ≡∏j(z−mj) and q is prime, r0≡mj(modq) for some j. Newton's step r′=r−Λ(r)Λ′(r)−1modQ2, applied to r≡mj(modQ), gives r′≡mj(modQ2): write r=mj+Qh; by Taylor expansion Λ(r)≡QhΛ′(r)(modQ2), so r′≡r−Qh≡mj(modQ2). This is Hensel's lemma, and Λ′(r) is invertible modulo Q2 because it is a unit modulo q. The modulus is squared until it exceeds 2B, where B=1+maxk∣λk∣ is Cauchy's bound, so ∣mj∣<B. Then the symmetric representative of r in (−Q/2,Q/2] is mj itself. Distinct roots modulo q give distinct mj, so all t values are found, they satisfy Λ(mj)=0 exactly, and the procedure returns them. □
Lemma 4 (the exponents). Line L6 computes ej from mj.
Proof. Dividing mj by pk as long as the division is exact counts the exponent of pk in mj, which is ejk by Lemma 1's factorization mj=∏kpkejk. After all k, the quotient is 1, so no error is raised. □
Lemma 5 (the coefficients). Line L7 returns c1,…,ct.
Proof. Fix j and let Λj(z)=Λ(z)/(z−mj)=∑i=0t−1qjizi. Synthetic division computes it: comparing coefficients in Λ(z)=(z−mj)Λj(z) gives qj,t−1=λt=1 and qj,i−1=λi+mjqji, which is the loop in the implementation. Then
i=0∑t−1qjiai=k=1∑tcki=0∑t−1qjimki=k=1∑tckΛj(mk)=cjΛj(mj), because Λj(mk)=0 for k=j. Finally Λj(mj)=Λ′(mj)=∏k=j(mj−mk)=0 by Lemma 1, so the division in the implementation gives cj. The system of line L7 has a nonsingular Vandermonde matrix, so this is its unique solution. □
Theorem. If f∈Q[x1,…,xn] has at most T terms, BEN-OR-TIWARI(f,n,T) terminates after exactly 2T evaluations and returns f.
Proof. Lines L1 and L2 make 2T evaluations and stop. Line L3 terminates by Massey's theorem and, by Lemma 2, returns Λ and the true number of terms t. If t=0 then f=0 is returned at line L4. Otherwise Lemmas 3, 4 and 5 show that lines L5, L6 and L7 terminate and produce the roots mj, the exponent vectors ej and the coefficients cj, all nonzero. Line L8 returns ∑jcjxej=f. ■