### 87.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 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 ·