declare.tex 61 KB

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