Commit 49391e6c authored by Taddeus Kroes's avatar Taddeus Kroes

Bugfix: added negation copy to substitute function.

parent 358e632e
graph_drawing @ ab2d0af7
Subproject commit aade5fc51f4b19e84d180fcff9b6c6d89db93667
Subproject commit ab2d0af74078bf71f10da5e1f671f866caa84908
......@@ -32,7 +32,7 @@ OP_AND = 9
OP_OR = 10
# Binary operators that are considered n-ary
NARY_OPERATORS = [OP_ADD, OP_SUB, OP_MUL]
NARY_OPERATORS = [OP_ADD, OP_SUB, OP_MUL, OP_AND, OP_OR]
# N-ary (functions)
OP_INT = 11
......@@ -139,9 +139,6 @@ def to_expression(obj):
class ExpressionBase(object):
def __init__(self, *args, **kwargs):
self.negated = 0
def __lt__(self, other):
"""
Comparison between this expression{node,leaf} and another
......
......@@ -125,7 +125,7 @@ def substitute(f, x, replacement):
children = map(lambda c: substitute(c, x, replacement), f)
return N(f.op, *children)
return N(f.op, *children, negated=f.negated)
def divides(m, n):
......
......@@ -58,6 +58,8 @@ class TestRulesUtils(RulesTestCase):
self.assertEqual(substitute(tree('x2'), x, a), tree('a2'))
self.assertEqual(substitute(tree('y + x + 1'), x, a),
tree('y + a + 1'))
self.assertEqual(substitute(tree('1 - 2x'), x, a),
tree('1 - 2a'))
def test_divides(self):
self.assertTrue(divides(3, 3))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment