1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
3
<!-- Created on September, 20 2006 by texi2html 1.76 -->
5
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
6
Karl Berry <karl@freefriends.org>
7
Olaf Bachmann <obachman@mathematik.uni-kl.de>
9
Maintained by: Many creative people <dev@texi2html.cvshome.org>
10
Send bugs and suggestions to <users@texi2html.cvshome.org>
14
<title>Maxima Manual: 12. Polynomials</title>
16
<meta name="description" content="Maxima Manual: 12. Polynomials">
17
<meta name="keywords" content="Maxima Manual: 12. Polynomials">
18
<meta name="resource-type" content="document">
19
<meta name="distribution" content="global">
20
<meta name="Generator" content="texi2html 1.76">
21
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
22
<style type="text/css">
24
a.summary-letter {text-decoration: none}
25
pre.display {font-family: serif}
26
pre.format {font-family: serif}
27
pre.menu-comment {font-family: serif}
28
pre.menu-preformatted {font-family: serif}
29
pre.smalldisplay {font-family: serif; font-size: smaller}
30
pre.smallexample {font-size: smaller}
31
pre.smallformat {font-family: serif; font-size: smaller}
32
pre.smalllisp {font-size: smaller}
33
span.sansserif {font-family:sans-serif; font-weight:normal;}
34
ul.toc {list-style: none}
47
font-family: sans-serif
53
font-family: sans-serif
59
font-family: sans-serif
62
h2,h3,h4,h5,h6 { margin-left: +4%; }
82
background: rgb(200,255,255);
83
font-family: sans-serif
93
background: rgb(255,220,255);
94
/*background: rgb(200,255,255); */
95
/* font-family: fixed */
105
background: rgb(247,242,180); /* kind of sandy */
106
/* background: rgb(200,255,255); */ /* sky blue */
107
font-family: "Lucida Console", monospace
126
<link rel="icon" href="http://maxima.sourceforge.net/favicon.ico"/>
129
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
131
<a name="Polynomials"></a>
133
<table cellpadding="1" cellspacing="1" border="0">
134
<tr><td valign="middle" align="left">[<a href="maxima_11.html#SEC43" title="Previous section in reading order"> < </a>]</td>
135
<td valign="middle" align="left">[<a href="#SEC45" title="Next section in reading order"> > </a>]</td>
136
<td valign="middle" align="left"> </td>
137
<td valign="middle" align="left">[<a href="maxima_11.html#SEC42" title="Beginning of this chapter or previous chapter"> << </a>]</td>
138
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Up section"> Up </a>]</td>
139
<td valign="middle" align="left">[<a href="maxima_13.html#SEC47" title="Next chapter"> >> </a>]</td>
140
<td valign="middle" align="left"> </td>
141
<td valign="middle" align="left"> </td>
142
<td valign="middle" align="left"> </td>
143
<td valign="middle" align="left"> </td>
144
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
145
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
146
<td valign="middle" align="left">[<a href="maxima_72.html#SEC264" title="Index">Index</a>]</td>
147
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
149
<h1 class="chapter"> 12. Polynomials </h1>
151
<table class="menu" border="0" cellspacing="0">
152
<tr><td align="left" valign="top"><a href="#SEC45">12.1 Introduction to Polynomials</a></td><td> </td><td align="left" valign="top">
154
<tr><td align="left" valign="top"><a href="#SEC46">12.2 Definitions for Polynomials</a></td><td> </td><td align="left" valign="top">
159
<a name="Introduction-to-Polynomials"></a>
161
<table cellpadding="1" cellspacing="1" border="0">
162
<tr><td valign="middle" align="left">[<a href="#SEC44" title="Previous section in reading order"> < </a>]</td>
163
<td valign="middle" align="left">[<a href="#SEC46" title="Next section in reading order"> > </a>]</td>
164
<td valign="middle" align="left"> </td>
165
<td valign="middle" align="left">[<a href="#SEC44" title="Beginning of this chapter or previous chapter"> << </a>]</td>
166
<td valign="middle" align="left">[<a href="#SEC44" title="Up section"> Up </a>]</td>
167
<td valign="middle" align="left">[<a href="maxima_13.html#SEC47" title="Next chapter"> >> </a>]</td>
168
<td valign="middle" align="left"> </td>
169
<td valign="middle" align="left"> </td>
170
<td valign="middle" align="left"> </td>
171
<td valign="middle" align="left"> </td>
172
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
173
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
174
<td valign="middle" align="left">[<a href="maxima_72.html#SEC264" title="Index">Index</a>]</td>
175
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
177
<h2 class="section"> 12.1 Introduction to Polynomials </h2>
179
<p>Polynomials are stored in Maxima either in General Form or as
180
Cannonical Rational Expressions (CRE) form. The latter is a standard
181
form, and is used internally by operations such as factor, ratsimp, and
184
<p>Canonical Rational Expressions constitute a kind of representation
185
which is especially suitable for expanded polynomials and rational
186
functions (as well as for partially factored polynomials and rational
187
functions when RATFAC is set to <code>true</code>). In this CRE form an
188
ordering of variables (from most to least main) is assumed for each
189
expression. Polynomials are represented recursively by a list
190
consisting of the main variable followed by a series of pairs of
191
expressions, one for each term of the polynomial. The first member of
192
each pair is the exponent of the main variable in that term and the
193
second member is the coefficient of that term which could be a number or
194
a polynomial in another variable again represented in this form. Thus
195
the principal part of the CRE form of 3*X^2-1 is (X 2 3 0 -1) and that
196
of 2*X*Y+X-3 is (Y 1 (X 1 2) 0 (X 1 1 0 -3)) assuming Y is the main
197
variable, and is (X 1 (Y 1 2 0 1) 0 -3) assuming X is the main
198
variable. "Main"-ness is usually determined by reverse alphabetical
199
order. The "variables" of a CRE expression needn't be atomic. In fact
200
any subexpression whose main operator is not + - * / or ^ with integer
201
power will be considered a "variable" of the expression (in CRE form) in
202
which it occurs. For example the CRE variables of the expression
203
X+SIN(X+1)+2*SQRT(X)+1 are X, SQRT(X), and SIN(X+1). If the user does
204
not specify an ordering of variables by using the RATVARS function
205
Maxima will choose an alphabetic one. In general, CRE's represent
206
rational expressions, that is, ratios of polynomials, where the
207
numerator and denominator have no common factors, and the denominator is
208
positive. The internal form is essentially a pair of polynomials (the
209
numerator and denominator) preceded by the variable ordering list. If
210
an expression to be displayed is in CRE form or if it contains any
211
subexpressions in CRE form, the symbol /R/ will follow the line label.
212
See the RAT function for converting an expression to CRE form. An
213
extended CRE form is used for the representation of Taylor series. The
214
notion of a rational expression is extended so that the exponents of the
215
variables can be positive or negative rational numbers rather than just
216
positive integers and the coefficients can themselves be rational
217
expressions as described above rather than just polynomials. These are
218
represented internally by a recursive polynomial form which is similar
219
to and is a generalization of CRE form, but carries additional
220
information such as the degree of truncation. As with CRE form, the
221
symbol /T/ follows the line label of such expressions.
224
<a name="Definitions-for-Polynomials"></a>
226
<table cellpadding="1" cellspacing="1" border="0">
227
<tr><td valign="middle" align="left">[<a href="#SEC45" title="Previous section in reading order"> < </a>]</td>
228
<td valign="middle" align="left">[<a href="maxima_13.html#SEC47" title="Next section in reading order"> > </a>]</td>
229
<td valign="middle" align="left"> </td>
230
<td valign="middle" align="left">[<a href="#SEC44" title="Beginning of this chapter or previous chapter"> << </a>]</td>
231
<td valign="middle" align="left">[<a href="#SEC44" title="Up section"> Up </a>]</td>
232
<td valign="middle" align="left">[<a href="maxima_13.html#SEC47" title="Next chapter"> >> </a>]</td>
233
<td valign="middle" align="left"> </td>
234
<td valign="middle" align="left"> </td>
235
<td valign="middle" align="left"> </td>
236
<td valign="middle" align="left"> </td>
237
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
238
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
239
<td valign="middle" align="left">[<a href="maxima_72.html#SEC264" title="Index">Index</a>]</td>
240
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
242
<h2 class="section"> 12.2 Definitions for Polynomials </h2>
245
<dt><u>Option variable:</u> <b>algebraic</b>
246
<a name="IDX382"></a>
248
<dd><p>Default value: <code>false</code>
250
<p><code>algebraic</code> must be set to <code>true</code> in order for the
251
simplification of algebraic integers to take effect.
256
<dt><u>Option variable:</u> <b>berlefact</b>
257
<a name="IDX383"></a>
259
<dd><p>Default value: <code>true</code>
261
<p>When <code>berlefact</code> is <code>false</code> then the Kronecker factoring
262
algorithm will be used otherwise the Berlekamp algorithm, which is the
263
default, will be used.
268
<dt><u>Function:</u> <b>bezout</b><i> (<var>p1</var>, <var>p2</var>, <var>x</var>)</i>
269
<a name="IDX384"></a>
271
<dd><p>an alternative to the <code>resultant</code> command. It
272
returns a matrix. <code>determinant</code> of this matrix is the desired resultant.
277
<dt><u>Function:</u> <b>bothcoef</b><i> (<var>expr</var>, <var>x</var>)</i>
278
<a name="IDX385"></a>
280
<dd><p>Returns a list whose first member is the
281
coefficient of <var>x</var> in <var>expr</var> (as found by <code>ratcoef</code> if <var>expr</var> is in CRE form
282
otherwise by <code>coeff</code>) and whose second member is the remaining part of
283
<var>expr</var>. That is, <code>[A, B]</code> where <code><var>expr</var> = A*<var>x</var> + B</code>.
287
<table><tr><td> </td><td><pre class="example">(%i1) islinear (expr, x) := block ([c],
288
c: bothcoef (rat (expr, x), x),
289
is (freeof (x, c) and c[1] # 0))$
290
(%i2) islinear ((r^2 - (x - r)^2)/x, x);
292
</pre></td></tr></table>
296
<dt><u>Function:</u> <b>coeff</b><i> (<var>expr</var>, <var>x</var>, <var>n</var>)</i>
297
<a name="IDX386"></a>
299
<dd><p>Returns the coefficient of <code><var>x</var>^<var>n</var></code> in <var>expr</var>. <var>n</var> may be
300
omitted if it is 1. <var>x</var> may be an atom, or complete subexpression of
301
<var>expr</var> e.g., <code>sin(x)</code>, <code>a[i+1]</code>, <code>x + y</code>, etc. (In the last case the
302
expression <code>(x + y)</code> should occur in <var>expr</var>). Sometimes it may be necessary
303
to expand or factor <var>expr</var> in order to make <code><var>x</var>^<var>n</var></code> explicit. This is not
304
done automatically by <code>coeff</code>.
308
<table><tr><td> </td><td><pre class="example">(%i1) coeff (2*a*tan(x) + tan(x) + b = 5*tan(x) + 3, tan(x));
310
(%i2) coeff (y + x*%e^x + 1, x, 0);
312
</pre></td></tr></table>
316
<dt><u>Function:</u> <b>combine</b><i> (<var>expr</var>)</i>
317
<a name="IDX387"></a>
319
<dd><p>Simplifies the sum <var>expr</var> by combining terms with the same
320
denominator into a single term.
325
<dt><u>Function:</u> <b>content</b><i> (<var>p_1</var>, <var>x_1</var>, ..., <var>x_n</var>)</i>
326
<a name="IDX388"></a>
328
<dd><p>Returns a list whose first element is
329
the greatest common divisor of the coefficients of the terms of the
330
polynomial <var>p_1</var> in the variable <var>x_n</var> (this is the content) and whose
331
second element is the polynomial <var>p_1</var> divided by the content.
335
<table><tr><td> </td><td><pre class="example">(%i1) content (2*x*y + 4*x^2*y^2, y);
337
(%o1) [2 x, 2 x y + y]
338
</pre></td></tr></table>
342
<dt><u>Function:</u> <b>denom</b><i> (<var>expr</var>)</i>
343
<a name="IDX389"></a>
345
<dd><p>Returns the denominator of the rational expression <var>expr</var>.
350
<dt><u>Function:</u> <b>divide</b><i> (<var>p_1</var>, <var>p_2</var>, <var>x_1</var>, ..., <var>x_n</var>)</i>
351
<a name="IDX390"></a>
353
<dd><p>computes the quotient and remainder
354
of the polynomial <var>p_1</var> divided by the polynomial <var>p_2</var>, in a main
355
polynomial variable, <var>x_n</var>.
356
The other variables are as in the <code>ratvars</code> function.
357
The result is a list whose first element is the quotient
358
and whose second element is the remainder.
362
<table><tr><td> </td><td><pre class="example">(%i1) divide (x + y, x - y, x);
364
(%i2) divide (x + y, x - y);
366
</pre></td></tr></table>
368
<p>Note that <code>y</code> is the main variable in the second example.
373
<dt><u>Function:</u> <b>eliminate</b><i> ([<var>eqn_1</var>, ..., <var>eqn_n</var>], [<var>x_1</var>, ..., <var>x_k</var>])</i>
374
<a name="IDX391"></a>
376
<dd><p>Eliminates variables from
377
equations (or expressions assumed equal to zero) by taking successive
378
resultants. This returns a list of <code><var>n</var> - <var>k</var></code> expressions with the <var>k</var>
379
variables <var>x_1</var>, ..., <var>x_k</var> eliminated. First <var>x_1</var> is eliminated yielding <code><var>n</var> - 1</code>
380
expressions, then <code>x_2</code> is eliminated, etc. If <code><var>k</var> = <var>n</var></code> then a single expression in a
381
list is returned free of the variables <var>x_1</var>, ..., <var>x_k</var>. In this case <code>solve</code>
382
is called to solve the last resultant for the last variable.
386
<table><tr><td> </td><td><pre class="example">(%i1) expr1: 2*x^2 + y*x + z;
389
(%i2) expr2: 3*x + 5*y - z - 1;
390
(%o2) - z + 5 y + 3 x - 1
391
(%i3) expr3: z^2 + x - y^2 + 5;
394
(%i4) eliminate ([expr3, expr2, expr1], [y, z]);
396
(%o4) [7425 x - 1170 x + 1299 x + 12076 x + 22887 x
399
- 5154 x - 1291 x + 7688 x + 15376]
400
</pre></td></tr></table>
404
<dt><u>Function:</u> <b>ezgcd</b><i> (<var>p_1</var>, <var>p_2</var>, <var>p_3</var>, ...)</i>
405
<a name="IDX392"></a>
407
<dd><p>Returns a list whose first element is the g.c.d of
408
the polynomials <var>p_1</var>, <var>p_2</var>, <var>p_3</var>, ... and whose remaining elements are the
409
polynomials divided by the g.c.d. This always uses the <code>ezgcd</code>
415
<dt><u>Option variable:</u> <b>facexpand</b>
416
<a name="IDX393"></a>
418
<dd><p>Default value: <code>true</code>
420
<p><code>facexpand</code> controls whether the irreducible factors
421
returned by <code>factor</code> are in expanded (the default) or recursive (normal
427
<dt><u>Function:</u> <b>factcomb</b><i> (<var>expr</var>)</i>
428
<a name="IDX394"></a>
430
<dd><p>Tries to combine the coefficients of factorials in <var>expr</var>
431
with the factorials themselves by converting, for example, <code>(n + 1)*n!</code>
432
into <code>(n + 1)!</code>.
434
<p><code>sumsplitfact</code> if set to <code>false</code> will cause <code>minfactorial</code> to be
435
applied after a <code>factcomb</code>.
440
<dt><u>Function:</u> <b>factor</b><i> (<var>expr</var>)</i>
441
<a name="IDX395"></a>
443
<dd><p>Factors the expression <var>expr</var>, containing any number of
444
variables or functions, into factors irreducible over the integers.
445
<code>factor (<var>expr</var>, p)</code> factors <var>expr</var> over the field of integers with an element
446
adjoined whose minimum polynomial is p.
448
<p><code>factor</code> uses <code>ifactors</code> function for factoring integers.
450
<p><code>factorflag</code> if <code>false</code> suppresses the factoring of integer factors
451
of rational expressions.
453
<p><code>dontfactor</code> may be set to a list of variables with respect to which
454
factoring is not to occur. (It is initially empty). Factoring also
455
will not take place with respect to any variables which are less
456
important (using the variable ordering assumed for CRE form) than
457
those on the <code>dontfactor</code> list.
459
<p><code>savefactors</code> if <code>true</code> causes the factors of an expression which
460
is a product of factors to be saved by certain functions in order to
461
speed up later factorizations of expressions containing some of the
464
<p><code>berlefact</code> if <code>false</code> then the Kronecker factoring algorithm will
465
be used otherwise the Berlekamp algorithm, which is the default, will
468
<p><code>intfaclim</code> if <code>true</code> maxima will give up factorization of
469
integers if no factor is found after trial divisions and Pollard's rho
470
method. If set to <code>false</code> (this is the case when the user calls
471
<code>factor</code> explicitly), complete factorization of the integer will be
472
attempted. The user's setting of <code>intfaclim</code> is used for internal
473
calls to <code>factor</code>. Thus, <code>intfaclim</code> may be reset to prevent
474
Maxima from taking an inordinately long time factoring large integers.
478
<table><tr><td> </td><td><pre class="example">(%i1) factor (2^63 - 1);
480
(%o1) 7 73 127 337 92737 649657
481
(%i2) factor (-8*y - 4*x + z^2*(2*y + x));
482
(%o2) (2 y + x) (z - 2) (z + 2)
483
(%i3) -1 - 2*x - x^2 + y^2 + 2*x*y^2 + x^2*y^2;
485
(%o3) x y + 2 x y + y - x - 2 x - 1
486
(%i4) block ([dontfactor: [x]], factor (%/36/(1 + 2*y + y^2)));
488
(x + 2 x + 1) (y - 1)
489
(%o4) ----------------------
491
(%i5) factor (1 + %e^(3*x));
493
(%o5) (%e + 1) (%e - %e + 1)
494
(%i6) factor (1 + x^4, a^2 - 2);
496
(%o6) (x - a x + 1) (x + a x + 1)
497
(%i7) factor (-y^2*z^2 - x*z^2 + x^2*y^2 + x^3);
499
(%o7) - (y + x) (z - x) (z + x)
500
(%i8) (2 + x)/(3 + x)/(b + x)/(c + x)^2;
502
(%o8) ------------------------
504
(x + 3) (x + b) (x + c)
507
(%o9) (x + 2)/(x + (2 c + b + 3) x
510
+ (c + (2 b + 6) c + 3 b) x + ((b + 3) c + 6 b c) x + 3 b c )
511
(%i10) partfrac (%, x);
513
(%o10) - (c - 4 c - b + 6)/((c + (- 2 b - 6) c
516
+ (b + 12 b + 9) c + (- 6 b - 18 b) c + 9 b ) (x + c))
519
- ---------------------------------
521
(c + (- b - 3) c + 3 b) (x + c)
524
+ -------------------------------------------------
526
((b - 3) c + (6 b - 2 b ) c + b - 3 b ) (x + b)
529
- ----------------------------------------------
531
((b - 3) c + (18 - 6 b) c + 9 b - 27) (x + 3)
532
(%i11) map ('factor, %);
534
c - 4 c - b + 6 c - 2
535
(%o11) - ------------------------- - ------------------------
537
(c - 3) (c - b) (x + c) (c - 3) (c - b) (x + c)
540
+ ------------------------ - ------------------------
542
(b - 3) (c - b) (x + b) (b - 3) (c - 3) (x + 3)
543
(%i12) ratsimp ((x^5 - 1)/(x - 1));
545
(%o12) x + x + x + x + 1
546
(%i13) subst (a, x, %);
548
(%o13) a + a + a + a + 1
549
(%i14) factor (%th(2), %);
551
(%o14) (x - a) (x - a ) (x - a ) (x + a + a + a + 1)
552
(%i15) factor (1 + x^12);
554
(%o15) (x + 1) (x - x + 1)
555
(%i16) factor (1 + x^99);
557
(%o16) (x + 1) (x - x + 1) (x - x + 1)
560
(x - x + x - x + x - x + x - x + x - x + 1)
562
20 19 17 16 14 13 11 10 9 7 6
563
(x + x - x - x + x + x - x - x - x + x + x
565
4 3 60 57 51 48 42 39 33
566
- x - x + x + 1) (x + x - x - x + x + x - x
569
- x - x + x + x - x - x + x + 1)
570
</pre></td></tr></table>
574
<dt><u>Option variable:</u> <b>factorflag</b>
575
<a name="IDX396"></a>
577
<dd><p>Default value: <code>false</code>
579
<p>When <code>factorflag</code> is <code>false</code>, suppresses the factoring of
580
integer factors of rational expressions.
585
<dt><u>Function:</u> <b>factorout</b><i> (<var>expr</var>, <var>x_1</var>, <var>x_2</var>, ...)</i>
586
<a name="IDX397"></a>
588
<dd><p>Rearranges the sum <var>expr</var> into a sum of
589
terms of the form <code>f (<var>x_1</var>, <var>x_2</var>, ...)*g</code> where <code>g</code> is a product of
590
expressions not containing any <var>x_i</var> and <code>f</code> is factored.
595
<dt><u>Function:</u> <b>factorsum</b><i> (<var>expr</var>)</i>
596
<a name="IDX398"></a>
598
<dd><p>Tries to group terms in factors of <var>expr</var> which are sums
599
into groups of terms such that their sum is factorable. <code>factorsum</code> can
600
recover the result of <code>expand ((x + y)^2 + (z + w)^2)</code> but it can't recover
601
<code>expand ((x + 1)^2 + (x + y)^2)</code> because the terms have variables in common.
605
<table><tr><td> </td><td><pre class="example">(%i1) expand ((x + 1)*((u + v)^2 + a*(w + z)^2));
607
(%o1) a x z + a z + 2 a w x z + 2 a w z + a w x + v x
610
+ 2 u v x + u x + a w + v + 2 u v + u
613
(%o2) (x + 1) (a (z + w) + (v + u) )
614
</pre></td></tr></table>
618
<dt><u>Function:</u> <b>fasttimes</b><i> (<var>p_1</var>, <var>p_2</var>)</i>
619
<a name="IDX399"></a>
621
<dd><p>Returns the product of the polynomials <var>p_1</var> and <var>p_2</var> by using a
622
special algorithm for multiplication of polynomials. <code>p_1</code> and <code>p_2</code> should be
623
multivariate, dense, and nearly the same size. Classical
624
multiplication is of order <code>n_1 n_2</code> where
625
<code>n_1</code> is the degree of <code>p_1</code>
626
and <code>n_2</code> is the degree of <code>p_2</code>.
627
<code>fasttimes</code> is of order <code>max (n_1, n_2)^1.585</code>.
632
<dt><u>Function:</u> <b>fullratsimp</b><i> (<var>expr</var>)</i>
633
<a name="IDX400"></a>
635
<dd><p><code>fullratsimp</code> repeatedly
636
applies <code>ratsimp</code> followed by non-rational simplification to an
637
expression until no further change occurs,
638
and returns the result.
640
<p>When non-rational expressions are involved, one call
641
to <code>ratsimp</code> followed as is usual by non-rational ("general")
642
simplification may not be sufficient to return a simplified result.
643
Sometimes, more than one such call may be necessary.
644
<code>fullratsimp</code> makes this process convenient.
646
<p><code>fullratsimp (<var>expr</var>, <var>x_1</var>, ..., <var>x_n</var>)</code> takes one or more arguments similar
647
to <code>ratsimp</code> and <code>rat</code>.
651
<table><tr><td> </td><td><pre class="example">(%i1) expr: (x^(a/2) + 1)^2*(x^(a/2) - 1)^2/(x^a - 1);
654
(%o1) -----------------------
657
(%i2) ratsimp (expr);
660
(%o2) ---------------
663
(%i3) fullratsimp (expr);
669
(%o4)/R/ -----------------------
672
</pre></td></tr></table>
676
<dt><u>Function:</u> <b>fullratsubst</b><i> (<var>a</var>, <var>b</var>, <var>c</var>)</i>
677
<a name="IDX401"></a>
679
<dd><p>is the same as <code>ratsubst</code> except that it calls
680
itself recursively on its result until that result stops changing.
681
This function is useful when the replacement expression and the
682
replaced expression have one or more variables in common.
684
<p><code>fullratsubst</code> will also accept its arguments in the format of
685
<code>lratsubst</code>. That is, the first argument may be a single substitution
686
equation or a list of such equations, while the second argument is the
687
expression being processed.
689
<p><code>load ("lrats")</code> loads <code>fullratsubst</code> and <code>lratsubst</code>.
693
<table><tr><td> </td><td><pre class="example">(%i1) load ("lrats")$
694
</pre></td></tr></table><ul>
696
<code>subst</code> can carry out multiple substitutions.
697
<code>lratsubst</code> is analogous to <code>subst</code>.
699
<table><tr><td> </td><td><pre class="example">(%i2) subst ([a = b, c = d], a + c);
701
(%i3) lratsubst ([a^2 = b, c^2 = d], (a + e)*c*(a + c));
702
(%o3) (d + a c) e + a d + b c
703
</pre></td></tr></table><ul>
705
If only one substitution is desired, then a single
706
equation may be given as first argument.
708
<table><tr><td> </td><td><pre class="example">(%i4) lratsubst (a^2 = b, a^3);
710
</pre></td></tr></table><ul>
712
<code>fullratsubst</code> is equivalent to <code>ratsubst</code>
713
except that it recurses until its result stops changing.
715
<table><tr><td> </td><td><pre class="example">(%i5) ratsubst (b*a, a^2, a^3);
718
(%i6) fullratsubst (b*a, a^2, a^3);
721
</pre></td></tr></table><ul>
723
<code>fullratsubst</code> also accepts a list of equations or a single
724
equation as first argument.
726
<table><tr><td> </td><td><pre class="example">(%i7) fullratsubst ([a^2 = b, b^2 = c, c^2 = a], a^3*b*c);
728
(%i8) fullratsubst (a^2 = b*a, a^3);
731
</pre></td></tr></table><ul>
733
<code>fullratsubst</code> may cause an indefinite recursion.
735
<table><tr><td> </td><td><pre class="example">(%i9) errcatch (fullratsubst (b*a^2, a^2, a^3));
737
*** - Lisp stack overflow. RESET
738
</pre></td></tr></table>
742
<dt><u>Function:</u> <b>gcd</b><i> (<var>p_1</var>, <var>p_2</var>, <var>x_1</var>, ...)</i>
743
<a name="IDX402"></a>
745
<dd><p>Returns the greatest common divisor of <var>p_1</var> and <var>p_2</var>.
746
The flag <code>gcd</code> determines which algorithm is employed.
747
Setting <code>gcd</code> to <code>ez</code>, <code>subres</code>, <code>red</code>, or <code>spmod</code> selects the <code>ezgcd</code>,
748
subresultant <code>prs</code>, reduced, or modular algorithm,
749
respectively. If <code>gcd</code> <code>false</code> then <code>gcd (<var>p_1</var>, <var>p_2</var>, <var>x</var>)</code> always returns 1
750
for all <var>x</var>. Many functions (e.g. <code>ratsimp</code>, <code>factor</code>, etc.) cause gcd's
751
to be taken implicitly. For homogeneous polynomials it is recommended
752
that <code>gcd</code> equal to <code>subres</code> be used. To take the gcd when an algebraic is
753
present, e.g., <code>gcd (<var>x</var>^2 - 2*sqrt(2)*<var>x</var> + 2, <var>x</var> - sqrt(2))</code>, <code>algebraic</code> must be
754
<code>true</code> and <code>gcd</code> must not be <code>ez</code>. <code>subres</code> is a new algorithm, and people
755
who have been using the <code>red</code> setting should probably change it to
758
<p>The <code>gcd</code> flag, default: <code>subres</code>, if <code>false</code> will also prevent the greatest
759
common divisor from being taken when expressions are converted to canonical rational expression (CRE)
760
form. This will sometimes speed the calculation if gcds are not
766
<dt><u>Function:</u> <b>gcdex</b><i> (<var>f</var>, <var>g</var>)</i>
767
<a name="IDX403"></a>
769
<dt><u>Function:</u> <b>gcdex</b><i> (<var>f</var>, <var>g</var>, <var>x</var>)</i>
770
<a name="IDX404"></a>
772
<dd><p>Returns a list <code>[<var>a</var>, <var>b</var>, <var>u</var>]</code>
773
where <var>u</var> is the greatest common divisor (gcd) of <var>f</var> and <var>g</var>,
774
and <var>u</var> is equal to <code><var>a</var> <var>f</var> + <var>b</var> <var>g</var></code>.
775
The arguments <var>f</var> and <var>g</var> should be univariate polynomials,
776
or else polynomials in <var>x</var> a supplied <b>main</b> variable
777
since we need to be in a principal ideal domain for this to work.
778
The gcd means the gcd regarding <var>f</var> and <var>g</var> as univariate polynomials with coefficients
779
being rational functions in the other variables.
781
<p><code>gcdex</code> implements the Euclidean algorithm,
782
where we have a sequence
783
of <code>L[i]: [a[i], b[i], r[i]]</code> which are all perpendicular
784
to <code>[f, g, -1]</code> and the next one is built as
785
if <code>q = quotient(r[i]/r[i+1])</code> then <code>L[i+2]: L[i] - q L[i+1]</code>, and it
786
terminates at <code>L[i+1]</code> when the remainder <code>r[i+2]</code> is zero.
789
<table><tr><td> </td><td><pre class="example">(%i1) gcdex (x^2 + 1, x^3 + 4);
792
(%o1)/R/ [- ------------, -----, 1]
794
(%i2) % . [x^2 + 1, x^3 + 4, -1];
796
</pre></td></tr></table>
797
<p>Note that the gcd in the following is <code>1</code>
798
since we work in <code>k(y)[x]</code>, not the <code>y+1</code> we would expect in <code>k[y, x]</code>.
801
<table><tr><td> </td><td><pre class="example">(%i1) gcdex (x*(y + 1), y^2 - 1, x);
803
(%o1)/R/ [0, ------, 1]
806
</pre></td></tr></table>
811
<dt><u>Function:</u> <b>gcfactor</b><i> (<var>n</var>)</i>
812
<a name="IDX405"></a>
814
<dd><p>Factors the Gaussian integer <var>n</var> over the Gaussian integers, i.e.,
815
numbers of the form <code><var>a</var> + <var>b</var> <code>%i</code></code> where <var>a</var> and <var>b</var> are rational integers
816
(i.e., ordinary integers). Factors are normalized by making <var>a</var> and <var>b</var>
822
<dt><u>Function:</u> <b>gfactor</b><i> (<var>expr</var>)</i>
823
<a name="IDX406"></a>
825
<dd><p>Factors the polynomial <var>expr</var> over the Gaussian integers
826
(that is, the integers with the imaginary unit <code>%i</code> adjoined).
827
This is like <code>factor (<var>expr</var>, <var>a</var>^2+1)</code> where <var>a</var> is <code>%i</code>.
831
<table><tr><td> </td><td><pre class="example">(%i1) gfactor (x^4 - 1);
832
(%o1) (x - 1) (x + 1) (x - %i) (x + %i)
833
</pre></td></tr></table>
837
<dt><u>Function:</u> <b>gfactorsum</b><i> (<var>expr</var>)</i>
838
<a name="IDX407"></a>
840
<dd><p>is similar to <code>factorsum</code> but applies <code>gfactor</code> instead
841
of <code>factor</code>.
846
<dt><u>Function:</u> <b>hipow</b><i> (<var>expr</var>, <var>x</var>)</i>
847
<a name="IDX408"></a>
849
<dd><p>Returns the highest explicit exponent of <var>x</var> in <var>expr</var>.
850
<var>x</var> may be a variable or a general expression.
851
If <var>x</var> does not appear in <var>expr</var>,
852
<code>hipow</code> returns <code>0</code>.
854
<p><code>hipow</code> does not consider expressions equivalent to <code>expr</code>.
855
In particular, <code>hipow</code> does not expand <code>expr</code>,
856
so <code>hipow (<var>expr</var>, <var>x</var>)</code> and <code>hipow (expand (<var>expr</var>, <var>x</var>))</code>
857
may yield different results.
861
<table><tr><td> </td><td><pre class="example">(%i1) hipow (y^3 * x^2 + x * y^4, x);
863
(%i2) hipow ((x + y)^5, x);
865
(%i3) hipow (expand ((x + y)^5), x);
867
(%i4) hipow ((x + y)^5, x + y);
869
(%i5) hipow (expand ((x + y)^5), x + y);
871
</pre></td></tr></table>
875
<dt><u>Option variable:</u> <b>intfaclim</b>
876
<a name="IDX409"></a>
878
<dd><p>Default value: true
880
<p>If <code>true</code>, maxima will give up factorization of
881
integers if no factor is found after trial divisions and Pollard's rho
882
method and factorization will not be complete.
884
<p>When <code>intfaclim</code> is <code>false</code> (this is the case when the user
885
calls <code>factor</code> explicitly), complete factorization will be
886
attempted. <code>intfaclim</code> is set to <code>false</code> when factors are
887
computed in <code>divisors</code>, <code>divsum</code> and <code>totient</code>.
889
<p>Internal calls to <code>factor</code> respect the user-specified value of
890
<code>intfaclim</code>. Setting <code>intfaclim</code> to <code>true</code> may reduce
891
the time spent factoring large integers.
896
<dt><u>Option variable:</u> <b>keepfloat</b>
897
<a name="IDX410"></a>
899
<dd><p>Default value: <code>false</code>
901
<p>When <code>keepfloat</code> is <code>true</code>, prevents floating
902
point numbers from being rationalized when expressions which contain
903
them are converted to canonical rational expression (CRE) form.
908
<dt><u>Function:</u> <b>lratsubst</b><i> (<var>L</var>, <var>expr</var>)</i>
909
<a name="IDX411"></a>
911
<dd><p>is analogous to <code>subst (<var>L</var>, <var>expr</var>)</code>
912
except that it uses <code>ratsubst</code> instead of <code>subst</code>.
914
<p>The first argument of
915
<code>lratsubst</code> is an equation or a list of equations identical in
916
format to that accepted by <code>subst</code>. The
917
substitutions are made in the order given by the list of equations,
918
that is, from left to right.
920
<p><code>load ("lrats")</code> loads <code>fullratsubst</code> and <code>lratsubst</code>.
924
<table><tr><td> </td><td><pre class="example">(%i1) load ("lrats")$
925
</pre></td></tr></table><ul>
927
<code>subst</code> can carry out multiple substitutions.
928
<code>lratsubst</code> is analogous to <code>subst</code>.
930
<table><tr><td> </td><td><pre class="example">(%i2) subst ([a = b, c = d], a + c);
932
(%i3) lratsubst ([a^2 = b, c^2 = d], (a + e)*c*(a + c));
933
(%o3) (d + a c) e + a d + b c
934
</pre></td></tr></table><ul>
936
If only one substitution is desired, then a single
937
equation may be given as first argument.
939
<table><tr><td> </td><td><pre class="example">(%i4) lratsubst (a^2 = b, a^3);
941
</pre></td></tr></table>
945
<dt><u>Option variable:</u> <b>modulus</b>
946
<a name="IDX412"></a>
948
<dd><p>Default value: <code>false</code>
950
<p>When <code>modulus</code> is a positive number <var>p</var>,
951
operations on rational numbers (as returned by <code>rat</code> and related functions)
952
are carried out modulo <var>p</var>,
953
using the so-called "balanced" modulus system
954
in which <code><var>n</var> modulo <var>p</var></code> is defined as
955
an integer <var>k</var> in <code>[-(<var>p</var>-1)/2, ..., 0, ..., (<var>p</var>-1)/2]</code>
956
when <var>p</var> is odd, or <code>[-(<var>p</var>/2 - 1), ..., 0, ...., <var>p</var>/2]</code> when <var>p</var> is even,
957
such that <code><var>a</var> <var>p</var> + <var>k</var></code> equals <var>n</var> for some integer <var>a</var>.
959
<p>If <var>expr</var> is already in canonical rational expression (CRE) form when <code>modulus</code> is reset,
960
then you may need to re-rat <var>expr</var>, e.g., <code>expr: rat (ratdisrep (expr))</code>,
961
in order to get correct results.
963
<p>Typically <code>modulus</code> is set to a prime number.
964
If <code>modulus</code> is set to a positive non-prime integer,
965
this setting is accepted, but a warning message is displayed.
966
Maxima will allow zero or a negative integer to be assigned to <code>modulus</code>,
967
although it is not clear if that has any useful consequences.
973
<dt><u>Function:</u> <b>num</b><i> (<var>expr</var>)</i>
974
<a name="IDX413"></a>
976
<dd><p>Returns the numerator of <var>expr</var> if it is a ratio.
977
If <var>expr</var> is not a ratio, <var>expr</var> is returned.
979
<p><code>num</code> evaluates its argument.
984
<dt><u>Function:</u> <b>polydecomp</b><i> (<var>p</var>, <var>x</var>)</i>
985
<a name="IDX414"></a>
987
<dd><p>Decomposes the polynomial <var>p</var> in the variable <var>x</var>
988
into the functional composition of polynomials in <var>x</var>.
989
<code>polydecomp</code> returns a list <code>[<var>p_1</var>, ..., <var>p_n</var>]</code> such that
991
<table><tr><td> </td><td><pre class="example">lambda ([x], p_1) (lambda ([x], p_2) (... (lambda ([x], p_n) (x)) ...))
992
</pre></td></tr></table>
993
<p>is equal to <var>p</var>.
994
The degree of <var>p_i</var> is greater than 1 for <var>i</var> less than <var>n</var>.
996
<p>Such a decomposition is not unique.
1000
<table><tr><td> </td><td><pre class="example">(%i1) polydecomp (x^210, x);
1002
(%o1) [x , x , x , x ]
1003
(%i2) p : expand (subst (x^3 - x - 1, x, x^2 - a));
1005
(%o2) x - 2 x - 2 x + x + 2 x - a + 1
1006
(%i3) polydecomp (p, x);
1008
(%o3) [x - a, x - x - 1]
1009
</pre></td></tr></table>
1010
<p>The following function composes <code>L = [e_1, ..., e_n]</code> as functions in <code>x</code>;
1011
it is the inverse of polydecomp:
1013
<table><tr><td> </td><td><pre class="example">compose (L, x) :=
1014
block ([r : x], for e in L do r : subst (e, x, r), r) $
1015
</pre></td></tr></table>
1016
<p>Re-express above example using <code>compose</code>:
1018
<table><tr><td> </td><td><pre class="example">(%i3) polydecomp (compose ([x^2 - a, x^3 - x - 1], x), x);
1020
(%o3) [x - a, x - x - 1]
1021
</pre></td></tr></table>
1022
<p>Note that though <code>compose (polydecomp (<var>p</var>, <var>x</var>), <var>x</var>)</code>
1023
always returns <var>p</var> (unexpanded),
1024
<code>polydecomp (compose ([<var>p_1</var>, ..., <var>p_n</var>], <var>x</var>), <var>x</var>)</code> does <i>not</i>
1025
necessarily return <code>[<var>p_1</var>, ..., <var>p_n</var>]</code>:
1027
<table><tr><td> </td><td><pre class="example">(%i4) polydecomp (compose ([x^2 + 2*x + 3, x^2], x), x);
1029
(%o4) [x + 2, x + 1]
1030
(%i5) polydecomp (compose ([x^2 + x + 1, x^2 + x + 1], x), x);
1033
(%o5) [------, ------, 2 x + 1]
1035
</pre></td></tr></table>
1039
<dt><u>Function:</u> <b>quotient</b><i> (<var>p_1</var>, <var>p_2</var>)</i>
1040
<a name="IDX415"></a>
1042
<dt><u>Function:</u> <b>quotient</b><i> (<var>p_1</var>, <var>p_2</var>, <var>x_1</var>, ..., <var>x_n</var>)</i>
1043
<a name="IDX416"></a>
1045
<dd><p>Returns the polynomial <var>p_1</var> divided by the polynomial <var>p_2</var>.
1046
The arguments <var>x_1</var>, ..., <var>x_n</var> are interpreted as in <code>ratvars</code>.
1048
<p><code>quotient</code> returns the first element of the two-element list returned by <code>divide</code>.
1053
<dt><u>Function:</u> <b>rat</b><i> (<var>expr</var>)</i>
1054
<a name="IDX417"></a>
1056
<dt><u>Function:</u> <b>rat</b><i> (<var>expr</var>, <var>x_1</var>, ..., <var>x_n</var>)</i>
1057
<a name="IDX418"></a>
1059
<dd><p>Converts <var>expr</var> to canonical rational expression (CRE) form by expanding and
1060
combining all terms over a common denominator and cancelling out the
1061
greatest common divisor of the numerator and denominator, as well as
1062
converting floating point numbers to rational numbers within a
1063
tolerance of <code>ratepsilon</code>.
1064
The variables are ordered according
1065
to the <var>x_1</var>, ..., <var>x_n</var>, if specified, as in <code>ratvars</code>.
1067
<p><code>rat</code> does not generally simplify functions other than
1068
addition <code>+</code>, subtraction <code>-</code>, multiplication <code>*</code>, division <code>/</code>, and
1069
exponentiation to an integer power,
1070
whereas <code>ratsimp</code> does handle those cases.
1071
Note that atoms (numbers and variables) in CRE form are not the
1072
same as they are in the general form.
1073
For example, <code>rat(x)- x</code> yields
1074
<code>rat(0)</code> which has a different internal representation than 0.
1076
<p>When <code>ratfac</code> is <code>true</code>, <code>rat</code> yields a partially factored form for CRE.
1077
During rational operations the expression is
1078
maintained as fully factored as possible without an actual call to the
1079
factor package. This should always save space and may save some time
1080
in some computations. The numerator and denominator are still made
1082
(e.g. <code>rat ((x^2 - 1)^4/(x + 1)^2)</code> yields <code>(x - 1)^4 (x + 1)^2)</code>,
1083
but the factors within each part may not be relatively prime.
1085
<p><code>ratprint</code> if <code>false</code> suppresses the printout of the message
1086
informing the user of the conversion of floating point numbers to
1089
<p><code>keepfloat</code> if <code>true</code> prevents floating point numbers from being
1090
converted to rational numbers.
1092
<p>See also <code>ratexpand</code> and <code>ratsimp</code>.
1096
<table><tr><td> </td><td><pre class="example">(%i1) ((x - 2*y)^4/(x^2 - 4*y^2)^2 + 1)*(y + a)*(2*y + x) /(4*y^2 + x^2);
1099
(y + a) (2 y + x) (------------ + 1)
1102
(%o1) ------------------------------------
1105
(%i2) rat (%, y, a, x);
1109
</pre></td></tr></table>
1113
<dt><u>Option variable:</u> <b>ratalgdenom</b>
1114
<a name="IDX419"></a>
1116
<dd><p>Default value: <code>true</code>
1118
<p>When <code>ratalgdenom</code> is <code>true</code>, allows rationalization of
1119
denominators with respect to radicals to take effect.
1120
<code>ratalgdenom</code> has an effect only when canonical rational expressions (CRE) are used in algebraic mode.
1125
<dt><u>Function:</u> <b>ratcoef</b><i> (<var>expr</var>, <var>x</var>, <var>n</var>)</i>
1126
<a name="IDX420"></a>
1128
<dt><u>Function:</u> <b>ratcoef</b><i> (<var>expr</var>, <var>x</var>)</i>
1129
<a name="IDX421"></a>
1131
<dd><p>Returns the coefficient of the expression <code><var>x</var>^<var>n</var></code>
1132
in the expression <var>expr</var>.
1133
If omitted, <var>n</var> is assumed to be 1.
1135
<p>The return value is free
1136
(except possibly in a non-rational sense) of the variables in <var>x</var>.
1137
If no coefficient of this type exists, 0 is returned.
1139
<p><code>ratcoef</code>
1140
expands and rationally simplifies its first argument and thus it may
1141
produce answers different from those of <code>coeff</code> which is purely
1143
Thus <code>ratcoef ((x + 1)/y + x, x)</code> returns <code>(y + 1)/y</code> whereas <code>coeff</code> returns 1.
1145
<p><code>ratcoef (<var>expr</var>, <var>x</var>, 0)</code>, viewing <var>expr</var> as a sum,
1146
returns a sum of those terms which do not contain <var>x</var>.
1147
Therefore if <var>x</var> occurs to any negative powers, <code>ratcoef</code> should not be used.
1149
<p>Since <var>expr</var> is rationally
1150
simplified before it is examined, coefficients may not appear quite
1151
the way they were envisioned.
1155
<table><tr><td> </td><td><pre class="example">(%i1) s: a*x + b*x + 5$
1156
(%i2) ratcoef (s, a + b);
1158
</pre></td></tr></table>
1162
<dt><u>Function:</u> <b>ratdenom</b><i> (<var>expr</var>)</i>
1163
<a name="IDX422"></a>
1165
<dd><p>Returns the denominator of <var>expr</var>,
1166
after coercing <var>expr</var> to a canonical rational expression (CRE).
1167
The return value is a CRE.
1169
<p><var>expr</var> is coerced to a CRE by <code>rat</code>
1170
if it is not already a CRE.
1171
This conversion may change the form of <var>expr</var> by putting all terms
1172
over a common denominator.
1174
<p><code>denom</code> is similar, but returns an ordinary expression instead of a CRE.
1175
Also, <code>denom</code> does not attempt to place all terms over a common denominator,
1176
and thus some expressions which are considered ratios by <code>ratdenom</code>
1177
are not considered ratios by <code>denom</code>.
1182
<dt><u>Option variable:</u> <b>ratdenomdivide</b>
1183
<a name="IDX423"></a>
1185
<dd><p>Default value: <code>true</code>
1187
<p>When <code>ratdenomdivide</code> is <code>true</code>,
1188
<code>ratexpand</code> expands a ratio in which the numerator is a sum
1189
into a sum of ratios,
1190
all having a common denominator.
1191
Otherwise, <code>ratexpand</code> collapses a sum of ratios into a single ratio,
1192
the numerator of which is the sum of the numerators of each ratio.
1196
<table><tr><td> </td><td><pre class="example">(%i1) expr: (x^2 + x + 1)/(y^2 + 7);
1202
(%i2) ratdenomdivide: true$
1203
(%i3) ratexpand (expr);
1206
(%o3) ------ + ------ + ------
1209
(%i4) ratdenomdivide: false$
1210
(%i5) ratexpand (expr);
1216
(%i6) expr2: a^2/(b^2 + 3) + b/(b^2 + 3);
1219
(%o6) ------ + ------
1222
(%i7) ratexpand (expr2);
1228
</pre></td></tr></table>
1232
<dt><u>Function:</u> <b>ratdiff</b><i> (<var>expr</var>, <var>x</var>)</i>
1233
<a name="IDX424"></a>
1235
<dd><p>Differentiates the rational expression <var>expr</var> with respect to <var>x</var>.
1236
<var>expr</var> must be a ratio of polynomials or a polynomial in <var>x</var>.
1237
The argument <var>x</var> may be a variable or a subexpression of <var>expr</var>.
1239
<p>The result is equivalent to <code>diff</code>, although perhaps in a different form.
1240
<code>ratdiff</code> may be faster than <code>diff</code>, for rational expressions.
1242
<p><code>ratdiff</code> returns a canonical rational expression (CRE) if <code>expr</code> is a CRE.
1243
Otherwise, <code>ratdiff</code> returns a general expression.
1245
<p><code>ratdiff</code> considers only the dependence of <var>expr</var> on <var>x</var>,
1246
and ignores any dependencies established by <code>depends</code>.
1251
<table><tr><td> </td><td><pre class="example">(%i1) expr: (4*x^3 + 10*x - 11)/(x^5 + 5);
1254
(%o1) ----------------
1257
(%i2) ratdiff (expr, x);
1259
8 x + 40 x - 55 x - 60 x - 50
1260
(%o2) - ---------------------------------
1263
(%i3) expr: f(x)^3 - f(x)^2 + 7;
1265
(%o3) f (x) - f (x) + 7
1266
(%i4) ratdiff (expr, f(x));
1268
(%o4) 3 f (x) - 2 f(x)
1269
(%i5) expr: (a + b)^3 + (a + b)^2;
1271
(%o5) (b + a) + (b + a)
1272
(%i6) ratdiff (expr, a + b);
1274
(%o6) 3 b + (6 a + 2) b + 3 a + 2 a
1275
</pre></td></tr></table>
1279
<dt><u>Function:</u> <b>ratdisrep</b><i> (<var>expr</var>)</i>
1280
<a name="IDX425"></a>
1282
<dd><p>Returns its argument as a general expression.
1283
If <var>expr</var> is a general expression, it is returned unchanged.
1285
<p>Typically <code>ratdisrep</code> is called to convert a canonical rational expression (CRE)
1286
into a general expression.
1287
This is sometimes convenient if one wishes to stop the "contagion", or
1288
use rational functions in non-rational contexts.
1290
<p>See also <code>totaldisrep</code>.
1295
<dt><u>Option variable:</u> <b>ratepsilon</b>
1296
<a name="IDX426"></a>
1298
<dd><p>Default value: 2.0e-8
1300
<p><code>ratepsilon</code> is the tolerance used in the conversion
1301
of floating point numbers to rational numbers.
1306
<dt><u>Function:</u> <b>ratexpand</b><i> (<var>expr</var>)</i>
1307
<a name="IDX427"></a>
1309
<dt><u>Option variable:</u> <b>ratexpand</b>
1310
<a name="IDX428"></a>
1312
<dd><p>Expands <var>expr</var> by multiplying out products of sums and
1313
exponentiated sums, combining fractions over a common denominator,
1314
cancelling the greatest common divisor of the numerator and
1315
denominator, then splitting the numerator (if a sum) into its
1316
respective terms divided by the denominator.
1318
<p>The return value of <code>ratexpand</code> is a general expression,
1319
even if <var>expr</var> is a canonical rational expression (CRE).
1321
<p>The switch <code>ratexpand</code> if <code>true</code> will cause CRE
1322
expressions to be fully expanded when they are converted back to
1323
general form or displayed, while if it is <code>false</code> then they will be put
1324
into a recursive form.
1325
See also <code>ratsimp</code>.
1327
<p>When <code>ratdenomdivide</code> is <code>true</code>,
1328
<code>ratexpand</code> expands a ratio in which the numerator is a sum
1329
into a sum of ratios,
1330
all having a common denominator.
1331
Otherwise, <code>ratexpand</code> collapses a sum of ratios into a single ratio,
1332
the numerator of which is the sum of the numerators of each ratio.
1334
<p>When <code>keepfloat</code> is <code>true</code>, prevents floating
1335
point numbers from being rationalized when expressions which contain
1336
them are converted to canonical rational expression (CRE) form.
1340
<table><tr><td> </td><td><pre class="example">(%i1) ratexpand ((2*x - 3*y)^3);
1342
(%o1) - 27 y + 54 x y - 36 x y + 8 x
1343
(%i2) expr: (x - 1)/(x + 1)^2 + 1/(x - 1);
1345
(%o2) -------- + -----
1348
(%i3) expand (expr);
1350
(%o3) ------------ - ------------ + -----
1352
x + 2 x + 1 x + 2 x + 1
1353
(%i4) ratexpand (expr);
1356
(%o4) --------------- + ---------------
1358
x + x - x - 1 x + x - x - 1
1359
</pre></td></tr></table>
1363
<dt><u>Option variable:</u> <b>ratfac</b>
1364
<a name="IDX429"></a>
1366
<dd><p>Default value: <code>false</code>
1368
<p>When <code>ratfac</code> is <code>true</code>,
1369
canonical rational expressions (CRE) are manipulated in a partially factored form.
1371
<p>During rational operations the
1372
expression is maintained as fully factored as possible without calling <code>factor</code>.
1373
This should always save space and may save time in some computations.
1374
The numerator and denominator are made relatively prime, for example
1375
<code>rat ((x^2 - 1)^4/(x + 1)^2)</code> yields <code>(x - 1)^4 (x + 1)^2)</code>,
1376
but the factors within each part may not be relatively prime.
1378
<p>In the <code>ctensr</code> (Component Tensor Manipulation) package,
1379
Ricci, Einstein, Riemann, and Weyl tensors and the scalar curvature
1380
are factored automatically when <code>ratfac</code> is <code>true</code>.
1381
<i><code>ratfac</code> should only be
1382
set for cases where the tensorial components are known to consist of
1385
<p>The <code>ratfac</code> and <code>ratweight</code> schemes are incompatible and may not
1386
both be used at the same time.
1391
<dt><u>Function:</u> <b>ratnumer</b><i> (<var>expr</var>)</i>
1392
<a name="IDX430"></a>
1394
<dd><p>Returns the numerator of <var>expr</var>,
1395
after coercing <var>expr</var> to a canonical rational expression (CRE).
1396
The return value is a CRE.
1398
<p><var>expr</var> is coerced to a CRE by <code>rat</code>
1399
if it is not already a CRE.
1400
This conversion may change the form of <var>expr</var> by putting all terms
1401
over a common denominator.
1403
<p><code>num</code> is similar, but returns an ordinary expression instead of a CRE.
1404
Also, <code>num</code> does not attempt to place all terms over a common denominator,
1405
and thus some expressions which are considered ratios by <code>ratnumer</code>
1406
are not considered ratios by <code>num</code>.
1411
<dt><u>Function:</u> <b>ratnump</b><i> (<var>expr</var>)</i>
1412
<a name="IDX431"></a>
1414
<dd><p>Returns <code>true</code> if <var>expr</var> is a literal integer or ratio of literal integers,
1415
otherwise <code>false</code>.
1420
<dt><u>Function:</u> <b>ratp</b><i> (<var>expr</var>)</i>
1421
<a name="IDX432"></a>
1423
<dd><p>Returns <code>true</code> if <var>expr</var> is a canonical rational expression (CRE) or extended CRE,
1424
otherwise <code>false</code>.
1426
<p>CRE are created by <code>rat</code> and related functions.
1427
Extended CRE are created by <code>taylor</code> and related functions.
1432
<dt><u>Option variable:</u> <b>ratprint</b>
1433
<a name="IDX433"></a>
1435
<dd><p>Default value: <code>true</code>
1437
<p>When <code>ratprint</code> is <code>true</code>,
1438
a message informing the user of the conversion of floating point numbers
1439
to rational numbers is displayed.
1444
<dt><u>Function:</u> <b>ratsimp</b><i> (<var>expr</var>)</i>
1445
<a name="IDX434"></a>
1447
<dt><u>Function:</u> <b>ratsimp</b><i> (<var>expr</var>, <var>x_1</var>, ..., <var>x_n</var>)</i>
1448
<a name="IDX435"></a>
1450
<dd><p>Simplifies the expression <var>expr</var> and all of its subexpressions,
1451
including the arguments to non-rational functions.
1452
The result is returned as the quotient of two polynomials in a recursive form,
1453
that is, the coefficients of the main variable are polynomials in the other variables.
1454
Variables may include non-rational functions (e.g., <code>sin (x^2 + 1)</code>)
1455
and the arguments to any such functions are also rationally simplified.
1457
<p><code>ratsimp (<var>expr</var>, <var>x_1</var>, ..., <var>x_n</var>)</code>
1458
enables rational simplification with the
1459
specification of variable ordering as in <code>ratvars</code>.
1461
<p>When <code>ratsimpexpons</code> is <code>true</code>,
1462
<code>ratsimp</code> is applied to the exponents of expressions during simplification.
1464
<p>See also <code>ratexpand</code>.
1465
Note that <code>ratsimp</code> is affected by some of the
1466
flags which affect <code>ratexpand</code>.
1470
<table><tr><td> </td><td><pre class="example">(%i1) sin (x/(x^2 + x)) = exp ((log(x) + 1)^2 - log(x)^2);
1472
x (log(x) + 1) - log (x)
1473
(%o1) sin(------) = %e
1478
(%o2) sin(-----) = %e x
1480
(%i3) ((x - 1)^(3/2) - (x + 1)*sqrt(x - 1))/sqrt((x - 1)*(x + 1));
1482
(x - 1) - sqrt(x - 1) (x + 1)
1483
(%o3) --------------------------------
1484
sqrt((x - 1) (x + 1))
1487
(%o4) - -------------
1490
(%i5) x^(a + 1/a), ratsimpexpons: true;
1496
</pre></td></tr></table>
1500
<dt><u>Option variable:</u> <b>ratsimpexpons</b>
1501
<a name="IDX436"></a>
1503
<dd><p>Default value: <code>false</code>
1505
<p>When <code>ratsimpexpons</code> is <code>true</code>,
1506
<code>ratsimp</code> is applied to the exponents of expressions during simplification.
1511
<dt><u>Function:</u> <b>ratsubst</b><i> (<var>a</var>, <var>b</var>, <var>c</var>)</i>
1512
<a name="IDX437"></a>
1514
<dd><p>Substitutes <var>a</var> for <var>b</var> in <var>c</var> and returns the resulting expression.
1515
<var>b</var> may be a sum, product, power, etc.
1517
<p><code>ratsubst</code> knows something of the meaning of expressions
1518
whereas <code>subst</code> does a purely syntactic substitution.
1519
Thus <code>subst (a, x + y, x + y + z)</code> returns <code>x + y + z</code>
1520
whereas <code>ratsubst</code> returns <code>z + a</code>.
1522
<p>When <code>radsubstflag</code> is <code>true</code>,
1523
<code>ratsubst</code> makes substitutions for radicals in expressions
1524
which don't explicitly contain them.
1528
<table><tr><td> </td><td><pre class="example">(%i1) ratsubst (a, x*y^2, x^4*y^3 + x^4*y^8);
1531
(%i2) cos(x)^4 + cos(x)^3 + cos(x)^2 + cos(x) + 1;
1533
(%o2) cos (x) + cos (x) + cos (x) + cos(x) + 1
1534
(%i3) ratsubst (1 - sin(x)^2, cos(x)^2, %);
1536
(%o3) sin (x) - 3 sin (x) + cos(x) (2 - sin (x)) + 3
1537
(%i4) ratsubst (1 - cos(x)^2, sin(x)^2, sin(x)^4);
1539
(%o4) cos (x) - 2 cos (x) + 1
1540
(%i5) radsubstflag: false$
1541
(%i6) ratsubst (u, sqrt(x), x);
1543
(%i7) radsubstflag: true$
1544
(%i8) ratsubst (u, sqrt(x), x);
1547
</pre></td></tr></table>
1551
<dt><u>Function:</u> <b>ratvars</b><i> (<var>x_1</var>, ..., <var>x_n</var>)</i>
1552
<a name="IDX438"></a>
1554
<dt><u>Function:</u> <b>ratvars</b><i> ()</i>
1555
<a name="IDX439"></a>
1557
<dt><u>System variable:</u> <b>ratvars</b>
1558
<a name="IDX440"></a>
1560
<dd><p>Declares main variables <var>x_1</var>, ..., <var>x_n</var> for rational expressions.
1561
<var>x_n</var>, if present in a rational expression, is considered the main variable.
1562
Otherwise, <var>x_[n-1]</var> is considered the main variable if present,
1563
and so on through the preceding variables to <var>x_1</var>,
1564
which is considered the main variable only if none of the succeeding variables are present.
1566
<p>If a variable in a rational expression is not present in the <code>ratvars</code> list,
1567
it is given a lower priority than <var>x_1</var>.
1569
<p>The arguments to <code>ratvars</code> can be either variables or non-rational functions
1570
such as <code>sin(x)</code>.
1572
<p>The variable <code>ratvars</code> is a list of the arguments of
1573
the function <code>ratvars</code> when it was called most recently.
1574
Each call to the function <code>ratvars</code> resets the list.
1575
<code>ratvars ()</code> clears the list.
1580
<dt><u>Function:</u> <b>ratweight</b><i> (<var>x_1</var>, <var>w_1</var>, ..., <var>x_n</var>, <var>w_n</var>)</i>
1581
<a name="IDX441"></a>
1583
<dt><u>Function:</u> <b>ratweight</b><i> ()</i>
1584
<a name="IDX442"></a>
1586
<dd><p>Assigns a weight <var>w_i</var> to the variable <var>x_i</var>.
1587
This causes a term to be replaced by 0 if its weight exceeds the
1588
value of the variable <code>ratwtlvl</code> (default yields no truncation).
1589
The weight of a term is the sum of the products of the
1590
weight of a variable in the term times its power.
1591
For example, the weight of <code>3 x_1^2 x_2</code> is <code>2 w_1 + w_2</code>.
1592
Truncation according to <code>ratwtlvl</code> is carried out only when multiplying
1593
or exponentiating canonical rational expressions (CRE).
1595
<p><code>ratweight ()</code> returns the cumulative list of weight assignments.
1597
<p>Note: The <code>ratfac</code> and <code>ratweight</code> schemes are incompatible and may not
1598
both be used at the same time.
1602
<table><tr><td> </td><td><pre class="example">(%i1) ratweight (a, 1, b, 1);
1604
(%i2) expr1: rat(a + b + 1)$
1607
(%o3)/R/ b + (2 a + 2) b + a + 2 a + 1
1610
(%o5)/R/ 2 b + 2 a + 1
1611
</pre></td></tr></table>
1615
<dt><u>System variable:</u> <b>ratweights</b>
1616
<a name="IDX443"></a>
1618
<dd><p>Default value: <code>[]</code>
1620
<p><code>ratweights</code> is the list of weights assigned by <code>ratweight</code>.
1621
The list is cumulative:
1622
each call to <code>ratweight</code> places additional items in the list.
1624
<p><code>kill (ratweights)</code> and <code>save (ratweights)</code> both work as expected.
1629
<dt><u>Option variable:</u> <b>ratwtlvl</b>
1630
<a name="IDX444"></a>
1632
<dd><p>Default value: <code>false</code>
1634
<p><code>ratwtlvl</code> is used in combination with the <code>ratweight</code>
1635
function to control the truncation of canonical rational expressions (CRE).
1636
For the default value of <code>false</code>, no truncation occurs.
1641
<dt><u>Function:</u> <b>remainder</b><i> (<var>p_1</var>, <var>p_2</var>)</i>
1642
<a name="IDX445"></a>
1644
<dt><u>Function:</u> <b>remainder</b><i> (<var>p_1</var>, <var>p_2</var>, <var>x_1</var>, ..., <var>x_n</var>)</i>
1645
<a name="IDX446"></a>
1647
<dd><p>Returns the remainder of the polynomial <var>p_1</var> divided by the polynomial <var>p_2</var>.
1648
The arguments <var>x_1</var>, ..., <var>x_n</var> are interpreted as in <code>ratvars</code>.
1650
<p><code>remainder</code> returns the second element
1651
of the two-element list returned by <code>divide</code>.
1656
<dt><u>Function:</u> <b>resultant</b><i> (<var>p_1</var>, <var>p_2</var>, <var>x</var>)</i>
1657
<a name="IDX447"></a>
1659
<dt><u>Variable:</u> <b>resultant</b>
1660
<a name="IDX448"></a>
1662
<dd><p>Computes the resultant of the two polynomials <var>p_1</var> and <var>p_2</var>,
1663
eliminating the variable <var>x</var>.
1664
The resultant is a determinant of the coefficients of <var>x</var>
1665
in <var>p_1</var> and <var>p_2</var>,
1667
if and only if <var>p_1</var> and <var>p_2</var> have a non-constant factor in common.
1669
<p>If <var>p_1</var> or <var>p_2</var> can be factored,
1670
it may be desirable to call <code>factor</code> before calling <code>resultant</code>.
1672
<p>The variable <code>resultant</code> controls which algorithm will be used to compute
1674
<code>subres</code> for subresultant prs,
1675
<code>mod</code> for modular resultant algorithm,
1676
and <code>red</code> for reduced prs.
1677
On most problems <code>subres</code> should be best.
1678
On some large degree univariate or bivariate problems <code>mod</code> may be better.
1680
<p>The function <code>bezout</code> takes the same arguments as <code>resultant</code> and returns
1681
a matrix. The determinant of the return value is the desired resultant.
1686
<dt><u>Option variable:</u> <b>savefactors</b>
1687
<a name="IDX449"></a>
1689
<dd><p>Default value: <code>false</code>
1691
<p>When <code>savefactors</code> is <code>true</code>, causes the factors of an
1692
expression which is a product of factors to be saved by certain
1693
functions in order to speed up later factorizations of expressions
1694
containing some of the same factors.
1699
<dt><u>Function:</u> <b>sqfr</b><i> (<var>expr</var>)</i>
1700
<a name="IDX450"></a>
1702
<dd><p>is similar to <code>factor</code> except that the polynomial factors are "square-free."
1703
That is, they have factors only of degree one.
1704
This algorithm, which is also used by the first stage of <code>factor</code>, utilizes
1705
the fact that a polynomial has in common with its n'th derivative all
1706
its factors of degree greater than n. Thus by taking greatest common divisors
1707
with the polynomial of
1708
the derivatives with respect to each variable in the polynomial, all
1709
factors of degree greater than 1 can be found.
1713
<table><tr><td> </td><td><pre class="example">(%i1) sqfr (4*x^4 + 4*x^3 - 3*x^2 - 4*x - 1);
1715
(%o1) (2 x + 1) (x - 1)
1716
</pre></td></tr></table>
1720
<dt><u>Function:</u> <b>tellrat</b><i> (<var>p_1</var>, ..., <var>p_n</var>)</i>
1721
<a name="IDX451"></a>
1723
<dt><u>Function:</u> <b>tellrat</b><i> ()</i>
1724
<a name="IDX452"></a>
1726
<dd><p>Adds to the ring of algebraic integers known to Maxima
1727
the elements which are the solutions of the polynomials <var>p_1</var>, ..., <var>p_n</var>.
1728
Each argument <var>p_i</var> is a polynomial with integer coefficients.
1730
<p><code>tellrat (<var>x</var>)</code> effectively means substitute 0 for <var>x</var> in rational
1733
<p><code>tellrat ()</code> returns a list of the current substitutions.
1735
<p><code>algebraic</code> must be set to <code>true</code> in order for the simplification of
1736
algebraic integers to take effect.
1738
<p>Maxima initially knows about the imaginary unit <code>%i</code>
1739
and all roots of integers.
1741
<p>There is a command <code>untellrat</code> which takes kernels and
1742
removes <code>tellrat</code> properties.
1744
<p>When <code>tellrat</code>'ing a multivariate
1745
polynomial, e.g., <code>tellrat (x^2 - y^2)</code>, there would be an ambiguity as to
1746
whether to substitute <code><var>y</var>^2</code> for <code><var>x</var>^2</code>
1748
Maxima picks a particular ordering, but if the user wants to specify which, e.g.
1749
<code>tellrat (y^2 = x^2)</code> provides a syntax which says replace
1750
<code><var>y</var>^2</code> by <code><var>x</var>^2</code>.
1755
<table><tr><td> </td><td><pre class="example">(%i1) 10*(%i + 1)/(%i + 3^(1/3));
1760
(%i2) ev (ratdisrep (rat(%)), algebraic);
1762
(%o2) (4 3 - 2 3 - 4) %i + 2 3 + 4 3 - 2
1763
(%i3) tellrat (1 + a + a^2);
1766
(%i4) 1/(a*sqrt(2) - 1) + a/(sqrt(3) + sqrt(2));
1768
(%o4) ------------- + -----------------
1769
sqrt(2) a - 1 sqrt(3) + sqrt(2)
1770
(%i5) ev (ratdisrep (rat(%)), algebraic);
1771
(7 sqrt(3) - 10 sqrt(2) + 2) a - 2 sqrt(2) - 1
1772
(%o5) ----------------------------------------------
1774
(%i6) tellrat (y^2 = x^2);
1776
(%o6) [y - x , a + a + 1]
1777
</pre></td></tr></table>
1781
<dt><u>Function:</u> <b>totaldisrep</b><i> (<var>expr</var>)</i>
1782
<a name="IDX453"></a>
1784
<dd><p>Converts every subexpression of <var>expr</var> from canonical rational expressions (CRE) to
1785
general form and returns the result.
1786
If <var>expr</var> is itself in CRE form then <code>totaldisrep</code> is identical to
1787
<code>ratdisrep</code>.
1789
<p><code>totaldisrep</code> may be useful for
1790
ratdisrepping expressions such as equations, lists, matrices, etc., which
1791
have some subexpressions in CRE form.
1796
<dt><u>Function:</u> <b>untellrat</b><i> (<var>x_1</var>, ..., <var>x_n</var>)</i>
1797
<a name="IDX454"></a>
1799
<dd><p>Removes <code>tellrat</code> properties from <var>x_1</var>, ..., <var>x_n</var>.
1804
<table cellpadding="1" cellspacing="1" border="0">
1805
<tr><td valign="middle" align="left">[<a href="#SEC44" title="Beginning of this chapter or previous chapter"> << </a>]</td>
1806
<td valign="middle" align="left">[<a href="maxima_13.html#SEC47" title="Next chapter"> >> </a>]</td>
1807
<td valign="middle" align="left"> </td>
1808
<td valign="middle" align="left"> </td>
1809
<td valign="middle" align="left"> </td>
1810
<td valign="middle" align="left"> </td>
1811
<td valign="middle" align="left"> </td>
1812
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
1813
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
1814
<td valign="middle" align="left">[<a href="maxima_72.html#SEC264" title="Index">Index</a>]</td>
1815
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
1819
This document was generated by <em>Robert Dodier</em> on <em>September, 20 2006</em> using <a href="http://texi2html.cvshome.org/"><em>texi2html 1.76</em></a>.