/** * Iterative Krylov-subspace linear solvers. * * For the large sparse systems a dense factorization (`lusolve`, `qr`, …) * can't handle — none of these methods ever form or fill in `A`. Each solver * accepts either a dense matrix or a matvec callback (a "linear operator" in * the SciPy/Trilinos sense), plus an optional preconditioner: * * - `cg` — Conjugate Gradient, for symmetric positive-definite `A`. * - `minres` — MINRES, for symmetric (possibly indefinite) `A`. * - `gmres` — restarted GMRES, for general nonsymmetric `A`. * - `bicgstab` — BiCGSTAB, for general nonsymmetric `A`. * * @packageDocumentation */ /** A linear operator: either a dense matrix or a matvec callback `x -> A x`. */ export type LinearOperatorInput = number[][] | ((x: number[]) => number[]); /** * Preconditioner. The three built-ins require a dense matrix (they read `A`'s * entries): `'jacobi'` (diagonal `M⁻¹ = diag(1/Aᵢᵢ)`), `'ilu'` (ILU(0) — * incomplete LU with zero fill on `A`'s sparsity pattern, for general `A`), * `'ic'` (IC(0) — incomplete Cholesky, for symmetric positive-definite `A`). * Or pass a custom `M⁻¹` callback (the only option that works with a * matvec-only operator). */ export type Preconditioner = 'jacobi' | 'ilu' | 'ic' | ((r: number[]) => number[]); /** Common options accepted by every solver in this module. */ export interface KrylovOptions { /** Initial guess (default: the zero vector). */ x0?: number[]; /** Relative-residual convergence tolerance (default 1e-10). */ tol?: number; /** Maximum iterations (default `min(10 * n, 1000)`). */ maxIter?: number; /** Preconditioner: `'jacobi'` or a custom `(r) => M⁻¹r` callback. */ preconditioner?: Preconditioner; } /** Options for {@link gmres}, adding the restart length. */ export interface GmresOptions extends KrylovOptions { /** Restart length (default 30). */ restart?: number; } /** Result returned by every solver in this module. */ export interface KrylovResult { /** Approximate solution. */ x: number[]; /** Number of iterations performed. */ iterations: number; /** Whether the relative residual dropped below `tol`. */ converged: boolean; /** Final relative residual `‖b − A x‖₂ / ‖b‖₂`. */ residual: number; } /** * ILU(0) — incomplete LU factorization with zero fill. Returns unit-lower `L` * and upper `U` (dense, with zeros outside `A`'s sparsity pattern) such that * `(L·U)ᵢⱼ = Aᵢⱼ` on that pattern, dropping any fill that would arise outside * it. The classic preconditioner for iterative solvers on general sparse `A`. * * @example * incompleteLU([[4,1,0],[1,4,1],[0,1,4]]) // tridiagonal → exact LU (no fill) */ export declare function incompleteLU(a: readonly number[][]): { L: number[][]; U: number[][]; }; /** * IC(0) — incomplete Cholesky factorization with zero fill, for symmetric * positive-definite `A`. Returns lower-triangular `L` on `A`'s sparsity pattern * with `(L·Lᵀ)ᵢⱼ = Aᵢⱼ` there. Throws on a non-positive pivot (the `A`-is-SPD * precondition failed). * * @example * incompleteCholesky([[4,1,0],[1,4,1],[0,1,4]]) // tridiagonal → exact Cholesky */ export declare function incompleteCholesky(a: readonly number[][]): { L: number[][]; }; /** * Conjugate Gradient (CG) — for symmetric positive-definite `A`. * * @example * cg([[4, 1], [1, 3]], [1, 2]) // => { x: [1/11, 7/11], converged: true, ... } */ export declare function cg(a: LinearOperatorInput, b: number[], opts?: KrylovOptions): KrylovResult; /** * MINRES — for symmetric (possibly indefinite) `A`. * * The Paige–Saunders short-recurrence MINRES (Paige & Saunders 1975): a * preconditioned Lanczos tridiagonalization coupled with an incrementally * updated Givens-rotation QR of the tridiagonal. Each iteration does a fixed * number of length-`n` vector operations (one matvec + a handful of `axpy`s) * and **O(1)** scalar work — no growing least-squares is ever formed or * solved. The solution is advanced through a running 3-term `w`-recurrence, so * the whole solve is **O(k·n)** for `k` iterations rather than the O(k³) of the * former "re-solve the growing `(k+1)×k` tridiagonal each step" formulation. * * With a preconditioner `M`, the loop converges the `M⁻¹`-norm relative * residual `‖r_k‖_{M⁻¹} / ‖r_0‖_{M⁻¹}` (the estimate MINRES minimizes); for * `M = I` this equals `‖b − A x‖₂ / ‖b‖₂`. The reported `residual`/`converged` * are always computed from the true Euclidean residual (one final matvec). * * @example * minres([[0, 1], [1, 0]], [1, 2]) // => { x: [2, 1], converged: true, ... } */ export declare function minres(a: LinearOperatorInput, b: number[], opts?: KrylovOptions): KrylovResult; /** * Restarted GMRES — for general nonsymmetric `A`. * * @example * gmres([[3, 1], [0, 2]], [4, 2]) // => { x: [1, 1], converged: true, ... } */ export declare function gmres(a: LinearOperatorInput, b: number[], opts?: GmresOptions): KrylovResult; /** * BiCGSTAB — for general nonsymmetric `A`. * * @example * bicgstab([[3, 1], [0, 2]], [4, 2]) // => { x: [1, 1], converged: true, ... } */ export declare function bicgstab(a: LinearOperatorInput, b: number[], opts?: KrylovOptions): KrylovResult; //# sourceMappingURL=krylov.d.ts.map