#
# root_coords(v,R) returns the coordinates of v with respect to base(R).
# If v is not in the linear span of base(R), either an error will occur
# or garbage will be produced.
#
`coxeter/root_coords`:=proc(v,R) local S,i,c,u,vars,eq;
  S:=coxeter['base'](R);
  vars:=seq(c[i],i=1..nops(S));
  u:=convert([seq(c[i]*S[i],i=1..nops(S))],`+`)-v;
  if type(u,'polynom'('rational')) or nops(S)=nops(indets(S)) then
    eq:={coeffs(expand(u),indets(S))}
  else
    u:=collect(u,indets(S));
    eq:={seq(coxeter['iprod'](i,u),i=S)}
  fi;
  subs(`coxeter/linsolve`(eq,{vars}),[vars])
end:
#
save `coxeter/root_coords`, cat(HomeLib,`/coxeter/root_coords.m`);
read cat(HomeLib,`/help/coxeter/root_coords`);
quit;

