#
# Given a polynomial expression f in the variables M[..] (orbit sums)
#  and X[..] (Weyl characters), where [..]=fund.wt. coordinates, convert 
#  f into a linear combination of Weyl characters X[..] using the
#  Brauer-Klimyk Rule (and related techniques).
# The output is "collected" with respect to the variables X[..].
#
`weyl/toX`:=proc(f,R) local S,coS,wt,r,N,g,v,r0,ct;
  if assigned(M) or assigned(X) then
    ERROR(`M and X cannot have assigned values`) fi;
  S:=coxeter['base'](R); r:=ilcm(op(map(denom,S)));
  S:=map((x,y)->y*x,S,r); wt:=weyl['weights'](S);
  coS:=coxeter['co_base'](S); r0:=convert(wt,`+`);
  N:=`weyl/neighbor`(S,{},0);
  g:=`weyl/flatten`(f,S,coS,wt,N);
  v:=`weyl/flatten/vars`(g,wt,'M');
  g:=subs({seq(r[1]=`weyl/orbit_sum`(r[3],r0,S,coS,N,'skew'),r=v)},g);
  v:=indets(g,'indexed');
  v:=map(proc(x) if op(0,x)='X' then x fi end,v);
  ct:=subs({seq(r=0,r=v)},g); g:=g-ct+ct*X[0$nops(S)];
  if ct<>0 then v:={op(v),X[0$nops(S)]} fi;
  collect(g,v,'distributed');
end:
#
save `weyl/toX`, cat(HomeLib,`/weyl/toX.m`);
read cat(HomeLib,`/help/weyl/toX`);
quit;

