Go to the first, previous, next, last section, table of contents.

# Simplification

## Definitions for Simplification

When `asksign` is called, `askexp` is the expression `asksign` is testing.

At one time, it was possible for a user to inspect `askexp` by entering a Maxima break with control-A.

Function: askinteger (expr, integer)
Function: askinteger (expr, even)
Function: askinteger (expr, odd)

`askinteger (expr, integer)` attempts to determine from the `assume` database whether expr is an integer. `askinteger` prompts the user if it cannot tell otherwise, and attempt to install the information in the database if possible. `askinteger (expr)` is equivalent to `askinteger (expr, integer)`.

`askinteger (expr, even)` and `askinteger (expr, odd)` likewise attempt to determine if expr is an even integer or odd integer, respectively.

First attempts to determine whether the specified expression is positive, negative, or zero. If it cannot, it asks the user the necessary questions to complete its deduction. The user's answer is recorded in the data base for the duration of the current computation. The return value of `asksign` is one of `pos`, `neg`, or `zero`.

Function: demoivre (expr)
Option variable: demoivre

The function `demoivre (expr)` converts one expression without setting the global variable `demoivre`.

When the variable `demoivre` is `true`, complex exponentials are converted into equivalent expressions in terms of circular functions: `exp (a + b*%i)` simplifies to `%e^a * (cos(b) + %i*sin(b))` if `b` is free of `%i`. `a` and `b` are not expanded.

The default value of `demoivre` is `false`.

`exponentialize` converts circular and hyperbolic functions to exponential form. `demoivre` and `exponentialize` cannot both be true at the same time.

Option variable: domain
Default value: `real`

When `domain` is set to `complex`, `sqrt (x^2)` will remain `sqrt (x^2)` instead of returning `abs(x)`.

Function: expand (expr)
Function: expand (expr, p, n)
Expand expression expr. Products of sums and exponentiated sums are multiplied out, numerators of rational expressions which are sums are split into their respective terms, and multiplication (commutative and non-commutative) are distributed over addition at all levels of expr.

For polynomials one should usually use `ratexpand` which uses a more efficient algorithm.

`maxnegex` and `maxposex` control the maximum negative and positive exponents, respectively, which will expand.

`expand (expr, p, n)` expands expr, using p for `maxposex` and n for `maxnegex`. This is useful in order to expand part but not all of an expression.

`expon` - the exponent of the largest negative power which is automatically expanded (independent of calls to `expand`). For example if `expon` is 4 then `(x+1)^(-5)` will not be automatically expanded.

`expop` - the highest positive exponent which is automatically expanded. Thus `(x+1)^3`, when typed, will be automatically expanded only if `expop` is greater than or equal to 3. If it is desired to have `(x+1)^n` expanded where `n` is greater than `expop` then executing `expand ((x+1)^n)` will work only if `maxposex` is not less than `n`.

The `expand` flag used with `ev` causes expansion.

The file `simplification/facexp.mac' contains several related functions (in particular `facsum`, `factorfacsum` and `collectterms`, which are autoloaded) and variables (`nextlayerfactor` and `facsum_combine`) that provide the user with the ability to structure expressions by controlled expansion. Brief function descriptions are available in `simplification/facexp.usg'. A demo is available by doing `demo("facexp")`.

Function: expandwrt (expr, x_1, ..., x_n)
Expands expression `expr` with respect to the variables x_1, ..., x_n. All products involving the variables appear explicitly. The form returned will be free of products of sums of expressions that are not free of the variables. x_1, ..., x_n may be variables, operators, or expressions.

By default, denominators are not expanded, but this can be controlled by means of the switch `expandwrt_denom`.

This function is autoloaded from `simplification/stopex.mac'.

Option variable: expandwrt_denom
Default value: `false`

`expandwrt_denom` controls the treatment of rational expressions by `expandwrt`. If `true`, then both the numerator and denominator of the expression will be expanded according to the arguments of `expandwrt`, but if `expandwrt_denom` is `false`, then only the numerator will be expanded in that way.

Function: expandwrt_factored (expr, x_1, ..., x_n)
is similar to `expandwrt`, but treats expressions that are products somewhat differently. `expandwrt_factored` expands only on those factors of `expr` that contain the variables x_1, ..., x_n.

This function is autoloaded from `simplification/stopex.mac'.

Option variable: expon
Default value: 0

`expon` is the exponent of the largest negative power which is automatically expanded (independent of calls to `expand`). For example, if `expon` is 4 then `(x+1)^(-5)` will not be automatically expanded.

Function: exponentialize (expr)
Option variable: exponentialize

The function `exponentialize (expr)` converts circular and hyperbolic functions in expr to exponentials, without setting the global variable `exponentialize`.

When the variable `exponentialize` is `true`, all circular and hyperbolic functions are converted to exponential form. The default value is `false`.

`demoivre` converts complex exponentials into circular functions. `exponentialize` and `demoivre` cannot both be true at the same time.

Option variable: expop
Default value: 0

`expop` is the highest positive exponent which is automatically expanded. Thus `(x + 1)^3`, when typed, will be automatically expanded only if `expop` is greater than or equal to 3. If it is desired to have `(x + 1)^n` expanded where `n` is greater than `expop` then executing `expand ((x + 1)^n)` will work only if `maxposex` is not less than n.

Option variable: factlim
Default value: -1

`factlim` specifies the highest factorial which is automatically expanded. If it is -1 then all integers are expanded.

Function: intosum (expr)
Moves multiplicative factors outside a summation to inside. If the index is used in the outside expression, then the function tries to find a reasonable index, the same as it does for `sumcontract`. This is essentially the reverse idea of the `outative` property of summations, but note that it does not remove this property, it only bypasses it.

In some cases, a `scanmap (multthru, expr)` may be necessary before the `intosum`.

Declaration: lassociative
`declare (g, lassociative)` tells the Maxima simplifier that `g` is left-associative. E.g., `g (g (a, b), g (c, d))` will simplify to `g (g (g (a, b), c), d)`.

Declaration: linear
One of Maxima's operator properties. For univariate `f` so declared, "expansion" `f(x + y)` yields `f(x) + f(y)`, `f(a*x)` yields `a*f(x)` takes place where `a` is a "constant". For functions of two or more arguments, "linearity" is defined to be as in the case of `sum` or `integrate`, i.e., `f (a*x + b, x)` yields `a*f(x,x) + b*f(1,x)` for `a` and `b` free of `x`.

`linear` is equivalent to `additive` and `outative`. See also `opproperties`.

Declaration: mainvar
You may declare variables to be `mainvar`. The ordering scale for atoms is essentially: numbers < constants (e.g., `%e`, `%pi`) < scalars < other variables < mainvars. E.g., compare `expand ((X+Y)^4)` with `(declare (x, mainvar), expand ((x+y)^4))`. (Note: Care should be taken if you elect to use the above feature. E.g., if you subtract an expression in which `x` is a `mainvar` from one in which `x` isn't a `mainvar`, resimplification e.g. with `ev (expr, simp)` may be necessary if cancellation is to occur. Also, if you save an expression in which `x` is a `mainvar`, you probably should also save `x`.)

Option variable: maxapplydepth
Default value: 10000

`maxapplydepth` is the maximum depth to which `apply1` and `apply2` will delve.

Option variable: maxapplyheight
Default value: 10000

`maxapplyheight` is the maximum height to which `applyb1` will reach before giving up.

Option variable: maxnegex
Default value: 1000

`maxnegex` is the largest negative exponent which will be expanded by the `expand` command (see also `maxposex`).

Option variable: maxposex
Default value: 1000

`maxposex` is the largest exponent which will be expanded with the `expand` command (see also `maxnegex`).

Declaration: multiplicative
`declare (f, multiplicative)` tells the Maxima simplifier that `f` is multiplicative.

1. If `f` is univariate, whenever the simplifier encounters `f` applied to a product, `f` distributes over that product. E.g., `f(x*y)` simplifies to `f(x)*f(y)`.
2. If `f` is a function of 2 or more arguments, multiplicativity is defined as multiplicativity in the first argument to `f`, e.g., `f (g(x) * h(x), x)` simplifies to `f (g(x) ,x) * f (h(x), x)`.

This simplification does not occur when `f` is applied to expressions of the form `product (x[i], i, m, n)`.

Option variable: negdistrib
Default value: `true`

When `negdistrib` is `true`, -1 distributes over an expression. E.g., `-(x + y)` becomes `- y - x`. Setting it to `false` will allow `- (x + y)` to be displayed like that. This is sometimes useful but be very careful: like the `simp` flag, this is one flag you do not want to set to `false` as a matter of course or necessarily for other than local use in your Maxima.

Option variable: negsumdispflag
Default value: `true`

When `negsumdispflag` is `true`, `x - y` displays as `x - y` instead of as `- y + x`. Setting it to `false` causes the special check in display for the difference of two expressions to not be done. One application is that thus `a + %i*b` and `a - %i*b` may both be displayed the same way.

Special symbol: noeval
`noeval` suppresses the evaluation phase of `ev`. This is useful in conjunction with other switches and in causing expressions to be resimplified without being reevaluated.

Declaration: noun
`noun` is one of the options of the `declare` command. It makes a function so declared a "noun", meaning that it won't be evaluated automatically.

Option variable: noundisp
Default value: `false`

When `noundisp` is `true`, nouns display with a single quote. This switch is always `true` when displaying function definitions.

Special symbol: nouns
`nouns` is an `evflag`. When used as an option to the `ev` command, `nouns` converts all "noun" forms occurring in the expression being `ev`'d to "verbs", i.e., evaluates them. See also `noun`, `nounify`, `verb`, and `verbify`.

Special symbol: numer
`numer` causes some mathematical functions (including exponentiation) with numerical arguments to be evaluated in floating point. It causes variables in `expr` which have been given numervals to be replaced by their values. It also sets the `float` switch on.

Function: numerval (x_1, expr_1, ..., var_n, expr_n)
Declares the variables `x_1`, ..., x_n to have numeric values equal to `expr_1`, ..., `expr_n`. The numeric value is evaluated and substituted for the variable in any expressions in which the variable occurs if the `numer` flag is `true`. See also `ev`.

The expressions `expr_1`, ..., `expr_n` can be any expressions, not necessarily numeric.

System variable: opproperties

`opproperties` is the list of the special operator properties recognized by the Maxima simplifier: `linear`, `additive`, `multiplicative`, `outative`, `evenfun`, `oddfun`, `commutative`, `symmetric`, `antisymmetric`, `nary`, `lassociative`, `rassociative`.

Option variable: opsubst
Default value: `true`

When `opsubst` is `false`, `subst` does not attempt to substitute into the operator of an expression. E.g., `(opsubst: false, subst (x^2, r, r+r))` will work.

Declaration: outative
`declare (f, outative)` tells the Maxima simplifier that constant factors in the argument of `f` can be pulled out.

1. If `f` is univariate, whenever the simplifier encounters `f` applied to a product, that product will be partitioned into factors that are constant and factors that are not and the constant factors will be pulled out. E.g., `f(a*x)` will simplify to `a*f(x)` where `a` is a constant. Non-atomic constant factors will not be pulled out.
2. If `f` is a function of 2 or more arguments, outativity is defined as in the case of `sum` or `integrate`, i.e., `f (a*g(x), x)` will simplify to `a * f(g(x), x)` for `a` free of `x`.

`sum`, `integrate`, and `limit` are all `outative`.

Declaration: posfun
`declare (f, posfun)` declares `f` to be a positive function. `is (f(x) > 0)` yields `true`.

Option variable: prodhack
Default value: `false`

When `prodhack` is `true`, the identity `product (f(i), i, a, b) = 1/product (f(i), i, b+1, a-1)` is applied if `a` is greater than `b`. For example, `product (f(i), i, 3, 1)` yields `1/f(2)`.

Simplifies expr, which can contain logs, exponentials, and radicals, by converting it into a form which is canonical over a large class of expressions and a given ordering of variables; that is, all functionally equivalent forms are mapped into a unique form. For a somewhat larger class of expressions, `radcan` produces a regular form. Two equivalent expressions in this class do not necessarily have the same appearance, but their difference can be simplified by `radcan` to zero.

For some expressions `radcan` is quite time consuming. This is the cost of exploring certain relationships among the components of the expression for simplifications based on factoring and partial-fraction expansions of exponents.

When `%e_to_numlog` is `true`, `%e^(r*log(expr))` simplifies to `expr^r` if `r` is a rational number.

When `radexpand` is `false`, certain transformations are inhibited. `radcan (sqrt (1-x))` remains `sqrt (1-x)` and is not simplified to `%i sqrt (x-1)`. `radcan (sqrt (x^2 - 2*x + 11))` remains `sqrt (x^2 - 2*x + 1)` and is not simplified to `x - 1`.

`example (radcan)` displays some examples.

Default value: `true`

`radexpand` controls some simplifications of radicals.

When `radexpand` is `all`, causes nth roots of factors of a product which are powers of n to be pulled outside of the radical. E.g. if `radexpand` is `all`, `sqrt (16*x^2)` simplifies to `4*x`.

More particularly, consider `sqrt (x^2)`.

• If `radexpand` is `all` or `assume (x > 0)` has been executed, `sqrt(x^2)` simplifies to `x`.
• If `radexpand` is `true` and `domain` is `real` (its default), `sqrt(x^2)` simplifies to `abs(x)`.
• If `radexpand` is `false`, or `radexpand` is `true` and `domain` is `complex`, `sqrt(x^2)` is not simplified.

Note that `domain` only matters when `radexpand` is `true`.

Default value: `false`

`radsubstflag`, if `true`, permits `ratsubst` to make substitutions such as `u` for `sqrt (x)` in `x`.

Declaration: rassociative
`declare (g, rassociative)` tells the Maxima simplifier that `g` is right-associative. E.g., `g(g(a, b), g(c, d))` simplifies to `g(a, g(b, g(c, d)))`.

Function: scsimp (expr, rule_1, ..., rule_n)
Sequential Comparative Simplification (method due to Stoute). `scsimp` attempts to simplify expr according to the rules rule_1, ..., rule_n. If a smaller expression is obtained, the process repeats. Otherwise after all simplifications are tried, it returns the original answer.

`example (scsimp)` displays some examples.

Option variable: simpsum
Default value: `false`

When `simpsum` is `true`, the result of a `sum` is simplified. This simplification may sometimes be able to produce a closed form. If `simpsum` is `false` or if the quoted form `'sum` is used, the value is a sum noun form which is a representation of the sigma notation used in mathematics.

Function: sumcontract (expr)
Combines all sums of an addition that have upper and lower bounds that differ by constants. The result is an expression containing one summation for each set of such summations added to all appropriate extra terms that had to be extracted to form this sum. `sumcontract` combines all compatible sums and uses one of the indices from one of the sums if it can, and then try to form a reasonable index if it cannot use any supplied.

It may be necessary to do an `intosum (expr)` before the `sumcontract`.

Option variable: sumexpand
Default value: `false`

When `sumexpand` is `true`, products of sums and exponentiated sums simplify to nested sums.

See also `cauchysum`.

Examples:

```(%i1) sumexpand: true\$
(%i2) sum (f (i), i, 0, m) * sum (g (j), j, 0, n);
m      n
====   ====
\      \
(%o2)                >      >     f(i1) g(i2)
/      /
====   ====
i1 = 0 i2 = 0
(%i3) sum (f (i), i, 0, m)^2;
m      m
====   ====
\      \
(%o3)                >      >     f(i3) f(i4)
/      /
====   ====
i3 = 0 i4 = 0
```

Option variable: sumhack
Default value: `false`

When `sumhack` is `true`, the identity `sum (f(i), i, a, b) = - sum (f(i), i, b+1, a-1)` is applied if `a` is greater than `b`. For example, `(sumhack: true, sum (f(i), i, 3, 1))` yields `-f(2)`.

Option variable: sumsplitfact
Default value: `true`

When `sumsplitfact` is `false`, `minfactorial` is applied after a `factcomb`.

Declaration: symmetric
`declare (h, symmetric)` tells the Maxima simplifier that `h` is a symmetric function. E.g., `h (x, z, y)` simplifies to `h (x, y, z)`.

`commutative` is synonymous with `symmetric`.

Function: unknown (expr)
Returns `true` if and only if expr contains an operator or function not recognized by the Maxima simplifier.

Go to the first, previous, next, last section, table of contents.