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