0
$\begingroup$

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)

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

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.49999999999999833`16]

-34.0 + 3.1 I

and:

Limit[(d+1/2)*Log[d+1/2]-(d-1/2)*Log[d-1/2],d->0.49999999999999833`16]

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

both produce answers more in tune with your expectations.

$\endgroup$
3
  • $\begingroup$ 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? $\endgroup$ – Alex Jun 6 '19 at 15:43
  • $\begingroup$ @Alex Use SetPrecision $\endgroup$ – Carl Woll Jun 6 '19 at 15:46
  • $\begingroup$ Ha, this is working, thank you! $\endgroup$ – Alex Jun 6 '19 at 15:49
0
$\begingroup$

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    *)
$\endgroup$
2
  • $\begingroup$ You could also use f[n_?(Internal`RealValuedNumberQ[#]&&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. $\endgroup$ – b3m2a1 Jun 6 '19 at 17:06
  • $\begingroup$ @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. $\endgroup$ – Roman Jun 6 '19 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.