## `rewrite` -- rewrite an expression

#### Introduction

`rewrite``(f, target)` transforms an expression `f` to a mathematically equivalent form, trying to express `f` in terms of the specified target function.

#### Call(s)

`rewrite(f, target)`

#### Parameters

`f` | - | an arithmetical expression
`target` | - | the target function to be used in the representation: one of `cot`, `coth`, `diff`, `exp`, `fact`, `gamma`, `heaviside`, `ln`, `piecewise`, `sign`, `sincos`, `sinhcosh`, `tan`, or `tanh`

#### Returns

an arithmetical expression.

### Overloadable:

`f`

#### Further Documentation

Chapter ``Manipulating Expressions'' of the Tutorial.

#### Related Functions

`collect`, `combine`, `expand`, `factor`, `normal`, `partfrac`, `rationalize`, `rectform`, `simplify`

#### Details

- The target indicates the function that is to be used in the desired representation. Unevaluated function calls in `f` are replaced by the target function if this is mathematically valid.
- With the target `exp`, all trigonometric and hyperbolic functions are rewritten in terms of `exp`. Further, the inverse functions as well as `arg` are rewritten in terms of `ln`.
- With the target sincos, the functions `tan`, `cot`, `exp`, `sinh`, `cosh`, `tanh`, and `coth` are rewritten in terms of `sin` and `cos`.
- With the target sinhcosh, the functions `exp`, `tanh`, `coth`, `sin`, `cos`, `tan`, and `cot` are rewritten in terms of `sinh` and `cosh`.

#### Example 1

This examples demonstrates the use of `rewrite`:

    >> rewrite(D(D(y))(x), diff)

                                 diff(y(x), x, x)

    >> rewrite(fact(n), gamma), rewrite(gamma(n), fact);

                             gamma(n + 1), fact(n - 1)

    >> rewrite(sign(x), heaviside), rewrite(heaviside(x), sign);

                                             sign(x)
                         2 heaviside(x) - 1, ------- + 1/2
                                                2

    >> rewrite(heaviside(x), piecewise)

             piecewise(1 if 0 < x, heaviside(0) if x = 0, -1 if x < 0)

#### Example 2

Trigonometric functions can be rewritten in terms of `exp`, `sin`, `cos` etc.:

    >> rewrite(tan(x), exp), rewrite(cot(x), sincos),
       rewrite(sin(x), tan)

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

    >> rewrite(arcsinh(x), ln)

                                         2     1/2
                                ln(x + (x  + 1)   )

#### Changes

- The targets `cot`, `coth`, `tanh`, and `piecewise` were added.

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