cortex-js / compute-engine

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

Only a nonstandard negation operator parses #134

Closed nathancarter closed 9 months ago

nathancarter commented 9 months ago

Description

The MathLive editor supports multiple ways to express the same logical negation symbol, but only one of them actually parses, and it is not one I had ever heard of.

Steps to Reproduce

After loading MathLive, I try these at the console.

// Other logical operators work as expected:
MathfieldElement.computeEngine.parse( 'A \\wedge B' ).json
// ==> ['And','A','B']
//     Great!  Works as expected!
MathfieldElement.computeEngine.parse( 'A \\vee B' ).json
// ==> ['Or','A','B']
//     Great!  Works as expected!
MathfieldElement.computeEngine.parse( 'A \\implies B' ).json
// ==> ['Implies','A','B']
//     Not standard LaTeX, but I'm not arguing.  That's fine.

// Now, the problem I'm reporting:
MathfieldElement.computeEngine.parse( '\\neg A' ).json
// ==> ['Error',['ErrorCode','\'unexpected-command\'','\'\\neg\''],['LatexString','\'\\neg\'']]
//     That means the most common negation symbol AFAIK isn't respected.
MathfieldElement.computeEngine.parse( '\\not A' ).json
// ==> ['Error',['ErrorCode','\'unexpected-command\'','\'\\not\''],['LatexString','\'\\not\'']]
//     This was just a guess because we had "implies" spelled out, so I was experimenting...
MathfieldElement.computeEngine.parse( '\\lnot A' ).json
// ==> ['Not','A']
//     Works but it's an unusual operator name.
//     The only way I discovered this symbol was by using the keyboard in the MathLive widget,
//     then inspecting under the hood what it was it had created.

Actual Behavior

The system accepts only \lnot as a parse-able negation operator.

Expected Behavior

I expected the (standard?) \neg operator to be parse-able.

Environment

MathLive version Latest from CDN on Dec 7, 2023, which is CortexJS Compute Engine 0.22.0.

Operating System macOS 12.4

Browser Brave

arnog commented 9 months ago

Both \neg and \lnot are used. See https://www.bu.edu/math/files/2013/08/LongTeX1.pdf, https://tex.stackexchange.com/questions/430677/what-is-the-difference-between-lnot-and-neg or https://www.cis.upenn.edu/~cis1600/current/files/resources/useful_latex_commands.pdf.

I'm not sure if one is more popular than the the other, but if you have any reference on that I'd be interested...

nathancarter commented 9 months ago

Okay, good point, I should be more specific, sorry. As your second reference points out, there isn't a visual or semantic difference between \neg and \lnot. Furthermore, you can enter both of them in MathLive. That's why I was surprised to find out that one of them parses into logical negation while the other one generates a parsing error. That's unexpected. I would think that if the appearance and accepted meaning of both are identical, then the behavior of both of them in the parser should also be identical.

arnog commented 9 months ago

Oh yes, no question they should both be recognized when parsing, but I was wondering if you had some info regarding their popularity to pick the most common one for serialization. For now, I still use \lnot.

BTW, not sure if you're aware of this, but the info above my comment ("arnog closed this as completed in ed43c81") indicates that I have checked-in a fix for the issue.

nathancarter commented 9 months ago

Ah! Oops. I saw that you had closed the issue but somehow did not see that it was with a fix--my bad! Thanks. :)

And no, I only have anecdotal evidence (what I've seen as a LaTeX user) of which is more common. No comprehensive survey of any kind.