diff options
Diffstat (limited to 'AufgabeFFP2.hs')
| -rw-r--r-- | AufgabeFFP2.hs | 18 |
1 files changed, 9 insertions, 9 deletions
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..] | |||
| 56 | 56 | ||
| 57 | -- function g with memoization (using hFast) | 57 | -- function g with memoization (using hFast) |
| 58 | fMT :: Int -> Int -> Float | 58 | fMT :: Int -> Int -> Float |
| 59 | fMT z k = g z k hFast | 59 | fMT z k = g z k hMT |
| 60 | 60 | ||
| 61 | -- function g without memoization (uning hSlow) | 61 | -- function g without memoization (uning hSlow) |
| 62 | f :: Int -> Int -> Float | 62 | f :: Int -> Int -> Float |
| 63 | f z k = g z k hSlow | 63 | f z k = g z k h |
| 64 | 64 | ||
| 65 | -- actual function g | 65 | -- actual function g (converts Int to Integer for more precision) |
| 66 | g :: Int -> Int -> (Int -> Int -> Float) -> Float | 66 | g :: Int -> Int -> (Integer -> Integer -> Float) -> Float |
| 67 | g z k h = sum $ map (h z) [1..k] | 67 | g z k h = sum $ map (h $ fromIntegral z) [1..(fromIntegral k)] |
| 68 | 68 | ||
| 69 | -- helper function h using mem-table for the power-series (z^i) and for faculty (i!) | 69 | -- helper function h using mem-table for the power-series (z^i) and for faculty (i!) |
| 70 | hFast :: Int -> Int -> Float | 70 | hMT :: Integer -> Integer -> Float |
| 71 | hFast z i = (fromInteger $ pofNs (fromIntegral z) !! i) / (fromInteger $ facGen !! (i-1)) | 71 | hMT z i = (fromInteger $ pofNs z !! (fromInteger i)) / (fromInteger $ facGen !! ((fromIntegral i)-1)) |
| 72 | 72 | ||
| 73 | -- helper function h without memoization | 73 | -- helper function h without memoization |
| 74 | hSlow :: Int -> Int -> Float | 74 | h :: Integer -> Integer -> Float |
| 75 | hSlow z i = (fromIntegral $ z^i) / (fromInteger $ fac $ fromIntegral i) | 75 | h z i = (fromInteger $ z^i) / (fromInteger $ fac i) |
| 76 | 76 | ||
| 77 | ------------------------------------------------------------------------------- | 77 | ------------------------------------------------------------------------------- |
| 78 | 78 | ||
