]> thyrsus.com Git - mad.git/commitdiff
Added first six pages of chapter 3.
authorEric S. Raymond <esr@thyrsus,com>
Wed, 18 Feb 2004 09:20:21 +0000 (09:20 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Wed, 18 Feb 2004 09:20:21 +0000 (09:20 +0000)
doc/mad-manual.xml

index 55f6f7391bccfbcdc7a6bd6f88436983463cf2b5..b67c3df4666b13aae535df3915305d12d2a5c70f 100644 (file)
@@ -5,6 +5,8 @@
 <!ENTITY maxfunc SYSTEM "../madhouse/maxfunc.mad">
 <!ENTITY newton1 SYSTEM "../madhouse/newton1.mad">
 <!ENTITY newton2 SYSTEM "../madhouse/newton2.mad">
+<!ENTITY quadratic SYSTEM "../madhouse/quadratic.mad">
+<!ENTITY truthtable SYSTEM "../madhouse/truthtable.mad">
 <!ENTITY scope1 SYSTEM "scope1.xml">
 <!ENTITY scope2 SYSTEM "scope2.xml">
 <!ENTITY scope3 SYSTEM "scope3.xml">
@@ -2873,26 +2875,185 @@ sufficiently high.</para>
 </chapter>
 <chapter><title>EXAMPLES</title>
 
+<para>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.</para>
+
+<para>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:</para> <!-- yes, that's "present", not "represented" -->
+
 <mediaobject>
   <imageobject>
     <imagedata fileref='fig6.png'/>
   </imageobject>
 </mediaobject>
 
+<para>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.</para>
+
+<sect1><title>Scientific Examples</title>
+
+<sect2><title>Example 1</title>
+
+<para><emphasis>Problem:</emphasis> To solve the quadratic equation
+ax<superscript>2</superscript> + bx + c = 0 for vartious sets of
+coefficients a, b, and c.</para>
+
+<para><emphasis>Analysis:</emphasis> Let x<subscript>1</subscript> and
+x<subscript>2</subscript> be the two roots of the equation.  Then
+their values are found by the formulas,</para>
+
+<mediaobject>
+  <imageobject>
+    <imagedata fileref='equation4.png'/>
+  </imageobject>
+</mediaobject>
+
+<para>whenever a &ne; 0.  The single root x<subscript>1</subscript> of
+the equation when a = 0 is x<subscript>1</subscript> = -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!).</para>
+
+<para><emphasis>Flow Diagram:</emphasis></para>
+
 <mediaobject>
   <imageobject>
     <imagedata fileref='fig7.png'/>
   </imageobject>
 </mediaobject>
 
+<para><emphasis>The Program:</emphasis></para>
+
+<programlisting>
+&quadratic;
+*DATA
+          4.          -8.          4.
+          0            5.         10.
+          1.           1.          1.
+</programlisting>
+
+</sect2>
+<sect2><title>Example 2</title>
+
+<para><emphasis>Problem:</emphasis> 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&shy;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:</para>
+
+<!-- 
+original table had:
+(a) vertical rules between all columns, with the one between S and T doubled
+(b) a horizontal rule separating header from body
+(c) a horizontal rule separating the first 8 rows from the last 8 
+-->
+<informaltable colsep='0' rowsep='0' frame='all'>
+<tgroup cols='5'>
+<thead>
+<row>
+<entry>P</entry><entry>Q</entry><entry>R</entry><entry>S</entry><entry>T</entry>
+</row>
+</thead>
+<tbody>
+<row>
+<entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry>
+</row>
+<row>
+<entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry>
+</row>
+<row>
+<entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry>
+</row>
+<row>
+<entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry>
+</row>
+<row>
+<entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry>
+</row>
+<row>
+<entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry>
+</row>
+<row>
+<entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry>
+</row>
+<row>
+<entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry>
+</row>
+<row>
+<entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry>
+</row>
+<row>
+<entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry>
+</row>
+<row>
+<entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry>
+</row>
+<row>
+<entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry>
+</row>
+<row>
+<entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry>
+</row>
+<row>
+<entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry>
+</row>
+<row>
+<entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;0B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry>
+</row>
+<row>
+<entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry><entry>&nbsp;&nbsp;&nbsp;&nbsp;1B&nbsp;&nbsp;&nbsp;&nbsp;</entry>
+</row>
+</tbody>
+</tgroup>
+</informaltable>
+
+<para>The problem is to write a program to generate the entire "truth
+table" for the given expression T.</para>
+
+<para><emphasis>Flow Diagram:</emphasis></para>
+
 <mediaobject>
   <imageobject>
     <imagedata fileref='fig8.png'/>
   </imageobject>
 </mediaobject>
 
+<para><emphasis>The Program:</emphasis></para>
+
+<programlisting>
+&truthtable;
+</programlisting>
+
+<para>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 <emphasis>internally</emphasis> 0B and 1B
+are stored as 0 and 1, respectively.  Also, the statement</para>
+
+<para role='centered'>
+NORMAL MODE IS BOOLEAN
+</para>
+
+<para>could have been used as tthe second statement of this program
+instead of the BOOLEAN declaration.</para>
+
+</sect2>
+</sect1>
 </chapter>
 </book>
+
 <!--
 Local Variables:
 compile-command: "make mad-manual.html"