[GAP Forum] Sortex( list, func )

Alexander Hulpke ahulpke at gmail.com
Wed Aug 6 17:39:43 BST 2008


Dear Forum,

> is there a reason why the versions Sort and SortParallel exist with  
> an optional Argument func which permits to define an own comparison  
> function while for Sortex and SortingPerm such a version does not  
> exist?

There is no fundamental reason for this (and in the next release such  
functionality will be available), the most likely reason is that it  
can be easily emulated, see below.
>
> And if so, is there a simple way to obtain what
>
>  SortingPerm(ConjugacyClasses, cmp)
>
> would do (for a given function cmp) if there were such a version?

Yes. You can use `SortParallel' to build a permutation (in fact this  
is what `Sortex' does internally):

gap> l:=[6,2,9,4,5];
gap> pos:=[1..Length(l)]; # list of positions
gap> SortParallel(l,pos,function(a,b) return a>b;end); # reverse  
sorting function
gap> l;
[ 9, 6, 5, 4, 2 ]

Now `PermList(pos)' is the inverse of  permutation that will do the  
same sort:

gap> l:=[6,2,9,4,5]; # old list again
gap> Permuted(l,PermList(pos)^-1);
[ 9, 6, 5, 4, 2 ]

All the best,

    Alexander Hulpke
>



More information about the Forum mailing list