  
  [1XA [33X[0;0YDirected graphs[133X[101X
  
  [33X[0;0YAutomata  are  frequently  described  through  directed labeled graphs. This
  appendix on directed graphs (digraphs) is devoted to some functions designed
  with the purpose of being used as auxiliary functions to deal with automata,
  but may have independent interest.[133X
  
  
  [1XA.1 [33X[0;0YDirected graphs[133X[101X
  
  [33X[0;0YA  directed  graph  with [22Xn[122X vertices is represented by an adjacency list. For
  example,  the list [10XG = [[2,4],[3],[1,4],[]][110X represents a directed graph with
  [10X4 (= Length(G))[110X vertices; the sublist in position [10Xi[110X is the list of endpoints
  of the edges beginning in vertex [22Xi[122X.[133X
  
  [1XA.1-1 RandomDiGraph[101X
  
  [33X[1;0Y[29X[2XRandomDiGraph[102X( [3Xn[103X ) [32X function[133X
  
  [33X[0;0YProduces a pseudo random digraph with [22Xn[122X vertices[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XRandomDiGraph(4);[127X[104X
    [4X[28X[ [  ], [ 1, 2, 4 ], [  ], [  ] ][128X[104X
  [4X[32X[104X
  
  [1XA.1-2 VertexInDegree[101X
  
  [33X[1;0Y[29X[2XVertexInDegree[102X( [3XDG[103X, [3Xv[103X ) [32X function[133X
  
  [33X[0;0YComputes the in degree of the vertex [3Xv[103X of the directed graph [3XDG[103X[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XG:= [ [ 1 ], [ 1, 2, 4 ], [  ], [ 1, 2, 3 ] ];;[127X[104X
    [4X[25Xgap>[125X [27XVertexInDegree(G,2);[127X[104X
    [4X[28X2[128X[104X
  [4X[32X[104X
  
  [1XA.1-3 VertexOutDegree[101X
  
  [33X[1;0Y[29X[2XVertexOutDegree[102X( [3XDG[103X, [3Xv[103X ) [32X function[133X
  
  [33X[0;0YComputes the out degree of the vertex [3Xv[103X of the directed graph [3XDG[103X[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XG:=[ [ 1 ], [ 1, 2, 4 ], [  ], [ 1, 2, 3 ] ];;[127X[104X
    [4X[25Xgap>[125X [27XVertexOutDegree(G,2);[127X[104X
    [4X[28X3[128X[104X
  [4X[32X[104X
  
  [1XA.1-4 AutoVertexDegree[101X
  
  [33X[1;0Y[29X[2XAutoVertexDegree[102X( [3XDG[103X, [3Xv[103X ) [32X function[133X
  
  [33X[0;0YComputes the degree of the vertex [3Xv[103X of the directed graph [3XDG[103X[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XG:=[ [ 1 ], [ 1, 2, 4 ], [  ], [ 1, 2, 3 ] ];;[127X[104X
    [4X[25Xgap>[125X [27XAutoVertexDegree(G,2);[127X[104X
    [4X[28X5[128X[104X
  [4X[32X[104X
  
  [1XA.1-5 ReversedGraph[101X
  
  [33X[1;0Y[29X[2XReversedGraph[102X( [3XG[103X ) [32X function[133X
  
  [33X[0;0YComputes  the  reversed  graph  of  the  directed  graph  G. It is the graph
  obtained from G by reversing the edges.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XG:=[ [  ], [ 4 ], [ 2 ], [ 1, 4 ] ];;[127X[104X
    [4X[25Xgap>[125X [27XReversedGraph(G);[127X[104X
    [4X[28X[ [ 4 ], [ 3 ], [  ], [ 2, 4 ] ][128X[104X
  [4X[32X[104X
  
  [33X[0;0YWe  say that a digraph is connected when for every pair of vertices there is
  a  path  consisting  of  directed  or  reversed edges from one vertex to the
  other.[133X
  
  [1XA.1-6 AutoConnectedComponents[101X
  
  [33X[1;0Y[29X[2XAutoConnectedComponents[102X( [3XG[103X ) [32X function[133X
  
  [33X[0;0YComputes a list of the connected components of the digraph[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XG:=[ [  ], [ 1, 4, 5, 6 ], [  ], [ 1, 3, 5, 6 ], [ 2, 3 ], [ 2, 4, 6 ] ];;[127X[104X
    [4X[25Xgap>[125X [27XAutoConnectedComponents(G);[127X[104X
    [4X[28X[ [ 1, 2, 3, 4, 5, 6 ] ][128X[104X
  [4X[32X[104X
  
  [33X[0;0YTwo  vertices of a digraph belong to a strongly connected component if there
  is a directed path from each one to the other.[133X
  
  [1XA.1-7 GraphStronglyConnectedComponents[101X
  
  [33X[1;0Y[29X[2XGraphStronglyConnectedComponents[102X( [3XG[103X ) [32X function[133X
  
  [33X[0;0YProduces the strongly connected components of the digraph [3XG[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XG:=[ [  ], [ 4 ], [  ], [ 4, 6 ], [  ], [ 1, 4, 5, 6 ] ];;[127X[104X
    [4X[25Xgap>[125X [27XSet(GraphStronglyConnectedComponents(G));[127X[104X
    [4X[28X[ [ 1 ], [ 2 ], [ 3 ], [ 5 ], [ 6, 4 ] ][128X[104X
  [4X[32X[104X
  
  [1XA.1-8 UnderlyingMultiGraphOfAutomaton[101X
  
  [33X[1;0Y[29X[2XUnderlyingMultiGraphOfAutomaton[102X( [3XA[103X ) [32X function[133X
  
  [33X[0;0Y[3XA[103X is an automaton. The output is the underlying directed multi-graph.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xa := Automaton("det",3,"ab",[ [ 0, 3, 0 ], [ 1, 2, 3 ] ],[ 1 ],[ 1 ]);;[127X[104X
    [4X[25Xgap>[125X [27XDisplay(a);[127X[104X
    [4X[28X   |  1  2  3  [128X[104X
    [4X[28X--------------[128X[104X
    [4X[28X a |     3     [128X[104X
    [4X[28X b |  1  2  3  [128X[104X
    [4X[28XInitial state:   [ 1 ][128X[104X
    [4X[28XAccepting state: [ 1 ][128X[104X
    [4X[25Xgap>[125X [27XUnderlyingMultiGraphOfAutomaton(a);[127X[104X
    [4X[28X[ [ 1 ], [ 3, 2 ], [ 3 ] ][128X[104X
  [4X[32X[104X
  
  [1XA.1-9 UnderlyingGraphOfAutomaton[101X
  
  [33X[1;0Y[29X[2XUnderlyingGraphOfAutomaton[102X( [3XA[103X ) [32X function[133X
  
  [33X[0;0Y[3XA[103X is an automaton. The output is the underlying directed graph.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xa := Automaton("det",3,"ab",[ [ 2, 3, 0 ], [ 0, 1, 3 ] ],[ 2 ],[ 1, 2, 3 ]);;[127X[104X
    [4X[25Xgap>[125X [27XDisplay(a);[127X[104X
    [4X[28X   |  1  2  3  [128X[104X
    [4X[28X--------------[128X[104X
    [4X[28X a |  2  3     [128X[104X
    [4X[28X b |     1  3  [128X[104X
    [4X[28XInitial state:    [ 2 ][128X[104X
    [4X[28XAccepting states: [ 1, 2, 3 ][128X[104X
    [4X[25Xgap>[125X [27XUnderlyingGraphOfAutomaton(a);[127X[104X
    [4X[28X[ [ 2 ], [ 1, 3 ], [ 3 ] ][128X[104X
  [4X[32X[104X
  
  [1XA.1-10 DiGraphToRelation[101X
  
  [33X[1;0Y[29X[2XDiGraphToRelation[102X( [3XD[103X ) [32X function[133X
  
  [33X[0;0YReturns  the  relation  corresponding  to  the digraph. Note that a directed
  graph  may  be  seen  in  a  natural  way as a binary relation on the set of
  vertices.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XG:=[ [  ], [  ], [ 4 ], [ 4 ] ];;[127X[104X
    [4X[25Xgap>[125X [27XDiGraphToRelation(G);[127X[104X
    [4X[28X[ [ 3, 4 ], [ 4, 4 ] ][128X[104X
  [4X[32X[104X
  
  [1XA.1-11 MSccAutomaton[101X
  
  [33X[1;0Y[29X[2XMSccAutomaton[102X( [3XA[103X ) [32X function[133X
  
  [33X[0;0YProduces  an  automaton  where,  in each strongly connected component, edges
  labeled by inverses are added. (M stands for modified.)[133X
  
  [33X[0;0YThis construction is useful in Finite Semigroup Theory.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xa := Automaton("det",3,"ab",[ [ 0, 2, 0 ], [ 1, 2, 0 ] ],[ 3 ],[ 1, 3 ]);;[127X[104X
    [4X[25Xgap>[125X [27XDisplay(a);[127X[104X
    [4X[28X   |  1  2  3  [128X[104X
    [4X[28X--------------[128X[104X
    [4X[28X a |     2     [128X[104X
    [4X[28X b |  1  2     [128X[104X
    [4X[28XInitial state:    [ 3 ][128X[104X
    [4X[28XAccepting states: [ 1, 3 ][128X[104X
    [4X[25Xgap>[125X [27XMSccAutomaton(a);[127X[104X
    [4X[28X< deterministic automaton on 4 letters with 3 states >[128X[104X
    [4X[25Xgap>[125X [27XDisplay(last);[127X[104X
    [4X[28X   |  1  2  3  [128X[104X
    [4X[28X--------------[128X[104X
    [4X[28X a |     2     [128X[104X
    [4X[28X b |  1  2     [128X[104X
    [4X[28X A |     2     [128X[104X
    [4X[28X B |  1  2     [128X[104X
    [4X[28XInitial state:    [ 3 ][128X[104X
    [4X[28XAccepting states: [ 1, 3 ][128X[104X
  [4X[32X[104X
  
  [1XA.1-12 AutoIsAcyclicGraph[101X
  
  [33X[1;0Y[29X[2XAutoIsAcyclicGraph[102X( [3XG[103X ) [32X function[133X
  
  [33X[0;0YThe argument is a graph's list of adjacencies and this function returns true
  if the argument is an acyclic graph and false otherwise.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XG := [ [  ], [ 3 ], [ 2 ] ];;[127X[104X
    [4X[25Xgap>[125X [27XAutoIsAcyclicGraph(last);[127X[104X
    [4X[28Xfalse[128X[104X
  [4X[32X[104X
  
