Commit 6add540a authored by Taddeus Kroes's avatar Taddeus Kroes

Changed function name.

parent b4b5542d
from .utils import find_variables, replace_variable, find_variable from .utils import find_variables, substitute, find_variable
from ..node import ExpressionLeaf as L, OP_INT, OP_INT_INDEF, OP_MUL, OP_DIV, \ from ..node import ExpressionLeaf as L, OP_INT, OP_INT_INDEF, OP_MUL, OP_DIV, \
OP_LOG, OP_SIN, OP_COS, Scope, sin, cos, ln, integral, indef, absolute OP_LOG, OP_SIN, OP_COS, Scope, sin, cos, ln, integral, indef, absolute
from ..possibilities import Possibility as P, MESSAGES from ..possibilities import Possibility as P, MESSAGES
...@@ -40,7 +40,7 @@ def solve_integral(integral, F): ...@@ -40,7 +40,7 @@ def solve_integral(integral, F):
x, lbnd, ubnd = integral[1:4] x, lbnd, ubnd = integral[1:4]
if x != find_variable(F): if x != find_variable(F):
return replace_variable(F, x, ubnd) - replace_variable(F, x, lbnd) return substitute(F, x, ubnd) - substitute(F, x, lbnd)
return indef(F, lbnd, ubnd) return indef(F, lbnd, ubnd)
...@@ -61,7 +61,7 @@ def solve_indef(root, args): ...@@ -61,7 +61,7 @@ def solve_indef(root, args):
Fx, a, b = root Fx, a, b = root
x = find_variable(Fx) x = find_variable(Fx)
return replace_variable(Fx, x, b) - replace_variable(Fx, x, a) return substitute(Fx, x, b) - substitute(Fx, x, a)
def match_integrate_variable_power(node): def match_integrate_variable_power(node):
......
...@@ -111,7 +111,7 @@ def find_variable(exp): ...@@ -111,7 +111,7 @@ def find_variable(exp):
return L(first_sorted_variable(variables)) return L(first_sorted_variable(variables))
def replace_variable(f, x, replacement): def substitute(f, x, replacement):
""" """
Replace all occurences of variable x in function f with the specified Replace all occurences of variable x in function f with the specified
replacement. replacement.
...@@ -122,6 +122,6 @@ def replace_variable(f, x, replacement): ...@@ -122,6 +122,6 @@ def replace_variable(f, x, replacement):
if f.is_leaf: if f.is_leaf:
return f return f
children = map(lambda c: replace_variable(c, x, replacement), f) children = map(lambda c: substitute(c, x, replacement), f)
return N(f.op, *children) return N(f.op, *children)
from src.rules import utils from src.rules import utils
from src.rules.utils import least_common_multiple, is_fraction, partition, \ from src.rules.utils import least_common_multiple, is_fraction, partition, \
find_variables, first_sorted_variable, find_variable, replace_variable find_variables, first_sorted_variable, find_variable, substitute
from tests.rulestestcase import tree, RulesTestCase from tests.rulestestcase import tree, RulesTestCase
...@@ -50,10 +50,10 @@ class TestRulesUtils(RulesTestCase): ...@@ -50,10 +50,10 @@ class TestRulesUtils(RulesTestCase):
self.assertEqual(find_variable(tree('1 + 2')), x) self.assertEqual(find_variable(tree('1 + 2')), x)
self.assertEqual(find_variable(tree('y ^ 2')), y) self.assertEqual(find_variable(tree('y ^ 2')), y)
def test_replace_variable(self): def test_substitute(self):
x, a = tree('x, a') x, a = tree('x, a')
self.assertEqual(replace_variable(x, x, a), a) self.assertEqual(substitute(x, x, a), a)
self.assertEqual(replace_variable(tree('x2'), x, a), tree('a2')) self.assertEqual(substitute(tree('x2'), x, a), tree('a2'))
self.assertEqual(replace_variable(tree('y + x + 1'), x, a), self.assertEqual(substitute(tree('y + x + 1'), x, a),
tree('y + a + 1')) tree('y + a + 1'))
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