|
MathUtils
A library of mathematical utilities.
|
Numerical functions. More...
#include "mathutils/log_factorial_lookup_table.hpp"#include "mathutils/simple_generator.hpp"#include "mathutils/spherical_harmonics_index_lookup_table.hpp"#include <Eigen/Dense>#include <array>#include <cmath>#include <complex>#include <coroutine>#include <cstdint>#include <stdexcept>
Go to the source code of this file.
Functions | |
| template<typename T> | |
| int | mathutils::sign (T x) |
| Compute the sign (1,-1, or 0) of a value. | |
| int | mathutils::special::minus_one_to_int_pow (int n) |
| Compute \((-1)^n\) for integer n. | |
| double | mathutils::special::log_factorial (uint64_t n) |
| Compute \(\ln(n!)\) for a non-negative integer n. Uses a lookup table for small values and lgamma for larger values. | |
| template<typename T> | |
| double | mathutils::special::Heaviside (T x) |
| The Heaviside step function. Returns 0.0 for negative values, 1.0 for positive values, and 0.5 for zero. | |
| template<typename T> | |
| double | mathutils::special::ReLog (const T &x) |
| Compute the real part of the complex logarithm \(Re(Log(x))=
ln(|x|)\). Returns \(Re(Log(0))=-\infty\) for \(x=0\). | |
| template<typename T> | |
| std::pair< double, int > | mathutils::special::ReLogRe_ImLogRe_over_pi (const T &x) |
| Compute \(Re(Log(Re(x)))\) and \(Im(Log(Re(x)))/\pi\). | |
| template<typename T> | |
| std::pair< double, int > | mathutils::special::ReLogRe_ImLogRe_over_pi_of_x_to_pow (const T &x, int n) |
| int | mathutils::special::spherical_harmonic_index_n_LM (int l, int m) |
| Compute the index of (l,m) in [(0,0), (1,-1), (1,0), (1,1), (2,-2), ...]. | |
| std::array< int, 2 > | mathutils::special::spherical_harmonic_index_lm_N (int n) |
| Compute the n-th element of the sequence [(0,0), (1,-1), (1,0), (1,1), (2,-2), ...]. | |
| double | mathutils::special::reduced_spherical_Pmm (int m, double theta) |
| Compute the associated Legendre polynomial with spherical harmonics normalization \(P_{m m}(\theta) = e^{-im\phi}Y_{m m}(\theta, \phi)\) for \(0\leq\theta\leq\pi/2\) and \(m\geq 0\). Used to initialize the recursion. | |
| mathutils::SimpleGenerator< double > | mathutils::special::generate_reduced_spherical_Plm_recursion_three_term_upward_ell (int l_start, int l_end, double theta) |
| Generate the associated Legendre polynomial with spherical harmonics normalization \(P_{\ell m}(\theta) = e^{-im\phi}Y_{\ell m}(\theta,
\phi)\) for \(\ell = \ell_{start}, \ell_{start} + 1, \ldots, \ell_{end}\) and \(m=\ell_{start}\). | |
| mathutils::SimpleGenerator< std::pair< int, double > > | mathutils::special::enumerate_reduced_spherical_Plm_recursion_three_term_upward_ell (int l_start, int l_end, double theta) |
| double | mathutils::special::reduced_spherical_Plm (int l, int m, double theta) |
| Compute the associated Legendre polynomial with spherical harmonics normalization \(P_{\ell m}(\theta) = e^{-im\phi}Y_{\ell m}(\theta, \phi)\) for \(0\leq\theta\leq\pi/2\) and \(m\geq 0\). | |
| double | mathutils::special::spherical_Plm (int l, int m, double theta) |
| Compute the associated Legendre polynomial with spherical harmonics normalization \(P_{\ell m}(\theta) = e^{-im\phi}Y_{\ell m}(\theta, \phi)\) for \(0\leq\theta\leq\pi\) and \(-\ell \leq m\geq \ell\). | |
| double | mathutils::special::recursive_real_Ylm (int l, int m, double theta, double phi) |
| Compute the real spherical harmonics \(Y_{l m}(\theta, \phi)\) for \(0\leq\theta\leq\pi\) and \(-\ell \leq m\geq \ell\). | |
| double | mathutils::special::real_Ylm (int l, int m, double theta, double phi) |
| Compute the real spherical harmonics \(Y_{l m}(\theta, \phi)\) for \(0\leq\theta\leq\pi\) and \(-\ell \leq m\geq \ell\). | |
| Eigen::VectorXd | mathutils::special::real_Ylm (int l, int m, const Eigen::MatrixXd &thetaphi_coord_P) |
| Compute the real spherical harmonics \(Y_{l m}(\theta, \phi)\) for \(0\leq\theta\leq\pi\) and \(-\ell \leq m\geq \ell\). | |
| Eigen::MatrixXd | mathutils::special::compute_all_real_Ylm (int l_max, const Eigen::MatrixXd &thetaphi_coord_P) |
| Compute real spherical harmonics \(y_{l m}(\theta, \phi)\) for \(\ell=0,...,\ell_{max}\) at the given coordinates. | |
| Eigen::MatrixXcd | mathutils::special::compute_all_Ylm (int l_max, const Eigen::MatrixXd &thetaphi_coord_P) |
| std::complex< double > | mathutils::special::recursive_Ylm (int l, int m, double theta, double phi) |
| Compute the spherical harmonics \(Y_{l m}(\theta, \phi)\) for \(0\leq\theta\leq\pi\) and \(-\ell \leq m\geq \ell\). | |
| std::complex< double > | mathutils::special::Ylm (int l, int m, double theta, double phi) |
| Compute the spherical harmonics \(Y_{l m}(\theta, \phi)\) for \(0\leq\theta\leq\pi\) and \(-\ell \leq m\geq \ell\). | |
| Eigen::VectorXcd | mathutils::special::Ylm (int l, int m, const Eigen::MatrixXd &thetaphi_coord_P) |
| Compute the spherical harmonics \(Y_{l m}(\theta, \phi)\) for \(0\leq\theta\leq\pi\) and \(-\ell \leq m\geq \ell\). | |
| double | mathutils::special::series_real_Ylm (int l, int m, double theta, double phi) |
| Eigen::VectorXd | mathutils::special::series_real_Ylm (int l, int m, const Eigen::MatrixXd &thetaphi_coord_P) |
| std::complex< double > | mathutils::special::series_Ylm (int l, int m, double theta, double phi) |
| Eigen::VectorXcd | mathutils::special::series_Ylm (int l, int m, const Eigen::MatrixXd &thetaphi_coord_P) |
| Eigen::MatrixXd | mathutils::special::compute_all_series_real_Ylm (int l_max, const Eigen::MatrixXd &thetaphi_coord_P) |
| Compute real spherical harmonics \(y_{l m}(\theta, \phi)\) for \(\ell=0,...,\ell_{max}\) at the given coordinates. | |
| Eigen::MatrixXcd | mathutils::special::compute_all_series_Ylm (int l_max, const Eigen::MatrixXd &thetaphi_coord_P) |
| Compute spherical harmonics \(Y_{l m}(\theta, \phi)\) for \(\ell=0,...,\ell_{max}\) at the given coordinates. | |
| double | mathutils::special::phi_independent_Ylm (int l, int m, double theta) |
| Compute Ylm(theta, phi)/exp(i*theta*phi) for m>=0 and 0<=theta<=pi. | |
| std::complex< double > | mathutils::special::old_Ylm (int l, int m, double theta, double phi) |
| double | mathutils::special::old_real_Ylm (int l, int m, double theta, double phi) |
| Eigen::MatrixXd | mathutils::special::old_compute_all_real_Ylm (int l_max, const Eigen::MatrixXd &thetaphi_coord_P) |
Numerical functions.
| Eigen::MatrixXd mathutils::special::compute_all_real_Ylm | ( | int | l_max, |
| const Eigen::MatrixXd & | thetaphi_coord_P ) |
Compute real spherical harmonics \(y_{l m}(\theta, \phi)\) for \(\ell=0,...,\ell_{max}\) at the given coordinates.
| l_max | The maximum order of the spherical harmonics (non-negative integer). |
| thetaphi_coord_P | A matrix of shape (num_points, 2) where each row contains the polar angle \(\theta\) and azimuthal angle \(\phi\) in radians. |
| Eigen::MatrixXd mathutils::special::compute_all_series_real_Ylm | ( | int | l_max, |
| const Eigen::MatrixXd & | thetaphi_coord_P ) |
Compute real spherical harmonics \(y_{l m}(\theta, \phi)\) for \(\ell=0,...,\ell_{max}\) at the given coordinates.
| l_max | The maximum order of the spherical harmonics (non-negative integer). |
| thetaphi_coord_P | A matrix of shape (num_points, 2) where each row contains the polar angle \(\theta\) and azimuthal angle \(\phi\) in radians. |
| Eigen::MatrixXcd mathutils::special::compute_all_series_Ylm | ( | int | l_max, |
| const Eigen::MatrixXd & | thetaphi_coord_P ) |
Compute spherical harmonics \(Y_{l m}(\theta, \phi)\) for \(\ell=0,...,\ell_{max}\) at the given coordinates.
| l_max | The maximum order of the spherical harmonics (non-negative integer). |
| thetaphi_coord_P | A matrix of shape (num_points, 2) where each row contains the polar angle \(\theta\) and azimuthal angle \(\phi\) in radians. |
|
inline |
The Heaviside step function. Returns 0.0 for negative values, 1.0 for positive values, and 0.5 for zero.
| T | The type of the input value (must be comparable to T{0}). |
| x | The input value. |
|
inline |
Compute \(\ln(n!)\) for a non-negative integer n. Uses a lookup table for small values and lgamma for larger values.
| n | The non-negative integer for which to compute log(n!). |
|
inline |
Compute Ylm(theta, phi)/exp(i*theta*phi) for m>=0 and 0<=theta<=pi.
| l | Degree of the spherical harmonic. |
| m | Order of the spherical harmonic. |
| theta | Polar angle in radians. |
| Eigen::VectorXd mathutils::special::real_Ylm | ( | int | l, |
| int | m, | ||
| const Eigen::MatrixXd & | thetaphi_coord_P ) |
Compute the real spherical harmonics \(Y_{l m}(\theta, \phi)\) for \(0\leq\theta\leq\pi\) and \(-\ell \leq m\geq \ell\).
| l | Degree of the spherical harmonic ( \(\ell=0,1,\ldots\)). |
| m | Order of the spherical harmonic ( \(m=-\ell,\ldots,\ell\)). |
| thetaphi_coord_P | Matrix containing the polar and azimuthal angles. |
|
inline |
Compute the real spherical harmonics \(Y_{l m}(\theta, \phi)\) for \(0\leq\theta\leq\pi\) and \(-\ell \leq m\geq \ell\).
| l | Degree of the spherical harmonic ( \(\ell=0,1,\ldots\)). |
| m | Order of the spherical harmonic ( \(m=-\ell,\ldots,\ell\)). |
| theta | Polar angle in radians ( \(0\leq\theta\leq\pi\)). |
| phi | Azimuthal angle in radians ( \(0\leq\phi<2\pi\)). |
|
inline |
Compute the real spherical harmonics \(Y_{l m}(\theta, \phi)\) for \(0\leq\theta\leq\pi\) and \(-\ell \leq m\geq \ell\).
| l | Degree of the spherical harmonic ( \(\ell=0,1,\ldots\)). |
| m | Order of the spherical harmonic ( \(m=-\ell,\ldots,\ell\)). |
| theta | Polar angle in radians ( \(0\leq\theta\leq\pi\)). |
| phi | Azimuthal angle in radians ( \(0\leq\phi<2\pi\)). |
|
inline |
Compute the spherical harmonics \(Y_{l m}(\theta, \phi)\) for \(0\leq\theta\leq\pi\) and \(-\ell \leq m\geq \ell\).
| l | Degree of the spherical harmonic ( \(\ell=0,1,\ldots\)). |
| m | Order of the spherical harmonic ( \(m=-\ell,\ldots,\ell\)). |
| theta | Polar angle in radians ( \(0\leq\theta\leq\pi\)). |
| phi | Azimuthal angle in radians ( \(0\leq\phi<2\pi\)). |
|
inline |
Compute the associated Legendre polynomial with spherical harmonics normalization \(P_{\ell m}(\theta) = e^{-im\phi}Y_{\ell m}(\theta, \phi)\) for \(0\leq\theta\leq\pi/2\) and \(m\geq 0\).
| l | Degree of the polynomial ( \(\ell=0,1,\ldots\)). |
| m | Order of the polynomial ( \(m=0,1,\ldots,\ell\)). |
| theta | Polar angle in radians ( \(0\leq\theta\leq\pi/2\)). |
|
inline |
Compute the associated Legendre polynomial with spherical harmonics normalization \(P_{m m}(\theta) = e^{-im\phi}Y_{m m}(\theta, \phi)\) for \(0\leq\theta\leq\pi/2\) and \(m\geq 0\). Used to initialize the recursion.
| m | Degree/order of the polynomial ( \(m=0,1,\ldots\)). |
| theta | Polar angle in radians ( \(0\leq\theta\leq\pi/2\)). |
|
inline |
Compute the real part of the complex logarithm \(Re(Log(x))= ln(|x|)\). Returns \(Re(Log(0))=-\infty\) for \(x=0\).
\[\mathbb{C}\rightarrow \mathbb{R}\cup\lbrace-\infty\rbrace\\ x\mapsto Re(Log(x)) \]
| x | The input value (can be floating-point or integral). |
|
inline |
Compute \(Re(Log(Re(x)))\) and \(Im(Log(Re(x)))/\pi\).
| x | The input value (can be floating-point or integral). |
|
inline |
Compute the sign (1,-1, or 0) of a value.
| T | The type of the input value (must be comparable to T{0}). |
| x | The input value. |
|
inline |
Compute the n-th element of the sequence [(0,0), (1,-1), (1,0), (1,1), (2,-2), ...].
| n | The linear index (must be non-negative). |
|
inline |
Compute the index of (l,m) in [(0,0), (1,-1), (1,0), (1,1), (2,-2), ...].
| l | The degree (non-negative). |
| m | The order (must be in the range [-l, l]). |
|
inline |
Compute the associated Legendre polynomial with spherical harmonics normalization \(P_{\ell m}(\theta) = e^{-im\phi}Y_{\ell m}(\theta, \phi)\) for \(0\leq\theta\leq\pi\) and \(-\ell \leq m\geq \ell\).
| l | Degree of the polynomial ( \(\ell=0,1,\ldots\)). |
| m | Order of the polynomial ( \(m=-\ell,\ldots,\ell\)). |
| theta | Polar angle in radians ( \(0\leq\theta\leq\pi\)). |
| Eigen::VectorXcd mathutils::special::Ylm | ( | int | l, |
| int | m, | ||
| const Eigen::MatrixXd & | thetaphi_coord_P ) |
Compute the spherical harmonics \(Y_{l m}(\theta, \phi)\) for \(0\leq\theta\leq\pi\) and \(-\ell \leq m\geq \ell\).
| l | Degree of the spherical harmonic ( \(\ell=0,1,\ldots\)). |
| m | Order of the spherical harmonic ( \(m=-\ell,\ldots,\ell\)). |
| thetaphi_coord_P | Matrix containing the polar and azimuthal angles. |
|
inline |
Compute the spherical harmonics \(Y_{l m}(\theta, \phi)\) for \(0\leq\theta\leq\pi\) and \(-\ell \leq m\geq \ell\).
| l | Degree of the spherical harmonic ( \(\ell=0,1,\ldots\)). |
| m | Order of the spherical harmonic ( \(m=-\ell,\ldots,\ell\)). |
| theta | Polar angle in radians ( \(0\leq\theta\leq\pi\)). |
| phi | Azimuthal angle in radians ( \(0\leq\phi<2\pi\)). |