How to evaluate MathML expressions?

Given some MathML content:

<apply> <eq/> <ci>c</ci> <apply> <plus/> <ci>a</ci> <ci>b</ci> </apply> </apply> 

and

 std::map<std::string,std::double> cal; cal["a"] = 1.; cal["b"] = 2.; cal["c"] = 0; // does not matter what c is 

I want to evaluate MathML and get results. Is there any way to do this?

+6
c ++ c xml mathml
source share
2 answers

MathML has both a semantic and a presentation bonus. Thus, a common MathML analyzer for evaluation is not possible.

I don’t know about the real implementation, some quick Googling did not find any reasonable results, but basically it comes down to writing your Polish expression interpreter (as an example that you gave in Polish notation). Steps:

  • get the XML parser and read in the document
  • go through a tree
  • if you encounter a known operation or item, put it on the stack
  • when the subexpression is complete, analyze it (or better: wait for the entire expression to complete, find the last operation, execute it with the number of arguments that its attribute prescribes and execute it until no operations are left)

In the end, you will get the result on the stack.

+3
source share

One way is to find a computer algebraic system (CAS) that can import math. Unfortunately, despite the fact that many programs export mathematics, almost no one reads it. Here are some links to several systems:

CasADi (not strictly CAS, but can evaluate expressions): https://sourceforge.net/apps/trac/casadi/ticket/149

SymPy: http://code.google.com/p/sympy/issues/detail?id=2971

Matlab / MuPAD: http://www.mathworks.nl/help/toolbox/mupad/generate/MathML.html

0
source share

All Articles