#
# orbit(v,R) will return the list of all distinct images of the vector v
#  under the action of the reflection group corresponding to R.
# orbit(L,R) where L is a list or set of vectors, will start the algorithm
#  at L and work towards the anti-dominant chamber, instead of starting at
#  a point in the dominant chamber.
#
`coxeter/orbit`:=proc(v0,R) local S,coS,EPS,is_mem,orb,old,new,u,i,v;
  S:=coxeter['base'](R); coS:=coxeter['co_base'](S);
  if type(v0,'set') or type(v0,'list') then orb:=op(v0)
    else orb:=coxeter['vec2fc'](v0,S)
  fi;
  if type([op(S),orb],'list'('polynom'('rational'))) then
    EPS:=0; is_mem:=(x,y,z)->member(x,y)
  else
    EPS:=`coxeter/default`['epsilon'];
    is_mem:=`coxeter/orbit/f`
  fi;
  new:=[orb];
  while nops(new)>0 do
    old:=new; new:=[];
    for u in old do
      for i to nops(S) do
        v:=coxeter['iprod'](coS[i],u);
        if v>EPS then v:=u-v*S[i];
          if not is_mem(v,new,EPS) then new:=[op(new),v] fi
        fi
      od  
    od;  
    orb:=orb,op(new);
  od; [orb]
end:
#
`coxeter/orbit/f`:=proc(v,L,EPS) local u;
  for u in L do if
    convert(map(abs,[coeffs(u-v)]),`+`)<EPS then RETURN(true)
  fi od; false
end:
#
save `coxeter/orbit`, `coxeter/orbit/f`, cat(HomeLib,`/coxeter/orbit.m`);
read cat(HomeLib,`/help/coxeter/orbit`);
quit;
 
