Commit f846f9e7 authored by Taddeus Kroes's avatar Taddeus Kroes

Source cleanup.

parent 7e891986
......@@ -7,41 +7,30 @@ from ..possibilities import Possibility as P, MESSAGES
from ..translate import _
def integral(f, x=None, lbnd=None, ubnd=None):
def integral(f, *args):
"""
Anti-derivative.
Create an integral node.
"""
params = [f]
if x:
params.append(x)
if lbnd:
params.append(lbnd)
if ubnd:
params.append(ubnd)
return N(OP_INT, *params)
def integral_params(integral):
"""
Get integral parameters:
- If f(x) and x are both specified, return them.
- If only f(x) is specified, find x.
"""
if len(integral) > 1:
assert integral[1].is_identifier()
return tuple(integral[:2])
f = integral[0]
variables = find_variables(integral)
if not len(variables):
return f, None
return f, L(first_sorted_variable(variables))
return N(OP_INT, *((f,) + args))
#def integral_params(integral):
# """
# Get integral parameters:
# - If f(x) and x are both specified, return them.
# - If only f(x) is specified, find x.
# """
# if len(integral) > 1:
# assert integral[1].is_identifier()
# return tuple(integral[:2])
#
# f = integral[0]
# variables = find_variables(integral)
#
# if not len(variables):
# return f, None
#
# return f, L(first_sorted_variable(variables))
def choose_constant(integral):
......@@ -88,7 +77,7 @@ def match_integrate_variable_power(node):
"""
assert node.is_op(OP_INT)
f, x = integral_params(node)
f, x = node
if f.is_power():
root, exponent = f
......
from src.rules.integrals import integral_params, choose_constant, \
from src.rules.integrals import choose_constant, \
match_integrate_variable_power, integrate_variable_root, \
integrate_variable_exponent
from src.rules.logarithmic import ln
......@@ -9,15 +9,15 @@ from tests.rulestestcase import RulesTestCase, tree
class TestRulesIntegrals(RulesTestCase):
def test_integral_params(self):
f, x = root = tree('int fx dx')
self.assertEqual(integral_params(root), (f, x))
#def test_integral_params(self):
# f, x = root = tree('int fx dx')
# self.assertEqual(integral_params(root), (f, x))
root = tree('int fx')
self.assertEqual(integral_params(root), (f, x))
# root = tree('int fx')
# self.assertEqual(integral_params(root), (f, x))
root = tree('int 3')
self.assertEqual(integral_params(root), (3, x))
# root = tree('int 3')
# self.assertEqual(integral_params(root), (3, x))
def test_choose_constant(self):
a, b, c = tree('a, b, c')
......
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