Easy conversions between different styles of expressions
Project description
formulate
Formulate
Easy conversions between different styles of expressions. Formulate currently supports converting between ROOT and numexpr style expressions.
Installation
Install formulate like any other Python package:
pip install --user formulate
or similar (use sudo
, virtualenv
, or conda
if you wish).
Usage
API
The most basic usage involves calling from_$BACKEND
and then to_$BACKEND
, for example when starting with a ROOT style expression:
>>> import formulate
>>> momentum = formulate.from_root('TMath::Sqrt(X_PX**2 + X_PY**2 + X_PZ**2)')
>>> momentum
Expression<SQRT>(Expression<ADD>(Expression<POW>(Variable(X_PX), UnnamedConstant(2)), Expression<POW>(Variable(X_PY), UnnamedConstant(2)), Expression<POW>(Variable(X_PZ), UnnamedConstant(2))))
>>> momentum.to_numexpr()
'sqrt(((X_PX ** 2) + (X_PY ** 2) + (X_PZ ** 2)))'
>>> momentum.to_root()
'TMath::Sqrt(((X_PX ** 2) + (X_PY ** 2) + (X_PZ ** 2)))'
Similarly, when starting with a numexpr
style expression:
>>> my_selection = formulate.from_numexpr('X_PT > 5 & (Mu_NHits > 3 | Mu_PT > 10)')
>>> my_selection.to_root()
'(X_PT > 5) && ((Mu_NHits > 3) || (Mu_PT > 10))'
>>> my_selection.to_numexpr()
'(X_PT > 5) & ((Mu_NHits > 3) | (Mu_PT > 10))'
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 formulate-1.0.0rc1.tar.gz
.
File metadata
- Download URL: formulate-1.0.0rc1.tar.gz
- Upload date:
- Size: 73.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdf70ea38b9d9812b066973f98881d8bfc64f068108fb68abfdc160ff660dcdf |
|
MD5 | 8699ea638f116c7f413931909c0d7f1f |
|
BLAKE2b-256 | 1042d2d68adf3dabf7ab108caa1c92f5491bd25552f1054367f8cc8499465f77 |
Provenance
The following attestation bundles were made for formulate-1.0.0rc1.tar.gz
:
Publisher:
cd.yml
on scikit-hep/formulate
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
formulate-1.0.0rc1.tar.gz
- Subject digest:
cdf70ea38b9d9812b066973f98881d8bfc64f068108fb68abfdc160ff660dcdf
- Sigstore transparency entry: 146772754
- Sigstore integration time:
- Predicate type:
File details
Details for the file formulate-1.0.0rc1-py3-none-any.whl
.
File metadata
- Download URL: formulate-1.0.0rc1-py3-none-any.whl
- Upload date:
- Size: 72.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19cf3d4a631d5a5209a6c650af8a7fc15acadc051171c2917f788683e6df7695 |
|
MD5 | c1ab3d133411ce5152f18ee7039ada86 |
|
BLAKE2b-256 | 9a139f704e54914cf8506c352b0aacdd40a29e8081417993c7b084e21598a696 |
Provenance
The following attestation bundles were made for formulate-1.0.0rc1-py3-none-any.whl
:
Publisher:
cd.yml
on scikit-hep/formulate
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
formulate-1.0.0rc1-py3-none-any.whl
- Subject digest:
19cf3d4a631d5a5209a6c650af8a7fc15acadc051171c2917f788683e6df7695
- Sigstore transparency entry: 146772757
- Sigstore integration time:
- Predicate type: