ROOTS.TEX 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. \documentstyle[11pt,reduce]{article}
  2. \title{The REDUCE Root Finding Package \\ Mod 1.94, 28 May 1993}
  3. \date{}
  4. \author {Stanley L. Kameny \\ E-mail: valley!stan@rand.org}
  5. \begin{document}
  6. \maketitle
  7. \index{root finding} \index{ROOTS package}
  8. \section{Introduction}
  9. The root finding package is designed so that it can be used as an
  10. independent package, or it can be integrated with and called by {\tt
  11. SOLVE}. \index{SOLVE package ! with ROOTS package} This document describes
  12. the package in its independent use. It can be used to find some or all of
  13. the roots of univariate polynomials with real or complex coefficients, to
  14. the accuracy specified by the user.
  15. \section{Root Finding Strategies}
  16. For all polynomials handled by the root finding package, strategies of
  17. factoring are employed where possible to reduce the amount of required
  18. work. These include square-free factoring and separation of complex
  19. polynomials into a product of a polynomial with real coefficients and one
  20. with complex coefficients. Whenever these succeed, the resulting smaller
  21. polynomials are solved separately, except that the root accuracy takes
  22. into account the possibility of close roots on different branches. One
  23. other strategy used where applicable is the powergcd method of reducing
  24. the powers of the initial polynomial by a common factor, and deriving the
  25. roots in two stages, as roots of the reduced power polynomial. Again
  26. here, the possibility of close roots on different branches is taken into
  27. account.
  28. \section{Top Level Functions}
  29. The top level functions can be called either as symbolic operators from
  30. algebraic mode, or they can be called directly from symbolic mode with
  31. symbolic mode arguments. Outputs are expressed in forms that print out
  32. correctly in algebraic mode.
  33. \subsection{Functions that refer to real roots only}
  34. Three top level functions refer only to real roots. Each of these
  35. functions can receive 1, 2 or 3 arguments.
  36. The first argument is the polynomial p, that can be complex and can
  37. have multiple or zero roots. If arg2 and arg3 are not present, all real
  38. roots are found. If the additional arguments are present, they restrict
  39. the region of consideration.
  40. \begin{itemize}
  41. \item If arguments are (p,arg2) then
  42. Arg2 must be POSITIVE or NEGATIVE. If arg2=NEGATIVE then only
  43. negative roots of p are included; if arg2=POSITIVE then only positive
  44. roots of p are included. Zero roots are excluded.
  45. \item If arguments are (p,arg2,arg3) then
  46. \ttindex{EXCLUDE} \ttindex{POSITIVE} \ttindex{NEGATIVE} \ttindex{INFINITY}
  47. Arg2 and Arg3 must be r (a real number) or EXCLUDE r, or a member of
  48. the list POSITIVE, NEGATIVE, INFINITY, -INFINITY. EXCLUDE r causes the
  49. value r to be excluded from the region. The order of the sequence
  50. arg2, arg3 is unimportant. Assuming that arg2 $\leq$ arg3 when both are
  51. numeric, then
  52. \begin{tabular}{l c l}
  53. \{-INFINITY,INFINITY\} & is equivalent to & \{\} represents all roots; \\
  54. \{arg2,NEGATIVE\} & represents & $-\infty < r < arg2$; \\
  55. \{arg2,POSITIVE\} & represents & $arg2 < r < \infty$;
  56. \end{tabular}
  57. In each of the following, replacing an {\em arg} with EXCLUDE {\em arg}
  58. converts the corresponding inclusive $\leq$ to the exclusive $<$
  59. \begin{tabular}{l c l}
  60. \{arg2,-INFINITY\} & represents & $-\infty < r \leq arg2$; \\
  61. \{arg2,INFINITY\} & represents & $arg2 \leq r < \infty$; \\
  62. \{arg2,arg3\} & represents & $arg2 \leq r \leq arg3$;
  63. \end{tabular}
  64. \item If zero is in the interval the zero root is included.
  65. \end{itemize}
  66. \begin{description}
  67. \ttindex{REALROOTS} \index{Sturm Sequences}
  68. \item[REALROOTS] This function finds the real roots of the polynomial p,
  69. using the REALROOT package to isolate real roots by the method of Sturm
  70. sequences, then polishing the root to the desired accuracy. Precision
  71. of computation is guaranteed to be sufficient to separate all real roots
  72. in the specified region. (cf. MULTIROOT for treatment of multiple
  73. roots.)
  74. \ttindex{ISOLATER}
  75. \item[ISOLATER] This function produces a list of rational intervals, each
  76. containing a single real root of the polynomial p, within the specified
  77. region, but does not find the roots.
  78. \ttindex{RLROOTNO}
  79. \item[RLROOTNO] This function computes the number of real roots of p in
  80. the specified region, but does not find the roots.
  81. \end{description}
  82. \subsection{Functions that return both real and complex roots}
  83. \begin{description}
  84. \ttindex{ROOTS}
  85. \item[ROOTS p;] This is the main top level function of the roots package.
  86. It will find all roots, real and complex, of the polynomial p to an
  87. accuracy that is sufficient to separate them and which is a minimum of 6
  88. decimal places. The value returned by ROOTS is a
  89. list of equations for all roots. In addition, ROOTS stores separate lists
  90. of real roots and complex roots in the global variables ROOTSREAL and
  91. ROOTSCOMPLEX. \ttindex{ROOTSREAL} \ttindex{ROOTSCOMPLEX}
  92. The order of root discovery by ROOTS is highly variable from system to
  93. system, depending upon very subtle arithmetic differences during the
  94. computation. In order to make it easier to compare results obtained on
  95. different computers, the output of ROOTS is sorted into a standard order:
  96. a root with smaller real part precedes a root with larger real part; roots
  97. with identical real parts are sorted so that larger imaginary part
  98. precedes smaller imaginary part. (This is done so that for complex pairs,
  99. the positive imaginary part is seen first.)
  100. However, when a polynomial has been factored (by square-free factoring or
  101. by separation into real and complex factors) then the root sorting is
  102. applied to each factor separately. This makes the final resulting order
  103. less obvious. However it is consistent from system to system.
  104. \ttindex{ROOTS\_AT\_PREC}
  105. \item[ROOTS\_AT\_PREC p;] Same as ROOTS except that roots values are
  106. returned to a minimum of the number of decimal places equal to the current
  107. system precision.
  108. \ttindex{ROOT\_VAL}
  109. \item[ROOT\_VAL p;] Same as ROOTS\_AT\_PREC, except that instead of
  110. returning a list of equations for the roots, a list of the root value is
  111. returned. This is the function that SOLVE calls.
  112. \ttindex{NEARESTROOT}
  113. \item[NEARESTROOT(p,s);] This top level function uses an iterative method
  114. to find the root to which the method converges given the initial starting
  115. origin s, which can be complex. If there are several roots in the
  116. vicinity of s and s is not significantly closer to one root than it is to
  117. all others, the convergence could arrive at a root that is not truly the
  118. nearest root. This function should therefore be used only when the user
  119. is certain that there is only one root in the immediate vicinity of the
  120. starting point s.
  121. \ttindex{FIRSTROOT}
  122. \item[FIRSTROOT p;] ROOTS is called, but only the first root determined by
  123. ROOTS is computed. Note that this is not in general the first root that
  124. would be listed in ROOTS output, since the ROOTS outputs are sorted into
  125. a canonical order. Also, in some difficult root finding cases, the first
  126. root computed might be incorrect.
  127. \end{description}
  128. \subsection{Other top level functions}
  129. \begin{description}
  130. \ttindex{GETROOT} \ttindex{ROOTS} \ttindex{REALROOTS} \ttindex{NEARESTROOTS}
  131. \item[GETROOT(n,rr);] If rr has the form of the output of ROOTS, REALROOTS,
  132. or NEARESTROOTS; GETROOT returns the rational, real, or complex value of
  133. the root equation. An error occurs if $n<1$ or $n>$ the number of roots in
  134. rr.
  135. \ttindex{MKPOLY}
  136. \item[MKPOLY rr;] This function can be used to reconstruct a polynomial
  137. whose root equation list is rr and whose denominator is 1. Thus one can
  138. verify that if $rr := ROOTS~p$, and $rr1 := ROOTS~MKPOLY~rr$, then
  139. $rr1 = rr$. (This will be true if {\tt MULTIROOT} and {\tt RATROOT} are ON,
  140. and {\tt ROUNDED} is off.)
  141. However, $MKPOLY~rr - NUM~p = 0$ will be true if and only if all roots of p
  142. have been computed exactly.
  143. \end{description}
  144. \subsection{Functions available for diagnostic or instructional use only}
  145. \begin{description}
  146. \ttindex{GFNEWT}
  147. \item[GFNEWT(p,r,cpx);] This function will do a single pass through the
  148. function GFNEWTON for polynomial p and root r. If cpx=T, then any
  149. complex part of the root will be kept, no matter how small.
  150. \ttindex{GFROOT}
  151. \item[GFROOT(p,r,cpx);] This function will do a single pass through the
  152. function GFROOTFIND for polynomial p and root r. If cpx=T, then any
  153. complex part of the root will be kept, no matter how small.
  154. \end{description}
  155. \section{Switches Used in Input}
  156. The input of polynomials in algebraic mode is sensitive to the switches
  157. {\tt COMPLEX}, {\tt ROUNDED}, and {\tt ADJPREC}. The correct choice of
  158. input method is important since incorrect choices will result in
  159. undesirable truncation or rounding of the input coefficients.
  160. Truncation or rounding may occur if {\tt ROUNDED} is on and
  161. one of the following is true:
  162. \begin{enumerate}
  163. \item a coefficient is entered in floating point form or rational form.
  164. \item {\tt COMPLEX} is on and a coefficient is imaginary or complex.
  165. \end{enumerate}
  166. Therefore, to avoid undesirable truncation or rounding, then:
  167. \begin{enumerate}
  168. \item {\tt ROUNDED} should be off and input should be
  169. in integer or rational form; or
  170. \item {\tt ROUNDED} can be on if it is acceptable to truncate or round
  171. input to the current value of system precision; or both {\tt ROUNDED} and
  172. {\tt ADJPREC} can be on, in which case system precision will be adjusted
  173. to accommodate the largest coefficient which is input; or \item if the
  174. input contains complex coefficients with very different magnitude for the
  175. real and imaginary parts, then all three switches {\tt ROUNDED}, {\tt
  176. ADJPREC} and {\tt COMPLEX} must be on.
  177. \end{enumerate}
  178. \begin{description}
  179. \item[integer and complex modes] (off {\tt ROUNDED}) any real
  180. polynomial can be input using integer coefficients of any size; integer or
  181. rational coefficients can be used to input any real or complex polynomial,
  182. independent of the setting of the switch {\tt COMPLEX}. These are the most
  183. versatile input modes, since any real or complex polynomial can be input
  184. exactly.
  185. \item[modes rounded and complex-rounded] (on {\tt ROUNDED}) polynomials can be
  186. input using
  187. integer coefficients of any size. Floating point coefficients will be
  188. truncated or rounded, to a size dependent upon the system. If complex
  189. is on, real coefficients can be input to any precision using integer
  190. form, but coefficients of imaginary parts of complex coefficients will
  191. be rounded or truncated.
  192. \end{description}
  193. \section{Internal and Output Use of Switches}
  194. The REDUCE arithmetic mode switches {\tt ROUNDED} and {\tt COMPLEX}
  195. control the behavior of the root finding package.
  196. These switches are returned in the same state in which they were set
  197. initially, (barring catastrophic error).
  198. \begin{description}
  199. \ttindex{COMPLEX}
  200. \item[COMPLEX] The root finding package controls the switch {\tt COMPLEX}
  201. internally, turning the switch on if it is processing a complex
  202. polynomial.
  203. For a polynomial with real coefficients, the
  204. \ttindex{NEARESTROOT}
  205. starting point argument for NEARESTROOT can be given in algebraic mode in
  206. complex form as rl + im * I and will be handled correctly, independent of
  207. the setting of the switch {\tt COMPLEX.} Complex roots will be computed
  208. and printed correctly regardless of the setting of the switch {\tt
  209. COMPLEX}. However, if {\tt COMPLEX} is off, the imaginary part will print
  210. out ahead of the real part, while the reverse order will be obtained if
  211. COMPLEX is on.
  212. \ttindex{ROUNDED}
  213. \item[ROUNDED] The
  214. root finding package performs computations using the arithmetic mode that
  215. is required at the time, which may be integer, Gaussian integer, rounded,
  216. or complex rounded. The switch {\tt BFTAG} is used internally to govern
  217. the mode of computation and precision is adjusted whenever necessary. The
  218. initial position of switches {\tt ROUNDED} and {\tt COMPLEX} are ignored.
  219. At output, these switches will emerge in their initial positions.
  220. \end{description}
  221. \section{Root Package Switches}
  222. Note: switches {\tt AUTOMODE}, {\tt ISOROOT} and {\tt ACCROOT}, present in
  223. earlier versions, have been eliminated.
  224. \begin{description}
  225. \ttindex{RATROOT}
  226. \item[RATROOT] (Default OFF) If {\tt RATROOT} is on all root equations are
  227. output in rational form. Assuming that the mode is {\tt COMPLEX} (i.e.
  228. {\tt ROUNDED} is off,) the root equations are
  229. guaranteed to be able to be input into REDUCE without truncation or
  230. rounding errors. (Cf. the function MKPOLY described above.)
  231. \ttindex{MULTIROOT}
  232. \item[MULTIROOT] (Default ON) Whenever the polynomial has complex
  233. coefficients or has real coefficients and has multiple roots, as
  234. \ttindex{SQFRF} determined by the Sturm function, the function {\tt SQFRF}
  235. is called automatically to factor the polynomial into square-free factors.
  236. If {\tt MULTIROOT} is on, the multiplicity of the roots will be indicated
  237. in the output of ROOTS or REALROOTS by printing the root output
  238. repeatedly, according to its multiplicity. If {\tt MULTIROOT} is off,
  239. each root will be printed once, and all roots should be normally be
  240. distinct. (Two identical roots should not appear. If the initial
  241. precision of the computation or the accuracy of the output was
  242. insufficient to separate two closely-spaced roots, the program attempts to
  243. increase accuracy and/or precision if it detects equal roots. If,
  244. however, the initial accuracy specified was too low, and it was not
  245. possible to separate the roots, the program will abort.)
  246. \index{tracing ! ROOTS package}
  247. \ttindex{TRROOT}
  248. \item[TRROOT] (Default OFF) If switch {\tt TRROOT} is on, trace messages
  249. are printed out during the course of root determination, to show the
  250. progress of solution.
  251. \ttindex{ROOTMSG} \item[ROOTMSG] (Default OFF) If switch
  252. {\tt ROOTMSG} is on in addition to switch {\tt TRROOT,} additional
  253. messages are printed out to aid in following the progress of Laguerre and
  254. Newton complex iteration. These messages are intended for debugging use
  255. primarily.
  256. \end{description}
  257. \section{Operational Parameters and Parameter Setting.}
  258. \begin{description}
  259. \ttindex{ROOTACC\#}
  260. \item[ROOTACC\#] (Default 6) This parameter can be set using the function
  261. ROOTACC n; which causes {\tt ROOTACC\#} to be set to MAX(n,6). If {\tt
  262. ACCROOT} is on, roots will be determined to a minimum of {\tt ROOT\-ACC\#}
  263. significant places. (If roots are closely spaced, a higher number of
  264. significant places is computed where needed.)
  265. \ttindex{system precision}
  266. \item[system precision] The roots package, during its operation, will
  267. change the value of system precision but will restore the original value
  268. of system precision at termination except that the value of system
  269. precision is increased if necessary to allow the full roots output to be
  270. printed.
  271. \ttindex{PRECISION}
  272. \item[PRECISION n;] If the user sets system precision, using the command
  273. PRECISION n; then the effect is to increase the system precision to n, and
  274. to have the same effect on ROOTS as ROOTACC n; ie. roots will now be
  275. printed with minimum accuracy n. The original conditions can then be
  276. restored by using the command PRECISION RESET; or PRECISION NIL;.
  277. \ttindex{ROOTPREC}
  278. \item[ROOTPREC n;] The roots package normally sets the computation mode and
  279. precision automatically. However, if ROOTPREC n; is
  280. called and $n$ is greater than the initial system precision then all root
  281. computation will be done initially using a minimum system precision n.
  282. Automatic operation can be restored by input of ROOTPREC 0;.
  283. \end{description}
  284. \section{Avoiding truncation of polynomials on input}
  285. The roots package will not internally truncate polynomials. However, it
  286. is possible that a polynomial can be truncated by input reading functions
  287. of the embedding lisp system, particularly when input is given in floating
  288. point (rounded) format.
  289. To avoid any difficulties, input can be done in integer or Gaussian
  290. integer format, or mixed, with integers or rationals used to represent
  291. quantities of high precision. There are many examples of this in the
  292. test package. It is usually best to let the roots package
  293. determine the precision needed to compute roots.
  294. The number of digits that can be safely represented in floating point in
  295. the lisp system are contained in the global variable {\tt !!NFPD}.
  296. Similarly, the maximum number of significant figures in floating point
  297. output are contained in the global variable {\tt !!FLIM}. The roots
  298. package computes these values, which are needed to control the logic of
  299. the program. \ttindex{"!"!FLIM} \ttindex{"!"!NFPD}
  300. The values of intermediate root iterations (that are printed when {\tt
  301. TRROOT} is on) are given in bigfloat format even when the actual values
  302. are computed in floating point. This avoids intrusive rounding of root
  303. printout.
  304. \end{document}