oper.tex 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. \chapter{Built-in Prefix Operators}
  2. In the following subsections are descriptions of the most useful prefix
  3. \index{Prefix}
  4. operators built into {\REDUCE} that are not defined in other sections (such
  5. as substitution operators). Some are fully defined internally as
  6. procedures; others are more nearly abstract operators, with only some of
  7. their properties known to the system.
  8. In many cases, an operator is described by a prototypical header line as
  9. follows. Each formal parameter is given a name and followed by its allowed
  10. type. The names of classes referred to in the definition are printed in
  11. lower case, and parameter names in upper case. If a parameter type is not
  12. commonly used, it may be a specific set enclosed in brackets {\tt \{} \ldots
  13. {\tt \}}.
  14. Operators that accept formal parameter lists of arbitrary length have the
  15. parameter and type class enclosed in square brackets indicating that zero
  16. or more occurrences of that argument are permitted. Optional parameters
  17. and their type classes are enclosed in angle brackets.
  18. \section{Numerical Operators}\index{Numerical operator}
  19. {\REDUCE} includes a number of functions that are analogs of those found
  20. in most numerical systems. With numerical arguments, such functions
  21. return the expected result. However, they may also be called with
  22. non-numerical arguments. In such cases, except where noted, the system
  23. attempts to simplify the expression as far as it can. In such cases, a
  24. residual expression involving the original operator usually remains.
  25. These operators are as follows:
  26. \subsection{ABS}
  27. {\tt ABS}\ttindex{ABS} returns the absolute value
  28. of its single argument, if that argument has a numerical value.
  29. A non-numerical argument is returned as an absolute value, with an overall
  30. numerical coefficient taken outside the absolute value operator. For example:
  31. \begin{verbatim}
  32. abs(-3/4) -> 3/4
  33. abs(2a) -> 2*ABS(A)
  34. abs(i) -> 1
  35. abs(-x) -> ABS(X)
  36. \end{verbatim}
  37. \subsection{CEILING}\ttindex{CEILING}
  38. This operator returns the ceiling (i.e., the least integer greater than
  39. the given argument) if its single argument has a numerical value. A
  40. non-numerical argument is returned as an expression in the original
  41. operator. For example:
  42. \begin{verbatim}
  43. ceiling(-5/4) -> -1
  44. ceiling(-a) -> CEILING(-A)
  45. \end{verbatim}
  46. \subsection{CONJ}\ttindex{CONJ}
  47. This returns the complex conjugate
  48. of an expression, if that argument has an numerical value. A
  49. non-numerical argument is returned as an expression in the operators
  50. {\tt REPART}\ttindex{REPART} and {\tt IMPART}\ttindex{IMPART}. For example:
  51. \begin{verbatim}
  52. conj(1+i) -> 1-I
  53. conj(a+i*b) -> REPART(A) - REPART(B)*I - IMPART(A)*I
  54. - IMPART(B)
  55. \end{verbatim}
  56. \subsection{FACTORIAL}\ttindex{FACTORIAL}
  57. If the single argument of {\tt FACTORIAL} evaluates to a non-negative
  58. integer, its factorial is returned. Otherwise an expression involving
  59. {\tt FACTORIAL} is returned. For example:
  60. \begin{verbatim}
  61. factorial(5) -> 120
  62. factorial(a) -> FACTORIAL(A)
  63. \end{verbatim}
  64. \subsection{FIX}\ttindex{FIX}
  65. This operator returns the fixed value (i.e., the integer part of
  66. the given argument) if its single argument has a numerical value. A
  67. non-numerical argument is returned as an expression in the original
  68. operator. For example:
  69. \begin{verbatim}
  70. fix(-5/4) -> -1
  71. fix(a) -> FIX(A)
  72. \end{verbatim}
  73. \subsection{FLOOR}\ttindex{FLOOR}
  74. This operator returns the floor (i.e., the greatest integer less than
  75. the given argument) if its single argument has a numerical value. A
  76. non-numerical argument is returned as an expression in the original
  77. operator. For example:
  78. \begin{verbatim}
  79. floor(-5/4) -> -2
  80. floor(a) -> FLOOR(A)
  81. \end{verbatim}
  82. \subsection{IMPART}\ttindex{IMPART}
  83. This operator returns the imaginary part of an expression, if that argument
  84. has an numerical value. A non-numerical argument is returned as an expression
  85. in the operators {\tt REPART}\ttindex{REPART} and {\tt IMPART}. For example:
  86. \begin{verbatim}
  87. impart(1+i) -> 1
  88. impart(a+i*b) -> REPART(B) + IMPART(A)
  89. \end{verbatim}
  90. \subsection{MAX/MIN}
  91. {\tt MAX} and {\tt MIN}\ttindex{MAX}\ttindex{MIN} can take an arbitrary
  92. number of expressions as their arguments. If all arguments evaluate to
  93. numerical values, the maximum or minimum of the argument list is returned.
  94. If any argument is non-numeric, an appropriately reduced expression is
  95. returned. For example:
  96. \begin{verbatim}
  97. max(2,-3,4,5) -> 5
  98. min(2,-2) -> -2.
  99. max(a,2,3) -> MAX(A,3)
  100. min(x) -> X
  101. \end{verbatim}
  102. {\tt MAX} or {\tt MIN} of an empty list returns 0.
  103. \subsection{NEXTPRIME}\ttindex{NEXTPRIME}
  104. {\tt NEXTPRIME} returns the next prime greater than its integer argument,
  105. using a probabilistic algorithm. A type error occurs if the value of the
  106. argument is not an integer. For example:
  107. \begin{verbatim}
  108. nextprime(5) -> 7
  109. nextprime(-2) -> 2
  110. nextprime(-7) -> -5
  111. nextprime 1000000 -> 1000003
  112. \end{verbatim}
  113. whereas {\tt nextprime(a)} gives a type error.
  114. \subsection{RANDOM}\ttindex{RANDOM}
  115. {\tt random(}{\em n\/}{\tt)} returns a random number $r$ in the range $0
  116. \leq r < n$. A type error occurs if the value of the argument is not a
  117. positive integer in algebraic mode, or positive number in symbolic mode.
  118. For example:
  119. \begin{verbatim}
  120. random(5) -> 3
  121. random(1000) -> 191
  122. \end{verbatim}
  123. whereas {\tt random(a)} gives a type error.
  124. \subsection{RANDOM\_NEW\_SEED}\ttindex{RANDOM\_NEW\_SEED}
  125. {\tt random\_new\_seed(}{\em n\/}{\tt)} reseeds the random number generator
  126. to a sequence determined by the integer argument $n$. It can be used to
  127. ensure that a repeatable pseudo-random sequence will be delivered
  128. regardless of any previous use of {\tt RANDOM}, or can be called early in
  129. a run with an argument derived from something variable (such as the time
  130. of day) to arrange that different runs of a REDUCE program will use
  131. different random sequences. When a fresh copy of REDUCE is first created
  132. it is as if {\tt random\_new\_seed(1)} has been obeyed.
  133. A type error occurs if the value of the argument is not a positive integer.
  134. \subsection{REPART}\ttindex{REPART}
  135. This returns the real part of an expression, if that argument has an
  136. numerical value. A non-numerical argument is returned as an expression in
  137. the operators {\tt REPART} and {\tt IMPART}\ttindex{IMPART}. For example:
  138. \begin{verbatim}
  139. repart(1+i) -> 1
  140. repart(a+i*b) -> REPART(A) - IMPART(B)
  141. \end{verbatim}
  142. \subsection{ROUND}\ttindex{ROUND}
  143. This operator returns the rounded value (i.e, the nearest integer) of its
  144. single argument if that argument has a numerical value. A non-numeric
  145. argument is returned as an expression in the original operator. For
  146. example:
  147. \begin{verbatim}
  148. round(-5/4) -> -1
  149. round(a) -> ROUND(A)
  150. \end{verbatim}
  151. \subsection{SIGN}\ttindex{SIGN}
  152. {\tt SIGN} tries to evaluate the sign of its argument. If this
  153. is possible {\tt SIGN} returns one of 1, 0 or -1. Otherwise, the result
  154. is the original form or a simplified variant. For example:
  155. \begin{verbatim}
  156. sign(-5) -> -1
  157. sign(-a^2*b) -> -SIGN(B)
  158. \end{verbatim}
  159. Note that even powers of formal expressions are assumed to be
  160. positive only as long as the switch {\tt COMPLEX} is off.
  161. \section{Mathematical Functions}
  162. {\REDUCE} knows that the following represent mathematical functions
  163. \index{Mathematical function} that can
  164. take arbitrary scalar expressions as their single argument:
  165. \begin{verbatim}
  166. ACOS ACOSH ACOT ACOTH ACSC ACSCH ASEC ASECH ASIN ASINH
  167. ATAN ATANH ATAN2 COS COSH COT COTH CSC CSCH DILOG EI EXP
  168. HYPOT LN LOG LOGB LOG10 SEC SECH SIN SINH SQRT TAN TANH
  169. \end{verbatim}
  170. \ttindex{ACOS}\ttindex{ACOSH}\ttindex{ACOT}
  171. \ttindex{ACOTH}\ttindex{ACSC}\ttindex{ACSCH}\ttindex{ASEC}
  172. \ttindex{ASECH}\ttindex{ASIN}
  173. \ttindex{ASINH}\ttindex{ATAN}\ttindex{ATANH}
  174. \ttindex{ATAN2}\ttindex{COS}
  175. \ttindex{COSH}\ttindex{COT}\ttindex{COTH}\ttindex{CSC}
  176. \ttindex{CSCH}\ttindex{DILOG}\ttindex{Ei}\ttindex{EXP}
  177. \ttindex{HYPOT}\ttindex{LN}\ttindex{LOG}\ttindex{LOGB}\ttindex{LOG10}
  178. \ttindex{SEC}\ttindex{SECH}\ttindex{SIN}
  179. \ttindex{SINH}\ttindex{SQRT}\ttindex{TAN}\ttindex{TANH}
  180. where {\tt LOG} is the natural logarithm (and equivalent to {\tt LN}),
  181. and {\tt LOGB} has two arguments of which the second is the logarithmic base.
  182. The derivatives of all these functions are also known to the system.
  183. {\REDUCE} knows various elementary identities and properties
  184. of these functions. For example:
  185. \begin{verbatim}
  186. cos(-x) = cos(x) sin(-x) = - sin (x)
  187. cos(n*pi) = (-1)^n sin(n*pi) = 0
  188. log(e) = 1 e^(i*pi/2) = i
  189. log(1) = 0 e^(i*pi) = -1
  190. log(e^x) = x e^(3*i*pi/2) = -i
  191. \end{verbatim}
  192. Beside these identities, there are a lot of simplifications
  193. for elementary functions
  194. defined in the {\REDUCE} system as rulelists. In order to
  195. view these, the SHOWRULES operator can be used, e.g.
  196. \begin{verbatim}
  197. SHOWRULES tan;
  198. {tan(~n*arbint(~i)*pi + ~(~ x)) => tan(x) when fixp(n),
  199. tan(~x)
  200. => trigquot(sin(x),cos(x)) when knowledge_about(sin,x,tan)
  201. ,
  202. ~x + ~(~ k)*pi
  203. tan(----------------)
  204. ~d
  205. x k 1
  206. => - cot(---) when x freeof pi and abs(---)=---,
  207. d d 2
  208. ~(~ w) + ~(~ k)*pi w + remainder(k,d)*pi
  209. tan(--------------------) => tan(-----------------------)
  210. ~(~ d) d
  211. k
  212. when w freeof pi and ratnump(---) and fixp(k)
  213. d
  214. k
  215. and abs(---)>=1,
  216. d
  217. tan(atan(~x)) => x,
  218. 2
  219. df(tan(~x),~x) => 1 + tan(x) }
  220. \end{verbatim}
  221. For further simplification, especially of expressions involving
  222. trigonometric functions, see the TRIGSIMP\ttindex{TRIGSIMP} package
  223. documentation.
  224. Functions not listed above may be defined in the special functions
  225. package SPECFN\ttindex{SPECFN}.
  226. The user can add further rules for the reduction of expressions involving
  227. these operators by using the {\tt LET}\ttindex{LET} command.
  228. % The square root function can be input using the name {\tt SQRT}, or the
  229. % power operation {\tt \verb|^|(1/2)}. On output, unsimplified square roots
  230. % are normally represented by the operator {\tt SQRT} rather than a
  231. % fractional power.
  232. In many cases it is desirable to expand product arguments of logarithms,
  233. or collect a sum of logarithms into a single logarithm. Since these are
  234. inverse operations, it is not possible to provide rules for doing both at
  235. the same time and preserve the {\REDUCE} concept of idempotent evaluation.
  236. As an alternative, REDUCE provides two switches {\tt EXPANDLOGS}
  237. \ttindex{EXPANDLOGS} and {\tt COMBINELOGS}\ttindex{COMBINELOGS} to carry
  238. out these operations. Both are off by default. Thus to expand {\tt
  239. LOG(X*Y)} into a sum of logs, one can say
  240. \begin{verbatim}
  241. ON EXPANDLOGS; LOG(X*Y);
  242. \end{verbatim}
  243. and to combine this sum into a single log:
  244. \begin{verbatim}
  245. ON COMBINELOGS; LOG(X) + LOG(Y);
  246. \end{verbatim}
  247. At the present time, it is possible to have both switches on at once,
  248. which could lead to infinite recursion. However, an expression is
  249. switched from one form to the other in this case. Users should not rely
  250. on this behavior, since it may change in the next release.
  251. The current version of {\REDUCE} does a poor job of simplifying surds. In
  252. particular, expressions involving the product of variables raised to
  253. non-integer powers do not usually have their powers combined internally,
  254. even though they are printed as if those powers were combined. For
  255. example, the expression
  256. \begin{verbatim}
  257. x^(1/3)*x^(1/6);
  258. \end{verbatim}
  259. will print as
  260. \begin{verbatim}
  261. SQRT(X)
  262. \end{verbatim}
  263. but will have an internal form containing the two exponentiated terms.
  264. If you now subtract {\tt sqrt(x)} from this expression, you will {\em not\/}
  265. get zero. Instead, the confusing form
  266. \begin{verbatim}
  267. SQRT(X) - SQRT(X)
  268. \end{verbatim}
  269. will result. To combine such exponentiated terms, the switch
  270. {\tt COMBINEEXPT}\ttindex{COMBINEEXPT} should be turned on.
  271. The square root function can be input using the name {\tt SQRT}, or the
  272. power operation {\tt \verb|^|(1/2)}. On output, unsimplified square roots
  273. are normally represented by the operator {\tt SQRT} rather than a
  274. fractional power. With the default system switch settings, the argument
  275. of a square root is first simplified, and any divisors of the expression
  276. that are perfect squares taken outside the square root argument. The
  277. remaining expression is left under the square root.
  278. % However, if the switch {\tt REDUCED}\ttindex{REDUCED} is on,
  279. % multiplicative factors in the argument of the square root are also
  280. % separated, becoming individual square roots. Thus with {\tt REDUCED} off,
  281. Thus the expression
  282. \begin{verbatim}
  283. sqrt(-8a^2*b)
  284. \end{verbatim}
  285. becomes
  286. \begin{verbatim}
  287. 2*a*sqrt(-2*b).
  288. \end{verbatim}
  289. % whereas with {\tt REDUCED} on, it would become
  290. % \begin{verbatim}
  291. % 2*a*i*sqrt(2)*sqrt(b) .
  292. % \end{verbatim}
  293. % The switch {\tt REDUCED}\ttindex{REDUCED} also applies to other rational
  294. % powers in addition to square roots.
  295. Note that such simplifications can cause trouble if {\tt A} is eventually
  296. given a value that is a negative number. If it is important that the
  297. positive property of the square root and higher even roots always be
  298. preserved, the switch {\tt PRECISE}\ttindex{PRECISE} should be set on
  299. (the default value).
  300. This causes any non-numerical factors taken out of surds to be represented
  301. by their absolute value form.
  302. With % both {\tt REDUCED} and
  303. {\tt PRECISE} on then, the above example would become
  304. \begin{verbatim}
  305. 2*abs(a)*sqrt(-2*b).
  306. \end{verbatim}
  307. The statement that {\REDUCE} knows very little about these functions
  308. applies only in the mathematically exact {\tt off rounded} mode. If
  309. {\tt ROUNDED}\ttindex{ROUNDED} is on, any of the functions
  310. \begin{verbatim}
  311. ACOS ACOSH ACOT ACOTH ACSC ACSCH ASEC ASECH ASIN ASINH
  312. ATAN ATANH ATAN2 COS COSH COT COTH CSC CSCH EXP HYPOT
  313. LN LOG LOGB LOG10 SEC SECH SIN SINH SQRT TAN TANH
  314. \end{verbatim}
  315. \ttindex{ACOS}\ttindex{ACOSH}\ttindex{ACOT}\ttindex{ACOTH}
  316. \ttindex{ACSC}\ttindex{ACSCH}\ttindex{ASEC}\ttindex{ASECH}
  317. \ttindex{ASIN}\ttindex{ASINH}\ttindex{ATAN}\ttindex{ATANH}
  318. \ttindex{ATAN2}\ttindex{COS}\ttindex{COSH}\ttindex{COT}
  319. \ttindex{COTH}\ttindex{CSC}\ttindex{CSCH}\ttindex{EXP}\ttindex{HYPOT}
  320. \ttindex{LN}\ttindex{LOG}\ttindex{LOGB}\ttindex{LOG10}\ttindex{SEC}
  321. \ttindex{SECH}\ttindex{SIN}\ttindex{SINH}\ttindex{SQRT}\ttindex{TAN}
  322. \ttindex{TANH}
  323. when given a numerical argument has its value calculated to the current
  324. degree of floating point precision. In addition, real (non-integer
  325. valued) powers of numbers will also be evaluated.
  326. If the {\tt COMPLEX} switch is turned on in addition to {\tt ROUNDED},
  327. these functions will also calculate a real or complex result, again to
  328. the current degree of floating point precision,
  329. if given complex arguments. For example, with {\tt on rounded,complex;}
  330. \begin{verbatim}
  331. 2.3^(5.6i) -> -0.0480793490914 - 0.998843519372*I
  332. cos(2+3i) -> -4.18962569097 - 9.10922789376*I
  333. \end{verbatim}
  334. \section{DF Operator}
  335. The operator {\tt DF}\ttindex{DF} is used to represent partial
  336. differentiation\index{Differentiation} with respect
  337. to one or more variables. It is used with the syntax:
  338. \begin{verbatim}
  339. DF(EXPRN:algebraic[,VAR:kernel<,NUM:integer>]):algebraic.
  340. \end{verbatim}
  341. The first argument is the expression to be differentiated. The remaining
  342. arguments specify the differentiation variables and the number of times
  343. they are applied.
  344. The number {\tt NUM} may be omitted if it is 1. For example,
  345. \begin{quote}
  346. \begin{tabbing}
  347. {\tt df(y,x1,2,x2,x3,2)} \= = $\partial^{5}y/\partial x_{1}^{2} \
  348. \partial x_{2}\partial x_{3}^{2}.$\kill
  349. {\tt df(y,x)} \> = $\partial y/\partial x$ \\
  350. {\tt df(y,x,2)} \> = $\partial^{2}y/\partial x^{2}$ \\
  351. {\tt df(y,x1,2,x2,x3,2)} \> = $\partial^{5}y/\partial x_{1}^{2} \
  352. \partial x_{2}\partial x_{3}^{2}.$
  353. \end{tabbing}
  354. \end{quote}
  355. The evaluation of {\tt df(y,x)} proceeds as follows: first, the values of
  356. {\tt Y} and {\tt X} are found. Let us assume that {\tt X} has no assigned
  357. value, so its value is {\tt X}. Each term or other part of the value of
  358. {\tt Y} that contains the variable {\tt X} is differentiated by the
  359. standard rules. If {\tt Z} is another variable, not {\tt X} itself, then
  360. its derivative with respect to {\tt X} is taken to be 0, unless {\tt Z}
  361. has previously been declared to {\tt DEPEND} on {\tt X}, in which
  362. case the derivative is reported as the symbol {\tt df(z,x)}.
  363. \subsection{Adding Differentiation Rules}
  364. The {\tt LET}\ttindex{LET} statement can be used to introduce
  365. rules for differentiation of user-defined operators. Its general form is
  366. \begin{verbatim}
  367. FOR ALL <var1>,...,<varn>
  368. LET DF(<operator><varlist>,<vari>)=<expression>
  369. \end{verbatim}
  370. where {\tt <varlist>} ::= ({\tt <var1>},\dots,{\tt <varn>}), and
  371. {\tt <var1>},...,{\tt <varn>} are the dummy variable arguments of
  372. {\tt <operator>}.
  373. An analogous form applies to infix operators.
  374. {\it Examples:}
  375. \begin{verbatim}
  376. for all x let df(tan x,x)= 1 + tan(x)^2;
  377. \end{verbatim}
  378. (This is how the tan differentiation rule appears in the {\REDUCE}
  379. source.)
  380. \begin{verbatim}
  381. for all x,y let df(f(x,y),x)=2*f(x,y),
  382. df(f(x,y),y)=x*f(x,y);
  383. \end{verbatim}
  384. Notice that all dummy arguments of the relevant operator must be declared
  385. arbitrary by the {\tt FOR ALL} command, and that rules may be supplied for
  386. operators with any number of arguments. If no differentiation rule
  387. appears for an argument in an operator, the differentiation routines will
  388. return as result an expression in terms of {\tt DF}\ttindex{DF}. For
  389. example, if the rule for the differentiation with respect to the second
  390. argument of {\tt F} is not supplied, the evaluation of {\tt df(f(x,z),z)}
  391. would leave this expression unchanged. (No {\tt DEPEND} declaration
  392. is needed here, since {\tt f(x,z)} obviously ``depends on'' {\tt Z}.)
  393. Once such a rule has been defined for a given operator, any future
  394. differentiation\index{Differentiation} rules for that operator must be
  395. defined with the same number of arguments for that operator, otherwise we
  396. get the error message
  397. \begin{verbatim}
  398. Incompatible DF rule argument length for <operator>
  399. \end{verbatim}
  400. \section{INT Operator}
  401. {\tt INT}\ttindex{INT} is an operator in {\REDUCE} for indefinite
  402. integration\index{Integration}\index{Indefinite integration} using a
  403. combination of the Risch-Norman algorithm and pattern matching. It is
  404. used with the syntax:
  405. \begin{verbatim}
  406. INT(EXPRN:algebraic,VAR:kernel):algebraic.
  407. \end{verbatim}
  408. This will return correctly the indefinite integral for expressions comprising
  409. polynomials, log functions, exponential functions and tan and atan. The
  410. arbitrary constant is not represented. If the integral cannot be done in
  411. closed terms, it returns a formal integral for the answer in one of two ways:
  412. \begin{enumerate}
  413. \item It returns the input, {\tt INT(\ldots,\ldots)} unchanged.
  414. \item It returns an expression involving {\tt INT}s of some
  415. other functions (sometimes more complicated than
  416. the original one, unfortunately).
  417. \end{enumerate}
  418. Rational functions can be integrated when the denominator is factorizable
  419. by the program. In addition it will attempt to integrate expressions
  420. involving error functions, dilogarithms and other trigonometric
  421. expressions. In these cases it might not always succeed in finding the
  422. solution, even if one exists.
  423. {\it Examples:}
  424. \begin{verbatim}
  425. int(log(x),x) -> X*(LOG(X) - 1),
  426. int(e^x,x) -> E**X.
  427. \end{verbatim}
  428. The program checks that the second argument is a variable and gives an
  429. error if it is not.
  430. {\it Note:} If the {\tt int} operator is called with 4 arguments,
  431. {\REDUCE} will implicitly call the definite integration package (DEFINT)
  432. and this package will interpret the third and fourth arguments as the lower
  433. and upper limit of integration, respectively. For details, consult
  434. the documentation on the DEFINT package.
  435. \subsection{Options}
  436. The switch {\tt TRINT} when on will trace the operation of the algorithm. It
  437. produces a great deal of output in a somewhat illegible form, and is not
  438. of much interest to the general user. It is normally off.
  439. If the switch {\tt FAILHARD} is on the algorithm will terminate with an
  440. error if the integral cannot be done in closed terms, rather than return a
  441. formal integration form. {\tt FAILHARD} is normally off.
  442. The switch {\tt NOLNR} suppresses the use of the linear properties of
  443. integration in cases when the integral cannot be found in closed terms.
  444. It is normally off.
  445. \subsection{Advanced Use}
  446. If a function appears in the integrand that is not one of the functions
  447. {\tt EXP, ERF, TAN, ATAN, LOG, DILOG}\ttindex{EXP}\ttindex{ERF}
  448. \ttindex{TAN}\ttindex{ATAN}\ttindex{LOG}\ttindex{DILOG}
  449. then the algorithm will make an
  450. attempt to integrate the argument if it can, differentiate it and reach a
  451. known function. However the answer cannot be guaranteed in this case. If
  452. a function is known to be algebraically independent of this set it can be
  453. flagged transcendental by
  454. \begin{verbatim}
  455. flag('(trilog),'transcendental);
  456. \end{verbatim}
  457. in which case this function will be added to the permitted field
  458. descriptors for a genuine decision procedure. If this is done the user is
  459. responsible for the mathematical correctness of his actions.
  460. The standard version does not deal with algebraic extensions. Thus
  461. integration of expressions involving square roots and other like things
  462. can lead to trouble. A contributed package that supports integration of
  463. functions involving square roots is available, however
  464. (ALGINT\extendedmanual{, chapter~\ref{ALGINT}}).
  465. In addition there is a definite integration
  466. package, DEFINT\extendedmanual{( chapter~\ref{DEFINT})}.
  467. \subsection{References}
  468. A. C. Norman \& P. M. A. Moore, ``Implementing the New Risch
  469. Algorithm'', Proc. 4th International Symposium on Advanced
  470. Comp. Methods in Theor. Phys., CNRS, Marseilles, 1977.
  471. S. J. Harrington, ``A New Symbolic Integration System in Reduce'',
  472. Comp. Journ. 22 (1979) 2.
  473. A. C. Norman \& J. H. Davenport, ``Symbolic Integration --- The Dust
  474. Settles?'', Proc. EUROSAM 79, Lecture Notes in Computer
  475. Science 72, Springer-Verlag, Berlin Heidelberg New York
  476. (1979) 398-407.
  477. %\subsection{Definite Integration} \index{Definite integration}
  478. %
  479. %If {\tt INT} is used with the syntax
  480. %
  481. %\begin{verbatim}
  482. % INT(EXPRN:algebraic,VAR:kernel,LOWER:algebraic,UPPER:algebraic):algebraic.
  483. %\end{verbatim}
  484. %
  485. %The definite integral of {\tt EXPRN} with respect to {\tt VAR} is
  486. %calculated between the limits {\tt LOWER} and {\tt UPPER}. In the present
  487. %system, this is calculated either by pattern matching, or by first finding
  488. %the indefinite integral, and then substituting the limits into this.
  489. \section{LENGTH Operator}
  490. {\tt LENGTH}\ttindex{LENGTH} is a generic operator for finding the
  491. length of various objects in the system. The meaning depends on the type
  492. of the object. In particular, the length of an algebraic expression is
  493. the number of additive top-level terms its expanded representation.
  494. {\it Examples:}
  495. \begin{verbatim}
  496. length(a+b) -> 2
  497. length(2) -> 1.
  498. \end{verbatim}
  499. Other objects that support a length operator include arrays, lists and
  500. matrices. The explicit meaning in these cases is included in the description
  501. of these objects.
  502. \section{MAP Operator}\ttindex{MAP}
  503. The {\tt MAP} operator applies a uniform evaluation pattern to all members
  504. of a composite structure: a matrix, a list, or the arguments of an
  505. operator expression. The evaluation pattern can be a unary procedure, an
  506. operator, or an algebraic expression with one free variable.
  507. It is used with the syntax:
  508. \begin{verbatim}
  509. MAP(U:function,V:object)
  510. \end{verbatim}
  511. Here {\tt object} is a list, a matrix or an operator expression.
  512. {\tt Function} can be one of the following:
  513. \begin{enumerate}
  514. \item the name of an operator for a single argument: the operator
  515. is evaluated once with each element of {\tt object} as its single argument;
  516. \item an algebraic expression with exactly one free variable, that is
  517. a variable preceded by the tilde symbol. The expression
  518. is evaluated for each element of {\tt object}, where the element is
  519. substituted for the free variable;
  520. \item a replacement rule of the form {\tt var => rep}
  521. where {\tt var} is a variable (a kernel without a subscript)
  522. and {\tt rep} is an expression that contains {\tt var}.
  523. {\tt Rep} is evaluated for each element of {\tt object} where
  524. the element is substituted for {\tt var}. {\tt Var} may be
  525. optionally preceded by a tilde.
  526. \end{enumerate}
  527. The rule form for {\tt function} is needed when more than
  528. one free variable occurs.
  529. Examples:
  530. \begin{verbatim}
  531. map(abs,{1,-2,a,-a}) -> {1,2,ABS(A),ABS(A)}
  532. map(int(~w,x), mat((x^2,x^5),(x^4,x^5))) ->
  533. [ 3 6 ]
  534. [ x x ]
  535. [---- ----]
  536. [ 3 6 ]
  537. [ ]
  538. [ 5 6 ]
  539. [ x x ]
  540. [---- ----]
  541. [ 5 6 ]
  542. map(~w*6, x^2/3 = y^3/2 -1) -> 2*X^2=3*(Y^3-2)
  543. \end{verbatim}
  544. You can use {\tt MAP} in nested expressions. However, you cannot
  545. apply {\tt MAP} to a non-composed object, e.g. an identifier or a number.
  546. \section{MKID Operator}\ttindex{MKID}
  547. In many applications, it is useful to create a set of identifiers for
  548. naming objects in a consistent manner. In most cases, it is sufficient to
  549. create such names from two components. The operator {\tt MKID} is provided
  550. for this purpose. Its syntax is:
  551. \begin{verbatim}
  552. MKID(U:id,V:id|non-negative integer):id
  553. \end{verbatim}
  554. for example
  555. \begin{verbatim}
  556. mkid(a,3) -> A3
  557. mkid(apple,s) -> APPLES
  558. \end{verbatim}
  559. while {\tt mkid(a+b,2)} gives an error.
  560. The {\tt SET}\ttindex{SET} operator can be used to give a value to the
  561. identifiers created by {\tt MKID}, for example
  562. \begin{verbatim}
  563. set(mkid(a,3),3);
  564. \end{verbatim}
  565. will give {\tt A3} the value 2.
  566. \section{PF Operator}\ttindex{PF}
  567. {\tt PF(<exp>,<var>)} transforms the expression {\tt <exp>} into a list of
  568. partial fractions with respect to the main variable, {\tt <var>}. {\tt PF}
  569. does a complete partial fraction decomposition, and as the algorithms used
  570. are fairly unsophisticated (factorization and the extended Euclidean
  571. algorithm), the code may be unacceptably slow in complicated cases.
  572. {\it Example:}
  573. Given {\tt 2/((x+1)\verb|^|2*(x+2))} in the workspace,
  574. {\tt pf(ws,x);} gives the result
  575. \begin{verbatim}
  576. 2 - 2 2
  577. {-------,-------,--------------} .
  578. X + 2 X + 1 2
  579. X + 2*X + 1
  580. \end{verbatim}
  581. If you want the denominators in factored form, use {\tt off exp;}.
  582. Thus, with {\tt 2/((x+1)\verb|^|2*(x+2))} in the workspace, the commands
  583. {\tt off exp; pf(ws,x);} give the result
  584. \begin{verbatim}
  585. 2 - 2 2
  586. {-------,-------,----------} .
  587. X + 2 X + 1 2
  588. (X + 1)
  589. \end{verbatim}
  590. To recombine the terms, {\tt FOR EACH \ldots SUM} can be used. So with
  591. the above list in the workspace, {\tt for each j in ws sum j;} returns the
  592. result
  593. \begin{verbatim}
  594. 2
  595. ------------------
  596. 2
  597. (X + 2)*(X + 1)
  598. \end{verbatim}
  599. Alternatively, one can use the operations on lists to extract any desired
  600. term.
  601. \section{SELECT Operator}\ttindex{SELECT}
  602. \ttindex{map}\ttindex{list}
  603. The {\tt SELECT} operator extracts from a list,
  604. or from the arguments of an n--ary operator, elements corresponding
  605. to a boolean predicate. It is used with the syntax:
  606. \begin{verbatim}
  607. SELECT(U:function,V:list)
  608. \end{verbatim}
  609. {\tt Function} can be one of the following forms:
  610. \begin{enumerate}
  611. \item the name of an operator for a single argument: the operator
  612. is evaluated once with each element of {\tt object} as its single argument;
  613. \item an algebraic expression with exactly one free variable, that is
  614. a variable preceded by the tilde symbol. The expression
  615. is evaluated for each element of \meta{object}, where the element is
  616. substituted for the free variable;
  617. \item a replacement rule of the form \meta{var $=>$ rep}
  618. where {\tt var} is a variable (a kernel without subscript)
  619. and {\tt rep} is an expression that contains {\tt var}.
  620. {\tt Rep} is evaluated for each element of {\tt object} where
  621. the element is substituted for {\tt var}. {\tt var} may be
  622. optionally preceded by a tilde.
  623. \end{enumerate}
  624. The rule form for {\tt function} is needed when more than
  625. one free variable occurs.
  626. The result of evaluating {\tt function} is
  627. interpreted as a boolean value corresponding to the conventions of
  628. {\REDUCE}. These values are composed with the leading operator of the
  629. input expression.
  630. {\it Examples:}
  631. \begin{verbatim}
  632. select( ~w>0 , {1,-1,2,-3,3}) -> {1,2,3}
  633. select(evenp deg(~w,y),part((x+y)^5,0):=list)
  634. -> {X^5 ,10*X^3*Y^2 ,5*X*Y^4}
  635. select(evenp deg(~w,x),2x^2+3x^3+4x^4) -> 4X^4 + 2X^2
  636. \end{verbatim}