Fix computing derivative of negated exponential expressions

parent 283780a4
......@@ -208,7 +208,7 @@ def variable_root(root, args):
"""
x, n = root[0]
return n * x ** (n - 1)
return (n).negate(root[0].negated) * x ** (n - 1)
MESSAGES[variable_root] = \
......@@ -225,9 +225,9 @@ def variable_exponent(root, args):
g, x = root[0]
if g == E:
return g ** x
return (g ** x).negate(root[0].negated)
return g ** x * ln(g)
return (g ** x).negate(root[0].negated) * ln(g)
MESSAGES[variable_exponent] = \
......
......@@ -138,6 +138,11 @@ class TestRulesDerivatives(RulesTestCase):
x, n = root[0]
self.assertEqual(variable_root(root, ()), n * x ** (n - 1))
def test_variable_root_with_negation(self):
root = tree('d/dx -x ^ 2')
x, n = root[0]
self.assertEqual(variable_root(root, ()), -n * x ** (n - 1))
def test_variable_exponent(self):
root = tree('d/dx 2 ^ x')
g, x = root[0]
......@@ -147,6 +152,10 @@ class TestRulesDerivatives(RulesTestCase):
e, x = root[0]
self.assertEqual(variable_exponent(root, ()), e ** x)
root = tree('d/dx -e ^ x')
e, x = root[0]
self.assertEqual(variable_exponent(root, ()), -e ** x)
def test_chain_rule(self):
root = tree('(2 ^ x ^ 3)\'')
l2, x3 = root[0]
......
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