cortex-js / compute-engine

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

0.5x ≠ frac{x}{2} #155

Closed remiangot closed 3 months ago

remiangot commented 7 months ago

Description

Problem with decimal and x for isEqual

Steps to Reproduce

import { ComputeEngine } from '@cortex-js/compute-engine'

const engine = new ComputeEngine()

const expr1 = '0.5x'
const expr2 = '\\frac{x}{2}'
const parsedExpr1 = engine.parse(expr1)
const parsedExpr2 = engine.parse(expr2)

console.log(parsedExpr1.isEqual(parsedExpr2)) // false and it should be true

Actual Behavior

parsedExpr1.isEqual(parsedExpr2) return false

There is the same problem with \\frac{1}{2}x or with with the other fractions in decimal notation.

Expected Behavior

parsedExpr1.isEqual(parsedExpr2) return true

Environment

ComputeEngine 0.24.1

truebluepl commented 5 months ago

Same here. Strange that complicated expressions like in example:

let a = ce.parse('\\frac{3*(x-1)}{(x-1)}');
let b = ce.parse('3');
console.log(a.isEqual(b));

work fine. Is there any hope for a solution this bug?