-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsols.py
249 lines (221 loc) · 10.9 KB
/
sols.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
__author__ = 'marcincuber'
# -*- coding: utf-8 -*-
'''
:psi is our parsed formula in tableaux format
:for each formula in the list deal with all alphas formulas
:return a list which does not contain any alpas to deal with
'''
def recursivealpha(psi):
#define constants and modalities
parsed_constants = ['or', 'and', 'imply', 'not']
parsed_modalities = ['diamond', 'box']
#deal with formulas which have AND in the first position
#scan formulas recursiverly until all formulas are dealt with
if psi[0] == 'and':
psi1_set = [psi[1]]
if psi[1][0] in parsed_constants or psi[1][0] in parsed_modalities:
psi1_set = recursivealpha(psi[1])
psi2_set = [psi[2]]
if psi[2][0] in parsed_constants or psi[2][0] in parsed_modalities:
psi2_set = recursivealpha(psi[2])
return psi1_set + psi2_set
#deal with formulas which contain double negations
elif psi[0] == 'not' and isinstance(psi[1], tuple) and psi[1][0] == 'not':
result = [psi[1][1]]
if psi[1][1][0] in parsed_constants or psi[1][1][0] in parsed_modalities:
result = recursivealpha(psi[1][1])
return result
#deal with formulas with NOT(IMPLY,A,B) in which we return negated B and A
elif psi[0] == 'not' and isinstance(psi[1], tuple) and psi[1][0] == 'imply':
psi1 = (psi[1][1])
psi1_set = [psi1]
if psi[1][1][0] in parsed_constants or psi[1][1][0] in parsed_modalities:
psi1_set = recursivealpha(psi1)
psi2_set = [('not',psi[1][2])]
if isinstance(psi[1][2], str):
psi2_set = [('not',psi[1][2])]
elif psi[1][2][0] in parsed_constants or psi[1][2][0] in parsed_modalities:
psi2_set = recursivealpha(('not',psi[1][2]))
return (psi1_set + psi2_set)
#deal with formulas with NOT(OR,A,B) in which we return negated B and negated A
elif psi[0] == 'not' and isinstance(psi[1], tuple) and psi[1][0] == 'or':
psi1 = ('not', psi[1][1])
psi1_set = ['not',psi[1][1]]
if psi[1][1][0] in parsed_constants or psi[1][1][0] in parsed_modalities:
psi1_set = recursivealpha(psi1)
psi2 = ('not', psi[1][2])
psi2_set = [('not', psi[1][2])]
if psi[1][2][0] in parsed_constants or psi[1][2][0] in parsed_modalities:
psi2_set = recursivealpha(psi2)
return psi1_set + psi2_set
#if there are formulas which are not alphas, just add them to the list
else:
return [psi]
'''
:Function finds and removes inconsistent formulas from the list
'''
def inconsistent(psi):
#initialise status to be false psi meaning that psi is consistent
status = False;
main_list=psi
for i in range(0,len(psi)):
for j in range(0,len(psi[i])):
#we assign each formula from the list to a variable main
main = psi[i]
if isinstance(main, str):
contra = ('not',main)
if (contra in main_list) and (main in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'not' and isinstance(main[1][1],str):
if (main[1] in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'or' and isinstance(main[1][1], tuple) and \
main[1][1][0] == 'not' and isinstance(main[1][1][1],str):
contra = ('not',main[1][1][1])
if (contra in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'or' and isinstance(main[1][2], tuple) and \
main[1][2][0] == 'not' and isinstance(main[1][2][1],str):
contra = ('not',main[1][2][1])
if (contra in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'or' and isinstance(main[1][2],str):
if (main[1][2] in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'or' and isinstance(main[1][2], tuple) and \
main[1][2][0] == 'not' and isinstance(main[1][2][1],str):
contra = ('not',main[1][2][1])
if (contra in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'or' and isinstance(main[1][1], tuple) and \
main[1][1][0] == 'not' and isinstance(main[1][1][1],str):
contra = ('not',main[1][1][1])
if (contra in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'or' and isinstance(main[1][1],str):
if (main[1][1] in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'imply' and isinstance(main[1][1], tuple) and \
main[1][1][0] == 'not' and isinstance(main[1][1][1],str):
print "we are here:"
if (main[1][1][1] in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'imply' and isinstance(main[1][2], tuple) and \
main[1][2][0] == 'not' and isinstance(main[1][2][1],str):
if (main[1][2][1] in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'imply' and isinstance(main[1][2],str):
if (main[1][2] in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'imply' and isinstance(main[1][2], tuple) and \
main[1][2][0] == 'not' and isinstance(main[1][2][1],str):
contra = ('not',main[1][2][1])
if (contra in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'imply' and isinstance(main[1][1], tuple) and \
main[1][1][0] == 'not' and isinstance(main[1][1][1],str):
if (main[1][1][1] in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'imply' and isinstance(main[1][1],str):
contra = ('not', main[1][1])
if (contra in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'or' and isinstance(main[1][1], str):
if (main[1][1] in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'or' and isinstance(main[1][2], str):
if (main[1][2] in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'or' and isinstance(main[1][2], str):
if (main[1][2] in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'or' and isinstance(main[1][1], str):
if (main[1][1] in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'imply' and isinstance(main[1][1], str):
contra = ('not',main[1][1])
if (contra in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'imply' and isinstance(main[1][2], str):
if (main[1][2] in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'imply' and isinstance(main[1][2], str):
if (main[1][2] in main_list):
status = True
break
elif main[0] == 'not' and main[1][0] == 'imply' and isinstance(main[1][1], str):
contra = ('not',main[1][1])
if (contra in main_list):
status = True
break
elif main[0] == 'and' and isinstance(main[1], tuple) and main[1][0] == 'not' and \
isinstance(main[1][1], str):
if (main[1][1] in main_list):
status = True
break
elif main[0] == 'and' and isinstance(main[2], tuple) and main[2][0] == 'not' and \
isinstance(main[2][1], str):
if (main[2][1] in main_list):
status = True
break
elif main[0] == 'and' and isinstance(main[2], str):
contra = ('not',main[2])
if (contra in main_list):
status = True
break
elif main[0] == 'and' and isinstance(main[2], tuple) and main[2][0] == 'not' and \
isinstance(main[2][1], str):
if (main[2][1] in main_list):
status = True
break
elif main[0] == 'and' and isinstance(main[1], tuple) and main[1][0] == 'not' and \
isinstance(main[1][1], str):
if (main[1][1] in main_list):
status = True
break
elif main[0] == 'and' and isinstance(main[1], str):
contra = ('not',main[1])
if (contra in main_list):
status = True
break
elif main[0] == 'and' and isinstance(main[1], str):
contra = ('not',main[1])
if (contra in main_list):
status = True
break
elif main[0] == 'and' and isinstance(main[2], str):
contra = ('not',main[2])
if (contra in main_list):
status = True
break
elif main[0] == 'and' and isinstance(main[2], str):
contra = ('not',main[2])
if (contra in main_list):
status = True
break
elif main[0] == 'and' and isinstance(main[1], str):
contra = ('not',main[1])
if (contra in main_list):
status = True
break
return status