diff --git a/poincare/src/derivative.cpp b/poincare/src/derivative.cpp index d4159e606..0d139fd73 100644 --- a/poincare/src/derivative.cpp +++ b/poincare/src/derivative.cpp @@ -176,8 +176,12 @@ Expression Derivative::shallowReduce(ExpressionNode::ReductionContext reductionC return *this; } /* Updates the value of derivand, because derivate may call - * replaceWithInplace on it */ - derivand = childAtIndex(0); + * replaceWithInplace on it. + * We need to reduce the derivand here before replacing the symbol : the + * general formulas used during the derivation process can create some nodes + * that are not defined for some values (e.g. log), but that would disappear + * at reduction. */ + derivand = childAtIndex(0).deepReduce(reductionContext); /* Deep reduces the child, because derivate may not preserve its reduced * status. */ diff --git a/poincare/test/derivative.cpp b/poincare/test/derivative.cpp index 1621c893b..89e9a1aee 100644 --- a/poincare/test/derivative.cpp +++ b/poincare/test/derivative.cpp @@ -64,4 +64,6 @@ QUIZ_CASE(poincare_derivative_approximation) { assert_reduces_for_approximation("diff(abs(x),x,123)", "1"); assert_reduces_for_approximation("diff(abs(x),x,-2.34)", "-1"); assert_reduces_for_approximation("diff(abs(x),x,0)", Undefined::Name()); + + assert_reduces_for_approximation("diff(1/x,x,-2)", "-1/4"); }