From eb98a42f6316a3c23a96cdae0724182bde9468f1 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 18 Feb 2004 09:20:21 +0000 Subject: [PATCH] Added first six pages of chapter 3. --- doc/mad-manual.xml | 161 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/doc/mad-manual.xml b/doc/mad-manual.xml index 55f6f73..b67c3df 100644 --- a/doc/mad-manual.xml +++ b/doc/mad-manual.xml @@ -5,6 +5,8 @@ + + @@ -2873,26 +2875,185 @@ sufficiently high. EXAMPLES +Note:The following illustrates how some programs may be writtten +in the MAD language. Since they were written to illustrate as many +features of the language as possible, they are not necessarily the +most efficient or elegant programs which could have been written. +They have all been tested on the computer, however, and are +correct. + +The flow chart notation used here varies somewhat from the +illustrations of Chapter 1. The variation is consistent with present +computing practice where many individualistic forms are encountered +and, moreover, causes no difficulty due to the essentially graphic +nature of charts. In particular, iterations are present by the +form: + +Here the scope of the iteration lies between the hexagonal box +and diamond box A, and the calculation proceeds from A when the stated +relation is true. + +Scientific Examples + +Example 1 + +Problem: To solve the quadratic equation +ax2 + bx + c = 0 for vartious sets of +coefficients a, b, and c. + +Analysis: Let x1 and +x2 be the two roots of the equation. Then +their values are found by the formulas, + + + + + + + +whenever a ≠ 0. The single root x1 of +the equation when a = 0 is x1 = -c/b. The input +values of a, b, and C are printed immediately after they are brought +in to help in finding trouble spots during the development of the +program (not as necessary here as in longer problems, but a good +idea!). + +Flow Diagram: + +The Program: + + +&quadratic; +*DATA + 4. -8. 4. + 0 5. 10. + 1. 1. 1. + + + +Example 2 + +Problem: A logical (Boolean) expression +such as (P .AND. Q) .OR.(.NOT. P .AND. R .AND. S).OR.(R .OR. P) will +have a value TRUE or FALSE (represnted here by 1B and 0B, +respective­ly) depending on the "input values" of the variables +involved: P,Q,R,S. Thus, if P = 1B, Q = R = S = 0B, then the total +expression T will have the value 1B. The entire table of outputs for +all possible inputs would be as follows: + + + + + + +PQRST + + + + +    0B        0B        0B        0B        0B     + + +    0B        0B        0B        1B        0B     + + +    0B        0B        1B        0B        1B     + + +    0B        0B        1B        1B        1B     + + +    0B        1B        0B        0B        0B     + + +    0B        1B        0B        1B        0B     + + +    0B        1B        1B        0B        1B     + + +    0B        1B        1B        1B        1B     + + +    1B        0B        0B        0B        1B     + + +    1B        0B        0B        1B        1B     + + +    1B        0B        1B        0B        1B     + + +    1B        0B        1B        1B        1B     + + +    1B        1B        0B        0B        1B     + + +    1B        1B        0B        1B        1B     + + +    1B        1B        1B        0B        1B     + + +    1B        1B        1B        1B        1B     + + + + + +The problem is to write a program to generate the entire "truth +table" for the given expression T. + +Flow Diagram: + +The Program: + + +&truthtable; + + +Note: Although it would have meant only a slight change in the +format information, no attempt was made here to label the "0" and "1" +that print as values in the table as Boolean, i.e., "0B" and "1B". +This points up the fact that internally 0B and 1B +are stored as 0 and 1, respectively. Also, the statement + + +NORMAL MODE IS BOOLEAN + + +could have been used as tthe second statement of this program +instead of the BOOLEAN declaration. + + + +