Ask Your Question
1

Parse and Evaluate MathML

asked 2011-04-29 09:32:37 +0100

Nobody gravatar image

updated 2011-04-30 11:35:32 +0100

benjaminfjones gravatar image

Is there a possibility to parse content-mathml in Sage?

I would like to evaluate a formula that is given in a content-mathml document. How would I do this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-01-03 01:38:07 +0100

vdelecroix gravatar image

updated 2016-01-03 01:38:33 +0100

Sage is based on Python which implies that any Python module is (in principle) usable from Sage. As there are modules to deal with mathml content in Python (such as mathdom you can do the following

Install the mathdom module within sage: within a console do

me@home$ sage -pip install mathdom
me@home$ sage -pip install lxml

(As a prerequisite, I needed to install to packages into my linux distribution, namely "libxslt1-dev")

Then, launch sage and use mathdom (the example is taken from mathdom website)

me@home$ sage
sage: from mathml.lmathdom import MathDOM
sage: doc = MathDOM.fromString("+2^x+4*-5i/6","infix_term")
sage: for apply_tag in doc.xpath(u'//math:apply[math:plus]'):
....:     apply_tag.set_operator(u'minus')
sage: [ n.value() for n in doc.xpath(u'//math:cn') ]
[2, 4, Complex(0-5j), 6]
sage: from mathml.utils import pyterm
sage: doc.serialize("python")
u'2 ** x - 4 * (-5j) / 6'
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-04-29 09:32:37 +0100

Seen: 3,802 times

Last updated: Jan 03 '16