September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -1,7 +1,22 @@
procedure main()
every write(left(i := !10/10.0,5),gamma(.i))
end
import Control.Applicative
procedure gamma(z) # Stirling's approximation
return (2*&pi/z)^0.5 * (z/&e)^z
end
cof :: [Double]
cof =
[ 76.18009172947146
, -86.50532032941677
, 24.01409824083091
, -1.231739572450155
, 0.001208650973866179
, -0.000005395239384953
]
gammaln :: Double -> Double
gammaln =
((+) . negate . (((-) . (5.5 +)) <*> (((*) . (0.5 +)) <*> (log . (5.5 +))))) <*>
(log .
((/) =<<
(2.5066282746310007 *) .
(1.000000000190015 +) . sum . zipWith (/) cof . enumFrom . (1 +)))
main :: IO ()
main = mapM_ print $ gammaln <$> [0.1,0.2 .. 1.0]