Advanced Algebrac Algorthms on Integers and Polynomals Analyss of Algorthms Prepared by John Ref, Ph.D.
Integer and Polynomal Computatons a) Newton Iteraton: applcaton to dvson b) Evaluaton and Interpolaton va Chnese Remanderng Man Lecture Materal: Algorthms on Integers Advanced Lecture Materal: Extenson of Algorthms to Polynomals
Taylor Expanson (x-x 0) f (x) = f (x 0) + (x - x 0) f ' (x 0) + f " (x 0) +...
Taylor Expanson (cont d) To fnd root f(x), use Newton Iteraton: x + 1 = x - f (x ) f '(x ) Example: To fnd recprocal of x choose fnd root f ( y) = 1 1 y = x f ( y ) y 1= y y ( y x) + f '( y ) = 1 xy
Applcaton of Newton Iteraton to Recprocal of an Integer Input nteger x, accuracy bound k Intalze f x has n bts y 0 = n for =1 to k do y y ( y x) + 1 1 output yk where 1 yk x proof let error ε = 1 y x k k then ε = 1 y x = 1 xy ( y x) k + 1 k + 1 k k k k = ( ε ) = ( ε ) = snce ε k 0 0 k 1
Applcaton of Newton Iteraton to Recprocal of an Integer (cont d) Theorem Integer Recprocal can be computed to accuracy -n n O(log n) nteger mults and addtons.
Steven Cooks s Improvement (Hs Harvard Ph.D. Thess) Key Trck: Snce we need only compute y k up to k+1 bt accuracy of error on kth stage Total Tme Cost log n k = 0 1 yk x c M O M n k + 1 ( ) ( ( )) k Where M(n) s tme cost to multply two n bt ntegers 1
Other Applcatons of Newton Iteratons on Integers O(M(n)) tme algorthms: Quotent + dvsor of nteger dvson Square root Sn, cosne, etc. Used n practce!
Advanced Topc: Extenson to Polynomal Recprocal Defnton of Polynomal Recprocal Recprocal ( P( x)) = n x P( x) " # = polynomal r(x) where r x p x x x n ( ) ( ) = + ε ( ) and ε(x) has degree < n-1
Algorthm: Recprocal (P(x)) Input polynomal P( x) n 1 = a x = 0 degree n-1, n s power of 1 [1] f n = 1 then return else a 1 1 1 (3/) n 1 1 n 0 [] r(x) Recprocal ( P( x)) where P( x) = ax [3] Rx ( ) r( xx ) r( x) Px ( ) [4] return r( x) = Rx ( ) x n 1 = n/ n
Proof of the Recprocal Algorthm Theorem: The Algorthm Correctly Computes Recprocal(P(x)) Proof by nducton bass n = 1 P( x) = a so r( x) = 0 1 a 0 n 1 nductve step let P( x) = P ( x) x + P ( x) n n where deg ( P1 ) = 1, deg ( P ) 1
Proof Algorthm Computes Recprocal (P(x)) (cont d) By nducton hypothess, f r ( x) = recprocal ( P ( x)) then 1 1 r ( x) P ( x) = x + ε ( x) n 1 1 1 n where ε1( x) has degree < 1
Proof Algorthm Computes Recprocal (P(x)) (cont d) At lne [3] we compute R( x) r ( x) x r ( x) P( x) (3/ ) n 1 1 n 1 snce P( x) = P ( x) x + P ( x) P( x) R( x) = r ( x) P ( x) x + r ( x) P ( x) x n (3/ ) n 1 1 1 n # $ % r1 ( x) p1 ( x) x + r1 ( x) p( x) & ' (
Proof Algorthm Computes Recprocal (P(x)) (cont d) n Substtutng x + ε1(x) for r1 ( x) p1 ( x), we get n 3n 4 % & R( x) p( x) = x ' ε1( x) x + r1 ( x) p( x) ( ) * 3n 4 n 4 = x 0( x ) R( x) But r( x) = so x n # $ r x p x x o x n n ( ) ( ) = ( )
Modular Arthmetc Assume relatvely prme P 0, P 1,, P k-1 Let p k 1 = = 0 p gven x, 0 < x < p x # x x ( 1 1 0,..., k-1) where x = x mod p for = 0,..., k -1
Applcatons to Arthmetc Compute u op v by computng for =0,...,k-1 w = u op v mod p where u = u mod p v = v mod p op {+, -, } But doesn t extend to dvson (overflow problems)
Super Modul Computaton Input p 0, p 1,, p k-1, where p < b Output Super modular Tree:
Super Modul Computaton (cont d) Tme Cost log k = 0 = k ( ) M b OM ( ( kb)log k)
Algorthm Resdue Computaton Input k 1 x, 0 x < P = P = 0 Output x 0, x 1,, x k-1, when x =x mod P =0, and k-1 Recursve algorthm [1] compute quotent and remanders: 1 1 1 1 ( k 1)/ x = q v + r, v = P = 0 k 1 x = q v + r, v = P ( k 1) = + 1
Algorthm Resdue Computaton (cont d) [] recursvely compute ( k 1) (.1) r1 mod P for = 0,..., ( k 1) (.) r mod P for = + 1,..., k 1 [3] output for = 0, 1,, k-1 x mod P " r1 mod P for $ = % $ r mod P for > $& ( k 1) ( k 1)
Tme Cost for Resdue Computaton Let D(n) = tme cost for nteger dvson = O(M(n)) Total Tme for nput sze n = k b! n " T ( n) = T # $ + kd( b) + O( n) % &! n " T # $ + O( M ( n)) % & O( M ( n)log n)
Proof of Algorthm for Resdue Computaton Idea of Proof of algorthm Uses fact: f x = q v + r and v mod P = 0, then X mod P = r mod P
Advanced Topc: Resdue Computaton on Polynomals Input modul P 0 (x), P 1 (x),, P k-1 (x) assume each degree < d and relatvely prme Algorthm uses smlar Super modular Tree tre, but usng polynomals rather than ntegers
Advanced Topc: Resdue Computaton on Polynomals (cont d) Output for =0,, k-1 Q (x) = Q(x) mod P (x) Q(x) has degree < kd Theorem The Resdue Computaton can be done n tme O(M(n) log n) where n = k d Proof Idea use same algorthm as n nteger case
Advanced Topc: Multpont Evaluaton of Polynomals by Resdue Computaton Input polynomal f(x) degree n-1 and ponts x 0, x 1,, x n-1 [1] for =0,, n-1 let P (x) = (x-x ) [] By Resdue Algorthm Computer for =0,, n-1 f(x ) = f(x) mod P (x) [3] output f(x 0 ),, f(x n-1 ) Tme Cost O(M(n) log n), = O(n(log n) )
Polynomal Interpolaton Input evaluaton ponts x 0,, x n-1 values y 0,, y n-1 Output P(x) where y k = P(x k ) for k=0,, n-1
Polynomal Interpolaton (cont d) Interpolaton formula: Where n 1 = P( x) y a ( x x ) k k k = 0 k a k = k 1 ( x x ) k
Proof of Polynomal Interpolaton Proof uses denttes: a k ( x x) mod( x xk) = 1 k a k ( x x) mod( x xj) = 0 for j k k
Usng Chnese Remanderng for Integer Interpolaton Input relatvely prme P 0, P 1,, P n-1 and y {0, P -1 } for =0,,n-1 Problem compute y < P 0 P 1 P n-1 s.t. y = y mod P =0,, n-1
Usng Chnese Remanderng for Integer Interpolaton Generalzed Interpolaton Formula: n 1 y y a P = k k k = 0 k Where proof a k = k s, k and s P P 1, k = ( ) mod k # $ " 1 & a k P ' mod Pj = % ( k ) * 0 j = k j k
Advanced Topc: Precondtoned Interpolaton Precondtoned Case assumes coeffcents {a k k=0,, n-1} precomputed Use Dvde & Conquer n 1 y y a P = k k k = 0 k # ( n 1)/ $ # $ n 1 n 1 n 1 = % ykak P & + % ykak P & k = 0 k ( n 1) k = + 1 k % & % & ' = 0 ( ' = 0 (
Precondtoned Interpolaton (cont d) # % $ & = ) * % & ( n 1)/ n 1 ( n 1) ' ( P % yka k P & + = 0, ( n 1) k = + 1 k % ( n 1) = + 1 & -. ' ( # n 1 ( n 1)/ ( n 1)/ $ + ) P * % ykak P & ( n 1) ) % & k = 0 = + 1 k + * %, - = 0 &.
Tme Cost for Precondtoned Interpolaton! n "! n " T ( n) = T # $ + M # $ % & % & = O( M ( n)log n) Assumng {a 0,, a n-1 } precomputed
Precomputaton of {a 0,, a n-1 } 1) Compute P n 1 = P = 0 ) Compute b k where b k P k = P mod (P k ) by Resdue Computaton O(M(n) log n) 3) Compute a k = (b k ) -1 mod P k by Extended GCD algorthm
Proof of Precomputaton of {a 0,, a n-1 } proof snce b P = P mod (P ) k k k k k k then P = d (P ) + b P so P = d P + b so b k = k k P mod P k k k
Precomputaton of {a 0,, a n-1 } for Polynomal Interpolatons Here P = (x-x ) for =0,, n-1 n-1 Q(x) b k = where Q(x)= (x-x j) (x - x ) k Q(x) - Q(x ) reduces to multpont evaluaton of dervatve of Q(x) O(M(n) log n) tme! j=0 k = snce Q(x k ) = 0 (x - x k ) = d Q(x) dx x = x k
Concluson Polynomal and Integer Computatons use smlar dvde and conquer technques to solve: 1. Multplcaton. Dvson 3. Interpolaton and evaluaton Open Problem Reduce from tme O(M(n)log n) to O(M(n))
Newton Iteraton and Polynomal Computaton Analyss of Algorthms Prepared by John Ref, Ph.D.