I'm just digging a bit into Haskell and I started by trying to compute the Phi-Coefficient of two words in a text. However, I ran into some very strange behaviour that I cannot explain.
After stripping everything down, I ended up with this code to reproduce the problem:
let sumTup = (sumTuples∘concat) frequencyLists
let sumFixTup = (138, 136, 17, 204)
putStrLn (show ((138, 136, 17, 204) == sumTup))
putStrLn (show (phi sumTup))
putStrLn (show (phi sumFixTup))
This outputs:
True
NaN
0.4574206676616167
So although the sumTup
and sumFixTup
show as equal, they behave differently when passed to phi
.
The definition of phi
is:
phi (a, b, c, d) =
let dividend = fromIntegral(a * d - b * c)
divisor = sqrt(fromIntegral((a + b) * (c + d) * (a + c) * (b + d)))
in dividend / divisor