Combinatorics in Haskell
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

27 lines
930 B

module Main where
import Bell
import Matchings
import Stirling
import Control.Monad
heightOfDistinctAtoms :: Int -> Integer
heightOfDistinctAtoms n = toInteger $ n + 1
heightOfAtoms :: Int -> Integer
heightOfAtoms n = sum [ norbits k * heightOfDistinctAtoms k | k <- [0 .. n] ]
+ sum [ matchings o1 o2 | (o1, o2) <- cross ]
where
norbits k = secondStirling n k
orbits k = replicate (fromIntegral (norbits k)) k
allOrbits = concat [ orbits k | k <- [0..n] ]
cross = [ (allOrbits !! i, allOrbits !! j) | let m = length allOrbits, i <- [0 .. m-1], j <- [i+1 .. m-1] ]
orbitsOf :: Int -> [Int]
orbitsOf n = concat [ replicate (fromIntegral (secondStirling n k)) k | k <- [0..n] ]
main :: IO ()
main = do
let out = [ (i, heightOfAtoms i, bell (2*i)) | i <- [0..10] ]
forM_ out $ \(i, n, b) -> putStrLn ("h(A^" ++ show i ++ ") = " ++ show n ++ " < B_" ++ show (2*i) ++ " = " ++ show b)