1

I noticed that Limit can return nonsense when using inexact parameters. In the following code, a is my (exact/inexact) parameter, and I want to know the limit for b -> 1 (or b -> 1., this does not matter).

expr := Limit[(-b*Cos[a*b] Sin[a/2] + Sin[a*b] Cos[a/2])/(b^2 - 1), b -> 1];
a = 2. Pi;
expr    (* Returns -Infinity *)
a = 2 Pi;
expr    (* Returns -Pi *) 

I observe this behavior in Mathematica 8, 9, and 10.

I then turned to the documentation of Limit, which states:

Limit may return an incorrect answer for an inexact input:

Limit[Log[1 - (Log[Exp[z]/z - 1] + Log[z])/z]/z, z -> 100.] 
(* -Infinity *)

The result is correct when an exact input is used:

Limit[Log[1 - (Log[Exp[z]/z - 1] + Log[z])/z]/z, z -> 100]
(* 1/100 Log[1 - 1/100 Log[-100 + E^100]] *)

I can see why Limit fails here: The subexpression 1 - 1/100*Log[-100 + E^100] evaluates to approximately 4*10^-44, which is prohibitively small (in single precision, but not in double - this confuses me a bit).

In my example, however, I can't see tiny or huge numbers that could cause this sort of problem. Can you help me see my error?

Edit: I found this problem when I was calculating the Fourier transform of an RF-pulse to find the maximum power density of its spectrum.

Martin J.H.
  • 753
  • 3
  • 15
  • 2
    Trace[expr] should help to clarify why the approximate case gives what it gives. – Daniel Lichtblau Jan 27 '16 at 18:05
  • Have a look at a = 2. [Pi] and a = 2 Pi without the semicolon 2 Pi ist not the same as 2*Pi, see also Trace as stated by @Daniel Lichtblau –  Jan 27 '16 at 18:46
  • @Louis: I am thoroughly confused. What do the square brackets in a = 2. [Pi] mean? I see that the output is different, but I am unfamiliar with that syntax (and could not find it here or here). Further, I don't see different output when not using the semicolon, or why 2 Pi is not equal to 2*Pi. – Martin J.H. Jan 27 '16 at 18:59
  • Pi leads to 6.28319 and 2 Pi leads to 2 [Pi], and try the Trace thing
  • –  Jan 27 '16 at 19:04
  • 3
    I think @Louis is saying that "2Pi" and "2.Pi" are different, but you already knew that. Try setting a to 2*Pi+e to see an odd result: apparently, there's a sign change in the limit near 2*Pi. –  Jan 27 '16 at 19:04