#
# irr_chars(R) returns the list of irreducible characters of W(R).
# Each character is a list of values on conjugacy classes.
# The characters for A.n are ordered as in combinat[character](n+1),
#  so that the character indexed by the partition lambda appears in
#  the reverse of the order used by combinat[partition].
#
`coxeter/irr_chars`:=proc() local i,j,R,L,sys,n,irr,new,f,g;
  R:=coxeter['name_of'](args); irr:=[[1]];
  sys:=sort([op(indets(R))],`coxeter/cox_order`);
  sys:=[seq(i$degree(R,i),i=sys)];
  for R in sys do
    n:=coxeter['rank'](R);
    if type(R,'indexed') then L:=op(0,R) else L:=substring(R,1..1) fi;
    if L='A' then
      new:=convert(combinat['character'](n+1),'listlist')
    elif L='B' or L='C' then
      new:=`coxeter/irr_chars/B`(n)
    elif L='D' and n>1 then
      new:=`coxeter/irr_chars/D`(n)
    elif L='E' and n<6 then
      new:=`coxeter/irr_chars`(coxeter['base'](R))
    elif member(L,['E','F','H']) then
      new:=`coxeter/read`(R,'irr_chars','chars')
    elif R='G2' then
      new:=`coxeter/irr_chars/I2`(R,6)
    elif L='I2' and type(op(R)-1,'posint') then
      new:=`coxeter/irr_chars/I2`(R,op(R))
    else
      ERROR(cat(R,` is not a recognized root system name`))
    fi;
    irr:=[seq(seq([seq(seq(i*j,i=f),j=g)],f=irr),g=new)]
  od; irr
end:
#
`coxeter/irr_chars/B`:=proc(n) local i,j,k,ct,sp,sz,irr,cc,f,g,ch,p,q;
  for k from 0 to n do
    sp:=combinat['partition'](k);
    sz:=map(`coxeter/par2A`,sp,0);
    cc:=[seq(sz[j]*convert([seq(p[i]/2,i=sp[j])],`*`)/k!,j=1..nops(sp))];
    irr:=convert(combinat['character'](k),'listlist');
    ct[k]:=[seq(convert(zip((x,y)->x*y,f,cc),`+`),f=irr)];
  od;
  cc:=[seq(seq(seq(convert([seq(p[i],i=f),seq(q[i],i=g)],`*`),
    f=combinat['partition'](n-k)),g=combinat['partition'](k)),k=0..n)];
  sz:=[seq(seq(seq(`coxeter/par2B`(f,g,0),
    f=combinat['partition'](n-k)),g=combinat['partition'](k)),k=0..n)];
  irr:=NULL;
  for k from 0 to n do
    for g in ct[k] do
      g:=subs({seq(p[i]=p[i]-q[i],i=1..k)},g);
      for f in ct[n-k] do
        ch:=table('sparse');
        f:=expand(subs({seq(p[i]=p[i]+q[i],i=1..n-k)},f)*g);
        f:=[coeffs(f,indets(f),'sp')]; sp:=[sp];
        for i to nops(sp) do
          member(sp[i],cc,'j'); ch[j]:=2^n*n!*f[i]/sz[j]
        od;
        irr:=irr,[seq(ch[j],j=1..nops(sz))]
      od
    od
  od; [irr]
end:
#
`coxeter/irr_chars/D`:=proc(n) local i,j,jj,k,ct,sp,sz,
    irr,cc,f,g,ch,dch,p,q,evn,g0,skip,N;
  for k from 0 to n do
    sp:=combinat['partition'](k);
    sz:=map(`coxeter/par2A`,sp,0);
    cc:=[seq(sz[j]*convert([seq(p[i]/2,i=sp[j])],`*`)/k!,j=1..nops(sp))];
    irr:=convert(combinat['character'](k),'listlist');
    ct[k]:=[seq(convert(zip((x,y)->x*y,f,cc),`+`),f=irr)];
  od;
  evn:=proc(k) map(proc(x) if modp(nops(x),2)=0 then x fi end,
    combinat['partition'](k)) end;
  cc:=[seq(seq(seq(convert([seq(p[i],i=f),seq(q[i],i=g)],`*`),
    f=combinat['partition'](n-k)),g=evn(k)),k=0..n)];
  sz:=[seq(seq(seq(`coxeter/par2B`(f,g,0),
    f=combinat['partition'](n-k)),g=evn(k)),k=0..n)];
  if modp(n,2)=1 then evn:=[]
    else evn:=[seq(convert([seq(p[2*i],i=f)],`*`),
    f=combinat['partition'](n/2))] fi;
  irr:=NULL; N:=nops(sz)+nops(evn);
  for k from 0 to n/2 do
    for g0 in ct[k] do
      g:=subs({seq(p[i]=p[i]-q[i],i=1..k)},g0); skip:=false;
      for f in ct[n-k] do
        if skip then next else ch:=table('sparse') fi;
        if k=n/2 and f=g0 then skip:=true fi;
        f:=expand(subs({seq(p[i]=p[i]+q[i],i=1..n-k)},f)*g);
        f:=[coeffs(f,indets(f),'sp')]; sp:=[sp];
        for i to nops(sp) do
          if member(sp[i],cc,'j') then ch[j]:=2^n*n!*f[i]/sz[j];
            if member(sp[i],evn,'jj') then ch[jj+nops(cc)]:=ch[j] fi
          fi
        od;
        if skip then dch:=table('sparse');
          g0:=subs({seq(p[i]=p[2*i],i=1..k)},g0);
          g0:=[coeffs(g0,indets(g0),'sp')]; sp:=[sp];
          for i to nops(sp) do
            member(sp[i],cc,'j'); dch[j]:=2^n*n!*g0[i]/sz[j];
            member(sp[i],evn,'jj'); dch[nops(cc)+jj]:=-dch[j];
          od;
          irr:=irr,[seq((ch[j]+dch[j])/2,j=1..N)],
            [seq((ch[j]-dch[j])/2,j=1..N)]
        else
          irr:=irr,[seq(ch[j],j=1..N)]
        fi
      od
    od
  od; [irr]
end:
#
`coxeter/irr_chars/I2`:=proc(R,m) local cc,w,irr,i,k,st;
  cc:=coxeter['class_rep'](R); st:=2,0;
  irr:=[1$nops(cc)],[seq((-1)^nops(w),w=cc)];
  if modp(m,2)=0 then st:=st,0;
    irr:=irr,[seq((-1)^nops(w),w=subs(2=NULL,cc))],
    [seq((-1)^nops(w),w=subs(1=NULL,cc))];
  fi;
  [irr,seq([st,seq(2*cos(2*Pi*k*i/m),i=1..m/2)],k=1..(m-1)/2)]
end:
#
save `coxeter/irr_chars`, `coxeter/irr_chars/B`, `coxeter/irr_chars/D`,
  `coxeter/irr_chars/I2`, cat(HomeLib,`/coxeter/irr_chars.m`);
read cat(HomeLib,`/help/coxeter/irr_chars`);
quit;

