Linear algebra operations for complex numbers in Clojure.
This namespace provides implementations of common linear algebra operations for complex numbers represented in a structure-of-arrays (SoA) format. It includes matrix addition, multiplication, inversion, eigen-decomposition, and other utilities necessary for quantum computing applications.
Complex Number Representation:
Linear Algebra Operations:
Linear algebra operations for complex numbers in Clojure. This namespace provides implementations of common linear algebra operations for complex numbers represented in a structure-of-arrays (SoA) format. It includes matrix addition, multiplication, inversion, eigen-decomposition, and other utilities necessary for quantum computing applications. Complex Number Representation: - Complex numbers are represented as maps with :real and :imag keys. - Vectors and matrices of complex numbers are represented as maps with :real and :imag keys containing vectors or matrices of real numbers. Linear Algebra Operations: - Matrix addition, subtraction, scaling, multiplication - Matrix-vector products - Kronecker products - Transpose and conjugate transpose - Inner products - Hermitian checks - Solving linear systems - Matrix inversion - Spectral norm computation - Eigen-decomposition for Hermitian matrices
(back-substitution Ar Ai br bi)Back substitution on upper-triangular complex system.
Back substitution on upper-triangular complex system.
(cholesky-decomposition A)Compute Cholesky decomposition of a complex Hermitian positive definite matrix A. Returns a map with lower triangular matrix L in SoA form.
Compute Cholesky decomposition of a complex Hermitian positive definite matrix A. Returns a map with lower triangular matrix L in SoA form.
(condition-number A)Compute condition number of a complex matrix A. Returns a positive real number or Double/POSITIVE_INFINITY if A is singular.
Compute condition number of a complex matrix A. Returns a positive real number or Double/POSITIVE_INFINITY if A is singular.
(diagonal? A)(diagonal? A tol)Check if complex matrix A is diagonal within given tolerance. Returns true if diagonal, false otherwise.
Check if complex matrix A is diagonal within given tolerance. Returns true if diagonal, false otherwise.
(eigen-general A)(eigen-general A eps)Compute eigen-decomposition of a complex square matrix A. Returns a map with eigenvalues and eigenvectors in SoA form. Optionally accepts a tolerance for numerical stability.
Compute eigen-decomposition of a complex square matrix A. Returns a map with eigenvalues and eigenvectors in SoA form. Optionally accepts a tolerance for numerical stability.
(eigen-hermitian A)(eigen-hermitian A eps)Compute eigen-decomposition of a complex Hermitian matrix A. Returns a map with eigenvalues and eigenvectors in SoA form. Optionally accepts a tolerance for numerical stability.
Compute eigen-decomposition of a complex Hermitian matrix A. Returns a map with eigenvalues and eigenvectors in SoA form. Optionally accepts a tolerance for numerical stability.
(forward-elimination Ar Ai br bi)Forward elimination (partial pivot) for complex A x = b. Ar/Ai: matrix parts, br/bi: RHS parts. Returns [Ar Ai br bi] in row echelon form.
Forward elimination (partial pivot) for complex A x = b. Ar/Ai: matrix parts, br/bi: RHS parts. Returns [Ar Ai br bi] in row echelon form.
(inverse A)Inverse of complex matrix via Gauss-Jordan.
Inverse of complex matrix via Gauss-Jordan.
(jacobi-symmetric A eps max-it)Compute eigen-decomposition of a real symmetric matrix via classical Jacobi rotations.
Parameters:
Returns map: {:eigenvalues [...unsorted...] :vectors V :iterations k} where V is an orthogonal matrix whose columns are the (unnormalized but numerically unit) eigenvectors corresponding to the returned eigenvalues.
NOTE:
Compute eigen-decomposition of a real symmetric matrix via classical
Jacobi rotations.
Parameters:
- A      real symmetric square matrix (vector of row vectors)
- eps    convergence tolerance on largest off-diagonal absolute value
- max-it maximum number of sweeps (rotation applications)
Returns map:
{:eigenvalues [...unsorted...] :vectors V :iterations k}
where V is an orthogonal matrix whose columns are the (unnormalized but
numerically unit) eigenvectors corresponding to the returned eigenvalues.
NOTE:
* Input matrix is copied; original is left untouched.
* Off-diagonal search is O(n^2) per iteration – acceptable for small n.
* Sorting of eigenpairs is intentionally left to callers so they can
  perform domain-specific post-processing (e.g. duplicate collapse in
  complex Hermitian embedding).(lu-decomposition A)(lu-decomposition A eps)Compute LU decomposition of a complex matrix A with partial pivoting. Returns a map with permutation vector P, lower triangular L and upper triangular U matrices in SoA form.
Compute LU decomposition of a complex matrix A with partial pivoting. Returns a map with permutation vector P, lower triangular L and upper triangular U matrices in SoA form.
(matrix-exp A)Compute matrix exponential of a complex matrix A. Returns a complex matrix in SoA form.
Compute matrix exponential of a complex matrix A. Returns a complex matrix in SoA form.
(matrix-log A)Compute matrix logarithm of a complex matrix A. Returns a complex matrix in SoA form.
Compute matrix logarithm of a complex matrix A. Returns a complex matrix in SoA form.
(matrix-sqrt A)Compute matrix square root of a complex matrix A. Returns a complex matrix in SoA form.
Compute matrix square root of a complex matrix A. Returns a complex matrix in SoA form.
(matrix-subtract-scalar A s)Subtract a scalar from the diagonal of a matrix A - sI.
Subtract a scalar from the diagonal of a matrix A - sI.
(norm2 x)Compute L2 norm of complex vector x (SoA form). Returns a non-negative real number.
Compute L2 norm of complex vector x (SoA form). Returns a non-negative real number.
(normalize-complex-phase v eps)Normalize global phase of complex vector v (SoA map) so the first non-negligible component becomes real and non-negative.
Parameters:
Returns new complex vector map with adjusted :real/:imag.
If all components are (near) zero the vector is returned unchanged.
Normalize global phase of complex vector v (SoA map) so the first
non-negligible component becomes real and non-negative.
Parameters:
- v   {:real [...], :imag [...]} (assumed already L2-normalized or close)
- eps magnitude threshold to select the reference component.
Returns new complex vector map with adjusted :real/:imag.
If all components are (near) zero the vector is returned unchanged.(outer-product x y)Compute outer product of complex vectors x and y. Returns a complex matrix in SoA form.
Compute outer product of complex vectors x and y. Returns a complex matrix in SoA form.
(positive-semidefinite? A)(positive-semidefinite? A eps)Check if complex matrix A is positive semidefinite. Returns true if A is PSD, false otherwise. Optionally accepts a tolerance for numerical stability.
Check if complex matrix A is positive semidefinite. Returns true if A is PSD, false otherwise. Optionally accepts a tolerance for numerical stability.
(qr-decomposition A)Compute QR decomposition of a complex matrix A. Returns a map with orthogonal matrix Q and upper triangular matrix R in SoA form.
Compute QR decomposition of a complex matrix A. Returns a map with orthogonal matrix Q and upper triangular matrix R in SoA form.
(qr-eigenvalues A max-iterations tolerance)Compute eigenvalues of a matrix using QR algorithm with Wilkinson shifts.
Compute eigenvalues of a matrix using QR algorithm with Wilkinson shifts.
(solve-linear A b)Solve complex linear system A x = b and return complex vector representation.
Solve complex linear system A x = b and return complex vector representation.
(spectral-norm A)Compute spectral norm of complex matrix A via power iteration on A^H A with Rayleigh quotient convergence.
Compute spectral norm of complex matrix A via power iteration on A^H A with Rayleigh quotient convergence.
(svd A)(svd A eps)Compute singular value decomposition of a complex matrix A. Returns a map with singular values and left/right singular vectors in SoA form. Optionally accepts a tolerance for numerical stability.
Compute singular value decomposition of a complex matrix A. Returns a map with singular values and left/right singular vectors in SoA form. Optionally accepts a tolerance for numerical stability.
(trace A)Compute trace of complex matrix A (SoA form). Returns a complex scalar.
Compute trace of complex matrix A (SoA form). Returns a complex scalar.
(unitary? U)(unitary? U eps)Check if complex matrix U is unitary (U^H U = I). Returns true if unitary, false otherwise. Optionally accepts a tolerance for numerical stability.
Check if complex matrix U is unitary (U^H U = I). Returns true if unitary, false otherwise. Optionally accepts a tolerance for numerical stability.
(wilkinson-shift A n)Compute Wilkinson shift for a 2x2 complex matrix. The shift is chosen to accelerate convergence of the QR algorithm.
Compute Wilkinson shift for a 2x2 complex matrix. The shift is chosen to accelerate convergence of the QR algorithm.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs | 
| ← | Move to previous article | 
| → | Move to next article | 
| Ctrl+/ | Jump to the search field |