Arbitrary-precision formula parser and solver.
Project description
formula - Arbitrary-precision formula parser and solver
Development status
Status: Beta
Development plan:
- Complex numbers support. (Character
i
are reserved for this by default.) - Support getting all variables, numbers, functions after parsing.
- Examples.
- Support the LongReal from python. Auto conversion in the get method. Try ... any?
This project built with pybind11.
Installation
On Unix (Linux, OS X)
pip install formula
On Windows (Requires Visual Studio 2015)
-
For Python 3.5+:
- clone this repository
pip install ./formula
-
For earlier versions of Python, including Python 2.7:
Pybind11 requires a C++11 compliant compiler (i.e. Visual Studio 2015 on Windows). Running a regular
pip install
command will detect the version of the compiler used to build Python and attempt to build the extension with it. We must force the use of Visual Studio 2015.- clone this repository
"%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" x64
set DISTUTILS_USE_SDK=1
set MSSdk=1
pip install ./formula
Note that this requires the user building
formula
to have registry edition rights on the machine, to be able to run thevcvarsall.bat
script.
Windows runtime requirements
On Windows, the Visual C++ 2015 redistributable packages are a runtime requirement for this project. It can be found here.
If you use the Anaconda python distribution, you may require the Visual Studio runtime as a platform-dependent runtime requirement for you package:
requirements:
build:
- python
- setuptools
- pybind11
run:
- python
- vs2015_runtime # [win]
Documentation
The formula contains case sensitive (by default) string parser.
Let's imagine that we have a string expression, e.g. "(x^2+y)/sin(a*z)"
.
We want to calculate the value of this function in the following point:
x=0.001, y=0.0000000000000000000000555, z=-2, a=-1,
So we pass the expression to the formula
constructor.
from formula import formula
f5a = formula("(x^2+y)/sin(a*z)")
And it is enough to call the get(...)
method or the getD(...)
to calculate
the value of the expression or the derivative of the expression at this point.
variables = {
"x": "0.001",
"y": "0.0000000000000000000000555",
"z": "-2",
"a": "-1",
}
value = f5a.get(variables)
x_derivative = f5a.getD("x", variables)
z_derivative = f5a.getD("z", variables)
License
formula is provided under Apache license that can be found in the LICENSE file. By using, distributing, or contributing to this project, you agree to the terms and conditions of this license.
Test call
from formula import formula
pi = formula("2*asin(x)", 64).get({"x": "1"})
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 Distributions
Hashes for formula-1.0.0b3-py3.6-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5984043912c07d1c8f39ba2b0b19df868f03629496b4eb1307a50e46397646e |
|
MD5 | 43ce1b773553be5428907d10fd3e2250 |
|
BLAKE2b-256 | 0d81c54a60c4d062e7d322b584b7ff3dd312ddf3a01dda0d4662bbd6178cd26a |
Hashes for formula-1.0.0b3-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f66c52a2298777cee8253d74db2e350b6d293371fba25e9dbd52bd445564f3e4 |
|
MD5 | 14a0caabedd3076a3cabb74b1bb8ab6f |
|
BLAKE2b-256 | 7847a42b9e94b503c34cd9f1df5d6bcfce661a37e4ce0cfcfc877988f44417d3 |
Hashes for formula-1.0.0b3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96c04bf6c137c6adc7c680b20a562c066d8b70aeb0ec6e468cb8b6d217f1e5bb |
|
MD5 | 69941559b8015a6dc5cb14d8f8ef32ce |
|
BLAKE2b-256 | eefeb925e02c0599973a845ff36996724c1ca55e1656de615aa50c0c1ec01309 |