pymittagleffler documentation#

Installation#

This package provides bindings around the Rust crate mittagleffler. It can be directly installed from PyPI using

python -m pip install pymittagleffler

For development, you need to clone this repository and go into the python folder. We use maturin as the build system, since this library is just a thin wrapper around some Rust code. To install into your virtual environment, run

python -m pip install --verbose --no-build-isolation --editable .

This assumes that you have the build requirements already installed. In general, the library follows the standard Python packaging rules, so read up on them in the official Python packaging guides if any of this sounds confusing.

Example#

As a simple example of the use of the functionality in this library, we will evaluate the Mittag-Leffler function for several parameters of interest. The function itself is defined most directly by the series expansion

\[E_{\alpha, \beta}(z) = \sum_{k = 0}^\infty \frac{z^k}{\Gamma(\alpha k + \beta)}\]

where \(\Re\{\alpha\} > 0\) and \(\beta \in \mathbb{C}\) is arbitrary. There are also some nicer integral representations of the function, but this is useful enough to get an idea of what we’re dealing with. For some more information see its Wikipedia article.

We setup up our evaluation as follows for some purely complex values of \(z\).

 1import numpy as np
 2
 3from pymittagleffler import mittag_leffler
 4
 5alphas = (0.5, 1.0, 2.0)
 6betas = (1.0, 1.5, 2.0)
 7
 8arg = np.pi / 2
 9r = np.linspace(0.0, 12.0, 256)
10z = r * np.exp(1j * arg)
11
12result = np.empty((len(alphas), z.size), dtype=z.dtype)
13for i, (alpha, beta) in enumerate(zip(alphas, betas, strict=True)):
14    result[i] = mittag_leffler(z, alpha, beta)

This gives the following behaviour of the Mittag-Leffler function for the chosen parameters. We can see that it exhibits a wide range of behaviors, both oscillatory and fast decaying.

Real part of the Mittag-Leffler function Imaginary part of the Mittag-Leffler function

Performance#

Warning

This is simply a preliminary look at the performance of the library. Further optimizations are possible and any suggestions or tests in this direction are very welcome.

The results below have been generated using bench_python.py. They compare the implementation based on Python bindings to the Rust crate, a pure Python implementation of the same algorithm from Garrappa (2015, doi:10.1137/140971191) and the associated MATLAB implementation.

Comparison with the pymittagleffler library.

The benchmark computes the Mittag-Leffler function of a vector of 256 complex numbers with a fixed \(\beta\) and over a range of \(\alpha\) parameters. The vertical axis shows the ratio of the minimum time of each implementation to the minimum time of the fully threaded Rust implementation, using the best of 32 timed runs. The all-threaded Rust implementation is therefore at \(1 \times\) and larger values are slower. The separate single-threaded Rust series separates the algorithmic speedup from the parallel one.

The all-threaded results use all available cores. Their number can be controlled with the RAYON_NUM_THREADS environment variable. Note that the Python reference is intended as a straightforward pure Python implementation of the same algorithm, not as an optimized NumPy implementation.

Parameter performance of the pymittagleffler library.

This benchmark computes the Mittag-Leffler function over a range of \(\alpha\) and \(|z|\), with \(\text{arg} z = \pi / 2\). The results show the minimum time over this range over a series of 32 runs. We can see that the performance has a strong dependence on both of these parameters, as much as \(7 \times\).

These results were obtained on Arch Linux running on an AMD Ryzen AI 9 HX 370. The software stack, roughly, is

  • mittagleffler version 0.3.0.

  • Rust 1.99.1 (in release mode) and compiled with the extra target-cpu=x86-64-v3.

  • Python 3.14 (running with -O).

  • MATLAB R2026a (standard parameters, hopefully also optimized).

Reference#

class pymittagleffler.GarrappaMittagLeffler(*, eps=None)#

Bases: object

eps: float#

Tolerance used by the algorithm.

evaluate(z: complex, alpha: float, beta: float) → complex | None#

Evaluate the Mittag-Leffler function at a scalar argument z. Note that, unlike mittag_leffler(), this function does not use any special cases and always evaluates the Mittag-Leffler function using the algorithm from Garrappa (2015, doi:10.1137/140971191).

pymittagleffler.mittag_leffler(z: numpy.ndarray[tuple[int, ...], numpy.dtype[numpy.inexact[Any]]], alpha: float, beta: float) → numpy.ndarray[tuple[int, ...], numpy.dtype[numpy.inexact[Any]]]#

Evaluate the Mittag-Leffler function with parameters alpha and beta.

Parameters:

z – any scalar or numpy.ndarray of real or complex numbers.

Changelog#

Version 0.3.0 (October 20, 2026)#

Dependencies#

  • Advertise support for Python 3.15.

  • Update to the new pyo3 and rust-numpy 0.30 releases.

Features#

  • Implement parallel evaluation in Python using rayon. This is quite a big performance boost. Use RAYON_NUM_THREADS to control the number of threads.

Maintenance#

  • Small updates to build, CI, linting.

  • Update benchmark script.

Version 0.2.1 (July 13, 2026)#

Features#

  • More performance improvements. Minor compared to last time, but still notable. We now use smallvec to avoid allocations and take advantage of some symmetries in the equations.

Maintenance#

  • Small updates to build and CI (dependency groups and cleanup).

  • Update benchmark script.

Version 0.2.0 (March 19, 2026)#

Features#

  • The performance of the library was improve quite a bit. In the little benchmark on readthedocs.org, its now up to 5-12x faster than the Python code and up to 3-7x faster than the MATLAB code.

Maintenance#

  • Small updates to build and CI (dependency groups and cleanup).

Version 0.1.9 (February 19, 2026)#

Dependencies#

  • Update to the new pyo3 and rust-numpy 0.28 releases.

Maintenance#

  • Switch to ty for type checking.

  • Small updates to build and CI (dependency groups and cleanup).

Version 0.1.8 (December 12th, 2025)#

Dependencies#

  • Updated the Rust edition to 2024.

  • Advertise support for Python 3.14.

Maintenance#

  • Update linting and formatting (for new ruff and mypy mainly).

Version 0.1.7 (November 21st, 2025)#

Maintenance#

  • Add long_description to Python bindings, so that it shows up on PyPI.

Version 0.1.6 (November 21st, 2025)#

Dependencies#

  • Update to the new pyo3 and rust-numpy 0.27 releases.

Version 0.1.5 (October 5th, 2025)#

Dependencies#

  • Update to the new pyo3 and rust-numpy 0.26 releases.

Version 0.1.4 (June 17th, 2025)#

Dependencies#

  • Update to the new pyo3 and rust-numpy 0.25 releases.

Maintenance#

  • Update linting and formatting (for new ruff and mypy mainly).

  • Fix seed in tests to remove flakiness.

  • Fix some small typos in README.

Version 0.1.3 (February 1st, 2025)#

Dependencies#

  • Update to the new rand 0.9.0 release.

Maintenance#

  • Switch to using just for development and on the CI.

  • Add a nice image to the README.

  • Update linting and formatting.

Version 0.1.2 (January 4th, 2025)#

Maintenance#

  • Switch README.rst to README.md for crates.io.

Version 0.1.1 (January 4th, 2025)#

Maintenance#

  • Fix CI to produce wheels for x86_64 macOS.

Version 0.1.0 (January 4th, 2025)#

This is the initial release of the Python bindings for the mittagleffler Rust crate. It mainly provides a simple function to evaluate the Mittag-Leffler function as:

from pymittagleffler import mittag_leffler

z = np.linspace(0.0, 1.0) + 1j * np.linspace(0.0, 1.0)
ml = mittag_leffler(z, alpha=1.0, beta=2.0)

The function accepts real and complex inputs, both scalars and numpy arrays of any shape. The function is applied component wise, i.e. this is different than the existing “Matrix” Mittag-Leffler function.

Acknowledgments#

Work on pymittagleffler was sponsored, in part, by

  • the West University of Timișoara (Romania) under START Grant No. 33580/25.05.2023,

  • the CNCS-UEFISCDI (Romania), under Project No. ROSUA-2024-0002,

  • the “Romanian Hub for Artificial Intelligence - HRIA”, Smart Growth, Digitization and Financial Instruments Program, 2021-2027, MySMIS no. 351416.

The views and opinions expressed herein do not necessarily reflect those of the funding agencies.

Indices and tables#