CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

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

Views: 418346
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!-- $Id: aut-vs-rat.xml,v 1.13 Exp $ -->
3
4
<Chapter><Heading>Automata <Emph>versus</Emph> rational expressions</Heading>
5
6
7
A 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.
8
<P/>
9
An automaton and a rational expression are said to be <E>equivalent</E> when both represent the same language.
10
In this chapter we describe functions to go from automata to equivalent rational expressions and <E>vice-versa</E>.
11
12
<Section><Heading>From automata to rational expressions</Heading>
13
14
15
<ManSection>
16
<Func Name="AutomatonToRatExp " Arg="A"/>
17
<Func Name="AutToRatExp" Arg="A"/>
18
<Func Name="FAtoRatExp" Arg="A"/>
19
<Description>
20
From a finite automaton, <C>FAtoRatExp</C>, <C>AutToRatExp</C> and <C>AutomatonToRatExp</C>, which are synonyms, compute one equivalent rational expression,
21
using the state elimination algorithm.
22
<Example>
23
gap> x:=Automaton("det",4,2,[[ 0, 1, 2, 3 ],[ 0, 1, 2, 3 ]],[ 3 ],[ 1, 3, 4 ]);;
24
gap> FAtoRatExp(x);
25
(aUb)(aUb)U@
26
gap> aut:=Automaton("det",4,"xy",[[ 0, 1, 2, 3 ],[ 0, 1, 2, 3 ]],[ 3 ],[ 1, 3, 4 ]);;
27
gap> FAtoRatExp(aut);
28
(xUy)(xUy)U@
29
</Example>
30
</Description>
31
</ManSection>
32
</Section>
33
<Section><Heading>From rational expression to automata</Heading>
34
35
<ManSection>
36
<Func Name="RatExpToNDAut" Arg="R"/>
37
<Description>
38
Given a rational expression <A>R</A>, computes the equivalent NFA
39
<Example>
40
gap> r:=RationalExpression("aUab");
41
aUab
42
gap> Display(RatExpToNDAut(r));
43
| 1 2 3 4
44
--------------------------------
45
a | [ 1, 2 ]
46
b | [ 3 ]
47
Initial state: [ 4 ]
48
Accepting states: [ 1, 3 ]
49
gap> r:=RationalExpression("xUxy");
50
xUxy
51
gap> Display(RatExpToNDAut(r));
52
| 1 2 3 4
53
--------------------------------
54
x | [ 1, 2 ]
55
y | [ 3 ]
56
Initial state: [ 4 ]
57
Accepting states: [ 1, 3 ]
58
</Example>
59
</Description>
60
</ManSection>
61
62
<ManSection>
63
<Func Name="RatExpToAutomaton" Arg="R"/>
64
<Func Name="RatExpToAut" Arg="R"/>
65
<Description>
66
Given 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 DFA
67
<Example>
68
gap> r:=RationalExpression("@U(aUb)(aUb)");
69
@U(aUb)(aUb)
70
gap> Display(RatExpToAut(r));
71
| 1 2 3 4
72
-----------------
73
a | 3 1 3 2
74
b | 3 1 3 2
75
Initial state: [ 4 ]
76
Accepting states: [ 1, 4 ]
77
gap> r:=RationalExpression("@U(0U1)(0U1)");
78
@U(0U1)(0U1)
79
gap> Display(RatExpToAut(r));
80
| 1 2 3 4
81
-----------------
82
0 | 3 1 3 2
83
1 | 3 1 3 2
84
Initial state: [ 4 ]
85
Accepting states: [ 1, 4 ]
86
</Example>
87
</Description>
88
</ManSection>
89
90
</Section>
91
<Section>
92
<Heading>
93
Some tests on automata
94
</Heading>
95
This section describes functions that perform tests on automata, rational expressions and their accepted languages.
96
<ManSection>
97
<Func Arg="R" Name="IsEmptyLang" />
98
<Description>
99
This function tests if the language given through a rational expression or an automaton
100
<Arg>
101
R
102
</Arg>
103
is the empty language.
104
<Example>
105
gap> r:=RandomRatExp(2);
106
empty_set
107
gap> IsEmptyLang(r);
108
true
109
gap> r:=RandomRatExp(2);
110
aUb
111
gap> IsEmptyLang(r);
112
false
113
</Example>
114
</Description>
115
</ManSection>
116
<ManSection>
117
<Func Arg="R" Name="IsFullLang" />
118
<Description>
119
This function tests if the language given through a rational expression or an automaton
120
<Arg>
121
R
122
</Arg>
123
represents the Kleene closure of the alphabet of
124
<A>
125
R
126
</A>
127
.
128
<Example>
129
gap> r:=RationalExpression("aUb");
130
aUb
131
gap> IsFullLang(r);
132
false
133
gap> r:=RationalExpression("(aUb)*");
134
(aUb)*
135
gap> IsFullLang(r);
136
true
137
</Example>
138
</Description>
139
</ManSection>
140
141
142
<ManSection>
143
<Func Arg="A1, A2" Name="AreEqualLang" />
144
<Func Name="AreEquivAut" Arg="A1,A2 "/>
145
<Description>
146
These 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.
147
This is performed by checking that the corresponding minimal automata are isomorphic. Note hat this cannot happen if the alphabets are different.
148
<Example>
149
gap> y:=RandomAutomaton("det",4,2);;
150
gap> x:=RandomAutomaton("det",4,2);;
151
gap> AreEquivAut(x, y);
152
false
153
gap> a:=RationalExpression("(aUb)*ab*");
154
(aUb)*ab*
155
gap> b:=RationalExpression("(aUb)*");
156
(aUb)*
157
gap> AreEqualLang(a, b);
158
false
159
gap> a:=RationalExpression("(bUa)*");
160
(bUa)*
161
gap> AreEqualLang(a, b);
162
true
163
gap> x:=RationalExpression("(1U0)*");
164
(1U0)*
165
gap> AreEqualLang(a, x);
166
The given languages are not over the same alphabet
167
false
168
</Example>
169
</Description>
170
</ManSection>
171
<ManSection>
172
<Func Arg="R1, R2" Name="IsContainedLang" />
173
<Description>
174
Tests if the language represented (through an automaton or a rational expression) by
175
<A>
176
R1
177
</A>
178
is contained in the language represented (through an automaton or a rational expression) by
179
<A>
180
R2
181
</A>
182
.
183
<Example>
184
gap> r:=RationalExpression("aUab");
185
aUab
186
gap> s:=RationalExpression("a","ab");
187
a
188
gap> IsContainedLang(s,r);
189
true
190
gap> IsContainedLang(r,s);
191
false
192
</Example>
193
</Description>
194
</ManSection>
195
<ManSection>
196
<Func Arg="R1, R2" Name="AreDisjointLang" />
197
<Description>
198
Tests if the languages represented (through automata or a rational expressions) by
199
<A>
200
R1
201
</A>
202
and
203
<A>
204
R2
205
</A>
206
are disjoint.
207
<Example>
208
gap> r:=RationalExpression("aUab");;
209
gap> s:=RationalExpression("a","ab");;
210
gap> AreDisjointLang(r,s);
211
false
212
</Example>
213
</Description>
214
</ManSection>
215
</Section>
216
217
</Chapter>
218
219