• Aucun résultat trouvé

MATH EMATICIAN

Dans le document JUNE 1981 (Page 32-37)

by Dr. John C . Nash

Operations on Floating-point Numbers

In last month's column, we presented the concept of the machine precision-the smallest positive that can be added to 1 .0 to give a result in the computer still greater than 1 .0.

The machine precision gives us a measure of how precisely we can represent numbers In the machine, before we even begin to calculate with them. I ndeed, It is frequently at this stage-before calculations begin-that some of the most serious errors creep into our results. We have, for Instance:

errors caused by the limitations of the measurement process, be it physical or statistical; others caused by the Incorrect recording or entry of the data, (e.g. digit transposition In writing down or keying data); and others that occur in converting the numbers to machine representable form.

This last class of errors, that of Input conversion, should be at most one unit in the last place (ulp) If the conversion method is correct. Sadly, a number of popular computers have sloppy compilers or Interpreters with errors in the Input/

output conversion routines . that may occasionally cause a disaster for our calculations. Fortunately, many micro­

computers use decimal floating-point representations, which effectively avoid this difficulty. The IEEE Draft Floating-Point Arithmetic Standard prescribes a binary representation, but specifies that conversion of decimal Input shall be such that a number is represented by the nearest representable number to it on the real scale. Let us hope that the Implementations of this standard (e.g. the Intel 8087) perform to specification.

For the purposes of discussion, we will assume that our input is exact up to the moment we enter it. Then there is a possible error proportional to the machine precision, which we will denote 8, as in the previous column. In a number X, this error will be such that:

A8S(X - fi(X)) A8S(x) * 8

That is, the absolute relative error may be as large as 8, the machine precision. Once again; fl ( ) will denote the floating­

point representation of the quantity within the parentheses.

In machines that round, 8 can be replaced by 8/2 in the above expression, since a smaller error will be possible.

We now wish to consider operations with numbers. Even if these are exactly represented, operations with them will create some rounding or truncation error. For example, in a four digit decimal machine:

fl(1 000 + 0.4999) = 1 000

In a rounding machine, we make an error of at most 0.5 in the last place in the result (half an ulp). Since 8 should be 1 ulp relative to 1 .0, we write:

A8S(fi(X + V) - (X + V)) A8S(X + V) * ( 1 + 0.5*8) It is not too hard to show that: ·

A8S(fi(X V) - X V)) A8S(X V) * ( 1 + 0.5*8)

where represents any of + , - , * , or /. However, this only describes the Individual operations and not their combinations.

Most students of engineering or physics are aware of the rules for combining error bounds on quantities already known to be subject to error or uncertainty. To review these, consider that X Is subject to an error as large as e, V to one as large as f. That is, the true values of the quantities we are dealing with lie in the intervals:

[X - e,X + e] and [V - f,V + f].

It is fairly easily seen that the true value of (X + V) lies in an Interval:

[(X + V) - (e + f), (X + V) + (e + f)].

Also that the true value of (X - V) lies In the interval:

[(X - V) - (e + f), (X - V) + (e + f)].

In this case, we see that while the quantities X and V are subtracted, the absolute errors are added. (See figure 1 .)

X

e e

v f f

r

e + f

\X + V e + f

X - V e + f e + f

Figure 1 . Addition and subtraction of numbers having errors.

Multiplication and division are slightly more complicated.

To simplify matters, we take all quantities positive. (In a strict analysis, one keeps absolute value symbols throughout.) For multiplication, the new interval is:

[ XV - Ve - Xf - ef, XV + Ve + Xf + ef ].

Scaling this by XV (i.e. dividing through) gives:

(XV) * [ 1 - e/X - flY - (ef)/(XV), 1 + e/X + flY + (ef)/(XV) ].

I f w e Ignore e f as being small relative t o 1 (this i s reasonable if X and V are greater than 1 and e and f are of a magnitude similar to the machine precision), we see that the deviation in the true XV is described by the sum of the relative errors (e/X) and (flY). A similar approach shows that the deviation in a quo­

tient is described by the sum of the relative errors in its parts.

To summarize: 1 ) the deviation In a sum or difference is given by the sum of the absolute deviations in the numbers;

and 2) the relative deviation in a product or quotient is given by the sum of the relative deviations in the numbers.

Note that relative errors can be converted to absolute errors. In the product example:

r = (e/X) + (flY)

STOP

and addressing system to do all the typing and clerical work on lists-from ten names to ten thousand.

LETTERIGHT.

$200. A correspondence processing package that speeds letter writing AN D merges your letters with names selected from your NAD list.

It takes very few hours at today's salary levels to repay the cost of any of these systems

.

...,.._,_ They' l l do you far better than that. SSG's

·�� §l��� �

Productivity Software Packages wi l l contribute

-.,...-t·

�f

immediately to the growth and success of

Here's the white col lar crime of 1981: Let your people labor away for hours at jobs a properly trained computer can do in seconds.

You pay for all those wasted hours.

And you're missing opportunities, because the hours could be spent on new, pro­

ductive, profitable projects.

We can help you.

If you have a C P/ M®-based microcomputer, SSG's Business Productivity Packages wi ll scoop up all those hours you're losing and give you back more productivity, more time, more i nformation, and more success.

ANALYST. $250. An information storage and retrieval (data base) system that wi l l replace piles of files with information you can USE.

MAGIC WORKSHEET.

$250. SSG's answer to the world's demand for electronic spreadsheet calculation and "what-if" capabilities on C P/ M systems. (Avai I able quarter two 1981.)

your business.

Please act now. Tear out this page . This coupon or a phone cal l wi l l get you immed iate relief from the wh ite col lar crime of

1 981. We' l l send you complete information. Or better

stil l , answer you r ques­

tions immediately.

Time's a-wasting.

That's a crime.

,

-D Please rush me information on the SSG Business Productivity Packages for CP/ M-based computers.

D Please cal l me right away.

Name ____________ _

Company ____________ _

Address ____________ _

City State Zip ___________ _

I Telephone ( I

NAD Name and Address. $100. A mail ing

L

_ _ _ _ _ _ _ _ _ _ _

.J

CP/M is a registered trademark of Digital Research. NAD, Magic Worksheet are trademarks of SSG.

JUNE 1 98 1 CIRCLE INQUIRY NO. 81 INTERFACE AGE 3 1

JUNE 1 98 1

/ I

SAVE SAVE

c·· over

over

400fo/$1 2.00 off 400fo/$1 2.00 off

newsstand price newsstand price

Send me: U.S. NEWSSTAND PRICE $30.00. YOU PAY ONLY $1 8.00.

0 One Year (12 issues) for $ 1 8.00 U.S. only0 Two years for $30.00 U.S. only

0 Canada One year $24.00 0 Canada Two years $42.00

0 Foreign Surface Mail One year $35.00 0 Foreign Air Mail One year $50.00

0 Check Auached

t'!:o

Am Ex

l::·�e�nB�;:�fuiii�0:Ca

U.

j' lati I I I I I I I I I I I I

0 0 0

If charge we must have Expiration

cardholder's signature: ____________________ Date_· ------ -This offer good for 90 days from dare of this issue.

First Initial Please rush my copies to this address

SAVE

over

400fo/$1 2.00 off

Allow 6-8 weeks for delivery

newsstand price newsstand price

Send me:

0 Check Allached

0 0 0

U.S. NEWSSTAND PRICE $30.00. YOU PAY ONLY $ 1 8.00.

0 One Year ( 1 2 issues) for $ 1 8.00 U.S. only0 Two years for $30.00 U.S. only

0 Canada One year $24.00 0 Canada Two years $42.00

0 Foreign Surface Mail One year $35.00 0 Foreign Air Mail One year $50.00

Must be in

U.S.

funds drawn on a

U.S.

bank.

0 Am Ex

c�J

D

B

A/Vi

sa [.)

D MC

I I I I I I I I I I I I I I I I

If charge we must have Expiration

cardholder's signature: ____________________ Date·---This offer good for 90 days from date of this issue.

First Initial

Please rush my copies to this address

Allow 6-8 weeks for delivery

• • •- r " � ,. _ r ,. _ r

.I.I U I

cnr�LC ��C

Magazine

P.O. Box 1 234 Cerritos, CA 90701

• • •- r " � " - r ,. _ r

.1.1

U I

C nr�L C ��C

Magazine P.O. Box 1 234

Cerritos, CA 90701

PLACE STAMP HERE The Post Office

wi l l not del iver mail without postage

PLACE STAMP H ERE The Post Office

w i l l not del iver mail without postage

which is the relative error in XY, gives the absolute error in this product as r(XY). What about a function of X? Can we estimate the error in say:

Z = g(X)

where X has an error bounded by e? Clearly, Z has an error as large as d , where d is given by:

d = max (g(t)) - min (g(t))

for all t in the interval [X - e, X + e]. Usually, one is not this strict, and assumes that the function g(X) is relatively smooth, so that it may be approximated by its tangent in the region of interest. The tangent is described by the first derivative of

Figure 2. Deviation In a function given a deviation In Its argument x.

The interval analysis we have been considering can be automated, but it has proven very expensive and difficult to carry out for real-world calculations. It is but one example of forward error analysis, which follows a calculation step by step to obtain error bounds on the results. This is very useful when one must know the limits on the results, but usually bounds obtained in this way are too conservative. That is, they usually indicate that very large deviations are possible in an answer, when the probability of ever having the errors combine in such a perverse way is infinitesimally small. In reality, errors may cancel each other, and the computer answer is frequently quite close to the exact result desired.

The difficulty, of course, is that we cannot be sure how close we are to the wanted result without a lot of analysis.

However, with the introduction of directed rounding (that is, up or down or both) in the Draft Floating-Point standard , it is likely that a lot more interval analysis will be perfqrmed.

Instead of looking at the estimation of errors in this forward analysis, one can consider a backward error analysis, which looks at the results and tries to find a neighboring problem that would give the same results if exact arithmetic were used throughout. This type of analysis is usually easier to carry out than the forward variety, but requires more attention to the mathematics.

Consider as an example the product of four numbers, X, Y, Z, and W. Taking the three products in order, we find: accounts, customers, and ven­

dors that con reside on a disk.

There ore many other i m ­ provements - send for deta i l s . W e bel ieve our product to b e the

best Osborne-based busi ness package ava i l a b l e for CP/M­

p l i cations software for over eight years . Qua l ity and su pport ore our way of doing busi ness.

O u r 3 0 - d o y m o n e y - b o c k guarantee speaks for itse lf.

General Ledger with Cosh Journal $295

Accounts Receivable $295

Accounts Payable $295

Payroll with Cost Accounting $295

All Four Packages (Gl, AR, AP, PR) $995

Magic Wand (Super Word Processor!!) $345 Pearl Level Ill (best prog. tool available) $645 agreement. Dealer inquiries invited.

To order call: (206)542-8370

Dans le document JUNE 1981 (Page 32-37)

Documents relatifs