#
# Find a representation of dominant weight v as a sum of minuscule and
# quasi-minuscule weights with dominant partial sums (=minuscule chain).
# Try to use minuscules where possible, but not at the expense
# of creating a longer representation.
#
# The chain is built by concatenating minimum-length chains for the
# fundamental weights. The validity of the algorithm rests on the
# empirical observation that a minimum-length chain for a non-minuscule
# fund.wt. w[i] is obtained by appending a (quasi-)minuscule weight to
# a minimal chain for some previous w[j].
#
`weyl/findrep`:=proc(v,S) local n,w,qm,vc,J,L,new,old,rep,i,u;
  w:=weyl['weights'](S); n:=nops(w);
  vc:=weyl['weight_coords'](v,S);
  qm:=weyl['minuscule'](S,'quasi',w);
  new:=[0,0]; rep[0]:=NULL; L:={$1..n};
  J:=map(proc(x,y) if y[x]>0 then x fi end,L,vc);
  while nops(J)>0 do
    old:=[new]; new:=NULL;
    if old=[] then ERROR(`this should not happen`) fi;
    for i in L do
      for u in old do
        if member(coxeter['vec2fc'](w[i]-u[1],S),qm) then
          rep[i]:=rep[u[2]],w[i]-u[1];
          new:=new,[w[i],i]; J:=subs(i=NULL,J); break
        fi;
      od;
      if nops(J)=0 then break fi;
    od;
    L:=L minus map(x->op(2,x),{new});
  od;
  map(op,[seq([rep[i]]$vc[i],i=1..n)]);
end:
#
save `weyl/findrep`, cat(HomeLib,`/weyl/findrep.m`);
quit;

