From: Eric S. Raymond Date: Tue, 27 Jan 2004 05:17:05 +0000 (+0000) Subject: Initial revision X-Git-Tag: 1.0~167 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=1a2e782f1599b8e99cb082454d21595189d039b0;p=mad.git Initial revision --- diff --git a/doc/mad-manual.xml b/doc/mad-manual.xml new file mode 100644 index 0000000..b64979b --- /dev/null +++ b/doc/mad-manual.xml @@ -0,0 +1,1531 @@ + + + + + + +]> + +Notes from the 21st century + +MAD: An Appreciation + +Most of this document is a faithful transcription of the +reference manual for MAD (Michigan Algorithm Decoder), an early +academic computer language from 1962. The manual should be +accompanied by an implementation. MAD has been revived as a work of +reconstructive archeology, so that language connoisseurs of the +present and future will be able to appreciate what computing life was +like back in that day. + +MAD was an extended dialect of ALGOL 58, designed near the +beginning of the great age of invention in compiled languages that +stretched from FORTRAN in 1955 until the rise to dominance of C after +1985. Study of it teaches a great deal about the uses and background +assumptions of computing in 1962 and earlier. + +Some features of MAD are only superficially odd. The all-caps +listings look strange to modern eyes; the IBM 709 on which it was +implemented had a pre-ASCII, pre-EBCDIC six-bit character set with no +lower-case letters and lacks several punctuation marks that later +became standard. The limitation to six characters in variable names, +labels, and strings reflects the compiler's primitive memory +management; it meant all of these could fit in one 36-bit machine +word. + +A deeper difference from modern languages is the complete lack +of interactive I/O. MAD was designed to run in a batch environment, +with programs submitted via card decks and sending output to line +printers or a card punch. This limitation is a bit obscured in the +implementation that goes with these notes, because the card punch is +identified with Unix standard input and the line printer with Unix +standard output. Thus, MAD I/O accidentally looks more flexible than +it was — modern MAD programs (assuming anyone were perverse +enough to write any new ones) could actually be part of +pipelines! + +Punched-card input also explains some syntactic features that +will seem strange to modern eyes. MAD statement labels lack a +delimiter like C's trailing colon because they were distinguished by +position (columns 1 to 7) on the card. The line continuation syntax, +a digit in column 10, also relies on character position. In the late +1960s and 1970s, when punched cards coexisted with interactive +timesharing, the term free-format was commonly used to +describe languages with the newer-style syntax that used +whitespace-delimited tokens without relying on card position, and +languages like MAD were called fixed-field. When batch +computing vanished in the 1990s, both terms passed out of use. + +Perhaps strangest to the modern eye is the exclusiveness with +which MAD is focused on numerical computations in applied +mathematics. String handling is rudimentary, and data structures other +than arrays are absent. These gaps reflect not only the +non-interactive style of computing back then but the fact that what we +would today call systems programming (which drove the incorporation of +features like pointers, structures, unions, and typedefs in C) was not +yet done in non-assembler languages. The fact that the if statement is +called WHENEVER and the goto called TRANSFER is a mere cosmetic +trivium by comparison. + +There are some significant respects in which MAD was actually +rather advanced for its period. The multiline WHENEVER statement +anticipated the free-format syntax of ALGOL 60 and its descendants, +including Pascal and C. + + + +How This Implementation Differs From The Original MAD + +The Retrocomputing Museum implementation of MAD translates MAD +code into compileable C. It has been tested on the examples in the +manual, which are included with the distribution. + +This implementation simulates the card format of the original by +reserving the first 8 character positions of each line for a either a label +field or continuation. Whether or not a label field is empty, it +must be followed by a tab, and the statement proper begins following the +tab. Continuation lines must begin with either 8 spaces or 7 spaces +followed by a digit (which is ignored). + +Card images are read from standard input and printing is to +standard output. Printer control codes +, 1, 2 and 4 are ignored +(treated as 0 or space). Tape and drum devices are not +supported. + +The 709 had 36-bit words; modern machines have 32 or 64. +Precision and overflow of numeric results may therefore differ. +The original MAD limit of 6 characters on variable names, labels, and +string constants is not enforced. + +Label arrays, and the associated computed-transfer statement, +are not implemented. + +The C output is self-contained and does not require any +dedicated runtime support, except that the math library must be linked +with it (linker option -lm). + + +Redactor's Notes + +The remainder of this document, following this section) is an exact +transcription of the original Michigan Algorithm Decoder manual dated +February 1962. Catherine Raymond typed it in from the original +velo-bound typed manual; Eric Raymond hand-corrected it, and moved the +result into PIC and XML-DocBook markup so both HTML and PostScript can +be generated from it. + +Typewriter underlining in the original is expressed by +DocBook <emphasis> tags in this version, which will probably +render as italics. + +The original hyphenation will probably not be discernible in the +visible rendering you see, though hyphen characters in the original +have been preserved as ISO soft-hyphen entities. + +The program listings in the original failed to distinguish +between 0 and O; this does not reflect incompetence but rather the +fact that typewriters of the period did not have a separate 0 key. +This distinction has been restored. + +In the original, the description of flowcharting conventions +in Chapter 1 include small hand-drawn geometrical shapes after each +of the items A, B, and the words "diamonds" and "rectangles" in item +D were corresponding shapes. + +The pic diagrams preserve the logic of the original hand-drawn +ones, but are not exact geometrical duplicates. The proportions of +the flowchart elements are slightly different. + +In the original, sections were numbered only down to three +levels deep. No per-chapter tables of contents were present. + +The item lists bulleted a., b., c... and 1., 2, 3... in this +transcription were bulleted (a), (b), (c)... and (1), (2), (3)... +in the original. There does not seem to be a good way to generate +the original style in DocBook. + +Special characters like white square (□), back arrow +(←), and the Greek letters were hand-drawn in the original +(except for the capital thetas, which were typed capital Os with bars +hand-drawn across them). The script-S used in the original as a base +for subscripted labels has no ISO equivalent and has been transcribed as +a Greek letter sigma (&statement;). + +Footnotes were tagged with asterisks in the original rather than +being numbered. Section references to section numbers have been +replaced with xref tags; as a result, they may render slightly +differently than in the original. Notably, "section 1.1" becomes +"Section 1.11" (capitalized) and expressions like "sections 1.1.4 and +3.2" become "Section 1.1.4 and Section 3.2". We discovered while +transcribing that Chapter 1 must have been added at the last minute, +because references to Chapter 2 in the original had the form 1.x rather +than 2.x. + +EPSLON and COMPLX and the like are not typos. As pointed out +earlier, MAD variable names are limited to the 6 characters in a +six-bit character set that would fit in the IBM 709's 36-bit +word. + +A few typos in the original have been fixed. If you're really +curious, comments in the XML source describe them. + +The original was not continuously page-numbered. Instead the +pages were numbered within each chapter with the chapter number as +a prefix; thus, page 6 of Chapter I was I.6. + + + +The Michigan Algorithm Decoder + +The Michigan Algorithm Decoder (MAD) is a computer program +which translates algebraic statements describing algorithms to +the equivalent machine instructions. This descriptive language – +also called MAD – is explained in this manual. The language was +patterned after ALGOL 58, a proposed standard language for the +description of algorithms, with certain extensions and adaptations +which the authors believe make tbe language more useful. It +should be undergtood in what follows that a computer program may +consist of several sections utilizing the language described +herein or other languages if desired. The sections can be +translated independently and are linked together just prior to +the actual execution of the program. + +The original translating program was written for an IBM 704 +computer with 8192 words of magnetic core storage, 8192 words of +magnetic drum storage and 6 magnetic tapes. The program was +subsequently written for the IBM 790/90 computers with 32768 words +of core storage. The features described in the appendices are +included only in this later version. The programming and the +preparation of this manual were done at the University of Michigan +Computing Center, and the language has been widely used by +University of Michigan students and staff. + + B. Arden + B. Galler + R. Graham + + + +INTRODUCTION + +In order to present a problem to a digital computer for +solution, it is necessary to transmit to the machine a statement of +the problem, a procedure for solving it (usually called an algorithm +for the solution of that problem), and the data which is needed in the +solution. In fact, a statement of the problem is not really +necessary, since the algorithm and data are sufficent for a computer, +provided the algorithm is stated unambiguously and completely. + +As a simple example, let us consider the problem of determining +the largest number in a collection of n + 1 numbers A = { +a0, a1, +a2, ... an } with n ≥ +1. A verbal description of the procedure (algorithm) might be: + + + +Pick up the first number. + + +Compare it with the second number. + + +If the first is larger or if they are equal, keep the first one. + + +If the second is larger, keep the second one. + + +Whichever one was saved from this comparison is now compared with +the third number. + + +Continue to repeat steps 2 through 5 (each time moving down the +list) until the n+1st number has been included in the +comparison. + + +The number which has been finally saved is then the largest +number in the collection A. + + + +Unfortunately, this method of description is not very precise. +Such words as "compare", "moving down the list", and "finally saved" +should really be spelled out more exactly. + + + +The following restatement of the procedure would probably be +more suitable: + + + +Set Z = a0. + + +Let j = 1. + + +If J > n, the problem is doneThis test is redundant +the first time, but after n times through steps (3) - (6) it will +terminate the process for us. go to step 7; otherwise +go on. + + +If Z < aj, let Z = +aj; otherwise, go on. + + +Let j increase by 1. + + +Return to step 3. + + +Z is the answer. + + + +This may be illustrated by following "flow diagram": + + + + + + + +Note that the following conventions have been used here: + + + +Computation of subscripts or countiong occurs in diamond-shaped +boxes. + + +Actual computation occurs in rectangular boxes. + + +Decisions, based on comparisons occur in triangular +boxes. + + +The "=" inside computation boxes (both diamonds and rectangles) is +meant in the dynamic sense: "Compute the value of the expression on the +right and let that now be the value of the variable whose name appears +on the left." + + + + + +Although this problem does not require it, we frequently ask a +question like "Does j = n?" The "=" in this context is a +relation and yields either "YES or NO" when +placed between two arithmetic expressions. + +We return to the example problems. The algorithm exhibits an +important concept, which occurs in a great many procedurs; namely, it +contains a loop. A loop has the following +characteristic properties: + + + +It is repeated over and over until some conditions is satisfied +(occasionally this may be a very complex condition). In the example, +the condition was "j > n". + + +Before the first "iteration," some initialization may be +performed. In the example, Z - a0 and j = 1. + + +After the "body" of the loop is performed, (the comparison, in +the example), some variable is incremented, and the termination +conditions is tested again. In our example, j is increased by 1, and +if j ≤ n, the "body" of the loop is computed again - with the new +value of j. + + + +It is often convenient to take advantage of this standard structure of +a loop, and use an "iteration box" in the flow diagram. This box +would have to indicate the "scope"; i.e., the extent of the body of +the loop, the variable which is to be initialized and later +incremented, and the condition which will determine the number of +iterations in the execution of the loop. The contents of a typical +iteration box, (not related to the example above) might be: + +Repeat the computation through the box labelled (for example) +"BACK", starting with the variable α having the value 12, and +increasing it by the amount 3 after each time until either α > +90, or |x + y| ≤ ε. + +We shall abbreviate this by the form: + + +THROUGH BACK, FOR ALPHA = 12, 3 ALPHA .G. 90 .OR. .ABS. (X+Y) .LE. EPSLON + + +Here we have substituted ".G." for ">", ".LE." for "≤", +".ABS. (X+Y)" for "|x + y|". (The reason for these simple +substitutions is characters such as >, ≤ as input to the computer. +Such details are fully presented +in Chapter II of this manual.) + +The flow diagram for our previous example, then, may be +rewritten as follows: (In order to keep the notation familiar when +possible, the above-mentioned character substitutions will not be made +in diagrams.) + + + + + + + +The three operators specified in a "THROUGH" statement are +written in a single box to indicate the correspondence to a single +statement. + +The question still remains: How does one communicate the +algorithm to the computer? A translator such as MAD is designed +according to the philosophy: Once the algorithm has been stated, as in +a flow diagram, it should be presented to the computer directly in +that form, or as near to it as possible. The "translator" then has +the job of producing a translation from a flow diagram in a form +acceptable as input to the translator, the user's work ends with the +diagram itself. + +It should be remembered that the MAD language was designed with several +important criteria in mind: + + + +Speed of translation - the choice of some words of more than six +characters (e.g. WHENEVER, TRANSFER, THROUGH) enables the translator +to recognize the statement type with a minimum of analysis. + + +Generality - a few restrictions on the construction of +statements and expressions have been introduced as possible. + + + +Ease of adding to the language - desired additions can be +made easily, since most of the necessary information can be stored in +tables during translation. + + + +It is obvious that a different set of criteria could lead to a +different language. The details of the form of statements in this +"input language" are the subject of Chapter II.The +reader may find some clarifying effect if he rereads Chapter I after +reading Chapter II. + +We are concerned here with introducing some of the basic ideas, +such as the loop, etc. The input form of our example would be: + + +&min; + + +The DIMENSION statement assigns a block of storage in the +computer large enough to handle a0, +a1, a2, +... a100, if necessary. The INTEGER statement +declares J and N to be integers. We have already seen that different +shaped boxes are used for operations on integers, such as subscript +modification and counting. The reason for this is that integer +arithmetic can be done more simply and efficiently, usually with less +round-off error, than arithmetic on non-integers. [Numbers which may +have fractional parts are usually written in the so-called "scientific +notation", such as 3.1 x 10-6 are called +floating point numbers.] Numbers are assumed to be in the +floating-point mode unless otherwise declared, as in the INTEGER +statement in the example. The WHENEVER statement above is to be +interpreted in the sense: Whenever the following condition (in this +case Z < aj) is satisfied, do the specified +action (Z = aj), otherwise just go on. + +It is interesting to ask just how complicated a condition can be +used in making decisions. We have seen that such conditions may occur +in iterations statements, and "WHENEVER" statements, etc., for the +purose of making binary (i.e., "yes" or "no") choices. An expression +which can be labelled +"True" or "False" is exactly what is needed +here. Such expressions are called +BooleanAfter the logician George +Boole. expressions, and usually +involve "and", "or", "not", and possibly other such words connecting +shorter expressions involving <, ≤, =, ≠, >, and ≥. +For example, the following is a Boolean expression: + + + ((x - 3)3 < y and i ≤ j) or x ≥ 3 + + +This will be "true" for some values of x and y, and "false" for +others. It might then occur in statements such as: + + +WHENEVER ((X - 3) .P. 3 .L. Y .AND. I .LE. J) .OR. X .GE. 3, +TRANSFER TO AGAIN + + +or in the iteration statement + + +THROUGH ALPHA, FOR BETA = 1, 1, (X - 3) .P. 3 .L. Y .AND. +I. .LE. J) .OR. X .GE. 3 + + +where .P. denotes exponentiation (i.e., "to the power"). + +Returning again to the example problem on the largest of a set +of numbers, we observe that no provision was made for obtaining the +values of n, a0, a1, +..., an on which to perform our computation, +nor was any provision made for producing an answer. Normally, each +program would contain suitable input and output statements, such as +are described in Chapter II and illustrated in Chapter III. Let us +assume instead that we are interested in making out little algorithm +available for use in any other program, as a pre-packaged "function", +in the sense that, given n and a0, ..., +an, this function computes as its value the +largest of a0, ..., an. +In this case we shall call our algorithm an EXTERNAL FUNCTION, and +give it a name, say MAX., since it will be written and translated +externally with respect to the program which will later call upon it. +The program will now be written: + + + +&maxfunc; + + +The first statement specifies the inputs to the function to be N and +A, the second statement indicates the point of entry, the FUNCTION +RETURN statement specifies the value of Z as the desired value of the +function, and the other statements are as before. Any program using +the function now need only call upon it by name, as in the statement: + + +LARGEQ = 1. + MAS. (6,Q)/3. + + +Note that the set (in this use of MAX.) hose largest element is +desired is called Q, and N has the value 6. No DIMENSION statement is +needed for A is the EXTERNAL FUNCTION definition program above, since +A is there only as a "dummy variable", anyway. When +used, with a concrete set Q, we would expect a +DIMENSION statement for Q in the program that calls on MAX. for a +value. + +For a second example consider the problem of repeatedly solving, +by Newton's method, of the equation f(x) - +ax + x = 0, taking a different value for a +each time but with the restriction that a ≥ 1. This method involves +the repeated evaluation of the formula + + + + + + + +(the prime denotes the derivative with respect to x) until +xi+1 is a root - i.e., until +f(xi+1) = 0. Actually, in the numerical +solution of equations where we deal with approximate numbers the +latter condition becomes: until |f(xi+1)| < +ε, where ε is a small positive number. + +To evaluate the iterative formula above the first time it is +necessary to have an initial approximation, x0, +to the desired root. The use of the index, i, as well as the initial +subscript zero suggests that we will produce a sequence, +x0, x1, +... xn, of approximations to the root. +However, from the computational point of view we do no need all of +these values simultaneously, since to evaluate the formula it is +sufficient to know only the last value, x, produced. We can +say + + +x is replaced by x - f(x)/f'(x) + + +Often a left arrow (←) is used to mean "is replaced by" but +in the actual statements produced for the computer +the "=" symbol conventionally has this meaning. + +It is important to realize what the "=" means in this context; it is +different from the usual use of the symbol where it indicated a +relation. When the "=" symbol is used as such a +"replacement operator" the item on the left of the "=" is always the +name of a variable. The +variable may have a complicated subscript but nevertheless it is not +an expression, but the name of a variable. The item on the right of +the symbol is an expression involving one or more constants, +variables, etc. The operation implied is simply that the value of the +express on the right becomes the value of the +variable whose name appears on the left. This is referred to as +substitution. + +For our specific example, then, the evaluation of the iterative +formula could be described as + + + + + + + + +although we will for convenience break this into two statements. +The entire computational procedure can be represented by the following +flow diagram. + + + + + + + + + + +The corresponding statements are: + + +&newton1; + + + +The first statement, labelled ST, causes a value for a,x, +and ε to be read into computer storage. A block of adjacent +storage location in the computer (a "vector") named ALPHA is +designated as containing a description of how the three +numbers were punched on the card. (This description – which +is the value of ALPHA – is described in a later statement; see +(9) below.) + +The second statement is a simple conditional which causes +the statement labelled PRT to be the next one executed if a < +1. Otherwise, the next one in ssequence (labelled REPEAT in +this case) will be executed. + +The statement labelled REPEAT computes +ax + x using the current value of x, and +places the result of this computation in a storage location named +F. + +The next statement divides the value F of the function +by the derivative of the function (loge a +· ax + 1.0), evaluated using the +current value of x, subtracts this quotient from the current value of +x and the resulting difference is stored as the current value of x. +The name ELOG. is the name for the function +loge and the item in parentheses following this +name indicated the variable whose natural logarithm is +desired. + + + +The following statement is a simple conditional which +causes the function and iterative formula to be evaluated +again if |f(x)| ≥ ε. Otherwise, (i.e., |f(x)| < +ε), the next statement in sequence is executed. + +The PRINT statement causes three numbers - the current +values of a, x and ε to be printed. The arrangement and form +of the numbers on the printed page are controlled by the +format description which is the value of the vector named +ALPHA. + +The TRANSFER statement following causes the statement +labelled ST to be the next one performed. + +The statement labelled PRT is the one executed immediately +after the first statement whenever a < 1.0. This statement +causes the current value of a to be printed (here a must be < +1.0) according to a format description stored in BETA. The +format description also causes the printing of some constant +alphabetic information preceding thenumber; namely, the remark +"A TOO SMALL, A = ". + +The next two statements following the last TRANSFER TO ST +set the initial values of two vectors named ALPHA and BETA. +Although VECTOR VALUES statements can be used to preset +vectors to specified numeric values, in both instances here +the values are format descriptions. The +strings of characters between the dollar signs (MAD quotation +marks!) are to be taken literally as they appear and stored in +designated vectors. The actual format specifications are +described in more detail in Chapter II, but, for example, the +first description: S1,3F15.6* means that the first item is to +be a space (S1), followed by three (3) numbers printed with a +decimal point but no exponent (F), each occupying fifteen card +or print positions (15), and that there will be six positions +to the right of the decimal point (.6). The asterisk (*) +indicates the termination of the description. + + The final statement indicates the end of the statements +and is the last statement executed when a definite termination +to the problem is known. In our particular example, the +computer would continue until it has exhausted the given input +values of a, x, ε. + + + + +The final example before the description of the language in +Chapter II is a more general and more elaborate illustration of +Newton's method. Here, we consider the solution of the equation +x3 + ax2 + bx + +c = 0, starting with some input value for x0, +using the iterative formula: + + + + + + + +which is obtained from the standard Newton's Method formula + + + + + + + + + +for the problem f(x) = 0. (Here f(x) = +x3 + ax2 + bx + +c). We shall specify quantities ε1 and +ε2, and stop the iteration when the +following condition is satisfied: + +
+(|xi+1 - xi| < ε1 +and +|f(xi| < ε2) +or +i ≤ n0 +
+ +where n0 is some upper limit to the +number of equations which we can tolerate. The inequaliies involving +ε1 and ε2 may +be illustrated by the graph below, We are requiring that at +xi the value of the function +f(xi) be between the upper and lower bounds +ε1 and -ε2. +Also the distance d between xi+1 and +xi should be less than +ε1. Observe that we are never concerned +with more than two successive aproximations to the root — say x +and xm (for next x) — and that the +incrementing of i is not really necessary. + + + + + + + + + + + + +&newton2; + + +The first statement, labelled GAMMA, would cause the program to +read from the data card the numbers a, b, c, x0, +ε=1, ε2, and +n0. The format of the input information is to +be found in a block of storage labelled "CARD" whose values are set +later in the program by a VECTOR VALUES statement. The vector CARD +actually has as values the format information in alphabetic form +(sometimes called HOllerith, or binary-coded decimal (BCD) form). The +con­struction and analysis of format information is thoroughly +discussed in Chapter II. + + +The second statement in the program causes the inout information, +properly labeled., to print out, preceded by the title "SOLUTION OF +CUBIC EQUATION". The appropriate alphabetic information is contained +in the format information which is t be found in the vecvtor TITLE, as +set by a VECTOR VALUES statement later in the program. + + +Two functions are defined in this program, and each is +designated as an INTERNAL FUNCTION. The statement following that +whuich is labelled BETA illustrates a conditional output statement. +If the iteration is terminated because i ≥ +n0, the alphabetic information NO CONVERGENCE +is printed before the values of I and X are printed, otherwise that +remark is not printed. The final transfer to GAMMA cause the program +to start over with a new set of data, if additional data is present, +otherwise, the computation is automatically terminated. + +The VECTOR VALUES statement, illustrated here, may be used to +cause vectors (and matrices) to be initialized to any desired value +(even alphabetic values) before the program computation is begun. Of +course, these values could be computed or read in as input, if +desired, so that the data for a problem could be preceded by its own +description of format, in problems where the format may change from +one set of data to another. +
+ +DESCRIPTION OF THE LANGUAGE + +Constants, Variables, Operations, and Expressions + +Constants + +There are four classes of constants: Integer, floating point, +alphabetic, and Boolean. + +Integer Constants + +Integer constants contain from 2 to 10 decimal digits. The +decimal point is assumed to be immediately to the right of the +rightmost digit, but is always omitted. Integers +may be positive or negative, and while the "+" sign may be omitted, +the "-" sign must be present if the number is negative (e.g., 2, -2, 0, ++0, -0. 100 are all integers). Leading (but not following) zeros may +be omitted (e.g., 5 and 005 represent the same integer, but 3 and 300 +do not. + + +Floating Point Constants + +Floating point constants may be written with or without +exponents. If written without an exponent, the constant contains from +one to eight digits and a decimal point ".", which must be written, +but which may appear anywhere in the number. Thus, 0., 1.5, -0.05, ++100.0, .1 and -4. are all floating-point constants. If the number is +written with an exponent, it must contain from one to eight digits +with or without a decimal point, followed by the letter "E", followed +by the exponent of the power of 10 that multiplies the number. (If +the decimal point is omitted, it is assumed to be immediately to the +left of the letter "E".) The exponent m consists of one or two digits +preceded by a sign (although a "+" sign may be omitted), and must +satisfy the condition -38 ≥ m ≥ 38. Examples of floating-point +constants with exponent are; + + + +.05E-2(= .05 × 10-2) -.05E2(= -.05 +× 102), +5E02(=5.0×102), +5.E2(-5.0×102). + +Negative floating point constants must be preceded by a +"-" sign. Positive constants may be preceded by a "+" sign. + + +Alphabetic Constants +An alphabetic consists of from one to six admissible +characters preceded and followed by the character "$". The admiss- +ible characters include all letters of the alphabet, the digits 0 +through 9, the special characters +, -(minus sign), -(dash), *, +/, =, ). (. ., the comma "," and the blank space, to be represented +here occasionally (but not punched on input cards), as the character +"□". Thus the following are alphabetic constants: $ABCD$, $TO BE$, +$DEC. 4$, $5 +3=8$. Note that blank spaces, while ignored elsewhere +in the language, count as characters in alphabetic constants. An +alphabetic constant is stored internally as an integer, and any +constant containing fewer than six characters will be extended to six +characters by adding blanks on the right; thus $ABCD$ will appear +internally as $ABCD□□$ + + + +Boolean Constants +There are two Boolean constants – "true", which is written +1B, and "false" which is written 0B. + + +Variables + +The name of a variable consists of one to six letters or digits, +the first of which must be a letter. If the variable is defined as an +n-dimensional array variable (see section 3.3) then the name of an +element of the array consists of the variable name, (i.e one to six +letters or digits, starting with a letter), followed by the +appropriate subscripts separated by commas and enclosed in +parentheses. Thus the following are "single variables:": X51, ALPHA6, +LAMBDA, GROSS, while the following are elements of arrays: BETA(C1, +C2, 6), X15(Y, Z1), J(6), J(Z1 + 5 *Z2, 5). (See for the description of subscripts.) Parentheses +enclosing subscripts may not be omitted. + + + + +Statement Labels A statement may be +labelled or unlabelled. Labels are used to refer to a statement in +other statements. A statement label consists of from one to six +letters or digits, the first of which must be a letter, e.g. IN or +BACK. A statement label may be an element of a statement label +vector, in which case the vector name is followed by a +constant integer subscript enclosed in +parentheses, e.g. S(2) or LBL(3). A statement label appears in the +label field (i.e. columns 1-10) of the statement it identifies. When +a statement extends to additional cards (i.e. cards identified by a +digit punched in col. 11) the statement label need not be punched on +the additional cards. + + +Functions +The name of a function consists of one to six letters or digits +followed by a period "." which must be written. The first character +of a function name must be a letter. If the function is +single-valued, then the value of the function is represented by +following the function name by the proper number of arguments (see +section 3.8 for the definition of function) separated by commas and +enclosed in parentheses. Thus, ADD51., COS., POLY., and FUNCT3. are +function names, while ADD51. (X,Y,ADD.), POLY. (N, VJ, 7) and COS. (X) +are values of functions. + + +Arithmetic Operations +The following arithmetic operations are available: + + +Addition, written as "+", e.g., Z5 + D. + +Subtraction, written as "-", e.g., Z5 - D. (Note, +both the minus sign and the dash are accepted.) + +Multiplication, written as "*", e.g. Z5*D. (Note that the +"*" may not be omitted. It is illegal to write Z5D, since it +would be impossible to distinguish such a product from the +variable Z5D.) + +Division, written as "/"; e.g., Z5/D. If both Z5 and D +are integers, the result is again an integer; e.g., the +"fractional part" of the true quotient is truncated (not +rounded). For example, if Z5 = 7, and D = 3, the Z5 = D will +have the value 2. + + +Exponentiation, written as ".P.", e.g., Z5.P.D, and +meaning (Z5)D, i.e., Z5 raised to the power +D. + +Negation, written as "-", e.g., -ALOHA, meaning the +"negative of ALOHA." Thus-X.P.-.5 +means-(X-.5). + + + + + +Arithmetic Expressions + +Arithmetic expressions are defined inductively as follows: + + +All integer, floating point, and alphabetic constants, +integer and floating point individual variables, subscripted integer +and floating point array variables, and integer and floating point +values of functions are arithmetic expressions. + +If E and F are any arithmetic expressions and V and +individual or subscripted array variable, then the following +are also arithmetic expressions: +E, -E, .ABS.E, E + F, E - F, +E * F, E/F, E.P.F, and (E). + +The only arithmetic expressions are those arising in +(a) and (b). + + + +Boolean Operations +The following Boolean, or logical, oeprations are available in the +language (where M and P are boolean expressions): + + +.NOT.M has the value 1B if and only if M has the value +0B. + +(M) has the same value as M. + +M.OR.P has the value 0B if and only if both M and P +have the value 0B. + +M.AND.P has the value 1B if and only if both M and P +have the value 1B. + +M.THEN.P has the value 0B if and only if M has the +value 1B and P has the value 0B. + + + +M.EQV.P has the value 1B if and only if M and P have +the same values. + + +Thus, .NOT., .OR., .AND., .THEN., AND .EQV. correspond to the +usual logical operations, ~, ∨, ∧, ⊃, and ≡. + + +Boolean Expressions + +Boolean expressions are defined inductively as follows: + + +Boolean constants, Boolean individual variables, +Boolean subscripted array variables and Boolean-valued functions are +Boolean expressions. (see and +section 3.2). + +If H and F are arithmetic expressions: then H.L.F., +H.LE.F, H.E.F., H.NE.F, H.G.F., H.GE.F, are Boolean +expressions, where the meanings are H < F, H ≤ F, H = F, H ≠ +F, H > F, and H ≥ F, respectively. + +If M and P are Boolean expressions, then the following are +also Boolean expressions: .NOT.M,(M), M.OR.P, M.AND.P, +M.THEN.P, and M.EQV.P. + +The only Boolean expressions are those that arise in (a), +(b), and (c). + + +Examples of Boolean expressions are: (X .G. 3 .AND. Y .LE. 2) +.OR. (GAMMA .L. EPSILN), and ((P .AND. Q) .THEN. Q) .EQV. (P +.OR. .NOT.P), where P and Q are Boolean variables. + + +Parentheses Conventions + +Parentheses are used in the same way as in ordinary algebra and logic +to specify the order of the computation. Also, certain conventions +are used to allow deletion of parentheses. The conventions used here +are the same as in ordinary algebra and logic, namely: Parentheses may +be omitted, subject to the rules (A) and (B) below, but redundant +parentheses are allowed. + +(A) Within any expression the sequence of computation, unless +otherwise indicated by parentheses, is: + + + + .ABS., + (as unary operations) + .P. + - (as a unary operator) + *, / + +, - (as binary operations, i.e., addition and subtraction) + + .E., .NE., .G., .GE., .L., .LE. + .NOT. + .AND. + .OR. + .THEN. + .EQV. + , (as used to separate function arguments) + = + + +Examples: + + + (1) .ABS.(B - C) means |B - C|, while .ABS.B - C means |B| - C. + (2) -B + C means (-B) + (C), while -(B + C) means the negation of + the sum. + (3) B.P. - X + Y means B-X + Y, while B.P.(-X + Y) means B-X+Y. + (4) K2/Z - 3 (K2/Z) - 3, while K2/(Z - 3) implies that Z - 3 is + the denominator. + (5) A * B + C means (A * B) + C. + (6) A.P.3/J means (A3)/J + (7) X.L. Y + 3 means (X) .L. (Y + 3). + (8) P.AND..NOT.P .EQV.Q means (P.AND.(.NOT.P)).EQV.Q. + (9) Z = X + Y /QA means Z = (X + Y/QA)) + (10) A = -B.P.X means A = -(BX). + + +(B) Within an expression operations appearing on the same line +of the list in (A) are to be performed from left to right, unless +otherwise indicated by parentheses. + + +Examples: + + + (1) A + B - C + D - E means (((A + B) - C) + D) - E. + (2) X/Z * Y/R * S means (((X/Z) * Y/R) * S. + + + +Mode of Expressions + +The kind of arithmetic performed on a constant, variable or +function value is determined by its mode. There are five modes in +MAD; floating point, integer, Boolean, statement label, and function +name. Floating point, integer, and Boolean constants were described +in . Alphabetic constants are assumed to +be of integer mode. Section 3.2 describes how the modes of variables +and functions are specified. + +If an expression consists entirely of one constant, one +variable, or one function value, the mode is that of the constant, +variable, of functional value itself. If the expression is a compound +expression; i.e., consists of two or more subexpressions joined by +logical or arithmetic operations, the following rule applies: + +If an expression is a Boolean expression as defined in , then its mode is Boolean. An +arithmetic expression is considered to be in the floating point mode +if any operand of any arithmetic expression in the expression is in +the floating point mode. If all operands are integer (or alphabetic), +then the expression is conisdered to be in the integer mode. In this +determination arguments, though not values, of functions are +ignored. + +Thus, if Y, Z, and W are floating point variables, while the +function GCD. and the variables I and J are in the integer mode, then +the expressions + + + Y = GCD.(I, J) + Y + Z - I + I + 1. + GCD. (I, J)/Z + + +are all floating point expressions while the expressions + + + I + GCD.(I, J) + (I + J)/3 + I + 1 + GCD.(I, J)/I + + +are all integer expressions. + +If an expression has subexpressions of different modes, a conversion +may be necessary before some of the operations can be performed. +Thus, in the expression + + + Y + 3 + + +if Y is in the floating point mode it cannot be added directly +to the integer 3. But for one precaution the user need not be +concerned with this since the instructions necessary for the +conversion of the integer to floating point form before adding are +automatically inserted by the translator during the translation +process. The precaution is that if the integer being converted is +greater than 134,217,728 (i.e. 227) then an +improper conversion will take place. + +In some cases, however, the user must understand the sequence in +which the conversions will be made. Consider the expression + + + ( Y + 7/3) + (I * J/K) + + +where Y is in the floating point mode, and I, J, and K are in the +integer mode. According to the parenthesizing conventions, the +computation will proceed in the following order (where the T's are +temporary locations): + + + T1 = I * J + T2 = T1/K + T3 = 7/3 + T4 = Y + T3 + T5 = T4 + T2 + + +and T5 will be the value of the +expression. + +Now, since both I and J are integers, the first multiplication +will be integer multiplication, and T1 will be +an integer. Since the following involves two integers, it will be +integer division, and, if K happens to have a larger value than +T1 the quotient is 0. Similarly, +T3 will have the value 2 because of the +division of two integers. In the computation of +T4, however, we have "mixed modes", since Y is +floating point and T3 is integer. There +I3 will be automatically converted to floating +point before adding. Likewise, in the next step, the integer T2 will be converted to floating +point before adding to the floating point number. + +In other words, although the mode of the expression is floating +point because of the presence of the floating point variable Y, some +of the computation (until Y is involved) is performed in integer +arithmetic, and this may occasionally cause the final value to be +different from the value one might expect from a different analysis. + +In the example above, the divisions would be performed in the +floating point mode if the expression were written: + + + (Y + 7./3) + (I * J)/(K + 0.) + + +Of course, many times the expression will be written as +originally stated just to achieve the "truncation" effect. + +A statement label (appearing in the label field of a statement) is a +constant of statement label mode. A function name with no arguments +(e.g. SIN.) is a constant of a function name mode. A single constant, +variable, or function value of statement label (function name) mode is +an expression of statement label (function name) mode. There are no +other expressions of statement label (function name) mode. If A and B +are both statement label (function name) expressions then A.E.B. and +A.NE.B are Boolean expressions except when A or B are elements of a +vactor which has been preset by a VECTOR VALUES statement (see section +3.7). In this exceptional case A.E.B. and A.NE.B are not expressions. + + +Subscript Expressions + +Any arithmetic expression may be used as a +subscript expression for an element of a linear array. If the value +of the expression is in the floating point mode (see +), it is truncated to integer form before +being used as a subscript. The expressions for subscripts of elements +of an array whose dimension is two or greater must be of integer +mode. Moreover, for arrays of dimension three or greater the use of +subscripts having other than integer mode will not be caught as an +error. Subscript expressions may contain variables with subscripts, +etc. + +Examples of subscripted variables: J(3), K10(Z + 5 * XY/T), +MP(A, B + 6 * J, I * 6/TDX), MA(K(Z + 5) + T(1) + 6). + + + +Statements (Executable) + +Substitution Statement + + +This statement has the form illustrated by + + + ALPHA = Y + Z + F.(X, Y, Z) + + +That is, the left side of the "=" sign consists of the name of a +variable (either an individual variable or a subscripted array +variable), and the right side consists of any expression of the same +mode. The only exceptions to this mode requirement are the cases: (1) +If the variable on the left is of integer mode then the value of a +floating point expression of the right will be converted to integer +mode. (2) if the variable on the left is of floating point mode then +the value of an integer expression on the right will be converted to +floating point mode. + +The substitution statement is to be interpreted as "(1) Compute the +value of the expression on the right, (2) convert it, if necessary, to +the mode of the variable on the left of the "=" sign, and (3) give the +variable on the left the value which results from steps (1) and (2)." +(See for mode of expressions.) + +Thus, if Y is a floating point variable, then the statement + + + Y = 1 + + +will cause the integer 1 to be converted to floating point and then +stored in the location called "Y"; i.e., Y will now have the value 1. +(as a floating point number). If the statement were written + + + Y = 1. + + +then the floating point number 1. would be stored in the +location "Y"; i.e., Y would again have the floating point value 1., +but in this case the conversation of the integer is unnecessary, thus +speeding up the computation. + +When a floating point number is to be converted to an integer, +it is first expressed as a number with both an integer part and a +fractional part, and then the fractional part is truncated. Thus, the +following floating point numbers: + + + 3E5, .3E0, .34568127E2, - .345681E10 + + +would convert to the following integers, respectively: + + + 300000, 0, 34, -3456810000. + + + +Transfer Statement + +This statement has the form: TRANSFER TO &statement; + +Here &statement; may be any statement label or any expression in + +statement label mode which labels an executable statement. Execution +of this statement causes the computation to continue from the +statement whose label is the value of &statement;. Examples: TRANSFER TO +SUMX, TRANSFER TO SWTCH (K + 2) (if K=4 then the value of SWTCH(K+2) +is SWTCH(6)). + + + +Conditional Statements + +There are two types of conditional statements. + +(a) Simple Conditional + + + WHENEVER B,Q + + +Here B is a Boolean expression and Q any executable statement +except the following: end of program, another conditional, iteration, +and function entry. If at the time of execution of this statement, +the expression B has the value 1B, the statement Q is executed. If, +however, B=0B, then Q is skipped and computation continues from the +next statement in sequence. The comma in this statement, as in other +statements containing punctuation, must be written. + +Examples: + + + WHENEVER XM.LE.1, TRANSFER TO END + WHENEVER I.GE.N.AND.J.NE.I-1, I=0 + + + +(b) Compound Conditional + + + + + &statement;1 WHENEVER B1 + + ... + ... &THgr;1 + + &statement;2 OR WHENEVER B2 + ... + ... &THgr;2 + ... + ... + &statement;k OR WHENEVER Bk + ... + ... &THgr;k + &statement;k+1 END OF CONDITIONAL + + +Often the last condition Bk is always +true. This may be epxressed by the statement + + + + OR WHENEVER 1B + + +or alternately the statement + + + OTHERWISE + + +The &statement;i are statement labels which +need not be used unless desired. k may equal one (if no "OR +WHENEVER..." statements are used). Here B1, +..., Bk are Boolean expressions, and the +execution of this block of statements is as follows. + +Each B1 is tested in turn, starting with +B1. It B1 has the value +0B, then B2 is tested, etc. As soon as some +expression, say Bj, has the value 1B, then the +statements between (but not including) +&statement;j and +&statement;j+1 +(i.e. &THgr;j) are executed. At this point the +execution of the entire block is considered ended, and computation +continues from the first statement after the declaration labelled +&statement;k+1. In other words, at most one of +the alternative computations is performed; e.g., that one which +immediately follows the first expression B1 +which has the value 1B. If none of the Bi has +the value 1B, none of the computation in the scope of these statements +is performed. + +Example: The evaluation of the function whose graph is + + + + + + + +might be given by the section of the program: + + + WHENEVER X .LE. 0. .OR. 1. .LE. X .AND. X .L. 2. .OR. X .GE.3 + Y = 0. + OR WHENEVER 0 .LE. X .AND. X. .L. 3. + Y = 1. + END OF CONDITIONAL + + +This section of program could be rewritten in another way. + + + + WHENEVER 0. .LE. X .AND. X .L. 1. + Y = X + OR WHENEVER 2. .LE. X .AND. X .L. 3. + Y = 1. + OTHERWISE + Y = 0. + END OF CONDITIONAL + + +The indentation of the statements between the conditional statements +is not required but contributes to the readability. + + +CONTINUE Statement + +This statement has the simple form: + + + CONTINUE + + +It serves as an entry point in the program, and causes no computation +to be performed by its presence or absence. + + +THROUGH (Iteration) Statement + +The following program segment illustrates the use of this +statement. + + + . + . + . + A = D(1, 1) + THROUGH ST1, FOR I = 1, I .G. 10 + THROUGH ST1, FOR J = 1, J .G. 10 + WHENEVER A .LE. D(I, J), TRANSFER TO ST1 + K = I + L = J + ST1 CONTINUE + . + . + . + + +This statement casues the block of statements which follows +immediately afterwards to be repeatedly executed, each time varying +the value of some variable, until the specified list of values for +that variable is exhausted, or until some specified condition is +satisfied. The THROUGH statement may take either of the following two +forms. + +(a) THROUGH &statement;, FOR VALUES OF V = +E1, E2, ..., +Em Here &statement; is the statement +label of the last executable statement in the block to be repeated. +The block of statements following (and not including) the THROUGH +statement, up to and including the statement +whose label is &statement;, will be called the "scope" of the THROUGH +statement. Following the word OF appears the name of the iteration +variable (in the illustration: V), which may be +either an individual variable or subscripted array variable of any +mode. To the right of the "=" sign may appear any number of +expressions E1, ... Em. +The modes of the E1 bear the same relationship +to the mode of V as they would in the statement V = +E1 (see ). + +The execution of this statement causes the statements within its +"scope" to be executed, first with V = E1, then +again with V = E2, and so on, until the list of +expressions is exhausted. Computation then proceeds with the +statement immediately following statement &statement;. At this time the +iteration variable will have the value of the expression +Em unless its value was +changed during the final iteration. An example of this type of +statement is: + + + THROUGH A, FOR VALUES OF BETA = 3, 4, X5, Y(6 + I) + 3 + J = 5 = BETA + 6 + J1 = J .P..5 - 1 + A X(BETA) = J1 * COS.(2. * THETA) + + +(b) THROUGH &statement;, FOR V = E1, +E2, B + +Here &statement; is a statement which defines the "scope" exactly +as in (a) above (with the exception: If &statement; is the label of the +THROUGH statement itself, the iteration will proceed as described +below, but the scope will be empty, and the iteration will consist +only of the incrementing of V by E2 and the +testing.) Following the word FOR is the name of the iteration +variable (in the illustration: V), which may be an individual variable +or subscripted array variable of any mode. The modes of +E1 and E2 are subject to +the rules which would apply to the statements V = +E1 and V = V + E2. B is +a Boolean expression. + +The execution of the statement proceeds as follows: The variable +V is set equal to E1. If the value of B = 1B, +the scope of the THROUGH statement is not executed. If the value of B += 0B, the scope is executed. V is then incremented by +E2, and B is tested again. In general, as soon +as B = 1B, the scope is not executed, and the computation proceeds +from the statement immediately following statement &statement;. Each +time B = 0B, the statements in the scope are executed, then V is +incremented by E2, and B is tested again. +Thus, when the iteration is finished and B = 1B, V has the value used +during the last computation of the scope, incremented by +E2. The scope will not have been executed for +this value of V. (The value of V will be E1, +of course, if B = 1B before the scope is executed at all.) If, at any +time, the computation transfers out of the iteration to another part +of the program, the value of V will be the current value at the time +the transfer was made. + +In all cases, every reference to an expression +E1 will involve its current value at the time +of reference. Moreover, the variable V may have +its value changed at any time during the execution of the +scope. + + + + +