% Copyright The Numerical Algorithms Group Limited 1991.
% Certain derivative-work portions Copyright (C) 1988 by Leslie Lamport.
% All rights reserved

% Title: Limits

%  Author: Richard Jenks, Clifton J. Williamson
%  Date created: 1 November 1989
%  Date last updated: 25 May 1990

\begin{page}{ExLimitBasic}{Computing Limits}
\beginscroll
To compute a limit, you must specify a functional expression,
a variable, and a limiting value for that variable.
For example, to compute the limit of (x**2 - 3*x + 2)/(x**2 - 1)
as x approaches 1, issue the following command:
\spadpaste{limit((x**2 - 3*x + 2)/(x**2 - 1),x = 1)}
% answer := -1/2
Since you have not specified a direction, \Language{} will attempt
to compute a two-sided limit. Sometimes the limit when approached from
the left is different from the limit from the right.
\downlink{Example}{ExLimitTwoSided}. In this case, you may
wish to ask for a one-sided limit.
\downlink{How.  }{ExLimitOneSided}
\endscroll
\autobuttons\end{page}

\begin{page}{ExLimitParameter}{Limits of Functions with Parameters}
\beginscroll
You may also take limits of functions with parameters. The limit
will be expressed in terms of those parameters.
Here's an example:
\spadpaste{limit(sinh(a*x)/tan(b*x),x = 0)}
% answer := a/b
\endscroll
\autobuttons\end{page}

\begin{page}{ExLimitOneSided}{One-sided Limits}
\beginscroll
If you have a function which is only defined on one side of a particular value,
you may wish to compute a one-sided limit.
For instance, the function \spad{log(x)} is only defined to the right of zero,
i.e. for \spad{x > 0}.
Thus, when computing limits of functions involving \spad{log(x)}, you probably
will want a 'right-hand' limit.
Here's an example:
\spadpaste{limit(x * log(x),x = 0,"right")}
% answer := 0
When you do not specify \spad{right} or \spad{left} as an optional fourth
argument, the function \spadfun{limit} will try to compute a two-sided limit.
In the above case, the limit from the left does not exist, as \Language{}
will indicate when you try to take a two-sided limit:
\spadpaste{limit(x * log(x),x = 0)}
% answer := [left = "failed",right = 0]
\endscroll
\autobuttons\end{page}

\begin{page}{ExLimitTwoSided}{Two-sided Limits}
\beginscroll
A function may be defined on both sides of a particular value, but will
tend to different limits as its variable tends to that value from the
left and from the right.
We can construct an example of this as follows:
Since { \em sqrt(y**2)} is simply the absolute value of \spad{y},
the function \spad{sqrt(y**2)/y}
is simply the sign (+1 or -1) of the real number \spad{y}.
Therefore, \spad{sqrt(y**2)/y = -1} for \spad{y < 0} and
\spad{sqrt(y**2)/y = +1} for \spad{y > 0}.
Watch what happens when we take the limit at \spad{y = 0}.
\spadpaste{limit(sqrt(y**2)/y,y = 0)}
% answer := [left = -1,right = 1]
The answer returned by \Language{} gives both a 'left-hand' and a 'right-hand'
limit.
Here's another example, this time using a more complicated function:
\spadpaste{limit(sqrt(1 - cos(t))/t,t = 0)}
% answer := [left = -sqrt(1/2),right = sqrt(1/2)]
\endscroll
\autobuttons\end{page}

\begin{page}{ExLimitInfinite}{Limits at Infinity}
\beginscroll
You can compute limits at infinity by passing either 'plus infinity'
or 'minus infinity' as the third argument of the function \spadfun{limit}.
To do this, use the constants \spad{\%plusInfinity} and \spad{\%minusInfinity}.
Here are two examples:
\spadpaste{limit(sqrt(3*x**2 + 1)/(5*x),x = \%plusInfinity)}
\spadpaste{limit(sqrt(3*x**2 + 1)/(5*x),x = \%minusInfinity)}
\endscroll
\autobuttons\end{page}

\begin{page}{ExLimitRealComplex}{Real Limits vs. Complex Limits}
\beginscroll
When you use the function \spadfun{limit}, you will be taking the limit of a real
function of a real variable.
For example, you can compute
\spadpaste{limit(z * sin(1/z),z = 0)}
\Language{} returns \spad{0} because as a function of a real variable
\spad{sin(1/z)} is always between \spad{-1} and \spad{1}, so \spad{z * sin(1/z)}
tends to \spad{0} as \spad{z} tends to \spad{0}.
However, as a function of a complex variable, \spad{sin(1/z)} is badly
behaved around \spad{0}
(one says that \spad{sin(1/z)} has an 'essential singularity' at \spad{z = 0}).
When viewed as a function of a complex variable, \spad{z * sin(1/z)}
does not approach any limit as \spad{z} tends to \spad{0} in the complex plane.
\Language{} indicates this when we call the function \spadfun{complexLimit}:
\spadpaste{complexLimit(z * sin(1/z),z = 0)}
\endscroll
\autobuttons\end{page}

\begin{page}{ExLimitComplexInfinite}{Complex Limits at Infinity}
\beginscroll
You may also take complex limits at infinity, i.e. limits of a function of
\spad{z} as \spad{z} approaches infinity on the Riemann sphere.
Use the symbol \spad{\%infinity} to denote `complex infinity'.
Also, to compute complex limits rather than real limits, use the
function \spadfun{complexLimit}.
Here is an example:
\spadpaste{complexLimit((2 + z)/(1 - z),z = \%infinity)}
In many cases, a limit of a real function of a real variable will exist
when the corresponding complex limit does not.
For example:
\spadpaste{limit(sin(x)/x,x = \%plusInfinity)}
\spadpaste{complexLimit(sin(x)/x,x = \%infinity)}
\endscroll
\autobuttons\end{page}

