mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[poincare/derivative] Reduce before replacing symbol
The general formula for deriving a power makes use of the logarithm,
which often disappears at simplification. However, replacing the symbol
before simplifying can lead to applying an invalid argument to the
logarithm, making the whole expression invalid.
e.g. diff(1/x,x,-2)
If x is replaced by -2 before reducing the power derivative, ln(-2)
will reduce to Unreal, as will the rest of the expression.
This commit is contained in:
committed by
EmilieNumworks
parent
1a47207bee
commit
3f6e4444a5
@@ -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. */
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user