packages feed

phonetic-languages-constraints-array 0.3.0.0 → 0.4.0.0

raw patch · 4 files changed

+35/−7 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Phladiprelio.Constraints: filterMixedDistanceIJK3 :: (InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) => Int -> Int -> Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int)
+ Phladiprelio.ConstraintsEncoded: M :: a -> a -> a -> EncodedContraints a b

Files

CHANGELOG.md view
@@ -22,3 +22,8 @@ * Third version. Added new types of constraints based on the signed and unsigned distance(s) between two or three elements (encoded with the capital letters V, W, H, R). +## 0.4.0.0 -- 2023-05-15++* Fourth version. Added a new type of constraint based on both signed and unsigned distances+between three elements (encoded with M). Some documentation improvements.+
Phladiprelio/Constraints.hs view
@@ -13,6 +13,9 @@ -- arguments must be in the range [0..n] though these inner constraints are -- not checked. It is up to user to check them. -- Uses arrays instead of vectors.+-- The word \"unsafe\" in the names means that there is no checking whether the arguments are +-- within the elements of the arrays, this checking is intended to be done elsewhere before applying +-- the functions here. Without such a checking the result are meaningless.  {-# LANGUAGE BangPatterns, FlexibleContexts, NoImplicitPrelude #-} @@ -36,6 +39,7 @@   , filterUnsignDistanceIJ   , filterSignDistanceIJK3   , filterUnsignDistanceIJK3+  , filterMixedDistanceIJK3 ) where  import GHC.Base hiding (foldr)@@ -58,6 +62,9 @@   | otherwise = (t,u,n) {-# INLINE helpG #-} +-- | Being given the data satisfying the constraints in the module header checks whether in the+-- 'Array' the distance between positions of the first two arguments values is equal to the signed +-- third argument. unsafeSignDistanceIJ    :: Int    -> Int @@ -71,6 +78,10 @@   | z /= u && z /= t && t >= 0 = (t, u, n + 1)   | otherwise = (-1, u, n) +-- | Being given the data satisfying the constraints in the module header checks whether in the+-- 'Array' the distance between positions of the first two arguments values is equal to the unsigned +-- third argument. The following is true: if 'unsafeSignDistanceIJ' @i@ @j@ @d@ @array@ == 'True' then+-- 'unsafeUnsignDistanceIJ' @i@ @j@ @d@ @array@ == 'True', but not necessarily vice versa.  unsafeUnsignDistanceIJ    :: Int    -> Int @@ -84,26 +95,29 @@   | z /= u && z /= t && t >= 0 = (t, u, n + 1)   | otherwise = (-1, u, n) - -- | Being given the data satisfying the constraints in the module header returns the elements that satisfy 'unsafeOrderIJ' as a predicate. filterOrderIJ :: (InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) => Int -> Int -> t (Array Int Int) -> t (Array Int Int) filterOrderIJ i j = filterG (unsafeOrderIJ i j) --- | +-- | Being given the data satisfying the constraints in the module header returns the elements that satisfy 'unsafeSignDistanceIJ' as a predicate. filterSignDistanceIJ :: (InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) => Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int) filterSignDistanceIJ i j d = filterG (unsafeSignDistanceIJ i j d) --- | +-- | Being given the data satisfying the constraints in the module header returns the elements that satisfy 'unsafeUnsignDistanceIJ' as a predicate. filterUnsignDistanceIJ :: (InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) => Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int) filterUnsignDistanceIJ i j d = filterG (unsafeUnsignDistanceIJ i j d) --- | +-- | Being given the data satisfying the constraints in the module header returns the elements that pairwisely (1 and 2, 2 and 3) satisfy 'unsafeSignDistanceIJ' as a predicate. filterSignDistanceIJK3 :: (InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) => Int -> Int -> Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int) filterSignDistanceIJK3 i j k d1 d2 = filterG (\arr -> unsafeSignDistanceIJ i j d1 arr && unsafeSignDistanceIJ j k d2 arr) --- | +-- | Being given the data satisfying the constraints in the module header returns the elements that pairwisely (1 and 2, 2 and 3) satisfy 'unsafeUnsignDistanceIJ' as a predicate. filterUnsignDistanceIJK3 :: (InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) => Int -> Int -> Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int) filterUnsignDistanceIJK3 i j k d1 d2 = filterG (\arr -> unsafeUnsignDistanceIJ i j d1 arr && unsafeUnsignDistanceIJ j k d2 arr)++-- | Being given the data satisfying the constraints in the module header returns the elements that satisfy both 'unsafeSignDistanceIJ' with the 1st, 2nd and 4th arguments and 'unsafeUnsignDistanceIJ' with the 2nd, 3rd and 5th arguments as predicates.+filterMixedDistanceIJK3 :: (InsertLeft t (Array Int Int), Monoid (t (Array Int Int))) => Int -> Int -> Int -> Int -> Int -> t (Array Int Int) -> t (Array Int Int)+filterMixedDistanceIJK3 i j k d1 d2 = filterG (\arr -> unsafeSignDistanceIJ i j d1 arr && unsafeUnsignDistanceIJ j k d2 arr)  -- | Being given the data satisfying the constraints in the module header reduces the number of further computations in the foldable structure of -- the permutations each one being represented as 'Array' 'Int' 'Int' where the elements are all the numbers in the range [0..n] without duplication if the
Phladiprelio/ConstraintsEncoded.hs view
@@ -50,7 +50,7 @@ import Phladiprelio.Constraints import Data.SubG (InsertLeft(..)) -data EncodedContraints a b = E a | P a b | Q a a a a a | T a a a a | SA a a b | SB a a b | F a a a | V a a | W a a | H a a a | R a a a deriving (Eq, Ord)+data EncodedContraints a b = E a | P a b | Q a a a a a | T a a a a | SA a a b | SB a a b | F a a a | V a a | W a a | H a a a | R a a a | M a a a deriving (Eq, Ord)  -- | Inspired by the: https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-Maybe.html -- Is provided here as a more general way to read the 'String' into a 'EncodedCnstrs' than more restricted@@ -104,6 +104,7 @@        'V' -> if length ts /= 2 then Just (E 0) else let [k,t] = map  (\x -> case (fromJust (readMaybe [x]::Maybe Int)) of {0 -> 9; n -> n - 1}) $ ts in Just . V k $ t        'H' -> if length ts /= 3 then Just (E 0) else let [k,t,w] = map  (\x -> case (fromJust (readMaybe [x]::Maybe Int)) of {0 -> 9; n -> n - 1}) $ ts in Just . H k t $ w         'R' -> if length ts /= 3 then Just (E 0) else let [k,t,w] = map  (\x -> case (fromJust (readMaybe [x]::Maybe Int)) of {0 -> 9; n -> n - 1}) $ ts in Just . R k t $ w +       'M' -> if length ts /= 3 then Just (E 0) else let [k,t,w] = map  (\x -> case (fromJust (readMaybe [x]::Maybe Int)) of {0 -> 9; n -> n - 1}) $ ts in Just . M k t $ w         _   -> Nothing  | otherwise = Nothing @@ -142,6 +143,7 @@ decodeConstraint1 (W i j) = filterUnsignDistanceIJ i j (abs $ j - i) decodeConstraint1 (H i j k) = filterSignDistanceIJK3 i j k (j - i) (k - j) decodeConstraint1 (R i j k) = filterUnsignDistanceIJK3 i j k (abs (j - i)) (abs (k - j))+decodeConstraint1 (M i j k) = filterMixedDistanceIJK3 i j k (j - i) (abs (k - j))  -- | Must be applied to the correct array of permutation indeces. Otherwise, it gives runtime error (exception). All the integers inside the -- 'EncodedCnstrs' must be in the range [0..n] where @n@ corresponds to the maximum element in the permutation 'Array' 'Int' 'Int'. Besides,@@ -201,6 +203,11 @@ isR (R _ _ _) = True isR _ = False +isM :: EncodedCnstrs -> Bool+isM (M _ _ _) = True+isM _ = False++ {-| Works only with the correctly defined argument though it is not checked. Use with this caution. -} getIEl :: EncodedCnstrs -> Int@@ -215,6 +222,7 @@ getIEl (W i _) = i getIEl (H i _ _) = i getIEl (R i _ _) = i+getIEl (M i _ _) = i  {-| Works only with the correctly defined arguments though it is not checked. Use with this caution. -}@@ -230,4 +238,5 @@ setIEl i (W _ j) = W i j setIEl i (H _ j k) = H i j k setIEl i (R _ j k) = R i j k+setIEl i (M _ j k) = M i j k 
phonetic-languages-constraints-array.cabal view
@@ -2,7 +2,7 @@ -- For further documentation, see http://haskell.org/cabal/users-guide/  name:                phonetic-languages-constraints-array-version:             0.3.0.0+version:             0.4.0.0 synopsis:            Constraints to filter the needed permutations description:         Provides several the most important variants of constraints. Can be used with the phonetic-languages-common series of package. Instead of vectors, uses arrays. homepage:            https://hackage.haskell.org/package/phonetic-languages-constraints-array