math.derivative returns a strange form of a polynomial involving negative powers. #3076
Replies: 3 comments
-
|
Makes sense. I'll label this as a possible improvement since it is not strictly speaking a bug. Anyone interested in looking into this? |
Beta Was this translation helpful? Give feedback.
-
|
Hey thanks for getting back to my comment. If you think it's a discussion and not a bug since it is a correct answer to the question that's cool. If I get more time I may come back to this and try to implement a change, but for now I have moved to another approach and don't have time. |
Beta Was this translation helpful? Give feedback.
-
|
As a sort of workaround at the moment, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
The bug is that when using math.derivative to evaluate
1x^2 -4x^-2, mathjs returns:(2 * x ^ 4 + 8) / x ^ 3. I appreciate that this is one valid way of notating the answer, however, it is quite strange. An analogy would be that if an arithmetic function evaluated2+2and returned8/2we would likely consider that a bug. It is true that8/2is one way of notating the answer but it's not how the vast majority of users would expect to receive the result, which would be4.It should be: 2 * x + 8 * x ^ -3, or
2 * x + 8 / x ^ 3. The documentation includes some examples of derivatives, but not expressions like this, so maybe it was overlooked.As a comparison the Python library SymPy evaluates
1*x**2 -4*x**-2to:2*x + 8/x**3.To Reproduce
Call math.derivative with the above polynomial and see that it evaluates to the above result.
Beta Was this translation helpful? Give feedback.
All reactions