diff options
author | Camil Staps | 2016-11-07 22:18:43 +0000 |
---|---|---|
committer | Camil Staps | 2016-11-07 22:18:43 +0000 |
commit | bb17db68f38c9a91ec4b12c664e0464efd5e9ccc (patch) | |
tree | 61295157d37a6033122b5e87a1630eb5f44ae1b6 | |
parent | update Makefile (diff) |
Adapted acker and e to be standalone
-rw-r--r-- | acker.icl | 12 | ||||
-rw-r--r-- | e.icl | 51 |
2 files changed, 59 insertions, 4 deletions
@@ -2,7 +2,17 @@ module acker // The Ackermann function. -import StdInt +//import StdInt + +(+) infixl 6 :: !Int !Int -> Int +(+) a b = code inline { + addI +} + +(-) infixl 6 :: !Int !Int -> Int +(-) a b = code inline { + subI +} Acker::Int Int -> Int Acker 0 j = j + 1 @@ -6,7 +6,52 @@ Approximation of the number e. Result: A list containing the first NrDigits digits of e = [2,7,1,8,2,8,1,8,2,8,...]. */ -import StdEnv +(<) infix 4 :: !Int !Int -> Bool +(<) a b = code inline { + ltI +} + +(+) infixl 6 :: !Int !Int -> Int +(+) a b = code inline { + addI +} + +(-) infixl 6 :: !Int !Int -> Int +(-) a b = code inline { + subI +} + +(*) infixl 7 :: !Int !Int -> Int +(*) a b = code inline { + mulI +} + +(/) infixl 7 :: !Int !Int -> Int +(/) a b = code inline { + divI +} + +(==) infix 4 :: !Int !Int -> Bool +(==) a b = code inline { + eqI +} + +(rem) infix 7 :: !Int !Int -> Int +(rem) a b = code inline { + remI +} + +take :: Int [a] -> [a] +take 0 _ = [] +take n [x:xs] = [x:take (n-1) xs] + +hd :: [a] -> a +hd [x:xs] = x + +tl :: [a] -> [a] +tl [_:xs] = xs + +//import StdEnv NrDigits :== 200 // The number of digits of the approximation of e @@ -26,7 +71,7 @@ Expan f = [hd ten:Expan (tl ten)] Ten::Int [Int] -> [Int] Ten c [p:q] | Safe k c = [k / c, k rem c + a1 : b1] = [(k + a1) / c, (k + a1) rem c : b1] - where + where a1 = hd ten b1 = tl ten ten = Ten (c+1) q @@ -40,6 +85,6 @@ The Start rule returns the first NrDigits elements of the list of digits returned by the function 'Approx_e' by means of the function take. */ - + Start::[Int] Start = take NrDigits Approx_e |