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
5 Some functions involving automata
3
4
This chapter describes some functions involving automata. It starts with
5
functions to obtain equivalent automata of other type. Then the
6
minimalization is considered.
7
8
9
5.1 From one type to another
10
11
Recall that two automata are said to be equivalent when they recognize the
12
same language. Next we have functions which have as input automata of one
13
type and as output equivalent automata of another type.
14
15
5.1-1 EpsilonToNFA
16
17
EpsilonToNFA( A )  function
18
19
A is an automaton with ϵ-transitions. Returns a NFA recognizing the same
20
language.
21
22
 Example 
23
gap> x:=RandomAutomaton("epsilon",3,2);;Display(x);
24
 | 1 2 3
25
------------------------------------
26
 a | [ 2 ] [ 3 ] [ 2 ]
27
 b | [ 1, 2 ] [ 1, 2 ] [ 1, 3 ]
28
 @ | [ 1, 2 ] [ 1, 2 ] [ 1, 2 ]
29
Initial states: [ 2, 3 ]
30
Accepting states: [ 1, 2, 3 ]
31
gap> Display(EpsilonToNFA(x));
32
 | 1 2 3
33
------------------------------------------
34
 a | [ 1, 2 ] [ 1, 2, 3 ] [ 1, 2 ]
35
 b | [ 1, 2 ] [ 1, 2 ] [ 1, 2, 3 ]
36
Initial states: [ 1, 2, 3 ]
37
Accepting states: [ 1, 2, 3 ]
38

39
40
5.1-2 EpsilonToNFASet
41
42
EpsilonToNFASet( A )  function
43
44
A is an automaton with ϵ-transitions. Returns a NFA recognizing the same
45
language. This function differs from EpsilonToNFA (5.1-1) in that it is
46
faster for smaller automata, or automata with few epsilon transitions, but
47
slower in the really hard cases.
48
49
5.1-3 EpsilonCompactedAut
50
51
EpsilonCompactedAut( A )  function
52
53
A is an automaton with ϵ-transitions. Returns an ϵNFA with each
54
strongly-connected component of the epsilon-transitions digraph of A
55
identified with a single state and recognizing the same language.
56
57
 Example 
58
gap> x:=RandomAutomaton("epsilon",3,2);;Display(x);
59
 | 1 2 3
60
------------------------------------
61
 a | [ 1, 2 ] [ 1, 3 ] [ 1, 2 ]
62
 b | [ 1, 2 ] [ 1, 2 ] [ 2, 3 ]
63
 @ | [ 3 ] [ 2 ]
64
Initial state: [ 3 ]
65
Accepting states: [ 1, 3 ]
66
gap> Display(EpsilonCompactedAut(x));
67
 | 1 2
68
-------------------------
69
 a | [ 1, 2 ] [ 1, 2 ]
70
 b | [ 1, 2 ] [ 1, 2 ]
71
 @ |
72
Initial state: [ 2 ]
73
Accepting states: [ 1, 2 ]
74

75
76
5.1-4 ReducedNFA
77
78
ReducedNFA( A )  function
79
80
A is a non deterministic automaton (without ϵ-transitions). Returns an NFA
81
accepting the same language as its input but with possibly fewer states (it
82
quotients out by the smallest right-invariant partition of the states). A
83
paper describing the algorithm is in preparation.
84
85
 Example 
86
gap> x:=RandomAutomaton("nondet",5,2);;Display(x);
87
 | 1 2 3 4 5
88
----------------------------------------------------------------------
89
 a | [ 1, 5 ] [ 1, 2, 4, 5 ] [ 1, 3, 5 ] [ 3, 4, 5 ] [ 4 ]
90
 b | [ 2, 3, 4 ] [ 3 ] [ 2, 3, 4 ] [ 2, 4, 5 ] [ 3 ]
91
Initial state: [ 4 ]
92
Accepting states: [ 1, 3, 4, 5 ]
93
gap> Display(ReducedNFA(x));
94
 | 1 2 3 4
95
--------------------------------------------------------
96
 a | [ 1, 3 ] [ 1, 2, 3, 4 ] [ 4 ] [ 1, 3, 4 ]
97
 b | [ 1, 2, 4 ] [ 1 ] [ 1 ] [ 2, 3, 4 ]
98
Initial state: [ 4 ]
99
Accepting states: [ 1, 3, 4 ]
100

101
102
5.1-5 NFAtoDFA
103
104
NFAtoDFA( A )  function
105
106
Given an NFA, these synonym functions, compute the equivalent DFA, using the
107
powerset construction, according to the algorithm presented in the report of
108
the AMoRE [MMPTV95] program. The returned automaton is dense deterministic
109
110
 Example 
111
gap> x:=RandomAutomaton("nondet",3,2);;Display(x);
112
 | 1 2 3
113
---------------------------
114
 a | [ 2 ] [ 1, 3 ]
115
 b | [ 2, 3 ]
116
Initial states: [ 1, 3 ]
117
Accepting states: [ 1, 2 ]
118
gap> Display(NFAtoDFA(x));
119
 | 1 2 3
120
--------------
121
 a | 2 2 1
122
 b | 3 3 3
123
Initial state: [ 1 ]
124
Accepting states: [ 1, 2, 3 ]
125

126
127
5.1-6 FuseSymbolsAut
128
129
FuseSymbolsAut( A, s1, s2 )  function
130
131
Given an automaton A and integers s1 and s2 which, returns an NFA obtained
132
by replacing all transitions through s2 by transitions through s1.
133
134
 Example 
135
gap> x:=RandomAutomaton("det",3,2);;Display(x);
136
 | 1 2 3
137
--------------
138
 a | 2 3
139
 b | 1
140
Initial state: [ 3 ]
141
Accepting states: [ 1, 2, 3 ]
142
gap> Display(FuseSymbolsAut(x,1,2));
143
 | 1 2 3
144
---------------------------
145
 a | [ 2 ] [ 1, 3 ]
146
Initial state: [ 3 ]
147
Accepting states: [ 1, 2, 3 ]
148

149
150
151
5.2 Minimalization of an automaton
152
153
The algorithm used to minimalize a dense deterministic automaton (i.e., to
154
compute a dense minimal automaton recognizing the same language) is based on
155
an algorithm due to Hopcroft (see [AHU74]). It is well known (see [HU69])
156
that it suffices to reduce the automaton given and remove the inaccessible
157
states. Again, the documentation for the computer program AMoRE [MMPTV95]
158
has been very useful.
159
160
5.2-1 UsefulAutomaton
161
162
UsefulAutomaton( A )  function
163
164
Given an automaton A (deterministic or not), outputs a dense DFA B whose
165
states are all reachable and such that A and B are equivalent.
166
167
 Example 
168
gap> x:=RandomAutomaton("det",4,2);;Display(x);
169
 | 1 2 3 4
170
-----------------
171
 a | 3 4
172
 b | 1 4
173
Initial state: [ 3 ]
174
Accepting states: [ 2, 3, 4 ]
175
gap> Display(UsefulAutomaton(x));
176
 | 1 2 3
177
--------------
178
 a | 2 3 3
179
 b | 3 3 3
180
Initial state: [ 1 ]
181
Accepting states: [ 1, 2 ]
182

183
184
5.2-2 MinimalizedAut
185
186
MinimalizedAut( A )  function
187
188
Returns the minimal automaton equivalent to A.
189
190
 Example 
191
gap> x:=RandomAutomaton("det",4,2);;Display(x);
192
 | 1 2 3 4
193
-----------------
194
 a | 3 4
195
 b | 1 2 3
196
Initial state: [ 4 ]
197
Accepting states: [ 2, 3, 4 ]
198
gap> Display(MinimalizedAut(x));
199
 | 1 2
200
-----------
201
 a | 2 2
202
 b | 2 2
203
Initial state: [ 1 ]
204
Accepting state: [ 1 ]
205

206
207
5.2-3 MinimalAutomaton
208
209
 MinimalAutomaton( A )  attribute
210
211
Returns the minimal automaton equivalent to A, but stores it so that future
212
computations of this automaton just return the stored automaton.
213
214
 Example 
215
gap> x:=RandomAutomaton("det",4,2);;Display(x);
216
 | 1 2 3 4
217
-----------------
218
 a | 2 4
219
 b | 3 4
220
Initial state: [ 4 ]
221
Accepting states: [ 1, 2, 3 ]
222
gap> Display(MinimalAutomaton(x));
223
 | 1
224
--------
225
 a | 1
226
 b | 1
227
Initial state: [ 1 ]
228
Accepting state:
229

230
231
5.2-4 AccessibleStates
232
233
AccessibleStates( aut[, p] )  function
234
235
Computes the list of states of the automaton aut which are accessible from
236
state p. When p is not given, returns the states which are accessible from
237
any initial state.
238
239
 Example 
240
gap> x:=RandomAutomaton("det",4,2);;Display(x);
241
 | 1 2 3 4
242
-----------------
243
 a | 1 2 4
244
 b | 2 4
245
Initial state: [ 2 ]
246
Accepting states: [ 1, 2, 3 ]
247
gap> AccessibleStates(x,3);
248
[ 1, 2, 3, 4 ]
249

250
251
5.2-5 AccessibleAutomaton
252
253
AccessibleAutomaton( A )  function
254
255
If A is a deterministic automaton, not necessarily dense, an equivalent
256
dense deterministic accessible automaton is returned. (The function
257
UsefulAutomaton is called.)
258
259
If A is not deterministic with a single initial state, an equivalent
260
accessible automaton is returned.
261
262
 Example 
263
gap> x:=RandomAutomaton("det",4,2);;Display(x);
264
 | 1 2 3 4
265
-----------------
266
 a | 1 3
267
 b | 1 3 4
268
Initial state: [ 2 ]
269
Accepting states: [ 3, 4 ]
270
gap> Display(AccessibleAutomaton(x));
271
 | 1 2 3 4
272
-----------------
273
 a | 2 4 4 4
274
 b | 2 3 4 4
275
Initial state: [ 1 ]
276
Accepting states: [ 2, 3 ]
277

278
279
5.2-6 IntersectionLanguage
280
281
IntersectionLanguage( A1, A2 )  function
282
IntersectionAutomaton( A1, A2 )  function
283
284
Computes an automaton that recognizes the intersection of the languages
285
given (through automata or rational expressions by) A1 and A2. When the
286
arguments are deterministic automata, is the same as ProductAutomaton, but
287
works for all kinds of automata. Note that the language of the product of
288
two automata is precisely the intersection of the languages of the automata.
289
290
 Example 
291
gap> x:=RandomAutomaton("det",3,2);;Display(x);
292
 | 1 2 3
293
--------------
294
 a | 2 3
295
 b | 1
296
Initial state: [ 3 ]
297
Accepting states: [ 1, 2, 3 ]
298
gap> y:=RandomAutomaton("det",3,2);;Display(y);
299
 | 1 2 3
300
--------------
301
 a | 1
302
 b | 1 3
303
Initial state: [ 3 ]
304
Accepting states: [ 1, 3 ]
305
gap> Display(IntersectionLanguage(x,y));
306
 | 1 2
307
-----------
308
 a | 2 2
309
 b | 2 2
310
Initial state: [ 1 ]
311
Accepting state: [ 1 ]
312

313
314
5.2-7 AutomatonAllPairsPaths
315
316
AutomatonAllPairsPaths( A )  function
317
318
Given an automaton A, with n states, outputs a n x n matrix P, such that
319
P[i][j] is the list of simple paths from state i to state j in A.
320
321
 Example 
322
gap> a:=RandomAutomaton("det",3,2);
323
< deterministic automaton on 2 letters with 3 states >
324
gap> AutomatonAllPairsPaths(a);
325
[ [ [ [ 1, 1 ] ], [ ], [ ] ], [ [ [ 2, 1 ] ], [ [ 2, 2 ] ], [ ] ],
326
 [ [ [ 3, 2, 1 ] ], [ [ 3, 2 ] ], [ [ 3, 3 ] ] ] ]
327
gap> Display(a);
328
 | 1 2 3
329
--------------
330
 a | 1 2
331
 b | 1 2 3
332
Initial state: [ 3 ]
333
Accepting states: [ 1, 2 ]
334

335
336
337