#
# weight_mults(v,R) produces the dimensions of the weight spaces of the
#  irreducible representation of LieAlg(R) with highest weight v.
#  The output is a sum  c1*M[w1]+c2*M[w2]+...,  where w1,w2,... are the
#  fund.wt.coords of the dominant weights in the weight system of v,
#  and c1,c2,... are their multiplicities.
# The positive roots and their fund.wt.coords can be passed along as
#  the third and fourth arguments.
# weight_mults(v,u,R) computes the multiplicity of u in the irrep of
#  highest weight v. The weight u need not be dominant (but v must be).
#
`weyl/weight_mults`:=proc(v0)
  local S,coS,pr,r0,wts,wl,prwc,m,n,i,j,k,J,SJ,u,v,mults,orb,u0;
  if nargs<>3 then S:=coxeter['base'](args[2]) else
    S:=coxeter['base'](args[3]);
    u:=coxeter['vec2fc'](args[2],S);
    v:=coxeter['root_coords'](v0-u,S);
    if not type(v,'list'('nonnegint')) then RETURN(0) fi
  fi;
  wts:=weyl['weight_sys'](v0,S,'wl');
  if nargs>3 then pr:=args[3]; prwc:=args[4] else
    pr:=coxeter['pos_roots'](S);
    coS:=coxeter['co_base'](S);
    prwc:=[seq(map(coxeter['iprod'],coS,i),i=pr)];
  fi;
  r0:=convert(pr,`+`)/2; mults[1]:=1;
  if nargs=3 then member(u,wts,'n') else n:=nops(wts) fi;
  for i from 2 to n do
    J:=map(proc(x,y) if y[x]=0 then x fi end,[$1..nops(S)],wl[i]);
    v:=wts[i]; SJ:=[seq(S[j],j=J)]; m:=0;
    for k to nops(pr) do
      if min(seq(prwc[k][j],j=J),1)<0 then next fi;
      u:=v+pr[k]; u0:=coxeter['vec2fc'](u,S);
      if not member(u0,wts,'j') then next fi;
      orb:=coxeter['orbit_size'](pr[k],SJ,-1);
      do
        m:=m+mults[j]*orb*coxeter['iprod'](u,pr[k]);
        u:=u+pr[k]; u0:=coxeter['vec2fc'](u,S);
        if not member(u0,wts,'j') then break fi;
      od
    od;
    k:=coxeter['iprod']((v0+r0)$2)-coxeter['iprod']((v+r0)$2);
    mults[i]:=m/k;
  od;
  if nargs=3 then mults[n] else
    convert([seq(mults[i]*M[op(wl[i])],i=1..n)],`+`) fi
end:
#
save `weyl/weight_mults`, cat(HomeLib,`/weyl/weight_mults.m`);
read cat(HomeLib,`/help/weyl/weight_mults`);
quit;

