CS321. Introduction to Numerical Methods



Similar documents
Measures of Error: for exact x and approximation x Absolute error e = x x. Relative error r = (x x )/x.

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

CSI 333 Lecture 1 Number Systems

CHAPTER 5 Round-off errors

2 Number Systems. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

Computer Science 281 Binary and Hexadecimal Review

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Numerical Matrix Analysis

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Useful Number Systems

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

NUMBER SYSTEMS. William Stallings

The string of digits in the binary number system represents the quantity

Systems I: Computer Organization and Architecture

Lecture 11: Number Systems

Number Systems and Radix Conversion

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

Correctly Rounded Floating-point Binary-to-Decimal and Decimal-to-Binary Conversion Routines in Standard ML. By Prashanth Tilleti

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Numerical Analysis I

Review of Scientific Notation and Significant Figures

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)

NUMBER SYSTEMS. 1.1 Introduction

This 3-digit ASCII string could also be calculated as n = (Data[2]-0x30) +10*((Data[1]-0x30)+10*(Data[0]-0x30));

26 Integers: Multiplication, Division, and Order

Figure 1. A typical Laboratory Thermometer graduated in C.

COMPSCI 210. Binary Fractions. Agenda & Reading

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

RN-coding of Numbers: New Insights and Some Applications

Chapter 2. Binary Values and Number Systems

Section 1.4 Place Value Systems of Numeration in Other Bases

Chapter 4 -- Decimals

=

Binary Adders: Half Adders and Full Adders

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

Number Representation

Binary, Hexadecimal, Octal, and BCD Numbers

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

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

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

Rational Exponents. Squaring both sides of the equation yields. and to be consistent, we must have

How do you compare numbers? On a number line, larger numbers are to the right and smaller numbers are to the left.

Irrational Numbers. A. Rational Numbers 1. Before we discuss irrational numbers, it would probably be a good idea to define rational numbers.

Base Conversion written by Cathy Saxton

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

Zuse's Z3 Square Root Algorithm Talk given at Fall meeting of the Ohio Section of the MAA October College of Wooster

Session 7 Fractions and Decimals

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

Lecture 2. Binary and Hexadecimal Numbers

The BBP Algorithm for Pi

MATH-0910 Review Concepts (Haugen)

Positional Numbering System

Session 29 Scientific Notation and Laws of Exponents. If you have ever taken a Chemistry class, you may have encountered the following numbers:

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

Trigonometric Functions and Triangles

Vocabulary Words and Definitions for Algebra

Section 1.1 Real Numbers

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

Continued Fractions and the Euclidean Algorithm

Chapter 7 Lab - Decimal, Binary, Octal, Hexadecimal Numbering Systems

Chapter 5. Binary, octal and hexadecimal numbers

Chapter 1. Binary, octal and hexadecimal numbers

Math Workshop October 2010 Fractions and Repeating Decimals

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

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.

What Every Computer Scientist Should Know About Floating-Point Arithmetic

CPEN Digital Logic Design Binary Systems

Chapter 3. if 2 a i then location: = i. Page 40

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

Zeros of a Polynomial Function

RN-Codings: New Insights and Some Applications

Zeros of Polynomial Functions

5.1 Radical Notation and Rational Exponents

JUST THE MATHS UNIT NUMBER 1.8. ALGEBRA 8 (Polynomials) A.J.Hobson

Numbering Systems. InThisAppendix...

MEP Y9 Practice Book A

Chapter 1: Digital Systems and Binary Numbers

Undergraduate Notes in Mathematics. Arkansas Tech University Department of Mathematics

Math 115 Spring 2011 Written Homework 5 Solutions

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

THE BINARY NUMBER SYSTEM

Addition Methods. Methods Jottings Expanded Compact Examples = 15

Math Circle Beginners Group October 18, 2015

Unsigned Conversions from Decimal or to Decimal and other Number Systems

Lies My Calculator and Computer Told Me

8 Square matrices continued: Determinants

1. The Fly In The Ointment

Arithmetic in MIPS. Objectives. Instruction. Integer arithmetic. After completing this lab you will:

Differentiation and Integration

6.2 Permutations continued

Math 319 Problem Set #3 Solution 21 February 2002

Lecture 8: Binary Multiplication & Division

FAST INVERSE SQUARE ROOT

Principles of Scientific Computing. David Bindel and Jonathan Goodman

THE NUMBER OF REPRESENTATIONS OF n OF THE FORM n = x 2 2 y, x > 0, y 0

Transcription:

CS3 Introduction to Numerical Methods Lecture Number Representations and Errors Professor Jun Zhang Department of Computer Science University of Kentucky Lexington, KY 40506-0633 August 7, 05

Number in Different Bases Humans use number base for reasons of the number of fingers Computers use number base for reasons of on-off switch A number based on 8 can be used to facilitate conversion between the base and the base Base Expansion: 763 0 The general formula for a base integer is 0 6 3 300 7 6000 4 3 70000 a n a n a a a 0 a 0 0 a a a n n a n n

Binary Numbers 3

Number System 4

Definitions There are some definitions for representing a real number in base and in base 5

Nonintegers and Fractions An example of a fractional number 0.63 6 6 3 0 4 00 3 000 3 The general formula for a decimal fraction 3 0. bbb3 b b b3 Decimal fractional numbers can be repeating or nonrepeating (rational or irrational numbers) ( a a a a. b b b ) n n 0 n k ak k 0 k b k 3 k 6

Number Conversion 7

Base β Numbers Convert an integer number from base 8 system to base system (763 General formula ) 8 8 8 0 3 8 8(3 8(6 8 3 (3 499 5 (0.9746 ) 6 8 8(6 (8(7))) 8(7 ))) 7 8 (3994 ) Convert a fractional number between 0 and (0.763 ) 7 8 6 8 3 8 ( a n a n k ak β k 0 k n aa0. bb b3 ) β b k β k 3 3 Convert integer and fractional parts separately 8

From system α to system β with α < β Conversion between Systems express (N) α in nested form using powers of α replace each digit by corresponding base β number carry out indicated arithmetic in base β Two examples were given in the previous page Note that one needs to convert the integer and the fractional parts separately The method is in theory can be used to convert a number between any two bases. But the third step is not easy for humans if the base is not 9

Division Algorithm Use remainder-quotient-split method to convert an integer, best if α > β ( N ) α ( c c c 0 m m β ( c c c 0 β ( c ) β β ( c m ) )). Divide the representation by β;. Take the remainder as the next digit in the base β representation; 3. Repeat the procedure on the quotient. This procedure is easier to carry out by hand Note that the first digit obtained is the one closest to the radix point

Repeated Division To convert a base integer number to a base β< number, we can use repeated division algorithm 576 3 40 / 8 5 / 8 So we have / 8 0 5 40 3 It can be further converted to a binary number using the binary-octal table (in a later slide) ( 576.) / 8 ( 576.) remainder remainder remainder remainder (500.) 8 Note that the first digit you obtain is the first digit next to the radix point 0 0 5 (500.) 8 ( 000 0 000.) 0 0 5

Multiplication Algorithm Use integer-fraction-split process for converting a fractional part x k c k - β k (0. c cc3 ) β.) multiply the (fractional) number by β;.) take the integer part as the first (next) digit; 3.) repeat the process on the remaining fractional part. Again, the first digit obtained is the one closest to the radix point Terminating fractional number may become non-terminating in different base systems, and vice versa

Integer-Fraction-Split To convert a fractional base number to a base β< number, we can use the integer-fractional-split algorithm So we have 0.37 0.744 0 0.744.488 0.488 0.976 0 0.976.95 0.95.904 0.904.808 ( 0.37 ) (0.0...) 3

Use Intermediate Base We can convert a base number to a base 8 (octal) number, then to base (binary) number, and vice versa Binary-octal table Groups of three binary digits can be translated to an octal number using the binary-octal table ( 00.0 0 ) (65.347) 8 (?) (57.3) (?) 8 (?) 4

Base 6 Numbers Certain computers with word length being multiples of 4 use hexadecimal system, need A, B, C, D, E, and F to represent,,, 3, 4, and 5. Binary-hexadecimal table (0 0. 0 ) ( 0. 00 ) (BC.DF)6 5

Definitions There are some definitions for representing a real number in base and in base 6

Write a number in the form of Normalized Scientific Notation 78.359 0.78359 A normalized floating-point number has the form 3 where d 0,n is an integer x ±. d d d 0 3 n In a simple notation n x ± r r < r is called normalized mantissa and n is the exponent. Also for binary representation m ± q q < x 7

Machine Numbers The real numbers that can be represented exactly in a computer are called the machine numbers for this computer Most real numbers are not machine numbers If a computer has word length of the form 0.d d d 3 d 4, then 0. is a machine number, but 0. is not Machine numbers are machine dependent. The use of normalized floating-point numbers creates a phenomenon of hole at zero, a bunch of numbers close to 0 are not representable This is mainly caused by the under-flow problem, i.e., small numbers close to zero will be treated as zero in a computer. (0.00 cannot be stored in the above mentioned computer, why?) 8

A 3-bit Machine Single precision floating-point numbers with 3-bit word length How to store a floating-point number with 3 bits? Sign of q needs bit Integer m needs 8 bits Number q needs 3 bits m ± q Single precision IEEE standard floating-point format s c 7 ( ) (. f ) 9

3-bit Representation The exponent number c is actually stored, so m c 7, this is an excess- 7 code (make sure only positive numbers are stored, 0< c <55) With normalized representation, the first bit is always and needs not be stored. The mantissa actually contains 4 binary digits with a hidden bit With a mantissa of 3 bits, a machine can have about six significant decimal digits of accuracy, since 3 7. The smallest positive number є such that ε is called the machine epsilon or unit roundoff error For single precision, ε. 7 For double precision, ε. 6 0

3-bit Representation IEEE 3-bit single precision

64-bit Representation IEEE 3-bit single precision and 64-bit double precision

The exponent c is stored, with More About the Exponent 0 < < 55 ( ) The actual range of exponent is 6 7 7 0 is reserved for the special number ±0, and 55is for ± This strategy avoids the need to handle sign for the exponent The largest number can be stored 3.4 The smallest number can be stored. 3

How to represent a real number x? Representation Procedure.) if x is zero, stored it by a full word of zero bits, (a possible sign bit).) for nonzero x, first consider sign bit and then consider x 3.) convert both integer and fractional parts of x from decimal to octal, then to binary 4.) one-plus normalize ( x ) by shifting the binary point 5.) find the 4 bit -plus normalized mantissa 6.) find the exponent of by setting it equal to c-7 and determine c 7.) denote the 3-bit representation as 8 hexadecimal digits 4

A 3-bit single-precision pattern Summary and Examples can be interpreted as the real number Examples b bb3 b9bb b3 Find the 3-bit representation of -5.34375. Integer part (5.) (64.) 8 ( 0.) Fractional part (.34375) (.7) 8 (.00 ) b ( b b b ) 7 3 9 ( ) (. b b b 3 ) 5

Examples cont. ( 5.34375) ( 0.00) (. 000 0) 5 The exponent is (5), we need to write it as c - 7 5 so c 3 The stored exponent is ( 3) The representation of -5.34375 is ( 000 0 000 0 000 000 000 00) (0 00 0 0000 0000 0000 0000) (C50F000) 6 What number has the representation (45DE4000) 6? (04) 8 ( 000 0) 6

Errors in Representing Numbers Non-machine numbers are represented by a nearest machine number in computer Additional digits will be truncated Correct rounding and roundoff error For a 3-bit single-precision machine with 3 bits for mantissa, the relative error in correct rounding is 3 The unit roundoff error is ε 3 For a computer with a 4 binary digit word length, the number 0. will be stored as 0. for rounding off, and 0. for correct rounding 7

Arithmetic Operations Most computers use double-length arithmetic operations. Numbers are extended to double length, arithmetic operations are performed, and the result is rounded to a single length number 0.3 0.3456 0.3000 0.00034560 ------------------------------------------------------------------------------------ 0.344560 On a machine with 4 digit word length, this number needs to be rounded to 0.34 resulting in an error 0.00004560 8

Notation fl(x) Use fl(x) to denote the floating-point machine number corresponding to a real number x fl(x) x( δ), For the 3-bit machine, we have δ ε It is easy to see that if є < -3, then fl( є) Note that the numbers are smaller than ε. It has more than 3 zeros. 9

Inverse-Error Analysis More generally known as backward error analysis Denote as one of the basic arithmetic operations, then fl(x y) (x y)( δ), Two interpretations ( δ 4 ) fl(z) (x y)( δ) perturbation of sum fl(z) x( δ) y( δ) sum of perturbations Direct-error analysis and reverse-error analysis Forward-error analysis and backward-error analysis 30

Loss of Significance Subtraction of two nearly equal numbers may result in loss of significant digits on a finite precision machine Cure: reprogram or use higher precision arithmetic, may be costly Use a 4-word length computer: 0. 0. 0.000 0. 0. 0. 0.000000 0.00 Loss of Precision Theorem Let x and y be normalized floating-point machine numbers with x > y > 0. If p q y/ x for some positive integers p and q, then at most p and at least q significant digits are lost in the subtraction x - y 3

Loss of Significance Since y<x, the computer has to shift y before carrying out the subtraction so Look at the mantissa Hence, to normalize the representation of x-y, a shift of at least q bits to the left is necessary. Thus at least q (spurious) zeros are supplied on the right-hand side of the mantissa ) ) ( ) ( p q n m n m r x y r r s r s r > < ( n n m s y ) (, where,, s r s y r x m n n n m s r y x ) ( 3

x 37.5936 and y 37.5846 y 0.00050754, x An Example from Book which is between - 0.00044 and - 0.000488. At least and at most binary digits are lost when computing x - y Exactly how many digits lost depends on a computer x 0.375936 and y 0.375846 Suppose a machine has 5 decimal digits of accuracy We have x 0.37594 and ~ y The machine computes ~ 0.37584, ~ ~ 3 x y 0.000 0.000 33

An Example Cont. Exact computation The relative error is x y 0.00009396 0.9396-4 ~ ~ ( x y) ( x y) x y 0.604 0.9396 5 4 0.0648 This relative error is considered to be large since the machine has 5 decimal digits of accuracy Note that the double length computing operations are carried out after the numbers are stored If we use a machine with at least 8 decimal digits of accuracy, we can have the exact value as 0.93960000-4 34

Avoiding Loss of Significance Analyze possible loss of significance, reschedule computation to avoid subtraction of two nearly equal numbers, modify algorithm Example. Evaluating f ( x) x at x Using 5-decimal-digit arithmetic for x -3, we have f(x) 0 Rationalizing the numerator, we have x f ( x) x 0 computing ( 3 6 ) 0., and f ( x) 0.5. 35

More Examples Evaluating f ( x) x sin x at x 0 Using Taylor series for sin x sin x x 3 x 3! 5 x 5! 7 x 7! Then f ( x) Compute x 0. with four-decimal-digit arithmetic, sin(0.) 0.9983 -. So x -sin x 0.7-3. But x 3 /3! 0.667-3. This strategy is not good for large x. For x π, x sin π π, but x 3 /3! 5.677. Range reduction for periodic functions 3 x 3! 5 x 5! 7 x 7! ( 53.4) sin( 3.47 994 π ) sin( 3.47) sin 36