# Evaluating a simple limit in Mathematica

Consider the function

$$M = \frac{\left[(f^{\prime})^2 - 2ff^{\prime \prime} - f^{\prime}_H~f^{\prime}\right]}{2f}$$

where $$f \equiv f(r)$$, and the primes are derivatives with respect to $$r$$. $$f'_H$$ is a constant. I want to consider a limit $$r \to r_H$$, wherein $$f\to 0, f' \to f'_H, f'' \to f''_H$$. If I evaluate this limit directly, I obtain an undetermined expression. Upon using L'Hospital's rule, I get,

$$\lim_{r\to r_H} \frac{2f^{\prime}f^{\prime \prime} - 2f^{\prime}f^{\prime \prime} - 2ff^{\prime \prime \prime} - f^{\prime}_Hf^{\prime \prime}}{2f^{\prime}} = - \frac{f^{\prime \prime}_H}{2}$$

However, I tried evaluating the same limit in Mathematica, and it's giving me $$-f''_H$$. My code is attached below:

M[r] =(-(fph*Derivative[1][f][r]) + Derivative[1][f][r]^2 - 2*f[r]*Derivative[2][f][r])/(2*f[r])

Limit[M[r], {f[r] -> 0, f'[r] -> fph, f''[r] -> fpph}]


which gives me an output of -fpph. Where is the discrepancy of the $$1/2$$ factor coming from?

• In the limit, you have specified the numerator goes to -fh'^2, while the denominator to zero. Hence the limit is minus infinity if fh'!=0. Commented Feb 12, 2023 at 10:37
• @AlexeiBoulbitch, how? The second term in the numerator vanishes. The first and third term cancel, giving 0. Since the denominator is also 0 in the limit, I can apply L'Hospital's rule Commented Feb 12, 2023 at 12:05

Limit is treating the function and its derivatives as independent variables, which is not the case in your intended problem. According to the docs, the limit is computed in nested iterator order (last rule done first). The result is the same as this:

FoldList[Limit, M[r], Reverse@{
f[r] -> 0,      (* third limit  *)
f'[r] -> fph,   (* second limit *)
f''[r] -> fpph  (* first limit  *)
}]

(*{
(-fph f'[r] + f'[r]^2 - 2 f[r] f''[r])/(2 f[r]),
(-2 fpph f[r] - fph f'[r] + f'[r]^2)/(2 f[r]),
-fpph,
-fpph
}*)


You have to compute your limit in a different way.

We could plug in the correlations between the function and derivative values:

M[r] /. {f[r] -> fph eps , f'[r] -> fph + fpph eps,
f''[r] -> fpph + fppph eps} // Simplify
% /. eps -> 0
(*
(eps fpph^2 - fph (fpph + 2 eps fppph))/(2 fph)

-(fpph/2)
*)


One caveat is to consider how far to expand the functions. The above works, but one could go farther. For instance:

M[r] /. {f[r] -> fph eps + fpph eps^2/2 + fppph eps^3/6 ,
f'[r] -> fph + fpph eps + fppph eps^2/2,
f''[r] -> fpph + fppph eps} // Simplify


The following approach uses Series[] to figure all that out for us, but the input and output are in slightly different form:

Assuming[{f'[rh] == fph, f[rh] == 0},
Series[M[r], {r, rh, 0}] // Simplify // Normal]
(*
-(1/2) f''[rh]
*)

• Thank you very much! Commented Feb 14, 2023 at 6:38