> with(combinat,permute):
> with(plots):
Die Prozedur cycleformat erhalt als Eingabe eine Liste die einer Permutation von n Elementen entspricht.
Zum Beispiel: [2,1,3] ist die Permution 1->2, 2->1, 3->3.
Ausgabe ist das Zykelformat dieser Permutation.
Verbesserungen am code sind willkommen!
> cycleformat:=proc(n,eingabe)
> local i,k,v,liste,zformat,naechste:
> liste:=[seq(i,i=1..n+1)]:
> i:=1: k:=1: v:=array(1..n):
> while i<=n do
> liste:=subsop(i=0,liste):
> naechste:=eingabe[i]: v[k]:=1:
> while naechste<>i do
> liste:=subsop(naechste=0,liste):
> naechste:=eingabe[naechste]:
> v[k]:=v[k]+1:
> od:
> i:=i+1:
> while liste[i]=0 do
> i:=i+1:
> od:
> k:=k+1:
> od:
> zformat:=sort([seq(v[i],i=1..k-1)]):
> return(zformat):
> end:
Ein Beispiel:
> vergleich:=proc(liste)
> if liste=[1,1,1,1,1] then return(1):
> elif liste=[1,1,1,2] then return(2):
> elif liste=[1,1,3] then return(3):
> elif liste=[1,2,2] then return(4):
> elif liste=[2,3] then return(5):
> elif liste=[1,4] then return(6):
> else return(7):
> fi:
> end:
> n:=5:
> s5:=permute(n):
> wurf:=rand(n!):
> eintrag:=wurf()+1:
> s5[eintrag];
> cycleformat(5,s5[eintrag]);
>
> q:=7: a:=array('sparse',1..7): b:=array('sparse',1..7):
> for i from 1 to 1000 do
> f:=randpoly(x,degree=n-1,coeffs=rand(0..q-1),dense) mod q:
> f:=x^n+f mod q:
> zerl1:=Factors(f) mod q:
> zerl:=zerl1[2]:
> liste1:=[]:
> for j from 1 to nops(zerl) do
> for l from 1 to zerl[j][2] do
> liste1:=[op(liste1),degree(zerl[j][1])]:
> end:
> end:
> liste1:=sort(liste1):
> eintrag:=wurf()+1:
> liste2:=cycleformat(5,s5[eintrag]):
> j:=vergleich(liste1):
> k:=vergleich(liste2):
> a[j]:=a[j]+1:
> b[k]:=b[k]+1:
> od:
> listplot([seq(a[i],i=1..7)], style=line);
> listplot([seq(b[i],i=1..7)], style=line);
>
>