Commit 28644d89 authored by Taddeus Kroes's avatar Taddeus Kroes

Instead of to the outside, negations in multiplications are now brought to the left.

parent 1c0dece5
......@@ -6,7 +6,7 @@ from ..translate import _
def match_negated_factor(node):
"""
This rule assures that negations in the scope of a multiplication are
brought `outside', to the multiplication itself.
brought to the most left node in the multiplication's scope.
Example:
a * -b -> -(ab)
......@@ -19,7 +19,7 @@ def match_negated_factor(node):
# FIXME: The negation that is brought outside is assigned to the first
# element in the scope during the next parsing step:
# -ab -> -(ab), but -(ab) is printed as -ab
for factor in scope:
for factor in scope[1:]:
if factor.negated:
p.append(P(node, negated_factor, (scope, factor)))
......@@ -28,12 +28,13 @@ def match_negated_factor(node):
def negated_factor(root, args):
"""
a * -b -> -(ab)
a * -b -> -ab
"""
scope, factor = args
scope[0] = -scope[0]
scope.replace(factor, +factor)
return -scope.as_nary_node()
return scope.as_nary_node()
MESSAGES[negated_factor] = \
......
......@@ -23,14 +23,13 @@ class TestRulesNegation(RulesTestCase):
def test_negated_factor(self):
a, b = root = tree('a * -b')
self.assertEqualNodes(negated_factor(root, (Scope(root), b)),
-(a * +b))
-a * +b)
(a, b), c = root = tree('a * -b * -c')
scope = Scope(root)
self.assertEqualNodes(negated_factor(root, (scope, b)),
-(a * +b * c))
self.assertEqualNodes(negated_factor(root, (scope, c)),
-(a * b * +c))
self.assertEqualNodes(negated_factor(root, (Scope(root), b)),
-a * +b * c)
self.assertEqualNodes(negated_factor(root, (Scope(root), c)),
-a * b * +c)
def test_match_negate_polynome(self):
root = tree('--a')
......
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