2 * Introduction to Simplification::
3 * Functions and Variables for Simplification::
6 @c -----------------------------------------------------------------------------
7 @node Introduction to Simplification, Functions and Variables for Simplification, Simplification , Simplification
8 @section Introduction to Simplification
9 @c -----------------------------------------------------------------------------
11 @c -----------------------------------------------------------------------------
12 Maxima interacts with the user through a cycle of actions called the read-eval-print loop (REPL).
13 This consists of three steps: reading and parsing, evaluating and simplifying,
14 and outputting. Parsing converts a syntactically valid sequence of typed characters into
15 a internal data structure. Evaluation
16 replaces variable and function names with their values and simplification rewrites
17 expressions to be easier for the user or other programs to understand. Output
18 displays results in a variety of different formats and notations.
20 Evaluation and simplification sometimes appear to have similar functionality, and
21 Maxima uses simplification in many cases where other systems use evaluation.
22 For example, arithmetic both on numbers and on symbolic expressions is simplification, not evaluation:
23 @code{2+2} simplifies to @code{4}, @code{2+x+x} simplifies to @code{2+2*x}, and
24 @code{sqrt(7)^4} simplifies to @code{49}.
25 Evaluation and simplification are interleaved.
26 For example, @code{factor(integrate(x+1,x))} first calls the built-in function @mref{integrate},
27 giving @code{x+x*x*2^-1};
28 that simplifies to @code{x+(1/2)*x^2}; this in turn is passed to the @mref{factor} function,
29 which returns @code{(x*(x+2))/2}.
31 Evaluation is what makes Maxima a programming language: it implements
32 functions, subroutines, variables, values, loops, assignments and so on.
33 Evaluation replaces built-in or user-defined function names by their definitions and
34 variables by their values. This is largely the same as activities of a
35 conventional programming language, but extended to work with symbolic mathematical data.
36 The system has various optional "flags" which the user can set to control the details of
37 evaluation. @xref{Functions and Variables for Evaluation}.
39 Simplification maintains the value of an expression
40 while re-formulating its form to be smaller, simpler to understand, or to
41 conform to a particular specification (like expanded). For
42 example, @code{sin(%pi/2)} to @code{1}, and @code{x+x} to @code{2*x}.
43 There are many flags which control simplification. For example,
44 with @code{triginverses:true}, @code{atan(tan(x))} does not simplify to @code{x},
45 but with @code{triginverses:all}, it does.
47 Simplification can be provided in three ways:
49 @item The internal, built-in automated simplifier,
50 @item User-written pattern-matching transformations, linked to the simplifier by using
51 "tellsimp" or "tellsimpafter" and called automatically,
52 @item User-written simplification routines adding using the @code{simplifying} subsystem.
55 The internal simplifier belongs to the heart of Maxima. It is a large and
56 complicated collection of programs, and it has been refined over many years and by
57 thousands of users. Nevertheless, especially if you are trying out novel ideas or
58 unconventional notation, you may find it helpful to make small (or large) changes
59 to the program yourself. For details see for example the paper at the end of
60 @url{https://people.eecs.berkeley.edu/~fateman/papers/intro5.txt}.
62 Maxima internally represents expressions as "trees" with operators or "roots"
63 like @code{+}, @code{*} , @code{=} and operands ("leaves") which are variables like
64 @var{x}, @var{y}, @var{z}, functions
65 or sub-trees, like @code{x*y}. Each operator has a simplification program
66 associated with it. @code{+} (which also covers binary @code{-} since
67 @code{a-b = a+(-1)*b)} and @code{*} (which also covers @code{/}
68 since @code{a/b = a*b^(-1)}) have rather elaborate simplification programs. These
69 simplification programs (simplus, simptimes, simpexpt, etc.) are called whenever
70 the simplifier encounters the respective arithmetic operators in an expression
73 The structure of the simplifier dates back to 1965, and many hands have worked
74 on it through the years. It is data-directed, or object-oriented in the sense that
75 it dispatches to the appropriate routine
76 depending on the root of some sub-tree of the expression, recursively. This general
77 approach means that modifications to simplification are generally localized.
78 In many cases it is straightforward to add an
79 operator and its simplification routine without disturbing existing code.
81 Maxima also provides a variety of transformation routines that can change the form of an
82 expression, including @mref{factor} (polynomial factorization), @mref{horner}
83 (reorganize a polynomial using Horner's rule), @mref{partfrac}
84 (rewrite a rational function as partial fractions),
85 @mref{trigexpand} (apply the sum formulas for trigonometric functions),
88 Users can also write routines that change the form of an expression.
90 Besides this general simplifier operating on algebraic
91 expression trees, there are several other representations of expressions in
92 Maxima which have separate methods. For example, the
93 @mref{rat} function converts polynomials to vectors of coefficients to
94 assist in rapid manipulation of such forms. Other representations include
95 Taylor series and the (rarely used) Poisson series.
97 All operators introduced by the user initially have no simplification
98 programs associated with them. Maxima does not know anything about
99 function "f" and so typing @code{f(a,b)} will result in simplifying
100 @var{a},@var{b}, but not @code{f}.
101 Even some built-in operators have no simplifications. For example,
102 @code{=} does not "simplify" -- it is a place-holder with no
103 simplification semantics other
104 than to simplify its two arguments, in this case referred to as the left and
105 right sides. Other parts of Maxima such as the solve program take special
106 note of equations, that is, trees with @code{=} as the root.
107 (Note -- in Maxima, the assignment operation is @code{:} . That is, @code{q: 4}
108 sets the value of the symbol @var{q} to @code{4}.
109 Function definition is done with @code{:=}. )
111 The general simplifier returns results with an internal flag indicating the
112 expression and each sub-expression has been simplified. This does not
113 guarantee that it is unique over all possible equivalent expressions. That's
114 too hard (theoretically, not possible given the generality of what can be
115 expressed in Maxima). However, some aspects of the expression, such as the
116 ordering of terms in a sum or product, are made uniform. This is important
117 for the other programs to work properly.
119 A number of option variables control simplification. Indeed, simplification
120 can be turned off entirely using @code{simp:false}. However, many
121 internal routines will not operate correctly with @code{simp:false}.
122 (About the only time it seems plausible to turn off the simplifier
123 is in the rare case that you want to over-ride a built-in simplification.
124 In that case you might temporarily disable the simplifier, put in the new
125 transformation via @mrefcomma{tellsimp} and then re-enable the simplifier
126 by @code{simp:true}.)
128 It is more plausible for you to associate user-defined symbolic function names
129 or operators with properties (@mrefcomma{additive}
130 @mrefcomma{lassociative} @mrefcomma{oddfun} @mrefcomma{antisymmetric}
131 @mrefcomma{linear} @mrefcomma{outative} @mrefcomma{commutative}
132 @mrefcomma{multiplicative} @mrefcomma{rassociative} @mrefcomma{evenfun}
133 @mref{nary} and @mref{symmetric}). These options steer
134 the simplifier processing in systematic directions.
136 For example, @code{declare(f,oddfun)} specifies that @code{f} is an odd function.
137 Maxima will simplify @code{f(-x)} to @code{-f(x)}. In the case of an even
138 function, that is @code{declare(g,evenfun)},
139 Maxima will simplify @code{g(-x)} to @code{g(x)}. You can also associate a
140 programming function with a name such as @code{h(x):=x^2+1}. In that case the
141 evaluator will immediately replace
142 @code{h(3)} by @code{10}, and @code{h(a+1)} by @code{(a+1)^2+1}, so any properties
143 of @code{h} will be ignored.
145 In addition to these directly related properties set up by the user, facts and
146 properties from the actual context may have an impact on the simplifier's behavior,
147 too. @xref{Introduction to Maxima's Database}.
149 Example: @code{sin(n*%pi)} is simplified to zero, if @var{n} is an integer.
153 @c declare(n, integer);
162 (%i2) declare(n, integer);
171 If automated simplification is not sufficient, you can consider a variety of
172 built-in, but explicitly called simplfication functions (@mrefcomma{ratsimp}
173 @mrefcomma{expand} @mrefcomma{factor} @mref{radcan} and others). There are
174 also flags that will push simplification into one or another direction.
175 Given @code{demoivre:true} the simplifier rewrites
176 complex exponentials as trigonometric forms. Given @code{exponentialize:true}
177 the simplifier tries to do the reverse: rewrite trigonometric forms as complex
180 As everywhere in Maxima, by writing your own functions (be it in the Maxima
181 user language or in the implementation language Lisp) and explicitly calling them
182 at selected places in the program, you can respond to your individual
183 simplification needs. Lisp gives you a handle on all the internal mechanisms, but
184 you rarely need this full generality. "Tellsimp" is designed to generate much
185 of the Lisp internal interface into the simplifier automatically.
186 See @xref{Rules and Patterns}.
188 Over the years (Maxima/Macsyma's origins date back to about 1966!) users have
189 contributed numerous application packages and tools to extend or alter its
190 functional behavior. Various non-standard and "share" packages exist to modify
191 or extend simplification as well. You are invited to look into this more
192 experimental material where work is still in progress @xref{Package simplification}.
194 The following appended material is optional on a first reading, and reading it
195 is not necessary for productive use of Maxima. It is for the curious user who
196 wants to understand what is going on, or the ambitious programmer who might
197 wish to change the (open-source) code. Experimentation with redefining Maxima
198 Lisp code is easily possible: to change the definition of a Lisp program (say
199 the one that simplifies @code{cos()}, named @code{simp%cos}), you simply
200 load into Maxima a text file that will overwrite the @code{simp%cos} function
201 from the maxima package.
203 @c -----------------------------------------------------------------------------
204 @node Functions and Variables for Simplification, , Introduction to Simplification, Simplification
205 @section Functions and Variables for Simplification
206 @c -----------------------------------------------------------------------------
208 @c -----------------------------------------------------------------------------
210 @defvr {Property} additive
212 If @code{declare(f,additive)} has been executed, then:
214 (1) If @code{f} is univariate, whenever the simplifier encounters @code{f}
215 applied to a sum, @code{f} will be distributed over that sum. I.e.
216 @code{f(y+x)} will simplify to @code{f(y)+f(x)}.
218 (2) If @code{f} is a function of 2 or more arguments, additivity is defined as
219 additivity in the first argument to @code{f}, as in the case of @code{sum} or
220 @code{integrate}, i.e. @code{f(h(x)+g(x),x)} will simplify to
221 @code{f(h(x),x)+f(g(x),x)}. This simplification does not occur when @code{f} is
222 applied to expressions of the form @code{sum(x[i],i,lower-limit,upper-limit)}.
228 @c declare (F3, additive);
233 (%i1) F3 (a + b + c);
237 (%i2) declare (F3, additive);
241 (%i3) F3 (a + b + c);
242 (%o3) F3(c) + F3(b) + F3(a)
246 @opencatbox{Categories:}
248 @category{Declarations and inferences}
252 @c -----------------------------------------------------------------------------
253 @anchor{antisymmetric}
254 @defvr {Property} antisymmetric
256 If @code{declare(h,antisymmetric)} is done, this tells the simplifier that
257 @code{h} is antisymmetric. E.g. @code{h(x,z,y)} will simplify to
258 @code{- h(x, y, z)}. That is, it will give (-1)^n times the result given by
259 @mref{symmetric} or @mrefcomma{commutative} where n is the number of interchanges
260 of two arguments necessary to convert it to that form.
266 @c declare (S, symmetric);
268 @c S (a, c, e, d, b);
270 @c declare (T, antisymmetric);
272 @c T (a, c, e, d, b);
280 (%i2) declare (S, symmetric);
288 (%i4) S (a, c, e, d, b);
289 (%o4) S(a, b, c, d, e)
296 (%i6) declare (T, antisymmetric);
304 (%i8) T (a, c, e, d, b);
305 (%o8) T(a, b, c, d, e)
309 @opencatbox{Categories:}
311 @category{Declarations and inferences}
315 @c -----------------------------------------------------------------------------
317 @deffn {Function} combine (@var{expr})
319 Simplifies the sum @var{expr} by combining terms with the same
320 denominator into a single term.
322 See also: @mrefdot{rncombine}
327 @c 1*f/2*b + 2*c/3*a + 3*f/4*b +c/5*b*a;
332 (%i1) 1*f/2*b + 2*c/3*a + 3*f/4*b +c/5*b*a;
334 (%o1) ----- + ----- + -----
339 75 b f + 4 (3 a b c + 10 a c)
340 (%o2) -----------------------------
345 @opencatbox{Categories:}
346 @category{Expressions}
350 @c -----------------------------------------------------------------------------
352 @defvr {Property} commutative
354 If @code{declare(h, commutative)} is done, this tells the simplifier that
355 @code{h} is a commutative function. E.g. @code{h(x, z, y)} will simplify to
356 @code{h(x, y, z)}. This is the same as @mrefdot{symmetric}
362 @c S (a, b) + S (b, a);
363 @c declare (S, commutative);
365 @c S (a, b) + S (b, a);
366 @c S (a, c, e, d, b);
374 (%i2) S (a, b) + S (b, a);
375 (%o2) S(b, a) + S(a, b)
378 (%i3) declare (S, commutative);
386 (%i5) S (a, b) + S (b, a);
390 (%i6) S (a, c, e, d, b);
391 (%o6) S(a, b, c, d, e)
395 @opencatbox{Categories:}
397 @category{Declarations and inferences}
401 @c NEEDS CLARIFICATION, EXAMPLES
403 @c -----------------------------------------------------------------------------
405 @deffn {Function} demoivre (@var{expr})
406 @deffnx {Option variable} demoivre
408 The function @code{demoivre (expr)} converts one expression
409 without setting the global variable @code{demoivre}.
411 When the variable @code{demoivre} is @code{true}, complex exponentials are
412 converted into equivalent expressions in terms of circular functions:
413 @code{exp (a + b*%i)} simplifies to @code{%e^a * (cos(b) + %i*sin(b))}
414 if @code{b} is free of @code{%i}. @code{a} and @code{b} are not expanded.
416 The default value of @code{demoivre} is @code{false}.
418 @code{exponentialize} converts circular and hyperbolic functions to exponential
419 form. @code{demoivre} and @code{exponentialize} cannot both be true at the same
422 @opencatbox{Categories:}
423 @category{Complex variables}
424 @category{Trigonometric functions}
425 @category{Hyperbolic functions}
431 @c -----------------------------------------------------------------------------
432 @anchor{function_distrib}
433 @deffn {Function} distrib (@var{expr})
435 Distributes sums over products. It differs from @code{expand} in that it works
436 at only the top level of an expression, i.e., it doesn't recurse and it is
437 faster than @code{expand}. It differs from @code{multthru} in that it expands
438 all sums at that level.
443 @c distrib ((a+b) * (c+d));
444 @c multthru ((a+b) * (c+d));
445 @c distrib (1/((a+b) * (c+d)));
446 @c expand (1/((a+b) * (c+d)), 1, 0);
449 (%i1) distrib ((a+b) * (c+d));
450 (%o1) b d + a d + b c + a c
451 (%i2) multthru ((a+b) * (c+d));
452 (%o2) (b + a) d + (b + a) c
453 (%i3) distrib (1/((a+b) * (c+d)));
455 (%o3) ---------------
457 (%i4) expand (1/((a+b) * (c+d)), 1, 0);
459 (%o4) ---------------------
460 b d + a d + b c + a c
463 @opencatbox{Categories:}
464 @category{Expressions}
468 @c -----------------------------------------------------------------------------
469 @anchor{distribute_over}
470 @defvr {Option variable} distribute_over
471 Default value: @code{true}
473 @code{distribute_over} controls the mapping of functions over bags like lists,
474 matrices, and equations. At this time not all Maxima functions have this
475 property. It is possible to look up this property with the command
476 @mrefdot{properties}.
478 The mapping of functions is switched off, when setting @code{distribute_over}
479 to the value @code{false}.
483 The @code{sin} function maps over a list:
490 (%i1) sin([x,1,1.0]);
491 (%o1) [sin(x), sin(1), 0.8414709848078965]
495 @code{mod} is a function with two arguments which maps over lists. Mapping over
496 nested lists is possible too:
499 @c mod([x,11,2*a],10);
500 @c mod([[x,y,z],11,2*a],10);
504 (%i1) mod([x,11,2*a],10);
505 (%o1) [mod(x, 10), 1, 2 mod(a, 5)]
508 (%i2) mod([[x,y,z],11,2*a],10);
509 (%o2) [[mod(x, 10), mod(y, 10), mod(z, 10)], 1, 2 mod(a, 5)]
513 Mapping of the @code{floor} function over a matrix and an equation:
516 @c floor(matrix([a,b],[c,d]));
521 (%i1) floor(matrix([a,b],[c,d]));
522 [ floor(a) floor(b) ]
524 [ floor(c) floor(d) ]
528 (%o2) floor(a) = floor(b)
532 Functions with more than one argument map over any of the arguments or all
536 @c expintegral_e([1,2],[x,y]);
540 (%i1) expintegral_e([1,2],[x,y]);
541 (%o1) [[expintegral_e(1, x), expintegral_e(1, y)],
542 [expintegral_e(2, x), expintegral_e(2, y)]]
546 Check if a function has the property distribute_over:
553 (%i1) properties(abs);
554 (%o1) [integral, rule, distributes over bags, noun, gradef,
559 The mapping of functions is switched off, when setting @code{distribute_over}
560 to the value @code{false}.
565 @c distribute_over : not distribute_over;
570 (%i1) distribute_over;
574 (%i2) sin([x,1,1.0]);
575 (%o2) [sin(x), sin(1), 0.8414709848078965]
578 (%i3) distribute_over : not distribute_over;
582 (%i4) sin([x,1,1.0]);
583 (%o4) sin([x, 1, 1.0])
587 @opencatbox{Categories:}
588 @category{Simplification flags and variables}
592 @c -----------------------------------------------------------------------------
594 @defvr {Option variable} domain
595 Default value: @code{real}
597 When @code{domain} is set to @code{complex}, @code{sqrt (x^2)} will remain
598 @code{sqrt (x^2)} instead of returning @code{abs(x)}.
600 @c PRESERVE EDITORIAL COMMENT -- MAY HAVE SOME SIGNIFICANCE NOT YET UNDERSTOOD !!!
601 @c The notion of a "domain" of simplification is still in its infancy,
602 @c and controls little more than this at the moment.
604 @opencatbox{Categories:}
605 @category{Simplification flags and variables}
609 @c -----------------------------------------------------------------------------
612 @defvr {Property} evenfun
613 @defvrx {Property} oddfun
615 @code{declare(f, evenfun)} or @code{declare(f, oddfun)} tells Maxima to recognize
616 the function @code{f} as an even or odd function.
622 @c declare (o, oddfun);
625 @c declare (e, evenfun);
629 (%i1) o (- x) + o (x);
631 (%i2) declare (o, oddfun);
633 (%i3) o (- x) + o (x);
635 (%i4) e (- x) - e (x);
637 (%i5) declare (e, evenfun);
639 (%i6) e (- x) - e (x);
644 @c -----------------------------------------------------------------------------
646 @deffn {Function} expand @
647 @fname{expand} (@var{expr}) @
648 @fname{expand} (@var{expr}, @var{p}, @var{n})
650 Expand expression @var{expr}.
651 Products of sums and exponentiated sums are
652 multiplied out, numerators of rational expressions which are sums are
653 split into their respective terms, and multiplication (commutative
654 and non-commutative) are distributed over addition at all levels of
657 For polynomials one should usually use @code{ratexpand} which uses a
658 more efficient algorithm.
660 @code{maxnegex} and @code{maxposex} control the maximum negative and
661 positive exponents, respectively, which will expand.
663 @code{expand (@var{expr}, @var{p}, @var{n})} expands @var{expr},
664 using @var{p} for @code{maxposex} and @var{n} for @code{maxnegex}.
665 This is useful in order to expand part but not all of an expression.
667 @code{expon} - the exponent of the largest negative power which is
668 automatically expanded (independent of calls to @code{expand}). For example
669 if @code{expon} is 4 then @code{(x+1)^(-5)} will not be automatically expanded.
671 @code{expop} - the highest positive exponent which is automatically expanded.
672 Thus @code{(x+1)^3}, when typed, will be automatically expanded only if
673 @code{expop} is greater than or equal to 3. If it is desired to have
674 @code{(x+1)^n} expanded where @code{n} is greater than @code{expop} then
675 executing @code{expand ((x+1)^n)} will work only if @code{maxposex} is not
678 @code{expand(expr, 0, 0)} causes a resimplification of @code{expr}. @code{expr}
679 is not reevaluated. In distinction from @code{ev(expr, noeval)} a special
680 representation (e. g. a CRE form) is removed. See also @mrefdot{ev}
682 The @code{expand} flag used with @code{ev} causes expansion.
684 The file @file{share/simplification/facexp.mac}
685 @c I should really use a macro which expands to something like
686 @c @uref{file://...,,simplification/facexp.mac}. But texi2html
687 @c currently supports @uref only with one argument.
688 @c Worse, the `file:' scheme is OS and browser dependent.
689 contains several related functions (in particular @code{facsum},
690 @code{factorfacsum} and @code{collectterms}, which are autoloaded) and variables
691 (@code{nextlayerfactor} and @code{facsum_combine}) that provide the user with
692 the ability to structure expressions by controlled expansion.
693 @c MERGE share/simplification/facexp.usg INTO THIS FILE OR CREATE NEW FILE facexp.texi
694 Brief function descriptions are available in @file{simplification/facexp.usg}.
695 A demo is available by doing @code{demo("facexp")}.
700 @c expr:(x+1)^2*(y+1)^3;
703 @c expr:(x+1)^-2*(y+1)^3;
709 (%i1) expr:(x+1)^2*(y+1)^3;
711 (%o1) (x + 1) (y + 1)
716 (%o2) x y + 2 x y + y + 3 x y + 6 x y + 3 y + 3 x y
718 + 6 x y + 3 y + x + 2 x + 1
721 (%i3) expand(expr,2);
723 (%o3) x (y + 1) + 2 x (y + 1) + (y + 1)
726 (%i4) expr:(x+1)^-2*(y+1)^3;
737 (%o5) ------------ + ------------ + ------------ + ------------
739 x + 2 x + 1 x + 2 x + 1 x + 2 x + 1 x + 2 x + 1
742 (%i6) expand(expr,2,2);
751 Resimplify an expression without expansion:
754 @c expr:(1+x)^2*sin(x);
755 @c exponentialize:true;
760 (%i1) expr:(1+x)^2*sin(x);
765 (%i2) exponentialize:true;
769 (%i3) expand(expr,0,0);
771 %i (x + 1) (%e - %e )
772 (%o3) - -------------------------------
777 @opencatbox{Categories:}
778 @category{Expressions}
784 @c -----------------------------------------------------------------------------
786 @deffn {Function} expandwrt (@var{expr}, @var{x_1}, @dots{}, @var{x_n})
788 Expands expression @code{expr} with respect to the
789 variables @var{x_1}, @dots{}, @var{x_n}.
790 All products involving the variables appear explicitly. The form returned
791 will be free of products of sums of expressions that are not free of
792 the variables. @var{x_1}, @dots{}, @var{x_n}
793 may be variables, operators, or expressions.
795 By default, denominators are not expanded, but this can be controlled by
796 means of the switch @code{expandwrt_denom}.
798 This function is autoloaded from
799 @file{simplification/stopex.mac}.
801 @opencatbox{Categories:}
802 @category{Expressions}
806 @c -----------------------------------------------------------------------------
807 @anchor{expandwert_denom}
808 @defvr {Option variable} expandwrt_denom
809 Default value: @code{false}
811 @code{expandwrt_denom} controls the treatment of rational
812 expressions by @code{expandwrt}. If @code{true}, then both the numerator and
813 denominator of the expression will be expanded according to the
814 arguments of @code{expandwrt}, but if @code{expandwrt_denom} is @code{false},
815 then only the numerator will be expanded in that way.
817 @opencatbox{Categories:}
818 @category{Expressions}
822 @c NEEDS A STAND-ALONE DESCRIPTION (NOT "IS SIMILAR TO")
825 @c -----------------------------------------------------------------------------
826 @anchor{expandwrt_factored}
827 @deffn {Function} expandwrt_factored (@var{expr}, @var{x_1}, @dots{}, @var{x_n})
829 is similar to @code{expandwrt}, but treats expressions that are products
830 somewhat differently. @code{expandwrt_factored} expands only on those factors
831 of @code{expr} that contain the variables @var{x_1}, @dots{}, @var{x_n}.
833 @c NOT SURE WHY WE SHOULD MENTION THIS HERE
834 This function is autoloaded from @file{simplification/stopex.mac}.
836 @opencatbox{Categories:}
837 @category{Expressions}
841 @c -----------------------------------------------------------------------------
843 @defvr {Option variable} expon
846 @code{expon} is the exponent of the largest negative power which
847 is automatically expanded (independent of calls to @code{expand}). For
848 example, if @code{expon} is 4 then @code{(x+1)^(-5)} will not be automatically
851 @opencatbox{Categories:}
852 @category{Expressions}
856 @c -----------------------------------------------------------------------------
857 @anchor{exponentialize}
858 @deffn {Function} exponentialize (@var{expr})
859 @deffnx {Option variable} exponentialize
861 The function @code{exponentialize (expr)} converts
862 circular and hyperbolic functions in @var{expr} to exponentials,
863 without setting the global variable @code{exponentialize}.
865 When the variable @code{exponentialize} is @code{true},
866 all circular and hyperbolic functions are converted to exponential form.
867 The default value is @code{false}.
869 @code{demoivre} converts complex exponentials into circular functions.
870 @code{exponentialize} and @code{demoivre} cannot
871 both be true at the same time.
873 @opencatbox{Categories:}
874 @category{Complex variables}
875 @category{Trigonometric functions}
876 @category{Hyperbolic functions}
880 @c NEEDS CLARIFICATION
883 @c -----------------------------------------------------------------------------
885 @defvr {Option variable} expop
888 @code{expop} is the highest positive exponent which is automatically expanded.
889 Thus @code{(x + 1)^3}, when typed, will be automatically expanded only if
890 @code{expop} is greater than or equal to 3. If it is desired to have
891 @code{(x + 1)^n} expanded where @code{n} is greater than @code{expop} then
892 executing @code{expand ((x + 1)^n)} will work only if @code{maxposex} is not
895 @opencatbox{Categories:}
896 @category{Expressions}
900 @c NEEDS CLARIFICATION, EXAMPLES
902 @c -----------------------------------------------------------------------------
903 @anchor{lassociative}
904 @defvr {Property} lassociative
906 @code{declare (g, lassociative)} tells the Maxima simplifier that @code{g} is
907 left-associative. E.g., @code{g (g (a, b), g (c, d))} will simplify to
908 @code{g (g (g (a, b), c), d)}.
910 See also @mrefdot{rassociative}
912 @opencatbox{Categories:}
913 @category{Declarations and inferences}
915 @category{Simplification}
919 @c NEEDS CLARIFICATION, EXAMPLES
920 @c WHAT'S UP WITH THE QUOTE MARKS ??
922 @c -----------------------------------------------------------------------------
924 @defvr {Property} linear
926 One of Maxima's operator properties. For univariate @code{f} so
927 declared, "expansion" @code{f(x + y)} yields @code{f(x) + f(y)},
928 @code{f(a*x)} yields @code{a*f(x)} takes
929 place where @code{a} is a "constant". For functions of two or more arguments,
930 "linearity" is defined to be as in the case of @mref{sum} or @mrefcomma{integrate}
931 i.e., @code{f (a*x + b, x)} yields @code{a*f(x,x) + b*f(1,x)}
932 for @code{a} and @code{b} free of @code{x}.
937 @c declare (f, linear);
939 @c declare (a, constant);
944 (%i1) declare (f, linear);
952 (%i3) declare (a, constant);
961 @code{linear} is equivalent to @mref{additive} and @mrefdot{outative}
962 See also @mrefdot{opproperties}
967 @c 'sum (F(k) + G(k), k, 1, inf);
968 @c declare (nounify (sum), linear);
969 @c 'sum (F(k) + G(k), k, 1, inf);
973 (%i1) 'sum (F(k) + G(k), k, 1, inf);
977 (%o1) > (G(k) + F(k))
983 (%i2) declare (nounify (sum), linear);
987 (%i3) 'sum (F(k) + G(k), k, 1, inf);
991 (%o3) > G(k) + > F(k)
998 @opencatbox{Categories:}
999 @category{Declarations and inferences}
1000 @category{Operators}
1001 @category{Simplification}
1007 @c -----------------------------------------------------------------------------
1009 @defvr {Option variable} maxnegex
1012 @code{maxnegex} is the largest negative exponent which will
1013 be expanded by the @code{expand} command, see also @mrefdot{maxposex}
1015 @opencatbox{Categories:}
1016 @category{Expressions}
1022 @c -----------------------------------------------------------------------------
1024 @defvr {Option variable} maxposex
1027 @code{maxposex} is the largest exponent which will be
1028 expanded with the @code{expand} command, see also @mrefdot{maxnegex}
1030 @opencatbox{Categories:}
1031 @category{Expressions}
1037 @c -----------------------------------------------------------------------------
1038 @anchor{multiplicative}
1039 @defvr {Property} multiplicative
1041 @code{declare(f, multiplicative)} tells the Maxima simplifier that @code{f}
1046 If @code{f} is univariate, whenever the simplifier encounters @code{f} applied
1047 to a product, @code{f} distributes over that product. E.g., @code{f(x*y)}
1048 simplifies to @code{f(x)*f(y)}.
1049 This simplification is not applied to expressions of the form @code{f('product(...))}.
1051 If @code{f} is a function of 2 or more arguments, multiplicativity is
1052 defined as multiplicativity in the first argument to @code{f}, e.g.,
1053 @code{f (g(x) * h(x), x)} simplifies to @code{f (g(x) ,x) * f (h(x), x)}.
1056 @code{declare(nounify(product), multiplicative)} tells Maxima to simplify symbolic products.
1062 @c declare (F2, multiplicative);
1067 (%i1) F2 (a * b * c);
1071 (%i2) declare (F2, multiplicative);
1075 (%i3) F2 (a * b * c);
1076 (%o3) F2(a) F2(b) F2(c)
1080 @code{declare(nounify(product), multiplicative)} tells Maxima to simplify symbolic products.
1083 @c product (a[i] * b[i], i, 1, n);
1084 @c declare (nounify (product), multiplicative);
1085 @c product (a[i] * b[i], i, 1, n);
1089 (%i1) product (a[i] * b[i], i, 1, n);
1098 (%i2) declare (nounify (product), multiplicative);
1102 (%i3) product (a[i] * b[i], i, 1, n);
1106 (%o3) ( ! ! a ) ! ! b
1112 @opencatbox{Categories:}
1113 @category{Declarations and inferences}
1114 @category{Expressions}
1115 @category{Simplification}
1121 @c -----------------------------------------------------------------------------
1123 @deffn {Function} multthru @
1124 @fname{multthru} (@var{expr}) @
1125 @fname{multthru} (@var{expr_1}, @var{expr_2})
1127 Multiplies a factor (which should be a sum) of @var{expr} by the other factors
1128 of @var{expr}. That is, @var{expr} is @code{@var{f_1} @var{f_2} ... @var{f_n}}
1129 where at least one factor, say @var{f_i}, is a sum of terms. Each term in that
1130 sum is multiplied by the other factors in the product. (Namely all the factors
1131 except @var{f_i}). @code{multthru} does not expand exponentiated sums.
1132 This function is the fastest way to distribute products (commutative or
1133 noncommutative) over sums. Since quotients are represented as products
1134 @code{multthru} can be used to divide sums by products as well.
1136 @code{multthru (@var{expr_1}, @var{expr_2})} multiplies each term in
1137 @var{expr_2} (which should be a sum or an equation) by @var{expr_1}. If
1138 @var{expr_1} is not itself a sum then this form is equivalent to
1139 @code{multthru (@var{expr_1}*@var{expr_2})}.
1142 @c x/(x-y)^2 - 1/(x-y) - f(x)/(x-y)^3;
1143 @c multthru ((x-y)^3, %);
1145 @c ((a+b)^10*s^2 + 2*a*b*s + (a*b)^2)/(a*b*s^2);
1146 @c multthru (%); /* note that this does not expand (b+a)^10 */
1147 @c multthru (a.(b+c.(d+e)+f));
1148 @c expand (a.(b+c.(d+e)+f));
1151 (%i1) x/(x-y)^2 - 1/(x-y) - f(x)/(x-y)^3;
1153 (%o1) - ----- + -------- - --------
1156 (%i2) multthru ((x-y)^3, %);
1158 (%o2) - (x - y) + x (x - y) - f(x)
1159 (%i3) ratexpand (%);
1161 (%o3) - y + x y - f(x)
1162 (%i4) ((a+b)^10*s^2 + 2*a*b*s + (a*b)^2)/(a*b*s^2);
1164 (b + a) s + 2 a b s + a b
1165 (%o4) ------------------------------
1168 (%i5) multthru (%); /* note that this does not expand (b+a)^10 */
1171 (%o5) - + --- + ---------
1174 (%i6) multthru (a.(b+c.(d+e)+f));
1175 (%o6) a . f + a . c . (e + d) + a . b
1176 (%i7) expand (a.(b+c.(d+e)+f));
1177 (%o7) a . f + a . c . e + a . c . d + a . b
1180 @opencatbox{Categories:}
1181 @category{Expressions}
1185 @c -----------------------------------------------------------------------------
1186 @anchor{property_nary}
1187 @defvr {Property} nary
1189 @code{declare(f, nary)} tells Maxima to recognize the function @code{f} as an
1192 The @code{nary} declaration is not the same as calling the
1193 @mxref{function_nary, nary} function. The sole effect of
1194 @code{declare(f, nary)} is to instruct the Maxima simplifier to flatten nested
1195 expressions, for example, to simplify @code{foo(x, foo(y, z))} to
1196 @code{foo(x, y, z)}. See also @mrefdot{declare}
1201 @c H (H (a, b), H (c, H (d, e)));
1202 @c declare (H, nary);
1203 @c H (H (a, b), H (c, H (d, e)));
1206 (%i1) H (H (a, b), H (c, H (d, e)));
1207 (%o1) H(H(a, b), H(c, H(d, e)))
1208 (%i2) declare (H, nary);
1210 (%i3) H (H (a, b), H (c, H (d, e)));
1211 (%o3) H(a, b, c, d, e)
1215 @c NEEDS CLARIFICATION, EXAMPLES
1217 @c -----------------------------------------------------------------------------
1219 @defvr {Option variable} negdistrib
1220 Default value: @code{true}
1222 When @code{negdistrib} is @code{true}, -1 distributes over an expression.
1223 E.g., @code{-(x + y)} becomes @code{- y - x}. Setting it to @code{false}
1224 will allow @code{- (x + y)} to be displayed like that. This is sometimes useful
1225 but be very careful: like the @code{simp} flag, this is one flag you do not
1226 want to set to @code{false} as a matter of course or necessarily for other
1227 than local use in your Maxima.
1234 @c negdistrib : not negdistrib ;
1247 (%i3) negdistrib : not negdistrib ;
1256 @opencatbox{Categories:}
1257 @category{Simplification flags and variables}
1261 @c -----------------------------------------------------------------------------
1262 @anchor{opproperties}
1263 @defvr {System variable} opproperties
1265 @code{opproperties} is the list of the special operator properties recognized
1266 by the Maxima simplifier.
1268 Items are added to the @code{opproperties} list by the function @mrefdot{define_opproperty}
1278 (%o1) [linear, additive, multiplicative, outative, evenfun,
1279 oddfun, commutative, symmetric, antisymmetric, nary,
1280 lassociative, rassociative]
1284 @opencatbox{Categories:}
1285 @category{Global variables}
1286 @category{Operators}
1287 @category{Simplification}
1293 @c -----------------------------------------------------------------------------
1294 @anchor{define_opproperty}
1295 @deffn {Function} define_opproperty (@var{property_name}, @var{simplifier_fn})
1297 Declares the symbol @var{property_name} to be an operator property,
1298 which is simplified by @var{simplifier_fn},
1299 which may be the name of a Maxima or Lisp function or a lambda expression.
1300 After @code{define_opproperty} is called,
1301 functions and operators may be declared to have the @var{property_name} property,
1302 and @var{simplifier_fn} is called to simplify them.
1304 @var{simplifier_fn} must be a function of one argument,
1305 which is an expression in which the main operator is declared to have the @var{property_name} property.
1307 @var{simplifier_fn} is called with the global flag @code{simp} disabled.
1308 Therefore @var{simplifier_fn} must be able to carry out its simplification
1309 without making use of the general simplifier.
1311 @code{define_opproperty} appends @var{property_name} to the
1312 global list @mrefdot{opproperties}
1314 @code{define_opproperty} returns @code{done}.
1318 Declare a new property, @code{identity}, which is simplified by @code{simplify_identity}.
1319 Declare that @code{f} and @code{g} have the new property.
1322 @c define_opproperty (identity, simplify_identity);
1323 @c simplify_identity(e) := first(e);
1324 @c declare ([f, g], identity);
1330 (%i1) define_opproperty (identity, simplify_identity);
1334 (%i2) simplify_identity(e) := first(e);
1335 (%o2) simplify_identity(e) := first(e)
1338 (%i3) declare ([f, g], identity);
1346 (%i5) g(3*u) - f(2*u);
1351 @opencatbox{Categories:}
1352 @category{Operators}
1353 @category{Simplification}
1357 @c -----------------------------------------------------------------------------
1359 @defvr {Property} outative
1361 @code{declare(f, outative)} tells the Maxima simplifier that constant factors
1362 in the argument of @code{f} can be pulled out.
1366 If @code{f} is univariate, whenever the simplifier encounters @code{f} applied
1367 to a product, that product will be partitioned into factors that are constant
1368 and factors that are not and the constant factors will be pulled out. E.g.,
1369 @code{f(a*x)} will simplify to @code{a*f(x)} where @code{a} is a constant.
1370 Non-atomic constant factors will not be pulled out.
1372 If @code{f} is a function of 2 or more arguments, outativity is defined as in
1373 the case of @mref{sum} or @mrefcomma{integrate} i.e., @code{f (a*g(x), x)} will
1374 simplify to @code{a * f(g(x), x)} for @code{a} free of @code{x}.
1377 @mrefcomma{sum} @mrefcomma{integrate} and @mref{limit} are all @code{outative}.
1383 @c declare (F1, outative);
1385 @c declare (zz, constant);
1394 (%i2) declare (F1, outative);
1402 (%i4) declare (zz, constant);
1411 @opencatbox{Categories:}
1412 @category{Declarations and inferences}
1413 @category{Operators}
1417 @c -----------------------------------------------------------------------------
1419 @deffn {Function} radcan (@var{expr})
1421 Simplifies @var{expr}, which can contain logs, exponentials, and radicals, by
1422 converting it into a form which is canonical over a large class of expressions
1423 and a given ordering of variables; that is, all functionally equivalent forms
1424 are mapped into a unique form. For a somewhat larger class of expressions,
1425 @code{radcan} produces a regular form. Two equivalent expressions in this class
1426 do not necessarily have the same appearance, but their difference can be
1427 simplified by @code{radcan} to zero.
1429 For some expressions @code{radcan} is quite time consuming. This is the cost
1430 of exploring certain relationships among the components of the expression for
1431 simplifications based on factoring and partial-fraction expansions of exponents.
1433 @c %e_to_numlog NEEDS ITS OWN @defvar !!!
1435 @c %e_to_numlog HAS NO EFFECT ON RADCAN. RADCAN ALWAYS SIMPLIFIES
1436 @c exp(a*log(x)) --> x^a. Commenting the following out. 11/2009
1437 @c When @code{%e_to_numlog} is @code{true}, @code{%e^(r*log(expr))} simplifies
1438 @c to @code{expr^r} if @code{r} is a rational number.
1440 @c RADEXPAND CONTROLS THE SIMPLIFICATION OF THE POWER FUNCTION, E.G.
1441 @c (x*y)^a --> x^a*y^a AND (x^a)^b --> x^(a*b), IF RADEXPAND HAS THE VALUE 'ALL.
1442 @c THE VALUE OF RADEXPAND HAS NO EFFECT ON RADCAN. RADCAN ALWAYS SIMPLIFIES
1443 @c THE ABOVE EXPRESSIONS. COMMENTING THE FOLLOWING OUT. 11/2009
1444 @c When @code{radexpand} is @code{false}, certain transformations are inhibited.
1445 @c @code{radcan (sqrt (1-x))} remains @code{sqrt (1-x)} and is not simplified
1446 @c to @code{%i sqrt (x-1)}. @code{radcan (sqrt (x^2 - 2*x + 1))} remains
1447 @c @code{sqrt (x^2 - 2*x + 1)} and is not simplified to @code{x - 1}.
1452 @c radcan((log(x+x^2)-log(x))^a/log(1+x)^(a/2));
1453 @c radcan((log(1+2*a^x+a^(2*x))/log(1+a^x)));
1454 @c radcan((%e^x-1)/(1+%e^(x/2)));
1458 (%i1) radcan((log(x+x^2)-log(x))^a/log(1+x)^(a/2));
1463 (%i2) radcan((log(1+2*a^x+a^(2*x))/log(1+a^x)));
1467 (%i3) radcan((%e^x-1)/(1+%e^(x/2)));
1473 @opencatbox{Categories:}
1474 @category{Simplification functions}
1478 @c NEEDS CLARIFICATION, EXAMPLES
1480 @c -----------------------------------------------------------------------------
1482 @defvr {Option variable} radexpand
1483 Default value: @code{true}
1485 @code{radexpand} controls some simplifications of radicals.
1487 When @code{radexpand} is @code{all}, causes nth roots of factors of a product
1488 which are powers of n to be pulled outside of the radical. E.g. if
1489 @code{radexpand} is @code{all}, @code{sqrt (16*x^2)} simplifies to @code{4*x}.
1491 @c EXPRESS SIMPLIFICATON RULES IN GENERAL CASE, NOT SPECIAL CASE
1492 More particularly, consider @code{sqrt (x^2)}.
1495 If @code{radexpand} is @code{all} or @code{assume (x > 0)} has been executed,
1496 @code{sqrt(x^2)} simplifies to @code{x}.
1498 If @code{radexpand} is @code{true} and @code{domain} is @code{real}
1499 (its default), @code{sqrt(x^2)} simplifies to @code{abs(x)}.
1501 If @code{radexpand} is @code{false}, or @code{radexpand} is @code{true} and
1502 @code{domain} is @code{complex}, @code{sqrt(x^2)} is not simplified.
1505 @c CORRECT STATEMENT HERE ???
1506 Note that @code{domain} only matters when @code{radexpand} is @code{true}.
1508 @opencatbox{Categories:}
1509 @category{Simplification flags and variables}
1513 @c NEEDS CLARIFICATION, EXAMPLES
1515 @c -----------------------------------------------------------------------------
1516 @anchor{rassociative}
1517 @defvr {Property} rassociative
1519 @code{declare (g, rassociative)} tells the Maxima
1520 simplifier that @code{g} is right-associative. E.g.,
1521 @code{g(g(a, b), g(c, d))} simplifies to @code{g(a, g(b, g(c, d)))}.
1523 See also @mrefdot{lassociative}
1525 @opencatbox{Categories:}
1526 @category{Declarations and inferences}
1527 @category{Operators}
1531 @c NEEDS CLARIFICATION, EXAMPLES
1533 @c -----------------------------------------------------------------------------
1535 @deffn {Function} scsimp (@var{expr}, @var{rule_1}, @dots{}, @var{rule_n})
1537 Sequential Comparative Simplification (method due to Stoute).
1538 @code{scsimp} attempts to simplify @var{expr}
1539 according to the rules @var{rule_1}, @dots{}, @var{rule_n}.
1540 If a smaller expression is obtained, the process repeats. Otherwise after all
1541 simplifications are tried, it returns the original answer.
1543 @c MERGE EXAMPLES INTO THIS FILE
1544 @code{example (scsimp)} displays some examples.
1546 @opencatbox{Categories:}
1547 @category{Simplification functions}
1551 @c -----------------------------------------------------------------------------
1553 @defvr {Option variable} simp
1554 Default value: @code{true}
1556 @code{simp} enables simplification. This is the default. @code{simp} is also
1557 an @code{evflag}, which is recognized by the function @code{ev}. See @mrefdot{ev}
1559 When @code{simp} is used as an @code{evflag} with a value @code{false}, the
1560 simplification is suppressed only during the evaluation phase of an expression.
1561 The flag does not suppress the simplification which follows the evaluation
1564 Many Maxima functions and operations require simplification to be enabled to work normally.
1565 When simplification is disabled, many results will be incomplete,
1566 and in addition there may be incorrect results or program errors.
1570 The simplification is switched off globally. The expression @code{sin(1.0)} is
1571 not simplified to its numerical value. The @code{simp}-flag switches the
1589 (%i3) sin(1.0),simp;
1590 (%o3) 0.8414709848078965
1594 The simplification is switched on again. The @code{simp}-flag cannot suppress
1595 the simplification completely. The output shows a simplified expression, but
1596 the variable @code{x} has an unsimplified expression as a value, because the
1597 assignment has occurred during the evaluation phase of the expression.
1601 @c x:sin(1.0),simp:false;
1610 (%i2) x:sin(1.0),simp:false;
1611 (%o2) 0.8414709848078965
1619 @opencatbox{Categories:}
1620 @category{Evaluation flags}
1624 @c NEEDS CLARIFICATION, EXAMPLES
1626 @c -----------------------------------------------------------------------------
1628 @defvr {Property} symmetric
1630 @code{declare (h, symmetric)} tells the Maxima
1631 simplifier that @code{h} is a symmetric function. E.g., @code{h (x, z, y)}
1632 simplifies to @code{h (x, y, z)}.
1634 @mref{commutative} is synonymous with @code{symmetric}.
1636 @opencatbox{Categories:}
1637 @category{Declarations and inferences}
1638 @category{Operators}
1642 @c -----------------------------------------------------------------------------
1644 @deffn {Function} xthru (@var{expr})
1646 Combines all terms of @var{expr} (which should be a sum) over a common
1647 denominator without expanding products and exponentiated sums as @code{ratsimp}
1648 does. @code{xthru} cancels common factors in the numerator and denominator of
1649 rational expressions but only if the factors are explicit.
1651 @c REPHRASE IN NEUTRAL TONE (GET RID OF "IT IS BETTER")
1652 Sometimes it is better to use @code{xthru} before @code{ratsimp}ing an
1653 expression in order to cause explicit factors of the gcd of the numerator and
1654 denominator to be canceled thus simplifying the expression to be
1660 @c ((x+2)^20 - 2*y)/(x+y)^20 + (x+y)^(-19) - x/(x+y)^20;
1665 (%i1) ((x+2)^20 - 2*y)/(x+y)^20 + (x+y)^(-19) - x/(x+y)^20;
1668 (%o1) --------- + --------------- - ---------
1670 (y + x) (y + x) (y + x)
1682 @opencatbox{Categories:}
1683 @category{Expressions}