#
# generate the label for the conjugacy class of w.
#
`coxeter/mytype`:=proc(w,L,n,R) local i,mu,sig,w0,m,pg;
  if L='A' then
    pg:={seq(cat('s',i)=[[i,i+1]],i=1..n)};
    mu:=map(nops,coxeter['multperm'](w,pg,n+1));
    [1$(n+1-convert(mu,`+`)),op(sort(mu))]
  elif L='B' or L='C' then
    pg:={s1=[[-1]],seq(cat('s',i)=[[i-1,i]],i=2..n)};
    `coxeter/mytype/bshape`(w,pg,n,'sig')
  elif L='D' then
    pg:={s1=[[-1,-2]],seq(cat('s',i)=[[i-1,i]],i=2..n)};
    mu:=`coxeter/mytype/bshape`(w,pg,n,'sig');
    if nops(mu[2])>0 or convert(map(modp,mu[1],2),`+`)>0 then sig:=NULL fi;
    mu,sig
  elif L='E' and n>5 then
    pg:=`coxeter/read`(R,'bpermrep','repn');
    mu:=`coxeter/mytype/bshape`(w,pg);
    if n<8 then mu:=(-1)^nops(w)*mu fi;
    pg:=`coxeter/read`(R,'mytype','types');
    if member(mu,pg,'i') then i else ERROR() fi;
  elif R='F4' then
    pg:=`coxeter/read`('F4','bpermrep','repn');
    mu:=`coxeter/mytype/bshape`(w,pg);
    sig:=coxeter['multperm'](subs(3=NULL,4=NULL,w),{s1=[[1,2]],s2=[[2,3]]},3);
    mu:=(-1)^nops(sig)*mu;
    pg:=`coxeter/read`('F4','mytype','types');
    if member(mu,pg,'i') then i else ERROR() fi;
  elif L='H' then
    sig:=round(2*coxeter['char_poly'](w,R,3));
    pg:=`coxeter/read`(R,'mytype','types');
    if member(sig,pg,'i') then i else ERROR() fi;
  elif L='I2' or R='G2' then
    w0:=coxeter['reduce'](w,R);
    if R='G2' then m:=6 else m:=op(R) fi;
    if w0=[] then 1
      elif modp(nops(w0),2)=1 then
        if modp(m,2)=1 then 2 else 1+w0[(nops(w0)+1)/2] fi
      else nops(w0)/2+3-modp(m,2)
    fi
  fi;
end:
#
# Determine the cycle type of a signed permutation
#
`coxeter/mytype/bshape`:=proc(w,pg,n) local alive,res,pi,c,i,j,cyc,sig;
  pi:=proc(k,x) if x<0 then -procname(k,-x) else x fi end;
  pi:=subsop(4=NULL,eval(pi));    # yuck
  for i in {op(w)} do
    for c in subs(pg,cat('s',i)) do;
      if nops(c)=1 then pi(i,-c[1]):=c[1]
        else pi(i,abs(c[2])):=c[1]; pi(i,abs(c[1])):=c[2]
      fi
    od
  od;
  alive:={$1..n}; res:=1; sig:=1;
  while nops(alive)>0 do
    j:=alive[1]; i:=j; cyc:=i;
    do
      for c in w do i:=pi(c,i) od;
      if i=j then res:=res*cat(``,nops([cyc])); break
        elif i=-j then res:=res*cat(``,-nops([cyc])); break
        else cyc:=cyc,abs(i); sig:=sig*sign(i)
      fi
    od;
    alive:=alive minus {cyc};
  od; 
  if nargs=3 then subs(`1`=1,res)
    else assign(args[4],sig);
    [seq(i$degree(res,cat(``,i)),i=1..n)],
    [seq(i$degree(res,cat(``,-i)),i=1..n)]
  fi
end:
#
save `coxeter/mytype`, `coxeter/mytype/bshape`,
  cat(HomeLib,`/coxeter/mytype.m`);
quit;

