8
$\begingroup$

Bug introduced in 8.0 and fixed in 10.0.0


Just try this example:

lst = {0, 1, 1, Sqrt[2], Sqrt[5], 2 Sqrt[2], 2, Sqrt[13], Sqrt[5], Sqrt[6], Sqrt[11], 
       Sqrt[14], Sqrt[11], Sqrt[10], 3 Sqrt[2], Sqrt[17], Sqrt[13], 2 Sqrt[5], Sqrt[29], 
       2 Sqrt[2]};

ex1 = BinCounts[lst, {Range[0, 18]}]
ex2 = BinCounts[lst, {Range[0, 19]}]
ex3 = BinCounts[N@lst, {Range[0, 18]}]
{1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
{1, 3, 6, 6, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
{1, 3, 6, 6, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

Seems that BinCounts failed to notice the irrational numbers in ex1:

Select[lst, IntegerQ]
(* This result is consistent with ex1. *)
{0, 1, 1, 2}

Is it a bug? I'm using Mathematica 8.0.4, Windows Vista 32bit.

$\endgroup$
  • 1
    $\begingroup$ Same result in 9.0.1. Odd behavior indeed; seems hard to justify it as anything other than a bug... $\endgroup$ – Oleksandr R. May 20 '14 at 10:25
  • $\begingroup$ Try BinCounts[lst + $MachineEpsilon, {Range[0, 18]}]... looks bug-like to me. You can use N, or Length /@ BinLists[lst, {Range[0, 18]}] as work-around. $\endgroup$ – ciao May 20 '14 at 10:26
  • $\begingroup$ same result in OSX v9.0.1 $\endgroup$ – gpap May 20 '14 at 10:36
  • 1
    $\begingroup$ But HistogramList[lst, {Range[0, 18]}] works ok. $\endgroup$ – b.gates.you.know.what May 20 '14 at 10:37
  • 1
    $\begingroup$ minimal example: BinCounts[{0, 3, Sqrt[2]}, {Range[1, 2]}] -> {0} $\endgroup$ – george2079 May 20 '14 at 19:58
3
$\begingroup$

This bug has been fixed in v10.0 (Tested on Wolfram Programming Cloud):

enter image description here

$\endgroup$
  • $\begingroup$ In MMA V10 desktop version it's ok too. $\endgroup$ – Murta Jul 15 '14 at 11: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.