Agda-2.4.2: A dependently typed functional programming language and proof assistant

Safe HaskellNone

Agda.Utils.Permutation

Contents

Synopsis

Documentation

data Permutation Source

Partial permutations. Examples:

permute [1,2,0] [x0,x1,x2] = [x1,x2,x0] (proper permutation).

permute [1,0] [x0,x1,x2] = [x1,x0] (partial permuation).

permute [1,0,1,2] [x0,x1,x2] = [x1,x0,x1,x2] (not a permutation because not invertible).

Agda typing would be: Perm : {m : Nat}(n : Nat) -> Vec (Fin n) m -> Permutation m is the size of the permutation.

Constructors

Perm 

Fields

permRange :: Int
 
permPicks :: [Int]
 

permute :: Permutation -> [a] -> [a]Source

permute [1,2,0] [x0,x1,x2] = [x1,x2,x0] More precisely, permute indices list = sublist, generates sublist from list by picking the elements of list as indicated by indices. permute [1,3,0] [x0,x1,x2,x3] = [x1,x3,x0]

Agda typing: permute (Perm {m} n is) : Vec A m -> Vec A n

idP :: Int -> PermutationSource

Identity permutation.

takeP :: Int -> Permutation -> PermutationSource

Restrict a permutation to work on n elements, discarding picks >=n.

droppedP :: Permutation -> PermutationSource

Pick the elements that are not picked by the permutation.

liftP :: Int -> Permutation -> PermutationSource

liftP k takes a Perm {m} n to a Perm {m+k} (n+k). Analogous to liftS, but Permutations operate on de Bruijn LEVELS, not indices.

composeP :: Permutation -> Permutation -> PermutationSource

permute (compose p1 p2) == permute p1 . permute p2

compactP :: Permutation -> PermutationSource

Turn a possible non-surjective permutation into a surjective permutation.

reverseP :: Permutation -> PermutationSource

permute (reverseP p) xs ==
    reverse $ permute p $ reverse xs

Example: permute (reverseP (Perm 4 [1,3,0])) [x0,x1,x2,x3] == permute (Perm 4 $ map (3-) [0,3,1]) [x0,x1,x2,x3] == permute (Perm 4 [3,0,2]) [x0,x1,x2,x3] == [x3,x0,x2] == reverse [x2,x0,x3] == reverse $ permute (Perm 4 [1,3,0]) [x3,x2,x1,x0] == reverse $ permute (Perm 4 [1,3,0]) $ reverse [x0,x1,x2,x3]

topoSort :: (a -> a -> Bool) -> [a] -> Maybe PermutationSource

Stable topologic sort. The first argument decides whether its first argument is an immediate parent to its second argument.

Drop (apply) and undrop (abstract)

data Drop a Source

Delayed dropping which allows undropping.

Constructors

Drop 

Fields

dropN :: Int

Non-negative number of things to drop.

dropFrom :: a

Where to drop from.

Instances

Functor Drop 
Typeable1 Drop 
Foldable Drop 
Traversable Drop 
Eq a => Eq (Drop a) 
Ord a => Ord (Drop a) 
Show a => Show (Drop a) 
KillRange a => KillRange (Drop a) 
DoDrop a => Abstract (Drop a) 
DoDrop a => Apply (Drop a) 
EmbPrj a => EmbPrj (Drop a) 

class DoDrop a whereSource

Things that support delayed dropping.

Methods

doDropSource

Arguments

:: Drop a 
-> a

Perform the dropping.

dropMoreSource

Arguments

:: Int 
-> Drop a 
-> Drop a

Drop more.

unDropSource

Arguments

:: Int 
-> Drop a 
-> Drop a

Pick up dropped stuff.

Instances