Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
math.derivative changed result between 3.14 and 3.16.1 #1013
First, thanks to Jos and everyone who has made this a great math library! I have unit tests for the parts of mathjs I use, and when I upgraded from 3.14.2 to 3.16.1 one of them that uses math.derivative() started failing.
For the expression "1 - (-B)" math.3.14.2 gives a derivative node which is a ConstantNode, value=1, which is correct.
In 3.16.1 and later, the same expression gives a derivative node which is a unaryMinus OperatorNode. Its only arg is a ConstantNode, value=1. So the derivative is -1, which is incorrect.
When I debugged thru the derivative call, it looks like what changed is the simplify rule:
Or am I missing something? Thanks, Sam
Can confirm that this is an issue in the most current version (3.19.0).
So, this is actually an issue in
simplify("0 - -1") // "-1" simplify("0 - -x") // "-x"
Diving into an invocation of
To fix this, I recommend that we remove the
While debugging this case, I found a related but more complicated (and more severe case):
Thanks a lot @joelhoover , your research saves me quite a headache ;) .
I think you're right: we cannot distinguish subtract and unary minus by their operator, we have to rely on their name instead in
I've applied your fix here: 8724ae0, will do a release today or tomorrow.
added a commit
Jan 13, 2018
Well, honestly, I have left that in place because else a couple of unit tests break, I haven't looked into it deeper (I haven't written the code). I suppose