You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

323 lines
11 KiB

25 years ago
  1. <HTML>
  2. <HEAD>
  3. <!-- Created by texi2html 1.56k from cln.texi on 14 January 2000 -->
  4. <TITLE>CLN, a Class Library for Numbers - 9. Univariate polynomials</TITLE>
  5. </HEAD>
  6. <BODY>
  7. Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_8.html">previous</A>, <A HREF="cln_10.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>.
  8. <P><HR><P>
  9. <H1><A NAME="SEC54" HREF="cln_toc.html#TOC54">9. Univariate polynomials</A></H1>
  10. <H2><A NAME="SEC55" HREF="cln_toc.html#TOC55">9.1 Univariate polynomial rings</A></H2>
  11. <P>
  12. CLN implements univariate polynomials (polynomials in one variable) over an
  13. arbitrary ring. The indeterminate variable may be either unnamed (and will be
  14. printed according to <CODE>cl_default_print_flags.univpoly_varname</CODE>, which
  15. defaults to <SAMP>`x'</SAMP>) or carry a given name. The base ring and the
  16. indeterminate are explicitly part of every polynomial. CLN doesn't allow you to
  17. (accidentally) mix elements of different polynomial rings, e.g.
  18. <CODE>(a^2+1) * (b^3-1)</CODE> will result in a runtime error. (Ideally this should
  19. return a multivariate polynomial, but they are not yet implemented in CLN.)
  20. <P>
  21. The classes of univariate polynomial rings are
  22. <PRE>
  23. Ring
  24. cl_ring
  25. &#60;cl_ring.h&#62;
  26. |
  27. |
  28. Univariate polynomial ring
  29. cl_univpoly_ring
  30. &#60;cl_univpoly.h&#62;
  31. |
  32. +----------------+-------------------+
  33. | | |
  34. Complex polynomial ring | Modular integer polynomial ring
  35. cl_univpoly_complex_ring | cl_univpoly_modint_ring
  36. &#60;cl_univpoly_complex.h&#62; | &#60;cl_univpoly_modint.h&#62;
  37. |
  38. +----------------+
  39. | |
  40. Real polynomial ring |
  41. cl_univpoly_real_ring |
  42. &#60;cl_univpoly_real.h&#62; |
  43. |
  44. +----------------+
  45. | |
  46. Rational polynomial ring |
  47. cl_univpoly_rational_ring |
  48. &#60;cl_univpoly_rational.h&#62; |
  49. |
  50. +----------------+
  51. |
  52. Integer polynomial ring
  53. cl_univpoly_integer_ring
  54. &#60;cl_univpoly_integer.h&#62;
  55. </PRE>
  56. <P>
  57. and the corresponding classes of univariate polynomials are
  58. <PRE>
  59. Univariate polynomial
  60. cl_UP
  61. &#60;cl_univpoly.h&#62;
  62. |
  63. +----------------+-------------------+
  64. | | |
  65. Complex polynomial | Modular integer polynomial
  66. cl_UP_N | cl_UP_MI
  67. &#60;cl_univpoly_complex.h&#62; | &#60;cl_univpoly_modint.h&#62;
  68. |
  69. +----------------+
  70. | |
  71. Real polynomial |
  72. cl_UP_R |
  73. &#60;cl_univpoly_real.h&#62; |
  74. |
  75. +----------------+
  76. | |
  77. Rational polynomial |
  78. cl_UP_RA |
  79. &#60;cl_univpoly_rational.h&#62; |
  80. |
  81. +----------------+
  82. |
  83. Integer polynomial
  84. cl_UP_I
  85. &#60;cl_univpoly_integer.h&#62;
  86. </PRE>
  87. <P>
  88. Univariate polynomial rings are constructed using the functions
  89. <DL COMPACT>
  90. <DT><CODE>cl_univpoly_ring cl_find_univpoly_ring (const cl_ring&#38; R)</CODE>
  91. <DD>
  92. <DT><CODE>cl_univpoly_ring cl_find_univpoly_ring (const cl_ring&#38; R, const cl_symbol&#38; varname)</CODE>
  93. <DD>
  94. This function returns the polynomial ring <SAMP>`R[X]'</SAMP>, unnamed or named.
  95. <CODE>R</CODE> may be an arbitrary ring. This function takes care of finding out
  96. about special cases of <CODE>R</CODE>, such as the rings of complex numbers,
  97. real numbers, rational numbers, integers, or modular integer rings.
  98. There is a cache table of rings, indexed by <CODE>R</CODE> and <CODE>varname</CODE>.
  99. This ensures that two calls of this function with the same arguments will
  100. return the same polynomial ring.
  101. <DT><CODE>cl_univpoly_complex_ring cl_find_univpoly_ring (const cl_complex_ring&#38; R)</CODE>
  102. <DD>
  103. <DT><CODE>cl_univpoly_complex_ring cl_find_univpoly_ring (const cl_complex_ring&#38; R, const cl_symbol&#38; varname)</CODE>
  104. <DD>
  105. <DT><CODE>cl_univpoly_real_ring cl_find_univpoly_ring (const cl_real_ring&#38; R)</CODE>
  106. <DD>
  107. <DT><CODE>cl_univpoly_real_ring cl_find_univpoly_ring (const cl_real_ring&#38; R, const cl_symbol&#38; varname)</CODE>
  108. <DD>
  109. <DT><CODE>cl_univpoly_rational_ring cl_find_univpoly_ring (const cl_rational_ring&#38; R)</CODE>
  110. <DD>
  111. <DT><CODE>cl_univpoly_rational_ring cl_find_univpoly_ring (const cl_rational_ring&#38; R, const cl_symbol&#38; varname)</CODE>
  112. <DD>
  113. <DT><CODE>cl_univpoly_integer_ring cl_find_univpoly_ring (const cl_integer_ring&#38; R)</CODE>
  114. <DD>
  115. <DT><CODE>cl_univpoly_integer_ring cl_find_univpoly_ring (const cl_integer_ring&#38; R, const cl_symbol&#38; varname)</CODE>
  116. <DD>
  117. <DT><CODE>cl_univpoly_modint_ring cl_find_univpoly_ring (const cl_modint_ring&#38; R)</CODE>
  118. <DD>
  119. <DT><CODE>cl_univpoly_modint_ring cl_find_univpoly_ring (const cl_modint_ring&#38; R, const cl_symbol&#38; varname)</CODE>
  120. <DD>
  121. These functions are equivalent to the general <CODE>cl_find_univpoly_ring</CODE>,
  122. only the return type is more specific, according to the base ring's type.
  123. </DL>
  124. <H2><A NAME="SEC56" HREF="cln_toc.html#TOC56">9.2 Functions on univariate polynomials</A></H2>
  125. <P>
  126. Given a univariate polynomial ring <CODE>R</CODE>, the following members can be used.
  127. <DL COMPACT>
  128. <DT><CODE>cl_ring R-&#62;basering()</CODE>
  129. <DD>
  130. This returns the base ring, as passed to <SAMP>`cl_find_univpoly_ring'</SAMP>.
  131. <DT><CODE>cl_UP R-&#62;zero()</CODE>
  132. <DD>
  133. This returns <CODE>0 in R</CODE>, a polynomial of degree -1.
  134. <DT><CODE>cl_UP R-&#62;one()</CODE>
  135. <DD>
  136. This returns <CODE>1 in R</CODE>, a polynomial of degree &#60;= 0.
  137. <DT><CODE>cl_UP R-&#62;canonhom (const cl_I&#38; x)</CODE>
  138. <DD>
  139. This returns <CODE>x in R</CODE>, a polynomial of degree &#60;= 0.
  140. <DT><CODE>cl_UP R-&#62;monomial (const cl_ring_element&#38; x, uintL e)</CODE>
  141. <DD>
  142. This returns a sparse polynomial: <CODE>x * X^e</CODE>, where <CODE>X</CODE> is the
  143. indeterminate.
  144. <DT><CODE>cl_UP R-&#62;create (sintL degree)</CODE>
  145. <DD>
  146. Creates a new polynomial with a given degree. The zero polynomial has degree
  147. <CODE>-1</CODE>. After creating the polynomial, you should put in the coefficients,
  148. using the <CODE>set_coeff</CODE> member function, and then call the <CODE>finalize</CODE>
  149. member function.
  150. </DL>
  151. <P>
  152. The following are the only destructive operations on univariate polynomials.
  153. <DL COMPACT>
  154. <DT><CODE>void set_coeff (cl_UP&#38; x, uintL index, const cl_ring_element&#38; y)</CODE>
  155. <DD>
  156. This changes the coefficient of <CODE>X^index</CODE> in <CODE>x</CODE> to be <CODE>y</CODE>.
  157. After changing a polynomial and before applying any "normal" operation on it,
  158. you should call its <CODE>finalize</CODE> member function.
  159. <DT><CODE>void finalize (cl_UP&#38; x)</CODE>
  160. <DD>
  161. This function marks the endpoint of destructive modifications of a polynomial.
  162. It normalizes the internal representation so that subsequent computations have
  163. less overhead. Doing normal computations on unnormalized polynomials may
  164. produce wrong results or crash the program.
  165. </DL>
  166. <P>
  167. The following operations are defined on univariate polynomials.
  168. <DL COMPACT>
  169. <DT><CODE>cl_univpoly_ring x.ring ()</CODE>
  170. <DD>
  171. Returns the ring to which the univariate polynomial <CODE>x</CODE> belongs.
  172. <DT><CODE>cl_UP operator+ (const cl_UP&#38;, const cl_UP&#38;)</CODE>
  173. <DD>
  174. Returns the sum of two univariate polynomials.
  175. <DT><CODE>cl_UP operator- (const cl_UP&#38;, const cl_UP&#38;)</CODE>
  176. <DD>
  177. Returns the difference of two univariate polynomials.
  178. <DT><CODE>cl_UP operator- (const cl_UP&#38;)</CODE>
  179. <DD>
  180. Returns the negative of a univariate polynomial.
  181. <DT><CODE>cl_UP operator* (const cl_UP&#38;, const cl_UP&#38;)</CODE>
  182. <DD>
  183. Returns the product of two univariate polynomials. One of the arguments may
  184. also be a plain integer or an element of the base ring.
  185. <DT><CODE>cl_UP square (const cl_UP&#38;)</CODE>
  186. <DD>
  187. Returns the square of a univariate polynomial.
  188. <DT><CODE>cl_UP expt_pos (const cl_UP&#38; x, const cl_I&#38; y)</CODE>
  189. <DD>
  190. <CODE>y</CODE> must be &#62; 0. Returns <CODE>x^y</CODE>.
  191. <DT><CODE>bool operator== (const cl_UP&#38;, const cl_UP&#38;)</CODE>
  192. <DD>
  193. <DT><CODE>bool operator!= (const cl_UP&#38;, const cl_UP&#38;)</CODE>
  194. <DD>
  195. Compares two univariate polynomials, belonging to the same univariate
  196. polynomial ring, for equality.
  197. <DT><CODE>cl_boolean zerop (const cl_UP&#38; x)</CODE>
  198. <DD>
  199. Returns true if <CODE>x</CODE> is <CODE>0 in R</CODE>.
  200. <DT><CODE>sintL degree (const cl_UP&#38; x)</CODE>
  201. <DD>
  202. Returns the degree of the polynomial. The zero polynomial has degree <CODE>-1</CODE>.
  203. <DT><CODE>cl_ring_element coeff (const cl_UP&#38; x, uintL index)</CODE>
  204. <DD>
  205. Returns the coefficient of <CODE>X^index</CODE> in the polynomial <CODE>x</CODE>.
  206. <DT><CODE>cl_ring_element x (const cl_ring_element&#38; y)</CODE>
  207. <DD>
  208. Evaluation: If <CODE>x</CODE> is a polynomial and <CODE>y</CODE> belongs to the base ring,
  209. then <SAMP>`x(y)'</SAMP> returns the value of the substitution of <CODE>y</CODE> into
  210. <CODE>x</CODE>.
  211. <DT><CODE>cl_UP deriv (const cl_UP&#38; x)</CODE>
  212. <DD>
  213. Returns the derivative of the polynomial <CODE>x</CODE> with respect to the
  214. indeterminate <CODE>X</CODE>.
  215. </DL>
  216. <P>
  217. The following output functions are defined (see also the chapter on
  218. input/output).
  219. <DL COMPACT>
  220. <DT><CODE>void fprint (cl_ostream stream, const cl_UP&#38; x)</CODE>
  221. <DD>
  222. <DT><CODE>cl_ostream operator&#60;&#60; (cl_ostream stream, const cl_UP&#38; x)</CODE>
  223. <DD>
  224. Prints the univariate polynomial <CODE>x</CODE> on the <CODE>stream</CODE>. The output may
  225. depend on the global printer settings in the variable
  226. <CODE>cl_default_print_flags</CODE>.
  227. </DL>
  228. <H2><A NAME="SEC57" HREF="cln_toc.html#TOC57">9.3 Special polynomials</A></H2>
  229. <P>
  230. The following functions return special polynomials.
  231. <DL COMPACT>
  232. <DT><CODE>cl_UP_I cl_tschebychev (sintL n)</CODE>
  233. <DD>
  234. Returns the n-th Tchebychev polynomial (n &#62;= 0).
  235. <DT><CODE>cl_UP_I cl_hermite (sintL n)</CODE>
  236. <DD>
  237. Returns the n-th Hermite polynomial (n &#62;= 0).
  238. <DT><CODE>cl_UP_RA cl_legendre (sintL n)</CODE>
  239. <DD>
  240. Returns the n-th Legendre polynomial (n &#62;= 0).
  241. <DT><CODE>cl_UP_I cl_laguerre (sintL n)</CODE>
  242. <DD>
  243. Returns the n-th Laguerre polynomial (n &#62;= 0).
  244. </DL>
  245. <P>
  246. Information how to derive the differential equation satisfied by each
  247. of these polynomials from their definition can be found in the
  248. <CODE>doc/polynomial/</CODE> directory.
  249. <P><HR><P>
  250. Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_8.html">previous</A>, <A HREF="cln_10.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>.
  251. </BODY>
  252. </HTML>