summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AufgabeFFP2.hs38
1 files changed, 37 insertions, 1 deletions
diff --git a/AufgabeFFP2.hs b/AufgabeFFP2.hs
index e66b7a8..e4e646b 100644
--- a/AufgabeFFP2.hs
+++ b/AufgabeFFP2.hs
@@ -38,4 +38,40 @@ powFast :: Int -> Integer
38powFast 0 = 1 38powFast 0 = 1
39powFast n = pof2s !! (n-1) + pof2s !! (n-1) 39powFast n = pof2s !! (n-1) + pof2s !! (n-1)
40 40
41------------------------------------------------------------------------------- \ No newline at end of file 41-------------------------------------------------------------------------------
42
43-- 3
44
45-- power series of N
46pofNs :: Integer -> [Integer]
47pofNs n = [1] ++ (map (n*) $ pofNs n)
48
49-- faculty function
50fac :: Integer -> Integer
51fac n = product [1..n]
52
53-- stream of faculties
54facGen :: [Integer]
55facGen = map (fac) [1..]
56
57-- function g with memoization (using hFast)
58fMT :: Int -> Int -> Float
59fMT z k = g z k hFast
60
61-- function g without memoization (uning hSlow)
62f :: Int -> Int -> Float
63f z k = g z k hSlow
64
65-- actual function g
66g :: Int -> Int -> (Int -> Int -> Float) -> Float
67g z k h = sum $ map (h z) [1..k]
68
69-- helper function h using mem-table for the power-series (z^i) and for faculty (i!)
70hFast :: Int -> Int -> Float
71hFast z i = (fromInteger $ pofNs (fromIntegral z) !! i) / (fromInteger $ facGen !! (i-1))
72
73-- helper function h without memoization
74hSlow :: Int -> Int -> Float
75hSlow z i = (fromIntegral $ z^i) / (fromInteger $ fac $ fromIntegral i)
76
77-------------------------------------------------------------------------------