|
|
@@ -1,7 +1,7 @@
|
|
|
from itertools import combinations
|
|
|
|
|
|
-from .utils import nary_node, least_common_multiple
|
|
|
-from ..node import ExpressionLeaf as L, OP_DIV, OP_ADD, OP_MUL, OP_NEG
|
|
|
+from .utils import least_common_multiple
|
|
|
+from ..node import ExpressionLeaf as L, Scope, OP_DIV, OP_ADD, OP_MUL, OP_NEG
|
|
|
from ..possibilities import Possibility as P, MESSAGES
|
|
|
from ..translate import _
|
|
|
|
|
|
@@ -84,7 +84,7 @@ def match_add_constant_fractions(node):
|
|
|
return node.is_op(OP_DIV) or \
|
|
|
(node.is_op(OP_NEG) and node[0].is_op(OP_DIV))
|
|
|
|
|
|
- fractions = filter(is_division, node.get_scope())
|
|
|
+ fractions = filter(is_division, Scope(node))
|
|
|
|
|
|
for a, b in combinations(fractions, 2):
|
|
|
if a.is_op(OP_NEG):
|
|
|
@@ -117,7 +117,7 @@ def equalize_denominators(root, args):
|
|
|
"""
|
|
|
denom = args[2]
|
|
|
|
|
|
- scope = root.get_scope()
|
|
|
+ scope = Scope(root)
|
|
|
|
|
|
for fraction in args[:2]:
|
|
|
n, d = fraction[0] if fraction.is_op(OP_NEG) else fraction
|
|
|
@@ -127,11 +127,11 @@ def equalize_denominators(root, args):
|
|
|
n = L(n.value * mult) if n.is_numeric() else L(mult) * n
|
|
|
|
|
|
if fraction.is_op(OP_NEG):
|
|
|
- scope[scope.index(fraction)] = -(n / L(d.value * mult))
|
|
|
+ scope.remove(fraction, -(n / L(d.value * mult)))
|
|
|
else:
|
|
|
- scope[scope.index(fraction)] = n / L(d.value * mult)
|
|
|
+ scope.remove(fraction, n / L(d.value * mult))
|
|
|
|
|
|
- return nary_node('+', scope)
|
|
|
+ return scope.as_nary_node()
|
|
|
|
|
|
|
|
|
MESSAGES[equalize_denominators] = _('Equalize the denominators of division'
|
|
|
@@ -157,17 +157,15 @@ def add_nominators(root, args):
|
|
|
else:
|
|
|
c = cb[0]
|
|
|
|
|
|
- substitution = (a + c) / b
|
|
|
-
|
|
|
- scope = root.get_scope()
|
|
|
+ scope = Scope(root)
|
|
|
|
|
|
# Replace the left node with the new expression
|
|
|
- scope[scope.index(ab)] = substitution
|
|
|
+ scope.remove(ab, (a + c) / b)
|
|
|
|
|
|
# Remove the right node
|
|
|
scope.remove(cb)
|
|
|
|
|
|
- return nary_node('+', scope)
|
|
|
+ return scope.as_nary_node()
|
|
|
|
|
|
|
|
|
# TODO: convert this to a lambda. Example: 22 / 77 - 28 / 77. the "-" is above
|