#
# vec2fc(v,R) produces the unique vector v0 in the orbit of v that belongs
#  to the (closure of the) fundamental chamber of R.
# vec2fc(v,R,'w') does the same thing, but also assigns to w the shortest
#  element of W(R) with the property that w.v0 =v.
# longest_elt(R) produces the longest element of W(R).
#
`coxeter/vec2fc`:=proc() local S,EPS,v,w,i;
  S:=coxeter['base'](args[2]); v:=args[1]; w:=NULL;
  if type([op(S),v],'list'('polynom'('rational'))) then EPS:=0
    else EPS:=-`coxeter/default`['epsilon']
  fi;
  do
    for i to nops(S) do
      if coxeter['iprod'](S[i],v)<EPS then w:=w,i;
        v:=coxeter['reflect'](S[i],v); break
      fi
    od;
    if i>nops(S) then break fi;
  od;
  if nargs>2 then assign(args[3],[w]) fi; v
end:
#
`coxeter/longest_elt`:=proc(R) local w,S;
  S:=coxeter['base'](R);
  `coxeter/vec2fc`(-coxeter['interior_pt'](S),S,'w'); w;
end: 
#
save `coxeter/vec2fc`, `coxeter/longest_elt`, cat(HomeLib,`/coxeter/vec2fc.m`);
read cat(HomeLib,`/help/coxeter/vec2fc`);
read cat(HomeLib,`/help/coxeter/longest_elt`);
quit;

