Click here to Skip to main content
15,896,467 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how i can transform the MathMl tags into stream of words (string)
for example:

XML
<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"><mml:msqrt><mml:msup><mml:mrow><mml:mi>a</mml:mi></mml:mrow><mml:mrow><mml:mn>2</mml:mn></mml:mrow></mml:msup><mml:mo>+</mml:mo><mml:msup><mml:mrow><mml:mi>b</mml:mi></mml:mrow><mml:mrow><mml:mn>2</mml:mn></mml:mrow></mml:msup></mml:msqrt></mml:math>

how i can transform the last formula to string like this "sqrt(a^2+b^2)"

i used the MMLtoCSharp but it transform formula to code like this:
double a = 0.0;
double b = 0.0;
Math.Sqrt(*a*a+b*b);
Posted
Updated 27-Jun-16 6:09am
v5
Comments
Richard MacCutchan 27-Jun-16 9:26am    
i want to build math search system for my master thesis
Then you are expected to do the work. Otherwise it is not your thesis

please help me
People here will help you, but you need to ask a specific question. No one is going to write your thesis or develop your code.
Member 12484974 27-Jun-16 10:29am    
which i need, its sub problem from my project
Richard MacCutchan 27-Jun-16 11:31am    
Sorry, I don't understand that comment.
[no name] 27-Jun-16 10:37am    
Take a look at this article : http://www.codeproject.com/Articles/30615/Converting-math-equations-to-C
Sergey Alexandrovich Kryukov 27-Jun-16 12:22pm    
It will make a fair answer. Will you post it with proper attribution as a formal answer using "Add your solution here"?
—SA

1 solution

If you want to do it to some reasonable extent (please see next paragraph), this is not extremely hard to do, but will be a big piece of work.

More importantly, most of advanced symbolic mathematical entities cannot be translated into an expression in any algorithmic language. One basic example is the integral. Of course, if this is, say, the integral of sin(x) dx, it can be done, but in general case this is theoretically impossible.

So, if you want to limit such transformation to a limited set of mathematical operations roughly matching the set of .NET BCL System.Math operations and reject all other cases, you can do it. After all, MathML is expressed in XML, which represents an expression tree (binary expression tree ). You can use any of the XML parsing libraries to parse MathML code in a kind of DOM. From this DOM, you can generate a C# strings. The parent-child relationships between nodes will define the structure of the expression, the order and () brackets, and text nodes will represent the terminal expression nodes (such as "2" in your example), or the variable names.

Note that some MathML entities have nothing to do with mathematical expressions. One example is the concept of "row", which is related just to the graphical representation. You can effectively ignore this problem, by considering such node as a regular sub-expression. You just take in in brackets on output, without any operation (you can consider a sub-expression without operation as a "trivial" sub-expression, a unary operation which does nothing). Certainly, you may get a lot of redundant round brackets; you may decide to optimize it or not.

MathML syntax and semantics is fully described here: W3 Math.

This is all you need.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900