Commit 7d602a84 authored by Taddeus Kroes's avatar Taddeus Kroes

Improved rewriting of the rule that deliberately creates a numeric fraction.

parent fb6c8bf9
......@@ -74,7 +74,7 @@ def match_add_fractions(node):
a / b + c / b and a, c in Z -> (a + c) / b
a / b + c / d and a, b, c, d in Z -> a' / e + c' / e # e = lcm(b, d)
# | e = b * d
a / b + c and a, b, c in Z -> a / b + b / b * c # =>* (a + bc) / b
a / b + c and a, b, c in Z -> a / b + (bc) / b # =>* (a + bc) / b
"""
assert node.is_op(OP_ADD)
......@@ -164,11 +164,11 @@ MESSAGES[equalize_denominators] = \
def constant_to_fraction(root, args):
"""
a / b + c and a, b, c in Z -> a / b + b / b * c # =>* (a + bc) / b
a / b + c and a, b, c in Z -> a / b + (bc) / b # =>* (a + bc) / b
"""
scope, ab, c = args
b = ab[1]
scope.replace(c, b / b * c)
scope.replace(c, b * c / b)
return scope.as_nary_node()
......
......@@ -140,7 +140,7 @@ class TestRulesFractions(RulesTestCase):
(a + -c) / -b)
def test_constant_to_fraction(self):
root, e = tree('2 / 3 + 1, 2 / 3 + 3 / 3 * 1')
root, e = tree('2 / 3 + 1, 2 / 3 + (3 * 1) / 3')
l23, l1 = root
self.assertEqual(constant_to_fraction(root, (Scope(root), l23, l1)), e)
......
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