This repository has been archived by the owner on May 23, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The original implementation of Expression._combineLikeTerms was written when Expressions were always simplified. In some cases where like-terms show up multiple times and are scattered, terms would be missed because I was splicing on the array that was being iterated through (which is probably bad in general). It’s been rewritten to keep track of which terms have already been encountered. E.g., this used to fail: var exp = algebra.parse("x + y + 3"); var unsimplified = exp.pow(3, false); unsimplified.toString(); // xxx + xyy + yxx + yxy + yyx + yyy + xxy + xyx + 3yx + 3xy + 3xy + 3yy + 3xx + 3xx + 3yy + 3yx + 3yy + 3yx + 3xx + 3xy + 3 * 3x + 3 * 3y + 3 * 3x + 3 * 3y + 3 * 3x + 3 * 3y + 3 * 3 * 3 var simplified = unsimplified.simplify(); simplified.toString(); // x^3 + y^3 + 2x^2y + y^2x + x^2y + 2y^2x + 6y^2 + 9x^2 + 3y^2 + 3xy + 15yx + 27x + 18y + 9y + 27 Notice the 2x^2y and x^2y terms are not combined when they should be. This now works correctly: var simplified = unsimplified.simplify(); simplified.toString(); // x^3 + y^3 + 3x^2y + 3y^2x + 9x^2 + 9y^2 + 18xy + 27x + 27y + 27
- Loading branch information