This section explains the basics of the algorithm used for computing limits.
Most of the time the limit() function should just work. However it is still
useful to keep in mind how it is implemented in case something does not work
as expected.

First we define an ordering on functions. Suppose and are two
real-valued functions such that and
similarly . We shall say that dominates, written , if for all we have
.
We also say that and
are of the same comparability class if neither nor
and shall denote it as .

Note that whenever then
, and we shall use this to extend the definition of
to all functions which tend to or as .
Thus we declare that and .

It is easy to show the following examples:

.

From the above definition, it is possible to prove the following property:

Suppose , are functions of ,
and for
all . Let with .

Then .

For and as above we also have the following easy result:

for

for ,
where the sign is determined by the (eventual) sign of

.

Using these results yields the following strategy for computing
:

Find the set of most rapidly varying subexpressions (MRV set) of .
That is, from the set of all subexpressions of , find the elements that
are maximal under the relation .

Choose a function that is in the same comparability class as
the elements in the MRV set, such that .

Expand as a series in in such a way that the antecedents of
the above theorem are satisfied.

Apply the theorem and conclude the computation of
, possibly by recursively working on .

This exposition glossed over several details. Many are described in the file
gruntz.py, and all can be found in Gruntz’ very readable thesis. The most
important points that have not been explained are: