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
2
4 Automata versus rational expressions
3
4
A remarkable theorem due to Kleene shows that a language is recognized by a
5
finite automaton precisely when it may be given by means of a rational
6
expression, i.e. is a rational language.
7
8
An automaton and a rational expression are said to be equivalent when both
9
represent the same language. In this chapter we describe functions to go
10
from automata to equivalent rational expressions and vice-versa.
11
12
13
4.1 From automata to rational expressions
14
15
4.1-1 AutomatonToRatExp 
16
17
AutomatonToRatExp ( A )  function
18
AutToRatExp( A )  function
19
FAtoRatExp( A )  function
20
21
From a finite automaton, FAtoRatExp, AutToRatExp and AutomatonToRatExp,
22
which are synonyms, compute one equivalent rational expression, using the
23
state elimination algorithm.
24
25
 Example 
26
gap> x:=Automaton("det",4,2,[[ 0, 1, 2, 3 ],[ 0, 1, 2, 3 ]],[ 3 ],[ 1, 3, 4 ]);;
27
gap> FAtoRatExp(x);
28
(aUb)(aUb)U@
29
gap> aut:=Automaton("det",4,"xy",[[ 0, 1, 2, 3 ],[ 0, 1, 2, 3 ]],[ 3 ],[ 1, 3, 4 ]);;
30
gap> FAtoRatExp(aut);
31
(xUy)(xUy)U@
32

33
34
35
4.2 From rational expression to automata
36
37
4.2-1 RatExpToNDAut
38
39
RatExpToNDAut( R )  function
40
41
Given a rational expression R, computes the equivalent NFA
42
43
 Example 
44
gap> r:=RationalExpression("aUab");
45
aUab
46
gap> Display(RatExpToNDAut(r));
47
 | 1 2 3 4
48
--------------------------------
49
 a | [ 1, 2 ]
50
 b | [ 3 ]
51
Initial state: [ 4 ]
52
Accepting states: [ 1, 3 ]
53
gap> r:=RationalExpression("xUxy"); 
54
xUxy
55
gap> Display(RatExpToNDAut(r)); 
56
 | 1 2 3 4
57
--------------------------------
58
 x | [ 1, 2 ] 
59
 y | [ 3 ] 
60
Initial state: [ 4 ]
61
Accepting states: [ 1, 3 ]
62

63
64
4.2-2 RatExpToAutomaton
65
66
RatExpToAutomaton( R )  function
67
RatExpToAut( R )  function
68
69
Given a rational expression R, these functions, which are synonyms, use
70
RatExpToNDAut (4.2-1)) to compute the equivalent NFA and then returns the
71
equivalent minimal DFA
72
73
 Example 
74
gap> r:=RationalExpression("@U(aUb)(aUb)");
75
@U(aUb)(aUb)
76
gap> Display(RatExpToAut(r));
77
 | 1 2 3 4
78
-----------------
79
 a | 3 1 3 2
80
 b | 3 1 3 2
81
Initial state: [ 4 ]
82
Accepting states: [ 1, 4 ]
83
gap> r:=RationalExpression("@U(0U1)(0U1)");
84
@U(0U1)(0U1)
85
gap> Display(RatExpToAut(r)); 
86
 | 1 2 3 4 
87
-----------------
88
 0 | 3 1 3 2 
89
 1 | 3 1 3 2 
90
Initial state: [ 4 ]
91
Accepting states: [ 1, 4 ]
92

93
94
95
4.3 Some tests on automata
96
97
This section describes functions that perform tests on automata, rational
98
expressions and their accepted languages.
99
100
4.3-1 IsEmptyLang
101
102
IsEmptyLang( R )  function
103
104
This function tests if the language given through a rational expression or
105
an automaton  R  is the empty language.
106
107
 Example 
108
gap> r:=RandomRatExp(2);
109
empty_set
110
gap> IsEmptyLang(r);
111
true
112
gap> r:=RandomRatExp(2);
113
aUb
114
gap> IsEmptyLang(r);
115
false
116

117
118
4.3-2 IsFullLang
119
120
IsFullLang( R )  function
121
122
This function tests if the language given through a rational expression or
123
an automaton  R  represents the Kleene closure of the alphabet of  R  .
124
125
 Example 
126
gap> r:=RationalExpression("aUb");
127
aUb
128
gap> IsFullLang(r);
129
false
130
gap> r:=RationalExpression("(aUb)*");
131
(aUb)*
132
gap> IsFullLang(r);
133
true
134

135
136
4.3-3 AreEqualLang
137
138
AreEqualLang( A1, A2 )  function
139
AreEquivAut( A1, A2 )  function
140
141
These functions, which are synonyms, test if the automata or rational
142
expressions A1 and A2 are equivalent, i.e. represent the same language. This
143
is performed by checking that the corresponding minimal automata are
144
isomorphic. Note hat this cannot happen if the alphabets are different.
145
146
 Example 
147
gap> y:=RandomAutomaton("det",4,2);;
148
gap> x:=RandomAutomaton("det",4,2);;
149
gap> AreEquivAut(x, y);
150
false
151
gap> a:=RationalExpression("(aUb)*ab*");
152
(aUb)*ab*
153
gap> b:=RationalExpression("(aUb)*");
154
(aUb)*
155
gap> AreEqualLang(a, b);
156
false
157
gap> a:=RationalExpression("(bUa)*");
158
(bUa)*
159
gap> AreEqualLang(a, b);
160
true
161
gap> x:=RationalExpression("(1U0)*");
162
(1U0)*
163
gap> AreEqualLang(a, x); 
164
The given languages are not over the same alphabet
165
false
166

167
168
4.3-4 IsContainedLang
169
170
IsContainedLang( R1, R2 )  function
171
172
Tests if the language represented (through an automaton or a rational
173
expression) by  R1  is contained in the language represented (through an
174
automaton or a rational expression) by  R2  .
175
176
 Example 
177
gap> r:=RationalExpression("aUab");
178
aUab
179
gap> s:=RationalExpression("a","ab");
180
a
181
gap> IsContainedLang(s,r);
182
true
183
gap> IsContainedLang(r,s);
184
false
185

186
187
4.3-5 AreDisjointLang
188
189
AreDisjointLang( R1, R2 )  function
190
191
Tests if the languages represented (through automata or a rational
192
expressions) by  R1  and  R2  are disjoint.
193
194
 Example 
195
gap> r:=RationalExpression("aUab");;
196
gap> s:=RationalExpression("a","ab");;
197
gap> AreDisjointLang(r,s);
198
false
199

200
201
202