开发者

How to evaluate MathML expressions? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 5 years ago.

Improve this question

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 开发者_JAVA百科is

I wish to evaluate the MathML and retrieve the results. Is there any way to do this?


MathML has both semantic and presentational mark-up. So a generic MathML parser for evaluation is not possible.

I don't know of an actual implementation, some quick Googling did not find any reasonable results, but it basically boils down to writing your Polish expression interpreter (as the example you gave is in Polish notation). The steps:

  1. get an XML parser and read in the document
  2. walk through the tree
  3. if you encounter a known operation or element, pop it on a stack
  4. when the subexpression is complete, parse it (or better: wait for the entire expression to finish, look for the last operation, perform it with the number of arguments its arity prescribes and perform this until no operations are left)

At the end you'll have your result on the stack.


One way is to find a Computer Algebra System (CAS) that can import mathml. Unfortunately, while a lot of software exports mathml, almost none of it reads it. Here are some related links for a few cas systems:

CasADi (not strictly a 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜