In [1]:
F = (
(set(['A']), set(['D'])),
(set(['A','B']), set(['E'])),
(set(['B','I']), set(['E'])),
(set(['C','D']), set(['I'])),
(set(['E']), set(['C'])),
)
$$AE^+$$
In [2]:
res = set(['A','E'])
mark = [0] * len(F)
while 1:
pre_visted = sum(mark)
for i in range(len(F)):
if mark[i] == 0: # not visited
if F[i][0].issubset(res):
res = res.union(F[i][1])
print(res)
mark[i] = 1
after_visted = sum(mark)
if pre_visted == after_visted:
break
{'A', 'E', 'D'} {'C', 'A', 'E', 'D'} {'I', 'C', 'A', 'E', 'D'}
In [3]:
F = (
(set(['A','B']), set(['C'])),
(set(['B']), set(['D'])),
(set(['C','D']), set(['E'])),
(set(['C','E']), set(['G','H'])),
(set(['G']), set(['A'])),
)
$$F\mid= AB\rightarrow G$$
In [4]:
res = set(['A','B'])
mark = [0] * len(F)
while 1:
pre_visted = sum(mark)
for i in range(len(F)):
if mark[i] == 0: # not visited
if F[i][0].issubset(res):
res = res.union(F[i][1])
print(res)
mark[i] = 1
after_visted = sum(mark)
if pre_visted == after_visted:
break
'G' in res
{'B', 'C', 'A'} {'B', 'C', 'A', 'D'} {'B', 'C', 'A', 'E', 'D'} {'H', 'G', 'B', 'C', 'A', 'E', 'D'} {'H', 'G', 'B', 'C', 'A', 'E', 'D'}
Out[4]:
True