Commit 694854ae authored by Taddeus Kroes's avatar Taddeus Kroes

Shortened rule name.

parent 17862fb9
...@@ -27,7 +27,7 @@ from src.rules.logarithmic import match_constant_logarithm, \ ...@@ -27,7 +27,7 @@ from src.rules.logarithmic import match_constant_logarithm, \
from src.rules.integrals import match_solve_indef, match_constant_integral, \ from src.rules.integrals import match_solve_indef, match_constant_integral, \
match_integrate_variable_power, match_factor_out_constant, \ match_integrate_variable_power, match_factor_out_constant, \
match_division_integral, match_function_integral match_division_integral, match_function_integral
from src.rules.lineq import match_subtract_addition_term from src.rules.lineq import match_subtract_term
RULES = { RULES = {
OP_ADD: [match_add_numerics, match_add_constant_fractions, OP_ADD: [match_add_numerics, match_add_constant_fractions,
...@@ -61,5 +61,5 @@ RULES = { ...@@ -61,5 +61,5 @@ RULES = {
match_factor_out_constant, match_division_integral, match_factor_out_constant, match_division_integral,
match_function_integral], match_function_integral],
OP_INT_INDEF: [match_solve_indef], OP_INT_INDEF: [match_solve_indef],
OP_EQ: [match_subtract_addition_term], OP_EQ: [match_subtract_term],
} }
...@@ -4,7 +4,7 @@ from ..possibilities import Possibility as P, MESSAGES ...@@ -4,7 +4,7 @@ from ..possibilities import Possibility as P, MESSAGES
from ..translate import _ from ..translate import _
def match_subtract_addition_term(node): def match_subtract_term(node):
""" """
x + a = b -> x + a - a = b - a x + a = b -> x + a - a = b - a
x = b + cx -> x + - cx = b + cx - cx x = b + cx -> x + - cx = b + cx - cx
...@@ -16,25 +16,21 @@ def match_subtract_addition_term(node): ...@@ -16,25 +16,21 @@ def match_subtract_addition_term(node):
left, right = node left, right = node
if left.is_op(OP_ADD): if left.is_op(OP_ADD):
scope = Scope(left) for n in Scope(left):
for n in scope:
# Bring terms without x to the right # Bring terms without x to the right
if not n.contains(x): if not n.contains(x):
p.append(P(node, subtract_addition_term, (n,))) p.append(P(node, subtract_term, (n,)))
if right.is_op(OP_ADD): if right.is_op(OP_ADD):
scope = Scope(right) for n in Scope(right):
for n in scope:
# Bring terms with x to the left # Bring terms with x to the left
if n.contains(x): if n.contains(x):
p.append(P(node, subtract_addition_term, (n,))) p.append(P(node, subtract_term, (n,)))
return p return p
def subtract_addition_term(root, args): def subtract_term(root, args):
""" """
x + a = b -> x + a - a = b - a x + a = b -> x + a - a = b - a
x = b + cx -> x + - cx = b + cx - cx x = b + cx -> x + - cx = b + cx - cx
...@@ -45,5 +41,4 @@ def subtract_addition_term(root, args): ...@@ -45,5 +41,4 @@ def subtract_addition_term(root, args):
return eq(left - term, right - term) return eq(left - term, right - term)
MESSAGES[subtract_addition_term] = \ MESSAGES[subtract_term] = _('Subtract {1} from both sides of the equation.')
_('Subtract {1} from both sides of the equation.')
from src.rules.lineq import match_subtract_addition_term, \ from src.rules.lineq import match_subtract_term, \
subtract_addition_term subtract_term
from src.node import Scope from src.node import Scope
from src.possibilities import Possibility as P from src.possibilities import Possibility as P
from tests.rulestestcase import RulesTestCase, tree from tests.rulestestcase import RulesTestCase, tree
...@@ -7,15 +7,15 @@ from tests.rulestestcase import RulesTestCase, tree ...@@ -7,15 +7,15 @@ from tests.rulestestcase import RulesTestCase, tree
class TestRulesLineq(RulesTestCase): class TestRulesLineq(RulesTestCase):
def test_match_subtract_addition_term(self): def test_match_subtract_term(self):
root, a = tree('x + a = b, a') root, a = tree('x + a = b, a')
self.assertEqualPos(match_subtract_addition_term(root), self.assertEqualPos(match_subtract_term(root),
[P(root, subtract_addition_term, (a,))]) [P(root, subtract_term, (a,))])
root, cx = tree('x = b + cx, cx') root, cx = tree('x = b + cx, cx')
self.assertEqualPos(match_subtract_addition_term(root), self.assertEqualPos(match_subtract_term(root),
[P(root, subtract_addition_term, (cx,))]) [P(root, subtract_term, (cx,))])
def test_subtract_addition_term(self): def test_subtract_term(self):
root, a, expect = tree('x + a = b, a, x + a - a = b - a') root, a, expect = tree('x + a = b, a, x + a - a = b - a')
self.assertEqual(subtract_addition_term(root, (a,)), expect) self.assertEqual(subtract_term(root, (a,)), expect)
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