-
Notifications
You must be signed in to change notification settings - Fork 0
/
p24.py
38 lines (31 loc) · 874 Bytes
/
p24.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
class Number:
def __init__(self, x):
self.value = x
def __repr__(self):
return "%s" % self.value
class Complex:
def __init__(self, a, b):
self.real = a
self.imag = b
def __repr__(self):
return "%s + %si" % (self.real, self.imag)
class Add:
def __init__(self, l, r):
self.left = l
self.right = r
def __repr__(self):
return "%s + %s" % (self.left, self.right)
class Multiply:
def __init__(self, l, r):
self.left = l
self.right = r
def __repr__(self):
return "%s * %s" % (self.left, self.right)
#Add(Multiply(Number(1), Number(2)), Multiply(Number(3), Number(4)))
def reducible(expr):
if expr.__class__ == Number or expr.__class__ == Complex:
return False
else:
return True
#reducible(Number(10))
#reducbile(Add(45, 12))