Selaa lähdekoodia

Fixed no possibilities when trying to apply sum rule.

Taddeus Kroes 14 vuotta sitten
vanhempi
sitoutus
fcfc7cefb9
2 muutettua tiedostoa jossa 7 lisäystä ja 4 poistoa
  1. 6 3
      src/rules/derivatives.py
  2. 1 1
      tests/test_rules_derivatives.py

+ 6 - 3
src/rules/derivatives.py

@@ -340,10 +340,13 @@ def match_sum_product_rule(node):
     x = L(x)
     functions = [n for n in scope if n.contains(x)]
 
-    if len(functions) < 2:
-        return []
+    if node[0].op == OP_MUL:
+        if len(functions) < 2:
+            return []
 
-    handler = sum_rule if node[0].op == OP_ADD else product_rule
+        handler = product_rule
+    else:
+        handler = sum_rule
 
     return [P(node, handler, (scope, f)) for f in functions]
 

+ 1 - 1
tests/test_rules_derivatives.py

@@ -208,7 +208,7 @@ class TestRulesDerivatives(RulesTestCase):
                  P(root, product_rule, (Scope(f), x))])
 
     def test_match_sum_product_rule_none(self):
-        root = tree('der(x ^ 2 + 2)')
+        root = tree('der(2 + 2)')
         self.assertEqualPos(match_sum_product_rule(root), [])
 
         root = tree('der(x ^ 2 * 2)')