1 @c FOR THE FUNCTIONS WHICH RETURN A CRE, BE SURE TO MENTION THAT
3 * Introduction to Polynomials::
4 * Functions and Variables for Polynomials::
7 @c -----------------------------------------------------------------------------
8 @node Introduction to Polynomials, Functions and Variables for Polynomials
9 @section Introduction to Polynomials
10 @c -----------------------------------------------------------------------------
12 Polynomials are stored in Maxima either in General Form or as Canonical
13 Rational Expressions (CRE) form. The latter is a standard form, and is
14 used internally by operations such as @mref{factor}, @mref{ratsimp}, and
17 Canonical Rational Expressions constitute a kind of representation
18 which is especially suitable for expanded polynomials and rational
19 functions (as well as for partially factored polynomials and rational
20 functions when @mref{ratfac} is set to @code{true}). In this CRE form an
21 ordering of variables (from most to least main) is assumed for each
24 Polynomials are represented recursively by a list consisting of the main
25 variable followed by a series of pairs of expressions, one for each term
26 of the polynomial. The first member of each pair is the exponent of the
27 main variable in that term and the second member is the coefficient of
28 that term which could be a number or a polynomial in another variable
29 again represented in this form. Thus the principal part of the CRE form
30 of @code{3*x^2-1} is @code{(X 2 3 0 -1)} and that of @code{2*x*y+x-3}
31 is @code{(Y 1 (X 1 2) 0 (X 1 1 0 -3))} assuming @code{y} is the main
32 variable, and is @code{(X 1 (Y 1 2 0 1) 0 -3)} assuming @code{x} is the
33 main variable. "Main"-ness is usually determined by reverse alphabetical
36 The "variables" of a CRE expression needn't be atomic. In fact any
37 subexpression whose main operator is not @code{+}, @code{-}, @code{*},
38 @code{/} or @code{^} with integer power will be considered a "variable"
39 of the expression (in CRE form) in which it occurs. For example the CRE
40 variables of the expression @code{x+sin(x+1)+2*sqrt(x)+1} are @code{x},
41 @code{sqrt(X)}, and @code{sin(x+1)}. If the user does not specify an
42 ordering of variables by using the @mref{ratvars} function Maxima will
43 choose an alphabetic one.
45 In general, CRE's represent rational expressions, that is, ratios of
46 polynomials, where the numerator and denominator have no common factors,
47 and the denominator is positive. The internal form is essentially a pair
48 of polynomials (the numerator and denominator) preceded by the variable
49 ordering list. If an expression to be displayed is in CRE form or if it
50 contains any subexpressions in CRE form, the symbol @code{/R/} will follow the
53 @c TODO: An example of some code that yields the /R/ form.
55 See the @mref{rat} function for converting an expression to CRE form.
57 An extended CRE form is used for the representation of Taylor
58 series. The notion of a rational expression is extended so that the
59 exponents of the variables can be positive or negative rational numbers
60 rather than just positive integers and the coefficients can themselves
61 be rational expressions as described above rather than just polynomials.
62 These are represented internally by a recursive polynomial form which is
63 similar to and is a generalization of CRE form, but carries additional
64 information such as the degree of truncation. As with CRE form, the
65 symbol @code{/T/} follows the line label of such expressions.
67 @c TODO: An example of some code that yields the /T/ form.
69 @opencatbox{Categories:}
70 @category{Polynomials}
71 @category{Rational expressions}
74 @c end concepts Polynomials
76 @c -----------------------------------------------------------------------------
77 @node Functions and Variables for Polynomials, , Introduction to Polynomials
78 @section Functions and Variables for Polynomials
79 @c -----------------------------------------------------------------------------
81 @c -----------------------------------------------------------------------------
83 @defvr {Option variable} algebraic
84 Default value: @code{false}
86 @code{algebraic} must be set to @code{true} in order for the simplification of
87 algebraic integers to take effect.
89 @opencatbox{Categories:}
90 @category{Simplification flags and variables}
95 @c -----------------------------------------------------------------------------
96 @defvr {Option variable} berlefact
97 Default value: @code{true}
99 When @code{berlefact} is @code{false} then the Kronecker factoring
100 algorithm will be used otherwise the Berlekamp algorithm, which is the
101 default, will be used.
103 @opencatbox{Categories:}
104 @category{Polynomials}
108 @c WHAT IS THIS ABOUT EXACTLY ??
110 @c -----------------------------------------------------------------------------
112 @deffn {Function} bezout (@var{p1}, @var{p2}, @var{x})
114 an alternative to the @mref{resultant} command. It
115 returns a matrix. @code{determinant} of this matrix is the desired resultant.
120 @c bezout(a*x+b, c*x^2+d, x);
122 @c resultant(a*x+b, c*x^2+d, x);
125 (%i1) bezout(a*x+b, c*x^2+d, x);
129 (%i2) determinant(%);
132 (%i3) resultant(a*x+b, c*x^2+d, x);
136 @opencatbox{Categories:}
137 @category{Polynomials}
141 @c REWORD THIS ITEM -- COULD BE MORE CONCISE
143 @c -----------------------------------------------------------------------------
145 @deffn {Function} bothcoef (@var{expr}, @var{x})
147 Returns a list whose first member is the coefficient of @var{x} in @var{expr}
148 (as found by @code{ratcoef} if @var{expr} is in CRE form
149 otherwise by @code{coeff}) and whose second member is the remaining part of
150 @var{expr}. That is, @code{[A, B]} where @code{@var{expr} = A*@var{x} + B}.
155 @c islinear (expr, x) := block ([c],
156 @c c: bothcoef (rat (expr, x), x),
157 @c is (freeof (x, c) and c[1] # 0))$
158 @c islinear ((r^2 - (x - r)^2)/x, x);
161 (%i1) islinear (expr, x) := block ([c],
162 c: bothcoef (rat (expr, x), x),
163 is (freeof (x, c) and c[1] # 0))$
164 (%i2) islinear ((r^2 - (x - r)^2)/x, x);
168 @opencatbox{Categories:}
169 @category{Polynomials}
173 @c -----------------------------------------------------------------------------
174 @deffn {Function} coeff @
175 @fname{coeff} (@var{expr}, @var{x}, @var{n}) @
176 @fname{coeff} (@var{expr}, @var{x})
178 Returns the coefficient of @code{@var{x}^@var{n}} in @var{expr},
179 where @var{expr} is a polynomial or a monomial term in @var{x}.
180 Other than @mref{ratcoef} @code{coeff} is a strictly syntactical
181 operation and will only find literal instances of
182 @code{@var{x}^@var{n}} in the internal representation of @var{expr}.
184 @code{coeff(@var{expr}, @var{x}^@var{n})} is equivalent
185 to @code{coeff(@var{expr}, @var{x}, @var{n})}.
186 @code{coeff(@var{expr}, @var{x}, 0)} returns the remainder of @var{expr}
187 which is free of @var{x}.
188 If omitted, @var{n} is assumed to be 1.
190 @var{x} may be a simple variable or a subscripted variable,
191 or a subexpression of @var{expr} which
192 comprises an operator and all of its arguments.
194 It may be possible to compute coefficients of expressions which are equivalent
195 to @var{expr} by applying @code{expand} or @code{factor}. @code{coeff} itself
196 does not apply @code{expand} or @code{factor} or any other function.
198 @code{coeff} distributes over lists, matrices, and equations.
200 See also @mrefdot{ratcoef}
204 @code{coeff} returns the coefficient @code{@var{x}^@var{n}} in @var{expr}.
207 @c coeff (b^3*a^3 + b^2*a^2 + b*a + 1, a^3);
211 (%i1) coeff (b^3*a^3 + b^2*a^2 + b*a + 1, a^3);
217 @code{coeff(@var{expr}, @var{x}^@var{n})} is equivalent
218 to @code{coeff(@var{expr}, @var{x}, @var{n})}.
221 @c coeff (c[4]*z^4 - c[3]*z^3 - c[2]*z^2 + c[1]*z, z, 3);
222 @c coeff (c[4]*z^4 - c[3]*z^3 - c[2]*z^2 + c[1]*z, z^3);
226 (%i1) coeff (c[4]*z^4 - c[3]*z^3 - c[2]*z^2 + c[1]*z, z, 3);
231 (%i2) coeff (c[4]*z^4 - c[3]*z^3 - c[2]*z^2 + c[1]*z, z^3);
237 @code{coeff(@var{expr}, @var{x}, 0)} returns the remainder of @var{expr}
238 which is free of @var{x}.
241 @c coeff (a*u + b^2*u^2 + c^3*u^3, b, 0);
245 (%i1) coeff (a*u + b^2*u^2 + c^3*u^3, b, 0);
251 @var{x} may be a simple variable or a subscripted variable,
252 or a subexpression of @var{expr} which
253 comprises an operator and all of its arguments.
256 @c coeff (h^4 - 2*%pi*h^2 + 1, h, 2);
257 @c coeff (v[1]^4 - 2*%pi*v[1]^2 + 1, v[1], 2);
258 @c coeff (sin(1+x)*sin(x) + sin(1+x)^3*sin(x)^3, sin(1+x)^3);
259 @c coeff ((d - a)^2*(b + c)^3 + (a + b)^4*(c - d), a + b, 4);
263 (%i1) coeff (h^4 - 2*%pi*h^2 + 1, h, 2);
267 (%i2) coeff (v[1]^4 - 2*%pi*v[1]^2 + 1, v[1], 2);
271 (%i3) coeff (sin(1+x)*sin(x) + sin(1+x)^3*sin(x)^3, sin(1+x)^3);
276 (%i4) coeff ((d - a)^2*(b + c)^3 + (a + b)^4*(c - d), a + b, 4);
281 @code{coeff} itself does not apply @code{expand} or @code{factor} or any other
285 @c coeff (c*(a + b)^3, a);
286 @c expand (c*(a + b)^3);
288 @c coeff (b^3*c + 3*a*b^2*c + 3*a^2*b*c + a^3*c, (a + b)^3);
289 @c factor (b^3*c + 3*a*b^2*c + 3*a^2*b*c + a^3*c);
290 @c coeff (%, (a + b)^3);
294 (%i1) coeff (c*(a + b)^3, a);
298 (%i2) expand (c*(a + b)^3);
300 (%o2) b c + 3 a b c + 3 a b c + a c
308 (%i4) coeff (b^3*c + 3*a*b^2*c + 3*a^2*b*c + a^3*c, (a + b)^3);
312 (%i5) factor (b^3*c + 3*a*b^2*c + 3*a^2*b*c + a^3*c);
317 (%i6) coeff (%, (a + b)^3);
322 @code{coeff} distributes over lists, matrices, and equations.
325 @c coeff ([4*a, -3*a, 2*a], a);
326 @c coeff (matrix ([a*x, b*x], [-c*x, -d*x]), x);
327 @c coeff (a*u - b*v = 7*u + 3*v, u);
331 (%i1) coeff ([4*a, -3*a, 2*a], a);
335 (%i2) coeff (matrix ([a*x, b*x], [-c*x, -d*x]), x);
341 (%i3) coeff (a*u - b*v = 7*u + 3*v, u);
346 @opencatbox{Categories:}
347 @category{Polynomials}
351 @c -----------------------------------------------------------------------------
353 @deffn {Function} content (@var{p_1}, @var{x_1}, @dots{}, @var{x_n})
355 Returns a list whose first element is
356 the greatest common divisor of the coefficients of the terms of the
357 polynomial @var{p_1} in the variable @var{x_n} (this is the content) and whose
358 second element is the polynomial @var{p_1} divided by the content.
359 @c APPEARS TO WORK AS ADVERTISED -- ONLY x_n HAS ANY EFFECT ON THE RESULT
360 @c WHAT ARE THE OTHER VARIABLES x_1 THROUGH x_{n-1} FOR ??
365 @c content (2*x*y + 4*x^2*y^2, y);
368 (%i1) content (2*x*y + 4*x^2*y^2, y);
371 (%o1) [2 x, 2 x y + y]
375 @opencatbox{Categories:}
376 @category{Polynomials}
380 @c -----------------------------------------------------------------------------
382 @deffn {Function} denom (@var{expr})
384 Returns the denominator of the rational expression @var{expr}.
389 @c g1:(x+2)*(x+1)/((x+3)^2);
391 @c g2:sin(x)/10*cos(x)/y;
396 (%i1) g1:(x+2)*(x+1)/((x+3)^2);
398 (%o1) ---------------
408 (%i3) g2:sin(x)/10*cos(x)/y;
419 @opencatbox{Categories:}
420 @category{Expressions}
424 @c -----------------------------------------------------------------------------
426 @deffn {Function} divide (@var{p_1}, @var{p_2}, @var{x_1}, @dots{}, @var{x_n})
428 computes the quotient and remainder
429 of the polynomial @var{p_1} divided by the polynomial @var{p_2}, in a main
430 polynomial variable, @var{x_n}.
431 @c SPELL OUT THE PURPOSE OF THE OTHER VARIABLES
432 The other variables are as in the @code{ratvars} function.
433 The result is a list whose first element is the quotient
434 and whose second element is the remainder.
439 @c divide (x + y, x - y, x);
440 @c divide (x + y, x - y);
443 (%i1) divide (x + y, x - y, x);
445 (%i2) divide (x + y, x - y);
450 Note that @code{y} is the main variable in the second example.
452 @opencatbox{Categories:}
453 @category{Polynomials}
458 @c -----------------------------------------------------------------------------
459 @deffn {Function} eliminate ([@var{eqn_1}, @dots{}, @var{eqn_n}], [@var{x_1}, @dots{}, @var{x_k}])
461 Eliminates variables from equations (or expressions assumed equal to zero) by
462 taking successive resultants. This returns a list of @code{@var{n} - @var{k}}
463 expressions with the @var{k} variables @var{x_1}, @dots{}, @var{x_k} eliminated.
464 First @var{x_1} is eliminated yielding @code{@var{n} - 1} expressions, then
465 @code{x_2} is eliminated, etc. If @code{@var{k} = @var{n}} then a single
466 expression in a list is returned free of the variables @var{x_1}, @dots{},
467 @var{x_k}. In this case @code{solve} is called to solve the last resultant for
473 @c expr1: 2*x^2 + y*x + z;
474 @c expr2: 3*x + 5*y - z - 1;
475 @c expr3: z^2 + x - y^2 + 5;
476 @c eliminate ([expr3, expr2, expr1], [y, z]);
479 (%i1) expr1: 2*x^2 + y*x + z;
482 (%i2) expr2: 3*x + 5*y - z - 1;
483 (%o2) - z + 5 y + 3 x - 1
484 (%i3) expr3: z^2 + x - y^2 + 5;
487 (%i4) eliminate ([expr3, expr2, expr1], [y, z]);
489 (%o4) [7425 x - 1170 x + 1299 x + 12076 x + 22887 x
492 - 5154 x - 1291 x + 7688 x + 15376]
495 @opencatbox{Categories:}
496 @category{Polynomials}
497 @category{Algebraic equations}
501 @c -----------------------------------------------------------------------------
503 @deffn {Function} ezgcd (@var{p_1}, @var{p_2}, @var{p_3}, @dots{})
505 Returns a list whose first element is the greatest common divisor of the
506 polynomials @var{p_1}, @var{p_2}, @var{p_3}, @dots{} and whose remaining
507 elements are the polynomials divided by the greatest common divisor. This
508 always uses the @code{ezgcd} algorithm.
510 See also @mrefcomma{gcd} @mrefcomma{gcdex} @mrefcomma{gcdivide} and
515 The three polynomials have the greatest common divisor @code{2*x-3}. The
516 gcd is first calculated with the function @code{gcd} and then with the function
520 @c p1 : 6*x^3-17*x^2+14*x-3;
521 @c p2 : 4*x^4-14*x^3+12*x^2+2*x-3;
522 @c p3 : -8*x^3+14*x^2-x-3;
523 @c gcd(p1, gcd(p2, p3));
524 @c ezgcd(p1, p2, p3);
527 (%i1) p1 : 6*x^3-17*x^2+14*x-3;
529 (%o1) 6 x - 17 x + 14 x - 3
530 (%i2) p2 : 4*x^4-14*x^3+12*x^2+2*x-3;
532 (%o2) 4 x - 14 x + 12 x + 2 x - 3
533 (%i3) p3 : -8*x^3+14*x^2-x-3;
535 (%o3) - 8 x + 14 x - x - 3
537 (%i4) gcd(p1, gcd(p2, p3));
540 (%i5) ezgcd(p1, p2, p3);
542 (%o5) [2 x - 3, 3 x - 4 x + 1, 2 x - 4 x + 1, - 4 x + x + 1]
545 @opencatbox{Categories:}
546 @category{Polynomials}
550 @c -----------------------------------------------------------------------------
551 @defvr {Option variable} facexpand
552 Default value: @code{true}
554 @code{facexpand} controls whether the irreducible factors returned by
555 @code{factor} are in expanded (the default) or recursive (normal CRE) form.
557 @opencatbox{Categories:}
558 @category{Polynomials}
562 @c -----------------------------------------------------------------------------
564 @deffn {Function} factor @
565 @fname{factor} (@var{expr}) @
566 @fname{factor} (@var{expr}, @var{p})
568 Factors the expression @var{expr}, containing any number of variables or
569 functions, into factors irreducible over the integers.
570 @code{factor (@var{expr}, @var{p})} factors @var{expr} over the field of
571 rationals with an element adjoined whose minimum polynomial is @var{p}.
573 @code{factor} uses @mref{ifactors} function for factoring integers.
575 @mref{factorflag} if @code{false} suppresses the factoring of integer factors
576 of rational expressions.
578 @mref{dontfactor} may be set to a list of variables with respect to which
579 factoring is not to occur. (It is initially empty). Factoring also
580 will not take place with respect to any variables which are less
581 important (using the variable ordering assumed for CRE form) than
582 those on the @code{dontfactor} list.
584 @mref{savefactors} if @code{true} causes the factors of an expression which
585 is a product of factors to be saved by certain functions in order to
586 speed up later factorizations of expressions containing some of the
589 @mref{berlefact} if @code{false} then the Kronecker factoring algorithm will
590 be used otherwise the Berlekamp algorithm, which is the default, will
593 @mref{intfaclim} if @code{true} maxima will give up factorization of
594 integers if no factor is found after trial divisions and Pollard's rho
595 method. If set to @code{false} (this is the case when the user calls
596 @code{factor} explicitly), complete factorization of the integer will be
597 attempted. The user's setting of @code{intfaclim} is used for internal
598 calls to @code{factor}. Thus, @code{intfaclim} may be reset to prevent
599 Maxima from taking an inordinately long time factoring large integers.
601 @mref{factor_max_degree} if set to a positive integer @code{n} will
602 prevent certain polynomials from being factored if their degree in any
603 variable exceeds @code{n}.
605 See also @mref{collectterms} and @mref{sqfr}
610 @c factor (2^63 - 1);
611 @c factor (-8*y - 4*x + z^2*(2*y + x));
612 @c -1 - 2*x - x^2 + y^2 + 2*x*y^2 + x^2*y^2;
613 @c block ([dontfactor: [x]], factor (%/36/(1 + 2*y + y^2)));
614 @c factor (1 + %e^(3*x));
615 @c factor (1 + x^4, a^2 - 2);
616 @c factor (-y^2*z^2 - x*z^2 + x^2*y^2 + x^3);
617 @c (2 + x)/(3 + x)/(b + x)/(c + x)^2;
621 @c ratsimp ((x^5 - 1)/(x - 1));
623 @c factor (%th(2), %);
624 @c factor (1 + x^12);
625 @c factor (1 + x^99);
628 (%i1) factor (2^63 - 1);
630 (%o1) 7 73 127 337 92737 649657
631 (%i2) factor (-8*y - 4*x + z^2*(2*y + x));
632 (%o2) (2 y + x) (z - 2) (z + 2)
633 (%i3) -1 - 2*x - x^2 + y^2 + 2*x*y^2 + x^2*y^2;
635 (%o3) x y + 2 x y + y - x - 2 x - 1
636 (%i4) block ([dontfactor: [x]], factor (%/36/(1 + 2*y + y^2)));
639 (x + 2 x + 1) (y - 1)
640 (%o4) ----------------------
643 (%i5) factor (1 + %e^(3*x));
645 (%o5) (%e + 1) (%e - %e + 1)
646 (%i6) factor (1 + x^4, a^2 - 2);
648 (%o6) (x - a x + 1) (x + a x + 1)
649 (%i7) factor (-y^2*z^2 - x*z^2 + x^2*y^2 + x^3);
651 (%o7) - (y + x) (z - x) (z + x)
652 (%i8) (2 + x)/(3 + x)/(b + x)/(c + x)^2;
654 (%o8) ------------------------
656 (x + 3) (x + b) (x + c)
660 (%o9) (x + 2)/(x + (2 c + b + 3) x
663 + (c + (2 b + 6) c + 3 b) x + ((b + 3) c + 6 b c) x + 3 b c )
665 (%i10) partfrac (%, x);
667 (%o10) - (c - 4 c - b + 6)/((c + (- 2 b - 6) c
670 + (b + 12 b + 9) c + (- 6 b - 18 b) c + 9 b ) (x + c))
673 - ---------------------------------
675 (c + (- b - 3) c + 3 b) (x + c)
678 + -------------------------------------------------
680 ((b - 3) c + (6 b - 2 b ) c + b - 3 b ) (x + b)
683 - ----------------------------------------------
685 ((b - 3) c + (18 - 6 b) c + 9 b - 27) (x + 3)
686 (%i11) map ('factor, %);
689 c - 4 c - b + 6 c - 2
690 (%o11) - ------------------------- - ------------------------
692 (c - 3) (c - b) (x + c) (c - 3) (c - b) (x + c)
695 + ------------------------ - ------------------------
697 (b - 3) (c - b) (x + b) (b - 3) (c - 3) (x + 3)
699 (%i12) ratsimp ((x^5 - 1)/(x - 1));
701 (%o12) x + x + x + x + 1
702 (%i13) subst (a, x, %);
704 (%o13) a + a + a + a + 1
705 (%i14) factor (%th(2), %);
707 (%o14) (x - a) (x - a ) (x - a ) (x + a + a + a + 1)
708 (%i15) factor (1 + x^12);
710 (%o15) (x + 1) (x - x + 1)
711 (%i16) factor (1 + x^99);
713 (%o16) (x + 1) (x - x + 1) (x - x + 1)
716 (x - x + x - x + x - x + x - x + x - x + 1)
718 20 19 17 16 14 13 11 10 9 7 6
719 (x + x - x - x + x + x - x - x - x + x + x
721 4 3 60 57 51 48 42 39 33
722 - x - x + x + 1) (x + x - x - x + x + x - x
725 - x - x + x + x - x - x + x + 1)
728 @opencatbox{Categories:}
729 @category{Polynomials}
733 @anchor{factor_max_degree}
736 @c -----------------------------------------------------------------------------
737 @defvr {Option variable} factor_max_degree
738 Default value: @code{1000}
740 When factor_max_degree is set to a positive integer @code{n}, it will prevent
741 Maxima from attempting to factor certain polynomials whose degree in any
742 variable exceeds @code{n}. If @mref{factor_max_degree_print_warning} is true,
743 a warning message will be printed. @code{factor_max_degree} can be used to
744 prevent excessive memory usage and/or computation time and stack overflows.
745 Note that "obvious" factoring of polynomials such as @code{x^2000+x^2001} to
746 @code{x^2000*(x+1)} will still take place. To disable this behavior, set
747 @code{factor_max_degree} to @code{0}.
751 @c factor_max_degree : 100$
756 (%i1) factor_max_degree : 100$
758 (%i2) factor(x^100-1);
760 (%o2) (x - 1) (x + 1) (x + 1) (x - x + x - x + 1)
762 (x + x + x + x + 1) (x - x + x - x + 1)
763 20 15 10 5 20 15 10 5
764 (x - x + x - x + 1) (x + x + x + x + 1)
769 (%i3) factor(x^101-1);
771 Refusing to factor polynomial x - 1
772 because its degree exceeds factor_max_degree (100)
778 See also: @mref{factor_max_degree_print_warning}
780 @opencatbox{Categories:}
781 @category{Polynomials}
785 @anchor{factor_max_degree_print_warning}
786 @c -----------------------------------------------------------------------------
787 @defvr {Option variable} factor_max_degree_print_warning
788 Default value: @code{true}
790 When factor_max_degree_print_warning is true, then Maxima will print a
791 warning message when the factoring of a polynomial is prevented because
792 its degree exceeds the value of factor_max_degree.
794 See also: @mref{factor_max_degree}
796 @opencatbox{Categories:}
797 @category{Polynomials}
802 @c -----------------------------------------------------------------------------
803 @defvr {Option variable} factorflag
804 Default value: @code{false}
806 @c WHAT IS THIS ABOUT EXACTLY ??
807 When @code{factorflag} is @code{false}, suppresses the factoring of
808 integer factors of rational expressions.
810 @opencatbox{Categories:}
811 @category{Polynomials}
815 @c -----------------------------------------------------------------------------
817 @deffn {Function} factorout (@var{expr}, @var{x_1}, @var{x_2}, @dots{})
819 Rearranges the sum @var{expr} into a sum of terms of the form
820 @code{f (@var{x_1}, @var{x_2}, @dots{})*g} where @code{g} is a product of
821 expressions not containing any @var{x_i} and @code{f} is factored.
823 Note that the option variable @code{keepfloat} is ignored by @code{factorout}.
828 @c expand (a*(x+1)*(x-1)*(u+1)^2);
833 (%i1) expand (a*(x+1)*(x-1)*(u+1)^2);
835 (%o1) a u x + 2 a u x + a x - a u - 2 a u - a
838 (%i2) factorout(%,x);
840 (%o2) a u (x - 1) (x + 1) + 2 a u (x - 1) (x + 1)
845 @opencatbox{Categories:}
846 @category{Expressions}
850 @c -----------------------------------------------------------------------------
852 @deffn {Function} factorsum (@var{expr})
854 Tries to group terms in factors of @var{expr} which are sums into groups of
855 terms such that their sum is factorable. @code{factorsum} can recover the
856 result of @code{expand ((x + y)^2 + (z + w)^2)} but it can't recover
857 @code{expand ((x + 1)^2 + (x + y)^2)} because the terms have variables in
863 @c expand ((x + 1)*((u + v)^2 + a*(w + z)^2));
867 (%i1) expand ((x + 1)*((u + v)^2 + a*(w + z)^2));
869 (%o1) a x z + a z + 2 a w x z + 2 a w z + a w x + v x
872 + 2 u v x + u x + a w + v + 2 u v + u
875 (%o2) (x + 1) (a (z + w) + (v + u) )
878 @opencatbox{Categories:}
879 @category{Expressions}
883 @c -----------------------------------------------------------------------------
885 @deffn {Function} fasttimes (@var{p_1}, @var{p_2})
887 Returns the product of the polynomials @var{p_1} and @var{p_2} by using a
888 special algorithm for multiplication of polynomials. @code{p_1} and @code{p_2}
889 should be multivariate, dense, and nearly the same size. Classical
890 multiplication is of order @code{n_1 n_2} where
891 @code{n_1} is the degree of @code{p_1}
892 and @code{n_2} is the degree of @code{p_2}.
893 @code{fasttimes} is of order @code{max (n_1, n_2)^1.585}.
895 @opencatbox{Categories:}
896 @category{Polynomials}
900 @c -----------------------------------------------------------------------------
902 @deffn {Function} fullratsimp (@var{expr})
904 @code{fullratsimp} repeatedly
905 applies @code{ratsimp} followed by non-rational simplification to an
906 expression until no further change occurs,
907 and returns the result.
909 When non-rational expressions are involved, one call
910 to @code{ratsimp} followed as is usual by non-rational ("general")
911 simplification may not be sufficient to return a simplified result.
912 Sometimes, more than one such call may be necessary.
913 @code{fullratsimp} makes this process convenient.
915 @code{fullratsimp (@var{expr}, @var{x_1}, ..., @var{x_n})} takes one or more
916 arguments similar to @code{ratsimp} and @code{rat}.
921 @c expr: (x^(a/2) + 1)^2*(x^(a/2) - 1)^2/(x^a - 1);
923 @c fullratsimp (expr);
927 (%i1) expr: (x^(a/2) + 1)^2*(x^(a/2) - 1)^2/(x^a - 1);
930 (%o1) -----------------------
933 (%i2) ratsimp (expr);
936 (%o2) ---------------
939 (%i3) fullratsimp (expr);
945 (%o4)/R/ -----------------------
950 @opencatbox{Categories:}
951 @category{Simplification functions}
952 @category{Rational expressions}
956 @c -----------------------------------------------------------------------------
957 @anchor{fullratsubst}
958 @deffn {Function} fullratsubst (@var{new}, @var{old}, @var{expr}) @
959 @fname{fullratsubst} (@code{@var{old} = @var{new}}, @var{expr}) @
960 @fname{fullratsubst} (@code{[ @var{old_1} = @var{new_1}, @dots{}, @var{old_n} = @var{new_n} ]}, @var{expr})
962 @code{fullratsubst} applies @mref{lratsubst} repeatedly until @var{expr}
963 stops changing (or @mref{lrats_max_iter} is reached). This function is
964 useful when the replacement expression and the replaced expression have
965 one or more variables in common.
967 @code{fullratsubst} accepts its arguments in the format of
968 @mref{ratsubst} or @mref{lratsubst}.
970 @c EXPRESSIONS ADAPTED FROM demo ("lrats")
976 @code{subst} can carry out multiple substitutions.
977 @code{lratsubst} is analogous to @code{subst}.
980 @c subst ([a = b, c = d], a + c);
981 @c lratsubst ([a^2 = b, c^2 = d], (a + e)*c*(a + c));
984 (%i2) subst ([a = b, c = d], a + c);
986 (%i3) lratsubst ([a^2 = b, c^2 = d], (a + e)*c*(a + c));
987 (%o3) (d + a c) e + a d + b c
991 If only one substitution is desired, then a single
992 equation may be given as first argument.
995 @c lratsubst (a^2 = b, a^3);
998 (%i4) lratsubst (a^2 = b, a^3);
1003 @code{fullratsubst} is equivalent to @code{ratsubst}
1004 except that it recurses until its result stops changing.
1007 @c ratsubst (b*a, a^2, a^3);
1008 @c fullratsubst (b*a, a^2, a^3);
1011 (%i5) ratsubst (b*a, a^2, a^3);
1014 (%i6) fullratsubst (b*a, a^2, a^3);
1020 @code{fullratsubst} also accepts a list of equations or a single
1021 equation as first argument.
1024 @c fullratsubst ([a^2 = b, b^2 = c, c^2 = a], a^3*b*c);
1025 @c fullratsubst (a^2 = b*a, a^3);
1028 (%i7) fullratsubst ([a^2 = b, b^2 = c, c^2 = a], a^3*b*c);
1030 (%i8) fullratsubst (a^2 = b*a, a^3);
1036 @code{fullratsubst} catches potential infinite recursions. @ref{lrats_max_iter}.
1039 @c fullratsubst (b*a^2, a^2, a^3), lrats_max_iter=15;
1042 (%i9) fullratsubst (b*a^2, a^2, a^3), lrats_max_iter=15;
1043 Warning: fullratsubst1(substexpr,forexpr,expr): reached maximum iterations of 15 . Increase `lrats_max_iter' to increase this limit.
1048 See also @mref{lrats_max_iter} and @mref{fullratsubstflag}.
1050 @opencatbox{Categories:}
1051 @category{Rational expressions}
1055 @c FULLRATSUBSTFLAG was undocumented until 2020-01
1057 @c -----------------------------------------------------------------------------
1058 @anchor{fullratsubstflag}
1059 @defvr {Option variable} fullratsubstflag
1060 Default value: @code{false}
1062 An option variable that is set to @code{true} in @mref{fullratsubst}.
1064 @opencatbox{Categories:}
1065 @category{Polynomials}
1066 @category{Rational expressions}
1072 @c GCD IS A VARIABLE AND A FUNCTION
1073 @c THIS ITEM NEEDS A LOT OF WORK
1075 @c -----------------------------------------------------------------------------
1077 @deffn {Function} gcd (@var{p_1}, @var{p_2}, @var{x_1}, @dots{})
1079 Returns the greatest common divisor of @var{p_1} and @var{p_2}. The flag
1080 @code{gcd} determines which algorithm is employed. Setting @code{gcd} to
1081 @code{ez}, @code{subres}, @code{red}, or @code{spmod} selects the @code{ezgcd},
1082 subresultant @code{prs}, reduced, or modular algorithm, respectively. If
1083 @code{gcd} @code{false} then @code{gcd (@var{p_1}, @var{p_2}, @var{x})} always
1084 returns 1 for all @var{x}. Many functions (e.g. @mrefcomma{ratsimp}@w{}
1085 @mrefcomma{factor} etc.) cause gcd's to be taken implicitly. For homogeneous
1086 polynomials it is recommended that @code{gcd} equal to @code{subres} be used.
1087 To take the gcd when an algebraic is present, e.g.,
1088 @code{gcd (@var{x}^2 - 2*sqrt(2)* @var{x} + 2, @var{x} - sqrt(2))}, the option
1089 variable @mref{algebraic} must be @code{true} and @code{gcd} must not be
1092 The @code{gcd} flag, default: @code{spmod}, if @code{false} will also prevent
1093 the greatest common divisor from being taken when expressions are converted to
1094 canonical rational expression (CRE) form. This will sometimes speed the
1095 calculation if gcds are not required.
1097 See also @mrefcomma{ezgcd} @mrefcomma{gcdex} @mrefcomma{gcdivide} and
1103 @c p1:6*x^3+19*x^2+19*x+6;
1104 @c p2:6*x^5+13*x^4+12*x^3+13*x^2+6*x;
1106 @c p1/gcd(p1, p2), ratsimp;
1107 @c p2/gcd(p1, p2), ratsimp;
1110 (%i1) p1:6*x^3+19*x^2+19*x+6;
1112 (%o1) 6 x + 19 x + 19 x + 6
1113 (%i2) p2:6*x^5+13*x^4+12*x^3+13*x^2+6*x;
1115 (%o2) 6 x + 13 x + 12 x + 13 x + 6 x
1118 (%o3) 6 x + 13 x + 6
1119 (%i4) p1/gcd(p1, p2), ratsimp;
1121 (%i5) p2/gcd(p1, p2), ratsimp;
1126 @mref{ezgcd} returns a list whose first element is the greatest common divisor
1127 of the polynomials @var{p_1} and @var{p_2}, and whose remaining elements are
1128 the polynomials divided by the greatest common divisor.
1134 (%i6) ezgcd(p1, p2);
1136 (%o6) [6 x + 13 x + 6, x + 1, x + x]
1139 @opencatbox{Categories:}
1140 @category{Polynomials}
1141 @category{Rational expressions}
1145 @c IN NEED OF SERIOUS CLARIFICATION HERE
1147 @c -----------------------------------------------------------------------------
1149 @deffn {Function} gcdex @
1150 @fname{gcdex} (@var{f}, @var{g}) @
1151 @fname{gcdex} (@var{f}, @var{g}, @var{x})
1153 Returns a list @code{[@var{a}, @var{b}, @var{u}]} where @var{u} is the greatest
1154 common divisor (gcd) of @var{f} and @var{g}, and @var{u} is equal to
1155 @code{@var{a} @var{f} + @var{b} @var{g}}. The arguments @var{f} and @var{g}
1156 should be univariate polynomials, or else polynomials in @var{x} a supplied
1157 main variable since we need to be in a principal ideal domain for this to
1158 work. The gcd means the gcd regarding @var{f} and @var{g} as univariate
1159 polynomials with coefficients being rational functions in the other variables.
1161 @code{gcdex} implements the Euclidean algorithm, where we have a sequence of
1162 @code{L[i]: [a[i], b[i], r[i]]} which are all perpendicular to @code{[f, g, -1]}
1163 and the next one is built as if @code{q = quotient(r[i]/r[i+1])} then
1164 @code{L[i+2]: L[i] - q L[i+1]}, and it terminates at @code{L[i+1]} when the
1165 remainder @code{r[i+2]} is zero.
1167 The arguments @var{f} and @var{g} can be integers. For this case the function
1168 @mref{igcdex} is called by @code{gcdex}.
1170 See also @mrefcomma{ezgcd} @mrefcomma{gcd} @mrefcomma{gcdivide} and
1176 @c gcdex (x^2 + 1, x^3 + 4);
1177 @c % . [x^2 + 1, x^3 + 4, -1];
1181 (%i1) gcdex (x^2 + 1, x^3 + 4);
1184 (%o1)/R/ [- ------------, -----, 1]
1188 (%i2) % . [x^2 + 1, x^3 + 4, -1];
1193 @c SORRY FOR BEING DENSE BUT WHAT IS THIS ABOUT EXACTLY
1194 Note that the gcd in the following is @code{1} since we work in @code{k(y)[x]},
1195 not the @code{y+1} we would expect in @code{k[y, x]}.
1198 @c gcdex (x*(y + 1), y^2 - 1, x);
1202 (%i1) gcdex (x*(y + 1), y^2 - 1, x);
1204 (%o1)/R/ [0, ------, 1]
1210 @opencatbox{Categories:}
1211 @category{Polynomials}
1212 @category{Rational expressions}
1216 @c CHOOSE ONE CHARACTERIZATION OF "GAUSSIAN INTEGERS" AND USE IT WHERE GAUSSIAN INTEGERS ARE REFERENCED
1218 @c -----------------------------------------------------------------------------
1220 @deffn {Function} gcfactor (@var{n})
1222 Factors the Gaussian integer @var{n} over the Gaussian integers, i.e., numbers
1223 of the form @code{@var{a} + @var{b} @code{%i}} where @var{a} and @var{b} are
1224 rational integers (i.e., ordinary integers). Factors are normalized by making
1225 @var{a} and @var{b} non-negative.
1226 @c NEED EXAMPLES HERE
1228 @opencatbox{Categories:}
1233 @c CHOOSE ONE CHARACTERIZATION OF "GAUSSIAN INTEGERS" AND USE IT WHERE GAUSSIAN INTEGERS ARE REFERENCED
1235 @c -----------------------------------------------------------------------------
1237 @deffn {Function} gfactor (@var{expr})
1239 Factors the polynomial @var{expr} over the Gaussian integers
1240 (that is, the integers with the imaginary unit @code{%i} adjoined).
1241 @c "This is like" -- IS IT THE SAME OR NOT ??
1242 This is like @code{factor (@var{expr}, @var{a}^2+1)} where @var{a} is @code{%i}.
1247 @c gfactor (x^4 - 1);
1250 (%i1) gfactor (x^4 - 1);
1251 (%o1) (x - 1) (x + 1) (x - %i) (x + %i)
1254 @opencatbox{Categories:}
1255 @category{Polynomials}
1259 @c DESCRIBE THIS INDEPENDENTLY OF factorsum
1260 @c THIS ITEM NEEDS MORE WORK
1262 @c -----------------------------------------------------------------------------
1264 @deffn {Function} gfactorsum (@var{expr})
1266 is similar to @code{factorsum} but applies @code{gfactor} instead
1269 @opencatbox{Categories:}
1270 @category{Expressions}
1274 @c -----------------------------------------------------------------------------
1276 @deffn {Function} hipow (@var{expr}, @var{x})
1278 Returns the highest explicit exponent of @var{x} in @var{expr}.
1279 @var{x} may be a variable or a general expression.
1280 If @var{x} does not appear in @var{expr},
1281 @code{hipow} returns @code{0}.
1283 @code{hipow} does not consider expressions equivalent to @code{expr}. In
1284 particular, @code{hipow} does not expand @code{expr}, so
1285 @code{hipow (@var{expr}, @var{x})} and
1286 @code{hipow (expand (@var{expr}, @var{x}))} may yield different results.
1291 @c hipow (y^3 * x^2 + x * y^4, x);
1292 @c hipow ((x + y)^5, x);
1293 @c hipow (expand ((x + y)^5), x);
1294 @c hipow ((x + y)^5, x + y);
1295 @c hipow (expand ((x + y)^5), x + y);
1298 (%i1) hipow (y^3 * x^2 + x * y^4, x);
1300 (%i2) hipow ((x + y)^5, x);
1302 (%i3) hipow (expand ((x + y)^5), x);
1304 (%i4) hipow ((x + y)^5, x + y);
1306 (%i5) hipow (expand ((x + y)^5), x + y);
1310 @opencatbox{Categories:}
1311 @category{Expressions}
1315 @c I SUSPECT THE FOLLOWING TEXT IS OUTDATED DUE TO CHANGES IN INTEGER FACTORING CODE
1318 @c -----------------------------------------------------------------------------
1319 @defvr {Option variable} intfaclim
1322 If @code{true}, maxima will give up factorization of
1323 integers if no factor is found after trial divisions and Pollard's rho
1324 method and factorization will not be complete.
1326 When @code{intfaclim} is @code{false} (this is the case when the user
1327 calls @code{factor} explicitly), complete factorization will be
1328 attempted. @code{intfaclim} is set to @code{false} when factors are
1329 computed in @code{divisors}, @code{divsum} and @code{totient}.
1332 @c WHAT ARE THESE MYSTERIOUS INTERNAL CALLS ?? (LET'S JUST LIST THE FUNCTIONS INVOLVED)
1333 Internal calls to @code{factor} respect the user-specified value of
1334 @code{intfaclim}. Setting @code{intfaclim} to @code{true} may reduce
1335 the time spent factoring large integers.
1336 @c NEED EXAMPLES HERE
1338 @opencatbox{Categories:}
1343 @c -----------------------------------------------------------------------------
1344 @defvr {Option variable} keepfloat
1345 Default value: @code{false}
1347 When @code{keepfloat} is @code{true}, prevents floating
1348 point numbers from being rationalized when expressions which contain
1349 them are converted to canonical rational expression (CRE) form.
1351 Note that the function @code{solve} and those functions calling it
1352 (@code{eigenvalues}, for example) currently ignore this flag, converting
1353 floating point numbers anyway.
1359 @c rat(x/2.0), keepfloat;
1365 rat: replaced 0.5 by 1/2 = 0.5
1371 (%i2) rat(x/2.0), keepfloat;
1376 @code{solve} ignores @code{keepfloat}:
1379 @c solve(1.0-x,x), keepfloat;
1383 (%i1) solve(1.0-x,x), keepfloat;
1385 rat: replaced 1.0 by 1/1 = 1.0
1390 @opencatbox{Categories:}
1391 @category{Numerical evaluation}
1395 @c -----------------------------------------------------------------------------
1397 @deffn {Function} lopow (@var{expr}, @var{x})
1399 Returns the lowest exponent of @var{x} which explicitly appears in
1403 @c lopow ((x+y)^2 + (x+y)^a, x+y);
1406 (%i1) lopow ((x+y)^2 + (x+y)^a, x+y);
1410 @opencatbox{Categories:}
1411 @category{Expressions}
1415 @c DESCRIBE lratsubst INDEPENDENTLY OF subst
1416 @c THIS ITEM NEEDS MORE WORK
1418 @c -----------------------------------------------------------------------------
1420 @deffn {Function} lratsubst (@var{new}, @var{old}, @var{expr}) @
1421 @fname{lratsubst} (@code{@var{old} = @var{new}}, @var{expr}) @
1422 @fname{lratsubst} (@code{[ @var{old_1} = @var{new_1}, @dots{}, @var{old_n} = @var{new_n} ]}, @var{expr})
1424 @code{lratsubst} is analogous to @mref{subst} except that it uses
1425 @code{ratsubst} to perform substitutions.
1427 The first argument of @code{lratsubst} is an equation, a list of
1428 equations or a list of unit length whose first element is a list of
1429 equations (that is, the first argument is identical in format to that
1430 accepted by @code{subst}). The substitutions are made in the order given
1431 by the list of equations, that is, from left to right.
1435 @c EXPRESSIONS ADAPTED FROM demo ("lrats")
1436 @c THIS STUFF CAN PROBABLY STAND REVISION -- EXAMPLES DON'T SEEM VERY ENLIGHTENING
1440 @code{subst} can carry out multiple substitutions.
1441 @code{lratsubst} is analogous to @code{subst}.
1444 @c lratsubst ([a = b, c = d], a + c);
1445 @c lratsubst ([a^2 = b, c^2 = d], (a + e)*c*(a + c));
1448 (%i2) lratsubst ([a = b, c = d], a + c);
1450 (%i3) lratsubst ([a^2 = b, c^2 = d], (a + e)*c*(a + c));
1451 (%o3) (d + a c) e + a d + b c
1455 If only one substitution is desired, then a single
1456 equation may be given as first argument.
1459 @c lratsubst (a^2 = b, a^3);
1462 (%i4) lratsubst (a^2 = b, a^3);
1467 A nested list of substitutions can be used--but it must contain only one list.
1470 @c lratsubst ([[a^2=b*a, b=c]], a^3);
1471 @c lratsubst ([[a^2=b*a, b=c],[a=b]], a^3);
1474 (%i5) lratsubst ([[a^2=b*a, b=c]], a^3);
1478 (%i6) lratsubst ([[a^2=b*a, b=c],[a=b]], a^3);
1482 lratsubst: improper argument: [[a = a b, b = c], [a = b]]
1483 #0: lratsubst(listofeqns=[[a^2 = a*b,b = c],[a = b]],expr=a^3)
1484 -- an error. To debug this try: debugmode(true);
1488 See also @mref{fullratsubst}.
1490 @opencatbox{Categories:}
1491 @category{Polynomials}
1492 @category{Rational expressions}
1497 @c -----------------------------------------------------------------------------
1498 @anchor{lrats_max_iter}
1499 @defvr {Option variable} lrats_max_iter
1500 Default value: @code{100000}
1502 The upper limit on the number of iterations that @mref{fullratsubst} and
1503 @mref{lratsubst} may perform. It must be set to a positive integer. See
1504 the example for @mref{fullratsubst}.
1506 @opencatbox{Categories:}
1507 @category{Polynomials}
1508 @category{Rational expressions}
1513 @c -----------------------------------------------------------------------------
1515 @defvr {Option variable} modulus
1516 Default value: @code{false}
1518 When @code{modulus} is a positive number @var{p}, operations on canonical rational
1519 expressions (CREs, as returned by @code{rat} and related functions) are carried out
1520 modulo @var{p}, using the so-called "balanced" modulus system in which @code{@var{n}
1521 modulo @var{p}} is defined as an integer @var{k} in
1522 @code{[-(@var{p}-1)/2, ..., 0, ..., (@var{p}-1)/2]} when @var{p} is odd, or
1523 @code{[-(@var{p}/2 - 1), ..., 0, ...., @var{p}/2]} when @var{p} is even, such
1524 that @code{@var{a} @var{p} + @var{k}} equals @var{n} for some integer @var{a}.
1525 @c NEED EXAMPLES OF "BALANCED MODULUS" HERE
1527 @c WHAT CAN THIS MEAN ?? IS THE MODULUS STORED WITH THE EXPRESSION ??
1528 @c "... in order to get correct results" -- WHAT DO YOU GET IF YOU DON'T RE-RAT ??
1529 If @var{expr} is already in canonical rational expression (CRE) form when
1530 @code{modulus} is reset, then you may need to re-rat @var{expr}, e.g.,
1531 @code{expr: rat (ratdisrep (expr))}, in order to get correct results.
1533 Typically @code{modulus} is set to a prime number. If @code{modulus} is set to
1534 a positive non-prime integer, this setting is accepted, but a warning message is
1535 displayed. Maxima signals an error, when zero or a negative integer is
1536 assigned to @code{modulus}.
1542 @c polymod([0,1,2,3,4,5,6,7]);
1553 (%i2) polymod([0,1,2,3,4,5,6,7]);
1554 (%o2) [0, 1, 2, 3, - 3, - 2, - 1, 0]
1555 (%i3) modulus:false;
1557 (%i4) poly:x^6+x^2+1;
1567 (%o7) (x + 6) (x - 6 x - 2)
1572 @opencatbox{Categories:}
1577 @c APPARENTLY OBSOLETE: ONLY EFFECT OF $newfac COULD BE TO CAUSE NONEXISTENT FUNCTION NMULTFACT
1578 @c TO BE CALLED (IN FUNCTION FACTOR72 IN src/factor.lisp CIRCA LINE 1400)
1579 @c $newfac NOT USED IN ANY OTHER CONTEXT (ASIDE FROM DECLARATIONS)
1580 @c COMMENT IT OUT NOW, CUT IT ON THE NEXT PASS THROUGH THIS FILE
1582 @c Default value: @code{false}
1584 @c When @code{newfac} is @code{true}, @code{factor} will use the new factoring
1589 @c -----------------------------------------------------------------------------
1591 @deffn {Function} num (@var{expr})
1593 Returns the numerator of @var{expr} if it is a ratio.
1594 If @var{expr} is not a ratio, @var{expr} is returned.
1596 @code{num} evaluates its argument.
1598 See also @mref{denom}
1601 @c g1:(x+2)*(x+1)/((x+3)^2);
1603 @c g2:sin(x)/10*cos(x)/y;
1608 (%i1) g1:(x+2)*(x+1)/((x+3)^2);
1610 (%o1) ---------------
1616 (%o2) (x + 1) (x + 2)
1619 (%i3) g2:sin(x)/10*cos(x)/y;
1630 @c NEED SOME EXAMPLES HERE
1631 @opencatbox{Categories:}
1632 @category{Expressions}
1636 @c -----------------------------------------------------------------------------
1638 @deffn {Function} polydecomp (@var{p}, @var{x})
1640 Decomposes the polynomial @var{p} in the variable @var{x}
1641 into the functional composition of polynomials in @var{x}.
1642 @code{polydecomp} returns a list @code{[@var{p_1}, ..., @var{p_n}]} such that
1645 lambda ([x], p_1) (lambda ([x], p_2) (... (lambda ([x], p_n) (x))
1649 is equal to @var{p}.
1650 The degree of @var{p_i} is greater than 1 for @var{i} less than @var{n}.
1652 Such a decomposition is not unique.
1657 @c polydecomp (x^210, x);
1658 @c p : expand (subst (x^3 - x - 1, x, x^2 - a));
1659 @c polydecomp (p, x);
1663 (%i1) polydecomp (x^210, x);
1665 (%o1) [x , x , x , x ]
1668 (%i2) p : expand (subst (x^3 - x - 1, x, x^2 - a));
1670 (%o2) x - 2 x - 2 x + x + 2 x - a + 1
1673 (%i3) polydecomp (p, x);
1675 (%o3) [x - a, x - x - 1]
1679 The following function composes @code{L = [e_1, ..., e_n]} as functions in
1680 @code{x}; it is the inverse of polydecomp:
1683 @c compose (L, x) :=
1684 @c block ([r : x], for e in L do r : subst (e, x, r), r) $
1688 (%i1) compose (L, x) :=
1689 block ([r : x], for e in L do r : subst (e, x, r), r) $
1693 Re-express above example using @code{compose}:
1696 @c polydecomp (compose ([x^2 - a, x^3 - x - 1], x), x);
1700 (%i1) polydecomp (compose ([x^2 - a, x^3 - x - 1], x), x);
1702 (%o1) [compose([x - a, x - x - 1], x)]
1706 Note that though @code{compose (polydecomp (@var{p}, @var{x}), @var{x})} always
1707 returns @var{p} (unexpanded), @code{polydecomp (compose ([@var{p_1}, ...,
1708 @var{p_n}], @var{x}), @var{x})} does @i{not} necessarily return
1709 @code{[@var{p_1}, ..., @var{p_n}]}:
1712 @c polydecomp (compose ([x^2 + 2*x + 3, x^2], x), x);
1713 @c polydecomp (compose ([x^2 + x + 1, x^2 + x + 1], x), x);
1717 (%i1) polydecomp (compose ([x^2 + 2*x + 3, x^2], x), x);
1719 (%o1) [compose([x + 2 x + 3, x ], x)]
1722 (%i2) polydecomp (compose ([x^2 + x + 1, x^2 + x + 1], x), x);
1724 (%o2) [compose([x + x + 1, x + x + 1], x)]
1728 @opencatbox{Categories:}
1729 @category{Polynomials}
1733 @c -----------------------------------------------------------------------------
1735 @deffn {Function} polymod @
1736 @fname{polymod} (@var{p}) @
1737 @fname{polymod} (@var{p}, @var{m})
1739 Converts the polynomial @var{p} to a modular representation with respect to the
1740 current modulus which is the value of the variable @code{modulus}.
1742 @code{polymod (@var{p}, @var{m})} specifies a modulus @var{m} to be used
1743 instead of the current value of @code{modulus}.
1745 See @mrefdot{modulus}
1747 @opencatbox{Categories:}
1748 @category{Polynomials}
1752 @c ISN'T THERE AN EQUIVALENT FUNCTION SOMEWHERE ??
1753 @c NEEDS WORK (IF KEPT)
1755 @c -----------------------------------------------------------------------------
1756 @anchor{polynomialp}
1757 @deffn {Function} polynomialp @
1758 @fname{polynomialp} (@var{p}, @var{L}, @var{coeffp}, @var{exponp}) @
1759 @fname{polynomialp} (@var{p}, @var{L}, @var{coeffp}) @
1760 @fname{polynomialp} (@var{p}, @var{L})
1762 Return @code{true} if @var{p} is a polynomial in the variables in the list
1763 @var{L}. The predicate @var{coeffp} must evaluate to @code{true} for each
1764 coefficient, and the predicate @var{exponp} must evaluate to @code{true} for all
1765 exponents of the variables in @var{L}. If you want to use a non-default value
1766 for @var{exponp}, you must supply @var{coeffp} with a value even if you want
1767 to use the default for @var{coeffp}.
1769 @c WORK THE FOLLOWING INTO THE PRECEDING
1770 The command @code{polynomialp (@var{p}, @var{L}, @var{coeffp})} is equivalent to
1771 @code{polynomialp (@var{p}, @var{L}, @var{coeffp}, 'nonnegintegerp)} and the
1772 command @code{polynomialp (@var{p}, @var{L})} is equivalent to
1773 @code{polynomialp (@var{p}, L@var{,} 'constantp, 'nonnegintegerp)}.
1775 The polynomial needn't be expanded:
1778 @c polynomialp ((x + 1)*(x + 2), [x]);
1779 @c polynomialp ((x + 1)*(x + 2)^a, [x]);
1782 (%i1) polynomialp ((x + 1)*(x + 2), [x]);
1784 (%i2) polynomialp ((x + 1)*(x + 2)^a, [x]);
1788 An example using non-default values for coeffp and exponp:
1791 @c polynomialp ((x + 1)*(x + 2)^(3/2), [x], numberp, numberp);
1792 @c polynomialp ((x^(1/2) + 1)*(x + 2)^(3/2), [x], numberp,
1796 (%i1) polynomialp ((x + 1)*(x + 2)^(3/2), [x], numberp, numberp);
1798 (%i2) polynomialp ((x^(1/2) + 1)*(x + 2)^(3/2), [x], numberp,
1803 Polynomials with two variables:
1806 @c polynomialp (x^2 + 5*x*y + y^2, [x]);
1807 @c polynomialp (x^2 + 5*x*y + y^2, [x, y]);
1810 (%i1) polynomialp (x^2 + 5*x*y + y^2, [x]);
1812 (%i2) polynomialp (x^2 + 5*x*y + y^2, [x, y]);
1816 @opencatbox{Categories:}
1817 @category{Predicate functions}
1818 @category{Polynomials}
1822 @c -----------------------------------------------------------------------------
1824 @deffn {Function} quotient @
1825 @fname{quotient} (@var{p_1}, @var{p_2}) @
1826 @fname{quotient} (@var{p_1}, @var{p_2}, @var{x_1}, @dots{}, @var{x_n})
1828 Returns the polynomial @var{p_1} divided by the polynomial @var{p_2}. The
1829 arguments @var{x_1}, @dots{}, @var{x_n} are interpreted as in @code{ratvars}.
1831 @code{quotient} returns the first element of the two-element list returned by
1834 @c NEED SOME EXAMPLES HERE
1835 @opencatbox{Categories:}
1836 @category{Polynomials}
1840 @c THIS ITEM CAN PROBABLY BE IMPROVED
1842 @c -----------------------------------------------------------------------------
1844 @deffn {Function} rat @
1845 @fname{rat} (@var{expr}) @
1846 @fname{rat} (@var{expr}, @var{x_1}, @dots{}, @var{x_n})
1848 Converts @var{expr} to canonical rational expression (CRE) form by expanding and
1849 combining all terms over a common denominator and cancelling out the
1850 greatest common divisor of the numerator and denominator, as well as
1851 converting floating point numbers to rational numbers within a
1852 tolerance of @code{ratepsilon}.
1853 The variables are ordered according
1854 to the @var{x_1}, @dots{}, @var{x_n}, if specified, as in @code{ratvars}.
1856 @code{rat} does not generally simplify functions other than addition @code{+},
1857 subtraction @code{-}, multiplication @code{*}, division @code{/}, and
1858 exponentiation to an integer power,
1859 whereas @code{ratsimp} does handle those cases.
1860 Note that atoms (numbers and variables) in CRE form are not the
1861 same as they are in the general form.
1862 For example, @code{rat(x)- x} yields
1863 @code{rat(0)} which has a different internal representation than 0.
1865 @c WHAT'S THIS ABOUT EXACTLY ??
1866 When @code{ratfac} is @code{true}, @code{rat} yields a partially factored
1867 form for CRE. During rational operations the expression is
1868 maintained as fully factored as possible without an actual call to the
1869 factor package. This should always save space and may save some time
1870 in some computations. The numerator and denominator are still made
1872 (e.g., @code{rat((x^2 - 1)^4/(x + 1)^2)} yields @code{(x - 1)^4 (x + 1)^2}
1873 when @code{ratfac} is @code{true}),
1874 but the factors within each part may not be relatively prime.
1876 @code{ratprint} if @code{false} suppresses the printout of the message
1877 informing the user of the conversion of floating point numbers to
1880 @code{keepfloat} if @code{true} prevents floating point numbers from being
1881 converted to rational numbers.
1883 See also @code{ratexpand} and @code{ratsimp}.
1887 @c ((x - 2*y)^4/(x^2 - 4*y^2)^2 + 1)*(y + a)*(2*y + x) /
1889 @c rat (%, y, a, x);
1893 (%i1) ((x - 2*y)^4/(x^2 - 4*y^2)^2 + 1)*(y + a)*(2*y + x) /
1897 (y + a) (2 y + x) (------------ + 1)
1900 (%o1) ------------------------------------
1905 (%i2) rat (%, y, a, x);
1912 @opencatbox{Categories:}
1913 @category{Rational expressions}
1917 @defvr {Option variable} ratalgdenom
1918 Default value: @code{true}
1920 When @code{ratalgdenom} is @code{true}, allows rationalization of denominators
1921 with respect to radicals to take effect. @code{ratalgdenom} has an effect only
1922 when canonical rational expressions (CRE) are used in algebraic mode.
1924 @opencatbox{Categories:}
1925 @category{Simplification flags and variables}
1929 @c THIS ITEM NEEDS MORE WORK
1931 @c -----------------------------------------------------------------------------
1933 @deffn {Function} ratcoef @
1934 @fname{ratcoef} (@var{expr}, @var{x}, @var{n}) @
1935 @fname{ratcoef} (@var{expr}, @var{x})
1937 Returns the coefficient of the expression @code{@var{x}^@var{n}}
1938 in the expression @var{expr}.
1939 If omitted, @var{n} is assumed to be 1.
1941 The return value is free
1942 (except possibly in a non-rational sense) of the variables in @var{x}.
1943 If no coefficient of this type exists, 0 is returned.
1946 expands and rationally simplifies its first argument and thus it may
1947 produce answers different from those of @code{coeff} which is purely
1949 @c MOVE THIS TO EXAMPLES SECTION
1950 Thus @code{ratcoef ((x + 1)/y + x, x)} returns @code{(y + 1)/y} whereas
1951 @code{coeff} returns 1.
1953 @code{ratcoef (@var{expr}, @var{x}, 0)}, viewing @var{expr} as a sum,
1954 returns a sum of those terms which do not contain @var{x}.
1955 @c "SHOULD NOT" -- WHAT DOES THIS MEAN ??
1956 Therefore if @var{x} occurs to any negative powers, @code{ratcoef} should not
1959 @c WHAT IS THE INTENT HERE ??
1960 Since @var{expr} is rationally
1961 simplified before it is examined, coefficients may not appear quite
1962 the way they were envisioned.
1967 @c s: a*x + b*x + 5$
1968 @c ratcoef (s, a + b);
1971 (%i1) s: a*x + b*x + 5$
1972 (%i2) ratcoef (s, a + b);
1975 @c NEED MORE EXAMPLES HERE
1977 @opencatbox{Categories:}
1978 @category{Polynomials}
1979 @category{Rational expressions}
1983 @c -----------------------------------------------------------------------------
1985 @deffn {Function} ratdenom (@var{expr})
1987 Returns the denominator of @var{expr},
1988 after coercing @var{expr} to a canonical rational expression (CRE).
1989 The return value is a CRE.
1991 @c ACTUALLY THE CONVERSION IS CARRIED OUT BY ratf BUT THAT'S WHAT $rat CALLS
1992 @var{expr} is coerced to a CRE by @code{rat}
1993 if it is not already a CRE.
1994 This conversion may change the form of @var{expr} by putting all terms
1995 over a common denominator.
1997 @code{denom} is similar, but returns an ordinary expression instead of a CRE.
1998 Also, @code{denom} does not attempt to place all terms over a common
1999 denominator, and thus some expressions which are considered ratios by
2000 @code{ratdenom} are not considered ratios by @code{denom}.
2002 @c NEEDS AN EXAMPLE HERE
2003 @opencatbox{Categories:}
2004 @category{Rational expressions}
2008 @c -----------------------------------------------------------------------------
2009 @defvr {Option variable} ratdenomdivide
2010 Default value: @code{true}
2012 When @code{ratdenomdivide} is @code{true},
2013 @code{ratexpand} expands a ratio in which the numerator is a sum
2014 into a sum of ratios,
2015 all having a common denominator.
2016 Otherwise, @code{ratexpand} collapses a sum of ratios into a single ratio,
2017 the numerator of which is the sum of the numerators of each ratio.
2022 @c expr: (x^2 + x + 1)/(y^2 + 7);
2023 @c ratdenomdivide: true$
2024 @c ratexpand (expr);
2025 @c ratdenomdivide: false$
2026 @c ratexpand (expr);
2027 @c expr2: a^2/(b^2 + 3) + b/(b^2 + 3);
2028 @c ratexpand (expr2);
2031 (%i1) expr: (x^2 + x + 1)/(y^2 + 7);
2037 (%i2) ratdenomdivide: true$
2038 (%i3) ratexpand (expr);
2041 (%o3) ------ + ------ + ------
2044 (%i4) ratdenomdivide: false$
2045 (%i5) ratexpand (expr);
2053 (%i6) expr2: a^2/(b^2 + 3) + b/(b^2 + 3);
2056 (%o6) ------ + ------
2059 (%i7) ratexpand (expr2);
2067 @opencatbox{Categories:}
2068 @category{Simplification flags and variables}
2069 @category{Rational expressions}
2073 @c -----------------------------------------------------------------------------
2075 @deffn {Function} ratdiff (@var{expr}, @var{x})
2077 Differentiates the rational expression @var{expr} with respect to @var{x}.
2078 @var{expr} must be a ratio of polynomials or a polynomial in @var{x}.
2079 The argument @var{x} may be a variable or a subexpression of @var{expr}.
2080 @c NOT CLEAR (FROM READING CODE) HOW x OTHER THAN A VARIABLE IS HANDLED --
2081 @c LOOKS LIKE (a+b), 10*(a+b), (a+b)^2 ARE ALL TREATED LIKE (a+b);
2082 @c HOW TO DESCRIBE THAT ??
2084 The result is equivalent to @code{diff}, although perhaps in a different form.
2085 @code{ratdiff} may be faster than @code{diff}, for rational expressions.
2087 @code{ratdiff} returns a canonical rational expression (CRE) if @code{expr} is
2088 a CRE. Otherwise, @code{ratdiff} returns a general expression.
2090 @code{ratdiff} considers only the dependence of @var{expr} on @var{x},
2091 and ignores any dependencies established by @code{depends}.
2093 @c WHAT THIS IS ABOUT -- ratdiff (rat (factor (expr)), x) AND ratdiff (factor (rat (expr)), x) BOTH SUCCEED
2094 @c COMMENTING THIS OUT UNTIL SOMEONE CAN ESTABLISH SOME CRE'S FOR WHICH ratdiff FAILS
2095 @c However, @code{ratdiff} should not be used on factored CRE forms;
2096 @c use @code{diff} instead for such expressions.
2101 @c expr: (4*x^3 + 10*x - 11)/(x^5 + 5);
2102 @c ratdiff (expr, x);
2103 @c expr: f(x)^3 - f(x)^2 + 7;
2104 @c ratdiff (expr, f(x));
2105 @c expr: (a + b)^3 + (a + b)^2;
2106 @c ratdiff (expr, a + b);
2109 (%i1) expr: (4*x^3 + 10*x - 11)/(x^5 + 5);
2113 (%o1) ----------------
2117 (%i2) ratdiff (expr, x);
2119 8 x + 40 x - 55 x - 60 x - 50
2120 (%o2) - ---------------------------------
2123 (%i3) expr: f(x)^3 - f(x)^2 + 7;
2125 (%o3) f (x) - f (x) + 7
2126 (%i4) ratdiff (expr, f(x));
2128 (%o4) 3 f (x) - 2 f(x)
2129 (%i5) expr: (a + b)^3 + (a + b)^2;
2131 (%o5) (b + a) + (b + a)
2132 (%i6) ratdiff (expr, a + b);
2134 (%o6) 3 b + (6 a + 2) b + 3 a + 2 a
2137 @opencatbox{Categories:}
2138 @category{Rational expressions}
2142 @c -----------------------------------------------------------------------------
2144 @deffn {Function} ratdisrep (@var{expr})
2146 Returns its argument as a general expression.
2147 If @var{expr} is a general expression, it is returned unchanged.
2149 Typically @code{ratdisrep} is called to convert a canonical rational expression
2150 (CRE) into a general expression.
2151 @c NOT REALLY FOND OF YOU-CAN-DO-THIS-YOU-CAN-DO-THAT STATEMENTS
2152 This is sometimes convenient if one wishes to stop the "contagion", or
2153 use rational functions in non-rational contexts.
2155 See also @mrefdot{totaldisrep}
2157 @opencatbox{Categories:}
2158 @category{Rational expressions}
2162 @c -----------------------------------------------------------------------------
2164 @deffn {Function} ratexpand (@var{expr})
2165 @deffnx {Option variable} ratexpand
2167 Expands @var{expr} by multiplying out products of sums and
2168 exponentiated sums, combining fractions over a common denominator,
2169 cancelling the greatest common divisor of the numerator and
2170 denominator, then splitting the numerator (if a sum) into its
2171 respective terms divided by the denominator.
2173 The return value of @code{ratexpand} is a general expression,
2174 even if @var{expr} is a canonical rational expression (CRE).
2176 @c WHAT DOES THE FOLLOWING MEAN EXACTLY ??
2177 The switch @code{ratexpand} if @code{true} will cause CRE
2178 expressions to be fully expanded when they are converted back to
2179 general form or displayed, while if it is @code{false} then they will be put
2180 into a recursive form.
2181 See also @mrefdot{ratsimp}
2183 When @code{ratdenomdivide} is @code{true},
2184 @code{ratexpand} expands a ratio in which the numerator is a sum
2185 into a sum of ratios,
2186 all having a common denominator.
2187 Otherwise, @code{ratexpand} collapses a sum of ratios into a single ratio,
2188 the numerator of which is the sum of the numerators of each ratio.
2190 When @code{keepfloat} is @code{true}, prevents floating
2191 point numbers from being rationalized when expressions which contain
2192 them are converted to canonical rational expression (CRE) form.
2197 @c ratexpand ((2*x - 3*y)^3);
2198 @c expr: (x - 1)/(x + 1)^2 + 1/(x - 1);
2200 @c ratexpand (expr);
2203 (%i1) ratexpand ((2*x - 3*y)^3);
2205 (%o1) - 27 y + 54 x y - 36 x y + 8 x
2206 (%i2) expr: (x - 1)/(x + 1)^2 + 1/(x - 1);
2208 (%o2) -------- + -----
2211 (%i3) expand (expr);
2214 (%o3) ------------ - ------------ + -----
2216 x + 2 x + 1 x + 2 x + 1
2218 (%i4) ratexpand (expr);
2221 (%o4) --------------- + ---------------
2223 x + x - x - 1 x + x - x - 1
2226 @opencatbox{Categories:}
2227 @category{Rational expressions}
2231 @c -----------------------------------------------------------------------------
2233 @defvr {Option variable} ratfac
2234 Default value: @code{false}
2236 When @code{ratfac} is @code{true}, canonical rational expressions (CRE) are
2237 manipulated in a partially factored form.
2239 During rational operations the expression is maintained as fully factored as
2240 possible without calling @code{factor}.
2241 This should always save space and may save time in some computations.
2242 The numerator and denominator are made relatively prime, for example
2243 @code{factor ((x^2 - 1)^4/(x + 1)^2)} yields @code{(x - 1)^4 (x + 1)^2},
2244 but the factors within each part may not be relatively prime.
2246 In the @code{ctensor} (Component Tensor Manipulation) package,
2247 Ricci, Einstein, Riemann, and Weyl tensors and the scalar curvature
2248 are factored automatically when @code{ratfac} is @code{true}.
2249 @i{@code{ratfac} should only be
2250 set for cases where the tensorial components are known to consist of
2253 The @code{ratfac} and @code{ratweight} schemes are incompatible and may not
2254 both be used at the same time.
2256 @c NEED EXAMPLES HERE
2257 @opencatbox{Categories:}
2258 @category{Rational expressions}
2262 @c -----------------------------------------------------------------------------
2264 @deffn {Function} ratnumer (@var{expr})
2266 Returns the numerator of @var{expr},
2267 after coercing @var{expr} to a canonical rational expression (CRE).
2268 The return value is a CRE.
2270 @c ACTUALLY THE CONVERSION IS CARRIED OUT BY ratf BUT THAT'S WHAT $rat CALLS
2271 @var{expr} is coerced to a CRE by @code{rat}
2272 if it is not already a CRE.
2273 This conversion may change the form of @var{expr} by putting all terms
2274 over a common denominator.
2276 @code{num} is similar, but returns an ordinary expression instead of a CRE.
2277 Also, @code{num} does not attempt to place all terms over a common denominator,
2278 and thus some expressions which are considered ratios by @code{ratnumer}
2279 are not considered ratios by @code{num}.
2281 @c NEEDS AN EXAMPLE HERE
2282 @opencatbox{Categories:}
2283 @category{Rational expressions}
2287 @c -----------------------------------------------------------------------------
2289 @deffn {Function} ratp (@var{expr})
2291 Returns @code{true} if @var{expr} is a canonical rational expression (CRE) or
2292 extended CRE, otherwise @code{false}.
2294 CRE are created by @code{rat} and related functions.
2295 Extended CRE are created by @code{taylor} and related functions.
2297 @opencatbox{Categories:}
2298 @category{Predicate functions}
2299 @category{Rational expressions}
2303 @c -----------------------------------------------------------------------------
2304 @defvr {Option variable} ratprint
2305 Default value: @code{true}
2307 When @code{ratprint} is @code{true},
2308 a message informing the user of the conversion of floating point numbers
2309 to rational numbers is displayed.
2311 @opencatbox{Categories:}
2312 @category{Rational expressions}
2313 @category{Numerical evaluation}
2314 @category{Console interaction}
2318 @c -----------------------------------------------------------------------------
2320 @deffn {Function} ratsimp (@var{expr})
2321 @deffnx {Function} ratsimp (@var{expr}, @var{x_1}, @dots{}, @var{x_n})
2323 Simplifies the expression @var{expr} and all of its subexpressions, including
2324 the arguments to non-rational functions. The result is returned as the quotient
2325 of two polynomials in a recursive form, that is, the coefficients of the main
2326 variable are polynomials in the other variables. Variables may include
2327 non-rational functions (e.g., @code{sin (x^2 + 1)}) and the arguments to any
2328 such functions are also rationally simplified.
2330 @code{ratsimp (@var{expr}, @var{x_1}, ..., @var{x_n})}
2331 enables rational simplification with the
2332 specification of variable ordering as in @code{ratvars}.
2334 When @code{ratsimpexpons} is @code{true},
2335 @code{ratsimp} is applied to the exponents of expressions during simplification.
2337 See also @mrefdot{ratexpand}
2338 Note that @code{ratsimp} is affected by some of the
2339 flags which affect @code{ratexpand}.
2344 @c sin (x/(x^2 + x)) = exp ((log(x) + 1)^2 - log(x)^2);
2346 @c ((x - 1)^(3/2) - (x + 1)*sqrt(x - 1))/sqrt((x - 1)*(x + 1));
2348 @c x^(a + 1/a), ratsimpexpons: true;
2351 (%i1) sin (x/(x^2 + x)) = exp ((log(x) + 1)^2 - log(x)^2);
2354 x (log(x) + 1) - log (x)
2355 (%o1) sin(------) = %e
2361 (%o2) sin(-----) = %e x
2363 (%i3) ((x - 1)^(3/2) - (x + 1)*sqrt(x - 1))/sqrt((x - 1)*(x + 1));
2366 (x - 1) - sqrt(x - 1) (x + 1)
2367 (%o3) --------------------------------
2368 sqrt((x - 1) (x + 1))
2372 (%o4) - -------------
2375 (%i5) x^(a + 1/a), ratsimpexpons: true;
2383 @opencatbox{Categories:}
2384 @category{Simplification functions}
2385 @category{Rational expressions}
2389 @c -----------------------------------------------------------------------------
2390 @defvr {Option variable} ratsimpexpons
2391 Default value: @code{false}
2393 When @code{ratsimpexpons} is @code{true},
2394 @code{ratsimp} is applied to the exponents of expressions during simplification.
2396 @c NEED AN EXAMPLE HERE -- RECYCLE THE ratsimpexpons EXAMPLE FROM ratsimp ABOVE
2397 @opencatbox{Categories:}
2398 @category{Simplification flags and variables}
2399 @category{Rational expressions}
2403 @c -----------------------------------------------------------------------------
2404 @anchor{radsubstflag}
2405 @defvr {Option variable} radsubstflag
2406 Default value: @code{false}
2408 @code{radsubstflag}, if @code{true}, permits @code{ratsubst} to make
2409 substitutions such as @code{u} for @code{sqrt (x)} in @code{x}.
2411 @opencatbox{Categories:}
2412 @category{Simplification flags and variables}
2416 @c -----------------------------------------------------------------------------
2418 @deffn {Function} ratsubst (@var{a}, @var{b}, @var{c})
2420 Substitutes @var{a} for @var{b} in @var{c} and returns the resulting expression.
2421 @c "ETC" SUGGESTS THE READER KNOWS WHAT ELSE GOES THERE -- NOT LIKELY THE CASE
2422 @var{b} may be a sum, product, power, etc.
2424 @c WHAT, EXACTLY, DOES ratsubst KNOW ??
2425 @code{ratsubst} knows something of the meaning of expressions
2426 whereas @code{subst} does a purely syntactic substitution.
2427 Thus @code{subst (a, x + y, x + y + z)} returns @code{x + y + z}
2428 whereas @code{ratsubst} returns @code{z + a}.
2430 When @code{radsubstflag} is @code{true},
2431 @code{ratsubst} makes substitutions for radicals in expressions
2432 which don't explicitly contain them.
2434 @code{ratsubst} ignores the value @code{true} of the option variables
2435 @code{keepfloat}, @code{float}, and @code{numer}.
2439 @c EXAMPLES BELOW ADAPTED FROM examples (ratsubst)
2440 @c WITH SOME ADDITIONAL STUFF
2443 @c ratsubst (a, x*y^2, x^4*y^3 + x^4*y^8);
2444 @c cos(x)^4 + cos(x)^3 + cos(x)^2 + cos(x) + 1;
2445 @c ratsubst (1 - sin(x)^2, cos(x)^2, %);
2446 @c ratsubst (1 - cos(x)^2, sin(x)^2, sin(x)^4);
2447 @c radsubstflag: false$
2448 @c ratsubst (u, sqrt(x), x);
2449 @c radsubstflag: true$
2450 @c ratsubst (u, sqrt(x), x);
2454 (%i1) ratsubst (a, x*y^2, x^4*y^3 + x^4*y^8);
2459 (%i2) cos(x)^4 + cos(x)^3 + cos(x)^2 + cos(x) + 1;
2461 (%o2) cos (x) + cos (x) + cos (x) + cos(x) + 1
2464 (%i3) ratsubst (1 - sin(x)^2, cos(x)^2, %);
2466 (%o3) sin (x) - 3 sin (x) + cos(x) (2 - sin (x)) + 3
2469 (%i4) ratsubst (1 - cos(x)^2, sin(x)^2, sin(x)^4);
2471 (%o4) cos (x) - 2 cos (x) + 1
2473 (%i5) radsubstflag: false$
2475 (%i6) ratsubst (u, sqrt(x), x);
2478 (%i7) radsubstflag: true$
2480 (%i8) ratsubst (u, sqrt(x), x);
2486 @opencatbox{Categories:}
2487 @category{Rational expressions}
2491 @c -----------------------------------------------------------------------------
2493 @deffn {Function} ratvars (@var{x_1}, @dots{}, @var{x_n})
2494 @deffnx {Function} ratvars ()
2495 @deffnx {System variable} ratvars
2497 Declares main variables @var{x_1}, @dots{}, @var{x_n} for rational expressions.
2498 @var{x_n}, if present in a rational expression, is considered the main variable.
2499 Otherwise, @var{x_[n-1]} is considered the main variable if present, and so on
2500 through the preceding variables to @var{x_1}, which is considered the main
2501 variable only if none of the succeeding variables are present.
2503 If a variable in a rational expression is not present in the @code{ratvars}
2504 list, it is given a lower priority than @var{x_1}.
2506 The arguments to @code{ratvars} can be either variables or non-rational
2507 functions such as @code{sin(x)}.
2509 The variable @code{ratvars} is a list of the arguments of
2510 the function @code{ratvars} when it was called most recently.
2511 Each call to the function @code{ratvars} resets the list.
2512 @code{ratvars ()} clears the list.
2514 @c NEED EXAMPLES HERE
2515 @opencatbox{Categories:}
2516 @category{Rational expressions}
2520 @c -----------------------------------------------------------------------------
2521 @defvr {Option variable} ratvarswitch
2522 Default value: @code{true}
2524 Maxima keeps an internal list in the Lisp variable @code{VARLIST} of the main
2525 variables for rational expressions. If @code{ratvarswitch} is @code{true},
2526 every evaluation starts with a fresh list @code{VARLIST}. This is the default
2527 behavior. Otherwise, the main variables from previous evaluations are not
2528 removed from the internal list @code{VARLIST}.
2530 The main variables, which are declared with the function @code{ratvars} are
2531 not affected by the option variable @code{ratvarswitch}.
2535 If @code{ratvarswitch} is @code{true}, every evaluation starts with a fresh
2536 list @code{VARLIST}.
2539 @c ratvarswitch:true$
2546 (%i1) ratvarswitch:true$
2562 If @code{ratvarswitch} is @code{false}, the main variables from the last
2563 evaluation are still present.
2566 @c ratvarswitch:false$
2573 (%i4) ratvarswitch:false$
2589 @opencatbox{Categories:}
2590 @category{Rational expressions}
2591 @category{Global flags}
2595 @c -----------------------------------------------------------------------------
2596 @deffn {Function} ratweight @
2597 @fname{ratweight} (@var{x_1}, @var{w_1}, @dots{}, @var{x_n}, @var{w_n}) @
2598 @fname{ratweight} ()
2600 Assigns a weight @var{w_i} to the variable @var{x_i}.
2601 This causes a term to be replaced by 0 if its weight exceeds the
2602 value of the variable @code{ratwtlvl} (default yields no truncation).
2603 The weight of a term is the sum of the products of the
2604 weight of a variable in the term times its power.
2605 For example, the weight of @code{3 x_1^2 x_2} is @code{2 w_1 + w_2}.
2606 Truncation according to @code{ratwtlvl} is carried out only when multiplying
2607 or exponentiating canonical rational expressions (CRE).
2609 @code{ratweight ()} returns the cumulative list of weight assignments.
2611 Note: The @code{ratfac} and @code{ratweight} schemes are incompatible and may
2612 not both be used at the same time.
2617 @c ratweight (a, 1, b, 1);
2618 @c expr1: rat(a + b + 1)$
2624 (%i1) ratweight (a, 1, b, 1);
2626 (%i2) expr1: rat(a + b + 1)$
2629 (%o3)/R/ b + (2 a + 2) b + a + 2 a + 1
2632 (%o5)/R/ 2 b + 2 a + 1
2635 @opencatbox{Categories:}
2636 @category{Rational expressions}
2640 @c -----------------------------------------------------------------------------
2641 @defvr {System variable} ratweights
2642 Default value: @code{[]}
2644 @code{ratweights} is the list of weights assigned by @code{ratweight}.
2645 The list is cumulative:
2646 each call to @code{ratweight} places additional items in the list.
2648 @c DO WE REALLY NEED TO MENTION THIS ??
2649 @code{kill (ratweights)} and @code{save (ratweights)} both work as expected.
2651 @opencatbox{Categories:}
2652 @category{Rational expressions}
2656 @c -----------------------------------------------------------------------------
2658 @defvr {Option variable} ratwtlvl
2659 Default value: @code{false}
2661 @code{ratwtlvl} is used in combination with the @code{ratweight}
2662 function to control the truncation of canonical rational expressions (CRE).
2663 For the default value of @code{false}, no truncation occurs.
2665 @opencatbox{Categories:}
2666 @category{Rational expressions}
2670 @c -----------------------------------------------------------------------------
2671 @deffn {Function} remainder @
2672 @fname{remainder} (@var{p_1}, @var{p_2}) @
2673 @fname{remainder} (@var{p_1}, @var{p_2}, @var{x_1}, @dots{}, @var{x_n})
2675 Returns the remainder of the polynomial @var{p_1} divided by the polynomial
2676 @var{p_2}. The arguments @var{x_1}, @dots{}, @var{x_n} are interpreted as in
2679 @code{remainder} returns the second element
2680 of the two-element list returned by @code{divide}.
2682 @c NEED SOME EXAMPLES HERE
2683 @opencatbox{Categories:}
2684 @category{Polynomials}
2688 @c -----------------------------------------------------------------------------
2690 @deffn {Function} resultant (@var{p_1}, @var{p_2}, @var{x})
2692 The function @code{resultant} computes the resultant of the two polynomials
2693 @var{p_1} and @var{p_2}, eliminating the variable @var{x}. The resultant is a
2694 determinant of the coefficients of @var{x} in @var{p_1} and @var{p_2}, which
2695 equals zero if and only if @var{p_1} and @var{p_2} have a non-constant factor
2698 If @var{p_1} or @var{p_2} can be factored, it may be desirable to call
2699 @mref{factor} before calling @code{resultant}.
2701 The option variable @code{resultant} controls which algorithm will be used to
2702 compute the resultant. See the option variable
2703 @mxrefdot{option_resultant, resultant}
2705 The function @mref{bezout} takes the same arguments as @code{resultant} and
2706 returns a matrix. The determinant of the return value is the desired resultant.
2711 @c resultant(2*x^2+3*x+1, 2*x^2+x+1, x);
2712 @c resultant(x+1, x+1, x);
2713 @c resultant((x+1)*x, (x+1), x);
2714 @c resultant(a*x^2+b*x+1, c*x + 2, x);
2715 @c bezout(a*x^2+b*x+1, c*x+2, x);
2719 (%i1) resultant(2*x^2+3*x+1, 2*x^2+x+1, x);
2721 (%i2) resultant(x+1, x+1, x);
2723 (%i3) resultant((x+1)*x, (x+1), x);
2725 (%i4) resultant(a*x^2+b*x+1, c*x + 2, x);
2727 (%o4) c - 2 b c + 4 a
2729 (%i5) bezout(a*x^2+b*x+1, c*x+2, x);
2735 (%i6) determinant(%);
2736 (%o6) 4 a - (2 b - c) c
2738 @opencatbox{Categories:}
2739 @category{Polynomials}
2743 @c -----------------------------------------------------------------------------
2744 @anchor{option_resultant}
2745 @defvr {Option variable} resultant
2746 Default value: @code{subres}
2748 The option variable @code{resultant} controls which algorithm will be used to
2749 compute the resultant with the function @mrefdot{resultant} The possible
2754 for the subresultant polynomial remainder sequence (PRS) algorithm,
2756 (not enabled) for the modular resultant algorithm, and
2758 for the reduced polynomial remainder sequence (PRS) algorithm.
2761 On most problems the default value @code{subres} should be best.
2762 @c On some large degree univariate or bivariate problems @code{mod}
2765 @opencatbox{Categories:}
2766 @category{Polynomials}
2770 @anchor{savefactors}
2771 @c -----------------------------------------------------------------------------
2772 @defvr {Option variable} savefactors
2773 Default value: @code{false}
2775 @c "certain functions" -- WHICH ONES ??
2776 When @code{savefactors} is @code{true}, causes the factors of an
2777 expression which is a product of factors to be saved by certain
2778 functions in order to speed up later factorizations of expressions
2779 containing some of the same factors.
2781 @opencatbox{Categories:}
2782 @category{Polynomials}
2786 @c -----------------------------------------------------------------------------
2787 @anchor{showratvars}
2788 @deffn {Function} showratvars (@var{expr})
2790 Returns a list of the canonical rational expression (CRE) variables in
2791 expression @code{expr}.
2793 See also @mrefdot{ratvars}
2795 @opencatbox{Categories:}
2796 @category{Rational expressions}
2797 @category{Display functions}
2801 @c I CAN'T TELL WHAT THIS IS SUPPOSED TO BE ABOUT
2803 @c -----------------------------------------------------------------------------
2805 @deffn {Function} sqfr (@var{expr})
2807 is similar to @mref{factor} except that the polynomial factors are
2808 "square-free." That is, they have factors only of degree one.
2809 This algorithm, which is also used by the first stage of @mrefcomma{factor} utilizes
2810 the fact that a polynomial has in common with its n'th derivative all
2811 its factors of degree greater than n. Thus by taking greatest common divisors
2812 with the polynomial of
2813 the derivatives with respect to each variable in the polynomial, all
2814 factors of degree greater than 1 can be found.
2819 @c sqfr (4*x^4 + 4*x^3 - 3*x^2 - 4*x - 1);
2822 (%i1) sqfr (4*x^4 + 4*x^3 - 3*x^2 - 4*x - 1);
2824 (%o1) (2 x + 1) (x - 1)
2827 @opencatbox{Categories:}
2828 @category{Polynomials}
2832 @c THIS ITEM STILL NEEDS WORK
2834 @c -----------------------------------------------------------------------------
2835 @deffn {Function} tellrat @
2836 @fname{tellrat} (@var{p_1}, @dots{}, @var{p_n}) @
2839 Adds to the ring of algebraic integers known to Maxima
2840 the elements which are the solutions of the polynomials @var{p_1}, @dots{},
2841 @var{p_n}. Each argument @var{p_i} is a polynomial with integer coefficients.
2843 @code{tellrat (@var{x})} effectively means substitute 0 for @var{x} in rational
2846 @code{tellrat ()} returns a list of the current substitutions.
2848 @code{algebraic} must be set to @code{true} in order for the simplification of
2849 algebraic integers to take effect.
2851 Maxima initially knows about the imaginary unit @code{%i}
2852 and all roots of integers.
2854 There is a command @code{untellrat} which takes kernels and
2855 removes @code{tellrat} properties.
2857 When @code{tellrat}'ing a multivariate
2858 polynomial, e.g., @code{tellrat (x^2 - y^2)}, there would be an ambiguity as to
2859 whether to substitute @code{@var{y}^2} for @code{@var{x}^2}
2861 Maxima picks a particular ordering, but if the user wants to specify which, e.g.
2862 @code{tellrat (y^2 = x^2)} provides a syntax which says replace
2863 @code{@var{y}^2} by @code{@var{x}^2}.
2865 @c CAN'T TELL WHAT THIS IS ABOUT -- tellrat(w^3-1)$ algebraic:true$ rat(1/(w^2-w));
2866 @c DOES NOT YIELD AN ERROR, SO WHAT IS THE POINT ABOUT ratalgdenom ??
2867 @c When you @code{tellrat} reducible polynomials, you want to be careful not to
2868 @c attempt to rationalize a denominator with a zero divisor. E.g.
2869 @c tellrat(w^3-1)$ algebraic:true$ rat(1/(w^2-w)); will give "quotient by
2870 @c zero". This error can be avoided by setting @code{ratalgdenom} to @code{false}.
2875 @c 10*(%i + 1)/(%i + 3^(1/3));
2876 @c ev (ratdisrep (rat(%)), algebraic);
2877 @c tellrat (1 + a + a^2);
2878 @c 1/(a*sqrt(2) - 1) + a/(sqrt(3) + sqrt(2));
2879 @c ev (ratdisrep (rat(%)), algebraic);
2880 @c tellrat (y^2 = x^2);
2883 (%i1) 10*(%i + 1)/(%i + 3^(1/3));
2888 (%i2) ev (ratdisrep (rat(%)), algebraic);
2890 (%o2) (4 3 - 2 3 - 4) %i + 2 3 + 4 3 - 2
2891 (%i3) tellrat (1 + a + a^2);
2894 (%i4) 1/(a*sqrt(2) - 1) + a/(sqrt(3) + sqrt(2));
2896 (%o4) ------------- + -----------------
2897 sqrt(2) a - 1 sqrt(3) + sqrt(2)
2898 (%i5) ev (ratdisrep (rat(%)), algebraic);
2899 (7 sqrt(3) - 10 sqrt(2) + 2) a - 2 sqrt(2) - 1
2900 (%o5) ----------------------------------------------
2902 (%i6) tellrat (y^2 = x^2);
2904 (%o6) [y - x , a + a + 1]
2907 @opencatbox{Categories:}
2908 @category{Polynomials}
2909 @category{Rational expressions}
2913 @c -----------------------------------------------------------------------------
2914 @anchor{totaldisrep}
2915 @deffn {Function} totaldisrep (@var{expr})
2917 Converts every subexpression of @var{expr} from canonical rational expressions
2918 (CRE) to general form and returns the result.
2919 If @var{expr} is itself in CRE form then @code{totaldisrep} is identical to
2922 @code{totaldisrep} may be useful for
2923 ratdisrepping expressions such as equations, lists, matrices, etc., which
2924 have some subexpressions in CRE form.
2926 @c NEED EXAMPLES HERE
2927 @opencatbox{Categories:}
2928 @category{Rational expressions}
2932 @c -----------------------------------------------------------------------------
2934 @deffn {Function} untellrat (@var{x_1}, @dots{}, @var{x_n})
2936 Removes @code{tellrat} properties from @var{x_1}, @dots{}, @var{x_n}.
2938 @c NEED EXAMPLES HERE
2939 @opencatbox{Categories:}
2940 @category{Polynomials}
2941 @category{Rational expressions}