mittagleffler/lib.rs
1// SPDX-FileCopyrightText: 2023 Alexandru Fikl <alexfikl@gmail.com>
2// SPDX-License-Identifier: MIT
3
4//! # Mittag-Leffler Function
5//!
6//! This library implements the two-parameter Mittag-Leffler function.
7//!
8//! Currently only the algorithm described in the paper by
9//! [Roberto Garrapa (2015)](<https://doi.org/10.1137/140971191>) is implemented.
10//! This seems to be the most accurate and computationally efficient method to
11//! date for evaluating the Mittag-Leffler function.
12//!
13//! ```rust
14//! use num::complex::Complex64;
15//! use mittagleffler::MittagLeffler;
16//!
17//! let alpha = 0.75;
18//! let beta = 1.25;
19//! let z = Complex64::new(1.0, 2.0);
20//! println!("E({}; {}, {}) = {:?}", z, alpha, beta, z.mittag_leffler(alpha, beta));
21//!
22//! let z: f64 = 3.1415;
23//! println!("E({}; {}, {}) = {:?}", z, alpha, beta, z.mittag_leffler(alpha, beta));
24//! ```
25//!
26//! # Acknowledgments
27//!
28//! Work on ``pycaputo`` was sponsored, in part, by
29//!
30//! * the West University of Timișoara (Romania) under START Grant No. 33580/25.05.2023,
31//! * the CNCS-UEFISCDI (Romania), under Project No. ROSUA-2024-0002,
32//! * the "Romanian Hub for Artificial Intelligence - HRIA", Smart Growth,
33//! Digitization and Financial Instruments Program, 2021-2027, MySMIS no. 351416.
34//!
35//! The views and opinions expressed herein do not necessarily reflect those of the
36//! funding agencies.
37
38mod algorithm;
39mod garrappa;
40
41pub use algorithm::MittagLefflerAlgorithm;
42pub use algorithm::mittag_leffler_special;
43pub use garrappa::GarrappaMittagLeffler;
44
45use num::complex::Complex64;
46
47/// Mittag-Leffler function.
48///
49/// Evaluates the Mittag-Leffler function using default parameters. It can be
50/// used as
51/// ```rust
52/// use mittagleffler::MittagLeffler;
53///
54/// let alpha: f64 = 1.0;
55/// let beta: f64 = 1.0;
56/// let z: f64 = 1.0;
57/// let result = z.mittag_leffler(alpha, beta);
58/// ```
59/// on real or complex arguments.
60pub trait MittagLeffler
61where
62 Self: Sized,
63{
64 fn mittag_leffler(&self, alpha: f64, beta: f64) -> Option<Complex64>;
65}
66
67impl MittagLeffler for f64 {
68 fn mittag_leffler(&self, alpha: f64, beta: f64) -> Option<Complex64> {
69 let ml = GarrappaMittagLeffler::default();
70 let z = Complex64::new(*self, 0.0);
71
72 match mittag_leffler_special(z, alpha, beta) {
73 Some(value) => Some(value),
74 None => ml.evaluate(z, alpha, beta),
75 }
76 }
77}
78
79impl MittagLeffler for Complex64 {
80 fn mittag_leffler(&self, alpha: f64, beta: f64) -> Option<Complex64> {
81 let ml = GarrappaMittagLeffler::default();
82
83 match mittag_leffler_special(*self, alpha, beta) {
84 Some(value) => Some(value),
85 None => ml.evaluate(*self, alpha, beta),
86 }
87 }
88}