Skip to content
Snippets Groups Projects
Commit b74f5aed authored by Taddeüs Kroes's avatar Taddeüs Kroes
Browse files

Applied temporary fix from previous commit to definite integral bounds too.

parent 719fc68d
No related branches found
No related tags found
No related merge requests found
...@@ -339,35 +339,36 @@ class ExpressionNode(Node, ExpressionBase): ...@@ -339,35 +339,36 @@ class ExpressionNode(Node, ExpressionBase):
# Add bounds # Add bounds
if len(self) > 2: if len(self) > 2:
lbnd, ubnd = self[2:] op += self.construct_bounds(*self[2:])
# FIXME: temporary fix: add parentheses around negated bounds to
# prevent a syntax error (solving the syntax error is better, but
# harder)
if lbnd.negated:
lbnds = '%s(%s)' % (OP_VALUE_MAP[OP_SUBSCRIPT], lbnd)
else:
lbnds = str(ExpressionNode(OP_SUBSCRIPT, lbnd))
if ubnd.negated:
ubnds = '%s(%s)' % (OP_VALUE_MAP[OP_POW], ubnd)
else:
ubnds = str(ExpressionNode(OP_POW, ubnd))
op += lbnds + ubnds
# int x ^ 2 -> int x ^ 2 dx # int x ^ 2 -> int x ^ 2 dx
# int x + 1 -> int (x + 1) dx # int x + 1 -> int (x + 1) dx
# int_a^b x ^ 2 -> int_a^b x ^ 2 dx # int_a^b x ^ 2 -> int_a^b x ^ 2 dx
return op + ' ' + operand return op + ' ' + operand
def construct_bounds(self, lbnd, ubnd):
# FIXME: temporary fix: add parentheses around negated bounds to
# prevent a syntax error (solving the syntax error is better, but
# harder)
if lbnd.negated:
lbnds = '%s(%s)' % (OP_VALUE_MAP[OP_SUBSCRIPT], lbnd)
else:
lbnds = str(ExpressionNode(OP_SUBSCRIPT, lbnd))
if ubnd.negated:
ubnds = '%s(%s)' % (OP_VALUE_MAP[OP_POW], ubnd)
else:
ubnds = str(ExpressionNode(OP_POW, ubnd))
return lbnds + ubnds
def construct_indef_integral(self, children): def construct_indef_integral(self, children):
# [x ^ 2]_a^b # [x ^ 2]_a^b
F, lbnd, ubnd = self F, lbnd, ubnd = self
lbnd = str(ExpressionNode(OP_SUBSCRIPT, lbnd)) #lbnd = str(ExpressionNode(OP_SUBSCRIPT, lbnd))
ubnd = str(ExpressionNode(OP_POW, ubnd)) #ubnd = str(ExpressionNode(OP_POW, ubnd))
return '[%s]%s%s' % (F, lbnd, ubnd) return '[%s]%s' % (F, self.construct_bounds(lbnd, ubnd))
def construct_function(self, children): def construct_function(self, children):
if self.op == OP_ABS: if self.op == OP_ABS:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment