# Wrong limit result?

I'm trying to evaluate the following limit:

Limit[(d + 1/2)*Log[d + 1/2] - (d - 1/2)*Log[d - 1/2],d->a]


Normally, when a tends towards 0.5, the limit is supposed to give 0 (which it does when I put a=0). However, when a=0.49999999999999833$$$$ (precisely), it gives me the result "Indeterminate". Why is it giving me that result? Can I do something to avoid it? (It creates problems afterwards)

• I do not reproduce the issue: imgur.com/a/zvGtZlk – corey979 Jun 6 '19 at 15:22
• This is odd. Are we on the same version? I'm using Wolfram Mathematica 12 – Alex Jun 6 '19 at 15:25
• Ah, here we go again... thread on meta – corey979 Jun 6 '19 at 15:27
• Isn't the version 12 the latest version tought? – Alex Jun 6 '19 at 15:33
• Are you calculating a von Neumann entropy? – Roman Jun 6 '19 at 17:05

I'm not sure how Limit works for inexact numbers, but the issue is probably related to:

Limit[Log[d - 1/2], d->0.49999999999999833]


-∞

There was a change in how machine numbers are handled starting in M11.3, and this change means the output of your limit will be different when comparing M12 and M11.1 and earlier.

Now, Limit works best with exact input. If you want to use inexact input, though, it is probably better to use an extended precision number. So:

Limit[Log[d - 1/2], d->0.4999999999999983316]


-34.0 + 3.1 I

and:

Limit[(d+1/2)*Log[d+1/2]-(d-1/2)*Log[d-1/2],d->0.4999999999999983316]


-6.*10^-14 + 5.*10^-15 I

• While using the extension is indeed working, the problem is that the number I gave as a example is the result of long calculations and is part of a big table of numbers. Is it possible to non-manually add those extensions? – Alex Jun 6 '19 at 15:43
• @Alex Use SetPrecision – Carl Woll Jun 6 '19 at 15:46
• Ha, this is working, thank you! – Alex Jun 6 '19 at 15:49

You don't need to take a limit here, you can just use a multiple dispatch function to "plug the holes" at $$a=\pm\frac12$$:

f[1/2 | 0.5] = 0;
f[-1/2 | -0.5] = I*π;
f[a_] = (a + 1/2)*Log[a + 1/2] - (a - 1/2)*Log[a - 1/2];


This is also much faster and easier:

f[0.5]
(*    0    *)
f[0.49999999999999833]
(*    -5.83346*10^-14 + 5.2318*10^-15 I    *)

• You could also use f[n_?(InternalRealValuedNumberQ[#]&&Abs[#]==.5)]:=... instead of the two Alternatives patterns, either of which could be missed for something like .49999999 which will probably also give poor behavior. – b3m2a1 Jun 6 '19 at 17:06
• @b3m2a1 in general you're right; in practice Log is such a tolerant function that in this case even f[0.5 + 2^-53] and f[0.5 - 2^-53] evaluate correctly. You cannot get any closer to $\frac12$ with machine precision. So there is no issue here. – Roman Jun 6 '19 at 17:14