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-func.xml,v 1.13 Exp $ -->
3
4
<Chapter><Heading>Some functions involving automata</Heading>
5
This chapter describes some functions involving automata. It starts with functions to obtain equivalent automata of other type. Then the minimalization is considered.
6
7
<Section><Heading>From one type to another</Heading>
8
Recall that two automata are said to be equivalent when they recognize the same language.
9
Next we have functions which have as input automata of one type and as output equivalent automata of another type.
10
11
<ManSection>
12
<Func Name="EpsilonToNFA" Arg="A"/>
13
<Description>
14
<A>A</A> is an automaton with <M>\epsilon</M>-transitions. Returns a NFA
15
recognizing the same language.
16
<Example><![CDATA[
17
gap> x:=RandomAutomaton("epsilon",3,2);;Display(x);
18
| 1 2 3
19
------------------------------------
20
a | [ 2 ] [ 3 ] [ 2 ]
21
b | [ 1, 2 ] [ 1, 2 ] [ 1, 3 ]
22
@ | [ 1, 2 ] [ 1, 2 ] [ 1, 2 ]
23
Initial states: [ 2, 3 ]
24
Accepting states: [ 1, 2, 3 ]
25
gap> Display(EpsilonToNFA(x));
26
| 1 2 3
27
------------------------------------------
28
a | [ 1, 2 ] [ 1, 2, 3 ] [ 1, 2 ]
29
b | [ 1, 2 ] [ 1, 2 ] [ 1, 2, 3 ]
30
Initial states: [ 1, 2, 3 ]
31
Accepting states: [ 1, 2, 3 ]
32
]]></Example>
33
</Description>
34
</ManSection>
35
36
37
<ManSection>
38
<Func Name="EpsilonToNFASet" Arg="A"/>
39
<Description>
40
<A>A</A> is an automaton with <M>\epsilon</M>-transitions. Returns a NFA
41
recognizing the same language. This function differs from <Ref Func="EpsilonToNFA"/>
42
in that it is faster for smaller automata, or automata with few
43
epsilon transitions, but slower in the really hard cases.
44
</Description>
45
</ManSection>
46
47
48
49
<ManSection>
50
<Func Name="EpsilonCompactedAut" Arg="A"/>
51
<Description>
52
<A>A</A> is an automaton with <M>\epsilon</M>-transitions. Returns an
53
<M>\epsilon</M>NFA with
54
each strongly-connected component of the
55
epsilon-transitions digraph of <A>A</A> identified with a single state and
56
recognizing the same language.
57
<Example><![CDATA[
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
]]></Example>
75
</Description>
76
</ManSection>
77
78
79
80
<ManSection>
81
<Func Name="ReducedNFA" Arg="A"/>
82
<Description>
83
<A>A</A> is a non deterministic automaton (without <M>\epsilon</M>-transitions). Returns an
84
NFA accepting
85
the same language as its input but with possibly fewer states (it
86
quotients out
87
by the smallest right-invariant partition of the states). A paper describing
88
the algorithm is in preparation.
89
<Example><![CDATA[
90
gap> x:=RandomAutomaton("nondet",5,2);;Display(x);
91
| 1 2 3 4 5
92
----------------------------------------------------------------------
93
a | [ 1, 5 ] [ 1, 2, 4, 5 ] [ 1, 3, 5 ] [ 3, 4, 5 ] [ 4 ]
94
b | [ 2, 3, 4 ] [ 3 ] [ 2, 3, 4 ] [ 2, 4, 5 ] [ 3 ]
95
Initial state: [ 4 ]
96
Accepting states: [ 1, 3, 4, 5 ]
97
gap> Display(ReducedNFA(x));
98
| 1 2 3 4
99
--------------------------------------------------------
100
a | [ 1, 3 ] [ 1, 2, 3, 4 ] [ 4 ] [ 1, 3, 4 ]
101
b | [ 1, 2, 4 ] [ 1 ] [ 1 ] [ 2, 3, 4 ]
102
Initial state: [ 4 ]
103
Accepting states: [ 1, 3, 4 ]
104
]]></Example>
105
</Description>
106
</ManSection>
107
108
109
110
<ManSection>
111
<Func Name="NFAtoDFA" Arg="A"/>
112
<Description>
113
Given an NFA, these synonym functions, compute the equivalent DFA, using the powerset construction,
114
according to the algorithm presented in the report of the AMoRE <Cite Key="AMORE:95"/> program.
115
The returned automaton is dense deterministic
116
<Example><![CDATA[
117
gap> x:=RandomAutomaton("nondet",3,2);;Display(x);
118
| 1 2 3
119
---------------------------
120
a | [ 2 ] [ 1, 3 ]
121
b | [ 2, 3 ]
122
Initial states: [ 1, 3 ]
123
Accepting states: [ 1, 2 ]
124
gap> Display(NFAtoDFA(x));
125
| 1 2 3
126
--------------
127
a | 2 2 1
128
b | 3 3 3
129
Initial state: [ 1 ]
130
Accepting states: [ 1, 2, 3 ]
131
]]></Example>
132
</Description>
133
</ManSection>
134
135
136
<ManSection>
137
<Func Name="FuseSymbolsAut" Arg="A, s1, s2"/>
138
<Description>
139
Given an automaton <A>A</A> and integers <A>s1</A> and <A>s2</A> which, returns an NFA
140
obtained by replacing all transitions through <A>s2</A> by transitions through <A>s1</A>.
141
<Example><![CDATA[
142
gap> x:=RandomAutomaton("det",3,2);;Display(x);
143
| 1 2 3
144
--------------
145
a | 2 3
146
b | 1
147
Initial state: [ 3 ]
148
Accepting states: [ 1, 2, 3 ]
149
gap> Display(FuseSymbolsAut(x,1,2));
150
| 1 2 3
151
---------------------------
152
a | [ 2 ] [ 1, 3 ]
153
Initial state: [ 3 ]
154
Accepting states: [ 1, 2, 3 ]
155
]]></Example>
156
</Description>
157
</ManSection>
158
159
160
161
</Section>
162
163
164
<Section><Heading>Minimalization of an automaton</Heading>
165
The algorithm used to minimalize a dense deterministic automaton (i.e., to
166
compute a dense minimal
167
automaton recognizing the same language) is based on an algorithm due to
168
Hopcroft (see <Cite Key="AHU:74"/>). It is well known (see <Cite Key="HU:69"/>) that it suffices
169
to reduce the automaton given and remove the inaccessible states. Again, the
170
documentation for the computer program AMoRE <Cite Key="AMORE:95"/> has been very useful.
171
172
<ManSection>
173
<Func Name="UsefulAutomaton" Arg="A"/>
174
<Description>
175
Given an automaton <A>A</A> (deterministic or not), outputs a dense DFA <A>B</A> whose states are all reachable and such that <A>A</A> and <A>B</A> are equivalent.
176
<Example><![CDATA[
177
gap> x:=RandomAutomaton("det",4,2);;Display(x);
178
| 1 2 3 4
179
-----------------
180
a | 3 4
181
b | 1 4
182
Initial state: [ 3 ]
183
Accepting states: [ 2, 3, 4 ]
184
gap> Display(UsefulAutomaton(x));
185
| 1 2 3
186
--------------
187
a | 2 3 3
188
b | 3 3 3
189
Initial state: [ 1 ]
190
Accepting states: [ 1, 2 ]
191
]]></Example>
192
</Description>
193
</ManSection>
194
195
<ManSection>
196
<Func Name="MinimalizedAut" Arg="A"/>
197
<Description>
198
Returns the minimal automaton equivalent to <A>A</A>.
199
<Example><![CDATA[
200
gap> x:=RandomAutomaton("det",4,2);;Display(x);
201
| 1 2 3 4
202
-----------------
203
a | 3 4
204
b | 1 2 3
205
Initial state: [ 4 ]
206
Accepting states: [ 2, 3, 4 ]
207
gap> Display(MinimalizedAut(x));
208
| 1 2
209
-----------
210
a | 2 2
211
b | 2 2
212
Initial state: [ 1 ]
213
Accepting state: [ 1 ]
214
]]></Example>
215
</Description>
216
</ManSection>
217
218
<ManSection>
219
<Attr Name=" MinimalAutomaton" Arg="A"/>
220
<Description>
221
Returns the minimal automaton equivalent to <A>A</A>, but stores it so that
222
future computations of this automaton just return the stored automaton.
223
<Example><![CDATA[
224
gap> x:=RandomAutomaton("det",4,2);;Display(x);
225
| 1 2 3 4
226
-----------------
227
a | 2 4
228
b | 3 4
229
Initial state: [ 4 ]
230
Accepting states: [ 1, 2, 3 ]
231
gap> Display(MinimalAutomaton(x));
232
| 1
233
--------
234
a | 1
235
b | 1
236
Initial state: [ 1 ]
237
Accepting state:
238
]]></Example>
239
</Description>
240
</ManSection>
241
242
<ManSection>
243
<Func Name="AccessibleStates" Arg="aut [, p]"/>
244
<Description>
245
Computes the list of states of the automaton <A>aut</A>
246
which are accessible from state <A>p</A>. When <A>p</A> is not given, returns the states which are accessible from any initial state.
247
<Example><![CDATA[
248
gap> x:=RandomAutomaton("det",4,2);;Display(x);
249
| 1 2 3 4
250
-----------------
251
a | 1 2 4
252
b | 2 4
253
Initial state: [ 2 ]
254
Accepting states: [ 1, 2, 3 ]
255
gap> AccessibleStates(x,3);
256
[ 1, 2, 3, 4 ]
257
]]></Example>
258
</Description>
259
</ManSection>
260
261
<ManSection>
262
<Func Name="AccessibleAutomaton" Arg="A"/>
263
<Description>
264
If <A>A</A> is a deterministic automaton, not necessarily dense, an
265
equivalent dense deterministic accessible automaton is returned.
266
(The function <C>UsefulAutomaton</C> is called.)
267
<P/>
268
If <A>A</A> is not deterministic with a single initial state, an equivalent
269
accessible automaton is returned.
270
271
<Example><![CDATA[
272
gap> x:=RandomAutomaton("det",4,2);;Display(x);
273
| 1 2 3 4
274
-----------------
275
a | 1 3
276
b | 1 3 4
277
Initial state: [ 2 ]
278
Accepting states: [ 3, 4 ]
279
gap> Display(AccessibleAutomaton(x));
280
| 1 2 3 4
281
-----------------
282
a | 2 4 4 4
283
b | 2 3 4 4
284
Initial state: [ 1 ]
285
Accepting states: [ 2, 3 ]
286
]]></Example>
287
</Description>
288
</ManSection>
289
290
<ManSection>
291
<Func Name="IntersectionLanguage" Arg="A1,A2"/>
292
<Func Name="IntersectionAutomaton" Arg="A1,A2"/>
293
<Description>
294
Computes an automaton that recognizes the intersection of the languages given (through automata or rational expressions by) <A>A1</A> and <A>A2</A>.
295
When the arguments are deterministic automata, is the same as ProductAutomaton, but works for all kinds of automata. Note that the language of the product of two automata is precisely the intersection of the languages of the automata.
296
<Example><![CDATA[
297
gap> x:=RandomAutomaton("det",3,2);;Display(x);
298
| 1 2 3
299
--------------
300
a | 2 3
301
b | 1
302
Initial state: [ 3 ]
303
Accepting states: [ 1, 2, 3 ]
304
gap> y:=RandomAutomaton("det",3,2);;Display(y);
305
| 1 2 3
306
--------------
307
a | 1
308
b | 1 3
309
Initial state: [ 3 ]
310
Accepting states: [ 1, 3 ]
311
gap> Display(IntersectionLanguage(x,y));
312
| 1 2
313
-----------
314
a | 2 2
315
b | 2 2
316
Initial state: [ 1 ]
317
Accepting state: [ 1 ]
318
]]></Example>
319
</Description>
320
</ManSection>
321
322
323
<ManSection>
324
<Func Name="AutomatonAllPairsPaths" Arg="A"/>
325
<Description>
326
Given an automaton <A>A</A>, with <C>n</C> states, outputs a <C>n</C> x <C>n</C> matrix P,
327
such that P[i][j] is the list of simple paths from state i to
328
state j in <A>A</A>.
329
<Example><![CDATA[
330
gap> a:=RandomAutomaton("det",3,2);
331
< deterministic automaton on 2 letters with 3 states >
332
gap> AutomatonAllPairsPaths(a);
333
[ [ [ [ 1, 1 ] ], [ ], [ ] ], [ [ [ 2, 1 ] ], [ [ 2, 2 ] ], [ ] ],
334
[ [ [ 3, 2, 1 ] ], [ [ 3, 2 ] ], [ [ 3, 3 ] ] ] ]
335
gap> Display(a);
336
| 1 2 3
337
--------------
338
a | 1 2
339
b | 1 2 3
340
Initial state: [ 3 ]
341
Accepting states: [ 1, 2 ]
342
]]></Example>
343
</Description>
344
</ManSection>
345
346
347
</Section>
348
</Chapter>
349
350
351
352
353
354