|
|
@@ -89,13 +89,14 @@ def match_add_fractions(node):
|
|
|
|
|
|
if b == d:
|
|
|
# Equal denominators, add nominators to create a single fraction
|
|
|
- p.append(P(node, add_nominators, (scope, ab, cd)))
|
|
|
+ p.append(P(node, add_nominators, (scope.clone(), ab, cd)))
|
|
|
elif all(map(is_numeric_node, (a, b, c, d))):
|
|
|
# Denominators are both numeric, rewrite both fractions to the
|
|
|
# least common multiple of their denominators. Later, the
|
|
|
# nominators will be added
|
|
|
lcm = least_common_multiple(b.value, d.value)
|
|
|
- p.append(P(node, equalize_denominators, (scope, ab, cd, lcm)))
|
|
|
+ p.append(P(node, equalize_denominators,
|
|
|
+ (scope.clone(), ab, cd, lcm)))
|
|
|
|
|
|
# Also, add the (non-recommended) possibility to multiply the
|
|
|
# denominators. Do this only if the multiplication is not equal to
|
|
|
@@ -103,7 +104,8 @@ def match_add_fractions(node):
|
|
|
mult = b.value * d.value
|
|
|
|
|
|
if mult != lcm:
|
|
|
- p.append(P(node, equalize_denominators, (scope, ab, cd, mult)))
|
|
|
+ p.append(P(node, equalize_denominators,
|
|
|
+ (scope.clone(), ab, cd, mult)))
|
|
|
|
|
|
for ab, c in product(fractions, numerics):
|
|
|
a, b = ab
|
|
|
@@ -111,7 +113,7 @@ def match_add_fractions(node):
|
|
|
if a.is_numeric() and b.is_numeric():
|
|
|
# Fraction of constants added to a constant -> create a single
|
|
|
# constant fraction
|
|
|
- p.append(P(node, constant_to_fraction, (scope, ab, c)))
|
|
|
+ p.append(P(node, constant_to_fraction, (scope.clone(), ab, c)))
|
|
|
|
|
|
return p
|
|
|
|
|
|
@@ -189,11 +191,11 @@ def match_multiply_fractions(node):
|
|
|
fractions, others = partition(lambda n: n.is_op(OP_DIV), scope)
|
|
|
|
|
|
for ab, cd in combinations(fractions, 2):
|
|
|
- p.append(P(node, multiply_fractions, (scope, ab, cd)))
|
|
|
+ p.append(P(node, multiply_fractions, (scope.clone(), ab, cd)))
|
|
|
|
|
|
for ab, c in product(fractions, others):
|
|
|
if evals_to_numeric(c) or not evals_to_numeric(ab):
|
|
|
- p.append(P(node, multiply_with_fraction, (scope, ab, c)))
|
|
|
+ p.append(P(node, multiply_with_fraction, (scope.clone(), ab, c)))
|
|
|
|
|
|
return p
|
|
|
|