Introduction to Scientific Computing Languages

Similar documents
Introduction to Scientific Computing Languages

Lecture 7. Floating point arithmetic and stability

ECS 231 Computer Arithmetic 1 / 27

Notes on floating point number, numerical computations and pitfalls

Elements of Floating-point Arithmetic

ACM 106a: Lecture 1 Agenda

Floating Point Number Systems. Simon Fraser University Surrey Campus MACM 316 Spring 2005 Instructor: Ha Le

Notes for Chapter 1 of. Scientific Computing with Case Studies

Elements of Floating-point Arithmetic

Arithmetic and Error. How does error arise? How does error arise? Notes for Part 1 of CMSC 460

Floating-point Computation

CME 302: NUMERICAL LINEAR ALGEBRA FALL 2005/06 LECTURE 5. Ax = b.

Mathematical preliminaries and error analysis

Jim Lambers MAT 610 Summer Session Lecture 2 Notes

1 Floating point arithmetic

Lecture Notes 7, Math/Comp 128, Math 250

Can You Count on Your Computer?

Numerical Analysis. Yutian LI. 2018/19 Term 1 CUHKSZ. Yutian LI (CUHKSZ) Numerical Analysis 2018/19 1 / 41

Chapter 4 Number Representations

Mathematics for Engineers. Numerical mathematics

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

Chapter 1 Mathematical Preliminaries and Error Analysis

1 ERROR ANALYSIS IN COMPUTATION

Chapter 1 Error Analysis

1 Backward and Forward Error

4.2 Floating-Point Numbers

FLOATING POINT ARITHMETHIC - ERROR ANALYSIS

FLOATING POINT ARITHMETHIC - ERROR ANALYSIS

Introduction of Computer-Aided Nano Engineering

Numerical Methods - Preliminaries

Contents Experimental Perturbations Introduction to Interval Arithmetic Review Questions Problems...

Compute the behavior of reality even if it is impossible to observe the processes (for example a black hole in astrophysics).

Math 411 Preliminaries

Numerical Algorithms. IE 496 Lecture 20

EAD 115. Numerical Solution of Engineering and Scientific Problems. David M. Rocke Department of Applied Science

Lecture 1. Introduction to Numerical Methods. T. Gambill. Department of Computer Science University of Illinois at Urbana-Champaign.

Errors. Intensive Computation. Annalisa Massini 2017/2018

Numerical Analysis and Computing

Numerical Methods - Lecture 2. Numerical Methods. Lecture 2. Analysis of errors in numerical methods

Homework 2 Foundations of Computational Math 1 Fall 2018

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Computer Arithmetic. MATH 375 Numerical Analysis. J. Robert Buchanan. Fall Department of Mathematics. J. Robert Buchanan Computer Arithmetic

CS412: Introduction to Numerical Methods

BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination December, 2015 BCS-054 : COMPUTER ORIENTED NUMERICAL TECHNIQUES

Introduction CSE 541

Applied Numerical Analysis (AE2220-I) R. Klees and R.P. Dwight

An Introduction to Numerical Analysis

Chapter 1 Computer Arithmetic

Binary floating point

Round-off Errors and Computer Arithmetic - (1.2)

Introduction, basic but important concepts

Interactions between parallelism and numerical stability, accuracy

Chapter 1. Numerical Errors. Module No. 1. Errors in Numerical Computations

1.1 COMPUTER REPRESENTATION OF NUM- BERS, REPRESENTATION ERRORS

Accurate polynomial evaluation in floating point arithmetic

MAT 460: Numerical Analysis I. James V. Lambers

Chapter 1: Introduction and mathematical preliminaries

INTRODUCTION TO COMPUTATIONAL MATHEMATICS

Math 128A: Homework 2 Solutions

QUADRATIC PROGRAMMING?

Introduction to Scientific Computing

Chapter 1 Mathematical Preliminaries and Error Analysis

Lecture notes to the course. Numerical Methods I. Clemens Kirisits

Homework 2. Matthew Jin. April 10, 2014

ALU (3) - Division Algorithms

Lecture 2 MODES OF NUMERICAL COMPUTATION

An Introduction to Numerical Analysis. James Brannick. The Pennsylvania State University

How do computers represent numbers?

1 Finding and fixing floating point problems

An Introduction to the Quality of Computed Solutions 1

Exercises MAT-INF1100. Øyvind Ryan

CHAPTER 11. A Revision. 1. The Computers and Numbers therein

8/13/16. Data analysis and modeling: the tools of the trade. Ø Set of numbers. Ø Binary representation of numbers. Ø Floating points.

ESO 208A: Computational Methods in Engineering. Saumyen Guha

BASIC COMPUTER ARITHMETIC

COMPUTER SCIENCE & ENGINEERING DEPARTMENT Harmattan Semester, 2013/2014 Session. CSC 307: Numerical Computations I [PRACTICAL LAB ONE]

One-Sided Difference Formula for the First Derivative

Lineare Algebra. Endliche Arithmetik. Walter Gander. ETH Zürich

Outline. Math Numerical Analysis. Errors. Lecture Notes Linear Algebra: Part B. Joseph M. Mahaffy,

Tu: 9/3/13 Math 471, Fall 2013, Section 001 Lecture 1

Program 1 Foundations of Computational Math 1 Fall 2018

Combining Static Analysis and Testing for Overflow and Roundoff Error Detection DO THI BICH NGOC

Getting tight error bounds in floating-point arithmetic: illustration with complex functions, and the real x n function

Introduction to Finite Di erence Methods

Numerical Mathematical Analysis

Computation of the error functions erf and erfc in arbitrary precision with correct rounding

1 What is numerical analysis and scientific computing?


Introduction to Numerical Analysis

Binary Floating-Point Numbers

Optimizing MPC for robust and scalable integer and floating-point arithmetic

INTRODUCTION TO SCIENTIFIC COMPUTING - DRAFT -](DRAFT)

DSP Design Lecture 2. Fredrik Edman.

Uniform Random Binary Floating Point Number Generation

ROUNDOFF ERRORS; BACKWARD STABILITY

Lecture 28 The Main Sources of Error

Bindel, Fall 2016 Matrix Computations (CS 6210) Notes for

2.29 Numerical Fluid Mechanics Fall 2011 Lecture 2

ON REPRESENTATIONS OF COEFFICIENTS IN IMPLICIT INTERVAL METHODS OF RUNGE-KUTTA TYPE

2. Motivation and Introduction: Numerical Algorithms in CSE Basics and Applications

Transcription:

1 / 19 Introduction to Scientific Computing Languages Prof. Paolo Bientinesi pauldj@aices.rwth-aachen.de

Numerical Representation 2 / 19 Numbers 123 = (first 40 digits) 29 4.241379310344827586206896551724137931034... π = 3.141592653589793238462643383279502884197... In general: Infinite number of digits

Numerical Representation 2 / 19 Numbers 123 = (first 40 digits) 29 4.241379310344827586206896551724137931034... π = 3.141592653589793238462643383279502884197... In general: Infinite number of digits Computers Finite memory

Computers: Inexact Numbers 3 / 19 Infinite numbers vs. finite memory Approximated numbers

Computers: Inexact Numbers 3 / 19 Infinite numbers vs. finite memory Approximated numbers How many digits? A pre-determined amount π= 3.141592653589793238462643383279502884197...

Computers: Inexact Numbers 3 / 19 Infinite numbers vs. finite memory Approximated numbers How many digits? A pre-determined amount π= 3.141592653589793238462643383279502884197... Using 4 digits: π = 3.141 Modern computers: normally 8 or 16 digits, single / double precision.

Computers: Inexact Numbers 3 / 19 Infinite numbers vs. finite memory Approximated numbers How many digits? A pre-determined amount π= 3.141592653589793238462643383279502884197... Using 4 digits: π = 3.141 Modern computers: normally 8 or 16 digits, single / double precision. Alternatively? Extended precision Variable precision Symbolic representation

4 / 19 Computers: Approximated Computations 4-digit representation Inexact Arithmetic 123.4 +.5678 = 123.9678 =

4 / 19 Computers: Approximated Computations 4-digit representation Inexact Arithmetic 123.4 +.5678 = 123.9678 =

4 / 19 Computers: Approximated Computations 4-digit representation Inexact Arithmetic 123.4 +.5678 = 123.9678 = Truncated 123.9 Rounded 124.0

4 / 19 Computers: Approximated Computations 4-digit representation Inexact Arithmetic 123.4 +.5678 = 123.9678 = Truncated 123.9 Rounded 124.0 Associativity? Exact arithmetic: (123.4 +.5678) +.5432 = 123.4 + (.5678 +.5432)

4 / 19 Computers: Approximated Computations 4-digit representation Inexact Arithmetic 123.4 +.5678 = 123.9678 = Truncated 123.9 Rounded 124.0 Associativity? Exact arithmetic: (123.4 +.5678) +.5432 = 123.4 + (.5678 +.5432) Inexact arithmetic: (123.4 +.5678) +.5432 = 124.4

4 / 19 Computers: Approximated Computations 4-digit representation Inexact Arithmetic 123.4 +.5678 = 123.9678 = Truncated 123.9 Rounded 124.0 Associativity? No! Exact arithmetic: (123.4 +.5678) +.5432 = 123.4 + (.5678 +.5432) Inexact arithmetic: (123.4 +.5678) +.5432 = 124.4 123.4 + (.5678 +.5432) = 124.5

Error Analysis 5 / 19 f : A B, y = f(x) Es.: f(x) = x 2 + sin(2 x) x = π, f(x) =? 123

Error Analysis 5 / 19 f : A B, y = f(x) Es.: f(x) = x 2 + sin(2 x) x = π, f(x) =? 123 Exact arithmetic: ( π ) 2 ( + sin 2 π ) 123 123 =...

Error Analysis 5 / 19 f : A B, y = f(x) Es.: f(x) = x 2 + sin(2 x) x = π, f(x) =? 123 Exact arithmetic: ( π ) 2 ( + sin 2 π ) 123 123 =... Inexact arithmetic: x ˆx, f ˆf ˆf(ˆx) instead of f(x)

Errors 6 / 19 Representation Errors Roundoff Errors Algorithmic Errors

Known Disasters 7 / 19

Known Disasters 7 / 19 Patriot Missile, 1991 Scud launched from Iraq againt US military base in South Arabia. US Patriot s missile missed the incoming Scud. 28 casualties. Cancellation

Known Disasters 7 / 19 Patriot Missile, 1991 Scud launched from Iraq againt US military base in South Arabia. US Patriot s missile missed the incoming Scud. 28 casualties. Cancellation Spaceship Ariane 5 launched in 1996, destroyed 37 seconds after liftoff. Overflow http://ta.twi.tudelft.nl/users/vuik/wi211/disasters.html

Floating Point Numbers 8 / 19 y = ±d 0.d 1 d 2... d t 1 β e

Floating Point Numbers 8 / 19 β: base (radix) y = ±d 0.d 1 d 2... d t 1 β e

Floating Point Numbers 8 / 19 β: base (radix) y = ±d 0.d 1 d 2... d t 1 β e t: precision = # slots for the mantissa (d 0.d 1... d t 1 )

Floating Point Numbers 8 / 19 y = ±d 0.d 1 d 2... d t 1 β e β: base (radix) t: precision = # slots for the mantissa (d 0.d 1... d t 1 ) 0 d i β 1: digits

Floating Point Numbers 8 / 19 y = ±d 0.d 1 d 2... d t 1 β e β: base (radix) t: precision = # slots for the mantissa (d 0.d 1... d t 1 ) 0 d i β 1: digits e min e e max : exponent range

Floating Point Numbers 8 / 19 y = ±d 0.d 1 d 2... d t 1 β e β: base (radix) t: precision = # slots for the mantissa (d 0.d 1... d t 1 ) 0 d i β 1: digits e min e e max : exponent range Normalization: d 0 = 1; d 0 used for the sign ±

Floating Point Numbers 8 / 19 y = ±d 0.d 1 d 2... d t 1 β e β: base (radix) t: precision = # slots for the mantissa (d 0.d 1... d t 1 ) 0 d i β 1: digits e min e e max : exponent range Normalization: d 0 = 1; d 0 used for the sign ± Arithmetic β t e min e max Single precision 2 24-125 128 Double precision 2 53-1021 1024

Floating Point Numbers 8 / 19 y = ±d 0.d 1 d 2... d t 1 β e β: base (radix) t: precision = # slots for the mantissa (d 0.d 1... d t 1 ) 0 d i β 1: digits e min e e max : exponent range Normalization: d 0 = 1; d 0 used for the sign ± Arithmetic β t e min e max Single precision 2 24-125 128 Double precision 2 53-1021 1024 HP calculator 10 12-499 499 IBM 3090 16 14-63 64 Setun 3 Quadruple prec. 2 113-16381 16384

Floating Point Numbers (2) 9 / 19 What are the nonnegative points in β = 2, t = 3, e min = 1, e max = 3?

Floating Point Numbers (2) 9 / 19 What are the nonnegative points in β = 2, t = 3, e min = 1, e max = 3? Floating point numbers are non-equidistant!

Floating Point Numbers (2) 9 / 19 What are the nonnegative points in β = 2, t = 3, e min = 1, e max = 3? Floating point numbers are non-equidistant! How to represent 0?

Floating Point Numbers (2) 9 / 19 What are the nonnegative points in β = 2, t = 3, e min = 1, e max = 3? Floating point numbers are non-equidistant! How to represent 0? underflow? overflow? NaN?

IEEE single precision FYI 10 / 19

IEEE double precision FYI 11 / 19

Machine Precision 12 / 19 Machine Precision u Smallest positive number such that [1 + u] 1

Machine Precision 12 / 19 Machine Precision u Smallest positive number such that [1 + u] 1 Largest positive number such that [1 + u] = 1

Machine Precision 12 / 19 Machine Precision u Smallest positive number such that [1 + u] 1 Largest positive number such that [1 + u] = 1 1 2 β1 t

Machine Precision 12 / 19 Machine Precision u Smallest positive number such that [1 + u] 1 Largest positive number such that [1 + u] = 1 1 2 β1 t Distance between 1 and the next floating point number Machine epsilon, ɛ M, u

Representation Error 13 / 19 f min = smallest positive floating point number f max = largest positive floating point number x = [x] = floating point representation of x Theorem: Let x R and x [f min, f max ] Then x = x(1 + δ 1 ) where δ 1 u

Representation Error 13 / 19 f min = smallest positive floating point number f max = largest positive floating point number x = [x] = floating point representation of x Theorem: Let x R and x [f min, f max ] Then x = x(1 + δ 1 ) where δ 1 u Also, x = x/(1 + δ 2 ) where δ 2 u Note: δ 1 and δ 2 are functions of x

Smallest distance 0 14 / 19

Smallest distance 0 14 / 19 x and y are floating point numbers, x y; how small can z be? z := x y

Smallest distance 0 14 / 19 x and y are floating point numbers, x y; how small can z be? z := x y vs. z := x y max( x, y )

Smallest distance 0 14 / 19 x and y are floating point numbers, x y; how small can z be? z := x y vs. z := x y max( x, y ) z := x y 1) 0.0 01 2 0 = 2 1 t 2) 0.0 01 2 emin = 2 emin t+1 3) 0.0 01 2 emin+t 1 = 2 emin

Smallest distance 0 14 / 19 x and y are floating point numbers, x y; how small can z be? z := x y vs. z := x y max( x, y ) z := x y 1) 0.0 01 2 0 = 2 1 t 2) 0.0 01 2 emin = 2 emin t+1 3) 0.0 01 2 emin+t 1 = 2 emin

Smallest distance 0 14 / 19 x and y are floating point numbers, x y; how small can z be? z := x y vs. z := x y max( x, y ) z := x y 1) 0.0 01 2 0 = 2 1 t 2) 0.0 01 2 emin = 2 emin t+1 3) 0.0 01 2 emin+t 1 = 2 emin z := x y max( x, y ) 1) 0.0 01 2 0 = 2 1 t 2) 0.0 01 2 emin = 2 emin t+1 3) 0.0 01 2 emin+t 1 = 2 emin

Smallest distance 0 14 / 19 x and y are floating point numbers, x y; how small can z be? z := x y vs. z := x y max( x, y ) z := x y 1) 0.0 01 2 0 = 2 1 t 2) 0.0 01 2 emin = 2 emin t+1 3) 0.0 01 2 emin+t 1 = 2 emin z := x y max( x, y ) 1) 0.0 01 2 0 = 2 1 t 2) 0.0 01 2 emin = 2 emin t+1 3) 0.0 01 2 emin+t 1 = 2 emin

Roundoff Error 15 / 19 Notation: [exp] denotes the evaluation of exp in floating point arithmetic. Assuming a left-to-right evaluation, it holds [ [[x] ] [ ] ] [x + y + z/w] = + [y] + [z]/[w]

Roundoff Error 15 / 19 Notation: [exp] denotes the evaluation of exp in floating point arithmetic. Assuming a left-to-right evaluation, it holds [ [[x] ] [ ] ] [x + y + z/w] = + [y] + [z]/[w] Floating Point Arithmetic Theorem: (Standard and Alternative Computational Models) Let x and y be floating point numbers Then [x op y] = (x op y)(1 + ɛ 1 ), where ɛ 1 u, and op {+,,, /}

Roundoff Error 15 / 19 Notation: [exp] denotes the evaluation of exp in floating point arithmetic. Assuming a left-to-right evaluation, it holds [ [[x] ] [ ] ] [x + y + z/w] = + [y] + [z]/[w] Floating Point Arithmetic Theorem: (Standard and Alternative Computational Models) Let x and y be floating point numbers Then [x op y] = (x op y)(1 + ɛ 1 ), where ɛ 1 u, and op {+,,, /} Also, [x op y] = x op y (1 + ɛ 2 ), where ɛ 2 u, and op {+,,, /} Note: ɛ 1 and ɛ 2 are functions of x, y and op

Example: Dot Product 16 / 19 x, y R n ; κ := x T y ( ((χ0 κ := ψ 0 + χ 1 ψ 1 ) + ) ) + χ n 2 ψ n 2 + χ n 1 ψ n 1 ˇκ = = ( ((χ0 ψ 0 (1 + ɛ (0) ) + χ 1 ψ 1 (1 + ɛ (1) ) ) (1 + ɛ (1) + ) + ) +χ n 1 ψ n 1 (1 + ɛ (n 1) ) (1 + ɛ (n 1) + ) n 1 n 1 χ i ψ i (1 + ɛ (i) ) (1 + ɛ (j) i=0 j=i + ) ) (1 + ɛ (n 2) + ) where ɛ (0) + = 0 and ɛ (0), ɛ (j), ɛ (j) + u for j = 1,..., n 1

Case Studies Bisection Recursive implementation Base case? 17 / 19

Case Studies Bisection Recursive implementation Base case? Π 2 /6 10000 i=1 1 i 2 vs. 1 i=10000 1 i 2 17 / 19

Case Studies Bisection Recursive implementation Base case? Π 2 /6 10000 i=1 1 i 2 vs. 1 i=10000 1 i 2 sqsqrt vs. sqrtsq 17 / 19

Case Studies Bisection Recursive implementation Base case? Π 2 /6 10000 i=1 1 i 2 vs. 1 i=10000 1 i 2 sqsqrt vs. sqrtsq Ax = b A = [ ɛ 1 1 1 ] 17 / 19

Backward Stability 18 / 19 Let f : D R be a map from the domain D to the range R. Let ˆf : D R represent the execution in floating point arithmetic of a given algorithm A that computes f. A is said to be backward stable if for all x D there exists a perturbed input x D, close to x, such that ˆf(x) = f( x).

Backward Stability 18 / 19 Let f : D R be a map from the domain D to the range R. Let ˆf : D R represent the execution in floating point arithmetic of a given algorithm A that computes f. A is said to be backward stable if for all x D there exists a perturbed input x D, close to x, such that ˆf(x) = f( x). I.e., the result computed in floating point arithmetic ( ˆf(x)) equals the result obtained when the mathematically exact function (f) is applied to slightly perturbed data ( x). The difference between x and x, is the perturbation to the original input x.

References 19 / 19 IEEE 754-1985 and IEEE 754-2008: Standard for Floating-Point Arithmetic Book: Accuracy and Stability of Numerical Algorithms, by Nick Higham Article: What every computer scientist should know about floating-point arithmetic, by David Goldberg Book: Numerical Computing with IEEE Floating Point Arithmetic, by Michael Overton