module Sym.Perm.D8
(
r0, r1, r2, r3
, s0, s1, s2, s3
, d8
, klein4
, orbit
, symmetryClasses
, d8Classes
, klein4Classes
, rotate
, complement
, reverse
, inverse
) where
import Prelude hiding (reverse)
import Data.List hiding (reverse)
import Sym.Internal.Util
import Sym.Perm
import Foreign hiding (complement, rotate)
import Foreign.C.Types
import System.IO.Unsafe
r0 :: Perm -> Perm
r0 w = w
r1 :: Perm -> Perm
r1 = s2 . s1
r2 :: Perm -> Perm
r2 = r1 . r1
r3 :: Perm -> Perm
r3 = r2 . r1
s0 :: Perm -> Perm
s0 = complement
s1 :: Perm -> Perm
s1 = reverse
s2 :: Perm -> Perm
s2 = inverse
s3 :: Perm -> Perm
s3 = s1 . r1
d8 :: [Perm -> Perm]
d8 = [r0, r1, r2, r3, s0, s1, s2, s3]
klein4 :: [Perm -> Perm]
klein4 = [r0, r2, s0, s1]
orbit :: [Perm -> Perm] -> Perm -> [Perm]
orbit fs x = nubSort [ f x | f <- fs ]
symmetryClasses :: [Perm -> Perm] -> [Perm] -> [[Perm]]
symmetryClasses _ [] = []
symmetryClasses fs xs@(x:xt) = insert orb $ symmetryClasses fs ys
where
orb = [ w | w <- orbit fs x, w `elem` xs ]
ys = [ y | y <- xt, y `notElem` orb ]
d8Classes :: [Perm] -> [[Perm]]
d8Classes = symmetryClasses d8
klein4Classes :: [Perm] -> [[Perm]]
klein4Classes = symmetryClasses klein4
marshal :: (Ptr CLong -> Ptr CLong -> CLong -> IO ()) -> Perm -> Perm
marshal op w =
unsafePerformIO . unsafeWith w $ \p -> do
let n = size w
unsafeNew n $ \q -> op q p (fromIntegral n)
foreign import ccall unsafe "d8.h inverse" c_inverse
:: Ptr CLong -> Ptr CLong -> CLong -> IO ()
inverse :: Perm -> Perm
inverse = marshal c_inverse
foreign import ccall unsafe "d8.h reverse" c_reverse
:: Ptr CLong -> Ptr CLong -> CLong -> IO ()
reverse :: Perm -> Perm
reverse = marshal c_reverse
foreign import ccall unsafe "d8.h complement" c_complement
:: Ptr CLong -> Ptr CLong -> CLong -> IO ()
complement :: Perm -> Perm
complement = marshal c_complement
rotate :: Perm -> Perm
rotate = r1