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

BoxedExpression.match throws TypeError: Cannot read properties of undefined (reading 'symbol') #175

Closed holgerengels closed 3 months ago

holgerengels commented 3 months ago

Description

TypeError: Cannot read properties of undefined (reading 'symbol')
    at He (compute-engine.min.esm.js:17:48589)
    at vr (compute-engine.min.esm.js:17:84289)
    at _r (compute-engine.min.esm.js:17:84519)
    at Nr (compute-engine.min.esm.js:17:87753)
    at md (compute-engine.min.esm.js:17:87027)
    at _e (compute-engine.min.esm.js:17:85264)
    at Ui (compute-engine.min.esm.js:17:88143)
    at n.match (compute-engine.min.esm.js:17:122743)
    at Object.func (KmapSolvee.ts:466:22)
    at KmapSolvee.apply (KmapSolvee.ts:178:34)

Steps to Reproduce

This works as expected .. it's a match .. _a, _b and _c are present

let quadraticForm = ce.box(["Add", ["Multiply", "_a", ["Power", "x", "2"]], ["Multiply", "_b", "x"], "_c"]);
let matches = ce.box(["Add", ["Power", "x", "2"], "x", 1]).match(quadraticForm);

This works as expected .. it's not a match .. returns null

let quadraticForm = ce.box(["Add", ["Multiply", "_a", ["Power", "x", "2"]], ["Multiply", "_b", "x"], "_c"]);
let nulls = ce.box(["Add", ["Power", "x", "3"], "x"]).match(quadraticForm);

This crashes .. seems like it matches and then throws, 'cause _c is missing

let quadraticForm = ce.box(["Add", ["Multiply", "_a", ["Power", "x", "2"]], ["Multiply", "_b", "x"], "_c"]);
let crashes = ce.box(["Add", ["Power", "x", "2"], "x"]).match(quadraticForm);

It should either not match or return a substitution with missing wildcards. But it should not throw an error!

Version: "@cortex-js/compute-engine": "^0.25.0" Operating System Linux 6.8.0-35