module Sym.Perm.Constructions
(
(/+/)
, (\-\)
, directSum
, skewSum
, inflate
) where
import Foreign
import System.IO.Unsafe
import Control.Monad
import Sym.Perm
import qualified Sym.Permgram as G
import qualified Sym.Perm.D8 as D8
infixl 6 /+/
infixl 6 \-\
(/+/) :: Perm -> Perm -> Perm
(/+/) u v =
let k = size u
l = size v
v' = imap (\_ x -> x + fromIntegral k) v
in unsafePerformIO . unsafeNew (k+l) $ \p ->
let q = advancePtr p k
in unsafeWith u $ \uPtr ->
unsafeWith v' $ \vPtr -> do
copyArray p uPtr k
copyArray q vPtr l
directSum :: [Perm] -> Perm
directSum = foldr (/+/) emptyperm
(\-\) :: Perm -> Perm -> Perm
(\-\) u v = D8.complement $ D8.complement u /+/ D8.complement v
skewSum :: [Perm] -> Perm
skewSum = foldr (\-\) emptyperm
inflate :: Perm -> [Perm] -> Perm
inflate w = G.perm . join . G.permgram w . map (`G.permgram` [()])