packages feed

sym 0.5 → 0.5.1

raw patch · 4 files changed

+112/−6 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Math.Sym: cast :: (Perm a, Perm b) => a -> b
+ Math.Sym: empty :: StPerm
+ Math.Sym: one :: StPerm
+ Math.Sym.Class: av231 :: Int -> [StPerm]
+ Math.Sym.Class: gt :: Int -> [StPerm]
+ Math.Sym.Class: lt :: Int -> [StPerm]
+ Math.Sym.Class: vee :: Int -> [StPerm]
+ Math.Sym.Class: vorb :: Int -> [StPerm]
+ Math.Sym.Class: wedge :: Int -> [StPerm]

Files

Math/Sym.hs view
@@ -15,6 +15,8 @@     (     -- * Standard permutations       StPerm+    , empty+    , one     , toVector     , fromVector     , toList@@ -27,9 +29,10 @@     -- * The permutation typeclass     , Perm (..) -    -- * Generalize and normalize+    -- * Generalize, normalize and cast     , generalize     , normalize+    , cast      -- * Generating permutations     , unrankPerm@@ -108,6 +111,15 @@           u' = toVector u           v' = SV.map ( + size u) $ toVector v ++-- | The empty permutation.+empty :: StPerm+empty = StPerm SV.empty++-- | The one letter permutation.+one :: StPerm+one = StPerm $ SV.singleton 0+ -- | Convert a standard permutation to a vector. toVector :: StPerm -> Vector Int toVector = perm0@@ -274,8 +286,8 @@     idperm n   = [1..n]  --- Generalize and normalize--- ------------------------+-- Generalize, normalize and cast+-- ------------------------------  -- | Generalize a function on 'StPerm' to a function on any permutations: -- @@ -292,6 +304,11 @@     where       ys = map st xs       n = maximum $ map size ys++-- | Cast a permutation of one type to another+cast :: (Perm a, Perm b) => a -> b+cast w = st w `act` idperm (size w)+  -- Generating permutations -- -----------------------
+ Math/Sym/Class.hs view
@@ -0,0 +1,64 @@+-- |+-- Module      : Math.Sym.Class+-- Copyright   : (c) Anders Claesson 2012+-- License     : BSD-style+-- Maintainer  : Anders Claesson <anders.claesson@gmail.com>+-- +-- A permutation class is a downset in the poset of permutations+-- ordered by containment. This module provides definitions of some+-- common classes.++module Math.Sym.Class+    (+     av231, vee, wedge, gt, lt, vorb+    ) where++import Data.Monoid ((<>))+import Math.Sym (empty, one, (/-/), StPerm, normalize)+import Math.Sym.D8 as D8++-- | Av(231); also know as the stack sortable permutations.+av231 :: Int -> [StPerm]+av231 0 = [empty]+av231 n = do+  k <- [0..n-1]+  s <- streamAv231 !! k+  t <- streamAv231 !! (n-k-1)+  return $ s <> (one /-/ t)++streamAv231 :: [[StPerm]]+streamAv231 = map av231 [0..]++-- | The V-class is Av(132, 231). It is so named because the diagram+-- of a typical permutation in this class is shaped like a V.+vee :: Int -> [StPerm]+vee = (streamVee !!)++streamVee :: [[StPerm]]+streamVee = [empty] : [one] : zipWith (++) vee_n n_vee+    where+      n_vee = (map.map) (one /-/) ws+      vee_n = (map.map) ( <> one) ws+      ws    = tail streamVee++-- | The ∧-class is Av(213, 312). It is so named because the diagram+-- of a typical permutation in this class is shaped like a wedge.+wedge :: Int -> [StPerm]+wedge = map D8.complement . vee++-- | The >-class is Av(132, 312). It is so named because the diagram+-- of a typical permutation in this class is shaped like a >.+gt :: Int -> [StPerm]+gt = map D8.rotate . vee++-- | The <-class is Av(213, 231). It is so named because the diagram+-- of a typical permutation in this class is shaped like a <.+lt :: Int -> [StPerm]+lt = map D8.reverse . gt++union :: [Int -> [StPerm]] -> Int -> [StPerm]+union cs n = normalize $ concat [ c n | c <- cs ]++-- | The union of 'vee', 'wedge', 'gt' and 'lt'; the orbit of a V under rotation+vorb :: Int -> [StPerm]+vorb = union [vee, wedge, gt, lt]
sym.cabal view
@@ -1,5 +1,5 @@ Name:                sym-Version:             0.5+Version:             0.5.1 Synopsis:            Permutations, patterns, and statistics Description:            Definitions for permutations with an emphasis on permutation@@ -36,6 +36,7 @@   Exposed-modules:     Math.Sym                        Math.Sym.D8                        Math.Sym.Stat+                       Math.Sym.Class                        Math.Sym.Internal    Build-depends:       base >= 3 && < 5, random, vector
tests/Properties.hs view
@@ -11,6 +11,7 @@ import qualified Math.Sym as Sym import qualified Math.Sym.D8 as D8 import qualified Math.Sym.Stat as S+import qualified Math.Sym.Class as C import qualified Math.Sym.Internal as I import qualified Data.Vector.Storable as SV import Test.QuickCheck@@ -674,9 +675,32 @@     ]  ---------------------------------------------------------------------------------+-- Properties for Math.Sym.Class+---------------------------------------------------------------------------------++prop_agrees_with_basis bs cls m =+    and [ sort (Sym.av (map Sym.st bs) n) == sort (cls n) | n<-[0..m] ]++prop_av231 = prop_agrees_with_basis ["231"]        C.av231 7+prop_vee   = prop_agrees_with_basis ["132", "231"] C.vee   7+prop_wedge = prop_agrees_with_basis ["213", "312"] C.wedge 7+prop_gt    = prop_agrees_with_basis ["132", "312"] C.gt    7+prop_lt    = prop_agrees_with_basis ["213", "231"] C.lt    7++testsClass =+    [ ("av231",        check prop_av231)+    , ("vee",          check prop_vee)+    , ("wedge",        check prop_wedge)+    , ("gt",           check prop_gt)+    , ("lt",           check prop_lt)+    ]++--------------------------------------------------------------------------------- -- Main --------------------------------------------------------------------------------- -tests = testsPerm ++ testsD8 ++ testsStat+tests = testsPerm ++ testsD8 ++ testsStat ++ testsClass -main = mapM_ (\(name, t) -> putStr (name ++ ":\t") >> t) tests+runTests = mapM_ (\(name, t) -> putStr (name ++ ":\t") >> t)++main = runTests tests