SymEngine.py is a Python library providing high-performance wrappers to the SymEngine C++ symbolic manipulation library. It aims to offer a fast and efficient alternative for symbolic mathematics in Python, often used as a backend for SymPy or independently. The library is actively maintained, with frequent releases that typically follow updates to the core C++ SymEngine library.
pip install symengineVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define symbolic variables, create an expression, compute a derivative, and perform substitutions using SymEngine.
Ensure your Python environment meets the `requires_python` specification for the installed SymEngine version. Upgrade or downgrade Python as necessary.
If specific `lambdify` behavior is required, explicitly specify the `backend` argument. Ensure LLVM is correctly configured if you intend to use the LLVM backend for performance.
Adjust code that expects mutable matrices after conversion or matrix operations. If mutability is critical, explicitly convert to a mutable matrix type after the operation.
For ease of installation, use pre-built wheels via `pip install symengine` or the `conda` package. If building from source, ensure `cmake` is installed and the C++ SymEngine library is at a compatible version as specified in the `symengine.py` repository.
Minimize explicit conversions between SymEngine and SymPy objects. If performance is critical, try to keep calculations within the SymEngine domain as much as possible. Consider using `symengine` as a backend for `sympy` where supported.
Install the appropriate C++ build tools for your operating system (e.g., 'Build Tools for Visual Studio' on Windows, `build-essential` package on Debian/Ubuntu, Xcode Command Line Tools on macOS).
Install the library using `pip install symengine` in your active Python environment.
Install the Boost development libraries for your operating system (e.g., `libboost-dev` on Debian/Ubuntu, `boost` via Homebrew on macOS, or manually download/build on Windows and ensure relevant environment variables are set).
Convert SymPy objects to Symengine objects using `symengine.convert` or define variables using `symengine.Symbol` directly when working with Symengine. Example: `symengine.sin(symengine.convert(x_sympy))` or `x_symengine = symengine.Symbol('x'); symengine.sin(x_symengine)`.