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: automata.xml,v 1.13 Exp $ -->
3
4
<Chapter><Heading>Finite Automata</Heading>
5
6
This chapter describes the representations used in this package for
7
finite automata and some functions to determine information about them.
8
<P/>
9
We have to remark that the states of an automaton are always named
10
<M>1,2,3,\ldots;</M> the alphabet may be given by the user. By default
11
it is <M>\{a,b,c,\ldots\}</M> (or <M>\{a_1,a_2,a_3,\ldots\}</M> in the
12
case of alphabets with more than <M>26</M> letters).
13
<P/>
14
The transition function of an automaton with <M>q</M> states over an alphabet with <M> n</M>
15
letters is represented by a (not necessarily dense) <M>n\times q</M>
16
matrix. Each row of the matrix describes the action of the corresponding
17
letter on the states.
18
In the case of a <Emph>deterministic automaton</Emph> (DFA) the entries of the
19
matrix are non-negative integers.
20
When all entries of the transition table
21
are positive integers, the automaton is said to be
22
<Emph>dense</Emph> or <Emph>complete</Emph>.
23
<!--<Index>automaton!complete</Index><Index>automaton!dense</Index>-->
24
25
In the case of a <Emph>non deterministic automaton</Emph> (NFA) the entries of the
26
matrix may be lists of non-negative integers.
27
28
<Emph>Automata with <M>\epsilon</M>-transitions</Emph> are also allowed: the
29
last letter of the alphabet is assumed to be <M>\epsilon</M> and is represented by @.
30
31
<Section><Heading>Automata generation</Heading>
32
<!-- In the case of <Emph>non
33
deterministic automata</Emph> the entries of the matrix are lists of
34
non-negative integers. -->
35
36
The way to create an automaton in &GAP; is the following
37
<ManSection>
38
<Func Name="Automaton" Arg="Type, Size, Alphabet,TransitionTable,
39
Initial, Accepting"/>
40
<Description>
41
<!-- The names chosen for the arguments describe their meaning.-->
42
<C>Type</C> may be
43
<C>"det"</C>, <C>"nondet"</C> or <C>"epsilon"</C> according to whether
44
the automaton is deterministic, non deterministic or an automaton with
45
<M>\epsilon</M>-transitions.
46
<C>Size</C> is a positive integer representing the
47
number of states of the automaton. <C>Alphabet</C> is the number of
48
letters of the alphabet or a list with the letters of the ordered alphabet.
49
<C>TransitionTable</C> is the transition matrix. The
50
entries are non-negative integers not greater than the size of the automaton.
51
In the case of non deterministic automata, lists of non-negative integers not
52
greater than the size of the automaton are also allowed. <C>Initial</C>
53
and <C>Accepting</C> are, respectively, the lists of initial and accepting
54
states.
55
<Example>
56
<![CDATA[
57
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,4]],[1],[4]);
58
< deterministic automaton on 2 letters with 4 states >
59
gap> Display(aut);
60
| 1 2 3 4
61
-----------------
62
a | 3 3 4
63
b | 3 4 4
64
Initial state: [ 1 ]
65
Accepting state: [ 4 ]
66
]]>
67
</Example>
68
The alphabet of the automaton may be specified:
69
<Example><![CDATA[
70
gap> aut:=Automaton("det",4,"01",[[3,,3,4],[3,4,0,4]],[1],[4]);
71
< deterministic automaton on 2 letters with 4 states >
72
gap> Display(aut);
73
| 1 2 3 4
74
-----------------
75
0 | 3 3 4
76
1 | 3 4 4
77
Initial state: [ 1 ]
78
Accepting state: [ 4 ]
79
]]></Example>
80
Instead of leaving a hole in the transition matrix, we may write a <C>0</C>
81
to mean that no transition is present.
82
Non deterministic automata may be given the same way.
83
<Example><![CDATA[
84
gap> ndaut:=Automaton("nondet",4,2,[[3,[1,2],3,0],[3,4,0,[2,3]]],[1],[4]);
85
< non deterministic automaton on 2 letters with 4 states >
86
gap> Display(ndaut);
87
| 1 2 3 4
88
-----------------------------------------
89
a | [ 3 ] [ 1, 2 ] [ 3 ]
90
b | [ 3 ] [ 4 ] [ 2, 3 ]
91
Initial state: [ 1 ]
92
Accepting state: [ 4 ]
93
]]></Example>
94
Also in the same way can be given <M>\epsilon</M>-automata. The letter <M>\epsilon</M> is written <C>@</C> instead.
95
<Example><![CDATA[
96
gap> x:=Automaton("epsilon",3,"01@",[[,[2],[3]],[[1,3],,[1]],[[1],[2],
97
> [2]]],[2],[2,3]);
98
< epsilon automaton on 3 letters with 3 states >
99
gap> Display(x);
100
| 1 2 3
101
------------------------------
102
0 | [ 2 ] [ 3 ]
103
1 | [ 1, 3 ] [ 1 ]
104
@ | [ 1 ] [ 2 ] [ 2 ]
105
Initial state: [ 2 ]
106
Accepting states: [ 2, 3 ]
107
]]></Example>
108
Bigger automata are displayed in another form:
109
<Example><![CDATA[
110
gap> aut:=Automaton("det",16,2,[[4,0,0,6,3,1,4,8,7,4,3,0,6,1,6,0],
111
> [3,4,0,0,6,1,0,6,1,6,1,6,6,4,8,7,4,5]],[1],[4]);
112
< deterministic automaton on 2 letters with 16 states >
113
gap> Display(aut);
114
1 a 4
115
1 b 3
116
2 b 4
117
... some more lines
118
15 a 6
119
15 b 8
120
16 b 7
121
Initial state: [ 1 ]
122
Accepting state: [ 4 ]
123
]]></Example>
124
</Description> </ManSection>
125
126
<ManSection>
127
<Func Name="IsAutomaton" Arg="O"/>
128
<Description>
129
In the presence of an object <A>O</A>, one may want to test whether
130
<C>O</C> is an automaton. This may be done using the function <C>IsAutomaton</C>.
131
<Example><![CDATA[
132
gap> x:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;
133
gap> IsAutomaton(x);
134
true
135
]]></Example>
136
</Description> </ManSection>
137
138
<ManSection>
139
<Func Name="IsDeterministicAutomaton" Arg="aut"/>
140
<Description>
141
Returns <K>true</K> when <C>aut</C> is a deterministic automaton and <K>false</K> otherwise.
142
<Example><![CDATA[
143
gap> x:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;
144
gap> IsDeterministicAutomaton(x);
145
true
146
]]></Example>
147
</Description> </ManSection>
148
<!-- silentius -->
149
<ManSection>
150
<Func Name="IsNonDeterministicAutomaton" Arg="aut"/>
151
<Description>
152
Returns <K>true</K> when <C>aut</C> is a non deterministic automaton and <K>false</K> otherwise.
153
<Example><![CDATA[
154
gap> y:=Automaton("nondet",3,2,[[,[1,3],],[,[2,3],[1,3]]],[1,2],[1,3]);;
155
gap> IsNonDeterministicAutomaton(y);
156
true
157
]]></Example>
158
</Description> </ManSection>
159
160
<ManSection>
161
<Func Name="IsEpsilonAutomaton" Arg="aut"/>
162
<Description>
163
Returns <K>true</K> when <C>aut</C> is an <M>\epsilon</M>-automaton and <K>false</K> otherwise.
164
<Example><![CDATA[
165
gap> z:=Automaton("epsilon",2,2,[[[1,2],],[[2],[1]]],[1,2],[1,2]);;
166
gap> IsEpsilonAutomaton(z);
167
true
168
]]></Example>
169
</Description> </ManSection>
170
<ManSection>
171
<Func Name="String" Arg="aut"/>
172
<Description>
173
174
The way &GAP; displays an automaton is quite natural, but when one wants to
175
do small changes, for example using <E>copy/paste</E>, the use of the function
176
<C>String</C> (possibly followed by <C>Print</C>) may be usefull.
177
<Example><![CDATA[
178
gap> x:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;
179
gap> String(x);
180
"Automaton(\"det\",3,\"ab\",[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;"
181
gap> Print(String(x));
182
Automaton("det",3,"ab",[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;
183
]]></Example>
184
<Example><![CDATA[
185
gap> z:=Automaton("epsilon",2,2,[[[1,2],],[[2],[1]]],[1,2],[1,2]);;
186
gap> Print(String(z));
187
Automaton("epsilon",2,"a@",[ [ [ 1, 2 ], [ ] ], [ [ 2 ], [ 1 ] ] ],[ 1, 2 ],[ \
188
1, 2 ]);;
189
]]></Example>
190
</Description> </ManSection>
191
192
<ManSection>
193
<Func Name="RandomAutomaton" Arg="Type, Size, Alphabet"/>
194
<Description>
195
Given the <A>Type</A>, the <A>Size</A> (i.e. the number of states) and the <A>Alphabet</A> (a positive integer
196
or a list), returns a pseudo random automaton with
197
these parameters.
198
<Example><![CDATA[
199
gap> RandomAutomaton("det",5,"ac");
200
< deterministic automaton on 2 letters with 5 states >
201
gap> Display(last);
202
| 1 2 3 4 5
203
--------------------
204
a | 2 3
205
c | 2 3
206
Initial state: [ 4 ]
207
Accepting states: [ 3, 4 ]
208
209
gap> RandomAutomaton("nondet",3,["a","b","c"]);
210
< non deterministic automaton on 3 letters with 3 states >
211
212
gap> RandomAutomaton("epsilon",2,"abc");
213
< epsilon automaton on 4 letters with 2 states >
214
215
gap> RandomAutomaton("epsilon",2,2);
216
< epsilon automaton on 3 letters with 2 states >
217
gap> Display(last);
218
| 1 2
219
----------------------
220
a | [ 1, 2 ]
221
b | [ 2 ] [ 1 ]
222
@ | [ 1, 2 ]
223
Initial state: [ 2 ]
224
Accepting states: [ 1, 2 ]
225
226
gap> a:=RandomTransformation(3);;
227
gap> b:=RandomTransformation(3);;
228
gap> aut:=RandomAutomaton("det",4,[a,b]);
229
< deterministic automaton on 2 letters with 4 states >
230
]]></Example>
231
</Description> </ManSection>
232
233
</Section>
234
235
236
<Section><Heading>Automata internals</Heading>
237
In this section we describe the functions used to access the internals of an automaton.
238
239
<ManSection>
240
<Func Name="AlphabetOfAutomaton" Arg="aut"/>
241
<Description>
242
243
Returns the number of symbols in the alphabet of automaton <C>aut</C>.
244
<Example><![CDATA[
245
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
246
gap> AlphabetOfAutomaton(aut);
247
2
248
]]></Example>
249
</Description> </ManSection>
250
251
252
<ManSection>
253
<Func Name="AlphabetOfAutomatonAsList" Arg="aut"/>
254
<Description>
255
256
Returns the alphabet of automaton <C>aut</C> always
257
as a list.
258
259
Note that when the alphabet of the automaton is given as an integer
260
(meaning the number of symbols)
261
not greater than 26 it returns the list <C>"abcd...."</C>.
262
If the alphabet is given by means of an integer greater than 26, the
263
function returns <C>[ "a1", "a2", "a3", "a4", ... ]</C>.
264
<Example><![CDATA[
265
gap> a:=RandomAutomaton("det",5,"cat");
266
< deterministic automaton on 3 letters with 5 states >
267
gap> AlphabetOfAutomaton(a);
268
3
269
gap> AlphabetOfAutomatonAsList(a);
270
"cat"
271
gap> a:=RandomAutomaton("det",5,20);
272
< deterministic automaton on 20 letters with 5 states >
273
gap> AlphabetOfAutomaton(a);
274
20
275
gap> AlphabetOfAutomatonAsList(a);
276
"abcdefghijklmnopqrst"
277
gap> a:=RandomAutomaton("det",5,30);
278
< deterministic automaton on 30 letters with 5 states >
279
gap> AlphabetOfAutomaton(a);
280
30
281
gap> AlphabetOfAutomatonAsList(a);
282
[ "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11",
283
"a12", "a13", "a14", "a15", "a16", "a17", "a18", "a19", "a20", "a21",
284
"a22", "a23", "a24", "a25", "a26", "a27", "a28", "a29", "a30" ]
285
]]></Example>
286
</Description> </ManSection>
287
288
289
290
<ManSection>
291
<Func Name="TransitionMatrixOfAutomaton" Arg="aut"/>
292
<Description>
293
294
Returns the transition matrix of automaton <C>aut</C>.
295
<Example><![CDATA[
296
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
297
gap> TransitionMatrixOfAutomaton(aut);
298
[ [ 3, 0, 3, 4 ], [ 3, 4, 0, 0 ] ]
299
]]></Example>
300
</Description> </ManSection>
301
302
303
<ManSection>
304
<Func Name="InitialStatesOfAutomaton" Arg="aut"/>
305
<Description>
306
307
Returns the initial states of automaton <C>aut</C>.
308
<Example><![CDATA[
309
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
310
gap> InitialStatesOfAutomaton(aut);
311
[ 1 ]
312
]]></Example>
313
</Description> </ManSection>
314
315
316
<ManSection>
317
<Func Name="SetInitialStatesOfAutomaton" Arg="aut, I"/>
318
<Description>
319
320
Sets the initial states of automaton <C>aut</C>.
321
<C>I</C> may be a positive integer or a list of positive integers.
322
<Example><![CDATA[
323
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
324
gap> SetInitialStatesOfAutomaton(aut,4);
325
gap> InitialStatesOfAutomaton(aut);
326
[ 4 ]
327
gap> SetInitialStatesOfAutomaton(aut,[2,3]);
328
gap> InitialStatesOfAutomaton(aut);
329
[ 2, 3 ]
330
]]></Example>
331
</Description> </ManSection>
332
333
334
<ManSection>
335
<Func Name="FinalStatesOfAutomaton" Arg="aut"/>
336
<Description>
337
338
Returns the final states of automaton <C>aut</C>.
339
<Example><![CDATA[
340
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
341
gap> FinalStatesOfAutomaton(aut);
342
[ 4 ]
343
]]></Example>
344
</Description> </ManSection>
345
346
347
<ManSection>
348
<Func Name="SetFinalStatesOfAutomaton" Arg="aut, F"/>
349
<Description>
350
351
Sets the final states of automaton <C>aut</C>.
352
<C>F</C> may be a positive integer or a list of positive integers.
353
<Example><![CDATA[
354
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
355
gap> FinalStatesOfAutomaton(aut);
356
[ 4 ]
357
gap> SetFinalStatesOfAutomaton(aut,2);
358
gap> FinalStatesOfAutomaton(aut);
359
[ 2 ]
360
]]></Example>
361
</Description> </ManSection>
362
363
364
<ManSection>
365
<Func Name="NumberStatesOfAutomaton" Arg="aut"/>
366
<Description>
367
368
Returns the number of states of automaton <C>aut</C>.
369
<Example><![CDATA[
370
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
371
gap> NumberStatesOfAutomaton(aut);
372
4
373
]]></Example>
374
</Description> </ManSection>
375
376
</Section>
377
378
379
380
<Section><Heading>Comparison of automata</Heading>
381
Although there is no standard way to compare automata it is usefull to be able to do some kind of comparison. Doing so, one can consider sets of automata.
382
We just compare the strings of the automata.
383
<Log>
384
gap> x:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;
385
gap> y:=Automaton("det",3,2,[ [ 2, 0, 0 ], [ 1, 3, 0 ] ],[ 3 ],[ 2, 3 ]);;
386
gap> x=y;
387
false
388
gap> Size(Set([y,x,x]));
389
2
390
</Log>
391
</Section>
392
<Section><Heading>Tests involving automata</Heading>
393
394
This section describes some useful tests involving automata.
395
396
<ManSection>
397
<Func Name="IsDenseAutomaton" Arg="aut"/>
398
<Description>
399
400
Tests whether a deterministic automaton <C>aut</C> is complete.
401
(See also <Ref Func="NullCompletionAutomaton"/>.)
402
<Example><![CDATA[
403
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
404
gap> IsDenseAutomaton(aut);
405
false
406
]]></Example>
407
</Description> </ManSection>
408
409
<ManSection>
410
<Func Name="IsRecognizedByAutomaton" Arg="A,w"/>
411
<Description>
412
The arguments are: an automaton <A>A</A> and a string (i.e. a word) <A>w</A> in the alphabet of the automaton.
413
Returns <C>true</C> if the word is recognized by the automaton
414
and <C>false</C> otherwise.
415
416
<Example><![CDATA[
417
gap> aut:=Automaton("det",3,2,[[1,2,1],[2,1,3]],[1],[2]);;
418
gap> IsRecognizedByAutomaton(aut,"bbb");
419
true
420
421
gap> aut:=Automaton("det",3,"01",[[1,2,1],[2,1,3]],[1],[2]);;
422
gap> IsRecognizedByAutomaton(aut,"111");
423
true
424
]]></Example>
425
</Description> </ManSection>
426
427
428
<ManSection>
429
<Func Name="IsPermutationAutomaton" Arg="aut"/>
430
<Description>
431
The argument is a deterministic automaton. Returns <K>true</K> when each letter of the alphabet induces a permutation on the vertices and <K>false</K> otherwise. <Example><![CDATA[
432
gap> x:=Automaton("det",3,2,[ [ 1, 2, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2, 3 ]);;
433
gap> IsPermutationAutomaton(x);
434
true
435
]]></Example>
436
</Description> </ManSection>
437
438
<ManSection>
439
<Func Name="IsInverseAutomaton" Arg="aut"/>
440
<Description>
441
The argument is a deterministic automaton. Returns <K>true</K> when each letter of the alphabet induces an injective partial function on the vertices and <K>false</K> otherwise. <Example><![CDATA[
442
gap> x:=Automaton("det",3,2,[ [ 0, 1, 3 ], [ 0, 1, 2 ] ],[ 2 ],[ 1 ]);;
443
gap> IsInverseAutomaton(x);
444
true
445
]]></Example>
446
447
Frequently an inverse automaton is thought as if the inverse edges (labeled by formal inverses of the letters of the alphabet) were present, although they are usually not explicited. They can be made explicit using the function <C>AddInverseEdgesToInverseAutomaton</C>
448
</Description> </ManSection>
449
450
<ManSection>
451
<Func Name="AddInverseEdgesToInverseAutomaton" Arg="aut"/>
452
<Description>
453
The argument is an inverse automaton over the alphabet <M>\{a,b,c,\ldots\}</M>. Returns an automaton with the inverse edges added. (The formal inverse of a letter is represented by the corresponding capital letter.)
454
<Example><![CDATA[
455
gap> x:=Automaton("det",3,2,[[ 0, 1, 3 ],[ 0, 1, 2 ]],[ 2 ],[ 1 ]);;Display(x);
456
| 1 2 3
457
--------------
458
a | 1 3
459
b | 1 2
460
Initial state: [ 2 ]
461
Accepting state: [ 1 ]
462
gap> AddInverseEdgesToInverseAutomaton(x);Display(x);
463
| 1 2 3
464
--------------
465
a | 1 3
466
b | 1 2
467
A | 2 3
468
B | 2 3
469
Initial state: [ 2 ]
470
Accepting state: [ 1 ]
471
]]></Example>
472
</Description> </ManSection>
473
474
<ManSection>
475
<Func Name="IsReversibleAutomaton" Arg="aut"/>
476
<Description>
477
The argument is a deterministic automaton.
478
Returns <K>true</K> when <A>aut</A> is a reversible automaton, i.e. the automaton obtained by reversing all edges and switching the initial and final states
479
(see also <Ref Func="ReversedAutomaton"/>) is deterministic. Returns <K>false</K> otherwise.
480
<Example><![CDATA[
481
gap> x:=Automaton("det",3,2,[ [ 0, 1, 2 ], [ 0, 1, 3 ] ],[ 2 ],[ 2 ]);;
482
gap> IsReversibleAutomaton(x);
483
true
484
]]></Example>
485
</Description> </ManSection>
486
487
</Section>
488
489
<Section><Heading>Basic operations</Heading>
490
491
492
<ManSection>
493
<Func Name="CopyAutomaton" Arg="aut"/>
494
<Description>
495
Returns a new automaton, which is a copy of automaton <A>aut</A>.
496
</Description> </ManSection>
497
498
499
<ManSection>
500
<Func Name="NullCompletionAutomaton" Arg="aut"/>
501
<Description>
502
503
<C>aut</C> is a deterministic automaton. If it is complete returns <A>aut</A>,
504
otherwise returns the completion (with a null state) of <A>aut</A>. Notice that the words recognized by <A>aut</A> and its completion are the same.
505
<Example><![CDATA[
506
gap> aut:=Automaton("det",4,2,[[3,,3,4],[2,4,4,]],[1],[4]);;
507
gap> IsDenseAutomaton(aut);
508
false
509
gap> y:=NullCompletionAutomaton(aut);;Display(y);
510
| 1 2 3 4 5
511
--------------------
512
a | 3 5 3 4 5
513
b | 2 4 4 5 5
514
Initial state: [ 1 ]
515
Accepting state: [ 4 ]
516
]]></Example>
517
518
The state added is a <Emph>sink state</Emph> i.e. it is a state <M>q</M> which is not initial nor accepting and for all letter <M>a</M> in the alphabet of the automaton, <M>q</M> is the result of the action of <M>a</M> in <M>q</M>. (Notice that reading
519
a word, one does not go out of a sink state.)
520
</Description> </ManSection>
521
522
<ManSection>
523
<Func Name="ListSinkStatesAut" Arg="aut"/>
524
<Description>
525
Computes the list of all sink states of the automaton <A>aut</A>.
526
<Example><![CDATA[
527
gap> x:=Automaton("det",3,2,[ [ 2, 3, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2, 3 ]);;
528
gap> ListSinkStatesAut(x);
529
[ ]
530
gap> y:=Automaton("det",3,2,[ [ 2, 3, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2 ]);;
531
gap> ListSinkStatesAut(y);
532
[ 3 ]
533
]]></Example>
534
</Description> </ManSection>
535
536
<ManSection>
537
<Func Name="RemovedSinkStates" Arg="aut"/>
538
<Description>
539
Removes all sink states of the automaton <A>aut</A>.
540
<Example><![CDATA[
541
gap> y:=Automaton("det",3,2,[[ 2, 3, 3 ],[ 1, 2, 3 ]],[ 1 ],[ 2 ]);;Display(y);
542
| 1 2 3
543
--------------
544
a | 2 3 3
545
b | 1 2 3
546
Initial state: [ 1 ]
547
Accepting state: [ 2 ]
548
gap> x := RemovedSinkStates(y);Display(x);
549
< deterministic automaton on 2 letters with 2 states >
550
| 1 2
551
-----------
552
a | 2
553
b | 1 2
554
Initial state: [ 1 ]
555
Accepting state: [ 2 ]
556
]]></Example>
557
</Description> </ManSection>
558
559
<ManSection>
560
<Func Name="ReversedAutomaton" Arg="aut"/>
561
<Description>
562
Inverts the arrows of the automaton <A>aut</A>.
563
<Example><![CDATA[
564
gap> y:=Automaton("det",3,2,[ [ 2, 3, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2 ]);;
565
gap> z:=ReversedAutomaton(y);;Display(z);
566
| 1 2 3
567
------------------------------
568
a | [ 1 ] [ 2, 3 ]
569
b | [ 1 ] [ 2 ] [ 3 ]
570
Initial state: [ 2 ]
571
Accepting state: [ 1 ]
572
]]></Example>
573
</Description> </ManSection>
574
575
576
<ManSection>
577
<Func Name="PermutedAutomaton" Arg="aut, p"/>
578
<Description>
579
Given an automaton <A>aut</A> and a list <A>p</A> representing a permutation of the states,
580
outputs the equivalent permuted automaton.
581
<Example><![CDATA[
582
gap> y:=Automaton("det",4,2,[[2,3,4,2],[0,0,0,1]],[1],[3]);;Display(y);
583
| 1 2 3 4
584
-----------------
585
a | 2 3 4 2
586
b | 1
587
Initial state: [ 1 ]
588
Accepting state: [ 3 ]
589
gap> Display(PermutedAutomaton(y, [3,2,4,1]));
590
| 1 2 3 4
591
-----------------
592
a | 2 4 2 1
593
b | 3
594
Initial state: [ 3 ]
595
Accepting state: [ 4 ]
596
]]></Example>
597
</Description> </ManSection>
598
599
600
601
<ManSection>
602
<Func Name="ListPermutedAutomata" Arg="aut"/>
603
<Description>
604
Given an automaton <A>aut</A>, returns a list of automata with permuted states
605
<Example><![CDATA[
606
gap> x:=Automaton("det",3,2,[ [ 0, 2, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2, 3 ]);;
607
gap> ListPermutedAutomata(x);
608
[ < deterministic automaton on 2 letters with 3 states >,
609
< deterministic automaton on 2 letters with 3 states >,
610
< deterministic automaton on 2 letters with 3 states >,
611
< deterministic automaton on 2 letters with 3 states >,
612
< deterministic automaton on 2 letters with 3 states >,
613
< deterministic automaton on 2 letters with 3 states > ]
614
]]></Example>
615
</Description> </ManSection>
616
617
618
<ManSection>
619
<Func Name="NormalizedAutomaton" Arg="A"/>
620
<Description>
621
Produces an equivalent automaton but in which the initial state is numbered 1 and the accepting states have the greatest numbers.
622
<Example><![CDATA[
623
gap> x:=Automaton("det",3,2,[[ 1, 2, 0 ],[ 0, 1, 2 ]],[2],[1, 2]);;Display(x);
624
| 1 2 3
625
--------------
626
a | 1 2
627
b | 1 2
628
Initial state: [ 2 ]
629
Accepting states: [ 1, 2 ]
630
gap> Display(NormalizedAutomaton(x));
631
| 1 2 3
632
--------------
633
a | 1 3
634
b | 3 1
635
Initial state: [ 1 ]
636
Accepting states: [ 3, 1 ]
637
]]></Example>
638
</Description> </ManSection>
639
640
<ManSection>
641
<Func Name="UnionAutomata" Arg="A,B"/>
642
<Description>
643
Produces the disjoint union of the deterministic or non deterministic automata <C>A</C> and <C>B</C>. The output is a non-deterministic automaton.
644
<Example><![CDATA[
645
gap> x:=Automaton("det",3,2,[ [ 1, 2, 0 ], [ 0, 1, 2 ] ],[ 2 ],[ 1, 2 ]);;
646
gap> y:=Automaton("det",3,2,[ [ 0, 1, 3 ], [ 0, 0, 0 ] ],[ 1 ],[ 1, 2, 3 ]);;
647
gap> UnionAutomata(x,y);
648
< non deterministic automaton on 2 letters with 6 states >
649
gap> Display(last);
650
| 1 2 3 4 5 6
651
------------------------------------------------
652
a | [ 1 ] [ 2 ] [ 4 ] [ 6 ]
653
b | [ 1 ] [ 2 ]
654
Initial states: [ 2, 4 ]
655
Accepting states: [ 1, 2, 4, 5, 6 ]
656
]]></Example>
657
</Description> </ManSection>
658
659
<ManSection>
660
<Func Name="ProductAutomaton" Arg="A1,A2"/>
661
<Description>
662
The arguments must be deterministic automata. Returns the product of <A>A1</A> and <A>A2</A>.
663
<P/>
664
Note: <M>(p,q)->(p-1)m+q</M> is a bijection from <M>\{1,\ldots, n\}\times \{1,\ldots, m\}</M> to <M>\{1,\ldots,mn\}</M>.
665
<Example><![CDATA[
666
gap> x:=RandomAutomaton("det",3,2);;Display(x);
667
| 1 2 3
668
--------------
669
a | 2 3
670
b | 1
671
Initial state: [ 3 ]
672
Accepting states: [ 1, 2, 3 ]
673
gap> y:=RandomAutomaton("det",3,2);;Display(y);
674
| 1 2 3
675
--------------
676
a | 1
677
b | 1 3
678
Initial state: [ 3 ]
679
Accepting states: [ 1, 3 ]
680
gap> z:=ProductAutomaton(x, y);;Display(z);
681
| 1 2 3 4 5 6 7 8 9
682
--------------------------------
683
a | 4 7
684
b | 1 3
685
Initial state: [ 9 ]
686
Accepting states: [ 1, 3, 4, 6, 7, 9 ]
687
]]></Example>
688
</Description>
689
</ManSection>
690
691
692
<ManSection>
693
<Func Name="ProductOfLanguages" Arg="A1,A2"/>
694
<Description>
695
Given two regular languages (as automata or rational expressions),
696
returns an automaton that recognizes the concatenation of the given
697
languages, that is, the set of words <M>uv</M> such that
698
<M>u</M> belongs to the first language and <M>v</M>
699
belongs to the second language.
700
<Example><![CDATA[
701
gap> a1:=ListOfWordsToAutomaton("ab",["aa","bb"]);
702
< deterministic automaton on 2 letters with 5 states >
703
gap> a2:=ListOfWordsToAutomaton("ab",["a","b"]);
704
< deterministic automaton on 2 letters with 3 states >
705
gap> ProductOfLanguages(a1,a2);
706
< deterministic automaton on 2 letters with 5 states >
707
gap> FAtoRatExp(last);
708
(bbUaa)(aUb)
709
]]></Example>
710
</Description>
711
</ManSection>
712
713
714
</Section>
715
<Section><Heading>Links with Semigroups</Heading>
716
717
Each letter of the alphabet of an automaton induces a partial transformation in its set of
718
states. The semigroup generated by these transformations is
719
called the <E>transition semigroup</E> of the automaton.
720
721
<ManSection>
722
<Func Name="TransitionSemigroup" Arg="aut"/>
723
<Description>
724
725
Returns the transition semigroup of the deterministic automaton <A>aut</A>.
726
<Example><![CDATA[
727
gap> aut := Automaton("det",10,2,[[7,5,7,5,4,9,10,9,10,9],
728
> [8,6,8,9,9,1,3,1,9,9]],[2],[6,7,8,9,10]);;
729
gap> s := TransitionSemigroup(aut);;
730
gap> Size(s);
731
30
732
]]></Example>
733
734
The transition semigroup of the minimal automaton recognizing a language is
735
the {\it syntactic semigroup} of that language.
736
737
</Description> </ManSection>
738
<ManSection>
739
<Func Name="SyntacticSemigroupAut" Arg="aut"/>
740
<Description>
741
742
Returns the syntactic semigroup of the deterministic automaton <A>aut</A> (i.e. the transition semigroup of the equivalent minimal automaton)
743
when it is non empty and returns <K>fail</K> otherwise.
744
<Example><![CDATA[
745
gap> x:=Automaton("det",3,2,[ [ 1, 2, 0 ], [ 0, 1, 2 ] ],[ 2 ],[ 1, 2 ]);;
746
gap> S:=SyntacticSemigroupAut(x);;
747
gap> Size(S);
748
3
749
]]></Example>
750
</Description> </ManSection>
751
<ManSection>
752
<Func Name="SyntacticSemigroupLang" Arg="rat"/>
753
<Description>
754
Returns the syntactic semigroup of the language given by the rational expression <A>rat</A>.
755
<Example><![CDATA[
756
gap> rat := RationalExpression("a*ba*ba*(@Ub)");;
757
gap> S:=SyntacticSemigroupLang(rat);;
758
gap> Size(S);
759
7
760
]]></Example>
761
</Description> </ManSection>
762
</Section>
763
</Chapter>
764
765
766
767