## `maprat` -- apply a function to the ``rationalization'' of an expression

#### Introduction

`maprat``(object, f)` applies the function `f` to the ``rationalized'' object.

#### Call(s)

`maprat(object, f <, inspect <, stop>>)`

#### Parameters

`object` | - | an arithmetical expression, or a sequence, or a set, or a list of such expressions
`f` | - | a procedure or a functional expression
`inspect, stop` | - | sets of types or procedures

#### Returns

an object returned by the function `f`.

#### Related Functions

`map`, `rationalize`

#### Details

- `maprat``(object, f, inspect, stop)` calls `rationalize``(object, inspect, stop)` to generate a rational expression in some ``temporary variables''. This rationalized expression is used as input to the function `f`. Finally, in the return value of `f`, the ``temporary variables'' introduced by `rationalize` are replaced by the original subexpressions in `object`.
- See the help page of `rationalize` for details and default values of the parameters `inspect` and `stop`.

#### Example 1

The function `partfrac` computes a partial fraction decomposition of rational expressions. It cannot be applied to general expressions:

    >> object := cos(x)/(cos(x)^2 - sin(x)^2): partfrac(object, x)

          Error: not a rational function [partfrac]

One may rationalize this expression to be able to apply `partfrac`:

    >> rat := rationalize(object)

                          D1
                       ---------, {D1 = cos(x), D2 = sin(x)}
                         2     2
                       D1  - D2

We compute the partial fraction decomposition of this rationalized expression and, finally, re-substitute the ``temporary variables'' `D1`, `D2`:

    >> part := partfrac(op(rat, 1), D1)

                                  1             1
                             ----------- - -----------
                             2 (D1 + D2)   2 (D2 - D1)

    >> subs(part, op(rat, 2))

                              1                     1
                     ------------------- - -------------------
                     2 (cos(x) + sin(x))   2 (sin(x) - cos(x))

`maprat` provides a shortcut. We define a function `f` that computes the partial fraction decomposition of its argument with respect to the first indeterminate found by `indets`:

    >> f := object -> partfrac(object, indets(object)[1]):

`maprat` applies this function after internal rationalization:

    >> maprat(object, f)

                              1                     1
                     ------------------- - -------------------
                     2 (cos(x) + sin(x))   2 (sin(x) - cos(x))

    >> delete object, rat, part, f:

#### Example 2

We apply the function `gcd` to two rationalized expressions. The first argument to `maprat` is a sequence of the two expressions `p`, `q`, which `gcd` takes as two parameters. Note the brackets around the sequence `p, q`:

    >> p := (x - sqrt(2))*(x^2 + sqrt(3)*x - 1):
       q := (x - sqrt(2))*(x - sqrt(3)):
       maprat((p, q), gcd)

                                      1/2
                                     2    - x

    >> delete p, q:

#### Changes

- no changes

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