From 7a09e8a755c39e651d04abf7be76788f73db36fe Mon Sep 17 00:00:00 2001 From: Anders Claesson Date: Sun, 6 Jul 2014 21:14:50 +0100 Subject: [PATCH] Refactor, and major restructuring of package layout. --- .gitignore | 3 + Math/Perm.hs | 18 ----- Math/Sym.hs => Sym.hs | 12 ++-- {Data => Sym/Internal}/CLongArray.hs | 10 +-- {Data => Sym/Internal}/Size.hs | 2 +- .../Internal.hs => Sym/Internal/SubSeq.hs | 70 ++++--------------- Sym/Internal/Util.hs | 53 ++++++++++++++ {Data => Sym}/Perm.hs | 6 +- {Math => Sym}/Perm/Bijection.hs | 4 +- {Math => Sym}/Perm/Class.hs | 16 ++--- {Math => Sym}/Perm/Component.hs | 6 +- {Math => Sym}/Perm/Constructions.hs | 8 +-- {Math => Sym}/Perm/D8.hs | 14 ++-- {Math => Sym}/Perm/Group.hs | 5 +- {Math => Sym}/Perm/MeshPattern.hs | 40 +++++------ Sym/Perm/Meta.hs | 18 +++++ {Math => Sym}/Perm/Pattern.hs | 24 +++---- {Data => Sym/Perm}/SSYT.hs | 4 +- {Math => Sym}/Perm/Simple.hs | 4 +- {Math => Sym}/Perm/Sort.hs | 4 +- {Math => Sym}/Perm/Stat.hs | 10 +-- {Data => Sym}/Permgram.hs | 6 +- sym.cabal | 48 +++++++------ util/migrate-to-0.11.sed | 22 ++++++ 24 files changed, 220 insertions(+), 187 deletions(-) delete mode 100644 Math/Perm.hs rename Math/Sym.hs => Sym.hs (95%) rename {Data => Sym/Internal}/CLongArray.hs (92%) rename {Data => Sym/Internal}/Size.hs (85%) rename Data/Perm/Internal.hs => Sym/Internal/SubSeq.hs (53%) create mode 100644 Sym/Internal/Util.hs rename {Data => Sym}/Perm.hs (96%) rename {Math => Sym}/Perm/Bijection.hs (95%) rename {Math => Sym}/Perm/Class.hs (94%) rename {Math => Sym}/Perm/Component.hs (96%) rename {Math => Sym}/Perm/Constructions.hs (92%) rename {Math => Sym}/Perm/D8.hs (93%) rename {Math => Sym}/Perm/Group.hs (96%) rename {Math => Sym}/Perm/MeshPattern.hs (79%) create mode 100644 Sym/Perm/Meta.hs rename {Math => Sym}/Perm/Pattern.hs (88%) rename {Data => Sym/Perm}/SSYT.hs (99%) rename {Math => Sym}/Perm/Simple.hs (92%) rename {Math => Sym}/Perm/Sort.hs (96%) rename {Math => Sym}/Perm/Stat.hs (98%) rename {Data => Sym}/Permgram.hs (97%) create mode 100755 util/migrate-to-0.11.sed diff --git a/.gitignore b/.gitignore index a3a60e4..7d711d4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ cabal-dev *.chi *.chs.h tests/Properties +tests/Test +tests/Test.* +TODO.txt diff --git a/Math/Perm.hs b/Math/Perm.hs deleted file mode 100644 index fd1b83d..0000000 --- a/Math/Perm.hs +++ /dev/null @@ -1,18 +0,0 @@ --- | --- Copyright : Anders Claesson 2013 --- Maintainer : Anders Claesson --- --- A meta module collecting all Perm-modules, except those that are best --- imported \"qualified\". - -module Math.Perm (module P) where - -import Data.Perm as P -import Math.Perm.Class as P -import Math.Perm.Component as P -import Math.Perm.Constructions as P -import Math.Perm.Bijection as P -import Math.Perm.Group as P -import Math.Perm.Pattern as P -import Math.Perm.Simple as P -import Math.Perm.Sort as P diff --git a/Math/Sym.hs b/Sym.hs similarity index 95% rename from Math/Sym.hs rename to Sym.hs index 4f7ca3d..8899046 100644 --- a/Math/Sym.hs +++ b/Sym.hs @@ -5,7 +5,7 @@ -- Maintainer : Anders Claesson -- -module Math.Sym +module Sym ( Permutation(..) , perms @@ -14,12 +14,12 @@ module Math.Sym ) where import Data.Ord -import Data.SSYT (SSYTPair (..)) -import qualified Data.SSYT as Y +import Sym.Perm.SSYT (SSYTPair (..)) +import qualified Sym.Perm.SSYT as Y import Data.List -import Math.Perm (Perm) -import qualified Math.Perm as P -import qualified Math.Perm.D8 as D8 +import Sym.Perm.Meta (Perm) +import qualified Sym.Perm.Meta as P +import qualified Sym.Perm.D8 as D8 -- The permutation typeclass diff --git a/Data/CLongArray.hs b/Sym/Internal/CLongArray.hs similarity index 92% rename from Data/CLongArray.hs rename to Sym/Internal/CLongArray.hs index 49529e6..b152432 100644 --- a/Data/CLongArray.hs +++ b/Sym/Internal/CLongArray.hs @@ -6,7 +6,7 @@ -- -- Convenience functions for dealing with arrays of 'CLong's. -module Data.CLongArray +module Sym.Internal.CLongArray ( -- * Data type CLongArray @@ -32,7 +32,7 @@ module Data.CLongArray ) where import Data.Ord -import Data.Size +import Sym.Internal.Size import Foreign import Foreign.C.Types import GHC.Base @@ -89,8 +89,8 @@ toList w = map fromIntegral . inlinePerformIO . unsafeWith w $ peekArray (size w -- size of the array. slice :: [Int] -> CLongArray -> [CLongArray] slice ks w - | any (<=0) ks = error "Data.CLongArray.slice: zero or negative parts" - | sum ks /= size w = error "Data.CLongArray.slice: parts doesn't sum to size of array" + | any (<=0) ks = error "Sym.Internal.CLongArray.slice: zero or negative parts" + | sum ks /= size w = error "Sym.Internal.CLongArray.slice: parts doesn't sum to size of array" | otherwise = unsafeSlice ks w -- | Like 'slice' but without range checking. @@ -112,7 +112,7 @@ at :: CLongArray -> Int -> Int at w i = let n = size w in if i < 0 || i >= n - then error $ "Data.CLongArray.at: " ++ show i ++ " not in [0.." ++ show (n-1) ++ "]" + then error $ "Sym.Internal.CLongArray.at: " ++ show i ++ " not in [0.." ++ show (n-1) ++ "]" else unsafeAt w i {-# INLINE at #-} diff --git a/Data/Size.hs b/Sym/Internal/Size.hs similarity index 85% rename from Data/Size.hs rename to Sym/Internal/Size.hs index e3e44d3..de3526c 100644 --- a/Data/Size.hs +++ b/Sym/Internal/Size.hs @@ -1,4 +1,4 @@ -module Data.Size (Size (..)) where +module Sym.Internal.Size (Size (..)) where import qualified Data.Set as Set diff --git a/Data/Perm/Internal.hs b/Sym/Internal/SubSeq.hs similarity index 53% rename from Data/Perm/Internal.hs rename to Sym/Internal/SubSeq.hs index ccbed96..08a1d90 100644 --- a/Data/Perm/Internal.hs +++ b/Sym/Internal/SubSeq.hs @@ -5,65 +5,21 @@ -- Maintainer : Anders Claesson -- -module Data.Perm.Internal +module Sym.Internal.SubSeq ( - Set - , normalize - , subsets - , minima - , maxima - , powerset - , kSubsets + module Sym.Internal.CLongArray + , SubSeq + , choose ) where -import Data.List -import Data.Ord -import qualified Data.Set as S -import Data.CLongArray +import Sym.Internal.CLongArray import Foreign import Foreign.C.Types import System.IO.Unsafe - --- | A set is represented by an increasing array of non-negative +-- | A SubSeq is represented by an increasing array of non-negative -- integers. -type Set = CLongArray - - --- Utils --- ----- - --- | Sort and remove duplicates. -normalize :: Ord a => [a] -> [a] -normalize = map head . group . sort - --- | The set of minimal elements with respect to inclusion. -minima :: Ord a => [S.Set a] -> [S.Set a] -minima = minima' . sortBy (comparing S.size) - where - minima' [] = [] - minima' (x:xs) = x : minima' [ y | y<-xs, not (S.isSubsetOf x y) ] - --- | The set of maximal elements with respect to the given order. -maxima :: Ord a => [S.Set a] -> [S.Set a] -maxima = maxima' . sortBy (comparing $ \x -> -S.size x) - where - maxima' [] = [] - maxima' (x:xs) = x : maxima' [ y | y<-xs, not (S.isSubsetOf y x) ] - -kSubsets :: Ord a => Int -> S.Set a -> [S.Set a] -kSubsets 0 _ = [ S.empty ] -kSubsets k s = if S.null s - then [] - else let (x, t) = S.deleteFindMin s - in kSubsets k t ++ map (S.insert x) (kSubsets (k-1) t) - -powerset :: Ord a => S.Set a -> [S.Set a] -powerset s = if S.null s - then [s] - else let (x, t) = S.deleteFindMin s - ts = powerset t - in ts ++ map (S.insert x) ts +type SubSeq = CLongArray -- Bitmasks -- -------- @@ -73,12 +29,12 @@ class (Bits a, Integral a) => Bitmask a where -- | Lexicographically, the next bitmask with the same Hamming weight. next :: a -> a - -- | @ones k m@ is the set of indices whose bits are set in - -- @m@. Default implementation: + -- | @ones k m@ is the set / subsequence of indices whose bits are + -- set in @m@. Default implementation: -- -- > ones m = fromListN (popCount m) $ filter (testBit m) [0..] -- - ones :: a -> CLongArray + ones :: a -> SubSeq ones m = fromList . take (popCount m) $ filter (testBit m) [0..] instance Bitmask CLong where @@ -97,10 +53,10 @@ bitmasks n k = take binomial (iterate next ((1 `shiftL` k) - 1)) k' = toInteger k binomial = fromIntegral $ product [n', n'-1 .. n'-k'+1] `div` product [1..k'] --- | @subsets n k@ is the list of subsets of @[0..n-1]@ with @k@ +-- | @n \`choose\` k@ is the list of subsequences of @[0..n-1]@ with @k@ -- elements. -subsets :: Int -> Int -> [Set] -subsets n k +choose :: Int -> Int -> [SubSeq] +choose n k | n <= 32 = map ones (bitmasks n k :: [CLong]) | otherwise = map ones (bitmasks n k :: [Integer]) diff --git a/Sym/Internal/Util.hs b/Sym/Internal/Util.hs new file mode 100644 index 0000000..42f9932 --- /dev/null +++ b/Sym/Internal/Util.hs @@ -0,0 +1,53 @@ +-- | +-- Copyright : Anders Claesson 2014 +-- Maintainer : Anders Claesson +-- + +module Sym.Internal.Util + ( + minima + , maxima + , kSubsets + , powerset + , nubSort + ) where + +import Data.List +import Data.Ord +import Data.Set (Set) +import qualified Data.Set as S + +-- | The set of minimal elements with respect to inclusion. +minima :: Ord a => [Set a] -> [Set a] +minima = minima' . sortBy (comparing S.size) + where + minima' [] = [] + minima' (x:xs) = x : minima' [ y | y<-xs, not (x `S.isSubsetOf` y) ] + +-- | The set of maximal elements with respect to the given order. +maxima :: Ord a => [Set a] -> [Set a] +maxima = maxima' . sortBy (comparing $ \x -> -S.size x) + where + maxima' [] = [] + maxima' (x:xs) = x : maxima' [ y | y<-xs, not (y `S.isSubsetOf` x) ] + +-- | A list of all k element subsets of the given set. +kSubsets :: Ord a => Int -> Set a -> [Set a] +kSubsets 0 _ = [ S.empty ] +kSubsets k s + | S.null s = [] + | otherwise = kSubsets k t ++ map (S.insert x) (kSubsets (k-1) t) + where + (x,t) = S.deleteFindMin s + +-- | A list of all subsets of the given set. +powerset :: Ord a => Set a -> [Set a] +powerset s + | S.null s = [s] + | otherwise = ts ++ map (S.insert x) ts + where + (x,t) = S.deleteFindMin s; ts = powerset t + +-- | Sort and remove duplicates. +nubSort :: Ord a => [a] -> [a] +nubSort = map head . group . sort diff --git a/Data/Perm.hs b/Sym/Perm.hs similarity index 96% rename from Data/Perm.hs rename to Sym/Perm.hs index f0d7af5..1a92443 100644 --- a/Data/Perm.hs +++ b/Sym/Perm.hs @@ -6,9 +6,9 @@ -- -- Generating permutations: rank and unrank -module Data.Perm +module Sym.Perm ( - module Data.CLongArray + module Sym.Internal.CLongArray , Perm , emptyperm , one @@ -21,7 +21,7 @@ module Data.Perm ) where import Data.List -import Data.CLongArray +import Sym.Internal.CLongArray import Foreign import Foreign.C.Types import System.IO.Unsafe diff --git a/Math/Perm/Bijection.hs b/Sym/Perm/Bijection.hs similarity index 95% rename from Math/Perm/Bijection.hs rename to Sym/Perm/Bijection.hs index 49c9dc2..cfe45b9 100644 --- a/Math/Perm/Bijection.hs +++ b/Sym/Perm/Bijection.hs @@ -5,13 +5,13 @@ -- Maintainer : Anders Claesson -- -module Math.Perm.Bijection +module Sym.Perm.Bijection ( simionSchmidt , simionSchmidt' ) where -import Data.Perm +import Sym.Perm import Foreign import Foreign.C.Types import System.IO.Unsafe diff --git a/Math/Perm/Class.hs b/Sym/Perm/Class.hs similarity index 94% rename from Math/Perm/Class.hs rename to Sym/Perm/Class.hs index 90e646b..8609afe 100644 --- a/Math/Perm/Class.hs +++ b/Sym/Perm/Class.hs @@ -3,7 +3,7 @@ -- Maintainer : Anders Claesson -- -module Math.Perm.Class +module Sym.Perm.Class ( inc , dec @@ -32,12 +32,12 @@ module Math.Perm.Class , fibonacci ) where -import Data.Perm -import Math.Perm.Bijection -import Math.Perm.Constructions -import Data.Perm.Internal -import Math.Perm.Pattern -import qualified Math.Perm.D8 as D8 +import Sym.Internal.Util +import Sym.Perm +import Sym.Perm.Bijection +import Sym.Perm.Constructions +import Sym.Perm.Pattern +import qualified Sym.Perm.D8 as D8 -- | The class of increasing permutations. inc :: Int -> [Perm] @@ -137,7 +137,7 @@ lt :: Int -> [Perm] lt = map D8.reverse . gt union :: [Int -> [Perm]] -> Int -> [Perm] -union cs n = normalize $ concat [ c n | c <- cs ] +union cs n = nubSort $ concat [ c n | c <- cs ] -- | The union of 'vee', 'caret', 'gt' and 'lt'. wedges :: Int -> [Perm] diff --git a/Math/Perm/Component.hs b/Sym/Perm/Component.hs similarity index 96% rename from Math/Perm/Component.hs rename to Sym/Perm/Component.hs index e6f1fbe..acd6722 100644 --- a/Math/Perm/Component.hs +++ b/Sym/Perm/Component.hs @@ -5,7 +5,7 @@ -- Components of permutations. -- -module Math.Perm.Component +module Sym.Perm.Component ( components , skewComponents @@ -17,8 +17,8 @@ module Math.Perm.Component import Foreign import System.IO.Unsafe -import Data.Perm -import qualified Math.Perm.D8 as D8 +import Sym.Perm +import qualified Sym.Perm.D8 as D8 -- Positions /i/ such that /max{ w[j] : j <= i } = i/. These positions -- mark the boundaries of components. diff --git a/Math/Perm/Constructions.hs b/Sym/Perm/Constructions.hs similarity index 92% rename from Math/Perm/Constructions.hs rename to Sym/Perm/Constructions.hs index 9ff2bd5..40732a2 100644 --- a/Math/Perm/Constructions.hs +++ b/Sym/Perm/Constructions.hs @@ -5,7 +5,7 @@ -- Sum, skew sum, etc -- -module Math.Perm.Constructions +module Sym.Perm.Constructions ( (/+/) , (\-\) @@ -17,9 +17,9 @@ module Math.Perm.Constructions import Foreign import System.IO.Unsafe import Control.Monad -import Data.Perm -import qualified Data.Permgram as G -import qualified Math.Perm.D8 as D8 +import Sym.Perm +import qualified Sym.Permgram as G +import qualified Sym.Perm.D8 as D8 infixl 6 /+/ infixl 6 \-\ diff --git a/Math/Perm/D8.hs b/Sym/Perm/D8.hs similarity index 93% rename from Math/Perm/D8.hs rename to Sym/Perm/D8.hs index 0045a35..ecbb2bd 100644 --- a/Math/Perm/D8.hs +++ b/Sym/Perm/D8.hs @@ -5,7 +5,7 @@ -- Maintainer : Anders Claesson -- -module Math.Perm.D8 +module Sym.Perm.D8 ( -- * The group elements r0, r1, r2, r3 @@ -26,11 +26,11 @@ module Math.Perm.D8 , inverse ) where -import Data.List hiding (reverse) -import Prelude hiding (reverse) -import Data.Perm -import Data.Perm.Internal -import Foreign hiding (complement, rotate) +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 @@ -94,7 +94,7 @@ klein4 = [r0, r2, s0, s1] -- > orbit klein4 "2314" == ["1423","2314","3241","4132"] -- orbit :: [Perm -> Perm] -> Perm -> [Perm] -orbit fs x = normalize [ f x | f <- fs ] +orbit fs x = nubSort [ f x | f <- fs ] -- | @symmetryClasses fs xs@ is the list of equivalence classes under -- the action of the /group/ of functions @fs@. diff --git a/Math/Perm/Group.hs b/Sym/Perm/Group.hs similarity index 96% rename from Math/Perm/Group.hs rename to Sym/Perm/Group.hs index b0e0ff8..b99f991 100644 --- a/Math/Perm/Group.hs +++ b/Sym/Perm/Group.hs @@ -5,18 +5,17 @@ -- Maintainer : Anders Claesson -- -module Math.Perm.Group +module Sym.Perm.Group ( compose , act ) where -import Data.Perm +import Sym.Perm import Foreign import Foreign.C.Types import System.IO.Unsafe - marshal :: (Ptr CLong -> Ptr CLong -> CLong -> Ptr CLong -> CLong -> IO ()) -> Perm -> Perm -> Perm marshal op u v = diff --git a/Math/Perm/MeshPattern.hs b/Sym/Perm/MeshPattern.hs similarity index 79% rename from Math/Perm/MeshPattern.hs rename to Sym/Perm/MeshPattern.hs index e45ce5c..bb3c199 100644 --- a/Math/Perm/MeshPattern.hs +++ b/Sym/Perm/MeshPattern.hs @@ -3,9 +3,9 @@ -- Maintainer : Anders Claesson -- --- TODO: Generalize interface and share with Math.Perm.Pattern +-- TODO: Generalize interface and share with Sym.Perm.Pattern -module Math.Perm.MeshPattern +module Sym.Perm.MeshPattern ( MeshPattern (..) , Mesh , Box @@ -25,18 +25,17 @@ module Math.Perm.MeshPattern , avoiders , kVincular , vincular - , kBivincular , bivincular , meshPatterns ) where import Data.List hiding (union) -import Data.Size -import Data.Perm.Internal hiding (Set) -import qualified Data.Perm.Internal as I +import Sym.Internal.Size +import Sym.Perm +import Sym.Internal.SubSeq import Data.Set (Set) import qualified Data.Set as Set -import Data.Perm +import Sym.Internal.Util type Point = (Int, Int) type Box = (Int, Int) @@ -76,24 +75,21 @@ box :: Box -> MeshPattern -> MeshPattern box xy = mesh [xy] kVincular :: Int -> Perm -> [MeshPattern] -kVincular k w = (\xs -> cols (toList xs) (pattern w)) `fmap` subsets (1+size w) k +kVincular k w = (flip cols (pattern w) . toList) `fmap` ((1+size w) `choose` k) +-- kVincular k w = (\xs -> cols (toList xs) (pattern w)) `fmap` ((1+size w) `choose` k) vincular :: Perm -> [MeshPattern] vincular w = [0..1+size w] >>= flip kVincular w --- WRONG!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -kBivincular :: Int -> Perm -> [MeshPattern] -kBivincular k w = - [ rows (toList ys) $ cols (toList xs) (pattern w) | xs <- sets, ys <- sets ] - where - n = size w - sets = subsets (n+1) k - bivincular :: Perm -> [MeshPattern] -bivincular w = [0..1+size w] >>= flip kBivincular w +bivincular w = + [ foldr ((.) . either col row) id c $ pattern w | c <- choices ] + where + choices = powerset' $ [0..size w] >>= \z -> [Left z, Right z] + powerset' = fmap Set.toList . powerset . Set.fromList fullMesh :: Int -> Mesh -fullMesh n = Set.fromList [ (x,y) | x <- range, y <- range ] where range = [0..n] +fullMesh n = let zs = [0..n] in Set.fromList [ (x,y) | x <- zs, y <- zs ] meshPatterns :: Perm -> [MeshPattern] meshPatterns w = [ MP w r | r <- powerset (fullMesh (size w)) ] @@ -111,7 +107,7 @@ match' (MP u r) v w = -- | @match p w m@ determines whether the subword in @w@ specified by -- @m@ is an occurrence of @p@. -match :: MeshPattern -> Perm -> I.Set -> Bool +match :: MeshPattern -> Perm -> SubSeq -> Bool match p w m = match' p v w' where w' = twoLine w @@ -121,8 +117,8 @@ twoLine :: Perm -> PermTwoLine twoLine = zip [1..] . map (+1) . toList -- | @copiesOf p w@ is the list of sets that represent copies of @p@ in @w@. -copiesOf :: MeshPattern -> Perm -> [I.Set] -copiesOf p w = filter (match p w) $ subsets (size w) (size p) +copiesOf :: MeshPattern -> Perm -> [SubSeq] +copiesOf p w = filter (match p w) $ size w `choose` size p {-# INLINE copiesOf #-} -- | @w `contains` p@ is a predicate determining if @w@ contains the pattern @p@. @@ -151,5 +147,5 @@ avoiders1 q vs@(v:_) = filter avoids_q us ++ filter (`avoids` q) ws n = size v k = size q (us, ws) = span (\u -> size u == n) vs - xs = subsets n k + xs = n `choose` k avoids_q u = not $ any (match q u) xs diff --git a/Sym/Perm/Meta.hs b/Sym/Perm/Meta.hs new file mode 100644 index 0000000..c149609 --- /dev/null +++ b/Sym/Perm/Meta.hs @@ -0,0 +1,18 @@ +-- | +-- Copyright : Anders Claesson 2013 +-- Maintainer : Anders Claesson +-- +-- A meta module collecting all Perm-modules, except those that are best +-- imported \"qualified\". + +module Sym.Perm.Meta (module P) where + +import Sym.Perm as P +import Sym.Perm.Class as P +import Sym.Perm.Component as P +import Sym.Perm.Constructions as P +import Sym.Perm.Bijection as P +import Sym.Perm.Group as P +import Sym.Perm.Pattern as P +import Sym.Perm.Simple as P +import Sym.Perm.Sort as P diff --git a/Math/Perm/Pattern.hs b/Sym/Perm/Pattern.hs similarity index 88% rename from Math/Perm/Pattern.hs rename to Sym/Perm/Pattern.hs index e88bbcc..5b60d17 100644 --- a/Math/Perm/Pattern.hs +++ b/Sym/Perm/Pattern.hs @@ -5,12 +5,12 @@ -- Maintainer : Anders Claesson -- -module Math.Perm.Pattern +module Sym.Perm.Pattern ( Pattern - , Set + , SubSeq , ordiso - , subsets + , choose , copiesOf , contains , avoids @@ -21,9 +21,9 @@ module Math.Perm.Pattern , coeff ) where -import Data.Perm (Perm, perms) -import Data.Perm.Internal hiding (minima, maxima) -import Data.CLongArray +import Sym.Perm (Perm, perms) +import Sym.Internal.SubSeq +import Sym.Internal.Util (nubSort) import Foreign import Foreign.C.Types import System.IO.Unsafe @@ -36,7 +36,7 @@ foreign import ccall unsafe "ordiso.h ordiso" c_ordiso -- | @ordiso u v m@ determines whether the subword in @v@ specified by -- @m@ is order isomorphic to @u@. -ordiso :: Perm -> Perm -> Set -> Bool +ordiso :: Pattern -> Perm -> SubSeq -> Bool ordiso u v m = let k = fromIntegral (size u) in unsafeDupablePerformIO $ @@ -47,8 +47,8 @@ ordiso u v m = {-# INLINE ordiso #-} -- | @copiesOf p w@ is the list of sets that represent copies of @p@ in @w@. -copiesOf :: Pattern -> Perm -> [Set] -copiesOf p w = filter (ordiso p w) $ subsets (size w) (size p) +copiesOf :: Pattern -> Perm -> [SubSeq] +copiesOf p w = filter (ordiso p w) $ size w `choose` size p {-# INLINE copiesOf #-} -- | @w `contains` p@ is a predicate determining if @w@ contains the pattern @p@. @@ -77,21 +77,21 @@ avoiders1 q vs@(v:_) = filter avoids_q us ++ filter (`avoids` q) ws n = size v k = size q (us, ws) = span (\u -> size u == n) vs - xs = subsets n k + xs = n `choose` k avoids_q u = not $ any (ordiso q u) xs -- | The set of minimal elements with respect to containment. FIX: Poor -- implementation minima :: [Pattern] -> [Pattern] minima [] = [] -minima ws = let (v:vs) = normalize ws +minima ws = let (v:vs) = nubSort ws in v : minima (avoiders [v] vs) -- | The set of maximal elements with respect to containment. FIX: Poor -- implementation maxima :: [Pattern] -> [Pattern] maxima [] = [] -maxima ws = let (v:vs) = reverse $ normalize ws +maxima ws = let (v:vs) = reverse $ nubSort ws in v : maxima (filter (avoids v) vs) -- | @coeff f v@ is the coefficient of @v@ when expanding the diff --git a/Data/SSYT.hs b/Sym/Perm/SSYT.hs similarity index 99% rename from Data/SSYT.hs rename to Sym/Perm/SSYT.hs index 6a2d31a..b1e9d22 100644 --- a/Data/SSYT.hs +++ b/Sym/Perm/SSYT.hs @@ -9,7 +9,7 @@ -- words, this module implements the Robinson-Schensted-Knuth (RSK) -- correspondence. -module Data.SSYT +module Sym.Perm.SSYT ( GeneralizedPerm , Entry @@ -27,7 +27,7 @@ module Data.SSYT import Prelude hiding (null) import Data.List hiding (null) -import Data.Perm +import Sym.Perm type Row = Int diff --git a/Math/Perm/Simple.hs b/Sym/Perm/Simple.hs similarity index 92% rename from Math/Perm/Simple.hs rename to Sym/Perm/Simple.hs index 904ffe7..e3b8592 100644 --- a/Math/Perm/Simple.hs +++ b/Sym/Perm/Simple.hs @@ -5,12 +5,12 @@ -- Maintainer : Anders Claesson -- -module Math.Perm.Simple +module Sym.Perm.Simple ( simple ) where -import Data.Perm +import Sym.Perm import Foreign import Foreign.C.Types import System.IO.Unsafe diff --git a/Math/Perm/Sort.hs b/Sym/Perm/Sort.hs similarity index 96% rename from Math/Perm/Sort.hs rename to Sym/Perm/Sort.hs index d252273..2700fc6 100644 --- a/Math/Perm/Sort.hs +++ b/Sym/Perm/Sort.hs @@ -5,13 +5,13 @@ -- Maintainer : Anders Claesson -- -module Math.Perm.Sort +module Sym.Perm.Sort ( stackSort , bubbleSort ) where -import Data.Perm +import Sym.Perm import Foreign import Foreign.C.Types import System.IO.Unsafe diff --git a/Math/Perm/Stat.hs b/Sym/Perm/Stat.hs similarity index 98% rename from Math/Perm/Stat.hs rename to Sym/Perm/Stat.hs index b09d761..a3b6018 100644 --- a/Math/Perm/Stat.hs +++ b/Sym/Perm/Stat.hs @@ -7,10 +7,10 @@ -- Common permutation statistics. To avoid name clashes this module is -- best imported @qualified@; e.g. -- --- > import qualified Math.Perm.Stat as S +-- > import qualified Sym.Perm.Stat as S -- -module Math.Perm.Stat +module Sym.Perm.Stat ( asc -- ascents , des -- descents @@ -48,9 +48,9 @@ module Math.Perm.Stat import Prelude hiding (head, last) import qualified Prelude -import Data.Perm -import qualified Data.SSYT as Y -import qualified Math.Perm.D8 as D8 +import Sym.Perm +import qualified Sym.Perm.SSYT as Y +import qualified Sym.Perm.D8 as D8 import Foreign.Ptr import Foreign.C.Types import System.IO.Unsafe diff --git a/Data/Permgram.hs b/Sym/Permgram.hs similarity index 97% rename from Data/Permgram.hs rename to Sym/Permgram.hs index c5caae0..a526d36 100644 --- a/Data/Permgram.hs +++ b/Sym/Permgram.hs @@ -4,7 +4,7 @@ -- -- Permutation diagrams, or permutations as monads. -module Data.Permgram +module Sym.Permgram ( -- * Data types Label @@ -22,8 +22,8 @@ module Data.Permgram import Data.Ord import Data.List -import Data.Perm (Perm) -import qualified Data.Perm as P +import Sym.Perm (Perm) +import qualified Sym.Perm as P import Data.Array.Unboxed -- | The purpose of this data type is to assign labels to the indices of diff --git a/sym.cabal b/sym.cabal index 6e22924..3dfdf97 100644 --- a/sym.cabal +++ b/sym.cabal @@ -1,5 +1,5 @@ name: sym -version: 0.10 +version: 0.11 synopsis: Permutations, patterns, and statistics description: Definitions for permutations with an emphasis on permutation @@ -19,28 +19,32 @@ source-repository head location: git://github.com/akc/sym.git library - exposed-modules: Data.CLongArray - Data.Perm - Data.Perm.Internal - Data.Permgram - Data.SSYT - Data.Size - Math.Perm - Math.Perm.Component - Math.Perm.Constructions - Math.Perm.D8 - Math.Perm.Group - Math.Perm.Bijection - Math.Perm.Stat - Math.Perm.Sort - Math.Perm.Simple - Math.Perm.Pattern - Math.Perm.MeshPattern - Math.Perm.Class - Math.Sym + exposed-modules: Sym + Sym.Perm + Sym.Perm.Meta + Sym.Perm.SSYT + Sym.Perm.Component + Sym.Perm.Constructions + Sym.Perm.D8 + Sym.Perm.Group + Sym.Perm.Bijection + Sym.Perm.Stat + Sym.Perm.Sort + Sym.Perm.Simple + Sym.Perm.Pattern + Sym.Perm.MeshPattern + Sym.Perm.Class + Sym.Permgram + Sym.Internal.SubSeq + Sym.Internal.CLongArray + Sym.Internal.Size + Sym.Internal.Util - build-depends: base >= 3 && <= 4.7, array >=0.4, hashable >=1.1, - QuickCheck >=2.5, containers + build-depends: base >= 3 && <= 4.7, + array >=0.4, + hashable >=1.1, + containers, + QuickCheck >=2.5 ghc-prof-options: -auto-all ghc-options: -Wall diff --git a/util/migrate-to-0.11.sed b/util/migrate-to-0.11.sed new file mode 100755 index 0000000..e41f11c --- /dev/null +++ b/util/migrate-to-0.11.sed @@ -0,0 +1,22 @@ +s/Data.Set.Util/Sym.Internal.Util/g +s/Data.CLongArray.SubSeq/Sym.Internal.SubSeq/g +s/Data.CLongArray.Perm/Sym.Perm/g +s/Data.Size/Sym.Internal.Size/g +s/Data.CLongArray/Sym.Internal.CLongArray/g +s/Data.List.Util/Sym.Internal.Util/g +s/Data.SSYT/Sym.Perm.SSYT/g +s/Data.Perm.Internal/Sym.Internal.Util/g +s/Data.Perm/Sym.Perm/g +s/Math.Permgram/Sym.Permgram/g +s/Math.Perm.Bijection/Sym.Perm.Bijection/g +s/Math.Perm.Class/Sym.Perm.Class/g +s/Math.Perm.Component/Sym.Perm.Component/g +s/Math.Perm.Constructions/Sym.Perm.Constructions/g +s/Math.Perm.D8/Sym.Perm.D8/g +s/Math.Perm.Group/Sym.Perm.Group/g +s/Math.Perm.MeshPattern/Sym.Perm.MeshPattern/g +s/Math.Perm.Pattern/Sym.Perm.Pattern/g +s/Math.Perm.Sort/Sym.Perm.Sort/g +s/Math.Perm.Stat/Sym.Perm.Stat/g +s/Math.Perm/Sym.Perm.Meta/g +s/Math.Sym/Sym/g