-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliteral.py
77 lines (59 loc) · 1.58 KB
/
literal.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
import copy
class Literal:
"""An literal consists of
- its symbol
- whether it is a positive literal
"True" and "False" are positive literals
"""
def __init__(self, positive = None, symbol = None):
try:
assert(isinstance(positive, bool))
self.p = positive
except:
print("'positive' is not a bool type.")
try:
assert(symbol is not None and isinstance(symbol, str))
self.s = symbol
if self.s == "True" or self.s == "False":
self.p = True
except:
print("No string symbol for the proposition is given")\
def isPositive(self):
return self.p
def isNegative(self):
return not self.p
def complements(self, other):
return self.s == other.s and self.p != self.p
def equalSymbol(self, other):
return self.s == other.s
def equalSymbol(self, symbol):
return self.s == symbol
def setSymbol(self, symbol):
self.s = symbol
# fake function to test if an object is of Literal
def literal():
return
# overridden
def __deepcopy__(self, memo):
cp = Literal(copy.deepcopy(self.p, memo), copy.deepcopy(self.s, memo))
return cp
def __copy__(self):
return copy.copy(self)
# magic
def __invert__(self): # perhaps make it a deep copy?
# cp = copy.deepcopy(self)
# cp.p = not self.p
# return cp
self.p = not self.p
return self
def __eq__(self, other):
return self.s == other.s and self.p == self.p
def __hash__(self):
return hash((self.s, self.p))
def __ne__(self, other):
return self.s != other.s or self.p == self.p
def __str__(self):
neg = "-"
return self.s if self.p else neg + self.s
def __iter__(self):
return self