]> thyrsus.com Git - mad.git/commitdiff
Examples and flowcharts are done.
authorEric S. Raymond <esr@thyrsus,com>
Tue, 2 Mar 2004 11:09:31 +0000 (11:09 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Tue, 2 Mar 2004 11:09:31 +0000 (11:09 +0000)
doc/mad-manual.xml

index 5e7419d63a68b8331647bae316640d206956eee1..ebaf36fb131659b01bb6f99dd18bf77212f02439 100644 (file)
 <!ENTITY findroot SYSTEM "../madhouse/findroot.mad">
 <!ENTITY transfunc SYSTEM "../madhouse/transfunc.mad">
 <!ENTITY matrixmult SYSTEM "../madhouse/matrixmult.mad">
+<!ENTITY jordan SYSTEM "../madhouse/jordan.mad">
+<!ENTITY payroll SYSTEM "../madhouse/payroll.mad">
+<!ENTITY altpayroll SYSTEM "../madhouse/altpayroll.mad">
+<!ENTITY payrolltape SYSTEM "../madhouse/payrolltape.mad">
+<!ENTITY mortgage SYSTEM "../madhouse/mortgage.mad">
+<!ENTITY commutefunc SYSTEM "../madhouse/commutefunc.mad">
+<!ENTITY commutemain SYSTEM "../madhouse/commutemain.mad">
+<!ENTITY wordsearch SYSTEM "../madhouse/wordsearch.mad">
 <!ENTITY factfunc SYSTEM "../madhouse/factfunc.mad">
+<!ENTITY factmain SYSTEM "../madhouse/factmain.mad">
+<!ENTITY gcdfunc SYSTEM "../madhouse/gcdfunc.mad">
+<!ENTITY gcdmain SYSTEM "../madhouse/gcdmain.mad">
+<!ENTITY tschebfunc SYSTEM "../madhouse/tschebfunc.mad">
+<!ENTITY tschebmain SYSTEM "../madhouse/tschebmain.mad">
 <!ENTITY scope1 SYSTEM "scope1.xml">
 <!ENTITY scope2 SYSTEM "scope2.xml">
 <!ENTITY scope3 SYSTEM "scope3.xml">
@@ -259,7 +272,9 @@ difficult to imagine code that would.</para>
 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.</para>
+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).</para>
 
 <para>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.</para>
 
-<para>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.</para>
+<para>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.</para>
 
 <para>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.</para>
 
 <sect1><title>Scientific Examples</title>
 
-<sect2><title>Example 1<emphasis role='note'>: Compute roots of linear and quadratic equations</emphasis></title>
+<sect2><title>Example 1<emphasis role='note'>: Compute roots of linear
+and quadratic equations</emphasis></title>
 
 <para><emphasis>Problem:</emphasis> To solve the quadratic equation
-ax<superscript>2</superscript> + bx + c = 0 for vartious sets of
+ax<superscript>2</superscript> + bx + c = 0 for various sets of
 coefficients a, b, and c.</para>
 
 <para><emphasis>Analysis:</emphasis> Let x<subscript>1</subscript> and
@@ -3632,7 +3650,7 @@ READ      READ FORMAT INPUTS,A,B,N,R
 <!-- beginpage -->
 <sect2><title>Example 4<emphasis role='note'>: Find roots of a function by half-interval approximation</emphasis></title>
 
-<!-- FIXME -->
+<!-- FIXME: TEXT FOR PAGE III. 11 GOES HERE -->
 
 <!-- beginpage -->
 <para><emphasis>Flow diagram:</emphasis></para>
@@ -3743,7 +3761,186 @@ there is no general way to implement this in generated C.</para></note>
 </programlisting>
 </sect2>
 <!-- pagebreak; -->
-<sect2><title><emphasis>Problem:</emphasis> Evaluate the recursive function,</title>
+<sect2><title>Example 7<emphasis role='note'>: Solve simultaneous linear equations</emphasis></title>
+
+<!-- FIXME: TEXT FOR PAGES III.19-20 GOES HERE -->
+
+<!-- beginpage -->
+<para><emphasis>Flow diagram:</emphasis></para>
+
+<mediaobject>
+  <imageobject>
+    <imagedata fileref='fig13.png'/>
+  </imageobject>
+</mediaobject>
+
+<!-- beginpage -->
+
+<para><emphasis>The Program:</emphasis></para>
+
+<programlisting>
+&jordan;
+<!-- pagebreak; -->
+* DATA
+   3
+          1.           1.           1.           6.         -1.           0
+          0.          -1.          -1.          -2.         -9.        -32.
+</programlisting>
+
+</sect2>
+</sect1>
+<!-- beginpage -->
+<sect1><title>Business Data Processing Examples</title>
+<sect2><title>Example 1<emphasis role='note'>: Payroll Processing</emphasis></title>
+
+<!-- FIXME: TEST FOR PAGES III.24-25 GOES HERE -->
+
+<!-- beginpage -->
+<para><emphasis>Flow diagram:</emphasis></para>
+
+<mediaobject>
+  <imageobject>
+    <imagedata fileref='fig14.png'/>
+  </imageobject>
+</mediaobject>
+
+<!-- beginpage -->
+
+<para><emphasis>The Program:</emphasis></para>
+
+<programlisting>
+&payroll;
+<!-- pagebreak; -->
+* 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.
+</programlisting>
+
+<!-- beginpage -->
+<para><emphasis>Alternate Program:</emphasis></para>
+
+<programlisting>
+&altpayroll;
+<!-- pagebreak; -->
+* 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.
+</programlisting>
+
+</sect2>
+<sect2><title>Example 2<emphasis role='note'>: Payroll Tape Processing</emphasis></title>
+
+<!-- FIXME: TEXT FOR PAGES III.30-32 GOES HERE -->
+
+<!-- beginpage -->
+<para><emphasis>Flow diagram:</emphasis></para>
+
+<mediaobject>
+  <imageobject>
+    <imagedata fileref='fig15.png'/>
+  </imageobject>
+</mediaobject>
+
+<!-- beginpage -->
+
+<para><emphasis>The Program:</emphasis></para>
+
+<programlisting>
+&payrolltape;
+</programlisting>
+
+</sect2>
+<sect2><title>Example 3<emphasis role='note'>: Mortgage Payment Processing</emphasis></title>
+
+<!-- FIXME: TEXT FOR PAGES III.37 GOES HERE -->
+
+<!-- beginpage -->
+<para><emphasis>Flow diagram:</emphasis></para>
+
+<mediaobject>
+  <imageobject>
+    <imagedata fileref='fig16.png'/>
+  </imageobject>
+</mediaobject>
+
+<mediaobject>
+  <imageobject>
+    <imagedata fileref='fig17.png'/>
+  </imageobject>
+</mediaobject>
+
+<!-- beginpage -->
+
+<para><emphasis>The Program:</emphasis></para>
+
+<programlisting>
+&mortgage;
+</programlisting>
+
+</sect2>
+<sect2><title>Example 4<emphasis role='note'>: Actuarial computation</emphasis></title>
+
+<!-- FIXME: TEXT FOR PAGES III.42-43 GOES HERE -->
+
+<!-- beginpage -->
+<para><emphasis>Flow diagram:</emphasis></para>
+
+<mediaobject>
+  <imageobject>
+    <imagedata fileref='fig18.png'/>
+  </imageobject>
+</mediaobject>
+
+<!-- beginpage -->
+
+<para><emphasis>The Program:</emphasis></para>
+
+<programlisting>
+&commutemain;
+</programlisting>
+
+<para><emphasis>The External Functions:</emphasis></para>
+
+<programlisting>
+&commutefunc;
+</programlisting>
+
+</sect2>
+</sect1>
+<sect1><title>Symbol Manipulation and Recursive Function Examples</title>
+<sect2><title><emphasis role='note'>Example 1: Find a word in a string</emphasis></title>
+
+<para><emphasis>Problem:</emphasis> Find the first occurrence of an
+arbitrary word in a given text.</para>
+
+<para><emphasis>Analysis:</emphasis> 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).</para>
+
+<mediaobject>
+  <imageobject>
+    <imagedata fileref='fig19.png'/>
+  </imageobject>
+</mediaobject>
+
+<!-- pagebreak -->
+<programlisting>
+&wordsearch;
+</programlisting>
+
+</sect2>
+<sect2><title><emphasis role='note'>Example 2: Compute the factorial function</emphasis></title>
+<para><emphasis>Problem:</emphasis> Evaluate the recursive function,</para>
+
+<para role='centered'>f(0) = 1</para>
+<para role='centered'>f(n) = f(n-1) * n</para>
 
 <note><para>Due to a reproduction error in the original, the Analysis
 paragraph below is somewhat mangled (the right-hand side sliced
@@ -3762,6 +3959,83 @@ handl<emphasis>ed.</emphasis></para>
 </programlisting>
 <!-- pagebreak; -->
 
+<para>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.</para>
+
+<programlisting>
+&factmain;
+</programlisting>
+
+</sect2>
+<sect2><title><emphasis role='note'>Example 3: Compute greatest common
+divisor</emphasis></title>
+<para><emphasis>Problem:</emphasis> To find the greatest common
+divisor of two integers Y and Z.</para>
+
+<para><emphasis>Analysis:</emphasis> The greatest common divisor is
+defined recursively by three equations</para>
+
+<!-- FIXME: MATH GOES HERE -->
+
+<para>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.</para>
+
+<programlisting>
+&gcdfunc;
+</programlisting>
+<!-- pagebreak; -->
+
+<para><emphasis>Note:</emphasis> 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 <emphasis>name</emphasis> of
+the function, wgile GCD.(...) is the <emphasis>value</emphasis> of the
+function.</para>
+
+<para><emphasis>Note:</emphasis> 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.</para>
+
+<para>An example of a program using GCD. is:</para>
+
+<programlisting>
+&gcdmain;
+</programlisting>
+
+</sect2>
+<sect2><title><emphasis role='note'>Example 4: Evaluate Tschebychev polynomials</emphasis></title>
+<para><emphasis>Problem:</emphasis> To evaluate Tschebychev polynomials.</para>
+
+<para><emphasis>Analysis:</emphasis> The Tschebychev polynomialT(N,X)
+is defined recursively as follows:</para>
+
+<!-- FIXME: MATH GOES HERE -->
+
+<para>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.</para>
+
+<programlisting>
+&tschebfunc;
+</programlisting>
+<!-- pagebreak; -->
+
+<para>A program which uses TSCHEB. is:</para>
+
+<programlisting>
+&tschebmain;
+</programlisting>
+
 </sect2>
 </sect1>
 </chapter>