jiggzson / nerdamer

a symbolic math expression evaluator for javascript
http://www.nerdamer.com
MIT License
517 stars 82 forks source link

Square roots in fractions don't simplify #480

Closed Wlowscha closed 5 years ago

Wlowscha commented 5 years ago

When I write an expression such as

sqrt(2) - 2/sqrt(2)

the fraction doesn't simplify, and consequently the result is not 0.

I skimmed through the other issue reports (including #239 ) and didn't find anything specifically addressing this. Since it is a very basic thing I expect it to be already known, in which case I apologize.

jiggzson commented 5 years ago

@Wlowscha, fixed on dev. Thanks for pointing it out.

Wlowscha commented 5 years ago

Thank you! Indeed, it works now.

However, the same issue remains for a similar kind of expression, that is 1/sqrt(2) - sqrt(2)/2 which I should have mentioned sooner.

In an attempt to come up with more cases, I noticed something weird with expressions like 2/sqrt(6) - sqrt(2)/sqrt(3) and sqrt(6)/2 - sqrt(3)/sqrt(2) These both return 0 when .evaluate() is called, but they don't simplify when .text() or .latex() are called.

I just signed up and still new to github, so I hope it's okay to add reports in the comments like this.

jiggzson commented 5 years ago

However, the same issue remains for a similar kind of expression, that is 1/sqrt(2) - sqrt(2)/2

@Wlowscha, I forgot to take care of those cases.

In an attempt to come up with more cases, I noticed something weird with expressions like 2/sqrt(6) - sqrt(2)/sqrt(3) and sqrt(6)/2 - sqrt(3)/sqrt(2) These both return 0 when .evaluate() is called, but they don't simplify when .text() or .latex() are called.

Those types of simplifications are more than likely going to handled by the simplify function at some point.

I just signed up and still new to github, so I hope it's okay to add reports in the comments like this.

It's perfectly okay. Please do. We can't fix something if we don't know about it.