default(parisize,"16M");
testgr(name)=
{
  my(G=eval(name));
  my(n=#G,m=#G[1]);
  my(S=permgroupinit(G));
  print(name,":",grouporder(S));
  my(p=G[1]^0); for(i=1,100,p*=G[random(n)+1]);
  my(q=vectorsmall(m,i,m+1-i));
  print("p:",groupisin(S,p));
  print("q:",groupisin(S,q));
  my(dS=groupderived(S));
  print("dS:",grouporder(dS));
  print("isincl:",groupisincl(S,dS));
}

J2=
{[Vecsmall([58,20,51,25,17,70,90,43,52,59,3,19,56,36,100,69,89,33,82,85,13,35,7,16,71,72,67,97,98,73,2,68,45,99,15,4,57,21,76,10,27,50,37,79,81,38,62,84,44,92,5,53,95,23,29,74,77,96,91,18,66,26,41,31,88,49,22,40,83,6,1,47,8,78,30,39,75,80,94,46,55,86,24,48,42,54,87,61,34,12,28,64,93,65,9,14,32,60,11,63]),
Vecsmall([91,78,86,62,73,56,59,66,13,32,37,82,47,77,31,26,24,45,29,3,52,40,36,2,75,72,58,96,7,42,18,33,11,50,17,84,98,19,88,94,20,60,46,12,16,69,10,100,93,55,48,90,43,92,4,38,27,97,28,15,25,74,1,21,44,41,9,83,68,63,23,30,35,57,87,79,71,80,14,85,5,54,64,49,81,22,89,51,39,53,65,70,76,99,6,95,34,67,8,61])];
}

M24=[Vecsmall([4,7,17,1,13,9,2,15,6,19,18,21,5,16,8,14,3,11,10,24,12,23,22,20]),Vecsmall([4,2,5,9,14,17,16,6,1,22,13,7,19,3,15,12,8,18,11,10,21,20,23,24])];

rubik=apply(Vecsmall,[[6,4,1,7,2,8,5,3,17,18,19,12,13,14,15,16,25,26,27,20,21,22,23,24,33,34,35,28,29,30,31,32,9,10,11,36,37,38,39,40,41,42,43,44,45,46,47,48],[40,2,3,37,5,35,7,8,14,12,9,15,10,16,13,11,1,18,19,4,21,6,23,24,25,26,27,28,29,30,31,32,33,34,46,36,44,38,39,41,17,42,43,20,45,22,47,48],[1,2,3,4,5,16,13,11,9,10,41,12,42,14,15,43,22,20,17,23,18,24,21,19,6,26,27,7,29,8,31,32,33,34,35,36,37,38,39,40,30,28,25,44,45,46,47,48],[1,2,19,4,21,6,7,24,9,10,11,12,13,14,15,16,17,18,43,20,45,22,23,48,30,28,25,31,26,32,29,27,8,34,35,5,37,3,39,40,41,42,38,44,36,46,47,33],[27,29,32,4,5,6,7,8,3,10,11,2,13,1,15,16,17,18,19,20,21,22,23,24,25,26,48,28,47,30,31,46,38,36,33,39,34,40,37,35,41,42,43,44,45,9,12,14],[1,2,3,4,5,6,7,8,9,10,11,12,13,38,39,40,17,18,19,20,21,14,15,16,25,26,27,28,29,22,23,24,33,34,35,36,37,30,31,32,46,44,41,47,42,48,45,43]]);
{
Co3= [Vecsmall([245,42,112,15,131,7,188,75,132,10,11,187,186,265,22,159,256,43,101,123,
134,4,32,209,238,35,45,235,126,5,19,60,66,80,154,251,117,206,71,118,93,
87,167,271,221,261,182,155,47,230,172,236,109,191,76,156,73,116,147,23,
127,231,38,53,122,210,24,68,86,255,196,139,149,21,111,203,252,72,262,114,
214,9,181,174,85,95,2,250,257,243,90,158,170,148,69,105,249,263,16,54,
31,115,51,104,125,219,92,46,64,204,8,266,225,34,175,145,161,180,237,241,
224,169,269,12,96,129,189,190,29,17,30,82,143,74,168,13,227,217,78,258,
220,178,228,146,58,254,273,215,57,106,77,110,50,26,248,260,274,107,99,
253,37,25,272,44,52,119,18,201,65,41,233,103,246,200,102,160,198,207,157,
40,223,49,267,79,1,136,124,6,61,268,100,70,98,171,121,39,62,211,208,84,
135,97,55,152,141,63,142,259,67,33,177,173,14,242,94,113,240,264,150,205,
27,183,83,195,216,163,247,133,36,153,197,140,194,120,270,165,166,162,218,
138,234,81,91,89,185,212,137,48,202,276,229,151,176,144,192,130,244,232,
199,56,108,184,193,239,213,3,222,128,20,28,164,226,59,179,275,88]),
Vecsmall([204,203,33,236,5,172,77,76,47,146,133,224,229,53,84,16,223,228,130,131,
252,190,13,263,242,10,32,196,199,65,246,209,40,99,241,198,269,251,75,118,
176,271,183,116,197,238,22,29,178,26,174,129,2,153,272,257,41,12,59,20,
27,175,106,159,218,259,137,258,261,164,262,189,45,177,260,85,25,15,226,
96,24,1,274,148,264,132,48,117,36,60,171,201,101,253,95,120,142,213,165,
51,115,44,103,167,243,66,141,108,88,97,276,30,139,222,166,173,231,3,73,
239,56,170,82,162,163,207,145,128,52,104,90,216,220,155,74,237,28,4,113,
273,230,270,248,180,206,50,250,78,127,150,54,232,217,121,69,156,6,125,
210,86,89,46,184,211,265,93,19,138,23,126,43,188,102,244,219,192,256,83,
58,144,181,187,91,158,205,235,147,157,114,9,152,57,39,64,143,67,119,161,
87,200,111,79,14,123,21,149,122,191,61,194,266,225,31,81,62,160,151,112,
215,254,234,72,17,179,105,267,227,18,169,249,109,208,275,68,233,168,55,
124,80,240,35,7,212,100,245,98,195,247,107,182,42,185,94,11,255,135,154,
221,63,193,134,71,214,8,34,70,202,268,37,110,38,136,140,49,186,92])
];
}
testgr("J2");
testgr("M24");
testgr("rubik");
testgr("Co3");

f(G)=
{
  [grouporder(G),grouporder(groupderived(G)),
   groupissolvable(G),groupisnilpotent(G)];
}

S4=permgroupinit([Vecsmall([2,3,4,1]), Vecsmall([1,2,4,3])]);
apply(x->Vec(x),groupelts(S4))
f(S4)
A4=groupderived(S4);
f(A4)
D8=permgroupinit([Vecsmall([2,3,4,1]),Vecsmall([3,2,1,4])]);
f(D8)
groupisnormal(S4,A4)
groupisnormal(S4,D8)

S=permgroupinit([Vecsmall([2,3,4,5,6,7,1]), Vecsmall([1,2,3,4,6,7,5])]);
#Set(groupelts(S))
f(S)
f(permgroupinit([Vecsmall([5,4,6,2,1,3]),Vecsmall([6,2,3,1,5,4])]))
f(permgroupinit([Vecsmall([6,2,3,1,5,4]),Vecsmall([5,4,6,2,1,3])]))
