Timeline for Bad Float Counts? (Length[xs] != Total@Counts[xs])
Current License: CC BY-SA 4.0
14 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 21, 2019 at 20:17 | comment | added | Greg Hurst |
@MichaelE2 I’ll check my other machine later to see if I can figure out where my 9.447839999999998 came from.
|
|
Jan 21, 2019 at 20:16 | comment | added | Michael E2 |
@ChipHurst "11.3.0 for Mac OS X x86 (64-bit) (January 22, 2018)" -- I got what you're now showing. My theory is that because MatchQ[9.44784`, 9.447839999999998`] returns True , they're treated as the same key.
|
|
Jan 21, 2019 at 20:03 | comment | added | Greg Hurst |
@MichaelE2 hmm, what OS are you on? It's weird, I'm seeing the least significant (base 10) digit as 6 instead of 8 now... In[18]:= $OperatingSystem Out[18]= "MacOSX" In[19]:= Merge[Association[{# -> 1}] & /@ xs, Total] // Keys Out[19]= {59.048999999999985, 23.6196, 922.640625, 369.05625000000003, 59.049, 147.6225, 9.44784, 369.05625, 1.5116543999999998, 23.61959999999999, 2306.6015625, 3.7791359999999994, 9.447839999999996}
|
|
Jan 21, 2019 at 18:33 | comment | added | Michael E2 |
@ChipHurst I get that 9.44784` and 9.447839999999998` are not both present in Merge[Association[{# -> 1}] & /@ xs, Total] , which seems to be different than what you are saying.
|
|
Jan 21, 2019 at 15:13 | vote | accept | Alan | ||
Jan 21, 2019 at 3:52 | answer | added | Michael E2 | timeline score: 9 | |
Jan 20, 2019 at 18:00 | history | tweeted | twitter.com/StackMma/status/1087047278421032962 | ||
Jan 20, 2019 at 17:27 | comment | added | Alan |
Since nobody is claiming this is expected behavior, I am reporting it. As far as I can tell, it is either a bug or a documentation bug. (Perhaps we shd not expect floats to work correctly as assocation keys, but then this shd be listed as a possible issue. Or, perhaps Counts shd be expected to be as intelligent as Tally .)
|
|
Jan 20, 2019 at 17:11 | comment | added | Greg Hurst |
FWIW Block[{$Internal`SameQTolerance = 0.55}, Total[Counts[xs]]] fixes this particular example.
|
|
Jan 20, 2019 at 17:00 | answer | added | Jerry | timeline score: 2 | |
Jan 20, 2019 at 17:00 | comment | added | Greg Hurst |
The missing key from both Counts and Total[AssociationThread @@ Transpose[Tally[xs]]] is 9.44784` . The fact that it's present in Tally[xs] , but not the association form led me to believe it's impossible to have both 9.44784` and 9.447839999999998` as keys in the same association... but that's not the case as they're both present with Merge[Association[{# -> 1}] & /@ xs, Total] .
|
|
Jan 20, 2019 at 16:55 | comment | added | kglr |
thanks @Alan. It seems to be a general problem with using floats as keys: e.g. assoc = AssociationThread[xs -> Range[Length[xs]]] .
|
|
Jan 20, 2019 at 16:45 | comment | added | Alan |
@kglr As the question states, rounding fixes the problem. But the question remains, is this behavior expected. (As the question states, Tally does not have the same problem.)
|
|
Jan 20, 2019 at 16:34 | history | asked | Alan | CC BY-SA 4.0 |