Supported Expressions
Formulate supports a wide range of expressions in both ROOT and numexpr formats. This page documents the supported expression types and syntax.
Operators
Arithmetic Operators
Both ROOT and numexpr support the following arithmetic operators:
Operator |
ROOT Example |
numexpr Example |
---|---|---|
Addition (+) |
|
|
Subtraction (-) |
|
|
Multiplication (*) |
|
|
Division (/) |
|
|
Power (**) |
|
|
Modulo (%) |
|
|
Comparison Operators
Operator |
ROOT Example |
numexpr Example |
---|---|---|
Equal (==) |
|
|
Not Equal (!=) |
|
|
Greater Than (>) |
|
|
Less Than (<) |
|
|
Greater Than or Equal (>=) |
|
|
Less Than or Equal (<=) |
|
|
Logical Operators
Operator |
ROOT Example |
numexpr Example |
---|---|---|
AND |
|
|
OR |
|
|
NOT |
|
|
Functions
Formulate supports many mathematical and utility functions. Here are some commonly used functions:
Mathematical Functions
Function |
ROOT Syntax |
numexpr Syntax |
---|---|---|
Square Root |
|
|
Absolute Value |
|
|
Exponential |
|
|
Logarithm (natural) |
|
|
Logarithm (base 10) |
|
|
Sine |
|
|
Cosine |
|
|
Tangent |
|
|
Arc Sine |
|
|
Arc Cosine |
|
|
Arc Tangent |
|
|
Arc Tangent (2 args) |
|
|
Hyperbolic Sine |
|
|
Hyperbolic Cosine |
|
|
Hyperbolic Tangent |
|
|
Floor |
|
|
Ceiling |
|
|
Statistical Functions
Function |
ROOT Syntax |
numexpr Syntax |
---|---|---|
Error Function |
|
|
Complementary Error Function |
|
|
Gamma Function |
|
Not directly supported |
Log Gamma Function |
|
Not directly supported |
Complex Expressions
Formulate can handle complex expressions combining multiple operators and functions:
# ROOT expression
# TODO: doesn't work yet?
root_expr = "TMath::Sqrt(px**2 + py**2 + pz**2) > 10 && TMath::Abs(eta) < 2.5"
# Equivalent numexpr expression
numexpr_expr = "sqrt(px**2 + py**2 + pz**2) > 10 & abs(eta) < 2.5"
# Convert between them
from_root = formulate.from_root(root_expr)
print(from_root.to_numexpr()) # Outputs the numexpr version
from_numexpr = formulate.from_numexpr(numexpr_expr)
print(from_numexpr.to_root()) # Outputs the ROOT version
Limitations
While Formulate supports a wide range of expressions, there are some limitations:
Function Support: Not all functions available in ROOT or numexpr are supported for conversion. If you encounter an unsupported function, please check the API documentation or consider contributing to add support.
Complex Data Types: Formulate primarily focuses on scalar operations. Operations on complex data types like arrays may have limited support.
Custom Functions: User-defined functions are not automatically supported for conversion.
Recursion Depth: Very complex nested expressions might hit recursion limits. If you encounter such issues, consider increasing the recursion limit in Python or simplifying the expression, via
sys.setrecursionlimit(N)
, withN
above 10’000.
For more details on specific limitations or to request support for additional expressions, please refer to the Common Issues page or open an issue on the GitHub repository.