
inhomoSum :: RealFloat a => [a] -> a
inhomoSum xs
  =  sum [ ((s1 n)**2 + (s2 n)**2) / n**2
         | i <- [1..huge], n <- [fromIntegral i] ]
  where
    s1 n    =  sum [ cos (2 * pi * n * x) | x <- xs ]
    s2 n    =  sum [ sin (2 * pi * n * x) | x <- xs ]
    huge    =  1000

inhomoSignificance :: RealFloat a => [a] -> a
inhomoSignificance xs  =  prob (inhomoSum xs / count)
  where
    count   =  fromIntegral (length xs)
    prob x  =  (min 1 . max 0) (
                 sum [ (if i < huge then 2 else 1) *
                       (-1)**(n-1) * exp (-n**2 * x)
                     | i <- [1..huge], n <- [fromIntegral i] ]
               )
    huge    =  1000

inhomogeneity :: RealFloat a => [a] -> a
inhomogeneity xs  =  sqrt (6 / pi**2 / count**2 * inhomoSum xs)
  where
    count  =  fromIntegral (length xs)


