#
# weight_sys(v,R) produces the list of all dominant weights u <= v,
#  where v1 < v2 means v2-v1 is a sum of positive roots.
# weight_sys(v,R,'wl') will do the same, but also assigns to 'wl' the
#  coordinates of the weight vectors w.r.t. the fundamental weights.
# weight_sys(v0,R,'wl',v1) will do the analogous thing for the list of
#  dominant weights v such that v1 <= v <= v0.
#  It does not waste time by checking first to see if v1 <= v0.
# The output is sorted by decreasing height (ht(u):=iprod(u,co_rho(R))).
#  The sorting is an unnecessary expense, but is used in 'qtensor' and
#  'weight_mults' so that equations are solved in a sensible order.
#
`weyl/weight_sys`:=proc(v0,R)
  local coS,pr,prwc,v,w,v1,cr0,peaks,lb,i,j,res,wres,sat;
  coS:=coxeter['base'](R); pr:=`weyl/lsdpr`(coS);
  coS:=coxeter['co_base'](coS); i:=[$1..nops(coS)];
  prwc:=[seq(map(coxeter['iprod'],coS,v),v=pr)];
  peaks:=[seq(map(proc(x,y) if y[x]>0 then x fi end,i,v),v=prwc)];
  if nargs>3 then
    if nargs>4 then w:=args[5] else w:=weyl['weights'](coS) fi;
    v1:=args[4]; cr0:=convert(w,`+`);
    lb:=proc(u,L) local r; for r in L do
      if coxeter['iprod'](u,r)<0 then RETURN(false) fi
    od; true end;
  else
    v1:=0; cr0:=weyl['rho'](coS); lb:=proc() true end;
  fi;
  res:=[v0]; wres:=[map(coxeter['iprod'],coS,v0)];
  for sat while sat<=nops(res) do
    for i to nops(pr) do v:=0;
      for j in peaks[i] while v>=0 do v:=wres[sat][j]-prwc[i][j] od;
      if v>=0 then v:=res[sat]-pr[i];
        if not member(v,res) and lb(v-v1,w) then res:=[op(res),v];
          wres:=[op(wres),zip((x,y)->x-y,wres[sat],prwc[i])]
        fi
      fi
    od
  od;
  res:=[seq([res[i],wres[i],coxeter['iprod'](res[i],cr0)],i=1..nops(res))];
  res:=sort(res,(x,y)->evalb(x[3]>=y[3]));
  if nargs>2 then assign(args[3],map(x->op(2,x),res)) fi;
  map(x->op(1,x),res);
end:
#
save `weyl/weight_sys`, cat(HomeLib,`/weyl/weight_sys.m`);
read cat(HomeLib,`/help/weyl/weight_sys`);
quit;

