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[1X5 [33X[0;0YSome functions involving automata[133X[101X23[33X[0;0YThis chapter describes some functions involving automata. It starts with4functions to obtain equivalent automata of other type. Then the5minimalization is considered.[133X678[1X5.1 [33X[0;0YFrom one type to another[133X[101X910[33X[0;0YRecall that two automata are said to be equivalent when they recognize the11same language. Next we have functions which have as input automata of one12type and as output equivalent automata of another type.[133X1314[1X5.1-1 EpsilonToNFA[101X1516[29X[2XEpsilonToNFA[102X( [3XA[103X ) [32X function1718[33X[0;0Y[3XA[103X is an automaton with [22Xϵ[122X-transitions. Returns a NFA recognizing the same19language.[133X2021[4X[32X Example [32X[104X22[4X[25Xgap>[125X [27Xx:=RandomAutomaton("epsilon",3,2);;Display(x);[127X[104X23[4X[28X | 1 2 3[128X[104X24[4X[28X------------------------------------[128X[104X25[4X[28X a | [ 2 ] [ 3 ] [ 2 ][128X[104X26[4X[28X b | [ 1, 2 ] [ 1, 2 ] [ 1, 3 ][128X[104X27[4X[28X @ | [ 1, 2 ] [ 1, 2 ] [ 1, 2 ][128X[104X28[4X[28XInitial states: [ 2, 3 ][128X[104X29[4X[28XAccepting states: [ 1, 2, 3 ][128X[104X30[4X[25Xgap>[125X [27XDisplay(EpsilonToNFA(x));[127X[104X31[4X[28X | 1 2 3[128X[104X32[4X[28X------------------------------------------[128X[104X33[4X[28X a | [ 1, 2 ] [ 1, 2, 3 ] [ 1, 2 ][128X[104X34[4X[28X b | [ 1, 2 ] [ 1, 2 ] [ 1, 2, 3 ][128X[104X35[4X[28XInitial states: [ 1, 2, 3 ][128X[104X36[4X[28XAccepting states: [ 1, 2, 3 ][128X[104X37[4X[32X[104X3839[1X5.1-2 EpsilonToNFASet[101X4041[29X[2XEpsilonToNFASet[102X( [3XA[103X ) [32X function4243[33X[0;0Y[3XA[103X is an automaton with [22Xϵ[122X-transitions. Returns a NFA recognizing the same44language. This function differs from [2XEpsilonToNFA[102X ([14X5.1-1[114X) in that it is45faster for smaller automata, or automata with few epsilon transitions, but46slower in the really hard cases.[133X4748[1X5.1-3 EpsilonCompactedAut[101X4950[29X[2XEpsilonCompactedAut[102X( [3XA[103X ) [32X function5152[33X[0;0Y[3XA[103X is an automaton with [22Xϵ[122X-transitions. Returns an [22Xϵ[122XNFA with each53strongly-connected component of the epsilon-transitions digraph of [3XA[103X54identified with a single state and recognizing the same language.[133X5556[4X[32X Example [32X[104X57[4X[25Xgap>[125X [27Xx:=RandomAutomaton("epsilon",3,2);;Display(x);[127X[104X58[4X[28X | 1 2 3[128X[104X59[4X[28X------------------------------------[128X[104X60[4X[28X a | [ 1, 2 ] [ 1, 3 ] [ 1, 2 ][128X[104X61[4X[28X b | [ 1, 2 ] [ 1, 2 ] [ 2, 3 ][128X[104X62[4X[28X @ | [ 3 ] [ 2 ][128X[104X63[4X[28XInitial state: [ 3 ][128X[104X64[4X[28XAccepting states: [ 1, 3 ][128X[104X65[4X[25Xgap>[125X [27XDisplay(EpsilonCompactedAut(x));[127X[104X66[4X[28X | 1 2[128X[104X67[4X[28X-------------------------[128X[104X68[4X[28X a | [ 1, 2 ] [ 1, 2 ][128X[104X69[4X[28X b | [ 1, 2 ] [ 1, 2 ][128X[104X70[4X[28X @ |[128X[104X71[4X[28XInitial state: [ 2 ][128X[104X72[4X[28XAccepting states: [ 1, 2 ][128X[104X73[4X[32X[104X7475[1X5.1-4 ReducedNFA[101X7677[29X[2XReducedNFA[102X( [3XA[103X ) [32X function7879[33X[0;0Y[3XA[103X is a non deterministic automaton (without [22Xϵ[122X-transitions). Returns an NFA80accepting the same language as its input but with possibly fewer states (it81quotients out by the smallest right-invariant partition of the states). A82paper describing the algorithm is in preparation.[133X8384[4X[32X Example [32X[104X85[4X[25Xgap>[125X [27Xx:=RandomAutomaton("nondet",5,2);;Display(x);[127X[104X86[4X[28X | 1 2 3 4 5[128X[104X87[4X[28X----------------------------------------------------------------------[128X[104X88[4X[28X a | [ 1, 5 ] [ 1, 2, 4, 5 ] [ 1, 3, 5 ] [ 3, 4, 5 ] [ 4 ][128X[104X89[4X[28X b | [ 2, 3, 4 ] [ 3 ] [ 2, 3, 4 ] [ 2, 4, 5 ] [ 3 ][128X[104X90[4X[28XInitial state: [ 4 ][128X[104X91[4X[28XAccepting states: [ 1, 3, 4, 5 ][128X[104X92[4X[25Xgap>[125X [27XDisplay(ReducedNFA(x));[127X[104X93[4X[28X | 1 2 3 4[128X[104X94[4X[28X--------------------------------------------------------[128X[104X95[4X[28X a | [ 1, 3 ] [ 1, 2, 3, 4 ] [ 4 ] [ 1, 3, 4 ][128X[104X96[4X[28X b | [ 1, 2, 4 ] [ 1 ] [ 1 ] [ 2, 3, 4 ][128X[104X97[4X[28XInitial state: [ 4 ][128X[104X98[4X[28XAccepting states: [ 1, 3, 4 ][128X[104X99[4X[32X[104X100101[1X5.1-5 NFAtoDFA[101X102103[29X[2XNFAtoDFA[102X( [3XA[103X ) [32X function104105[33X[0;0YGiven an NFA, these synonym functions, compute the equivalent DFA, using the106powerset construction, according to the algorithm presented in the report of107the AMoRE [MMPTV95] program. The returned automaton is dense deterministic[133X108109[4X[32X Example [32X[104X110[4X[25Xgap>[125X [27Xx:=RandomAutomaton("nondet",3,2);;Display(x);[127X[104X111[4X[28X | 1 2 3[128X[104X112[4X[28X---------------------------[128X[104X113[4X[28X a | [ 2 ] [ 1, 3 ][128X[104X114[4X[28X b | [ 2, 3 ][128X[104X115[4X[28XInitial states: [ 1, 3 ][128X[104X116[4X[28XAccepting states: [ 1, 2 ][128X[104X117[4X[25Xgap>[125X [27XDisplay(NFAtoDFA(x));[127X[104X118[4X[28X | 1 2 3[128X[104X119[4X[28X--------------[128X[104X120[4X[28X a | 2 2 1[128X[104X121[4X[28X b | 3 3 3[128X[104X122[4X[28XInitial state: [ 1 ][128X[104X123[4X[28XAccepting states: [ 1, 2, 3 ][128X[104X124[4X[32X[104X125126[1X5.1-6 FuseSymbolsAut[101X127128[29X[2XFuseSymbolsAut[102X( [3XA[103X, [3Xs1[103X, [3Xs2[103X ) [32X function129130[33X[0;0YGiven an automaton [3XA[103X and integers [3Xs1[103X and [3Xs2[103X which, returns an NFA obtained131by replacing all transitions through [3Xs2[103X by transitions through [3Xs1[103X.[133X132133[4X[32X Example [32X[104X134[4X[25Xgap>[125X [27Xx:=RandomAutomaton("det",3,2);;Display(x);[127X[104X135[4X[28X | 1 2 3[128X[104X136[4X[28X--------------[128X[104X137[4X[28X a | 2 3[128X[104X138[4X[28X b | 1[128X[104X139[4X[28XInitial state: [ 3 ][128X[104X140[4X[28XAccepting states: [ 1, 2, 3 ][128X[104X141[4X[25Xgap>[125X [27XDisplay(FuseSymbolsAut(x,1,2));[127X[104X142[4X[28X | 1 2 3[128X[104X143[4X[28X---------------------------[128X[104X144[4X[28X a | [ 2 ] [ 1, 3 ][128X[104X145[4X[28XInitial state: [ 3 ][128X[104X146[4X[28XAccepting states: [ 1, 2, 3 ][128X[104X147[4X[32X[104X148149150[1X5.2 [33X[0;0YMinimalization of an automaton[133X[101X151152[33X[0;0YThe algorithm used to minimalize a dense deterministic automaton (i.e., to153compute a dense minimal automaton recognizing the same language) is based on154an algorithm due to Hopcroft (see [AHU74]). It is well known (see [HU69])155that it suffices to reduce the automaton given and remove the inaccessible156states. Again, the documentation for the computer program AMoRE [MMPTV95]157has been very useful.[133X158159[1X5.2-1 UsefulAutomaton[101X160161[29X[2XUsefulAutomaton[102X( [3XA[103X ) [32X function162163[33X[0;0YGiven an automaton [3XA[103X (deterministic or not), outputs a dense DFA [3XB[103X whose164states are all reachable and such that [3XA[103X and [3XB[103X are equivalent.[133X165166[4X[32X Example [32X[104X167[4X[25Xgap>[125X [27Xx:=RandomAutomaton("det",4,2);;Display(x);[127X[104X168[4X[28X | 1 2 3 4[128X[104X169[4X[28X-----------------[128X[104X170[4X[28X a | 3 4[128X[104X171[4X[28X b | 1 4[128X[104X172[4X[28XInitial state: [ 3 ][128X[104X173[4X[28XAccepting states: [ 2, 3, 4 ][128X[104X174[4X[25Xgap>[125X [27XDisplay(UsefulAutomaton(x));[127X[104X175[4X[28X | 1 2 3[128X[104X176[4X[28X--------------[128X[104X177[4X[28X a | 2 3 3[128X[104X178[4X[28X b | 3 3 3[128X[104X179[4X[28XInitial state: [ 1 ][128X[104X180[4X[28XAccepting states: [ 1, 2 ][128X[104X181[4X[32X[104X182183[1X5.2-2 MinimalizedAut[101X184185[29X[2XMinimalizedAut[102X( [3XA[103X ) [32X function186187[33X[0;0YReturns the minimal automaton equivalent to [3XA[103X.[133X188189[4X[32X Example [32X[104X190[4X[25Xgap>[125X [27Xx:=RandomAutomaton("det",4,2);;Display(x);[127X[104X191[4X[28X | 1 2 3 4[128X[104X192[4X[28X-----------------[128X[104X193[4X[28X a | 3 4[128X[104X194[4X[28X b | 1 2 3[128X[104X195[4X[28XInitial state: [ 4 ][128X[104X196[4X[28XAccepting states: [ 2, 3, 4 ][128X[104X197[4X[25Xgap>[125X [27XDisplay(MinimalizedAut(x));[127X[104X198[4X[28X | 1 2[128X[104X199[4X[28X-----------[128X[104X200[4X[28X a | 2 2[128X[104X201[4X[28X b | 2 2[128X[104X202[4X[28XInitial state: [ 1 ][128X[104X203[4X[28XAccepting state: [ 1 ][128X[104X204[4X[32X[104X205206[1X5.2-3 MinimalAutomaton[101X207208[29X[2X MinimalAutomaton[102X( [3XA[103X ) [32X attribute209210[33X[0;0YReturns the minimal automaton equivalent to [3XA[103X, but stores it so that future211computations of this automaton just return the stored automaton.[133X212213[4X[32X Example [32X[104X214[4X[25Xgap>[125X [27Xx:=RandomAutomaton("det",4,2);;Display(x);[127X[104X215[4X[28X | 1 2 3 4[128X[104X216[4X[28X-----------------[128X[104X217[4X[28X a | 2 4[128X[104X218[4X[28X b | 3 4[128X[104X219[4X[28XInitial state: [ 4 ][128X[104X220[4X[28XAccepting states: [ 1, 2, 3 ][128X[104X221[4X[25Xgap>[125X [27XDisplay(MinimalAutomaton(x));[127X[104X222[4X[28X | 1[128X[104X223[4X[28X--------[128X[104X224[4X[28X a | 1[128X[104X225[4X[28X b | 1[128X[104X226[4X[28XInitial state: [ 1 ][128X[104X227[4X[28XAccepting state:[128X[104X228[4X[32X[104X229230[1X5.2-4 AccessibleStates[101X231232[29X[2XAccessibleStates[102X( [3Xaut[103X[, [3Xp[103X] ) [32X function233234[33X[0;0YComputes the list of states of the automaton [3Xaut[103X which are accessible from235state [3Xp[103X. When [3Xp[103X is not given, returns the states which are accessible from236any initial state.[133X237238[4X[32X Example [32X[104X239[4X[25Xgap>[125X [27Xx:=RandomAutomaton("det",4,2);;Display(x);[127X[104X240[4X[28X | 1 2 3 4[128X[104X241[4X[28X-----------------[128X[104X242[4X[28X a | 1 2 4[128X[104X243[4X[28X b | 2 4[128X[104X244[4X[28XInitial state: [ 2 ][128X[104X245[4X[28XAccepting states: [ 1, 2, 3 ][128X[104X246[4X[25Xgap>[125X [27XAccessibleStates(x,3);[127X[104X247[4X[28X[ 1, 2, 3, 4 ][128X[104X248[4X[32X[104X249250[1X5.2-5 AccessibleAutomaton[101X251252[29X[2XAccessibleAutomaton[102X( [3XA[103X ) [32X function253254[33X[0;0YIf [3XA[103X is a deterministic automaton, not necessarily dense, an equivalent255dense deterministic accessible automaton is returned. (The function256[10XUsefulAutomaton[110X is called.)[133X257258[33X[0;0YIf [3XA[103X is not deterministic with a single initial state, an equivalent259accessible automaton is returned.[133X260261[4X[32X Example [32X[104X262[4X[25Xgap>[125X [27Xx:=RandomAutomaton("det",4,2);;Display(x);[127X[104X263[4X[28X | 1 2 3 4[128X[104X264[4X[28X-----------------[128X[104X265[4X[28X a | 1 3[128X[104X266[4X[28X b | 1 3 4[128X[104X267[4X[28XInitial state: [ 2 ][128X[104X268[4X[28XAccepting states: [ 3, 4 ][128X[104X269[4X[25Xgap>[125X [27XDisplay(AccessibleAutomaton(x));[127X[104X270[4X[28X | 1 2 3 4[128X[104X271[4X[28X-----------------[128X[104X272[4X[28X a | 2 4 4 4[128X[104X273[4X[28X b | 2 3 4 4[128X[104X274[4X[28XInitial state: [ 1 ][128X[104X275[4X[28XAccepting states: [ 2, 3 ][128X[104X276[4X[32X[104X277278[1X5.2-6 IntersectionLanguage[101X279280[29X[2XIntersectionLanguage[102X( [3XA1[103X, [3XA2[103X ) [32X function281[29X[2XIntersectionAutomaton[102X( [3XA1[103X, [3XA2[103X ) [32X function282283[33X[0;0YComputes an automaton that recognizes the intersection of the languages284given (through automata or rational expressions by) [3XA1[103X and [3XA2[103X. When the285arguments are deterministic automata, is the same as ProductAutomaton, but286works for all kinds of automata. Note that the language of the product of287two automata is precisely the intersection of the languages of the automata.[133X288289[4X[32X Example [32X[104X290[4X[25Xgap>[125X [27Xx:=RandomAutomaton("det",3,2);;Display(x);[127X[104X291[4X[28X | 1 2 3[128X[104X292[4X[28X--------------[128X[104X293[4X[28X a | 2 3[128X[104X294[4X[28X b | 1[128X[104X295[4X[28XInitial state: [ 3 ][128X[104X296[4X[28XAccepting states: [ 1, 2, 3 ][128X[104X297[4X[25Xgap>[125X [27Xy:=RandomAutomaton("det",3,2);;Display(y);[127X[104X298[4X[28X | 1 2 3[128X[104X299[4X[28X--------------[128X[104X300[4X[28X a | 1[128X[104X301[4X[28X b | 1 3[128X[104X302[4X[28XInitial state: [ 3 ][128X[104X303[4X[28XAccepting states: [ 1, 3 ][128X[104X304[4X[25Xgap>[125X [27XDisplay(IntersectionLanguage(x,y));[127X[104X305[4X[28X | 1 2[128X[104X306[4X[28X-----------[128X[104X307[4X[28X a | 2 2[128X[104X308[4X[28X b | 2 2[128X[104X309[4X[28XInitial state: [ 1 ][128X[104X310[4X[28XAccepting state: [ 1 ][128X[104X311[4X[32X[104X312313[1X5.2-7 AutomatonAllPairsPaths[101X314315[29X[2XAutomatonAllPairsPaths[102X( [3XA[103X ) [32X function316317[33X[0;0YGiven an automaton [3XA[103X, with [10Xn[110X states, outputs a [10Xn[110X x [10Xn[110X matrix P, such that318P[i][j] is the list of simple paths from state i to state j in [3XA[103X.[133X319320[4X[32X Example [32X[104X321[4X[25Xgap>[125X [27Xa:=RandomAutomaton("det",3,2);[127X[104X322[4X[28X< deterministic automaton on 2 letters with 3 states >[128X[104X323[4X[25Xgap>[125X [27XAutomatonAllPairsPaths(a);[127X[104X324[4X[28X[ [ [ [ 1, 1 ] ], [ ], [ ] ], [ [ [ 2, 1 ] ], [ [ 2, 2 ] ], [ ] ],[128X[104X325[4X[28X [ [ [ 3, 2, 1 ] ], [ [ 3, 2 ] ], [ [ 3, 3 ] ] ] ][128X[104X326[4X[25Xgap>[125X [27XDisplay(a);[127X[104X327[4X[28X | 1 2 3[128X[104X328[4X[28X--------------[128X[104X329[4X[28X a | 1 2[128X[104X330[4X[28X b | 1 2 3[128X[104X331[4X[28XInitial state: [ 3 ][128X[104X332[4X[28XAccepting states: [ 1, 2 ][128X[104X333[4X[32X[104X334335336337