Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 4183461[1X2 [33X[0;0YFinite Automata[133X[101X23[33X[0;0YThis chapter describes the representations used in this package for finite4automata and some functions to determine information about them.[133X56[33X[0;0YWe have to remark that the states of an automaton are always named7[22X1,2,3,...;[122X the alphabet may be given by the user. By default it is8[22X{a,b,c,...}[122X (or [22X{a_1,a_2,a_3,...}[122X in the case of alphabets with more than [22X26[122X9letters).[133X1011[33X[0;0YThe transition function of an automaton with [22Xq[122X states over an alphabet with12[22Xn[122X letters is represented by a (not necessarily dense) [22Xn× q[122X matrix. Each row13of the matrix describes the action of the corresponding letter on the14states. In the case of a [13Xdeterministic automaton[113X (DFA) the entries of the15matrix are non-negative integers. When all entries of the transition table16are positive integers, the automaton is said to be [13Xdense[113X or [13Xcomplete[113X. In the17case of a [13Xnon deterministic automaton[113X (NFA) the entries of the matrix may be18lists of non-negative integers. [13XAutomata with [22Xϵ[122X-transitions[113X are also19allowed: the last letter of the alphabet is assumed to be [22Xϵ[122X and is20represented by @.[133X212223[1X2.1 [33X[0;0YAutomata generation[133X[101X2425[33X[0;0YThe way to create an automaton in [5XGAP[105X is the following[133X2627[1X2.1-1 Automaton[101X2829[29X[2XAutomaton[102X( [3XType[103X, [3XSize[103X, [3XAlphabet[103X, [3XTransitionTable[103X, [3XInitial[103X, [3XAccepting[103X ) [32X function3031[33X[0;0Y[10XType[110X may be [10X"det"[110X, [10X"nondet"[110X or [10X"epsilon"[110X according to whether the automaton32is deterministic, non deterministic or an automaton with [22Xϵ[122X-transitions. [10XSize[110X33is a positive integer representing the number of states of the automaton.34[10XAlphabet[110X is the number of letters of the alphabet or a list with the letters35of the ordered alphabet. [10XTransitionTable[110X is the transition matrix. The36entries are non-negative integers not greater than the size of the37automaton. In the case of non deterministic automata, lists of non-negative38integers not greater than the size of the automaton are also allowed.39[10XInitial[110X and [10XAccepting[110X are, respectively, the lists of initial and accepting40states.[133X4142[4X[32X Example [32X[104X43[4X[28X[128X[104X44[4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,4]],[1],[4]);[127X[104X45[4X[28X< deterministic automaton on 2 letters with 4 states >[128X[104X46[4X[25Xgap>[125X [27XDisplay(aut);[127X[104X47[4X[28X | 1 2 3 4[128X[104X48[4X[28X-----------------[128X[104X49[4X[28X a | 3 3 4[128X[104X50[4X[28X b | 3 4 4[128X[104X51[4X[28XInitial state: [ 1 ][128X[104X52[4X[28XAccepting state: [ 4 ][128X[104X53[4X[28X[128X[104X54[4X[32X[104X5556[33X[0;0YThe alphabet of the automaton may be specified:[133X5758[4X[32X Example [32X[104X59[4X[25Xgap>[125X [27Xaut:=Automaton("det",4,"01",[[3,,3,4],[3,4,0,4]],[1],[4]);[127X[104X60[4X[28X< deterministic automaton on 2 letters with 4 states >[128X[104X61[4X[25Xgap>[125X [27XDisplay(aut);[127X[104X62[4X[28X | 1 2 3 4[128X[104X63[4X[28X-----------------[128X[104X64[4X[28X 0 | 3 3 4[128X[104X65[4X[28X 1 | 3 4 4[128X[104X66[4X[28XInitial state: [ 1 ][128X[104X67[4X[28XAccepting state: [ 4 ][128X[104X68[4X[32X[104X6970[33X[0;0YInstead of leaving a hole in the transition matrix, we may write a [10X0[110X to mean71that no transition is present. Non deterministic automata may be given the72same way.[133X7374[4X[32X Example [32X[104X75[4X[25Xgap>[125X [27Xndaut:=Automaton("nondet",4,2,[[3,[1,2],3,0],[3,4,0,[2,3]]],[1],[4]);[127X[104X76[4X[28X< non deterministic automaton on 2 letters with 4 states >[128X[104X77[4X[25Xgap>[125X [27XDisplay(ndaut);[127X[104X78[4X[28X | 1 2 3 4[128X[104X79[4X[28X-----------------------------------------[128X[104X80[4X[28X a | [ 3 ] [ 1, 2 ] [ 3 ][128X[104X81[4X[28X b | [ 3 ] [ 4 ] [ 2, 3 ][128X[104X82[4X[28XInitial state: [ 1 ][128X[104X83[4X[28XAccepting state: [ 4 ][128X[104X84[4X[32X[104X8586[33X[0;0YAlso in the same way can be given [22Xϵ[122X-automata. The letter [22Xϵ[122X is written [10X@[110X87instead.[133X8889[4X[32X Example [32X[104X90[4X[25Xgap>[125X [27Xx:=Automaton("epsilon",3,"01@",[[,[2],[3]],[[1,3],,[1]],[[1],[2],[127X[104X91[4X[25X>[125X [27X[2]]],[2],[2,3]);[127X[104X92[4X[28X< epsilon automaton on 3 letters with 3 states >[128X[104X93[4X[25Xgap>[125X [27XDisplay(x);[127X[104X94[4X[28X | 1 2 3[128X[104X95[4X[28X------------------------------[128X[104X96[4X[28X 0 | [ 2 ] [ 3 ][128X[104X97[4X[28X 1 | [ 1, 3 ] [ 1 ][128X[104X98[4X[28X @ | [ 1 ] [ 2 ] [ 2 ][128X[104X99[4X[28XInitial state: [ 2 ][128X[104X100[4X[28XAccepting states: [ 2, 3 ][128X[104X101[4X[32X[104X102103[33X[0;0YBigger automata are displayed in another form:[133X104105[4X[32X Example [32X[104X106[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[104X107[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[104X108[4X[28X< deterministic automaton on 2 letters with 16 states >[128X[104X109[4X[25Xgap>[125X [27XDisplay(aut);[127X[104X110[4X[28X1 a 4[128X[104X111[4X[28X1 b 3[128X[104X112[4X[28X2 b 4[128X[104X113[4X[28X ... some more lines[128X[104X114[4X[28X15 a 6[128X[104X115[4X[28X15 b 8[128X[104X116[4X[28X16 b 7[128X[104X117[4X[28XInitial state: [ 1 ][128X[104X118[4X[28XAccepting state: [ 4 ][128X[104X119[4X[32X[104X120121[1X2.1-2 IsAutomaton[101X122123[29X[2XIsAutomaton[102X( [3XO[103X ) [32X function124125[33X[0;0YIn the presence of an object [3XO[103X, one may want to test whether [10XO[110X is an126automaton. This may be done using the function [10XIsAutomaton[110X.[133X127128[4X[32X Example [32X[104X129[4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;[127X[104X130[4X[25Xgap>[125X [27XIsAutomaton(x);[127X[104X131[4X[28Xtrue[128X[104X132[4X[32X[104X133134[1X2.1-3 IsDeterministicAutomaton[101X135136[29X[2XIsDeterministicAutomaton[102X( [3Xaut[103X ) [32X function137138[33X[0;0YReturns [9Xtrue[109X when [10Xaut[110X is a deterministic automaton and [9Xfalse[109X otherwise.[133X139140[4X[32X Example [32X[104X141[4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;[127X[104X142[4X[25Xgap>[125X [27XIsDeterministicAutomaton(x);[127X[104X143[4X[28Xtrue[128X[104X144[4X[32X[104X145146[1X2.1-4 IsNonDeterministicAutomaton[101X147148[29X[2XIsNonDeterministicAutomaton[102X( [3Xaut[103X ) [32X function149150[33X[0;0YReturns [9Xtrue[109X when [10Xaut[110X is a non deterministic automaton and [9Xfalse[109X otherwise.[133X151152[4X[32X Example [32X[104X153[4X[25Xgap>[125X [27Xy:=Automaton("nondet",3,2,[[,[1,3],],[,[2,3],[1,3]]],[1,2],[1,3]);;[127X[104X154[4X[25Xgap>[125X [27XIsNonDeterministicAutomaton(y);[127X[104X155[4X[28Xtrue[128X[104X156[4X[32X[104X157158[1X2.1-5 IsEpsilonAutomaton[101X159160[29X[2XIsEpsilonAutomaton[102X( [3Xaut[103X ) [32X function161162[33X[0;0YReturns [9Xtrue[109X when [10Xaut[110X is an [22Xϵ[122X-automaton and [9Xfalse[109X otherwise.[133X163164[4X[32X Example [32X[104X165[4X[25Xgap>[125X [27Xz:=Automaton("epsilon",2,2,[[[1,2],],[[2],[1]]],[1,2],[1,2]);;[127X[104X166[4X[25Xgap>[125X [27XIsEpsilonAutomaton(z);[127X[104X167[4X[28Xtrue[128X[104X168[4X[32X[104X169170[1X2.1-6 String[101X171172[29X[2XString[102X( [3Xaut[103X ) [32X function173174[33X[0;0YThe way [5XGAP[105X displays an automaton is quite natural, but when one wants to do175small changes, for example using [13Xcopy/paste[113X, the use of the function [10XString[110X176(possibly followed by [10XPrint[110X) may be usefull.[133X177178[4X[32X Example [32X[104X179[4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;[127X[104X180[4X[25Xgap>[125X [27XString(x);[127X[104X181[4X[28X"Automaton(\"det\",3,\"ab\",[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;"[128X[104X182[4X[25Xgap>[125X [27XPrint(String(x));[127X[104X183[4X[28XAutomaton("det",3,"ab",[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;[128X[104X184[4X[32X[104X185186[4X[32X Example [32X[104X187[4X[25Xgap>[125X [27Xz:=Automaton("epsilon",2,2,[[[1,2],],[[2],[1]]],[1,2],[1,2]);;[127X[104X188[4X[25Xgap>[125X [27XPrint(String(z));[127X[104X189[4X[28XAutomaton("epsilon",2,"a@",[ [ [ 1, 2 ], [ ] ], [ [ 2 ], [ 1 ] ] ],[ 1, 2 ],[ \[128X[104X190[4X[28X1, 2 ]);;[128X[104X191[4X[32X[104X192193[1X2.1-7 RandomAutomaton[101X194195[29X[2XRandomAutomaton[102X( [3XType[103X, [3XSize[103X, [3XAlphabet[103X ) [32X function196197[33X[0;0YGiven the [3XType[103X, the [3XSize[103X (i.e. the number of states) and the [3XAlphabet[103X (a198positive integer or a list), returns a pseudo random automaton with these199parameters.[133X200201[4X[32X Example [32X[104X202[4X[25Xgap>[125X [27XRandomAutomaton("det",5,"ac");[127X[104X203[4X[28X< deterministic automaton on 2 letters with 5 states >[128X[104X204[4X[25Xgap>[125X [27XDisplay(last);[127X[104X205[4X[28X | 1 2 3 4 5[128X[104X206[4X[28X--------------------[128X[104X207[4X[28X a | 2 3[128X[104X208[4X[28X c | 2 3[128X[104X209[4X[28XInitial state: [ 4 ][128X[104X210[4X[28XAccepting states: [ 3, 4 ][128X[104X211[4X[28X[128X[104X212[4X[25Xgap>[125X [27XRandomAutomaton("nondet",3,["a","b","c"]);[127X[104X213[4X[28X< non deterministic automaton on 3 letters with 3 states >[128X[104X214[4X[28X[128X[104X215[4X[25Xgap>[125X [27XRandomAutomaton("epsilon",2,"abc");[127X[104X216[4X[28X< epsilon automaton on 4 letters with 2 states >[128X[104X217[4X[28X[128X[104X218[4X[25Xgap>[125X [27XRandomAutomaton("epsilon",2,2);[127X[104X219[4X[28X< epsilon automaton on 3 letters with 2 states >[128X[104X220[4X[25Xgap>[125X [27XDisplay(last);[127X[104X221[4X[28X | 1 2[128X[104X222[4X[28X----------------------[128X[104X223[4X[28X a | [ 1, 2 ][128X[104X224[4X[28X b | [ 2 ] [ 1 ][128X[104X225[4X[28X @ | [ 1, 2 ][128X[104X226[4X[28XInitial state: [ 2 ][128X[104X227[4X[28XAccepting states: [ 1, 2 ][128X[104X228[4X[28X[128X[104X229[4X[25Xgap>[125X [27Xa:=RandomTransformation(3);;[127X[104X230[4X[25Xgap>[125X [27Xb:=RandomTransformation(3);;[127X[104X231[4X[25Xgap>[125X [27Xaut:=RandomAutomaton("det",4,[a,b]);[127X[104X232[4X[28X< deterministic automaton on 2 letters with 4 states >[128X[104X233[4X[32X[104X234235236[1X2.2 [33X[0;0YAutomata internals[133X[101X237238[33X[0;0YIn this section we describe the functions used to access the internals of an239automaton.[133X240241[1X2.2-1 AlphabetOfAutomaton[101X242243[29X[2XAlphabetOfAutomaton[102X( [3Xaut[103X ) [32X function244245[33X[0;0YReturns the number of symbols in the alphabet of automaton [10Xaut[110X.[133X246247[4X[32X Example [32X[104X248[4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;[127X[104X249[4X[25Xgap>[125X [27XAlphabetOfAutomaton(aut);[127X[104X250[4X[28X2[128X[104X251[4X[32X[104X252253[1X2.2-2 AlphabetOfAutomatonAsList[101X254255[29X[2XAlphabetOfAutomatonAsList[102X( [3Xaut[103X ) [32X function256257[33X[0;0YReturns the alphabet of automaton [10Xaut[110X always as a list. Note that when the258alphabet of the automaton is given as an integer (meaning the number of259symbols) not greater than 26 it returns the list [10X"abcd...."[110X. If the alphabet260is given by means of an integer greater than 26, the function returns [10X[261"a1", "a2", "a3", "a4", ... ][110X.[133X262263[4X[32X Example [32X[104X264[4X[25Xgap>[125X [27Xa:=RandomAutomaton("det",5,"cat");[127X[104X265[4X[28X< deterministic automaton on 3 letters with 5 states >[128X[104X266[4X[25Xgap>[125X [27XAlphabetOfAutomaton(a);[127X[104X267[4X[28X3[128X[104X268[4X[25Xgap>[125X [27XAlphabetOfAutomatonAsList(a);[127X[104X269[4X[28X"cat"[128X[104X270[4X[25Xgap>[125X [27Xa:=RandomAutomaton("det",5,20);[127X[104X271[4X[28X< deterministic automaton on 20 letters with 5 states >[128X[104X272[4X[25Xgap>[125X [27XAlphabetOfAutomaton(a);[127X[104X273[4X[28X20[128X[104X274[4X[25Xgap>[125X [27XAlphabetOfAutomatonAsList(a);[127X[104X275[4X[28X"abcdefghijklmnopqrst"[128X[104X276[4X[25Xgap>[125X [27Xa:=RandomAutomaton("det",5,30);[127X[104X277[4X[28X< deterministic automaton on 30 letters with 5 states >[128X[104X278[4X[25Xgap>[125X [27XAlphabetOfAutomaton(a);[127X[104X279[4X[28X30[128X[104X280[4X[25Xgap>[125X [27XAlphabetOfAutomatonAsList(a);[127X[104X281[4X[28X[ "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11", [128X[104X282[4X[28X "a12", "a13", "a14", "a15", "a16", "a17", "a18", "a19", "a20", "a21",[128X[104X283[4X[28X "a22", "a23", "a24", "a25", "a26", "a27", "a28", "a29", "a30" ][128X[104X284[4X[32X[104X285286[1X2.2-3 TransitionMatrixOfAutomaton[101X287288[29X[2XTransitionMatrixOfAutomaton[102X( [3Xaut[103X ) [32X function289290[33X[0;0YReturns the transition matrix of automaton [10Xaut[110X.[133X291292[4X[32X Example [32X[104X293[4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;[127X[104X294[4X[25Xgap>[125X [27XTransitionMatrixOfAutomaton(aut);[127X[104X295[4X[28X[ [ 3, 0, 3, 4 ], [ 3, 4, 0, 0 ] ][128X[104X296[4X[32X[104X297298[1X2.2-4 InitialStatesOfAutomaton[101X299300[29X[2XInitialStatesOfAutomaton[102X( [3Xaut[103X ) [32X function301302[33X[0;0YReturns the initial states of automaton [10Xaut[110X.[133X303304[4X[32X Example [32X[104X305[4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;[127X[104X306[4X[25Xgap>[125X [27XInitialStatesOfAutomaton(aut);[127X[104X307[4X[28X[ 1 ][128X[104X308[4X[32X[104X309310[1X2.2-5 SetInitialStatesOfAutomaton[101X311312[29X[2XSetInitialStatesOfAutomaton[102X( [3Xaut[103X, [3XI[103X ) [32X function313314[33X[0;0YSets the initial states of automaton [10Xaut[110X. [10XI[110X may be a positive integer or a315list of positive integers.[133X316317[4X[32X Example [32X[104X318[4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;[127X[104X319[4X[25Xgap>[125X [27XSetInitialStatesOfAutomaton(aut,4);[127X[104X320[4X[25Xgap>[125X [27XInitialStatesOfAutomaton(aut);[127X[104X321[4X[28X[ 4 ][128X[104X322[4X[25Xgap>[125X [27XSetInitialStatesOfAutomaton(aut,[2,3]);[127X[104X323[4X[25Xgap>[125X [27XInitialStatesOfAutomaton(aut);[127X[104X324[4X[28X[ 2, 3 ][128X[104X325[4X[32X[104X326327[1X2.2-6 FinalStatesOfAutomaton[101X328329[29X[2XFinalStatesOfAutomaton[102X( [3Xaut[103X ) [32X function330331[33X[0;0YReturns the final states of automaton [10Xaut[110X.[133X332333[4X[32X Example [32X[104X334[4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;[127X[104X335[4X[25Xgap>[125X [27XFinalStatesOfAutomaton(aut);[127X[104X336[4X[28X[ 4 ][128X[104X337[4X[32X[104X338339[1X2.2-7 SetFinalStatesOfAutomaton[101X340341[29X[2XSetFinalStatesOfAutomaton[102X( [3Xaut[103X, [3XF[103X ) [32X function342343[33X[0;0YSets the final states of automaton [10Xaut[110X. [10XF[110X may be a positive integer or a344list of positive integers.[133X345346[4X[32X Example [32X[104X347[4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;[127X[104X348[4X[25Xgap>[125X [27XFinalStatesOfAutomaton(aut);[127X[104X349[4X[28X[ 4 ][128X[104X350[4X[25Xgap>[125X [27XSetFinalStatesOfAutomaton(aut,2);[127X[104X351[4X[25Xgap>[125X [27XFinalStatesOfAutomaton(aut);[127X[104X352[4X[28X[ 2 ][128X[104X353[4X[32X[104X354355[1X2.2-8 NumberStatesOfAutomaton[101X356357[29X[2XNumberStatesOfAutomaton[102X( [3Xaut[103X ) [32X function358359[33X[0;0YReturns the number of states of automaton [10Xaut[110X.[133X360361[4X[32X Example [32X[104X362[4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;[127X[104X363[4X[25Xgap>[125X [27XNumberStatesOfAutomaton(aut);[127X[104X364[4X[28X4[128X[104X365[4X[32X[104X366367368[1X2.3 [33X[0;0YComparison of automata[133X[101X369370[33X[0;0YAlthough there is no standard way to compare automata it is usefull to be371able to do some kind of comparison. Doing so, one can consider sets of372automata. We just compare the strings of the automata.[133X373374[4X[32X Example [32X[104X375[4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;[127X[104X376[4X[25Xgap>[125X [27Xy:=Automaton("det",3,2,[ [ 2, 0, 0 ], [ 1, 3, 0 ] ],[ 3 ],[ 2, 3 ]);;[127X[104X377[4X[25Xgap>[125X [27Xx=y;[127X[104X378[4X[28Xfalse[128X[104X379[4X[25Xgap>[125X [27XSize(Set([y,x,x]));[127X[104X380[4X[28X2[128X[104X381[4X[32X[104X382383384[1X2.4 [33X[0;0YTests involving automata[133X[101X385386[33X[0;0YThis section describes some useful tests involving automata.[133X387388[1X2.4-1 IsDenseAutomaton[101X389390[29X[2XIsDenseAutomaton[102X( [3Xaut[103X ) [32X function391392[33X[0;0YTests whether a deterministic automaton [10Xaut[110X is complete. (See also393[2XNullCompletionAutomaton[102X ([14X2.5-2[114X).)[133X394395[4X[32X Example [32X[104X396[4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;[127X[104X397[4X[25Xgap>[125X [27XIsDenseAutomaton(aut); [127X[104X398[4X[28Xfalse[128X[104X399[4X[32X[104X400401[1X2.4-2 IsRecognizedByAutomaton[101X402403[29X[2XIsRecognizedByAutomaton[102X( [3XA[103X, [3Xw[103X ) [32X function404405[33X[0;0YThe arguments are: an automaton [3XA[103X and a string (i.e. a word) [3Xw[103X in the406alphabet of the automaton. Returns [10Xtrue[110X if the word is recognized by the407automaton and [10Xfalse[110X otherwise.[133X408409[4X[32X Example [32X[104X410[4X[25Xgap>[125X [27Xaut:=Automaton("det",3,2,[[1,2,1],[2,1,3]],[1],[2]);;[127X[104X411[4X[25Xgap>[125X [27XIsRecognizedByAutomaton(aut,"bbb");[127X[104X412[4X[28Xtrue[128X[104X413[4X[28X[128X[104X414[4X[25Xgap>[125X [27Xaut:=Automaton("det",3,"01",[[1,2,1],[2,1,3]],[1],[2]);;[127X[104X415[4X[25Xgap>[125X [27XIsRecognizedByAutomaton(aut,"111");[127X[104X416[4X[28Xtrue[128X[104X417[4X[32X[104X418419[1X2.4-3 IsPermutationAutomaton[101X420421[29X[2XIsPermutationAutomaton[102X( [3Xaut[103X ) [32X function422423[33X[0;0YThe argument is a deterministic automaton. Returns [9Xtrue[109X when each letter of424the alphabet induces a permutation on the vertices and [9Xfalse[109X otherwise.[133X425426[4X[32X Example [32X[104X427[4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 1, 2, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2, 3 ]);;[127X[104X428[4X[25Xgap>[125X [27XIsPermutationAutomaton(x);[127X[104X429[4X[28Xtrue[128X[104X430[4X[32X[104X431432[1X2.4-4 IsInverseAutomaton[101X433434[29X[2XIsInverseAutomaton[102X( [3Xaut[103X ) [32X function435436[33X[0;0YThe argument is a deterministic automaton. Returns [9Xtrue[109X when each letter of437the alphabet induces an injective partial function on the vertices and [9Xfalse[109X438otherwise.[133X439440[4X[32X Example [32X[104X441[4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 0, 1, 3 ], [ 0, 1, 2 ] ],[ 2 ],[ 1 ]);;[127X[104X442[4X[25Xgap>[125X [27XIsInverseAutomaton(x);[127X[104X443[4X[28Xtrue[128X[104X444[4X[32X[104X445446[33X[0;0YFrequently an inverse automaton is thought as if the inverse edges (labeled447by formal inverses of the letters of the alphabet) were present, although448they are usually not explicited. They can be made explicit using the449function [10XAddInverseEdgesToInverseAutomaton[110X[133X450451[1X2.4-5 AddInverseEdgesToInverseAutomaton[101X452453[29X[2XAddInverseEdgesToInverseAutomaton[102X( [3Xaut[103X ) [32X function454455[33X[0;0YThe argument is an inverse automaton over the alphabet [22X{a,b,c,...}[122X. Returns456an automaton with the inverse edges added. (The formal inverse of a letter457is represented by the corresponding capital letter.)[133X458459[4X[32X Example [32X[104X460[4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[[ 0, 1, 3 ],[ 0, 1, 2 ]],[ 2 ],[ 1 ]);;Display(x);[127X[104X461[4X[28X | 1 2 3[128X[104X462[4X[28X--------------[128X[104X463[4X[28X a | 1 3[128X[104X464[4X[28X b | 1 2[128X[104X465[4X[28XInitial state: [ 2 ][128X[104X466[4X[28XAccepting state: [ 1 ][128X[104X467[4X[25Xgap>[125X [27XAddInverseEdgesToInverseAutomaton(x);Display(x);[127X[104X468[4X[28X | 1 2 3[128X[104X469[4X[28X--------------[128X[104X470[4X[28X a | 1 3[128X[104X471[4X[28X b | 1 2[128X[104X472[4X[28X A | 2 3[128X[104X473[4X[28X B | 2 3[128X[104X474[4X[28XInitial state: [ 2 ][128X[104X475[4X[28XAccepting state: [ 1 ][128X[104X476[4X[32X[104X477478[1X2.4-6 IsReversibleAutomaton[101X479480[29X[2XIsReversibleAutomaton[102X( [3Xaut[103X ) [32X function481482[33X[0;0YThe argument is a deterministic automaton. Returns [9Xtrue[109X when [3Xaut[103X is a483reversible automaton, i.e. the automaton obtained by reversing all edges and484switching the initial and final states (see also [2XReversedAutomaton[102X ([14X2.5-5[114X))485is deterministic. Returns [9Xfalse[109X otherwise.[133X486487[4X[32X Example [32X[104X488[4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 0, 1, 2 ], [ 0, 1, 3 ] ],[ 2 ],[ 2 ]);;[127X[104X489[4X[25Xgap>[125X [27XIsReversibleAutomaton(x);[127X[104X490[4X[28Xtrue[128X[104X491[4X[32X[104X492493494[1X2.5 [33X[0;0YBasic operations[133X[101X495496[1X2.5-1 CopyAutomaton[101X497498[29X[2XCopyAutomaton[102X( [3Xaut[103X ) [32X function499500[33X[0;0YReturns a new automaton, which is a copy of automaton [3Xaut[103X.[133X501502[1X2.5-2 NullCompletionAutomaton[101X503504[29X[2XNullCompletionAutomaton[102X( [3Xaut[103X ) [32X function505506[33X[0;0Y[10Xaut[110X is a deterministic automaton. If it is complete returns [3Xaut[103X, otherwise507returns the completion (with a null state) of [3Xaut[103X. Notice that the words508recognized by [3Xaut[103X and its completion are the same.[133X509510[4X[32X Example [32X[104X511[4X[25Xgap>[125X [27Xaut:=Automaton("det",4,2,[[3,,3,4],[2,4,4,]],[1],[4]);;[127X[104X512[4X[25Xgap>[125X [27XIsDenseAutomaton(aut);[127X[104X513[4X[28Xfalse[128X[104X514[4X[25Xgap>[125X [27Xy:=NullCompletionAutomaton(aut);;Display(y);[127X[104X515[4X[28X | 1 2 3 4 5[128X[104X516[4X[28X--------------------[128X[104X517[4X[28X a | 3 5 3 4 5[128X[104X518[4X[28X b | 2 4 4 5 5[128X[104X519[4X[28XInitial state: [ 1 ][128X[104X520[4X[28XAccepting state: [ 4 ][128X[104X521[4X[32X[104X522523[33X[0;0YThe state added is a [13Xsink state[113X i.e. it is a state [22Xq[122X which is not initial524nor accepting and for all letter [22Xa[122X in the alphabet of the automaton, [22Xq[122X is525the result of the action of [22Xa[122X in [22Xq[122X. (Notice that reading a word, one does526not go out of a sink state.)[133X527528[1X2.5-3 ListSinkStatesAut[101X529530[29X[2XListSinkStatesAut[102X( [3Xaut[103X ) [32X function531532[33X[0;0YComputes the list of all sink states of the automaton [3Xaut[103X.[133X533534[4X[32X Example [32X[104X535[4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 2, 3, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2, 3 ]);;[127X[104X536[4X[25Xgap>[125X [27XListSinkStatesAut(x);[127X[104X537[4X[28X[ ][128X[104X538[4X[25Xgap>[125X [27Xy:=Automaton("det",3,2,[ [ 2, 3, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2 ]);;[127X[104X539[4X[25Xgap>[125X [27XListSinkStatesAut(y);[127X[104X540[4X[28X[ 3 ][128X[104X541[4X[32X[104X542543[1X2.5-4 RemovedSinkStates[101X544545[29X[2XRemovedSinkStates[102X( [3Xaut[103X ) [32X function546547[33X[0;0YRemoves all sink states of the automaton [3Xaut[103X.[133X548549[4X[32X Example [32X[104X550[4X[25Xgap>[125X [27Xy:=Automaton("det",3,2,[[ 2, 3, 3 ],[ 1, 2, 3 ]],[ 1 ],[ 2 ]);;Display(y);[127X[104X551[4X[28X | 1 2 3[128X[104X552[4X[28X--------------[128X[104X553[4X[28X a | 2 3 3[128X[104X554[4X[28X b | 1 2 3[128X[104X555[4X[28XInitial state: [ 1 ][128X[104X556[4X[28XAccepting state: [ 2 ][128X[104X557[4X[25Xgap>[125X [27Xx := RemovedSinkStates(y);Display(x);[127X[104X558[4X[28X< deterministic automaton on 2 letters with 2 states >[128X[104X559[4X[28X | 1 2[128X[104X560[4X[28X-----------[128X[104X561[4X[28X a | 2[128X[104X562[4X[28X b | 1 2[128X[104X563[4X[28XInitial state: [ 1 ][128X[104X564[4X[28XAccepting state: [ 2 ][128X[104X565[4X[32X[104X566567[1X2.5-5 ReversedAutomaton[101X568569[29X[2XReversedAutomaton[102X( [3Xaut[103X ) [32X function570571[33X[0;0YInverts the arrows of the automaton [3Xaut[103X.[133X572573[4X[32X Example [32X[104X574[4X[25Xgap>[125X [27Xy:=Automaton("det",3,2,[ [ 2, 3, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2 ]);;[127X[104X575[4X[25Xgap>[125X [27Xz:=ReversedAutomaton(y);;Display(z);[127X[104X576[4X[28X | 1 2 3[128X[104X577[4X[28X------------------------------[128X[104X578[4X[28X a | [ 1 ] [ 2, 3 ][128X[104X579[4X[28X b | [ 1 ] [ 2 ] [ 3 ][128X[104X580[4X[28XInitial state: [ 2 ][128X[104X581[4X[28XAccepting state: [ 1 ][128X[104X582[4X[32X[104X583584[1X2.5-6 PermutedAutomaton[101X585586[29X[2XPermutedAutomaton[102X( [3Xaut[103X, [3Xp[103X ) [32X function587588[33X[0;0YGiven an automaton [3Xaut[103X and a list [3Xp[103X representing a permutation of the589states, outputs the equivalent permuted automaton.[133X590591[4X[32X Example [32X[104X592[4X[25Xgap>[125X [27Xy:=Automaton("det",4,2,[[2,3,4,2],[0,0,0,1]],[1],[3]);;Display(y);[127X[104X593[4X[28X | 1 2 3 4[128X[104X594[4X[28X-----------------[128X[104X595[4X[28X a | 2 3 4 2[128X[104X596[4X[28X b | 1[128X[104X597[4X[28XInitial state: [ 1 ][128X[104X598[4X[28XAccepting state: [ 3 ][128X[104X599[4X[25Xgap>[125X [27XDisplay(PermutedAutomaton(y, [3,2,4,1]));[127X[104X600[4X[28X | 1 2 3 4[128X[104X601[4X[28X-----------------[128X[104X602[4X[28X a | 2 4 2 1[128X[104X603[4X[28X b | 3[128X[104X604[4X[28XInitial state: [ 3 ][128X[104X605[4X[28XAccepting state: [ 4 ][128X[104X606[4X[32X[104X607608[1X2.5-7 ListPermutedAutomata[101X609610[29X[2XListPermutedAutomata[102X( [3Xaut[103X ) [32X function611612[33X[0;0YGiven an automaton [3Xaut[103X, returns a list of automata with permuted states[133X613614[4X[32X Example [32X[104X615[4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 0, 2, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2, 3 ]);;[127X[104X616[4X[25Xgap>[125X [27XListPermutedAutomata(x);[127X[104X617[4X[28X[ < deterministic automaton on 2 letters with 3 states >, [128X[104X618[4X[28X < deterministic automaton on 2 letters with 3 states >, [128X[104X619[4X[28X < deterministic automaton on 2 letters with 3 states >, [128X[104X620[4X[28X < deterministic automaton on 2 letters with 3 states >, [128X[104X621[4X[28X < deterministic automaton on 2 letters with 3 states >, [128X[104X622[4X[28X < deterministic automaton on 2 letters with 3 states > ][128X[104X623[4X[32X[104X624625[1X2.5-8 NormalizedAutomaton[101X626627[29X[2XNormalizedAutomaton[102X( [3XA[103X ) [32X function628629[33X[0;0YProduces an equivalent automaton but in which the initial state is numbered6301 and the accepting states have the greatest numbers.[133X631632[4X[32X Example [32X[104X633[4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[[ 1, 2, 0 ],[ 0, 1, 2 ]],[2],[1, 2]);;Display(x);[127X[104X634[4X[28X | 1 2 3[128X[104X635[4X[28X--------------[128X[104X636[4X[28X a | 1 2[128X[104X637[4X[28X b | 1 2[128X[104X638[4X[28XInitial state: [ 2 ][128X[104X639[4X[28XAccepting states: [ 1, 2 ][128X[104X640[4X[25Xgap>[125X [27XDisplay(NormalizedAutomaton(x));[127X[104X641[4X[28X | 1 2 3[128X[104X642[4X[28X--------------[128X[104X643[4X[28X a | 1 3[128X[104X644[4X[28X b | 3 1[128X[104X645[4X[28XInitial state: [ 1 ][128X[104X646[4X[28XAccepting states: [ 3, 1 ][128X[104X647[4X[32X[104X648649[1X2.5-9 UnionAutomata[101X650651[29X[2XUnionAutomata[102X( [3XA[103X, [3XB[103X ) [32X function652653[33X[0;0YProduces the disjoint union of the deterministic or non deterministic654automata [10XA[110X and [10XB[110X. The output is a non-deterministic automaton.[133X655656[4X[32X Example [32X[104X657[4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 1, 2, 0 ], [ 0, 1, 2 ] ],[ 2 ],[ 1, 2 ]);;[127X[104X658[4X[25Xgap>[125X [27Xy:=Automaton("det",3,2,[ [ 0, 1, 3 ], [ 0, 0, 0 ] ],[ 1 ],[ 1, 2, 3 ]);;[127X[104X659[4X[25Xgap>[125X [27XUnionAutomata(x,y);[127X[104X660[4X[28X< non deterministic automaton on 2 letters with 6 states >[128X[104X661[4X[25Xgap>[125X [27XDisplay(last);[127X[104X662[4X[28X | 1 2 3 4 5 6[128X[104X663[4X[28X------------------------------------------------[128X[104X664[4X[28X a | [ 1 ] [ 2 ] [ 4 ] [ 6 ][128X[104X665[4X[28X b | [ 1 ] [ 2 ][128X[104X666[4X[28XInitial states: [ 2, 4 ][128X[104X667[4X[28XAccepting states: [ 1, 2, 4, 5, 6 ][128X[104X668[4X[32X[104X669670[1X2.5-10 ProductAutomaton[101X671672[29X[2XProductAutomaton[102X( [3XA1[103X, [3XA2[103X ) [32X function673674[33X[0;0YThe arguments must be deterministic automata. Returns the product of [3XA1[103X and675[3XA2[103X.[133X676677[33X[0;0YNote: [22X(p,q)->(p-1)m+q[122X is a bijection from [22X{1,..., n}× {1,..., m}[122X to678[22X{1,...,mn}[122X.[133X679680[4X[32X Example [32X[104X681[4X[25Xgap>[125X [27Xx:=RandomAutomaton("det",3,2);;Display(x);[127X[104X682[4X[28X | 1 2 3[128X[104X683[4X[28X--------------[128X[104X684[4X[28X a | 2 3[128X[104X685[4X[28X b | 1[128X[104X686[4X[28XInitial state: [ 3 ][128X[104X687[4X[28XAccepting states: [ 1, 2, 3 ][128X[104X688[4X[25Xgap>[125X [27Xy:=RandomAutomaton("det",3,2);;Display(y);[127X[104X689[4X[28X | 1 2 3[128X[104X690[4X[28X--------------[128X[104X691[4X[28X a | 1[128X[104X692[4X[28X b | 1 3[128X[104X693[4X[28XInitial state: [ 3 ][128X[104X694[4X[28XAccepting states: [ 1, 3 ][128X[104X695[4X[25Xgap>[125X [27Xz:=ProductAutomaton(x, y);;Display(z);[127X[104X696[4X[28X | 1 2 3 4 5 6 7 8 9[128X[104X697[4X[28X--------------------------------[128X[104X698[4X[28X a | 4 7[128X[104X699[4X[28X b | 1 3[128X[104X700[4X[28XInitial state: [ 9 ][128X[104X701[4X[28XAccepting states: [ 1, 3, 4, 6, 7, 9 ][128X[104X702[4X[32X[104X703704[1X2.5-11 ProductOfLanguages[101X705706[29X[2XProductOfLanguages[102X( [3XA1[103X, [3XA2[103X ) [32X function707708[33X[0;0YGiven two regular languages (as automata or rational expressions), returns709an automaton that recognizes the concatenation of the given languages, that710is, the set of words [22Xuv[122X such that [22Xu[122X belongs to the first language and [22Xv[122X711belongs to the second language.[133X712713[4X[32X Example [32X[104X714[4X[25Xgap>[125X [27Xa1:=ListOfWordsToAutomaton("ab",["aa","bb"]);[127X[104X715[4X[28X< deterministic automaton on 2 letters with 5 states >[128X[104X716[4X[25Xgap>[125X [27Xa2:=ListOfWordsToAutomaton("ab",["a","b"]);[127X[104X717[4X[28X< deterministic automaton on 2 letters with 3 states >[128X[104X718[4X[25Xgap>[125X [27XProductOfLanguages(a1,a2);[127X[104X719[4X[28X< deterministic automaton on 2 letters with 5 states >[128X[104X720[4X[25Xgap>[125X [27XFAtoRatExp(last);[127X[104X721[4X[28X(bbUaa)(aUb)[128X[104X722[4X[32X[104X723724725[1X2.6 [33X[0;0YLinks with Semigroups[133X[101X726727[33X[0;0YEach letter of the alphabet of an automaton induces a partial transformation728in its set of states. The semigroup generated by these transformations is729called the [13Xtransition semigroup[113X of the automaton.[133X730731[1X2.6-1 TransitionSemigroup[101X732733[29X[2XTransitionSemigroup[102X( [3Xaut[103X ) [32X function734735[33X[0;0YReturns the transition semigroup of the deterministic automaton [3Xaut[103X.[133X736737[4X[32X Example [32X[104X738[4X[25Xgap>[125X [27Xaut := Automaton("det",10,2,[[7,5,7,5,4,9,10,9,10,9],[127X[104X739[4X[25X>[125X [27X[8,6,8,9,9,1,3,1,9,9]],[2],[6,7,8,9,10]);;[127X[104X740[4X[25Xgap>[125X [27Xs := TransitionSemigroup(aut);; [127X[104X741[4X[25Xgap>[125X [27XSize(s); [127X[104X742[4X[28X30[128X[104X743[4X[32X[104X744745[33X[0;0YThe transition semigroup of the minimal automaton recognizing a language is746the {\it syntactic semigroup} of that language.[133X747748[1X2.6-2 SyntacticSemigroupAut[101X749750[29X[2XSyntacticSemigroupAut[102X( [3Xaut[103X ) [32X function751752[33X[0;0YReturns the syntactic semigroup of the deterministic automaton [3Xaut[103X (i.e. the753transition semigroup of the equivalent minimal automaton) when it is non754empty and returns [9Xfail[109X otherwise.[133X755756[4X[32X Example [32X[104X757[4X[25Xgap>[125X [27Xx:=Automaton("det",3,2,[ [ 1, 2, 0 ], [ 0, 1, 2 ] ],[ 2 ],[ 1, 2 ]);;[127X[104X758[4X[25Xgap>[125X [27XS:=SyntacticSemigroupAut(x);;[127X[104X759[4X[25Xgap>[125X [27XSize(S);[127X[104X760[4X[28X3[128X[104X761[4X[32X[104X762763[1X2.6-3 SyntacticSemigroupLang[101X764765[29X[2XSyntacticSemigroupLang[102X( [3Xrat[103X ) [32X function766767[33X[0;0YReturns the syntactic semigroup of the language given by the rational768expression [3Xrat[103X.[133X769770[4X[32X Example [32X[104X771[4X[25Xgap>[125X [27Xrat := RationalExpression("a*ba*ba*(@Ub)");;[127X[104X772[4X[25Xgap>[125X [27XS:=SyntacticSemigroupLang(rat);;[127X[104X773[4X[25Xgap>[125X [27XSize(S);[127X[104X774[4X[28X7[128X[104X775[4X[32X[104X776777778779