#
# base(R) returns a base of simple roots for the root system R.
# co_base(R) returns the simple co-roots for base(R).
# In non-xtal cases, floating-point coordinates are used.
#
`coxeter/base`:=proc(X) local sys,R,i,S,pi;
  if X=1 then []
    elif type(X,'list') then X
    elif type(X,'matrix') then
      R:=coxeter['name_of'](X,'pi');
      S:=`coxeter/base`(R);
      subsop(seq(pi[i]=S[i],i=1..nops(pi)),S)
    else i:=1;
      sys:=sort([op(indets(X))],`coxeter/cox_order`);
      sys:=[seq(R$degree(X,R),R=sys)];
      [seq(`coxeter/base/simple`(R,i,'i'),R=sys)]
  fi
end:
#
`coxeter/co_base`:=proc(R) local r;
  [seq(2*r/coxeter['iprod'](r,r),r=`coxeter/base`(R))]
end:
#
`coxeter/base/simple`:=proc(R) local r,i,j,L,S,a;
  r:=coxeter['rank'](R); i:=args[2];
  if type(R,'indexed') then L:=op(0,R) else L:=substring(R,1..1) fi;
  if R='A1' then
    S:=cat('e',i)
  elif L='A' then
    S:=seq(cat('e',j+1)-cat('e',j),j=i..i+r-1); i:=i+1
  elif L='B' then
    S:=cat('e',i),seq(cat('e',j+1)-cat('e',j),j=i..i+r-2)
  elif L='C' then
    S:=2*cat('e',i),seq(cat('e',j+1)-cat('e',j),j=i..i+r-2)
  elif L='D' and r>1 then
    S:=cat('e',i)+cat('e',i+1),seq(cat('e',j+1)-cat('e',j),j=i..i+r-2)
  elif L='E' and r>2 and r<9 then
    S:=(cat('e',i)-cat('e',i+1)-cat('e',i+2)-cat('e',i+3)-cat('e',i+4)
      -cat('e',i+5)-cat('e',i+6)+cat('e',i+7))/2,cat('e',i)+cat('e',i+1),
      seq(cat('e',j+1)-cat('e',j),j=i..i+r-3); i:=i+8-r
  elif R='F4' then
    S:=(-cat('e',i)-cat('e',i+1)-cat('e',i+2)+cat('e',i+3))/2,
      cat('e',i),cat('e',i+1)-cat('e',i),cat('e',i+2)-cat('e',i+1)
  elif R='G2' then i:=i+1;
    S:=cat('e',i)-cat('e',i-1),cat('e',i-1)-2*cat('e',i)+cat('e',i+1)
  elif R='H3' or R='H4' then a:=evalf((1+sqrt(5))/2);
    S:=-a*cat('e',i)+(a-1)*cat('e',i+1)-cat('e',i+2);
    S:=2*cat('e',i),S,2*cat('e',i+2);
    if r=4 then S:=S,-a*cat('e',i+1)-cat('e',i+2)+(a-1)*cat('e',i+3) fi;
  elif L='I2' and type(op(R)-1,'posint') then a:=op(R);
    S:=op(evalf([cat('e',i),-cos(Pi/a)*cat('e',i)+sin(Pi/a)*cat('e',i+1)]))
  else
    ERROR(cat(R,` is not a recognized root system name`))
  fi;
  assign(args[3],i+r); S
end:
#
save `coxeter/base`, `coxeter/co_base`, `coxeter/base/simple`,
  cat(HomeLib,`/coxeter/base.m`);
read cat(HomeLib,`/help/coxeter/base`);
read cat(HomeLib,`/help/coxeter/co_base`);
quit;

