intro.tex 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. \chapter{Introductory Information}
  2. \index{Introduction}{\REDUCE} is a system for carrying out algebraic
  3. operations accurately, no matter how complicated the expressions become.
  4. It can manipulate polynomials in a variety of forms, both expanding and
  5. factoring them, and extract various parts of them as required. {\REDUCE} can
  6. also do differentiation and integration, but we shall only show trivial
  7. examples of this in this introduction. Other topics not
  8. considered include the use of arrays, the definition of procedures and
  9. operators, the specific routines for high energy physics calculations, the
  10. use of files to eliminate repetitious typing and for saving results, and
  11. the editing of the input text.
  12. Also not considered in any detail in this introduction are the many options
  13. that are available for varying computational procedures, output forms,
  14. number systems used, and so on.
  15. {\REDUCE} is designed to be an interactive system, so that the user can input
  16. an algebraic expression and see its value before moving on to the next
  17. calculation. For those systems that do not support interactive use, or
  18. for those calculations, especially long ones, for which a standard script
  19. can be defined, {\REDUCE} can also be used in batch mode. In this case,
  20. a sequence of commands can be given to {\REDUCE} and results obtained
  21. without any user interaction during the computation.
  22. In this introduction, we shall limit ourselves to the interactive use of
  23. {\REDUCE}, since this illustrates most completely the capabilities of the
  24. system. When {\REDUCE} is called, it begins by printing a banner message
  25. like:
  26. \begin{verbatim}
  27. REDUCE 3.8, 15-Jul-2003 ...
  28. \end{verbatim}
  29. where the version number and the system release date will change from time
  30. to time. It then prompts the user for input by:
  31. \begin{verbatim}
  32. 1:
  33. \end{verbatim}
  34. You can now type a {\REDUCE} statement, terminated by a semicolon to indicate
  35. the end of the expression, for example:
  36. \begin{verbatim}
  37. (x+y+z)^2;
  38. \end{verbatim}
  39. This expression would normally be followed by another character (a
  40. \key{Return} on an ASCII keyboard) to ``wake up'' the system, which would
  41. then input the expression, evaluate it, and return the result:
  42. \begin{verbatim}
  43. 2 2 2
  44. X + 2*X*Y + 2*X*Z + Y + 2*Y*Z + Z
  45. \end{verbatim}
  46. Let us review this simple example to learn a little more about the way that
  47. {\REDUCE} works. First, we note that {\REDUCE} deals with variables, and
  48. constants like other computer languages, but that in evaluating the former,
  49. a variable can stand for itself. Expression evaluation normally follows
  50. the rules of high school algebra, so the only surprise in the above example
  51. might be that the expression was expanded. {\REDUCE} normally expands
  52. expressions where possible, collecting like terms and ordering the
  53. variables in a specific manner. However, expansion, ordering of variables,
  54. format of output and so on is under control of the user, and various
  55. declarations are available to manipulate these.
  56. Another characteristic of the above example is the use of lower case on
  57. input and upper case on output. In fact, input may be in either mode, but
  58. output is usually in lower case. To make the difference between input and
  59. output more distinct in this manual, all expressions intended for input
  60. will be shown in lower case and output in upper case. However, for
  61. stylistic reasons, we represent all single identifiers in the text in
  62. upper case.
  63. Finally, the numerical prompt can be used to reference the result in a
  64. later computation.
  65. As a further illustration of the system features, the user should try:
  66. \begin{verbatim}
  67. for i:= 1:40 product i;
  68. \end{verbatim}
  69. The result in this case is the value of 40!,
  70. \begin{verbatim}
  71. 815915283247897734345611269596115894272000000000
  72. \end{verbatim}
  73. You can also get the same result by saying
  74. \begin{verbatim}
  75. factorial 40;
  76. \end{verbatim}
  77. Since we want exact results in algebraic calculations, it is essential that
  78. integer arithmetic be performed to arbitrary precision, as in the above
  79. example. Furthermore, the {\tt FOR} statement in the above is illustrative of a
  80. whole range of combining forms that {\REDUCE} supports for the convenience of
  81. the user.
  82. Among the many options in {\REDUCE} is the use of other number systems, such
  83. as multiple precision floating point with any specified number of digits ---
  84. of use if roundoff in, say, the $100^{th}$ digit is all that can be tolerated.
  85. In many cases, it is necessary to use the results of one calculation in
  86. succeeding calculations. One way to do this is via an assignment for a
  87. variable, such as
  88. \begin{verbatim}
  89. u := (x+y+z)^2;
  90. \end{verbatim}
  91. If we now use {\tt U} in later calculations, the value of the right-hand
  92. side of the above will be used.
  93. The results of a given calculation are also saved in the variable
  94. {\tt WS}\ttindex{WS} (for WorkSpace), so this can be used in the next
  95. calculation for further processing.
  96. For example, the expression
  97. \begin{verbatim}
  98. df(ws,x);
  99. \end{verbatim}
  100. following the previous evaluation will calculate the derivative of
  101. {\tt (x+y+z)\verb|^|2} with respect to {\tt X}. Alternatively,
  102. \begin{verbatim}
  103. int(ws,y);
  104. \end{verbatim}
  105. would calculate the integral of the same expression with respect to y.
  106. {\REDUCE} is also capable of handling symbolic matrices. For example,
  107. \begin{verbatim}
  108. matrix m(2,2);
  109. \end{verbatim}
  110. declares m to be a two by two matrix, and
  111. \begin{verbatim}
  112. m := mat((a,b),(c,d));
  113. \end{verbatim}
  114. gives its elements values. Expressions that include {\tt M} and make
  115. algebraic sense may now be evaluated, such as {\tt 1/m} to give the
  116. inverse, {\tt 2*m - u*m\verb|^|2} to give us another matrix and {\tt det(m)}
  117. to give us the determinant of {\tt M}.
  118. {\REDUCE} has a wide range of substitution capabilities. The system knows
  119. about elementary functions, but does not automatically invoke many of their
  120. well-known properties. For example, products of trigonometrical functions
  121. are not converted automatically into multiple angle expressions, but if the
  122. user wants this, he can say, for example:
  123. \begin{verbatim}
  124. (sin(a+b)+cos(a+b))*(sin(a-b)-cos(a-b))
  125. where cos(~x)*cos(~y) = (cos(x+y)+cos(x-y))/2,
  126. cos(~x)*sin(~y) = (sin(x+y)-sin(x-y))/2,
  127. sin(~x)*sin(~y) = (cos(x-y)-cos(x+y))/2;
  128. \end{verbatim}
  129. where the tilde in front of the variables {\tt X} and {\tt Y} indicates
  130. that the rules apply for all values of those variables.
  131. The result of this calculation is
  132. \begin{verbatim}
  133. -(COS(2*A) + SIN(2*B))
  134. \end{verbatim}
  135. \extendedmanual{See also the user-contributed packages ASSIST
  136. (chapter~\ref{ASSIST}), CAMAL (chapter~\ref{CAMAL}) and TRIGSIMP
  137. (chapter~\ref{TRIGSIMP}).}
  138. Another very commonly used capability of the system, and an illustration
  139. of one of the many output modes of {\REDUCE}, is the ability to output
  140. results in a FORTRAN compatible form. Such results can then be used in a
  141. FORTRAN based numerical calculation. This is particularly useful as a way
  142. of generating algebraic formulas to be used as the basis of extensive
  143. numerical calculations.
  144. For example, the statements
  145. \begin{verbatim}
  146. on fort;
  147. df(log(x)*(sin(x)+cos(x))/sqrt(x),x,2);
  148. \end{verbatim}
  149. will result in the output
  150. \begin{verbatim}
  151. ANS=(-4.*LOG(X)*COS(X)*X**2-4.*LOG(X)*COS(X)*X+3.*
  152. . LOG(X)*COS(X)-4.*LOG(X)*SIN(X)*X**2+4.*LOG(X)*
  153. . SIN(X)*X+3.*LOG(X)*SIN(X)+8.*COS(X)*X-8.*COS(X)-8.
  154. . *SIN(X)*X-8.*SIN(X))/(4.*SQRT(X)*X**2)
  155. \end{verbatim}
  156. These algebraic manipulations illustrate the algebraic mode of {\REDUCE}.
  157. {\REDUCE} is based on Standard Lisp. A symbolic mode is also available for
  158. executing Lisp statements. These statements follow the syntax of Lisp,
  159. e.g.
  160. \begin{verbatim}
  161. symbolic car '(a);
  162. \end{verbatim}
  163. Communication between the two modes is possible.
  164. With this simple introduction, you are now in a position to study the
  165. material in the full {\REDUCE} manual in order to learn just how extensive
  166. the range of facilities really is. If further tutorial material is
  167. desired, the seven {\REDUCE} Interactive Lessons by David R. Stoutemyer are
  168. recommended. These are normally distributed with the system.