summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2022-04-28 19:36:22 -0500
committerHombreLaser <sebastian-440@live.com>2022-04-28 19:36:22 -0500
commit459085fd21dcf26ec3ee9f6a293e3f6721a85383 (patch)
treec1ce41703cbfd7b5ca8c2668506274edf4b48ab6
parent44ec4d12336e290ad8d1f6e1559e04bf19e79075 (diff)
Corregido error de la regla de la cadena.HEADmaster
-rw-r--r--differentiator.cpp16
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.