14

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?

VividD
  • 3,660
  • 4
  • 26
  • 42
mschen
  • 141
  • 3
  • Indeed the correct limit for real $\alpha$ is the one you said. – acl Apr 01 '12 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. – rcollyer Apr 01 '12 at 15:49
  • 4
    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. – Daniel Lichtblau Apr 02 '12 at 16:39

3 Answers3

16

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.

Initial answer

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]

Contour Plot

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.

Jens
  • 97,245
  • 7
  • 213
  • 499
  • You already had my +1, but the most recent edit is very clever. It works even if you remove the α ∈ Reals condition on Simplify. – rcollyer Apr 02 '12 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 02 '12 at 15:55
8

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}]

Mathematica graphics

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}
  ]
]

Mathematica graphics

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.

rm -rf
  • 88,781
  • 21
  • 293
  • 472
Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323
  • Not a bug. There's a simplification that I'm about to post that will make it clear(er). – rcollyer Apr 01 '12 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]]] – Dr. belisarius Apr 01 '12 at 14:55
  • @belisarius try this range: {\[Alpha], .001, 1, .01} – Sjoerd C. de Vries Apr 01 '12 at 15:01
  • @Sjoerd, yep. I did that earlier :) – Dr. belisarius Apr 01 '12 at 15:03
  • 2
    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. – Heike Apr 01 '12 at 15:28
  • @Heike So, what you're saying the result is correct except when $\alpha$ is real. I'd say the output at least is incorrect then. – Sjoerd C. de Vries Apr 01 '12 at 15:36
  • @Heike exactly, and if $\sqrt{\alpha^4}\neq\alpha^2$ then the expression on the rhs of the last line of the first eqn of rcollyer's (now-deleted) answer simplifies to 2, as we may cancel the nonzero factors in the first term – acl Apr 01 '12 at 15:37
  • @Heike Since $\alpha$ is a real number, we do have $\sqrt{a^4}=a^2$. – Jens Apr 01 '12 at 15:39
  • @SjoerdC.deVries $\sqrt{a^4} = -a^2$ if $\pi/4<\arg(a)<3\pi/4$ or $-3\pi/4<\arg(a)<-\pi/4$ (provided that we take the positive branch for the square root). – Heike Apr 01 '12 at 15:41
  • @Heike Using Assumptions you still get the same result. Assuming[\[Alpha] \[Element] Reals, Limit[((k + 2) (\[Alpha]^2 - Sqrt[\[Alpha]^4 + k]) + k)/(\[Alpha]^2 - Sqrt[\[Alpha]^4 + k] + 2 k) // Simplify, k -> 0]] I call a bug. – Sjoerd C. de Vries Apr 01 '12 at 15:43
  • @Jens but Mathematica doesn't know this unless you tell it. If you don't add the assumption that $\alpha$ is real, Mathematica won't simplify $\sqrt{\alpha^4}$ to $\alpha^2$ which means that the terms $\sqrt{\alpha^4}-\alpha^2$ don't cancel. – Heike Apr 01 '12 at 15:44
  • @Heike although \[Alpha] > 0 yields the correct result – Sjoerd C. de Vries Apr 01 '12 at 15:44
  • @SjoerdC.deVries and \[Alpha] < 0 as well, but not \[Alpha] > 0 || \[Alpha] < 0, so there is some bugginess there. – Heike Apr 01 '12 at 15:47
  • @Heike \[Alpha] < 0 also gets the correct answer. Only \[Alpha] \[Element] Reals doesn't work – Sjoerd C. de Vries Apr 01 '12 at 15:48
  • @heike too much going on at the same time ;-) – Sjoerd C. de Vries Apr 01 '12 at 15:49
  • @Heike You are correct about the complex case, but the question explicitly assumes real numbers. – Jens Apr 01 '12 at 15:52
  • @Jens you're right. I missed that part in the question. – Heike Apr 01 '12 at 15:54
  • @Heike try this complex for value and still claim 2 is the correct answer: Limit[((k + 2) (\[Alpha]^2 - Sqrt[\[Alpha]^4 + k]) + k)/(\[Alpha]^2 - Sqrt[\[Alpha]^4 + k] + 2 k) /. \[Alpha] -> 1 + I, k -> 0] – Sjoerd C. de Vries Apr 01 '12 at 16:07
  • @SjoerdC.deVries $\alpha = 1+i$ lies on the boundary between the two regions where the limit changes behaviour, so it could go either way. Try for example for \[Alpha] -> 1.01 + I or \[Alpha] -> .99 + I. – Heike Apr 01 '12 at 16:16
  • @Heike What I'm saying is that the answer of 2 is incorrect for all real $\alpha$ and some complex areas. The fact that there are areas for which the limit holds doesn't make the answer correct. – Sjoerd C. de Vries Apr 01 '12 at 16:23
  • @SjoerdC.deVries I initially missed that the OP made the assumption that \[Alpha] \[Element] Reals. I agree that 2 is the wrong answer in this case. – Heike Apr 01 '12 at 16:33
  • @heike I want to make a case for this being generally incorrect, irrespective of the OP's initial assumptions. IMO MMA should make clear the conditions for which this answer holds, like Reduce does. – Sjoerd C. de Vries Apr 01 '12 at 16:38
8

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.

rm -rf
  • 88,781
  • 21
  • 293
  • 472
rcollyer
  • 33,976
  • 7
  • 92
  • 191
  • The OP mentioned $\alpha$ is real... – Sjoerd C. de Vries Apr 01 '12 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. – rcollyer Apr 01 '12 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)}$. – celtschk Apr 01 '12 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? – rcollyer Apr 01 '12 at 16:04
  • @rcollyer: Simple: Use $\sqrt{a^4-k} = a^2\sqrt{1-k/a^4}$ (here the assumption of the positive root comes in), then do a taylor expansion $\sqrt{1+k/a^4} = 1 + (1/2) k/a^4 + O(k^2)$ and insert that. The $a^2$ terms cancel out, and you get $\lim_{k->0} \frac{k}{-a^2 k/{2a^4}+2k + O(k^2)}$ where you can easily cancel $k$ from the fraction, resulting in $\lim_{k->0} \frac{1}{2 - 1/(2a^2) + O(k)}$ which clearly is $\frac{1}{2 - 1/(2 a^2)}$. – celtschk Apr 01 '12 at 16:09
  • @celtschk I see now. So, don't choose. :) – rcollyer Apr 01 '12 at 16:16
  • 2
    @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 01 '12 at 16:16
  • @Jens Using code to prove your point is not effective here, as we've established there is some odd behavior. Also, in my experience, ignoring the negative branch is done for some external reason, e.g. negative areas, and the usual reason for assuming a positive root is to make the branch explicit: $\sqrt{\ }$ becomes $\pm \sqrt{\ }$. – rcollyer Apr 02 '12 at 01:07
  • In your own answer you use the code lim /. # & /@ (Sqrt[α^4] -> # & /@ {α^2, -α^2}) // Simplify to prove a point. But your point doesn't apply in this problem. The Sqrt function is defined to use the first branch only, so Sqrt[α^4] cannot be negative here. Recall how the two solutions to a quadratic equation are written with a $\pm\sqrt{\ldots}$ term? The reason for that is the definition of $\sqrt{\ldots}$ that I'm taling about. – Jens Apr 02 '12 at 01:33
  • @Jens I had difficulty with your code because the branch choice was in question, and that the choice made by WRI is to take the same branch. So, your code did not lend any weight to your argument. That being said, I'm just being stubborn, and if we run into each other at a conference (we run in similar circles), I'll buy you a beer. In my defense, if I don't account for the negative branch, I usually miss something, even when working with strictly real quantities. (Incidentally, it was de Moirvre's formula that finally told me I was just being stubborn.) – rcollyer Apr 02 '12 at 02:23
  • @Jens lastly, we do both agree, however, that mma is treating the branches here inconsistently. – rcollyer Apr 02 '12 at 02:24