arith.tex 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. \section{Arithmetic Operations}
  2. \begin{Introduction}{ARITHMETIC\_OPERATIONS}
  3. This section considers operations defined in REDUCE that concern numbers,
  4. or operators that can operate on numbers in addition, in most cases, to
  5. more general expressions.
  6. \end{Introduction}
  7. \begin{Operator}{ABS}
  8. \index{absolute value}
  9. The \name{abs} operator returns the absolute value of its argument.
  10. \begin{Syntax}
  11. \name{abs}\(\meta{expression}\)
  12. \end{Syntax}
  13. \meta{expression} can be any REDUCE scalar expression.
  14. \begin{Examples}
  15. abs(-a); & ABS(A) \\
  16. abs(-5); & 5 \\
  17. a := -10; & A := -10 \\
  18. abs(a); & 10 \\
  19. abs(-a); & 10
  20. \end{Examples}
  21. \begin{Comments}
  22. If the argument has had no numeric value assigned to it, such as an
  23. identifier or polynomial, \name{abs} returns an expression involving
  24. \name{abs} of its argument, doing as much simplification of the argument
  25. as it can, such as dropping any preceding minus sign.
  26. \end{Comments}
  27. \end{Operator}
  28. \begin{Switch}{ADJPREC}
  29. \index{input}\index{precision}
  30. When a real number is input, it is normally truncated to the
  31. \nameref{precision} in
  32. effect at the time the number is read. If it is desired to keep the full
  33. precision of all numbers input, the switch \name{adjprec}
  34. (for \meta{adjust precision}) can be turned on. While on, \name{adjprec}
  35. will automatically increase the precision, when necessary, to match that
  36. of any integer or real input, and a message printed to inform the user of
  37. the precision increase.
  38. \begin{Examples}
  39. on rounded; \\
  40. 1.23456789012345; & 1.23456789012 \\
  41. on adjprec; \\
  42. 1.23456789012345; \\
  43. *** precision increased to 15 \\
  44. 1.23456789012345
  45. \end{Examples}
  46. \end{Switch}
  47. \begin{Operator}{ARG}
  48. \index{complex}\index{polar angle}
  49. If \nameref{complex} and \nameref{rounded} are on, and {\em arg}
  50. evaluates to a complex number, \name{arg} returns the polar angle of {\em
  51. arg}, measured in radians. Otherwise an expression in {\em arg} is
  52. returned.
  53. \begin{Examples}
  54. arg(3+4i) & ARG(3 + 4*I) \\
  55. on rounded, complex; \\
  56. ws; & 0.927295218002 \\
  57. arg a; & ARG(A)
  58. \end{Examples}
  59. \end{Operator}
  60. \begin{Operator}{CEILING}
  61. \index{integer}
  62. \begin{Syntax}
  63. \name{ceiling}\(\meta{expression}\)
  64. \end{Syntax}
  65. This operator returns the ceiling (i.e., the least integer greater than or
  66. equal to its argument) if its argument has a numerical value. For
  67. negative numbers, this is equivalent to \nameref{fix}. For non-numeric
  68. arguments, the value is an expression in the original operator.
  69. \begin{Examples}
  70. ceiling 3.4; & 4 \\
  71. fix 3.4; & 3 \\
  72. ceiling(-5.2); & -5 \\
  73. fix(-5.2); & -5 \\
  74. ceiling a; & CEILING(A)
  75. \end{Examples}
  76. \end{Operator}
  77. \begin{Operator}{CHOOSE}
  78. \name{choose}(\meta{m},\meta{m}) returns the number of ways of choosing
  79. \meta{m} objects from a collection of \meta{n} distinct objects --- in other
  80. words the binomial coefficient. If \meta{m} and \meta{n} are not positive
  81. integers, or $m > n$, the expression is returned unchanged.
  82. than or equal to
  83. \begin{Examples}
  84. choose(2,3); & 3 \\
  85. choose(3,2); & CHOOSE(3,2) \\
  86. choose(a,b); & CHOOSE(A,B)
  87. \end{Examples}
  88. \end{Operator}
  89. \begin{Operator}{DEG2DMS}
  90. \index{degrees}\index{radians}
  91. \begin{Syntax}
  92. \name{deg2dms}\(\meta{expression}\)
  93. \end{Syntax}
  94. In \nameref{rounded} mode, if \meta{expression} is a real number, the
  95. operator \name{deg2dms} will interpret it as degrees, and convert it to a
  96. list containing the equivalent degrees, minutes and seconds. In all other
  97. cases, an expression in terms of the original operator is returned.
  98. \begin{Examples}
  99. deg2dms 60; & DEG2DMS(60) \\
  100. on rounded; \\
  101. ws; & \{60,0,0\} \\
  102. deg2dms 42.4; & \{42,23,60.0\} \\
  103. deg2dms a; & DEG2DMS(A)
  104. \end{Examples}
  105. \end{Operator}
  106. \begin{Operator}{DEG2RAD}
  107. \index{degrees}\index{radians}
  108. \begin{Syntax}
  109. \name{deg2rad}\(\meta{expression}\)
  110. \end{Syntax}
  111. In \nameref{rounded} mode, if \meta{expression} is a real number, the
  112. operator \name{deg2rad} will interpret it as degrees, and convert it to
  113. the equivalent radians. In all other cases, an expression in terms of the
  114. original operator is returned.
  115. \begin{Examples}
  116. deg2rad 60; & DEG2RAD(60) \\
  117. on rounded; \\
  118. ws; & 1.0471975512 \\
  119. deg2rad a; & DEG2RAD(A)
  120. \end{Examples}
  121. \end{Operator}
  122. \begin{Operator}{DIFFERENCE}
  123. The \name{difference} operator may be used as either an infix or prefix binary
  124. subtraction operator. It is identical to \name{-} as a binary operator.
  125. \begin{Syntax}
  126. \name{difference}\(\meta{expression},\meta{expression}\) or
  127. \meta{expression} \name{difference} \meta{expression}
  128. \{\name{difference} \meta{expression}\}\optional
  129. \end{Syntax}
  130. \meta{expression} can be a number or any other valid REDUCE expression. Matrix
  131. expressions are allowed if they are of the same dimensions.
  132. \begin{Examples}
  133. difference(10,4); & 6 \\
  134. 15 difference 5 difference 2; & 8 \\
  135. a difference b; & A - B
  136. \end{Examples}
  137. \begin{Comments}
  138. The \name{difference} operator is left associative, as shown in the second
  139. example above.
  140. \end{Comments}
  141. \end{Operator}
  142. \begin{Operator}{DILOG}
  143. \index{dilogarithm function}
  144. The \name{dilog} operator is known to the differentiation and integration
  145. operators, but has numeric value attached only at \name{dilog(0)}. Dilog is
  146. defined by
  147. \begin{TEX}
  148. \begin{displaymath}
  149. dilog(x) = -\int{{log(x)\,dx}\over{x-1}}
  150. \end{displaymath}
  151. \end{TEX}
  152. \begin{INFO}
  153. dilog(x) = -int(log(x),x)/(x-1)
  154. \end{INFO}
  155. \begin{Examples}
  156. df(dilog(x**2),x); & - \rfrac{2*LOG(X^{2})*X}{X^{2} - 1}\\
  157. int(dilog(x),x); & DILOG(X)*X - DILOG(X) + LOG(X)*X - X \\
  158. dilog(0); & \rfrac{PI^{2}}{6}
  159. \end{Examples}
  160. \end{Operator}
  161. \begin{Operator}{DMS2DEG}
  162. \index{degrees}\index{radians}
  163. \begin{Syntax}
  164. \name{dms2deg}\(\meta{list}\)
  165. \end{Syntax}
  166. In \nameref{rounded} mode, if \meta{list} is a list of three real numbers,
  167. the operator \name{dms2deg} will interpret the list as degrees, minutes
  168. and seconds and convert it to the equivalent degrees. In all other cases,
  169. an expression in terms of the original operator is returned.
  170. \begin{Examples}
  171. dms2deg \{42,3,7\}; & DMS2DEG(\{42,3,7\}) \\
  172. on rounded; \\
  173. ws; & 42.0519444444 \\
  174. dms2deg a; & DMS2DEG(A)
  175. \end{Examples}
  176. \end{Operator}
  177. \begin{Operator}{DMS2RAD}
  178. \index{degrees}\index{radians}
  179. \begin{Syntax}
  180. \name{dms2rad}\(\meta{list}\)
  181. \end{Syntax}
  182. In \nameref{rounded} mode, if \meta{list} is a list of three real numbers,
  183. the operator \name{dms2rad} will interpret the list as degrees, minutes
  184. and seconds and convert it to the equivalent radians. In all other cases,
  185. an expression in terms of the original operator is returned.
  186. \begin{Examples}
  187. dms2rad \{42,3,7\}; & DMS2RAD(\{42,3,7\}) \\
  188. on rounded; \\
  189. ws; & 0.733944887421 \\
  190. dms2rad a; & DMS2RAD(A)
  191. \end{Examples}
  192. \end{Operator}
  193. \begin{Operator}{FACTORIAL}
  194. \index{gamma}
  195. \begin{Syntax}
  196. \name{factorial}\(\meta{expression}\)
  197. \end{Syntax}
  198. If the argument of \name{factorial} is a positive integer or zero, its
  199. factorial is returned. Otherwise the result is expressed in terms of the
  200. original operator. For more general operations, the \nameref{gamma} operator
  201. is available in the \nameref{Special Function Package}.
  202. \begin{Examples}
  203. factorial 4; & 24 \\
  204. factorial 30 ; & 265252859812191058636308480000000 \\
  205. factorial(a) ; FACTORIAL(A)
  206. \end{Examples}
  207. \end{Operator}
  208. \begin{Operator}{FIX}
  209. \index{integer}
  210. \begin{Syntax}
  211. \name{fix}\(\meta{expression}\)
  212. \end{Syntax}
  213. The operator \name{fix} returns the integer part of its argument, if that
  214. argument has a numerical value. For positive numbers, this is equivalent
  215. to \nameref{floor}, and, for negative numbers, \nameref{ceiling}. For
  216. non-numeric arguments, the value is an expression in the original operator.
  217. \begin{Examples}
  218. fix 3.4; & 3 \\
  219. floor 3.4; & 3 \\
  220. ceiling 3.4; & 4 \\
  221. fix(-5.2); & -5 \\
  222. floor(-5.2); & -6 \\
  223. ceiling(-5.2); & -5 \\
  224. fix(a); & FIX(A)
  225. \end{Examples}
  226. \end{Operator}
  227. \begin{Operator}{FIXP}
  228. \index{integer}
  229. The \name{fixp} logical operator returns true if its argument is an integer.
  230. \begin{Syntax}
  231. \name{fixp}\(\meta{expression}\) or \name{fixp} \meta{simple\_expression}
  232. \end{Syntax}
  233. \meta{expression} can be any valid REDUCE expression, \meta{simple\_expression}
  234. must be a single identifier or begin with a prefix operator.
  235. \begin{Examples}
  236. if fixp 1.5 then write "ok" else write "not";
  237. & not \\
  238. if fixp(a) then write "ok" else write "not";
  239. & not \\
  240. a := 15; & A := 15 \\
  241. if fixp(a) then write "ok" else write "not";
  242. & ok
  243. \end{Examples}
  244. \begin{Comments}
  245. Logical operators can only be used inside conditional expressions such as
  246. \name{if}\ldots\name{then} or \name{while}\ldots\name{do}.
  247. \end{Comments}
  248. \end{Operator}
  249. \begin{Operator}{FLOOR}
  250. \index{integer}
  251. \begin{Syntax}
  252. \name{floor}\(\meta{expression}\)
  253. \end{Syntax}
  254. This operator returns the floor (i.e., the greatest integer less than or
  255. equal to its argument) if its argument has a numerical value. For
  256. positive numbers, this is equivalent to \nameref{fix}. For non-numeric
  257. arguments, the value is an expression in the original operator.
  258. \begin{Examples}
  259. floor 3.4; & 3 \\
  260. fix 3.4; & 3 \\
  261. floor(-5.2); & -6 \\
  262. fix(-5.2); & -5 \\
  263. floor a; & FLOOR(A)
  264. \end{Examples}
  265. \end{Operator}
  266. \begin{Operator}{EXPT}
  267. The \name{expt} operator is both an infix and prefix binary exponentiation
  268. operator. It is identical to \name{^} or \name{**}.
  269. \begin{Syntax}
  270. \name{expt}\(\meta{expression},\meta{expression}\)
  271. or \meta{expression} \name{expt} \meta{expression}
  272. \end{Syntax}
  273. \begin{Examples}
  274. a expt b; & A^{B} \\
  275. expt(a,b); & A^{B} \\
  276. (x+y) expt 4; & X^{4} + 4*X^{3}*Y + 6*X^{2}*Y^{2} + 4*X*Y^{3} + Y^{4}
  277. \end{Examples}
  278. \begin{Comments}
  279. Scalar expressions may be raised to fractional and floating-point powers.
  280. Square matrix expressions may be raised to positive powers, and also to
  281. negative powers if non-singular.
  282. \name{expt} is left associative. In other words, \name{a expt b expt c} is
  283. equivalent to \name{a expt (b*c)}, not \name{a expt (b expt c)}, which
  284. would be right associative.
  285. \end{Comments}
  286. \end{Operator}
  287. \begin{Operator}{GCD}
  288. \index{greatest common divisor}\index{polynomial}
  289. The \name{gcd} operator returns the greatest common divisor of two
  290. polynomials.
  291. \begin{Syntax}
  292. \name{gcd}\(\meta{expression},\meta{expression}\)
  293. \end{Syntax}
  294. \meta{expression} must be a polynomial (or integer), otherwise an error
  295. occurs.
  296. \begin{Examples}
  297. gcd(2*x**2 - 2*y**2,4*x + 4*y); & 2*(X + Y) \\
  298. gcd(sin(x),x**2 + 1); & 1 \\
  299. gcd(765,68); & 17
  300. \end{Examples}
  301. \begin{Comments}
  302. The operator \name{gcd} described here provides an explicit means to find the
  303. gcd of two expressions. The switch \name{gcd} described below simplifies
  304. expressions by finding and canceling gcd's at every opportunity. When
  305. the switch \nameref{ezgcd} is also on, gcd's are figured using the EZ GCD
  306. algorithm, which is usually faster.
  307. %%% The \nameref{heugcd} switch is also available, providing
  308. %%% gcd's by the Heuristic algorithm.
  309. \end{Comments}
  310. \end{Operator}
  311. \begin{Operator}{LN}
  312. \index{logarithm}
  313. \begin{Syntax}
  314. \name{ln}\(\meta{expression}\)
  315. \end{Syntax}
  316. \meta{expression} can be any valid scalar REDUCE expression.
  317. The \name{ln} operator returns the natural logarithm of its argument.
  318. However, unlike \nameref{log}, there are no algebraic rules associated
  319. with it; it will only evaluate when \nameref{rounded} is on, and the
  320. argument is a real number.
  321. \begin{Examples}
  322. ln(x); & LN(X) \\
  323. ln 4; & LN(4) \\
  324. ln(e); & LN(E) \\
  325. df(ln(x),x); & DF(LN(X),X) \\
  326. on rounded; \\
  327. ln 4; & 1.38629436112 \\
  328. ln e; & 1
  329. \end{Examples}
  330. \begin{Comments}
  331. Because of the restricted algebraic properties of \name{ln}, users are
  332. advised to use \nameref{log} whenever possible.
  333. \end{Comments}
  334. \end{Operator}
  335. \begin{Operator}{LOG}
  336. \index{logarithm}
  337. The \name{log} operator returns the natural logarithm of its argument.
  338. \begin{Syntax}
  339. \name{log}\(\meta{expression}\) or \name{log} \meta{expression}
  340. \end{Syntax}
  341. \meta{expression} can be any valid scalar REDUCE expression.
  342. \begin{Examples}
  343. log(x); & LOG(X) \\
  344. log 4; & LOG(4) \\
  345. log(e); & 1 \\
  346. on rounded; \\
  347. log 4; & 1.38629436112
  348. \end{Examples}
  349. \begin{Comments}
  350. \name{log} returns a numeric value only when \nameref{rounded} is on. In that
  351. case, use of a negative argument for \name{log} results in an error
  352. message. No error is given on a negative argument when REDUCE is not in
  353. that mode.
  354. \end{Comments}
  355. \end{Operator}
  356. \begin{Operator}{LOGB}
  357. \index{logarithm}
  358. \begin{Syntax}
  359. \name{logb}\(\meta{expression}\,\meta{integer}\)
  360. \end{Syntax}
  361. \meta{expression} can be any valid scalar REDUCE expression.
  362. The \name{logb} operator returns the logarithm of its first argument using
  363. the second argument as base. However, unlike \nameref{log}, there are no
  364. algebraic rules associated with it; it will only evaluate when
  365. \nameref{rounded} is on, and the first argument is a real number.
  366. \begin{Examples}
  367. logb(x,2); & LOGB(X,2) \\
  368. logb(4,3); & LOGB(4,3) \\
  369. logb(2,2); & LOGB(2,2) \\
  370. df(logb(x,3),x); & DF(LOGB(X,3),X) \\
  371. on rounded; \\
  372. logb(4,3); & 1.26185950714 \\
  373. logb(2,2); & 1
  374. \end{Examples}
  375. \end{Operator}
  376. \begin{Operator}{MAX}
  377. \index{maximum}
  378. The operator \name{max} is an n-ary prefix operator, which returns the largest
  379. value in its arguments.
  380. \begin{Syntax}
  381. \name{max}\(\meta{expression}\{,\meta{expression}\}\optional\)
  382. \end{Syntax}
  383. \meta{expression} must evaluate to a number. \name{max} of an empty list
  384. returns 0.
  385. \begin{Examples}
  386. max(4,6,10,-1); & 10 \\
  387. <<a := 23;b := 2*a;c := 4**2;max(a,b,c)>>;
  388. & 46 \\
  389. max(-5,-10,-a); & -5
  390. \end{Examples}
  391. \end{Operator}
  392. \begin{Operator}{MIN}
  393. \index{minimum}
  394. The operator \name{min} is an n-ary prefix operator, which returns the
  395. smallest value in its arguments.
  396. \begin{Syntax}
  397. \name{min}\(\meta{expression}\{,\meta{expression}\}\optional\)
  398. \end{Syntax}
  399. \meta{expression} must evaluate to a number. \name{min} of an empty list
  400. returns 0.
  401. \begin{Examples}
  402. min(-3,0,17,2); & -3 \\
  403. <<a := 23;b := 2*a;c := 4**2;min(a,b,c)>>;
  404. & 16 \\
  405. min(5,10,a); & 5
  406. \end{Examples}
  407. \end{Operator}
  408. \begin{Operator}{MINUS}
  409. The \name{minus} operator is a unary minus, returning the negative of its
  410. argument. It is equivalent to the unary \name{-}.
  411. \begin{Syntax}
  412. \name{minus}\(\meta{expression}\)
  413. \end{Syntax}
  414. \meta{expression} may be any scalar REDUCE expression.
  415. \begin{Examples}
  416. minus(a); & - A \\
  417. minus(-1); & 1 \\
  418. minus((x+1)**4); & - (X^{4} + 4*X^{3} + 6*X^{2} + 4*X + 1)
  419. \end{Examples}
  420. \end{Operator}
  421. \begin{Operator}{NEXTPRIME}
  422. \index{prime number}
  423. \begin{Syntax}
  424. \name{nextprime}\(\meta{expression}\)
  425. \end{Syntax}
  426. If the argument of \name{nextprime} is an integer, the least prime greater
  427. than that argument is returned. Otherwise, a type error results.
  428. \begin{Examples}
  429. nextprime 5001; & 5003 \\
  430. nextprime(10^30); & 1000000000000000000000000000057 \\
  431. nextprime a; & ***** A invalid as integer
  432. \end{Examples}
  433. \end{Operator}
  434. \begin{Switch}{NOCONVERT}
  435. Under normal circumstances when \name{rounded} is on, \REDUCE\ converts the
  436. number 1.0 to the integer 1. If this is not desired, the switch
  437. \name{noconvert} can be turned on.
  438. \begin{Examples}
  439. on rounded; \\
  440. 1.0000000000001; & 1 \\
  441. on noconvert; \\
  442. 1.0000000000001; & 1.0 \\
  443. \end{Examples}
  444. \end{Switch}
  445. \begin{Operator}{NORM}
  446. \index{complex}
  447. \begin{Syntax}
  448. \name{norm}\(\meta{expression}\)
  449. \end{Syntax}
  450. If \name{rounded} is on, and the argument is a real number, \meta{norm}
  451. returns its absolute value. If \name{complex} is also on, \meta{norm}
  452. returns the square root of the sum of squares of the real and imaginary
  453. parts of the argument. In all other cases, a result is returned in
  454. terms of the original operator.
  455. \begin{Examples}
  456. norm (-2); & NORM(-2) \\
  457. on rounded;\\
  458. ws; & 2.0 \\
  459. norm(3+4i); & NORM(4*I+3) \\
  460. on complex;\\
  461. ws; & 5.0\\
  462. \end{Examples}
  463. \end{Operator}
  464. \begin{Operator}{PERM}
  465. \index{permutation}
  466. \begin{Syntax}
  467. perm(\meta{expression1},\meta{expression2})
  468. \end{Syntax}
  469. If \meta{expression1} and \meta{expression2} evaluate to positive integers,
  470. \name{perm} returns the number of permutations possible in selecting
  471. \meta{expression1} objects from \meta{expression2} objects.
  472. In other cases, an expression in the original operator is returned.
  473. \begin{Examples}
  474. perm(1,1); & 1 \\
  475. perm(3,5); & 60 \\
  476. perm(-3,5); & PERM(-3,5) \\
  477. perm(a,b); & PERM(A,B)
  478. \end{Examples}
  479. \end{Operator}
  480. \begin{Operator}{PLUS}
  481. The \name{plus} operator is both an infix and prefix n-ary addition
  482. operator. It exists because of the way in which {\REDUCE} handles such
  483. operators internally, and is not recommended for use in algebraic mode
  484. programming. \nameref{plussign}, which has the identical effect, should be
  485. used instead.
  486. \begin{Syntax}
  487. \name{plus}\(\meta{expression},\meta{expression}\{,\meta{expression}\}
  488. \optional\) or \\
  489. \meta{expression} \name{plus} \meta{expression} \{\name{plus} \meta{expression}\}\optional
  490. \end{Syntax}
  491. \meta{expression} can be any valid REDUCE expression, including matrix
  492. expressions of the same dimensions.
  493. \begin{Examples}
  494. a plus b plus c plus d; & A + B + C + D \\
  495. 4.5 plus 10; & \rfrac{29}{2} \\\\
  496. plus(x**2,y**2); & X^{2} + Y^{2}
  497. \end{Examples}
  498. \end{Operator}
  499. \begin{Operator}{QUOTIENT}
  500. The \name{quotient} operator is both an infix and prefix binary operator that
  501. returns the quotient of its first argument divided by its second. It is
  502. also a unary \nameref{recip}rocal operator. It is identical to \name{/} and
  503. \nameref{slash}.
  504. \begin{Syntax}
  505. \name{quotient}\(\meta{expression},\meta{expression}\) or
  506. \meta{expression} \name{quotient} \meta{expression} or
  507. \name{quotient}\(\meta{expression}\) or
  508. \name{quotient} \meta{expression}
  509. \end{Syntax}
  510. \meta{expression} can be any valid REDUCE scalar expression. Matrix
  511. expressions can also be used if the second expression is invertible and the
  512. matrices are of the correct dimensions.
  513. \begin{Examples}
  514. quotient(a,x+1); & \rfrac{A}{X + 1} \\
  515. 7 quotient 17; & \rfrac{7}{17} \\
  516. on rounded; \\
  517. 4.5 quotient 2; & 2.25 \\
  518. quotient(x**2 + 3*x + 2,x+1); & X + 2 \\
  519. matrix m,inverse; \\
  520. m := mat((a,b),(c,d)); & \begin{multilineoutput}{6cm}
  521. M(1,1) := A;
  522. M(1,2) := B;
  523. M(2,1) := C
  524. M(2,2) := D
  525. \end{multilineoutput}\\
  526. inverse := quotient m; & \begin{multilineoutput}{8cm}
  527. INVERSE(1,1) := \rfrac{D}{A*D - B*C}
  528. INVERSE(1,2) := - \rfrac{B}{A*D - B*C}
  529. INVERSE(2,1) := - \rfrac{C}{A*D - B*C}
  530. INVERSE(2,2) := \rfrac{A}{A*D - B*C}
  531. \end{multilineoutput}
  532. \end{Examples}
  533. \begin{Comments}
  534. The \name{quotient} operator is left associative: \name{a quotient b quotient c}
  535. is equivalent to \name{(a quotient b) quotient c}.
  536. If a matrix argument to the unary \name{quotient} is not invertible, or if the
  537. second matrix argument to the binary quotient is not invertible, an error
  538. message is given.
  539. \end{Comments}
  540. \end{Operator}
  541. \begin{Operator}{RAD2DEG}
  542. \index{degrees}\index{radians}
  543. \begin{Syntax}
  544. \name{rad2deg}\(\meta{expression}\)
  545. \end{Syntax}
  546. In \nameref{rounded} mode, if \meta{expression} is a real number, the
  547. operator \name{rad2deg} will interpret it as radians, and convert it to
  548. the equivalent degrees. In all other cases, an expression in terms of the
  549. original operator is returned.
  550. \begin{Examples}
  551. rad2deg 1; & RAD2DEG(1) \\
  552. on rounded; \\
  553. ws; & 57.2957795131 \\
  554. rad2deg a; & RAD2DEG(A)
  555. \end{Examples}
  556. \end{Operator}
  557. \begin{Operator}{RAD2DMS}
  558. \index{degrees}\index{radians}
  559. \begin{Syntax}
  560. \name{rad2dms}\(\meta{expression}\)
  561. \end{Syntax}
  562. In \nameref{rounded} mode, if \meta{expression} is a real number, the
  563. operator \name{rad2dms} will interpret it as radians, and convert it to a
  564. list containing the equivalent degrees, minutes and seconds. In all other
  565. cases, an expression in terms of the original operator is returned.
  566. \begin{Examples}
  567. rad2dms 1; & RAD2DMS(1) \\
  568. on rounded; \\
  569. ws; & \{57,17,44.8062470964\} \\
  570. rad2dms a; & RAD2DMS(A)
  571. \end{Examples}
  572. \end{Operator}
  573. \begin{Operator}{RECIP}
  574. \name{recip} is the alphabetical name for the division operator \name{/}
  575. or \nameref{slash} used as a unary operator. The use of \name{/} is preferred.
  576. \begin{Examples}
  577. recip a; & \rfrac{1}{A} \\
  578. recip 2; & \rfrac{1}{2}
  579. \end{Examples}
  580. \end{Operator}
  581. \begin{Operator}{REMAINDER}
  582. \index{polynomial}
  583. The \name{remainder} operator returns the remainder after its first
  584. argument is divided by its second argument.
  585. \begin{Syntax}
  586. \name{remainder}\(\meta{expression},\meta{expression}\)
  587. \end{Syntax}
  588. \meta{expression} can be any valid REDUCE polynomial, and is not limited
  589. to numeric values.
  590. \begin{Examples}
  591. remainder(13,6); & 1 \\
  592. remainder(x**2 + 3*x + 2,x+1); & 0 \\
  593. remainder(x**3 + 12*x + 4,x**2 + 1); & 11*X + 4 \\
  594. remainder(sin(2*x),x*y); & SIN(2*X)
  595. \end{Examples}
  596. \begin{Comments}
  597. In the default case, remainders are calculated over the integers. If you
  598. need the remainder with respect to another domain, it must be declared
  599. explicitly.
  600. If the first argument to \name{remainder} contains a denominator not equal to
  601. 1, an error occurs.
  602. \end{Comments}
  603. \end{Operator}
  604. \begin{Operator}{ROUND}
  605. \index{integer}
  606. \begin{Syntax}
  607. \name{round}\(\meta{expression}\)
  608. \end{Syntax}
  609. If its argument has a numerical value, \name{round} rounds it to the
  610. nearest integer. For non-numeric arguments, the value is an expression in
  611. the original operator.
  612. \begin{Examples}
  613. round 3.4; & 3 \\
  614. round 3.5; & 4 \\
  615. round a; & ROUND(A)
  616. \end{Examples}
  617. \end{Operator}
  618. \begin{Command}{SETMOD}
  619. \index{modular}
  620. The \name{setmod} command sets the modulus value for subsequent \nameref{modular}
  621. arithmetic.
  622. \begin{Syntax}
  623. \name{setmod} \meta{integer}
  624. \end{Syntax}
  625. \meta{integer} must be positive, and greater than 1. It need not be a prime
  626. number.
  627. \begin{Examples}
  628. setmod 6; & 1 \\
  629. on modular; \\
  630. 16; & 4 \\
  631. x^2 + 5x + 7; & X^{2} + 5*X + 1 \\
  632. x/3; & \rfrac{X}{3} \\
  633. setmod 2; & 6 \\
  634. (x+1)^4; & X^{4} + 1 \\
  635. x/3; & X
  636. \end{Examples}
  637. \begin{Comments}
  638. \name{setmod} returns the previous modulus, or 1 if none has been set
  639. before. \name{setmod} only has effect when \nameref{modular} is on.
  640. Modular operations are done only on numbers such as coefficients of
  641. polynomials, not on the exponents. The modulus need not be prime.
  642. Attempts to divide by a power of the modulus produces an error message, since the
  643. operation is equivalent to dividing by 0. However, dividing by a factor
  644. of a non-prime modulus does not produce an error message.
  645. \end{Comments}
  646. \end{Command}
  647. \begin{Operator}{SIGN}
  648. \begin{Syntax}
  649. \name{sign} \meta{expression}
  650. \end{Syntax}
  651. \name{sign} tries to evaluate the sign of its argument. If this
  652. is possible \name{sign} returns one of 1, 0 or -1. Otherwise, the result
  653. is the original form or a simplified variant.
  654. \begin{Examples}
  655. sign(-5) & -1\\
  656. sign(-a^2*b) & -SIGN(B)\\
  657. \end{Examples}
  658. \begin{Comments}
  659. Even powers of formal expressions are assumed to be positive only as long
  660. as the switch \nameref{complex} is off.
  661. \end{Comments}
  662. \end{Operator}
  663. \begin{Operator}{SQRT}
  664. \index{square root}
  665. The \name{sqrt} operator returns the square root of its argument.
  666. \begin{Syntax}
  667. \name{sqrt}\(\meta{expression}\)
  668. \end{Syntax}
  669. \meta{expression} can be any REDUCE scalar expression.
  670. \begin{Examples}
  671. sqrt(16*a^3); & 4*SQRT(A)*A \\
  672. sqrt(17); & SQRT(17) \\
  673. on rounded; \\
  674. sqrt(17); & 4.12310562562 \\
  675. off rounded; \\
  676. sqrt(a*b*c^5*d^3*27); &
  677. 3*SQRT(D)*SQRT(C)*SQRT(B)*SQRT(A)*SQRT(3)*C^{2}*D
  678. \end{Examples}
  679. \begin{Comments}
  680. \name{sqrt} checks its argument for squared factors and removes them.
  681. % If the \name{reduced} switch is on, square roots of a product become a
  682. % product of square roots.
  683. Numeric values for square roots that are not exact integers are given only
  684. when \nameref{rounded} is on.
  685. Please note that \name{sqrt(a**2)} is given as \name{a}, which may be
  686. incorrect if \name{a} eventually has a negative value. If you are
  687. programming a calculation in which this is a concern, you can turn on the
  688. \nameref{precise} switch, which causes the absolute value of the square root
  689. to be returned.
  690. \end{Comments}
  691. \end{Operator}
  692. \begin{Operator}{TIMES}
  693. The \name{times} operator is an infix or prefix n-ary multiplication
  694. operator. It is identical to \name{*}.
  695. \begin{Syntax}
  696. \meta{expression} \name{times} \meta{expression} \{\name{times} \meta{expression}\}\optional
  697. or \name{times}\(\meta{expression},\meta{expression} \{,\meta{expression}\}\optional\)
  698. \end{Syntax}
  699. \meta{expression} can be any valid REDUCE scalar or matrix expression.
  700. Matrix expressions must be of the correct dimensions. Compatible scalar
  701. and matrix expressions can be mixed.
  702. \begin{Examples}
  703. var1 times var2; & VAR1*VAR2 \\
  704. times(6,5); & 30 \\
  705. matrix aa,bb; \\
  706. aa := mat((1),(2),(x))\$ \\
  707. bb := mat((0,3,1))\$ \\
  708. aa times bb times 5; &
  709. \begin{multilineoutput}{6cm}
  710. [0 15 5 ]
  711. [ ]
  712. [0 30 10 ]
  713. [ ]
  714. [0 15*X 5*X]
  715. \end{multilineoutput}
  716. \end{Examples}
  717. \end{Operator}