Browse Source

Added notation for indefinite integrals.

Taddeus Kroes 14 years ago
parent
commit
2ed4de97ba
4 changed files with 26 additions and 8 deletions
  1. 1 0
      src/node.py
  2. 8 4
      src/parser.py
  3. 11 3
      src/rules/integrals.py
  4. 6 1
      tests/test_parser.py

+ 1 - 0
src/node.py

@@ -91,6 +91,7 @@ OP_MAP = {
 
 OP_VALUE_MAP = dict([(v, k) for k, v in OP_MAP.iteritems()])
 OP_MAP['ln'] = OP_LOG
+OP_VALUE_MAP[OP_INT_INDEF] = 'indef'
 
 TOKEN_MAP = {
         OP_COMMA: 'COMMA',

+ 8 - 4
src/parser.py

@@ -398,6 +398,7 @@ class Parser(BisonParser):
               | bracket_derivative
               | INTEGRAL exp
               | integral_bounds TIMES exp %prec INTEGRAL
+              | LBRACKET exp RBRACKET lbnd ubnd
         """
 
         if option == 0:  # rule: NEG exp
@@ -460,14 +461,17 @@ class Parser(BisonParser):
 
             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".'
                                % (option, target))  # pragma: nocover
 
     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]
 
         raise BisonSyntaxError('Unsupported option %d in target "%s".'
@@ -483,9 +487,9 @@ class Parser(BisonParser):
         raise BisonSyntaxError('Unsupported option %d in target "%s".'
                                % (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
             return values[1]

+ 11 - 3
src/rules/integrals.py

@@ -2,16 +2,24 @@ from .utils import find_variables, first_sorted_variable, infinity, \
         replace_variable
 from .logarithmic import ln
 #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 ..translate import _
 
 
-def integral(f, *args):
+def integral(*args):
     """
     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):

+ 6 - 1
tests/test_parser.py

@@ -9,7 +9,7 @@ from tests.rulestestcase import tree
 from src.rules.goniometry import sin, cos
 from src.rules.derivatives import der
 from src.rules.logarithmic import log, ln
-from src.rules.integrals import integral
+from src.rules.integrals import integral, indef
 
 
 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)^(a+b) x2'),
                          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))