nerdamer icon indicating copy to clipboard operation
nerdamer copied to clipboard

Problems with nerdamer.simplify and {expr}.simplify with square roots

Open michaelcheers opened this issue 3 years ago • 2 comments

Review the following code examples:

nerdamer('sqrt(2)').simplify().toString()     -> 'sqrt(2)'
nerdamer('sqrt(a)/a').simplify().toString()   -> 'a^(-1/2)'
nerdamer('sqrt(2*a)/a').simplify().toString() -> 'a^(-1)*sqrt(2)*sqrt(a)' // should be sqrt(2/a)
nerdamer.simplify('sqrt(2)').toString()       -> '131836323/93222358'
nerdamer.simplify('sqrt(a)/a').toString()     -> 'sqrt(a)^(-1)'
nerdamer.simplify('sqrt(2*a)/a').toString()   -> 'sqrt((131836323/93222358)*a)^(-1)' // this is wrong sqrt(sqrt(2)*a)^(-1) is not equal to sqrt(2*a)^(-1)

So I've found three problems:

  • .simplify() does not simplify sqrt(n*a)/a to sqrt(n/a)
  • nerdamer.simplify converts irrational numbers into confusing fractional approximations.
  • nerdamer.simplify makes a mistake in my specific example in converting sqrt(sqrt(2)*a) not sqrt(2*a)

michaelcheers avatar Dec 09 '21 20:12 michaelcheers

To your second point, it is not simplify() that does that, it is simply how Nerdamer represents numbers internally. .text("decimals") or simply .text() is your friend if that is what you want, instead of .toString(). As for the rest, yeah, I have given up on simplify(). Perhaps one of use should take the time to debug that, as a community contribution.

gunnarmein-ts avatar Dec 17 '21 02:12 gunnarmein-ts

Also, if you want functions like sqrt(2) evaluated, you need to say "evaluate()". I agree with the concept of keeping things symbolic as long as one can.

gunnarmein-ts avatar Dec 17 '21 02:12 gunnarmein-ts