From: Eric S. Raymond Date: Thu, 11 Mar 2004 06:29:24 +0000 (+0000) Subject: Chapter II is typed in. X-Git-Tag: 1.0~41 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=95362044f684edeba0b652c43b5ed38e3c99a8d5;p=mad.git Chapter II is typed in. --- diff --git a/doc/mad-manual.xml b/doc/mad-manual.xml index 9b76c6b..c376187 100644 --- a/doc/mad-manual.xml +++ b/doc/mad-manual.xml @@ -6,6 +6,7 @@ + @@ -466,6 +467,7 @@ ugly by contrast. + The Michigan Algorithm Decoder The Michigan Algorithm Decoder (MAD) is a computer program @@ -496,7 +498,7 @@ University of Michigan students and staff. R. Graham - + INTRODUCTION In order to present a problem to a digital computer for @@ -545,7 +547,7 @@ number in the collection A. 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: @@ -608,7 +610,7 @@ 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 @@ -661,8 +663,9 @@ 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 the lack of characters such as >, ≤ as input to -the computer. Such details are fully presented in -Chapter II of this manual.) +the computer. Such details are fully presented + +in Chapter II of this manual.) The IBM 704 on which MAD was implemented had a very primitive pre-ASCII character set. It did not even include @@ -707,7 +710,7 @@ 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 @@ -755,14 +758,15 @@ action (Z = aj), otherwise just go on. 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: +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 @@ -802,7 +806,7 @@ 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; @@ -860,8 +864,10 @@ 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. +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 @@ -897,7 +903,7 @@ flow diagram. - + The corresponding statements are: @@ -934,7 +940,7 @@ 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 @@ -981,7 +987,7 @@ 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 @@ -1034,7 +1040,7 @@ 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. - + @@ -1043,7 +1049,7 @@ incrementing of i is not really necessary. - + + The second statement in the program causes the inout information, properly labeled., to print out, preceded by the title "SOLUTION OF @@ -1091,6 +1097,7 @@ 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 @@ -1134,7 +1141,7 @@ 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), @@ -1185,10 +1192,10 @@ 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. +be omitted. - + Statement Labels @@ -1238,7 +1245,7 @@ are integers, the result is again an integer; e.g., the 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. @@ -1290,7 +1297,7 @@ 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. @@ -1340,7 +1347,7 @@ parentheses are allowed. (A) Within any expression the sequence of computation, unless otherwise indicated by parentheses, is: - + .ABS., + (as unary operations) .P. @@ -1378,7 +1385,7 @@ otherwise indicated by parentheses, is: of the list in (A) are to be performed from left to right, unless otherwise indicated by parentheses. - + Examples: @@ -1431,7 +1438,7 @@ I + GCD.(I, J) I + 1 GCD.(I, J)/I - + are all integer expressions. If an expression has subexpressions of different modes, a conversion @@ -1484,8 +1491,9 @@ 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. 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 @@ -1539,7 +1547,7 @@ MP(A, B + 6 * J, I * 6/TDX), MA(K(Z + 5) + T(1) + 6). Substitution Statement - + This statement has the form illustrated by @@ -1602,7 +1610,7 @@ following floating point numbers: This statement has the form: TRANSFER TO &scriptS; Here &scriptS; 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 &scriptS;. Examples: TRANSFER TO @@ -1660,7 +1668,7 @@ WHENEVER I.GE.N.AND.J.NE.I-1, I=0 Often the last condition Bk is always true. This may be expressed by the statement - + OR WHENEVER 1B @@ -1715,7 +1723,7 @@ END OF CONDITIONAL This section of program could be rewritten in another way. - + WHENEVER 0. .LE. X .AND. X .L. 1. Y = X @@ -1778,13 +1786,15 @@ The block of statements following (and not including) the THROUGH statement, up to and including the statement whose label is &scriptS;, 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 ). +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 @@ -1792,9 +1802,10 @@ again with V = E2, and so on, until the list of expressions is exhausted. Computation then proceeds with the statement immediately following statement &scriptS;. 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: +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 @@ -1839,12 +1850,13 @@ 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. In a -statement of the form (a), the value of V will be reset by the value -of the next E1 for the next computation of the -scope. In a statement of form (b), the current value of V will be -used for incrementing, testing, etc. +of reference. Moreover, the variable + +V may have its value changed at any time during the execution of the +scope. In a statement of the form (a), the value of V will be reset +by the value of the next E1 for the next +computation of the scope. In a statement of form (b), the current +value of V will be used for incrementing, testing, etc. Examples: @@ -1891,7 +1903,7 @@ iteration is to be performed for those multiples of 2 which are not multiples of 5 and which are less than the value of the integer K, one might write the iteration as follows: - + THROUGH END, FOR J = 2, .GE. K @@ -1938,7 +1950,7 @@ themselves, be iteration statements. However, if iteration statement be entirely within the scope of a. The following diagrams represent some valid configurations: - + &scope1; Here, although the scopes of a and @@ -1953,7 +1965,7 @@ iteration b is completed before iteration &scope3; - + When iteration statements occur in the scope of other iteration statements, they are said to be "nested". The "nesting depth" of an iteration statement is the number of iteration statements in whose @@ -1973,7 +1985,7 @@ statements in the scope of an iteration. - + Pause Statement @@ -3372,22 +3384,161 @@ statements define a function). If this is defining an external function, the declaration would be EXTERNAL FUNCTION (X). Following the words INTERNAL (or EXTERNAL) FUNCTION is the dummy variable list ((X) in this example). The END OF FUNCTION declaration is the last -statement in the function definition program. (In an external - +statement in the function definition program. (In an external + function definition this is also the last statement in the program.) An entry must provided for each function being defined, but several functions may share any number of FUNCTION RETURN statements. An entry statement merely marks a point of entry, and does not effect the sequence of computation in any way. The expression after the word "RETURN" indicates that on this return the value of the function is to -be the value of that expression. +be the value of that expression. This expression must agree in mode +with the function whose value it supplies; this agreement is not +checked. The definitions of functions whose calls are intended to be +included in expressions must have an expression following the FUNCTION +RETURN statement. If the calls for a function are to appear in an +EXECUTE STATEMENT (generally such functions have multiple outputs) the +FUNCTION RETURN statement may appear without an accompanying +expression. - +An example of a definition for procedures is as follows: + +EXTERNAL FUNCTION (M, N, I, P, Q) +STATEMENT LABEL N, I +... +... +... +FUNCTION RETURN +... +... +... +WHENEVER B, TRANSFER TO I +... +... +... +TRANSFER TO N +END OF FUNCTION + + +In this example, N and I are actual alternate exits, and B represents +some Boolean expression. + +It is important to note that internal function definitions of +any kind whatever (including the single statement definition of ) may occur anywhere in the program, +except within another internal function definition. Internal function +definitions may occur within external function definitions, however. +External function definitions may not occur within any other programs, +not even within other external function definitions. Each external +function definition must be a complete, self-contained program. + + +The following is an example of a function whose value is 1/x if +0 < x ≤ 1 and 1/x^2 if x > 1. If x ≤ 0, one obtains an +error return (see ). + + +&invsf; + + +(Here the statments are all labelled only for reference in what +follows.) + +The list of dummy variables in the declaration statement itself +(statement A in the preceding paragraph) may contain only +nonsubscripted variable names (either individual or array) or function +names (without arguments). Within the definition program itself (the +statements between statement A and statement B), a function name will +usually occur with arguments, and an array variable will usually occur +with subscripts. + +A few comments about the last example. This definition program +defines a single-valued function of X, called INVSF.. Since no mode +declaration is given it is assumed by the translator that X is +floating point. The value of INVSF.(X) is computed by the use of a +compound conditional. If 0 < x ≤ 1, (statement G) then statement C +is executed, causing a return to the calling program with the value +1/x. If the condition 0 < x ≤ 1 is not true, then the condition X +> 1 is tested (statement H). If X > 1, statement D is executed. +Finally, if neither of the conditions 0 < x ≤ 1 or x > 1 is true, +then statement I finds that X ≤ 0 and statement E (the error +return) is executed. If + + + + + A = B - D + Z = T(I) + INVSF.(Y) *T(I-1) + Y(I) = Z + R(J) * 2.5 + + +is part of a program and the error return statement is executed during +the evaluation of INVSF.(Y) (i.e., Y ≤ 0), then control is returned to +the system in which the translated program is embedded, with an error +flag set. If + + + A = B - D + F Z = T(X) + INVSF.(Y, ER)* T(I-1) + S Y(I) = Z = R(J) * 2.5 + ... + ... + ER Z = 0 + L Y(I) = 1. + ... + + +is part of a program and Y ≤ 0, then when the ERROR RETURN +statement is executed control transfers to statement ER (then goes on +to L), instead of finishing the execution of statement F (and then +going on to S). Note that the END OF FUNCTION statement will never be +executed, but must be present in the definition. + +Restrictions + +Variable names appearing as dummy arguments in +any function declaration may not appear in a PROGRAM COMMON, ERASABLE, +or EQUIVALENCE declaration. + +The name of a function with the period deleted must not be used as the +name of a variable or as a statement label. A statement label must +not be identical with any variable name. + +The translator automatically calls on some subroutines, hence the +following names may not be used as variable names or statement labels +in a MAD program. They may be used as function names only when +referring to these subroutines. (These subroutines will be described +in Chapter 4). + + + SYSTEM. SETEOF. PRINT. READ. + ERROR. SETETT. COMMNT. TAPERD. + TAPEWR. PUNCH. SETERR. + + + +If a block designation +A(i1,...,in)...A(ji,...,jn) +is used in an input-output list &scriptL; for reading or writing + binary tape or drum , the +linear subscript corresponding to +ii,...in may not +be greater than the linear subscript corresponding to +J1,...,jn. +While the list for a binary tape or drum statement is transmitted in +the sequence written, a block +A(i1,...,in)...A(j1,...,jn) +within the list is actually transmitted in reverse order, i.e., in the +sequence +A(j1,...,jn) to +A(i1,...,in). + + EXAMPLES Note:The following illustrates how some programs may be writtten