Skip to main content

Easy conversions between different styles of expressions

Project description

formulate

Actions Status Documentation Status

PyPI version Conda-Forge PyPI platforms

GitHub Discussion Scikit-HEP

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

formulate-1.0.0rc1.tar.gz (73.7 kB view details)

Uploaded Source

Built Distribution

formulate-1.0.0rc1-py3-none-any.whl (72.3 kB view details)

Uploaded Python 3

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

Hashes for formulate-1.0.0rc1.tar.gz
Algorithm Hash digest
SHA256 cdf70ea38b9d9812b066973f98881d8bfc64f068108fb68abfdc160ff660dcdf
MD5 8699ea638f116c7f413931909c0d7f1f
BLAKE2b-256 1042d2d68adf3dabf7ab108caa1c92f5491bd25552f1054367f8cc8499465f77

See more details on using hashes here.

Provenance

The following attestation bundles were made for formulate-1.0.0rc1.tar.gz:

Publisher: cd.yml on scikit-hep/formulate

Attestations:

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

Hashes for formulate-1.0.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 19cf3d4a631d5a5209a6c650af8a7fc15acadc051171c2917f788683e6df7695
MD5 c1ab3d133411ce5152f18ee7039ada86
BLAKE2b-256 9a139f704e54914cf8506c352b0aacdd40a29e8081417993c7b084e21598a696

See more details on using hashes here.

Provenance

The following attestation bundles were made for formulate-1.0.0rc1-py3-none-any.whl:

Publisher: cd.yml on scikit-hep/formulate

Attestations:

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page