From: Eric S. Raymond Date: Tue, 2 Mar 2004 11:09:31 +0000 (+0000) Subject: Examples and flowcharts are done. X-Git-Tag: 1.0~43 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=5fa38c3c0bd68ab3b2e9ddcc7477c503e0fab604;p=mad.git Examples and flowcharts are done. --- diff --git a/doc/mad-manual.xml b/doc/mad-manual.xml index 5e7419d..ebaf36f 100644 --- a/doc/mad-manual.xml +++ b/doc/mad-manual.xml @@ -12,7 +12,20 @@ + + + + + + + + + + + + + @@ -259,7 +272,9 @@ difficult to imagine code that would. computed-transfer statement are not implemented (mainly because the manual did not include programs with which they could be tested). Neither are multiple ENTRY points, EQUIVALENCE, ERASABLE, COMMON, -TAPE, or DRUM statements. +TAPE, or DRUM statements. More seriously, though array references +and assignments are implemented, array I/O is not (except for the +special case of character arrays which are handled as strings). Only the no-argument case of ERROR RETURN is supported. The language describing the more general case of this feature is deeply @@ -321,12 +336,14 @@ 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. -In the original, each example in Chapter 3 was introduced by a -centered numbered header "Example N" with no section numbering. These -headers have been turned into second-level sections, and descriptive -titles added because the Contents page looked awful without -them. To remind the reader that these are additions by the redactor, -they are highlighted like redactor's notes. +In the original, each example in the first two parts of Chapter +3 was introduced by a centered numbered header "Example N" with no +section numbering; examples in the third part had no headings at all. +These headers have been massaged or added to produce second-level +sections, and descriptive titles added because the Contents page +looked awful without them. To remind the reader that these are +additions by the redactor, they are highlighted like redactor's +notes. The PIC diagrams preserve the logic of the original hand-drawn ones, but are not exact geometrical duplicates. The proportions of @@ -3392,10 +3409,11 @@ relation is true. Scientific Examples -Example 1<emphasis role='note'>: Compute roots of linear and quadratic equations</emphasis> +Example 1<emphasis role='note'>: Compute roots of linear +and quadratic equations</emphasis> Problem: To solve the quadratic equation -ax2 + bx + c = 0 for vartious sets of +ax2 + bx + c = 0 for various sets of coefficients a, b, and c. Analysis: Let x1 and @@ -3632,7 +3650,7 @@ READ READ FORMAT INPUTS,A,B,N,R Example 4<emphasis role='note'>: Find roots of a function by half-interval approximation</emphasis> - + Flow diagram: @@ -3743,7 +3761,186 @@ there is no general way to implement this in generated C. -<emphasis>Problem:</emphasis> Evaluate the recursive function, +Example 7<emphasis role='note'>: Solve simultaneous linear equations</emphasis> + + + + +Flow diagram: + + + + + + + + + +The Program: + + +&jordan; + +* DATA + 3 + 1. 1. 1. 6. -1. 0 + 0. -1. -1. -2. -9. -32. + + + + + +Business Data Processing Examples +Example 1<emphasis role='note'>: Payroll Processing</emphasis> + + + + +Flow diagram: + + + + + + + + + +The Program: + + +&payroll; + +* DATA +GEORGE WASHINGTON 12345678 100. 4800. +JOHN ADAMS 12345679 200. 4900. +THOMAS JEFFERSON 12345680 200. 4600. +JAMES MADISON 12345681 200. 4700. +JOHN QUINCY ADAMS 12345682 100. 300. + + + +Alternate Program: + + +&altpayroll; + +* DATA +GEORGE WASHINGTON 12345678 100. 4800. +JOHN ADAMS 12345679 200. 4900. +THOMAS JEFFERSON 12345680 200. 4600. +JAMES MADISON 12345681 200. 4700. +JOHN QUINCY ADAMS 12345682 100. 300. + + + +Example 2<emphasis role='note'>: Payroll Tape Processing</emphasis> + + + + +Flow diagram: + + + + + + + + + +The Program: + + +&payrolltape; + + + +Example 3<emphasis role='note'>: Mortgage Payment Processing</emphasis> + + + + +Flow diagram: + + + + + + + + + + + + + + + +The Program: + + +&mortgage; + + + +Example 4<emphasis role='note'>: Actuarial computation</emphasis> + + + + +Flow diagram: + + + + + + + + + +The Program: + + +&commutemain; + + +The External Functions: + + +&commutefunc; + + + + +Symbol Manipulation and Recursive Function Examples +<emphasis role='note'>Example 1: Find a word in a string</emphasis> + +Problem: Find the first occurrence of an +arbitrary word in a given text. + +Analysis: Let N be the number of characters in +the text and T(1)...T(N) be the text stored one character per +word. Let L be the number of letters in the word which is stored one +character per word in W(1)...W(L). + + + + + + + + + +&wordsearch; + + + +<emphasis role='note'>Example 2: Compute the factorial function</emphasis> +Problem: Evaluate the recursive function, + +f(0) = 1 +f(n) = f(n-1) * n Due to a reproduction error in the original, the Analysis paragraph below is somewhat mangled (the right-hand side sliced @@ -3762,6 +3959,83 @@ handled. +In order to use this function, the calling program would have to +specify a list for use in the SAVE and RESTORE stayements. The +following is an example of a program which uses FACT. + + +&factmain; + + + +<emphasis role='note'>Example 3: Compute greatest common +divisor</emphasis> +Problem: To find the greatest common +divisor of two integers Y and Z. + +Analysis: The greatest common divisor is +defined recursively by three equations + + + +Where REM.(A,B) is the remainder of A/B. This function expects +the arguments to be found on the temporary storage list as the two +most recent additions. The use of the list as a parameter list makes +the establishment of dummy variables unnecessary. This is less +efficient than the usuall way of defining functions, but serves to +remove many pitfalls encountered in using dummy variables with +recursive functions. + + +&gcdfunc; + + + +Note: When called upon for a value, a +function such as GCD, must have at least one argument (in this example +a dummy argument of zero is used) even though the argument is never +called upon. This is because GCD. is the name of +the function, wgile GCD.(...) is the value of the +function. + +Note: The SET LIST TO statement need be +executed only once, either in the main program or in a subprogram(but +before any use of SAVE or RESTORE), since the SAVE and RESTORE +statements always refer to the current list. + +An example of a program using GCD. is: + + +&gcdmain; + + + +<emphasis role='note'>Example 4: Evaluate Tschebychev polynomials</emphasis> +Problem: To evaluate Tschebychev polynomials. + +Analysis: The Tschebychev polynomialT(N,X) +is defined recursively as follows: + + + +It is important to understand that when an expression is written +as an argument of a function its value is computed and stored in a +temporary location. It is this location (or address) which is actually +used as the argument of the function. The implication of this use of +a temporary location is that often expressions cannot be used as +arguments of recursive functions. + + +&tschebfunc; + + + +A program which uses TSCHEB. is: + + +&tschebmain; + +