Copyright | (c) Erich Gut |
---|---|
License | BSD3 |
Maintainer | zerich.gut@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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
make
of avalid
PermutationForm
, which defines also the validity for the constructed permutation.swap
and theMultiplicative
structure for permutations.permuteBy
forPermutableSequence
.xPermutation
to 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
xs
be in[x]
with
andConstructableSequence
[] r [x]p
a permutation in
, thenPermutation
rxs
is given by<*
p
, wheresqcIndexMap
is (pmt
p) xsis
is the image of the support ofxs
under the inverse ofp
. - CSequence
- Let
xs
be in
withCSequence
x
andConstructableSequence
CSequence
N
xp
a permutation in
, thenPermutation
N
xs
is given by<*
p
, wheresqcIndexMap
is (pmt
p) xsis
is the image of the support ofxs
under the inverse ofp
. - PSequence
- Let
xs
be in
withPSequence
i x
andConstructableSequence
(PSequence
i) i xp
a permutation in
, thenPermutation
ixs
is given by<*
p
, wheresqcIndexMap
is (pmt
p) xsis
is the image of the support ofxs
under the inverse ofp
. - Permutation
- Let
xs
,p
be in
, thenPermutation
ixs
is 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
xs
be ins x
,p
in
withPermutation
i
for someimage
z p<<=
support
z xsz
inz i
, then holds:(xs
for all<*
p)??
i==
((xs??
).
pmt
p) ii
in
.support
z xs Let
xs
be ins x
,w
inx -> w
,c
inw -> w ->
andOrdering
z
inz i
, then holds: Let(xs',p) =
inpermuteBy
z 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.
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 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
.
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
ijs
isvalid
, then for alli
ini
there exists at most one(_,i')
in
such thatpsqxs
jisi'
. As such, the function==
i
is well defined.pmf
p - If the permutation form
p
itself isvalid
than
is a bijection and as such a permutation ofpmf
pi
. - The behavior of
pmf
differs from??
as its evaluation will not end up in aIndexOutOfSupport
-exception.
X
:: (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.