Commit 5990b9b7 by simonpj

### [project @ 2003-03-10 08:58:31 by simonpj]

`Add bernouilli test`
parent e329d0dc
 -- There was a lot of discussion about various ways of computing -- Bernouilli numbers (whatever they are) on haskell-cafe in March 2003 -- Here's one of the programs. -- It's not a very good test, I suspect, because it manipulates big integers, -- and so probably spends most of its time in GMP. import Ratio import System.Environment -- powers = [[r^n | r<-[2..]] | n<-1..] powers = [2..] : map (zipWith (*) (head powers)) powers -- powers = [[(-1)^r * r^n | r<-[2..]] | n<-1..] neg_powers = map (zipWith (\n x -> if n then x else -x) (iterate not True)) powers pascal:: [[Integer]] pascal = [1,2,1] : map (\line -> zipWith (+) (line++[0]) (0:line)) pascal bernoulli 0 = 1 bernoulli 1 = -(1%2) bernoulli n | odd n = 0 bernoulli n = (-1)%2 + sum [ fromIntegral ((sum \$ zipWith (*) powers (tail \$ tail combs)) - fromIntegral k) % fromIntegral (k+1) | (k,combs)<- zip [2..n] pascal] where powers = (neg_powers!!(n-1)) main = do [arg] <- getArgs let n = (read arg)::Int putStr \$ "Bernoulli of " ++ (show n) ++ " is " print (bernoulli n)
 TOP = ../.. include \$(TOP)/mk/boilerplate.mk # Override default SRCS; the default is all source files, but # we don't want to include paraffins.c SRCS=Main.hs SRC_RUNTEST_OPTS += 500 include \$(TOP)/mk/target.mk
 Bernoulli of 500 is (-16596380640568557229852123088077134206658664302806671892352650993155331641220960084014956088135770921465025323942809207851857992860213463783252745409096420932509953165466735675485979034817619983727209844291081908145597829674980159889976244240633746601120703300698329029710482600069717866917229113749797632930033559794717838407415772796504419464932337498642714226081743688706971990010734262076881238322867559275748219588404488023034528296023051638858467185173202483888794342720837413737644410765563213220043477396887812891242952336301344808165757942109887803692579439427973561487863524556256869403384306433922049078300720480361757680714198044230522015775475287075315668886299978958150756677417180004362981454396613646612327019784141740499835461) % 8365830
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!