Utilities for MathJSON evaluation
Project description
MathJSON Solver
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.
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mathjson_solver-1.14.0.tar.gz
.
File metadata
- Download URL: mathjson_solver-1.14.0.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 575e9e11a17bd340699d42353e8d9bafe37be7ac918e0963f5fc72f63c6944cc |
|
MD5 | c4edaa7e54c47fa15388cbd0fe6c7ec7 |
|
BLAKE2b-256 | 09ff64dc629dc1394b133f1ce3b01f459a481c8fa748426f6e4a2e27c5552790 |
File details
Details for the file mathjson_solver-1.14.0-py3-none-any.whl
.
File metadata
- Download URL: mathjson_solver-1.14.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 111930d6456e9f18e6b49cb77e1504d225143e5f48177e6633ae6bf04cbbf01c |
|
MD5 | d8ba4009a42398f34cae8a86d58b7f7e |
|
BLAKE2b-256 | 6c24cc42e644f538789abe8a73f9cc146bd879c07381d84e4da014811fa2bc3b |