diff options
author | HombreLaser <sebastian-440@live.com> | 2022-04-28 19:36:22 -0500 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2022-04-28 19:36:22 -0500 |
commit | 459085fd21dcf26ec3ee9f6a293e3f6721a85383 (patch) | |
tree | c1ce41703cbfd7b5ca8c2668506274edf4b48ab6 /differentiator.cpp | |
parent | 44ec4d12336e290ad8d1f6e1559e04bf19e79075 (diff) |
Diffstat (limited to 'differentiator.cpp')
-rw-r--r-- | differentiator.cpp | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/differentiator.cpp b/differentiator.cpp index d25366d..5f8fffa 100644 --- a/differentiator.cpp +++ b/differentiator.cpp @@ -75,17 +75,11 @@ Expression *Differentiator::visit(SubExpression *expr) const { // Regla de la potencia. f(x)=x^c, f'(x)=c*x^(c-1)}*f'(x). Expression *Differentiator::visit(PowerExpression *expr) const { Literal *c = dynamic_cast<Literal *>(expr->getRight()); - Variable *x = dynamic_cast<Variable *>(expr->getLeft()); - - /* Si el valor izquierdo no es un número, entonces el derecho - lo es. */ - if(c == NULL) { - c = dynamic_cast<Literal *>(expr->getLeft()); - x = dynamic_cast<Variable *>(expr->getRight()); - } - - return new MultiplicationExpression(new MultiplicationExpression(c->copy(), new PowerExpression(x->copy(), new Literal(c->getValue() - 1))), - expr->getLeft()->diff(this)); + Expression *left = expr->getLeft(); + + return new MultiplicationExpression(new MultiplicationExpression + (new Literal(c->getValue()), new PowerExpression(left->copy(), new Literal(c->getValue() - 1))), + left->diff(this)); } // Regla del producto. |