2 * Introduction to Simplification::
3 * Functions and Variables for Simplification::
6 @c -----------------------------------------------------------------------------
7 @node Introduction to Simplification, Functions and Variables for 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{simplification-pkg}.
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 @code{symmetric} or @code{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 @code{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
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 @opencatbox{Categories:}
911 @category{Declarations and inferences}
913 @category{Simplification}
917 @c NEEDS CLARIFICATION, EXAMPLES
918 @c WHAT'S UP WITH THE QUOTE MARKS ??
920 @c -----------------------------------------------------------------------------
922 @defvr {Property} linear
924 One of Maxima's operator properties. For univariate @code{f} so
925 declared, "expansion" @code{f(x + y)} yields @code{f(x) + f(y)},
926 @code{f(a*x)} yields @code{a*f(x)} takes
927 place where @code{a} is a "constant". For functions of two or more arguments,
928 "linearity" is defined to be as in the case of @code{sum} or @code{integrate},
929 i.e., @code{f (a*x + b, x)} yields @code{a*f(x,x) + b*f(1,x)}
930 for @code{a} and @code{b} free of @code{x}.
935 @c declare (f, linear);
937 @c declare (a, constant);
942 (%i1) declare (f, linear);
950 (%i3) declare (a, constant);
959 @code{linear} is equivalent to @code{additive} and @code{outative}.
960 See also @mrefdot{opproperties}
965 @c 'sum (F(k) + G(k), k, 1, inf);
966 @c declare (nounify (sum), linear);
967 @c 'sum (F(k) + G(k), k, 1, inf);
971 (%i1) 'sum (F(k) + G(k), k, 1, inf);
975 (%o1) > (G(k) + F(k))
981 (%i2) declare (nounify (sum), linear);
985 (%i3) 'sum (F(k) + G(k), k, 1, inf);
989 (%o3) > G(k) + > F(k)
996 @opencatbox{Categories:}
997 @category{Declarations and inferences}
999 @category{Simplification}
1005 @c -----------------------------------------------------------------------------
1007 @defvr {Option variable} maxnegex
1010 @code{maxnegex} is the largest negative exponent which will
1011 be expanded by the @code{expand} command, see also @mrefdot{maxposex}
1013 @opencatbox{Categories:}
1014 @category{Expressions}
1020 @c -----------------------------------------------------------------------------
1022 @defvr {Option variable} maxposex
1025 @code{maxposex} is the largest exponent which will be
1026 expanded with the @code{expand} command, see also @mrefdot{maxnegex}
1028 @opencatbox{Categories:}
1029 @category{Expressions}
1035 @c -----------------------------------------------------------------------------
1036 @anchor{multiplicative}
1037 @defvr {Property} multiplicative
1039 @code{declare(f, multiplicative)} tells the Maxima simplifier that @code{f}
1044 If @code{f} is univariate, whenever the simplifier encounters @code{f} applied
1045 to a product, @code{f} distributes over that product. E.g., @code{f(x*y)}
1046 simplifies to @code{f(x)*f(y)}.
1047 This simplification is not applied to expressions of the form @code{f('product(...))}.
1049 If @code{f} is a function of 2 or more arguments, multiplicativity is
1050 defined as multiplicativity in the first argument to @code{f}, e.g.,
1051 @code{f (g(x) * h(x), x)} simplifies to @code{f (g(x) ,x) * f (h(x), x)}.
1054 @code{declare(nounify(product), multiplicative)} tells Maxima to simplify symbolic products.
1060 @c declare (F2, multiplicative);
1065 (%i1) F2 (a * b * c);
1069 (%i2) declare (F2, multiplicative);
1073 (%i3) F2 (a * b * c);
1074 (%o3) F2(a) F2(b) F2(c)
1078 @code{declare(nounify(product), multiplicative)} tells Maxima to simplify symbolic products.
1081 @c product (a[i] * b[i], i, 1, n);
1082 @c declare (nounify (product), multiplicative);
1083 @c product (a[i] * b[i], i, 1, n);
1087 (%i1) product (a[i] * b[i], i, 1, n);
1096 (%i2) declare (nounify (product), multiplicative);
1100 (%i3) product (a[i] * b[i], i, 1, n);
1104 (%o3) ( ! ! a ) ! ! b
1110 @opencatbox{Categories:}
1111 @category{Declarations and inferences}
1112 @category{Expressions}
1113 @category{Simplification}
1119 @c -----------------------------------------------------------------------------
1121 @deffn {Function} multthru @
1122 @fname{multthru} (@var{expr}) @
1123 @fname{multthru} (@var{expr_1}, @var{expr_2})
1125 Multiplies a factor (which should be a sum) of @var{expr} by the other factors
1126 of @var{expr}. That is, @var{expr} is @code{@var{f_1} @var{f_2} ... @var{f_n}}
1127 where at least one factor, say @var{f_i}, is a sum of terms. Each term in that
1128 sum is multiplied by the other factors in the product. (Namely all the factors
1129 except @var{f_i}). @code{multthru} does not expand exponentiated sums.
1130 This function is the fastest way to distribute products (commutative or
1131 noncommutative) over sums. Since quotients are represented as products
1132 @code{multthru} can be used to divide sums by products as well.
1134 @code{multthru (@var{expr_1}, @var{expr_2})} multiplies each term in
1135 @var{expr_2} (which should be a sum or an equation) by @var{expr_1}. If
1136 @var{expr_1} is not itself a sum then this form is equivalent to
1137 @code{multthru (@var{expr_1}*@var{expr_2})}.
1140 @c x/(x-y)^2 - 1/(x-y) - f(x)/(x-y)^3;
1141 @c multthru ((x-y)^3, %);
1143 @c ((a+b)^10*s^2 + 2*a*b*s + (a*b)^2)/(a*b*s^2);
1144 @c multthru (%); /* note that this does not expand (b+a)^10 */
1145 @c multthru (a.(b+c.(d+e)+f));
1146 @c expand (a.(b+c.(d+e)+f));
1149 (%i1) x/(x-y)^2 - 1/(x-y) - f(x)/(x-y)^3;
1151 (%o1) - ----- + -------- - --------
1154 (%i2) multthru ((x-y)^3, %);
1156 (%o2) - (x - y) + x (x - y) - f(x)
1157 (%i3) ratexpand (%);
1159 (%o3) - y + x y - f(x)
1160 (%i4) ((a+b)^10*s^2 + 2*a*b*s + (a*b)^2)/(a*b*s^2);
1162 (b + a) s + 2 a b s + a b
1163 (%o4) ------------------------------
1166 (%i5) multthru (%); /* note that this does not expand (b+a)^10 */
1169 (%o5) - + --- + ---------
1172 (%i6) multthru (a.(b+c.(d+e)+f));
1173 (%o6) a . f + a . c . (e + d) + a . b
1174 (%i7) expand (a.(b+c.(d+e)+f));
1175 (%o7) a . f + a . c . e + a . c . d + a . b
1178 @opencatbox{Categories:}
1179 @category{Expressions}
1183 @c -----------------------------------------------------------------------------
1184 @anchor{property_nary}
1185 @defvr {Property} nary
1187 @code{declare(f, nary)} tells Maxima to recognize the function @code{f} as an
1190 The @code{nary} declaration is not the same as calling the
1191 @mxref{function_nary, nary} function. The sole effect of
1192 @code{declare(f, nary)} is to instruct the Maxima simplifier to flatten nested
1193 expressions, for example, to simplify @code{foo(x, foo(y, z))} to
1194 @code{foo(x, y, z)}. See also @mrefdot{declare}
1199 @c H (H (a, b), H (c, H (d, e)));
1200 @c declare (H, nary);
1201 @c H (H (a, b), H (c, H (d, e)));
1204 (%i1) H (H (a, b), H (c, H (d, e)));
1205 (%o1) H(H(a, b), H(c, H(d, e)))
1206 (%i2) declare (H, nary);
1208 (%i3) H (H (a, b), H (c, H (d, e)));
1209 (%o3) H(a, b, c, d, e)
1213 @c NEEDS CLARIFICATION, EXAMPLES
1215 @c -----------------------------------------------------------------------------
1217 @defvr {Option variable} negdistrib
1218 Default value: @code{true}
1220 When @code{negdistrib} is @code{true}, -1 distributes over an expression.
1221 E.g., @code{-(x + y)} becomes @code{- y - x}. Setting it to @code{false}
1222 will allow @code{- (x + y)} to be displayed like that. This is sometimes useful
1223 but be very careful: like the @code{simp} flag, this is one flag you do not
1224 want to set to @code{false} as a matter of course or necessarily for other
1225 than local use in your Maxima.
1232 @c negdistrib : not negdistrib ;
1245 (%i3) negdistrib : not negdistrib ;
1254 @opencatbox{Categories:}
1255 @category{Simplification flags and variables}
1259 @c -----------------------------------------------------------------------------
1260 @anchor{opproperties}
1261 @defvr {System variable} opproperties
1263 @code{opproperties} is the list of the special operator properties recognized
1264 by the Maxima simplifier.
1266 Items are added to the @code{opproperties} list by the function @code{define_opproperty}.
1276 (%o1) [linear, additive, multiplicative, outative, evenfun,
1277 oddfun, commutative, symmetric, antisymmetric, nary,
1278 lassociative, rassociative]
1282 @opencatbox{Categories:}
1283 @category{Global variables}
1284 @category{Operators}
1285 @category{Simplification}
1291 @c -----------------------------------------------------------------------------
1292 @anchor{define_opproperty}
1293 @deffn {Function} define_opproperty (@var{property_name}, @var{simplifier_fn})
1295 Declares the symbol @var{property_name} to be an operator property,
1296 which is simplified by @var{simplifier_fn},
1297 which may be the name of a Maxima or Lisp function or a lambda expression.
1298 After @code{define_opproperty} is called,
1299 functions and operators may be declared to have the @var{property_name} property,
1300 and @var{simplifier_fn} is called to simplify them.
1302 @var{simplifier_fn} must be a function of one argument,
1303 which is an expression in which the main operator is declared to have the @var{property_name} property.
1305 @var{simplifier_fn} is called with the global flag @code{simp} disabled.
1306 Therefore @var{simplifier_fn} must be able to carry out its simplification
1307 without making use of the general simplifier.
1309 @code{define_opproperty} appends @var{property_name} to the
1310 global list @code{opproperties}.
1312 @code{define_opproperty} returns @code{done}.
1316 Declare a new property, @code{identity}, which is simplified by @code{simplify_identity}.
1317 Declare that @code{f} and @code{g} have the new property.
1320 @c define_opproperty (identity, simplify_identity);
1321 @c simplify_identity(e) := first(e);
1322 @c declare ([f, g], identity);
1328 (%i1) define_opproperty (identity, simplify_identity);
1332 (%i2) simplify_identity(e) := first(e);
1333 (%o2) simplify_identity(e) := first(e)
1336 (%i3) declare ([f, g], identity);
1344 (%i5) g(3*u) - f(2*u);
1349 @opencatbox{Categories:}
1350 @category{Operators}
1351 @category{Simplification}
1355 @c -----------------------------------------------------------------------------
1357 @defvr {Property} outative
1359 @code{declare(f, outative)} tells the Maxima simplifier that constant factors
1360 in the argument of @code{f} can be pulled out.
1364 If @code{f} is univariate, whenever the simplifier encounters @code{f} applied
1365 to a product, that product will be partitioned into factors that are constant
1366 and factors that are not and the constant factors will be pulled out. E.g.,
1367 @code{f(a*x)} will simplify to @code{a*f(x)} where @code{a} is a constant.
1368 Non-atomic constant factors will not be pulled out.
1370 If @code{f} is a function of 2 or more arguments, outativity is defined as in
1371 the case of @code{sum} or @code{integrate}, i.e., @code{f (a*g(x), x)} will
1372 simplify to @code{a * f(g(x), x)} for @code{a} free of @code{x}.
1375 @code{sum}, @code{integrate}, and @code{limit} are all @code{outative}.
1381 @c declare (F1, outative);
1383 @c declare (zz, constant);
1392 (%i2) declare (F1, outative);
1400 (%i4) declare (zz, constant);
1409 @opencatbox{Categories:}
1410 @category{Declarations and inferences}
1411 @category{Operators}
1415 @c -----------------------------------------------------------------------------
1417 @deffn {Function} radcan (@var{expr})
1419 Simplifies @var{expr}, which can contain logs, exponentials, and radicals, by
1420 converting it into a form which is canonical over a large class of expressions
1421 and a given ordering of variables; that is, all functionally equivalent forms
1422 are mapped into a unique form. For a somewhat larger class of expressions,
1423 @code{radcan} produces a regular form. Two equivalent expressions in this class
1424 do not necessarily have the same appearance, but their difference can be
1425 simplified by @code{radcan} to zero.
1427 For some expressions @code{radcan} is quite time consuming. This is the cost
1428 of exploring certain relationships among the components of the expression for
1429 simplifications based on factoring and partial-fraction expansions of exponents.
1431 @c %e_to_numlog NEEDS ITS OWN @defvar !!!
1433 @c %e_to_numlog HAS NO EFFECT ON RADCAN. RADCAN ALWAYS SIMPLIFIES
1434 @c exp(a*log(x)) --> x^a. Commenting the following out. 11/2009
1435 @c When @code{%e_to_numlog} is @code{true}, @code{%e^(r*log(expr))} simplifies
1436 @c to @code{expr^r} if @code{r} is a rational number.
1438 @c RADEXPAND CONTROLS THE SIMPLIFICATION OF THE POWER FUNCTION, E.G.
1439 @c (x*y)^a --> x^a*y^a AND (x^a)^b --> x^(a*b), IF RADEXPAND HAS THE VALUE 'ALL.
1440 @c THE VALUE OF RADEXPAND HAS NO EFFECT ON RADCAN. RADCAN ALWAYS SIMPLIFIES
1441 @c THE ABOVE EXPRESSIONS. COMMENTING THE FOLLOWING OUT. 11/2009
1442 @c When @code{radexpand} is @code{false}, certain transformations are inhibited.
1443 @c @code{radcan (sqrt (1-x))} remains @code{sqrt (1-x)} and is not simplified
1444 @c to @code{%i sqrt (x-1)}. @code{radcan (sqrt (x^2 - 2*x + 1))} remains
1445 @c @code{sqrt (x^2 - 2*x + 1)} and is not simplified to @code{x - 1}.
1450 @c radcan((log(x+x^2)-log(x))^a/log(1+x)^(a/2));
1451 @c radcan((log(1+2*a^x+a^(2*x))/log(1+a^x)));
1452 @c radcan((%e^x-1)/(1+%e^(x/2)));
1456 (%i1) radcan((log(x+x^2)-log(x))^a/log(1+x)^(a/2));
1461 (%i2) radcan((log(1+2*a^x+a^(2*x))/log(1+a^x)));
1465 (%i3) radcan((%e^x-1)/(1+%e^(x/2)));
1471 @opencatbox{Categories:}
1472 @category{Simplification functions}
1476 @c NEEDS CLARIFICATION, EXAMPLES
1478 @c -----------------------------------------------------------------------------
1480 @defvr {Option variable} radexpand
1481 Default value: @code{true}
1483 @code{radexpand} controls some simplifications of radicals.
1485 When @code{radexpand} is @code{all}, causes nth roots of factors of a product
1486 which are powers of n to be pulled outside of the radical. E.g. if
1487 @code{radexpand} is @code{all}, @code{sqrt (16*x^2)} simplifies to @code{4*x}.
1489 @c EXPRESS SIMPLIFICATON RULES IN GENERAL CASE, NOT SPECIAL CASE
1490 More particularly, consider @code{sqrt (x^2)}.
1493 If @code{radexpand} is @code{all} or @code{assume (x > 0)} has been executed,
1494 @code{sqrt(x^2)} simplifies to @code{x}.
1496 If @code{radexpand} is @code{true} and @code{domain} is @code{real}
1497 (its default), @code{sqrt(x^2)} simplifies to @code{abs(x)}.
1499 If @code{radexpand} is @code{false}, or @code{radexpand} is @code{true} and
1500 @code{domain} is @code{complex}, @code{sqrt(x^2)} is not simplified.
1503 @c CORRECT STATEMENT HERE ???
1504 Note that @code{domain} only matters when @code{radexpand} is @code{true}.
1506 @opencatbox{Categories:}
1507 @category{Simplification flags and variables}
1511 @c NEEDS CLARIFICATION, EXAMPLES
1513 @c -----------------------------------------------------------------------------
1514 @anchor{rassociative}
1515 @defvr {Property} rassociative
1517 @code{declare (g, rassociative)} tells the Maxima
1518 simplifier that @code{g} is right-associative. E.g.,
1519 @code{g(g(a, b), g(c, d))} simplifies to @code{g(a, g(b, g(c, d)))}.
1521 @opencatbox{Categories:}
1522 @category{Declarations and inferences}
1523 @category{Operators}
1527 @c NEEDS CLARIFICATION, EXAMPLES
1529 @c -----------------------------------------------------------------------------
1531 @deffn {Function} scsimp (@var{expr}, @var{rule_1}, @dots{}, @var{rule_n})
1533 Sequential Comparative Simplification (method due to Stoute).
1534 @code{scsimp} attempts to simplify @var{expr}
1535 according to the rules @var{rule_1}, @dots{}, @var{rule_n}.
1536 If a smaller expression is obtained, the process repeats. Otherwise after all
1537 simplifications are tried, it returns the original answer.
1539 @c MERGE EXAMPLES INTO THIS FILE
1540 @code{example (scsimp)} displays some examples.
1542 @opencatbox{Categories:}
1543 @category{Simplification functions}
1547 @c -----------------------------------------------------------------------------
1549 @defvr {Option variable} simp
1550 Default value: @code{true}
1552 @code{simp} enables simplification. This is the default. @code{simp} is also
1553 an @code{evflag}, which is recognized by the function @code{ev}. See @mrefdot{ev}
1555 When @code{simp} is used as an @code{evflag} with a value @code{false}, the
1556 simplification is suppressed only during the evaluation phase of an expression.
1557 The flag does not suppress the simplification which follows the evaluation
1560 Many Maxima functions and operations require simplification to be enabled to work normally.
1561 When simplification is disabled, many results will be incomplete,
1562 and in addition there may be incorrect results or program errors.
1566 The simplification is switched off globally. The expression @code{sin(1.0)} is
1567 not simplified to its numerical value. The @code{simp}-flag switches the
1585 (%i3) sin(1.0),simp;
1586 (%o3) 0.8414709848078965
1590 The simplification is switched on again. The @code{simp}-flag cannot suppress
1591 the simplification completely. The output shows a simplified expression, but
1592 the variable @code{x} has an unsimplified expression as a value, because the
1593 assignment has occurred during the evaluation phase of the expression.
1597 @c x:sin(1.0),simp:false;
1606 (%i2) x:sin(1.0),simp:false;
1607 (%o2) 0.8414709848078965
1615 @opencatbox{Categories:}
1616 @category{Evaluation flags}
1620 @c NEEDS CLARIFICATION, EXAMPLES
1622 @c -----------------------------------------------------------------------------
1624 @defvr {Property} symmetric
1626 @code{declare (h, symmetric)} tells the Maxima
1627 simplifier that @code{h} is a symmetric function. E.g., @code{h (x, z, y)}
1628 simplifies to @code{h (x, y, z)}.
1630 @code{commutative} is synonymous with @code{symmetric}.
1632 @opencatbox{Categories:}
1633 @category{Declarations and inferences}
1634 @category{Operators}
1638 @c -----------------------------------------------------------------------------
1640 @deffn {Function} xthru (@var{expr})
1642 Combines all terms of @var{expr} (which should be a sum) over a common
1643 denominator without expanding products and exponentiated sums as @code{ratsimp}
1644 does. @code{xthru} cancels common factors in the numerator and denominator of
1645 rational expressions but only if the factors are explicit.
1647 @c REPHRASE IN NEUTRAL TONE (GET RID OF "IT IS BETTER")
1648 Sometimes it is better to use @code{xthru} before @code{ratsimp}ing an
1649 expression in order to cause explicit factors of the gcd of the numerator and
1650 denominator to be canceled thus simplifying the expression to be
1656 @c ((x+2)^20 - 2*y)/(x+y)^20 + (x+y)^(-19) - x/(x+y)^20;
1661 (%i1) ((x+2)^20 - 2*y)/(x+y)^20 + (x+y)^(-19) - x/(x+y)^20;
1664 (%o1) --------- + --------------- - ---------
1666 (y + x) (y + x) (y + x)
1678 @opencatbox{Categories:}
1679 @category{Expressions}