Skip to content

Commit ac49792

Browse files
committed
Fix bugs in diff() and simp(). Add a smoke test.
1 parent 28b485b commit ac49792

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

logic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ def diff(y, x):
977977
u, op, v = y.args[0], y.op, y.args[-1]
978978
if op == '+':
979979
return diff(u, x) + diff(v, x)
980-
elif op == '-' and len(args) == 1:
980+
elif op == '-' and len(y.args) == 1:
981981
return -diff(u, x)
982982
elif op == '-':
983983
return diff(u, x) - diff(v, x)
@@ -998,7 +998,7 @@ def diff(y, x):
998998

999999
def simp(x):
10001000
"Simplify the expression x."
1001-
if not x.args:
1001+
if isnumber(x) or not x.args:
10021002
return x
10031003
args = list(map(simp, x.args))
10041004
u, op, v = args[0], x.op, args[-1]

tests/test_logic.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ def test_ask(query, kb=None):
173173
assert repr(test_ask('Rabbit(x)')) == '[{x: MrsRabbit}, {x: Pete}]'
174174
assert repr(test_ask('Criminal(x)', crime_kb)) == '[{x: West}]'
175175

176+
def test_d():
177+
assert d(x*x - x, x) == 2*x - 1
178+
176179
def test_WalkSAT():
177180
def check_SAT(clauses, single_solution = {}):
178181
# Make sure the solution is correct if it is returned by WalkSat

0 commit comments

Comments
 (0)