* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download mathnotes
Survey
Document related concepts
Transcript
Some supporting mathematical notes Note 1. The Greeks based their measurement upon fractions of the form m/n, where m and n are integer numbers. Greatest common divisors are important in comparing fractions: if m=Md and n=Nd, then M/N is the fraction m/n "in its lowest terms". Note 2. The sequence of numbers F[0], F[1], F[2],..., F[n] where F[k+1] = F[k]+F[k-1] and F[0] = F[1] = 1, is named after Fibonacci, an Italian mathematician who introduced it in 1202. The first few terms of the sequence are: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, ... We can derive a formula for the k-th Fibonacci number: (a) find the roots, ( ('alpha') and ( ('beta') of the quadratic equation x2 = x + 1 (b) find values for A and B so that A + B = A( + B( = 1 (c) F[k] can then be expressed as A(k + B(k You can prove this by checking the following claims: (1) Step (a) computes two numbers x such that xk+1 = xk + xk-1 (2) If A and B are any numbers, the sequence defined by f[k] = A(k + B(k satisfies f[k+1] = f[k] + f[k-1] (3) Step (b) computes A and B so that f[0] = f[1] = 1, and so defines the Fibonacci sequence. We can use the results of (a), (b) and (c) to calculate the k-th Fibonacci number using tkeden: /* the roots of the quadratic in (a) are alpha and beta */ alpha is (1 + sqrt(5))/2; beta is (1 - sqrt(5))/2; /* sqrt = square root */ /* the solutions to the equations in (b) are A and B */ B is (alpha - 1) / (alpha - beta); A is (1 - beta) / (alpha - beta); /* the formula for F[k] in (c) defines the k-th Fibonacci number */ fibk is int(A*pow(alpha, k)+B*pow(beta, k)); /* pow(x,n) returns 'x raised to the power n', int() rounds to an integer */ We can then check claim (1) by direct computation: /* check that sequence pow(alpha,k) satisfies the Fibonacci recurrence: pa1 is pow(alpha,1); pa2 is pow(alpha,2); pa3 is pow(alpha,3); pa4 is pow(alpha,4); pa12 is pa1+pa2; pa23 is pa2+pa3; pa34 is pa3+pa4; */ We can also confirm that computing the GCD of F[k+1] and F[k] leads to a large number of division steps: fibk is int(A*pow(alpha, k)+B*pow(beta, k)); fibkplus1 is int(A*pow(alpha, k+1)+B*pow(beta, k+1)); A2 is fibkplus1; B2 is fibk; /* substitute different values for k to test the results */ k k k k = = = = 4; 20; 23; 25; Note 3. There is a link between the JUGS model and GCD computation: A mathematical fact ... gcd(m,n) is the smallest positive integer of the form Mm+Nn where M and N are integer values Proof: Let x be the smallest positive integer expressible as Mm+Nn. If we divide n by x, we have an integer quotient Q and integer remainder r, where 0<=r<x: r = n - Qx = n - Q(Mm+Nn) = -QMm + (1-QN)n This means that r is less than x, and is also expressible in the form Mm+Nn. Since x is the smallest positive integer expressible in this form, r = 0, and x divides n. By a similar argument, x divides m. So x is a common divisor of m and n. But if any number y divides m and n it also divides x = Mm+Nn. So x is the greatest common divisor of m and n. How this links to the JUGS model... Suppose that we have jugs Jug A and Jug B of capacities a and b respectively, where a ( b. There are two basic routines for manipulating the jugs: (1) Fill the Jug B repeat { Pour from Jug B to Jug A Empty Jug A if Jug B is not empty } (2) repeat { if Jug B is not full { Fill the Jug A Pour from the Jug A to the Jug B } } If p mod q denotes the remainder on dividing p by q, these routines are respectively equivalent to: computing b mod a, then (b - (a - b mod a)) mod a = 2b mod a etc and computing a - b mod a, then (a - (b - (a - b mod a)) mod a = -2b mod a etc Since gcd(a,b) is of the form Aa+Bb, and is less than a, it is expressible as Bb mod a for some B. Hence the quantity of liquid gcd(a, b) can be obtained using jugs of size a and b.