Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

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

Open
michaelcheers opened this issue Dec 9, 2021 · 2 comments

Comments

@michaelcheers
Copy link

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)
@gunnarmein-ts
Copy link

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
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants