#
# P &u Q returns the disjoint union of the posets P and Q. That is, the
#  vertices of P and Q are renamed so as to be disjoint sets, and then
#  the union of P and Q is returned. (One can also use P &u Q &u R, etc).
#  If one or more of the posets, say P, has isolated vertices, then one
#  must use the syntax (P,X) &u Q or (P,n) &u Q, where X or {1,...,n} is
#  the vertex set of P, resp.
# The output will be a poset on the vertex set {1,2,...,m} for some m.
#  If any of the arguments are of the form (P,X) or (P,n), then the
#  output will also be of this form.
#
`posets/&u`:=proc() local P,Q,X,i,n,flag,j;
  flag:=false; n:=0; Q:=NULL;
  for i to nargs do P:=args[i];
    if i=nargs or type(args[i+1],'set'('list')) then X:=map(op,P)
      elif type(args[i+1],'set') then
        flag:=true; i:=i+1; X:=args[i]
      elif type(args[i+1],'integer') then
        flag:=true; i:=i+1; X:={$1..args[i]}
      else ERROR(`invalid arguments`) fi;
    Q:=Q,subs({seq(X[j]=j+n,j=1..nops(X))},P);
    n:=n+nops(X);
  od;
  Q:=map(op,{Q});
  if flag then Q,n else Q fi;
end:
#
save `posets/&u`, cat(HomeLib,`/posets/disj_union.m`);
read cat(HomeLib,`/help/posets/disj_union`);
quit;

