Code Monkey home page Code Monkey logo

mathml.jl's Introduction

MathML

Github Action CI Coverage Status ColPrac: Contributor's Guide on Collaborative Practices for Community Packages

A parser for the MathML XML standard.

Uses Symbolics.jl under the hood for defining equations and uses EzXML.jl for XML parsing.

MathML Specification: https://www.w3.org/TR/MathML3/

Examples:

using MathML, EzXML, Symbolics, AbstractTrees
xml = xml"""<math xmlns="http://www.w3.org/1998/Math/MathML">
   <apply>
      <times />
      <ci>compartment</ci>
      <ci>k1</ci>
      <ci>S1</ci>
   </apply>
</math>"""

num = parse_node(xml)
# 1-element Vector{Num}:
#  S1*compartment*k1

# to pretty print the tree use `print_tree`
print_tree(xml)
# math
# └─ apply
#    ├─ times
#    ├─ ci
#    ├─ ci
#    └─ ci

# you can also just go directly from EzXML.Document or String
str = "<apply><power/><ci>x</ci><cn>3</cn></apply>"
MathML.parse_str(str)
# x^3

# derivatives also work!
str = """
<apply><diff/>
  <bvar><ci>x</ci><degree><cn>2</cn></degree></bvar>
  <apply><power/><ci>x</ci><cn>4</cn></apply>
</apply>
"""
expand_derivatives(MathML.parse_str(str))
# 12(x^2)

# there is also a macro @MathML_str to directly call `parse_str`
ml = MathML"""
<apply><diff/>
  <bvar><ci>x</ci><degree><cn>2</cn></degree></bvar>
  <apply><power/><ci>x</ci><cn>4</cn></apply>
</apply>
"""
expand_derivatives(ml)
# 12(x^2)

Check the tests in test/parse.jl to see a more exaustive list of what is covered.

TODO:

  • calculus:
    • ivars fix, make ODESystem(parse_node(readxml("lorenz.xml").root)) work
    • partial derivatives partialdiff tags
    • integration int tags - needs JuliaSymbolics/Symbolics.jl#58
      • often a var like dPidt is assigned to Differential(time)(Pi) where dPidt is refered to after this <eq> (I think solution is Symbolics.diff2term)
    • diffs with no independent variable: like <apply><diff/><ci>f</ci></apply>

DONE:

  • nested apply
  • fix sep/ tags in cn, take type attribute into account
    • rational, e-notation, complex, complex polar
  • basic diff handling
  • bound variables like bvar, might be lingering issues though
  • eq nodes sometimes needs to be ~ and sometimes needs to be =
  • fix sep tags in cis, take type attribute into account
  • piecewise tags: make heaviside test work
  • fix undefined namespacing issues JuliaIO/EzXML.jl#156
    • parsers like SBML and CellMLToolkit should be handling
  • to_mathml: julia expr -> mathml and Symbolics Num -> mathml. round tripping

mathml.jl's People

Contributors

anandijain avatar chrisrackauckas avatar dependabot[bot] avatar github-actions[bot] avatar oscardssmith avatar thazhemadam avatar shahriariravanian avatar ven-k avatar paulflang avatar arnostrouwen avatar devmotion avatar ranocha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.