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, \
OP_LOG, OP_SIN, OP_COS, Scope, sin, cos, ln, integral, indef, absolute
from ..possibilities import Possibility as P, MESSAGES
......@@ -40,7 +40,7 @@ def solve_integral(integral, F):
x, lbnd, ubnd = integral[1:4]
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)
......@@ -61,7 +61,7 @@ def solve_indef(root, args):
Fx, a, b = root
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):
......
......@@ -111,7 +111,7 @@ def find_variable(exp):
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
replacement.
......@@ -122,6 +122,6 @@ def replace_variable(f, x, replacement):
if f.is_leaf:
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)
from src.rules import utils
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
......@@ -50,10 +50,10 @@ class TestRulesUtils(RulesTestCase):
self.assertEqual(find_variable(tree('1 + 2')), x)
self.assertEqual(find_variable(tree('y ^ 2')), y)
def test_replace_variable(self):
def test_substitute(self):
x, a = tree('x, a')
self.assertEqual(replace_variable(x, x, a), a)
self.assertEqual(replace_variable(tree('x2'), x, a), tree('a2'))
self.assertEqual(replace_variable(tree('y + x + 1'), x, a),
self.assertEqual(substitute(x, x, a), a)
self.assertEqual(substitute(tree('x2'), x, a), tree('a2'))
self.assertEqual(substitute(tree('y + x + 1'), x, a),
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