From 8613f7154f815835fc5e6ddbe15e9aebc62109b1 Mon Sep 17 00:00:00 2001 From: Matthias Wisniowski Date: Mon, 26 Mar 2012 00:15:48 +0200 Subject: Fixed different values for h-function Using Integer instead of Int solved the difference in values for the different h-functions. Apparently they have equal performance. Added basic testcases. --- AufgabeFFP2.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'AufgabeFFP2.hs') diff --git a/AufgabeFFP2.hs b/AufgabeFFP2.hs index 9e466b7..7993c01 100644 --- a/AufgabeFFP2.hs +++ b/AufgabeFFP2.hs @@ -56,23 +56,23 @@ facGen = map (fac) [1..] -- function g with memoization (using hFast) fMT :: Int -> Int -> Float -fMT z k = g z k hFast +fMT z k = g z k hMT -- function g without memoization (uning hSlow) f :: Int -> Int -> Float -f z k = g z k hSlow +f z k = g z k h --- actual function g -g :: Int -> Int -> (Int -> Int -> Float) -> Float -g z k h = sum $ map (h z) [1..k] +-- actual function g (converts Int to Integer for more precision) +g :: Int -> Int -> (Integer -> Integer -> Float) -> Float +g z k h = sum $ map (h $ fromIntegral z) [1..(fromIntegral k)] -- helper function h using mem-table for the power-series (z^i) and for faculty (i!) -hFast :: Int -> Int -> Float -hFast z i = (fromInteger $ pofNs (fromIntegral z) !! i) / (fromInteger $ facGen !! (i-1)) +hMT :: Integer -> Integer -> Float +hMT z i = (fromInteger $ pofNs z !! (fromInteger i)) / (fromInteger $ facGen !! ((fromIntegral i)-1)) -- helper function h without memoization -hSlow :: Int -> Int -> Float -hSlow z i = (fromIntegral $ z^i) / (fromInteger $ fac $ fromIntegral i) +h :: Integer -> Integer -> Float +h z i = (fromInteger $ z^i) / (fromInteger $ fac i) ------------------------------------------------------------------------------- -- cgit v1.2.3