algebra.tex 60 KB

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