Commit a455b76b authored by Taddeus Kroes's avatar Taddeus Kroes

Added left-or-right check to application that brings an expression into a fraction nominator.

parent 5f556a4e
...@@ -60,8 +60,6 @@ Division of 0 by 1 reduces to 0. ...@@ -60,8 +60,6 @@ Division of 0 by 1 reduces to 0.
- Parser: 'apia' -> 'aa' - Parser: 'apia' -> 'aa'
- 'x(1 / x)' -> '(x * 1) / x' (currently no left/right check: '1x / x')
- Unit tests for strategy. - Unit tests for strategy.
- MESSAGES needs to be expanded. - MESSAGES needs to be expanded.
......
...@@ -217,12 +217,17 @@ MESSAGES[multiply_fractions] = _('Multiply fractions {2} and {3}.') ...@@ -217,12 +217,17 @@ MESSAGES[multiply_fractions] = _('Multiply fractions {2} and {3}.')
def multiply_with_fraction(root, args): def multiply_with_fraction(root, args):
""" """
a / b * c and a, c in Z or a == 1 -> ac / b a / b * c and (eval(c) in Z or eval(a / b) not in Z) -> (ac) / b
""" """
scope, ab, c = args scope, ab, c = args
a, b = ab a, b = ab
scope.replace(ab, (a * c / b).negate(ab.negated)) if scope.index(ab) - scope.index(c) < 0:
replacement = a * c / b
else:
replacement = c * a / b
scope.replace(ab, replacement.negate(ab.negated))
scope.remove(c) scope.remove(c)
return scope.as_nary_node() return scope.as_nary_node()
......
...@@ -57,10 +57,10 @@ class TestLeidenOefenopgaveV12(TestCase): ...@@ -57,10 +57,10 @@ class TestLeidenOefenopgaveV12(TestCase):
def test_2_a(self): def test_2_a(self):
self.assertRewrite([ self.assertRewrite([
'(a^2b^-1)^3(ab^2)', '(a ^ 2 * b ^ -1) ^ 3(ab ^ 2)',
'(a ^ 2 * 1 / b ^ 1) ^ 3 * ab ^ 2', '(a ^ 2 * 1 / b ^ 1) ^ 3 * ab ^ 2',
'(a ^ 2 * 1 / b) ^ 3 * ab ^ 2', '(a ^ 2 * 1 / b) ^ 3 * ab ^ 2',
'((1a ^ 2) / b) ^ 3 * ab ^ 2', '((a ^ 2 * 1) / b) ^ 3 * ab ^ 2',
'(a ^ 2 / b) ^ 3 * ab ^ 2', '(a ^ 2 / b) ^ 3 * ab ^ 2',
'(a ^ 2) ^ 3 / b ^ 3 * ab ^ 2', '(a ^ 2) ^ 3 / b ^ 3 * ab ^ 2',
'a ^ (2 * 3) / b ^ 3 * ab ^ 2', 'a ^ (2 * 3) / b ^ 3 * ab ^ 2',
...@@ -103,7 +103,7 @@ class TestLeidenOefenopgaveV12(TestCase): ...@@ -103,7 +103,7 @@ class TestLeidenOefenopgaveV12(TestCase):
self.assertRewrite([ self.assertRewrite([
'4b^-2', '4b^-2',
'4 * 1 / b ^ 2', '4 * 1 / b ^ 2',
'(1 * 4) / b ^ 2', '(4 * 1) / b ^ 2',
'4 / b ^ 2', '4 / b ^ 2',
]) ])
......
...@@ -110,7 +110,7 @@ class TestRulesDerivatives(RulesTestCase): ...@@ -110,7 +110,7 @@ class TestRulesDerivatives(RulesTestCase):
"x ^ x * (1ln(x) + x[ln(x)]')", "x ^ x * (1ln(x) + x[ln(x)]')",
"x ^ x * (ln(x) + x[ln(x)]')", "x ^ x * (ln(x) + x[ln(x)]')",
"x ^ x * (ln(x) + x * 1 / x)", "x ^ x * (ln(x) + x * 1 / x)",
"x ^ x * (ln(x) + (1x) / x)", "x ^ x * (ln(x) + (x * 1) / x)",
"x ^ x * (ln(x) + x / x)", "x ^ x * (ln(x) + x / x)",
"x ^ x * (ln(x) + 1)", "x ^ x * (ln(x) + 1)",
"x ^ x * ln(x) + x ^ x * 1", "x ^ x * ln(x) + x ^ x * 1",
......
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