#
# An isomorphism tester/finder for directed graphs.
# Based on the fast discriminant (see `posets/fastdisc`).
# Note: this is similar to the algorithm used by Brendan McKay for nauty.
# See http://cs.anu.edu.au:80/people/bdm/nauty/,
#   Congressus Numerantium 21 (1978), 499-517.
#
# isom(P,Q) decides if the digraphs P and Q are isomorphic.
# isom(P,Q,'pi') does the same, and if P is isomorphic to Q, assigns
#  to pi an explicit isomorphism in the form {x1=y1,x2=y2,...},
#  where {x1,x2,...} and {y1,y2,...} are the vertex sets of P and Q.
#
# An undocumented feature: we also allow P and Q to be vertex-colored.
# In this case, the calling sequence should be isom(P,mu,Q,nu), where
# mu and nu are vertex partitions of P and Q (lists of sets).
#
`posets/isom`:=proc() local n,flag,Y,P,mu,pi;
  n:=0; flag:=false;
  for Y in [args] do
    if type(Y,'set(list)') then
      n:=n+1; P[n]:=Y; mu[n]:=[map(op,Y)]
      elif type(Y,'list(set)') then mu[n]:=Y
      elif type(Y,'set') then mu[n]:=[Y]
      elif type(Y,'integer') then mu[n]:=[{$1..Y}]
      elif type(Y,'name') and Y=args[nargs] then flag:=true
      else ERROR(`invalid arguments`)
    fi
  od;
  if n<>2 then ERROR(`invalid arguments`) fi;
  pi:=`posets/cisom`(P[1],mu[1],P[2],mu[2]);
  if pi=NULL then false else
    if flag then assign(args[nargs],pi) fi; true
  fi
end:
#
save `posets/isom`, cat(HomeLib,`/posets/isom.m`);
read cat(HomeLib,`/help/posets/isom`);
quit;

