algebra.tex 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714
  1. \section{Algebraic Operators}
  2. \begin{Operator}{APPEND}
  3. \index{list}
  4. The \name{append} operator constructs a new \nameref{list}
  5. from the elements of its two arguments (which must be lists).
  6. \begin{Syntax}
  7. \name{append}\(\meta{list},\meta{list}\)
  8. \end{Syntax}
  9. \meta{list} must be a list, though it may be the empty list (\name{\{\}}).
  10. Any arguments beyond the first two are ignored.
  11. \begin{Examples}
  12. alist := \{1,2,\{a,b\}\}; & ALIST := \{1,2,\{A,B\}\} \\
  13. blist := \{3,4,5,sin(y)\}; & BLIST := \{3,4,5,SIN(Y)\} \\
  14. append(alist,blist); & \{1,2,\{A,B\},3,4,5,SIN(Y)\} \\
  15. append(alist,\{\}); & \{1,2,\{A,B\}\} \\
  16. append(list z,blist); & \{Z,3,4,5,SIN(Y)\}
  17. \end{Examples}
  18. \begin{Comments}
  19. The new list consists of the elements of the second list appended to the
  20. elements of the first list. You can \name{append} new elements to the
  21. beginning or end of an existing list by putting the new element in a
  22. list (use curly braces or the operator \name{list}). This is
  23. particularly helpful in an iterative loop.
  24. \end{Comments}
  25. \end{Operator}
  26. \begin{Operator}{ARBINT}
  27. \index{arbitrary value}
  28. The operator \name{arbint} is used to express arbitrary integer parts
  29. of an expression, e.g. in the result of \nameref{solve} when
  30. \nameref{allbranch} is on.
  31. \begin{Examples}
  32. solve(log(sin(x+3)),x); &
  33. \begin{multilineoutput}{6cm}
  34. \{X=2*ARBINT(1)*PI - ASIN(1) - 3,
  35. X=2*ARBINT(1)*PI + ASIN(1) + PI - 3\}
  36. \end{multilineoutput}
  37. \end{Examples}
  38. \end{Operator}
  39. \begin{Operator}{ARBCOMPLEX}
  40. \index{arbitrary value}
  41. The operator \name{arbcomplex} is used to express arbitrary scalar parts
  42. of an expression, e.g. in the result of \nameref{solve} when
  43. the solution is parametric in one of the variable.
  44. \begin{Examples}
  45. solve({x+3=y-2z,y-3x=0},{x,y,z}); &
  46. \begin{multilineoutput}{6cm}
  47. \{X=\rfrac{2*ARBCOMPLEX(1) + 3}{2},
  48. Y=\rfrac{3*ARBCOMPLEX(1) + 3}{2},
  49. Z=ARBCOMPLEX(1)\}
  50. \end{multilineoutput}
  51. \end{Examples}
  52. \end{Operator}
  53. \begin{Operator}{ARGLENGTH}
  54. \index{argument}
  55. The operator \name{arglength} returns the number of arguments of the top-level
  56. operator in its argument.
  57. \begin{Syntax}
  58. \name{arglength}\(\meta{expression}\)
  59. \end{Syntax}
  60. \meta{expression} can be any valid REDUCE algebraic expression.
  61. \begin{Examples}
  62. arglength(a + b + c + d); & 4 \\
  63. arglength(a/b/c); & 2 \\
  64. arglength(log(sin(df(r**3*x,x)))); & 1
  65. \end{Examples}
  66. \begin{Comments}
  67. In the first example, \name{+} is an n-ary operator, so the number of terms
  68. is returned. In the second example, since \name{/} is a binary operator, the
  69. argument is actually (a/b)/c, so there are two terms at the top level. In
  70. the last example, no matter how deeply the operators are nested, there is
  71. still only one argument at the top level.
  72. \end{Comments}
  73. \end{Operator}
  74. \begin{Operator}{COEFF}
  75. \index{coefficient}
  76. The \name{coeff} operator returns the coefficients of the powers of the
  77. specified variable in the given expression, in a \nameref{list}.
  78. \begin{Syntax}
  79. \name{coeff}\(\meta{expression}\name{,}\meta{variable}\)
  80. \end{Syntax}
  81. \meta{expression} is expected to be a polynomial expression, not a rational
  82. expression. Rational expressions are accepted when the switch
  83. \nameref{ratarg} is on. \meta{variable} must be a kernel. The results are
  84. returned in a list.
  85. \begin{Examples}
  86. coeff((x+y)**3,x); & \{Y^{3} ,3*Y^{2} ,3*Y,1\} \\
  87. coeff((x+2)**4 + sin(x),x); & \{SIN(X) + 16,32,24,8,1\} \\
  88. high_pow; & 4 \\
  89. low_pow; & 0 \\
  90. ab := x**9 + sin(x)*x**7 + sqrt(y);
  91. & AB := SQRT(Y) + SIN(X)*X^{7} + X^{9}\\
  92. coeff(ab,x); & \{SQRT(Y),0,0,0,0,0,0,SIN(X),0,1\}
  93. \end{Examples}
  94. \begin{Comments}
  95. The variables \nameref{high\_pow} and \nameref{low\_pow} are set to the
  96. highest and lowest powers of the variable, respectively, appearing in the
  97. expression.
  98. The coefficients are put into a list, with the coefficient of the lowest
  99. (constant) term first. You can use the usual list access methods
  100. (\name{first}, \name{second}, \name{third}, \name{rest}, \name{length}, and
  101. \name{part}) to extract them. If a power does not appear in the
  102. expression, the corresponding element of the list is zero. Terms involving
  103. functions of the specified variable but not including powers of it (for
  104. example in the expression \name{x**4 + 3*x**2 + tan(x)}) are placed in the
  105. constant term.
  106. Since the \name{coeff} command deals with the expanded form of the expression,
  107. you may get unexpected results when \nameref{exp} is off, or when
  108. \nameref{factor} or \nameref{ifactor} are on.
  109. If you want only a specific coefficient rather than all of them, use the
  110. \nameref{coeffn} operator.
  111. \end{Comments}
  112. \end{Operator}
  113. \begin{Operator}{COEFFN}
  114. \index{coefficient}
  115. The \name{coeffn} operator takes three arguments: an expression, a kernel, and
  116. a non-negative integer. It returns the coefficient of the kernel to that
  117. integer power, appearing in the expression.
  118. \begin{Syntax}
  119. \name{coeffn}\(\meta{expression},\meta{kernel},\meta{integer}\)
  120. \end{Syntax}
  121. \meta{expression} must be a polynomial, unless \nameref{ratarg} is on which
  122. allows rational expressions. \meta{kernel} must be a kernel, and
  123. \meta{integer} must be a non-negative integer.
  124. \begin{Examples}
  125. ff := x**7 + sin(y)*x**5 + y**4 + x + 7; &
  126. FF := SIN(Y)*X^{5} + X^{7} + X + Y^{4} + 7 \\
  127. coeffn(ff,x,5); & SIN(Y) \\
  128. coeffn(ff,z,3); & 0 \\
  129. coeffn(ff,y,0); & SIN(Y)*X^{5} + X^{7} + X + 7 \\
  130. rr := 1/y**2+y**3+sin(y); &
  131. RR := \rfrac{SIN(Y)*Y^{2} + Y^{5} + 1}{Y^{2}} \\
  132. on ratarg; \\
  133. coeffn(rr,y,-2); & ***** -2 invalid as COEFFN index \\
  134. coeffn(rr,y,5); & \rfrac{1}{Y^{2}}\\
  135. \end{Examples}
  136. \begin{Comments}
  137. If the given power of the kernel does not appear in the expression,
  138. \name{coeffn} returns 0. Negative powers are never detected, even if
  139. they appear in the expression and \nameref{ratarg} are on. \name{coeffn}
  140. with an integer argument of 0 returns any terms in the expression that
  141. do {\em not} contain the given kernel.
  142. \end{Comments}
  143. \end{Operator}
  144. \begin{Operator}{CONJ}
  145. \index{conjugate}\index{complex}
  146. \begin{Syntax}
  147. \name{conj}\(\meta{expression}\) or \name{conj} \meta{simple\_expression}
  148. \end{Syntax}
  149. This operator returns the complex conjugate of an expression, if that
  150. argument has an numerical value. A non-numerical argument is returned as
  151. an expression in the operators \nameref{repart} and \nameref{impart}.
  152. \begin{Examples}
  153. conj(1+i); & 1-I \\
  154. conj(a+i*b); & REPART(A) - REPART(B)*I - IMPART(A)*I - IMPART(B)
  155. \end{Examples}
  156. \end{Operator}
  157. \begin{Operator}{CONTINUED_FRACTION}
  158. \index{approximation}\index{rational numbers}
  159. \begin{Syntax}
  160. \name{continued\_fraction}\(\meta{num}\)
  161. or \name{continued\_fraction}\( \meta{num},\meta{size}\)
  162. \end{Syntax}
  163. This operator approximates the real number \meta{num}
  164. ( \nameref{rational} number, \nameref{rounded} number)
  165. into a continued fraction. The result is a list of two elements: the
  166. first one is the rational value of the approximation, the second one
  167. is the list of terms of the continued fraction which represents the
  168. same value according to the definition \name{t0 +1/(t1 + 1/(t2 + ...))}.
  169. Precision: the second optional parameter \meta{size} is an upper bound
  170. for the absolute value of the result denominator. If omitted, the
  171. approximation is performed up to the current system precision.
  172. \begin{Examples}
  173. continued_fraction pi;
  174. & \{\rfrac{1146408},{364913},\{3,7,15,1,292,1,1,1,2,1\}\} \\
  175. continued_fraction(pi,100);
  176. & \{\rfrac{22},{7},\{3,7\}\} \\
  177. \end{Examples}
  178. \end{Operator}
  179. \begin{Operator}{DECOMPOSE}
  180. \index{decomposition}\index{polynomial}
  181. The \name{decompose} operator takes a multivariate polynomial as argument,
  182. and returns an expression and a \nameref{list} of
  183. \nameref{equation}s from which the
  184. original polynomial can be found by composition.
  185. \begin{Syntax}
  186. \name{decompose}\(\meta{expression}\) or \name{decompose}
  187. \meta{simple\_expression}
  188. \end{Syntax}
  189. \begin{Examples}
  190. \begin{multilineinput}
  191. decompose(x^8-88*x^7+2924*x^6-43912*x^5+263431*x^4-
  192. 218900*x^3+65690*x^2-7700*x+234)
  193. \end{multilineinput}
  194. & {U^{2} + 35*U + 234, U=V^{2} + 10*V, V=X^{2} - 22*X} \\
  195. decompose(u^2+v^2+2u*v+1) & {W^{2} + 1, W=U + V}
  196. \end{Examples}
  197. \begin{Comments}
  198. Unlike factorization, this decomposition is not unique. Further
  199. details can be found in V.S. Alagar, M.Tanh, \meta{Fast Polynomial
  200. Decomposition}, Proc. EUROCAL 1985, pp 150-153 (Springer) and J. von zur
  201. Gathen, \meta{Functional}
  202. \meta{Decomposition of Polynomials: the Tame Case}, J.
  203. Symbolic Computation (1990) 9, 281-299.
  204. \end{Comments}
  205. \end{Operator}
  206. \begin{Operator}{DEG}
  207. \index{degree}\index{polynomial}
  208. The operator \name{deg} returns the highest degree of its variable argument
  209. found in its expression argument.
  210. \begin{Syntax}
  211. \name{deg}\(\meta{expression},\meta{kernel}\)
  212. \end{Syntax}
  213. \meta{expression} is expected to be a polynomial expression, not a rational
  214. expression. Rational expressions are accepted when the switch
  215. \nameref{ratarg} is on. \meta{variable} must be a \nameref{kernel}. The
  216. results are returned in a list.
  217. \begin{Examples}
  218. deg((x+y)**5,x); & 5 \\
  219. deg((a+b)*(c+2*d)**2,d); & 2 \\
  220. deg(x**2 + cos(y),sin(x)); \\
  221. deg((x**2 + sin(x))**5,sin(x)); & 5
  222. \end{Examples}
  223. \end{Operator}
  224. \begin{Operator}{DEN}
  225. \index{denominator}\index{rational expression}
  226. The \name{den} operator returns the denominator of its argument.
  227. \begin{Syntax}
  228. \name{den}\(\meta{expression}\)
  229. \end{Syntax}
  230. \meta{expression} is ordinarily a rational expression, but may be any valid
  231. scalar REDUCE expression.
  232. \begin{Examples}
  233. a := x**3 + 3*x**2 + 12*x; & A := X*(X^{2} + 3*X + 12) \\
  234. b := 4*x*y + x*sin(x); & B := X*(SIN(X) + 4*Y) \\
  235. den(a/b); & SIN(X) + 4*Y \\
  236. den(aa/4 + bb/5); & 20 \\
  237. den(100/6); & 3 \\
  238. den(sin(x)); & 1
  239. \end{Examples}
  240. \begin{Comments}
  241. \name{den} returns the denominator of the expression after it has been
  242. simplified by REDUCE. As seen in the examples, this includes putting
  243. sums of rational expressions over a common denominator, and reducing
  244. common factors where possible. If the expression does not have any
  245. other denominator, 1 is returned.
  246. Switch settings, such as \nameref{mcd} or \nameref{rational}, have an
  247. effect on the denominator of an expression.
  248. \end{Comments}
  249. \end{Operator}
  250. \begin{Operator}{DF}
  251. \index{derivative}\index{partial derivative}
  252. The \name{df} operator finds partial derivatives with respect to one or
  253. more variables.
  254. \begin{TEX}
  255. \begin{Syntax}
  256. \name{df}\(\meta{expression}\name{,}\meta{var}
  257. \&optional\(\name{,}\meta{number}\)
  258. \{\name{,}\meta{var}\&option\(\name{,}\meta{number}\)\}\optional\)
  259. \end{Syntax}
  260. \end{TEX}
  261. \begin{INFO}{
  262. \begin{Syntax}
  263. \name{df}\(\meta{expression}\name{,}\meta{var}
  264. [\name{,}\meta{number}\]
  265. \{\name{,}\meta{var} [ \name{,}\meta{number}] \} \)
  266. \end{Syntax}
  267. }\end{INFO}
  268. \meta{expression} can be any valid REDUCE algebraic expression. \meta{var}
  269. must be a \nameref{kernel}, and is the differentiation variable.
  270. \meta{number} must be a non-negative integer.
  271. \begin{Examples}
  272. df(x**2,x); & 2*X \\
  273. df(x**2*y + sin(y),y); & COS(Y) + X^{2} \\
  274. df((x+y)**10,z); & 0 \\
  275. df(1/x**2,x,2); & \rfrac{6}{X^{4}}\\
  276. df(x**4*y + sin(y),y,x,3); & 24*X \\
  277. for all x let df(tan(x),x) = sec(x)**2; \\
  278. df(tan(3*x),x); & 3*SEC(3*X)^{2}
  279. \end{Examples}
  280. \begin{Comments}
  281. An error message results if a non-kernel is entered as a differentiation
  282. operator. If the optional number is omitted, it is assumed to be 1.
  283. See the declaration \nameref{depend} to establish dependencies for implicit
  284. differentiation.
  285. You can define your own differentiation rules, expanding REDUCE's
  286. capabilities, using the \nameref{let} command as shown in the last example
  287. above. Note that once you add your own rule for differentiating a
  288. function, it supersedes REDUCE's normal handling of that function for the
  289. duration of the REDUCE session. If you clear the rule
  290. (\nameref{clearrules}), you don't get back
  291. to the previous rule.
  292. \end{Comments}
  293. \end{Operator}
  294. \begin{Operator}{EXPAND\_CASES}
  295. \index{solve}
  296. When a \nameref{root\_of} form in a result of \nameref{solve}
  297. has been converted to a \nameref{one\_of} form, \name{expand\_cases}
  298. can be used to convert this into form corresponding to the
  299. normal explicit results of \nameref{solve}. See \nameref{root\_of}.
  300. \end{Operator}
  301. \begin{Operator}{EXPREAD}
  302. \index{input}
  303. \begin{Syntax}
  304. \name{expread}\(\)
  305. \end{Syntax}
  306. \name{expread} reads one well-formed expression from the current input
  307. buffer and returns its value.
  308. \begin{Examples}
  309. expread(); a+b; & A + B
  310. \end{Examples}
  311. \end{Operator}
  312. \begin{Operator}{FACTORIZE}
  313. \index{factorize}\index{polynomial}
  314. The \name{factorize} operator factors a given expression.
  315. \begin{Syntax}
  316. \name{factorize}\(\meta{expression}\)
  317. \end{Syntax}
  318. \meta{expression} should be a polynomial, otherwise an error will result.
  319. \begin{Examples}
  320. fff := factorize(x^3 - y^3); &
  321. \{X - Y,X^{2} + X*Y + Y^{2}\} \\
  322. fac1 := first fff; & FAC1 := X - Y \\
  323. factorize(x^15 - 1); &
  324. \begin{multilineoutput}{5cm}
  325. \{X - 1,
  326. X^{2} + X + 1,
  327. X^{4} + X^{3} + X^{2} + X + 1,
  328. X^{8} - X^{7} + X^{6} - X^{5} + X^{4} - X + 1\}
  329. \end{multilineoutput}\\
  330. lastone := part(ws,length ws); &
  331. LASTONE := X^{8} - X^{7} + X^{6} - X^{5} + X^{4} - X + 1 \\
  332. setmod 2; & 1 \\
  333. on modular; \\
  334. factorize(x^15 - 1); &
  335. \begin{multilineoutput}{5cm}
  336. \{X + 1,
  337. X^{2} + X + 1,
  338. X^{4} + X + 1,
  339. X^{4} + X^{3} + 1,
  340. X^{4} + X^{3} + X^{2} + X + 1\}
  341. \end{multilineoutput}
  342. \end{Examples}
  343. \begin{Comments}
  344. The \name{factorize} command returns the factors it finds as a \nameref{list}.
  345. You can therefore use the usual list access methods (\nameref{first},
  346. \nameref{second}, \nameref{third}, \nameref{rest}, \nameref{length} and
  347. \nameref{part}) to extract the factors.
  348. If the \meta{expression} given to \name{factorize} is an integer, it will be
  349. factored into its prime components. To factor any integer factor of a
  350. non-numerical expression, the switch \nameref{ifactor} should be turned on.
  351. Its default is off. \nameref{ifactor} has effect only when factoring is
  352. explicitly done by \name{factorize}, not when factoring is automatically
  353. done with the \nameref{factor} switch. If full factorization is not
  354. needed the switch \nameref{limitedfactors} allows you to reduce the
  355. computing time of calls to \name{factorize}.
  356. Factoring can be done in a modular domain by calling \name{factorize} when
  357. \nameref{modular} is on. You can set the modulus with the \nameref{setmod}
  358. command. The last example above shows factoring modulo 2.
  359. For general comments on factoring, see comments under the switch
  360. \nameref{factor}.
  361. \end{Comments}
  362. \end{Operator}
  363. \begin{Operator}{HYPOT}
  364. \begin{Syntax}
  365. hypot(\meta{expression},\meta{expression})
  366. \end{Syntax}
  367. If \name{rounded} is on, and the two arguments evaluate to numbers, this
  368. operator returns the square root of the sums of the squares of the
  369. arguments in a manner that avoids intermediate overflow. In other cases,
  370. an expression in the original operator is returned.
  371. \begin{Examples}
  372. hypot(3,4); & HYPOT(3,4) \\
  373. on rounded; \\
  374. ws; & 5.0 \\
  375. hypot(a,b); & HYPOT(A,B)
  376. \end{Examples}
  377. \end{Operator}
  378. \begin{Operator}{IMPART}
  379. \index{imaginary part}\index{complex}
  380. \begin{Syntax}
  381. \name{impart}\(\meta{expression}\) or \name{impart} \meta{simple\_expression}
  382. \end{Syntax}
  383. This operator returns the imaginary part of an expression, if that
  384. argument has an numerical value. A non-numerical argument is returned as
  385. an expression in the operators \nameref{repart} and \name{impart}.
  386. \begin{Examples}
  387. impart(1+i); & 1 \\
  388. impart(a+i*b); & REPART(B) + IMPART(A)
  389. \end{Examples}
  390. \end{Operator}
  391. \begin{Operator}{INT}
  392. \index{integration}
  393. The \name{int} operator performs analytic integration on a variety of
  394. functions.
  395. \begin{Syntax}
  396. \name{int}\(\meta{expression},\meta{kernel}\)
  397. \end{Syntax}
  398. \meta{expression} can be any scalar expression. involving polynomials, log
  399. functions, exponential functions, or tangent or arctangent expressions.
  400. \name{int} attempts expressions involving error functions, dilogarithms
  401. and other trigonometric expressions. Integrals involving algebraic
  402. extensions (such as square roots) may not succeed. \meta{kernel} must be a
  403. REDUCE \nameref{kernel}.
  404. \begin{Examples}
  405. int(x**3 + 3,x); & \rfrac{X*(X^{3} + 12)}{4} \\\\
  406. int(sin(x)*exp(2*x),x);
  407. & - \rfrac{E^{2*X}*(COS(X) - 2*SIN(X))}{5} \\
  408. int(1/(x^2-2),x);
  409. & \rfrac{SQRT(2)*(LOG( - SQRT(2) + X) - LOG(SQRT(2) + X))}{4} \\
  410. int(sin(x)/(4 + cos(x)**2),x);
  411. & - \rfrac{ATAN(\rfrac{COS(X)}{2})}{2} \\\\
  412. int(1/sqrt(x^2-x),x); & INT(\rfrac{SQRT(X)*SQRT(X - 1)}{X^{2}-X},X)
  413. \end{Examples}
  414. \begin{Comments}
  415. Note that REDUCE couldn't handle the last integral with its default
  416. integrator, since the integrand involves a square root. However,
  417. the integral can be found using the \nameref{algint} package.
  418. Alternatively, you could add a rule using the \nameref{let} statement
  419. to evaluate this integral.
  420. The arbitrary constant of integration is not shown. Definite integrals can
  421. be found by evaluating the result at the limits of integration (use
  422. \nameref{rounded}) and subtracting the lower from the higher. Evaluation can
  423. be easily done by the \nameref{sub} operator.
  424. When \name{int} cannot find an integral it returns an expression
  425. involving formal \name{int} expressions unless the switch
  426. \nameref{failhard} has been set. If not all of the expression
  427. can be integrated, the switch \nameref{nolnr} controls whether a partially
  428. integrated result should be returned or not.
  429. \end{Comments}
  430. \end{Operator}
  431. \begin{Operator}{INTERPOL}
  432. \index{interpolation}\index{polynomial}\index{approximation}
  433. \name{interpol} generates an interpolation polynomial.
  434. \begin{Syntax}
  435. interpol(\meta{values},\meta{variable},\meta{points})
  436. \end{Syntax}
  437. \meta{values} and \meta{points} are \nameref{list}s of equal length and
  438. \meta{variable} is an algebraic expression (preferably a \nameref{kernel}).
  439. The interpolation polynomial is generated in the given variable of degree
  440. length(\meta{values})-1. The unique polynomial \name{f} is defined by the
  441. property that for corresponding elements \name{v} of \meta{values} and
  442. \name{p} of \meta{points} the relation \name{f(p)=v} holds.
  443. \begin{Examples}
  444. f := for i:=1:4 collect(i**3-1); & F := {0,7,26,63} \\
  445. p := {1,2,3,4}; & P := {1,2,3,4} \\
  446. interpol(f,x,p); & X^{3} - 1
  447. \end{Examples}
  448. \begin{Comments}
  449. The Aitken-Neville interpolation algorithm is used which guarantees a
  450. stable result even with rounded numbers and an ill-conditioned problem.
  451. \end{Comments}
  452. \end{Operator}
  453. \begin{Operator}{LCOF}
  454. \index{coefficient}\index{polynomial}
  455. The \name{lcof} operator returns the leading coefficient of a given expression
  456. with respect to a given variable.
  457. \begin{Syntax}
  458. \name{lcof}\(\meta{expression},\meta{kernel}\)
  459. \end{Syntax}
  460. \meta{expression} is ordinarily a polynomial. If \nameref{ratarg} is on,
  461. a rational expression may also be used, otherwise an error results.
  462. \meta{kernel} must be a \nameref{kernel}.
  463. \begin{Examples}
  464. lcof((x+2*y)**5,y); & 32 \\
  465. lcof((x + y*sin(x))**2 + cos(x)*sin(x)**2,sin(x));
  466. & COS(X)^{2} + Y \\
  467. lcof(x**2 + 3*x + 17,y); & X^{2} + 3*X + 17
  468. \end{Examples}
  469. \begin{Comments}
  470. If the kernel does not appear in the expression, \name{lcof} returns the
  471. expression.
  472. \end{Comments}
  473. \end{Operator}
  474. \begin{Operator}{LENGTH}
  475. \index{list}
  476. The \name{length} operator returns the number of items in a \nameref{list}, the
  477. number of
  478. terms in an expression, or the dimensions of an array or matrix.
  479. \begin{Syntax}
  480. \name{length}\(\meta{expr}\) or \name{length} \meta{expr}
  481. \end{Syntax}
  482. \meta{expr} can be a list structure, an array, a matrix, or a scalar expression.
  483. \begin{Examples}
  484. alist := \{a,b,\{ww,xx,yy,zz\}\}; &
  485. ALIST := \{A,B,\{WW,XX,YY,ZZ\}\} \\
  486. length alist; & 3 \\
  487. length third alist; & 4 \\
  488. dlist := \{d\}; & DLIST := \{D\} \\
  489. length rest dlist; & 0 \\
  490. matrix mmm(4,5); \\
  491. length mmm; & \{4,5\} \\
  492. array aaa(5,3,2); \\
  493. length aaa; & \{6,4,3\} \\
  494. eex := (x+3)**2/(x-y); & EEX := \rfrac{X^{2} + 6*X + 9}{X - Y} \\
  495. length eex; & 5
  496. \end{Examples}
  497. \begin{Comments}
  498. An item in a list that is itself a list only counts as one item. An error
  499. message will be printed if \name{length} is called on a matrix which has
  500. not had its dimensions set. The \name{length} of an array includes the
  501. zeroth element of each dimension, showing the full number of elements
  502. allocated. (Declaring an array \IFTEX{$A$}{A} with \IFTEX{$n$}{n} elements
  503. allocates \IFTEX{$ A(0),A(1),\ldots,A(n)$}{A(0),A(1),...,A(n)}.) The
  504. \name{length} of an expression is the total number of additive terms
  505. appearing in the numerator and denominator of the expression. Note that
  506. subtraction of a term is represented internally as addition of a negative
  507. term.
  508. \end{Comments}
  509. \end{Operator}
  510. \begin{Operator}{LHS}
  511. \index{left-hand side}\index{equation}
  512. The \name{lhs} operator returns the left-hand side of an \nameref{equation},
  513. such as those
  514. returned in a list by \nameref{solve}.
  515. \begin{Syntax}
  516. \name{lhs}\(\meta{equation}\) or \name{lhs} \meta{equation}
  517. \end{Syntax}
  518. \meta{equation} must be an equation of the form \\
  519. \name{left-hand side} \name{=} \name{right-hand side}.
  520. \begin{Examples}
  521. polly := (x+3)*(x^4+2x+1); &
  522. POLLY := X^{5} + 3*X^{4} + 2*X^{2} + 7*X + 3 \\
  523. pollyroots := solve(polly,x); &
  524. \begin{multilineoutput}{1cm}
  525. POLLYROOTS := \{X=ROOT_OF(X_^{3} - X_^{2} + X_ + 1,X_),
  526. X=-1,
  527. X=-3\}
  528. \end{multilineoutput} \\
  529. variable := lhs first pollyroots; &
  530. VARIABLE := X
  531. \end{Examples}
  532. \end{Operator}
  533. \begin{Operator}{LIMIT}
  534. \index{limit}\index{l'Hopital's rule}
  535. LIMITS is a fast limit package for REDUCE for functions which are
  536. continuous except for computable poles and singularities, based on
  537. some earlier work by Ian Cohen and John P. Fitch. The Truncated
  538. Power Series package is used for non-critical points, at which
  539. the value of the function is the constant term in the expansion
  540. around that point. l'Hopital's rule is used in critical cases,
  541. with preprocessing of 1-1 forms and reformatting of product forms
  542. in order to apply l'Hopital's rule. A limited amount of bounded
  543. arithmetic is also employed where applicable.
  544. \begin{Syntax}
  545. \name{limit}\(\meta{expr},\meta{var},\meta{limpoint}\) or \\
  546. \name{limit!+}\(\meta{expr},\meta{var},\meta{limpoint}\) or \\
  547. \name{limit!-}\(\meta{expr},\meta{var},\meta{limpoint}\)
  548. \end{Syntax}
  549. where \meta{expr} is an expression depending of the variable \meta{var}
  550. (a \nameref{kernel}) and \meta{limpoint} is the limit point.
  551. If the limit depends upon the direction of approach to the \meta{limpoint},
  552. the operators \name{limit!+} and \name{limit!-} may be used.
  553. \begin{Examples}
  554. limit(x*cot(x),x,0);&0\\
  555. limit((2x+5)/(3x-2),x,infinity);&\rfrac{2}{3}\\
  556. \end{Examples}
  557. \end{Operator}
  558. \begin{Operator}{LPOWER}
  559. \index{leading power}\index{polynomial}
  560. The \name{lpower} operator returns the leading power of an expression with
  561. respect to a kernel. 1 is returned if the expression does not depend on
  562. the kernel.
  563. \begin{Syntax}
  564. \name{lpower}\(\meta{expression},\meta{kernel}\)
  565. \end{Syntax}
  566. \meta{expression} is ordinarily a polynomial. If \nameref{ratarg} is on,
  567. a rational expression may also be used, otherwise an error results.
  568. \meta{kernel} must be a \nameref{kernel}.
  569. \begin{Examples}
  570. lpower((x+2*y)**6,y); & Y^{6} \\
  571. lpower((x + cos(x))**8 + df(x**2,x),cos(x));
  572. & COS(X)^{8} \\
  573. lpower(x**3 + 3*x,y); & 1
  574. \end{Examples}
  575. \end{Operator}
  576. \begin{Operator}{LTERM}
  577. \index{leading term}\index{polynomial}
  578. The \name{lterm} operator returns the leading term of an expression with
  579. respect to a kernel. The expression is returned if it does not depend on
  580. the kernel.
  581. \begin{Syntax}
  582. \name{lterm}\(\meta{expression},\meta{kernel}\)
  583. \end{Syntax}
  584. \meta{expression} is ordinarily a polynomial. If \nameref{ratarg} is on,
  585. a rational expression may also be used, otherwise an error results.
  586. \meta{kernel} must be a \nameref{kernel}.
  587. \begin{Examples}
  588. lterm((x+2*y)**6,y); & 64*Y^{6} \\
  589. lterm((x + cos(x))**8 + df(x**2,x),cos(x));
  590. & COS(X)^{8} \\
  591. lterm(x**3 + 3*x,y); & X^{3} + 3X
  592. \end{Examples}
  593. \end{Operator}
  594. \begin{Operator}{MAINVAR}
  595. \index{main variable}\index{polynomial}
  596. The \name{mainvar} operator returns the main variable (in the system's
  597. internal representation) of its argument.
  598. \begin{Syntax}
  599. \name{mainvar}\(\meta{expression}\)
  600. \end{Syntax}
  601. \meta{expression} is usually a polynomial, but may be any valid REDUCE
  602. scalar expression. In the case of a rational function, the main variable
  603. of the numerator is returned. The main variable returned is a
  604. \nameref{kernel}.
  605. \begin{Examples}
  606. test := (a + b + c)**2; &
  607. TEST := A^{2} + 2*A*B + 2*A*C + B^{2} + 2*B*C + C^{2} \\
  608. mainvar(test); & A \\
  609. korder c,b,a; \\
  610. mainvar(test); & C \\
  611. mainvar(2*cos(x)**2); & COS(X) \\
  612. mainvar(17); & 0
  613. \end{Examples}
  614. \begin{Comments}
  615. The main variable is the first variable in the canonical ordering of
  616. kernels. Generally, alphabetically ordered functions come first, then
  617. alphabetically ordered identifiers (variables). Numbers come last, and as
  618. far as \name{mainvar} is concerned belong in the family \name{0}. The
  619. canonical ordering can be changed by the declaration \nameref{korder}, as
  620. shown above.
  621. \end{Comments}
  622. \end{Operator}
  623. \begin{Operator}{MAP}
  624. \index{map}\index{composite structure}
  625. The \name{map} operator applies a uniform evaluation pattern
  626. to all members of a composite structure: a \nameref{matrix},
  627. a \nameref{list} or the arguments of an \nameref{operator} expression.
  628. The evaluation pattern can be a
  629. unary procedure, an operator, or an algebraic expression with
  630. one free variable.
  631. \begin{Syntax}
  632. \name{map}\(\meta{function},\meta{object}\)
  633. \end{Syntax}
  634. \meta{object} is a list, a matrix or an operator expression.
  635. \meta{function} is
  636. the name of an operator for a single argument: the operator
  637. is evaluated once with each element of \meta{object} as its single argument,
  638. or an algebraic expression with exactly one \nameref{free variable}, that is
  639. a variable preceded by the tilde symbol: the expression
  640. is evaluated for each element of \meta{object} where the element is
  641. substituted for the free variable,
  642. or a replacement \nameref{rule} of the form
  643. \begin{Syntax}
  644. \name{var} => \name{rep}
  645. \end{Syntax}
  646. where \meta{var} is a variable (a \meta{kernel} without subscript)
  647. and \meta{rep} is an expression which contains \meta{var}.
  648. Here \name{rep} is evaluated for each element of \meta{object} where
  649. the element is substituted for \name{var}. \name{var} may be
  650. optionally preceded by a tilde.
  651. The rule form for \meta{function} is needed when more than
  652. one free variable occurs.
  653. \begin{Examples}
  654. map(abs,{1,-2,a,-a}); & {1,2,abs(a),abs(a)} \\
  655. map(int(~w,x), mat((x^2,x^5),(x^4,x^5))); &
  656. \begin{multilineoutput}{1cm}
  657. [ 3 6 ]
  658. [ x x ]
  659. [---- ----]
  660. [ 3 6 ]
  661. [ ]
  662. [ 5 6 ]
  663. [ x x ]
  664. [---- ----]
  665. [ 5 6 ]
  666. \end{multilineoutput}\\
  667. map(~w*6, x^2/3 = y^3/2 -1); & 2*x^2=3*(y^3-2)\\
  668. \end{Examples}
  669. \begin{Comments}
  670. You can use \name{map} in nested expressions. It is not allowed to
  671. apply \name{map} for a non-composed object, e.g. an identifier or a number.
  672. \end{Comments}
  673. \end{Operator}
  674. \begin{Command}{MKID}
  675. \index{identifier}
  676. The \name{mkid} command constructs an identifier, given a stem and an identifier
  677. or an integer.
  678. \begin{Syntax}
  679. \name{mkid}\(\meta{stem},\meta{leaf}\)
  680. \end{Syntax}
  681. \meta{stem} can be any valid REDUCE identifier that does not include escaped
  682. special characters. \meta{leaf} may be an integer, including one given by a
  683. local variable in a \nameref{for} loop, or any other legal group of
  684. characters.
  685. \begin{Examples}
  686. mkid(x,3); & X3 \\
  687. factorize(x^15 - 1); & \begin{multilineoutput}{6cm}
  688. \{X - 1,
  689. X^{2} + X + 1,
  690. X^{4} + X^{3} + X^{2} + X + 1,
  691. X^{8} - X^{7} + X^{5} - X^{4} + X^{3} - X + 1\}
  692. \end{multilineoutput}\\
  693. for i := 1:length ws do write set(mkid(f,i),part(ws,i));
  694. & \begin{multilineoutput}{6cm}
  695. X^{8} - X^{7} + X^{5} - X^{4} + X^{3} - X + 1
  696. X^{4} + X^{3} + X^{2} + X + 1
  697. X^{2} + X + 1
  698. X - 1
  699. \end{multilineoutput} \\
  700. \end{Examples}
  701. \begin{Comments}
  702. You can use \name{mkid} to construct identifiers from inside procedures. This
  703. allows you to handle an unknown number of factors, or deal with variable
  704. amounts of data. It is particularly helpful to attach identifiers to the
  705. answers returned by \name{factorize} and \name{solve}.
  706. \end{Comments}
  707. \end{Command}
  708. \begin{Operator}{NPRIMITIVE}
  709. \index{primitive part}\index{polynomial}
  710. \begin{Syntax}
  711. \name{nprimitive}\(\meta{expression}\) or \name{nprimitive}
  712. \meta{simple\_expression}
  713. \end{Syntax}
  714. This operator returns the numerically-primitive part of any scalar
  715. expression. In other words, any overall integer factors in the expression
  716. are removed.
  717. \begin{Examples}
  718. nprimitive((2x+2y)^2); & X^{2} + 2*X*Y + Y^{2} \\
  719. nprimitive(3*a*b*c); & 3*A*B*C
  720. \end{Examples}
  721. \end{Operator}
  722. \begin{Operator}{NUM}
  723. \index{numerator}\index{rational expression}
  724. The \name{num} operator returns the numerator of its argument.
  725. \begin{Syntax}
  726. \name{num}\(\meta{expression}\) or \name{num} \meta{simple\_expression}
  727. \end{Syntax}
  728. \meta{expression} can be any valid REDUCE scalar expression.
  729. \begin{Examples}
  730. num(100/6); & 50 \\
  731. num(a/5 + b/6); & 6*A + 5*B \\
  732. num(sin(x)); & SIN(X)
  733. \end{Examples}
  734. \begin{Comments}
  735. \name{num} returns the numerator of the expression after it has been simplified
  736. by REDUCE. As seen in the examples, this includes putting sums of rational
  737. expressions over a common denominator, and reducing common factors where
  738. possible. If the expression is not a rational expression, it is returned
  739. unchanged.
  740. \end{Comments}
  741. \end{Operator}
  742. \begin{Operator}{ODESOLVE}
  743. \index{differential equation}\index{solve}
  744. The \name{odesolve} package is a solver for ordinary differential
  745. equations. At the present time it has still limited capabilities:
  746. 1. it can handle only a single scalar equation presented as an
  747. algebraic expression or equation, and
  748. 2. it can solve only first-order equations of simple types, linear
  749. equations with constant coefficients and Euler equations.
  750. These solvable types are exactly those for which Lie symmetry
  751. techniques give no useful information.
  752. \begin{Syntax}
  753. \name{odesolve}\(\meta{expr},\meta{var1},\meta{var2}\)
  754. \end{Syntax}
  755. \meta{expr} is a single scalar expression such that \meta{expr}=0
  756. is the ordinary differential equation (ODE for short) to be solved, or
  757. is an equivalent \nameref{equation}.
  758. \meta{var1} is the name of the dependent variable,
  759. \meta{var2} is the name of the independent variable.
  760. A differential in \meta{expr} is expressed using the \nameref{df}
  761. operator. Note that in most cases you must declare explicitly
  762. \meta{var1} to depend of \meta{var2} using a \nameref{depend}
  763. declaration -- otherwise the derivative might be evaluated to
  764. zero on input to \name{odesolve}.
  765. The returned value is a list containing the equation giving the general
  766. solution of the ODE (for simultaneous equations this will be a
  767. list of equations eventually). It will contain occurrences of
  768. the operator \name{arbconst} for the arbitrary constants in the general
  769. solution. The arguments of \name{arbconst} should be new.
  770. A counter \name{!!arbconst} is used to arrange this.
  771. \begin{Examples}
  772. depend y,x;\\
  773. \% A first-order linear equation, with an initial condition\\
  774. ode:=df(y,x) + y * sin x/cos x - 1/cos x$\\
  775. odesolve(ode,y,x); & \{y=arbconst(1)*cos(x) + sin(x)\}
  776. \end{Examples}
  777. \end{Operator}
  778. \begin{Type}{ONE\_OF}
  779. The operator \name{one\_of} is used to represent an indefinite choice
  780. of one element from a finite set of objects.
  781. \begin{Examples}
  782. x=one_of{1,2,5}\\
  783. \explanation{this equation encodes that x can take one of the values
  784. 1,2 or 5}\\
  785. \end{Examples}
  786. REDUCE generates a \name{one\_of} form in cases when an implicit
  787. \name{root\_of} expression could be converted to an explicit solution set.
  788. A \name{one\_of} form can be converted to a \name{solve} solution using
  789. \nameref{expand\_cases}. See \nameref{root\_of}.
  790. \end{Type}
  791. \begin{Operator}{PART}
  792. \index{decomposition}
  793. The operator \name{part} permits the extraction of various parts or
  794. operators of expressions and \nameref{list}\name{s}.
  795. \begin{Syntax}
  796. \name{part}\(\meta{expression,integer}\{,\meta{integer}\}\optional\)
  797. \end{Syntax}
  798. \meta{expression} can be any valid REDUCE expression or a list, {\it
  799. integer} may be an expression that evaluates to a positive or negative
  800. integer or 0. A positive integer \meta{n} picks up the {\it n} th term,
  801. counting from the first term toward the end. A negative integer {\it n}
  802. picks up the {\it n} th term, counting from the back toward the front. The
  803. integer 0 picks up the operator (which is \name{LIST} when the expression
  804. is a \ref{list}).
  805. \begin{Examples}
  806. part((x + y)**5,4); & 10*X^{2}*Y^{3} \\
  807. part((x + y)**5,4,2); & X^{2} \\
  808. part((x + y)**5,4,2,1); & X \\
  809. part((x + y)**5,0); & PLUS \\
  810. part((x + y)**5,-5); & 5*X *Y^{4} \\
  811. part((x + y)**5,4) := sin(x); &
  812. X^{5} + 5*X^{4}*Y + 10*X^{3}*Y^{2} + SIN(X) + 5*X*Y^{4} + Y^{5} \\
  813. alist := \{x,y,\{aa,bb,cc\},x**2*sqrt(y)\}; &
  814. ALIST := \{X,Y,\{AA,BB,CC\},SQRT(Y)*X^{2}\} \\
  815. part(alist,3,2); & BB \\
  816. part(alist,4,0); & TIMES
  817. \end{Examples}
  818. \begin{Comments}
  819. Additional integer arguments after the first one examine the
  820. terms recursively, as shown above. In the third line, the fourth term
  821. is picked from the original polynomial, \IFTEX{$10x^2y^3$}{10x^2y^3},
  822. then the second term from that, \IFTEX{$x^2$}{x^2}, and finally the first
  823. component, \IFTEX{$x$}{x}. If an integer's absolute value is too large for
  824. the appropriate expression, a message is given.
  825. \name{part} works on the form of the expression as printed, or as it would
  826. have been printed at that point of the calculation, bearing in mind the
  827. current switch settings. It is important to realize that the switch settings
  828. change the operation of \name{part}. \nameref{pri} must be on when
  829. \name{part} is used.
  830. When \name{part} is used on a polynomial expression that has minus signs, the
  831. \name{+} is always returned as the top-level operator. The minus is found
  832. as a unary operator attached to the negative term.
  833. \name{part} can also be used to change the relevant part of the expression or
  834. list as shown in the sixth example line. The \name{part} operator returns the
  835. changed expression, though original expression is not changed. You can
  836. also use \name{part} to change the operator.
  837. \end{Comments}
  838. \end{Operator}
  839. \begin{Operator}{PF}
  840. \index{partial fraction}\index{rational expression}
  841. \begin{Syntax}
  842. pf(\meta{expression},\meta{variable})
  843. \end{Syntax}
  844. \name{pf} transforms \meta{expression} into a \nameref{list} of partial fraction
  845. s
  846. with respect to the main variable, \meta{variable}. \name{pf} does a
  847. complete partial fraction decomposition, and as the algorithms used are
  848. fairly unsophisticated (factorization and the extended Euclidean
  849. algorithm), the code may be unacceptably slow in complicated cases.
  850. \begin{Examples}
  851. pf(2/((x+1)^2*(x+2)),x); &
  852. \{\rfrac{2}{X + 2},\rfrac{-2}{X + 1},\rfrac{2}{X^{2} + 2*X + 1}\} \\
  853. off exp; \\
  854. pf(2/((x+1)^2*(x+2)),x);
  855. & \{\rfrac{2}{X + 2},\rfrac{- 2}{X + 1},\rfrac{2}{(X + 1)^{2}}\} \\
  856. for each j in ws sum j; & \rfrac{2}{( + 2)*(X + 1)^{2}}
  857. \end{Examples}
  858. \begin{Comments}
  859. If you want the denominators in factored form, turn \nameref{exp} off, as
  860. shown in the second example above. As shown in the final example, the
  861. \nameref{for} \name{each} construct can be used to recombine the terms.
  862. Alternatively, one can use the operations on lists to extract any desired
  863. term.
  864. \end{Comments}
  865. \end{Operator}
  866. \begin{Operator}{PROD}
  867. \index{Gosper algorithm}\index{product}
  868. The operator \name{prod} returns
  869. the indefinite or definite product of a given expression.
  870. \begin{Syntax}
  871. \name{prod}\(\meta{expr},\meta{k}[,\meta{lolim} [,\meta{uplim} ]]\)
  872. \end{Syntax}
  873. where \meta{expr} is the expression to be multiplied, \meta{k} is the
  874. control variable (a \nameref{kernel}), and \meta{lolim} and \meta{uplim}
  875. uplim are the optional lower and upper limits. If \meta{uplim} is
  876. not supplied the upper limit is taken as \meta{k}. The
  877. Gosper algorithm is used. If there is no closed form solution,
  878. the operator returns the input unchanged.
  879. \begin{Examples}
  880. prod(k/(k-2),k);&k*( - k + 1)\\
  881. \end{Examples}
  882. \end{Operator}
  883. \begin{Operator}{REDUCT}
  884. \index{reductum}\index{polynomial}
  885. The \name{reduct} operator returns the remainder of its expression after the
  886. leading term with respect to the kernel in the second argument is removed.
  887. \begin{Syntax}
  888. \name{reduct}\(\meta{expression},\meta{kernel}\)
  889. \end{Syntax}
  890. \meta{expression} is ordinarily a polynomial. If \nameref{ratarg} is on,
  891. a rational expression may also be used, otherwise an error results.
  892. \meta{kernel} must be a \nameref{kernel}.
  893. \begin{Examples}
  894. reduct((x+y)**3,x); & Y*(3*X^{2} + 3*X*Y + Y^{2}) \\
  895. reduct(x + sin(x)**3,sin(x)); & X \\
  896. reduct(x + sin(x)**3,y); & 0
  897. \end{Examples}
  898. \begin{Comments}
  899. If the expression does not contain the kernel, \name{reduct} returns 0.
  900. \end{Comments}
  901. \end{Operator}
  902. \begin{Operator}{REPART}
  903. \index{real part}\index{complex}
  904. \begin{Syntax}
  905. \name{repart}\(\meta{expression}\) or \name{repart} \meta{simple\_expression}
  906. \end{Syntax}
  907. This operator returns the real part of an expression, if that argument has an
  908. numerical value. A non-numerical argument is returned as an expression in
  909. the operators \name{repart} and \nameref{impart}.
  910. \begin{Examples}
  911. repart(1+i); & 1 \\
  912. repart(a+i*b); & REPART(A) - IMPART(B)
  913. \end{Examples}
  914. \end{Operator}
  915. \begin{Operator}{RESULTANT}
  916. \index{polynomial}
  917. The \name{resultant} operator computes the resultant of two polynomials with
  918. respect to a given variable. If the resultant is 0, the polynomials have
  919. a root in common.
  920. \begin{Syntax}
  921. \name{resultant}\(\meta{expression},\meta{expression},\meta{kernel}\)
  922. \end{Syntax}
  923. \meta{expression} must be a polynomial containing \meta{kernel} ;
  924. \meta{kernel} must be a \nameref{kernel}.
  925. \begin{Examples}
  926. resultant(x**2 + 2*x + 1,x+1,x); & 0 \\
  927. resultant(x**2 + 2*x + 1,x-3,x); & 16 \\
  928. \begin{multilineinput}
  929. resultant(z**3 + z**2 + 5*z + 5,
  930. z**4 - 6*z**3 + 16*z**2 - 30*z + 55,
  931. z);
  932. \end{multilineinput} & 0 \\
  933. resultant(x**3*y + 4*x*y + 10,y**2 + 6*y + 4,y); &
  934. Y^{6} + 18*Y^{5} + 120*Y^{4} + 360*Y^{3} + 480*Y^{2} + 288*Y + 64
  935. \end{Examples}
  936. \begin{Comments}
  937. The resultant is the determinant of the Sylvester matrix, formed from the
  938. coefficients of the two polynomials in the following way:
  939. Given two polynomials:
  940. \begin{TEX}
  941. \begin{displaymath}
  942. a_0x^n+a_1x^{n-1}+\cdots+a_n
  943. \end{displaymath}
  944. \end{TEX}
  945. \begin{INFO}
  946. {\begin{verbatim}
  947. n n-1
  948. a x + a1 x + ... + an
  949. \end{verbatim}}
  950. \end{INFO}
  951. and
  952. \begin{TEX}
  953. \begin{displaymath}
  954. b_0x^n+b_1x^{n-1}+\cdots+b_n
  955. \end{displaymath}
  956. \end{TEX}
  957. \begin{INFO}
  958. {\begin{verbatim}
  959. m m-1
  960. b x + b1 x + ... + bm
  961. \end{verbatim}}
  962. \end{INFO}
  963. form the (m+n)x(m+n-1) Sylvester matrix by the following means:
  964. \begin{TEX}
  965. \begin{displaymath}
  966. \left(\begin{array}{cccccccc}
  967. 0&\ldots&0&0&a_0&a_1&\ldots&a_n\\
  968. 0&\ldots&0&a_0&a_1&\ldots&a_n&0\\
  969. \vdots&&&\vdots&&&\vdots\\
  970. a_0&a_1&\ldots&a_n&0&0&\ldots&0\\
  971. 0&\ldots&0&0&b_0&b_1&\ldots&b_n\\
  972. \vdots&&&\vdots&&&\vdots\\
  973. b_0&b_1&\ldots&b_n&0&0&\ldots&0
  974. \end{array}\right)
  975. \end{displaymath}
  976. \end{TEX}
  977. \begin{INFO}
  978. {\begin{verbatim}
  979. 0.......0 a a1 .......... an
  980. 0....0 a a1 .......... an 0
  981. . . . .
  982. a0 a1 .......... an 0.......0
  983. 0.......0 b b1 .......... bm
  984. 0....0 b b1 .......... bm 0
  985. . . . .
  986. b b1 .......... bm 0.......0
  987. \end{verbatim}}
  988. \end{INFO}
  989. If the determinant of this matrix is 0, the two polynomials have a common
  990. root. Finding the resultant of large expressions is time-consuming, due
  991. to the time needed to find a large determinant.
  992. The sign conventions \name{resultant} uses are those given in the article,
  993. ``Computing in Algebraic Extensions,'' by R. Loos, appearing in
  994. \meta{Computer Algebra--Symbolic and Algebraic Computation}, 2nd ed.,
  995. edited by B. Buchberger, G.E. Collins and R. Loos, and published by
  996. Springer-Verlag, 1983.
  997. These are:
  998. \begin{TEX}
  999. \begin{eqnarray*}
  1000. \mbox{resultant}(p(x),q(x),x)
  1001. &=& (-1)^{\deg p(x)*\deg q(x)}\cdot\mbox{resultant}(q(x),p(x),x),\\
  1002. \mbox{resultant}(a,p(x),x) &=& a^{\deg p(x)},\\
  1003. \mbox{resultant}(a,b,x) &=& 1
  1004. \end{eqnarray*}
  1005. where $p(x)$ and $q(x)$ are polynomials which have $x$ as a variable, and
  1006. $a$ and $b$ are free of $x$.
  1007. \end{TEX}
  1008. \begin{INFO}
  1009. {
  1010. \begin{verbatim}
  1011. resultant(p(x),q(x),x) = (-1)^{deg p(x)*deg q(x)} * resultant(q(x),p(x),x),
  1012. resultant(a,p(x),x) = a^{deg p(x)},
  1013. resultant(a,b,x) = 1
  1014. \end{verbatim}
  1015. where p(x) and q(x) are polynomials which have x as a variable, and
  1016. a and b are free of x.
  1017. }
  1018. \end{INFO}
  1019. Error messages are given if \name{resultant} is given a non-polynomial
  1020. expression, or a non-kernel variable.
  1021. \end{Comments}
  1022. \end{Operator}
  1023. \begin{Operator}{RHS}
  1024. \index{right-hand side}\index{equation}
  1025. The \name{rhs} operator returns the right-hand side of an \nameref{equation},
  1026. such as those returned in a \nameref{list} by \nameref{solve}.
  1027. \begin{Syntax}
  1028. \name{rhs}\(\meta{equation}\) or \name{rhs} \meta {equation}
  1029. \end{Syntax}
  1030. \meta{equation} must be an equation of the form {\it left-hand side = right-hand
  1031. side}.
  1032. \begin{Examples}
  1033. roots := solve(x**2 + 6*x*y + 5x + 3y**2,x); &
  1034. \begin{multilineoutput}{6cm}
  1035. ROOTS := \{X= - \rfrac{SQRT(24*Y^{2} + 60*Y + 25) + 6*Y + 5}{2},
  1036. X= \rfrac{SQRT(24*Y^{2} + 60*Y + 25) - 6*Y - 5}{2}\}
  1037. \end{multilineoutput} \\
  1038. root1 := rhs first roots; &
  1039. ROOT1 := - \rfrac{SQRT(24*Y^{2} + 60*Y + 25) + 6*Y + 5}{2} \\
  1040. root2 := rhs second roots; &
  1041. ROOT2 := \rfrac{SQRT(24*Y^{2} + 60*Y + 25) - 6*Y - 5}{2}
  1042. \end{Examples}
  1043. \begin{Comments}
  1044. An error message is given if \name{rhs} is applied to something other than an
  1045. equation.
  1046. \end{Comments}
  1047. \end{Operator}
  1048. \begin{Operator}{ROOT\_OF}
  1049. \index{roots}\index{solve}
  1050. When the operator \nameref{solve} is unable to find an explicit solution
  1051. or if that solution would be too complicated, the result is presented
  1052. as formal root expression using the internal operator \name{root\_of}
  1053. and a new local variable. An expression with a top level \name{root\_of}
  1054. is implicitly a list with an unknown number of elements since we
  1055. can't always know how many solutions an equation has. If a
  1056. substitution is made into such an expression, closed form solutions
  1057. can emerge. If this occurs, the \name{root\_of} construct is
  1058. replaced by an operator \nameref{one\_of}. At this point it is
  1059. of course possible to transform the result if the original \name{solve}
  1060. operator expression into a standard \name{solve} solution. To
  1061. effect this, the operator \nameref{expand\_cases} can be used.
  1062. \begin{Examples}
  1063. solve(a*x^7-x^2+1,x);&
  1064. \{x=root\_of(a*x\_^7 - x\_^2 + 1,x\_)\}\\
  1065. sub(a=0,ws);&
  1066. \{x=one\_of(1,-1)\}\\
  1067. expand_cases ws;&
  1068. {x=1,x=-1}\\
  1069. \end{Examples}
  1070. The components of \name{root\_of} and \name{one\_of} expressions can be
  1071. processed as usual with operators \nameref{arglength} and \nameref{part}.
  1072. A higher power of a \name{root\_of} expression with a polynomial
  1073. as first argument is simplified by using the polynomial as a side relation.
  1074. \end{Operator}
  1075. \begin{Operator}{SELECT}
  1076. \index{map}\index{list}
  1077. The \name{select} operator extracts from a list
  1078. or from the arguments of an n--ary operator elements corresponding
  1079. to a boolean predicate. The predicate pattern can be a
  1080. unary procedure, an operator or an algebraic expression with
  1081. one \nameref{free variable}.
  1082. \begin{Syntax}
  1083. \name{select}\(\meta{function},\meta{object}\)
  1084. \end{Syntax}
  1085. \meta{object} is a \nameref{list}.
  1086. \meta{function} is
  1087. the name of an operator for a single argument: the operator
  1088. is evaluated once with each element of \meta{object} as its single argument,
  1089. or an algebraic expression with exactly one \nameref{free variable}, that is
  1090. a variable preceded by the tilde symbol: the expression
  1091. is evaluated for each element of \meta{object} where the element is
  1092. substituted for the free variable,
  1093. or a replacement \nameref{rule} of the form
  1094. \begin{Syntax}
  1095. \name{var} => \name{rep}
  1096. \end{Syntax}
  1097. where \meta{var} is a variable (a \meta{kernel} without subscript)
  1098. and \meta{rep} is an expression which contains \meta{var}.
  1099. Here \name{rep} is evaluated for each element of \meta{object} where
  1100. the element is substituted for \name{var}. \name{var} may be
  1101. optionally preceded by a tilde.
  1102. The rule form for \meta{function} is needed when more than
  1103. one free variable occurs. The evaluation result of \meta{function} is
  1104. interpreted as \nameref{boolean value} corresponding to the conventions of
  1105. REDUCE. The result value is built with the leading operator of the
  1106. input expression.
  1107. \begin{Examples}
  1108. select( ~w>0 , {1,-1,2,-3,3}) & \{1,2,3\} \\
  1109. q:=(part((x+y)^5,0):=list)\\
  1110. select(evenp deg(~w,y),q);& \{x^5 ,10*x^3 *y^2 ,5*x*y^4 \}\\
  1111. select(evenp deg(~w,x),2x^2+3x^3+4x^4);& 2x^2+4x^4\\
  1112. \end{Examples}
  1113. \end{Operator}
  1114. \begin{Operator}{SHOWRULES}
  1115. \index{rule}\index{output}
  1116. \begin{Syntax}
  1117. \name{showrules}\(\meta{expression}\) or
  1118. \name{showrules} \meta{simple\_expression}
  1119. \end{Syntax}
  1120. \name{showrules} returns in \nameref{rule}\name{-list} form any
  1121. \nameref{operator} rules associated with its argument.
  1122. \begin{Examples}
  1123. showrules log; &
  1124. \begin{multilineoutput}{6cm}
  1125. \{LOG(E) => 1,
  1126. LOG(1) => 0,
  1127. LOG(E^{~X} ) => ~X,
  1128. DF(LOG(~X),~X) => \rfrac{1}{~X}\}
  1129. \end{multilineoutput}
  1130. \end{Examples}
  1131. Such rules can then be manipulated further as with any \nameref{list}. For
  1132. example
  1133. \name{rhs first ws;} has the value {\em 1}.
  1134. \begin{Comments}
  1135. An operator may have properties that cannot be displayed in such a form,
  1136. such as the fact it is an \ref{odd} function, or has a definition defined
  1137. as a procedure.
  1138. \end{Comments}
  1139. \end{Operator}
  1140. \begin{Operator}{SOLVE}
  1141. \index{equation}\index{equation solving}
  1142. \index{equation system}\index{root}\index{solve}
  1143. The \name{solve} operator solves a single algebraic \nameref{equation} or a
  1144. system of simultaneous equations.
  1145. \begin{TEX}
  1146. \begin{Syntax}
  1147. % \name{solve}\(\meta{expression} \&option(, \meta{kernel})\) or
  1148. % \name{solve}\(\name{\{}\meta{expression}\{,\meta{expression}\}
  1149. % \optional\name{\}}
  1150. % \&option(,\meta{kernel}\optional\)
  1151. \name{solve}\(\meta{expression}\&option(, \meta{kernel})\) or \\
  1152. \name{solve}\(\name{\{}\meta{expression}\&option( ,\meta{expression})
  1153. \optional\name{\}}
  1154. \&option(,\{\meta{kernel})\optional\name{\}\}}\)
  1155. \end{Syntax}
  1156. \end{TEX}
  1157. \begin{INFO}
  1158. {\begin{Syntax}
  1159. \name{solve}\(\meta{expression} [ , \meta{kernel}]\) or
  1160. \name{solve}\(\{\meta{expression},...\} [ ,\{ \meta{kernel} ,...\}] \)
  1161. \end{Syntax}
  1162. }\end{INFO}
  1163. If the number of equations equals the number of distinct kernels, the
  1164. optional kernel argument(s) may be omitted. \meta{expression} is either a
  1165. scalar expression or an \nameref{equation}.
  1166. When more than one expression is given,
  1167. the \nameref{list} of expressions is surrounded by curly braces.
  1168. The optional list
  1169. of \nameref{kernel}s follows, also in curly braces.
  1170. \begin{Examples}
  1171. sss := solve(x^2 + 7); &
  1172. \begin{multilineoutput}{6cm}
  1173. Unknown: X
  1174. SSS := \{X= - SQRT(7)*I,
  1175. X=SQRT(7)*I\}
  1176. \end{multilineoutput}\\
  1177. rhs first sss; & - SQRT(7)*I \\
  1178. solve(sin(x^2*y),y); &
  1179. \begin{multilineoutput}{6cm}
  1180. \{Y=\rfrac{2*ARBINT(1)*PI}{X^{2}}
  1181. Y=\rfrac{PI*(2*ARBINT(1) + 1)}{X^{2}}\}
  1182. \end{multilineoutput}\\
  1183. off allbranch; \\
  1184. solve(sin(x**2*y),y); & \{Y=0\} \\
  1185. solve({3x + 5y = -4,2*x + y = -10},{x,y});
  1186. & \{\{X= - \rfrac{22}{7},Y=\rfrac{46}{7}\}\} \\
  1187. solve({x + a*y + z,2x + 5},{x,y});
  1188. & \{\{X= - \rfrac{5}{2},Y= - \rfrac{2*Z - 5}{2*A}\}\} \\
  1189. % xval := rhs part(ws,1,1); & XVAL := - \rfrac{5}{2} \\
  1190. ab := (x+2)^2*(x^6 + 17x + 1);
  1191. & AB := X^{8} + 4*X^{7} + 4*X^{6} + 17*X^{3} + 69*X^{2} + 72*X + 4 \\
  1192. www := solve(ab,x); & \{X=ROOT_OF(X_^{6} + 17*X_ + 1),X=-2\} \\
  1193. root_multiplicities; & \{1,2\}
  1194. \end{Examples}
  1195. \begin{Comments}
  1196. Results of the \name{solve} operator are returned as \nameref{equation}\name{s}
  1197. in a \nameref{list}.
  1198. You can use the usual list access methods (\nameref{first},
  1199. \nameref{second}, \nameref{third}, \nameref{rest} and \nameref{part}) to
  1200. extract the desired equation, and then use the operators \nameref{rhs} and
  1201. \nameref{lhs} to access the right-hand or left-hand expression of the
  1202. equation. When \name{solve} is unable to solve an equation, it returns the
  1203. unsolved part as the argument of \name{root_of}, with the variable renamed
  1204. to avoid confusion, as shown in the last example above.
  1205. For one equation, \name{solve} uses square-free factorization, roots of
  1206. unity, and the known inverses of the \nameref{log}, \nameref{sin},
  1207. \nameref{cos}, \nameref{acos}, \nameref{asin}, and
  1208. exponentiation operators. The quadratic, cubic and quartic formulas are
  1209. used if necessary, but these are applied only when the switch
  1210. \nameref{fullroots} is set on; otherwise or when no closed form is available
  1211. the result is returned as
  1212. \nameref{root\_of} expression. The switch \nameref{trigform}
  1213. determines which type of cubic and quartic formula is used.
  1214. The multiplicity of each solution is given in a list as
  1215. the system variable \nameref{root\_multiplicities}. For systems of
  1216. simultaneous linear equations, matrix inversion is used. For nonlinear
  1217. systems, the Groebner basis method is used.
  1218. %If kernels are given for linear equations, and there are an unequal number
  1219. %of kernels and equations, an error message is given. If no kernels are
  1220. %given, and there are more kernels in the equations than there are
  1221. %equations, an error message is given.
  1222. Linear equation system solving is influenced by the switch \nameref{cramer}.
  1223. %For nonlinear equations, it is
  1224. %possible to have a consistent set in which the number of variables does not
  1225. %match the number of equations.
  1226. Singular systems can be solved when the switch \nameref{solvesingular} is
  1227. on, which is the default setting. An empty list is returned the system of
  1228. equations is inconsistent. For a linear inconsistent system with parameters
  1229. the variable \nameref{requirements} constraints
  1230. conditions for the system to become consistent.
  1231. For a solvable linear and polynomial system with parameters
  1232. the variable \nameref{assumptions}
  1233. contains a list side relations for the parameters: the solution is
  1234. valid only as long as none of these expressions is zero.
  1235. If the switch \nameref{varopt} is on (default), the system rearranges the
  1236. variable sequence for minimal computation time. Without \name{varopt}
  1237. the user supplied variable sequence is maintained.
  1238. If the solution has free variables (dimension of the solution is greater
  1239. than zero), these are represented by \nameref{arbcomplex} expressions
  1240. as long as the switch \nameref{arbvars} is on (default). Without
  1241. \name{arbvars} no explicit equations are generated for free variables.
  1242. \end{Comments}
  1243. \begin{Related}
  1244. \item[\nameref{allbranch} switch]
  1245. \item[\nameref{arbvars} switch]
  1246. \item[\nameref{assumptions} variable]
  1247. \item[\nameref{fullroots} switch]
  1248. \item[\nameref{requirements} variable]
  1249. \item[\nameref{roots} operator]
  1250. \item[\nameref{root\_of} operator]
  1251. \item[\nameref{trigform} switch]
  1252. \item[\nameref{varopt} switch]
  1253. \end{Related}
  1254. \end{Operator}
  1255. \begin{Operator}{SORT}
  1256. \index{sorting}
  1257. The \name{sort} operator sorts the elements of a list according to
  1258. an arbitrary comparison operator.
  1259. \begin{Syntax}
  1260. \name{sort}\(\meta{lst},\meta{comp}\)
  1261. \end{Syntax}
  1262. \meta{lst} is a \nameref{list} of algebraic expressions.
  1263. \meta{comp} is a comparison operator which defines a partial
  1264. ordering among the members of \meta{lst}. \meta{comp} may be
  1265. one of the builtin comparison operators like
  1266. \name{<}(\nameref{lessp}), \name{<=}(\nameref{leq})
  1267. etc., or \meta{comp} may be the name of a comparison procedure.
  1268. Such a procedure has two arguments, and it returns
  1269. \nameref{true} if the first argument
  1270. ranges before the second one, and 0 or \nameref{nil} otherwise.
  1271. The result of \name{sort} is a new list which contains the
  1272. elements of \meta{lst} in a sequence corresponding to \meta{comp}.
  1273. \begin{Examples}
  1274. % Sort random integers\\
  1275. procedure ce(a,b);\\
  1276. if evenp a and not evenp b then 1 else 0;\\
  1277. for i:=1:10 collect random(50)$\\
  1278. sort(ws,>=); & \{41,38,33,30,28,25,20,17,8,5\}\\
  1279. sort(ws,<); & \{5,8,17,20,25,28,30,33,38,41\}\\
  1280. sort(ws,ce); &\{8,20,28,30,38,5,17,25,33,41\}\\
  1281. % Sort a set of polynomials, first for degree of x\\
  1282. % and second for degree of y.\\
  1283. procedure cd(a,b);\\
  1284. if deg(a,x)>deg(b,x) then 1 else\\
  1285. if deg(a,x)<deg(b,x) then 0 else\\
  1286. if deg(a,y)>deg(b,y) then 1 else 0;\\
  1287. sort({x^2,y^2,x*y},cd);&\{x^2,x*y,y^2\}
  1288. \end{Examples}
  1289. \end{Operator}
  1290. \begin{Operator}{STRUCTR}
  1291. \index{decomposition}
  1292. The \name{structr} operator breaks its argument expression into named
  1293. subexpressions.
  1294. \begin{TEX}
  1295. \begin{Syntax}
  1296. \name{structr}\(\meta{expression} \&option(,\meta{identifier}
  1297. \&option(,\meta{identifier}))\)
  1298. \end{Syntax}
  1299. \end{TEX}
  1300. \begin{Syntax}
  1301. \name{structr}\(\meta{expression} [,\meta{identifier}[,\meta{identifier} ...]]\)
  1302. \end{Syntax}
  1303. \begin{INFO}
  1304. \end{INFO}
  1305. \meta{expression} may be any valid REDUCE scalar expression.
  1306. \meta{identifier} may be any valid REDUCE \name{identifier}. The first
  1307. identifier
  1308. is the stem for subexpression names, the second is the name to be assigned
  1309. to the structured expression.
  1310. \begin{Examples}
  1311. structr(sqrt(x**2 + 2*x) + sin(x**2*z)); &
  1312. \begin{multilineoutput}{6cm}
  1313. ANS1 + ANS2
  1314. where
  1315. ANS2 := SIN(X^{2}*Z)
  1316. ANS1 := ((X + 2)*X)^{1/2}
  1317. \end{multilineoutput}\\
  1318. ans3; & ANS3 \\
  1319. on fort; \\
  1320. structr((x+1)**5 + tan(x*y*z),var,aa); &
  1321. \begin{multilineoutput}{6cm}
  1322. VAR1=TAN(X*Y*Z)
  1323. AA=VAR1+X**5+5.*X**4+10.*X**3+10.X**2+5.*X+1
  1324. \end{multilineoutput}
  1325. \end{Examples}
  1326. \begin{Comments}
  1327. The second argument to \name{structr} is optional. If it is not given, the
  1328. default stem \name{ANS} is used by REDUCE to construct names for the
  1329. subexpression. The names are only for display purposes: REDUCE does not
  1330. store the names and their values unless the switch \nameref{savestructr} is
  1331. on.
  1332. If a third argument is given, the structured expression as a whole is named by
  1333. this argument, when \nameref{fort} is on. The expression is not stored
  1334. under this
  1335. name. You can send these structured Fortran expressions to a file with the
  1336. \name{out} command.
  1337. \end{Comments}
  1338. \end{Operator}
  1339. \begin{Operator}{SUB}
  1340. \index{substitution}
  1341. The \name{sub} operator substitutes a new expression for a kernel in an
  1342. expression.
  1343. \begin{Syntax}
  1344. %\name{sub}\(\meta{kernel}\name{=}\meta{expression}%
  1345. % \{,\meta{kernel}\name{=}\meta{expression}\}\optional,%
  1346. % \meta{expression}\)
  1347. \name{sub}\(\meta{kernel}\name{=}\meta{expression}
  1348. \{,\meta{kernel}\name{=}\meta{expression}\}\optional,
  1349. \meta{expression}\) or \\
  1350. \name{sub}\(\{\meta{kernel}\name{=}\meta{expression}\optional,
  1351. \meta{kernel}\name{=}\name{expression}\},\meta{expression}\)
  1352. \end{Syntax}
  1353. \meta{kernel} must be a \nameref{kernel}, \meta{expression} can be any REDUCE
  1354. scalar expression.
  1355. \begin{Examples}
  1356. sub(x=3,y=4,(x+y)**3); & 343 \\
  1357. x; & X \\
  1358. sub({cos=sin,sin=cos},cos a+sin b} & COS(B) + SIN(A)
  1359. \end{Examples}
  1360. \begin{Comments}
  1361. Note in the second example that operators can be replaced using the
  1362. \name{sub} operator.
  1363. \end{Comments}
  1364. \end{Operator}
  1365. \begin{Operator}{SUM}
  1366. \index{Gosper algorithm}\index{summation}
  1367. The operator \name{sum} returns
  1368. the indefinite or definite summation of a given expression.
  1369. \begin{Syntax}
  1370. \name{sum}\(\meta{expr},\meta{k}[,\meta{lolim} [,\meta{uplim} ]]\)
  1371. \end{Syntax}
  1372. where \meta{expr} is the expression to be added, \meta{k} is the
  1373. control variable (a \nameref{kernel}), and \meta{lolim} and \meta{uplim}
  1374. are the optional lower and upper limits. If \meta{uplim} is
  1375. not supplied the upper limit is taken as \meta{k}. The Gosper
  1376. algorithm is used. If there is no closed form solution, the operator
  1377. returns the input unchanged.
  1378. \begin{Examples}
  1379. sum(4n**3,n); &n^2 *(n^2 + 2*n + 1)\\
  1380. sum(2a+2k*r,k,0,n-1);& n*(2*a + n*r - r)\\
  1381. \end{Examples}
  1382. \end{Operator}
  1383. \begin{Operator}{WS}
  1384. \index{work space}\index{interactive}
  1385. The \name{ws} operator alone returns the last result; \name{ws} with a
  1386. number argument returns the results of the REDUCE statement executed after
  1387. that numbered prompt.
  1388. \begin{Syntax}
  1389. \name{ws} or \name{ws}\(\meta{number}\)
  1390. \end{Syntax}
  1391. \meta{number} must be an integer between 1 and the current REDUCE prompt number.
  1392. \begin{Examples}
  1393. \explanation{(In the following examples, unlike most others, the numbered
  1394. prompt is shown.)} \\
  1395. 1: df(sin y,y); & COS(Y) \\
  1396. 2: ws^2; & COS(Y)^{2} \\
  1397. 3: df(ws 1,y); & -SIN(Y)
  1398. \end{Examples}
  1399. \begin{Comments}
  1400. \name{ws} and \name{ws}\name{(}\meta{number}\name{)} can be used anywhere the
  1401. expression they stand for can be used. Calling a number for which no
  1402. result was produced, such as a switch setting, will give an error message.
  1403. The current workspace always contains the results of the last REDUCE
  1404. command that produced an expression, even if several input statements
  1405. that do not produce expressions have intervened. For example, if you do
  1406. a differentiation, producing a result expression, then change several
  1407. switches, the operator \name{ws;} returns the results of the differentiation.
  1408. The current workspace (\name{ws}) can also be used inside files, though the
  1409. numbered workspace contains only the \name{in} command that input the file.
  1410. There are three history lists kept in your REDUCE session. The first
  1411. stores raw input, suitable for the statement editor. The second stores
  1412. parsed input, ready to execute and accessible by \nameref{input}. The
  1413. third stores results, when they are produced by statements, which are
  1414. accessible by the \name{ws}\meta{ n} operator. If your session is very
  1415. long, storage space begins to fill up with these expressions, so it is a
  1416. good idea to end the session once in a while, saving needed expressions to
  1417. files with the \nameref{saveas} and \nameref{out} commands.
  1418. % Or you could use the \name{forget} command to clear all history lists and
  1419. % reset the prompt number to 1, which doesn't change any switch settings or
  1420. % variable assignments.
  1421. An error message is given if a reference number has not yet been used.
  1422. \end{Comments}
  1423. \end{Operator}