2

I have a mathml expression suppose:

<math><msup><mi>x</mi><mn>2</mn></msup></math>

I need to make x^2 from this say math notation.

I checked a lot and find out certain solutions but all refers the opposite thing, ie, making mathml from math notation.

Reference

I need just the opposite.

Making math notation from mathml.

Note: I need a generalised thing that should work on all conditions of mathml?

Python version: 3.4

Santhucool
  • 1,656
  • 2
  • 36
  • 92
  • 3
    possible duplicate of [Alternative for python-mathdom](http://stackoverflow.com/questions/6188082/alternative-for-python-mathdom) – swenzel Aug 24 '15 at 11:37
  • My python version is 3.4. Sadly that library support only on 2.6 and 2.7 – Santhucool Aug 24 '15 at 13:25
  • @Santhucool do you or your colleagues have the skill to port this library to Python 3.4? – shuttle87 Aug 24 '15 at 15:11
  • @shuttle87 it will be a tedious task!! Why python does not have version compatibility? Thats y java is still the best!! – Santhucool Aug 25 '15 at 04:10
  • @Santhucool, if it's worth it to your team you could always port if need be, there's tools to help that, for example the 2to3 tool. This particular library happens to interest me and I'd be happy to port it given the means (translation: some nominal amount of money). The reason Python 3 broke backwards compatibility was to fix core problems with the language that couldn't otherwise be fixed. As someone who uses Java professionally the backwards compatibility is great but we have to recognize that it does come with a very real cost, that being the enormous amount of cruft in the language. – shuttle87 Aug 25 '15 at 14:21
  • Not sure if anyone's still interested, but, as nearly as I can tell, MathML appears to be more of a formatting language, not a "function representing" language. Having said that, I might be able to help by running the MathML through Mathematica and then converting it w/ some tools I wrote. –  Sep 15 '17 at 15:49

1 Answers1

2

The answer below assumes that you have Maple installed. Maple can parse MathML code that can be converted later using the CodeGeneration package to the following programming languages:

C, CSharp, Fortran, IntermediateCode, Java, JavaScript,
Julia, LanguageDefinition, Matlab, Names, Perl,
Python, R, Save, Swift, Translate, VisualBasic

Here is an example:

  • Copy the MathML code.
  • Open Maple, and paste. You will see this message box:

enter image description here

  • Clicking on Yes, you will see:

enter image description here

  • Load the CodeGeneration package, and call the Python function:
with(CodeGeneration)
Python(cos(x)^2 + sin(x)^2 = 1, resultname = "expr1")

The result will be:

expr1 = math.cos(x) ** 2 + math.sin(x) ** 2 == 1

You can adjust the result accordingly.

s.ouchene
  • 1,682
  • 13
  • 31