APT, a common computer language

APT, a common computer language

APT, a Common Computer Language* R. P. R I C H The Johns Hobkins University, Sih'er S~ring, .~fd. INTRODUCTION 1.1. A common machine language The AP...

821KB Sizes 1 Downloads 190 Views

APT, a Common Computer Language* R. P. R I C H The Johns Hobkins University, Sih'er S~ring, .~fd.

INTRODUCTION

1.1. A common machine language The APT language here described is intended to serve as a common computer language for computational problems. A programmer may describe the desired course of computation in A P T without regard to the specific type of computer on which the computation is to be done. Any internally programmed digital computer above a certain minimum strength can be provided with a compiler program which will translate from A P T to basic machine language, and thereafter can be used for any program written in A P T that does not exceed the storage limitations of the particular machine used. * Editorial Note: APT, the common computer language developed by workers at the Applied Physics Laboratory of the Johns Hopkins University, applies the so-called 'Polish' notation to algebraic language. This notation has also been used in the U.S.A. by Dr. Blum (while at the Naval Research Laboratory, Whiteoak, Maryland) and Gordon Rice at the Westinghouse Research Division, Pittsburg, Pennsylvania. By a curious coincidence, Gordon called his language APS. The peculiar virtue of APT, therefore, lies not in its application of this notation, but, rather, in joining it to the iterative subscripting procedure used by Professor A l a n J . Perlis of the Carnegie Institute of Technology for his I T language, and then searching for economy of expression in the result. The first use of this language outside the computing centre was by a physicist who received the programming memorandum at 11 a.m. and returned at 3 p.m. the same day with a four-body problem of some complexity correctly programmed except for a slight difficulty with the output format. This was corrected, and he had his answers by 5 p.m. closing time! It should also be pointed out that the letters ' A P T ' were pre-empted by the Massachusetts Institute of Technology for their 'Automatic Programmed Tool' program, a fact which was not known to the originators of A P T until the acronym had attained considerable local currency for that language. 141

142

R. P. Rich

The existence of such a common machine language has a number of important advantages. Programs written and checked out at any installation can be made available without reprogramming to other installations even when the machines involved are not of the same type. Within a s.ingle installation it becomes possible to use a small machine for most checking-out of problems and for short runs and to r e s e r v e a large fast machine for production--with appreciable gain in the economic efficiency of the installation. Such a mixed operation need not require two complete staffs of programmers for the two machines. The replacement of one machine by a n o t h e r - - a frequent occurrence in this rapidly changing field--will no longer require a complete recoding ot~continfling pi-oblems but merely the provision of a compiler for the new machine. 1.2. A natural programming language The A P T language is the result of an attempt to determine what it is that the programmer actually wants to say to the computer when he describes a computational problem and then to find an efficient language for this subject matter. Appendix E points out that the subject matter involved is essentially different from the subject matter of mathematics; it is not, therefore, surprising that A P T differs from the usual mathematical notation. This difference between APT and the usual mathematical notation offers a certain initial diffÉculty for those who want to use it. Since A P T has been designed for its purpose, however, the demands of machine and compiler do not require exception on exception: once the simple and explicit g r a m m a r has been learned it is not necessary to go on and memorize a long list of exceptions and caveats. Consequently A P T is more accessible to the learner than m a n y languages which bear a greater superficial resemblance to the usual mathematical notation. It appears quite possible, therefore, for a specialist in a field other than programming to learn within a short time to write his own programs in A P T and check them out himselfwith little or no help from an experiencedl programmer. 1.3. An easy compiler A P T represents a considered compromise between the needs a n d desires of the programmer on the one h a n d a n d thecost of compilation on the o t h e r . As a result, it is possible to write an APT compiler which is single pass

APT, a Common.Computer Langttage

143

in the strict .sense: compilation proceeds not only statement by statement but even character by character, so it is not necessary to read in a complete statement before beginning t.o translate it. The machine code turned out by such a strictly single pass compiler. will be quite inefficient. An appreciably better job can be done by compiling a whole statement at a time to avoid recomputing a n y sub-expr.essions that occur more than once. Still• greater efficiency in the running code can be obtained by a eomr piler ~yhich takes into account several statements at a time, or even makes several passes over the whole program (e.g. to optimize use of B-box.es as. F O R T R A N does). Hence for any particular type of machine a whole class of compilers is possible, eacll making a different compromise between compilation time and production• efficiency. An installation might decide, for example, to have a compiler with fast compilation to use for checkout and a different compiler which turned out the most efficient code possible for production. The advantage of having a fast compiler for problem checkout lies in the fact that if compilation is cheap enough in terms of machine time then the programmer can afford to recompile for each checkout attempt and can therefore do his checkout in symbolic rather than absolute machine language. The advantage of a language with restricted character range and the possibility of a simple compiler is that it can be in fact a common language for most of the machines now in use or currently contemplated, rather than being accessible only to the large and expensive types. 1.4. Limitations APT is designed for computational problems--those consisting largely of arithmetic operations inside the machine. It is not well suited to problems which are primarily logical (such as certain set-theoretic manipulations) or involve the processing of large files of data (such as most 'business' problems). Some problems of this sort can be handled by subroutines or subterfuge within the APT system, but a new start, differently oriented, is really required for these problems. Even within its design range (and even with a sophisticated compiler). APT does not produce as fast a program as hand coding can do when the chips are down. When a long production problem requires a really fastrunning code, for instance, at least the inner loops should be done in: fixed point, rather than floating point arithmetic~ a n d APT has. no provisi9n for the scaled fixed:point arithmetic needed. Also, when the problem really pushes the storage limit of the machine:

144

R. P. Rich

it is to be run on, the economies that good hand coding permit may be required in order to find room. For these and other reasons it is still necessary for the computer installation to have available a compiler accepting a language nearer to the basic machine language, and to maintain some programmers well trained in its use. The considerations touched on above, and others that will occur to the experienced reader, appear to indicate that provision of compilers at both levels is worth while for an installation that has a variety of scientific problems to handle. 1.5. Fo~m of the language An A P T program consists of a sequence of characters written from left to right. The permitted characters are the decimal digits and the capital letters excluding the letters O, Q. Spaces and divisions into lines on a p a g e are ignored by the compiler, and may be used as convenient. The language is conveniently described by listing first the permissible terms and then the permissible statements. TERMS

2. I. The mode of a term A term in the A P T language is any number or any symbolic expression to which a numerical value is to be assigned. A term is in one or the other of two modes: stated point or floating point. The numerical value of a stated point term will always be an integer (negative, zero or positive); such terms are usually used for indexing, much as subscripts are used in the customary mathematical notation. The numerical value of a floating point term, on the other hand, will be the computer approximation to a real number, which may have both an integral and a fractional part. Most of the actual computation in a problem will normally be done with floating point terms. The exact form in which the two modes of numbers occur in a particular machine need not concern the A P T user. The mode of a term is important in the A P T language, and the programmer must keep the distinction between stated point terms and floating point terms clearly in mind while he is writing his program. 2.2. Absolute constants An absolute constant is simply a non-negative number written in the usual decimal notation except that the letter 'V' is used instead of the period to indicate the decimal point.

APT, a Common Computer Language

145

An absolute constant is a stated point term if the decimal point Vdoes not occur, and is a floating point term if the decimal point V does occur. The manner of expressing negative numbers is described in Section 2.8. More precisely: by an absolute constant we mean a sequence of consecutive characters with the following properties: Ca) the sequence contains at least one character; (b) each character of the sequence is either a decimal digit or the letter V (spaces do not count as characters, as pointed out above, and may occur in the sequence) ; (c) the sequence contains at most one V; (d) the character adjacent to the sequence o n the left is a letter other than V; (if the sequence contains the first character of the program this condition is ignored) ; (e) the character adjacent to the sequence on the right is a letter other than V. An absolute constant without a V stands for a non-negative integer and will frequently be referred to as a natural number in what follows when it is greater than or equal to one.

Examples (In each example assume that the next character on both right and left is a letter other than V) : 0 means 13 m e a n s 13V means V12 means V means 1 V23 means

zero thirteen thirteen 0.12 zero 1-23

(stated point) (stated point) (floating point) (floating point) (floating point) (floating point)

Remark. It is sometimes necessary to write two or more absolute constants in succession. In this situation it is necessary to separate the successive absolute constants by the letter P to indicate where one stops and the next starts. This use of the letter P to separate successive absolute constants is not inconsistent with its introduction below to indicate the 'absolute value' operator, since the absolute value of a non-negative number is the same as the number itself. I f condition (e) is satisfied naturally by the context then the 'P' is not necessary and should not be used. 2.3. Variables I f u > 1 is a stated point term then uI and uJ are stated point terms referring to the current contents of the symbolic addresses 'uI' and 'uJ' respectively.

R. P. Rich

146

I f u > I is a stated point term then uA, uY and uG are floating point terms referring to the current contents of the symbolic addresses 'uX', 'uY' and 'uG' respectively. Thes!ated point term u in the symbols uI, uJ, uX, uY, uG is an adscript serving much the same purpose that a subscript does in the usual mathematical notation, so that 3 J means ja, the current contents of the third cell in the block of storage assigned to J-numbers. Notice that adscripts on adscripts to any level are permitted and that no restriction is placed on the complexity of the stated point term u. Thus 3 J X means x~,, the current contents of the cell numberedja in the block of storage assigned to X-numbers. Clearly two categories of variables (one stated point and one floating point) Would be suflieient from the logical point of view. The extra three categories were included for the convenience of the programmer, and any of the symbols described above may be used as desired, subject only to modal restrictions. Tile programmer m a y find it convenient, however, to use the variables in the following specific way: J-numbers X-numbers G-numbers /-numbers Y-numbers

for for for for for

main program housekeeping, main program variables, main program parameters, subroutine housekeeping, subroutine variables.

2.4. Addition I f x a n d y are two terms of the same mode then x.yA is again a term of the same mode, referring to the result of adding tile two terms x andy. Examples:

2J1A means~j2 -k 1 (stated point) 2X1 Vii means x2 -{- 1.0 (floating point) 1P3JA means 1 + i s (stated point) (note use of 'P' to separate the '1' from the '3'). 1 VP3XA means 1.0 -{- xs (floating point) (note use of 'P' to separate the ' V ' from t h e '3'). 1JIX 2C A means x~jI -t- c2 2 J 1 A X means xj,+~

I f x a n d y are not of the same mode then x.yA is not defined.

APT, a Common ComputerLanguage

1~t7

2.5. Subtraction I f x a n d y are terms o f t h e same mode then xyS is again a term of the same m o d e referring to the result, x - - y , of s u b t r a e t i n g y from x. I f x a n d y are not of the same m o d e then xyS is not defined.

Examples. 3V23P 2 X S 1J1XS 3PIXS 1J2IS 4J2SX 1X A

means 3.23 -- xz (floating point) not d e f i n e d - - m i x e d operands not d e f i n e d - - m i x e d operands m e a n s j x -- i 2 (stated point) means xj,_. + xx (floating point)

2.6. Multiplication (M) I f x a n d y are terms of the same mode t h e n xyM is again a term of the same m o d e referring to the result of multiplying x b y y . I f x a n d y are not of the same mode then xy21I is not defined.

Examples. 2 X 1 X M means x 2 x 1 3X1XAI 2X A means x3x1 2 7 X2 3X1XA 2X M means (xa -b xl) x2 3X 1X2XA 21~/means Xa (xl -k x2) 3X 1X2X21I A means xa -b XlX2 1JIIM meansjli 1 1X 2JC 21I means x 1 ch 1X1JM means u n d e f i n e d - - m i x e d operands 2.7 Division (D) I f x a n d y are a n y terms of ihe same mode then xyD is again a term of the same m o d e obtained as follows:

(a) Stated Pohzt. I f x a n d y are both stated point terms then xyD is a stated point term referring to the integral part o f the fraction x]y. (b) Floating Point. I f x and y are both floating point terms then xyD is a floating point term referring to the result x]y of dividing x b y y . I f x a n d y are not o f the same mode then xyD is not defined. Examples. 3P2D means[P ] = 1 (stated point) 3VP2VD means 3.0/2.0 = 1-5 (floating point) 3P2VD

means undefined~--mixed operands.

2.8. Negative ( N) I f x is a n y term then xN is a term of the same mode referring to the algebraic negative of x.

R. P. Rich

148

Examples. 3N means --3 (stated point) 3VN means --3.0 (floating point) 2X1CAN means --(x2 + Ca) 2.9. Absolute value (P) I f x is any term then xP is a term of the same mode referring to the absolute value Ix] ofx.

Examples. 2XP 2XPIGA 2X1CAP 2X1GPA 3NP 2xPP 2XPN

means means means means means means means

[xo[

Ix21 + cl [xo. q- cx[ xz q- lc l

1-31 -- + a I(Ix l)l -- Ix. l -Ixzl

As indicated in Section (2.2) the letter P is written after an absolute constant which would otherwise be immediately followed by a digit or a V, so that the compiler can tell when one n u m b e r stops and the next starts. 2.10. Unscramble (U) I f x is a term of either mode then xU is a term of the opposite mode defined as follows:

(a) Stated to floating conversion. I f x is a stated point term then xU is the numerically equivalent floating point term obtained by converting the integer x to floating point form. (b) Floating to stated conversion. I f x is a floating point term then xU is the machine integer obtained by converting the integral part of x from floating form. Note particularly that in this case xU is not in general numerically equal to x since the fractional part of x (if any) is dropped in the process of conversion. Examples. 3

means means 3UU means 3 V3 means 3V3U means 3V3UU means 3U

3 (stated point) 3.0 (floating point) [3.0] = 3 (stated point) 3"3 (floating point) [3-3] ---- 3 (stated point) 3.0 (floating point)

The main purpose of the unscramble operator U is to permit the programmer to combine operands which m a y happen to be stored in

APT, a CommonComputer Language

149

conflicting modes. For instance if 1J is a counter and 2G is an increment he may want to multiply the contents of 1J by the contents of 2G to get a new value of the variable. I f he writes 1J2CM he will get an alarm 'mixed operands'. But he may write 1JU2GM to get the correct floating point result j l . c2. O r he may write 1J2CUA¢ to get the truncated stated point result j x . [q]. This will usually be different numerically from the result of truncating after multiplication by writing 1JU2GMU to get

[j,. c21. The operator U may, however, be used for other purposes, such as separation of the integer part and fractional part o f a number. 2.11. Functions(F) The sequence nF, where n is a natural number, is used to designate a function subroutine available in the standard library. At any particular time a specific list of such subroutines 1F, 2 F , . . . , mF--will be available for use. When a new function subroutine is added to the standard library its designator nF and its specifications become a part of the language. A function defined by a functi9n subroutine may have any number of inputs but must have a single output. The number of arguments, their respective modes, and the mode of the function value must be included in the subroutine specifications. The formal definition of a function-term is as follows. I f nF designates a function subroutine with k arguments (where h is a natural number) and ux, u 2 , . . . , uk are terms whose respective modes are those specified for the arguments of the subroutine, then It 1 u 2 .

.

. u~nF

is a term whose mode is that stated in the subroutine specifications. A list of the available function subroutines is given in Appendix B.

Examples. 1X1F 2X5F 1X6FA 1X1F5F 1XSFIF

means means means means

V'-xx sin x2 q- cos x1 sin ~Z~x1 ~ xx X3 + X1 3X1XA 2X 9F means a r c t a n X2

STATEMENTS 3.1. Statementforms The characters K, H, G, R, T, E, L, W, B and Z are called terminators. A statement in the language consists of all the characters from (but not

150

R . P. Rich

including) one terminator to (and including) the next terminator to the right. Hence the terminators not only tell what kind of a statement is involved but also provide the punctuation between statements. Each kind of statement is described below under its terminato1". 3.2. Header statement, The ierminator K is Used in two distinct ways in the APT language: (a). abnormal use in the header statement; (b) nornthluse i n the bod,+, of the program. The present section describes the abnormal use and the next section describes the normal use. Tile APT .language is designed to permit one-pass compilation o n the computing machine being used. Consequentlyit is necessary to provide certain.information about ,stdrage requirements at the beginning of the written program. Therefore the first statement of every program must be a header statement of the form iI j J

cC x X y Y

kK

where i,j, c, x,y, k are natural numbers used by the compiler to determine how much storage to reserve for the respective lists, Thus k must be at least as large as the largest statement number used in a key statement nK of the p~'ogram. And i must be at least as large as the biggest adscript actua!ly .used for a n -Lnumber uI (whether this number is explicitly written by t.h.e: programmer as in ' 3 I ' or computed-lin, the program as in '3JI'). The compiler will then reserve i consecutive storage cells for the variables. 11,21,3I,..,iI Tile integers j, c , x and y of the header statement are analogously determined. The pair kK must occur in the header statement and must be written last (as shown in the examples). The pai.rs iI, j J, cC, .xX, y Y may be written in any order in the headerstatement. If one or more categories of variables are not used in the problem then the corresponding pair or pairs need not occur in the header statement. Precisely one header statement must occur in each program, and must be the first statement of the program. Example. If only J- and X-variables are used in the problem tile header" statement might be: 5X7JI OK

APT, a Common Computer Language

151

3.3. Key statements As indicated in Section 3.2 the letter K occurs precisely once in each program in its abnormal use as terminator for the header statement. Every other occurrence of the letter K in the program will be in its normal use as terminator for a key statement of the form nK, where n = 1, 2 , . . . is a natural number called the statement number of the key statement. A key statement nK is used simply to mark a specific point in the sequence of statements so that during running of the problem control can be transferred to that point by a j u m p instruction at some other point in the program. Except in special circumstances the same statement number should not be used for two key statements in the same program. The key statements do not need to be numbered in the order in which they occur in the program. 3.4. Halt statement (H) The character H is a statement meaning: stop executing the program at

this point. 3.5. Terminal statement ( T) I f n is any natural number (sequence of decimal digits) then n T is a statement indicating that the endofthe written program has been reached and that execution is to start at key statement nK. Precise~ one T-statement must occur in a program, and it must be the last statement of the program as written. In order to avoid confusion between H- and T-statements the programmer should notice that the T-statement signals the end of the wr#ten program (i.e. tells the compiler to stop compiling) while the H-statement signals the end of the running program (i.e. tells the machine to stop

computing). 3.6. Go statement ( G) I f u is any stated point term then uG is a statement meaning: transfer control to the key statement nK for which n is equal to the current value o f tl.

Examples. 3G 1JG

means: transfer control to statement 3K means: transfer control to statementjzK , w h e r e j z is the current value of the variable 13". IJ3A G means: transfer control to statement (Jx -[- 3)K.

R. P. Rich

152 3.7. Replacement statement (R)

I f x is the symbol o f a variable (i.e. a n y t e r m whose rightmost c h a r a c t e r is I, J , G, X o r Y) a n d y is any term of the same mode as x then xyR is a statem e n t m e a n i n g : replace x b y the c u r r e n t value o f y .

Examples. 1JOR means set j l = 0 1X 1X2XA R means set xl = xl -b x2 1X 1XI VA R means set x~ = x~ q- 1.0 1JX2VR means set xjl = 2.0 1 J 2 A X 3 J C R means set x~,+2 = ci, I f x a n d y are not of the same mode a n d x is a variable with only a n a t u r a l n u m b e r in front o f the c h a r a c t e r / , aT, X, Y or C w h i l e y is either a n absolute constant or a variable with a b o v e restriction t h e n the r e p l a c e m e n t will be m a d e b u t a warning will be p r i n t e d d u r i n g compilation to call this to the attention o f the p r o g r a m m e r .

Examples. 1J2CR 311 VR 5X4R 7G2JR

means means means means

set j l = set/3 = set x 5 = set c7 =

co 1.0 4 J2

3.8. Equality test (E} I f x a n d y are a n y terms o f the same m o d e t h e n xyE is a s t a t e m e n t m e a n i n g : if x ----y execute the s t a t e m e n t i m m e d i a t e l y following this one: otherwise skip the next statement.

Examples. 1X2XE1G2Gmeans: ifx~ = x2 go to 1K; otherwise go to 1J13EH

2K means: if j l = 13, halt; otherwise c o n t i n u e

W h e n two floating point n u m b e r s are c o m p a r e d , n u m b e r s w h i c h should be considered as equal m a y differ f r o m each o t h e r b y a small a m o u n t because o f the a p p r o x i m a t e n a t u r e o f floating point a r i t h m e t i c ; therefore, a n equality test on floating point terms is not advisable. 3.9. Less-than test (L) I f x a n d y are terms o f the same m o d e then xyL is a statement m e a n i n g : if x < y execute the s t a t e m e n t i m m e d i a t e l y following this one; otherwise skip the next statement.

Examples. 1X2XL 1X2XR 3G means: ifxl <( x2 set x 1 ~ x2 and go to 3K; if xl <~ x2 go to 3 K b u t do not set xl ---- x2.

ziP T, a Common Computer Language

153:

3.10. Less-than-or Equal test (W) I f x a n d y are terms of the same mode then xy Wis a statement meaning: if x < y execute the statement immediately following this one; otherwise skip the next statement. For mnemonic purposes, notice that the sign looks like a IV turned on its side with one stroke erased.

Example. 1X3V34 IV 1G 2G means: i f x z < 3.34 go to 1K, otherwise go to 2K. 3.11. B-Statement (B) The symbol nB, where n is a natural number (sequence of decimal digits) is used primarily to designate the nth service routine in the standard library. At any time there will be a particular list 1B, 2 B , . . . , bB of such routines in the library. W h e n a new service routine is added to the library its designator nB and its specifications become a p a r t of the language. I f n B designates a service routine with k parameters and uz, u ~ , . . . , uk are terms whose respective modes are those specified by the routine then

uzu2 • . . uknB is a statement meaning: carry out ihe se~cice routine nB with the current values of us as parameters. A list of the service routines available in the initial version of APT is ~ v e n in Appendix C. The symbol nB is also used to designate statements other than service routines. A list of these is given in Appendix C.

3.12. Zero-setting statement ( Z) I f m and n are natural numbers then m Z is a statement with the following effects:

(a) Every statement nK between m Z and the next Z occurrbzg hz the wTitten program (regardless of the order of actual execution of the staterrients involved) will be executed as if it had been written (m -t-"n)K. (b) Every statement uG between m Z and the next Z occurring in the written program (regardless of the order of actual execution of:the statei~ents involved) will be executed as if it had been written umAG. The main purpose of the Z-statement is to facilitate the inclusion in several programs of subroutines written in A P T language.

154

R. P. Rich APPENDIX

A

Summary of symbols

(Sect.ion 2.4) (Section 3.11) uC = floating point variable (Section 2.3) xyD = x]y (Section 2.7) xyE: ifx = y take next statement (Section 3.8) nF: nth function routine (Section 2.11 i u G : Go to statement uK (Section 3.6) H: Halt (Section 3.4) ul: stated point variable (Section 2.3) (Section 2.3) uJ: stated point variable (Sections 3.2 and 3.3) nK:" "key statement xyL: ifx < y take next statement (Section 3.9) xyM= x.y (Section 2.6) --X (Section 2.8) xN " x P ~ Ixl (Sections 2.9 and 2.2) (Section 3.7) xyR: replace x byy (Section 2.5) x--y (Section3.5) nT: terminal statement (Section 2.10) xU: reverse mode of x (Section 2.2) V: decimal point xyW: if x < y take next statement (Section 3.10) (Section 2.3) uX: floating point variable uY: floating point variable (Section 2.3) (Section 3.12) nZ: zero-setting statement xyA = x q- y nB: nth service routine

=

APPENDIX

B

Function subroutines xlF: y = ~Fx x2F: y ~ X2 x3F: y ~ C'Z: x4F: y = 19g, x: x5F: y = sin x: xrF: y ~ C O S X: xTF: y = tan x:

floating point input and stated point or floating same form as input. floating point input and floating point input and floating point input and floating point input and floating point input and

output. point input; output in output. output. output, x in radians. output, x in radians. output, x in radians.

155

A P T , a Common Computer Language x8F: y = arcsin x: floating point input and output, y in radians. 7r

7"g

x

xy9F: z = a r c t a n - : two floating point inputs, floating point radian Y output, 0 ~ z < 2~r 10F: Table lookup: I f x, u, v, are floating point terms and n is .a stated point term then:

x

u

v n

10F

means: (1) n values of the independent variable are stored starting at symbolic address u; (2) the n corresponding values of the dependent variable are stored at symbolic address v; (3) look up the argument value, x, in this table and substitute the corresponding value of the dependent variable iusing cubic interpolation) for xuvnlOF in the formula. Example. 2 Y 2 X I C 5 1 C 5 O P I O F R means Y2 = f ( x 2 ) , i.e. look up the argument x~ in t h e table starting at symbolic address 1C, and then the corresponding dependent variable in the second table starting at symbolic address 51C and replacey 2 b y t h i s value. • 11F: R a n d o m number generator. This function subroutine will generate a floating point rectangular random number. For example the statement 3X 11F R will generate and store a floating point rectangular random number in symbolic location 3X, i.e. xs = a random number. APPENDIX

C

Output and Input Subroutines

1B: ' Output routine: if ut, u 2 , . . . , us are terms and 1 < k -< 30 then ulu2 . . . uklB

means: print out t h e terms ua, u2, • • . , us in that order, each in its proper form (stated or floating point), in the standard output format of the machine being u s e d . 1 : I f there are no terms in front ofstatement 1B, it prints a blank line.

156

R. P. Rich 2B: Input routine: The statement 2B means: read input to the addresses specified on the input medium until an end of file signal is met on the input medium.

APPENDIX

D

Parentheses-free notation The APT language specifies the order in which operations are to be carried out by the order in which the symbols are written, rather than by a combination of parentheses, vincula, and conventions as in the usual mathematical notations. Since this method of specification may seem somewhat strange until custom renders it natural it seems appropriate to include a few suggestions and examples. In order to concentrate on the main current question we shall ignore the distinction between stated point and floating point and use letters x, y, z, for terms ambiguously. It is convenient to define the scope of an operator as follows: (1) The scope of a term is the term itself. • (2) The scope of a unary operator (P, N or U, G) is the operator plus the term which precedes it. (3) The scope of a binary operator (A, S,/l~r, D or R, E, L, W) is the operator plus the two terms that precede it. When an APT expression is to be interpreted visually it is helpful to draw a horizontal line under the symbols constituting each scope: for exampl e in the expression

x y A z M = (x + y ) z a line is drawn under xyA for the scope of the operator A and another line under the whole expression to show the scope of the operator M. Each scope line corresponds to a term, as defined in the body of the memo. The scope of a function subroutine symbol nF consists of that symbol plus the n u m b e r of preceding terms specified for the particular function. For example: xylFA = x -k- V'.,~

xyz9FA = x --}- tan -1 yz

xyAz 917 = tan -x ((x + y ) l z)

A P T , a Common Computer Language

157

Further examples: xyA z w M D = (x + y ) l z w x y A z M w D = (x + y ) z / w x y A z M uvSwMD = (x + y ) z / ( u -- v)w Subscripts. It will be recalled that when a stated point term u is immediately followed by a Jr, X or G, the u corresponds to a subscript to the or, X o r G. Hence so far as the present discussion of scopes is concerned the letters J, X and C act symbolically as if they were unary operators. For example: uX

=

xu

ttvAX = xu+~ uvAX w x M z A X A = x,,+__2 ~ + xw_,+~

The multiple subscripts of the usual mathematical notation can be handled in A P T by writing out what the subscript actually means. For example, if a~,~is a two-dimensional array with i= 1J= j=2J=

1,2,3,4,5 1,2,3

and a n is stored at, say, symbolic address 10X, then a~ may be written as : 9P 3 P 1 J I S M A 2JAX, for X9 ÷3{ i--l) + t

While this fashion of expressing subscripts is somewhat clumsy, it does have the major advantage that the number and complexity of subscripts is not limited and that no new procedure for handling multiple Subscripts n e e d s t o be learned by the user or coded into the compiler. APPENDIX

E

IVhat to talk about to the machine

Of the main steps involved in getting answers from a computer consider the following four: (1) (2) (3) (4)

Mathematical Formulation of the Problem Programming Coding Computing

158

R. P. Rich

Step (1) consists of setting up a description of the problem in mathematical terms. It is currently done :by a problem sponsor whose interest and competence is usually.in the subject matter of the problem rather than in machine methods. The output of step (1) is largely in tile usual matl~ematical notation. Step (2) consists of translating fi'om the mathematical formulation of the. problem (output of step (1)) to an explicit computational procedure. This step is carried out by a programmer (or analyst plus programmer). Its output is a flow chart of the computation, or equivalent detailed clescr!ption. Step (3) consists of translating from the flowchart (output of.step (2)) to a sequence of instructions for.t!m particular machine on Which the computation is to be done. This step is (or used to be) done by a coder; its output is a running machine program for this particular problem on this particular machine. Step (4)--computing--can then be carried out, as usual, by the computer and its operator, with less and less'emphasis on the operator as time goes o n - - b u t that is another story. There is a growing feeling, based on growing experience, that step (3) as well as step (4)can safely be left to the machine, so that any machine above some minimum strength would b e able to accept the output of step (2) in some suitable form, write its own code, and then go ahead and compute.. T h e advantage o f having this "suitable form' standardized among machines is so well recognized as to need no discussion here. It may be conjectured that in the future .large machines can also be taught to carry out step (2)--numerical analysis and programmingz-:-for themselves. When that time arrives it will be appropriate to use: the output of step (1)--mathematical notation--as input to the machine. But that is not yet here even for the large machines and may never come for machines of the strength of a basic 650. In the meantime step (2) must continue.to be carried out by a human programmer and the appropriate input to the computer is the output of step (2)--explicit description of the computational process~rather than the input to step (2) mathematical formulation of the problem. The first implication of this fact is that the. input language to the machine should represent a compromise between the machine and the programmer, not a compromise bet~,een the n/achlne and the problem sponsor. Hence a departure from the mathematical notation familiar to the problem sponsor is of small consequence as long as the result is easy for a trained programmer to learn and use.

A P T, a Common Computer Language

159

Until tile input language becomes versatile enough to express all problems fluentlywlogical ones as well as computational ones--the programmer will need to preserve much the same approach to his job as he now does, for those problems not suited to automatic coding. Loops will still have to be set, computed, stepped and tested. Decisions will still need to be expressed by a test and a jump. And so on. The automatic coding language should therefore be suitable for expressing these familiar sequences and should not require a basically different approach to programming. Once the point has been raised, it is probably not necessary to argue in detail the differences between the output of step (1)--mathematical notation--and step (2)--description of a computational process. But a few examples may illustrate and emphasize the point. In the mathematical formulation the associative law holds for multiplication of numbers: a (be) .=- (ab) c But in a floating point machine with maximum exponent of 103s the form (lOZ°x 10°'°) X 10-1° would cause an exponent overflow and give no answer, while the form 1020 × (1020 × 10 -1° )

gives the correct answer 1030. In the mathematical formulation the questions of precision, truncation, and round-off errors do not arise: in programming they are of the essence. Thus, once questions of convergence have been settled, an integral is an integral to the problem sponsor. But it is something quite different to the programmer--Simpson's rule with h -----0.01 for example. In the mathematical formulation the questions of computing time and storage space do not arise; to the programmer these are matters of interest. -But the reader can multiply examples to suit his own taste and reach his own conviction that what the programmer has to say to the machine is a very different sort of thing than what the problem sponsor has to say to the programmer. And that the efficient languages suitable for these two subject matters will turn out to be identical only by a very curious coincidence indeed.