Skip to content

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

MathJSON Solver

PyPI PyPI Downloads Coverage

MathJSON Solver is a Python module to numerically evaluate MathJSON expressions, like ["Add", 1, 2]. It is developed by Longenesis to enable numerical evaluation of user provided mathematical expressions in Longenesis digital health products. Its development was inspired by CortexJS Compute Engine.

Please ask questions and share feedback in our Gitter chat https://gitter.im/mathjson-solver/community. Gitter

How to use

from mathjson_solver import create_solver

parameters = {"x": 2, "y": 3}
expression = ["Add", "x", "y", 4]

solver = create_solver(parameters)
answer = solver(expression)

print(answer)
# 9, because 2+3+4=9

Currently supported constructs

Find the full list of supported constructs in the docs/README.md.

Exception handling

A MathJSONException is raised when expression cannot be evaluated. Import MathJSONException to handle it:

from mathjson_solver import create_solver, MathJSONException

solver = create_solver({})
try:
    solver(["Divide", 1, 0])
except MathJSONException:
    pass
    # invoke your own exception logger here

Left unhandled, the exception will look like MathJSONException("Problem in Divide. ['Divide', 1, 0]. division by zero").

How to run tests

Make sure you have pytest installed. Then cd into project directory and run:

pytest

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages