-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.py
54 lines (52 loc) · 1.32 KB
/
demo.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
import DFA
#5 / 10 8 7 3
#Basics:
states = range(5)
states = range(5)
start = 0
accepts = [0]
alphabet = ['0','1']
def delta(state, char):
char = int(char)
if char == 0:
return state * 2 % 5
return (state*2+1)%5
d = DFA.DFA(states=states, start=start, accepts=accepts, alphabet=alphabet, delta=delta)
print "Given a binary input, d accepts if the number represented is divisible by 5 (plus the empty string):"
d.pretty_print()
#raw_input()
print 'd.input_sequence("1110101011101") #7517'
d.input_sequence("1110101011101") #7517
print "Current state:", d.current_state
print "Accepting:", d.status()
#raw_input()
print "Resetting..."
d.reset()
print d.current_state
d.input_sequence("10011011101") #1245
print d.current_state
print d.status()
#Various minimizations
a = ['1', '11', '111', '1111', '11110', '11111', '111111', '111110']
b = ['0', '1']
e = DFA.from_word_list(a,b)
print "a = ['1', '11', '111', '1111', '11110', '11111', '111111', '111110']"
print "b = ['0', '1']"
print "e = DFA.from_word_list(a,b)"
print "..."
#raw_input()
print "===The starting DFA==="
e.pretty_print()
#raw_input()
print "==Minimized==="
e.minimize()
e.pretty_print()
#raw_input()
print "==...then DFCA-Minimized==="
e.DFCA_minimize()
e.pretty_print()
#raw_input()
print "==...then Finite-Difference Minimized==="
e.hyper_minimize()
e.pretty_print()
#raw_input()