Professional Documents
Culture Documents
Jean-Marie CHESNEAUX
Fabienne JZQUEL
Introduction (1)
A good knowledge of floating-point arithmetic should be required of all computer
scientists!
Introduction (2)
It really happened!
During the 1st Gulf war (1991) in the control programs of Patriot
missiles which had to intercept Scud missiles
At 1600 km/h, 0.34 s 500 m
The interception failed, 28 people were killed.
With the other implementation
do ...
i =i +1
t =hi
enddo
If no overflow occurs for i, with double precision IEEE arithmetic, the
relative rounding error remains below 1015 .
Pp1
i=0
1
s
2 ...
9 10
7
E + 2 1 a1
.........
.........
32
a23
1
s
2 ...
12 13
10
E + 2 1 a1
.........
.........
64
a52
Rounding mode
Let IF be the set of all floating-point numbers.
Let Xmin (resp. Xmax ) be the smallest (resp. the greatest) floating point
number.
Let x be a real number which is not machine representable.
If x (Xmin , Xmax ), X , X + IF2
such that
X < x < X + and (X , X + ) IF =
A rounding mode is a rule which, from x, provides X or X + .
This rounding occurs at each assignment and at each arithmetic
operation.
The CADNA software
A significant example - I
A significant example - II
n
X
gi (d) 2p i
i=1
10
i
= p log
g
(d)
CR log2
i
2
r
r
i=1
Theorem
The loss of accuracy during a numerical computation is independent of
the precision used.
11
12
13
n
X
gi (d) 2p i
i=1
14
,R +
P r R
=P Rr
=
N
N
N
with
R=
N
1X
Ri
N
i=1
and
s2 =
2
1 X
Ri R .
N 1
i=1
15
CR = log10
!
N R
s
with s2 =
2
1 X
Ri R
N 1
i=1
16
17
18
and
x =y
/ X = Y.
X Y
/ x y
and
x y
/ X Y.
19
20
J. Vignes, 1986
Definition
Using the CESTAC method, a result R is a computed zero, denoted by
@.0, if
i, Ri = 0 or CR 0.
It means that R is a computed result which, because of round-off
errors, cannot be distinguished from 0.
21
Definition
Let X and Y be two results computed using the CESTAC method.
Stochastically equality, denoted by s=, is defined as:
X s= Y if and only if X Y = @.0.
Stochastically inequalities, denoted by s> and s, are defined as:
X s> Y if and only if X > Y and X s=
/ Y.
X s Y if and only if X Y and X s= Y .
DSA (Discrete Stochastic Arithmetic) is the joint use of the CESTAC
method, the computed zero and the stochastic relations.
22
A few properties
x = 0 = X = @.0 .
X s=
/ Y = x =
/ y.
X s> Y = x > y .
x y = X s Y .
The relation s> is transitive.
The relation s= is reflexive, symmetric but not transitive.
The relation s is reflexive, antisymmetric but not transitive.
23
24
25
26
27
28
29
The call to the cadna_init subroutine must be added just after the
main program declaration statements to initialize the library.
cadna_init(numb_instability, cadna_instability,
cancel_level, init_random)
if numb_instability = -1 : all the instabilities will be detected
if numb_instability = 0 : no instability will be detected
if numb instability = M : (strictly positive M), the M first
instabilities will be detected.
The other arguments are optional.
30
31
Termination
The call to the cadna_end subroutine must finish the source code.
It should be the last statement.
The cadna_end subroutine writes on the standard output a report on
the numerical stability of the run.
32
33
Operator Modifications
34
...
write(6,100) x
100 format(1x,x=,f8.3)
Modified statements
for CADNA
use cadna
type (single_st) :: x
call cadna_init(-1)
...
write(6,100) str(x)
100 format(1x,x=,a14)
35
.....
read (5,*) x
Modified statements
for CADNA
use cadna
real :: xaux
type (single_st) ::
call cadna_init(-1)
.....
read (5,*) xaux
x=xaux
36
-1.980967
-2.100000
3rd MRS Network Workshop
37
Contributions of CADNA
In direct methods:
estimate the numerical quality of the results
control branching statements
In iterative methods:
optimize the number of iterations
check if the computed solution is satisfactory
In approximation methods:
optimize the integration step
38
39
with CADNA
p6 = 0.14315490506E-005
p7 = 0.9009749273E-007
p8 = 0.56599705E-008
p9 = 0.3551346E-009
p10= 0.22264E-010
p11= 0.140E-011
D = 0.302E-064
40
In iterative methods
The equation
1.47x 3 + 1.19x 2 1.83x + 0.45 = 0
is solved using Newtons method with x0 = 0.5.
The stopping criterion is ||xn xn+1 || 1020 .
rounding to the nearest:
rounding towards zero
rouding towards :
rouding towards + :
with CADNA :
x(24) = 0.4285714332352813
x(24) = 0.4285714343480436
x(24) = 0.4285714343480436
x(30) = 0.4285714326546251
x(25) = 0.428571433
41
42
Approximation methods
exponent
em (h)
mantissa
ec (h)
43
Approximation of integrals
Rb
I = a f (x)dx is computed using a quadrature method (trapezoidal
rule, Simpsons rule, ...)
Let In be the approximation computed with step h =
ba
2n .
44
A demo ?
45
21.0 130.0
0.0
2.1
13.0 80.0
4.74e + 8
752.0
A=
0.0 0.4 3.9816e + 8
4.2
0.0
0.0
1.7
9.0e 9
153.1
849.74
B=
7.7816
2.6e 8
1.
1.
The solution is =
1.e 8
1.
Gaussian elimination method with total pivoting is implemented.
46