Copyright | (C) Frank Staals |
---|---|
License | see the LICENSE file |
Maintainer | Frank Staals |
Safe Haskell | None |
Language | GHC2021 |
Data type for representing a non-empty Permutation
Synopsis
- data Permutation a = Permutation (NonEmptyVector (Orbit a)) (Vector (Int, Int))
- orbits :: forall a b f. Functor f => (NonEmptyVector (Orbit a) -> f (NonEmptyVector (Orbit b))) -> Permutation a -> f (Permutation b)
- indices :: (Indexable i p, Applicative f) => (i -> Bool) -> Optical' p (Indexed i) f a a
- type Orbit a = NonEmptyVector a
- elems :: Permutation a -> NonEmptyVector a
- size :: Permutation a -> Int
- cycleOf :: Enum a => Permutation a -> a -> Orbit a
- next :: NonEmptyVector a -> Int -> a
- previous :: NonEmptyVector a -> Int -> a
- lookupIdx :: Enum a => Permutation a -> a -> (Int, Int)
- apply :: Enum a => Permutation a -> a -> a
- orbitFrom :: Eq a => a -> (a -> a) -> NonEmpty a
- cycleRep :: (Enum a, Eq a) => NonEmptyVector a -> (a -> a) -> Permutation a
- toCycleRep :: Enum a => Int -> NonEmpty (NonEmpty a) -> Permutation a
Documentation
data Permutation a Source #
Cyclic representation of a non-empty permutation.
Permutation (NonEmptyVector (Orbit a)) (Vector (Int, Int)) |
Instances
orbits :: forall a b f. Functor f => (NonEmptyVector (Orbit a) -> f (NonEmptyVector (Orbit b))) -> Permutation a -> f (Permutation b) Source #
Lens to access the orbits of the permutation
indices :: (Indexable i p, Applicative f) => (i -> Bool) -> Optical' p (Indexed i) f a a Source #
This allows you to filter an IndexedFold
, IndexedGetter
, IndexedTraversal
or IndexedLens
based on a predicate
on the indices.
>>>
["hello","the","world","!!!"]^..traversed.indices even
["hello","world"]
>>>
over (traversed.indices (>0)) Prelude.reverse $ ["He","was","stressed","o_O"]
["He","saw","desserts","O_o"]
type Orbit a = NonEmptyVector a Source #
Orbits (Cycles) are represented by vectors
elems :: Permutation a -> NonEmptyVector a Source #
Get the elements of the permutation
size :: Permutation a -> Int Source #
Get the size of a permutation
running time: \(O(1)\)
next :: NonEmptyVector a -> Int -> a Source #
Next item in a cyclic permutation
previous :: NonEmptyVector a -> Int -> a Source #
Previous item in a cyclic permutation
lookupIdx :: Enum a => Permutation a -> a -> (Int, Int) Source #
Lookup the indices of an element, i.e. in which orbit the item is, and the index within the orbit.
runnign time: \(O(1)\)
apply :: Enum a => Permutation a -> a -> a Source #
Apply the permutation, i.e. consider the permutation as a function.
orbitFrom :: Eq a => a -> (a -> a) -> NonEmpty a Source #
Find the cycle in the permutation starting at element s
cycleRep :: (Enum a, Eq a) => NonEmptyVector a -> (a -> a) -> Permutation a Source #
Given a vector with items in the permutation, and a permutation (by its functional representation) construct the cyclic representation of the permutation.
toCycleRep :: Enum a => Int -> NonEmpty (NonEmpty a) -> Permutation a Source #
Given the size n, and a list of Cycles, turns the cycles into a cyclic representation of the Permutation.