Another Algorithm for Computing π Attributable to Archimedes: Avoiding Cancellation Errors

Similar documents
One-Sided Difference Formula for the First Derivative

Grade 8 Chapter 7: Rational and Irrational Numbers

Proof of the Equivalent Area of a Circle and a Right Triangle with Leg Lengths of the Radius and Circumference

LESSON 8.1 RATIONAL EXPRESSIONS I

Brunswick School Department Honors Geometry Unit 6: Right Triangles and Trigonometry

WEEK 7 NOTES AND EXERCISES

CN#5 Objectives 5/11/ I will be able to describe the effect on perimeter and area when one or more dimensions of a figure are changed.

Indicate whether the statement is true or false.

Explain any relationship you see between the length of the diameter and the circumference.

Prentice Hall Mathematics, Geometry 2009 Correlated to: Maine Learning Results 2007 Mathematics Grades 9-Diploma

Chapter 1/3 Rational Inequalities and Rates of Change

1. (25 points) Consider the region bounded by the curves x 2 = y 3 and y = 1. (a) Sketch both curves and shade in the region. x 2 = y 3.

Assignment 16 Assigned Weds Oct 11

Mathematics Precalculus: Honors Unit 3: Analytic Trigonometry

Stepping stones for Number systems. 1) Concept of a number line : Marking using sticks on the floor. (1 stick length = 1 unit)

Mathematics: Algebra II Honors Unit 1: Quadratic Functions

Paper 1 Foundation Revision List

Since x + we get x² + 2x = 4, or simplifying it, x² = 4. Therefore, x² + = 4 2 = 2. Ans. (C)

Chapter 1. Areas, volumes and simple sums. 1.1 Introduction. 1.2 Areas of simple shapes

Solution Week 68 (12/29/03) Tower of circles

The Computation of π by Archimedes. Bill McKeeman Dartmouth College

Mathematics: Algebra II Honors Unit 6: Radical Functions

How to (Almost) Square a Circle

Problem 1. Suppose we calculate the response of an LTI system to an input signal x(n), using the convolution sum:

Foundations of Basic Geometry

Basic Ideas in Greek Mathematics

π is a mathematical constant that symbolizes the ratio of a circle s circumference to its

Integer (positive or negative whole numbers or zero) arithmetic

Math Calculus I

Revision notes for Pure 1(9709/12)

2018 Sprint Solutions

b UVW is a right-angled triangle, therefore VW is the diameter of the circle. Centre of circle = Midpoint of VW = (8 2) + ( 2 6) = 100

The Celsius temperature scale is based on the freezing point and the boiling point of water. 12 degrees Celsius below zero would be written as

California Subject Examinations for Teachers

Take It To The Limit. Calculus H Mr. Russo Reaction to Take It To The Limit

2.1 Notes: Simplifying Radicals (Real and Imaginary)

On Various Ways of Approximating the Quadrature of a Circle by Numbers. 1 Author Leonh. Euler

ADALINE for Pattern Classification

HIGHER MATHS REVISION CHECKLIST (Grades 9 4)

CHAPTER 1 NUMBER SYSTEMS. 1.1 Introduction

Fixed Weight Competitive Nets: Hamming Net

2. Two binary operations (addition, denoted + and multiplication, denoted

56 CHAPTER 3. POLYNOMIAL FUNCTIONS

I.31 Now given a circular field, the circumference is 30 bu and the diameter 10 bu. Question: What is the area? Answer:

Area. HS PUMP. Spring 2009 CSUN Math. NSF Grant Measuring Aera A Candel

Sums and Products. a i = a 1. i=1. a i = a i a n. n 1

Mathematics AQA Advanced Subsidiary GCE Core 1 (MPC1) January 2010

Time: 1 hour 30 minutes

There are two main properties that we use when solving linear equations. Property #1: Additive Property of Equality

Brunswick School Department: Grades Essential Understandings

Rising 7th Grade Math. Pre-Algebra Summer Review Packet

Prep for the CSU ELM

THE FIVE GROUPS OF AXIOMS.

Archimedes and Continued Fractions* John G. Thompson University of Cambridge

Chapter 1/3 Rational Inequalities and Rates of Change

Fractals. Justin Stevens. Lecture 12. Justin Stevens Fractals (Lecture 12) 1 / 14

Item 8. Constructing the Square Area of Two Proving No Irrationals. 6 Total Pages

Maths Revision. Book 2. Name:.

Understand the difference between truncating and rounding. Calculate with roots, and with integer and fractional indices.

Integration Made Easy

Chapter 5 THE APPLICATION OF THE Z TRANSFORM. 5.3 Stability

Copyright 2012 UC Regents and ALEKS Corporation. ALEKS is a registered trademark of ALEKS Corporation. P. 1/6

Grades 7 & 8, Math Circles 17/18/19 October, Angles & Circles

Prep for College Algebra

Honors 213 / Math 300. Second Hour Exam. Name

Homework 2 from lecture 11 to lecture 20

Meet #4. Math League SCASD. Self-study Packet. Problem Categories for this Meet (in addition to topics of earlier meets):

Chapter 7 Sect. 2. A pythagorean triple is a set of three nonzero whole numbers a, b, and c, that satisfy the equation a 2 + b 2 = c 2.

How can you find decimal approximations of square roots that are not rational? ACTIVITY: Approximating Square Roots

Prep for College Algebra with Trigonometry

Mathematics Precalculus: Academic Unit 1: Polynomial and Transcendental Functions

FOUNDATION MATHS REVISION CHECKLIST (Grades 5 1)

Time: 1 hour 30 minutes

The Not-Formula Book for C1

Sequences and Series. Copyright Cengage Learning. All rights reserved.

THE BORSUK CONJECTURE. Saleem Watson California State University, Long Beach

Applied Mathematics 205. Unit 0: Overview of Scientific Computing. Lecturer: Dr. David Knezevic

Mathematics Precalculus: Academic Unit 7: Conics

Calculus: Area. Mathematics 15: Lecture 22. Dan Sloughter. Furman University. November 12, 2006

Holes in a function. Even though the function does not exist at that point, the limit can still obtain that value.

Grade 7/8 Math Circles Winter March 20/21/22 Types of Numbers

Solutions, Project on p-adic Numbers, Real Analysis I, Fall, 2010.

Section 7.2: Area of a Triangle

Unit 10 Geometry Circles. NAME Period

8.4. Systems of Equations in Three Variables. Identifying Solutions 2/20/2018. Example. Identifying Solutions. Solving Systems in Three Variables

Mathematics Higher Tier, June /1H (Paper 1, non calculator)

P1 Chapter 6 :: Circles

Vectors. Advanced Math Circle. October 18, 2018

Campus Academic Resource Program The Pythagorean Theorem

CS 6820 Fall 2014 Lectures, October 3-20, 2014

Chapter 2 Polynomial and Rational Functions

CIRCLES MODULE - 3 OBJECTIVES EXPECTED BACKGROUND KNOWLEDGE. Circles. Geometry. Notes

Exact Value of pi π (17-8 3)

Check boxes of Edited Copy of Sp Topics (was 217-pilot)

"Full Coverage": Pythagoras Theorem

The following document was developed by Learning Materials Production, OTEN, DET.

5. Introduction to limit

p and q are two different primes greater than 25. Pass on the least possible value of p + q.

MATH 117 LECTURE NOTES

Check boxes of Edited Copy of Sp Topics (was 261-pilot)

Transcription:

POLYTECHNIC UNIVERSITY Department of Computer and Information Science Another Algorithm for Computing π Attributable to Archimedes: Avoiding Cancellation Errors K. Ming Leung Abstract: We illustrate how cancellation error can limit the accuracy that can be achieved by an algorithm for computing π, and how that error can be avoided. Directory Table of Contents Begin Article Copyright c 2000 mleung@poly.edu Last Revision Date: February 21, 2004

In 250 B.C., the Greek mathematician Archimedes estimated the value of π by approximating the circumference of a circle by the perimeter of a regular polygon having 2n sides, where n = 2, 3,.... He knew that the approximation becomes better and better as n increases. In addition he was able to derive a recursion formula relating the perimeter of a regular polygon to the perimeter of another regular polygon having twice as many sides. One version of his method is described here. He considered a circle with diameter equal to 1, hence its circumference is π. Inside the circle he inscribed a square. The perimeter of the square is less than the circumference of the circle, and so it is a lower bound for π. Archimedes then considered an inscribed octagon, hexadecagon, etc., each time doubling the number of sides of the inscribed polygon, and producing better and better estimates for π. Let p n be the perimeter of the inscribed polygon with 2 n+1 sides, where n = 1, 2,.... Let the length of each side be denoted by s n. Then p 1 is the perimeter of the inscribed square, and from the geometry we know that s 1 = 1/ 2 and so p 1 = 4s 1 = 2 2. The perimeter of an 2

3 D A h s 2 s 1 /2 C 1/2 B

inscribed octagon p 2 is equal to 8s 2, and the perimeter of an inscribed hexadecagon p 3 is equal to 16s 2. In general we see that p n = 2 n+1 s n for n = 1, 2,.... (1) In the limit that n goes to infinity, the regular polygon becomes more and more like the circle and so we have p = π. So far the only perimeter we know is p 1 for the square. However Archimedes was able to obtain a recursive formula for the perimeters of the polygons. This allowed him to compute p 2 from p 1, and p 3 from p 2, and so on. To obtain such a recursive formula, let us see how to compute p 2 from p 1 using geometry only. Since triangle BCD is a right-angled triangle, Pythagoras theorem gives (1 ) 2 ( s1 ) 2. h = (2) 2 2 Actually it is clear that h = s 1 /2, however this geometric relation does not apply to other polygons with a different n. Since we want a recursive relation that applies to all n, that relation must not be used. The length AC is 1/2 and so the length AD is 1/2 h. Applying 4

5 Pythagoras theorem to triangle ABD one has (s1 ) ( ) 2 2 1 s 2 = + 2 2 h Substituting h from Eq. (2) into this equation, expanding and then simplifying the expression yields the result (1 ) 2 ( 1 s 2 = 2 s1 ) 2. 2 2 A careful inspection of the diagram reveals that such a relation holds between s 3 and s 2, etc. Thus in general one has the recursive relation (1 ) 2 ( 1 s n+1 = 2 sn ) 2, (3) 2 2 for n = 1, 2,.... We then obtain a recursive relation involving the

perimeters using Eq. (1). The result is p n+1 = 2 n+1 2 (1 1 6 ) ( pn ) 2 2 n+1. (4) Starting the iteration with p 1 = 2 2 and n = 1 we then get p 2, etc. One can easily write a program to implement that. The result computed using MATLAB (in double-precision) is shown below. Notice that because of the iterative nature of the algorithm, the program cannot be vectorized. The computed values for p 1 to p 31 are shown below. 1 2.82842712474619 2 3.06146745892072 3 3.12144515225805 4 3.13654849054594 5 3.14033115695474 6 3.14127725093276 7 3.14151380114415 8 3.14157294036788 9 3.14158772527996

7 10 3.14159142150464 11 3.14159234561108 12 3.14159257654500 13 3.14159263346325 14 3.14159265480759 15 3.14159264532122 16 3.14159260737572 17 3.14159291093967 18 3.14159412519519 19 3.14159655370482 20 3.14159655370482 21 3.14167426502176 22 3.14182968188920 23 3.14245127249413 24 3.14245127249413 25 3.16227766016838 26 3.16227766016838 27 3.46410161513775 28 4 29 0

30 0 31 0 Notice that the values at first increase (as expected) and seem to converge to the correct value for π until p 14. Notice that this value is slightly larger than π, but how can an inscribed polygon have a perimeter larger than the inscribing circle! After that the values decrease slightly (again this is rather alarming since we do not expect the perimeters to ever decrease with increasing n.) and gradually increase above π and drift further and further away from π. After the 28th term the computed perimeters all become zero. The reason for that is obvious from Eq. (4). Since p n is expected to be around 3, the factor p n /2 n+1, which is actually the length of each side of the polygon, decreases as we iterate. As soon as ( pn ) 2 ɛ mach 2 n+1, 2 we have ( pn ) 2 1 1, and so pn+1 2 n+1 0, due to cancellation in the above iteration formula in Eq. (4). 8

To estimate the value of n at which that happens, we set p n 3 in the equation and solve for n to get n = log 2 ( p n ( pn ) 2 ɛ = mach 2 n+1 2 ) ( ) 2 2 3 ɛ mach 1.1 10 16 29. This agrees with the results obtained from the program. Before we deal with the problem associated with cancellation, we want to address some issues related to numerical efficiency. First, notice from Eq. (4) that on the right-hand side p n is divided by 2 n+1 but p n+1 is obtained by multiplying a certain factor with 2 n+1. Clearly we can avoid all that if we perform the iteration on s n instead of p n, i.e. we iterate using equation Eq. (3). The cancellation problem is still present since as n increases the length of each segment of the polygon s n decreases. Second, notice that s n is being squared but to obtain s n+1 we need to take a square root. Clearly all that can be avoided if we work with, 9

a new variable t n = s 2 n. Changing to this new variable, we take the square of Eq. (3) to obtain t n+1 = 1 ( ) 1 1 tn. 2 We can iterate using this formula starting with t 1 = s 2 1 = 1/2. The perimeters are then given by p n = 2 n+1 s n = 2 n+1 t n. Avoiding the squaring and the taking of a square root actually saves about 40% of the computing time. Of course the cancellation problem is still not yet solved. Now we solve the cancellation problem. The key is to realize that the above equation looks almost like the quadratic formula. The cure is of course exactly the same. So we write t n+1 = 1 ( ) ( 1 + ) 1 t n 1 1 tn 2 1 + (5) 1 t n = 1 1 (1 t n ) 2 1 + = 1 t n 1 t n 2 1 +. (6) 1 t n 10

Now this recursive formula does not have any cancellation problem. When t n is small, the denominator simply becomes 2. Let us do one more thing to see if we can further improve the efficiency of the above algorithm by a simple re-scaling of the variable. Let us introduce a scaled variable g n by writing t n = αg n. One can see that Eq. (5) becomes g n g n+1 = 2 + 2. 1 α α g n Therefore if we let α = 1/4 so that 2 α = 1, the iterative relation for g n becomes g n g n+1 = 2 +. (7) 4 g n There is one fewer multiplication in this formula than the one in Eq. (5). Notice that t n = g n /4 = s 2 n, and p n = 2 n g n. Thus we start the iteration with g 1 = 4s 2 1 = 2. The computed values for p 1 to p 31 are shown below. 1 2.828427124746190 11

12 2 3.061467458920718 3 3.121445152258052 4 3.136548490545939 5 3.140331156954753 6 3.141277250932773 7 3.141513801144301 8 3.141572940367091 9 3.141587725277160 10 3.141591421511200 11 3.141592345570118 12 3.141592576584873 13 3.141592634338563 14 3.141592648776986 15 3.141592652386591 16 3.141592653288993 17 3.141592653514593 18 3.141592653570993 19 3.141592653585093 20 3.141592653588618

21 3.141592653589500 22 3.141592653589720 23 3.141592653589775 24 3.141592653589789 25 3.141592653589793 26 3.141592653589794 27 3.141592653589794 28 3.141592653589794 29 3.141592653589794 30 3.141592653589794 After 26 iterations, the result converges to a value as close to π as is possible using IEEE double-precision. The result does not change with further iterations. If one computes the relative error of this converged value, the result is eps. That means that we have obtained the most accurate result as we possibly can on this floating point system. 13