-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Description
Description
BoxedExpression.match() incorrectly returns null for a Rational when the second argument is anything other than a variable.
Steps to Reproduce
// Incorrect results
const brokenOne = ce.box(["Rational", 3,2]).match(ce.box(["Rational", "_num", "_den"])) // Incorrectly returns null
const brokenTwo = ce.box(["Rational", "x",2]).match(ce.box(["Rational", "_num", "_den"])) // Incorrectly returns null
const brokenThree = ce.box(["Rational", "x",["Power", 3, 2]]).match(ce.box(["Rational", "_num", "_den"])) // Incorrectly returns null
// Similar, correct results
const worksOne = ce.box(["Rational", 3,"y"]).match(ce.box(["Rational", "_num", "_den"])) // Correctly returns {_num: 3, _den: "y"} when converted to JSON
const worksTwo = ce.box(["Rational", "x","y"]).match(ce.box(["Rational", "_num", "_den"])) // Correctly returns {_num: "x", _den: "y"} when converted to JSON
console.log({brokenOne, brokenTwo, worksOne, worksTwo})Actual Result
{
brokenOne: null,
brokenTwo: null,
brokenThree: null,
worksOne: {
_num: qe {
engine: [n],
verbatimLatex: undefined,
_value: [n],
_hash: undefined
},
_den: Gt {
engine: [n],
verbatimLatex: undefined,
_hash: undefined,
_id: 'y',
_def: [Object]
}
},
worksTwo: {
_num: Gt {
engine: [n],
verbatimLatex: undefined,
_hash: undefined,
_id: 'x',
_def: [Object]
},
_den: Gt {
engine: [n],
verbatimLatex: undefined,
_hash: undefined,
_id: 'y',
_def: [Object]
}
}
}
Expected Result
// when converted to JSON
{
brokenOne: {_num: 3, _den: 2}, // instead of null
brokenTwo: {_num: "x", _den: 2}, // instead of null
brokenThree: {_num: "x", _den: ["Power",3,2]}, //instead of null
worksOne: {_num: 3, _den: "y"}, // this is already correct
worksTwo: {_num: "x", _den: "y"} // this is also already correct
}Environment
- Node using "@cortex-js/compute-engine": "^0.30.2"
- Also occurs using the demo boxes on the website
Metadata
Metadata
Assignees
Labels
No labels