ON SHANKS ALGORITHM FOR COMPUTING THE CONTINUED FRACTION OF log b a.

Similar documents
Continued Fractions and the Euclidean Algorithm

GREATEST COMMON DIVISOR

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

CS 103X: Discrete Structures Homework Assignment 3 Solutions

MATH 289 PROBLEM SET 4: NUMBER THEORY

CONTINUED FRACTIONS AND PELL S EQUATION. Contents 1. Continued Fractions 1 2. Solution to Pell s Equation 9 References 12

Zero: If P is a polynomial and if c is a number such that P (c) = 0 then c is a zero of P.

Arithmetic Coding: Introduction

Lecture 13: Factoring Integers

Continued Fractions. Darren C. Collins

SIMPLIFYING SQUARE ROOTS

MATH10040 Chapter 2: Prime and relatively prime numbers

Lecture 3: Finding integer solutions to systems of linear equations

Section 1.1 Real Numbers

Math Review. for the Quantitative Reasoning Measure of the GRE revised General Test

An example of a computable

HOMEWORK 5 SOLUTIONS. n!f n (1) lim. ln x n! + xn x. 1 = G n 1 (x). (2) k + 1 n. (n 1)!

26 Integers: Multiplication, Division, and Order

Crosswalk Directions:

Section IV.21. The Field of Quotients of an Integral Domain

COMMUTATIVE RINGS. Definition: A domain is a commutative ring R that satisfies the cancellation law for multiplication:

FACTORISATION YEARS. A guide for teachers - Years 9 10 June The Improving Mathematics Education in Schools (TIMES) Project

Lesson Plan. N.RN.3: Use properties of rational and irrational numbers.

On the generation of elliptic curves with 16 rational torsion points by Pythagorean triples

THREE DIMENSIONAL GEOMETRY

CHAPTER 5. Number Theory. 1. Integers and Division. Discussion

Solve addition and subtraction word problems, and add and subtract within 10, e.g., by using objects or drawings to represent the problem.

MATHEMATICAL INDUCTION. Mathematical Induction. This is a powerful method to prove properties of positive integers.

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 2

SCORE SETS IN ORIENTED GRAPHS

Math 115 Spring 2011 Written Homework 5 Solutions

Negative Integer Exponents

Answer Key for California State Standards: Algebra I

k, then n = p2α 1 1 pα k

Some Polynomial Theorems. John Kennedy Mathematics Department Santa Monica College 1900 Pico Blvd. Santa Monica, CA

Matrix Algebra. Some Basic Matrix Laws. Before reading the text or the following notes glance at the following list of basic matrix algebra laws.

DIVISIBILITY AND GREATEST COMMON DIVISORS

A Second Course in Mathematics Concepts for Elementary Teachers: Theory, Problems, and Solutions

God created the integers and the rest is the work of man. (Leopold Kronecker, in an after-dinner speech at a conference, Berlin, 1886)

MBA Jump Start Program

Using the ac Method to Factor

Local periods and binary partial words: An algorithm

Just the Factors, Ma am

Handout NUMBER THEORY

YOU CAN COUNT ON NUMBER LINES

CONTINUED FRACTIONS AND FACTORING. Niels Lauritzen

Simplifying Algebraic Fractions

8 Divisibility and prime numbers

Chapter 5. Rational Expressions

Math Workshop October 2010 Fractions and Repeating Decimals

n k=1 k=0 1/k! = e. Example 6.4. The series 1/k 2 converges in R. Indeed, if s n = n then k=1 1/k, then s 2n s n = 1 n

Homework until Test #2

3 1. Note that all cubes solve it; therefore, there are no more

Radicals - Multiply and Divide Radicals

11 Ideals Revisiting Z

Elementary Number Theory

Copy in your notebook: Add an example of each term with the symbols used in algebra 2 if there are any.

A Short Guide to Significant Figures

Chapter 7 - Roots, Radicals, and Complex Numbers

Chapter 4 -- Decimals

Year 9 set 1 Mathematics notes, to accompany the 9H book.

= = 3 4, Now assume that P (k) is true for some fixed k 2. This means that

Student Outcomes. Lesson Notes. Classwork. Discussion (10 minutes)

An Efficient RNS to Binary Converter Using the Moduli Set {2n + 1, 2n, 2n 1}

Math Released Set Algebra 1 PBA Item #13 Two Real Numbers Defined M44105

Number Theory Hungarian Style. Cameron Byerley s interpretation of Csaba Szabó s lectures

Core Maths C1. Revision Notes

PYTHAGOREAN TRIPLES KEITH CONRAD

Corollary. (f є C n+1 [a,b]). Proof: This follows directly from the preceding theorem using the inequality

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

Stanford Math Circle: Sunday, May 9, 2010 Square-Triangular Numbers, Pell s Equation, and Continued Fractions

This is a square root. The number under the radical is 9. (An asterisk * means multiply.)

Radicals - Multiply and Divide Radicals

Tim Kerins. Leaving Certificate Honours Maths - Algebra. Tim Kerins. the date

ON FIBONACCI NUMBERS WITH FEW PRIME DIVISORS

Online EFFECTIVE AS OF JANUARY 2013

4.2 Euclid s Classification of Pythagorean Triples

CM2202: Scientific Computing and Multimedia Applications General Maths: 2. Algebra - Factorisation

About the inverse football pool problem for 9 games 1

SOLVING QUADRATIC EQUATIONS - COMPARE THE FACTORING ac METHOD AND THE NEW DIAGONAL SUM METHOD By Nghi H. Nguyen

4. Binomial Expansions

Properties of Real Numbers

3. Mathematical Induction

AMBIGUOUS CLASSES IN QUADRATIC FIELDS

9.3 OPERATIONS WITH RADICALS

The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors.

Solutions of Equations in One Variable. Fixed-Point Iteration II

mod 10 = mod 10 = 49 mod 10 = 9.

Lesson 9: Radicals and Conjugates

Lies My Calculator and Computer Told Me

Counting Primes whose Sum of Digits is Prime

CS 173, Spring 2015 Examlet 2, Part A

V Quantitative Reasoning: Computers, Number Theory and Cryptography

Common Core Standards for Fantasy Sports Worksheets. Page 1

MATH. ALGEBRA I HONORS 9 th Grade ALGEBRA I HONORS

On numbers which are the sum of two squares

Factoring - Greatest Common Factor

Basic Proof Techniques

Mathematics for Computer Science/Software Engineering. Notes for the course MSM1F3 Dr. R. A. Wilson

Transcription:

ON SHANKS ALGORITHM FOR COMPUTING THE CONTINUED FRACTION OF log b a. TERENCE JACKSON AND KEITH MATTHEWS Abstract. We give a more practical variant of Shanks 954 algorithm for computing the continued fraction of log b a, for integers a > b >, using the floor and ceiling functions and an integer parameter c >. The variant, when repeated for a few values of c = 0 r, enables one to guess if log b a is rational and to find approximately r partial quotients.. Shanks algorithm In his article [], Shanks gave an algorithm for computing the partial quotients of log b a, where a > b are positive integers greater than. Construct two sequences a 0 = a, a = b, a 2,... and n 0, n, n 2,..., where the a i are positive rationals and the n i are positive integers, by the following rule: If i and a i > a i >, then (.) (.2) a ni i a i < a ni + i a i+ = a i /a ni i. Clearly (.) and (.2) imply a i > a i+. Also (.) implies a i a /ni i i and hence by induction on i 0, (.3) (.4) Also by induction on j 0, a i+ a /n0 ni 0. a 2j = a r 0/a s, a 2j+ = a u /a v 0, where r and u are positive integers and s and v are non negative integers. Two possibilities arise: (i) a r+ = for some r. Then equations (.4) imply a relation a q 0 = ap for positive integers p and q and so log a a 0 = p/q. (ii) a i+ > for all i. In this case the decreasing sequence {a i } tends to a. Also (.3) implies a =, unless perhaps n i = for all sufficiently large i; but then (.2) becomes a i+ = a i /a i and hence a = a/a =. If a i > a i >, then from (.) we have log ai (.5) n i =. log a i Let x i = log ai+ a i if a i+ >. Then we have Lemma. If a i+2 >, then (.6) x i = n i + /x i+. 99 Mathematics Subject Classification. Primary D09. for

2 TERENCE JACKSON AND KEITH MATTHEWS Proof. From (.2), we have (.7) (.8) (.9) from which (.6) follows. log a i+2 = log a i n i log a i+ = log a i log a i+ n i log a i+ log a i+ log a i+2 log a i+2 = x i x i+ n i x i+, From Lemma. and (.5), we deduce Lemma 2. (a) If log a a 0 is irrational, then x i = n i + /x i+ for all i 0. (b) If log a a 0 is rational, with a r+ =, then { ni + /x x i = i+ if 0 i < r, n r if i = r. In view of the equation log a a 0 = x 0, Lemma 2 leads immediately to Corollary. (.0) log a a 0 = { [n0, n,... ] if log a a 0 is irrational, [n 0, n,..., n r ] if log a a 0 is rational and a r+ =. Remark. It is an easy exercise to show that for j 0, (.) a 2j = a q2j 2 0 /a p2j 2, a 2j+ = a p2j a q2j 0 where p k /q k is the k th convergent to log a a 0. Example. log 2 0: Here a 0 = 0, a = 2. Then 2 3 < 0 < 2 4, so n 0 = 3 and a 2 = 0/2 3 =.25. Further,.25 3 < 2 <.25 4, so n = 3 and a 3 = 2/.25 3 =.024. Also,.024 9 <.25 <.024 0, so n 2 = 9 and a 4 =.25/.024 9 = 250000000000000000000000000/23794003928538027489924224 =.009749586 Continuing we obtain Table and log 2 0 = [3, 3, 9, 2, 2, 4, 6, 2,,,... ].

ON SHANKS ALGORITHM FOR COMPUTING THE CONTINUED FRACTION OF log b a. 3 Table i n i a i p i/q i 0 3 0 3/ 3 2 0/3 2 9.25 93/28 3 2.024 96/59 4 2.009749586 485/46 5 4.0043362776 236/643 6 6.00045475 330/4004 7 2.00062894 28738/865 8.0000637223 42039/2655 9.0000354408 70777/2306 0.0000282805.00000760 2. Some Pseudocode In Table 2 we present pseudocode for the Shanks algorithm. It soon becomes impractical to perform the calculations in multiprecision arithmetic, as the numerators and denominators a i grow rapidly. If we truncate the decimal expansions of the a[i] to r places and represent a positive rational a as g(a)/0 r, where g(a) = 0 r a, the ratio aa/bb will be calculated as 0 r g(aa)/g(bb). Working explicitly in integers, using the g(a), then results in algorithm, also depicted in Table 2, with c = 0 r, where int(x,y) equals x/y, when x and y are integers. As shown in the next section, the A[i] decrease strictly until they reach c. Also m[0]=n[0] and we can expect a number of the initial m[i] will be partial quotients. Naturally, the larger we take c, the more partial quotients will be produced. 3. Formal description of algorithm We show in Theorem 2. below, that algorithm will give the correct partial quotients when log a a 0 is rational and otherwise gives a parameterised sequence of integers which tend to the correct partial quotients when log a a 0 is irrational. Algorithm is now explicitly described. We define two integer sequences {A i,c }, i = 0,..., l(c) and {m j,c }, j = 0,..., l(c) 2, as follows. Let A 0,c = c a 0, A,c = c a. Then if i and A i,c > A i,c > c, we define m i,c and A i+,c by means of an intermediate sequence {B i,r,c }, defined for r 0, by B i,0,c = A i,c and cbi,r,c (3.) B i,r+,c =, r 0. A i,c Then c B i,r+,c < B i,r,c, if B i,r,c A i,c > c and hence there is a unique integer m = m i,c such that B i,m,c < A i,c B i,m,c. Then we define A i+,c = B i,m,c. Hence A i+,c c and the sequence {A i,c } decreases strictly until A l(c),c = c. There are two possible outcomes, depending on whether or not log b (a) is rational:

4 TERENCE JACKSON AND KEITH MATTHEWS Table 2 Shanks algorithm algorithm input: integers a>b> input: integers a>b>, c> output: n[0],n[],... output: m[0],m[],... s:= 0 s:= 0 a[0]:= a; a[]:= b A[0]:= a*c; A[]:= b*c aa:= a[0]; bb:= a[] aa:= A[0]; bb:= A[] while(bb > ){ while(bb > c){ i:=0 i:=0 while(aa bb){ while(aa bb){ aa:= aa/bb aa:= int(aa*c,bb) i:= i+ i:= i+ } } a[s+2]:= aa A[s+2]:= aa n[s]:= i m[s]:= i t:= bb t:= bb bb:= aa bb:= aa aa:= t aa:= t s:= s+ s:= s+ } } Theorem 2. () log a a 0 is a rational number p/q, p > q, gcd(p, q) =. Then (a) a 0 = d p, a = d q for some positive integer d; (b) if p/q = [n 0,..., n r ], where n r > if r >, then (i) A r+,c = c, a r+ = ; (ii) A i,c = c a i for 0 i r + ; (iii) m i,c = n i for 0 i r. (2) log a a 0 is irrational. Then (a) m 0,c = n 0 ; (b) l(c) and for fixed i, A i,c /c a i as c and m i,c = n i for all large c. Proof. (a) follows from the equation a p = aq 0. (b) is also straightforward on noticing that a i is a power of d and that we are implicitly performing Euclid s algorithm on the pair (p, q). For 2(a), we have (3.2) a n0 < a 0 < a n0+ and A 0,c = c a 0, A,c = c a. Also by induction on 0 r n 0, (3.3) B,r,c ca n0 r, B,r,c ca 0 (3.4) a r. Inequality (3.3) with r n 0 gives B,r,c A,c, while inequality (3.4) with r = n 0 gives B,n0,c ca 0 a n0 < ca = A,c,

ON SHANKS ALGORITHM FOR COMPUTING THE CONTINUED FRACTION OF log b a. 5 by inequality (3.2). Hence m 0,c = n 0. For 2(b), we use induction on i and assume l(c) i holds for all large c and that A i,c /c a i and A i,c /c a i as c. This is clearly true when i =. By properties of the integer part symbol, equation (3.) gives (3.5) c r A i,c A r i,c ( cr A r i,c ) c A i,c for r 0. Hence for r < n i, inequalities (3.5) give < B i,r,c cr A i,c A r. i,c B i,r,c /c a i /a r i a i /a ni i > a i. Then, because A i,c /c a i, it follows that B i,r,c > A i,c for all large c. Also B i,ni,c/c a i /a ni i < a i, so B i,ni,c < A i,c for all large c. Hence m i,c = n i for all large c. Also A i+,c = B i,ni,c > c, so l(c) > i+ for all large c. Moreover A i+,c /c a i /a ni i = a i+ and the induction goes through. Example 3. Table 3 lists the sequences m 0,c,..., m l(c) 2,c for c = 2 u, u =,..., 30, when a 0 = 3, a = 2. Table 3,,,,,,,,,,,,2,,,,2,,,,2,3,,,,2,2,2,,,,2,2,2,,,,,2,2,2,,2,,,,2,2,3,2,3,,,,2,2,3,2,,,,2,2,3,,2,,,, 2,,,,2,2,3,,3,,,3,,,,,2,2,3,,4, 3,,,,,2,2,3,,4,, 9,,,,,2,2,3,,5,24,,2,,,,2,2,3,,5, 3,,, 2,7,,,,2,2,3,,5, 2,,, 5,3,,,,,2,2,3,,5, 2, 2,, 3,,6,,,,2,2,3,,5, 2,5,, 6,2,,,2,2,3,,5, 2, 9,5,,2,,,,2,2,3,,5, 2,3,,,, 6,, 2, 2,,,,2,2,3,,5, 2,7,2, 7,8,,,,2,2,3,,5, 2,9,,49,2,,,,,2,2,3,,5, 2,22,4, 8,3, 4,,,,,2,2,3,,5, 2,22,2,,3,, 3, 8,,,,2,2,3,,5, 2,22,, 6,3,,, 3, 4, 2,,,,2,2,3,,5, 2,23,2,,, 2,,2,7,,,,2,2,3,,5, 2,23,3, 2,2, 2, 2,, 3, 2,,,,2,2,3,,5, 2,23,2,,7, 2, 2,4,,, 6, In fact log 2 3 = [,,, 2, 2, 3,, 5, 2, 23, 2,... ].

6 TERENCE JACKSON AND KEITH MATTHEWS 4. A heuristic algorithm We can replace the x function in equation (3.) by x, the least integer exceeding x. This produces an algorithm with similar properties to algorithm, with integer sequences {A i,c }, i = 0,..., l (c) and {m j,c }, j = 0,..., l (c) 2. Here A 0,c = A 0,c = a 0 c, A,c = A,c = a c and m 0,c = m 0,c = n 0. Then if i and A i,c > A i,c > c, we define m i,c and A i+,c by means of an intermediate sequence {B i,r,c }, defined for r 0, by B i,0,c = A i,c and (4.) and B i,r+,c = cb i,r,c A i,c Then c B i,r+,c < B i,r,c, if B i,r,c A i,c > c. For cb i,r,c A i,c B i,r+,c cb i,r,c A i,c, r 0. + + B i,r,c cb i,r,c + A i,c A i,cb i,r,c A i,c A i,c c B i,r,c. The last inequality is certainly true if B i,r,c A i,c > c. Hence there is a unique integer m = m i,c such that B i,m,c < A i,c B i,m,c. Then we define A i+,c = B i,m,c. Hence A i+,c c and the sequence {A i,c } decreases strictly until A l (c),c = c. If we perform the two computations simultaneously, the common initial elements of the sequences {m j,c } and {m k,c } are likely to be partial quotients of log b(a). With c = 0 r we expect roughly r partial quotients to be produced. If l(c) = l (c) and A j,c = A j,c and m j,c = m j,c for j = 0,..., l(c) 2, then log b a is likely to be rational. In practice, to get a feeling of certainty regarding the output when c = 0 r, we also run the algorithm for c = 0 t, r 5 t r + 5. Example 4. Table 4 lists the common values of m i,c and m i,c, when a = 3, b = 2 and c = 2 r, r 3. It seems likely that only partial quotients are produced for all r. Example 5. Table 5 lists the common values of m i,c and m i,c, when a = 34, b = 2 and c = 0 r, r 20. Partial quotients are not always produced, as is seen from lines 9,4 and 7. 5. Acknowledgement The second author is grateful for the hospitality provided by the School of Mathematical Sciences, ANU, where research for part of this paper was carried out.

ON SHANKS ALGORITHM FOR COMPUTING THE CONTINUED FRACTION OF log b a. 7 Table 4. a = 3, b = 2, c = 2 r, r 3. : 2: 3:,, 4:,, 5:,,,2 6:,,,2 7:,,,2,2 8:,,,2,2 9:,,,2,2 0:,,,2,2 :,,,2,2 2:,,,2,2 3:,,,2,2,3, 4:,,,2,2,3, 5:,,,2,2,3, 6:,,,2,2,3,,5 7:,,,2,2,3,,5 8:,,,2,2,3,,5 9:,,,2,2,3,,5,2 20:,,,2,2,3,,5 2:,,,2,2,3,,5,2 22:,,,2,2,3,,5,2 23:,,,2,2,3,,5,2 24:,,,2,2,3,,5,2 25:,,,2,2,3,,5,2 26:,,,2,2,3,,5,2 27:,,,2,2,3,,5,2 28:,,,2,2,3,,5,2,23 29:,,,2,2,3,,5,2,23 30:,,,2,2,3,,5,2,23,2 3:,,,2,2,3,,5,2,23,2 Table 5. a = 34, b = 2, c = 0 r, r =,..., 20. :,2,2 2:,2,2,, 3:,2,2,,,2 4:,2,2,,,2 5:,2,2,,,2,3, 6:,2,2,,,2,3,,8, 7:,2,2,,,2,3,,8,, 8:,2,2,,,2,3,,8,,,2 9:,2,2,,,2,3,,8,,,2,2,,3,3,2,32,7 0:,2,2,,,2,3,,8,,,2,2, :,2,2,,,2,3,,8,,,2,2,,2, 2:,2,2,,,2,3,,8,,,2,2,,2, 3:,2,2,,,2,3,,8,,,2,2,,2,,3 4:,2,2,,,2,3,,8,,,2,2,,2,,3,3,3 5:,2,2,,,2,3,,8,,,2,2,,2,,3,3,2 6:,2,2,,,2,3,,8,,,2,2,,2,,3,3,2,2 7:,2,2,,,2,3,,8,,,2,2,,2,,3,3,2,2,8,,,,, 8:,2,2,,,2,3,,8,,,2,2,,2,,3,3,2,2,7, 9:,2,2,,,2,3,,8,,,2,2,,2,,3,3,2,2,7, 20:,2,2,,,2,3,,8,,,2,2,,2,,3,3,2,2,7, References. D. Shanks, A logarithm algorithm, Math. Tables and Other Aids to Computation 8 (954). 60 64. DEPARTMENT OF MATHEMATICS, UNIVERSITY OF YORK, HESLINGTON. YORK YO05DD, ENGLAND E-mail address: thj@york.ac.uk DEPARTMENT OF MATHEMATICS, UNIVERSITY OF QUEENSLAND, BRISBANE, AUSTRALIA, 4072 E-mail address: krm@maths.uq.edu.au