Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 110 lines (74 sloc) 2.623 kb
93f1ab5 @slomo draft for resolution
authored
1 import fofTypes as f
2 from copy import deepcopy
3
4 def is_splittable(form):
5
6 if type(form) == f.BinaryOperand:
7 return True
8
9 if type(form) == f.UnaryOperand and type(form.term) != f.Identifier:
10 return True
11
12 return False
13
14
15 def proof(formula):
16
3843dfa @slomo rewrote resolution to work on sets
authored
17 splittables = set([frozenset([formula])])
18 result = []
93f1ab5 @slomo draft for resolution
authored
19
3843dfa @slomo rewrote resolution to work on sets
authored
20 while len(splittables) > 0:
93f1ab5 @slomo draft for resolution
authored
21
3843dfa @slomo rewrote resolution to work on sets
authored
22 disj = splittables.pop()
93f1ab5 @slomo draft for resolution
authored
23
3843dfa @slomo rewrote resolution to work on sets
authored
24 [ splittables.add(frozenset(x)) for x in split_any(disj) ]
93f1ab5 @slomo draft for resolution
authored
25
3843dfa @slomo rewrote resolution to work on sets
authored
26 result.append(disj)
93f1ab5 @slomo draft for resolution
authored
27
3843dfa @slomo rewrote resolution to work on sets
authored
28 print("splitted formulas", result)
aa19127 @slomo working resolution
authored
29
3843dfa @slomo rewrote resolution to work on sets
authored
30 return resolute(result)
93f1ab5 @slomo draft for resolution
authored
31
32 # returns: <[]>
33 def split_any(disjunction):
34
3843dfa @slomo rewrote resolution to work on sets
authored
35 result_set = []
93f1ab5 @slomo draft for resolution
authored
36
37 for formula in disjunction:
38 if is_splittable(formula):
39
40 if type(formula) == f.UnaryOperand:
41 if type(formula.term) == f.UnaryOperand:
3843dfa @slomo rewrote resolution to work on sets
authored
42 d = list(disjunction)
43 d.remove(formula)
93f1ab5 @slomo draft for resolution
authored
44 d.append(formula.term.term)
45 break
46
47 #alpha
48 if type(formula) == f.BinaryOperand and formula.op == "&":
3843dfa @slomo rewrote resolution to work on sets
authored
49 d = list(disjunction)
93f1ab5 @slomo draft for resolution
authored
50 d.remove(formula)
aa19127 @slomo working resolution
authored
51 d1 = deepcopy(d)
52 d1.append(formula.terms[0])
93f1ab5 @slomo draft for resolution
authored
53 result_set.append(d1)
54
55 d.append(formula.terms[1])
56 result_set.append(d)
57 break
58
59 # is beta
60 if type(formula) == f.BinaryOperand and formula.op == "|":
3843dfa @slomo rewrote resolution to work on sets
authored
61 d = list(disjunction)
93f1ab5 @slomo draft for resolution
authored
62 d.remove(formula)
63 d.append(formula.terms[0])
64 d.append(formula.terms[1])
65 result_set.append(d)
66 break
67
68 return result_set
69
70
aa19127 @slomo working resolution
authored
71 def is_tautology(d):
72
73 for q in d:
74 negate = f.UnaryOperand("~",q)
75 if negate in d:
76 return True
77 return False
78
79
80
93f1ab5 @slomo draft for resolution
authored
81 def resolute(knf):
82
83 for disj in knf:
84
85 for elem in disj:
86
aa19127 @slomo working resolution
authored
87 # check weather i look for ~Z or Z
88 if type(elem) is f.UnaryOperand:
93f1ab5 @slomo draft for resolution
authored
89 target = elem.term
90 else:
aa19127 @slomo working resolution
authored
91 target = f.UnaryOperand("~",elem)
93f1ab5 @slomo draft for resolution
authored
92
aa19127 @slomo working resolution
authored
93 for other_disj in deepcopy(knf):
94 if target in other_disj:
93f1ab5 @slomo draft for resolution
authored
95
3843dfa @slomo rewrote resolution to work on sets
authored
96 d = list(other_disj)
93f1ab5 @slomo draft for resolution
authored
97 d.remove(target)
98 d.extend(disj)
99 d.remove(elem)
3843dfa @slomo rewrote resolution to work on sets
authored
100
101 d = frozenset(d)
93f1ab5 @slomo draft for resolution
authored
102
aa19127 @slomo working resolution
authored
103 if len(d) == 0:
104 return True
105 if not (d in knf) and not is_tautology(d):
106 print("Resoluting",disj,"with",other_disj,"to",d)
107 knf.append(d)
108
109 return False
Something went wrong with that request. Please try again.