The subproduct tree holds the range products, and its two traversals evaluate and combine correctly full
This proof shows: correctness.
Let R be a commutative ring, n≥1 and u0,…,un−1∈R. For integers 0≤l≤r≤n write
P(l,r)=l≤j<r∏(x−uj), a monic polynomial of degree r−l, with P(l,l)=1. For a level h≥0 and an index i≥0, let lh,i=i2h and rh,i=min((i+1)2h,n).
The build
Claim. After line L1, and after each pass of the loop L3 to L8, the list T[h] has ⌈n/2h⌉ nodes and its node i is P(lh,i,rh,i).
Level 0. Line L1 sets node i to x−ui=P(i,i+1), and r0,i=i+1 because i<n. There are n nodes.
From h to h+1. Let L=⌈n/2h⌉ be the number of nodes at level h. For a pair 2i,2i+1<L, line L6 forms
P(lh,2i,rh,2i)⋅P(lh,2i+1,rh,2i+1)=P(2i2h,(2i+1)2h)⋅P((2i+1)2h,rh,2i+1)=P(lh+1,i,rh+1,i), because rh,2i=(2i+1)2h when node 2i+1 exists, and rh,2i+1=min((2i+2)2h,n)=rh+1,i. If L is odd, line L7 copies the last node, of index L−1=2i, as node i of level h+1. It is P(2i2h,n), and lh+1,i=2i2h and rh+1,i=n because (2i+1)2h≥n. So level h+1 has ⌈L/2⌉=⌈n/2h+1⌉ nodes of the claimed form.
End. The number of nodes is at least 1 and decreases strictly while it is larger than 1, so the loop stops, at the first k with ⌈n/2k⌉=1, that is k=⌈log2n⌉. Then T[k]=[P(0,n)]=[m] with m=∏j(x−uj).
Remainder descent
Let f∈R[x]. Every node is monic, so division with remainder by a node is defined over R. EVALUATE sets rk,0=fremm and then, for each level h from k−1 down to 0, rh,i=rh+1,⌊i/2⌋remT[h][i].
Claim. rh,i=fremT[h][i] for all h and i.
The node T[h][i] divides its parent T[h+1][⌊i/2⌋], because by the build claim the range of the child is contained in the range of the parent. If g∣G and G is monic, then (fremG)remg=fremg: write f=qG+(fremG); then f−(fremG)=qG is a multiple of g, so f and fremG have the same remainder modulo the monic g, by the uniqueness of the remainder. The claim follows by induction from the root down. When the degree of rh+1,⌊i/2⌋ is already less than the degree of the node, the remainder is this polynomial itself, which is the shortcut in the implementation.
At level 0 the node is x−uj and frem(x−uj)=f(uj) by the polynomial remainder theorem. So EVALUATE returns f(u0),…,f(un−1).
Linear combination
Let c0,…,cn−1∈R. COMBINE sets s0,i=ci and, for each level, sh+1,i=sh,2i⋅T[h][2i+1]+sh,2i+1⋅T[h][2i] for each pair, and copies sh,L−1 when L is odd.
Claim. sh,i=∑l≤j<rcjP(l,r)/(x−uj), where l=lh,i, r=rh,i, and P(l,r)/(x−uj)=P(l,j)P(j+1,r) is the product of the other factors.
At level 0 the sum has the single term ciP(i,i+1)/(x−ui)=ci. For a pair, let the left range be [l,t) and the right range [t,r). For j in the left range, P(l,r)/(x−uj)=(P(l,t)/(x−uj))⋅P(t,r), and P(t,r) is the right node T[h][2i+1]. For j in the right range, P(l,r)/(x−uj)=P(l,t)⋅(P(t,r)/(x−uj)), and P(l,t) is the left node. Adding the two parts gives the formula of line C4. A copied node keeps its range, so its sum does not change. At the root, COMBINE returns ∑jcjm/(x−uj).
Interpolation
Let R be a field and the uj distinct. Then m′(uj)=∏i=j(uj−ui)=0, by the product rule applied to m=(x−uj)⋅m/(x−uj) at x=uj. With cj=vj/m′(uj), the polynomial f=∑jcjm/(x−uj) has degree less than n, and at x=ui every term with j=i vanishes, so f(ui)=ci∏j=i(ui−uj)=vi. This is the Lagrange form of the interpolating polynomial, which is the unique polynomial of degree less than n with these values. ■