Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to turn into correct MathJSON #13

Open
7 of 10 tasks
stefnotch opened this issue Jul 1, 2021 · 5 comments
Open
7 of 10 tasks

Fails to turn into correct MathJSON #13

stefnotch opened this issue Jul 1, 2021 · 5 comments

Comments

@stefnotch
Copy link
Contributor

stefnotch commented Jul 1, 2021

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)

  • \begin{equation*} N(\varepsilon)\coloneq\lceil\frac{4}{\varepsilon^2}\rceil \end{equation*}
    image
    turns into "" syntax-error

  • \begin{equation*} x_{1,2}=1,2 \end{equation*}
    image
    turns into ["Equal", ["Subscript", "x", {num: "12"}], {num: "12"}]. Notice how the comma is missing

  • \begin{equation*} \{1,2\} \end{equation*}
    image
    turns into ["Multiply", "\\{", {num: "12"}, "\\}"]. I assume this happens because sets haven't been implemented yet

  • \begin{equation*} [1,2] \end{equation*}
    image
    turns into "" syntax-error. I assume this happens because vectors/matrices and the like haven't been implemented yet.



  • \begin{equation*} \frac{2}{\sqrt{n}}\Leftrightarrow n>\frac{5}{n^2} \end{equation*}
    image
    turns into the following, notice how \\Leftrightarrow doesn't have a special meaning and its precedence is off
[
  "Greater",
  [
    "Multiply",
    ["Divide", 
      {num: "2"}, ["Sqrt", "n"]],
    "\\Leftrightarrow",
    "n"
  ],
  ["Divide", 
    {num: "5"}, ["Power", "n", 2]]
]


  • \begin{equation*} |a_n|\le\frac{2}{\sqrt{n}}\Rightarrow a_n\to0=0 \end{equation*}
    image
    turns into the following, notice how \\Rightarrow doesn't have a special meaning (implies) and its precedence is off.
[
  "LessEqual",
  ["Abs", ["Subscript", "a", "n"]],
  [
    "Equal",
    [
      "To",
      [
        "Multiply",
        ["Divide", 
          {num: "2"}, ["Sqrt", "n"]],
        "\\Rightarrow",
        ["Subscript", "a", "n"]
      ],
      
      {num: "0"}
    ],
    
    {num: "0"}
  ]
]
  • \begin{equation*} 3\equiv5\mod7 \end{equation*} or also \begin{equation*} 3\equiv 5 (\mod 7) \end{equation*}
    image
    This is a congruence relation. I assume this is simply something that hasn't been implemented yet. Hopefully it's a good test case for round-tripping

  • \begin{equation*} a={\displaystyle \lim_{n\to\infin}a_n} \end{equation*}
    image
    turns into

["Equal", "a", "Missing"]
syntax-error
  • \begin{equation*} \forall x\in\C^2:|x|<0 \end{equation*}
    image
    turns into the following
[
  "Element",
  ["Multiply", "\\forall", "x"],
  ["Power", "ComplexNumber", 2]
]
syntax-error
  • \begin{equation*} \forall n\colon a_n\le c_n\le b_n\implies\lim_{n\to\infin}c_n=a \end{equation*}
    image
    turns into the following, note how a few operators aren't parsed and how the precedences for other operators are slightly off. I think the correct order of operations in this case would start at the :, then the => and then the normal rules. Another interesting tidbit here are the two <= signs. While a comparison would usually return a boolean value (true/false), here the comparisons are more like a range.
    The expression is a part of the squeeze theorem.
[
  "LessEqual",
  [
    "Multiply",
    "\\forall",
    "n",
    "\\colon",
    ["Subscript", "a", "n"]
  ],
  [
    "LessEqual",
    ["Subscript", "c", "n"],
    [
      "Equal",
      [
        "Multiply",
        ["Subscript", "b", "n"],
        "\\implies",
        ["Subscript", "\\lim", ["To", "n", "\\infin"]],
        ["Subscript", "c", "n"]
      ],
      "a"
    ]
  ]
]
@arnog
Copy link
Member

arnog commented Jul 1, 2021

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
Copy link
Contributor Author

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
Copy link
Member

arnog commented Jul 1, 2021

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
Copy link
Contributor Author

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
Copy link
Contributor Author

stefnotch commented Aug 10, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants