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

Precedence of the logical operations is not rendered correctly #156

Open mathematicswizard opened 5 months ago

mathematicswizard commented 5 months ago

Description

The Compute Engine doesn't recognize the precedence of the logical operations.

Steps to Reproduce

Write some propositions with logical connectives in a mathfield, such as: 3=4\vee 7=8 A\subseteq B\wedge\emptyset\subset B

Actual Behavior

These propositions renders to the following MathJSON: ["Equal",3,["And",["Error",["ErrorCode","'incompatible-domain'","Booleans","PositiveIntegers"],4],["Error",["ErrorCode","'incompatible-domain'","Booleans","PositiveIntegers"],5]],7] ["SubsetEqual","A",["Subset",["And","B",["Error",["ErrorCode","'incompatible-domain'","Booleans","Sets"],"EmptySet"]],"B"]]

Expected Behavior

["Or",["Equal",3,4],["Equal",7,8]] ["And",["SubsetEqual","A","B"],["Subset","EmptySet","B"]]

An error occurs because the Compute Engine reads all these propositions as simple propositions and not compound ones. So it find the first relational symbol and expects to find a noun to the left of it and a noun to the right it.

To note - adding parentheses "solves" the problem and the MathJSON is as above. But the paraentheses in these cases a superfluous - even without them these are still WFF's; these propositions cannot be interpreted in any other way - that is why the parentheses are not needed, and the Compute Engine should have read them accordingly.

Environment

I have never checked if this worked in the past. Did this with the latest version of mathlive in the demo page and adding to the developer console this code: formula._mathfield.getValue("math-json")