CORDIC: How Hand Calculators Calculate



Similar documents
Thnkwell s Homeschool Precalculus Course Lesson Plan: 36 weeks

Sequence of Mathematics Courses

With the Tan function, you can calculate the angle of a triangle with one corner of 90 degrees, when the smallest sides of the triangle are given:

PURSUITS IN MATHEMATICS often produce elementary functions as solutions that need to be

Investigation of Chebyshev Polynomials

Background Knowledge

Precalculus REVERSE CORRELATION. Content Expectations for. Precalculus. Michigan CONTENT EXPECTATIONS FOR PRECALCULUS CHAPTER/LESSON TITLES

PRE-CALCULUS GRADE 12

Extra Credit Assignment Lesson plan. The following assignment is optional and can be completed to receive up to 5 points on a previously taken exam.

REVIEW EXERCISES DAVID J LOWRY

South Carolina College- and Career-Ready (SCCCR) Pre-Calculus

Algebra. Exponents. Absolute Value. Simplify each of the following as much as possible. 2x y x + y y. xxx 3. x x x xx x. 1. Evaluate 5 and 123

Dear Accelerated Pre-Calculus Student:

Chapter 7 Outline Math 236 Spring 2001

Prentice Hall Mathematics: Algebra Correlated to: Utah Core Curriculum for Math, Intermediate Algebra (Secondary)

Georgia Department of Education Kathy Cox, State Superintendent of Schools 7/19/2005 All Rights Reserved 1

MATH BOOK OF PROBLEMS SERIES. New from Pearson Custom Publishing!

MATH 2 Course Syllabus Spring Semester 2007 Instructor: Brian Rodas

Core Maths C2. Revision Notes

School of Mathematics, Computer Science and Engineering. Mathematics* Associate in Arts Degree COURSES, PROGRAMS AND MAJORS

SEMESTER PLANS FOR MATH COURSES, FOR MAJORS OUTSIDE MATH.

COURSE OUTLINE FOR MATH 115. Instructor: Rich Tschritter, Ewing 268. Text: Precalculus, Sixth Edition, by Larson & Hostetler CHAPTER A: APPENDIX A

Math Placement Test Study Guide. 2. The test consists entirely of multiple choice questions, each with five choices.

Evaluating trigonometric functions

Advanced Math Study Guide

Right Triangles 4 A = 144 A = A = 64

Precalculus Orientation and FAQ

MATHEMATICS (MATH) 3. Provides experiences that enable graduates to find employment in sciencerelated

Big Ideas in Mathematics

Appendix 3 IB Diploma Programme Course Outlines

Math 1050 Khan Academy Extra Credit Algebra Assignment

SOLVING TRIGONOMETRIC INEQUALITIES (CONCEPT, METHODS, AND STEPS) By Nghi H. Nguyen

Algebra and Geometry Review (61 topics, no due date)

Lies My Calculator and Computer Told Me

Week 13 Trigonometric Form of Complex Numbers

X On record with the USOE.

COURSE SYLLABUS Pre-Calculus A/B Last Modified: April 2015

Higher Education Math Placement

Birmingham City Schools

Techniques of Integration

(1.) The air speed of an airplane is 380 km/hr at a bearing of. Find the ground speed of the airplane as well as its

HIGH SCHOOL: GEOMETRY (Page 1 of 4)

Science, Technology, Engineering and Math

Trigonometric Functions and Equations

Estimated Pre Calculus Pacing Timeline

Introduction Assignment

KEANSBURG SCHOOL DISTRICT KEANSBURG HIGH SCHOOL Mathematics Department. HSPA 10 Curriculum. September 2007

Math 1280/1300, Pre-Calculus

Please start the slide show from the beginning to use links. Click here for active links to various courses

Graphing Trigonometric Skills

Curriculum Map by Block Geometry Mapping for Math Block Testing August 20 to August 24 Review concepts from previous grades.

Essential Mathematics for Computer Graphics fast

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

Differentiation and Integration

Trigonometric Functions and Triangles

Mathematics INDIVIDUAL PROGRAM INFORMATION Macomb1 ( )

PCHS ALGEBRA PLACEMENT TEST

1 TRIGONOMETRY. 1.0 Introduction. 1.1 Sum and product formulae. Objectives

The Mathematics Diagnostic Test

A GENERAL CURRICULUM IN MATHEMATICS FOR COLLEGES W. L. DUREN, JR., Chairmnan, CUPM 1. A report to the Association. The Committee on the Undergraduate

Trigonometry Hard Problems

Diablo Valley College Catalog

Course Syllabus for Math 205 College Math I, Online Summer 2010 This is an online course accessible at: bb.wit.edu.

Mathematics (MAT) MAT 061 Basic Euclidean Geometry 3 Hours. MAT 051 Pre-Algebra 4 Hours

Content. Chapter 4 Functions Basic concepts on real functions 62. Credits 11

Academic Support Services Supplemental Learning Materials - Math

Tips for Solving Mathematical Problems

FACTORING ANGLE EQUATIONS:

Lectures 5-6: Taylor Series

Math Placement Test Practice Problems

Mathematics Pre-Test Sample Questions A. { 11, 7} B. { 7,0,7} C. { 7, 7} D. { 11, 11}

Algebra I Credit Recovery

Notes on Factoring. MA 206 Kurt Bryan

04 Mathematics CO-SG-FLD Program for Licensing Assessments for Colorado Educators

Vector Math Computer Graphics Scott D. Anderson

ALGEBRA 2/TRIGONOMETRY

5.3 SOLVING TRIGONOMETRIC EQUATIONS. Copyright Cengage Learning. All rights reserved.

Trigonometry LESSON ONE - Degrees and Radians Lesson Notes

Entry Level College Mathematics: Algebra or Modeling

Semester 2, Unit 4: Activity 21

PHILOSOPHY OF THE MATHEMATICS DEPARTMENT

LIES MY CALCULATOR AND COMPUTER TOLD ME

During the three years which I spent at

Approximating functions by Taylor Polynomials.

G.A. Pavliotis. Department of Mathematics. Imperial College London

PYTHAGOREAN TRIPLES KEITH CONRAD

The Fourth International DERIVE-TI92/89 Conference Liverpool, U.K., July Derive 5: The Easiest... Just Got Better!

SOLVING TRIGONOMETRIC EQUATIONS

Taylor and Maclaurin Series

Parallel and Perpendicular. We show a small box in one of the angles to show that the lines are perpendicular.

Figure 1.1 Vector A and Vector F

FX 260 Training guide. FX 260 Solar Scientific Calculator Overhead OH 260. Applicable activities

Polynomial and Synthetic Division. Long Division of Polynomials. Example 1. 6x 2 7x 2 x 2) 19x 2 16x 4 6x3 12x 2 7x 2 16x 7x 2 14x. 2x 4.

Solutions to Exercises, Section 5.1

Using Excel to Execute Trigonometric Functions

The Factor Theorem and a corollary of the Fundamental Theorem of Algebra

Pre-Calculus Semester 1 Course Syllabus

MATH. ALGEBRA I HONORS 9 th Grade ALGEBRA I HONORS

SOME EXCEL FORMULAS AND FUNCTIONS

7 Gaussian Elimination and LU Factorization

Transcription:

Integre Technical Publishing Co., Inc. College Mathematics Journal 40: December 7, 008 :49 p.m. sultan.tex page 87 CORDIC: How Hand Calculators Calculate Alan Sultan Alan Sultan is a professor of mathematics at Queens College of the City University of New York. He is the author of two books and several research articles, and is currently heavily involved in the math education of prospective high school math teachers. He enjoys singing bass in the Oratorio Society of Queens, and loves to see how the math we teach can be applied. Almost every calculus teacher I ask answers the question, How do calculators compute sines and cosines? with the words, Taylor Polynomials. It comes as quite a surprise to most that, though it is reasonable to use Taylor polynomials, it is really a method known as CORDIC that is used to compute these and other special functions. CORDIC was discovered by Jack Volder in 959 while working for the Convair corporation and was developed to replace the analog resolver in the B-58 bomber s navigation computer. What was needed was a program that could compute trigonometric functions in real time without the use of much hardware. CORDIC, an acronym for COordinate Rotation DIgital Computer, was the solution. CORDIC is fast; much faster than Taylor series for the low level hardware used on a calculator, though when you first see it, it is hard to believe. What is nice about CORDIC is that it connects mathematics usually learned in high school with computer hardware, making it especially interesting to students who wonder where the math they learn might be used. The method can be adapted to compute inverse trigonometric functions, hyperbolic functions, logarithms, exponentials, and can even be modified to do multiplication and division! (See [] or[3] for more on this.) This amazing method is a genuinely key part of calculator technology and knowledge of it can benefit both teacher and student. We present CORDIC in its original binary form even though now it uses binarycoded decimal (BCD). What we present is the heart of the algorithm, focusing on a special case the computation of sines and cosines. (For the history of computing transcendental functions see [4]. For its actual implementation in hardware, see [].) The basics What makes CORDIC fast are two facts: () When we take a binary number and multiply it by n, we shift the binary point n places to the right and when we divide by n we shift the binary point n places to the left. () The operations on a computer that are cheapest and fastest to perform are (A) addition and subtraction, (B) comparing numbers to see which is larger or smaller, (C) storing and retrieving numbers from memory, and (D) shifting the binary point. Addition and subtraction are very fast, but not multiplication or division. The machine does compute multiplications and divisions by powers of very quickly however, by just shifting the binary point. CORDIC exploits this, and thus uses only operations (A) (D) to evaluate sines and cosines. The heart of the algorithm is a series of cleverly performed rotations. VOL. 40, NO., MARCH 009 THE COLLEGE MATHEMATICS JOURNAL 87

Integre Technical Publishing Co., Inc. College Mathematics Journal 40: December 7, 008 :49 p.m. sultan.tex page 88 Rotations In high school, students learn to rotate a point P = (x 0, y 0 ) through an angle of θ degrees. The rotated point has coordinates P = (x, y) where x = x 0 cos θ y 0 sin θ, y = x 0 sin θ + y 0 cos θ, which can be written in matrix form as P = R θ P 0 where cos θ sin θ R θ =. () sin θ cos θ Now suppose we rotate the point (, 0) by θ radians. Then the rotated point, P = (x, y) has coordinates (cos θ,sin θ). However, we can t use () to rotate by the angle θ unless we already know sin θ and cos θ. But finding them is our goal! So what are we to do? CORDIC breaks down rotation by θ radians, into rotations by smaller angles θ 0,θ, θ,θ 3,... These are cleverly chosen so that these rotations can be calculated using angles hardwired into the computer. It then generates points P, P, P 3 etc. on the unit circle which approach the point (cos θ,sin θ). (See Figure.) P (cos θ, sin θ) P 3 P P 0 = (, 0) Figure. Hard-wiring the machine Which angles does CORDIC hard-wire? They are the angles whose tangents are of the form, where n = 0,,, 3,... Let n us list these θ i s: θ 0 = tan () = π 4.785398, θ = tan (/).463648, θ = tan (/4).44979 4, 88 c THE MATHEMATICAL ASSOCIATION OF AMERICA

Integre Technical Publishing Co., Inc. College Mathematics Journal 40: December 7, 008 :49 p.m. sultan.tex page 89 θ 3 = tan (/8).4355 8, θ 4 = tan (/6).0649 6. We observe that when θ is small, tan θ θ. Thus, we don t even need to store all the values θ i, since eventually tan θ and θ are the same for practical purposes. A numerical example We go through an example, to illustrate how CORDIC works. We set as our goal the angle θ = radian, and try to build it from the θ i s we have chosen. We start with z 0 = θ 0 =.785398. (The letters z i will keep a running total of our rotation.) This is too small, so the algorithm now adds θ attempting to bring the total up to radian. We get z = θ 0 + θ.785398 +.463648 =.49046. This is more than radian, so the algorithm backs up. It subtracts θ,toget z = θ 0 + θ θ.49046.44979 =.004067. This is still more than, so the algorithm backs up again getting z 3 = θ 0 + θ θ θ 3.004067.4355 = 0.8797. This is less than, so we add θ 4 =.0649, to get z 4 = θ 0 + θ θ θ 3 + θ 4.879773 +.0649 = 0.949, and so on. With 40 terms, which is what many machines use, z 39 = θ 0 + θ θ θ 3 + θ 4 + θ 5 + θ 6 + θ 7 + θ 8 + θ 39. () (Notice the θ 39.) At each step, the machine checks to see if the running total z i is more or less than the angle of radian, and either adds or subtracts the next θ accordingly. Simultaneously, the algorithm performs the corresponding rotations. So, following () we initially rotate (, 0) by θ 0,thenbyθ, then rotate by θ, then rotate by θ 3 andsoon. After 40 rotations, we get P 40 = R θ39 R θ R θ R θ0 P 0 cos( θ39 ) sin( θ = 39 ) cos θ sin θ cos θ0 sin θ 0. sin( θ 39 ) cos( θ 39 ) sin θ cos θ sin θ 0 cos θ 0 0 (3) Forty rotations may seem like a lot of work. We will see. VOL. 40, NO., MARCH 009 THE COLLEGE MATHEMATICS JOURNAL 89

Integre Technical Publishing Co., Inc. College Mathematics Journal 40: December 7, 008 :49 p.m. sultan.tex page 90 How good is our approximation? For any iterative procedure to be useful, we must have an idea of how accurate our answers are. The following theorem tells us. Theorem. Using the method described in this paper, after n + iterations, the approximations obtained for sin θ and cos θ are within of the true values, provided π θ π. Thus, the CORDIC Method converges to (cos n θ,sin θ). A detailed proof is given in [5] and uses a combination of induction, trig identities and the Mean Value Theorem. If the inequality π θ π is false, then we subtract multiples of π to yield an angle between 0 and π and then, using trig identities, replace θ with an angle between π and π. Theorem guarantees that the error we make in computing sin and cos by computing P 40 is not more than =.890 0. Thus, we have at least 0 places of decimal accuracy! 39 Taming equation (3) Equation (3) certainly looks daunting. You must be thinking This method is far more difficult than using Taylor polynomials. And so it is, unless we can multiply those matrices rapidly. In this section we show how to accomplish this. Each matrix in the above product (3) is of the form cos θi sin θ R θi = i sin θ i cos θ i which can be rewritten as tan θi R θi = cos θ i, (4) tan θ i and now we see how the tangent function comes into play. Since by design, tan θ i =, (4) becomes i R θi = cos θ i i. (5) i (Note: R θi, is of the same form with off diagonal entries switched.) Finally, since for π θ π,cosθ = =, (5) can be written as +( i ) +tan θ Now substituting into (3), we get R θi = i + ( i ) ( P 40 = + ( 39 ) ( 0 + (0 ) 0 ) )( 0). i + ( ) 90 c THE MATHEMATICAL ASSOCIATION OF AMERICA

Integre Technical Publishing Co., Inc. College Mathematics Journal 40: December 7, 008 :49 p.m. sultan.tex page 9 Pulling the constants, where K = P 40 = K to the front of this matrix product, we get that +( i ) ( )( 0 0) 0 + ( 39 ) + ( 38 ) + ( ) + (0 ), and we are on our way. K is a constant! Once we compute it, we can, and do, hard-wire it into the machine. It turns out that K.6075935. So finally (3) becomes P 40.6075935 ( )( 0 0) 0 Observe that all entries in (6) are hard-wired into the machine. No computation is needed to obtain them. Then, as we shall see, multiplying the matrices is very fast. (6) The speed with which the matrices are multiplied We observe that ( a n = b) n a b n. (7) a + b n Now b is computed by shifting the binary point in b. So our first entry in the product, n a b, uses a shift and a subtraction (two fast operations). Our second entry, a + n b, uses a shift and an addition (another fast operations). Thus, when we multiply n the two matrices from (7) we do 4 very fast operations. We then store the two results for a total of 6 operations, all of which are among the computer s fastest. Now consider all of the operations in (6). We must execute 40 matrix multiplications, each of which takes only 6 fast operations. The bottom line: this requires only 40 6 = 40 fast operations. (After we multiply all of the matrices in (6) we must not forget to multiply our final result by K =.6075935.) If, for the example, θ = radian, we multiply just matrices, and then multiply by K, we obtain (cos, sin ) (0.5397, 0.8485). According to Theorem () we should be within 0 =.00097656 of the correct results, and in fact, cos 0.5403 and sin 0.8447. (8) Of course, if we multiply all 40 matrices together and then multiply by K, the approximations we get for sin θ and cos θ will be accurate to more than 0 places, as we have pointed out. VOL. 40, NO., MARCH 009 THE COLLEGE MATHEMATICS JOURNAL 9

Integre Technical Publishing Co., Inc. College Mathematics Journal 40: December 7, 008 :49 p.m. sultan.tex page 9 Final remarks CORDIC is a robust and practical algorithm, preferred by calculator manufacturers because it requires relatively low level electronics. It is perfect for calculators, and good for the company s bottom line. What is amazing about CORDIC in addition, is that by just slightly modifying the method, we get all of the usual calculator functions. The details of this are technical and some are even proprietary. But one cannot help but be astounded by the fact that essentially one algorithm, and its variations, can be used to compute sines, cosines, tangents, inverse trig functions, hyperbolic functions, logarithms, exponentials, roots even do multiplications and divisions. It is just mindboggling! References. R. Andraka, A survey of CORDIC algorithms for FPGA based computers, FPGA 98, Proc. of the 998 ACM/SIGDA Sixth International Symposium on Field Programmable Gate Arrays, Monterey CA, 998, 9 00.. N. Eklund, CORDIC: Elementary function computation using recursive sequences, this JOURNAL 3 (00) 330 333. 3., CORDIC: Elementary function computation using recursive sequences, Electronic Proceeding of the ICTCM (998) C07. 4. C. W. Schelin, Calculator function approximation, Amer. Math. Monthly 90 (983) 37 35. 5. J. Underwood and B. Edwards, How do calculators calculate trigonometric functions? Educational Resources Information Center (ERIC) document ED4659. Also available at http://www.math.ufl.edu/~haven/ papers/paper.pdf. On Achieving the Petaflop (Sung to the tune of the Ode to Joy in Beethoven s Choral Symphony) Hectic, hectic apoplectic Life in the Computer Age Things start fast Then go yet faster Soon we ll reach the final stage Mega-tasks in nano-seconds Glad we ve achieved the Petaflop If we are forced to go yet faster Things will come to a Dead Stop David Seppala-Holtzman (dholtzman@sjcny.edu) [David Seppala-Holtzman is a professor of mathematics at St. Joseph s College where he has taught for the past 7 years. His mathematical interests are many and varied, his love for the subject, in general, being the only constant.] 9 c THE MATHEMATICAL ASSOCIATION OF AMERICA