#
# par2A(mu)   = shortest, lex-first rep of type mu
# par2A(mu,*) = size of class indexed by mu
#
`coxeter/par2A`:=proc(mu) local sz,rep,mul,j,i;
  if nargs=1 then
    j:=0; rep:=NULL;
    for i from nops(mu) by -1 to 1 do
      rep:=rep,$j+1..j+mu[i]-1; j:=j+mu[i]
    od; [rep]
  else
    j:=0; sz:=convert(mu,`+`)!; mul:=1;
    for i in mu do
      if i=j then mul:=mul+1 else mul:=1; j:=i fi;
      sz:=sz/mul/j;
    od; sz
  fi
end:
#
# par2B(mu,nu)   = shortest, lex-first rep of type (mu,nu)
# par2B(mu,nu,*) = size of class indexed by (mu,nu)
#   
`coxeter/par2B`:=proc(mu,nu) local m,n,i,k,w,w0,pi;
  if nargs=2 then
    m:=nops(nu)+1; n:=convert(nu,`+`);
    pi:=[$2..n+1]; w:=NULL; w0:=NULL;
    for i to nops(nu) do
      w0:=w0,seq(-k,k=-i..-2),$1..i;
      pi:=subsop(i=m,pi); m:=m+nu[i]-1; pi:=subs(m=i,pi)
    od;
    while n>1 do
      member(n,pi,'i'); n:=n-1;
      w:=seq(-k+1,k=-n..-i),w; pi:=subsop(i=NULL,pi)
    od;
    [w0,w,seq(i+m,i=`coxeter/par2A`(mu))]
  else
    m:=convert(mu,`+`); n:=convert(nu,`+`);
    2^(m+n-nops(mu)-nops(nu))*binomial(m+n,m)
      *`coxeter/par2A`(mu,0)*`coxeter/par2A`(nu,0)
  fi
end:
#
# par2D(mu,nu)    = shortest, lex-first rep of type (mu,nu)
#   (NULL if nops(nu) odd)
# par2D(mu,[],+1) = shortest, lex-first rep of type (mu,+), if all mu even
# par2D(mu,[],-1) = shortest, lex-first rep of type (mu,-), if all mu even
# par2D(mu,nu,0)  = class size(s) indexed by (mu,nu) (NULL if nops(nu) odd)
#
`coxeter/par2D`:=proc(mu,nu) local j,n;
  if modp(nops(nu),2)=1 then NULL
  elif nargs=2 and nops(nu)>0 then
    subs({1=2,2=1},subsop(1=NULL,seq(j*(j-1)+2=NULL,j=2..nops(nu)),
     `coxeter/par2B`(mu,nu)))
  elif nargs=2 or args[3]=-1 then
    subs(2=1,`coxeter/par2B`(mu,nu))
  elif args[3]=1 then
    `coxeter/par2B`(mu,nu)
  else
    n:=`coxeter/par2B`(mu,nu,0);
    if nu=[] and convert([seq(modp(j,2),j=mu)],`+`)=0 then n/2 else n fi
  fi
end: 
#
save `coxeter/par2A`, `coxeter/par2B`, `coxeter/par2D`,
  cat(HomeLib,`/coxeter/par2.m`);
quit;

