summaryrefslogtreecommitdiffstats
path: root/AufgabeFFP2.hs
diff options
context:
space:
mode:
Diffstat (limited to 'AufgabeFFP2.hs')
-rw-r--r--AufgabeFFP2.hs57
1 files changed, 56 insertions, 1 deletions
diff --git a/AufgabeFFP2.hs b/AufgabeFFP2.hs
index e66b7a8..7993c01 100644
--- a/AufgabeFFP2.hs
+++ b/AufgabeFFP2.hs
@@ -38,4 +38,59 @@ 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 hMT
60
61-- function g without memoization (uning hSlow)
62f :: Int -> Int -> Float
63f z k = g z k h
64
65-- actual function g (converts Int to Integer for more precision)
66g :: Int -> Int -> (Integer -> Integer -> Float) -> Float
67g z k h = sum $ map (h $ fromIntegral z) [1..(fromIntegral k)]
68
69-- helper function h using mem-table for the power-series (z^i) and for faculty (i!)
70hMT :: Integer -> Integer -> Float
71hMT z i = (fromInteger $ pofNs z !! (fromInteger i)) / (fromInteger $ facGen !! ((fromIntegral i)-1))
72
73-- helper function h without memoization
74h :: Integer -> Integer -> Float
75h z i = (fromInteger $ z^i) / (fromInteger $ fac i)
76
77-------------------------------------------------------------------------------
78
79-- 4
80
81-- gets the digits of an integer as a list
82digits :: Integer -> [Integer]
83digits x
84 | x<=0 = []
85 | otherwise = (digits $ x `div` 10)++[x `mod` 10]
86
87-- calculates the goedel-number for the given integer
88-- returns 0 for non-positive numbers
89gz :: Integer -> Integer
90gz n
91 | n<=0 = 0
92 | otherwise = product $ zipWith (^) primes (digits n)
93
94-- goedel-number generator
95gzs :: [Integer]
96gzs = map (gz) [1..]