Przeglądaj źródła

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

Taddeus Kroes 14 lat temu
rodzic
commit
7d602a8435
2 zmienionych plików z 4 dodań i 4 usunięć
  1. 3 3
      src/rules/fractions.py
  2. 1 1
      tests/test_rules_fractions.py

+ 3 - 3
src/rules/fractions.py

@@ -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()
 

+ 1 - 1
tests/test_rules_fractions.py

@@ -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)