  
  [1X2 [33X[0;0YFinite Automata[133X[101X
  
  [33X[0;0YThis  chapter  describes the representations used in this package for finite
  automata and some functions to determine information about them.[133X
  
  [33X[0;0YWe  have  to  remark  that  the  states  of  an  automaton  are always named
  [22X1,2,3,...;[122X  the  alphabet  may  be  given  by  the  user.  By  default it is
  [22X{a,b,c,...}[122X (or [22X{a_1,a_2,a_3,...}[122X in the case of alphabets with more than [22X26[122X
  letters).[133X
  
  [33X[0;0YThe  transition function of an automaton with [22Xq[122X states over an alphabet with
  [22Xn[122X  letters is represented by a (not necessarily dense) [22Xn× q[122X matrix. Each row
  of  the  matrix  describes  the  action  of  the corresponding letter on the
  states.  In  the  case of a [13Xdeterministic automaton[113X (DFA) the entries of the
  matrix  are  non-negative integers. When all entries of the transition table
  are positive integers, the automaton is said to be [13Xdense[113X or [13Xcomplete[113X. In the
  case of a [13Xnon deterministic automaton[113X (NFA) the entries of the matrix may be
  lists  of  non-negative  integers.  [13XAutomata  with  [22Xϵ[122X-transitions[113X  are  also
  allowed:  the  last  letter  of  the  alphabet  is  assumed  to  be [22Xϵ[122X and is
  represented by @.[133X
  
  
  [1X2.1 [33X[0;0YAutomata generation[133X[101X
  
  [33X[0;0YThe way to create an automaton in [5XGAP[105X is the following[133X
  
  [1X2.1-1 Automaton[101X
  
  [33X[1;0Y[29X[2XAutomaton[102X( [3XType[103X, [3XSize[103X, [3XAlphabet[103X, [3XTransitionTable[103X, [3XInitial[103X, [3XAccepting[103X ) [32X function[133X
  
  [33X[0;0Y[10XType[110X  may be [10X"det"[110X, [10X"nondet"[110X or [10X"epsilon"[110X according to whether the automaton
  is deterministic, non deterministic or an automaton with [22Xϵ[122X-transitions. [10XSize[110X
  is  a  positive  integer representing the number of states of the automaton.
  [10XAlphabet[110X is the number of letters of the alphabet or a list with the letters
  of  the  ordered  alphabet.  [10XTransitionTable[110X  is  the transition matrix. The
  entries  are  non-negative  integers  not  greater  than  the  size  of  the
  automaton.  In the case of non deterministic automata, lists of non-negative
  integers  not  greater  than  the  size  of  the automaton are also allowed.
  [10XInitial[110X  and [10XAccepting[110X are, respectively, the lists of initial and accepting
  states.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28X[128X[104X
    [4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,4]],[1],[4]);[127X[104X
    [4X[28X< deterministic automaton on 2 letters with 4 states >[128X[104X
    [4X[25Xgap>[125X [27XDisplay(aut);[127X[104X
    [4X[28X   |  1  2  3  4[128X[104X
    [4X[28X-----------------[128X[104X
    [4X[28X a |  3     3  4[128X[104X
    [4X[28X b |  3  4     4[128X[104X
    [4X[28XInitial state:   [ 1 ][128X[104X
    [4X[28XAccepting state: [ 4 ][128X[104X
    [4X[28X[128X[104X
  [4X[32X[104X
  
  [33X[0;0YThe alphabet of the automaton may be specified:[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xaut:=Automaton("det",4,"01",[[3,,3,4],[3,4,0,4]],[1],[4]);[127X[104X
    [4X[28X< deterministic automaton on 2 letters with 4 states >[128X[104X
    [4X[25Xgap>[125X [27XDisplay(aut);[127X[104X
    [4X[28X   |  1  2  3  4[128X[104X
    [4X[28X-----------------[128X[104X
    [4X[28X 0 |  3     3  4[128X[104X
    [4X[28X 1 |  3  4     4[128X[104X
    [4X[28XInitial state:   [ 1 ][128X[104X
    [4X[28XAccepting state: [ 4 ][128X[104X
  [4X[32X[104X
  
  [33X[0;0YInstead of leaving a hole in the transition matrix, we may write a [10X0[110X to mean
  that  no  transition is present. Non deterministic automata may be given the
  same way.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xndaut:=Automaton("nondet",4,2,[[3,[1,2],3,0],[3,4,0,[2,3]]],[1],[4]);[127X[104X
    [4X[28X< non deterministic automaton on 2 letters with 4 states >[128X[104X
    [4X[25Xgap>[125X [27XDisplay(ndaut);[127X[104X
    [4X[28X   |  1       2          3       4[128X[104X
    [4X[28X-----------------------------------------[128X[104X
    [4X[28X a | [ 3 ]   [ 1, 2 ]   [ 3 ][128X[104X
    [4X[28X b | [ 3 ]   [ 4 ]              [ 2, 3 ][128X[104X
    [4X[28XInitial state:   [ 1 ][128X[104X
    [4X[28XAccepting state: [ 4 ][128X[104X
  [4X[32X[104X
  
  [33X[0;0YAlso  in  the  same  way  can be given [22Xϵ[122X-automata. The letter [22Xϵ[122X is written [10X@[110X
  instead.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx:=Automaton("epsilon",3,"01@",[[,[2],[3]],[[1,3],,[1]],[[1],[2],[127X[104X
    [4X[25X>[125X [27X[2]]],[2],[2,3]);[127X[104X
    [4X[28X< epsilon automaton on 3 letters with 3 states >[128X[104X
    [4X[25Xgap>[125X [27XDisplay(x);[127X[104X
    [4X[28X   |  1          2       3[128X[104X
    [4X[28X------------------------------[128X[104X
    [4X[28X 0 |            [ 2 ]   [ 3 ][128X[104X
    [4X[28X 1 | [ 1, 3 ]           [ 1 ][128X[104X
    [4X[28X @ | [ 1 ]      [ 2 ]   [ 2 ][128X[104X
    [4X[28XInitial state:    [ 2 ][128X[104X
    [4X[28XAccepting states: [ 2, 3 ][128X[104X
  [4X[32X[104X
  
  [33X[0;0YBigger automata are displayed in another form:[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xaut:=Automaton("det",16,2,[[4,0,0,6,3,1,4,8,7,4,3,0,6,1,6,0],[127X[104X
    [4X[25X>[125X [27X[3,4,0,0,6,1,0,6,1,6,1,6,6,4,8,7,4,5]],[1],[4]);[127X[104X
    [4X[28X< deterministic automaton on 2 letters with 16 states >[128X[104X
    [4X[25Xgap>[125X [27XDisplay(aut);[127X[104X
    [4X[28X1    a   4[128X[104X
    [4X[28X1    b   3[128X[104X
    [4X[28X2    b   4[128X[104X
    [4X[28X    ... some more lines[128X[104X
    [4X[28X15   a   6[128X[104X
    [4X[28X15   b   8[128X[104X
    [4X[28X16   b   7[128X[104X
    [4X[28XInitial state:   [ 1 ][128X[104X
    [4X[28XAccepting state: [ 4 ][128X[104X
  [4X[32X[104X
  
  [1X2.1-2 IsAutomaton[101X
  
  [33X[1;0Y[29X[2XIsAutomaton[102X( [3XO[103X ) [32X function[133X
  
  [33X[0;0YIn  the  presence  of  an  object  [3XO[103X,  one  may want to test whether [10XO[110X is an
  automaton. This may be done using the function [10XIsAutomaton[110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;[127X[104X
    [4X[25Xgap>[125X [27XIsAutomaton(x);[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X2.1-3 IsDeterministicAutomaton[101X
  
  [33X[1;0Y[29X[2XIsDeterministicAutomaton[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YReturns [9Xtrue[109X when [10Xaut[110X is a deterministic automaton and [9Xfalse[109X otherwise.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;[127X[104X
    [4X[25Xgap>[125X [27XIsDeterministicAutomaton(x);[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X2.1-4 IsNonDeterministicAutomaton[101X
  
  [33X[1;0Y[29X[2XIsNonDeterministicAutomaton[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YReturns [9Xtrue[109X when [10Xaut[110X is a non deterministic automaton and [9Xfalse[109X otherwise.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xy:=Automaton("nondet",3,2,[[,[1,3],],[,[2,3],[1,3]]],[1,2],[1,3]);;[127X[104X
    [4X[25Xgap>[125X [27XIsNonDeterministicAutomaton(y);[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X2.1-5 IsEpsilonAutomaton[101X
  
  [33X[1;0Y[29X[2XIsEpsilonAutomaton[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YReturns [9Xtrue[109X when [10Xaut[110X is an [22Xϵ[122X-automaton and [9Xfalse[109X otherwise.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xz:=Automaton("epsilon",2,2,[[[1,2],],[[2],[1]]],[1,2],[1,2]);;[127X[104X
    [4X[25Xgap>[125X [27XIsEpsilonAutomaton(z);[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X2.1-6 String[101X
  
  [33X[1;0Y[29X[2XString[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YThe way [5XGAP[105X displays an automaton is quite natural, but when one wants to do
  small  changes, for example using [13Xcopy/paste[113X, the use of the function [10XString[110X
  (possibly followed by [10XPrint[110X) may be usefull.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;[127X[104X
    [4X[25Xgap>[125X [27XString(x);[127X[104X
    [4X[28X"Automaton(\"det\",3,\"ab\",[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;"[128X[104X
    [4X[25Xgap>[125X [27XPrint(String(x));[127X[104X
    [4X[28XAutomaton("det",3,"ab",[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;[128X[104X
  [4X[32X[104X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xz:=Automaton("epsilon",2,2,[[[1,2],],[[2],[1]]],[1,2],[1,2]);;[127X[104X
    [4X[25Xgap>[125X [27XPrint(String(z));[127X[104X
    [4X[28XAutomaton("epsilon",2,"a@",[ [ [ 1, 2 ], [ ] ], [ [ 2 ], [ 1 ] ] ],[ 1, 2 ],[ \[128X[104X
    [4X[28X1, 2 ]);;[128X[104X
  [4X[32X[104X
  
  [1X2.1-7 RandomAutomaton[101X
  
  [33X[1;0Y[29X[2XRandomAutomaton[102X( [3XType[103X, [3XSize[103X, [3XAlphabet[103X ) [32X function[133X
  
  [33X[0;0YGiven  the  [3XType[103X,  the  [3XSize[103X (i.e. the number of states) and the [3XAlphabet[103X (a
  positive  integer  or  a list), returns a pseudo random automaton with these
  parameters.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XRandomAutomaton("det",5,"ac");[127X[104X
    [4X[28X< deterministic automaton on 2 letters with 5 states >[128X[104X
    [4X[25Xgap>[125X [27XDisplay(last);[127X[104X
    [4X[28X   |  1  2  3  4  5[128X[104X
    [4X[28X--------------------[128X[104X
    [4X[28X a |     2  3[128X[104X
    [4X[28X c |  2  3[128X[104X
    [4X[28XInitial state:    [ 4 ][128X[104X
    [4X[28XAccepting states: [ 3, 4 ][128X[104X
    [4X[28X[128X[104X
    [4X[25Xgap>[125X [27XRandomAutomaton("nondet",3,["a","b","c"]);[127X[104X
    [4X[28X< non deterministic automaton on 3 letters with 3 states >[128X[104X
    [4X[28X[128X[104X
    [4X[25Xgap>[125X [27XRandomAutomaton("epsilon",2,"abc");[127X[104X
    [4X[28X< epsilon automaton on 4 letters with 2 states >[128X[104X
    [4X[28X[128X[104X
    [4X[25Xgap>[125X [27XRandomAutomaton("epsilon",2,2);[127X[104X
    [4X[28X< epsilon automaton on 3 letters with 2 states >[128X[104X
    [4X[25Xgap>[125X [27XDisplay(last);[127X[104X
    [4X[28X   |  1          2[128X[104X
    [4X[28X----------------------[128X[104X
    [4X[28X a | [ 1, 2 ][128X[104X
    [4X[28X b | [ 2 ]      [ 1 ][128X[104X
    [4X[28X @ | [ 1, 2 ][128X[104X
    [4X[28XInitial state:    [ 2 ][128X[104X
    [4X[28XAccepting states: [ 1, 2 ][128X[104X
    [4X[28X[128X[104X
    [4X[25Xgap>[125X [27Xa:=RandomTransformation(3);;[127X[104X
    [4X[25Xgap>[125X [27Xb:=RandomTransformation(3);;[127X[104X
    [4X[25Xgap>[125X [27Xaut:=RandomAutomaton("det",4,[a,b]);[127X[104X
    [4X[28X< deterministic automaton on 2 letters with 4 states >[128X[104X
  [4X[32X[104X
  
  
  [1X2.2 [33X[0;0YAutomata internals[133X[101X
  
  [33X[0;0YIn this section we describe the functions used to access the internals of an
  automaton.[133X
  
  [1X2.2-1 AlphabetOfAutomaton[101X
  
  [33X[1;0Y[29X[2XAlphabetOfAutomaton[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YReturns the number of symbols in the alphabet of automaton [10Xaut[110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;[127X[104X
    [4X[25Xgap>[125X [27XAlphabetOfAutomaton(aut);[127X[104X
    [4X[28X2[128X[104X
  [4X[32X[104X
  
  [1X2.2-2 AlphabetOfAutomatonAsList[101X
  
  [33X[1;0Y[29X[2XAlphabetOfAutomatonAsList[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YReturns  the  alphabet of automaton [10Xaut[110X always as a list. Note that when the
  alphabet  of  the  automaton  is  given as an integer (meaning the number of
  symbols) not greater than 26 it returns the list [10X"abcd...."[110X. If the alphabet
  is  given  by  means  of  an integer greater than 26, the function returns [10X[
  "a1", "a2", "a3", "a4", ... ][110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xa:=RandomAutomaton("det",5,"cat");[127X[104X
    [4X[28X< deterministic automaton on 3 letters with 5 states >[128X[104X
    [4X[25Xgap>[125X [27XAlphabetOfAutomaton(a);[127X[104X
    [4X[28X3[128X[104X
    [4X[25Xgap>[125X [27XAlphabetOfAutomatonAsList(a);[127X[104X
    [4X[28X"cat"[128X[104X
    [4X[25Xgap>[125X [27Xa:=RandomAutomaton("det",5,20);[127X[104X
    [4X[28X< deterministic automaton on 20 letters with 5 states >[128X[104X
    [4X[25Xgap>[125X [27XAlphabetOfAutomaton(a);[127X[104X
    [4X[28X20[128X[104X
    [4X[25Xgap>[125X [27XAlphabetOfAutomatonAsList(a);[127X[104X
    [4X[28X"abcdefghijklmnopqrst"[128X[104X
    [4X[25Xgap>[125X [27Xa:=RandomAutomaton("det",5,30);[127X[104X
    [4X[28X< deterministic automaton on 30 letters with 5 states >[128X[104X
    [4X[25Xgap>[125X [27XAlphabetOfAutomaton(a);[127X[104X
    [4X[28X30[128X[104X
    [4X[25Xgap>[125X [27XAlphabetOfAutomatonAsList(a);[127X[104X
    [4X[28X[ "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11", [128X[104X
    [4X[28X  "a12", "a13", "a14", "a15", "a16", "a17", "a18", "a19", "a20", "a21",[128X[104X
    [4X[28X  "a22", "a23", "a24", "a25", "a26", "a27", "a28", "a29", "a30" ][128X[104X
  [4X[32X[104X
  
  [1X2.2-3 TransitionMatrixOfAutomaton[101X
  
  [33X[1;0Y[29X[2XTransitionMatrixOfAutomaton[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YReturns the transition matrix of automaton [10Xaut[110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;[127X[104X
    [4X[25Xgap>[125X [27XTransitionMatrixOfAutomaton(aut);[127X[104X
    [4X[28X[ [ 3, 0, 3, 4 ], [ 3, 4, 0, 0 ] ][128X[104X
  [4X[32X[104X
  
  [1X2.2-4 InitialStatesOfAutomaton[101X
  
  [33X[1;0Y[29X[2XInitialStatesOfAutomaton[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YReturns the initial states of automaton [10Xaut[110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;[127X[104X
    [4X[25Xgap>[125X [27XInitialStatesOfAutomaton(aut);[127X[104X
    [4X[28X[ 1 ][128X[104X
  [4X[32X[104X
  
  [1X2.2-5 SetInitialStatesOfAutomaton[101X
  
  [33X[1;0Y[29X[2XSetInitialStatesOfAutomaton[102X( [3Xaut[103X, [3XI[103X ) [32X function[133X
  
  [33X[0;0YSets  the  initial states of automaton [10Xaut[110X. [10XI[110X may be a positive integer or a
  list of positive integers.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;[127X[104X
    [4X[25Xgap>[125X [27XSetInitialStatesOfAutomaton(aut,4);[127X[104X
    [4X[25Xgap>[125X [27XInitialStatesOfAutomaton(aut);[127X[104X
    [4X[28X[ 4 ][128X[104X
    [4X[25Xgap>[125X [27XSetInitialStatesOfAutomaton(aut,[2,3]);[127X[104X
    [4X[25Xgap>[125X [27XInitialStatesOfAutomaton(aut);[127X[104X
    [4X[28X[ 2, 3 ][128X[104X
  [4X[32X[104X
  
  [1X2.2-6 FinalStatesOfAutomaton[101X
  
  [33X[1;0Y[29X[2XFinalStatesOfAutomaton[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YReturns the final states of automaton [10Xaut[110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;[127X[104X
    [4X[25Xgap>[125X [27XFinalStatesOfAutomaton(aut);[127X[104X
    [4X[28X[ 4 ][128X[104X
  [4X[32X[104X
  
  [1X2.2-7 SetFinalStatesOfAutomaton[101X
  
  [33X[1;0Y[29X[2XSetFinalStatesOfAutomaton[102X( [3Xaut[103X, [3XF[103X ) [32X function[133X
  
  [33X[0;0YSets  the  final  states  of automaton [10Xaut[110X. [10XF[110X may be a positive integer or a
  list of positive integers.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;[127X[104X
    [4X[25Xgap>[125X [27XFinalStatesOfAutomaton(aut);[127X[104X
    [4X[28X[ 4 ][128X[104X
    [4X[25Xgap>[125X [27XSetFinalStatesOfAutomaton(aut,2);[127X[104X
    [4X[25Xgap>[125X [27XFinalStatesOfAutomaton(aut);[127X[104X
    [4X[28X[ 2 ][128X[104X
  [4X[32X[104X
  
  [1X2.2-8 NumberStatesOfAutomaton[101X
  
  [33X[1;0Y[29X[2XNumberStatesOfAutomaton[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YReturns the number of states of automaton [10Xaut[110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;[127X[104X
    [4X[25Xgap>[125X [27XNumberStatesOfAutomaton(aut);[127X[104X
    [4X[28X4[128X[104X
  [4X[32X[104X
  
  
  [1X2.3 [33X[0;0YComparison of automata[133X[101X
  
  [33X[0;0YAlthough  there  is  no standard way to compare automata it is usefull to be
  able  to  do  some  kind  of  comparison. Doing so, one can consider sets of
  automata. We just compare the strings of the automata.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;[127X[104X
    [4X[25Xgap>[125X [27Xy:=Automaton("det",3,2,[ [ 2, 0, 0 ], [ 1, 3, 0 ] ],[ 3 ],[ 2, 3 ]);;[127X[104X
    [4X[25Xgap>[125X [27Xx=y;[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27XSize(Set([y,x,x]));[127X[104X
    [4X[28X2[128X[104X
  [4X[32X[104X
  
  
  [1X2.4 [33X[0;0YTests involving automata[133X[101X
  
  [33X[0;0YThis section describes some useful tests involving automata.[133X
  
  [1X2.4-1 IsDenseAutomaton[101X
  
  [33X[1;0Y[29X[2XIsDenseAutomaton[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YTests   whether  a  deterministic  automaton  [10Xaut[110X  is  complete.  (See  also
  [2XNullCompletionAutomaton[102X ([14X2.5-2[114X).)[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;[127X[104X
    [4X[25Xgap>[125X [27XIsDenseAutomaton(aut);                                 [127X[104X
    [4X[28Xfalse[128X[104X
  [4X[32X[104X
  
  [1X2.4-2 IsRecognizedByAutomaton[101X
  
  [33X[1;0Y[29X[2XIsRecognizedByAutomaton[102X( [3XA[103X, [3Xw[103X ) [32X function[133X
  
  [33X[0;0YThe  arguments  are:  an  automaton  [3XA[103X  and  a string (i.e. a word) [3Xw[103X in the
  alphabet  of  the  automaton.  Returns [10Xtrue[110X if the word is recognized by the
  automaton and [10Xfalse[110X otherwise.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xaut:=Automaton("det",3,2,[[1,2,1],[2,1,3]],[1],[2]);;[127X[104X
    [4X[25Xgap>[125X [27XIsRecognizedByAutomaton(aut,"bbb");[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[28X[128X[104X
    [4X[25Xgap>[125X [27Xaut:=Automaton("det",3,"01",[[1,2,1],[2,1,3]],[1],[2]);;[127X[104X
    [4X[25Xgap>[125X [27XIsRecognizedByAutomaton(aut,"111");[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X2.4-3 IsPermutationAutomaton[101X
  
  [33X[1;0Y[29X[2XIsPermutationAutomaton[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YThe  argument is a deterministic automaton. Returns [9Xtrue[109X when each letter of
  the alphabet induces a permutation on the vertices and [9Xfalse[109X otherwise.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 1, 2, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2, 3 ]);;[127X[104X
    [4X[25Xgap>[125X [27XIsPermutationAutomaton(x);[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X2.4-4 IsInverseAutomaton[101X
  
  [33X[1;0Y[29X[2XIsInverseAutomaton[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YThe  argument is a deterministic automaton. Returns [9Xtrue[109X when each letter of
  the alphabet induces an injective partial function on the vertices and [9Xfalse[109X
  otherwise.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 0, 1, 3 ], [ 0, 1, 2 ] ],[ 2 ],[ 1 ]);;[127X[104X
    [4X[25Xgap>[125X [27XIsInverseAutomaton(x);[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [33X[0;0YFrequently  an inverse automaton is thought as if the inverse edges (labeled
  by  formal  inverses  of the letters of the alphabet) were present, although
  they  are  usually  not  explicited.  They  can  be  made explicit using the
  function [10XAddInverseEdgesToInverseAutomaton[110X[133X
  
  [1X2.4-5 AddInverseEdgesToInverseAutomaton[101X
  
  [33X[1;0Y[29X[2XAddInverseEdgesToInverseAutomaton[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YThe  argument is an inverse automaton over the alphabet [22X{a,b,c,...}[122X. Returns
  an  automaton  with the inverse edges added. (The formal inverse of a letter
  is represented by the corresponding capital letter.)[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[[ 0, 1, 3 ],[ 0, 1, 2 ]],[ 2 ],[ 1 ]);;Display(x);[127X[104X
    [4X[28X   |  1  2  3[128X[104X
    [4X[28X--------------[128X[104X
    [4X[28X a |     1  3[128X[104X
    [4X[28X b |     1  2[128X[104X
    [4X[28XInitial state:   [ 2 ][128X[104X
    [4X[28XAccepting state: [ 1 ][128X[104X
    [4X[25Xgap>[125X [27XAddInverseEdgesToInverseAutomaton(x);Display(x);[127X[104X
    [4X[28X   |  1  2  3[128X[104X
    [4X[28X--------------[128X[104X
    [4X[28X a |     1  3[128X[104X
    [4X[28X b |     1  2[128X[104X
    [4X[28X A |  2     3[128X[104X
    [4X[28X B |  2  3[128X[104X
    [4X[28XInitial state:   [ 2 ][128X[104X
    [4X[28XAccepting state: [ 1 ][128X[104X
  [4X[32X[104X
  
  [1X2.4-6 IsReversibleAutomaton[101X
  
  [33X[1;0Y[29X[2XIsReversibleAutomaton[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YThe  argument  is  a  deterministic  automaton.  Returns  [9Xtrue[109X when [3Xaut[103X is a
  reversible automaton, i.e. the automaton obtained by reversing all edges and
  switching  the initial and final states (see also [2XReversedAutomaton[102X ([14X2.5-5[114X))
  is deterministic. Returns [9Xfalse[109X otherwise.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 0, 1, 2 ], [ 0, 1, 3 ] ],[ 2 ],[ 2 ]);;[127X[104X
    [4X[25Xgap>[125X [27XIsReversibleAutomaton(x);[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  
  [1X2.5 [33X[0;0YBasic operations[133X[101X
  
  [1X2.5-1 CopyAutomaton[101X
  
  [33X[1;0Y[29X[2XCopyAutomaton[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YReturns a new automaton, which is a copy of automaton [3Xaut[103X.[133X
  
  [1X2.5-2 NullCompletionAutomaton[101X
  
  [33X[1;0Y[29X[2XNullCompletionAutomaton[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0Y[10Xaut[110X  is  a deterministic automaton. If it is complete returns [3Xaut[103X, otherwise
  returns  the  completion  (with  a null state) of [3Xaut[103X. Notice that the words
  recognized by [3Xaut[103X and its completion are the same.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[2,4,4,]],[1],[4]);;[127X[104X
    [4X[25Xgap>[125X [27XIsDenseAutomaton(aut);[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27Xy:=NullCompletionAutomaton(aut);;Display(y);[127X[104X
    [4X[28X   |  1  2  3  4  5[128X[104X
    [4X[28X--------------------[128X[104X
    [4X[28X a |  3  5  3  4  5[128X[104X
    [4X[28X b |  2  4  4  5  5[128X[104X
    [4X[28XInitial state:   [ 1 ][128X[104X
    [4X[28XAccepting state: [ 4 ][128X[104X
  [4X[32X[104X
  
  [33X[0;0YThe  state  added  is a [13Xsink state[113X i.e. it is a state [22Xq[122X which is not initial
  nor  accepting  and  for all letter [22Xa[122X in the alphabet of the automaton, [22Xq[122X is
  the  result  of  the action of [22Xa[122X in [22Xq[122X. (Notice that reading a word, one does
  not go out of a sink state.)[133X
  
  [1X2.5-3 ListSinkStatesAut[101X
  
  [33X[1;0Y[29X[2XListSinkStatesAut[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YComputes the list of all sink states of the automaton [3Xaut[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 2, 3, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2, 3 ]);;[127X[104X
    [4X[25Xgap>[125X [27XListSinkStatesAut(x);[127X[104X
    [4X[28X[  ][128X[104X
    [4X[25Xgap>[125X [27Xy:=Automaton("det",3,2,[ [ 2, 3, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2 ]);;[127X[104X
    [4X[25Xgap>[125X [27XListSinkStatesAut(y);[127X[104X
    [4X[28X[ 3 ][128X[104X
  [4X[32X[104X
  
  [1X2.5-4 RemovedSinkStates[101X
  
  [33X[1;0Y[29X[2XRemovedSinkStates[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YRemoves all sink states of the automaton [3Xaut[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xy:=Automaton("det",3,2,[[ 2, 3, 3 ],[ 1, 2, 3 ]],[ 1 ],[ 2 ]);;Display(y);[127X[104X
    [4X[28X   |  1  2  3[128X[104X
    [4X[28X--------------[128X[104X
    [4X[28X a |  2  3  3[128X[104X
    [4X[28X b |  1  2  3[128X[104X
    [4X[28XInitial state:   [ 1 ][128X[104X
    [4X[28XAccepting state: [ 2 ][128X[104X
    [4X[25Xgap>[125X [27Xx := RemovedSinkStates(y);Display(x);[127X[104X
    [4X[28X< deterministic automaton on 2 letters with 2 states >[128X[104X
    [4X[28X   |  1  2[128X[104X
    [4X[28X-----------[128X[104X
    [4X[28X a |  2[128X[104X
    [4X[28X b |  1  2[128X[104X
    [4X[28XInitial state:   [ 1 ][128X[104X
    [4X[28XAccepting state: [ 2 ][128X[104X
  [4X[32X[104X
  
  [1X2.5-5 ReversedAutomaton[101X
  
  [33X[1;0Y[29X[2XReversedAutomaton[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YInverts the arrows of the automaton [3Xaut[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xy:=Automaton("det",3,2,[ [ 2, 3, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2 ]);;[127X[104X
    [4X[25Xgap>[125X [27Xz:=ReversedAutomaton(y);;Display(z);[127X[104X
    [4X[28X   |  1       2       3[128X[104X
    [4X[28X------------------------------[128X[104X
    [4X[28X a |         [ 1 ]   [ 2, 3 ][128X[104X
    [4X[28X b | [ 1 ]   [ 2 ]   [ 3 ][128X[104X
    [4X[28XInitial state:   [ 2 ][128X[104X
    [4X[28XAccepting state: [ 1 ][128X[104X
  [4X[32X[104X
  
  [1X2.5-6 PermutedAutomaton[101X
  
  [33X[1;0Y[29X[2XPermutedAutomaton[102X( [3Xaut[103X, [3Xp[103X ) [32X function[133X
  
  [33X[0;0YGiven  an  automaton  [3Xaut[103X  and  a  list  [3Xp[103X representing a permutation of the
  states, outputs the equivalent permuted automaton.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xy:=Automaton("det",4,2,[[2,3,4,2],[0,0,0,1]],[1],[3]);;Display(y);[127X[104X
    [4X[28X   |  1  2  3  4[128X[104X
    [4X[28X-----------------[128X[104X
    [4X[28X a |  2  3  4  2[128X[104X
    [4X[28X b |           1[128X[104X
    [4X[28XInitial state:   [ 1 ][128X[104X
    [4X[28XAccepting state: [ 3 ][128X[104X
    [4X[25Xgap>[125X [27XDisplay(PermutedAutomaton(y, [3,2,4,1]));[127X[104X
    [4X[28X   |  1  2  3  4[128X[104X
    [4X[28X-----------------[128X[104X
    [4X[28X a |  2  4  2  1[128X[104X
    [4X[28X b |  3[128X[104X
    [4X[28XInitial state:   [ 3 ][128X[104X
    [4X[28XAccepting state: [ 4 ][128X[104X
  [4X[32X[104X
  
  [1X2.5-7 ListPermutedAutomata[101X
  
  [33X[1;0Y[29X[2XListPermutedAutomata[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YGiven an automaton [3Xaut[103X, returns a list of automata with permuted states[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 0, 2, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2, 3 ]);;[127X[104X
    [4X[25Xgap>[125X [27XListPermutedAutomata(x);[127X[104X
    [4X[28X[ < deterministic automaton on 2 letters with 3 states >, [128X[104X
    [4X[28X  < deterministic automaton on 2 letters with 3 states >, [128X[104X
    [4X[28X  < deterministic automaton on 2 letters with 3 states >, [128X[104X
    [4X[28X  < deterministic automaton on 2 letters with 3 states >, [128X[104X
    [4X[28X  < deterministic automaton on 2 letters with 3 states >, [128X[104X
    [4X[28X  < deterministic automaton on 2 letters with 3 states > ][128X[104X
  [4X[32X[104X
  
  [1X2.5-8 NormalizedAutomaton[101X
  
  [33X[1;0Y[29X[2XNormalizedAutomaton[102X( [3XA[103X ) [32X function[133X
  
  [33X[0;0YProduces  an equivalent automaton but in which the initial state is numbered
  1 and the accepting states have the greatest numbers.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[[ 1, 2, 0 ],[ 0, 1, 2 ]],[2],[1, 2]);;Display(x);[127X[104X
    [4X[28X   |  1  2  3[128X[104X
    [4X[28X--------------[128X[104X
    [4X[28X a |  1  2[128X[104X
    [4X[28X b |     1  2[128X[104X
    [4X[28XInitial state:    [ 2 ][128X[104X
    [4X[28XAccepting states: [ 1, 2 ][128X[104X
    [4X[25Xgap>[125X [27XDisplay(NormalizedAutomaton(x));[127X[104X
    [4X[28X   |  1  2  3[128X[104X
    [4X[28X--------------[128X[104X
    [4X[28X a |  1     3[128X[104X
    [4X[28X b |  3  1[128X[104X
    [4X[28XInitial state:    [ 1 ][128X[104X
    [4X[28XAccepting states: [ 3, 1 ][128X[104X
  [4X[32X[104X
  
  [1X2.5-9 UnionAutomata[101X
  
  [33X[1;0Y[29X[2XUnionAutomata[102X( [3XA[103X, [3XB[103X ) [32X function[133X
  
  [33X[0;0YProduces  the  disjoint  union  of  the  deterministic  or non deterministic
  automata [10XA[110X and [10XB[110X. The output is a non-deterministic automaton.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 1, 2, 0 ], [ 0, 1, 2 ] ],[ 2 ],[ 1, 2 ]);;[127X[104X
    [4X[25Xgap>[125X [27Xy:=Automaton("det",3,2,[ [ 0, 1, 3 ], [ 0, 0, 0 ] ],[ 1 ],[ 1, 2, 3 ]);;[127X[104X
    [4X[25Xgap>[125X [27XUnionAutomata(x,y);[127X[104X
    [4X[28X< non deterministic automaton on 2 letters with 6 states >[128X[104X
    [4X[25Xgap>[125X [27XDisplay(last);[127X[104X
    [4X[28X   |  1       2       3       4    5       6[128X[104X
    [4X[28X------------------------------------------------[128X[104X
    [4X[28X a | [ 1 ]   [ 2 ]                [ 4 ]   [ 6 ][128X[104X
    [4X[28X b |         [ 1 ]   [ 2 ][128X[104X
    [4X[28XInitial states:   [ 2, 4 ][128X[104X
    [4X[28XAccepting states: [ 1, 2, 4, 5, 6 ][128X[104X
  [4X[32X[104X
  
  [1X2.5-10 ProductAutomaton[101X
  
  [33X[1;0Y[29X[2XProductAutomaton[102X( [3XA1[103X, [3XA2[103X ) [32X function[133X
  
  [33X[0;0YThe  arguments must be deterministic automata. Returns the product of [3XA1[103X and
  [3XA2[103X.[133X
  
  [33X[0;0YNote:  [22X(p,q)->(p-1)m+q[122X  is  a  bijection  from  [22X{1,...,  n}×  {1,...,  m}[122X to
  [22X{1,...,mn}[122X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx := Automaton("det",3,"ab",[ [ 0, 1, 2 ], [ 1, 3, 0 ] ],[ 1 ],[ 1, 2 ]);;[127X[104X
    [4X[25Xgap>[125X [27XDisplay(x);[127X[104X
    [4X[28X   |  1  2  3  [128X[104X
    [4X[28X--------------[128X[104X
    [4X[28X a |     1  2  [128X[104X
    [4X[28X b |  1  3     [128X[104X
    [4X[28XInitial state:    [ 1 ][128X[104X
    [4X[28XAccepting states: [ 1, 2 ][128X[104X
    [4X[25Xgap>[125X [27Xy := Automaton("det",3,"ab",[ [ 0, 1, 2 ], [ 0, 2, 0 ] ],[ 2 ],[ 1, 2 ]);;[127X[104X
    [4X[25Xgap>[125X [27XDisplay(y);[127X[104X
    [4X[28X   |  1  2  3  [128X[104X
    [4X[28X--------------[128X[104X
    [4X[28X a |     1  2  [128X[104X
    [4X[28X b |     2     [128X[104X
    [4X[28XInitial state:    [ 2 ][128X[104X
    [4X[28XAccepting states: [ 1, 2 ][128X[104X
    [4X[25Xgap>[125X [27Xz:=ProductAutomaton(x, y);;Display(z);[127X[104X
    [4X[28X   |  1  2  3  4  5  6  7  8  9  [128X[104X
    [4X[28X--------------------------------[128X[104X
    [4X[28X a |              1  2     4  5  [128X[104X
    [4X[28X b |     2        8              [128X[104X
    [4X[28XInitial state:    [ 2 ][128X[104X
    [4X[28XAccepting states: [ 1, 2, 4, 5 ][128X[104X
  [4X[32X[104X
  
  [1X2.5-11 ProductOfLanguages[101X
  
  [33X[1;0Y[29X[2XProductOfLanguages[102X( [3XA1[103X, [3XA2[103X ) [32X function[133X
  
  [33X[0;0YGiven  two  regular languages (as automata or rational expressions), returns
  an  automaton that recognizes the concatenation of the given languages, that
  is,  the  set  of  words  [22Xuv[122X such that [22Xu[122X belongs to the first language and [22Xv[122X
  belongs to the second language.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xa1:=ListOfWordsToAutomaton("ab",["aa","bb"]);[127X[104X
    [4X[28X< deterministic automaton on 2 letters with 5 states >[128X[104X
    [4X[25Xgap>[125X [27Xa2:=ListOfWordsToAutomaton("ab",["a","b"]);[127X[104X
    [4X[28X< deterministic automaton on 2 letters with 3 states >[128X[104X
    [4X[25Xgap>[125X [27XProductOfLanguages(a1,a2);[127X[104X
    [4X[28X< deterministic automaton on 2 letters with 5 states >[128X[104X
    [4X[25Xgap>[125X [27XFAtoRatExp(last);[127X[104X
    [4X[28X(bbUaa)(aUb)[128X[104X
  [4X[32X[104X
  
  
  [1X2.6 [33X[0;0YLinks with Semigroups[133X[101X
  
  [33X[0;0YEach letter of the alphabet of an automaton induces a partial transformation
  in  its  set  of states. The semigroup generated by these transformations is
  called the [13Xtransition semigroup[113X of the automaton.[133X
  
  [1X2.6-1 TransitionSemigroup[101X
  
  [33X[1;0Y[29X[2XTransitionSemigroup[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YReturns the transition semigroup of the deterministic automaton [3Xaut[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xaut := Automaton("det",10,2,[[7,5,7,5,4,9,10,9,10,9],[127X[104X
    [4X[25X>[125X [27X[8,6,8,9,9,1,3,1,9,9]],[2],[6,7,8,9,10]);;[127X[104X
    [4X[25Xgap>[125X [27Xs := TransitionSemigroup(aut);;       [127X[104X
    [4X[25Xgap>[125X [27XSize(s);                                                                  [127X[104X
    [4X[28X30[128X[104X
  [4X[32X[104X
  
  [33X[0;0YThe  transition semigroup of the minimal automaton recognizing a language is
  the [13Xsyntactic semigroup[113X of that language.[133X
  
  [1X2.6-2 SyntacticSemigroupAut[101X
  
  [33X[1;0Y[29X[2XSyntacticSemigroupAut[102X( [3Xaut[103X ) [32X function[133X
  
  [33X[0;0YReturns the syntactic semigroup of the deterministic automaton [3Xaut[103X (i.e. the
  transition  semigroup  of  the  equivalent minimal automaton) when it is non
  empty and returns [9Xfail[109X otherwise.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 1, 2, 0 ], [ 0, 1, 2 ] ],[ 2 ],[ 1, 2 ]);;[127X[104X
    [4X[25Xgap>[125X [27XS:=SyntacticSemigroupAut(x);;[127X[104X
    [4X[25Xgap>[125X [27XSize(S);[127X[104X
    [4X[28X3[128X[104X
  [4X[32X[104X
  
  [1X2.6-3 SyntacticSemigroupLang[101X
  
  [33X[1;0Y[29X[2XSyntacticSemigroupLang[102X( [3Xrat[103X ) [32X function[133X
  
  [33X[0;0YReturns  the  syntactic  semigroup  of  the  language  given by the rational
  expression [3Xrat[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xrat := RationalExpression("a*ba*ba*(@Ub)");;[127X[104X
    [4X[25Xgap>[125X [27XS:=SyntacticSemigroupLang(rat);;[127X[104X
    [4X[25Xgap>[125X [27XSize(S);[127X[104X
    [4X[28X7[128X[104X
  [4X[32X[104X
  
