Horner's rule, synthetic division and the Taylor shift compute what they claim full
This proof shows: correctness.
Let R be a commutative ring with 1, let f=∑i=0naixi∈R[x] with n≥0 and an=0, stored as the list a=[a0,…,an], and let u∈R. For HORNER the point u may also lie in an associative ring S that contains the coefficients and in which u commutes with them; the argument below uses only the ring axioms of S.
Lemma 1 (HORNER). HORNER(a,u) returns f(u)=∑i=0naiui, and HORNER([],u) returns 0.
Proof. The empty list is the zero polynomial, and line L1 returns 0. Let n≥0. We prove the invariant
(H) before the step of line L4 with index i (for i=n−1,…,0), and after the loop with i=−1, s=∑j=i+1najuj−i−1.
Initialization. Line L2 sets s=an. For i=n−1 the sum in (H) is the single term anu0=an.
Maintenance. Suppose (H) holds before the step with index i. Line L4 computes
s⋅u+ai=(j=i+1∑najuj−i−1)u+ai=j=i+1∑najuj−i+aiu0=j=i∑najuj−i. The middle step is distributivity and associativity of S (with ajuku=ajuk+1). This is (H) for the index i−1.
Termination. The loop runs for i=n−1 down to 0 and stops; then (H) holds with i=−1, so s=∑j=0najuj=f(u), which line L5 returns. If n=0 the loop does not run and s=a0=f(u). □
Lemma 2 (SYNTHETIC-DIVISION). Let n≥1. SYNTHETIC-DIVISION(a,u) returns b=[b0,…,bn−1] and r with
f=(x−u)j=0∑n−1bjxj+r,r=f(u),bn−1=an. Proof. Lines S1 to S4 define bn−1=an, bi−1=biu+ai for i=n−1,…,1, and r=b0u+a0. Let q=∑j=0n−1bjxj. Then
(x−u)q+r=j=0∑n−1bjxj+1−j=0∑n−1ubjxj+r. Collect the coefficient of each power. For xn it is bn−1=an. For xi with 1≤i≤n−1 it is bi−1−ubi=(biu+ai)−ubi=ai, by line S3 and commutativity of R. For x0 it is r−ub0=a0, by line S4. So (x−u)q+r=f. The values bn−1,…,b0,r are exactly the successive values of s in HORNER(a,u) (line L2, then line L4 for i=n−1,…,0), so r=f(u) by Lemma 1. □
Lemma 3 (TAYLOR-SHIFT). TAYLOR-SHIFT(a,u) returns c=[c0,…,cn] with f(x)=∑k=0nck(x−u)k. Equivalently, f(x+u)=∑k=0nckxk.
Proof. For 0≤k≤n write Pk(x)=∑j=0n−kc[k+j]xj for the polynomial formed by the top part of the current list. We prove the invariant
(T) before round k of the loop of line T2 (for k=0,…,n, with k=n meaning after the loop), f(x)=∑j<kc[j](x−u)j+(x−u)kPk(x).
Initialization. For k=0, line T1 sets c=a, so P0=f, the first sum is empty, and (T) reads f=f.
Maintenance. Round k runs line T4 for i=n−1 down to k. Write pj=c[k+j] for the entries before the round, so Pk=∑j=0n−kpjxj, and write c′ for the entries after the round. The entry c[n] is not changed, so c′[n]=pn−k. For i from n−1 down to k, line T4 sets c′[i]=c[i]+u⋅c′[i+1], because c[i+1] was already updated (or is c[n]). With βj=c′[k+1+j] for 0≤j≤n−k−1, this reads βn−k−1=pn−k, βj−1=βju+pj for j=n−k−1,…,1, and c′[k]=β0u+p0. These are the recurrences of SYNTHETIC-DIVISION applied to Pk, if n−k≥1. By Lemma 2, Pk=(x−u)Pk+1+c′[k], where Pk+1=∑jβjxj is the polynomial formed by c′[k+1..n], and c′[k]=Pk(u). Entries below k are not touched. Substituting into (T):
f=j<k∑c′[j](x−u)j+(x−u)k((x−u)Pk+1+c′[k])=j<k+1∑c′[j](x−u)j+(x−u)k+1Pk+1, which is (T) for k+1. (Lemma 2 is stated for the list a, but its proof uses only the recurrences, so it applies to any list of length at least 2.)
Termination. The loop runs for k=0,…,n−1. Then (T) holds for k=n, and Pn=c[n] is a constant. So f=∑j<nc[j](x−u)j+c[n](x−u)n=∑k=0nck(x−u)k. Substituting x+u for x, which is a ring homomorphism of R[x], gives f(x+u)=∑ckxk. If n=0, the loop does not run and c=[a0], which is correct. □
Corollary (Taylor coefficients). If k! is a unit in R, then ck=f(k)(u)/k!, where f(k) is the k-th formal derivative. Proof. Differentiate f=∑jcj(x−u)j formally k times: the terms with j<k vanish, the term j=k gives k!ck, and the terms with j>k keep a factor (x−u), which vanishes at x=u. So f(k)(u)=k!ck. In particular c0=f(u) and c1=f′(u) over every commutative ring. □
Theorem. HORNER, SYNTHETIC-DIVISION and TAYLOR-SHIFT are correct, by Lemmas 1, 2 and 3. HORNER uses exactly n multiplications and n additions for degree n, because line L4 runs n times; SYNTHETIC-DIVISION uses the same; TAYLOR-SHIFT runs line T4 ∑k=0n−1(n−k)=n(n+1)/2 times. ■