4.5.2 THE GREATEST COMMON DIVISOR 333 Thus the (Apache web server for windows)
4.5.2 THE GREATEST COMMON DIVISOR 333 Thus the double recurrence (34) can be transformed into the single recurrence relation in (37). Use of the generating function G(z) = & + Alz + A2z2 + . . . now transforms (37) into the equation (1-$z-&z2)G(z) = ao+aiz+a2z2+~ 1–+$1–z/2 A?-+ (l-z/2)2 7 (38) where a~, al, and a2 are constants that can be determined by the values of Ao, Al, and Aa. Since 1-$z + az2 = (1+ az)(l -z), we can express G(z) by the method of partial fractions in the form Tedious manipulations produce the values of these constants bo, . . . , bs, and thus the coefficients of G(z) are determined. We finally obtain the solution + (-:,Y-& -+@ + &c + ++bo) + &c&o; A,, = +mc + n($a + +A + (&a + $b + & + @oo) + 2- (44 + (-$,+&a -@ + $c + @bo), m > n. (39) With these elaborate calculations done, we can readily determine the be- havior of the lattice-point model. Assume that the inputs u and v to the algo- rithm are odd, and let m = LlguJ, n = [lg vJ. The average number of subtrac- tion cycles, namely the quantity C in the analysis of Program B, is obtained by setting a = 1, b = 0, c = 1, A00 = 1 in the recurrence (34). By (39) we see that (for m 2: n) the lattice model predicts subtraction cycles, plus terms that rapidly go to zero as n approaches infinity. The average number of times that gcd(u, v) = 1 is obtained by setting a = b = c = 0, A00 = 1; this gives the probability that u and v are relatively prime, approximately 2. Actually, since u and v are assumed to be odd, they should be relatively prime with probability 8/.rr2 (see exercise 13), so this reflects the degree of inaccuracy of the lattice-point model. The average number of times that a path from (m, n) goes through one of the diagonal points (m , m ) for some m 2 1 is obtained by setting a = 1, b = c = &O = 0 in (34); so we find that this quantity is approximately m n. *n + & + &L,, when 2 Now we can determine the average number of shifts, i.e., the number of times that step B3 is performed. (This is the quantity D in Program B.) In any