polyrat.tex 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. \chapter{Polynomials and Rationals}
  2. Many operations in computer algebra are concerned with polynomials
  3. \index{Polynomial} and rational functions\index{Rational function}. In
  4. this section, we review some of the switches and operators available for
  5. this purpose. These are in addition to those that work on general
  6. expressions (such as {\tt DF} and {\tt INT}) described elsewhere. In the
  7. case of operators, the arguments are first simplified before the
  8. operations are applied. In addition, they operate only on arguments of
  9. prescribed types, and produce a type mismatch error if given arguments
  10. which cannot be interpreted in the required mode with the current switch
  11. settings. For example, if an argument is required to be a kernel and
  12. {\tt a/2} is used (with no other rules for {\tt A}), an error
  13. \begin{verbatim}
  14. A/2 invalid as kernel
  15. \end{verbatim}
  16. will result.
  17. With the exception of those that select various parts of a polynomial or
  18. rational function, these operations have potentially significant effects on
  19. the space and time associated with a given calculation. The user should
  20. therefore experiment with their use in a given calculation in order to
  21. determine the optimum set for a given problem.
  22. One such operation provided by the system is an operator {\tt LENGTH}
  23. \ttindex{LENGTH} which returns the number of top level terms in the
  24. numerator of its argument. For example,
  25. \begin{verbatim}
  26. length ((a+b+c)^3/(c+d));
  27. \end{verbatim}
  28. has the value 10. To get the number of terms in the denominator, one
  29. would first select the denominator by the operator {\tt DEN}\ttindex{DEN}
  30. and then call {\tt LENGTH}, as in
  31. \begin{verbatim}
  32. length den ((a+b+c)^3/(c+d));
  33. \end{verbatim}
  34. Other operations currently supported, the relevant switches and operators,
  35. and the required argument and value modes of the latter, follow.
  36. \section{Controlling the Expansion of Expressions}
  37. The switch {\tt EXP}\ttindex{EXP} controls the expansion of expressions. If
  38. it is off, no expansion of powers or products of expressions occurs.
  39. Users should note however that in this case results come out in a normal
  40. but not necessarily canonical form. This means that zero expressions
  41. simplify to zero, but that two equivalent expressions need not necessarily
  42. simplify to the same form.
  43. {\it Example:} With {\tt EXP} on, the two expressions
  44. \begin{verbatim}
  45. (a+b)*(a+2*b)
  46. \end{verbatim}
  47. and
  48. \begin{verbatim}
  49. a^2+3*a*b+2*b^2
  50. \end{verbatim}
  51. will both simplify to the latter form. With {\tt EXP}
  52. off, they would remain unchanged, unless the complete factoring {\tt
  53. (ALLFAC)} option were in force. {\tt EXP} is normally on.
  54. Several operators that expect a polynomial as an argument behave
  55. differently when {\tt EXP} is off, since there is often only one term at
  56. the top level. For example, with {\tt EXP} off
  57. \begin{verbatim}
  58. length((a+b+c)^3/(c+d));
  59. \end{verbatim}
  60. returns the value 1.
  61. \section{Factorization of Polynomials}\index{Factorization}
  62. {\REDUCE} is capable of factorizing univariate and multivariate polynomials
  63. that have integer coefficients, finding all factors that also have integer
  64. coefficients. The package for doing this was written by Dr. Arthur C.
  65. Norman and Ms. P. Mary Ann Moore at The University of Cambridge. It is
  66. described in P. M. A. Moore and A. C. Norman, ``Implementing a Polynomial
  67. Factorization and GCD Package'', Proc. SYMSAC '81, ACM (New York) (1981),
  68. 109-116.
  69. The easiest way to use this facility is to turn on the switch
  70. {\tt FACTOR},\ttindex{FACTOR} which causes all expressions to be output in
  71. a factored form. For example, with {\tt FACTOR} on, the expression
  72. {\tt A\verb|^|2-B\verb|^|2} is returned as {\tt (A+B)*(A-B)}.
  73. It is also possible to factorize a given expression explicitly. The
  74. operator {\tt FACTORIZE}\ttindex{FACTORIZE} that invokes this facility is
  75. used with the syntax
  76. \begin{verbatim}
  77. FACTORIZE(EXPRN:polynomial[,INTEXP:prime integer]):list,
  78. \end{verbatim}
  79. the optional argument of which will be described later. Thus to find and
  80. display all factors of the cyclotomic polynomial $x^{105}-1$, one could
  81. write:
  82. \begin{verbatim}
  83. factorize(x^105-1);
  84. \end{verbatim}
  85. The result is a list of factor,exponent pairs.
  86. In the above example, there is no overall numerical factor in the result,
  87. so the results will consist only of polynomials in x. The number of such
  88. polynomials can be found by using the operator {\tt LENGTH}.\ttindex{LENGTH}
  89. If there is a numerical factor, as in factorizing $12x^{2}-12$,
  90. that factor will appear as the first member of the result.
  91. It will however not be factored further. Prime factors of such numbers
  92. can be found, using a probabilistic algorithm, by turning on the switch
  93. {\tt IFACTOR}.\ttindex{IFACTOR} For example,
  94. \begin{verbatim}
  95. on ifactor; factorize(12x^2-12);
  96. \end{verbatim}
  97. would result in the output
  98. \begin{verbatim}
  99. {{2,2},{3,1},{X + 1,1},{X - 1,1}}.
  100. \end{verbatim}
  101. If the first argument of {\tt FACTORIZE} is an integer, it will be
  102. decomposed into its prime components, whether or not {\tt IFACTOR} is on.
  103. Note that the {\tt IFACTOR} switch only affects the result of {\tt FACTORIZE}.
  104. It has no effect if the {\tt FACTOR}\ttindex{FACTOR} switch is also on.
  105. The order in which the factors occur in the result (with the exception of
  106. a possible overall numerical coefficient which comes first) can be system
  107. dependent and should not be relied on. Similarly it should be noted that
  108. any pair of individual factors can be negated without altering their
  109. product, and that {\REDUCE} may sometimes do that.
  110. The factorizer works by first reducing multivariate problems to univariate
  111. ones and then solving the univariate ones modulo small primes. It normally
  112. selects both evaluation points and primes using a random number generator
  113. that should lead to different detailed behavior each time any particular
  114. problem is tackled. If, for some reason, it is known that a certain
  115. (probably univariate) factorization can be performed effectively with a
  116. known prime, {\tt P} say, this value of {\tt P} can be handed to
  117. {\tt FACTORIZE}\ttindex{FACTORIZE} as a second
  118. argument. An error will occur if a non-prime is provided to {\tt FACTORIZE} in
  119. this manner. It is also an error to specify a prime that divides the
  120. discriminant of the polynomial being factored, but users should note that
  121. this condition is not checked by the program, so this capability should be
  122. used with care.
  123. Factorization can be performed over a number of polynomial coefficient
  124. domains in addition to integers. The particular description of the relevant
  125. domain should be consulted to see if factorization is supported. For
  126. example, the following statements will factorize $x^{4}+1$ modulo 7:
  127. \begin{verbatim}
  128. setmod 7;
  129. on modular;
  130. factorize(x^4+1);
  131. \end{verbatim}
  132. The factorization module is provided with a trace facility that may be useful
  133. as a way of monitoring progress on large problems, and of satisfying
  134. curiosity about the internal workings of the package. The most simple use
  135. of this is enabled by issuing the {\REDUCE} command\ttindex{TRFAC}
  136. {\tt on trfac;} .
  137. Following this, all calls to the factorizer will generate informative
  138. messages reporting on such things as the reduction of multivariate to
  139. univariate cases, the choice of a prime and the reconstruction of full
  140. factors from their images. Further levels of detail in the trace are
  141. intended mainly for system tuners and for the investigation of suspected
  142. bugs. For example, {\tt TRALLFAC} gives tracing information at all levels
  143. of detail. The switch that can be set by {\tt on timings;} makes it
  144. possible for one who is familiar with the algorithms used to determine
  145. what part of the factorization code is consuming the most resources.
  146. {\tt on overview}; reduces the amount of detail presented in other forms of
  147. trace. Other forms of trace output are enabled by directives of the form
  148. \begin{verbatim}
  149. symbolic set!-trace!-factor(<number>,<filename>);
  150. \end{verbatim}
  151. where useful numbers are 1, 2, 3 and 100, 101, ... . This facility is
  152. intended to make it possible to discover in fairly great detail what just
  153. some small part of the code has been doing --- the numbers refer mainly to
  154. depths of recursion when the factorizer calls itself, and to the split
  155. between its work forming and factorizing images and reconstructing full
  156. factors from these. If {\tt NIL} is used in place of a filename the trace
  157. output requested is directed to the standard output stream. After use of
  158. this trace facility the generated trace files should be closed by calling
  159. \begin{verbatim}
  160. symbolic close!-trace!-files();
  161. \end{verbatim}
  162. {\it NOTE:} Using the factorizer with {\tt MCD}\ttindex{MCD} off will
  163. result in an error.
  164. \section{Cancellation of Common Factors}
  165. Facilities are available in {\REDUCE} for cancelling common factors in the
  166. numerators and denominators of expressions, at the option of the user. The
  167. system will perform this greatest common divisor computation if the switch
  168. {\tt GCD}\ttindex{GCD} is on. ({\tt GCD} is normally off.)
  169. A check is automatically made, however, for common variable and numerical
  170. products in the numerators and denominators of expressions, and the
  171. appropriate cancellations made.
  172. When {\tt GCD} is on, and {\tt EXP} is off, a check is made for square
  173. free factors in an expression. This includes separating out and
  174. independently checking the content of a given polynomial where
  175. appropriate. (For an explanation of these terms, see Anthony C. Hearn,
  176. ``Non-Modular Computation of Polynomial GCDs Using Trial Division'', Proc.
  177. EUROSAM 79, published as Lecture Notes on Comp. Science, Springer-Verlag,
  178. Berlin, No 72 (1979) 227-239.)
  179. {\it Example:} With {\tt EXP}\ttindex{EXP} off and {\tt GCD}\ttindex{GCD}
  180. on,
  181. the polynomial {\tt a*c+a*d+b*c+b*d} would be returned as {\tt (A+B)*(C+D)}.
  182. Under normal circumstances, GCDs are computed using an algorithm described
  183. in the above paper. It is also possible in {\REDUCE} to compute GCDs using
  184. an alternative algorithm, called the EZGCD Algorithm, which uses modular
  185. arithmetic. The switch {\tt EZGCD}\ttindex{EZGCD}, if on in addition to
  186. {\tt GCD}, makes this happen.
  187. In non-trivial cases, the EZGCD algorithm is almost always better
  188. than the basic algorithm, often by orders of magnitude. We therefore
  189. {\em strongly\/} advise users to use the {\tt EZGCD} switch where they have the
  190. resources available for supporting the package.
  191. For a description of the EZGCD algorithm, see J. Moses and D.Y.Y. Yun,
  192. ``The EZ GCD Algorithm'', Proc. ACM 1973, ACM, New York (1973) 159-166.
  193. {\it NOTE:}
  194. This package shares code with the factorizer, so a certain amount of trace
  195. information can be produced using the factorizer trace switches.
  196. \subsection{Determining the GCD of Two Polynomials}
  197. This operator, used with the syntax
  198. \begin{verbatim}
  199. GCD(EXPRN1:polynomial,EXPRN2:polynomial):polynomial,
  200. \end{verbatim}
  201. returns the greatest common divisor of the two polynomials {\tt EXPRN1} and
  202. {\tt EXPRN2}.
  203. {\it Examples:}
  204. \begin{verbatim}
  205. gcd(x^2+2*x+1,x^2+3*x+2) -> X+1
  206. gcd(2*x^2-2*y^2,4*x+4*y) -> 2*X+2*Y
  207. gcd(x^2+y^2,x-y) -> 1.
  208. \end{verbatim}
  209. \section{Working with Least Common Multiples}
  210. Greatest common divisor calculations can often become expensive if
  211. extensive work with large rational expressions is required. However, in
  212. many cases, the only significant cancellations arise from the fact that
  213. there are often common factors in the various denominators which are
  214. combined when two rationals are added. Since these denominators tend to be
  215. smaller and more regular in structure than the numerators, considerable
  216. savings in both time and space can occur if a full GCD check is made when
  217. the denominators are combined and only a partial check when numerators are
  218. constructed. In other words, the true least common multiple of the
  219. denominators is computed at each step. The switch {\tt LCM}\ttindex{LCM}
  220. is available for this purpose, and is normally on.
  221. In addition, the operator {\tt LCM},\ttindex{LCM} used with the syntax
  222. \begin{verbatim}
  223. LCM(EXPRN1:polynomial,EXPRN2:polynomial):polynomial,
  224. \end{verbatim}
  225. returns the least common multiple of the two polynomials {\tt EXPRN1} and
  226. {\tt EXPRN2}.
  227. {\it Examples:}
  228. \begin{verbatim}
  229. lcm(x^2+2*x+1,x^2+3*x+2) -> X**3 + 4*X**2 + 5*X + 2
  230. lcm(2*x^2-2*y^2,4*x+4*y) -> 4*(X**2 - Y**2)
  231. \end{verbatim}
  232. \section{Controlling Use of Common Denominators}
  233. When two rational functions are added, {\REDUCE} normally produces an
  234. expression over a common denominator. However, if the user does not want
  235. denominators combined, he or she can turn off the switch {\tt MCD}
  236. \ttindex{MCD} which controls this process. The latter switch is
  237. particularly useful if no greatest common divisor calculations are
  238. desired, or excessive differentiation of rational functions is required.
  239. {\it CAUTION:} With {\tt MCD} off, results are not guaranteed to come out in
  240. either normal or canonical form. In other words, an expression equivalent
  241. to zero may in fact not be simplified to zero. This option is therefore
  242. most useful for avoiding expression swell during intermediate parts of a
  243. calculation.
  244. {\tt MCD}\ttindex{MCD} is normally on.
  245. \section{REMAINDER Operator}\ttindex{REMAINDER}
  246. This operator is used with the syntax
  247. \begin{verbatim}
  248. REMAINDER(EXPRN1:polynomial,EXPRN2:polynomial):polynomial.
  249. \end{verbatim}
  250. It returns the remainder when {\tt EXPRN1} is divided by {\tt EXPRN2}. This
  251. is the true remainder based on the internal ordering of the variables, and
  252. not the pseudo-remainder. The pseudo-remainder \ttindex{PSEUDO\_REMAINDER}
  253. and in general pseudo-division \ttindex{PSEUDO\_DIVIDE} of polynomials
  254. can be calculated after loading the {\tt polydiv} package.
  255. Please refer to the documentation of this package for details.
  256. {\it Examples:}
  257. \begin{verbatim}
  258. remainder((x+y)*(x+2*y),x+3*y) -> 2*Y**2
  259. remainder(2*x+y,2) -> Y.
  260. \end{verbatim}
  261. {\it CAUTION:} In the default case, remainders are calculated over the
  262. integers. If you need the remainder with respect to another domain, it
  263. must be declared explicitly.
  264. {\it Example:}
  265. \begin{verbatim}
  266. remainder(x^2-2,x+sqrt(2)); -> X^2 - 2
  267. load_package arnum;
  268. defpoly sqrt2**2-2;
  269. remainder(x^2-2,x+sqrt2); -> 0
  270. \end{verbatim}
  271. \section{RESULTANT Operator}\ttindex{RESULTANT}
  272. This is used with the syntax
  273. \begin{verbatim}
  274. RESULTANT(EXPRN1:polynomial,EXPRN2:polynomial,VAR:kernel):
  275. polynomial.
  276. \end{verbatim}
  277. It computes the resultant of the two given polynomials with respect to the
  278. given variable, the coefficients of the polynomials can be taken from any
  279. domain. The result can be identified as the determinant of a
  280. Sylvester matrix, but can often also be thought of informally as the
  281. result obtained when the given variable is eliminated between the two input
  282. polynomials. If the two input polynomials have a non-trivial GCD their
  283. resultant vanishes.
  284. The switch {\tt Bezout}\ttindex{Bezout} controls the computation of the
  285. resultants. It is off by default. In this case a subresultant algorithm
  286. is used. If the switch Bezout is turned on, the resultant is computed via
  287. the Bezout Matrix. However, in the latter case, only polynomial coefficients
  288. are permitted.
  289. \begin{samepage}
  290. The sign conventions used by the resultant function follow those in R.
  291. Loos, ``Computing in Algebraic Extensions'' in ``Computer Algebra --- Symbolic
  292. and Algebraic Computation'', Second Ed., Edited by B. Buchberger, G.E.
  293. Collins and R. Loos, Springer-Verlag, 1983. Namely, with {\tt A} and {\tt B}
  294. not dependent on {\tt X}:
  295. \begin{verbatim}
  296. deg(p)*deg(q)
  297. resultant(p(x),q(x),x)= (-1) *resultant(q,p,x)
  298. deg(p)
  299. resultant(a,p(x),x) = a
  300. resultant(a,b,x) = 1
  301. \end{verbatim}
  302. \end{samepage}
  303. {\it Examples:}
  304. \begin{samepage}
  305. \begin{verbatim}
  306. 2
  307. resultant(x/r*u+y,u*y,u) -> - y
  308. \end{verbatim}
  309. \end{samepage}
  310. {\it calculation in an algebraic extension:}
  311. \begin{samepage}
  312. \begin{verbatim}
  313. load arnum;
  314. defpoly sqrt2**2 - 2;
  315. resultant(x + sqrt2,sqrt2 * x +1,x) -> -1
  316. \end{verbatim}
  317. \end{samepage}
  318. {\it or in a modular domain:}
  319. \begin{samepage}
  320. \begin{verbatim}
  321. setmod 17;
  322. on modular;
  323. resultant(2x+1,3x+4,x) -> 5
  324. \end{verbatim}
  325. \end{samepage}
  326. \section{DECOMPOSE Operator}\ttindex{DECOMPOSE}
  327. The {\tt DECOMPOSE} operator takes a multivariate polynomial as argument,
  328. and returns an expression and a list of equations from which the
  329. original polynomial can be found by composition. Its syntax is:
  330. \begin{verbatim}
  331. DECOMPOSE(EXPRN:polynomial):list.
  332. \end{verbatim}
  333. For example:
  334. \begin{verbatim}
  335. decompose(x^8-88*x^7+2924*x^6-43912*x^5+263431*x^4-
  336. 218900*x^3+65690*x^2-7700*x+234)
  337. 2 2 2
  338. -> {U + 35*U + 234, U=V + 10*V, V=X - 22*X}
  339. 2
  340. decompose(u^2+v^2+2u*v+1) -> {W + 1, W=U + V}
  341. \end{verbatim}
  342. Users should note however that, unlike factorization, this decomposition
  343. is not unique.
  344. \section{INTERPOL operator}\ttindex{INTERPOL}
  345. Syntax:
  346. \begin{verbatim}
  347. INTERPOL(<values>,<variable>,<points>);
  348. \end{verbatim}
  349. where {\tt <values>} and {\tt <points>} are lists of equal length and
  350. {\tt <variable>} is an algebraic expression (preferably a kernel).
  351. {\tt INTERPOL} generates an interpolation polynomial {\em f\/} in the given
  352. variable of degree length({\tt <values>})-1. The unique polynomial {\em f\/}
  353. is defined by the property that for corresponding elements {\em v\/} of
  354. {\tt <values>} and {\em p\/} of {\tt <points>} the relation $f(p)=v$ holds.
  355. The Aitken-Neville interpolation algorithm is used which guarantees a
  356. stable result even with rounded numbers and an ill-conditioned problem.
  357. \section{Obtaining Parts of Polynomials and Rationals}
  358. These operators select various parts of a polynomial or rational function
  359. structure. Except for the cost of rearrangement of the structure, these
  360. operations take very little time to perform.
  361. For those operators in this section that take a kernel {\tt VAR} as their
  362. second argument, an error results if the first expression is not a
  363. polynomial in {\tt VAR}, although the coefficients themselves can be
  364. rational as long as they do not depend on {\tt VAR}. However, if the
  365. switch {\tt RATARG}\ttindex{RATARG} is on, denominators are not checked
  366. for dependence on {\tt VAR}, and are taken to be part of the coefficients.
  367. \subsection{DEG Operator}\ttindex{DEG}
  368. This operator is used with the syntax
  369. \begin{verbatim}
  370. DEG(EXPRN:polynomial,VAR:kernel):integer.
  371. \end{verbatim}
  372. It returns the leading degree\index{Degree} of the polynomial {\tt EXPRN}
  373. in the variable {\tt VAR}. If {\tt VAR} does not occur as a variable in
  374. {\tt EXPRN}, 0 is returned.
  375. {\it Examples:}
  376. \begin{verbatim}
  377. deg((a+b)*(c+2*d)^2,a) -> 1
  378. deg((a+b)*(c+2*d)^2,d) -> 2
  379. deg((a+b)*(c+2*d)^2,e) -> 0.
  380. \end{verbatim}
  381. Note also that if {\tt RATARG} is on,
  382. \begin{verbatim}
  383. deg((a+b)^3/a,a) -> 3
  384. \end{verbatim}
  385. since in this case, the denominator {\tt A} is considered part of the
  386. coefficients of the numerator in {\tt A}. With {\tt RATARG} off, however,
  387. an error would result in this case.
  388. \subsection{DEN Operator}\ttindex{DEN}
  389. This is used with the syntax:
  390. \begin{verbatim}
  391. DEN(EXPRN:rational):polynomial.
  392. \end{verbatim}
  393. It returns the denominator of the rational expression {\tt EXPRN}. If
  394. {\tt EXPRN} is a polynomial, 1 is returned.
  395. {\it Examples:}
  396. \begin{verbatim}
  397. den(x/y^2) -> Y**2
  398. den(100/6) -> 3
  399. [since 100/6 is first simplified to 50/3]
  400. den(a/4+b/6) -> 12
  401. den(a+b) -> 1
  402. \end{verbatim}
  403. \subsection{LCOF Operator}\ttindex{LCOF}
  404. LCOF is used with the syntax
  405. \begin{verbatim}
  406. LCOF(EXPRN:polynomial,VAR:kernel):polynomial.
  407. \end{verbatim}
  408. It returns the leading coefficient\index{Leading coefficient} of the
  409. polynomial {\tt EXPRN} in the variable {\tt VAR}. If {\tt VAR} does not
  410. occur as a variable in {\tt EXPRN}, {\tt EXPRN} is returned.
  411. \extendedmanual{\newpage}
  412. {\it Examples:}
  413. \begin{verbatim}
  414. lcof((a+b)*(c+2*d)^2,a) -> C**2+4*C*D+4*D**2
  415. lcof((a+b)*(c+2*d)^2,d) -> 4*(A+B)
  416. lcof((a+b)*(c+2*d),e) -> A*C+2*A*D+B*C+2*B*D
  417. \end{verbatim}
  418. \subsection{LPOWER Operator}\ttindex{LPOWER}
  419. \begin{samepage}
  420. Syntax:
  421. \begin{verbatim}
  422. LPOWER(EXPRN:polynomial,VAR:kernel):polynomial.
  423. \end{verbatim}
  424. LPOWER returns the leading power of {\tt EXPRN} with respect to {\tt VAR}.
  425. If {\tt EXPRN} does not depend on {\tt VAR}, 1 is returned.
  426. \end{samepage}
  427. {\it Examples:}
  428. \begin{verbatim}
  429. lpower((a+b)*(c+2*d)^2,a) -> A
  430. lpower((a+b)*(c+2*d)^2,d) -> D**2
  431. lpower((a+b)*(c+2*d),e) -> 1
  432. \end{verbatim}
  433. \subsection{LTERM Operator}\ttindex{LTERM}
  434. \begin{samepage}
  435. Syntax:
  436. \begin{verbatim}
  437. LTERM(EXPRN:polynomial,VAR:kernel):polynomial.
  438. \end{verbatim}
  439. LTERM returns the leading term of {\tt EXPRN} with respect to {\tt VAR}.
  440. If {\tt EXPRN} does not depend on {\tt VAR}, {\tt EXPRN} is returned.
  441. \end{samepage}
  442. {\it Examples:}
  443. \begin{verbatim}
  444. lterm((a+b)*(c+2*d)^2,a) -> A*(C**2+4*C*D+4*D**2)
  445. lterm((a+b)*(c+2*d)^2,d) -> 4*D**2*(A+B)
  446. lterm((a+b)*(c+2*d),e) -> A*C+2*A*D+B*C+2*B*D
  447. \end{verbatim}
  448. {\COMPATNOTE} In some earlier versions of REDUCE, {\tt LTERM} returned
  449. {\tt 0} if the {\tt EXPRN} did not depend on {\tt VAR}. In the present
  450. version, {\tt EXPRN} is always equal to {\tt LTERM(EXPRN,VAR)} $+$ {\tt
  451. REDUCT(EXPRN,VAR)}.
  452. \subsection{MAINVAR Operator}\ttindex{MAINVAR}
  453. Syntax:
  454. \begin{verbatim}
  455. MAINVAR(EXPRN:polynomial):expression.
  456. \end{verbatim}
  457. Returns the main variable (based on the internal polynomial representation)
  458. of {\tt EXPRN}. If {\tt EXPRN} is a domain element, 0 is returned.
  459. {\it Examples:}
  460. Assuming {\tt A} has higher kernel order than {\tt B}, {\tt C}, or {\tt D}:
  461. \begin{verbatim}
  462. mainvar((a+b)*(c+2*d)^2) -> A
  463. mainvar(2) -> 0
  464. \end{verbatim}
  465. \subsection{NUM Operator}\ttindex{NUM}
  466. Syntax:
  467. \begin{verbatim}
  468. NUM(EXPRN:rational):polynomial.
  469. \end{verbatim}
  470. Returns the numerator of the rational expression {\tt EXPRN}. If {\tt EXPRN}
  471. is a polynomial, that polynomial is returned.
  472. {\it Examples:}
  473. \begin{verbatim}
  474. num(x/y^2) -> X
  475. num(100/6) -> 50
  476. num(a/4+b/6) -> 3*A+2*B
  477. num(a+b) -> A+B
  478. \end{verbatim}
  479. \subsection{REDUCT Operator}\ttindex{REDUCT}
  480. Syntax:
  481. \begin{verbatim}
  482. REDUCT(EXPRN:polynomial,VAR:kernel):polynomial.
  483. \end{verbatim}
  484. Returns the reductum of {\tt EXPRN} with respect to {\tt VAR} (i.e., the
  485. part of {\tt EXPRN} left after the leading term is removed). If {\tt
  486. EXPRN} does not depend on the variable {\tt VAR}, 0 is returned.
  487. {\it Examples:}
  488. \begin{verbatim}
  489. reduct((a+b)*(c+2*d),a) -> B*(C + 2*D)
  490. reduct((a+b)*(c+2*d),d) -> C*(A + B)
  491. reduct((a+b)*(c+2*d),e) -> 0
  492. \end{verbatim}
  493. {\COMPATNOTE} In some earlier versions of REDUCE, {\tt REDUCT} returned
  494. {\tt EXPRN} if it did not depend on {\tt VAR}. In the present version, {\tt
  495. EXPRN} is always equal to {\tt LTERM(EXPRN,VAR)} $+$ {\tt
  496. REDUCT(EXPRN,VAR)}.
  497. \section{Polynomial Coefficient Arithmetic}\index{Coefficient}
  498. {\REDUCE} allows for a variety of numerical domains for the numerical
  499. coefficients of polynomials used in calculations. The default mode is
  500. integer arithmetic, although the possibility of using real coefficients
  501. \index{Real coefficient} has been discussed elsewhere. Rational
  502. coefficients have also been available by using integer coefficients in
  503. both the numerator and denominator of an expression, using the {\tt ON
  504. DIV}\ttindex{DIV} option to print the coefficients as rationals.
  505. However, {\REDUCE} includes several other coefficient options in its basic
  506. version which we shall describe in this section. All such coefficient
  507. modes are supported in a table-driven manner so that it is
  508. straightforward to extend the range of possibilities. A description of
  509. how to do this is given in R.J. Bradford, A.C. Hearn, J.A. Padget and
  510. E. Schr\"ufer, ``Enlarging the {\REDUCE} Domain of Computation,'' Proc. of
  511. SYMSAC '86, ACM, New York (1986), 100--106.
  512. \subsection{Rational Coefficients in Polynomials}\index{Coefficient}
  513. \index{Rational coefficient}
  514. Instead of treating rational numbers as the numerator and denominator of a
  515. rational expression, it is also possible to use them as polynomial
  516. coefficients directly. This is accomplished by turning on the switch
  517. {\tt RATIONAL}.\ttindex{RATIONAL}
  518. {\it Example:} With {\tt RATIONAL} off, the input expression {\tt a/2}
  519. would be converted into a rational expression, whose numerator was {\tt A}
  520. and denominator 2. With {\tt RATIONAL} on, the same input would become a
  521. rational expression with numerator {\tt 1/2*A} and denominator {\tt 1}.
  522. Thus the latter can be used in operations that require polynomial input
  523. whereas the former could not.
  524. \subsection{Real Coefficients in Polynomials}\index{Coefficient}
  525. \index{Real coefficient}
  526. The switch {\tt ROUNDED}\ttindex{ROUNDED} permits the use of arbitrary
  527. sized real coefficients in polynomial expressions. The actual precision
  528. of these coefficients can be set by the operator {\tt PRECISION}.
  529. \ttindex{PRECISION} For example, {\tt precision 50;} sets the precision to
  530. fifty decimal digits. The default precision is system dependent and can
  531. be found by {\tt precision 0;}. In this mode, denominators are
  532. automatically made monic, and an appropriate adjustment is made to the
  533. numerator.
  534. {\it Example:} With {\tt ROUNDED} on, the input expression {\tt a/2} would
  535. be converted into a rational expression whose numerator is {\tt 0.5*A} and
  536. denominator {\tt 1}.
  537. Internally, {\REDUCE} uses floating point numbers up to the precision
  538. supported by the underlying machine hardware, and so-called {\em
  539. bigfloats} for higher precision or whenever necessary to represent numbers
  540. whose value cannot be represented in floating point. The internal
  541. precision is two decimal digits greater than the external precision to
  542. guard against roundoff inaccuracies. Bigfloats represent the fraction and
  543. exponent parts of a floating-point number by means of (arbitrary
  544. precision) integers, which is a more precise representation in many cases
  545. than the machine floating point arithmetic, but not as efficient. If a
  546. case arises where use of the machine arithmetic leads to problems, a user
  547. can force {\REDUCE} to use the bigfloat representation at all precisions by
  548. turning on the switch {\tt ROUNDBF}.\ttindex{ROUNDBF} In rare cases,
  549. this switch is turned on by the system, and the user informed by the
  550. message
  551. \begin{verbatim}
  552. ROUNDBF turned on to increase accuracy
  553. \end{verbatim}
  554. Rounded numbers are normally printed to the specified precision. However,
  555. if the user wishes to print such numbers with less precision, the printing
  556. precision can be set by the command {\tt PRINT\_PRECISION}.
  557. \ttindex{PRINT\_PRECISION} For example, {\tt print\_precision 5;} will
  558. cause such numbers to be printed with five digits maximum.
  559. Under normal circumstances when {\tt ROUNDED} is on, {\REDUCE} converts the
  560. number 1.0 to the integer 1. If this is not desired, the switch
  561. {\tt NOCONVERT}\ttindex{NOCONVERT} can be turned on.
  562. Numbers that are stored internally as bigfloats are normally printed with
  563. a space between every five digits to improve readability. If this
  564. feature is not required, it can be suppressed by turning off the switch
  565. {\tt BFSPACE}.\ttindex{BFSPACE}
  566. Further information on the bigfloat arithmetic may be found in T. Sasaki,
  567. ``Manual for Arbitrary Precision Real Arithmetic System in {\REDUCE}'',
  568. Department of Computer Science, University of Utah, Technical Note No.
  569. TR-8 (1979).
  570. When a real number is input, it is normally truncated to the precision in
  571. effect at the time the number is read. If it is desired to keep the full
  572. precision of all numbers input, the switch {\tt ADJPREC}\ttindex{ADJPREC}
  573. (for {\em adjust precision\/}) can be turned on. While on, {\tt ADJPREC}
  574. will automatically increase the precision, when necessary, to match that
  575. of any integer or real input, and a message printed to inform the user of
  576. the precision increase.
  577. When {\tt ROUNDED} is on, rational numbers are normally converted to
  578. rounded representation. However, if a user wishes to keep such numbers in
  579. a rational form until used in an operation that returns a real number,
  580. the switch {\tt ROUNDALL}\ttindex{ROUNDALL} can be turned off. This
  581. switch is normally on.
  582. Results from rounded calculations are returned in rounded form with two
  583. exceptions: if the result is recognized as {\tt 0} or {\tt 1} to the
  584. current precision, the integer result is returned.
  585. \subsection{Modular Number Coefficients in Polynomials}\index{Coefficient}
  586. \index{Modular coefficient}
  587. {\REDUCE} includes facilities for manipulating polynomials whose
  588. coefficients are computed modulo a given base. To use this option, two
  589. commands must be used; {\tt SETMOD} {\tt <integer>},\ttindex{SETMOD} to set
  590. the prime modulus, and {\tt ON MODULAR}\ttindex{MODULAR} to cause the
  591. actual modular calculations to occur.
  592. For example, with {\tt setmod 3;} and {\tt on modular;}, the polynomial
  593. {\tt (a+2*b)\verb|^|3} would become {\tt A\verb|^|3+2*B\verb|^|3}.
  594. The argument of {\tt SETMOD} is evaluated algebraically, except that
  595. non-modular (integer) arithmetic is used. Thus the sequence
  596. \begin{verbatim}
  597. setmod 3; on modular; setmod 7;
  598. \end{verbatim}
  599. will correctly set the modulus to 7.
  600. Modular numbers are by default represented by integers in the interval
  601. [0,p-1] where p is the current modulus. Sometimes it is more convenient
  602. to use an equivalent symmetric representation in the interval
  603. [-p/2+1,p/2], or more precisely
  604. [-floor((p-1)/2), ceiling((p-1)/2)],
  605. especially if the modular numbers map objects that include
  606. negative quantities. The switch {\tt BALANCED\_MOD}\ttindex{BALANCED\_MOD}
  607. allows you to select the symmetric representation for output.
  608. Users should note that the modular calculations are on the polynomial
  609. coefficients only. It is not currently possible to reduce the exponents
  610. since no check for a prime modulus is made (which would allow
  611. $x^{p-1}$ to be reduced to 1 mod p). Note also that any division by a
  612. number not co-prime with the modulus will result in the error ``Invalid
  613. modular division''.
  614. \subsection{Complex Number Coefficients in Polynomials}\index{Coefficient}
  615. \index{Complex coefficient}
  616. Although {\REDUCE} routinely treats the square of the variable {\em i\/} as
  617. equivalent to $-1$, this is not sufficient to reduce expressions involving
  618. {\em i\/} to lowest terms, or to factor such expressions over the complex
  619. numbers. For example, in the default case,
  620. \begin{verbatim}
  621. factorize(a^2+1);
  622. \end{verbatim}
  623. gives the result
  624. \begin{verbatim}
  625. {{A**2+1,1}}
  626. \end{verbatim}
  627. and
  628. \begin{verbatim}
  629. (a^2+b^2)/(a+i*b)
  630. \end{verbatim}
  631. is not reduced further. However, if the switch
  632. {\tt COMPLEX}\ttindex{COMPLEX} is turned on, full complex arithmetic is then
  633. carried out. In other words, the above factorization will give the result
  634. \begin{verbatim}
  635. {{A + I,1},{A - I,1}}
  636. \end{verbatim}
  637. and the quotient will be reduced to {\tt A-I*B}.
  638. The switch {\tt COMPLEX} may be combined with {\tt ROUNDED} to give complex
  639. real numbers; the appropriate arithmetic is performed in this case.
  640. Complex conjugation is used to remove complex numbers from denominators of
  641. expressions. To do this if {\tt COMPLEX} is off, you must turn the switch
  642. {\tt RATIONALIZE}\ttindex{RATIONALIZE} on.