/** * Typed Matrix Operations * * Advanced matrix operations including characteristic polynomial, * row reduction (RREF), Cholesky decomposition, Hessenberg form, * matrix power/log, polar decomposition, and Jordan form. * * All functions operate on number[][] (nested arrays) for consistency * with the rest of the typed functions layer. SVD and eigendecomposition * are delegated to @danielsimonjr/mathts-matrix when needed. * * @packageDocumentation */ type f64 = number; type i32 = number; /** * Compute the characteristic polynomial of a square matrix. * * Returns coefficients of det(A - lambda*I) in ascending power order: * [c0, c1, ..., cn] represents c0 + c1*lambda + ... + cn*lambda^n. * * Uses the Faddeev-LeVerrier algorithm which computes the coefficients * from traces of successive matrix powers, achieving O(n^4) complexity. * * @param A - Square matrix (n x n) * @returns Coefficient array of length n+1 (ascending power order) * * @example * // Matrix [[2,1],[1,2]] has char poly lambda^2 - 4*lambda + 3 * characteristicPolynomial([[2,1],[1,2]]) // => [3, -4, 1] */ export declare function characteristicPolynomial(A: number[][]): Promise; /** * Compute the reduced row echelon form (RREF) of a matrix. * * Uses Gauss-Jordan elimination with partial pivoting for numerical * stability. The result has leading 1s in each pivot column and zeros * in all other entries of pivot columns. * * @param A - Matrix (m x n), not modified in place * @param tol - Tolerance for zero detection (default 1e-10) * @returns RREF matrix (m x n) * * @example * rowReduce([[1,2,3],[4,5,6],[7,8,9]]) * // => [[1,0,-1],[0,1,2],[0,0,0]] */ export declare function rowReduce(A: number[][], tol?: f64): number[][]; /** * Compute the rank of a matrix using RREF. * * The rank is the number of nonzero rows in the reduced row echelon form, * which equals the number of pivot columns. * * @param A - Matrix (m x n) * @param tol - Tolerance for zero detection (default 1e-10) * @returns Rank (number of linearly independent rows/columns) * * @example * matrixRank([[1,2],[2,4]]) // => 1 * matrixRank([[1,0],[0,1]]) // => 2 */ export declare function matrixRank(A: number[][], tol?: f64): i32; /** * Result of Cholesky decomposition. */ export interface CholeskyResult { /** Lower triangular matrix L such that A = L * L^T */ L: number[][]; } /** * Cholesky decomposition of a symmetric positive-definite matrix. * * Decomposes A = L * L^T where L is lower triangular with positive * diagonal entries. The matrix must be symmetric and positive definite, * otherwise an error is thrown. * * @param A - Symmetric positive-definite matrix (n x n) * @returns Object with L (lower triangular factor) * @throws Error if matrix is not symmetric or not positive definite * * @example * cholesky([[4,2],[2,3]]) * // => { L: [[2,0],[1, Math.sqrt(2)]] } */ export declare function cholesky(A: number[][]): CholeskyResult; /** * Result of Hessenberg reduction. */ export interface HessenbergResult { /** Upper Hessenberg matrix H */ H: number[][]; /** Orthogonal transformation matrix Q such that A = Q * H * Q^T */ Q: number[][]; } /** * Reduce a square matrix to upper Hessenberg form using Householder reflections. * * Computes Q and H such that A = Q * H * Q^T, where H is upper Hessenberg * (zero below the first subdiagonal) and Q is orthogonal. * * @param A - Square matrix (n x n) * @returns Object with H (Hessenberg) and Q (orthogonal) * * @example * const { H, Q } = hessenbergForm([[1,2,3],[4,5,6],[7,8,9]]); * // H is upper Hessenberg, Q is orthogonal, A = Q * H * Q^T */ export declare function hessenbergForm(A: number[][]): HessenbergResult; /** * Compute a matrix raised to an integer or fractional power. * * For non-negative integers: uses binary exponentiation (repeated squaring). * For p = -1: computes the matrix inverse via Gauss-Jordan elimination. * For negative integers: computes inverse then raises to |p|. * For fractional p: uses eigendecomposition A = V * diag(lambda) * V^{-1}, * then A^p = V * diag(lambda^p) * V^{-1}. * * @param A - Square matrix (n x n) * @param p - Exponent (integer or fractional) * @returns A^p as an n x n matrix * * @example * matrixPower([[1,1],[0,1]], 3) // => [[1,3],[0,1]] * matrixPower([[4,0],[0,9]], 0.5) // => [[2,0],[0,3]] */ export declare function matrixPower(A: number[][], p: f64): Promise; /** * Compute the matrix logarithm. * * For matrices near the identity, uses the Padé approximant of log(I + X) * with inverse scaling and squaring. For general matrices, uses eigendecomposition: * log(A) = V * diag(log(lambda_i)) * V^{-1}. * * @param A - Square matrix with positive real eigenvalues * @returns log(A) as an n x n matrix * * @example * // log(exp([[0,1],[0,0]])) should recover [[0,1],[0,0]] * matrixLog([[1,1],[0,1]]) // => [[0,1],[0,0]] */ export declare function matrixLog(A: number[][]): Promise; /** * Result of polar decomposition. */ export interface PolarResult { /** Unitary factor U (orthogonal for real matrices) */ U: number[][]; /** Positive semi-definite factor P */ P: number[][]; } /** * Compute the polar decomposition A = U * P. * * U is unitary (orthogonal for real matrices) and P is symmetric positive * semi-definite. Computed via SVD: if A = W*S*V^T, then U = W*V^T and P = V*S*V^T. * * @param A - Square matrix (n x n) * @returns Object with U (unitary) and P (positive semi-definite) * * @example * const { U, P } = polarDecomposition([[1,0],[0,2]]); * // U is identity (or close), P = [[1,0],[0,2]] */ export declare function polarDecomposition(A: number[][]): Promise; /** * Result of Jordan decomposition. */ export interface JordanResult { /** Jordan normal form matrix J */ J: number[][]; /** Transformation matrix P such that A = P * J * P^{-1} */ P: number[][]; } /** * Compute the Jordan normal form of a square matrix. * * For matrices with distinct eigenvalues, this is simply the diagonal * matrix of eigenvalues. For repeated eigenvalues, Jordan blocks are * formed by analyzing the null spaces of (A - lambda*I)^k. * * Note: This implementation works best for matrices with real eigenvalues * and reasonably well-conditioned eigenvectors. For matrices with complex * eigenvalues, only the real parts are used. * * @param A - Square matrix (n x n) * @returns Object with J (Jordan form) and P (transformation matrix) * * @example * // Diagonal matrix with distinct eigenvalues * jordanForm([[2,0],[0,3]]) // => { J: [[2,0],[0,3]], P: ... } */ export declare function jordanForm(A: number[][]): Promise; /** * Compute the Moore-Penrose pseudoinverse of a DenseMatrix (Option A — Slice 4.2 primitive). * * Delegates to the DenseMatrix-based `matrixPinv` from `@danielsimonjr/mathts-matrix`, * which uses full SVD with `rcond · max(S)` singular-value thresholding. * * @example * const A = DenseMatrix.fromArray([[1,2],[3,4],[5,6]]); * const Ap = pinv(A); // shape 2x3 * const Ap2 = pinv(A, { rcond: 1e-6 }); */ export declare const pinv: import("@danielsimonjr/mathts-core").TypedFunction; /** * Compute the condition number of a matrix (ratio σ_max / σ_min via SVD). * * Returns `Infinity` for singular or rank-deficient matrices. * * @example * cond([[1,0],[0,2]]) // => 2 * cond([[1,2],[2,4]]) // => Infinity */ export declare const cond: import("@danielsimonjr/mathts-core").TypedFunction; /** * Compute the spectral norm (2-norm) of a matrix — the largest singular value. * * @example * norm2([[3,0],[0,2]]) // => 3 */ export declare const norm2: import("@danielsimonjr/mathts-core").TypedFunction; /** * Compute the Frobenius norm of a matrix — `sqrt(sum(A_ij²))`. * * @example * normFro([[1,0],[0,1]]) // => sqrt(2) ≈ 1.414 */ export declare const normFro: import("@danielsimonjr/mathts-core").TypedFunction; /** * Compute a rank-k approximation of a matrix using truncated SVD. * * Returns the best rank-k approximation in the Frobenius-norm sense: * `A_k = U[:, :k] * diag(S[:k]) * V[:, :k]^T`. * * @example * lowRankApprox([[1,2],[3,4],[5,6]], 1) */ export declare const lowRankApprox: import("@danielsimonjr/mathts-core").TypedFunction; /** * Return the singular values of a matrix in descending order. * * The result has length `min(m, n)` and all values are non-negative. * * @example * singularValues([[3,0],[0,2]]) // => [3, 2] */ export declare const singularValues: import("@danielsimonjr/mathts-core").TypedFunction; /** * Compute the matrix exponential via Padé-13 scaling-and-squaring. * * Dispatches on `DenseMatrix` (returns `DenseMatrix`) or `Array` (number[][], * wraps in DenseMatrix, returns number[][]). * * Algorithm: Higham (2005) "The scaling and squaring method for the matrix * exponential revisited." Accurate to near machine precision for general real * matrices. * * @example * matrixExpm(DenseMatrix.zeros(3, 3)) // => identity DenseMatrix * matrixExpm([[0,0],[0,0]]) // => [[1,0],[0,1]] * matrixExpm([[1,0],[0,1]]) // => [[e,0],[0,e]] */ export declare const matrixExpm: import("@danielsimonjr/mathts-core").TypedFunction; /** * Compute the principal matrix logarithm via inverse scaling-and-squaring * with 16-point Gauss-Legendre quadrature for log(I + X). * * Dispatches on `DenseMatrix` (returns `DenseMatrix`) or `Array` (returns * number[][]). Throws for matrices with non-positive or complex eigenvalues. * * Slice 5.9a limitations: * - Non-positive eigenvalues: throws (principal log undefined). * - Complex eigenvalues: throws. * - Full Schur-based algorithm for non-diagonalisable A: Slice 5.9b. * * @example * matrixLogm(DenseMatrix.eye(3)) // => zero DenseMatrix * matrixLogm([[Math.E,0],[0,Math.E]]) // => [[1,0],[0,1]] */ export declare const matrixLogm: import("@danielsimonjr/mathts-core").TypedFunction; /** * Compute the principal square root of a matrix. * * For symmetric positive semi-definite A: uses Newton iteration (robust for * all non-negative eigenvalue cases). For general diagonalisable A: Newton * iteration falling back to eigendecomposition. * * Dispatches on `DenseMatrix` (returns `DenseMatrix`) or `Array` (returns * number[][]). Throws for matrices with negative or complex eigenvalues. * * Slice 5.9a limitations: * - Negative eigenvalues: throws (complex sqrt not supported). * - Complex eigenvalues: throws. * - Full Schur-based Björck-Hammarling: Slice 5.9b. * * @example * matrixSqrtm(DenseMatrix.fromArray([[4,0],[0,9]])) // => [[2,0],[0,3]] DenseMatrix * matrixSqrtm([[4,0],[0,9]]) // => [[2,0],[0,3]] */ export declare const matrixSqrtm: import("@danielsimonjr/mathts-core").TypedFunction; export {}; //# sourceMappingURL=matrix-ops.d.ts.map