## `limit` -- compute a limit

#### Introduction

`limit``(f, x = x0)` computes the bidirectional limit lim(f(x), x = x0).

`limit``(f, x = x0, Left)` computes the one-sided limit lim(f(x), x = x0-).

`limit``(f, x = x0, Right)` computes the one-sided limit lim(f(x), x = x0+).

#### Call(s)

`limit(f, x <= x0> <, dir>)`

#### Parameters

`f` | - | an arithmetical expression representing a function in `x`
`x` | - | an identifier
`x0` | - | the limit point: an arithmetical expression, possibly `infinity` or `-infinity`

#### Options

``dir`` | - | either Left or Right. This controls the direction of the limit computation.

#### Returns

an arithmetical expression, an interval of type `Dom::Interval`, an expression of type `"limit"`, or `FAIL`.

#### Side Effects

The function is sensitive to the environment variable `ORDER`, which determines the default number of terms in series computations (see `series` and example 6 below).

Properties of identifiers set by `assume` are taken into account.

### Overloadable:

`f`

#### Related Functions

`asympt`, `diff`, `discont`, `int`, `O`, `series`, `taylor`

#### Details

- `limit``(f, x = x0)` computes the bidirectional limit of `f` when `x` tends to `x0` on the real axis. The limit point `x0` may be omitted, in which case `limit` assumes `x0 = 0`.

  If the limit point `x0` is infinity or -infinity, then the limit is taken from the left to infinity or from the right to -infinity, respectively.

  If the left and right limits are different, then `undefined` is returned; see example 2.

- `limit``(f, x = x0, Left)` returns the limit when `x` tends to `x0` from the left. `limit``(f, x = x0, Right)` returns the limit when `x` tends to `x0` from the right. See example 2.

- If the limit does not exist mathematically, but the system can assert that the function `f` is bounded when `x` approaches `x0`, then a bounding interval, of type `Dom::Interval`, for `f(x)` in a sufficiently small neighborhood of `x0` is returned. This may happen, e.g., if `f` oscillates infinitesimally fast in the neighborhood of `x0`; see example 4. The boundaries are the limes inferior and the limes superior of `f` for x -> x0.

- If the limit cannot be computed, then the system returns a symbolic `limit` call (see example 3).

- If `f` contains parameters, then `limit` reacts to properties of those parameters set by `assume`; see example 5. If the limit cannot be computed without additional assumptions about the parameters, then `limit` indicates this by a warning.

- Internally, `limit` tries to determine the limit from a series expansion of `f` around `x = x0` computed via `series`. If the number of terms in the series expansion is too small to compute the limit, then `limit` returns `FAIL`. In such a case, it may be necessary to increase the value of the environment variable `ORDER` in order to find the limit (see example 6).

#### Example 1

The following command computes lim( (1-cos(x)/x^2),x=0 ):

    >> limit((1 - cos(x))/x^2, x)

                                        1/2

A possible definition of e is given by the limit of the sequence (1+1/n)^n for n->infinity:

    >> limit((1 + 1/n)^n, n = infinity)

                                      exp(1)

Here is a more complex example:

    >> limit(
         (exp(x*exp(-x)/(exp(-x) + exp(-2*x^2/(x+1)))) - exp(x))/x,
         x = infinity
       )

                                      -exp(2)

#### Example 2

The bidirectional limit of f(x)=1/x for x -> 0 does not exist:

    >> limit(1/x, x = 0)

                                     undefined

You can compute the one-sided limits from the left and from the right by passing the options Left and Right, respectively:

    >> limit(1/x, x = 0, Left),
       limit(1/x, x = 0, Right)

                                -infinity, infinity

#### Example 3

If `limit` is not able to compute the limit, then a symbolic `limit` call is returned:

    >> delete f: limit(f(x), x = infinity)

                             limit(f(x), x = infinity)

#### Example 4

The function sin(x) oscillates for x -> infinity. The limes inferior and the limes superior are -1 and 1, respectively:

    >> limit(sin(x), x = infinity)

                                      [-1, 1]

In fact, for x -> infinity the function `f=sin(x)` assumes every value in the returned interval infinitely often. This need not be the case in general.

#### Example 5

`limit` is not able to compute the limit of x^n for x -> infinity without additional information about the parameter n:

    >> delete n: limit(x^n, x = infinity)

          Warning: cannot determine sign of n [stdlib::limit::limitMRV]

                                     n
                              limit(x , x = infinity)

However, for n > 0 the limit exists and equals infinity. We use `assume` to achieve this:

    >> assume(n > 0): limit(x^n, x = infinity)

                                     infinity

Similarly, the limit is zero for n < 0:

    >> assume(n < 0): limit(x^n, x = infinity)

                                         0

#### Example 6

It may be necessary to increase the value of the environment variable `ORDER` in order to find the limit, as in the following example:

    >> limit((sin(tan(x)) - tan(sin(x)))/x^7, x = 0)

          Warning: ORDER seems to be not big enough for series \
          computation [stdlib::limit::lterm]

                                       FAIL

    >> ORDER := 8: limit((sin(tan(x)) - tan(sin(x)))/x^7, x)

                                       -1/30

#### Background

- If a limit cannot be computed, then `limit` issues a warning with a possible reason, as shown in examples 5 and 6. You may want to suppress these warnings when you call `limit` from within your own procedures. You can control this by means of the procedure `stdlib::limit::printWarnings`.

  The calls `stdlib::limit::printWarnings(TRUE)` and `stdlib::limit::printWarnings(FALSE)` switch the warnings that `limit` issues on and off, respectively, and return the previous setting. The command `stdlib::limit::printWarnings()` returns the current setting, which is `TRUE` by default.

- `limit` first tries a series computation to determine the limit. If this fails, then an algorithm based on the thesis of Dominik Gruntz: ``On Computing Limits in a Symbolic Manipulation System'', Swiss Federal Institute of Technology, Zurich, Switzerland, 1995, is used.

#### Changes

- `limit` may return an interval of type `Dom::Interval`.

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