where the symbol f'l denotes an A N D operation and the symbol F U R T H E R REMARKS ON REDU
• denotes a multiplication operation. TRUNCATION ERRORS
(2) The result of an OR operation w i t h any number of Boolean variables is the same as the (arithmetic) addition of tile x, y, z R e c e n t l y Jack M. Wolfe [1] proposed the use o f integer variables after the following t e s t is made: accumulators to evaluate a sum of the form S = (a) If the sum is equal to zero, t h e result is correct; when N is large and all the y's are of rougMy the s a m ( (b) If the sum is larger thart zero, t h e answer is a 1; i.e. magnitude. His intention was to alleviate tile accumula~tion 0/ rounding or t r u n c a t i o n errors which otherwise occurs wlmn S i~ x+y+z= A U B U C ifx+y+ z = 0 evaluated in the straightforward way illustrated by t h e followbv, ! (2) iFoRTtRAN program. x+y+ z = 1 if ( x - F y + z) ~ 1 1 S = 0.0 where the symbol O denotes an OR (}peration and the symbol 2 D O 4 I = 1, N -{- denotes an addition operation. 3 Y[ . . . . (3) The result of a NOT operation with a Bo{}lean variable is 4 S=S+Y[ the same as subtracting an integer variable x from 1; i.e. 5 ....
i = (1 -- x) (3) The rounding or truncation in statement 4 could c o n t r i b u t e to a
loss of almost log~o N significant decimals in S. 2}his w o u k t be because if A = x = l, t h e n A = 1 -- 1 = 0 ; a n d i f A = x = 0, important in those cases where the values of YI c o m p u t e d in then /[ = I -- 0 = I . s t a t e m e n t 3 were correct to nearly full machine p r e c i s i o n ; ether. The FOUTm~N program in Figure 1 illustrates the method pre- wise t h e uncertainty in tile Yl's would swamp any a d d i t i o n a l !{ sented. It simulates the logic of a full-adder as described by the error introduced in s t a t e m e n t 4. folh}wing two Boolean flmctions: ii Of course, the simplest and fastest way to prevent s u c h figure. .L = K1K.., + K~Ka + K2Ka (4) loss is to accumulate S to double-precision. For e x ~ m p I e , ia FOn'rRAN IV program it would suffice to precede st,'~teinent 1 M = L(K, + K~ + Ka) + K~K~KKa (5) above by tile T Y P E s t a t e m e n t DOUBLE P R E C I S I O N S • where K~ , K.a and Ka are the two i n p u t bits attd previous carry The convenient accessibility of double-precision in m a n y Fol~Taax to be added, L is the output carry, and M is the output sum. and some ALGOL compilers indicates that d o u b l e - p r e c i s i o n will htteger variables were chosen for compatibility with the FOEn'R~N soon be universally acceptable as a substitute for i n g e n u i t y iT, language. the solution of muncrieal problems. In the meantime, programmers without easy access t o dou[ precision arithmetic may be able to simulate it in t h e p r o g r E EXAMPLE OF BQOLEAN S I M U L A T I O N above by a method far simpler than Wolfe's, p r o v i d e d t h e y L S I M U L A T | O N (IF A F U L L - A D I I E R DIMENSION K(31 usit~g one of the electronic computers which n o r m a l i z e floati C INITIAL. I / E IHE INPUT TRUTtt TABLE r 0 ZERO [10 1{} 1 = 1 , 3 point sums before rounding or truncating them. A m o n g s~ I0 K{I};O machines are, for ext~mple, tile I,B.M. 704, 709, 7090, 7094, 7( L { ) ~ R I V ETHE [RtJIH rABLE FOR THE SUM Mt AN[) THE CARRY L, 7044 and 360 (short word arithmetic). I}f] 110 I=1,8 L : KII)'KI2I~KII)*KI3}~KI2ImE{3) T h e trick to be described below does not work o n roach' ITIL} 2(},~0,20 20 L = 1 such as the I.B.M. 650, 1620, Univac 1l(t7 and the C o n t r o l I 30 I.I=K[I}+KI2)~K(3} 3600 which round or truncate floating-point sums t o s i n g l e 1FILl) 60,50,40 40 tl=l cision before normalizing them. 50 ~ = (I-LI.LI + KIII~RIgI~K(3) In the following program $2 is an estimate of the e r r o r caused IF(R) 60,T0,60 60 M = 1 when S = T was last rounded or truncated, and is u s e d i n state ~ tO PRINT T S , K I 3 I , K I 2 I , K I I I , M , L ment 13 to compensate for t h a t error. The p a r e n t h e s e s i n state- C GENERATETHE NEXT INPUT C O M B I N A I I ( } N merit 23 must not be omitted; they cause tile d i f f e r e n c e (S--T) KI3):KII)*K(2Ii(I-K(3)) ~ II-K(1)'KI2I}~KII) I F ( R I 3 } ) 80,90,g0 to be evaluated first and hence, in most e~ses, w i t h o u t e r r o r be- 80 KI3}=l 90 K(2} =KII)~II-K(2}} + {I-KIII|~K{2} cause the difference is normalized before it is rounded o r t r u n c a t e d . I F I K ( 2 ) ) TO0,110,100 tO0 K(2)=l 1 S=0.0 IiO K(II=(I-K[I)) s2 = o.o 75 FORMAT(10X,I3,I3,I3,6X,I3,13) PAUSE 2 DO4I = I,N END 3 YI . . . . ]?iG, 1 13 82 = 82 + YI T = S + 82 23 $2 = ( S - T ) + $2 The AND and NOT operatimts are transf0rlned to multiplica- 4 S-T i! tion and subtraction operations as described in (1) and (3). The 5 .... OR operation needs a control I F s t a t e m e n t after the arithmetic Until double-precision arithmetic was made ~;::k:l addition is performed in order to r e s t o r e the value of tile variable of tile t;OI~TRAX language, the author and his t I s to unity. This may be simplified by using a li'unction subprogram trick on a 7090 in ili'OI~TmtN II programs to perform q u a d r a t u r e , to calculate tile result of the OIL o p e r a t i o n , thus eliminating the solve differential equations and sum infinite series. need for repetition of the IF s t a t e m e n t s . It was not done in this I{.E F E I~.EN E E : example because of the limitatien of t h e FOremAN colnpiier in the 1. WOLFE, J. 5/[. Reducing truncation errors by p r o g r a m m i n g . 1620 Model 1 computer where this p r o g r a m was checked out, and Comm. ACM 7 (Jmm 1964), 355-35B. where the use of subprograms is not pernfitted. M. MORRIS MANO W. KAHAN California State College at Los Angeles University of Toronto Los Angeles, California. I{E:CELVED JULY, 1964 Toronto, Ontqrio, C'ar~ada RECEIWBD FEBRUARY, 1964 (Pracniques are eontin~,ed on page 48}
40 C o m m u n i c a t i o n s o f t h e AC~I Volume 8 Number 1 / January, 1965
t h e d o m a i n last, e n t e r e d is k n o w n a n d it is this d o m a i n in PRACNIQUES--Conf. from page 40 w h i c h t h e t e r m i n a l p o i n t lies. LONGEI~, STRINGS Ft~OM S()[{T[NG* -VII. C o m m e n t s on hnplementation of Algorithm Presented hm'(: is a description of a SO IUI'/M EI{t~I!; L(~chniqus I t is to be n o t e d t h a t a c t u a l use of t h i s a l g o r i t h m will which can be ineorpor:~ted into existi~g sorbing methods to sub, f r e q u e n t l y i n v o l v e c o n s i d e r a t i o n s of a c c u r a c y a n d sig~ stantially increase the lengths of the sort output sLrings. This is nifieance. T h e s e n m s t be v i e w e d from t h e v i e w p o i n t of accomplished by relaxing the sort string ord('r erit, eria Lo the ex, n u m e r i c a l a n a l y s i s in t e r m s of permissible errors as re- tenl, that string order is recoverable by the first merge pass. The q u i r e d b y t h e n a t u r e of t h e given p r o b l e m . C o n s e q u e n t l y , standard sorting programs generate sequenced file records i~ tape record blocks. The records within a tape block are sequenced, a s s o c i a t e d w i t h each test, such as those for inclusion within and Lhe last record of one Mock precedes the lirs~ record of the new or on a rectangle, coincident points, etc., t h e r e will nor- block according ~o sequence. This new technique still requires that m a l l y be some s m a l l q u a n t i t y ~ ( p e r h a p s u n i q u e to t h e the tape bloeks contain sequenced file records, but relaxes the given t e s t ) which results in t h e t e s t being m o r e "eonserva-- second eriteria. This revised requirement is that for a set of tape l i v e , " i.e. r e t a i n i n g c e r t a i n borderline cases for considera- blocks with last, reeord sort keys, the next tape block nmst contain records with sort keys at least as large as the lowest of the tabled t i o n u n d e r s u b s e q u e n t tests in t h e procedure. last record sort keys. In addition, the last record sort key of this A second p o i n t is t h a t a l t h o u g h t h e d e s c r i p t i o n of t h e new bloek will replace :the sort key which was previously lowest. a l g o r i t h m is in t e r m s of a static set of p a r t i t i o n i n g b o u n d - The number of entries it* this set of last sort keys is the number 0f aries, it is q u i t e a d a p t a b l e to a s i t u a t i o n in which t h e tape records which nmst be merged from this tape on the first b o u n d a r i e s of t h e region are d y n a m i c a l l y changing d u r i n g merge pass with the nmltiple records from the other sort pass out. put tapes. The number of buffers required for reading this tape t h e course of t h e p r o b l e m solution. T h e s t r u c t u r e of t h e exceeds the size of the set by one buffer, if the set consists of one list of significant p o i n t s is such t h a t insertions a n d dele- entry, then the sort pass will generate the standard type output. t i o n s m a y be easily m a d e to reflect c h a n g i n g b o u n d a r i e s . To use the above technique, it is necessary to have special sort T h e n a t u r e of t h e a l g o r i t h m will be u n c h a n g e d . Of course, pass routines. Separate techniques are proposed below for fixed a s a l r e a d y n o t e d , processing t i m e is c o n d i t i o n e d b y t h e and w~riable-length file records. They appear to have the mosl promise. The fixed-length method will be superior to the variable. n u m b e r of b o u n d a r i e s i n v o l v e d , t h e i r o r i e n t a t i o n , etc. length method when most records approach the longest record in A n e x a m p l e of a n a p p l i c a t i o n s a r e a w h e r e a p r o c e d u r e of length. t h e t y p e here d e s c r i b e d is e x t e n s i v e l y e m p l o y e d is t h a t of For fixeddength records, two read buffers and a scatter write c o m p u t e r - g e n e r a t e d p a t h s over configurations of surfaces procedure should be used. A binary selection technique (see for p u r p o s e s of n u m e r i c a l l y c o n t r o l l e d m a c h i n i n g . * T o o l tournament or replacement selection of the literature) should be used to select file records for output. Output is considered a paired p a t h s are c o n s t r u c t e d b y a series of c o n n e c t e d s t r a i g h t - l i n e procedure. As one tape record is being written, the file records s e g m e n t s . T h e g e n e r a t i o n of t h e s e tool p a t h s is d e p e n d e n t from the other tape record are being replaced in a burst from the o n k n o w l e d g e of t h e surface ( d o m a i n ) on which the c u r r e n t input buffers. After the replacement the next tape record is se- a n d p r e v i o u s tool p o i n t s lie. T h u s t h e intersection curves lected. This will cause the binary selection tree to pulsate. The ( b o u n d a r i e s ) b e t w e e n c o n t i g u o u s c o n s t i t u e n t surfaces in file records on each tape block will be in sequence. During the re. placement each new record is checked to determine if it is in the t h e c o m p l e x m u s t be observed. I n a d d i t i o n , t h e tool p a t h current string. When core is filled with the next string, that string c u r r e n t l y being g e n e r a t e d m u s t c o n f o r m to e e r t a i u restric- is started. t i o n s i m p o s e d b y t h e p r e v i o u s l y g e n e r a t e d tool p a t h s , The above method is believed to be superior to all others since w h i c h t h u s c o n s t i t u t e a d y n a m i c set of boundaries. Sines it uses the fastest selection technique, requires only one data t h i s a l g o r i t h m is d e v e l o p e d in t e r m s of p a r t i t i o n i n g inove, and uses a minimum of buffers. Conservative estimates are that overlapping tape blocks will be equivalent to having orts b o u n d a r i e s in a b o u n d e d , plane region, t h e given configura- extra magnetic tape drive on the first merge pass. t i o n of surfaces in such a inachine t o o l i n g p r o b l e m m u s t For variable-length records, it is proposed that a read to full be such t h a t the p r o j e c t i o n s into some fixed p l a n e of t h e core, and then write all of core, be used for great length varia- b o u n d a r i e s c o r r e s p o n d i n g to t h e i r d e l i m i t i n g curves of tions. For this procedure, the sets of tape block last record keys i n t e r s e c t i o n as well as t h e b o u n d a r i e s c o r r e s p o n d i n g to t h e will be maintained for all output tapes. After the first few core loads, outtmt will be to all output tapes on each core load. Selec- t o o l p a t h s g e n e r a t e d on t h e surfaces m u s t satisfy t h e cri- tion of output tat)e is according to the lowest sort key permitted t e r i a for v a l i d t)oundaries e s t a b l i s h e d in Section I I of this for a tape. The procedure begins with the tape with tile highest paper. tabled sort key. When there are records remaining after all tapes are used for output, a new string is begun on the tape with the Acknowledgments. T h e e o n e e p t i o n of t h e essence of t h e largest tabled sert keys. p r o c e d u r e d e s c r i b e d in this p a p e r was p r i m a r i l y a c h i e v e d Excluding the first and last records on each tape the strings will b y M r . A r n o l d Siegel, t h e n w i t h I B M , now w i t h C o m p u - be approximately 2.5 core lengths long if tile strings are evenly tronics, Inc., a n d M r . S a m u e l M . M a t s a , I B M M a t h e - distributed on two or more tapes. Additional gains will be made matics and Applications Department. for files where the record length variances cannot be e~tieicntly handled by other techniques. I:{ECEIVED JUNE, 1964; t~EWSED SEP'rl~:MBEr~,1964 t{. J. DINSMORE The Bunker-Ramo Corp. iREiFE RE N CE Eastern Technical Center 1. AUTOPROMT, A System for N:umerieal Programming. iX[ & Silver Spring, Maryland A-12, IBM Math. & Appl., New York, May 1961. RECEIVED SEPTEMBER, 1964
* These techniques were developed by ~he author during his employment a~
48 C o m m u n i c a t i o n s of the ACM Control Data Corporation.