@menu
* Functions and Variables for Limits::
@end menu

@c -----------------------------------------------------------------------------
@node Functions and Variables for Limits,  , Limits, Limits
@section Functions and Variables for Limits
@c -----------------------------------------------------------------------------

@c -----------------------------------------------------------------------------
@anchor{lhospitallim}
@defvr {Option variable} lhospitallim
Default value: 4

@code{lhospitallim} is the maximum number of times L'Hospital's
rule is used in @mref{limit}.  This prevents infinite looping in cases like
@code{limit (cot(x)/csc(x), x, 0)}.

@opencatbox{Categories:}
@category{Limits}
@closecatbox
@end defvr

@c -----------------------------------------------------------------------------
@anchor{limit}
@deffn  {Function} limit @
@fname{limit} (@var{expr}, @var{x}, @var{val}, @var{dir}) @
@fname{limit} (@var{expr}, @var{x}, @var{val}) @
@fname{limit} (@var{expr})

Computes the limit of @var{expr} as the real variable @var{x} approaches the
value @var{val} from the direction @var{dir}.  @var{dir} may have the value
@code{plus} for a limit from above, @code{minus} for a limit from below, or
may be omitted (implying a two-sided limit is to be computed).

@code{limit} uses the following special symbols: @code{inf} (positive infinity)
and @mref{minf} (negative infinity).  On output it may also use @mref{und}
(undefined), @mref{ind} (indefinite but bounded) and @mref{infinity} (complex
infinity).

@code{infinity} (complex infinity) is returned when the limit of
the absolute value of the expression is positive infinity, but
the limit of the expression itself is not positive infinity or
negative infinity.  This includes cases where the limit of the
complex argument is a constant, as in @code{limit(log(x), x, minf)}, 
cases where the complex argument oscillates, as in
@code{limit((-2)^x, x, inf)}, and cases where the complex
argument is different for either side of a two-sided limit, as in
@code{limit(1/x, x, 0)} and @code{limit(log(x), x, 0)}.

@mref{lhospitallim} is the maximum number of times L'Hospital's rule
is used in @code{limit}.  This prevents infinite looping in cases like
@code{limit (cot(x)/csc(x), x, 0)}.

@mref{tlimswitch} when true will allow the @code{limit} command to use
Taylor series expansion when necessary.

@mref{limsubst} prevents @code{limit} from attempting substitutions on
unknown forms.  This is to avoid bugs like @code{limit (f(n)/f(n+1), n, inf)}
giving 1.  Setting @code{limsubst} to @code{true} will allow such
substitutions.

@code{limit} with one argument is often called upon to simplify constant
expressions, for example, @code{limit (inf-1)}.

@c MERGE EXAMPLES INTO THIS FILE
@code{example (limit)} displays some examples.

For the method see Wang, P., "Evaluation of Definite Integrals by Symbolic
Manipulation", Ph.D. thesis, MAC TR-92, October 1971.

@opencatbox{Categories:}
@category{Limits}
@closecatbox
@end deffn

@c -----------------------------------------------------------------------------
@anchor{limsubst}
@defvr {Option variable} limsubst
Default value: @code{false}

prevents @mref{limit} from attempting substitutions on unknown forms.  This is
to avoid bugs like @code{limit (f(n)/f(n+1), n, inf)} giving 1.  Setting
@code{limsubst} to @code{true} will allow such substitutions.

@opencatbox{Categories:}
@category{Limits}
@closecatbox
@end defvr

@c -----------------------------------------------------------------------------
@anchor{tlimit}
@deffn  {Function} tlimit @
@fname{tlimit} (@var{expr}, @var{x}, @var{val}, @var{dir}) @
@fname{tlimit} (@var{expr}, @var{x}, @var{val}) @
@fname{tlimit} (@var{expr})

Take the limit of the Taylor series expansion of @code{expr} in @code{x}
at @code{val} from direction @code{dir}.

@opencatbox{Categories:}
@category{Limits}
@closecatbox
@end deffn

@c -----------------------------------------------------------------------------
@anchor{tlimswitch}
@defvr {Option variable} tlimswitch
Default value: @code{true}

When @code{tlimswitch} is @code{true}, the @mref{limit} command will use a
Taylor series expansion if the limit of the input expression cannot be computed
directly.  This allows evaluation of limits such as
@code{limit(x/(x-1)-1/log(x),x,1,plus)}.  When @code{tlimswitch} is @code{false}
and the limit of input expression cannot be computed directly, @code{limit} will
return an unevaluated limit expression.

@opencatbox{Categories:}
@category{Limits}
@closecatbox
@end defvr

@c -----------------------------------------------------------------------------
@anchor{gruntz}
@deffn {Function} gruntz @
@fname{gruntz} (@var{expr}, @var{var}, @var{value}) @
@fname{gruntz} (@var{expr}, @var{var}, @var{value}, @var{direction})

Compute limit of expression @var{expr} with respect to variable @var{var} at @var{value}.
When @var{value} is not infinite (i.e., not @code{inf} or @code{minf}),
@var{direction} must be supplied,
either @code{plus} for a limit from above,
or @code{minus} for a limit from below.

If @code{gruntz} cannot find the limit,
an unevaluated expression @code{gruntz(...)} is returned.

@code{gruntz} implements the method described in the dissertation of
Dominik Gruntz, "On Computing Limits in a Symbolic Manipulation System"
(ETH Zurich, 1996).

The algorithm identifies the most rapidly varying subexpression,
replaces it with a new variable, rewrites the expression in terms
of the new variable, and then repeats.

The algorithm doesn't handle oscillating functions, so it can't do things like
@code{limit(sin(x)/x, x, inf)}.

To handle limits involving functions such as @code{gamma(x)} and @code{erf(x)},
the Gruntz algorithm requires them to be written in terms of asymptotic expansions,
which Maxima cannot currently do.

The Gruntz algorithm assumes that variables and expressions are real,
so, for example, it can't handle @code{limit((-2)^x, x, inf)}.

@code{gruntz} is one of the methods called from @code{limit}.

@opencatbox{Categories:}
@category{Limits}
@closecatbox

@end deffn
