-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtruthvalues.py
More file actions
51 lines (38 loc) · 1 KB
/
Copy pathtruthvalues.py
File metadata and controls
51 lines (38 loc) · 1 KB
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
#!/usr/bin/python
# Classes for truth functions of propositional logic expressions
class Simple_exp(object):
"""
A simple expression, i.e. a propositional variable.
Define value(self) when creating the propositional variable.
"""
def __init__(self):
pass
class Not_exp(object):
"""
A expression that is a negation, i.e. negation has widest scope.
"""
def __init__(self, rhs):
self.rhs = rhs
def value(self):
if value(self.rhs) == True:
return False
if value(self.rhs) == False:
return True
class Or_exp(object):
"""
A disjunction: p OR q
"""
def __init__(self, lhs, rhs):
self.lhs = lhs
self.rhs = rhs
def value(self):
return (value(lhs) or value(rhs))
class And_exp(object):
"""
A conjunction: p AND q
"""
def __init__(self, lhs, rhs):
self.lhs = lhs
self.rhs = rhs
def value(self):
return (value(lhs) and value(rhs))