Introduction to simplification
==============================

The directory maxima/share/simplification contains several scripts which implement simplification rules and functions, and also some functions not related to simplification.

Package absimp
==============

The absimp package contains pattern-matching rules that extend the built-in simplification rules for the abs and signum functions. absimp respects relations established with the built-in assume function and by declarations such as  mode_declare (m, even, n, odd)  for even or odd integers.

absimp defines unitramp and unitstep functions in terms of abs and signum.

load ("absimp") loads this package. demo ("absimp") shows a demonstration of this package.

Examples:

     (%i1) load ("absimp")$

     (%i2) (abs (x))^2;
                                     2
     (%o2)                          x

     (%i3) diff (abs (x), x);
                                    x
     (%o3)                        ------
                                  abs(x)

     (%i4) cosh (abs (x));
     (%o4)                        cosh(x)

Categories: Simplification functions Rules and patterns Share packages Package absimp

Package facexp
==============

The facexp package contains several related  functions that provide the user with the ability to structure expressions by controlled expansion.   This capability  is especially  useful when  the expression contains variables that have physical meaning, because it is  often true that the most economical form  of such an expression can be  obtained by fully expanding the expression with respect to those variables, and then factoring their coefficients.  While it is  true that this  procedure is not difficult to carry out using standard Maxima  functions, additional fine-tuning may also  be desirable, and  these finishing touches  can be more  difficult to  apply.

The  function facsum  and its  related forms provide a convenient means for controlling the structure  of expressions in this way.  Another function, collectterms, can be used to add  two or more expressions that have already been simplified to this form, without resimplifying the whole expression again.  This function may be useful when the expressions are very large.

load ("facexp") loads this package. demo ("facexp") shows a demonstration of this package.

Categories: Expressions Share packages Package facexp

 -- Function: facsum (EXPR, ARG_1, ..., ARG_N)
     Returns  a form  of EXPR  which depends  on the arguments ARG_1, ..., ARG_N. The arguments can be any form suitable for ratvars, or they can be lists  of such  forms.  If  the arguments  are not  lists, then  the form returned is  fully expanded with respect  to the arguments,  and the coefficients of the arguments are factored.  These  coefficients are free of the arguments, except perhaps in a non-rational sense.

     If any of the arguments are  lists, then all such lists are combined into  a  single  list,   and  instead  of  calling  factor   on  the coefficients  of  the  arguments,  facsum  calls  itself   on  these coefficients, using  this newly constructed  single list as  the new argument list  for this  recursive  call.  This  process can  be  repeated to arbitrary depth by nesting the desired elements in lists.

     It is possible that one may wish to facsum with respect  to more complicated subexpressions,  such as  log (x + y).  Such  arguments are also  permissible.

     Occasionally the user may wish to obtain any of the  above forms for expressions which are specified only by their leading operators. For example, one may wish  to facsum with respect to all  log's.  In this situation, one may  include among the arguments either  the specific log's which are to be treated in this way, or  alternatively, either the expression  operator (log) or 'operator (log).   If one  wished to facsum the expression EXPR with respect to the operators OP_1, ..., OP_N, one   would  evaluate  facsum (EXPR, operator (OP_1, ..., OP_N)). The operator form may also appear inside list arguments.

     In  addition,  the  setting  of  the  switches   facsum_combine  and nextlayerfactor may affect the result of facsum.

     Categories: Package facexp Expressions

 -- Global variable: nextlayerfactor
     Default value: false

     When nextlayerfactor is true, recursive calls  of facsum are applied  to  the  factors  of  the  factored  form   of  the coefficients of the arguments.

     When  false, facsum is applied to each coefficient as a whole whenever recursive calls to  facsum occur.

     Inclusion   of   the  atom nextlayerfactor in  the argument  list of facsum  has the  effect of nextlayerfactor: true, but for the next level of the expression only. Since nextlayerfactor is  always bound to  either true or  false, it must be presented single-quoted whenever it appears in the argument list of facsum.

     Categories: Package facexp Expressions

 -- Global variable: facsum_combine
     Default value: true

     facsum_combine controls the form  of the final result  returned by facsum  when  its  argument  is  a  quotient  of   polynomials.   If facsum_combine is false  then the form will  be returned as  a fully expanded  sum  as described  above,  but if  true,  then  the expression returned is a ratio of polynomials, with each polynomial in the form described above.

     The true setting of this switch is useful when one wants to  facsum both  the numerator and  denominator of  a rational expression,  but  does not  want  the denominator  to  be multiplied through the terms of the numerator.

     Categories: Package facexp Expressions

 -- Function: factorfacsum (EXPR, ARG_1, ... ARG_N)
     Returns a  form of EXPR  which is obtained by calling  facsum on the factors  of EXPR with ARG_1, ... ARG_N as arguments.  If any of the factors of EXPR is raised to a  power, both the factor and the exponent will be processed in this way.

     Categories: Package facexp Expressions

 -- Function: collectterms (EXPR, ARG_1, ..., ARG_N)

     Collects all terms that contain ARG_1 ... ARG_N. If several expressions have been simplified  with the following functions facsum, factorfacsum, factenexpand, facexpten or factorfacexpten, and they are to be added together, it may be desirable to combine them using the function  collecterms.  collecterms can take as arguments all of the arguments that can be given to these other associated functions with the exception of nextlayerfactor, which has no effect on collectterms.  The advantage of collectterms is that it returns a form  similar to facsum, but since it is adding forms that have already been processed by facsum, it does not need to repeat that effort. This capability is especially useful when the expressions to be summed are very large.

     See also factor

     Example:

          (%i1) (exp(x)+2)*x+exp(x);
                                       x          x
          (%o1)                   x (%e  + 2) + %e

          (%i2) collectterms(expand(%),exp(x));
                                            x
          (%o2)                   (x + 1) %e  + 2 x

     Categories: Package facexp Expressions

Package functs
==============

Categories: Share packages Package functs

 -- Function: rempart (EXPR, N)
     Removes part N from the expression EXPR.

     If N is a list of the form [L, M] then parts L thru M are removed.

     To use this function write first load("functs").

     Categories: Package functs Expressions

 -- Function: wronskian ([F_1, ..., F_N], X)
     Returns the Wronskian matrix of the list of expressions [F_1, ..., F_N] in the variable X. The determinant of the Wronskian matrix is the Wronskian determinant of the list of expressions.

     To use wronskian, first load("functs"). Example:

          (%i1) load ("functs")$

          (%i2) wronskian([f(x), g(x)],x);
                              [   f(x)       g(x)    ]
                              [                      ]
          (%o2)               [ d          d         ]
                              [ -- (f(x))  -- (g(x)) ]
                              [ dx         dx        ]

     Categories: Package functs Differential calculus

 -- Function: tracematrix (M)
     Returns the trace (sum of the diagonal elements) of matrix M.

     To use this function write first load("functs").

     Categories: Package functs Matrices

 -- Function: rational (Z)
     Multiplies numerator and denominator of Z by the complex conjugate of denominator, thus rationalizing the denominator. Returns canonical rational expression (CRE) form if given one, else returns general form.

     To use this function write first load("functs").

     Categories: Package functs Expressions

 -- Function: nonzeroandfreeof (X, EXPR)
     Returns true if EXPR is nonzero and freeof (X, EXPR) returns true. Returns false otherwise.

     To use this function write first load("functs").

     Categories: Package functs Expressions

 -- Function: linear (EXPR, X)
     When EXPR is an expression of the form A*X + B where A is nonzero, and A and B are free of X, linear returns a list of three equations, one for each of the three formal variables B, A, and X. Otherwise, linear returns false.

     load("antid") loads this function.

     Example:

          (%i1) load ("antid");
          (%o1)  /maxima/share/integration/antid.mac

          (%i2) linear ((1 - w)*(1 - x)*z, z);
          (%o2) [bargumentb = 0, aargumenta = (w - 1) x - w + 1,
                                                            xargumentx = z]

          (%i3) linear (cos(u - v) + cos(u + v), u);
          (%o3)                         false

     Categories: Package antid Expressions

 -- Function: gcdivide (P, Q)

     When the option variable takegcd is true which is the default, gcdivide divides the polynomials P and Q by their greatest common divisor and returns the ratio of the results.  gcdivde calls the function ezgcd to divide the polynomials by the greatest common divisor.

     When takegcd is false, gcdivide returns the ratio P/Q.

     To use this function write first load("functs").

     See also ezgcd gcd gcdex and poly_gcd

     Example:

          (%i1) load("functs")$

          (%i2) p1:6*x^3+19*x^2+19*x+6;
                                  3       2
          (%o2)                6 x  + 19 x  + 19 x + 6
          (%i3) p2:6*x^5+13*x^4+12*x^3+13*x^2+6*x;
                            5       4       3       2
          (%o3)          6 x  + 13 x  + 12 x  + 13 x  + 6 x
          (%i4) gcdivide(p1, p2);
                                       x + 1
          (%o4)                        ------
                                        3
                                       x  + x
          (%i5) takegcd:false;
          (%o5)                         false
          (%i6) gcdivide(p1, p2);
                                 3       2
                              6 x  + 19 x  + 19 x + 6
          (%o6)          ----------------------------------
                            5       4       3       2
                         6 x  + 13 x  + 12 x  + 13 x  + 6 x
          (%i7) ratsimp(%);
                                       x + 1
          (%o7)                        ------
                                        3
                                       x  + x

     Categories: Package functs Polynomials

 -- Function: arithmetic (A, D, N)
     Returns the N-th term of the arithmetic series A, A + D, A + 2*D, ..., A + (N - 1)*D.

     To use this function write first load("functs").

     Categories: Package functs Sums and products

 -- Function: geometric (A, R, N)
     Returns the N-th term of the geometric series A, A*R, A*R^2, ..., A*R^(N - 1).

     To use this function write first load("functs").

     Categories: Package functs Sums and products

 -- Function: harmonic (A, B, C, N)
     Returns the N-th term of the harmonic series A/B, A/(B + C), A/(B + 2*C), ..., A/(B + (N - 1)*C).

     To use this function write first load("functs").

     Categories: Package functs Sums and products

 -- Function: arithsum (A, D, N)
     Returns the sum of the arithmetic series from 1 to N.

     To use this function write first load("functs").

     Categories: Package functs Sums and products

 -- Function: geosum (A, R, N)
     Returns the sum of the geometric series from 1 to N.  If N is infinity (inf) then a sum is finite only if the absolute value of R is less than 1.

     To use this function write first load("functs").

     Categories: Package functs Sums and products

 -- Function: gaussprob (X)
     Returns the Gaussian probability function %e^(-X^2/2) / sqrt(2*%pi).

     To use this function write first load("functs").

     Categories: Package functs Mathematical functions

 -- Function: gd (X)
     Returns the Gudermannian function 2*atan(%e^x)-%pi/2.

     To use this function write first load("functs").

     Categories: Package functs Mathematical functions

 -- Function: agd (X)
     Returns the inverse Gudermannian function log (tan (%pi/4 + x/2)).

     To use this function write first load("functs").

     Categories: Package functs Mathematical functions

 -- Function: vers (X)
     Returns the versed sine 1 - cos (x).

     To use this function write first load("functs").

     Categories: Package functs Mathematical functions

 -- Function: covers (X)
     Returns the coversed sine 1 - sin (X).

     To use this function write first load("functs").

     Categories: Package functs Mathematical functions

 -- Function: exsec (X)
     Returns the exsecant sec (X) - 1.

     To use this function write first load("functs").

     Categories: Package functs Mathematical functions

 -- Function: hav (X)
     Returns the haversine (1 - cos(x))/2.

     To use this function write first load("functs").

     Categories: Package functs Mathematical functions

 -- Function: combination (N, R)
     Returns the number of combinations of N objects taken R at a time.

     To use this function write first load("functs").

     Categories: Package functs Mathematical functions

 -- Function: permutation (N, R)
     Returns the number of permutations of R objects selected from a set of N objects.

     To use this function write first load("functs").

     Categories: Package functs Mathematical functions

Package ineq
============

The ineq package contains simplification rules for inequalities.

Example session:

     (%i1) load("ineq")$
     tellsimp: warning: rule will treat '+
                               ' as noncommutative and nonassociative.
     tellsimp: warning: rule will treat '+
                               ' as noncommutative and nonassociative.
     tellsimp: warning: rule will treat '+
                               ' as noncommutative and nonassociative.
     tellsimp: warning: rule will treat '+
                               ' as noncommutative and nonassociative.
     tellsimp: warning: rule will treat '+
                               ' as noncommutative and nonassociative.
     tellsimp: warning: rule will treat '+
                               ' as noncommutative and nonassociative.
     tellsimp: warning: rule will treat '+
                               ' as noncommutative and nonassociative.
     tellsimp: warning: rule will treat '+
                               ' as noncommutative and nonassociative.

     (%i2) a>=4;  /* a sample inequality */
     (%o2)                        a >= 4
     (%o3)                     b + a > c + 4
     (%o4)                       7 x < 7 y
     (%o5)                    - 2 x <= - 6 z
                                      2
     (%o6)                      1 <= a  + 1
     (%o8)                       2 x < 3 x
     (%o9)                        a >= b
     (%o10)                   a + 3 >= b + 3
     (%o11)                       a >= b
     (%o12)                     a >= c - b
     (%o13)                     b + a >= c
     (%o14)                 (- c) + b + a >= 0
     (%o15)                   c - b - a <= 0
                                    2
     (%o16)                  (z - 1)  > - 2 z
                                 2
     (%o17)                     z  + 1 > 0
     (%o18)                        true

     (%i19) (b>c)+%; /* add a second, strict inequality */

Be careful about using parentheses around the inequalities: when the user types in (A > B) + (C = 5) the result is A + C > B + 5, but A > B + C = 5 is a syntax error, and (A > B + C) = 5 is something else entirely.

Do disprule (all) to see a complete listing of the rule definitions.

The user will be queried if Maxima is unable to decide the sign of a quantity multiplying an inequality.

The most common mis-feature is illustrated by:

     (%i1) eq: a > b;
     (%o1)                         a > b

     (%i2) 2*eq;
     (%o2)                       2 (a > b)

     (%i3) % - eq;
     (%o3)                         a > b

Another problem is 0 times an inequality; the default to have this turn into 0 has been left alone. However, if you type X*SOME_INEQUALITY and Maxima asks about the sign of X and you respond zero (or z), the program returns X*SOME_INEQUALITY and not use the information that X is 0. You should do ev (%, x: 0) in such a case, as the database will only be used for comparison purposes in decisions, and not for the purpose of evaluating X.

The user may note a slower response when this package is loaded, as the simplifier is forced to examine more rules than without the package, so you might wish to remove the rules after making use of them. Do kill (rules) to eliminate all of the rules (including any that you might have defined); or you may be more selective by killing only some of them; or use remrule on a specific rule.

Note that if you load this package after defining your own rules you will clobber your rules that have the same name. The rules in this package are: *rule1, ..., *rule8, +rule1, ..., +rule18, and you must enclose the rulename in quotes to refer to it, as in remrule ("+", "+rule1") to specifically remove the first rule on "+" or disprule ("*rule2") to display the definition of the second multiplicative rule.

Categories: Simplification functions Rules and patterns Share packages Package ineq

Package rducon
==============

Categories: Expressions Share packages Package rducon

 -- Function: reduce_consts (EXPR)
     Replaces constant subexpressions of EXPR with constructed constant atoms, saving the definition of all these constructed constants in the list of equations const_eqns, and returning the modified EXPR.  Those parts of EXPR are constant which return true when operated on by the function constantp.  Hence, before invoking reduce_consts, one should do

          declare ([OBJECTS TO BE GIVEN THE CONSTANT PROPERTY], constant)$

     to set up a database of the constant quantities occurring in your expressions.

     If you are planning to generate Fortran output after these symbolic calculations, one of the first code sections should be the calculation of all constants.  To generate this code segment, do

          map ('fortran, const_eqns)$

     Variables besides const_eqns which affect reduce_consts are:

     const_prefix (default value: xx) is the string of characters used to prefix all symbols generated by reduce_consts to represent constant subexpressions.

     const_counter (default value: 1) is the integer index used to generate unique symbols to represent each constant subexpression found by reduce_consts.

     load ("rducon") loads this function. demo ("rducon") shows a demonstration of this function.

     Categories: Package rducon Expressions

Package scifac
==============

Categories: Expressions Share packages Package scifac

 -- Function: gcfac (EXPR)
     gcfac is a factoring function that attempts to apply the same heuristics which scientists apply in trying to make expressions simpler.  gcfac is limited to monomial-type factoring.  For a sum, gcfac does the following:

      1. Factors over the integers.

      2. Factors out the largest powers of terms occurring as coefficients, regardless of the complexity of the terms.

      3. Uses (1) and (2) in factoring adjacent pairs of terms.

      4. Repeatedly and recursively applies these techniques until the expression no longer changes.

     Item (3) does not necessarily do an optimal job of pairwise factoring because of the combinatorially-difficult nature of finding which of all possible rearrangements of the pairs yields the most compact pair-factored result.

     load ("scifac") loads this function. demo ("scifac") shows a demonstration of this function.

     Categories: Package scifac Expressions