{-# LANGUAGE NoImplicitPrelude #-}{- |
Copyright : (c) Henning Thielemann 2006
Maintainer : numericprelude@henning-thielemann.de
Stability : provisional
Portability :
Permutation represented by an array of the images.
-}moduleMathObj.Permutation.TablewhereimportqualifiedMathObj.PermutationasPermimportData.Set(Set)importqualifiedData.SetasSetimportData.Array(Array,(!),(//),Ix)importqualifiedData.ArrayasArrayimportData.List((\\),nub,unfoldr,)importData.Tuple.HT(swap,)importData.Maybe.HT(toMaybe,)-- import NumericPrelude (Integer)importPreludeBasehiding(cycle)typeTi=ArrayiifromFunction::(Ixi)=>(i,i)->(i->i)->TifromFunctionrngf=Array.listArrayrng(mapf(Array.rangerng))toFunction::(Ixi)=>Ti->(i->i)toFunction=(!){-
Create a permutation in table form
from any other permutation representation.
-}fromPermutation::(Ixi,Perm.Cp)=>pi->TifromPermutationx=letrng=Perm.domainxinArray.listArrayrng(map(Perm.applyx)(Array.rangerng))fromCycles::(Ixi)=>(i,i)->[[i]]->TifromCyclesrng=foldl(flipcycle)(identityrng)identity::(Ixi)=>(i,i)->Tiidentityrng=Array.listArrayrng(Array.rangerng)cycle::(Ixi)=>[i]->Ti->Ticyclecycp=p//zipWith(\ij->(j,p!i))cyc(tail(cyc++cyc))inverse::(Ixi)=>Ti->Tiinversep=letrng=Array.boundspinArray.arrayrng(mapswap(Array.assocsp))compose::(Ixi)=>Ti->Ti->Ticomposepq=letpRng=Array.boundspqRng=Array.boundsqinifpRng==qRngthenfmap(p!)qelseerror"compose: ranges differ"-- ++ show pRng ++ " /= " ++ show qRng){- |
Extremely na´ve algorithm
to generate a list of all elements in a group.
Should be replaced by a Schreier-Sims system
if this code is ever used for anything bigger than .. say ..
groups of order 512 or so.
-}{-
Alternative to Data.Set.minView in GHC-6.6.
-}choose::Seta->Maybe(a,Seta)chooseset=toMaybe(not(Set.nullset))(Set.deleteFindMinset)closure::(Ixi)=>[Ti]->[Ti]closure[]=[]closuregenerators@(gen:_)=letgenSet=Set.fromListgeneratorsidSet=Set.singleton(identity(Array.boundsgen))generate(registered,candidates)=do(cand,remCands)<-choosecandidatesletnewCands=flipSet.differenceregistered$Set.map(composecand)genSetreturn(cand,(Set.unionregisterednewCands,Set.unionremCandsnewCands))inunfoldrgenerate(idSet,idSet)closureSlow::(Ixi)=>[Ti]->[Ti]closureSlow[]=[]closureSlowgenerators@(gen:_)=letaddEltsgrp[]=grpaddEltsgrpcands@(cand:remCands)=letgroup'=grp++[cand]newCands=map(composecand)generatorscands'=nub(remCands++newCands)\\(grp++cands)inaddEltsgroup'cands'inaddElts[][identity(Array.boundsgen)]