#
# Build the "neighbor table" for a root system R of rank n:
#  Entry i is a list of neighbors j of the i-th simple root with j>i.
#  For all such pairs, entry (i,j) is the list of roots obtained by
#  applying the j-th reflection to the simple roots i,i+1,...,j-1.
#  Entry n+1 is an empty list. Entry 0 is [n,n-1,...,2,1].  
#  Entry -i is the list of neighbors and 1,...,i-1, sorted in reverse.
# Assuming J is a subset of {1,...,n}, then each member of J is purged
#  from the entries 0,-1,...,-n (used for moving into dominant chambers
#  of corresponding root subsystems).
# Note: neg = a small negative float (or 0, for the xtal case).
# Reference: Sec. 4 in MSJ Memoirs Vol. 11, Math Soc. Japan, 2001,
#  <http://www.math.lsa.umich.edu/~jrs/papers/carswc.ps.gz>.
#
`weyl/neighbor`:=proc(R,J,neg) local S,i,j,IP,sJ;
  S:=coxeter['base'](R);
  sJ:={seq(j=NULL,j=J)};
  for i to nops(S) do
    IP[i]:=NULL; IP[-i]:=seq(-j,j=1-i..-1);
    for j from i+1 to nops(S) do
      if coxeter['iprod'](S[i],S[j])<neg then
        IP[i]:=IP[i],j; IP[-i]:=j,IP[-i];
        IP[i,j]:=map((x,y)->coxeter['reflect'](y,x),[op(i..j-1,S)],S[j]);
      fi
    od;
    IP[i]:=[IP[i]]; IP[-i]:=subs(sJ,[IP[-i]]);
  od;
  IP[0]:=subs(sJ,[seq(-j,j=-nops(S)..-1)]);
  IP[nops(S)+1]:=[]; op(IP);
end:
#
save `weyl/neighbor`, cat(HomeLib,`/weyl/neighbor.m`);
quit;

