-
Notifications
You must be signed in to change notification settings - Fork 5
/
lecture_automata_products.py
executable file
·66 lines (48 loc) · 1.31 KB
/
lecture_automata_products.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
from nfa import NFA
NFA.clear() # clean visu.pdf on each run
# NFA.NOVISU=True # check that all runs without generating PDFs
A = NFA.spec("""
0
2
0 a 1 a 2
1 a 0 b 2
""",name="A").visu()
A.run("aaab")
B = NFA.spec("""
0
0
0 c 1 a 0
1 c 0""", name="B").visu()
NFA.visutext("DETERMINISATION")
A.visu().dfa().visu(doublearrows=True)
NFA.visutext("PRODUCTS")
from itertools import product
A.visu(); B.visu()
(A & B).visu().dfa().visu().mini().visu()
(A | B).visu().dfa().visu().mini().visu().renum().visu()
NFA.visutext("COMPLETE")
Σ="abc"
OA, OB = A, B
A = A.complete(Σ).visu()
B = B.complete(Σ).visu()
NFA.visutext("UNION THROUGH PRODUCT OF COMPLETE")
U = ( A & B ).named("A ∪(prod) B")
U.F = set(product(A.F,B.Q)) | set(product(A.Q,B.F))
U = U.visu().trim().visu().dfa().visu().mini().visu().renum().visu()
# U.run("cc")
AUB = (A | B).mini().renum().visu()
NFA.visutext(U.iso(AUB))
NFA.visutext("SHUFFLE: UNSYNCHRONISED PRODUCT")
A, B = OA, OB
Shu = A.visu() @ B.visu()
Shu.visu().mini().visu()
S = NFA.of_word("abc").visu() @ NFA.of_word("ABC").visu()
S.visu()
(-S).visu()
S = NFA.of_word("a") @ NFA.of_word("ABC")
S.visu()
S = NFA.of_word("abc") @ NFA.of_word("abc")
S.visu().mini().visu()
S = NFA.of_word("abc") @ NFA.of_word("abc") @ NFA.of_word("abc")
S.renum().visu().mini().visu()