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