latqcdtools.math.math ============= ```python RMS(data) -> float: """ Root-mean-square of data Args: data (np.ndarray) Returns: float: RMS of data """ ``` ```python TA(mat) -> numpy.ndarray: """ Make mat traceless and antihermitian Args: mat (np.ndarray) Returns: bool: _description_ """ ``` ```python _absPrec(mat) -> float: """ Absolute tolerance for comparing mat to a transformed copy of itself, relative to the size of its largest element, so that such checks do not depend on the units of mat. """ ``` ```python applySVDCut(vals, svdcut=1e-12) -> numpy.ndarray: """ Raise all singular values or (non-negative) eigenvalues below svdcut*max(vals) to that floor. This caps the condition number of the corresponding matrix at 1/svdcut. Args: vals (np.ndarray): singular values or eigenvalues svdcut (float, optional): condition number threshold. Defaults to 1e-12. Returns: np.ndarray: modified copy of vals """ ``` ```python checkMatrix(mat) ``` ```python checkSquare(mat): """ Make sure mat is a square np.ndarray object. Args: mat (np.ndarray) """ ``` ```python checkVector(vec) ``` ```python dagger(arr) -> numpy.ndarray ``` ```python eigh(mat): """ Eigenvalues and eigenvectors of a Hermitian (or real symmetric) matrix. Unlike a general eigensolver, this guarantees real eigenvalues and orthonormal eigenvectors, also when eigenvalues are degenerate. Rounding errors that make mat slightly non-Hermitian are removed by symmetrizing first. Args: mat (np.ndarray): Hermitian matrix Returns: np.ndarray, np.ndarray: eigenvalues in ascending order, and eigenvectors as the columns of a matrix """ ``` ```python exp(mat) -> numpy.ndarray: """ Exponential of square matrix. """ ``` ```python fallFactorial(n, m) -> float: """ Falling factorial n fall to m. """ ``` ```python id(N) -> numpy.ndarray: """ NxN complex identity matrix """ ``` ```python invert(mat, method='scipy', svdcut=1e-12) -> numpy.ndarray: """ Invert matrix. Args: mat (np.ndarray): to-be-inverted matrix method (str): algorithm for inverting the matrix Returns: np.ndarray: mat^{-1} """ ``` ```python isAntihermitian(mat) -> bool: """ Antihermitian matrices satisfy dagger(M)=-M Args: mat (np.ndarray) Returns: bool: True if antihermitian """ ``` ```python isHankel(mat) -> bool: """ Hankel matrices look like (3d example) a b c b c d c d e Args: mat np.ndarray Returns: bool: True if Hankel """ ``` ```python isHermitian(mat) -> bool: """ Hermitian matrices satisfy dagger(M)=M Args: mat (np.ndarray) Returns: bool: True if hermitian """ ``` ```python isMatrix(mat) -> bool ``` ```python isOrthogonal(mat) -> bool: """ Orthogonal matrices satisfy M^t M = id Args: mat (np.ndarray) Returns: bool: True if orthogonal """ ``` ```python isPositiveSemidefinite(mat, details=False, eps=1e-12) -> bool: """Returns true if mat is positive semidefinite. Otherwise, if details=True, list the eigenvalues that are not >=0. Only the Hermitian part of mat matters, since x^dagger mat x is real only for that part, so we check its eigenvalues. Args: mat (np.ndarray) details (bool, optional): If true, report problematic eigenvalues. Defaults to False. eps (float, optional): Tolerance relative to the largest |eigenvalue|, so that the check does not depend on the units of mat. Defaults to 1e-12. Returns: bool: True if positive semidefinite """ ``` ```python isSpecial(mat) -> bool: """ Special matrices M satisfy det(M) = 1. Args: mat (np.ndarray) Returns: bool: True if special """ ``` ```python isSquare(mat) -> bool ``` ```python isSymmetric(mat) -> bool: """ Symmetric matrices satisfy M^t = M. Args: mat (np.ndarray) Returns: bool: True if symmetric """ ``` ```python isUnitary(mat) -> bool: """ Unitary matrices U satisfy U^dag U = 1. Args: mat (np.ndarray) Returns: bool: True if unitary """ ``` ```python isVector(vec) -> bool ``` ```python log(mat) -> numpy.ndarray: """ Natural logarithm of square matrix. """ ``` ```python logDet(mat) -> float: """ Logarithm of determinant. """ ``` ```python normalize(arr, p=2) -> numpy.ndarray: """ Normalize vector or matrix arr using p-norm. Args: arr (np.ndarray) p (float, optional): Defaults to 2. Returns: np.ndarray: normalized array """ ``` ```python pnorm(arr, p=2) -> float: """ Returns p-norm of vector or matrix arr. Args: arr (np.ndarray) p (float, optional): Defaults to 2. Returns: float: pnorm """ ``` ```python pow(mat, power) -> numpy.ndarray: """ Matrix power. """ ``` ```python quadrature(data, axis=None): """ Add data in quadrature Args: data (np.ndarray) axis (int, optional): Axis along which to add. Defaults to None, meaning all elements. Returns: float or np.ndarray: data added in quadrature """ ``` ```python regulate(mat, svdcut=1e-12) -> numpy.ndarray: """ If a matrix's singular values are too small, it will be ill-conditioned, making it difficult to invert and hence reducing numerical stability. This method extracts its singular values using SVD, then doctors the singular values to reduce the condition number. In the context of applying an SVD cut to a covariance matrix, see e.g. Appendix D of 10.1103/PhysRevD.100.094508. Args: mat (np.ndarray) svdcut (float, optional): condition number threshold. Defaults to 1e-12. Returns: np.ndarray: regulated matrix """ ``` ```python rel_check(a, b, prec=1e-06, abs_prec=1e-14) -> bool: """ Check whether a and b are equal. a and b can be array-like, float-like, or complexes. If a and b are array-like, we check that they are element-wise equal within the tolerance. Args: a (obj) b (obj) prec (float, optional): Relative precision. Defaults to 1e-6. abs_prec (float, optional): Absolute precision. Defaults to 1e-14. Returns: bool: True if a and b are equal. """ ``` ```python riseFactorial(n, m) -> float: """ Rising factorial n rise to m. """ ``` ```python ze(N) -> numpy.ndarray: """ NxN complex zero matrix """ ``` ```python class SUN(N=None, mat=None): """ A member of the Lie group SU(N). Implemented as a subclass of the np.ndarray class. This gives us access already to all the nice features of np.ndarray and lets us leverage the speed of numpy. g.det() g.dagger() g[i,j], which can be used to access and assign g + h g*h = g@h 2*g """ ```