[BUG] error when handling coefficients with fractions
Steps to reproduce:
- URL encode
simplify('w/5-(2w+3)/2-3w/5')tosimplify%28%27w%2F5-%282w%2B3%29%2F2-3w%2F5%27%29using any URL encoder (I used https://www.urlencoder.io/). - Hit https://api.mathjs.org/v4/?expr=simplify%28%27w%2F5-%282w%2B3%29%2F2-3w%2F5%27%29 in the address bar in any web browser (I'm using Google Chrome).
- Got output
w * -2 / 5 + (-(2 * w) - 3) / 2.
Expected output: $$\frac{w}{5}-\frac{2w+3}{2}-\frac{3w}{5} = -\frac75w-\frac32$$
Thanks, would be nice to improve simplify to also simplify this case. So in short:
math.simplify('w * -2 / 5 + (-(2 * w) - 3) / 2').toString()
// actual output: "w * -2 / 5 + (-(2 * w) - 3) / 2"
// expected output: "w * -7 / 5 + -3 / 2"
Anyone interested in writing additional rules for simplify to address cases like these?
Hi, I would like to take a shot at this. Haven't contributed to an open source project yet so please excuse the obvious mistakes if any. The simplify function breaks ( no further simplification is done ) if the inner string is of the form n1 + ( n1 * c1 + c2) / c3. The approach would then be to simplify that to something like n1+((c1*n1)/c3+c2/c3). Is that correct ?
Thanks Ayush. It will indeed be a solution around expanding the two terms inside the parenthesis, and/or extracting the constants out of it and then simplifying the constant terms. It will require some trial and error I think to see how things work out and if there are no unwanted side effects.
So adding one extra rule in the form of s: '(c1*v+c2)/c3 -> ((c1*v)/c3)+c2/c3', makes the above mentioned expression work if there is no subtraction (If it was 'w/5+(2w+3)/2+3w/5'). That results in the correct w * 9 / 5 + 3 / 2
Came to report a similar issue and found this one already open. A simpler example of the problem, if it helps:
simplify("(-0.5) x + y")
x * -1 / 2 + y
simplify("(-0.5) x + y").toTex()
"\frac{ x\cdot-1}{2}+ y"
A simpler example of the problem, if it helps:
simplify("(-0.5) x + y")
x * -1 / 2 + y
Sorry, what's the desired output in this case? -x/2 + y? I don't see anything wrong with the current actual output, so what it should simplify to may be a matter of judgment, so it would be good to know your view about what you expected.