square x = x * x -- Compute the minimum of two numbers mymin x y = if x<=y then x else y fac n = if n==0 then 1 else n * fac (n-1) -- Compute the n-th Fibonacci number fib1 n = if n==0 then 0 else if n==1 then 1 else fib1 (n-1) + fib1 (n-2) fib2' n fibn fibnp1 = if n==0 then fibn else fib2' (n-1) fibnp1 (fibn+fibnp1) fib2 n = fib2' n 0 1 -- with local definitions fib3 n = g (fib3' n 0 1) where fib3' n fibn fibnp1 = if n==0 then fibn else fib3' (n-1) fibnp1 (fibn+fibnp1) g x = x fib4 n = let fib3' n fibn fibnp1 = if n==0 then fibn else fib3' (n-1) fibnp1 (fibn+fibnp1) in fib3' n 0 1 --f x y = y * (1-y) + (1 + x*y) * (1-y) + x*y f x y = let a = 1-y b = x*y in y * a + (1+b) * a + b -- Vorteil: weniger Parameter zu uebergeben isPrim n = n/= 1 && checkDiv (n-1) where checkDiv m = m==1 || mod n m /= 0 && checkDiv (m-1)