## `simplify` -- simplify an expression

#### Introduction

`simplify``(f)` tries to simplify the expression `f` by applying term rewriting rules.

`simplify``(f, target)` restricts the simplification to term rewriting rules applicable to the target function(s).

#### Call(s)

`simplify(f <, target>)`
`simplify(l <, target>)`

#### Parameters

`f` | - | an arithmetical expression
`l` | - | a set, a list, an array, or a polynomial of type `DOM_POLY`

#### Options

`target` | - | one of the identifiers `cos`, `sin`, `exp`, `ln`, `sqrt`, logic, or relation

#### Returns

an object of the same type as the input object `f` or `l`, respectively.

### Overloadable:

`f`, `l`

#### Side Effects

Without a target option, `simplify` reacts to properties of identifiers.

#### Further Documentation

Chapter ``Manipulating Expressions'' of the Tutorial.

#### Related Functions

`collect`, `combine`, `expand`, `factor`, `match`, `normal`, `radsimp`, `rectform`, `rewrite`

#### Details

- In a call without a target option, first a simplification of the expression ``as a whole'' is tried. This includes rewriting of products of trigonometric and exponential terms. Next, `simplify` is recursively applied to the operands of the expression. In this process, the `"simplify"` methods of the special functions contained in the expression are called.
- The call `simplify(`f`)` implies all simplifications that can be achieved with the targets `sin`, `cos`, `exp`, and `ln`.
- The call `simplify(`f, sqrt`)` is equivalent to `radsimp``(f)`. With this option, constant radical expressions are simplified.
- In the call `simplify(`l <, target>`)`, simplification is applied to the operands of the object `l`.

#### Option: target

- With the targets `sin`, `cos`, `exp`, and `ln`, only specific simplifications such as rewriting of products of trigonometric or exponential terms occur.
- The option `sqrt` invokes `radsimp`, i.e., simplification of constant radicals occur. See `radsimp` for details.
- With the option logic, rules of Boolean algebra are applied to Boolean expressions; the property mechanism it not used to decide the truth of the atoms.
- The option relation is obsolete now, since arithmetical operations for equations and inequalities are now available in MuPAD. It is still available for compatibility reasons, but will be removed in future versions.

#### Example 1

`simplify` tries to simplify algebraic expressions:

    >> simplify(exp(x)-exp(x/2)^2)

                                         0

    >> f := sin(x)^2 + cos(x)^2 + (exp(x) - 1)/(exp(x/2) + 1):
       simplify(f)

                                        / x \
                                     exp| - |
                                        \ 2 /

Only special simplifications occur if special target functions are specified:

    >> simplify(f, sin)

                                             / x \
                                 exp(x) + exp| - |
                                             \ 2 /
                                 -----------------
                                      / x \
                                   exp| - | + 1
                                      \ 2 /

    >> simplify(f, exp)

                               2         2      / x \
                         cos(x)  + sin(x)  + exp| - | - 1
                                                \ 2 /

    >> delete f:

#### Example 2

The option `sqrt` serves for simplifying radicals:

    >> simplify(sqrt(4 + 2*sqrt(3)), sqrt)

                                      1/2
                                     3    + 1

    >> x := 1/2 + sqrt(23/108):
       y := x^(1/3) + 1/3/x^(1/3):
       z := y^3 - y

          /                             /  1/2   1/2       \1/3 \3
          |             1               | 3    23          |    |
          | ------------------------- + | ---------- + 1/2 |    |  -
          |   /  1/2   1/2       \1/3   \     18           /    |
          |   | 3    23          |                              |
          | 3 | ---------- + 1/2 |                              |
          \   \     18           /                              /

             /  1/2   1/2       \1/3
             | 3    23          |                  1
             | ---------- + 1/2 |    - -------------------------
             \     18           /        /  1/2   1/2       \1/3
                                         | 3    23          |
                                       3 | ---------- + 1/2 |
                                         \     18           /

    >> simplify(z, sqrt)

                                         1

    >> delete x, y, z:

#### Example 3

The option logic serves for simplifying Boolean expressions:

    >> simplify((a and b) or (a and (not b)), logic)

                                         a

#### Example 4

User-defined functions can have `"simplify"` attributes. For example, suppose we know that f is an additive function (but we do not know more about f). Hence we cannot compute the function value of f at any point except zero, but we can tell MuPAD to use the additivity:

    >> f := funcenv( x -> if iszero(x) then 0 else procname(x) end):
       f::simplify := proc(F)
                        local argument;
                        begin
                          argument := op(F,1);
                          if type(argument) = "_plus" then
                            map(argument, f)
                          else
                            F
                          end
                        end:

    >> f(x + 3*y) - f(3*y) = simplify(f(x + 3*y) - f(3*y))

                            f(x + 3 y) - f(3 y) = f(x)

We could still refine the `"simplify"` attribute of `f` such that it also turns `f(3*y)` into `3*f(y)`. However, it is certainly a matter of taste whether f(x)+f(y) is really simpler than f(x+y). The reverse rule (rewriting f(x)+f(y) as f(x+y)) is not context-free and cannot be implemented in a `"simplify"` attribute.

#### Changes

- no changes

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000