I've been trying to solve a problem that requires Sigma Notation (Or at least I think), but every implementation of Sigma Notation in Haskell i've come across doesn't use the index variable in its function. The particular formula i've been trying to replicate is:
It's used in calculating the number of trailing zeros in n!, but the best i've got is:
sigma :: (Enum a, Num b) => a -> a -> (a -> b) -> b
sigma i k fn = sum . map fn $ [i..k]
zeros :: Int -> Int
zeros n = sigma 1 n (???)
I'm trying to also create a general sigma function, that works with an index variable in f. This works, but for 100!, it gives -11 trailing zeros. Overflow?
zeros :: Int -> Int
zeros n = sigma 1 n (\i -> n `div` 5 ^ i)
where sigma i k fn = sum $ map fn [i..k]
P.S. Im on an in-browser IDE that limits compile time. (So speed counts)