-- Fractran prime generation algorithm -- Implementation by Eliot Ball -- See http://mathworld.wolfram.com/FRACTRAN.html for further details -- The fractran program frac = [[17, 91], [78, 85], [19, 51], [23, 38], [29, 33], [77, 29], [95, 23], [77, 19], [1, 17], [11, 13], [13, 11], [15, 2], [1, 7], [55, 1]] -- Function to obtain the remainder when dividing n*f0 by f1 fpart :: Integer -> [Integer] -> Integer fpart n f = mod (n * (head f)) (last f) -- Function to multiply a number by the first fraction in the fractran program that gives an integral product fmul :: Integer -> Integer fmul n = head [div (n * (head f)) (last f) | f <- frac, fpart n f == 0] -- An infinite list containing the sequence generated by the fractan program with initial seed n sequ :: Integer -> [Integer] sequ n = [n] ++ sequ (fmul n) -- Function to check whether the real number n is an integer isround :: Double -> Bool isround n = fromIntegral (truncate n) == n -- An infinite list of primes primes = [truncate (pc n) | n <- (sequ 2), isround (pc n)] where pc n = logBase 2 (fromIntegral n)