jiggzson / nerdamer

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

Problem with simplify #623

Open szoshi opened 3 years ago

szoshi commented 3 years ago

Hi, I think here is a bug that needs to be looked at. I am trying to simplify two expressions which results in a sign error

For e.g.

let eq1 = nerdamer("(-3/2)x+(1/3)y+2+z") eq1.simplify gives "-12-2y-6z+9*x" with a multiplier of 1/6 which is a sign error

If however, let eq1 = nerdamer("(-3/2)x+(1/3)y+z") Then eq2.simplify gives "-9x+2y+6*z" also with a multiplier of 1/6 which is correct.

I had similar expressions where it worked without a problem so i could not narrow it down further.

Yaffle commented 3 years ago

not sure where the bug is, but https://github.com/jiggzson/nerdamer/blob/master/nerdamer.core.js#L9290 on this line sign is set to 1 and the sign of b is ignored

jiggzson commented 3 years ago

@szoshi, got it.

@Yaffle, Thanks for looking into this. Gives me a place to start looking.

jiggzson commented 3 years ago

@szoshi, it appears this issue was fixed with one of the commits. Not sure which one but I suspect this one (5fb1b7b09c7d926fe9a4a837e67d177984392589). I added a test for this issue.

jiggzson commented 2 years ago

@Yaffle, after taking a closer look at the line you mentioned, it appears that the sign eventually gets used here. I think it's being stored that early on because that information is lost after that point. Unless I'm missing something.

szoshi commented 2 years ago

Hi guys, I haven't received any further updates on this issue so just wanted to check if there has been any progress? Thanks!

jiggzson commented 2 years ago

@szoshi, this should be fixed on the dev branch.