1@menu
2* Introduction to Simplification::
3* Functions and Variables for Simplification::
4@end menu
5
6@c -----------------------------------------------------------------------------
7@node Introduction to Simplification, Functions and Variables for Simplification,  , Simplification
8@section Introduction to Simplification
9@c -----------------------------------------------------------------------------
10
11@c -----------------------------------------------------------------------------
12Maxima performs a cycle of actions in response to each new user-typed command. This
13consists of four steps: reading or "parsing" the input, evaluation, simplification
14and output. Parsing converts a syntactically valid sequence of typed characters into
15a data structure to be used for the rest of the operations. Evaluation includes
16replacing names with their assigned values. Simplification means rewriting an
17expression to be easier for the user or other programs to understand. Output includes
18displaying computational results in a variety of different formats and notations.
19
20Evaluation and simplification sometimes appear to have similar functionality as they
21both have the goal of removing "complexity" and system designers have sometimes divided a
22task so that it is performed partly in each. For example, @code{integrate(x,x)} evaluates
23the answer as @code{x*x/2}, which is then simplified to @code{x^2/2}.
24
25Evaluation is always present: it is the consequence of having a programming system with
26functions, subroutines, variables, values, loops, assignments and so on. In the
27evaluation step, built-in or user-defined function names are replaced by their definitions,
28variables are replaced by their values. This is largely the same as activities of a
29conventional programming language, but extended to work with symbolic mathematical data.
30Because of the generality of the mathematics at hand, there are different possible models
31of evaluation and so the systems has optional "flags" that can steer the process of
32evaluation. @xref{Functions and Variables for Evaluation}.
33
34By contrast, the intent of simplification is to maintain the value of an expression
35while re-formulating its representation to be smaller, simpler to understand, or to
36conform to particular specifications (like factored, expanded). For
37example, @code{sin(0)} to @code{0} or @code{x+x to 2*x}.
38There are several powerful tools to alter the results
39of simplification, since it is largely in this part of the system that a user can
40incorporate knowledge of newly introduced functions or symbolic notation into Maxima.
41
42Simplification is generally done at four different levels:
43@itemize @bullet
44@item The internal, built-in automated simplifier,
45@item Built-in simplification routines that can be explicitly called by the user
46      at selected places in a program or command sequence,
47@item User-written simplification routines, linked to the simplifier by using
48      "tellsimp" or "tellsimpafter" and called automatically,
49@item User-written routines that can be explicitly called by the user at selected
50      places in a program or command sequence.
51@end itemize
52The internal simplifier belongs to the heart of Maxima. It is a large and
53complicated collection of programs, and it has been refined over many years and by
54thousands of users. Nevertheless, especially if you are trying out novel ideas or
55unconventional notation, you may find it helpful to make small (or large) changes
56to the program yourself. For details see for example the paper at the end of
57@url{https://people.eecs.berkeley.edu/~fateman/papers/intro5.txt}.
58
59Maxima internally represents expressions as "trees" with operators or "roots"
60like @code{+}, @code{*} , @code{=} and operands ("leaves") which are variables like
61@var{x}, @var{y}, @var{z}, functions
62or sub-trees, like @code{x*y}. Each operator has a simplification program
63associated with it.  @code{+} (which also covers binary @code{-} since
64@code{a-b = a+(-1)*b)} and @code{*} (which also covers @code{/}
65since @code{a/b = a*b^(-1)}) have rather elaborate simplification programs. These
66simplification programs (simplus, simptimes, simpexpt, etc.) are called whenever
67the simplifier encounters the respective arithmetic operators in an expression
68tree to be analyzed.
69
70The structure of the simplifier dates back to 1965, and many hands have worked
71on it through the years. The structure turns out to be, in modern jargon, data-
72directed, or object-oriented. The program dispatches to the appropriate routine
73depending on the root of some sub-tree of the expression, recursively. This general
74notion means you can make modifications to the simplification process by very local
75changes to the program. In many cases it is conceptually straightforward to add an
76operator and add its simplification routine without disturbing existing code.
77
78We note that in addition to this general simplifier operating on algebraic
79expression trees, there are several other representations of expressions in
80Maxima which have separate methods and simplifiers. For example, the
81@mref{rat} function converts polynomials to vectors of coefficients to
82assist in rapid manipulation of such forms. Other representations include
83Taylor series and the (rarely used) Poisson series.
84
85All operators introduced by the user initially have no simplification
86programs associated with them.  Maxima does not know anything about
87function "f"  and so typing @code{f(a,b)} will result in simplifying
88@var{a},@var{b}, but not @code{f}.
89Even some built-in operators have no simplifications. For example,
90@code{=} does not "simplify" -- it is a place-holder with no
91simplification semantics other
92than to simplify its two arguments, in this case referred to as the left and
93right sides. Other parts of Maxima such as the solve program take special
94note of equations, that is, trees with @code{=} as the root.
95(Note -- in Maxima, the assignment operation is @code{:} . That is, @code{q: 4}
96sets the value of the symbol @var{q} to @code{4}.
97Function definition is done with @code{:=}. )
98
99The general simplifier returns results with an internal flag indicating the
100expression and each sub-expression has been simplified. This does not
101guarantee that it is unique over all possible equivalent expressions. That's
102too hard (theoretically, not possible given the generality of what can be
103expressed in Maxima). However, some aspects of the expression, such as the
104ordering of terms in a sum or product, are made uniform. This is important
105for the other programs to work properly.
106
107You can set a number of option variables which direct Maxima's processing to
108favor particular kinds of patterns as being goals. You can even use the most
109extreme option which is to turn the simplifier off by simp:false. We do not
110recommend this since many internal routines expect their arguments to be
111simplified. (About the only time it seems plausible to turn off the simplifier
112is in the rare case that you want to over-ride a built-in simplification.
113In that case  you might temporarily disable the simplifier, put in the new
114transformation via @mrefcomma{tellsimp} and then re-enable the simplifier
115by @code{simp:true}.)
116
117It is more plausible for you to associate user-defined symbolic function names
118or operators with properties (@mrefcomma{additive}
119@mrefcomma{lassociative} @mrefcomma{oddfun} @mrefcomma{antisymmetric}
120@mrefcomma{linear} @mrefcomma{outative} @mrefcomma{commutative}
121@mrefcomma{multiplicative} @mrefcomma{rassociative} @mrefcomma{evenfun}
122@mref{nary} and @mref{symmetric}). These options steer
123the simplifier processing in systematic directions.
124
125For example, @code{declare(f,oddfun)} specifies that @code{f} is an odd function.
126Maxima will simplify @code{f(-x)} to @code{-f(x)}. In the case of an even
127function, that is @code{declare(g,evenfun)},
128Maxima will simplify @code{g(-x)} to @code{g(x)}. You can also associate a
129programming function with a name such as @code{h(x):=x^2+1}. In that case the
130evaluator will immediately replace
131@code{h(3)} by @code{10}, and @code{h(a+1)} by @code{(a+1)^2+1}, so any properties
132of @code{h} will be ignored.
133
134In addition to these directly related properties set up by the user, facts and
135properties from the actual context may have an impact on the simplifier's behavior,
136too. @xref{Introduction to Maximas Database}.
137
138Example: @code{sin(n*%pi)} is simplified to zero, if @var{n} is an integer.
139
140@c ===beg===
141@c sin(n*%pi);
142@c declare(n, integer);
143@c sin(n*%pi);
144@c ===end===
145@example
146@group
147(%i1) sin(n*%pi);
148(%o1)                      sin(%pi n)
149@end group
150@group
151(%i2) declare(n, integer);
152(%o2)                         done
153@end group
154@group
155(%i3) sin(n*%pi);
156(%o3)                           0
157@end group
158@end example
159
160If automated simplification is not sufficient, you can consider a variety of
161built-in, but explicitly called simplfication functions (@mrefcomma{ratsimp}
162@mrefcomma{expand} @mrefcomma{factor} @mref{radcan} and others). There are
163also flags that will push simplification into one or another direction.
164Given @code{demoivre:true} the simplifier rewrites
165complex exponentials as trigonometric forms. Given @code{exponentialize:true}
166the  simplifier tries to do the reverse: rewrite trigonometric forms as complex
167exponentials.
168
169As everywhere in Maxima, by writing your own functions (be it in the Maxima
170user language or in the implementation language Lisp) and explicitly calling them
171at selected places in the program, you can respond to your individual
172simplification needs. Lisp gives you a handle on all the internal mechanisms, but
173you rarely need this full generality. "Tellsimp" is designed to generate much
174of the Lisp internal interface into the simplifier automatically.
175See @xref{Rules and Patterns}.
176
177Over the years (Maxima/Macsyma's origins date back to about 1966!) users have
178contributed numerous application packages and tools to extend or alter its
179functional behavior. Various non-standard and "share" packages exist to modify
180or extend simplification as well. You are invited to look into this more
181experimental material where work is still in progress @xref{simplification-pkg}.
182
183The following appended material is optional on a first reading, and reading it
184is not necessary for productive use of Maxima. It is for the curious user who
185wants to understand what is going on, or the ambitious programmer who might
186wish to change the (open-source) code. Experimentation with redefining Maxima
187Lisp code is easily possible: to change the definition of a Lisp program (say
188the one that simplifies @code{cos()}, named @code{simp%cos}), you simply
189load into Maxima a text file that will overwrite the @code{simp%cos} function
190from the maxima package.
191
192@c -----------------------------------------------------------------------------
193@node Functions and Variables for Simplification,  , Introduction to Simplification, Simplification
194@section Functions and Variables for Simplification
195@c -----------------------------------------------------------------------------
196
197@c -----------------------------------------------------------------------------
198@anchor{additive}
199@defvr {Property} additive
200
201If @code{declare(f,additive)} has been executed, then:
202
203(1) If @code{f} is univariate, whenever the simplifier encounters @code{f}
204applied to a sum, @code{f} will be distributed over that sum.  I.e.
205@code{f(y+x)} will simplify to @code{f(y)+f(x)}.
206
207(2) If @code{f} is a function of 2 or more arguments, additivity is defined as
208additivity in the first argument to @code{f}, as in the case of @code{sum} or
209@code{integrate}, i.e.  @code{f(h(x)+g(x),x)} will simplify to
210@code{f(h(x),x)+f(g(x),x)}.  This simplification does not occur when @code{f} is
211applied to expressions of the form @code{sum(x[i],i,lower-limit,upper-limit)}.
212
213Example:
214
215@c ===beg===
216@c F3 (a + b + c);
217@c declare (F3, additive);
218@c F3 (a + b + c);
219@c ===end===
220@example
221@group
222(%i1) F3 (a + b + c);
223(%o1)                     F3(c + b + a)
224@end group
225@group
226(%i2) declare (F3, additive);
227(%o2)                         done
228@end group
229@group
230(%i3) F3 (a + b + c);
231(%o3)                 F3(c) + F3(b) + F3(a)
232@end group
233@end example
234
235@opencatbox
236@category{Operators}
237@category{Declarations and inferences}
238@closecatbox
239@end defvr
240
241@c -----------------------------------------------------------------------------
242@anchor{antisymmetric}
243@defvr {Property} antisymmetric
244
245If @code{declare(h,antisymmetric)} is done, this tells the simplifier that
246@code{h} is antisymmetric.  E.g.  @code{h(x,z,y)} will simplify to
247@code{- h(x, y, z)}.  That is, it will give (-1)^n times the result given by
248@code{symmetric} or @code{commutative}, where n is the number of interchanges
249of two arguments necessary to convert it to that form.
250
251Examples:
252
253@c ===beg===
254@c S (b, a);
255@c declare (S, symmetric);
256@c S (b, a);
257@c S (a, c, e, d, b);
258@c T (b, a);
259@c declare (T, antisymmetric);
260@c T (b, a);
261@c T (a, c, e, d, b);
262@c ===end===
263@example
264@group
265(%i1) S (b, a);
266(%o1)                        S(b, a)
267@end group
268@group
269(%i2) declare (S, symmetric);
270(%o2)                         done
271@end group
272@group
273(%i3) S (b, a);
274(%o3)                        S(a, b)
275@end group
276@group
277(%i4) S (a, c, e, d, b);
278(%o4)                   S(a, b, c, d, e)
279@end group
280@group
281(%i5) T (b, a);
282(%o5)                        T(b, a)
283@end group
284@group
285(%i6) declare (T, antisymmetric);
286(%o6)                         done
287@end group
288@group
289(%i7) T (b, a);
290(%o7)                       - T(a, b)
291@end group
292@group
293(%i8) T (a, c, e, d, b);
294(%o8)                   T(a, b, c, d, e)
295@end group
296@end example
297
298@opencatbox
299@category{Operators}
300@category{Declarations and inferences}
301@closecatbox
302@end defvr
303
304@c -----------------------------------------------------------------------------
305@deffn {Function} combine (@var{expr})
306
307Simplifies the sum @var{expr} by combining terms with the same
308denominator into a single term.
309
310Example:
311
312@c ===beg===
313@c 1*f/2*b + 2*c/3*a + 3*f/4*b +c/5*b*a;
314@c combine (%);
315@c ===end===
316@example
317@group
318(%i1) 1*f/2*b + 2*c/3*a + 3*f/4*b +c/5*b*a;
319                      5 b f   a b c   2 a c
320(%o1)                 ----- + ----- + -----
321                        4       5       3
322@end group
323@group
324(%i2) combine (%);
325                  75 b f + 4 (3 a b c + 10 a c)
326(%o2)             -----------------------------
327                               60
328@end group
329@end example
330
331@opencatbox
332@category{Expressions}
333@closecatbox
334@end deffn
335
336@c -----------------------------------------------------------------------------
337@anchor{commutative}
338@defvr {Property} commutative
339
340If @code{declare(h, commutative)} is done, this tells the simplifier that
341@code{h} is a commutative function.  E.g.  @code{h(x, z, y)} will simplify to
342@code{h(x, y, z)}.  This is the same as @code{symmetric}.
343
344Exemplo:
345
346@c ===beg===
347@c S (b, a);
348@c S (a, b) + S (b, a);
349@c declare (S, commutative);
350@c S (b, a);
351@c S (a, b) + S (b, a);
352@c S (a, c, e, d, b);
353@c ===end===
354@example
355@group
356(%i1) S (b, a);
357(%o1)                        S(b, a)
358@end group
359@group
360(%i2) S (a, b) + S (b, a);
361(%o2)                   S(b, a) + S(a, b)
362@end group
363@group
364(%i3) declare (S, commutative);
365(%o3)                         done
366@end group
367@group
368(%i4) S (b, a);
369(%o4)                        S(a, b)
370@end group
371@group
372(%i5) S (a, b) + S (b, a);
373(%o5)                       2 S(a, b)
374@end group
375@group
376(%i6) S (a, c, e, d, b);
377(%o6)                   S(a, b, c, d, e)
378@end group
379@end example
380
381@opencatbox
382@category{Operators}
383@category{Declarations and inferences}
384@closecatbox
385@end defvr
386
387@c NEEDS CLARIFICATION, EXAMPLES
388
389@c -----------------------------------------------------------------------------
390@anchor{demoivre}
391@deffn  {Function} demoivre (@var{expr})
392@deffnx {Option variable} demoivre
393
394The function @code{demoivre (expr)} converts one expression
395without setting the global variable @code{demoivre}.
396
397When the variable @code{demoivre} is @code{true}, complex exponentials are
398converted into equivalent expressions in terms of circular functions:
399@code{exp (a + b*%i)} simplifies to @code{%e^a * (cos(b) + %i*sin(b))}
400if @code{b} is free of @code{%i}.  @code{a} and @code{b} are not expanded.
401
402The default value of @code{demoivre} is @code{false}.
403
404@code{exponentialize} converts circular and hyperbolic functions to exponential
405form.  @code{demoivre} and @code{exponentialize} cannot both be true at the same
406time.
407
408@opencatbox
409@category{Complex variables}
410@category{Trigonometric functions}
411@category{Hyperbolic functions}
412@closecatbox
413@end deffn
414
415@c NEEDS WORK
416
417@c -----------------------------------------------------------------------------
418@anchor{function_distrib}
419@deffn {Function} distrib (@var{expr})
420
421Distributes sums over products.  It differs from @code{expand} in that it works
422at only the top level of an expression, i.e., it doesn't recurse and it is
423faster than @code{expand}.  It differs from @code{multthru} in that it expands
424all sums at that level.
425
426Examples:
427
428@c ===beg===
429@c distrib ((a+b) * (c+d));
430@c multthru ((a+b) * (c+d));
431@c distrib (1/((a+b) * (c+d)));
432@c expand (1/((a+b) * (c+d)), 1, 0);
433@c ===end===
434@example
435(%i1) distrib ((a+b) * (c+d));
436(%o1)                 b d + a d + b c + a c
437(%i2) multthru ((a+b) * (c+d));
438(%o2)                 (b + a) d + (b + a) c
439(%i3) distrib (1/((a+b) * (c+d)));
440                                1
441(%o3)                    ---------------
442                         (b + a) (d + c)
443(%i4) expand (1/((a+b) * (c+d)), 1, 0);
444                                1
445(%o4)                 ---------------------
446                      b d + a d + b c + a c
447@end example
448
449@opencatbox
450@category{Expressions}
451@closecatbox
452@end deffn
453
454@c -----------------------------------------------------------------------------
455@anchor{distribute_over}
456@defvr {Option variable} distribute_over
457Default value: @code{true}
458
459@code{distribute_over} controls the mapping of functions over bags like lists,
460matrices, and equations.  At this time not all Maxima functions have this
461property.  It is possible to look up this property with the command
462@code{properties}.
463
464The mapping of functions is switched off, when setting @code{distribute_over}
465to the value @code{false}.
466
467Examples:
468
469The @code{sin} function maps over a list:
470
471@c ===beg===
472@c sin([x,1,1.0]);
473@c ===end===
474@example
475@group
476(%i1) sin([x,1,1.0]);
477(%o1)         [sin(x), sin(1), 0.8414709848078965]
478@end group
479@end example
480
481@code{mod} is a function with two arguments which maps over lists.  Mapping over
482nested lists is possible too:
483
484@c ===beg===
485@c mod([x,11,2*a],10);
486@c mod([[x,y,z],11,2*a],10);
487@c ===end===
488@example
489@group
490(%i1) mod([x,11,2*a],10);
491(%o1)             [mod(x, 10), 1, 2 mod(a, 5)]
492@end group
493@group
494(%i2) mod([[x,y,z],11,2*a],10);
495(%o2) [[mod(x, 10), mod(y, 10), mod(z, 10)], 1, 2 mod(a, 5)]
496@end group
497@end example
498
499Mapping of the @code{floor} function over a matrix and an equation:
500
501@c ===beg===
502@c floor(matrix([a,b],[c,d]));
503@c floor(a=b);
504@c ===end===
505@example
506@group
507(%i1) floor(matrix([a,b],[c,d]));
508                     [ floor(a)  floor(b) ]
509(%o1)                [                    ]
510                     [ floor(c)  floor(d) ]
511@end group
512@group
513(%i2) floor(a=b);
514(%o2)                  floor(a) = floor(b)
515@end group
516@end example
517
518Functions with more than one argument map over any of the arguments or all
519arguments:
520
521@c ===beg===
522@c expintegral_e([1,2],[x,y]);
523@c ===end===
524@example
525@group
526(%i1) expintegral_e([1,2],[x,y]);
527(%o1) [[expintegral_e(1, x), expintegral_e(1, y)],
528                      [expintegral_e(2, x), expintegral_e(2, y)]]
529@end group
530@end example
531
532Check if a function has the property distribute_over:
533
534@c ===beg===
535@c properties(abs);
536@c ===end===
537@example
538@group
539(%i1) properties(abs);
540(%o1) [integral, rule, distributes over bags, noun, gradef,
541                                                 system function]
542@end group
543@end example
544
545The mapping of functions is switched off, when setting @code{distribute_over}
546to the value @code{false}.
547
548@c ===beg===
549@c distribute_over;
550@c sin([x,1,1.0]);
551@c distribute_over : not distribute_over;
552@c sin([x,1,1.0]);
553@c ===end===
554@example
555@group
556(%i1) distribute_over;
557(%o1)                         true
558@end group
559@group
560(%i2) sin([x,1,1.0]);
561(%o2)         [sin(x), sin(1), 0.8414709848078965]
562@end group
563@group
564(%i3) distribute_over : not distribute_over;
565(%o3)                         false
566@end group
567@group
568(%i4) sin([x,1,1.0]);
569(%o4)                   sin([x, 1, 1.0])
570@end group
571@end example
572
573@opencatbox
574@category{Simplification flags and variables}
575@closecatbox
576@end defvr
577
578@c -----------------------------------------------------------------------------
579@anchor{domain}
580@defvr {Option variable} domain
581Default value: @code{real}
582
583When @code{domain} is set to @code{complex}, @code{sqrt (x^2)} will remain
584@code{sqrt (x^2)} instead of returning @code{abs(x)}.
585
586@c PRESERVE EDITORIAL COMMENT -- MAY HAVE SOME SIGNIFICANCE NOT YET UNDERSTOOD !!!
587@c The notion of a "domain" of simplification is still in its infancy,
588@c and controls little more than this at the moment.
589
590@opencatbox
591@category{Simplification flags and variables}
592@closecatbox
593@end defvr
594
595@c -----------------------------------------------------------------------------
596@anchor{evenfun}
597@anchor{oddfun}
598@defvr  {Property} evenfun
599@defvrx {Property} oddfun
600
601@code{declare(f, evenfun)} or @code{declare(f, oddfun)} tells Maxima to recognize
602the function @code{f} as an even or odd function.
603
604Examples:
605
606@c ===beg===
607@c o (- x) + o (x);
608@c declare (o, oddfun);
609@c o (- x) + o (x);
610@c e (- x) - e (x);
611@c declare (e, evenfun);
612@c e (- x) - e (x);
613@c ===end===
614@example
615(%i1) o (- x) + o (x);
616(%o1)                     o(x) + o(- x)
617(%i2) declare (o, oddfun);
618(%o2)                         done
619(%i3) o (- x) + o (x);
620(%o3)                           0
621(%i4) e (- x) - e (x);
622(%o4)                     e(- x) - e(x)
623(%i5) declare (e, evenfun);
624(%o5)                         done
625(%i6) e (- x) - e (x);
626(%o6)                           0
627@end example
628@end defvr
629
630@c -----------------------------------------------------------------------------
631@anchor{expand}
632@deffn  {Function} expand @
633@fname{expand} (@var{expr}) @
634@fname{expand} (@var{expr}, @var{p}, @var{n})
635
636Expand expression @var{expr}.
637Products of sums and exponentiated sums are
638multiplied out, numerators of rational expressions which are sums are
639split into their respective terms, and multiplication (commutative
640and non-commutative) are distributed over addition at all levels of
641@var{expr}.
642
643For polynomials one should usually use @code{ratexpand} which uses a
644more efficient algorithm.
645
646@code{maxnegex} and @code{maxposex} control the maximum negative and
647positive exponents, respectively, which will expand.
648
649@code{expand (@var{expr}, @var{p}, @var{n})} expands @var{expr},
650using @var{p} for @code{maxposex} and @var{n} for @code{maxnegex}.
651This is useful in order to expand part but not all of an expression.
652
653@code{expon} - the exponent of the largest negative power which is
654automatically expanded (independent of calls to @code{expand}).  For example
655if @code{expon} is 4 then @code{(x+1)^(-5)} will not be automatically expanded.
656
657@code{expop} - the highest positive exponent which is automatically expanded.
658Thus @code{(x+1)^3}, when typed, will be automatically expanded only if
659@code{expop} is greater than or equal to 3.  If it is desired to have
660@code{(x+1)^n} expanded where @code{n} is greater than @code{expop} then
661executing @code{expand ((x+1)^n)} will work only if @code{maxposex} is not
662less than @code{n}.
663
664@code{expand(expr, 0, 0)} causes a resimplification of @code{expr}.  @code{expr}
665is not reevaluated.  In distinction from @code{ev(expr, noeval)} a special
666representation (e. g. a CRE form) is removed.  See also @mrefdot{ev}
667
668The @code{expand} flag used with @code{ev} causes expansion.
669
670The file @file{share/simplification/facexp.mac}
671@c I should really use a macro which expands to something like
672@c @uref{file://...,,simplification/facexp.mac}.  But texi2html
673@c currently supports @uref only with one argument.
674@c Worse, the `file:' scheme is OS and browser dependent.
675contains several related functions (in particular @code{facsum},
676@code{factorfacsum} and @code{collectterms}, which are autoloaded) and variables
677(@code{nextlayerfactor} and @code{facsum_combine}) that provide the user with
678the ability to structure expressions by controlled expansion.
679@c MERGE share/simplification/facexp.usg INTO THIS FILE OR CREATE NEW FILE facexp.texi
680Brief function descriptions are available in @file{simplification/facexp.usg}.
681A demo is available by doing @code{demo("facexp")}.
682
683Examples:
684
685@c ===beg===
686@c expr:(x+1)^2*(y+1)^3;
687@c expand(expr);
688@c expand(expr,2);
689@c expr:(x+1)^-2*(y+1)^3;
690@c expand(expr);
691@c expand(expr,2,2);
692@c ===end===
693@example
694@group
695(%i1) expr:(x+1)^2*(y+1)^3;
696                               2        3
697(%o1)                   (x + 1)  (y + 1)
698@end group
699@group
700(%i2) expand(expr);
701       2  3        3    3      2  2        2      2      2
702(%o2) x  y  + 2 x y  + y  + 3 x  y  + 6 x y  + 3 y  + 3 x  y
703                                                      2
704                                     + 6 x y + 3 y + x  + 2 x + 1
705@end group
706@group
707(%i3) expand(expr,2);
708               2        3              3          3
709(%o3)         x  (y + 1)  + 2 x (y + 1)  + (y + 1)
710@end group
711@group
712(%i4) expr:(x+1)^-2*(y+1)^3;
713                                   3
714                            (y + 1)
715(%o4)                       --------
716                                   2
717                            (x + 1)
718@end group
719@group
720(%i5) expand(expr);
721            3               2
722           y             3 y            3 y             1
723(%o5) ------------ + ------------ + ------------ + ------------
724       2              2              2              2
725      x  + 2 x + 1   x  + 2 x + 1   x  + 2 x + 1   x  + 2 x + 1
726@end group
727@group
728(%i6) expand(expr,2,2);
729                                   3
730                            (y + 1)
731(%o6)                     ------------
732                           2
733                          x  + 2 x + 1
734@end group
735@end example
736
737Resimplify an expression without expansion:
738
739@c ===beg===
740@c expr:(1+x)^2*sin(x);
741@c exponentialize:true;
742@c expand(expr,0,0);
743@c ===end===
744@example
745@group
746(%i1) expr:(1+x)^2*sin(x);
747                                2
748(%o1)                    (x + 1)  sin(x)
749@end group
750@group
751(%i2) exponentialize:true;
752(%o2)                         true
753@end group
754@group
755(%i3) expand(expr,0,0);
756                            2    %i x     - %i x
757                  %i (x + 1)  (%e     - %e      )
758(%o3)           - -------------------------------
759                                 2
760@end group
761@end example
762
763@opencatbox
764@category{Expressions}
765@closecatbox
766@end deffn
767
768@c NEEDS EXAMPLES
769
770@c -----------------------------------------------------------------------------
771@anchor{expandwrt}
772@deffn {Function} expandwrt (@var{expr}, @var{x_1}, @dots{}, @var{x_n})
773
774Expands expression @code{expr} with respect to the
775variables @var{x_1}, @dots{}, @var{x_n}.
776All products involving the variables appear explicitly.  The form returned
777will be free of products of sums of expressions that are not free of
778the variables.  @var{x_1}, @dots{}, @var{x_n}
779may be variables, operators, or expressions.
780
781By default, denominators are not expanded, but this can be controlled by
782means of the switch @code{expandwrt_denom}.
783
784This function is autoloaded from
785@file{simplification/stopex.mac}.
786
787@opencatbox
788@category{Expressions}
789@closecatbox
790@end deffn
791
792@c -----------------------------------------------------------------------------
793@anchor{expandwert_denom}
794@defvr {Option variable} expandwrt_denom
795Default value: @code{false}
796
797@code{expandwrt_denom} controls the treatment of rational
798expressions by @code{expandwrt}.  If @code{true}, then both the numerator and
799denominator of the expression will be expanded according to the
800arguments of @code{expandwrt}, but if @code{expandwrt_denom} is @code{false},
801then only the numerator will be expanded in that way.
802
803@opencatbox
804@category{Expressions}
805@closecatbox
806@end defvr
807
808@c NEEDS A STAND-ALONE DESCRIPTION (NOT "IS SIMILAR TO")
809@c NEEDS EXAMPLES
810
811@c -----------------------------------------------------------------------------
812@anchor{expandwrt_factored}
813@deffn {Function} expandwrt_factored (@var{expr}, @var{x_1}, @dots{}, @var{x_n})
814
815is similar to @code{expandwrt}, but treats expressions that are products
816somewhat differently.  @code{expandwrt_factored} expands only on those factors
817of @code{expr} that contain the variables @var{x_1}, @dots{}, @var{x_n}.
818
819@c NOT SURE WHY WE SHOULD MENTION THIS HERE
820This function is autoloaded from @file{simplification/stopex.mac}.
821
822@opencatbox
823@category{Expressions}
824@closecatbox
825@end deffn
826
827@c -----------------------------------------------------------------------------
828@anchor{expon}
829@defvr {Option variable} expon
830Default value: 0
831
832@code{expon} is the exponent of the largest negative power which
833is automatically expanded (independent of calls to @code{expand}).  For
834example, if @code{expon} is 4 then @code{(x+1)^(-5)} will not be automatically
835expanded.
836
837@opencatbox
838@category{Expressions}
839@closecatbox
840@end defvr
841
842@c -----------------------------------------------------------------------------
843@anchor{exponentialize}
844@deffn  {Function} exponentialize (@var{expr})
845@deffnx {Option variable} exponentialize
846
847The function @code{exponentialize (expr)} converts
848circular and hyperbolic functions in @var{expr} to exponentials,
849without setting the global variable @code{exponentialize}.
850
851When the variable @code{exponentialize} is @code{true},
852all circular and hyperbolic functions are converted to exponential form.
853The default value is @code{false}.
854
855@code{demoivre} converts complex exponentials into circular functions.
856@code{exponentialize} and @code{demoivre} cannot
857both be true at the same time.
858
859@opencatbox
860@category{Complex variables}
861@category{Trigonometric functions}
862@category{Hyperbolic functions}
863@closecatbox
864@end deffn
865
866@c NEEDS CLARIFICATION
867@c NEEDS EXAMPLES
868
869@c -----------------------------------------------------------------------------
870@anchor{expop}
871@defvr {Option variable} expop
872Default value: 0
873
874@code{expop} is the highest positive exponent which is automatically expanded.
875Thus @code{(x + 1)^3}, when typed, will be automatically expanded only if
876@code{expop} is greater than or equal to 3.  If it is desired to have
877@code{(x + 1)^n} expanded where @code{n} is greater than @code{expop} then
878executing @code{expand ((x + 1)^n)} will work only if @code{maxposex} is not
879less than n.
880
881@opencatbox
882@category{Expressions}
883@closecatbox
884@end defvr
885
886@c NEEDS CLARIFICATION, EXAMPLES
887
888@c -----------------------------------------------------------------------------
889@anchor{lassociative}
890@defvr {Property} lassociative
891
892@code{declare (g, lassociative)} tells the Maxima simplifier that @code{g} is
893left-associative.  E.g., @code{g (g (a, b), g (c, d))} will simplify to
894@code{g (g (g (a, b), c), d)}.
895
896@opencatbox
897@category{Declarations and inferences}
898@category{Operators}
899@category{Simplification}
900@closecatbox
901@end defvr
902
903@c NEEDS CLARIFICATION, EXAMPLES
904@c WHAT'S UP WITH THE QUOTE MARKS ??
905
906@c -----------------------------------------------------------------------------
907@anchor{linear}
908@defvr {Property} linear
909
910One of Maxima's operator properties.  For univariate @code{f} so
911declared, "expansion" @code{f(x + y)} yields @code{f(x) + f(y)},
912@code{f(a*x)} yields @code{a*f(x)} takes
913place where @code{a} is a "constant".  For functions of two or more arguments,
914"linearity" is defined to be as in the case of @code{sum} or @code{integrate},
915i.e., @code{f (a*x + b, x)} yields @code{a*f(x,x) + b*f(1,x)}
916for @code{a} and @code{b} free of @code{x}.
917
918Example:
919
920@c ===beg===
921@c declare (f, linear);
922@c f(x+y);
923@c declare (a, constant);
924@c f(a*x);
925@c ===end===
926@example
927@group
928(%i1) declare (f, linear);
929(%o1)                         done
930@end group
931@group
932(%i2) f(x+y);
933(%o2)                      f(y) + f(x)
934@end group
935@group
936(%i3) declare (a, constant);
937(%o3)                         done
938@end group
939@group
940(%i4) f(a*x);
941(%o4)                        a f(x)
942@end group
943@end example
944
945@code{linear} is equivalent to @code{additive} and @code{outative}.
946See also @mrefdot{opproperties}
947
948Example:
949
950@c ===beg===
951@c 'sum (F(k) + G(k), k, 1, inf);
952@c declare (nounify (sum), linear);
953@c 'sum (F(k) + G(k), k, 1, inf);
954@c ===end===
955@example
956@group
957(%i1) 'sum (F(k) + G(k), k, 1, inf);
958                       inf
959                       ====
960                       \
961(%o1)                   >    (G(k) + F(k))
962                       /
963                       ====
964                       k = 1
965@end group
966@group
967(%i2) declare (nounify (sum), linear);
968(%o2)                         done
969@end group
970@group
971(%i3) 'sum (F(k) + G(k), k, 1, inf);
972                     inf          inf
973                     ====         ====
974                     \            \
975(%o3)                 >    G(k) +  >    F(k)
976                     /            /
977                     ====         ====
978                     k = 1        k = 1
979@end group
980@end example
981
982@opencatbox
983@category{Declarations and inferences}
984@category{Operators}
985@category{Simplification}
986@closecatbox
987@end defvr
988
989@c NEEDS EXAMPLES
990
991@c -----------------------------------------------------------------------------
992@anchor{maxnegex}
993@defvr {Option variable} maxnegex
994Default value: 1000
995
996@code{maxnegex} is the largest negative exponent which will
997be expanded by the @code{expand} command, see also @mrefdot{maxposex}
998
999@opencatbox
1000@category{Expressions}
1001@closecatbox
1002@end defvr
1003
1004@c NEEDS EXAMPLES
1005
1006@c -----------------------------------------------------------------------------
1007@anchor{maxposex}
1008@defvr {Option variable} maxposex
1009Default value: 1000
1010
1011@code{maxposex} is the largest exponent which will be
1012expanded with the @code{expand} command, see also @mrefdot{maxnegex}
1013
1014@opencatbox
1015@category{Expressions}
1016@closecatbox
1017@end defvr
1018
1019@c NEEDS EXAMPLES
1020
1021@c -----------------------------------------------------------------------------
1022@anchor{multiplicative}
1023@defvr {Property} multiplicative
1024
1025@code{declare(f, multiplicative)} tells the Maxima simplifier that @code{f}
1026is multiplicative.
1027
1028@enumerate
1029@item
1030If @code{f} is univariate, whenever the simplifier encounters @code{f} applied
1031to a product, @code{f} distributes over that product.  E.g., @code{f(x*y)}
1032simplifies to @code{f(x)*f(y)}.
1033This simplification is not applied to expressions of the form @code{f('product(...))}.
1034@item
1035If @code{f} is a function of 2 or more arguments, multiplicativity is
1036defined as multiplicativity in the first argument to @code{f}, e.g.,
1037@code{f (g(x) * h(x), x)} simplifies to @code{f (g(x) ,x) * f (h(x), x)}.
1038@end enumerate
1039
1040@code{declare(nounify(product), multiplicative)} tells Maxima to simplify symbolic products.
1041
1042Example:
1043
1044@c ===beg===
1045@c F2 (a * b * c);
1046@c declare (F2, multiplicative);
1047@c F2 (a * b * c);
1048@c ===end===
1049@example
1050@group
1051(%i1) F2 (a * b * c);
1052(%o1)                       F2(a b c)
1053@end group
1054@group
1055(%i2) declare (F2, multiplicative);
1056(%o2)                         done
1057@end group
1058@group
1059(%i3) F2 (a * b * c);
1060(%o3)                   F2(a) F2(b) F2(c)
1061@end group
1062@end example
1063
1064@code{declare(nounify(product), multiplicative)} tells Maxima to simplify symbolic products.
1065
1066@c ===beg===
1067@c product (a[i] * b[i], i, 1, n);
1068@c declare (nounify (product), multiplicative);
1069@c product (a[i] * b[i], i, 1, n);
1070@c ===end===
1071@example
1072@group
1073(%i1) product (a[i] * b[i], i, 1, n);
1074                             n
1075                           /===\
1076                            ! !
1077(%o1)                       ! !  a  b
1078                            ! !   i  i
1079                           i = 1
1080@end group
1081@group
1082(%i2) declare (nounify (product), multiplicative);
1083(%o2)                         done
1084@end group
1085@group
1086(%i3) product (a[i] * b[i], i, 1, n);
1087                          n         n
1088                        /===\     /===\
1089                         ! !       ! !
1090(%o3)                  ( ! !  a )  ! !  b
1091                         ! !   i   ! !   i
1092                        i = 1     i = 1
1093@end group
1094@end example
1095
1096@opencatbox
1097@category{Declarations and inferences}
1098@category{Expressions}
1099@category{Simplification}
1100@closecatbox
1101@end defvr
1102
1103@c NEEDS WORK
1104
1105@c -----------------------------------------------------------------------------
1106@anchor{multthru}
1107@deffn  {Function} multthru @
1108@fname{multthru} (@var{expr}) @
1109@fname{multthru} (@var{expr_1}, @var{expr_2})
1110
1111Multiplies a factor (which should be a sum) of @var{expr} by the other factors
1112of @var{expr}.  That is, @var{expr} is @code{@var{f_1} @var{f_2} ... @var{f_n}}
1113where at least one factor, say @var{f_i}, is a sum of terms.  Each term in that
1114sum is multiplied by the other factors in the product.  (Namely all the factors
1115except @var{f_i}).  @code{multthru} does not expand exponentiated sums.
1116This function is the fastest way to distribute products (commutative or
1117noncommutative) over sums.  Since quotients are represented as products
1118@code{multthru} can be used to divide sums by products as well.
1119
1120@code{multthru (@var{expr_1}, @var{expr_2})} multiplies each term in
1121@var{expr_2} (which should be a sum or an equation) by @var{expr_1}.  If
1122@var{expr_1} is not itself a sum then this form is equivalent to
1123@code{multthru (@var{expr_1}*@var{expr_2})}.
1124
1125@c ===beg===
1126@c x/(x-y)^2 - 1/(x-y) - f(x)/(x-y)^3;
1127@c multthru ((x-y)^3, %);
1128@c ratexpand (%);
1129@c ((a+b)^10*s^2 + 2*a*b*s + (a*b)^2)/(a*b*s^2);
1130@c multthru (%);  /* note that this does not expand (b+a)^10 */
1131@c multthru (a.(b+c.(d+e)+f));
1132@c expand (a.(b+c.(d+e)+f));
1133@c ===end===
1134@example
1135(%i1) x/(x-y)^2 - 1/(x-y) - f(x)/(x-y)^3;
1136                      1        x         f(x)
1137(%o1)             - ----- + -------- - --------
1138                    x - y          2          3
1139                            (x - y)    (x - y)
1140(%i2) multthru ((x-y)^3, %);
1141                           2
1142(%o2)             - (x - y)  + x (x - y) - f(x)
1143(%i3) ratexpand (%);
1144                           2
1145(%o3)                   - y  + x y - f(x)
1146(%i4) ((a+b)^10*s^2 + 2*a*b*s + (a*b)^2)/(a*b*s^2);
1147                        10  2              2  2
1148                 (b + a)   s  + 2 a b s + a  b
1149(%o4)            ------------------------------
1150                                  2
1151                             a b s
1152(%i5) multthru (%);  /* note that this does not expand (b+a)^10 */
1153                                        10
1154                       2   a b   (b + a)
1155(%o5)                  - + --- + ---------
1156                       s    2       a b
1157                           s
1158(%i6) multthru (a.(b+c.(d+e)+f));
1159(%o6)            a . f + a . c . (e + d) + a . b
1160(%i7) expand (a.(b+c.(d+e)+f));
1161(%o7)         a . f + a . c . e + a . c . d + a . b
1162@end example
1163
1164@opencatbox
1165@category{Expressions}
1166@closecatbox
1167@end deffn
1168
1169@c -----------------------------------------------------------------------------
1170@anchor{property_nary}
1171@defvr {Property} nary
1172
1173@code{declare(f, nary)} tells Maxima to recognize the function @code{f} as an
1174n-ary function.
1175
1176The @code{nary} declaration is not the same as calling the
1177@mxref{function_nary, nary} function.  The sole effect of
1178@code{declare(f, nary)} is to instruct the Maxima simplifier to flatten nested
1179expressions, for example, to simplify @code{foo(x, foo(y, z))} to
1180@code{foo(x, y, z)}.  See also @mrefdot{declare}
1181
1182Example:
1183
1184@c ===beg===
1185@c H (H (a, b), H (c, H (d, e)));
1186@c declare (H, nary);
1187@c H (H (a, b), H (c, H (d, e)));
1188@c ===end===
1189@example
1190(%i1) H (H (a, b), H (c, H (d, e)));
1191(%o1)               H(H(a, b), H(c, H(d, e)))
1192(%i2) declare (H, nary);
1193(%o2)                         done
1194(%i3) H (H (a, b), H (c, H (d, e)));
1195(%o3)                   H(a, b, c, d, e)
1196@end example
1197@end defvr
1198
1199@c NEEDS CLARIFICATION, EXAMPLES
1200
1201@c -----------------------------------------------------------------------------
1202@anchor{negdistrib}
1203@defvr {Option variable} negdistrib
1204Default value: @code{true}
1205
1206When @code{negdistrib} is @code{true}, -1 distributes over an expression.
1207E.g., @code{-(x + y)} becomes @code{- y - x}.  Setting it to @code{false}
1208will allow @code{- (x + y)} to be displayed like that.  This is sometimes useful
1209but be very careful: like the @code{simp} flag, this is one flag you do not
1210want to set to @code{false} as a matter of course or necessarily for other
1211than local use in your Maxima.
1212
1213Example:
1214
1215@c ===beg===
1216@c negdistrib;
1217@c -(x+y);
1218@c negdistrib : not negdistrib ;
1219@c -(x+y);
1220@c ===end===
1221@example
1222@group
1223(%i1) negdistrib;
1224(%o1)                         true
1225@end group
1226@group
1227(%i2) -(x+y);
1228(%o2)                       (- y) - x
1229@end group
1230@group
1231(%i3) negdistrib : not negdistrib ;
1232(%o3)                         false
1233@end group
1234@group
1235(%i4) -(x+y);
1236(%o4)                       - (y + x)
1237@end group
1238@end example
1239
1240@opencatbox
1241@category{Simplification flags and variables}
1242@closecatbox
1243@end defvr
1244
1245@c -----------------------------------------------------------------------------
1246@anchor{opproperties}
1247@defvr {System variable} opproperties
1248
1249@code{opproperties} is the list of the special operator properties recognized
1250by the Maxima simplifier.
1251
1252Items are added to the @code{opproperties} list by the function @code{define_opproperty}.
1253
1254Example:
1255
1256@c ===beg===
1257@c opproperties;
1258@c ===end===
1259@example
1260@group
1261(%i1) opproperties;
1262(%o1) [linear, additive, multiplicative, outative, evenfun,
1263oddfun, commutative, symmetric, antisymmetric, nary,
1264lassociative, rassociative]
1265@end group
1266@end example
1267
1268@opencatbox
1269@category{Global variables}
1270@category{Operators}
1271@category{Simplification}
1272@closecatbox
1273@end defvr
1274
1275@c NEEDS EXAMPLES
1276
1277@c -----------------------------------------------------------------------------
1278@anchor{define_opproperty}
1279@deffn {Function} define_opproperty (@var{property_name}, @var{simplifier_fn})
1280
1281Declares the symbol @var{property_name} to be an operator property,
1282which is simplified by @var{simplifier_fn},
1283which may be the name of a Maxima or Lisp function or a lambda expression.
1284After @code{define_opproperty} is called,
1285functions and operators may be declared to have the @var{property_name} property,
1286and @var{simplifier_fn} is called to simplify them.
1287
1288@var{simplifier_fn} must be a function of one argument,
1289which is an expression in which the main operator is declared to have the @var{property_name} property.
1290
1291@var{simplifier_fn} is called with the global flag @code{simp} disabled.
1292Therefore @var{simplifier_fn} must be able to carry out its simplification
1293without making use of the general simplifier.
1294
1295@code{define_opproperty} appends @var{property_name} to the
1296global list @code{opproperties}.
1297
1298@code{define_opproperty} returns @code{done}.
1299
1300Example:
1301
1302Declare a new property, @code{identity}, which is simplified by @code{simplify_identity}.
1303Declare that @code{f} and @code{g} have the new property.
1304
1305@c ===beg===
1306@c define_opproperty (identity, simplify_identity);
1307@c simplify_identity(e) := first(e);
1308@c declare ([f, g], identity);
1309@c f(10 + t);
1310@c g(3*u) - f(2*u);
1311@c ===end===
1312@example
1313@group
1314(%i1) define_opproperty (identity, simplify_identity);
1315(%o1)                         done
1316@end group
1317@group
1318(%i2) simplify_identity(e) := first(e);
1319(%o2)           simplify_identity(e) := first(e)
1320@end group
1321@group
1322(%i3) declare ([f, g], identity);
1323(%o3)                         done
1324@end group
1325@group
1326(%i4) f(10 + t);
1327(%o4)                        t + 10
1328@end group
1329@group
1330(%i5) g(3*u) - f(2*u);
1331(%o5)                           u
1332@end group
1333@end example
1334
1335@opencatbox
1336@category{Operators}
1337@category{Simplification}
1338@closecatbox
1339@end deffn
1340
1341@c -----------------------------------------------------------------------------
1342@anchor{outative}
1343@defvr {Property} outative
1344
1345@code{declare(f, outative)} tells the Maxima simplifier that constant factors
1346in the argument of @code{f} can be pulled out.
1347
1348@enumerate
1349@item
1350If @code{f} is univariate, whenever the simplifier encounters @code{f} applied
1351to a product, that product will be partitioned into factors that are constant
1352and factors that are not and the constant factors will be pulled out.  E.g.,
1353@code{f(a*x)} will simplify to @code{a*f(x)} where @code{a} is a constant.
1354Non-atomic constant factors will not be pulled out.
1355@item
1356If @code{f} is a function of 2 or more arguments, outativity is defined as in
1357the case of @code{sum} or @code{integrate}, i.e., @code{f (a*g(x), x)} will
1358simplify to @code{a * f(g(x), x)} for @code{a} free of @code{x}.
1359@end enumerate
1360
1361@code{sum}, @code{integrate}, and @code{limit} are all @code{outative}.
1362
1363Example:
1364
1365@c ===beg===
1366@c F1 (100 * x);
1367@c declare (F1, outative);
1368@c F1 (100 * x);
1369@c declare (zz, constant);
1370@c F1 (zz * y);
1371@c ===end===
1372@example
1373@group
1374(%i1) F1 (100 * x);
1375(%o1)                       F1(100 x)
1376@end group
1377@group
1378(%i2) declare (F1, outative);
1379(%o2)                         done
1380@end group
1381@group
1382(%i3) F1 (100 * x);
1383(%o3)                       100 F1(x)
1384@end group
1385@group
1386(%i4) declare (zz, constant);
1387(%o4)                         done
1388@end group
1389@group
1390(%i5) F1 (zz * y);
1391(%o5)                       zz F1(y)
1392@end group
1393@end example
1394
1395@opencatbox
1396@category{Declarations and inferences}
1397@category{Operators}
1398@closecatbox
1399@end defvr
1400
1401@c -----------------------------------------------------------------------------
1402@anchor{radcan}
1403@deffn {Function} radcan (@var{expr})
1404
1405Simplifies @var{expr}, which can contain logs, exponentials, and radicals, by
1406converting it into a form which is canonical over a large class of expressions
1407and a given ordering of variables; that is, all functionally equivalent forms
1408are mapped into a unique form.  For a somewhat larger class of expressions,
1409@code{radcan} produces a regular form.  Two equivalent expressions in this class
1410do not necessarily have the same appearance, but their difference can be
1411simplified by @code{radcan} to zero.
1412
1413For some expressions @code{radcan} is quite time consuming.  This is the cost
1414of exploring certain relationships among the components of the expression for
1415simplifications based on factoring and partial-fraction expansions of exponents.
1416
1417@c %e_to_numlog NEEDS ITS OWN @defvar !!!
1418
1419@c %e_to_numlog HAS NO EFFECT ON RADCAN. RADCAN ALWAYS SIMPLIFIES
1420@c exp(a*log(x)) --> x^a. Commenting the following out. 11/2009
1421@c When @code{%e_to_numlog} is @code{true}, @code{%e^(r*log(expr))} simplifies
1422@c to @code{expr^r} if @code{r} is a rational number.
1423
1424@c RADEXPAND CONTROLS THE SIMPLIFICATION OF THE POWER FUNCTION, E.G.
1425@c (x*y)^a --> x^a*y^a AND (x^a)^b --> x^(a*b), IF RADEXPAND HAS THE VALUE 'ALL.
1426@c THE VALUE OF RADEXPAND HAS NO EFFECT ON RADCAN. RADCAN ALWAYS SIMPLIFIES
1427@c THE ABOVE EXPRESSIONS. COMMENTING THE FOLLOWING OUT. 11/2009
1428@c When @code{radexpand} is @code{false}, certain transformations are inhibited.
1429@c @code{radcan (sqrt (1-x))} remains @code{sqrt (1-x)} and is not simplified
1430@c to @code{%i sqrt (x-1)}. @code{radcan (sqrt (x^2 - 2*x + 1))} remains
1431@c @code{sqrt (x^2 - 2*x + 1)} and is not simplified to @code{x - 1}.
1432
1433Examples:
1434
1435@c ===beg===
1436@c radcan((log(x+x^2)-log(x))^a/log(1+x)^(a/2));
1437@c radcan((log(1+2*a^x+a^(2*x))/log(1+a^x)));
1438@c radcan((%e^x-1)/(1+%e^(x/2)));
1439@c ===end===
1440@example
1441@group
1442(%i1) radcan((log(x+x^2)-log(x))^a/log(1+x)^(a/2));
1443                                    a/2
1444(%o1)                     log(x + 1)
1445@end group
1446@group
1447(%i2) radcan((log(1+2*a^x+a^(2*x))/log(1+a^x)));
1448(%o2)                           2
1449@end group
1450@group
1451(%i3) radcan((%e^x-1)/(1+%e^(x/2)));
1452                              x/2
1453(%o3)                       %e    - 1
1454@end group
1455@end example
1456
1457@opencatbox
1458@category{Simplification functions}
1459@closecatbox
1460@end deffn
1461
1462@c NEEDS CLARIFICATION, EXAMPLES
1463
1464@c -----------------------------------------------------------------------------
1465@anchor{radexpand}
1466@defvr {Option variable} radexpand
1467Default value: @code{true}
1468
1469@code{radexpand} controls some simplifications of radicals.
1470
1471When @code{radexpand} is @code{all}, causes nth roots of factors of a product
1472which are powers of n to be pulled outside of the radical.  E.g. if
1473@code{radexpand} is @code{all}, @code{sqrt (16*x^2)} simplifies to @code{4*x}.
1474
1475@c EXPRESS SIMPLIFICATON RULES IN GENERAL CASE, NOT SPECIAL CASE
1476More particularly, consider @code{sqrt (x^2)}.
1477@itemize @bullet
1478@item
1479If @code{radexpand} is @code{all} or @code{assume (x > 0)} has been executed,
1480@code{sqrt(x^2)} simplifies to @code{x}.
1481@item
1482If @code{radexpand} is @code{true} and @code{domain} is @code{real}
1483(its default), @code{sqrt(x^2)} simplifies to @code{abs(x)}.
1484@item
1485If @code{radexpand} is @code{false}, or @code{radexpand} is @code{true} and
1486@code{domain} is @code{complex}, @code{sqrt(x^2)} is not simplified.
1487@end itemize
1488
1489@c CORRECT STATEMENT HERE ???
1490Note that @code{domain} only matters when @code{radexpand} is @code{true}.
1491
1492@opencatbox
1493@category{Simplification flags and variables}
1494@closecatbox
1495@end defvr
1496
1497@c NEEDS CLARIFICATION, EXAMPLES
1498
1499@c -----------------------------------------------------------------------------
1500@anchor{rassociative}
1501@defvr {Property} rassociative
1502
1503@code{declare (g, rassociative)} tells the Maxima
1504simplifier that @code{g} is right-associative.  E.g.,
1505@code{g(g(a, b), g(c, d))} simplifies to @code{g(a, g(b, g(c, d)))}.
1506
1507@opencatbox
1508@category{Declarations and inferences}
1509@category{Operators}
1510@closecatbox
1511@end defvr
1512
1513@c NEEDS CLARIFICATION, EXAMPLES
1514
1515@c -----------------------------------------------------------------------------
1516@anchor{scsimp}
1517@deffn {Function} scsimp (@var{expr}, @var{rule_1}, @dots{}, @var{rule_n})
1518
1519Sequential Comparative Simplification (method due to Stoute).
1520@code{scsimp} attempts to simplify @var{expr}
1521according to the rules @var{rule_1}, @dots{}, @var{rule_n}.
1522If a smaller expression is obtained, the process repeats.  Otherwise after all
1523simplifications are tried, it returns the original answer.
1524
1525@c MERGE EXAMPLES INTO THIS FILE
1526@code{example (scsimp)} displays some examples.
1527
1528@opencatbox
1529@category{Simplification functions}
1530@closecatbox
1531@end deffn
1532
1533@c -----------------------------------------------------------------------------
1534@anchor{simp}
1535@defvr {Option variable} simp
1536Default value: @code{true}
1537
1538@code{simp} enables simplification.  This is the default.  @code{simp} is also
1539an @code{evflag}, which is recognized by the function @code{ev}.  See @mrefdot{ev}
1540
1541When @code{simp} is used as an @code{evflag} with a value @code{false}, the
1542simplification is suppressed only during the evaluation phase of an expression.
1543The flag does not suppress the simplification which follows the evaluation
1544phase.
1545
1546Many Maxima functions and operations require simplification to be enabled to work normally.
1547When simplification is disabled, many results will be incomplete,
1548and in addition there may be incorrect results or program errors.
1549
1550Examples:
1551
1552The simplification is switched off globally.  The expression @code{sin(1.0)} is
1553not simplified to its numerical value.  The @code{simp}-flag switches the
1554simplification on.
1555
1556@c ===beg===
1557@c simp:false;
1558@c sin(1.0);
1559@c sin(1.0),simp;
1560@c ===end===
1561@example
1562@group
1563(%i1) simp:false;
1564(%o1)                         false
1565@end group
1566@group
1567(%i2) sin(1.0);
1568(%o2)                       sin(1.0)
1569@end group
1570@group
1571(%i3) sin(1.0),simp;
1572(%o3)                  0.8414709848078965
1573@end group
1574@end example
1575
1576The simplification is switched on again.  The @code{simp}-flag cannot suppress
1577the simplification completely.  The output shows a simplified expression, but
1578the variable @code{x} has an unsimplified expression as a value, because the
1579assignment has occurred during the evaluation phase of the expression.
1580
1581@c ===beg===
1582@c simp:true;
1583@c x:sin(1.0),simp:false;
1584@c :lisp $x
1585@c ===end===
1586@example
1587@group
1588(%i1) simp:true;
1589(%o1)                         true
1590@end group
1591@group
1592(%i2) x:sin(1.0),simp:false;
1593(%o2)                  0.8414709848078965
1594@end group
1595@group
1596(%i3) :lisp $x
1597((%SIN) 1.0)
1598@end group
1599@end example
1600
1601@opencatbox
1602@category{Evaluation flags}
1603@closecatbox
1604@end defvr
1605
1606@c NEEDS CLARIFICATION, EXAMPLES
1607
1608@c -----------------------------------------------------------------------------
1609@anchor{symmetric}
1610@defvr {Property} symmetric
1611
1612@code{declare (h, symmetric)} tells the Maxima
1613simplifier that @code{h} is a symmetric function.  E.g., @code{h (x, z, y)}
1614simplifies to @code{h (x, y, z)}.
1615
1616@code{commutative} is synonymous with @code{symmetric}.
1617
1618@opencatbox
1619@category{Declarations and inferences}
1620@category{Operators}
1621@closecatbox
1622@end defvr
1623
1624@c -----------------------------------------------------------------------------
1625@anchor{xthru}
1626@deffn {Function} xthru (@var{expr})
1627
1628Combines all terms of @var{expr} (which should be a sum) over a common
1629denominator without expanding products and exponentiated sums as @code{ratsimp}
1630does.  @code{xthru} cancels common factors in the numerator and denominator of
1631rational expressions but only if the factors are explicit.
1632
1633@c REPHRASE IN NEUTRAL TONE (GET RID OF "IT IS BETTER")
1634Sometimes it is better to use @code{xthru} before @code{ratsimp}ing an
1635expression in order to cause explicit factors of the gcd of the numerator and
1636denominator to be canceled thus simplifying the expression to be
1637@code{ratsimp}ed.
1638
1639Examples:
1640
1641@c ===beg===
1642@c ((x+2)^20 - 2*y)/(x+y)^20 + (x+y)^(-19) - x/(x+y)^20;
1643@c xthru (%);
1644@c ===end===
1645@example
1646@group
1647(%i1) ((x+2)^20 - 2*y)/(x+y)^20 + (x+y)^(-19) - x/(x+y)^20;
1648                                20
1649                 1       (x + 2)   - 2 y       x
1650(%o1)        --------- + --------------- - ---------
1651                    19             20             20
1652             (y + x)        (y + x)        (y + x)
1653@end group
1654@group
1655(%i2) xthru (%);
1656                                 20
1657                          (x + 2)   - y
1658(%o2)                     -------------
1659                                   20
1660                            (y + x)
1661@end group
1662@end example
1663
1664@opencatbox
1665@category{Expressions}
1666@closecatbox
1667@end deffn
1668
1669