English 中文(简体)
How to evaluate MathML expressions? [closed]
原标题:

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 6 years ago.

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 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





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签