Ver Fonte

Rewrite two constants into one constant (in combine_numerics).

Sander Mathijs van Veen há 14 anos atrás
pai
commit
26b4d4424d
1 ficheiros alterados com 14 adições e 1 exclusões
  1. 14 1
      src/rules/poly.py

+ 14 - 1
src/rules/poly.py

@@ -1,6 +1,7 @@
 from itertools import combinations
 
-from ..node import ExpressionNode as Node, TYPE_OPERATOR, OP_ADD, OP_MUL
+from ..node import ExpressionNode as Node, ExpressionLeaf as Leaf, \
+        TYPE_OPERATOR, OP_ADD, OP_MUL
 from ..possibilities import Possibility as P
 from .utils import nary_node
 
@@ -110,6 +111,18 @@ def match_combine_polynomes(node, verbose=False):
     return p
 
 
+def combine_numerics(root, args):
+    """
+    Combine two constants to a single constant in an n-ary plus.
+
+    Synopsis:
+    c0 + c1 -> eval(c1 + c2)
+    """
+    c0, c1 = args
+
+    return Leaf(c0.value + c1.value)
+
+
 def combine_polynomes(root, args):
     """
     Combine two multiplications of any polynome in an n-ary plus.