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[1X4 [33X[0;0YAutomata [13Xversus[113X[101X[1X rational expressions[133X[101X23[33X[0;0YA remarkable theorem due to Kleene shows that a language is recognized by a4finite automaton precisely when it may be given by means of a rational5expression, i.e. is a rational language.[133X67[33X[0;0YAn automaton and a rational expression are said to be [13Xequivalent[113X when both8represent the same language. In this chapter we describe functions to go9from automata to equivalent rational expressions and [13Xvice-versa[113X.[133X101112[1X4.1 [33X[0;0YFrom automata to rational expressions[133X[101X1314[1X4.1-1 AutomatonToRatExp [101X1516[29X[2XAutomatonToRatExp [102X( [3XA[103X ) [32X function17[29X[2XAutToRatExp[102X( [3XA[103X ) [32X function18[29X[2XFAtoRatExp[102X( [3XA[103X ) [32X function1920[33X[0;0YFrom a finite automaton, [10XFAtoRatExp[110X, [10XAutToRatExp[110X and [10XAutomatonToRatExp[110X,21which are synonyms, compute one equivalent rational expression, using the22state elimination algorithm.[133X2324[4X[32X Example [32X[104X25[4X[25Xgap>[125X [27Xx:=Automaton("det",4,2,[[ 0, 1, 2, 3 ],[ 0, 1, 2, 3 ]],[ 3 ],[ 1, 3, 4 ]);;[127X[104X26[4X[25Xgap>[125X [27XFAtoRatExp(x);[127X[104X27[4X[28X(aUb)(aUb)U@[128X[104X28[4X[25Xgap>[125X [27Xaut:=Automaton("det",4,"xy",[[ 0, 1, 2, 3 ],[ 0, 1, 2, 3 ]],[ 3 ],[ 1, 3, 4 ]);;[127X[104X29[4X[25Xgap>[125X [27XFAtoRatExp(aut);[127X[104X30[4X[28X(xUy)(xUy)U@[128X[104X31[4X[32X[104X323334[1X4.2 [33X[0;0YFrom rational expression to automata[133X[101X3536[1X4.2-1 RatExpToNDAut[101X3738[29X[2XRatExpToNDAut[102X( [3XR[103X ) [32X function3940[33X[0;0YGiven a rational expression [3XR[103X, computes the equivalent NFA[133X4142[4X[32X Example [32X[104X43[4X[25Xgap>[125X [27Xr:=RationalExpression("aUab");[127X[104X44[4X[28XaUab[128X[104X45[4X[25Xgap>[125X [27XDisplay(RatExpToNDAut(r));[127X[104X46[4X[28X | 1 2 3 4[128X[104X47[4X[28X--------------------------------[128X[104X48[4X[28X a | [ 1, 2 ][128X[104X49[4X[28X b | [ 3 ][128X[104X50[4X[28XInitial state: [ 4 ][128X[104X51[4X[28XAccepting states: [ 1, 3 ][128X[104X52[4X[25Xgap>[125X [27Xr:=RationalExpression("xUxy"); [127X[104X53[4X[28XxUxy[128X[104X54[4X[25Xgap>[125X [27XDisplay(RatExpToNDAut(r)); [127X[104X55[4X[28X | 1 2 3 4[128X[104X56[4X[28X--------------------------------[128X[104X57[4X[28X x | [ 1, 2 ] [128X[104X58[4X[28X y | [ 3 ] [128X[104X59[4X[28XInitial state: [ 4 ][128X[104X60[4X[28XAccepting states: [ 1, 3 ][128X[104X61[4X[32X[104X6263[1X4.2-2 RatExpToAutomaton[101X6465[29X[2XRatExpToAutomaton[102X( [3XR[103X ) [32X function66[29X[2XRatExpToAut[102X( [3XR[103X ) [32X function6768[33X[0;0YGiven a rational expression [3XR[103X, these functions, which are synonyms, use69[2XRatExpToNDAut[102X ([14X4.2-1[114X)) to compute the equivalent NFA and then returns the70equivalent minimal DFA[133X7172[4X[32X Example [32X[104X73[4X[25Xgap>[125X [27Xr:=RationalExpression("@U(aUb)(aUb)");[127X[104X74[4X[28X@U(aUb)(aUb)[128X[104X75[4X[25Xgap>[125X [27XDisplay(RatExpToAut(r));[127X[104X76[4X[28X | 1 2 3 4[128X[104X77[4X[28X-----------------[128X[104X78[4X[28X a | 3 1 3 2[128X[104X79[4X[28X b | 3 1 3 2[128X[104X80[4X[28XInitial state: [ 4 ][128X[104X81[4X[28XAccepting states: [ 1, 4 ][128X[104X82[4X[25Xgap>[125X [27Xr:=RationalExpression("@U(0U1)(0U1)");[127X[104X83[4X[28X@U(0U1)(0U1)[128X[104X84[4X[25Xgap>[125X [27XDisplay(RatExpToAut(r)); [127X[104X85[4X[28X | 1 2 3 4 [128X[104X86[4X[28X-----------------[128X[104X87[4X[28X 0 | 3 1 3 2 [128X[104X88[4X[28X 1 | 3 1 3 2 [128X[104X89[4X[28XInitial state: [ 4 ][128X[104X90[4X[28XAccepting states: [ 1, 4 ][128X[104X91[4X[32X[104X929394[1X4.3 [33X[0;0YSome tests on automata[133X[101X9596[33X[0;0YThis section describes functions that perform tests on automata, rational97expressions and their accepted languages.[133X9899[1X4.3-1 IsEmptyLang[101X100101[29X[2XIsEmptyLang[102X( [3XR[103X ) [32X function102103[33X[0;0YThis function tests if the language given through a rational expression or104an automaton [3X R [103X is the empty language.[133X105106[4X[32X Example [32X[104X107[4X[25Xgap>[125X [27Xr:=RandomRatExp(2);[127X[104X108[4X[28Xempty_set[128X[104X109[4X[25Xgap>[125X [27XIsEmptyLang(r);[127X[104X110[4X[28Xtrue[128X[104X111[4X[25Xgap>[125X [27Xr:=RandomRatExp(2);[127X[104X112[4X[28XaUb[128X[104X113[4X[25Xgap>[125X [27XIsEmptyLang(r);[127X[104X114[4X[28Xfalse[128X[104X115[4X[32X[104X116117[1X4.3-2 IsFullLang[101X118119[29X[2XIsFullLang[102X( [3XR[103X ) [32X function120121[33X[0;0YThis function tests if the language given through a rational expression or122an automaton [3X R [103X represents the Kleene closure of the alphabet of [3X R [103X .[133X123124[4X[32X Example [32X[104X125[4X[25Xgap>[125X [27Xr:=RationalExpression("aUb");[127X[104X126[4X[28XaUb[128X[104X127[4X[25Xgap>[125X [27XIsFullLang(r);[127X[104X128[4X[28Xfalse[128X[104X129[4X[25Xgap>[125X [27Xr:=RationalExpression("(aUb)*");[127X[104X130[4X[28X(aUb)*[128X[104X131[4X[25Xgap>[125X [27XIsFullLang(r);[127X[104X132[4X[28Xtrue[128X[104X133[4X[32X[104X134135[1X4.3-3 AreEqualLang[101X136137[29X[2XAreEqualLang[102X( [3XA1[103X, [3XA2[103X ) [32X function138[29X[2XAreEquivAut[102X( [3XA1[103X, [3XA2[103X ) [32X function139140[33X[0;0YThese functions, which are synonyms, test if the automata or rational141expressions [3XA1[103X and [3XA2[103X are equivalent, i.e. represent the same language. This142is performed by checking that the corresponding minimal automata are143isomorphic. Note hat this cannot happen if the alphabets are different.[133X144145[4X[32X Example [32X[104X146[4X[25Xgap>[125X [27Xy:=RandomAutomaton("det",4,2);;[127X[104X147[4X[25Xgap>[125X [27Xx:=RandomAutomaton("det",4,2);;[127X[104X148[4X[25Xgap>[125X [27XAreEquivAut(x, y);[127X[104X149[4X[28Xfalse[128X[104X150[4X[25Xgap>[125X [27Xa:=RationalExpression("(aUb)*ab*");[127X[104X151[4X[28X(aUb)*ab*[128X[104X152[4X[25Xgap>[125X [27Xb:=RationalExpression("(aUb)*");[127X[104X153[4X[28X(aUb)*[128X[104X154[4X[25Xgap>[125X [27XAreEqualLang(a, b);[127X[104X155[4X[28Xfalse[128X[104X156[4X[25Xgap>[125X [27Xa:=RationalExpression("(bUa)*");[127X[104X157[4X[28X(bUa)*[128X[104X158[4X[25Xgap>[125X [27XAreEqualLang(a, b);[127X[104X159[4X[28Xtrue[128X[104X160[4X[25Xgap>[125X [27Xx:=RationalExpression("(1U0)*");[127X[104X161[4X[28X(1U0)*[128X[104X162[4X[25Xgap>[125X [27XAreEqualLang(a, x); [127X[104X163[4X[28XThe given languages are not over the same alphabet[128X[104X164[4X[28Xfalse[128X[104X165[4X[32X[104X166167[1X4.3-4 IsContainedLang[101X168169[29X[2XIsContainedLang[102X( [3XR1[103X, [3XR2[103X ) [32X function170171[33X[0;0YTests if the language represented (through an automaton or a rational172expression) by [3X R1 [103X is contained in the language represented (through an173automaton or a rational expression) by [3X R2 [103X .[133X174175[4X[32X Example [32X[104X176[4X[25Xgap>[125X [27Xr:=RationalExpression("aUab");[127X[104X177[4X[28XaUab[128X[104X178[4X[25Xgap>[125X [27Xs:=RationalExpression("a","ab");[127X[104X179[4X[28Xa[128X[104X180[4X[25Xgap>[125X [27XIsContainedLang(s,r);[127X[104X181[4X[28Xtrue[128X[104X182[4X[25Xgap>[125X [27XIsContainedLang(r,s);[127X[104X183[4X[28Xfalse[128X[104X184[4X[32X[104X185186[1X4.3-5 AreDisjointLang[101X187188[29X[2XAreDisjointLang[102X( [3XR1[103X, [3XR2[103X ) [32X function189190[33X[0;0YTests if the languages represented (through automata or a rational191expressions) by [3X R1 [103X and [3X R2 [103X are disjoint.[133X192193[4X[32X Example [32X[104X194[4X[25Xgap>[125X [27Xr:=RationalExpression("aUab");;[127X[104X195[4X[25Xgap>[125X [27Xs:=RationalExpression("a","ab");;[127X[104X196[4X[25Xgap>[125X [27XAreDisjointLang(r,s);[127X[104X197[4X[28Xfalse[128X[104X198[4X[32X[104X199200201202