Commit c7a9125f authored by Taddeus Kroes's avatar Taddeus Kroes

Applied usage of Scope.replace method and fixed some failing unit tests.

parent b63b5130
......@@ -45,7 +45,7 @@ def expand_single(root, args):
scope = Scope(root)
# Replace 'a' with the new expression
scope.remove(a, a * b + a * c)
scope.replace(a, a * b + a * c)
# Remove the addition
scope.remove(bc)
......@@ -66,7 +66,7 @@ def expand_double(root, args):
scope = Scope(root)
# Replace 'a + b' with the new expression
scope.remove(ab, a * c + a * d + b * c + b * d)
scope.replace(ab, a * c + a * d + b * c + b * d)
# Remove the right addition
scope.remove(cd)
......
from itertools import combinations
from .utils import least_common_multiple
from ..node import ExpressionLeaf as L, Scope, OP_DIV, OP_ADD, OP_MUL
from ..node import ExpressionLeaf as L, Scope, negate, OP_DIV, OP_ADD, OP_MUL
from ..possibilities import Possibility as P, MESSAGES
from ..translate import _
......@@ -112,10 +112,15 @@ def equalize_denominators(root, args):
mult = denom / d.value
if mult != 1:
n = L(n.value * mult) if n.is_numeric() else L(mult) * n
if n.is_numeric():
n = L(n.value * mult)
else:
n = L(mult) * n
scope.remove(fraction, negate(n / L(d.value * mult),
fraction.negated))
#n = L(n.value * mult) if n.is_numeric() else L(mult) * n
scope.replace(fraction, negate(n / L(d.value * mult),
fraction.negated))
return scope.as_nary_node()
......@@ -137,7 +142,7 @@ def add_nominators(root, args):
scope = Scope(root)
# Replace the left node with the new expression
scope.remove(ab, (a + negate(cb[0], cb.negated)) / b)
scope.replace(ab, (a + cb[0].negate(cb.negated)) / b)
# Remove the right node
scope.remove(cb)
......
......@@ -59,7 +59,7 @@ def combine_groups(root, args):
c0 = Leaf(c0)
# Replace the left node with the new expression
scope.remove(n0, (c0 + c1) * g0)
scope.replace(n0, (c0 + c1) * g0)
# Remove the right node
scope.remove(n1)
......
......@@ -19,7 +19,7 @@ def add_numerics(root, args):
scope = Scope(root)
# Replace the left node with the new expression
scope.remove(n0, Leaf(c0.actual_value() + c1.actual_value()))
scope.replace(n0, Leaf(c0.actual_value() + c1.actual_value()))
# Remove the right node
scope.remove(n1)
......@@ -171,7 +171,7 @@ def multiply_numerics(root, args):
scope = Scope(root)
# Replace the left node with the new expression
scope.remove(n0, substitution)
scope.replace(n0, substitution)
# Remove the right node
scope.remove(n1)
......
......@@ -84,7 +84,7 @@ def combine_polynomes(root, args):
# Replace the left node with the new expression:
# (c0 + c1) * a ^ b
# a, b and c are from 'left', d is from 'right'.
scope.remove(n0, (c0 + c1) * power)
scope.replace(n0, (c0 + c1) * power)
# Remove the right node
scope.remove(n1)
......
......@@ -54,7 +54,7 @@ def add_exponents(root, args):
scope = Scope(root)
# Replace the left node with the new expression
scope.remove(n0, a ** (p + q))
scope.replace(n0, a ** (p + q))
# Remove the right node
scope.remove(n1)
......
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