Commit 2ed4de97 authored by Taddeus Kroes's avatar Taddeus Kroes

Added notation for indefinite integrals.

parent 8600bb1f
...@@ -91,6 +91,7 @@ OP_MAP = { ...@@ -91,6 +91,7 @@ OP_MAP = {
OP_VALUE_MAP = dict([(v, k) for k, v in OP_MAP.iteritems()]) OP_VALUE_MAP = dict([(v, k) for k, v in OP_MAP.iteritems()])
OP_MAP['ln'] = OP_LOG OP_MAP['ln'] = OP_LOG
OP_VALUE_MAP[OP_INT_INDEF] = 'indef'
TOKEN_MAP = { TOKEN_MAP = {
OP_COMMA: 'COMMA', OP_COMMA: 'COMMA',
......
...@@ -398,6 +398,7 @@ class Parser(BisonParser): ...@@ -398,6 +398,7 @@ class Parser(BisonParser):
| bracket_derivative | bracket_derivative
| INTEGRAL exp | INTEGRAL exp
| integral_bounds TIMES exp %prec INTEGRAL | integral_bounds TIMES exp %prec INTEGRAL
| LBRACKET exp RBRACKET lbnd ubnd
""" """
if option == 0: # rule: NEG exp if option == 0: # rule: NEG exp
...@@ -460,14 +461,17 @@ class Parser(BisonParser): ...@@ -460,14 +461,17 @@ class Parser(BisonParser):
return Node(OP_INT, fx, x, lbnd, ubnd) return Node(OP_INT, fx, x, lbnd, ubnd)
if option == 7: # rule: LBRACKET exp RBRACKET lbnd ubnd
return Node(OP_INT_INDEF, values[1], values[3], values[4])
raise BisonSyntaxError('Unsupported option %d in target "%s".' raise BisonSyntaxError('Unsupported option %d in target "%s".'
% (option, target)) # pragma: nocover % (option, target)) # pragma: nocover
def on_integral_bounds(self, target, option, names, values): def on_integral_bounds(self, target, option, names, values):
""" """
integral_bounds : INTEGRAL lbnd rbnd integral_bounds : INTEGRAL lbnd ubnd
""" """
if option == 0: # rule: INTEGRAL lbnd rbnd if option == 0: # rule: INTEGRAL lbnd ubnd
return values[1], values[2] return values[1], values[2]
raise BisonSyntaxError('Unsupported option %d in target "%s".' raise BisonSyntaxError('Unsupported option %d in target "%s".'
...@@ -483,9 +487,9 @@ class Parser(BisonParser): ...@@ -483,9 +487,9 @@ class Parser(BisonParser):
raise BisonSyntaxError('Unsupported option %d in target "%s".' raise BisonSyntaxError('Unsupported option %d in target "%s".'
% (option, target)) # pragma: nocover % (option, target)) # pragma: nocover
def on_rbnd(self, target, option, names, values): def on_ubnd(self, target, option, names, values):
""" """
rbnd : POW exp ubnd : POW exp
""" """
if option == 0: # rule: POW exp if option == 0: # rule: POW exp
return values[1] return values[1]
......
...@@ -2,16 +2,24 @@ from .utils import find_variables, first_sorted_variable, infinity, \ ...@@ -2,16 +2,24 @@ from .utils import find_variables, first_sorted_variable, infinity, \
replace_variable replace_variable
from .logarithmic import ln from .logarithmic import ln
#from .goniometry import sin, cos #from .goniometry import sin, cos
from ..node import ExpressionNode as N, ExpressionLeaf as L, OP_INT from ..node import ExpressionNode as N, ExpressionLeaf as L, OP_INT, \
OP_INT_INDEF
from ..possibilities import Possibility as P, MESSAGES from ..possibilities import Possibility as P, MESSAGES
from ..translate import _ from ..translate import _
def integral(f, *args): def integral(*args):
""" """
Create an integral node. Create an integral node.
""" """
return N(OP_INT, *((f,) + args)) return N(OP_INT, *args)
def indef(*args):
"""
Create an indefinite integral node.
"""
return N(OP_INT_INDEF, *args)
#def integral_params(integral): #def integral_params(integral):
......
...@@ -9,7 +9,7 @@ from tests.rulestestcase import tree ...@@ -9,7 +9,7 @@ from tests.rulestestcase import tree
from src.rules.goniometry import sin, cos from src.rules.goniometry import sin, cos
from src.rules.derivatives import der from src.rules.derivatives import der
from src.rules.logarithmic import log, ln from src.rules.logarithmic import log, ln
from src.rules.integrals import integral from src.rules.integrals import integral, indef
class TestParser(unittest.TestCase): class TestParser(unittest.TestCase):
...@@ -111,3 +111,8 @@ class TestParser(unittest.TestCase): ...@@ -111,3 +111,8 @@ class TestParser(unittest.TestCase):
self.assertEqual(tree('int_a^b x2 dy'), integral(x ** 2, y, a, b)) self.assertEqual(tree('int_a^b x2 dy'), integral(x ** 2, y, a, b))
self.assertEqual(tree('int_(a-b)^(a+b) x2'), self.assertEqual(tree('int_(a-b)^(a+b) x2'),
integral(x ** 2, x, a - b, a + b)) integral(x ** 2, x, a - b, a + b))
def test_indefinite_integral(self):
x2, a, b = tree('x ^ 2, a, b')
self.assertEqual(tree('[x ^ 2]_a^b'), indef(x2, a, b))
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