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: 418346<?xml version="1.0" encoding="UTF-8"?>1<!-- $Id: aut-vs-rat.xml,v 1.13 Exp $ -->23<Chapter><Heading>Automata <Emph>versus</Emph> rational expressions</Heading>456A remarkable theorem due to Kleene shows that a language is recognized by a finite automaton precisely when it may be given by means of a rational expression, i.e. is a rational language.7<P/>8An automaton and a rational expression are said to be <E>equivalent</E> when both represent the same language.9In this chapter we describe functions to go from automata to equivalent rational expressions and <E>vice-versa</E>.1011<Section><Heading>From automata to rational expressions</Heading>121314<ManSection>15<Func Name="AutomatonToRatExp " Arg="A"/>16<Func Name="AutToRatExp" Arg="A"/>17<Func Name="FAtoRatExp" Arg="A"/>18<Description>19From a finite automaton, <C>FAtoRatExp</C>, <C>AutToRatExp</C> and <C>AutomatonToRatExp</C>, which are synonyms, compute one equivalent rational expression,20using the state elimination algorithm.21<Example>22gap> x:=Automaton("det",4,2,[[ 0, 1, 2, 3 ],[ 0, 1, 2, 3 ]],[ 3 ],[ 1, 3, 4 ]);;23gap> FAtoRatExp(x);24(aUb)(aUb)U@25gap> aut:=Automaton("det",4,"xy",[[ 0, 1, 2, 3 ],[ 0, 1, 2, 3 ]],[ 3 ],[ 1, 3, 4 ]);;26gap> FAtoRatExp(aut);27(xUy)(xUy)U@28</Example>29</Description>30</ManSection>31</Section>32<Section><Heading>From rational expression to automata</Heading>3334<ManSection>35<Func Name="RatExpToNDAut" Arg="R"/>36<Description>37Given a rational expression <A>R</A>, computes the equivalent NFA38<Example>39gap> r:=RationalExpression("aUab");40aUab41gap> Display(RatExpToNDAut(r));42| 1 2 3 443--------------------------------44a | [ 1, 2 ]45b | [ 3 ]46Initial state: [ 4 ]47Accepting states: [ 1, 3 ]48gap> r:=RationalExpression("xUxy");49xUxy50gap> Display(RatExpToNDAut(r));51| 1 2 3 452--------------------------------53x | [ 1, 2 ]54y | [ 3 ]55Initial state: [ 4 ]56Accepting states: [ 1, 3 ]57</Example>58</Description>59</ManSection>6061<ManSection>62<Func Name="RatExpToAutomaton" Arg="R"/>63<Func Name="RatExpToAut" Arg="R"/>64<Description>65Given a rational expression <A>R</A>, these functions, which are synonyms, use <Ref Func="RatExpToNDAut"/>) to compute the equivalent NFA and then returns the equivalent minimal DFA66<Example>67gap> r:=RationalExpression("@U(aUb)(aUb)");68@U(aUb)(aUb)69gap> Display(RatExpToAut(r));70| 1 2 3 471-----------------72a | 3 1 3 273b | 3 1 3 274Initial state: [ 4 ]75Accepting states: [ 1, 4 ]76gap> r:=RationalExpression("@U(0U1)(0U1)");77@U(0U1)(0U1)78gap> Display(RatExpToAut(r));79| 1 2 3 480-----------------810 | 3 1 3 2821 | 3 1 3 283Initial state: [ 4 ]84Accepting states: [ 1, 4 ]85</Example>86</Description>87</ManSection>8889</Section>90<Section>91<Heading>92Some tests on automata93</Heading>94This section describes functions that perform tests on automata, rational expressions and their accepted languages.95<ManSection>96<Func Arg="R" Name="IsEmptyLang" />97<Description>98This function tests if the language given through a rational expression or an automaton99<Arg>100R101</Arg>102is the empty language.103<Example>104gap> r:=RandomRatExp(2);105empty_set106gap> IsEmptyLang(r);107true108gap> r:=RandomRatExp(2);109aUb110gap> IsEmptyLang(r);111false112</Example>113</Description>114</ManSection>115<ManSection>116<Func Arg="R" Name="IsFullLang" />117<Description>118This function tests if the language given through a rational expression or an automaton119<Arg>120R121</Arg>122represents the Kleene closure of the alphabet of123<A>124R125</A>126.127<Example>128gap> r:=RationalExpression("aUb");129aUb130gap> IsFullLang(r);131false132gap> r:=RationalExpression("(aUb)*");133(aUb)*134gap> IsFullLang(r);135true136</Example>137</Description>138</ManSection>139140141<ManSection>142<Func Arg="A1, A2" Name="AreEqualLang" />143<Func Name="AreEquivAut" Arg="A1,A2 "/>144<Description>145These functions, which are synonyms, test if the automata or rational expressions <A>A1</A> and <A>A2</A> are equivalent, i.e. represent the same language.146This is performed by checking that the corresponding minimal automata are isomorphic. Note hat this cannot happen if the alphabets are different.147<Example>148gap> y:=RandomAutomaton("det",4,2);;149gap> x:=RandomAutomaton("det",4,2);;150gap> AreEquivAut(x, y);151false152gap> a:=RationalExpression("(aUb)*ab*");153(aUb)*ab*154gap> b:=RationalExpression("(aUb)*");155(aUb)*156gap> AreEqualLang(a, b);157false158gap> a:=RationalExpression("(bUa)*");159(bUa)*160gap> AreEqualLang(a, b);161true162gap> x:=RationalExpression("(1U0)*");163(1U0)*164gap> AreEqualLang(a, x);165The given languages are not over the same alphabet166false167</Example>168</Description>169</ManSection>170<ManSection>171<Func Arg="R1, R2" Name="IsContainedLang" />172<Description>173Tests if the language represented (through an automaton or a rational expression) by174<A>175R1176</A>177is contained in the language represented (through an automaton or a rational expression) by178<A>179R2180</A>181.182<Example>183gap> r:=RationalExpression("aUab");184aUab185gap> s:=RationalExpression("a","ab");186a187gap> IsContainedLang(s,r);188true189gap> IsContainedLang(r,s);190false191</Example>192</Description>193</ManSection>194<ManSection>195<Func Arg="R1, R2" Name="AreDisjointLang" />196<Description>197Tests if the languages represented (through automata or a rational expressions) by198<A>199R1200</A>201and202<A>203R2204</A>205are disjoint.206<Example>207gap> r:=RationalExpression("aUab");;208gap> s:=RationalExpression("a","ab");;209gap> AreDisjointLang(r,s);210false211</Example>212</Description>213</ManSection>214</Section>215216</Chapter>217218219