Weyl - iparsw/differintP GitHub Wiki
Weyl
– Weyl Fractional Derivative (Periodic, Fourier-Based)
Overview
Weyl
computes the Weyl fractional derivative of a function, leveraging the Fast Fourier Transform (FFT) to efficiently and accurately evaluate the derivative for periodic functions over a uniform grid. The approach is well-suited for applications involving functions on the interval $[a, b]$ where the endpoints are identified (i.e., periodic boundary conditions).
The method directly implements the Fourier-space definition of the Weyl (right-sided, periodic) fractional derivative, making it extremely fast for large domains and high-resolution grids.
Mathematical Background
The Weyl fractional derivative of order $\alpha$ for a periodic function $f(x)$ is defined via its Fourier series. Given the function’s Fourier coefficients, the fractional derivative is computed by multiplying each coefficient by $(ik)^\alpha$, where $k$ is the Fourier frequency. In the continuous case:
$$ \mathcal{F}D^\alpha_W f = (ik)^\alpha \mathcal{F}f $$
In practice, the computation is performed on a discrete uniform grid using the FFT, which efficiently transforms between physical and frequency space.
Reference: Samko, Kilbas, Marichev, Fractional Integrals and Derivatives, Chapter 7 (Weyl Derivative)
Implementation Details
- Supports Functions and Arrays: Accepts a callable function, NumPy array, or list of values. If a function is provided, it is evaluated on a uniform grid covering the interval $[domain_start, domain_end]$.
- Optimized for Periodic Domains: The method assumes the function is periodic on the specified interval. The interval should correspond to one period of the function.
- FFT-Based: Uses the FFT to transform to frequency space, applies the fractional derivative, and inverts back to physical space. This provides high accuracy and speed ($O(n \log n)$).
- Handles Real and Complex Data: Returns a real array when input is real-valued; otherwise, returns complex values.
Function Signature
Weyl(
alpha: float,
f_name: Callable | np.ndarray | list,
domain_start: float = 0.0,
domain_end: float = 2 * np.pi,
num_points: int = 100,
) -> np.ndarray
Parameters
-
alpha (
float
): Order of the fractional derivative. -
f_name (
Callable
,np.ndarray
, orlist
): Function or array of values to differentiate. If callable, evaluated on the uniform grid. -
domain_start (
float
, optional): Start of the periodic domain (default:0.0
). -
domain_end (
float
, optional): End of the periodic domain (default:2 * np.pi
). The interval $[domain_start, domain_end]$ should be one period. -
num_points (
int
, optional): Number of grid points in the interval (default:100
).
Returns
- df (
np.ndarray
): Array of the Weyl fractional derivative evaluated at each grid point.
Example Usage
import numpy as np
from differintP import Weyl
# Example: Fractional derivative of sin(x)
dalpha = 0.5
f = np.sin
x = np.linspace(0, 2 * np.pi, 100, endpoint=False)
weyl_deriv = Weyl(dalpha, f)
# Example: Directly passing array of values
fvals = np.cos(x)
weyl_cos = Weyl(1.2, fvals)
Notes
- The function is optimized for periodic functions. For non-periodic problems, the output may not be meaningful.
- The zero-frequency (DC) component is not differentiated (set to zero).
- For further details on the mathematical theory, see Samko, Kilbas, Marichev, Ch. 7.
Riesz
Fractional Derivative
The Riesz
function computes the Riesz fractional derivative of a function using an FFT-based approach. Unlike the Weyl derivative, the Riesz operator is symmetric and produces real-valued outputs for real-valued periodic input functions. It is widely used in physical applications (such as anomalous diffusion and signal processing) where a symmetric, non-directional fractional derivative is needed.
Mathematical Background
The Riesz fractional derivative of order $\alpha$ for a periodic function $f(x)$ is defined in the Fourier domain by multiplying each Fourier component by $-|k|^\alpha$, where $k$ are the frequencies:
$$ \mathcal{F}\leftD^\alpha_{\text{Riesz}} f\right = -|k|^\alpha , \mathcal{F}f $$
This ensures the operator is symmetric (unbiased left/right) and always real for real-valued input. The Riesz derivative generalizes the classical second derivative (Laplacian) to fractional orders.
Implementation Details
- Supports Functions and Arrays: Accepts a callable, NumPy array, or list. If a function is passed, it is evaluated on a uniform periodic grid.
- Symmetric Operator: Applies the symbol $-|k|^\alpha$ in the Fourier domain, ensuring symmetry and real outputs for real input.
- Optimized for Periodic Domains: Assumes the interval $[domain_start, domain_end]$ is one period of the function.
- FFT-Based: Fast and efficient, suitable for high-resolution periodic signals.
- Returns: Real-valued array when the input is real.
Function Signature
Riesz(
alpha: float,
f_name: Callable | np.ndarray | list,
domain_start: float = 0.0,
domain_end: float = 2 * np.pi,
num_points: int = 100,
) -> np.ndarray
Parameters
-
alpha (
float
): Order of the fractional derivative. -
f_name (
Callable
,np.ndarray
, orlist
): Function or array to differentiate. If callable, evaluated on a uniform grid. -
domain_start (
float
, optional): Start of the periodic domain (default:0.0
). -
domain_end (
float
, optional): End of the periodic domain (default:2 * np.pi
). -
num_points (
int
, optional): Number of grid points (default:100
).
Returns
- df (
np.ndarray
): Array of the Riesz fractional derivative at each grid point.
Example Usage
import numpy as np
from differintP import Riesz
# Example: Riesz derivative of sin(x)
alpha = 1.5
x = np.linspace(0, 2 * np.pi, 100, endpoint=False)
f = np.sin
riesz_sin = Riesz(alpha, f)
# Example: Riesz derivative of a given array
fvals = np.cos(x)
riesz_cos = Riesz(0.7, fvals)
Notes
- The Riesz derivative is especially useful for problems involving symmetric fractional diffusion or Lévy flights.
- The operator generalizes the negative Laplacian: for $\alpha=2$, Riesz reduces to the standard second derivative.
- As with
Weyl
, results are most meaningful for periodic functions on the specified interval.