josdejong / mathjs

An extensive math library for JavaScript and Node.js
https://mathjs.org
Apache License 2.0
14.44k stars 1.24k forks source link

simplify("(x^2)^0.5") should be "abs(x)" #3329

Open paulftw opened 3 days ago

paulftw commented 3 days ago

While there are genuine use cases when returning "x" would be better (that's what most humans would expect), strictly speaking it is incorrect.

To reproduce in the mathnotepad:

derivative("(x^2)^0.5", "x").evaluate({x:-3})
    1

derivative("(x^2)^0.5", "x", {simplify:false}).evaluate({x:-3})
    -1

Here I evaluate the same derivative at the same point x=-3 but get two different results. Same problem for x^4 and I assume all other even powers.

josdejong commented 2 days ago

Thanks that is a very good and valid point.

Anyone able to improve simplify? Help would be welcome.