symbolic.tex 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. \chapter{Symbolic Mode}\index{Symbolic mode}
  2. At the system level, {\REDUCE} is based on a version of the programming
  3. language Lisp\index{Lisp} known as {\em Standard Lisp\/} which is described
  4. in J. Marti, Hearn, A. C., Griss, M. L. and Griss, C., ``Standard LISP
  5. Report" SIGPLAN Notices, ACM, New York, 14, No 10 (1979) 48-68. We shall
  6. assume in this section that the reader is familiar with the material in
  7. that paper. This also assumes implicitly that the reader has a reasonable
  8. knowledge about Lisp in general, say at the level of the LISP 1.5
  9. Programmer's Manual (McCarthy, J., Abrahams, P. W., Edwards, D. J., Hart,
  10. T. P. and Levin, M. I., ``LISP 1.5 Programmer's Manual'', M.I.T. Press,
  11. 1965) or any of the books mentioned at the end of this section. Persons
  12. unfamiliar with this material will have some difficulty understanding this
  13. section.
  14. Although {\REDUCE} is designed primarily for algebraic calculations, its
  15. source language is general enough to allow for a full range of Lisp-like
  16. symbolic calculations. To achieve this generality, however, it is
  17. necessary to provide the user with two modes of evaluation, namely an
  18. algebraic mode\index{Algebraic mode} and a symbolic mode.\index{Symbolic
  19. mode} To enter symbolic mode, the user types {\tt symbolic;}
  20. \ttindex{SYMBOLIC} (or {\tt lisp;})\ttindex{LISP} and to return to
  21. algebraic mode one types {\tt algebraic;}.\ttindex{ALGEBRAIC}
  22. Evaluations proceed differently in each mode so the user is advised to
  23. check what mode he is in if a puzzling error arises. He can find his mode
  24. by typing\ttindex{EVAL\_MODE}
  25. \begin{verbatim}
  26. eval_mode;
  27. \end{verbatim}
  28. The current mode will then be printed as {\tt ALGEBRAIC} or {\tt SYMBOLIC}.
  29. Expression evaluation may proceed in either mode at any level of a
  30. calculation, provided the results are passed from mode to mode in a
  31. compatible manner. One simply prefixes the relevant expression by the
  32. appropriate mode. If the mode name prefixes an expression at the top
  33. level, it will then be handled as if the global system mode had been
  34. changed for the scope of that particular calculation.
  35. For example, if the current mode is {\tt ALGEBRAIC}, then the commands
  36. \extendedmanual{\newpage}
  37. \begin{verbatim}
  38. symbolic car '(a);
  39. x+y;
  40. \end{verbatim}
  41. will cause the first expression to be evaluated and printed in symbolic
  42. mode and the second in algebraic mode. Only the second evaluation will
  43. thus affect the expression workspace. On the other hand, the statement
  44. \begin{verbatim}
  45. x + symbolic car '(12);
  46. \end{verbatim}
  47. will result in the algebraic value {\tt X+12}.
  48. The use of {\tt SYMBOLIC} (and equivalently {\tt ALGEBRAIC}) in this
  49. manner is the same as any operator. That means that parentheses could be
  50. omitted in the above examples since the meaning is obvious. In other
  51. cases, parentheses must be used, as in
  52. \begin{verbatim}
  53. symbolic(x := 'a);
  54. \end{verbatim}
  55. Omitting the parentheses, as in
  56. \begin{verbatim}
  57. symbolic x := a;
  58. \end{verbatim}
  59. would be wrong, since it would parse as
  60. \begin{verbatim}
  61. symbolic(x) := a;
  62. \end{verbatim}
  63. For convenience, it is assumed that any operator whose {\em first\/} argument is
  64. quoted is being evaluated in symbolic mode, regardless of the mode in
  65. effect at that time. Thus, the first example above could be equally well
  66. written:
  67. \begin{verbatim}
  68. car '(a);
  69. \end{verbatim}
  70. Except where explicit limitations have been made, most {\REDUCE} algebraic
  71. constructions carry over into symbolic mode.\index{Symbolic mode}
  72. However, there are some differences. First, expression evaluation now
  73. becomes Lisp evaluation. Secondly, assignment statements are handled
  74. differently, as we shall discuss shortly. Thirdly, local variables and array
  75. elements are initialized to {\tt NIL} rather than {\tt 0}. (In fact, any
  76. variables not explicitly declared {\tt INTEGER} are also initialized to
  77. {\tt NIL} in algebraic mode, but the algebraic evaluator recognizes {\tt
  78. NIL} as {\tt 0}.) Finally, function definitions follow the conventions of
  79. Standard Lisp.
  80. To begin with, we mention a few extensions to our basic syntax which are
  81. designed primarily if not exclusively for symbolic mode.
  82. \section{Symbolic Infix Operators}
  83. There are three binary infix operators in {\REDUCE} intended for use in
  84. symbolic mode, namely . {\tt (CONS), EQ and MEMQ}. The precedence of
  85. these operators was given in another section.
  86. \section{Symbolic Expressions}
  87. These consist of scalar variables and operators and follow the normal
  88. rules of the Lisp meta language.
  89. {\it Examples:}
  90. \begin{verbatim}
  91. x
  92. car u . reverse v
  93. simp (u+v^2)
  94. \end{verbatim}
  95. \section{Quoted Expressions}\ttindex{QUOTE}
  96. Because symbolic evaluation requires that each variable or expression has a
  97. value, it is necessary to add to {\REDUCE} the concept of a quoted expression
  98. by analogy with the Lisp {\tt QUOTE} function. This is provided by the single
  99. quote mark {\tt '}. For example,
  100. \begin{quote}
  101. \begin{tabbing}
  102. {\tt '(a b c)} \= represents the Lisp S-expression \= {\tt (quote (a b
  103. c))}\kill
  104. {\tt 'a} \> represents the Lisp S-expression \>
  105. {\tt (quote a)} \\
  106. {\tt '(a b c)} \> represents the Lisp S-expression \> {\tt (quote (a b c))}
  107. \end{tabbing}
  108. \end{quote}
  109. Note, however, that strings are constants and therefore evaluate to
  110. themselves in symbolic mode. Thus, to print the string {\tt "A String"}, one
  111. would write
  112. \begin{verbatim}
  113. prin2 "A String";
  114. \end{verbatim}
  115. Within a quoted expression, identifier syntax rules are those of {\REDUCE}.
  116. Thus {\tt (A~!.~~B)} is the list consisting of the three elements {\tt A},
  117. {\tt .}, and {\tt B}, whereas {\tt (A . B)} is the dotted pair of {\tt A}
  118. and {\tt B}.
  119. \section{Lambda Expressions}\ttindex{LAMBDA}
  120. \label{sec-lambda}
  121. {\tt LAMBDA} expressions provide the means for constructing Lisp {\tt LAMBDA}
  122. expressions in symbolic mode. They may not be used in algebraic mode.
  123. Syntax:
  124. \begin{verbatim}
  125. <LAMBDA expression> ::=
  126. LAMBDA <varlist><terminator><statement>
  127. \end{verbatim}
  128. where
  129. \begin{verbatim}
  130. <varlist> ::= (<variable>,...,<variable>)
  131. \end{verbatim}
  132. e.g.,
  133. \begin{verbatim}
  134. lambda (x,y); car x . cdr y;
  135. \end{verbatim}
  136. is equivalent to the Lisp {\tt LAMBDA} expression
  137. \begin{verbatim}
  138. (lambda (x y) (cons (car x) (cdr y)))
  139. \end{verbatim}
  140. The parentheses may be omitted in specifying the variable list if desired.
  141. {\tt LAMBDA} expressions may be used in symbolic mode in place of prefix
  142. operators, or as an argument of the reserved word {\tt FUNCTION}.
  143. In those cases where a {\tt LAMBDA} expression is used to introduce local
  144. variables to avoid recomputation, a {\tt WHERE} statement can also be
  145. used. For example, the expression
  146. \begin{verbatim}
  147. (lambda (x,y); list(car x,cdr x,car y,cdr y))
  148. (reverse u,reverse v)
  149. \end{verbatim}
  150. can also be written
  151. \begin{verbatim}
  152. {car x,cdr x,car y,cdr y} where x=reverse u,y=reverse v
  153. \end{verbatim}
  154. Where possible, {\tt WHERE} syntax is preferred to {\tt LAMBDA} syntax,
  155. since it is more natural.
  156. \section{Symbolic Assignment Statements}\index{Assignment}
  157. In symbolic mode, if the left side of an assignment statement is a
  158. variable, a {\tt SETQ} of the right-hand side to that variable occurs. If
  159. the left-hand side is an expression, it must be of the form of an array
  160. element, otherwise an error will result. For example, {\tt x:=y}
  161. translates into {\tt (SETQ X Y)} whereas {\tt a(3) := 3} will be valid if
  162. {\tt A} has been previously declared a single dimensioned array of at
  163. least four elements.
  164. \section{FOR EACH Statement}\ttindex{FOR EACH}
  165. The {\tt FOR EACH} form of the {\tt FOR} statement, designed for iteration
  166. down a list, is more general in symbolic mode. Its syntax is:
  167. \begin{verbatim}
  168. FOR EACH ID:identifier {IN|ON} LST:list
  169. {DO|COLLECT|JOIN|PRODUCT|SUM} EXPRN:S-expr
  170. \end{verbatim}
  171. As in algebraic mode, if the keyword {\tt IN} is used, iteration is on
  172. each element of the list. With {\tt ON}, iteration is on the whole list
  173. remaining at each point in the iteration. As a result, we have the
  174. following equivalence between each form of {\tt FOR EACH} and the various
  175. mapping functions in Lisp:
  176. \begin{center}
  177. {\tt
  178. \begin{tabular}{|l|lr r|} \hline
  179. & DO & COLLECT & JOIN \\ \hline
  180. IN & MAPC & MAPCAR & MAPCAN \\
  181. ON & MAP & MAPLIST & MAPCON \\ \hline
  182. \end{tabular}}
  183. \end{center}
  184. {\it Example:} To list each element of the list {\tt (a b c)}:
  185. \begin{verbatim}
  186. for each x in '(a b c) collect list x;
  187. \end{verbatim}
  188. \section{Symbolic Procedures}\index{Symbolic procedure}
  189. All the functions described in the Standard Lisp Report are available to
  190. users in symbolic mode. Additional functions may also be defined as
  191. symbolic procedures. For example, to define the Lisp function {\tt ASSOC},
  192. the following could be used:
  193. \begin{verbatim}
  194. symbolic procedure assoc(u,v);
  195. if null v then nil
  196. else if u = caar v then car v
  197. else assoc(u, cdr v);
  198. \end{verbatim}
  199. If the default mode were symbolic, then {\tt SYMBOLIC} could be omitted in
  200. the above definition. {\tt MACRO}s\ttindex{MACRO} may be defined by
  201. prefixing the keyword {\tt PROCEDURE} by the word {\tt MACRO}.
  202. (In fact, ordinary functions may be defined with the keyword {\tt EXPR}
  203. \ttindex{EXPR} prefixing {\tt PROCEDURE} as was used in the Standard Lisp
  204. Report.) For example, we could define a {\tt MACRO CONSCONS} by
  205. \begin{verbatim}
  206. symbolic macro procedure conscons l;
  207. expand(cdr l,'cons);
  208. \end{verbatim}
  209. Another form of macro, the {\tt SMACRO}\ttindex{SMACRO} is also available.
  210. These are described in the Standard Lisp Report. The Report also defines
  211. a function type {\tt FEXPR}.\ttindex{FEXPR}
  212. However, its use is discouraged since it is hard to implement efficiently,
  213. and most uses can be replaced by macros. At the present time, there are
  214. no {\tt FEXPR}s in the core REDUCE system.
  215. \section{Standard Lisp Equivalent of Reduce Input}
  216. A user can obtain the Standard Lisp equivalent of his {\REDUCE} input by
  217. turning on the switch {\tt DEFN}\ttindex{DEFN} (for definition). The
  218. system then prints the Lisp translation of his input but does not evaluate
  219. it. Normal operation is resumed when {\tt DEFN} is turned off.
  220. \section{Communicating with Algebraic Mode}\index{Mode communication}
  221. One of the principal motivations for a user of the algebraic facilities of
  222. {\REDUCE} to learn about symbolic mode\index{Symbolic mode} is that it
  223. gives one access to a wider range of techniques than is possible in
  224. algebraic mode\index{Algebraic mode} alone. For example, if a user
  225. wishes to use parts of the system defined in the basic system source code,
  226. or refine their algebraic code definitions to make them more efficient,
  227. then it is necessary to understand the source language in fairly complete
  228. detail. Moreover, it is also necessary to know a little more about the
  229. way {\REDUCE} operates internally. Basically, {\REDUCE} considers
  230. expressions in two forms: prefix form, which follow the normal Lisp rules
  231. of function composition, and so-called canonical form, which uses a
  232. completely different syntax.
  233. Once these details are understood, the most critical problem faced by a
  234. user is how to make expressions and procedures communicate between symbolic
  235. and algebraic mode. The purpose of this section is to teach a user the
  236. basic principles for this.
  237. If one wants to evaluate an expression in algebraic mode, and then use
  238. that expression in symbolic mode calculations, or vice versa, the easiest
  239. way to do this is to assign a variable to that expression whose value is
  240. easily obtainable in both modes. To facilitate this, a declaration {\tt
  241. SHARE}\ttindex{SHARE} is available. {\tt SHARE} takes a list of
  242. identifiers as argument, and marks these variables as having recognizable
  243. values in both modes. The declaration may be used in either mode.
  244. E.g.,
  245. \begin{verbatim}
  246. share x,y;
  247. \end{verbatim}
  248. says that {\tt X} and {\tt Y} will receive values to be used in both modes.
  249. If a {\tt SHARE} declaration is made for a variable with a previously
  250. assigned algebraic value, that value is also made available in symbolic
  251. mode.
  252. \subsection{Passing Algebraic Mode Values to Symbolic Mode}
  253. If one wishes to work with parts of an algebraic mode
  254. \index{Algebraic mode} expression in symbolic mode,\index{Symbolic mode}
  255. one simply makes an assignment\index{Assignment} of a shared variable to
  256. the relevant expression in algebraic mode. For example, if one wishes to
  257. work with {\tt (a+b)\verb|^|2}, one would say, in algebraic mode:
  258. \begin{verbatim}
  259. x := (a+b)^2;
  260. \end{verbatim}
  261. assuming that {\tt X} was declared shared as above. If we now change to
  262. symbolic mode and say
  263. \begin{verbatim}
  264. x;
  265. \end{verbatim}
  266. its value will be printed as a prefix form with the syntax:
  267. \begin{verbatim}
  268. (*SQ <standard quotient> T)
  269. \end{verbatim}
  270. This particular format reflects the fact that the algebraic mode processor
  271. currently likes to transfer prefix forms from command to command, but
  272. doesn't like to reconvert standard forms\index{Standard form} (which
  273. represent polynomials) and standard quotients back to a true Lisp prefix
  274. form for the expression (which would result in excessive computation). So
  275. {\tt *SQ} is used to tell the algebraic processor that it is dealing with
  276. a prefix form which is really a standard quotient\index{Standard
  277. quotient} and the second argument ({\tt T} or {\tt NIL}) tells it whether
  278. it needs further processing (essentially, an {\em already simplified\/}
  279. flag).
  280. So to get the true standard quotient form in symbolic mode, one needs
  281. {\tt CADR} of the variable. E.g.,
  282. \begin{verbatim}
  283. z := cadr x;
  284. \end{verbatim}
  285. would store in {\tt Z} the standard quotient form for {\tt (a+b)\verb|^|2}.
  286. Once you have this expression, you can now manipulate it as you wish. To
  287. facilitate this, a standard set of selectors\index{Selector} and
  288. constructors\index{Constructor} are available for getting at parts of the
  289. form. Those presently defined are as follows:
  290. \extendedmanual{\newpage}
  291. \begin{center}
  292. \vspace{10pt}
  293. {\large REDUCE Selectors\par}
  294. %\end{center}
  295. %\begin{center}
  296. \renewcommand{\arraystretch}{1.5}
  297. \begin{tabular}{lp{\rboxwidth}}
  298. {\tt DENR} & denominator of standard quotient \\
  299. %
  300. {\tt LC} & leading coefficient of polynomial \\
  301. %
  302. {\tt LDEG} & leading degree of polynomial \\
  303. %
  304. {\tt LPOW} & leading power of polynomial \\
  305. %
  306. {\tt LT} & leading term of polynomial \\
  307. %
  308. {\tt MVAR} & main variable of polynomial \\
  309. %
  310. {\tt NUMR} & numerator (of standard quotient) \\
  311. %
  312. {\tt PDEG} & degree of a power \\
  313. %
  314. {\tt RED} & reductum of polynomial \\
  315. %
  316. {\tt TC} & coefficient of a term \\
  317. %
  318. {\tt TDEG} & degree of a term \\
  319. %
  320. {\tt TPOW} & power of a term
  321. \end{tabular}
  322. \end{center}
  323. \begin{center}
  324. \vspace{10pt}
  325. {\large REDUCE Constructors \par}
  326. %\end{center}
  327. %\begin{center}
  328. \renewcommand{\arraystretch}{1.5}
  329. \begin{tabular}{lp{\redboxwidth}}
  330. \verb|.+| & add a term to a polynomial \\
  331. %
  332. \verb|./| & divide (two polynomials to get quotient) \\
  333. \verb|.*| & multiply power by coefficient to produce term \\
  334. %
  335. \verb|.^| & raise a variable to a power
  336. \end{tabular}
  337. \end{center}
  338. For example, to find the numerator of the standard quotient above, one
  339. could say:
  340. \begin{verbatim}
  341. numr z;
  342. \end{verbatim}
  343. or to find the leading term of the numerator:
  344. \begin{verbatim}
  345. lt numr z;
  346. \end{verbatim}
  347. Conversion between various data structures is facilitated by the use of a
  348. set of functions defined for this purpose. Those currently implemented
  349. include:
  350. {\renewcommand{\arraystretch}{1.5}
  351. \begin{tabular}{lp{\reduceboxwidth}}
  352. {\tt !*A2F} & convert an algebraic expression to
  353. a standard form. If result is rational, an error results; \\
  354. %
  355. {\tt !*A2K} & converts an algebraic expression to
  356. a kernel. If this is not possible, an error results; \\
  357. %
  358. {\tt !*F2A} & converts a standard form to an
  359. algebraic expression; \\
  360. %
  361. {\tt !*F2Q} & convert a standard form to a
  362. standard quotient; \\
  363. %
  364. {\tt !*K2F} & convert a kernel to a standard form; \\
  365. {\tt !*K2Q} & convert a kernel to a standard quotient; \\
  366. %
  367. {\tt !*P2F} & convert a standard power to a
  368. standard form; \\
  369. %
  370. {\tt !*P2Q} & convert a standard power to a standard quotient; \\
  371. %
  372. {\tt !*Q2F} & convert a standard quotient to a
  373. standard form. If the quotient denominator is not 1, an error results; \\
  374. %
  375. {\tt !*Q2K} & convert a standard quotient to a
  376. kernel. If this is not possible, an error results; \\
  377. %
  378. {\tt !*T2F} & convert a standard term to a standard form \\
  379. %
  380. {\tt !*T2Q} & convert a standard term to a standard quotient.
  381. \end{tabular}}
  382. \subsection{Passing Symbolic Mode Values to Algebraic Mode}
  383. In order to pass the value of a shared variable from symbolic mode to
  384. algebraic mode, the only thing to do is make sure that the value in
  385. symbolic mode is a prefix expression. E.g., one uses
  386. {\tt (expt (plus a b) 2)} for {\tt (a+b)\verb|^|2}, or the format ({\tt *sq
  387. <standard quotient> t}) as described above. However, if you have
  388. been working with parts of a standard form they will probably not be in
  389. this form. In that case, you can do the following:
  390. \begin{enumerate}
  391. \item If it is a standard quotient, call {\tt PREPSQ} on it. This takes a
  392. standard quotient as argument, and returns a prefix expression.
  393. Alternatively, you can call {\tt MK!*SQ} on it, which returns a prefix
  394. form like ({\tt *SQ <standard quotient> T)} and avoids translation of
  395. the expression into a true prefix form.
  396. \item If it is a standard form, call {\tt PREPF} on it. This takes a
  397. standard form as argument, and returns the equivalent prefix expression.
  398. Alternatively, you can convert it to a standard quotient and then call
  399. {\tt MK!*SQ}.
  400. \item If it is a part of a standard form, you must usually first build up a
  401. standard form out of it, and then go to step 2. The conversion functions
  402. described earlier may be used for this purpose. For example,
  403. \begin{enumerate}
  404. \item If {\tt Z} is an expression which is a term, {\tt !*T2F Z} is a
  405. standard form.
  406. \item If {\tt Z} is a standard power, {\tt !*P2F Z} is a standard form.
  407. \item If {\tt Z} is a variable, you can pass it direct to algebraic mode.
  408. \end{enumerate}
  409. \end{enumerate}
  410. For example, to pass the leading term of {\tt (a+b)\verb|^|2} back to
  411. algebraic mode, one could say:
  412. \begin{verbatim}
  413. y:= mk!*sq !*t2q lt numr z;
  414. \end{verbatim}
  415. where {\tt Y} has been declared shared as above. If you now go back to
  416. algebraic mode, you can work with {\tt Y} in the usual way.
  417. \subsection{Complete Example}
  418. The following is the complete code for doing the above steps. The end
  419. result will be that the square of the leading term of $(a+b)^{2}$ is
  420. calculated.
  421. %%\begin{tabular}{lp{\rboxwidth}}
  422. %%{\tt share x,y;} & {\tt \% declare {\tt X} and
  423. %%{\tt Y} as shared} \\
  424. %%{\tt x := (a+b)\verb|^|2;} & {\tt \% store (a+b)\verb|^|2 in X} \\
  425. %%{\tt symbolic;} & {\tt \% transfer to symbolic mode} \\
  426. %%{\tt z := cadr x;} & {\tt \% store a true standard quotient \newline
  427. %% \% in Z} \\[1.7pt]
  428. %%{\tt lt numr z;} & {\tt \% print the leading term of the \newline
  429. %% \% numerator of Z} \\
  430. %%{\tt y := mk!*sq !*t2q numr z;} & {\tt \% store the
  431. %% prefix form of this \newline
  432. %% \% leading term in Y} \\
  433. %%{\tt algebraic;} & {\tt \% return to algebraic mode} \\
  434. %%{\tt y\verb|^|2;} & {\tt \% evaluate square of the leading \newline
  435. %%\% term of (a+b)\verb|^|2}
  436. %%\end{tabular}
  437. \begin{verbatim}
  438. share x,y; % declare X and Y as shared
  439. x := (a+b)^2; % store (a+b)^2 in X
  440. symbolic; % transfer to symbolic mode
  441. z := cadr x; % store a true standard quotient in Z
  442. lt numr z; % print the leading term of the
  443. % numerator of Z
  444. y := mk!*sq !*t2q numr z; % store the prefix form of this
  445. % leading term in Y
  446. algebraic; % return to algebraic mode
  447. y^2; % evaluate square of the leading term
  448. % of (a+b)^2
  449. \end{verbatim}
  450. \subsection{Defining Procedures for Intermode Communication}
  451. If one wishes to define a procedure in symbolic mode for use as an
  452. operator in algebraic mode, it is necessary to declare this fact to the
  453. system by using the declaration {\tt OPERATOR}\ttindex{OPERATOR} in
  454. symbolic mode. Thus
  455. \begin{verbatim}
  456. symbolic operator leadterm;
  457. \end{verbatim}
  458. would declare the procedure {\tt LEADTERM} as an algebraic operator. This
  459. declaration {\em must\/} be made in symbolic mode as the effect in algebraic
  460. mode is different. The value of such a procedure must be a prefix form.
  461. The algebraic processor will pass arguments to such procedures in prefix
  462. form. Therefore if you want to work with the arguments as standard
  463. quotients you must first convert them to that form by using the function
  464. {\tt SIMP!*}. This function takes a prefix form as argument and returns the
  465. evaluated standard quotient.
  466. For example, if you want to define a procedure {\tt LEADTERM} which gives the
  467. leading term of an algebraic expression, one could do this as follows:
  468. \begin{samepage}
  469. \begin{verbatim}
  470. symbolic operator leadterm; % Declare LEADTERM as a symbolic
  471. % mode procedure to be used in
  472. % algebraic mode.
  473. symbolic procedure leadterm u; % Define LEADTERM.
  474. mk!*sq !*t2q lt numr simp!* u;
  475. \end{verbatim}
  476. \end{samepage}
  477. Note that this operator has a different effect than the operator {\tt LTERM}
  478. \ttindex{LTERM}. In the latter case, the calculation is done
  479. with respect to the second argument of the operator. In the example here,
  480. we simply extract the leading term with respect to the system's choice of
  481. main variable.
  482. Finally, if you wish to use the algebraic evaluator on an argument in a
  483. symbolic mode definition, the function {\tt REVAL} can be used. The one
  484. argument of {\tt REVAL} must be the prefix form of an expression. {\tt
  485. REVAL} returns the evaluated expression as a true Lisp prefix form.