9
$\begingroup$

Using Mathematica 10.4.1.0 I have a problem with Binomial on numerical computations.

Both of the following correctly return 1.0 as the result:

Binomial[0.1999999999999998, 1/5]
(* 1. *)

Binomial[0.2, 1/5]
(* 1. *)

However, if I change the last digit to 9, it returns 5.0, which is wrong.

Binomial[0.1999999999999999, 1/5]
(* 5. *)

Note that in general, Binomial[x,x] is 1. In this case, both arguments are very close to 1/5, so the correct result is 1.

Do you have the same problem? Are there any workarounds?

$\endgroup$
7
  • 4
    $\begingroup$ If you remove a single 9, it becomes 1. It has got to be a bug. Try: Binomial[SetPrecision[0.19999999999999996`, 50], 1/5] it gives me 0.9999999999999999872024250753568454 $\endgroup$
    – flinty
    Jul 2 '20 at 11:32
  • 3
    $\begingroup$ The problem also appears in v12.1.1. (Binomial[m, n] // FunctionExpand) /. {m -> 0.19999999999999996`, n -> 1/5} gives 0.9999999999999999 so the problem is with Binomial rather than Gamma $\endgroup$
    – Bob Hanlon
    Jul 2 '20 at 15:54
  • 2
    $\begingroup$ A possible workaround is to wrap the first argument in Rationalize. Not sure if this is acceptable performance-wise. $\endgroup$
    – Natas
    Jul 3 '20 at 12:24
  • 2
    $\begingroup$ The problem does NOT appear in versions 8.0.4 and 5.2. Can anybody check version 9? $\endgroup$
    – innaiz
    Jul 4 '20 at 7:21
  • 1
    $\begingroup$ @innaiz Same problem with version 9 $\endgroup$
    – Ali Hashmi
    Jul 31 '20 at 14:28
3
$\begingroup$

Try using Rationalize

Binomial[0.19999999999999996//Rationalize,1/5]//N = 1.
$\endgroup$
1
  • $\begingroup$ Rationalize will not rationalize all real numbers, for example Rationalize[Pi // N]. So, to avoid unexpected results, we have to use Rationalize[#,0]& instead. $\endgroup$ Sep 3 '20 at 10:02
3
$\begingroup$

Actually, the workaround to calculate

Binomial[a, b]

is:

Binomial[Rationalize [a, 0], Rationalize [b, 0]] // N
$\endgroup$

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.