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
2 Finite Automata
3
4
This chapter describes the representations used in this package for finite
5
automata and some functions to determine information about them.
6
7
We have to remark that the states of an automaton are always named
8
1,2,3,...; the alphabet may be given by the user. By default it is
9
{a,b,c,...} (or {a_1,a_2,a_3,...} in the case of alphabets with more than 26
10
letters).
11
12
The transition function of an automaton with q states over an alphabet with
13
n letters is represented by a (not necessarily dense) n× q matrix. Each row
14
of the matrix describes the action of the corresponding letter on the
15
states. In the case of a deterministic automaton (DFA) the entries of the
16
matrix are non-negative integers. When all entries of the transition table
17
are positive integers, the automaton is said to be dense or complete. In the
18
case of a non deterministic automaton (NFA) the entries of the matrix may be
19
lists of non-negative integers. Automata with ϵ-transitions are also
20
allowed: the last letter of the alphabet is assumed to be ϵ and is
21
represented by @.
22
23
24
2.1 Automata generation
25
26
The way to create an automaton in GAP is the following
27
28
2.1-1 Automaton
29
30
Automaton( Type, Size, Alphabet, TransitionTable, Initial, Accepting )  function
31
32
Type may be "det", "nondet" or "epsilon" according to whether the automaton
33
is deterministic, non deterministic or an automaton with ϵ-transitions. Size
34
is a positive integer representing the number of states of the automaton.
35
Alphabet is the number of letters of the alphabet or a list with the letters
36
of the ordered alphabet. TransitionTable is the transition matrix. The
37
entries are non-negative integers not greater than the size of the
38
automaton. In the case of non deterministic automata, lists of non-negative
39
integers not greater than the size of the automaton are also allowed.
40
Initial and Accepting are, respectively, the lists of initial and accepting
41
states.
42
43
 Example 
44

45
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,4]],[1],[4]);
46
< deterministic automaton on 2 letters with 4 states >
47
gap> Display(aut);
48
 | 1 2 3 4
49
-----------------
50
 a | 3 3 4
51
 b | 3 4 4
52
Initial state: [ 1 ]
53
Accepting state: [ 4 ]
54

55

56
57
The alphabet of the automaton may be specified:
58
59
 Example 
60
gap> aut:=Automaton("det",4,"01",[[3,,3,4],[3,4,0,4]],[1],[4]);
61
< deterministic automaton on 2 letters with 4 states >
62
gap> Display(aut);
63
 | 1 2 3 4
64
-----------------
65
 0 | 3 3 4
66
 1 | 3 4 4
67
Initial state: [ 1 ]
68
Accepting state: [ 4 ]
69

70
71
Instead of leaving a hole in the transition matrix, we may write a 0 to mean
72
that no transition is present. Non deterministic automata may be given the
73
same way.
74
75
 Example 
76
gap> ndaut:=Automaton("nondet",4,2,[[3,[1,2],3,0],[3,4,0,[2,3]]],[1],[4]);
77
< non deterministic automaton on 2 letters with 4 states >
78
gap> Display(ndaut);
79
 | 1 2 3 4
80
-----------------------------------------
81
 a | [ 3 ] [ 1, 2 ] [ 3 ]
82
 b | [ 3 ] [ 4 ] [ 2, 3 ]
83
Initial state: [ 1 ]
84
Accepting state: [ 4 ]
85

86
87
Also in the same way can be given ϵ-automata. The letter ϵ is written @
88
instead.
89
90
 Example 
91
gap> x:=Automaton("epsilon",3,"01@",[[,[2],[3]],[[1,3],,[1]],[[1],[2],
92
> [2]]],[2],[2,3]);
93
< epsilon automaton on 3 letters with 3 states >
94
gap> Display(x);
95
 | 1 2 3
96
------------------------------
97
 0 | [ 2 ] [ 3 ]
98
 1 | [ 1, 3 ] [ 1 ]
99
 @ | [ 1 ] [ 2 ] [ 2 ]
100
Initial state: [ 2 ]
101
Accepting states: [ 2, 3 ]
102

103
104
Bigger automata are displayed in another form:
105
106
 Example 
107
gap> aut:=Automaton("det",16,2,[[4,0,0,6,3,1,4,8,7,4,3,0,6,1,6,0],
108
> [3,4,0,0,6,1,0,6,1,6,1,6,6,4,8,7,4,5]],[1],[4]);
109
< deterministic automaton on 2 letters with 16 states >
110
gap> Display(aut);
111
1 a 4
112
1 b 3
113
2 b 4
114
 ... some more lines
115
15 a 6
116
15 b 8
117
16 b 7
118
Initial state: [ 1 ]
119
Accepting state: [ 4 ]
120

121
122
2.1-2 IsAutomaton
123
124
IsAutomaton( O )  function
125
126
In the presence of an object O, one may want to test whether O is an
127
automaton. This may be done using the function IsAutomaton.
128
129
 Example 
130
gap> x:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;
131
gap> IsAutomaton(x);
132
true
133

134
135
2.1-3 IsDeterministicAutomaton
136
137
IsDeterministicAutomaton( aut )  function
138
139
Returns true when aut is a deterministic automaton and false otherwise.
140
141
 Example 
142
gap> x:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;
143
gap> IsDeterministicAutomaton(x);
144
true
145

146
147
2.1-4 IsNonDeterministicAutomaton
148
149
IsNonDeterministicAutomaton( aut )  function
150
151
Returns true when aut is a non deterministic automaton and false otherwise.
152
153
 Example 
154
gap> y:=Automaton("nondet",3,2,[[,[1,3],],[,[2,3],[1,3]]],[1,2],[1,3]);;
155
gap> IsNonDeterministicAutomaton(y);
156
true
157

158
159
2.1-5 IsEpsilonAutomaton
160
161
IsEpsilonAutomaton( aut )  function
162
163
Returns true when aut is an ϵ-automaton and false otherwise.
164
165
 Example 
166
gap> z:=Automaton("epsilon",2,2,[[[1,2],],[[2],[1]]],[1,2],[1,2]);;
167
gap> IsEpsilonAutomaton(z);
168
true
169

170
171
2.1-6 String
172
173
String( aut )  function
174
175
The way GAP displays an automaton is quite natural, but when one wants to do
176
small changes, for example using copy/paste, the use of the function String
177
(possibly followed by Print) may be usefull.
178
179
 Example 
180
gap> x:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;
181
gap> String(x);
182
"Automaton(\"det\",3,\"ab\",[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;"
183
gap> Print(String(x));
184
Automaton("det",3,"ab",[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;
185

186
187
 Example 
188
gap> z:=Automaton("epsilon",2,2,[[[1,2],],[[2],[1]]],[1,2],[1,2]);;
189
gap> Print(String(z));
190
Automaton("epsilon",2,"a@",[ [ [ 1, 2 ], [ ] ], [ [ 2 ], [ 1 ] ] ],[ 1, 2 ],[ \
191
1, 2 ]);;
192

193
194
2.1-7 RandomAutomaton
195
196
RandomAutomaton( Type, Size, Alphabet )  function
197
198
Given the Type, the Size (i.e. the number of states) and the Alphabet (a
199
positive integer or a list), returns a pseudo random automaton with these
200
parameters.
201
202
 Example 
203
gap> RandomAutomaton("det",5,"ac");
204
< deterministic automaton on 2 letters with 5 states >
205
gap> Display(last);
206
 | 1 2 3 4 5
207
--------------------
208
 a | 2 3
209
 c | 2 3
210
Initial state: [ 4 ]
211
Accepting states: [ 3, 4 ]
212

213
gap> RandomAutomaton("nondet",3,["a","b","c"]);
214
< non deterministic automaton on 3 letters with 3 states >
215

216
gap> RandomAutomaton("epsilon",2,"abc");
217
< epsilon automaton on 4 letters with 2 states >
218

219
gap> RandomAutomaton("epsilon",2,2);
220
< epsilon automaton on 3 letters with 2 states >
221
gap> Display(last);
222
 | 1 2
223
----------------------
224
 a | [ 1, 2 ]
225
 b | [ 2 ] [ 1 ]
226
 @ | [ 1, 2 ]
227
Initial state: [ 2 ]
228
Accepting states: [ 1, 2 ]
229

230
gap> a:=RandomTransformation(3);;
231
gap> b:=RandomTransformation(3);;
232
gap> aut:=RandomAutomaton("det",4,[a,b]);
233
< deterministic automaton on 2 letters with 4 states >
234

235
236
237
2.2 Automata internals
238
239
In this section we describe the functions used to access the internals of an
240
automaton.
241
242
2.2-1 AlphabetOfAutomaton
243
244
AlphabetOfAutomaton( aut )  function
245
246
Returns the number of symbols in the alphabet of automaton aut.
247
248
 Example 
249
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
250
gap> AlphabetOfAutomaton(aut);
251
2
252

253
254
2.2-2 AlphabetOfAutomatonAsList
255
256
AlphabetOfAutomatonAsList( aut )  function
257
258
Returns the alphabet of automaton aut always as a list. Note that when the
259
alphabet of the automaton is given as an integer (meaning the number of
260
symbols) not greater than 26 it returns the list "abcd....". If the alphabet
261
is given by means of an integer greater than 26, the function returns [
262
"a1", "a2", "a3", "a4", ... ].
263
264
 Example 
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

286
287
2.2-3 TransitionMatrixOfAutomaton
288
289
TransitionMatrixOfAutomaton( aut )  function
290
291
Returns the transition matrix of automaton aut.
292
293
 Example 
294
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
295
gap> TransitionMatrixOfAutomaton(aut);
296
[ [ 3, 0, 3, 4 ], [ 3, 4, 0, 0 ] ]
297

298
299
2.2-4 InitialStatesOfAutomaton
300
301
InitialStatesOfAutomaton( aut )  function
302
303
Returns the initial states of automaton aut.
304
305
 Example 
306
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
307
gap> InitialStatesOfAutomaton(aut);
308
[ 1 ]
309

310
311
2.2-5 SetInitialStatesOfAutomaton
312
313
SetInitialStatesOfAutomaton( aut, I )  function
314
315
Sets the initial states of automaton aut. I may be a positive integer or a
316
list of positive integers.
317
318
 Example 
319
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
320
gap> SetInitialStatesOfAutomaton(aut,4);
321
gap> InitialStatesOfAutomaton(aut);
322
[ 4 ]
323
gap> SetInitialStatesOfAutomaton(aut,[2,3]);
324
gap> InitialStatesOfAutomaton(aut);
325
[ 2, 3 ]
326

327
328
2.2-6 FinalStatesOfAutomaton
329
330
FinalStatesOfAutomaton( aut )  function
331
332
Returns the final states of automaton aut.
333
334
 Example 
335
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
336
gap> FinalStatesOfAutomaton(aut);
337
[ 4 ]
338

339
340
2.2-7 SetFinalStatesOfAutomaton
341
342
SetFinalStatesOfAutomaton( aut, F )  function
343
344
Sets the final states of automaton aut. F may be a positive integer or a
345
list of positive integers.
346
347
 Example 
348
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
349
gap> FinalStatesOfAutomaton(aut);
350
[ 4 ]
351
gap> SetFinalStatesOfAutomaton(aut,2);
352
gap> FinalStatesOfAutomaton(aut);
353
[ 2 ]
354

355
356
2.2-8 NumberStatesOfAutomaton
357
358
NumberStatesOfAutomaton( aut )  function
359
360
Returns the number of states of automaton aut.
361
362
 Example 
363
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
364
gap> NumberStatesOfAutomaton(aut);
365
4
366

367
368
369
2.3 Comparison of automata
370
371
Although there is no standard way to compare automata it is usefull to be
372
able to do some kind of comparison. Doing so, one can consider sets of
373
automata. We just compare the strings of the automata.
374
375
 Example 
376
gap> x:=Automaton("det",3,2,[ [ 0, 2, 0 ], [ 0, 1, 0 ] ],[ 3 ],[ 2 ]);;
377
gap> y:=Automaton("det",3,2,[ [ 2, 0, 0 ], [ 1, 3, 0 ] ],[ 3 ],[ 2, 3 ]);;
378
gap> x=y;
379
false
380
gap> Size(Set([y,x,x]));
381
2
382

383
384
385
2.4 Tests involving automata
386
387
This section describes some useful tests involving automata.
388
389
2.4-1 IsDenseAutomaton
390
391
IsDenseAutomaton( aut )  function
392
393
Tests whether a deterministic automaton aut is complete. (See also
394
NullCompletionAutomaton (2.5-2).)
395
396
 Example 
397
gap> aut:=Automaton("det",4,2,[[3,,3,4],[3,4,0,]],[1],[4]);;
398
gap> IsDenseAutomaton(aut); 
399
false
400

401
402
2.4-2 IsRecognizedByAutomaton
403
404
IsRecognizedByAutomaton( A, w )  function
405
406
The arguments are: an automaton A and a string (i.e. a word) w in the
407
alphabet of the automaton. Returns true if the word is recognized by the
408
automaton and false otherwise.
409
410
 Example 
411
gap> aut:=Automaton("det",3,2,[[1,2,1],[2,1,3]],[1],[2]);;
412
gap> IsRecognizedByAutomaton(aut,"bbb");
413
true
414

415
gap> aut:=Automaton("det",3,"01",[[1,2,1],[2,1,3]],[1],[2]);;
416
gap> IsRecognizedByAutomaton(aut,"111");
417
true
418

419
420
2.4-3 IsPermutationAutomaton
421
422
IsPermutationAutomaton( aut )  function
423
424
The argument is a deterministic automaton. Returns true when each letter of
425
the alphabet induces a permutation on the vertices and false otherwise.
426
427
 Example 
428
gap> x:=Automaton("det",3,2,[ [ 1, 2, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2, 3 ]);;
429
gap> IsPermutationAutomaton(x);
430
true
431

432
433
2.4-4 IsInverseAutomaton
434
435
IsInverseAutomaton( aut )  function
436
437
The argument is a deterministic automaton. Returns true when each letter of
438
the alphabet induces an injective partial function on the vertices and false
439
otherwise.
440
441
 Example 
442
gap> x:=Automaton("det",3,2,[ [ 0, 1, 3 ], [ 0, 1, 2 ] ],[ 2 ],[ 1 ]);;
443
gap> IsInverseAutomaton(x);
444
true
445

446
447
Frequently an inverse automaton is thought as if the inverse edges (labeled
448
by formal inverses of the letters of the alphabet) were present, although
449
they are usually not explicited. They can be made explicit using the
450
function AddInverseEdgesToInverseAutomaton
451
452
2.4-5 AddInverseEdgesToInverseAutomaton
453
454
AddInverseEdgesToInverseAutomaton( aut )  function
455
456
The argument is an inverse automaton over the alphabet {a,b,c,...}. Returns
457
an automaton with the inverse edges added. (The formal inverse of a letter
458
is represented by the corresponding capital letter.)
459
460
 Example 
461
gap> x:=Automaton("det",3,2,[[ 0, 1, 3 ],[ 0, 1, 2 ]],[ 2 ],[ 1 ]);;Display(x);
462
 | 1 2 3
463
--------------
464
 a | 1 3
465
 b | 1 2
466
Initial state: [ 2 ]
467
Accepting state: [ 1 ]
468
gap> AddInverseEdgesToInverseAutomaton(x);Display(x);
469
 | 1 2 3
470
--------------
471
 a | 1 3
472
 b | 1 2
473
 A | 2 3
474
 B | 2 3
475
Initial state: [ 2 ]
476
Accepting state: [ 1 ]
477

478
479
2.4-6 IsReversibleAutomaton
480
481
IsReversibleAutomaton( aut )  function
482
483
The argument is a deterministic automaton. Returns true when aut is a
484
reversible automaton, i.e. the automaton obtained by reversing all edges and
485
switching the initial and final states (see also ReversedAutomaton (2.5-5))
486
is deterministic. Returns false otherwise.
487
488
 Example 
489
gap> x:=Automaton("det",3,2,[ [ 0, 1, 2 ], [ 0, 1, 3 ] ],[ 2 ],[ 2 ]);;
490
gap> IsReversibleAutomaton(x);
491
true
492

493
494
495
2.5 Basic operations
496
497
2.5-1 CopyAutomaton
498
499
CopyAutomaton( aut )  function
500
501
Returns a new automaton, which is a copy of automaton aut.
502
503
2.5-2 NullCompletionAutomaton
504
505
NullCompletionAutomaton( aut )  function
506
507
aut is a deterministic automaton. If it is complete returns aut, otherwise
508
returns the completion (with a null state) of aut. Notice that the words
509
recognized by aut and its completion are the same.
510
511
 Example 
512
gap> aut:=Automaton("det",4,2,[[3,,3,4],[2,4,4,]],[1],[4]);;
513
gap> IsDenseAutomaton(aut);
514
false
515
gap> y:=NullCompletionAutomaton(aut);;Display(y);
516
 | 1 2 3 4 5
517
--------------------
518
 a | 3 5 3 4 5
519
 b | 2 4 4 5 5
520
Initial state: [ 1 ]
521
Accepting state: [ 4 ]
522

523
524
The state added is a sink state i.e. it is a state q which is not initial
525
nor accepting and for all letter a in the alphabet of the automaton, q is
526
the result of the action of a in q. (Notice that reading a word, one does
527
not go out of a sink state.)
528
529
2.5-3 ListSinkStatesAut
530
531
ListSinkStatesAut( aut )  function
532
533
Computes the list of all sink states of the automaton aut.
534
535
 Example 
536
gap> x:=Automaton("det",3,2,[ [ 2, 3, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2, 3 ]);;
537
gap> ListSinkStatesAut(x);
538
[ ]
539
gap> y:=Automaton("det",3,2,[ [ 2, 3, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2 ]);;
540
gap> ListSinkStatesAut(y);
541
[ 3 ]
542

543
544
2.5-4 RemovedSinkStates
545
546
RemovedSinkStates( aut )  function
547
548
Removes all sink states of the automaton aut.
549
550
 Example 
551
gap> y:=Automaton("det",3,2,[[ 2, 3, 3 ],[ 1, 2, 3 ]],[ 1 ],[ 2 ]);;Display(y);
552
 | 1 2 3
553
--------------
554
 a | 2 3 3
555
 b | 1 2 3
556
Initial state: [ 1 ]
557
Accepting state: [ 2 ]
558
gap> x := RemovedSinkStates(y);Display(x);
559
< deterministic automaton on 2 letters with 2 states >
560
 | 1 2
561
-----------
562
 a | 2
563
 b | 1 2
564
Initial state: [ 1 ]
565
Accepting state: [ 2 ]
566

567
568
2.5-5 ReversedAutomaton
569
570
ReversedAutomaton( aut )  function
571
572
Inverts the arrows of the automaton aut.
573
574
 Example 
575
gap> y:=Automaton("det",3,2,[ [ 2, 3, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2 ]);;
576
gap> z:=ReversedAutomaton(y);;Display(z);
577
 | 1 2 3
578
------------------------------
579
 a | [ 1 ] [ 2, 3 ]
580
 b | [ 1 ] [ 2 ] [ 3 ]
581
Initial state: [ 2 ]
582
Accepting state: [ 1 ]
583

584
585
2.5-6 PermutedAutomaton
586
587
PermutedAutomaton( aut, p )  function
588
589
Given an automaton aut and a list p representing a permutation of the
590
states, outputs the equivalent permuted automaton.
591
592
 Example 
593
gap> y:=Automaton("det",4,2,[[2,3,4,2],[0,0,0,1]],[1],[3]);;Display(y);
594
 | 1 2 3 4
595
-----------------
596
 a | 2 3 4 2
597
 b | 1
598
Initial state: [ 1 ]
599
Accepting state: [ 3 ]
600
gap> Display(PermutedAutomaton(y, [3,2,4,1]));
601
 | 1 2 3 4
602
-----------------
603
 a | 2 4 2 1
604
 b | 3
605
Initial state: [ 3 ]
606
Accepting state: [ 4 ]
607

608
609
2.5-7 ListPermutedAutomata
610
611
ListPermutedAutomata( aut )  function
612
613
Given an automaton aut, returns a list of automata with permuted states
614
615
 Example 
616
gap> x:=Automaton("det",3,2,[ [ 0, 2, 3 ], [ 1, 2, 3 ] ],[ 1 ],[ 2, 3 ]);;
617
gap> ListPermutedAutomata(x);
618
[ < deterministic automaton on 2 letters with 3 states >, 
619
 < deterministic automaton on 2 letters with 3 states >, 
620
 < deterministic automaton on 2 letters with 3 states >, 
621
 < deterministic automaton on 2 letters with 3 states >, 
622
 < deterministic automaton on 2 letters with 3 states >, 
623
 < deterministic automaton on 2 letters with 3 states > ]
624

625
626
2.5-8 NormalizedAutomaton
627
628
NormalizedAutomaton( A )  function
629
630
Produces an equivalent automaton but in which the initial state is numbered
631
1 and the accepting states have the greatest numbers.
632
633
 Example 
634
gap> x:=Automaton("det",3,2,[[ 1, 2, 0 ],[ 0, 1, 2 ]],[2],[1, 2]);;Display(x);
635
 | 1 2 3
636
--------------
637
 a | 1 2
638
 b | 1 2
639
Initial state: [ 2 ]
640
Accepting states: [ 1, 2 ]
641
gap> Display(NormalizedAutomaton(x));
642
 | 1 2 3
643
--------------
644
 a | 1 3
645
 b | 3 1
646
Initial state: [ 1 ]
647
Accepting states: [ 3, 1 ]
648

649
650
2.5-9 UnionAutomata
651
652
UnionAutomata( A, B )  function
653
654
Produces the disjoint union of the deterministic or non deterministic
655
automata A and B. The output is a non-deterministic automaton.
656
657
 Example 
658
gap> x:=Automaton("det",3,2,[ [ 1, 2, 0 ], [ 0, 1, 2 ] ],[ 2 ],[ 1, 2 ]);;
659
gap> y:=Automaton("det",3,2,[ [ 0, 1, 3 ], [ 0, 0, 0 ] ],[ 1 ],[ 1, 2, 3 ]);;
660
gap> UnionAutomata(x,y);
661
< non deterministic automaton on 2 letters with 6 states >
662
gap> Display(last);
663
 | 1 2 3 4 5 6
664
------------------------------------------------
665
 a | [ 1 ] [ 2 ] [ 4 ] [ 6 ]
666
 b | [ 1 ] [ 2 ]
667
Initial states: [ 2, 4 ]
668
Accepting states: [ 1, 2, 4, 5, 6 ]
669

670
671
2.5-10 ProductAutomaton
672
673
ProductAutomaton( A1, A2 )  function
674
675
The arguments must be deterministic automata. Returns the product of A1 and
676
A2.
677
678
Note: (p,q)->(p-1)m+q is a bijection from {1,..., n}× {1,..., m} to
679
{1,...,mn}.
680
681
 Example 
682
gap> x:=RandomAutomaton("det",3,2);;Display(x);
683
 | 1 2 3
684
--------------
685
 a | 2 3
686
 b | 1
687
Initial state: [ 3 ]
688
Accepting states: [ 1, 2, 3 ]
689
gap> y:=RandomAutomaton("det",3,2);;Display(y);
690
 | 1 2 3
691
--------------
692
 a | 1
693
 b | 1 3
694
Initial state: [ 3 ]
695
Accepting states: [ 1, 3 ]
696
gap> z:=ProductAutomaton(x, y);;Display(z);
697
 | 1 2 3 4 5 6 7 8 9
698
--------------------------------
699
 a | 4 7
700
 b | 1 3
701
Initial state: [ 9 ]
702
Accepting states: [ 1, 3, 4, 6, 7, 9 ]
703

704
705
2.5-11 ProductOfLanguages
706
707
ProductOfLanguages( A1, A2 )  function
708
709
Given two regular languages (as automata or rational expressions), returns
710
an automaton that recognizes the concatenation of the given languages, that
711
is, the set of words uv such that u belongs to the first language and v
712
belongs to the second language.
713
714
 Example 
715
gap> a1:=ListOfWordsToAutomaton("ab",["aa","bb"]);
716
< deterministic automaton on 2 letters with 5 states >
717
gap> a2:=ListOfWordsToAutomaton("ab",["a","b"]);
718
< deterministic automaton on 2 letters with 3 states >
719
gap> ProductOfLanguages(a1,a2);
720
< deterministic automaton on 2 letters with 5 states >
721
gap> FAtoRatExp(last);
722
(bbUaa)(aUb)
723

724
725
726
2.6 Links with Semigroups
727
728
Each letter of the alphabet of an automaton induces a partial transformation
729
in its set of states. The semigroup generated by these transformations is
730
called the transition semigroup of the automaton.
731
732
2.6-1 TransitionSemigroup
733
734
TransitionSemigroup( aut )  function
735
736
Returns the transition semigroup of the deterministic automaton aut.
737
738
 Example 
739
gap> aut := Automaton("det",10,2,[[7,5,7,5,4,9,10,9,10,9],
740
> [8,6,8,9,9,1,3,1,9,9]],[2],[6,7,8,9,10]);;
741
gap> s := TransitionSemigroup(aut);; 
742
gap> Size(s); 
743
30
744

745
746
The transition semigroup of the minimal automaton recognizing a language is
747
the {\it syntactic semigroup} of that language.
748
749
2.6-2 SyntacticSemigroupAut
750
751
SyntacticSemigroupAut( aut )  function
752
753
Returns the syntactic semigroup of the deterministic automaton aut (i.e. the
754
transition semigroup of the equivalent minimal automaton) when it is non
755
empty and returns fail otherwise.
756
757
 Example 
758
gap> x:=Automaton("det",3,2,[ [ 1, 2, 0 ], [ 0, 1, 2 ] ],[ 2 ],[ 1, 2 ]);;
759
gap> S:=SyntacticSemigroupAut(x);;
760
gap> Size(S);
761
3
762

763
764
2.6-3 SyntacticSemigroupLang
765
766
SyntacticSemigroupLang( rat )  function
767
768
Returns the syntactic semigroup of the language given by the rational
769
expression rat.
770
771
 Example 
772
gap> rat := RationalExpression("a*ba*ba*(@Ub)");;
773
gap> S:=SyntacticSemigroupLang(rat);;
774
gap> Size(S);
775
7
776

777
778
779