DECLARE.TEX 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  1. \section{Declarations}
  2. \begin{Command}{ALGEBRAIC}
  3. \index{evaluation}
  4. The \name{algebraic} command changes REDUCE's mode of operation to
  5. algebraic. When \name{algebraic} is used as an operator (with an
  6. argument inside parentheses) that argument is evaluated in algebraic
  7. mode, but REDUCE's mode is not changed.
  8. \begin{Examples}
  9. algebraic; \\
  10. symbolic; & NIL \\
  11. algebraic(x**2); & X^{2} \\
  12. x**2; & \begin{multilineoutput}{6cm}
  13. ***** The symbol X has no value.
  14. \end{multilineoutput}
  15. \end{Examples}
  16. \begin{Comments}
  17. REDUCE's symbolic mode does not know about most algebraic commands.
  18. Error messages in this mode may also depend on the particular Lisp
  19. used for the REDUCE implementation.
  20. % You can tell that you are in algebraic mode if the numbered prompt
  21. % contains a colon rather than an asterisk.
  22. \end{Comments}
  23. \end{Command}
  24. \begin{Declaration}{ANTISYMMETRIC}
  25. When an operator is declared \name{antisymmetric}, its arguments are
  26. reordered to conform to the internal ordering of the system. If an odd
  27. number of argument interchanges are required to do this ordering,
  28. the sign of the expression is changed.
  29. \begin{Syntax}
  30. \name{antisymmetric} \meta{identifier}\{\name{,}\meta{identifier}\}\optional
  31. \end{Syntax}
  32. \meta{identifier} is an identifier that has been declared as an operator.
  33. \begin{Examples}
  34. operator m,n; \\
  35. antisymmetric m,n; \\
  36. m(x,n(1,2)); & - M( - N(2,1),X) \\
  37. operator p; \\
  38. antisymmetric p; \\
  39. p(a,b,c); & P(A,B,C) \\
  40. p(b,a,c); & - P(A,B,C)
  41. \end{Examples}
  42. \begin{Comments}
  43. If \meta{identifier} has not been declared an operator, the flag
  44. \name{antisymmetric} is still attached to it. When \meta{identifier} is
  45. subsequently used as an operator, the message \name{Declare} \meta{identifier}
  46. \name{operator? (Y or N)} is printed. If the user replies \name{y}, the
  47. antisymmetric property of the operator is used.
  48. Note in the first example, identifiers are customarily ordered
  49. alphabetically, while numbers are ordered from largest to smallest.
  50. The operators may have any desired number of arguments (less than 128).
  51. \end{Comments}
  52. \end{Declaration}
  53. \begin{Declaration}{ARRAY}
  54. The \name{array} declaration declares a list of identifiers to be of type
  55. \name{array}, and sets all their entries to 0.
  56. \begin{Syntax}
  57. \name{array}
  58. \meta{identifier}\(\meta{dimensions}\)
  59. \{\name{,}\meta{identifier}\(\meta{dimensions}\)\}\optional
  60. \end{Syntax}
  61. \meta{identifier} may be any valid REDUCE identifier. If the identifier
  62. was already an array, a warning message is given that the array has been
  63. redefined. \meta{dimensions} are of form
  64. \meta{integer}\{,\meta{integer}\}\optional.
  65. \begin{Examples}
  66. array a(2,5),b(3,3,3),c(200); \\
  67. array a(3,5); & *** ARRAY A REDEFINED \\
  68. a(3,4); & 0 \\
  69. length a; & {4,6}
  70. \end{Examples}
  71. \begin{Comments}
  72. Arrays are always global, even if defined inside a procedure or block
  73. statement. Their status as an array remains until the variable is
  74. reset by \nameref{clear}. Arrays may not have the same names as operators,
  75. procedures or scalar variables.
  76. Array elements are referred to by the usual notation: \name{a(i,j)}
  77. returns the jth element of the ith row. The \nameref{assign}ment operator
  78. \name{:=} is used to put values into the array. Arrays as a whole
  79. cannot be subject to assignment by \nameref{let} or \name{:=} ; the
  80. assignment operator \name{:=} is only valid for individual elements.
  81. When you use \nameref{let} on an array element, the contents of that
  82. element become the argument to \name{let}. Thus, if the element
  83. contains a number or some other expression that is not a valid argument
  84. for this command, you get an error message. If the element contains an
  85. identifier, the identifier has the substitution rule attached to it
  86. globally. The same behavior occurs with \nameref{clear}. If the array
  87. element contains an identifier or simple\_expression, it is cleared. Do
  88. \meta{not} use \name{clear} to try to set an array element to 0. Because
  89. of the side effects of either \name{let} or \name{clear}, it is unwise
  90. to apply either of these to array elements.
  91. Array indices always start with 0, so that the declaration \name{array a(5)}
  92. sets aside 6 units of space, indexed from 0 through 5, and initializes
  93. them to 0. The \nameref{length} command returns a list of the true number of
  94. elements in each dimension.
  95. \end{Comments}
  96. \end{Declaration}
  97. \begin{Command}{CLEAR}
  98. The \name{clear} command is used to remove assignments or remove substitution
  99. rules from any expression.
  100. \begin{Syntax}
  101. \name{clear} \meta{identifier}\{,\meta{identifier}\}\repeated \ or \\
  102. \meta{let-type statement} \name{clear} \meta{identifier}
  103. \end{Syntax}
  104. \meta{identifier} can be any \name{scalar}, \nameref{matrix},
  105. or \nameref{array} variable or
  106. \nameref{procedure} name. \meta{let-type statement} can be any general
  107. or specific \nameref{let} statement (see below in Comments).
  108. \begin{Examples}
  109. array a(2,3); \\
  110. a(2,2) := 15; & A(2,2) := 15 \\
  111. clear a; \\
  112. a(2,2); & Declare A operator? (Y or N) \\
  113. let x = y + z; \\
  114. sin(x); & SIN(Y + Z) \\
  115. clear x; \\
  116. sin(x); & SIN(X) \\
  117. let x**5 = 7; \\
  118. clear x; \\
  119. x**5; & 7 \\
  120. clear x**5; \\
  121. x**5; & X^{5}
  122. \end{Examples}
  123. \begin{Comments}
  124. Although it is not a good idea, operators of the same name but taking
  125. different numbers of arguments can be defined. Using a \name{clear} statement
  126. on any of these operators clears every one with the same name, even if the
  127. number of arguments is different.
  128. The \name{clear} command is used to ``forget" matrices, arrays, operators
  129. and scalar variables, returning their identifiers to the pristine state
  130. to be used for other purposes. When \name{clear} is applied to array
  131. elements, the contents of the array element becomes the argument for
  132. \name{clear}. Thus, you get an error message if the element contains a
  133. number, or some other expression that is not a legal argument to
  134. \name{clear}. If the element contains an identifier, it is cleared.
  135. When clear is applied to matrix elements, an error message is returned
  136. if the element evaluates to a number, otherwise there is no effect. Do
  137. {\em not} try to use \name{clear} to set array or matrix elements to 0.
  138. You will not be pleased with the results.
  139. If you are trying to clear power or product substitution rules made with
  140. either \nameref{let} or \nameref{forall}\ldots\name{let}, you must
  141. reproduce the rule, exactly as you typed it with the same arguments, up to
  142. but not including the equal sign, using the word \name{clear} instead of
  143. the word \name{let}. This is shown in the last example. Any other type of
  144. \name{let} or \name{forall}\ldots\name{let} substitution can be cleared
  145. with just the variable or operator name. \nameref{match} behaves the same as
  146. \nameref{let} in this situation. There is a more complicated example under
  147. \nameref{forall}.
  148. \end{Comments}
  149. \end{Command}
  150. \begin{Command}{CLEARRULES}
  151. \index{rule}
  152. \begin{Syntax}
  153. \name{clearrules} \meta{list}\{,\meta{list}\}\repeated
  154. \end{Syntax}
  155. The operator \name{clearrules} is used to remove previously defined
  156. \nameref{rule} lists from the system. \meta{list} can be an explicit rule
  157. list, or evaluate to a rule list.
  158. \begin{Examples}
  159. trig1 := {cos(~x)*cos(~y) => (cos(x+y)+cos(x-y))/2,
  160. cos(~x)*sin(~y) => (sin(x+y)-sin(x-y))/2,
  161. sin(~x)*sin(~y) => (cos(x-y)-cos(x+y))/2,
  162. cos(~x)^2 => (1+cos(2*x))/2,
  163. sin(~x)^2 => (1-cos(2*x))/2}$ \\
  164. let trig1;
  165. cos(a)*cos(b); &
  166. \rfrac{COS(A - B) + COS(A + B)}{2} \\
  167. clearrules trig1;
  168. cos(a)*cos(b); & COS(A)*COS(B)
  169. \end{Examples}
  170. \end{Command}
  171. \begin{Command}{DEFINE}
  172. The command \name{define} allows you to supply a new name for an identifier
  173. or replace it by any valid REDUCE expression.
  174. \begin{Syntax}
  175. \name{define} \meta{identifier}\name{=}\meta{substitution}
  176. \{\name{,}\meta{identifier}\name{=}\meta{substitution}\}\optional
  177. \end{Syntax}
  178. \meta{identifier} is any valid REDUCE identifier, \meta{substitution} can be a
  179. number, an identifier, an operator, a reserved word, or an expression.
  180. \begin{Examples}
  181. define is= :=, xx=y+z; \\
  182. a is 10; & A := 10 \\
  183. xx**2; & Y^{2} + 2*Y*Z + Z^{2} \\
  184. xx := 10; & Y + Z := 10
  185. \end{Examples}
  186. \begin{Comments}
  187. The renaming is done at the input level, and therefore takes precedence
  188. over any other replacement or substitution declared for the same identifier.
  189. It remains in effect until the end of the REDUCE session. Be careful with
  190. it, since you cannot easily undo it without ending the session.
  191. \end{Comments}
  192. \end{Command}
  193. \begin{Declaration}{DEPEND}
  194. \index{dependency}
  195. \name{depend} declares that its first argument depends on the rest of its
  196. arguments.
  197. \begin{Syntax}
  198. \name{depend} \meta{kernel}\{\name{,}\meta{kernel}\}\repeated
  199. \end{Syntax}
  200. \meta{kernel} must be a legal variable name or a prefix operator (see
  201. \nameref{kernel}).
  202. \begin{Examples}
  203. depend y,x; \\
  204. df(y**2,x); & 2*DF(Y,X)*Y \\
  205. depend z,cos(x),y; \\
  206. df(sin(z),cos(x)); & COS(Z)*DF(Z,COS(X)) \\
  207. df(z**2,x); & 2*DF(Z,X)*Z \\
  208. nodepend z,y; \\
  209. df(z**2,x); & 2*DF(Z,X)*Z \\
  210. cc := df(y**2,x); & CC := 2*DF(Y,X)*Y \\
  211. y := tan x; & Y := TAN(X); \\
  212. cc; & 2*TAN(X)*(TAN(X)^{2} + 1)
  213. \end{Examples}
  214. \begin{Comments}
  215. Dependencies can be removed by using the declaration \nameref{nodepend}.
  216. The differentiation operator uses this information, as shown in the
  217. examples above. Linear operators also use knowledge of dependencies
  218. (see \nameref{linear}). Note that dependencies can be nested: Having
  219. declared \IFTEX{$y$}{y} to depend on \IFTEX{$x$}{x}, and \IFTEX{$z$}{z}
  220. to depend on \IFTEX{$y$}{y}, we
  221. see that the chain rule was applied to the derivative of a function of
  222. \IFTEX{$z$}{z} with respect to \IFTEX{$x$}{x}. If the explicit function of the
  223. dependency is later entered into the system, terms with \name{DF(Y,X)},
  224. for example, are expanded when they are displayed again, as shown in the
  225. last example. The boolean operator \nameref{freeof} allows you to
  226. check the dependency between two algebraic objects.
  227. \end{Comments}
  228. \end{Declaration}
  229. \begin{Declaration}{EVEN}
  230. \begin{Syntax}
  231. \name{even} \meta{identifier}\{,\meta{identifier}\}\optional
  232. \end{Syntax}
  233. This declaration is used to declare an operator {\em even} in its first
  234. argument. Expressions involving an operator declared in this manner are
  235. transformed if the first argument contains a minus sign. Any other
  236. arguments are not affected.
  237. \begin{Examples}
  238. even f; \\
  239. f(-a) & F(A) \\
  240. f(-a,-b) & F(A,-B)
  241. \end{Examples}
  242. \end{Declaration}
  243. \begin{Declaration}{FACTOR}
  244. \index{output}
  245. When a kernel is declared by \name{factor}, all terms involving fixed
  246. powers of that kernel are printed as a product of the fixed powers and
  247. the rest of the terms.
  248. \begin{Syntax}
  249. \name{factor} \meta{kernel} \{\name{,}\meta{kernel}\}\optional
  250. \end{Syntax}
  251. \meta{kernel} must be a \nameref{kernel} or a \nameref{list} of
  252. \name{kernel}s.
  253. \begin{Examples}
  254. a := (x + y + z)**2; &
  255. A := X^{2} + 2*X*Y + 2*X*Z + Y^{2} + 2*Y*Z + Z^{2} \\
  256. factor y; \\
  257. a; &
  258. Y^{2} + 2*Y*(X + Z) + X^{2} + 2*X*Z + Z^{2} \\
  259. factor sin(x); \\
  260. c := df(sin(x)**4*x**2*z,x); &
  261. C := 2*SIN(X)^{4}*X*Z + 4*SIN(X)^{3}*COS(X)*X^{2}*Z \\
  262. remfac sin(x); \\
  263. c; &
  264. 2*SIN(X)^{3}*X*Z*(2*COS(X)*X + SIN(X))
  265. \end{Examples}
  266. \begin{Comments}
  267. Use the \name{factor} declaration to display variables of interest so that
  268. you can see their powers more clearly, as shown in the example. Remove
  269. this special treatment with the declaration \nameref{remfac}. The
  270. \name{factor} declaration is only effective when the switch \nameref{pri}
  271. is on.
  272. The \name{factor} declaration is not a factoring command; to factor
  273. expressions use the \nameref{factor} switch or the \nameref{factorize} command.
  274. The \name{factor} declaration is helpful in such cases as Taylor polynomials
  275. where the explicit powers of the variable are expected at the top level, not
  276. buried in various factored forms.
  277. \end{Comments}
  278. \end{Declaration}
  279. \begin{Command}{FORALL}
  280. \index{substitution}
  281. The \name{forall} or (preferably) \name{for all} command is used as a
  282. modifier for \nameref{let} statements, indicating the universal applicability
  283. of the rule, with possible qualifications.
  284. \begin{Syntax}
  285. \name{for all} \meta{identifier}\{,\meta{identifier}\}\optional\ \name{let}
  286. \meta{let statement}
  287. {\em or}
  288. \name{for all} \meta{identifier}\{,\meta{identifier}\}\optional
  289. \ \name{such that} \meta{condition} \name{let} \meta{let statement}
  290. \end{Syntax}
  291. \meta{identifier} may be any valid REDUCE identifier, \meta{let statement}
  292. can be an operator, a product or power, or a group or block statement.
  293. \meta{condition} must be a logical or comparison operator returning true or
  294. false.
  295. \begin{Examples}
  296. for all x let f(x) = sin(x**2);
  297. & Declare F operator ? (Y or N) \\
  298. y \\
  299. f(a); & SIN(A^{2}) \\
  300. operator pos; \\
  301. for all x such that x>=0 let pos(x) = sqrt(x + 1); \\
  302. pos(5); & SQRT(6) \\
  303. pos(-5); & POS(-5) \\
  304. clear pos; \\
  305. pos(5); & Declare POS operator ? (Y or N) \\
  306. for all a such that numberp a let x**a = 1; \\
  307. x**4; & 1 \\
  308. clear x**a; & *** X**A not found \\
  309. for all a clear x**a; \\
  310. x**4; & 1 \\
  311. for all a such that numberp a clear x**a; \\
  312. x**4; & X^{4}
  313. \end{Examples}
  314. \begin{Comments}
  315. Substitution rules defined by \name{for all} or \name{for
  316. all}\ldots\name{such that} commands that involve products or powers are
  317. cleared by reproducing the command, with exactly the same variable names
  318. used, up to but not including the equal sign, with \nameref{clear}
  319. replacing \name{let}, as shown in the last example. Other substitutions
  320. involving variables or operator names can be cleared with just the name,
  321. like any other variable.
  322. The \nameref{match} command can also be used in product and power substitutions.
  323. The syntax of its use and clearing is exactly like \name{let}. A \name{match}
  324. substitution only replaces the term if it is exactly like the pattern, for
  325. example \name{match x**5 = 1} replaces only terms of \name{x**5} and not
  326. terms of higher powers.
  327. It is easier to declare your potential operator before defining the
  328. \name{for all} rule, since the system will ask you to declare it an
  329. operator anyway. Names of declared arrays or matrices or scalar
  330. variables are invalid as operator names, to avoid ambiguity. Either
  331. \name{for all}\ldots\name{let} statements or procedures are often used to define
  332. operators. One difference is that procedures implement ``call by value"
  333. meaning that assignments involving their formal parameters do not change
  334. the calling variables that replace them. If you use assignment statements
  335. on the formal parameters in a \name{for all}\ldots\name{let} statement, the
  336. effects are seen in the calling variables. Be careful not to redefine a
  337. system operator unless you mean it: the statement \name{for all x let
  338. sin(x)=0;} has exactly that effect, and the usual definition for sin(x) has
  339. been lost for the remainder of the REDUCE session. \end{Comments}
  340. \end{Command}
  341. \begin{Declaration}{INFIX}
  342. \index{operator}
  343. \name{infix} declares identifiers to be infix operators.
  344. \begin{Syntax}
  345. \name{infix} \meta{identifier}\{,\meta{identifier}\}\optional
  346. \end{Syntax}
  347. \meta{identifier} can be any valid REDUCE identifier, which has not already
  348. been declared an operator, array or matrix, and is not reserved by the
  349. system.
  350. \begin{Examples}
  351. infix aa; \\
  352. for all x,y let aa(x,y) = cos(x)*cos(y) - sin(x)*sin(y); \\
  353. x aa y; & COS(X)*COS(Y) - SIN(X)*SIN(Y) \\
  354. pi/3 aa pi/2; & - \rfrac{SQRT(3)}{2} \\
  355. aa(pi,pi); & 1
  356. \end{Examples}
  357. \begin{Comments}
  358. A \nameref{let} statement must be used to attach functionality to
  359. the operator. Note that the operator is defined in prefix form in
  360. the \name{let} statement.
  361. After its definition, the operator may be used in either prefix or infix
  362. mode. The above operator \IFTEX{$aa$}{aa} finds the cosine of the sum
  363. of two angles by the formula
  364. \begin{TEX}
  365. \begin{displaymath}
  366. \cos(x+y) = \cos x \cos y - \sin x \sin y.
  367. \end{displaymath}
  368. \end{TEX}
  369. \begin{INFO}
  370. cos(x+y) = cos(x)*cos(y) - sin(x)*sin(y).
  371. \end{INFO}
  372. Precedence may be attached to infix operators with the
  373. \nameref{precedence} declaration.
  374. User-defined infix operators may be used in prefix form. If they are used
  375. in infix form, a space must be left on each side of the operator to avoid
  376. ambiguity. Infix operators are always binary.
  377. \end{Comments}
  378. \end{Declaration}
  379. \begin{Declaration}{INTEGER}
  380. The \name{integer} declaration must be made immediately after a
  381. \nameref{begin} (or other variable declaration such as \nameref{real}
  382. and \nameref{scalar}) and declares local integer variables. They are
  383. initialized to 0.
  384. \begin{Syntax}
  385. \name{integer} \meta{identifier}\{,\meta{identifier}\}\optional
  386. \end{Syntax}
  387. \meta{identifier} may be any valid REDUCE identifier, except
  388. \name{t} or \name{nil}.
  389. \begin{Comments}
  390. Integer variables remain local, and do not share values with variables of
  391. the same name outside the \nameref{begin}\ldots\name{end} block. When the
  392. block is finished, the variables are removed. You may use the words
  393. \nameref{real} or \nameref{scalar} in the place of \name{integer}.
  394. \name{integer} does not indicate typechecking by the
  395. current REDUCE; it is only for your own information. Declaration
  396. statements must immediately follow the \name{begin}, without a semicolon
  397. between \name{begin} and the first variable declaration.
  398. Any variables used inside \name{begin}\ldots\name{end} blocks that were not
  399. declared \name{scalar}, \name{real} or \name{integer} are global, and any
  400. change made to them inside the block affects their global value. Any
  401. \ref{array} or \ref{matrix} declared inside a block is always global.
  402. \end{Comments}
  403. \end{Declaration}
  404. \begin{Declaration}{KORDER}
  405. \index{kernel order}\index{variable order}\index{order}
  406. The \name{korder} declaration changes the internal canonical ordering of
  407. kernels.
  408. \begin{Syntax}
  409. \name{korder} \meta{kernel}\{\name{,}\meta{kernel}\}\optional
  410. \end{Syntax}
  411. \meta{kernel} must be a REDUCE \nameref{kernel} or a \nameref{list} of
  412. \name{kernel}s.
  413. \begin{Comments}
  414. The declaration \name{korder} changes the internal ordering, but not the print
  415. ordering, so the effects cannot be seen on output. However, in some
  416. calculations, the order of the variables can have significant effects on the
  417. time and space demands of a calculation. If you are doing a demanding
  418. calculation with several kernels, you can experiment with changing the
  419. canonical ordering to improve behavior.
  420. The first kernel in the argument list is given the highest priority, the
  421. second gets the next highest, and so on. Kernels not named in a
  422. \name{korder} ordering otherwise. A new \name{korder} declaration replaces
  423. the previous one. To return to canonical ordering, use the command
  424. \name{korder nil}.
  425. To change the print ordering, use the declaration \nameref{order}.
  426. \end{Comments}
  427. \end{Declaration}
  428. \begin{Command}{LET}
  429. \index{substitution}\index{rule}
  430. The \name{let} command defines general or specific substitution rules.
  431. \begin{Syntax}
  432. \name{let} \meta{identifier} \name{=} \meta{expression}\{,\meta{identifier}
  433. \name{=} \meta{expression}\}\optional
  434. \end{Syntax}
  435. \meta{identifier} can be any valid REDUCE identifier except an array, and in
  436. some cases can be an expression; \meta{expression} can be any valid REDUCE
  437. expression.
  438. \begin{Examples}
  439. let a = sin(x); \\
  440. b := a; & B := SIN X; \\
  441. let c = a; \\
  442. exp(a); & E^{SIN(X)} \\
  443. a := x**2; & A := X^{2} \\
  444. exp(a); & E^{X^{2}} \\
  445. exp(b); & E^{SIN(X)} \\
  446. exp(c); & E^{X^{2}} \\
  447. let m + n = p; \\
  448. (m + n)**5; & P^{5} \\
  449. %%%let z**6 = 0; \\
  450. %%%z**3*(z + 1)**4; & Z^{3}*(6*Z^{2} + 4*Z + 1) \\
  451. operator h; \\
  452. let h(u,v) = u - v; \\
  453. h(u,v); & U - V \\
  454. h(x,y); & H(X,Y) \\
  455. array q(10); \\
  456. let q(1) = 15; & ***** Substitution for 0 not allowed
  457. \end{Examples}
  458. The \name{let} command is also used to activate a \name{rule sets}.
  459. \begin{Syntax}
  460. \name{let} \meta{list}\{,\meta{list}\}\repeated
  461. \end{Syntax}
  462. \meta{list} can be an explicit \nameref{rule} \name{list}, or evaluate
  463. to a rule list.
  464. \begin{Examples}
  465. trig1 := {cos(~x)*cos(~y) => (cos(x+y)+cos(x-y))/2,
  466. cos(~x)*sin(~y) => (sin(x+y)-sin(x-y))/2,
  467. sin(~x)*sin(~y) => (cos(x-y)-cos(x+y))/2,
  468. cos(~x)^2 => (1+cos(2*x))/2,
  469. sin(~x)^2 => (1-cos(2*x))/2}$ \\
  470. let trig1;
  471. cos(a)*cos(b); &
  472. \rfrac{COS(A - B) + COS(A + B)}{2}
  473. \end{Examples}
  474. \begin{Comments}
  475. A \name{let} command returns no value, though the substitution rule is
  476. entered. Assignment rules made by \nameref{assign} and \name{let}
  477. rules are at the
  478. same level, and cancel each other. There is a difference in their
  479. operation, however, as shown in the first example: a \name{let} assignment
  480. tracks the changes in what it is assigned to, while a \name{:=} assignment
  481. is fixed at the value it originally had.
  482. The use of expressions as left-hand sides of \name{let} statements is a
  483. little complicated. The rules of operation are:
  484. \begin{itemize}
  485. \item[(i)]
  486. Expressions of the form A*B = C do not change A, B or C, but set A*B to C.
  487. \item[(ii)]
  488. Expressions of the form A+B = C substitute C - B for A, but do not change
  489. B or C.
  490. \item[(iii)]
  491. Expressions of the form A-B = C substitute B + C for A, but do not change
  492. B or C.
  493. \item[(iv)]
  494. Expressions of the form A/B = C substitute B*C for A, but do not change B or
  495. C.
  496. \item[(v)]
  497. Expressions of the form A**N = C substitute C for A**N in every expression of
  498. a power of A to N or greater. An asymptotic command such as A**N = 0 sets
  499. all terms involving A to powers greater than or equal to N to 0. Finite
  500. fields may be generated by requiring modular arithmetic (the \nameref{modular}
  501. switch) and defining the primitive polynomial via a \name{let} statement.
  502. \end{itemize}
  503. \name{let} substitutions involving expressions are cleared by using
  504. the \nameref{clear} command with exactly the same expression.
  505. Note when a simple \name{let} statement is used to assign functionality to an
  506. operator, it is valid only for the exact identifiers used. For the use of the
  507. \name{let} command to attach more general functionality to an operator,
  508. see \nameref{forall}.
  509. Arrays as a whole cannot be arguments to \name{let} statements, but
  510. matrices as a whole can be legal arguments, provided both arguments are
  511. matrices. However, it is important to note that the two matrices are then
  512. linked. Any change to an element of one matrix changes the corresponding
  513. value in the other. Unless you want this behavior, you should not use
  514. \name{let} for matrices. The assignment operator \nameref{assign} can be used
  515. for non-tracking assignments, avoiding the side effects. Matrices are
  516. redimensioned as needed in \name{let} statements.
  517. When array or matrix elements are used as the left-hand side of \name{let}
  518. statements, the contents of that element is used as the argument. When the
  519. contents is a number or some other expression that is not a valid left-hand
  520. side for \name{let}, you get an error message. If the contents is an
  521. identifier or simple expression, the \name{let} rule is globally attached
  522. to that identifier, and is in effect not only inside the array or matrix,
  523. but everywhere. Because of such unwanted side effects, you should not
  524. use \name{let} with array or matrix elements. The assignment operator
  525. \name{:=} can be used to put values into array or matrix elements without
  526. the side effects.
  527. Local variables declared inside \name{begin}\ldots\name{end} blocks cannot
  528. be used as the left-hand side of \name{let} statements. However,
  529. \nameref{begin}\ldots\name{end} blocks themselves can be used as the
  530. right-hand side of \name{let} statements. The construction:
  531. \begin{Syntax}
  532. \name{for all} \meta{vars}
  533. \name{let}\meta{operator}\(\meta{vars}\)\name{=}\meta{block}
  534. \end{Syntax}
  535. is an alternative to the
  536. \begin{Syntax}
  537. \name{procedure} \meta{name}\(\meta{vars}\)\name{;}\meta{block}
  538. \end{Syntax}
  539. construction. One important difference between the two constructions is that
  540. the \meta{vars} as formal parameters to a procedure have their global values
  541. protected against change by the procedure, while the \meta{vars} of a
  542. \name{let} statement are changed globally by its actions.
  543. Be careful in using a construction such as \name{let x = x + 1} except inside
  544. a controlled loop statement. The process of resubstitution continues until
  545. a stack overflow message is given.
  546. The \name{let} statement may be used to make global changes to variables from
  547. inside procedures. If \name{x} is a formal parameter to a procedure, the
  548. command \name{let x = }\ldots makes the change to the calling variable.
  549. For example, if a procedure was defined by
  550. \begin{verbatim}
  551. procedure f(x,y);
  552. let x = 15;
  553. \end{verbatim}
  554. and the procedure was called as
  555. \begin{verbatim}
  556. f(a,b);
  557. \end{verbatim}
  558. \name{a} would have its value changed to 15. Be careful when using \name{let}
  559. statements inside procedures to avoid unwanted side effects.
  560. It is also important to be careful when replacing \name{let} statements with
  561. other \name{let} statements. The overlapping of these substitutions can be
  562. unpredictable. Ordinarily the latest-entered rule is the first to be applied.
  563. Sometimes the previous rule is superseded completely; other times it stays
  564. around as a special case. The order of entering a set of related \name{let}
  565. expressions is very important to their eventual behavior. The best
  566. approach is to assume that the rules will be applied in an arbitrary order.
  567. %%%Be sure to research this subject carefully when you are programming
  568. %%%mathematical operations using related \name{let} substitutions.
  569. \end{Comments}
  570. \end{Command}
  571. \begin{Declaration}{LINEAR}
  572. \index{operator}
  573. An operator can be declared linear in its first argument over powers of
  574. its second argument by the declaration \name{linear.}
  575. \begin{Syntax}
  576. \name{linear} \meta{operator}\{\name{,}\meta{operator}\}\optional
  577. \end{Syntax}
  578. \meta{operator} must have been declared to be an operator. Be careful not
  579. to use a system operator name, because this command may change its definition.
  580. The operator being declared must have at least two arguments, and the
  581. second one must be a \nameref{kernel}.
  582. \begin{Examples}
  583. operator f; \\
  584. linear f; \\
  585. f(0,x); & 0 \\
  586. f(-y,x); & - F(1,X)*Y \\
  587. f(y+z,x); & F(1,X)*(Y + Z) \\
  588. f(y*z,x); & F(1,X)*Y*Z \\
  589. depend z,x; \\
  590. f(y*z,x); & F(Z,X)*Y \\
  591. f(y/z,x); & F(\rfrac{1}{Z},X)*Y \\
  592. depend y,x; \\
  593. f(y/z,x); & F(\rfrac{Y}{Z},X) \\
  594. nodepend z,x; \\
  595. f(y/z,x); & \rfrac{F(Y,X)}{Z} \\
  596. f(2*e**sin(x),x); & 2*F(E^{SIN(X)},X)
  597. \end{Examples}
  598. \begin{Comments}
  599. Even when the operator has not had its functionality attached, it exhibits
  600. linear properties as shown in the examples. Notice the difference when
  601. dependencies are added. Dependencies are also in effect when the operator's
  602. first argument contains its second, as in the last line above.
  603. For a fully-developed example of the use of linear operators, refer to the
  604. article in the \meta{Journal of Computational Physics}, Vol. 14 (1974), pp.
  605. 301-317, ``Analytic Computation of Some Integrals in Fourth Order Quantum
  606. Electrodynamics," by J.A. Fox and A.C. Hearn. The article includes the
  607. complete listing of REDUCE procedures used for this work.
  608. \end{Comments}
  609. \end{Declaration}
  610. \begin{Declaration}{LINELENGTH}
  611. \index{output}
  612. The \name{linelength} declaration sets the length of the output line. Default
  613. is 80.
  614. \begin{Syntax}
  615. \name{linelength} \meta{expression}
  616. \end{Syntax}
  617. To change the linelength,
  618. \meta{expression} must evaluate to a positive integer less than 128
  619. (although this varies from system to system), and should not be less than
  620. 20 or so for proper operation.
  621. \begin{Comments}
  622. % If you want to use a thin window to set beside another window,
  623. % reset the linelength shorter to avoid problems with raised exponents.
  624. \name{linelength} returns the previous linelength. If you want the current
  625. linelength value, but not change it, say \name{linelength nil}.
  626. \end{Comments}
  627. \end{Declaration}
  628. \begin{Command}{LISP}
  629. The \name{lisp} command changes REDUCE's mode of operation to symbolic. When
  630. \name{lisp} is followed by an expression, that expression is evaluated in
  631. symbolic mode, but REDUCE's mode is not changed. This command is
  632. equivalent to \nameref{symbolic}.
  633. \begin{Examples}
  634. lisp; & NIL \\
  635. car '(a b c d e); & A \\
  636. algebraic; \\
  637. c := (lisp car '(first second))**2; \\
  638. & C := FIRST^{2}
  639. \end{Examples}
  640. \end{Command}
  641. \begin{Declaration}{LISTARGP}
  642. \index{list}\index{argument}
  643. \begin{Syntax}
  644. \name{listargp} \meta{operator}\{\name{,}\meta{operator}\}\optional
  645. \end{Syntax}
  646. If an operator other than those specifically defined for lists is given a
  647. single argument that is a \nameref{list}, then the result of this
  648. operation will be a list in which that operator is applied to each element
  649. of the list.
  650. This process can be inhibited for a specific operator, or list of operators,
  651. by using the declaration \name{listargp}.
  652. \begin{Examples}
  653. log {a,b,c}; & {LOG(A),LOG(B),LOG(C)} \\
  654. listargp log; \\
  655. log {a,b,c}; & LOG({A,B,C})
  656. \end{Examples}
  657. \begin{Comments}
  658. It is possible to inhibit such distribution globally by turning on the
  659. switch \nameref{listargs}. In addition, if an operator has more than one
  660. argument, no such distribution occurs, so \name{listargp} has no effect.
  661. \end{Comments}
  662. \end{Declaration}
  663. \begin{Declaration}{NODEPEND}
  664. \index{depend}
  665. The \name{nodepend} declaration removes the dependency declared with
  666. \nameref{depend}.
  667. \begin{Syntax}
  668. \name{nodepend} \meta{dep-kernel}\{,\meta{kernel}\}\repeated
  669. \end{Syntax}
  670. \meta{dep-kernel} must be a kernel that has had a dependency declared upon the
  671. one or more other kernels that are its other arguments.
  672. \begin{Examples}
  673. depend y,x,z; \\
  674. df(sin y,x); & COS(Y)*DF(Y,X) \\
  675. df(sin y,x,z); & COS(Y)*DF(Y,X,Z) - DF(Y,X)*DF(Y,Z)*SIN(Y) \\
  676. nodepend y,z; \\
  677. df(sin y,x); & COS(Y)*DF(Y,X) \\
  678. df(sin y,x,z); & 0
  679. \end{Examples}
  680. \begin{Comments}
  681. A warning message is printed if the dependency had not been declared by
  682. \name{depend}.
  683. \end{Comments}
  684. \end{Declaration}
  685. \begin{Command}{MATCH}
  686. \index{substitution}
  687. The \name{match} command is similar to the \nameref{let} command, except
  688. that it matches only explicit powers in substitution.
  689. \begin{Syntax}
  690. \name{match} \meta{expr} \name{=} \meta{expression}\{,\meta{expr}
  691. \name{=}\meta{expression}\}\optional
  692. \end{Syntax}
  693. \meta{expr} is generally a term involving powers, and is limited by
  694. the rules for the \nameref{let} command. \meta{expression} may be
  695. any valid REDUCE scalar expression.
  696. \begin{Examples}
  697. match c**2*a**2 = d;
  698. (a+c)**4; &
  699. A^{4} + 4*A^{3}*C + 4*A*C^{3} + C^{4} + 6*D \\
  700. match a+b = c; \\
  701. a + 2*b; & B + C \\
  702. (a + b + c)**2; &
  703. A^{2} - B^{2} + 2*B*C + 3*C^{2} \\
  704. clear a+b; \\
  705. (a + b + c)**2; &
  706. A ^{2} + 2*A*B + 2*A*C + B^{2} + 2*B*C + C^{2} \\
  707. let p*r = s; \\
  708. match p*q = ss; \\
  709. (a + p*r)**2; & A^{2} + 2*A*S + S^{2} \\
  710. (a + p*q)**2; & A^{2} + 2*A*SS + P^{2}*Q^{2}
  711. \end{Examples}
  712. \begin{Comments}
  713. Note in the last example that \name{a + b} has been explicitly matched
  714. after the squaring was done, replacing each single power of \name{a} by
  715. \name{c - b}. This kind of substitution, although following the rules, is
  716. confusing and could lead to unrecognizable results. It is better to use
  717. \name{match} with explicit powers or products only. \name{match} should
  718. not be used inside procedures for the same reasons that \name{let} should
  719. not be.
  720. Unlike \nameref{let} substitutions, \name{match} substitutions are executed
  721. after all other operations are complete. The last example shows the
  722. difference. \name{match} commands can be cleared by using \nameref{clear},
  723. with exactly the expression that the original \name{match} took.
  724. \name{match} commands can also be done more generally with \name{for all}
  725. or \nameref{forall}\ldots\name{such that} commands.
  726. \end{Comments}
  727. \end{Command}
  728. \begin{Declaration}{NONCOM}
  729. \index{commutative}\index{non commutative}\index{operator}
  730. \name{noncom} declares that already-declared operators are noncommutative
  731. under multiplication.
  732. \begin{Syntax}
  733. \name{noncom} \meta{operator}\{,\meta{operator}\}\optional
  734. \end{Syntax}
  735. \meta{operator} must have been declared an \nameref{operator}, or a warning
  736. message is given.
  737. \begin{Examples}
  738. operator f,h; \\
  739. noncom f; \\
  740. f(a)*f(b) - f(b)*f(a); & F(A)*F(B) - F(B)*F(A) \\
  741. h(a)*h(b) - h(b)*h(a); & 0 \\
  742. operator comm; \\
  743. \begin{multilineinput}
  744. for all x,y such that x neq y and ordp(x,y)
  745. let f(x)*f(y) = f(y)*f(x) + comm(x,y);
  746. \end{multilineinput}\\
  747. f(1)*f(2); & F(1)*F(2) \\
  748. f(2)*f(1); & COMM(2,1) + F(1)*F(2)
  749. \end{Examples}
  750. \begin{Comments}
  751. The last example introduces the commutator of $f(x)$ and $f(y)$
  752. for all x and y. The equality check is to prevent an infinite loop. The
  753. operator {\it f} can have other functionality attached to it if desired, or it
  754. can remain an indeterminate operator.
  755. \end{Comments}
  756. \end{Declaration}
  757. \begin{Declaration}{NONZERO}
  758. \index{operator}
  759. \begin{Syntax}
  760. \name{nonzero} \meta{identifier}\{,\meta{identifier}\}\optional
  761. \end{Syntax}
  762. If an \ref{operator} \name{f} is declared \nameref{odd}, then \name{f(0)}
  763. is replaced by zero unless \name{f} is also declared {\em non zero} by the
  764. declaration \name{nonzero}.
  765. \begin{Examples}
  766. odd f; \\
  767. f(0) & 0 \\
  768. nonzero f; \\
  769. f(0) & F(0)
  770. \end{Examples}
  771. \end{Declaration}
  772. \begin{Declaration}{ODD}
  773. \index{operator}
  774. \begin{Syntax}
  775. \name{odd} \meta{identifier}\{,\meta{identifier}\}\optional
  776. \end{Syntax}
  777. This declaration is used to declare an operator {\em odd} in its first
  778. argument. Expressions involving an operator declared in this manner are
  779. transformed if the first argument contains a minus sign. Any other
  780. arguments are not affected.
  781. \begin{Examples}
  782. odd f; \\
  783. f(-a) & -F(A) \\
  784. f(-a,-b) & -F(A,-B) \\
  785. f(a,-b) & F(A,-B)
  786. \end{Examples}
  787. \begin{Comments}
  788. If say \name{f} is declared odd, then \name{f(0)} is replaced by zero
  789. unless \name{f} is also declared {\em non zero} by the declaration
  790. \nameref{nonzero}.
  791. \end{Comments}
  792. \end{Declaration}
  793. \begin{Command}{OFF}
  794. \index{switch}
  795. The \name{off} command is used to turn switches off.
  796. \begin{Syntax}
  797. \name{off} \meta{switch}\{,\meta{switch}\}\optional
  798. \end{Syntax}
  799. \meta{switch} can be any \name{switch} name. There is no problem if the
  800. switch is already off. If the switch name is mistyped, an error message is
  801. given.
  802. \end{Command}
  803. \begin{Command}{ON}
  804. \index{switch}
  805. The \name{on} command is used to turn switches on.
  806. \begin{Syntax}
  807. \name{on} \meta{switch}\{,\meta{switch}\}\optional
  808. \end{Syntax}
  809. \meta{switch} can be any \name{switch} name. There is no problem if the
  810. switch is already on. If the switch name is mistyped, an error message is
  811. given.
  812. \end{Command}
  813. \begin{Declaration}{OPERATOR}
  814. Use the \name{operator} declaration to declare your own operators.
  815. \begin{Syntax}
  816. \name{operator} \meta{identifier}\{,\meta{identifier}\}\optional
  817. \end{Syntax}
  818. \meta{identifier} can be any valid REDUCE identifier, which is not the name
  819. of a \nameref{matrix}, \nameref{array}, scalar variable or previously-defined
  820. operator.
  821. \begin{Examples}
  822. operator dis,fac; \\
  823. let dis(~x,~y) = sqrt(x^2 + y^2); \\
  824. dis(1,2); & SQRT(5) \\
  825. dis(a,10); & SQRT(A^{2} + 100) \\
  826. on rounded; \\
  827. dis(1.5,7.2); & 7.35459040329\\
  828. \begin{multilineinput}
  829. let fac(~n) = if n=0 then 1
  830. else if not(fixp n and n>0)
  831. then rederr "choose non-negative integer"
  832. else for i := 1:n product i;
  833. \end{multilineinput} \\
  834. fac(5); & 120 \\
  835. fac(-2); & ***** choose non-negative integer
  836. \end{Examples}
  837. \begin{Comments}
  838. The first operator is the Euclidean distance metric, the distance of point
  839. $(x,y)$ from the origin. The second operator is the factorial.
  840. Operators can have various properties assigned to them; they can be
  841. declared \nameref{infix}, \nameref{linear}, \nameref{symmetric},
  842. \nameref{antisymmetric}, or \nameref{noncom}\name{mutative}.
  843. The default operator is prefix, nonlinear, and commutative.
  844. Precedence can also be assigned to operators using the declaration
  845. \nameref{precedence}.
  846. Functionality is assigned to an operator by a \nameref{let} statement or
  847. a \nameref{forall}\ldots\name{let} statement,
  848. (or possibly by a procedure with the name
  849. of the operator). Be careful not to redefine a system operator by
  850. accident. REDUCE permits you to redefine system operators, giving you a
  851. warning message that the operator was already defined. This flexibility
  852. allows you to add mathematical rules that do what you want them to do, but
  853. can produce odd or erroneous behavior if you are not careful.
  854. You can declare operators from inside \nameref{procedure}s, as long as they
  855. are not local variables. Operators defined inside procedures are global.
  856. A formal parameter may be declared as an operator, and has the effect of
  857. declaring the calling variable as the operator.
  858. \end{Comments}
  859. \end{Declaration}
  860. \begin{Declaration}{ORDER}
  861. \index{order}\index{variable order}\index{output}
  862. The \name{order} declaration changes the order of precedence of kernels for
  863. display purposes only.
  864. \begin{Syntax}
  865. \name{order} \meta{identifier}\{,\meta{identifier}\}\optional
  866. \end{Syntax}
  867. \meta{kernel} must be a valid \nameref{kernel} or \nameref{operator} name
  868. complete with argument or a \nameref{list} of such objects.
  869. \begin{Examples}
  870. x + y + z + cos(a); & COS(A) + X + Y + Z \\
  871. order z,y,x,cos(a); \\
  872. x + y + z + cos(a); & Z + Y + X + COS(A) \\
  873. (x + y)**2; & Y^{2} + 2*Y*X + X^{2} \\
  874. order nil; \\
  875. (z + cos(z))**2; & COS(Z)^{2} + 2*COS(Z)*Z + Z^{2}
  876. \end{Examples}
  877. \begin{Comments}
  878. \name{order} affects the printing order of the identifiers only; internal
  879. order is unchanged. Change internal order of evaluation with the
  880. declaration \nameref{korder}. You can use \name{order} to feature variables
  881. or functions you are particularly interested in.
  882. Declarations made with \name{order} are cumulative: kernels in new order
  883. declarations are ordered behind those in previous declarations, and
  884. previous declarations retain their relative order. Of course, specific
  885. kernels named in new declarations are removed from previous ones and given
  886. the new priority. Return to the standard canonical printing order with the
  887. statement \name{order nil}.
  888. The print order specified by \name{order} commands is not in effect if the
  889. switch \nameref{pri} is off.
  890. \end{Comments}
  891. \end{Declaration}
  892. \begin{Declaration}{PRECEDENCE}
  893. \index{operator}
  894. The \name{precedence} declaration attaches a precedence to an infix operator.
  895. \begin{Syntax}
  896. \name{precedence} \meta{operator},\meta{known\_operator}
  897. \end{Syntax}
  898. \meta{operator} should have been declared an operator but may be a REDUCE
  899. identifier that is not already an operator, array, or matrix.
  900. \meta{known\_operator} must be a system infix operator or have had its
  901. precedence already declared.
  902. \begin{Examples}
  903. operator f,h; \\
  904. precedence f,+; \\
  905. precedence h,*; \\
  906. a + f(1,2)*c; & (1 F 2)*C + A \\
  907. a + h(1,2)*c; & 1 H 2*C + A \\
  908. a*1 f 2*c; & A F 2*C \\
  909. a*1 h 2*c; & 1 H 2*A*C
  910. %%%symbolic; & NIL \\
  911. %%%preclis!*; &
  912. %%% (IREM IEQUAL OVER ADD MULT TO OR AND NOT MEMBER MEMQ EQUAL NEQ EQ GEQ
  913. %%% GREATERP IGREATERP LEQ LESSP ILESSP FREEOF PLUS F IPLUS DIFFERENCE
  914. %%% IDIFFERENCE TIMES H ITIMES QUOTIENT IQUOTIENT EXPT CONS)
  915. \end{Examples}
  916. \begin{Comments}
  917. The operator whose precedence is being declared is inserted into the infix
  918. operator precedence list at the next higher place than \meta{known\_operator}.
  919. Attaching a precedence to an operator has the side effect of declaring the
  920. operator to be infix. If the identifier argument for \name{precedence} has
  921. not been declared to be an operator, an attempt to use it causes an error
  922. message. After declaring it to be an operator, it becomes an infix operator
  923. with the precedence previously given. Infix operators may be used in prefix
  924. form; if they are used in infix form, a space must be left on each side of
  925. the operator to avoid ambiguity. Declared infix operators are always binary.
  926. To see the infix operator precedence list, enter symbolic mode and type
  927. \name{preclis!*;}. The lowest precedence operator is listed first.
  928. All prefix operators have precedence higher than infix operators.
  929. \end{Comments}
  930. \end{Declaration}
  931. \begin{Declaration}{PRECISION}
  932. \index{rounded}\index{floating point}
  933. The \name{precision} declaration sets the number of decimal places used when
  934. \nameref{rounded} is on. Default is system dependent, and normally about 12.
  935. \begin{Syntax}
  936. \name{precision}(\meta{integer}) or \name{precision} \meta{integer}
  937. \end{Syntax}
  938. \meta{integer} must be a positive integer. When \meta{integer} is 0, the
  939. current precision is displayed, but not changed. There is no upper limit,
  940. but precision of greater than several hundred causes unpleasantly slow
  941. operation on numeric calculations.
  942. \begin{Examples}
  943. on rounded; \\
  944. 7/9; & 0.777777777778 \\
  945. precision 20; & 20 \\
  946. 7/9; & 0.77777777777777777778 \\
  947. sin(pi/4); & 0.7071067811865475244
  948. \end{Examples}
  949. \begin{Comments}
  950. Trailing zeroes are dropped, so sometimes fewer than 20 decimal places are
  951. printed as in the last example. Turn on the switch \nameref{fullprec} if
  952. you want to print all significant digits. The \nameref{rounded} mode
  953. carries calculations to two more places than given by \name{precision}, and
  954. rounds off.
  955. \end{Comments}
  956. \end{Declaration}
  957. \begin{Declaration}{PRINT\_PRECISION}
  958. \index{output}\index{floating point}\index{rounded}
  959. \begin{Syntax}
  960. \name{print\_precision}(\meta{integer})
  961. or \name{print\_precision} \meta{integer}
  962. \end{Syntax}
  963. In \nameref{rounded} mode, numbers are normally printed to the specified
  964. precision. If the user wishes to print such numbers with less precision,
  965. the printing precision can be set by the declaration \name{print\_precision}.
  966. \begin{Examples}
  967. on rounded; \\
  968. 1/3; & 0.333333333333 \\
  969. print_precision 5; \\
  970. 1/3 & 0.33333
  971. \end{Examples}
  972. \end{Declaration}
  973. \begin{Declaration}{REAL}
  974. The \name{real} declaration must be made immediately after a
  975. \nameref{begin} (or other variable declaration such as \nameref{integer}
  976. and \nameref{scalar}) and declares local integer variables. They are
  977. initialized to zero.
  978. \begin{Syntax}
  979. \name{real} \meta{identifier}\{,\meta{identifier}\}\optional
  980. \end{Syntax}
  981. \meta{identifier} may be any valid REDUCE identifier, except
  982. \name{t} or \name{nil}.
  983. \begin{Comments}
  984. Real variables remain local, and do not share values with variables of the
  985. same name outside the \nameref{begin}\ldots\name{end} block. When the
  986. block is finished, the variables are removed. You may use the words
  987. \nameref{integer} or \nameref{scalar} in the place of \name{real}.
  988. \name{real} does not indicate typechecking by the current REDUCE; it is
  989. only for your own information. Declaration statements must immediately
  990. follow the \name{begin}, without a semicolon between \name{begin} and the
  991. first variable declaration.
  992. Any variables used inside a \name{begin}\ldots\name{end} \nameref{block}
  993. that were not declared \name{scalar}, \name{real} or \name{integer} are
  994. global, and any change made to them inside the block affects their global
  995. value. Any \ref{array} or \ref{matrix} declared inside a block is always
  996. global.
  997. \end{Comments}
  998. \end{Declaration}
  999. \begin{Declaration}{REMFAC}
  1000. \index{factor}\index{output}
  1001. The \name{remfac} declaration removes the special factoring treatment of its
  1002. arguments that was declared with \nameref{factor}.
  1003. \begin{Syntax}
  1004. \name{remfac} \meta{kernel}\{,\meta{kernel}\}\repeated
  1005. \end{Syntax}
  1006. \meta{kernel} must be a \nameref{kernel} or \nameref{operator} name that
  1007. was declared as special with the \nameref{factor} declaration.
  1008. \end{Declaration}
  1009. \begin{Declaration}{SCALAR}
  1010. The \name{scalar} declaration must be made immediately after a
  1011. \nameref{begin} (or other variable declaration such as \nameref{integer}
  1012. and \nameref{real}) and declares local scalar variables. They are
  1013. initialized to 0.
  1014. \begin{Syntax}
  1015. \name{scalar} \meta{identifier}\{,\meta{identifier}\}\optional
  1016. \end{Syntax}
  1017. \meta{identifier} may be any valid REDUCE identifier, except \name{t} or
  1018. \name{nil}.
  1019. \begin{Comments}
  1020. Scalar variables remain local, and do not share values with variables of
  1021. the same name outside the \nameref{begin}\ldots\name{end} \nameref{block}.
  1022. When the block is finished, the variables are removed. You may use the
  1023. words \nameref{real} or \nameref{integer} in the place of \name{scalar}.
  1024. \name{real} and \name{integer} do not indicate typechecking by the current
  1025. REDUCE; they are only for your own information. Declaration statements
  1026. must immediately follow the \name{begin}, without a semicolon between
  1027. \name{begin} and the first variable declaration.
  1028. Any variables used inside \name{begin}\ldots\name{end} blocks that were not
  1029. declared \name{scalar}, \name{real} or \name{integer} are global, and any
  1030. change made to them inside the block affects their global value. Arrays
  1031. declared inside a block are always global.
  1032. \end{Comments}
  1033. \end{Declaration}
  1034. \begin{Declaration}{SCIENTIFIC\_NOTATION}
  1035. \index{output}\index{floating point}\index{rounded}
  1036. \begin{Syntax}
  1037. \name{scientific\_notation}(\meta{m}) or
  1038. \name{scientific\_notation}(\{\meta{m},\meta{n}\})
  1039. \end{Syntax}
  1040. \meta{m} and \meta{n} are positive integers.
  1041. \name{scientific\_notation} controls the output format of floating point
  1042. numbers. At the default settings, any number with five or less digits
  1043. before the decimal point is printed in a fixed-point notation, e.g.,
  1044. {\tt 12345.6}. Numbers with more than five digits are printed in scientific
  1045. notation, e.g., {\tt 1.234567E+5}. Similarly, by default, any number with
  1046. eleven or more zeros after the decimal point is printed in scientific
  1047. notation.
  1048. When \name{scientific\_notation} is called with the numerical argument
  1049. {\em m} a number with more than {\em m} digits before the decimal point,
  1050. or {\em m} or more zeros after the decimal point, is printed in scientific
  1051. notation. When \name{scientific\_notation} is called with a list
  1052. \{\meta{m},\meta{n}\}, a number with more than {\em m} digits before the
  1053. decimal point, or {\em n} or more zeros after the decimal point is
  1054. printed in scientific notation.
  1055. \begin{Examples}
  1056. on rounded;\\
  1057. 12345.6;&
  1058. 12345.6\\
  1059. 123456.5;&1.234565e+5\\
  1060. 0.00000000000000012;&
  1061. 1.2e-16\\
  1062. scientific_notation 20;&
  1063. {5,11}\\
  1064. 5: 123456.7;&
  1065. 123456.7\\
  1066. 0.00000000000000012;&
  1067. 0.00000000000000012\\
  1068. \end{Examples}
  1069. \end{Declaration}
  1070. \begin{Declaration}{SHARE}
  1071. The \name{share} declaration allows access to its arguments by both
  1072. algebraic and symbolic modes.
  1073. \begin{Syntax}
  1074. \name{share} \meta{identifier}\{,\meta{identifier}\}\optional
  1075. \end{Syntax}
  1076. \meta{identifier} can be any valid REDUCE identifier.
  1077. \begin{Comments}
  1078. Programming in \nameref{symbolic} as well as algebraic mode allows
  1079. you a wider range
  1080. of techniques than just algebraic mode alone. Expressions do not cross the
  1081. boundary since they have different representations, unless the \name{share}
  1082. declaration is used. For more information on using symbolic mode, see
  1083. the \meta{REDUCE User's Manual}, and the \meta{Standard Lisp Report}.
  1084. You should be aware that a previously-declared array is destroyed by the
  1085. \name{share} declaration. Scalar variables retain their values. You can
  1086. share a declared \nameref{matrix} that has not yet
  1087. been dimensioned so that it can be
  1088. used by both modes. Values that are later put into the matrix are
  1089. accessible from symbolic mode too, but not by the usual matrix reference
  1090. mechanism. In symbolic mode, a matrix is stored as a list whose first
  1091. element is \nameref{MAT}, and whose next elements are the rows of the matrix
  1092. stored as lists of the individual elements. Access in symbolic mode is by
  1093. the operators \nameref{first}, \nameref{second}, \nameref{third} and
  1094. \nameref{rest}.
  1095. \end{Comments}
  1096. \end{Declaration}
  1097. \begin{Command}{SYMBOLIC}
  1098. The \name{symbolic} command changes REDUCE's mode of operation to symbolic.
  1099. When \name{symbolic} is followed by an expression, that expression is
  1100. evaluated in symbolic mode, but REDUCE's mode is not changed. It is
  1101. equivalent to the \nameref{lisp} command.
  1102. \begin{Examples}
  1103. symbolic; & NIL \\
  1104. cdr '(a b c); & (B C) \\
  1105. algebraic; \\
  1106. x + symbolic car '(y z); & X + Y
  1107. \end{Examples}
  1108. % \begin{Comments}
  1109. % You can tell when you are in symbolic mode by noting that the numbered
  1110. % prompt contains an asterisk (\name{*}) rather than a colon.
  1111. % \end{Comments}
  1112. \end{Command}
  1113. \begin{Declaration}{SYMMETRIC}
  1114. \index{operator}
  1115. When an operator is declared \name{symmetric}, its arguments are reordered
  1116. to conform to the internal ordering of the system.
  1117. \begin{Syntax}
  1118. \name{symmetric} \meta{identifier}\{,\meta{identifier}\}\optional
  1119. \end{Syntax}
  1120. \meta{identifier} is an identifier that has been declared an operator.
  1121. \begin{Examples}
  1122. operator m,n; \\
  1123. symmetric m,n; \\
  1124. m(y,a,sin(x)); & M(SIN(X),A,Y) \\
  1125. n(z,m(b,a,q)); & N(M(A,B,Q),Z)
  1126. \end{Examples}
  1127. \begin{Comments}
  1128. If \meta{identifier} has not been declared to be an operator, the flag
  1129. \name{symmetric} is still attached to it. When \meta{identifier} is
  1130. subsequently used as an operator, the message \name{Declare}\meta{identifier}
  1131. \name{operator ? (Y or N)} is printed. If the user replies \name{y}, the
  1132. symmetric property of the operator is used.
  1133. \end{Comments}
  1134. \end{Declaration}
  1135. \begin{Declaration}{TR}
  1136. \index{trace}
  1137. The \name{tr} declaration is used to trace system or user-written procedures.
  1138. It is only useful to those with a good knowledge of both Lisp and the
  1139. internal formats used by REDUCE.
  1140. \begin{Syntax}
  1141. \name{tr} \meta{name}\{,\meta{name}\}\optional
  1142. \end{Syntax}
  1143. \meta{name} is the name of a REDUCE system procedure or one of your own
  1144. procedures.
  1145. \begin{Examples}
  1146. \explanation{The system procedure \name{prepsq} is traced,
  1147. which prepares REDUCE standard
  1148. forms for printing by converting them to a Lisp prefix form.} \\
  1149. tr prepsq; & (PREPSQ) \\
  1150. x**2 + y; &
  1151. \begin{multilineoutput}{6cm}
  1152. PREPSQ entry:
  1153. Arg 1: (((((X . 2) . 1) ((Y . 1) . 1)) . 1)
  1154. PREPSQ return value = (PLUS (EXPT X 2) Y)
  1155. PREPSQ entry:
  1156. Arg 1: (1 . 1)
  1157. PREPSQ return value = 1
  1158. X^{2} + Y
  1159. \end{multilineoutput}\\
  1160. untr prepsq; & (PREPSQ)
  1161. \end{Examples}
  1162. \begin{Comments}
  1163. This example is for a PSL-based system; the above format will vary if
  1164. other Lisp systems are used.
  1165. When a procedure is traced, the first lines show entry to the procedure and
  1166. the arguments it is given. The value returned by the procedure is printed
  1167. upon exit. If you are tracing several procedures, with a call to one of
  1168. them inside the other, the inner trace will be indented showing procedure
  1169. nesting. There are no trace options. However, the format of the trace
  1170. depends on the underlying Lisp system used. The trace can be removed with
  1171. the command \nameref{untr}. Note that \name{trace}, below, is a matrix
  1172. operator, while \name{tr} does procedure tracing.
  1173. \end{Comments}
  1174. \end{Declaration}
  1175. \begin{Declaration}{UNTR}
  1176. \index{trace}
  1177. The \name{untr} declaration is used to remove a trace from system or
  1178. user-written procedures declared with \nameref{tr}. It is only useful to
  1179. those with a good knowledge of both Lisp and the internal formats used by
  1180. REDUCE.
  1181. \begin{Syntax}
  1182. \name{untr} \meta{name}\{,\meta{name}\}\optional
  1183. \end{Syntax}
  1184. \meta{name} is the name of a REDUCE system procedure or one of your own
  1185. procedures that has previously been the argument of a \name{tr}
  1186. declaration.
  1187. \end{Declaration}
  1188. \begin{Declaration}{VARNAME}
  1189. The declaration \name{varname} instructs REDUCE to use its argument as the
  1190. default Fortran (when \nameref{fort} is on) or \nameref{structr} identifier
  1191. and identifier stem, rather than using \name{ANS}.
  1192. \begin{Syntax}
  1193. \name{varname} \meta{identifier}
  1194. \end{Syntax}
  1195. \meta{identifier} can be any combination of one or more alphanumeric
  1196. characters. Try to avoid REDUCE reserved words.
  1197. \begin{Examples}
  1198. varname ident; & IDENT \\
  1199. on fort; \\
  1200. x**2 + 1; & IDENT=X**2+1. \\
  1201. off fort,exp; \\
  1202. structr(((x+y)**2 + z)**3); &\begin{multilineoutput}{6cm}
  1203. IDENT2^{3}
  1204. where
  1205. IDENT2 := IDENT1^{2} + Z
  1206. IDENT1 := X + Y
  1207. \end{multilineoutput}
  1208. \end{Examples}
  1209. \begin{Comments}
  1210. \nameref{exp} was turned off so that \nameref{structr} could show the
  1211. structure. If \name{exp} had been on, the expression would have been
  1212. expanded into a polynomial.
  1213. \end{Comments}
  1214. \end{Declaration}
  1215. \begin{Command}{WEIGHT}
  1216. The \name{weight} command is used to attach weights to kernels for asymptotic
  1217. constraints.
  1218. \begin{Syntax}
  1219. \name{weight} \meta{kernel} \name{=}\meta{number}
  1220. \end{Syntax}
  1221. \meta{kernel} must be a REDUCE \nameref{kernel}, \meta{number} must be a
  1222. positive integer, not 0.
  1223. \begin{Examples}
  1224. a := (x+y)**4; &
  1225. A := X^{4} + 4*X^{3}*Y + 6*X^{2}*Y^{2} + 4*X*Y^{3} + Y^{4} \\
  1226. weight x=2,y=3; \\
  1227. wtlevel 8; \\
  1228. a; & X^{4} \\
  1229. wtlevel 10; \\
  1230. a; & X^{2}*(6*Y^{2} + 4*X*Y + X^{2}) \\
  1231. int(x**2,x); & ***** X invalid as KERNEL
  1232. \end{Examples}
  1233. \begin{Comments}
  1234. Weights and \nameref{wtlevel} are used for asymptotic constraints, where
  1235. higher-order terms are considered insignificant.
  1236. Weights are originally equivalent to 0 until set by a \name{weight}
  1237. command. To remove a weight from a kernel, use the \nameref{clear}
  1238. command. Weights once assigned cannot be changed without clearing the
  1239. identifier. Once a weight is assigned to a kernel, it is no longer a
  1240. kernel and cannot be used in any REDUCE commands or operators that require
  1241. kernels, until the weight is cleared. Note that terms are ordered by
  1242. greatest weight.
  1243. The weight level of the system is set by \nameref{wtlevel}, initially at
  1244. 2. Since no kernels have weights, no effect from \name{wtlevel} can be
  1245. seen. Once you assign weights to kernels, you must set \name{wtlevel}
  1246. correctly for the desired operation. When weighted variables appear in a
  1247. term, their weights are summed for the total weight of the term (powers of
  1248. variables multiply their weights). When a term exceeds the weight level
  1249. of the system, it is discarded from the result expression.
  1250. \end{Comments}
  1251. \end{Command}
  1252. \begin{Operator}{WHERE}
  1253. \index{substitution}
  1254. The \name{where} operator provides an infix notation for one-time
  1255. substitutions for kernels in expressions.
  1256. \begin{Syntax}
  1257. \meta{expression} \name{where} \meta{kernel}
  1258. \name{=}\meta{expression}\
  1259. \{,\meta{kernel} \name{=}\meta{expression}\}\optional
  1260. \end{Syntax}
  1261. \meta{expression} can be any REDUCE scalar expression, \meta{kernel} must
  1262. be a \nameref{kernel}. Alternatively a \nameref{rule} or a \name{rule list}
  1263. can be a member of the right-hand part of a \name{where} expression.
  1264. \begin{Examples}
  1265. x**2 + 17*x*y + 4*y**2 where x=1,y=2; & 51 \\
  1266. for i := 1:5 collect x**i*q where q= for j := 1:i product j;
  1267. & \{X,2*X^{2},6*X^{3},24*X^{4},120*X^{5}\} \\
  1268. x**2 + y + z where z=y**3,y=3; & X^{2} + Y^{3} + 3
  1269. \end{Examples}
  1270. \begin{Comments}
  1271. Substitution inside a \name{where} expression has no effect upon the values
  1272. of the kernels outside the expression. The \name{where} operator has the
  1273. lowest precedence of all the infix operators, which are lower than prefix
  1274. operators, so that the substitutions apply to the entire expression
  1275. preceding the \name{where} operator. However, \name{where} is applied
  1276. before command keywords such as \name{then}, \name{repeat}, or \name{do}.
  1277. A \nameref{rule} or a \name{rule set} in the right-hand part of the
  1278. \name{where} expression act as if the rules were activated by \nameref{let}
  1279. immediately before the evaluation of the expression and deactivated
  1280. by \nameref{clearrules} immediately afterwards.
  1281. \name{where} gives you a natural notation for auxiliary variables in
  1282. expressions. As the second example shows, the substitute expression can be
  1283. a command to be evaluated. The substitute assignments are made in
  1284. parallel, rather than sequentially, as the last example shows. The
  1285. expression resulting from the first round of substitutions is not
  1286. reexamined to see if any further such substitutions can be made.
  1287. \name{where} can also be used to define auxiliary variables in
  1288. \nameref{procedure} definitions.
  1289. \end{Comments}
  1290. \end{Operator}
  1291. \begin{Command}{WHILE}
  1292. \index{loop}
  1293. The \name{while} command causes a statement to be repeatedly executed until a
  1294. given condition is true. If the condition is initially false, the statement
  1295. is not executed at all.
  1296. \begin{Syntax}
  1297. \name{while} \meta{condition} \name{do} \meta{statement}
  1298. \end{Syntax}
  1299. \meta{condition} is given by a logical operator, \meta{statement} must be a
  1300. single REDUCE statement, or a \nameref{group} (\name{<<}\ldots\name{>>}) or
  1301. \nameref{begin}\ldots\name{end} \nameref{block}.
  1302. \begin{Examples}
  1303. a := 10; & A := 10 \\
  1304. while a <= 12 do <<write a; a := a + 1>>;
  1305. & 10 \\
  1306. 11 \\
  1307. 12 \\
  1308. while a < 5 do <<write a; a := a + 1>>;
  1309. & {\it nothing is printed}
  1310. \end{Examples}
  1311. \end{Command}
  1312. \begin{Command}{WTLEVEL}
  1313. In conjunction with \nameref{weight}, \name{wtlevel} is used to implement
  1314. asymptotic constraints. Its default value is 2.
  1315. \begin{Syntax}
  1316. \name{wtlevel} \meta{expression}
  1317. \end{Syntax}
  1318. To change the weight level, \meta{expression} must evaluate to a positive
  1319. integer that is the greatest weight term to be retained in expressions
  1320. involving kernels with weight assignments. \name{wtlevel} returns the
  1321. new weight level. If you want the current weight level, but not
  1322. change it, say \name{wtlevel nil}.
  1323. \begin{Examples}
  1324. (x+y)**4;
  1325. & X^{4} + 4*X^{3}*Y + 6*X^{2}*Y^{2} + 4*X*Y^{3} + Y^{4} \\
  1326. weight x=2,y=3; \\
  1327. wtlevel 8; \\
  1328. (x+y)**4; & X^{4} \\
  1329. wtlevel 10; \\
  1330. (x+y)**4; & X^{2}*(6*Y^{2} + 4*X*Y + X^{2}) \\
  1331. int(x**2,x); & ***** X invalid as KERNEL
  1332. \end{Examples}
  1333. \begin{Comments}
  1334. \name{wtlevel} is used in conjunction with the command \nameref{weight} to
  1335. enable asymptotic constraints. Weight of a term is computed by multiplying
  1336. the weights of each variable in it by the power to which it has been
  1337. raised, and adding the resulting weights for each variable. If the weight
  1338. of the term is greater than \name{wtlevel}, the term is dropped from the
  1339. expression, and not used in any further computation involving the
  1340. expression.
  1341. Once a weight has been attached to a \nameref{kernel}, it is no longer
  1342. recognized by the system as a kernel, though still a variable. It cannot
  1343. be used in REDUCE commands and operators that need kernels. The weight
  1344. attachment can be undone with a \nameref{clear} command. \name{wtlevel} can
  1345. be changed as desired.
  1346. \end{Comments}
  1347. \end{Command}