GL - iparsw/differintP GitHub Wiki
GL
– Grünwald-Letnikov Fractional Derivative
Overview
GL
computes the Grünwald-Letnikov (GL) fractional derivative of a function over a specified domain, efficiently evaluating the derivative at each point using fast vectorized techniques. This method implements the classical Grünwald-Letnikov definition, which is a direct generalization of the finite-difference approximation to non-integer orders.
Mathematical Background
The Grünwald-Letnikov derivative of order $\alpha$ for a function $f(x)$ is defined as:
$$ D^\alpha f(x) \approx h^{-\alpha} \sum_{k=0}^n (-1)^k \binom{\alpha}{k} f(x - k h) $$
where:
- $h$ is the step size between points in the domain,
- $\binom{\alpha}{k}$ is the generalized (fractional) binomial coefficient,
- the sum is taken over previous grid points.
In practice, this computation for all points in a discretized domain can be viewed as a convolution of the function values with the sequence of binomial coefficients.
Implementation Details
-
Input Flexibility: Accepts a callable function, NumPy array, or Python list. If a function is provided, it is evaluated at
num_points
equally spaced points betweendomain_start
anddomain_end
. -
Optimized with FFT: The computation leverages the Fast Fourier Transform (FFT) to efficiently perform the convolution, making it extremely fast even for large domains. This avoids the $O(n^2)$ complexity of a naïve implementation and reduces it to $O(n \log n)$.
-
Vectorized Coefficient Calculation: The binomial coefficients for the fractional derivative are precomputed using a vectorized approach for maximum efficiency.
Function Signature
GL(
alpha: float,
f_name: Callable | np.ndarray | list,
domain_start: float = 0.0,
domain_end: float = 1.0,
num_points: int = 100,
) -> np.ndarray
Parameters
- alpha (
float
): The order of the fractional derivative. - f_name (
Callable
,list
, ornp.ndarray
): Function, lambda, or sequence of function values to be differintegrated. - domain_start (
float
, optional): Left endpoint of the domain. Default is0.0
. - domain_end (
float
, optional): Right endpoint of the domain. Default is1.0
. - num_points (
int
, optional): Number of points in the domain. Default is100
.
Returns
- result (
np.ndarray
): Array containing the GL fractional derivative at each grid point.
Example Usage
import numpy as np
from differintP import GL
# Example 1: Fractional derivative of a quadratic polynomial
DF_poly = GL(-0.5, lambda x: x**2 - 1)
# Example 2: Fractional derivative of sqrt(x) on [0, 1]
DF_sqrt = GL(0.5, np.sqrt, 0., 1., 100)
Notes
- The GL method is the standard reference for fractional finite-difference approximations.
- All computation is fully vectorized and highly efficient.
- For even higher-order accuracy, See the GLI page for the improved Grünwald-Letnikov method.