Python Math Expression Parser
Project description
python.math.expression.parser.pymep
pymep can parse or evaluate math expressions.
This algorithm does not use a decision tree. It is a kind of Recursive Ascent Parser (https://en.wikipedia.org/wiki/Recursive_ascent_parser). In fact, it is LR parser (Left-Right Parser) without backtracking. This recursive algorithm is faster than decision trees
pypi version
https://pypi.org/project/pymep/
Installation
pip install pymep
Examples
Here you can see some examples:
Real Numbers:
from pymep.realParser import parse
from pymep.realParser import eval
#Real Expresion parser
fx="cos(10)"
print(parse(fx))
xi=5
fx = "1 + x"
print(eval(fx, xi))
var = {"x":"1+1", "Z":1}
eval(" 2*(-(((z*3)*sqrt(x^(2)))+3))",var)
For Complex Numbers:
from pymep.complexParser import parse
from pymep.complexParser import eval
from pymep.complex import Complex
#Operation with complex numbers
a = Complex(1,2)
print(a.__radd__(10).__complex__())
print(Complex.radd(10, a).__complex__())
#Complex Expresion parser
fx="cos(10+2j)"
print(parse(fx).__complex__())
xi=5
fx = "1 +j+x"
print(eval(fx, xi).__complex__())
var={"x":"1+2j", "Y":complex(2,1)}
f_x = "x-y"
eval(f_x,var).__complex__()
There is a full list of examples inside!!
Enjoy it!!
The java version of this library is: https://github.com/sbesada/java.math.expression.parser
NOTE: Regarding to the OS where you excute the tests, it is possible that some tests fail beacause of rounding issues. The mathematical library that was used in this project is "math". In the future, it is possible that the math library changes.
PD: If you think that my work deserves a donation, you can do it: https://sbesada.github.io/
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pymep-1.0.7.tar.gz.
File metadata
- Download URL: pymep-1.0.7.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9dcc2cfbb9e2c3d31ac28817457e8d0d4d7bcd070cb9130829fe8661b1088471
|
|
| MD5 |
6e41f0337777398340ebd2c09b4b37e9
|
|
| BLAKE2b-256 |
a19c784c3ae45d6d05cecc4e57cf3ca77346409f2fdd8f08af6d815372018dc8
|
File details
Details for the file pymep-1.0.7-py3-none-any.whl.
File metadata
- Download URL: pymep-1.0.7-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48806faf7291f2f84fe4b302288536e57caa01eb3a9fd9ca52f918336a67a948
|
|
| MD5 |
e718cccf7d8250f5bc1035b794f04e01
|
|
| BLAKE2b-256 |
90065d96d9b09e40470e05d79871a8a8a5f5b270bd2709364c45f85538306a85
|