cortex-js / compute-engine

An engine for symbolic manipulation and numeric evaluation of math formulas expressed with MathJSON
https://cortexjs.io
MIT License
356 stars 42 forks source link

Fix x/2/y. It was yielding (xy)/2 rather than x/(2y). #144

Closed dcbradley closed 6 months ago

dcbradley commented 6 months ago

This patch fixes a problem in symbolic evaluation of the division of a fraction by something else.

How to reproduce

const ce = new ComputeEngine();
var expr = ce.parse("(x/2)/y");
console.log(expr.json);

Actual behavior

[ 'Divide', [ 'Multiply', 'x', 'y' ], 2 ]

Expected behavior

[ 'Divide', 'x', [ 'Multiply', 2, 'y' ] ]

Environment

compute-engine 0.23.1

I have not tried previous versions.

Cheers!

arnog commented 6 months ago

Oops. Good catch and good fix. Thanks!