simplification-pkg (Maxima 5.43.2 Manual)

Next: solve_rec-pkg, Previous: simplex-pkg, Up: Top [Contents][Index]

## 82 simplification

Next: Package absimp, Previous: simplification-pkg, Up: simplification-pkg [Contents][Index]

### 82.1 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.

Next: Package facexp, Previous: Introduction to simplification, Up: simplification-pkg [Contents][Index]

### 82.2 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

Next: Package functs, Previous: Package absimp, Up: simplification-pkg [Contents][Index]

### 82.3 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 recusive 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

Next: Package ineq, Previous: Package facexp, Up: simplification-pkg [Contents][Index]

### 82.4 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

Next: Package rducon, Previous: Package functs, Up: simplification-pkg [Contents][Index]

### 82.5 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

Next: Package scifac, Previous: Package ineq, Up: simplification-pkg [Contents][Index]

### 82.6 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

Next: Package sqdnst, Previous: Package rducon, Up: simplification-pkg [Contents][Index]

### 82.7 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

Previous: Package scifac, Up: simplification-pkg [Contents][Index]

### 82.8 Package sqdnst

Function: sqrtdenest (expr)

  Denests `sqrt` of simple, numerical, binomial surds, where possible. E.g.

      (%i1) load ("sqdnst")$

      (%i2) sqrt(sqrt(3)/2+1)/sqrt(11*sqrt(2)-12);
                                   sqrt(3)
                              sqrt(------- + 1)
                                      2
      (%o2)                 ---------------------
                            sqrt(11 sqrt(2) - 12)

      (%i3) sqrtdenest(%);
                                 sqrt(3)   1
                                 ------- + -
                                    2      2
      (%o3)                     -------------
                                   1/4    3/4
                                3 2    - 2

  Sometimes it helps to apply `sqrtdenest` more than once, on such as `(19601-13860 sqrt(2))^(7/4)`.

  `load ("sqdnst")` loads this function.

  Categories: Expressions Share packages Package sqdnst

Previous: Package scifac, Up: simplification-pkg [Contents][Index]