#
# P &* Q returns the direct product of the posets P and Q. Similarly, one
#  may use P &* Q &* R, etc. If any of the posets, say P, has isolated
#  vertices, then one must use the syntax (P,X) &* Q or (P,n) &* Q,
#  according to whether X or {1,...,n} is the vertex set of P.
# The output will be a poset on the vertex set {1,2,...,m} for some m.
#  If all of the arguments are of the form (P,X) or (P,n), then the
#  output will also be of this form.
# N.B.: rather than trap errors, we must return bad input unevaluated
#  in order to avoid breaking certain Maple commands in V.3 or later.
# It would be safer to name this `&p`....
#
`posets/&*`:=proc() local flag,P,Q,X,Y,n,i,j,x,e;
  flag:=true; n:=1; Q:={};
  for i to nargs do P:=args[i];
    if not type(P,'set'('list')) then RETURN('procname(args)')
      elif i=nargs or type(args[i+1],'set'('list')) then
        flag:=false; X:=map(op,P)
      elif type(args[i+1],'set') then i:=i+1; X:=args[i]
      elif type(args[i+1],'integer') then i:=i+1; X:={$1..args[i]}
      else RETURN('procname(args)') fi;
    Y:=[seq(seq([j,x],j=1..n),x=X)];
    Y:=table([seq(op(Y[j])=j,j=1..nops(Y))]);
    Q:={seq(seq([Y[e[1],x],Y[e[2],x]],x=X),e=Q),
      seq(seq([Y[j,e[1]],Y[j,e[2]]],j=1..n),e=P)};
    n:=n*nops(X);
  od;
  if flag then Q,n else Q fi;
end:
#
save `posets/&*`, cat(HomeLib,`/posets/product.m`);
read cat(HomeLib,`/help/posets/product`);
quit;

