Commit 9419b2b1 authored by Taddeus Kroes's avatar Taddeus Kroes

Added some messages and comments to negation rules.

parent 8b4634e0
...@@ -16,6 +16,9 @@ def match_negated_factor(node): ...@@ -16,6 +16,9 @@ def match_negated_factor(node):
p = [] p = []
scope = Scope(node) scope = Scope(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:
if factor.negated: if factor.negated:
p.append(P(node, negated_factor, (scope, factor))) p.append(P(node, negated_factor, (scope, factor)))
...@@ -33,6 +36,10 @@ def negated_factor(root, args): ...@@ -33,6 +36,10 @@ def negated_factor(root, args):
return -scope.as_nary_node() return -scope.as_nary_node()
MESSAGES[negated_factor] = \
_('Bring negation of {2} to the outside of the multiplication.')
def match_negate_polynome(node): def match_negate_polynome(node):
""" """
--a -> a --a -> a
...@@ -60,7 +67,7 @@ def double_negation(root, args): ...@@ -60,7 +67,7 @@ def double_negation(root, args):
return root.reduce_negation(2) return root.reduce_negation(2)
MESSAGES[double_negation] = _('Remove double negation in {1}.') MESSAGES[double_negation] = _('Remove double negation in {0}.')
def negate_polynome(root, args): def negate_polynome(root, args):
...@@ -76,7 +83,7 @@ def negate_polynome(root, args): ...@@ -76,7 +83,7 @@ def negate_polynome(root, args):
return +scope.as_nary_node() return +scope.as_nary_node()
MESSAGES[negate_polynome] = _('Apply negation to the polynome {1}.') MESSAGES[negate_polynome] = _('Apply negation to the polynome {0}.')
#def negate_group(root, args): #def negate_group(root, args):
...@@ -140,7 +147,7 @@ def double_negated_division(root, args): ...@@ -140,7 +147,7 @@ def double_negated_division(root, args):
MESSAGES[double_negated_division] = \ MESSAGES[double_negated_division] = \
_('Eliminate top and bottom negation in {1}.') _('Eliminate top and bottom negation in {0}.')
# TODO: negated multiplication: -a * -b = ab # TODO: negated multiplication: -a * -b = ab
...@@ -46,6 +46,10 @@ class TestRulesNegation(RulesTestCase): ...@@ -46,6 +46,10 @@ class TestRulesNegation(RulesTestCase):
[P(root, double_negation, (b,)), [P(root, double_negation, (b,)),
P(root, negate_polynome, ())]) P(root, negate_polynome, ())])
def test_double_negation(self):
root = tree('--a')
self.assertEqualNodes(double_negation(root, ()), ++root)
def test_negate_polynome(self): def test_negate_polynome(self):
a, b = root = tree('-(a + b)') a, b = root = tree('-(a + b)')
self.assertEqualNodes(negate_polynome(root, ()), -a + -b) self.assertEqualNodes(negate_polynome(root, ()), -a + -b)
......
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