I\'m in the middle of porting David Blei\'s original C implementation of Latent Dirichlet Allocation to Haskell, and I\'m trying to decide whether to leave some of the low-l
Before the optimization work, I wouldn't say that your original translation is the most idiomatic way to express in Haskell what the C code is doing.
How would the optimization process have proceeded if we started with the following instead:
trigamma :: Double -> Double
trigamma x = foldl' (+) p' . map invSq . take 6 . iterate (+ 1) $ x
where
invSq y = 1 / (y * y)
x' = x + 6
p = invSq x'
p' =(((((0.075757575757576*p-0.033333333333333)*p+0.0238095238095238)
*p-0.033333333333333)*p+0.166666666666667)*p+1)/x'+0.5*p