Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mathematical formulas: parsing and canonical *programming* form

Tags:

math

haskell

tex

Is there any conventional format to represent a mathematical formula, that could be read by a computer?

I'm working on some mathematical problems, and have some kind of TDD approach to it. Every time I get stuck in a proof (or simply that I have no proof yet, but some intuition of what the result should be), I tend to write a little program to check that everything so far behaves as I'm thinking it does. I usually write a Haskell function for some intermediary result in my proof, play with it through GHCi until I'm convinced I'm still going in the right direction.

My absolute ideal would be to have some canonical form for math formulas which I could, using some tool, both output to LaTeX and Haskell. I could run QuickTest on it, and if a step is wrong, it would tell me. LaTeX's mathematical notations are actually pretty close to a canonical form, though a lot is inferred by the reader (you don't want to explicitly write every parentheses).

This ideal tool seems too good to be true; rather, what would be the correct way to spell out a mathematical formula for a computer, possibly parsing it as well? While looking around, I saw a lot for simple formulas using solely *,+,-,/ and the like. Nothing encompassing things like sums (e.g. over sets), derivatives, all the "cool" stuff. Moreover, the output of such parsers are mostly used to calculate a result, giving some values for the variables; not for translating it to other languages (language agnostic, I guess). It seems like something like this should either already exist, or there should be a good reason why not. Which one did I miss?

like image 842
Nicolas Mattia Avatar asked Sep 27 '22 04:09

Nicolas Mattia


1 Answers

The standard computer representation of mathematical notation is MathML. Note that it includes both Presentation MathML, which represents the way mathematical expressions are written and can be converted to LaTeX, and Content MathML which is intended to represent the meaning of expressions and is what you'd need for translation to Haskell or another programming language (but I don't know of any tool which does such translation).

Of course, you wouldn't want to write (either flavor of) MathML manually; there are some editors which produce it, but I can't recommend one.

Otherwise, OpenMath could be an option. It seems to be oriented exactly towards people "working with mathematics on computer".

like image 158
Alexey Romanov Avatar answered Nov 15 '22 10:11

Alexey Romanov