3 <!-- Created by texi2html 1.56k from cln.texi on 14 January 2000 -->
5 <TITLE>CLN, a Class Library for Numbers - 9. Univariate polynomials</TITLE>
8 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>.
12 <H1><A NAME="SEC54" HREF="cln_toc.html#TOC54">9. Univariate polynomials</A></H1>
16 <H2><A NAME="SEC55" HREF="cln_toc.html#TOC55">9.1 Univariate polynomial rings</A></H2>
19 CLN implements univariate polynomials (polynomials in one variable) over an
20 arbitrary ring. The indeterminate variable may be either unnamed (and will be
21 printed according to <CODE>cl_default_print_flags.univpoly_varname</CODE>, which
22 defaults to <SAMP>`x'</SAMP>) or carry a given name. The base ring and the
23 indeterminate are explicitly part of every polynomial. CLN doesn't allow you to
24 (accidentally) mix elements of different polynomial rings, e.g.
25 <CODE>(a^2+1) * (b^3-1)</CODE> will result in a runtime error. (Ideally this should
26 return a multivariate polynomial, but they are not yet implemented in CLN.)
30 The classes of univariate polynomial rings are
40 Univariate polynomial ring
42 <cl_univpoly.h>
44 +----------------+-------------------+
46 Complex polynomial ring | Modular integer polynomial ring
47 cl_univpoly_complex_ring | cl_univpoly_modint_ring
48 <cl_univpoly_complex.h> | <cl_univpoly_modint.h>
52 Real polynomial ring |
53 cl_univpoly_real_ring |
54 <cl_univpoly_real.h> |
58 Rational polynomial ring |
59 cl_univpoly_rational_ring |
60 <cl_univpoly_rational.h> |
64 Integer polynomial ring
65 cl_univpoly_integer_ring
66 <cl_univpoly_integer.h>
70 and the corresponding classes of univariate polynomials are
77 <cl_univpoly.h>
79 +----------------+-------------------+
81 Complex polynomial | Modular integer polynomial
83 <cl_univpoly_complex.h> | <cl_univpoly_modint.h>
89 <cl_univpoly_real.h> |
95 <cl_univpoly_rational.h> |
101 <cl_univpoly_integer.h>
105 Univariate polynomial rings are constructed using the functions
110 <DT><CODE>cl_univpoly_ring cl_find_univpoly_ring (const cl_ring& R)</CODE>
112 <DT><CODE>cl_univpoly_ring cl_find_univpoly_ring (const cl_ring& R, const cl_symbol& varname)</CODE>
114 This function returns the polynomial ring <SAMP>`R[X]'</SAMP>, unnamed or named.
115 <CODE>R</CODE> may be an arbitrary ring. This function takes care of finding out
116 about special cases of <CODE>R</CODE>, such as the rings of complex numbers,
117 real numbers, rational numbers, integers, or modular integer rings.
118 There is a cache table of rings, indexed by <CODE>R</CODE> and <CODE>varname</CODE>.
119 This ensures that two calls of this function with the same arguments will
120 return the same polynomial ring.
122 <DT><CODE>cl_univpoly_complex_ring cl_find_univpoly_ring (const cl_complex_ring& R)</CODE>
124 <DT><CODE>cl_univpoly_complex_ring cl_find_univpoly_ring (const cl_complex_ring& R, const cl_symbol& varname)</CODE>
126 <DT><CODE>cl_univpoly_real_ring cl_find_univpoly_ring (const cl_real_ring& R)</CODE>
128 <DT><CODE>cl_univpoly_real_ring cl_find_univpoly_ring (const cl_real_ring& R, const cl_symbol& varname)</CODE>
130 <DT><CODE>cl_univpoly_rational_ring cl_find_univpoly_ring (const cl_rational_ring& R)</CODE>
132 <DT><CODE>cl_univpoly_rational_ring cl_find_univpoly_ring (const cl_rational_ring& R, const cl_symbol& varname)</CODE>
134 <DT><CODE>cl_univpoly_integer_ring cl_find_univpoly_ring (const cl_integer_ring& R)</CODE>
136 <DT><CODE>cl_univpoly_integer_ring cl_find_univpoly_ring (const cl_integer_ring& R, const cl_symbol& varname)</CODE>
138 <DT><CODE>cl_univpoly_modint_ring cl_find_univpoly_ring (const cl_modint_ring& R)</CODE>
140 <DT><CODE>cl_univpoly_modint_ring cl_find_univpoly_ring (const cl_modint_ring& R, const cl_symbol& varname)</CODE>
142 These functions are equivalent to the general <CODE>cl_find_univpoly_ring</CODE>,
143 only the return type is more specific, according to the base ring's type.
148 <H2><A NAME="SEC56" HREF="cln_toc.html#TOC56">9.2 Functions on univariate polynomials</A></H2>
151 Given a univariate polynomial ring <CODE>R</CODE>, the following members can be used.
156 <DT><CODE>cl_ring R->basering()</CODE>
158 This returns the base ring, as passed to <SAMP>`cl_find_univpoly_ring'</SAMP>.
160 <DT><CODE>cl_UP R->zero()</CODE>
162 This returns <CODE>0 in R</CODE>, a polynomial of degree -1.
164 <DT><CODE>cl_UP R->one()</CODE>
166 This returns <CODE>1 in R</CODE>, a polynomial of degree <= 0.
168 <DT><CODE>cl_UP R->canonhom (const cl_I& x)</CODE>
170 This returns <CODE>x in R</CODE>, a polynomial of degree <= 0.
172 <DT><CODE>cl_UP R->monomial (const cl_ring_element& x, uintL e)</CODE>
174 This returns a sparse polynomial: <CODE>x * X^e</CODE>, where <CODE>X</CODE> is the
177 <DT><CODE>cl_UP R->create (sintL degree)</CODE>
179 Creates a new polynomial with a given degree. The zero polynomial has degree
180 <CODE>-1</CODE>. After creating the polynomial, you should put in the coefficients,
181 using the <CODE>set_coeff</CODE> member function, and then call the <CODE>finalize</CODE>
186 The following are the only destructive operations on univariate polynomials.
191 <DT><CODE>void set_coeff (cl_UP& x, uintL index, const cl_ring_element& y)</CODE>
193 This changes the coefficient of <CODE>X^index</CODE> in <CODE>x</CODE> to be <CODE>y</CODE>.
194 After changing a polynomial and before applying any "normal" operation on it,
195 you should call its <CODE>finalize</CODE> member function.
197 <DT><CODE>void finalize (cl_UP& x)</CODE>
199 This function marks the endpoint of destructive modifications of a polynomial.
200 It normalizes the internal representation so that subsequent computations have
201 less overhead. Doing normal computations on unnormalized polynomials may
202 produce wrong results or crash the program.
206 The following operations are defined on univariate polynomials.
211 <DT><CODE>cl_univpoly_ring x.ring ()</CODE>
213 Returns the ring to which the univariate polynomial <CODE>x</CODE> belongs.
215 <DT><CODE>cl_UP operator+ (const cl_UP&, const cl_UP&)</CODE>
217 Returns the sum of two univariate polynomials.
219 <DT><CODE>cl_UP operator- (const cl_UP&, const cl_UP&)</CODE>
221 Returns the difference of two univariate polynomials.
223 <DT><CODE>cl_UP operator- (const cl_UP&)</CODE>
225 Returns the negative of a univariate polynomial.
227 <DT><CODE>cl_UP operator* (const cl_UP&, const cl_UP&)</CODE>
229 Returns the product of two univariate polynomials. One of the arguments may
230 also be a plain integer or an element of the base ring.
232 <DT><CODE>cl_UP square (const cl_UP&)</CODE>
234 Returns the square of a univariate polynomial.
236 <DT><CODE>cl_UP expt_pos (const cl_UP& x, const cl_I& y)</CODE>
238 <CODE>y</CODE> must be > 0. Returns <CODE>x^y</CODE>.
240 <DT><CODE>bool operator== (const cl_UP&, const cl_UP&)</CODE>
242 <DT><CODE>bool operator!= (const cl_UP&, const cl_UP&)</CODE>
244 Compares two univariate polynomials, belonging to the same univariate
245 polynomial ring, for equality.
247 <DT><CODE>cl_boolean zerop (const cl_UP& x)</CODE>
249 Returns true if <CODE>x</CODE> is <CODE>0 in R</CODE>.
251 <DT><CODE>sintL degree (const cl_UP& x)</CODE>
253 Returns the degree of the polynomial. The zero polynomial has degree <CODE>-1</CODE>.
255 <DT><CODE>cl_ring_element coeff (const cl_UP& x, uintL index)</CODE>
257 Returns the coefficient of <CODE>X^index</CODE> in the polynomial <CODE>x</CODE>.
259 <DT><CODE>cl_ring_element x (const cl_ring_element& y)</CODE>
261 Evaluation: If <CODE>x</CODE> is a polynomial and <CODE>y</CODE> belongs to the base ring,
262 then <SAMP>`x(y)'</SAMP> returns the value of the substitution of <CODE>y</CODE> into
265 <DT><CODE>cl_UP deriv (const cl_UP& x)</CODE>
267 Returns the derivative of the polynomial <CODE>x</CODE> with respect to the
268 indeterminate <CODE>X</CODE>.
272 The following output functions are defined (see also the chapter on
278 <DT><CODE>void fprint (cl_ostream stream, const cl_UP& x)</CODE>
280 <DT><CODE>cl_ostream operator<< (cl_ostream stream, const cl_UP& x)</CODE>
282 Prints the univariate polynomial <CODE>x</CODE> on the <CODE>stream</CODE>. The output may
283 depend on the global printer settings in the variable
284 <CODE>cl_default_print_flags</CODE>.
289 <H2><A NAME="SEC57" HREF="cln_toc.html#TOC57">9.3 Special polynomials</A></H2>
292 The following functions return special polynomials.
297 <DT><CODE>cl_UP_I cl_tschebychev (sintL n)</CODE>
299 Returns the n-th Tchebychev polynomial (n >= 0).
301 <DT><CODE>cl_UP_I cl_hermite (sintL n)</CODE>
303 Returns the n-th Hermite polynomial (n >= 0).
305 <DT><CODE>cl_UP_RA cl_legendre (sintL n)</CODE>
307 Returns the n-th Legendre polynomial (n >= 0).
309 <DT><CODE>cl_UP_I cl_laguerre (sintL n)</CODE>
311 Returns the n-th Laguerre polynomial (n >= 0).
315 Information how to derive the differential equation satisfied by each
316 of these polynomials from their definition can be found in the
317 <CODE>doc/polynomial/</CODE> directory.
321 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>.