UNIVERSITY OF MASSACHUSETTS Dept

Slides:



Advertisements
Similar presentations
Roundoff and truncation errors
Advertisements

CENG536 Computer Engineering department Çankaya University.
Introduction to Scientific Computing ICE / ICE 508 Prof. Hyuckjae Lee KAIST- ICC
UNIVERSITY OF MASSACHUSETTS Dept
Copyright 2008 Koren ECE666/Koren Part.9b.1 Israel Koren Spring 2008 UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering Digital Computer.
CSE 246: Computer Arithmetic Algorithms and Hardware Design Instructor: Prof. Chung-Kuan Cheng Fall 2006 Lecture 11 Cordic, Log, Square, Exponential Functions.
UNIVERSITY OF MASSACHUSETTS Dept
UNIVERSITY OF MASSACHUSETTS Dept
Digital Kommunikationselektronik TNE027 Lecture 3 1 Multiply-Accumulator (MAC) Compute Sum of Product (SOP) Linear convolution y[n] = f[n]*x[n] = Σ f[k]
Copyright 2008 Koren ECE666/Koren Part.6a.1 Israel Koren Spring 2008 UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering Digital Computer.
1.1 Numbers Classifications of Numbers Natural numbers {1,2,3,…}
Computer Arithmetic Integers: signed / unsigned (can overflow) Fixed point (can overflow) Floating point (can overflow, underflow) (Boolean / Character)
Ch. 21. Square-rootingSlide 1 VI Function Evaluation Topics in This Part Chapter 21 Square-Rooting Methods Chapter 22 The CORDIC Algorithms Chapter 23.
Zeros of Polynomial Functions
© T Madas. Add zero and negative integers Add fractions and decimals which can be represented by fractions Add imaginary numbers Real Numbers ( ) Integers.
1. Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Rational Exponents, Radicals, and Complex Numbers CHAPTER 10.1Radical.
Preview of Calculus.
Algebra Review. Polynomial Manipulation Combine like terms, multiply, FOIL, factor, etc.
Real Numbers and Algebra
Copyright © Cengage Learning. All rights reserved. 0 Precalculus Review.
Sequences Informally, a sequence is a set of elements written in a row. – This concept is represented in CS using one- dimensional arrays The goal of mathematics.
Foundations Basics: Notation, and other things Algebraic manipulations Indices, Logs, Roots and Surds Binomial expansion Trigonometric functions Trigonometric.
Basic Concepts of Algebra
Rational Exponents, Radicals, and Complex Numbers
TMAT 103 Chapter 1 Fundamental Concepts. TMAT 103 §1.1 The Real Number System.
Department of Computer Systems Engineering, N-W.F.P. University of Engineering & Technology. DSP Presentation Computing Multiplication & division using.
MATH – High School Common Core Vs Tested Kansas Standards Please note: For informational purposes, all Common Core standards are listed, and the tested.
Introduction An exponent is a quantity that shows the number of times a given number is being multiplied by itself in an exponential expression. In other.
June 2007 Computer Arithmetic, Function EvaluationSlide 1 VI Function Evaluation Topics in This Part Chapter 21 Square-Rooting Methods Chapter 22 The CORDIC.
Natural Logarithms.
CORDIC Algorithm COordinate Rotation DIgital Computer Method for Elementary Function Evaluation (e.g., sin(z), cos(z), tan -1 (y)) Originally Used for.
More on Logarithmic Functions 9.6
The Rational Zero Theorem The Rational Zero Theorem gives a list of possible rational zeros of a polynomial function. Equivalently, the theorem gives all.
Copyright 2008 Koren ECE666/Koren Part.7b.1 Israel Koren Spring 2008 UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering Digital Computer.
CORDIC Algorithm COordinate Rotation DIgital Computer
Module 2.2 Errors 03/08/2011. Sources of errors Data errors Modeling Implementation errors Absolute and relative errors Round off errors Overflow and.
NUMERICAL ANALYSIS I. Introduction Numerical analysis is concerned with the process by which mathematical problems are solved by the operations.
1.2 Mathematical Models: A Catalog of Essential Functions
Trigonometric Identities
UNIVERSITY OF MASSACHUSETTS Dept
UNIVERSITY OF MASSACHUSETTS Dept
Zeros of Polynomial Functions
Taylor series in numerical computations (review)
UNIVERSITY OF MASSACHUSETTS Dept
CSE 575 Computer Arithmetic Spring 2003 Mary Jane Irwin (www. cse. psu
The Inverse Z-Transform
Copyright © Cengage Learning. All rights reserved.
Class Notes 9: Power Series (1/3)
Unconventional Fixed-Radix Number Systems
Clicker Question 1 What is the degree 2 (i.e., quadratic) Taylor polynomial for f (x) = 1 / (x + 1) centered at 0? A. 1 + x – x 2 / 2 B. 1  x C. 1 
UNIVERSITY OF MASSACHUSETTS Dept
1. What is the difference between simplifying an expression and solving an expression? 2. -(3x+5)-4x x-7=13 4. x/2 +4 =16 5. Write the following.
Rational Exponents, Radicals, and Complex Numbers
Copyright © Cengage Learning. All rights reserved.
UNIVERSITY OF MASSACHUSETTS Dept
1 Preliminaries Precalculus Review I Precalculus Review II
UNIVERSITY OF MASSACHUSETTS Dept
UNIVERSITY OF MASSACHUSETTS Dept
UNIVERSITY OF MASSACHUSETTS Dept
UNIVERSITY OF MASSACHUSETTS Dept
UNIVERSITY OF MASSACHUSETTS Dept
UNIVERSITY OF MASSACHUSETTS Dept
Introduction An exponent is a quantity that shows the number of times a given number is being multiplied by itself in an exponential expression. In other.
UNIVERSITY OF MASSACHUSETTS Dept
Division Rules for Exponents
CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4: KFUPM CISE301_Topic1.
THE LAPLACE TRANSFORM LEARNING GOALS Definition
1.2 Essential Functions.
Lecture 9: Shift, Mult, Div Fixed & Floating Point
Presentation transcript:

UNIVERSITY OF MASSACHUSETTS Dept UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering Digital Computer Arithmetic ECE 666 Part 9a Evaluation of Elementary Functions - I Israel Koren

Efficient Algorithms for Evaluating Elementary Functions Hardware algorithms which are accurate and fast compared to software algorithms Useful for scientific hand-held calculators and numerical processors Examples: e , ln x, sin x, cos x Straightforward method: look-up table x,y of length n bits To evaluate y=F(x) - ROM of size 2  n Prohibitive for n  20 - size  16 M Second method: Taylor series expansion x n

Taylor Series Expansion Example: Converges rapidly when x is a fraction Converges slowly for x close to 1 Hardware implementation complex - separate logical networks for different functions Algorithms requiring a smaller number of computational steps for same precision exist Most commonly used methods: based on either polynomial or rational approximations

Example - Exponential Function Exponent divided into integer part I and fractional part f : x log 2 e = I+f Calculation of 2 in either fixed-point or floating-point - straightforward Calculation of 2 - rational approximation - ratio between 2 polynomials Example: Two degree-5 polynomials ai,bi (i=0,1,...,5) known constants - 10 multiplications, 10 additions, 1 division Approximations with smaller execution time exist I f

Alternative Methods for Evaluating Elementary Functions Similar to division-by-convergence 2 (or more) recursive formulas - one is forced to a constant while other yields result Example: Evaluating y=e for some fraction x0 bi's selection - x0,x1,…,xm approach 0 m - number of iterations needed to ensure xm=0 Linear convergence - m linear function of number of bits n x

Exponential Function xm=0  In particular: Similar to division-by-convergence - product yi e remains constant for all bi's Need a simple way to select bi's to ensure convergence of xi+1 to 0 Also, multiplication by bi should be simple and fast Use the form bi =(1+si 2 ), where si  {-1,0,1} Multiplication reduced to shift and add The term ln bi=ln (1+si2 ) can be positive or negative Must ensure convergence of positive or negative xi+1 to 0 xi -i -i

Precalculated ln(12 ) s={s0,s1,…,sm-1} so that xm=0 or -i Precalculated ln(12 ) Online calculation too slow Stored in a look-up table (ROM of size 2nn) (i) xi+1=xi -ln (1+si 2 ) (ii) yi+1=yi (1+si 2 ) To calculate e - find the vector s={s0,s1,…,sm-1} so that xm=0 or If sl restricted to {-1,0,1} - smallest/largest x0 correspond to all sl =-1 / sl =1 For every x0 in interval there exists vector s guaranteeing convergence to 0 -i -i x

Domain of x0 For large m (20) bounds converge: -1.24  x0  1.56 If x0 positive fraction - simple scheme for selecting si - one-sided selection rule: si  {0,1} Similar to quotient-bit selection in restoring division In step i+1 form difference D=xi-ln (1+2 ) If D positive or zero - set si=1 and xi+1=D If D negative - set si=0 and xi+1=xi Analyze subtract in xi+1 - examine Taylor series: At step i can cancel bit of weight 2 by subtracting ln (1+si 2 ) from xi Up to n steps needed to ensure convergence of n-bit fraction to 0 - convergence linear and m=n -i -i -i

Modify Selection Rule Improves performance of algorithm If bit in ith position =1 - select si=1 and calculate xi+1=xi-ln (1+si 2 ) If 0 - select si=0, go to next step without subtract - capability of skipping over 0’s More complex selection rules can be used as well -i Example ln(12 ) for i=0,1,2,…,10 10 fractional bits rounded-to-nearest ln(12 )=2 for i 6 -i

Example: e in 10-bit precision 0.25 Example: e in 10-bit precision One-sided selection rule x0=0.2510= 0.01000 0000002 x0<ln (1+2 )  s0=s1=0  x2=x0 Select s2=1 and obtain x3=x2-0.00111 00100 = 0.00000 11100 Set s3=s4=0  s5=0 , s6=s7=s8=1, and s9=s10=0 Yielding x11=0 -1

Example - Cont. -2 -6 In parallel :y11=y0(1+2 )(1+2 )(1+2 )(1+2 ) yielding y11=1.01001 000112 = 1.2841810 Exact value (to 5 five decimal digits)=1.2840310 Approximation error =0.158·2 If si=-1 allowed - selected values (s0,…,s10)=0,1,-1,1,0,0,0,1,1,1,1 x11=0 ; y11=1.01001 000102 Approximation error=0.842·2 -7 -8 -10 -10

Extending Argument of Exponential Function x = x log 2 e ln 2 x log 2 e = I + f (I - integer ; 0  f < 1) Calculate y=e =e =e =2 e Set x0=f ln 2  0  x0 < ln 2 =0.693 2 is easily dealt with Incorporation into exponent part of floating-point number Through a shift operation for fixed-point arithmetic x (I+f)ln2 I ln2+f ln2 I f ln2 I

The Logarithm Function x Calculating e - continued summation of terms ln (1+si 2 ) to force convergence of xi to 0 - additive normalization Multiplicative normalization - xi is forced to 1 (or some other nonzero constant) by continued multiplication with precalculated factors bi selected so that After m steps (multiplicative inverse) -i

Domain of Algorithm Multiplication factor bi: 1+si 2 for si{-1,0,1} For large m: Domain for x0: 0.21  x0  3.45 Positive normalized fractions are in domain If argument not normalized floating-point number - rewrite as x=x0·2 ; 0.5  x0<1 ln x=ln x0+Ex ln 2 -i Ex

One Sided Selection Rule si{0,1} has i leading 1's  xi+1=xibi=xi+xisi2 (with si=1) has (i+1) leading 1's In yi+1 formula: g(bl)=ln(bl)  xi+1 approaches 1  yi+1 converges to -i

Calculating Natural Logarithm Same table of ln (1+si 2 ) needed here Base e can be replaced by any other base Base 10 - used in hand-held calculators Finally: yi+1 + ln xi+1 = (yi-ln bi)+(ln xi+ln bi)= yi+ln xi is a constant xi+1 approaches 1  yi+1 approaches y0+ln x0

Example - ln (0.50) in 10-bit precision y11=-0.10110 001012=-0.6923810 Exact result (in 5 decimal digits) = -0.69315 Approximation error = 0.783·2 -10

Operation in (ii) - Multiplication k g(bi)=bi (k - any real number): Example: k=1 : yi+1  y0 / x0 - divide operation k=1/2 : yi+1  y0 /  x0 - reciprocal of square root y0=x0 : yi+1   x0 - square root calculated g(bi)= bi ; for simplicity g(bi)=(1+si 2 ) Multiplication by bi more complex - not efficient for square root extraction -i

Trigonometric Functions jx E = cos x + j sin x where j= -1 For exponential function: For trigonometric functions select bi=(1+jsi 2 ) This complex number can be written as where Polar form of complex numbers -i

Domain for Trigonometric Functions si's selected so that x0,x1,…,xm  0  Denoting: Then: Convergence domain for m  20 : (including 0  x0 /2 = 1.57) 

Equations for x and y xi's real numbers - yi's complex numbers yi=Zi + jWi (Zi - real part ; Wi - imaginary part) Initial value y0 can be complex - Z0+jW0 Setting W0=0, Z0=y0 - desired values obtained: Volder developed differently using rotations in polar system - CORDIC (COordinated Rotation DIgital Computer)

Selection Rule for Si tan (si 2 )= si tan (2 ) For si {-1,0,1} n constants stored in ROM For si {-1,0,1} K not constant - depends on s which depends on x0 Also, full-length comparison between xi & tan (2 ) If si restricted to {-1,1} - Constant that can be precalculated For m > 16, K=1.6468 - set y0=1/K Zm =cos x0 ; Wm = sin x0 -1 -1 -i -1 -i

Selection Rule - Modified Selection rule becomes Similar to rule for nonrestoring division Examine convergence rate of xi+1 to 0 - Taylor series expansion of tan (si2 ) (in radians): Linear convergence For i>n/3, all terms except first negligible - reduce size of ROM -1 -i Table for 10 fractional bits: arctan (2 )= 2 for i4 -i

Example: sin(/4) in 10-bit precision /4=0.78539810=0.11001001002 Initially Z0=1/K=0.10011011102 (=0.607410) Set si=sign(xi) Final results: Z11=0.10110100112 and W11=0.10110101002 “exact” results in 10-bit precision: both 0.10110101002= 0.707110 Approximation error not larger than 2 -10