2 * Functions and Variables for to_poly_solve::
5 @node Functions and Variables for to_poly_solve, , Package to_poly_solve, Package to_poly_solve
6 @section Functions and Variables for to_poly_solve
8 The packages @code{to_poly} and @code{to_poly_solve} are experimental;
9 the specifications of the functions in these packages might change or
10 the some of the functions in these packages might be merged into other
13 Barton Willis (Professor of Mathematics, University of Nebraska at
14 Kearney) wrote the @code{to_poly} and @code{to_poly_solve} packages and the
15 English language user documentation for these packages.
17 @fnindex Logical conjunction
18 @deffn {Operator} %and
20 The operator @code{%and} is a simplifying nonshort-circuited logical
21 conjunction. Maxima simplifies an @code{%and} expression to either true,
22 false, or a logically equivalent, but simplified, expression. The
23 operator @code{%and} is associative, commutative, and idempotent. Thus
24 when @code{%and} returns a noun form, the arguments of @code{%and} form
25 a non-redundant sorted list; for example
28 (%i1) a %and (a %and b);
32 If one argument to a conjunction is the @i{explicit} the negation of another
33 argument, @code{%and} returns false:
40 If any member of the conjunction is false, the conjunction simplifies
41 to false even if other members are manifestly non-boolean; for example
48 Any argument of an @code{%and} expression that is an inequation (that
49 is, an inequality or equation), is simplified using the Fourier
50 elimination package. The Fourier elimination simplifier has a
51 pre-processor that converts some, but not all, nonlinear inequations
52 into linear inequations; for example the Fourier elimination code
53 simplifies @code{abs(x) + 1 > 0} to true, so
56 (%i4) (x < 1) %and (abs(x) + 1 > 0);
62 @item The option variable @code{prederror} does @i{not} alter the
63 simplification @code{%and} expressions.
65 @item To avoid operator precedence errors, compound expressions
66 involving the operators @code{%and, %or}, and @code{not} should be
69 @item The Maxima operators @code{and} and @code{or} are both
70 short-circuited. Thus @code{and} isn't associative or commutative.
74 @b{Limitations} The conjunction @code{%and} simplifies inequations
75 @i{locally, not globally}. This means that conjunctions such as
78 (%i5) (x < 1) %and (x > 1);
79 (%o5) (x > 1) %and (x < 1)
82 do @i{not} simplify to false. Also, the Fourier elimination code @i{ignores}
88 (%i7) (x > 1) %and (x > 2);
89 (%o7) (x > 1) %and (x > 2)
92 Finally, nonlinear inequations that aren't easily converted into an
93 equivalent linear inequation aren't simplified.
95 There is no support for distributing @code{%and} over @code{%or};
96 neither is there support for distributing a logical negation over
99 @b{To use} @code{load("to_poly_solve")}
101 @b{Related functions} @code{%or, %if, and, or, not}
103 @b{Status} The operator @code{%and} is experimental; the
104 specifications of this function might change and its functionality
105 might be merged into other Maxima functions.
109 @fnindex conditional evaluation
110 @deffn {Operator} %if (@var{bool}, @var{a}, @var{b})
112 The operator @code{%if} is a simplifying conditional. The
113 @i{conditional} @var{bool} should be boolean-valued. When the
114 conditional is true, return the second argument; when the conditional is
115 false, return the third; in all other cases, return a noun form.
117 Maxima inequations (either an inequality or an equality) are @i{not}
118 boolean-valued; for example, Maxima does @i{not} simplify @math{5 < 6}
119 to true, and it does not simplify @math{5 = 6} to false; however, in
120 the context of a conditional to an @code{%if} statement, Maxima
121 @i{automatically} attempts to determine the truth value of an
122 inequation. Examples:
125 (%i1) f : %if(x # 1, 2, 8);
126 (%o1) %if(x - 1 # 0, 2, 8)
127 (%i2) [subst(x = -1,f), subst(x=1,f)];
131 If the conditional involves an inequation, Maxima simplifies it using
132 the Fourier elimination package.
137 @item If the conditional is manifestly non-boolean, Maxima returns a noun form:
146 @item The Maxima operator @code{if} is nary, the operator @code{%if} @i{isn't}
150 @b{Limitations} The Fourier elimination code only simplifies nonlinear
151 inequations that are readily convertible to an equivalent linear
154 @b{To use:} @code{load("to_poly_solve")}
156 @b{Status:} The operator @code{%if} is experimental; its
157 specifications might change and its functionality might be merged into
158 other Maxima functions.
162 @fnindex Logical disjunction
163 @deffn {Operator} %or
165 The operator @code{%or} is a simplifying nonshort-circuited logical
166 disjunction. Maxima simplifies an @code{%or} expression to either
167 true, false, or a logically equivalent, but simplified,
168 expression. The operator @code{%or} is associative, commutative, and
169 idempotent. Thus when @code{%or} returns a noun form, the arguments
170 of @code{%or} form a non-redundant sorted list; for example
173 (%i1) a %or (a %or b);
177 If one member of the disjunction is the @i{explicit} the negation of another
178 member, @code{%or} returns true:
185 If any member of the disjunction is true, the disjunction simplifies
186 to true even if other members of the disjunction are manifestly non-boolean;
194 Any argument of an @code{%or} expression that is an inequation (that
195 is, an inequality or equation), is simplified using the Fourier
196 elimination package. The Fourier elimination code simplifies
197 @code{abs(x) + 1 > 0} to true, so we have
200 (%i4) (x < 1) %or (abs(x) + 1 > 0);
206 @item The option variable @code{prederror} does @i{not} alter the
207 simplification of @code{%or} expressions.
209 @item You should parenthesize compound expressions involving the
210 operators @code{%and, %or}, and @code{not}; the binding powers of these
211 operators might not match your expectations.
213 @item The Maxima operators @code{and} and @code{or} are both short-circuited.
214 Thus @code{or} isn't associative or commutative.
218 @b{Limitations} The conjunction @code{%or} simplifies inequations
219 @i{locally, not globally}. This means that conjunctions such as
221 @c TODO: IN MAXIMA 5.24POST THIS SIMPLIFIES TO TRUE.
224 (%i1) (x < 1) %or (x >= 1);
225 (%o1) (x > 1) %or (x >= 1)
228 do @i{not} simplify to true. Further, the Fourier elimination code ignores
234 (%i3) (x > 1) %and (x > 2);
235 (%o3) (x > 1) %and (x > 2)
238 Finally, nonlinear inequations that aren't easily converted into an
239 equivalent linear inequation aren't simplified.
241 The algorithm that looks for terms that cannot both be false is weak;
242 also there is no support for distributing @code{%or} over @code{%and};
243 neither is there support for distributing a logical negation over
246 @b{To use} @code{load("to_poly_solve")}
248 @b{Related functions} @code{%or, %if, and, or, not}
250 @b{Status} The operator @code{%or} is experimental; the
251 specifications of this function might change and its functionality
252 might be merged into other Maxima functions.
256 @anchor{complex_number_p}
257 @deffn {Function} complex_number_p (@var{x})
259 The predicate @code{complex_number_p} returns true if its argument is
260 either @code{a + %i * b}, @code{a}, @code{%i b}, or @code{%i},
261 where @code{a} and @code{b} are either rational or floating point
262 numbers (including big floating point); for all other inputs,
263 @code{complex_number_p} returns false; for example
266 (%i1) map('complex_number_p,[2/3, 2 + 1.5 * %i, %i]);
267 (%o1) [true, true, true]
268 (%i2) complex_number_p((2+%i)/(5-%i));
270 (%i3) complex_number_p(cos(5 - 2 * %i));
274 @b{Related functions} @code{isreal_p}
276 @b{To use} @code{load("to_poly_solve")}
278 @b{Status} The operator @code{complex_number_p} is experimental; its
279 specifications might change and its functionality might be merged into
280 other Maxima functions.
284 @anchor{compose_functions}
285 @deffn {Function} compose_functions (@var{l})
287 The function call @code{compose_functions(l)} returns a lambda form that is
288 the @i{composition} of the functions in the list @var{l}. The functions are
289 applied from @i{right} to @i{left}; for example
292 (%i1) compose_functions([cos, exp]);
294 (%o1) lambda([%g151], cos(%e ))
300 When the function list is empty, return the identity function:
303 (%i3) compose_functions([]);
304 (%o3) lambda([%g152], %g152)
311 @item When Maxima determines that a list member isn't a symbol or
312 a lambda form, @code{funmake} (@i{not} @code{compose_functions})
317 (%i5) compose_functions([a < b]);
319 funmake: first argument must be a symbol, subscripted symbol,
320 string, or lambda expression; found: a < b
321 #0: compose_functions(l=[a < b])(to_poly_solve.mac line 40)
322 -- an error. To debug this try: debugmode(true);
326 @item To avoid name conflicts, the independent variable is determined by the
327 function @code{new_variable}.
330 (%i6) compose_functions([%g0]);
331 (%o6) lambda([%g154], %g0(%g154))
332 (%i7) compose_functions([%g0]);
333 (%o7) lambda([%g155], %g0(%g155))
336 Although the independent variables are different, Maxima is able to to
337 deduce that these lambda forms are semantically equal:
340 (%i8) is(equal(%o6,%o7));
345 @b{To use} @code{load("to_poly_solve")}
347 @b{Status} The function @code{compose_functions} is experimental; its
348 specifications might change and its functionality might be merged into
349 other Maxima functions.
353 @deffn {Function} dfloat (@var{x})
355 The function @code{dfloat} is a similar to @code{float}, but the function
356 @code{dfloat} applies @code{rectform} when @code{float} fails to evaluate
357 to an IEEE double floating point number; thus
360 (%i1) float(4.5^(1 + %i));
363 (%i2) dfloat(4.5^(1 + %i));
364 (%o2) 4.48998802962884 %i + .3000124893895671
370 @item The rectangular form of an expression might be poorly suited for
371 numerical evaluation--for example, the rectangular form might
372 needlessly involve the difference of floating point numbers
373 (subtractive cancellation).
376 @item The identifier @code{float} is both an option variable (default
377 value false) and a function name.
382 @b{Related functions} @code{float, bfloat}
384 @b{To use} @code{load("to_poly_solve")}
386 @b{Status} The function @code{dfloat} is experimental; its
387 specifications might change and its functionality might be merged into
388 other Maxima functions.
393 @deffn {Function} elim (@var{l}, @var{x})
395 The function @code{elim} eliminates the variables in the set or list
396 @code{x} from the equations in the set or list @code{l}. Each member
397 of @code{x} must be a symbol; the members of @code{l} can either be
398 equations, or expressions that are assumed to equal zero.
400 The function @code{elim} returns a list of two lists; the first is
401 the list of expressions with the variables eliminated; the second
402 is the list of pivots; thus, the second list is a list of
403 expressions that @code{elim} used to eliminate the variables.
405 Here is an example of eliminating between linear equations:
408 (%i1) elim(set(x + y + z = 1, x - y - z = 8, x - z = 1),
410 (%o1) [[2 z - 7], [y + 7, z - x + 1]]
413 Eliminating @code{x} and @code{y} yields the single equation @code{2 z - 7 = 0};
414 the equations @code{y + 7 = 0} and @code{z - z + 1 = 1} were used as pivots.
415 Eliminating all three variables from these equations, triangularizes the linear
419 (%i2) elim(set(x + y + z = 1, x - y - z = 8, x - z = 1),
421 (%o2) [[], [2 z - 7, y + 7, z - x + 1]]
424 Of course, the equations needn't be linear:
427 (%i3) elim(set(x^2 - 2 * y^3 = 1, x - y = 5), [x,y]);
429 (%o3) [[], [2 y - y - 10 y - 24, y - x + 5]]
432 The user doesn't control the order the variables are
433 eliminated. Instead, the algorithm uses a heuristic to @i{attempt} to
434 choose the best pivot and the best elimination order.
439 @item Unlike the related function @code{eliminate}, the function
440 @code{elim} does @i{not} invoke @code{solve} when the number of equations
441 equals the number of variables.
443 @item The function @code{elim} works by applying resultants; the option
444 variable @code{resultant} determines which algorithm Maxima
445 uses. Using @code{sqfr}, Maxima factors each resultant and suppresses
448 @item The @code{elim} will triangularize a nonlinear set of polynomial
449 equations; the solution set of the triangularized set @i{can} be larger
450 than that solution set of the untriangularized set. Thus, the triangularized
451 equations can have @i{spurious} solutions.
454 @b{Related functions} @i{elim_allbut, eliminate_using, eliminate}
456 @b{Option variables} @i{resultant}
458 @b{To use} @code{load("to_poly")}
460 @b{Status} The function @code{elim} is experimental; its
461 specifications might change and its functionality might be merged into
462 other Maxima functions.
467 @deffn {Function} elim_allbut (@var{l}, @var{x})
469 This function is similar to @code{elim}, except that it eliminates all the
470 variables in the list of equations @code{l} @i{except} for those variables that
471 in in the list @code{x}
474 (%i1) elim_allbut([x+y = 1, x - 5*y = 1],[]);
475 (%o1) [[], [y, y + x - 1]]
476 (%i2) elim_allbut([x+y = 1, x - 5*y = 1],[x]);
477 (%o2) [[x - 1], [y + x - 1]]
480 @b{To use} @code{load("to_poly")}
482 @b{Option variables} @i{resultant}
484 @b{Related functions} @i{elim, eliminate_using, eliminate}
486 @b{Status} The function @code{elim_allbut} is experimental; its
487 specifications might change and its functionality might be merged into
488 other Maxima functions.
492 @anchor{eliminate_using}
493 @deffn {Function} eliminate_using (@var{l}, @var{e}, @var{x})
495 Using @code{e} as the pivot, eliminate the symbol @code{x} from the
496 list or set of equations in @code{l}. The function @code{eliminate_using}
500 (%i1) eq : [x^2 - y^2 - z^3 , x*y - z^2 - 5, x - y + z];
502 (%o1) [- z - y + x , - z + x y - 5, z - y + x]
503 (%i2) eliminate_using(eq,first(eq),z);
505 (%o2) @{y + (1 - 3 x) y + 3 x y - x - x ,
507 y - x y + 13 x y - 75 x y + x + 125@}
508 (%i3) eliminate_using(eq,second(eq),z);
510 (%o3) @{y - 3 x y + x + 5, y - x y + 13 x y - 75 x y + x
512 (%i4) eliminate_using(eq, third(eq),z);
514 (%o4) @{y - 3 x y + x + 5, y + (1 - 3 x) y + 3 x y - x - x @}
517 @b{Option variables} @i{resultant}
519 @b{Related functions} @i{elim, eliminate, elim_allbut}
521 @b{To use} @code{load("to_poly")}
523 @b{Status} The function @code{eliminate_using} is experimental; its
524 specifications might change and its functionality might be merged into
525 other Maxima functions.
529 @anchor{fourier_elim}
530 @deffn {Function} fourier_elim ([@var{eq1}, @var{eq2}, @dots{}], [@var{var1}, @var{var}, @dots{}])
532 Fourier elimination is the analog of Gauss elimination for linear inequations
533 (equations or inequalities). The function call @code{fourier_elim([eq1, eq2,
534 ...], [var1, var2, ...])} does Fourier elimination on a list of linear
535 inequations @code{[eq1, eq2, ...]} with respect to the variables
536 @code{[var1, var2, ...]}; for example
539 (%i1) fourier_elim([y-x < 5, x - y < 7, 10 < y],[x,y]);
540 (%o1) [y - 5 < x, x < y + 7, 10 < y]
541 (%i2) fourier_elim([y-x < 5, x - y < 7, 10 < y],[y,x]);
542 (%o2) [max(10, x - 7) < y, y < x + 5, 5 < x]
545 Eliminating first with respect to @math{x} and second with respect to
546 @math{y} yields lower and upper bounds for @math{x} that depend on
547 @math{y}, and lower and upper bounds for @math{y} that are numbers.
548 Eliminating in the other order gives @math{x} dependent lower and
549 upper bounds for @math{y}, and numerical lower and upper bounds for
552 When necessary, @code{fourier_elim} returns a @emph{disjunction} of lists of
556 (%i3) fourier_elim([x # 6],[x]);
557 (%o3) [x < 6] or [6 < x]
560 When the solution set is empty, @code{fourier_elim} returns @code{emptyset},
561 and when the solution set is all reals, @code{fourier_elim} returns @code{universalset};
565 (%i4) fourier_elim([x < 1, x > 1],[x]);
567 (%i5) fourier_elim([minf < x, x < inf],[x]);
571 For nonlinear inequations, @code{fourier_elim} returns a (somewhat)
572 simplified list of inequations:
575 (%i6) fourier_elim([x^3 - 1 > 0],[x]);
578 (%o6) [1 < x, x + x + 1 > 0] or [x < 1, - (x + x + 1) > 0]
580 (%i7) fourier_elim([cos(x) < 1/2],[x]);
581 (%o7) [1 - 2 cos(x) > 0]
584 Instead of a list of inequations, the first argument to @code{fourier_elim}
585 may be a logical disjunction or conjunction:
588 (%i8) fourier_elim((x + y < 5) and (x - y >8),[x,y]);
590 (%o8) [y + 8 < x, x < 5 - y, y < - -]
592 (%i9) fourier_elim(((x + y < 5) and x < 1) or (x - y >8),[x,y]);
593 (%o9) [y + 8 < x] or [x < min(1, 5 - y)]
596 The function @code{fourier_elim} supports the inequation operators
597 @code{<, <=, >, >=, #}, and @code{=}.
599 The Fourier elimination code has a preprocessor that converts some
600 nonlinear inequations that involve the absolute value, minimum, and
601 maximum functions into linear in equations. Additionally, the preprocessor
602 handles some expressions that are the product or quotient of linear terms:
605 (%i10) fourier_elim([max(x,y) > 6, x # 8, abs(y-1) > 12],[x,y]);
606 (%o10) [6 < x, x < 8, y < - 11] or [8 < x, y < - 11]
607 or [x < 8, 13 < y] or [x = y, 13 < y] or [8 < x, x < y, 13 < y]
609 (%i11) fourier_elim([(x+6)/(x-9) <= 6],[x]);
610 (%o11) [x = 12] or [12 < x] or [x < 9]
611 (%i12) fourier_elim([x^2 - 1 # 0],[x]);
612 (%o12) [- 1 < x, x < 1] or [1 < x] or [x < - 1]
615 @b{To use} @code{load("fourier_elim")}
620 @deffn {Function} isreal_p (@var{e})
622 The predicate @code{isreal_p} returns true when Maxima is able to
623 determine that @code{e} is real-valued on the @i{entire} real line; it
624 returns false when Maxima is able to determine that @code{e} @i{isn't}
625 real-valued on some nonempty subset of the real line; and it returns a
626 noun form for all other cases.
629 (%i1) map('isreal_p, [-1, 0, %i, %pi]);
630 (%o1) [true, true, false, true]
633 Maxima variables are assumed to be real; thus
640 The function @code{isreal_p} examines the fact database:
643 (%i3) declare(z,complex)$
650 Too often, @code{isreal_p} returns a noun form when it should be able
651 to return false; a simple example: the logarithm function isn't
652 real-valued on the entire real line, so @code{isreal_p(log(x))} should
653 return false; however
656 (%i5) isreal_p(log(x));
657 (%o5) isreal_p(log(x))
660 @b{To use} @code{load("to_poly_solve")}
662 @b{Related functions} @i{complex_number_p}
664 @b{Status} The function @code{isreal_p} is experimental; its
665 specifications might change and its functionality might be merged into
666 other Maxima functions.
670 @anchor{new_variable}
671 @deffn {Function} new_variable (type)
673 Return a unique symbol of the form @code{%[z,n,r,c,g]k}, where
674 @code{k} is an integer. The allowed values for @math{type} are
675 @i{integer, natural_number, real, complex,} and @i{general}.
676 (By natural number, we mean the @i{nonnegative integers}; thus zero is
677 a natural number. Some, but not all, definitions of natural number
680 When @math{type} isn't one of the allowed values, @math{type} defaults
681 to @math{general}. For integers, natural numbers, and complex numbers,
682 Maxima automatically appends this information to the fact database.
685 (%i1) map('new_variable,
686 ['integer, 'natural_number, 'real, 'complex, 'general]);
687 (%o1) [%z144, %n145, %r146, %c147, %g148]
688 (%i2) nicedummies(%);
689 (%o2) [%z0, %n0, %r0, %c0, %g0]
690 (%i3) featurep(%z0, 'integer);
692 (%i4) featurep(%n0, 'integer);
696 (%i6) featurep(%c0, 'complex);
700 @b{Note} Generally, the argument to @code{new_variable} should be quoted. The quote
701 will protect against errors similar to
706 (%i8) new_variable(integer);
708 (%i9) new_variable('integer);
712 @b{Related functions} @i{nicedummies}
714 @b{To use} @code{load("to_poly_solve")}
716 @b{Status} The function @code{new_variable} is experimental; its
717 specifications might change and its functionality might be merged into
718 other Maxima functions.
723 @deffn {Function} nicedummies
725 Starting with zero, the function @code{nicedummies} re-indexes the variables
726 in an expression that were introduced by @code{new_variable};
729 (%i1) new_variable('integer) + 52 * new_variable('integer);
730 (%o1) 52 %z136 + %z135
731 (%i2) new_variable('integer) - new_variable('integer);
733 (%i3) nicedummies(%);
737 @b{Related functions} @i{new_variable}
739 @b{To use} @code{load("to_poly_solve")}
741 @b{Status} The function @code{nicedummies} is experimental; its
742 specifications might change and its functionality might be merged into
743 other Maxima functions.
747 @deffn {Function} parg (@var{x})
749 The function @code{parg} is a simplifying version of the complex argument function
753 (%i1) map('parg,[1,1+%i,%i, -1 + %i, -1]);
755 (%o1) [0, ---, ---, -----, %pi]
759 Generally, for a non-constant input, @code{parg} returns a noun form; thus
762 (%i2) parg(x + %i * sqrt(x));
763 (%o2) parg(x + %i sqrt(x))
766 When @code{sign} can determine that the input is a positive or negative real
767 number, @code{parg} will return a non-noun form for a non-constant input.
768 Here are two examples:
770 @c TODO: THE FIRST RESULT IS A NOUNFORM IN MAXIMA 5.24POST
779 @b{Note} The @code{sign} function mostly ignores the variables that are declared
780 to be complex (@code{declare(x,complex)}); for variables that are declared
781 to be complex, the @code{parg} can return incorrect values; for example
783 @c TODO: IN MAXIMA 5.24POST THE RESULT IS A NOUNFORM.
786 (%i1) declare(x,complex)$
792 @b{Related function} @i{carg, isreal_p}
794 @b{To use} @code{load("to_poly_solve")}
796 @b{Status} The function @code{parg} is experimental; its
797 specifications might change and its functionality might be merged into
798 other Maxima functions.
802 @anchor{real_imagpart_to_conjugate}
803 @deffn {Function} real_imagpart_to_conjugate (@var{e})
805 The function @code{real_imagpart_to_conjugate} replaces all occurrences
806 of @code{realpart} and @code{imagpart} to algebraically equivalent expressions
807 involving the @code{conjugate}.
810 (%i1) declare(x, complex)$
812 (%i2) real_imagpart_to_conjugate(realpart(x) + imagpart(x) = 3);
813 conjugate(x) + x %i (x - conjugate(x))
814 (%o2) ---------------- - --------------------- = 3
818 @b{To use} @code{load("to_poly_solve")}
820 @b{Status} The function @code{real_imagpart_to_conjugate} is experimental; its
821 specifications might change and its functionality might be merged into
822 other Maxima functions.
826 @anchor{rectform_log_if_constant}
827 @deffn {Function} rectform_log_if_constant (@var{e})
829 The function @code{rectform_log_if_constant} converts all terms of the form
830 @code{ log(c)} to @code{rectform(log(c))}, where @code{c} is
831 either a declared constant expression or explicitly declared constant
834 (%i1) rectform_log_if_constant(log(1-%i) - log(x - %i));
836 (%o1) - log(x - %i) + ------ - ------
838 (%i2) declare(a,constant, b,constant)$
840 (%i3) rectform_log_if_constant(log(a + %i*b));
843 (%o3) ------------ + %i atan2(b, a)
847 @b{To use} @code{load("to_poly_solve")}
849 @b{Status} The function @code{rectform_log_if_constant} is
850 experimental; the specifications of this function might change might change and its functionality
851 might be merged into other Maxima functions.
855 @anchor{simp_inequality}
856 @deffn {Function} simp_inequality (@var{e})
858 The function @code{simp_inequality} applies basic simplifications to inequations,
859 returning either a boolean value (true or false) or the original inequation.
861 The simplification rules used by @code{simp_inequality}
862 include some facts about the ranges of the absolute value, power,
863 and exponential functions along with some elementary algebra facts.
865 For conjunctions or disjunctions of inequations,
866 @code{simp_inequality} is applied to each individual inequation,
867 but no effort is made to simplify the entire logical expression.
869 Effectively, simp_inequality creates a new empty context,
870 so database facts are not used to simplify inequations.
872 @code{load("to_poly_solve")} loads this function.
877 (%i2) simp_inequality(1 # 0);
882 (%i3) simp_inequality(1 < 0);
887 (%i4) simp_inequality(a=a);
892 (%i5) simp_inequality(a # a);
897 (%i6) simp_inequality(a + 1 # a);
902 (%i7) simp_inequality(a < a+1);
907 (%i8) simp_inequality(abs(x) >= 0);
912 (%i9) simp_inequality(exp(x) > 0);
917 (%i10) simp_inequality(x^2 >= 0);
922 (%i11) simp_inequality(2^x # 0);
927 (%i12) simp_inequality(2^(x+1) > 2^x);
931 The fact database is not consulted.
935 (%i13) assume(xx > 0)$
936 (%i14) simp_inequality(xx > 0);
940 And finally, for conjunctions or disjunctions of inequations,
941 each inequation is simplified,
942 but no effort is made to simplify the entire logical expression;
946 (%i15) simp_inequality((1 > 0) and (x < 0) and (x > 0));
952 @anchor{standardize_inverse_trig}
953 @deffn {Function} standardize_inverse_trig (@var{e})
955 This function applies the identities @code{cot(x) = atan(1/x),
956 acsc(x) = asin(1/x),} and similarly for @code{asec, acoth, acsch}
957 and @code{asech} to an expression. See Abramowitz and Stegun,
958 Eqs. 4.4.6 through 4.4.8 and 4.6.4 through 4.6.6.
960 @b{To use} @code{load("to_poly_solve")}
962 @b{Status} The function @code{standardize_inverse_trig} is experimental; its
963 specifications might change and its functionality might be merged into
964 other Maxima functions.
967 @anchor{subst_parallel}
968 @deffn {Function} subst_parallel (@var{l}, @var{e})
970 When @code{l} is a single equation or a list of equations, substitute
971 the right hand side of each equation for the left hand side. The
972 substitutions are made in parallel; for example
975 (%i1) load("to_poly_solve")$
977 (%i2) subst_parallel([x=y,y=x], [x,y]);
981 Compare this to substitutions made serially:
984 (%i3) subst([x=y,y=x],[x,y]);
988 The function @code{subst_parallel} is similar to @code{sublis} except that
989 @code{subst_parallel} allows for substitution of nonatoms; for example
992 (%i4) subst_parallel([x^2 = a, y = b], x^2 * y);
994 (%i5) sublis([x^2 = a, y = b], x^2 * y);
997 sublis: left-hand side of equation must be a symbol; found: x
998 -- an error. To debug this try: debugmode(true);
1001 The substitutions made by @code{subst_parallel} are literal, not semantic; thus
1002 @code{subst_parallel} @i{does not} recognize that @math{x * y} is a subexpression
1006 (%i6) subst_parallel([x * y = a], x^2 * y);
1011 The function @code{subst_parallel} completes all substitutions
1012 @i{before} simplifications. This allows for substitutions into
1013 conditional expressions where errors might occur if the
1014 simplifications were made earlier:
1017 (%i7) subst_parallel([x = 0], %if(x < 1, 5, log(x)));
1019 (%i8) subst([x = 0], %if(x < 1, 5, log(x)));
1021 log: encountered log(0).
1022 -- an error. To debug this try: debugmode(true);
1025 @b{Related functions} @i{subst, sublis, ratsubst}
1027 @b{To use} @code{load("to_poly_solve_extra.lisp")}
1029 @b{Status} The function @code{subst_parallel} is experimental; the
1030 specifications of this function might change might change and its
1031 functionality might be merged into other Maxima functions.
1036 @deffn {Function} to_poly (@var{e}, @var{l})
1038 The function @code{to_poly} attempts to convert the equation @code{e}
1039 into a polynomial system along with inequality constraints; the
1040 solutions to the polynomial system that satisfy the constraints are
1041 solutions to the equation @code{e}. Informally, @code{to_poly}
1042 attempts to polynomialize the equation @var{e}; an example might
1046 (%i1) load("to_poly_solve")$
1048 (%i2) to_poly(sqrt(x) = 3, [x]);
1050 (%o2) [[%g130 - 3, x = %g130 ],
1052 [- --- < parg(%g130), parg(%g130) <= ---], []]
1056 The conditions @code{-%pi/2<parg(%g130),parg(%g130)<=%pi/2} tell us that
1057 @code{%g130} is in the range of the square root function. When this is
1058 true, the solution set to @code{sqrt(x) = 3} is the same as the
1059 solution set to @code{%g130-3,x=%g130^2}.
1061 To polynomialize trigonometric expressions, it is necessary to
1062 introduce a non algebraic substitution; these non algebraic substitutions
1063 are returned in the third list returned by @code{to_poly}; for example
1066 (%i3) to_poly(cos(x),[x]);
1068 (%o3) [[%g131 + 1], [2 %g131 # 0], [%g131 = %e ]]
1071 Constant terms aren't polynomializied unless the number one is a member of
1072 the variable list; for example
1075 (%i4) to_poly(x = sqrt(5),[x]);
1076 (%o4) [[x - sqrt(5)], [], []]
1077 (%i5) to_poly(x = sqrt(5),[1,x]);
1079 (%o5) [[x - %g132, 5 = %g132 ],
1081 [- --- < parg(%g132), parg(%g132) <= ---], []]
1085 To generate a polynomial with @math{sqrt(5) + sqrt(7)} as
1086 one of its roots, use the commands
1089 (%i6) first(elim_allbut(first(to_poly(x = sqrt(5) + sqrt(7),
1092 (%o6) [x - 24 x + 4]
1095 @b{Related functions} @i{to_poly_solve}
1097 @b{To use} @code{load("to_poly")}
1099 @b{Status:} The function @code{to_poly} is experimental; its
1100 specifications might change and its functionality might be merged into
1101 other Maxima functions.
1105 @deffn {Function} to_poly_solve (@var{e}, @var{l}, [options])
1107 The function @code{to_poly_solve} tries to solve the equations @math{e}
1108 for the variables @math{l}. The equation(s) @math{e} can either be a
1109 single expression or a set or list of expressions; similarly, @math{l}
1110 can either be a single symbol or a list of set of symbols. When
1111 a member of @math{e} isn't explicitly an equation, for example @math{x^2 -1},
1112 the solver assumes that the expression vanishes.
1114 The basic strategy of @code{to_poly_solve} is to convert the input into a polynomial form and to
1115 call @code{algsys} on the polynomial system. Internally @code{to_poly_solve} defaults @code{algexact}
1116 to true. To change the default for @code{algexact}, append 'algexact=false to the @code{to_poly_solve}
1119 When @code{to_poly_solve} is able to determine the solution set, each
1120 member of the solution set is a list in a @code{%union} object:
1123 (%i1) load("to_poly_solve")$
1125 (%i2) to_poly_solve(x*(x-1) = 0, x);
1126 (%o2) %union([x = 0], [x = 1])
1129 When @code{to_poly_solve} is @i{unable} to determine the solution set, a
1130 @code{%solve} nounform is returned (in this case, a warning is printed)
1133 (%i3) to_poly_solve(x^k + 2* x + 1 = 0, x);
1135 Nonalgebraic argument given to 'to_poly'
1138 (%o3) %solve([x + 2 x + 1 = 0], [x])
1141 Substitution into a @code{%solve} nounform can sometimes result in the solution
1144 (%i4) subst(k = 2, %);
1145 (%o4) %union([x = - 1])
1148 Especially for trigonometric equations, the solver sometimes needs
1149 to introduce an arbitrary integer. These arbitrary integers have the
1150 form @code{%zXXX}, where @code{XXX} is an integer; for example
1153 (%i5) to_poly_solve(sin(x) = 0, x);
1154 (%o5) %union([x = 2 %pi %z33 + %pi], [x = 2 %pi %z35])
1157 To re-index these variables to zero, use @code{nicedummies}:
1160 (%i6) nicedummies(%);
1161 (%o6) %union([x = 2 %pi %z0 + %pi], [x = 2 %pi %z1])
1164 Occasionally, the solver introduces an arbitrary complex number of the
1165 form @code{%cXXX} or an arbitrary real number of the form @code{%rXXX}.
1166 The function @code{nicedummies} will re-index these identifiers to zero.
1168 The solution set sometimes involves simplifying versions of various
1169 of logical operators including @code{%and}, @code{%or}, or @code{%if}
1170 for conjunction, disjunction, and implication, respectively; for example
1173 (%i7) sol : to_poly_solve(abs(x) = a, x);
1174 (%o7) %union(%if(isnonnegative_p(a), [x = - a], %union()),
1175 %if(isnonnegative_p(a), [x = a], %union()))
1176 (%i8) subst(a = 42, sol);
1177 (%o8) %union([x = - 42], [x = 42])
1178 (%i9) subst(a = -42, sol);
1182 The empty set is represented by @code{%union()}.
1184 The function @code{to_poly_solve} is able to solve some, but not all,
1185 equations involving rational powers, some nonrational powers, absolute
1186 values, trigonometric functions, and minimum and maximum. Also, some it
1187 can solve some equations that are solvable in in terms of the Lambert W
1188 function; some examples:
1191 (%i1) load("to_poly_solve")$
1193 (%i2) to_poly_solve(set(max(x,y) = 5, x+y = 2), set(x,y));
1194 (%o2) %union([x = - 3, y = 5], [x = 5, y = - 3])
1195 (%i3) to_poly_solve(abs(1-abs(1-x)) = 10,x);
1196 (%o3) %union([x = - 10], [x = 12])
1197 (%i4) to_poly_solve(set(sqrt(x) + sqrt(y) = 5, x + y = 10),
1201 (%o4) %union([x = - ------------, y = ------------],
1205 [x = ------------, y = - ------------])
1207 (%i5) to_poly_solve(cos(x) * sin(x) = 1/2,x,
1208 'simpfuncs = ['expand, 'nicedummies]);
1210 (%o5) %union([x = %pi %z0 + ---])
1212 (%i6) to_poly_solve(x^(2*a) + x^a + 1,x);
1217 (%o6) %union([x = -----------------------------------],
1224 (- sqrt(3) %i - 1) %e
1225 [x = -------------------------------------])
1229 (%i7) to_poly_solve(x * exp(x) = a, x);
1230 (%o7) %union([x = lambert_w(a)])
1233 For @i{linear} inequalities, @code{to_poly_solve} automatically does Fourier
1237 (%i8) to_poly_solve([x + y < 1, x - y >= 8], [x,y]);
1239 (%o8) %union([x = y + 8, y < - -],
1242 [y + 8 < x, x < 1 - y, y < - -])
1246 Each optional argument to @code{to_poly_solve} must be an equation;
1247 generally, the order of these options does not matter.
1250 @item @code{simpfuncs = l}, where @code{l} is a list of functions.
1251 Apply the composition of the members of l to each solution.
1254 (%i1) to_poly_solve(x^2=%i,x);
1256 (%o1) %union([x = - (- 1) ], [x = (- 1) ])
1257 (%i2) to_poly_solve(x^2= %i,x, 'simpfuncs = ['rectform]);
1259 (%o2) %union([x = - ------- - -------], [x = ------- + -------])
1260 sqrt(2) sqrt(2) sqrt(2) sqrt(2)
1263 Sometimes additional simplification can revert a simplification; for example
1266 (%i3) to_poly_solve(x^2=1,x);
1267 (%o3) %union([x = - 1], [x = 1])
1268 (%i4) to_poly_solve(x^2= 1,x, 'simpfuncs = [polarform]);
1270 (%o4) %union([x = 1], [x = %e ]
1273 Maxima doesn't try to check that each member of the function list @code{l} is
1274 purely a simplification; thus
1277 (%i5) to_poly_solve(x^2 = %i,x, 'simpfuncs = [lambda([s],s^2)]);
1278 (%o5) %union([x = %i])
1281 To convert each solution to a double float, use @code{simpfunc = ['dfloat]}:
1284 (%i6) to_poly_solve(x^3 +x + 1 = 0,x,
1285 'simpfuncs = ['dfloat]), algexact : true;
1286 (%o6) %union([x = - .6823278038280178],
1287 [x = .3411639019140089 - 1.161541399997251 %i],
1288 [x = 1.161541399997251 %i + .3411639019140089])
1291 @item @code{use_grobner = true} With this option, the function
1292 @code{poly_reduced_grobner} is applied to the equations before
1293 attempting their solution. Primarily, this option provides a workaround
1294 for weakness in the function @code{algsys}. Here is an example of
1298 (%i7) to_poly_solve([x^2+y^2=2^2,(x-1)^2+(y-1)^2=2^2],[x,y],
1299 'use_grobner = true);
1301 sqrt(7) - 1 sqrt(7) + 1
1302 (%o7) %union([x = - -----------, y = -----------],
1305 sqrt(7) + 1 sqrt(7) - 1
1306 [x = -----------, y = - -----------])
1308 (%i8) to_poly_solve([x^2+y^2=2^2,(x-1)^2+(y-1)^2=2^2],[x,y]);
1312 @item @code{maxdepth = k}, where @code{k} is a positive integer. This
1313 function controls the maximum recursion depth for the solver. The
1314 default value for @code{maxdepth} is five. When the recursions depth is
1315 exceeded, the solver signals an error:
1318 (%i9) to_poly_solve(cos(x) = x,x, 'maxdepth = 2);
1322 (%o9) %solve([cos(x) = x], [x], maxdepth = 2)
1325 @item @code{parameters = l}, where @code{l} is a list of symbols. The solver
1326 attempts to return a solution that is valid for all members of the list
1327 @code{l}; for example:
1330 (%i10) to_poly_solve(a * x = x, x);
1331 (%o10) %union([x = 0])
1332 (%i11) to_poly_solve(a * x = x, x, 'parameters = [a]);
1333 (%o11) %union(%if(a - 1 = 0, [x = %c111], %union()),
1334 %if(a - 1 # 0, [x = 0], %union()))
1337 In @code{(%o2)}, the solver introduced a dummy variable; to re-index the
1338 these dummy variables, use the function @code{nicedummies}:
1341 (%i12) nicedummies(%);
1342 (%o12) %union(%if(a - 1 = 0, [x = %c0], %union()),
1343 %if(a - 1 # 0, [x = 0], %union()))
1347 The @code{to_poly_solve} uses data stored in the hashed array
1348 @code{one_to_one_reduce} to solve equations of the form @math{f(a) =
1349 f(b)}. The assignment @code{one_to_one_reduce['f,'f] : lambda([a,b],
1350 a=b)} tells @code{to_poly_solve} that the solution set of @math{f(a)
1351 = f(b)} equals the solution set of @math{a=b}; for example
1354 (%i13) one_to_one_reduce['f,'f] : lambda([a,b], a=b)$
1356 (%i14) to_poly_solve(f(x^2-1) = f(0),x);
1357 (%o14) %union([x = - 1], [x = 1])
1360 More generally, the assignment @code{one_to_one_reduce['f,'g] : lambda([a,b],
1361 w(a, b) = 0} tells @code{to_poly_solve} that the solution set of @math{f(a)
1362 = f(b)} equals the solution set of @math{w(a,b) = 0}; for example
1365 (%i15) one_to_one_reduce['f,'g] : lambda([a,b], a = 1 + b/2)$
1367 (%i16) to_poly_solve(f(x) - g(x),x);
1368 (%o16) %union([x = 2])
1371 Additionally, the function @code{to_poly_solve} uses data stored in the hashed array
1372 @code{function_inverse} to solve equations of the form @math{f(a) = b}.
1373 The assignment @code{function_inverse['f] : lambda([s], g(s))}
1374 informs @code{to_poly_solve} that the solution set to @code{f(x) = b} equals
1375 the solution set to @code{x = g(b)}; two examples:
1378 (%i17) function_inverse['Q] : lambda([s], P(s))$
1380 (%i18) to_poly_solve(Q(x-1) = 2009,x);
1381 (%o18) %union([x = P(2009) + 1])
1382 (%i19) function_inverse['G] : lambda([s], s+new_variable(integer));
1383 (%o19) lambda([s], s + new_variable(integer))
1384 (%i20) to_poly_solve(G(x - a) = b,x);
1385 (%o20) %union([x = b + a + %z125])
1392 @item The solve variables needn't be symbols; when @code{fullratsubst} is
1393 able to appropriately make substitutions, the solve variables can be nonsymbols:
1397 (%i1) to_poly_solve([x^2 + y^2 + x * y = 5, x * y = 8],
1398 [x^2 + y^2, x * y]);
1400 (%o1) %union([x y = 8, y + x = - 3])
1404 @item For equations that involve complex conjugates, the solver automatically
1405 appends the conjugate equations; for example
1409 (%i1) declare(x,complex)$
1411 (%i2) to_poly_solve(x + (5 + %i) * conjugate(x) = 1, x);
1413 (%o2) %union([x = - -----------])
1415 (%i3) declare(y,complex)$
1417 (%i4) to_poly_solve(set(conjugate(x) - y = 42 + %i,
1418 x + conjugate(y) = 0), set(x,y));
1420 (%o4) %union([x = - -------, y = - -------])
1425 @item For an equation that involves the absolute value function, the
1426 @code{to_poly_solve} consults the fact database to decide if the
1427 argument to the absolute value is complex valued. When
1430 (%i1) to_poly_solve(abs(x) = 6, x);
1431 (%o1) %union([x = - 6], [x = 6])
1432 (%i2) declare(z,complex)$
1434 (%i3) to_poly_solve(abs(z) = 6, z);
1435 (%o3) %union(%if((%c11 # 0) %and (%c11 conjugate(%c11) - 36 =
1436 0), [z = %c11], %union()))
1439 @i{This is the only situation that the solver consults the fact database. If
1440 a solve variable is declared to be an integer, for example, @code{to_poly_solve}
1441 ignores this declaration}.
1444 @b{Relevant option variables} @i{algexact, resultant, algebraic}
1446 @b{Related functions} @i{to_poly}
1448 @b{To use} @code{load("to_poly_solve")}
1450 @b{Status:} The function @code{to_poly_solve} is experimental; its
1451 specifications might change and its functionality might be merged into
1452 other Maxima functions.
1456 @deffn {Operator} %union (@var{soln_1}, @var{soln_2}, @var{soln_3}, ...)
1457 @deffnx {Operator} %union ()
1459 @code{%union(@var{soln_1}, @var{soln_2}, @var{soln_3}, ...)} represents the union of its arguments,
1460 each of which represents a solution set,
1461 as determined by @code{to_poly_solve}.
1462 @code{%union()} represents the empty set.
1464 In many cases, a solution is a list of equations @code{[@var{x} = ..., @var{y} = ..., @var{z} = ...]}
1465 where @var{x}, @var{y}, and @var{z} are one or more unknowns.
1466 In such cases, @code{to_poly_solve} returns a @code{%union} expression
1467 containing one or more such lists.
1469 The solution set sometimes involves simplifying versions of various
1470 of logical operators including @code{%and}, @code{%or}, or @code{%if}
1471 for conjunction, disjunction, and implication, respectively.
1475 @code{%union(...)} represents the union of its arguments,
1476 each of which represents a solution set,
1477 as determined by @code{to_poly_solve}.
1478 In many cases, a solution is a list of equations.
1481 @c load ("to_poly_solve") $
1482 @c to_poly_solve ([sqrt(x^2 - y^2), x + y], [x, y]);
1485 (%i1) load ("to_poly_solve") $
1486 (%i2) to_poly_solve ([sqrt(x^2 - y^2), x + y], [x, y]);
1487 (%o2) %union([x = 0, y = 0], [x = %c13, y = - %c13])
1490 @code{%union()} represents the empty set.
1493 @c load ("to_poly_solve") $
1494 @c to_poly_solve (abs(x) = -1, x);
1497 (%i1) load ("to_poly_solve") $
1498 (%i2) to_poly_solve (abs(x) = -1, x);
1502 The solution set sometimes involves simplifying versions of various
1503 of logical operators.
1506 @c load ("to_poly_solve") $
1507 @c sol : to_poly_solve (abs(x) = a, x);
1508 @c subst (a = 42, sol);
1509 @c subst (a = -42, sol);
1512 (%i1) load ("to_poly_solve") $
1513 (%i2) sol : to_poly_solve (abs(x) = a, x);
1514 (%o2) %union(%if(isnonnegative_p(a), [x = - a], %union()),
1515 %if(isnonnegative_p(a), [x = a], %union()))
1516 (%i3) subst (a = 42, sol);
1517 (%o3) %union([x = - 42], [x = 42])
1518 (%i4) subst (a = -42, sol);