# How to evaluate the $0/0$ type limit in Mathematica?

When I use Limit to evaluate the limit

\begin{align}\lim_{k \to 0} \frac{ (k+2)(\alpha^2 - \sqrt{\alpha^4 + k}) + k}{\alpha^2 - \sqrt{\alpha^4 + k} + 2 k}\end{align}

((k + 2) (α^2 - Sqrt[α^4 + k]) + k)/(α^2 - Sqrt[α^4 + k] + 2 k)


(α and k are assumed to be real)

Limit gives the answer: 2.

However, I believe the correct answer is

(2 (-1 + α^2))/(-1 + 4 α^2)


So, when should I trust the answer of Limit?

• Indeed the correct limit for real $\alpha$ is the one you said.
– acl
Apr 1, 2012 at 15:08
• @acl he's made the assumption that $\sqrt{\alpha^4}=\alpha^2$ which ignores the existence of the negative root. This jumps the branch cut. Apr 1, 2012 at 15:49
• This is a long standing weakness in Limit for cases where it cannot discern parametrized branchcut behavior. It is, coincidently, under current investigation. But the outlook does not look terribly promising at the moment. Apr 2, 2012 at 16:39

Edit

The answer is "ambiguous" because you have two parameters, $\alpha$ and $k$, and in this case the limit depends on the value of $\alpha$. What you can try is the following:

f[k_, α_] := ((k + 2) (α^2 - Sqrt[α^4 + k]) + k)/(α^2 - Sqrt[α^4 + k] + 2 k)
Simplify[Limit[f[k, α^(1/4)], k -> 0] /. α -> α^4, α ∈ Reals]


$\frac{2 \left(\alpha ^2-1\right)}{4 \alpha ^2-1}$

What I did is to remove all powers of $\alpha$ from under the square roots, so that the $k\to 0$ limit makes them look like $\sqrt{k+\alpha}\to \sqrt{\alpha}$ which manifestly cancels with the already present $\sqrt{\alpha}$ terms. At the end, I replace $\alpha$ by $\alpha^4$ to return to the original definition.

What follows below are the steps that led me to finally settle on the above approach. The upshot is that we have to avoid handing Mathematica expressions such as $\sqrt{\alpha^4}-\alpha^2 = 0$ because it doesn't simplify them at an early enough stage in the evaluation, even when the domain is real.

First assume simply that $\alpha$ is real:

Assuming[α ∈ Reals, Limit[f[k, α], k -> 0]]


2

Now say explicitly that $\alpha>0$:

Assuming[α > 0, Limit[f[k, α], k -> 0]]


$\frac{2 \left(\alpha ^2-1\right)}{4 \alpha ^2-1}$

The behavior can be illustrated with a contour plot of f[k, α] around {0,0}:

ContourPlot[f[k, α], {k, 0, .1}, {α, -.3, .3}, FrameLabel -> {"k", "α"},
PlotRange -> {1, 5}, ContourLabels -> True] In the plane of $k, \alpha$, Mathematica acts as if it preferred to choose the "easiest" approach to the $k=0$ axis by taking $\alpha = 0$ in the first case. But what it should have done is to return the more general result, or a ConditionalExpression (not necessary in this particular case because the general result goes smoothly to 2 for $\alpha\to0$).

The first result is a bug, I would say: Since $\alpha$ is a constant while the limit is taken, setting it to zero when it's allowed to be any real number is just too restrictive. This preliminary conclusion that it's a bug is strengthened below where I try to understand why it may be happening, and whether the function f[k, α] can be made to look less pathological before doing the limit.

Work-around

From the comments in the other answers, it is clear that Mathematica doesn't use the assumption of real variables at a sufficiently early stage in the calculation. You can even see that without taking any limit:

f[0, α]


2

The reason for this result is that it can't see the simplification $\sqrt{\alpha^4}-\alpha^2 = 0$ which is always true for real $\alpha$. It knows this fact, but isn't using it. To check this, we can do

Refine[0 == (Sqrt[α^4] - α^2), α ∈ Reals]


True

If this guess about the bug is right, then it's basically a problem of the order of two non-commuting limits. In addition to doing $k\to0$, the assumption of real $\alpha$ amounts to taking the limit $\Im(\alpha)\to 0$ (zero imaginary part). If you do the latter limit last, it gives $2$, but we are interested in the opposite order of limits.

To avoid this problem, one can eliminate the variable $k$ in terms of a new variable that gets rid of the square root:

First transform to variables $x=\sqrt{k}$ and $y=\alpha^2$ to end up with at most squares:

Clear[g];
g[x, y] = Simplify[f[x^2, Sqrt[y]]]


$\frac{\left(x^2+2\right)\left(y-\sqrt{x^2+y^2}\right)+x^2}{-\sqrt{x^2+y^2}+2x^2+y}$

Next, define a third new variable $z\equiv y-\sqrt{x^2+y^2}$ that incorporates the unwanted square root,

newg = g/.First@Solve[Eliminate[{g == g[x, y], z == -Sqrt[x^2 + y^2] + y}, x],g]


$\frac{2 y z+2 y-z^2-z-2}{4 y-2 z-1}$

Finally, observe that the limit $k\to0$ is the same as the limit $z\to0$ provided that we make the assumption $\lim_{x\to 0}(y-\sqrt{x^2+y^2})=0$ (which is true because $y\ge0$). Therefore, we can take the desired limit by setting

newg /. z -> 0


$\frac{2 y-2}{4 y-1}$

This is the correct limit if we reinstate $y=\alpha^2$. Note that I didn't have to use Limit at all because the function is well-behaved in this simplified form.

• You already had my +1, but the most recent edit is very clever. It works even if you remove the α ∈ Reals condition on Simplify. Apr 2, 2012 at 15:38
• @rcollyer Thanks, it's OK to remove it, but I'll leave the condition in because it gets me the form I ultimately wanted.
– Jens
Apr 2, 2012 at 15:55

The answer does in fact seem to be 2. This can be seen by expanding over the $k + 2$ term in the numerator

\begin{align}\lim_{k \to 0} \frac{ (k+2)(\alpha^2 - \sqrt{\alpha^4 + k}) + k}{\alpha^2 - \sqrt{\alpha^4 + k} + 2 k} = &\lim_{k \to 0} \frac{k (\alpha^2 - \sqrt{\alpha^4 + k})}{\alpha^2 - \sqrt{\alpha^4 + k} + 2 k} \\ &+ \lim_{k \to 0} \frac{2 (\alpha^2 - \sqrt{\alpha^4 + k})}{\alpha^2 - \sqrt{\alpha^4 + k} + 2 k} \\ &+ \lim_{k \to 0}\frac{k}{\alpha^2 - \sqrt{\alpha^4 + k} + 2 k} \\ =&\lim_{k \to 0} \frac{k (\alpha^2 - \sqrt{\alpha^4 + k})}{\alpha^2 - \sqrt{\alpha^4 + k} + 2 k} + 2 +0. \end{align}

A cursory inspection reveals that the first term must go to zero as $k \to 0$ like the third term did. This is in contrast to what you get, though, when you break the original fraction into separate terms:

frac = ((k + 2) (α^2 - Sqrt[α^4 + k]) + k)/(α^2 - Sqrt[α^4 + k] + 2 k) // Apart


$\frac{1}{4} \left(2 \alpha ^2+1\right)-\frac{\sqrt{\alpha ^4+k}}{2}+\frac{2 \alpha ^2 \sqrt{\alpha ^4+k}}{4 \alpha ^2+4 k-1}+\frac{-8 \alpha ^4+18 \alpha ^2-7}{4 \left(4 \alpha ^2+4 k-1\right)}-\frac{7 \sqrt{\alpha ^4+k}}{2 \left(4 \alpha ^2+4 k-1\right)}$

with a limit

lim = Limit[frac, k -> 0]


$\frac{3 \sqrt{\alpha ^4}-5 \alpha ^2+2}{1-4 \alpha ^2}.$

The difficulty in interpretation here lies with $\sqrt{\alpha^4}$. If you specify that α ∈ Reals,

Simplify[lim, α ∈ Reals]


you get what you found

$\frac{2 \left(\alpha ^2-1\right)}{4 \alpha ^2-1}.$

However, this is choosing the positive branch, but $\sqrt{a^2} = \pm a$, as seen by

lim /. # & /@ (Sqrt[α^4] -> # & /@ {α^2, -α^2}) //  Simplify


{$\frac{2 \left(\alpha ^2-1\right)}{4 \alpha ^2-1}$, $2$}.

The problem here is the assumption as it implies that the positive root is taken, and hence jumps to the other branch. My initial analysis, however, does not make any assumptions about which branch is used by not expanding the square root.

• The OP mentioned $\alpha$ is real... Apr 1, 2012 at 15:41
• @SjoerdC.deVries Yes, but the reality of α does not play a role in the initial analysis, and regardless of whether or not α is real, there's still the negative root to contend with. The bug here is that Sqrt[q^2] == |q|, not Sqrt[q^2] == ±|q| as it is supposed to be, causing the solution to jump branches. Apr 1, 2012 at 15:47
• In your first formula, if you take the positive root then the third term converges not to 0, but to $\frac{1}{2-1/(2a^2)}$. Apr 1, 2012 at 16:00
• @celtschk to be clear, you're talking about $$\lim_{k \to 0}\frac{k}{\alpha^2 - \sqrt{\alpha^4 + k} + 2 k},$$ correct? If so, then I don't see how it converges to $$\frac{1}{2 - 1/(2 \alpha^2)}.$$ Would you give more details, please? Apr 1, 2012 at 16:04
• @rcollyer There is no problem with branches when the variables are real, because by definition of the square root: Assuming[a [Element] Reals, Simplify[Sqrt[a^4]]] i.e., the square root is always the positive root.
– Jens
Apr 1, 2012 at 16:16

Never trust anything or anyone with limits, indeed. Let's look at some plots for a variety of values of $\alpha$:

Plot[Table[((k + 2) (α^2 - Sqrt[α^4 + k]) + k)/(α^2 - Sqrt[α^4 + k] + 2 k),
{α, -10, 10, 1.5}] // Evaluate, {k, -2, 2}] Applying L'Hospital's rule we get:

(k*(α^2 - Sqrt[α^4 + k]) + k)/(α^2 - Sqrt[α^4 + k] + 2*k) //
(D[Numerator[#1], k]/D[Denominator[#1], k])& // Simplify


$\frac{2 \left(\alpha ^2-1\right)}{4 \alpha ^2-1}$

Indeed, calculating the limit for various of $\alpha$ and comparing it to the above result we get:

lim =
ListPlot[
Limit[
Table[{α, ((k + 2) (α^2 -
Sqrt[α^4 + k]) + k)/(α^2 -
Sqrt[α^4 + k] + 2 k)},
{α, .001, 3, .1}
],
k -> 0
], PlotRange -> {-3, 3}
];

Show[
lim,
Plot[(2 (-1 + α^2))/(-1 + 4 α^2), {α, 0, 3},
PlotRange -> {-3, 3}
]
] With assumptions about $a$:

Assuming[α ∈ Reals,
Limit[((k + 2) (α^2 - Sqrt[α^4 + k]) + k)/(α^2 -
Sqrt[α^4 + k] + 2 k) // Simplify, k -> 0]]

(*
==> 2
*)

Assuming[α > 0,
Limit[((k + 2) (α^2 - Sqrt[α^4 + k]) + k)/(α^2 -
Sqrt[α^4 + k] + 2 k) // Simplify, k -> 0]]

(*
==> (2 (-1 + α^2))/(-1 + 4 α^2)
*)


Same for α < 0.

• Not a bug. There's a simplification that I'm about to post that will make it clear(er). Apr 1, 2012 at 14:22
• Show[Plot[(2 (-1 + [Alpha]^2))/(-1 + 4 [Alpha]^2), {[Alpha], .01, .5}], ListPlot[Limit[ Table[{[Alpha], ((k + 2) ([Alpha]^2 - Sqrt[[Alpha]^4 + k]) + k)/([Alpha]^2 - Sqrt[[Alpha]^4 + k] + 2 k)}, {[Alpha], .01, .5, .01}], k -> 0]]] Apr 1, 2012 at 14:55
• @belisarius try this range: {\[Alpha], .001, 1, .01} Apr 1, 2012 at 15:01
• @Sjoerd, yep. I did that earlier :) Apr 1, 2012 at 15:03
• It's not a bug. It has to do with the fact that Sqrt[a^4] is not always equal to a^2. If $\sqrt{a^4}\neq a^2$ the limit is indeed 2. Apr 1, 2012 at 15:28