| Copyright | (c) Erich Gut |
|---|---|
| License | BSD3 |
| Maintainer | zerich.gut@gmail.com |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
OAlg.Entity.Sequence.Permutation
Description
permutations on totally ordered index types i to permute the items of sequences.
Synopsis
- data Permutation i
- pmt :: Ord i => Permutation i -> i -> i
- swap :: (Entity i, Ord i) => i -> i -> Permutation i
- class (Sequence s i x, TotalOpr (Permutation i) (s x)) => PermutableSequence s i x where
- permuteBy :: p i -> (w -> w -> Ordering) -> (x -> w) -> s x -> (s x, Permutation i)
- permuteByN :: PermutableSequence s N x => (w -> w -> Ordering) -> (x -> w) -> s x -> (s x, Permutation N)
- newtype PermutationForm i = PermutationForm (PSequence i i)
- pmf :: Ord i => PermutationForm i -> i -> i
- xPermutation :: (Entity i, Ord i) => N -> X i -> X (Permutation i)
- xPermutationB :: (Ord i, Enum i) => i -> i -> X (Permutation i)
- xPermutationN :: N -> X (Permutation N)
- xMltPermutation :: (Entity i, Ord i) => N -> X i -> XMlt (Permutation i)
- prpPermutation :: Statement
- prpPermutableSequence :: (PermutableSequence s i x, Entity x, Entity i, Show w) => N -> z i -> (w -> w -> Ordering) -> (x -> w) -> X (s x) -> Statement
- prpOprPermutation :: Statement
Permutation
data Permutation i Source #
permutation of a totally ordered index type i which yield a bijection pmt on
i. They are constructed using
makeof avalidPermutationForm, which defines also the validity for the constructed permutation.swapand theMultiplicativestructure for permutations.permuteByforPermutableSequence.xPermutationto generate randomly permutations.
In the following the total right operation <* of a permutation on several types of
sequences will be defined to achieve the permutation of there items.
Definitions
- List
- Let
xsbe in[x]withandConstructableSequence[] r [x]pa permutation in, thenPermutationrxsis given by<*p, wheresqcIndexMapis (pmtp) xsisis the image of the support ofxsunder the inverse ofp. - CSequence
- Let
xsbe inwithCSequencexandConstructableSequenceCSequenceNxpa permutation in, thenPermutationNxsis given by<*p, wheresqcIndexMapis (pmtp) xsisis the image of the support ofxsunder the inverse ofp. - PSequence
- Let
xsbe inwithPSequencei xandConstructableSequence(PSequencei) i xpa permutation in, thenPermutationixsis given by<*p, wheresqcIndexMapis (pmtp) xsisis the image of the support ofxsunder the inverse ofp. - Permutation
- Let
xs,pbe in, thenPermutationixsis given by<*p*.
Note The given definitions are not very efficient and only terminate for finite
sequences (in fact, a more efficient implementation has been chosen that also
terminates for infinite sequences (see example below)). However, they serve on the one
hand to define the semantic and to 'prove' the properties for TotalOpr and on the
other hand to verify the chosen implementation for finite sequences (see
prpOprPermutation).
Examples
>>>"abcdef" <* (swap 2 5 :: Permutation N)"abfdec"
the support of a sequence and the relevant image of a permutation may be disjoint which will leave the sequence untouched
>>>"abcdef" <* (swap 7 10 :: Permutation N)"abcdef"
the intersection of the support of a sequence with the relevant image of a permutation may be a non empty proper sub set
>>>"abcdef" <* swap 2 10 :: Permutation N)"abdefc"
the result can be interpreted as: first, put c at position 10 and Nothing
(which is the item at position 10) at position 2. Second, strip all nothings form it.
Although the given definition of the permutation of sequences dose not terminate for infinite sequences, its implementation will terminate
>>>takeN 5 $ (([0..] :: [N]) <* (swap 1 2 :: Permutation N)[0,2,1,3,4]
Instances
pmt :: Ord i => Permutation i -> i -> i Source #
Permutable
class (Sequence s i x, TotalOpr (Permutation i) (s x)) => PermutableSequence s i x where Source #
total right operations of permutations on sequences, admitting the following properties:
Property Let s, i, x be an instance of
, then holds:PermutableSequence s i x
- Let
xsbe ins x,pinwithPermutationifor someimagez p<<=supportz xszinz i, then holds:(xsfor all<*p)??i==((xs??).pmtp) iiin.supportz xs Let
xsbe ins x,winx -> w,cinw -> w ->andOrderingzinz i, then holds: Let(xs',p) =inpermuteByz c w xs
Examples
>>>fst $ permuteBy nProxy compare isUpper "abCd1eFgH""abd1egCFH"
>>>fst $ permuteBy nProxy (coCompare compare) isUpper "abCd1eFgH""CFHabd1eg"
which orders it in the reverse ordering.
Methods
permuteBy :: p i -> (w -> w -> Ordering) -> (x -> w) -> s x -> (s x, Permutation i) Source #
a resulting permuation.
Instances
| Entity x => PermutableSequence CSequence N x Source # | |
Defined in OAlg.Entity.Sequence.Permutation | |
| (Entity i, Ord i) => PermutableSequence Permutation i i Source # | |
Defined in OAlg.Entity.Sequence.Permutation Methods permuteBy :: p i -> (w -> w -> Ordering) -> (i -> w) -> Permutation i -> (Permutation i, Permutation i) Source # | |
| Entity x => PermutableSequence [] N x Source # | |
Defined in OAlg.Entity.Sequence.Permutation | |
| (Oriented x, Entity p) => PermutableSequence (Dim x) N p Source # | |
Defined in OAlg.Entity.Matrix.Dim | |
| (Entity x, Entity i, Ord i) => PermutableSequence (Col i) i x Source # | |
Defined in OAlg.Entity.Matrix.Entries | |
| (Entity x, Entity j, Ord j) => PermutableSequence (Row j) j x Source # | |
Defined in OAlg.Entity.Matrix.Entries | |
| (Entity x, Entity i, Ord i) => PermutableSequence (PSequence i) i x Source # | |
Defined in OAlg.Entity.Sequence.Permutation | |
permuteByN :: PermutableSequence s N x => (w -> w -> Ordering) -> (x -> w) -> s x -> (s x, Permutation N) Source #
orders the permutable sequence according to the given ordering an delivers the resulting permutation form.
Form
newtype PermutationForm i Source #
form of a permutation from i to i which is given by pmf.
Property Let p = be in PermutationForm jis, then
holds: PermutationForm i for some proxy support z p == image z pz in z i.
The partial sequence ijs is called the relevant part of p.
Constructors
| PermutationForm (PSequence i i) |
Instances
pmf :: Ord i => PermutationForm i -> i -> i Source #
the associated function i to i and is given by:
Definition Let p = be in PermutationForm jis
then PermutationForm i is defined by: If there exists an pmf p i(j,i') in with
psqxs jisi' then == i else pmf p i = j.pmf p i = i
Note
- If the partial sequence
ijsisvalid, then for alliinithere exists at most one(_,i')insuch thatpsqxsjisi'. As such, the function==iis well defined.pmfp - If the permutation form
pitself isvalidthanis a bijection and as such a permutation ofpmfpi. - The behavior of
pmfdiffers from??as its evaluation will not end up in aIndexOutOfSupport-exception.
X
Arguments
| :: (Entity i, Ord i) | |
| => N | maximal number of swappings. |
| -> X i | span of the swappings. |
| -> X (Permutation i) |
random variable of permutations.
xPermutationB :: (Ord i, Enum i) => i -> i -> X (Permutation i) Source #
random variable of permutations within the given bounds.
xPermutationN :: N -> X (Permutation N) Source #
random variable of permutations of the index set [0..prd n].
xMltPermutation :: (Entity i, Ord i) => N -> X i -> XMlt (Permutation i) Source #
random variable for validating the Multiplicative structure.
Propositions
prpPermutation :: Statement Source #
validity of the functionality of the module Permutation.
prpPermutableSequence :: (PermutableSequence s i x, Entity x, Entity i, Show w) => N -> z i -> (w -> w -> Ordering) -> (x -> w) -> X (s x) -> Statement Source #
validity for PermutableSequence.
prpOprPermutation :: Statement Source #
validity of the total right operation <* of permutations on sequences.