#
# buildall(R) attempts to build orthogonal and rational seminormal models
#  for all irreps of W(R). It also reports diagnostic information about the
#  amount of time (in CPU seconds) and space allocated (in bytes) for each
#  calculation, and the totals.
# If L is a sublist of [1,2,...,m], where m is the number of irreps of W(R),
#  buildall(R,L) only builds models for the irreps indexed by L.
# By default, assume that the simple roots are ordered gracefully.
# Add the optional argument 'slow' to indicate an ungraceful order.
#
# The results of the computation are saved in three tables named
#  Rep, Semi, and Branch. Save these three tables to a file for use in
#  later Maple sessions.
# Use the 'unpack' function to explicitly extract the data in these
#  tables into representing matrices for a particular irrep.
#
# Examples:
#   buildall(E7);
#   save Rep,Semi,Branch,`E7_data.m`;
#
#   buildall(E8,[$1..25]);
#   save Rep,Semi,Branch,`E8_25data.m`;
#
######################################################3
#
# Load version 2.4 of the coxeter package, vanilla edition.
# See:  <www.math.lsa.umich.edu/~jrs/maple.html#coxeter>
# If you already have the (nicer) unix version installed, you can
# comment out the following line, and replace it with the line
#  with(coxeter):

read `coxeter2.4v.txt`; withcoxeter():

read orthogonal;
read quadsolve;
read sparseops;
read clone_test;
read seminormal;
read orthopt;
read unpack;
infolevel[orthopt]:=2;

# Initialize the tables that comprise the database of models.
# Note that we do this only once, when the file is loaded.
# So in a given Maple session, you can only build models for reps of groups
#  that fit in a single parabolic chain. To build reps for another chain,
#  you'll have to re-load this file, or re-initialize the tables yourself.
# You can also jump-start the tables by reading in one of the data files
#  from the data directory, but do this *after* you read this file.
#  (So you can avoid recomputing E7 models prior to building E8 models.)

Rep:=table(); Branch:=table(); Semi:=table();

if `+`(0)=0 then # we are using Maple V.4 or later
  myspace:=proc() kernelopts(bytesalloc) end
else # we don't have to deal with the latest "improvements"
  myspace:=proc() 4*status[2] end
fi;

buildall:=proc(R) local n,L,st0,i,st,stn,fl;
  interface(quiet=true);
  fl:=NULL; L:=[$1..nops(coxeter['class_rep'](R))];
  for i from 2 to nargs do
    if type(args[i],'list') then L:=args[i] else fl:=fl,args[i] fi
  od;
  n:=coxeter['rank'](R); st0:=time();
  for i in L do
    st:=time(); orthogonal(i,R,fl);
    stn:=time(); seminormal(i,n);
    lprint(`seminormal took`,time()-stn);
    print(i,Rep[n][i][1],time()-st,myspace());
  od;
  interface(quiet=false);
  time()-st0,myspace();
end;

