cortex-js / compute-engine

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

Evaluation of Piecewise expressions (cases) incorect #61

Closed fabiastisch closed 1 year ago

fabiastisch commented 1 year ago

Evaluation and numeric approximation gives incorrect results.

version: 0.8.0:

let expr = ce.parse("\begin{cases} 0 & n = 0\\ 1 & n = 1\\ n \geq 2 & n^2+1 \end{cases}")
expr = expr.subs({n: 1})

console.log(expr.N().latex)
// > `\begin{cases}\\1&1=1\\2\le1&1+1\end{cases}`

Expected result: 1