cortex-js / compute-engine

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

Fails to turn into correct MathJSON #13

Open stefnotch opened 3 years ago

stefnotch commented 3 years ago

I went through some mathematics notes and found the following interesting equations. I tested them on the compute engine demo page https://cortexjs.io/compute-engine/demo/

(Information for myself: Page 1 of ANA_UE_SS_21_Mo_1.pdf , meaning there are a few more testcases)





arnog commented 3 years ago

Those are excellent test cases, thank you!

x_{1,2} is a particularly interesting one: the comma is a valid inter-digit separator (as in "1,234.56") but of course I should be a bit more rigorous when considering it as a digit separator. Still, I suppose that x_{123,456} would be ambiguous... Hmmm..

stefnotch commented 3 years ago

That's true, that makes this test case surprisingly tricky. It doesn't help that countries and standards can't agree on which decimal separator to use https://en.wikipedia.org/wiki/Decimal_separator (My preferred one is grouping digits into groups of 3. Simple spacing rules and no funky, ambiguous extra characters.)

For what it's worth, I personally have never seen a , decimal separator in a mathematical equation. However, it does appear somewhat frequently in tables of numbers and other cases where it's mostly just a number.

Another interesting thing that I just found out is that by default, a comma has a small space after it. image

arnog commented 3 years ago

Yes, it's considered a punctuation character and so has a small padding on its right.

Note also that you can configure which character (or rather which LaTeX command sequence) is used with the groupSeparator option.

That said, some people have very strong opinions about this: http://wordpress.mrreid.org/2014/05/27/stop-putting-commas-in-your-numbers/

Maybe I should reconsider the default value for groupSeparator... :)

stefnotch commented 3 years ago

Oh nice, I didn't know that there was configuration option for that :)

I like the idea of changing the default value for groupSeparator, but it doesn't matter very much to me either way.

stefnotch commented 3 years ago

I found another case where the compute-engine doesn't quite work: Logarithms.

For example \begin{equation*} \log_3(7) \end{equation*} gets parsed as

[
  "Multiply",
  ["Subscript", "\\log", 3],
  ["Parentheses", 
    {num: "7"}]
]

@phcreery