@danielsimonjr/mathts-functions 0.34.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/geometry/geometry-extra.d.ts +109 -0
- package/dist/geometry/geometry-extra.d.ts.map +1 -0
- package/dist/graph/optimization.d.ts +116 -0
- package/dist/graph/optimization.d.ts.map +1 -0
- package/dist/graph/traversal-centrality.d.ts +147 -0
- package/dist/graph/traversal-centrality.d.ts.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2522 -456
- package/dist/numeric/control-equations.d.ts +94 -0
- package/dist/numeric/control-equations.d.ts.map +1 -0
- package/dist/numeric/eigsh.d.ts +60 -0
- package/dist/numeric/eigsh.d.ts.map +1 -0
- package/dist/numeric/interpn.d.ts +40 -0
- package/dist/numeric/interpn.d.ts.map +1 -0
- package/dist/numeric/interval.d.ts +84 -0
- package/dist/numeric/interval.d.ts.map +1 -0
- package/dist/numeric/krylov.d.ts +83 -0
- package/dist/numeric/krylov.d.ts.map +1 -0
- package/dist/numeric/matrix-functions.d.ts +74 -0
- package/dist/numeric/matrix-functions.d.ts.map +1 -0
- package/dist/numeric/structured-solvers.d.ts +89 -0
- package/dist/numeric/structured-solvers.d.ts.map +1 -0
- package/dist/typed/algebra.d.ts +40 -3
- package/dist/typed/algebra.d.ts.map +1 -1
- package/dist/typed/numeric.d.ts +19 -4
- package/dist/typed/numeric.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Control-theory matrix equations — `dlyap`/`care`/`dare`.
|
|
3
|
+
*
|
|
4
|
+
* These solve the algebraic matrix equations that underlie LQR (linear-
|
|
5
|
+
* quadratic regulator) and Kalman-filter design:
|
|
6
|
+
*
|
|
7
|
+
* - {@link dlyap} — discrete Lyapunov equation `A X Aᵀ − X + Q = 0`, solved
|
|
8
|
+
* directly via the Kronecker-product linear system
|
|
9
|
+
* `(I − A⊗A) vec(X) = vec(Q)` (exact for the small `n` this targets;
|
|
10
|
+
* the codebase's `linsolve` does the O(n²)³ = O(n⁶) dense solve).
|
|
11
|
+
* - {@link care} — continuous algebraic Riccati equation
|
|
12
|
+
* `AᵀX + XA − X B R⁻¹ Bᵀ X + Q = 0`, solved via the **matrix sign
|
|
13
|
+
* function** applied to the Hamiltonian `H = [[A, −BR⁻¹Bᵀ], [−Q, −Aᵀ]]`.
|
|
14
|
+
* This avoids both complex eigenvectors (this codebase's `eig` only
|
|
15
|
+
* returns real eigenvector columns — see `matrix-functions.ts` — so a
|
|
16
|
+
* Hamiltonian-eigenvector approach isn't usable here) and the need for a
|
|
17
|
+
* stabilizing initial gain that a Kleinman/Newton iteration would
|
|
18
|
+
* require (the natural starting point `X₀ = 0` is not stabilizing for
|
|
19
|
+
* e.g. the classic double-integrator `A = [[0,1],[0,0]]`, which is only
|
|
20
|
+
* marginally stable). The sign-function Newton iteration converges
|
|
21
|
+
* unconditionally (given the standard stabilizability/detectability
|
|
22
|
+
* assumptions) directly from `H` itself.
|
|
23
|
+
* - {@link dare} — discrete algebraic Riccati equation
|
|
24
|
+
* `AᵀXA − X − AᵀXB(R + BᵀXB)⁻¹BᵀXA + Q = 0`, solved via the
|
|
25
|
+
* **structure-preserving doubling algorithm** (SDA), the discrete-time
|
|
26
|
+
* analogue of the sign-function method above: it iterates a triple
|
|
27
|
+
* `(Aₖ, Gₖ, Hₖ)` with quadratic convergence and, likewise, needs no
|
|
28
|
+
* stabilizing initial gain.
|
|
29
|
+
*
|
|
30
|
+
* All three return the (numerically symmetrized) stabilizing solution `X`.
|
|
31
|
+
* Both `care`/`dare` require `R` invertible and `(A, B)` stabilizable — the
|
|
32
|
+
* standard LQR well-posedness assumptions.
|
|
33
|
+
*
|
|
34
|
+
* @packageDocumentation
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Solve the discrete-time Lyapunov (Stein) equation `A X Aᵀ − X + Q = 0` for
|
|
38
|
+
* `X`, given square `A` and `Q` of the same size.
|
|
39
|
+
*
|
|
40
|
+
* Builds the Kronecker-product linear system `(I − A⊗A) vec(X) = vec(Q)`
|
|
41
|
+
* explicitly (practical for the `n ≲ 20` this targets — the system has
|
|
42
|
+
* `n²` unknowns) and solves it with `linsolve`.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* dlyap([[0.5, 0], [0, 0.5]], [[1, 0], [0, 1]]) // => (4/3) * I (since 0.25x - x + 1 = 0)
|
|
46
|
+
*/
|
|
47
|
+
export declare function dlyap(A: number[][], Q: number[][]): number[][];
|
|
48
|
+
/**
|
|
49
|
+
* Solve the continuous-time algebraic Riccati equation (CARE)
|
|
50
|
+
* `AᵀX + XA − X B R⁻¹ Bᵀ X + Q = 0` for the stabilizing symmetric `X`,
|
|
51
|
+
* given `A` (n×n), `B` (n×m), `Q` (n×n, typically PSD), `R` (m×m, invertible).
|
|
52
|
+
*
|
|
53
|
+
* Method: Newton iteration for the **matrix sign function** of the
|
|
54
|
+
* Hamiltonian `H = [[A, −BR⁻¹Bᵀ], [−Q, −Aᵀ]]` (2n×2n):
|
|
55
|
+
*
|
|
56
|
+
* `Zₖ₊₁ = ½(cₖ Zₖ + cₖ⁻¹ Zₖ⁻¹)`, `Z₀ = H`, `cₖ = √(‖Zₖ⁻¹‖₁ / ‖Zₖ‖₁)`
|
|
57
|
+
*
|
|
58
|
+
* converging quadratically to `S = sign(H)`. The projector `P = ½(I − S)`
|
|
59
|
+
* has range equal to `H`'s stable (Re λ < 0) invariant subspace; taking its
|
|
60
|
+
* first `n` columns `U = [U₁; U₂]` (split at the `n`-th row) gives
|
|
61
|
+
* `X = U₂ U₁⁻¹` (real arithmetic throughout — no complex eigenvectors
|
|
62
|
+
* needed, unlike the classical Hamiltonian-eigenvector construction).
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* care([[0, 1], [0, 0]], [[0], [1]], [[1, 0], [0, 1]], [[1]])
|
|
66
|
+
* // => [[sqrt(3), 1], [1, sqrt(3)]] (pinned vs scipy.linalg.solve_continuous_are)
|
|
67
|
+
*/
|
|
68
|
+
export declare function care(A: number[][], B: number[][], Q: number[][], R: number[][]): number[][];
|
|
69
|
+
/**
|
|
70
|
+
* Solve the discrete-time algebraic Riccati equation (DARE)
|
|
71
|
+
* `AᵀXA − X − AᵀXB(R + BᵀXB)⁻¹BᵀXA + Q = 0` for the stabilizing symmetric
|
|
72
|
+
* `X`, given `A` (n×n), `B` (n×m), `Q` (n×n, typically PSD), `R` (m×m,
|
|
73
|
+
* invertible).
|
|
74
|
+
*
|
|
75
|
+
* Method: the **structure-preserving doubling algorithm** (SDA) — the
|
|
76
|
+
* discrete-time analogue of the sign-function iteration used by {@link care}.
|
|
77
|
+
* Starting from `A₀ = A`, `G₀ = B R⁻¹ Bᵀ`, `H₀ = Q`, it iterates
|
|
78
|
+
*
|
|
79
|
+
* `Aₖ₊₁ = Aₖ(I + GₖHₖ)⁻¹Aₖ`
|
|
80
|
+
* `Gₖ₊₁ = Gₖ + Aₖ(I + GₖHₖ)⁻¹Gₖ Aₖᵀ`
|
|
81
|
+
* `Hₖ₊₁ = Hₖ + Aₖᵀ Hₖ(I + GₖHₖ)⁻¹Aₖ`
|
|
82
|
+
*
|
|
83
|
+
* with `Hₖ → X` quadratically. Like {@link care}'s sign-function method, this
|
|
84
|
+
* needs no stabilizing initial gain (unlike a Kleinman/Newton iteration on
|
|
85
|
+
* the DARE directly) — only the standard stabilizability/detectability
|
|
86
|
+
* assumptions.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* dare([[1, 1], [0, 1]], [[0], [1]], [[1, 0], [0, 1]], [[1]])
|
|
90
|
+
* // => [[2.94712297, 2.36920541], [2.36920541, 4.61313426]]
|
|
91
|
+
* // (pinned vs scipy.linalg.solve_discrete_are)
|
|
92
|
+
*/
|
|
93
|
+
export declare function dare(A: number[][], B: number[][], Q: number[][], R: number[][]): number[][];
|
|
94
|
+
//# sourceMappingURL=control-equations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-equations.d.ts","sourceRoot":"","sources":["../../src/numeric/control-equations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAuJH;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAgB9D;AASD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CA6C3F;AAMD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CA+B3F"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterative symmetric eigensolver — Lanczos tridiagonalization + Rayleigh-Ritz.
|
|
3
|
+
*
|
|
4
|
+
* For large symmetric problems where the dense `eigs` (full O(n^3)
|
|
5
|
+
* eigendecomposition of the whole matrix) is prohibitive, `eigsh` extracts
|
|
6
|
+
* just the `k` largest or smallest eigenpairs. It builds an orthonormal
|
|
7
|
+
* Krylov basis `V` via the Lanczos iteration (with full reorthogonalization
|
|
8
|
+
* against every prior Lanczos vector, for numerical stability at the small
|
|
9
|
+
* sizes this is exercised at), forming the small tridiagonal projection
|
|
10
|
+
* `T = Vᵀ A V`. `T`'s eigenproblem is solved directly (cyclic Jacobi
|
|
11
|
+
* rotations — `T` is dense-symmetric-small by construction) and lifted back
|
|
12
|
+
* through `V` (Rayleigh-Ritz) to approximate `A`'s eigenpairs. Accepts either
|
|
13
|
+
* a dense matrix or a matvec callback (a linear operator, matching the
|
|
14
|
+
* `krylov.ts` convention) — the matvec form never forms `A` and requires
|
|
15
|
+
* `opts.n` since the dimension can't otherwise be inferred.
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
/** A symmetric linear operator: either a dense matrix or a matvec callback `x -> A x`. */
|
|
20
|
+
export type EigshOperatorInput = number[][] | ((x: number[]) => number[]);
|
|
21
|
+
/** Options accepted by {@link eigsh}. */
|
|
22
|
+
export interface EigshOptions {
|
|
23
|
+
/** Which end of the spectrum to return: `'LM'` (largest, default) or `'SM'` (smallest). */
|
|
24
|
+
which?: 'LM' | 'SM';
|
|
25
|
+
/** Dimension of `A` — required when `A` is a matvec callback. */
|
|
26
|
+
n?: number;
|
|
27
|
+
/** Convergence tolerance for diagonalizing the small tridiagonal projection (default 1e-10). */
|
|
28
|
+
tol?: number;
|
|
29
|
+
/** Maximum Lanczos steps (default `min(max(2k + 20, 20), n)`). */
|
|
30
|
+
maxIter?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Result of {@link eigsh}.
|
|
34
|
+
*
|
|
35
|
+
* `eigenvectors` is an `n x k` matrix with eigenvectors stored as **columns**:
|
|
36
|
+
* `eigenvectors[i][j]` is the `i`-th component of the `j`-th eigenvector,
|
|
37
|
+
* which corresponds to `eigenvalues[j]`.
|
|
38
|
+
*/
|
|
39
|
+
export interface EigshResult {
|
|
40
|
+
/** The `k` selected eigenvalues, ordered by `which` (largest-first for `'LM'`, smallest-first for `'SM'`). */
|
|
41
|
+
eigenvalues: number[];
|
|
42
|
+
/** The `k` corresponding eigenvectors, as columns of an `n x k` matrix. */
|
|
43
|
+
eigenvectors: number[][];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* `eigsh` — the `k` largest or smallest eigenpairs of a **symmetric** matrix
|
|
47
|
+
* via the Lanczos iteration, for problems too large for the dense `eigs`.
|
|
48
|
+
*
|
|
49
|
+
* `A` may be a dense `number[][]` or a matvec callback `x => A x` (in which
|
|
50
|
+
* case `opts.n` is required — the dimension can't be inferred from a
|
|
51
|
+
* function). Eigenvectors are returned as **columns** of an `n x k` matrix:
|
|
52
|
+
* `result.eigenvectors[i][j]` is the `i`-th component of the eigenvector for
|
|
53
|
+
* `result.eigenvalues[j]`.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* eigsh([[2, 1, 0], [1, 2, 1], [0, 1, 2]], 1, { which: 'LM' })
|
|
57
|
+
* // => { eigenvalues: [2 + Math.SQRT2], eigenvectors: [[...]] }
|
|
58
|
+
*/
|
|
59
|
+
export declare function eigsh(a: EigshOperatorInput, k?: number, opts?: EigshOptions): EigshResult;
|
|
60
|
+
//# sourceMappingURL=eigsh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eigsh.d.ts","sourceRoot":"","sources":["../../src/numeric/eigsh.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,0FAA0F;AAC1F,MAAM,MAAM,kBAAkB,GAAG,MAAM,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;AAE1E,yCAAyC;AACzC,MAAM,WAAW,YAAY;IAC3B,2FAA2F;IAC3F,KAAK,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACpB,iEAAiE;IACjE,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,gGAAgG;IAChG,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,8GAA8G;IAC9G,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,2EAA2E;IAC3E,YAAY,EAAE,MAAM,EAAE,EAAE,CAAC;CAC1B;AAkKD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,kBAAkB,EAAE,CAAC,SAAI,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,WAAW,CAmDpF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regular-grid N-D multilinear interpolation — `scipy.interpolate.interpn`
|
|
3
|
+
* (default `method='linear'`, `bounds_error=True`).
|
|
4
|
+
*
|
|
5
|
+
* Given `n` strictly-increasing coordinate arrays (`grids`) and a matching
|
|
6
|
+
* `n`-dimensional array of sampled values, `interpn` evaluates the
|
|
7
|
+
* multilinear interpolant at each query point: for a query point, the
|
|
8
|
+
* bracketing grid cell is located along every axis (binary search), and the
|
|
9
|
+
* result is the weighted average of the `2^n` cell-corner values, weighted
|
|
10
|
+
* by the fractional position within the cell along each axis. This is exact
|
|
11
|
+
* for functions that are affine in each coordinate (e.g. `f(x,y) = x + y`)
|
|
12
|
+
* and reduces to ordinary linear interpolation when `n = 1`.
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
/** A nested numeric array of arbitrary depth (matches an N-D grid's shape). */
|
|
17
|
+
export type NDArrayInput = number | readonly NDArrayInput[];
|
|
18
|
+
/**
|
|
19
|
+
* Regular-grid multilinear interpolation, matching `scipy.interpolate.interpn`.
|
|
20
|
+
*
|
|
21
|
+
* @param grids - One strictly-increasing coordinate array per dimension (1 for
|
|
22
|
+
* 1-D, 2 for bilinear, 3 for trilinear, etc.).
|
|
23
|
+
* @param values - Sampled values on the grid, nested `grids.length` levels
|
|
24
|
+
* deep and shaped `grids.map(g => g.length)` (e.g. for 2-D,
|
|
25
|
+
* `values[i][j] === f(grids[0][i], grids[1][j])`); for 1-D, a flat
|
|
26
|
+
* `number[]`.
|
|
27
|
+
* @param query - Points to interpolate at, each with `grids.length` coordinates.
|
|
28
|
+
* @returns The interpolated value at each query point.
|
|
29
|
+
* @throws If a grid axis is not strictly increasing, if `values`' shape
|
|
30
|
+
* doesn't match `grids`, or if a query point falls outside the grid's
|
|
31
|
+
* bounding box (matches scipy's default `bounds_error=True` — no
|
|
32
|
+
* extrapolation).
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const xs = [0, 1, 2], ys = [0, 1, 2];
|
|
36
|
+
* const vals = xs.map((x) => ys.map((y) => x + y)); // f(x,y) = x + y
|
|
37
|
+
* interpn([xs, ys], vals, [[0.5, 0.5]]); // [1] (exact — f is affine)
|
|
38
|
+
*/
|
|
39
|
+
export declare function interpn(grids: readonly (readonly number[])[], values: NDArrayInput, query: readonly (readonly number[])[]): number[];
|
|
40
|
+
//# sourceMappingURL=interpn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interpn.d.ts","sourceRoot":"","sources":["../../src/numeric/interpn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,+EAA+E;AAC/E,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,SAAS,YAAY,EAAE,CAAC;AA8D5D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,OAAO,CACrB,KAAK,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EACrC,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,GACpC,MAAM,EAAE,CA0CV"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interval arithmetic with outward rounding.
|
|
3
|
+
*
|
|
4
|
+
* `Interval` (constructed via the `interval(lo, hi)` factory) implements
|
|
5
|
+
* rigorous interval arithmetic: every operation guarantees the true
|
|
6
|
+
* mathematical result over any pair of real inputs drawn from the operand
|
|
7
|
+
* intervals is contained in the returned interval. JavaScript has no access
|
|
8
|
+
* to IEEE-754 directed rounding modes (round-toward-negative-infinity /
|
|
9
|
+
* round-toward-positive-infinity), so as a practical surrogate every result
|
|
10
|
+
* is nudged outward by a tiny relative epsilon (`Number.EPSILON`) plus one
|
|
11
|
+
* ULP (`Number.MIN_VALUE`) after each operation: `lo` is decreased and `hi`
|
|
12
|
+
* is increased. This is the same idea underlying mpmath's `iv` module and
|
|
13
|
+
* MATLAB's INTLAB — a verified-bounds numeric type, the first in this
|
|
14
|
+
* library.
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* A closed real interval `[lo, hi]` with outward-rounded arithmetic.
|
|
20
|
+
*
|
|
21
|
+
* Construct via the {@link interval} factory rather than `new Interval(...)`
|
|
22
|
+
* directly (both work; the factory reads more naturally at call sites).
|
|
23
|
+
*/
|
|
24
|
+
export declare class Interval {
|
|
25
|
+
readonly lo: number;
|
|
26
|
+
readonly hi: number;
|
|
27
|
+
constructor(lo: number, hi: number);
|
|
28
|
+
/** `[this.lo + b.lo, this.hi + b.hi]`, outward-rounded. */
|
|
29
|
+
add(b: Interval): Interval;
|
|
30
|
+
/** `[this.lo - b.hi, this.hi - b.lo]`, outward-rounded. */
|
|
31
|
+
sub(b: Interval): Interval;
|
|
32
|
+
/**
|
|
33
|
+
* Interval product: the min/max of all four endpoint products
|
|
34
|
+
* (`lo*lo, lo*hi, hi*lo, hi*hi`), outward-rounded. Correct for any
|
|
35
|
+
* combination of signs.
|
|
36
|
+
*/
|
|
37
|
+
mul(b: Interval): Interval;
|
|
38
|
+
/**
|
|
39
|
+
* Interval quotient. Throws if `b` contains 0 (division would be
|
|
40
|
+
* unbounded). Otherwise the min/max of the four endpoint quotients,
|
|
41
|
+
* outward-rounded.
|
|
42
|
+
*/
|
|
43
|
+
div(b: Interval): Interval;
|
|
44
|
+
/** `[-this.hi, -this.lo]`, outward-rounded. */
|
|
45
|
+
neg(): Interval;
|
|
46
|
+
/** `hi - lo`. */
|
|
47
|
+
width(): number;
|
|
48
|
+
/** `(lo + hi) / 2`. */
|
|
49
|
+
mid(): number;
|
|
50
|
+
/** Whether the closed interval `[lo, hi]` contains the real number `x`. */
|
|
51
|
+
contains(x: number): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Square root, monotonic-increasing over `[0, +Infinity)`. Throws if the
|
|
54
|
+
* interval contains negative values (real square root is undefined there).
|
|
55
|
+
*/
|
|
56
|
+
sqrt(): Interval;
|
|
57
|
+
/** Exponential, monotonic-increasing over all reals. */
|
|
58
|
+
exp(): Interval;
|
|
59
|
+
/**
|
|
60
|
+
* Natural log, monotonic-increasing over `(0, +Infinity)`. Throws if the
|
|
61
|
+
* interval is not strictly positive.
|
|
62
|
+
*/
|
|
63
|
+
log(): Interval;
|
|
64
|
+
/**
|
|
65
|
+
* Integer power `x^n`, monotonic-aware:
|
|
66
|
+
* - `n` odd: `x^n` is monotonic-increasing over all reals, so the result is
|
|
67
|
+
* `[lo^n, hi^n]`.
|
|
68
|
+
* - `n` even, interval entirely non-negative: monotonic-increasing, so
|
|
69
|
+
* `[lo^n, hi^n]`.
|
|
70
|
+
* - `n` even, interval entirely non-positive: monotonic-decreasing (in
|
|
71
|
+
* magnitude, toward zero), so `[hi^n, lo^n]`.
|
|
72
|
+
* - `n` even, interval spans zero: the minimum is `0` (attained at `x=0`)
|
|
73
|
+
* and the maximum is `max(|lo|, |hi|)^n`.
|
|
74
|
+
* - `n` negative: computed as the reciprocal of `pow(-n)`; throws if that
|
|
75
|
+
* positive-power interval contains zero (division by zero).
|
|
76
|
+
* - `n = 0`: `[1, 1]` for every interval.
|
|
77
|
+
*
|
|
78
|
+
* Throws if `n` is not an integer.
|
|
79
|
+
*/
|
|
80
|
+
pow(n: number): Interval;
|
|
81
|
+
}
|
|
82
|
+
/** Construct an `Interval([lo, hi])`. Throws if `lo > hi`. */
|
|
83
|
+
export declare function interval(lo: number, hi: number): Interval;
|
|
84
|
+
//# sourceMappingURL=interval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interval.d.ts","sourceRoot":"","sources":["../../src/numeric/interval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAYH;;;;;GAKG;AACH,qBAAa,QAAQ;IACnB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;gBAER,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAQlC,2DAA2D;IAC3D,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,QAAQ;IAI1B,2DAA2D;IAC3D,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,QAAQ;IAI1B;;;;OAIG;IACH,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,QAAQ;IAQ1B;;;;OAIG;IACH,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,QAAQ;IAW1B,+CAA+C;IAC/C,GAAG,IAAI,QAAQ;IAIf,iBAAiB;IACjB,KAAK,IAAI,MAAM;IAIf,uBAAuB;IACvB,GAAG,IAAI,MAAM;IAIb,2EAA2E;IAC3E,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO;IAI5B;;;OAGG;IACH,IAAI,IAAI,QAAQ;IAOhB,wDAAwD;IACxD,GAAG,IAAI,QAAQ;IAIf;;;OAGG;IACH,GAAG,IAAI,QAAQ;IAOf;;;;;;;;;;;;;;;OAeG;IACH,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ;CA2BzB;AAED,8DAA8D;AAC9D,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,QAAQ,CAEzD"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterative Krylov-subspace linear solvers.
|
|
3
|
+
*
|
|
4
|
+
* For the large sparse systems a dense factorization (`lusolve`, `qr`, …)
|
|
5
|
+
* can't handle — none of these methods ever form or fill in `A`. Each solver
|
|
6
|
+
* accepts either a dense matrix or a matvec callback (a "linear operator" in
|
|
7
|
+
* the SciPy/Trilinos sense), plus an optional preconditioner:
|
|
8
|
+
*
|
|
9
|
+
* - `cg` — Conjugate Gradient, for symmetric positive-definite `A`.
|
|
10
|
+
* - `minres` — MINRES, for symmetric (possibly indefinite) `A`.
|
|
11
|
+
* - `gmres` — restarted GMRES, for general nonsymmetric `A`.
|
|
12
|
+
* - `bicgstab` — BiCGSTAB, for general nonsymmetric `A`.
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
/** A linear operator: either a dense matrix or a matvec callback `x -> A x`. */
|
|
17
|
+
export type LinearOperatorInput = number[][] | ((x: number[]) => number[]);
|
|
18
|
+
/** Preconditioner: `'jacobi'` (diagonal, dense-matrix only) or a custom `M⁻¹` callback. */
|
|
19
|
+
export type Preconditioner = 'jacobi' | ((r: number[]) => number[]);
|
|
20
|
+
/** Common options accepted by every solver in this module. */
|
|
21
|
+
export interface KrylovOptions {
|
|
22
|
+
/** Initial guess (default: the zero vector). */
|
|
23
|
+
x0?: number[];
|
|
24
|
+
/** Relative-residual convergence tolerance (default 1e-10). */
|
|
25
|
+
tol?: number;
|
|
26
|
+
/** Maximum iterations (default `min(10 * n, 1000)`). */
|
|
27
|
+
maxIter?: number;
|
|
28
|
+
/** Preconditioner: `'jacobi'` or a custom `(r) => M⁻¹r` callback. */
|
|
29
|
+
preconditioner?: Preconditioner;
|
|
30
|
+
}
|
|
31
|
+
/** Options for {@link gmres}, adding the restart length. */
|
|
32
|
+
export interface GmresOptions extends KrylovOptions {
|
|
33
|
+
/** Restart length (default 30). */
|
|
34
|
+
restart?: number;
|
|
35
|
+
}
|
|
36
|
+
/** Result returned by every solver in this module. */
|
|
37
|
+
export interface KrylovResult {
|
|
38
|
+
/** Approximate solution. */
|
|
39
|
+
x: number[];
|
|
40
|
+
/** Number of iterations performed. */
|
|
41
|
+
iterations: number;
|
|
42
|
+
/** Whether the relative residual dropped below `tol`. */
|
|
43
|
+
converged: boolean;
|
|
44
|
+
/** Final relative residual `‖b − A x‖₂ / ‖b‖₂`. */
|
|
45
|
+
residual: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Conjugate Gradient (CG) — for symmetric positive-definite `A`.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* cg([[4, 1], [1, 3]], [1, 2]) // => { x: [1/11, 7/11], converged: true, ... }
|
|
52
|
+
*/
|
|
53
|
+
export declare function cg(a: LinearOperatorInput, b: number[], opts?: KrylovOptions): KrylovResult;
|
|
54
|
+
/**
|
|
55
|
+
* MINRES — for symmetric (possibly indefinite) `A`.
|
|
56
|
+
*
|
|
57
|
+
* Builds the preconditioned Lanczos tridiagonalization of `A` and, at each
|
|
58
|
+
* step, solves the growing `(k+1) x k` tridiagonal least-squares problem
|
|
59
|
+
* `min ||beta1 e1 - T_k y||` via a small dense Householder QR. This is the
|
|
60
|
+
* textbook MINRES minimization restated directly (rather than the
|
|
61
|
+
* incrementally-updated Givens-rotation form), which keeps it simple to
|
|
62
|
+
* verify against a closed-form oracle at the cost of some redundant work
|
|
63
|
+
* per iteration — acceptable since `maxIter` is bounded by `min(10n, 1000)`.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* minres([[0, 1], [1, 0]], [1, 2]) // => { x: [2, 1], converged: true, ... }
|
|
67
|
+
*/
|
|
68
|
+
export declare function minres(a: LinearOperatorInput, b: number[], opts?: KrylovOptions): KrylovResult;
|
|
69
|
+
/**
|
|
70
|
+
* Restarted GMRES — for general nonsymmetric `A`.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* gmres([[3, 1], [0, 2]], [4, 2]) // => { x: [1, 1], converged: true, ... }
|
|
74
|
+
*/
|
|
75
|
+
export declare function gmres(a: LinearOperatorInput, b: number[], opts?: GmresOptions): KrylovResult;
|
|
76
|
+
/**
|
|
77
|
+
* BiCGSTAB — for general nonsymmetric `A`.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* bicgstab([[3, 1], [0, 2]], [4, 2]) // => { x: [1, 1], converged: true, ... }
|
|
81
|
+
*/
|
|
82
|
+
export declare function bicgstab(a: LinearOperatorInput, b: number[], opts?: KrylovOptions): KrylovResult;
|
|
83
|
+
//# sourceMappingURL=krylov.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"krylov.d.ts","sourceRoot":"","sources":["../../src/numeric/krylov.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,gFAAgF;AAChF,MAAM,MAAM,mBAAmB,GAAG,MAAM,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;AAE3E,2FAA2F;AAC3F,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;AAEpE,8DAA8D;AAC9D,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;IACd,+DAA+D;IAC/D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qEAAqE;IACrE,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,4DAA4D;AAC5D,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,mCAAmC;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,sDAAsD;AACtD,MAAM,WAAW,YAAY;IAC3B,4BAA4B;IAC5B,CAAC,EAAE,MAAM,EAAE,CAAC;IACZ,sCAAsC;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,SAAS,EAAE,OAAO,CAAC;IACnB,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAC;CAClB;AAmGD;;;;;GAKG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,mBAAmB,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,YAAY,CAwC1F;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,mBAAmB,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,YAAY,CAyF9F;AA8CD;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,mBAAmB,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,YAAY,CA2F5F;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,mBAAmB,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,YAAY,CAqEhG"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Complex matrix functions — `funm`/`cosm`/`sinm` for a general real matrix.
|
|
3
|
+
*
|
|
4
|
+
* `funm(A, f)` evaluates a scalar analytic function `f` at a square matrix
|
|
5
|
+
* `A`, returning the complex matrix `f(A)`. Unlike `sqrtm`/`matrixLogm`
|
|
6
|
+
* (which only handle real matrices whose spectrum stays on the principal
|
|
7
|
+
* branch — positive reals for sqrt/log), `funm` accepts any real spectrum
|
|
8
|
+
* (negative, complex-conjugate pairs, …) because the result is allowed to be
|
|
9
|
+
* complex-valued.
|
|
10
|
+
*
|
|
11
|
+
* Algorithm (diagonalizable matrices with distinct eigenvalues):
|
|
12
|
+
* - If `A` is diagonal, `f(A)` is exact and trivial: apply `f` to each
|
|
13
|
+
* diagonal entry (handles repeated eigenvalues fine, since a diagonal
|
|
14
|
+
* matrix is always diagonalizable regardless of eigenvalue multiplicity).
|
|
15
|
+
* - Otherwise, compute `A`'s eigenvalues `λ_1, …, λ_n` (via the shared
|
|
16
|
+
* `@danielsimonjr/mathts-matrix` `eig` — Householder + Francis QR) and,
|
|
17
|
+
* when they are all distinct, apply the Lagrange-Sylvester interpolation
|
|
18
|
+
* formula for a diagonalizable matrix with simple spectrum:
|
|
19
|
+
*
|
|
20
|
+
* f(A) = Σ_i f(λ_i) · L_i(A), L_i(A) = Π_{j≠i} (A − λ_j I) / (λ_i − λ_j)
|
|
21
|
+
*
|
|
22
|
+
* evaluated in complex arithmetic (`A` embedded with zero imaginary
|
|
23
|
+
* part). This needs only eigenvalues, not eigenvectors, and is exact for
|
|
24
|
+
* any polynomial or entire function `f` (cos, sin, sqrt, exp, log, …)
|
|
25
|
+
* whenever the spectrum is simple.
|
|
26
|
+
*
|
|
27
|
+
* Limitation (documented, not yet implemented): matrices with repeated (or
|
|
28
|
+
* numerically indistinguishable) eigenvalues that are NOT diagonal — i.e.
|
|
29
|
+
* genuinely defective/non-diagonalizable matrices, or diagonalizable
|
|
30
|
+
* matrices with a repeated eigenvalue and off-diagonal structure — are not
|
|
31
|
+
* supported; `funm` throws rather than silently return a wrong answer. A
|
|
32
|
+
* full Schur-Parlett block recurrence (Higham 2008 Ch. 9) would lift this
|
|
33
|
+
* restriction; that is future work, not required by the current call sites.
|
|
34
|
+
*
|
|
35
|
+
* @packageDocumentation
|
|
36
|
+
*/
|
|
37
|
+
/** A complex number as a plain `{re, im}` pair. */
|
|
38
|
+
export interface ComplexValue {
|
|
39
|
+
re: number;
|
|
40
|
+
im: number;
|
|
41
|
+
}
|
|
42
|
+
/** A complex-valued dense matrix, stored as parallel real/imaginary 2-D arrays. */
|
|
43
|
+
export interface ComplexMatrix {
|
|
44
|
+
re: number[][];
|
|
45
|
+
im: number[][];
|
|
46
|
+
}
|
|
47
|
+
/** A scalar analytic function to be applied to a matrix's spectrum. */
|
|
48
|
+
export type ScalarComplexFunction = (z: ComplexValue) => ComplexValue;
|
|
49
|
+
/**
|
|
50
|
+
* Evaluate the matrix function `f(A)` for a square real matrix `A`, returning
|
|
51
|
+
* a complex matrix `{re, im}`.
|
|
52
|
+
*
|
|
53
|
+
* Supports diagonal matrices unconditionally (exact, elementwise), and
|
|
54
|
+
* general diagonalizable matrices whose eigenvalues are pairwise distinct
|
|
55
|
+
* (Lagrange-Sylvester interpolation on the spectrum — see module docs).
|
|
56
|
+
* Throws for matrices with repeated or numerically indistinguishable
|
|
57
|
+
* eigenvalues that are not diagonal (defective / non-diagonalizable case;
|
|
58
|
+
* not yet supported — see module docs for the Schur-Parlett follow-up).
|
|
59
|
+
*
|
|
60
|
+
* @param A - Square real matrix, as a plain 2-D array.
|
|
61
|
+
* @param f - Scalar function to apply to each eigenvalue, e.g. `cos`, `sin`,
|
|
62
|
+
* `sqrt`, `exp`, `log`, extended to complex arguments.
|
|
63
|
+
* @returns `{ re, im }` — the (possibly complex) matrix `f(A)`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function funm(A: number[][], f: ScalarComplexFunction): ComplexMatrix;
|
|
66
|
+
/** Complex cosine: `cos(z) = cos(re)cosh(im) - i sin(re)sinh(im)`. */
|
|
67
|
+
export declare function complexCos(z: ComplexValue): ComplexValue;
|
|
68
|
+
/** Complex sine: `sin(z) = sin(re)cosh(im) + i cos(re)sinh(im)`. */
|
|
69
|
+
export declare function complexSin(z: ComplexValue): ComplexValue;
|
|
70
|
+
/** Matrix cosine `cos(A)`, via {@link funm} with {@link complexCos}. */
|
|
71
|
+
export declare function cosm(A: number[][]): ComplexMatrix;
|
|
72
|
+
/** Matrix sine `sin(A)`, via {@link funm} with {@link complexSin}. */
|
|
73
|
+
export declare function sinm(A: number[][]): ComplexMatrix;
|
|
74
|
+
//# sourceMappingURL=matrix-functions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrix-functions.d.ts","sourceRoot":"","sources":["../../src/numeric/matrix-functions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAIH,mDAAmD;AACnD,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,mFAAmF;AACnF,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC;IACf,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC;CAChB;AAED,uEAAuE;AACvE,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,EAAE,YAAY,KAAK,YAAY,CAAC;AAoHtE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,qBAAqB,GAAG,aAAa,CAuD3E;AAED,sEAAsE;AACtE,wBAAgB,UAAU,CAAC,CAAC,EAAE,YAAY,GAAG,YAAY,CAKxD;AAED,oEAAoE;AACpE,wBAAgB,UAAU,CAAC,CAAC,EAAE,YAAY,GAAG,YAAY,CAKxD;AAED,wEAAwE;AACxE,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,aAAa,CAEjD;AAED,sEAAsE;AACtE,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,aAAa,CAEjD"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured and indefinite direct linear solvers.
|
|
3
|
+
*
|
|
4
|
+
* These exploit matrix structure (tridiagonal, banded, Toeplitz, symmetric
|
|
5
|
+
* indefinite) to solve `Ax = b` in less than the O(n^3) a general dense LU
|
|
6
|
+
* (`lusolve`) would cost, or — for `ldl` — to factor matrices `cholesky`
|
|
7
|
+
* cannot handle because they are not positive-definite (e.g. KKT systems):
|
|
8
|
+
*
|
|
9
|
+
* - `thomasSolve` — the Thomas algorithm, O(n) for tridiagonal systems.
|
|
10
|
+
* - `solveBanded` — banded-aware Gaussian elimination (no pivoting; touches
|
|
11
|
+
* only the O(n(l+u)) entries inside the band), for systems with `l` lower
|
|
12
|
+
* and `u` upper nonzero diagonals.
|
|
13
|
+
* - `toeplitzSolve` — the Levinson–Durbin recursion, O(n^2) for a Toeplitz
|
|
14
|
+
* system given only its first row and column.
|
|
15
|
+
* - `ldl` — Bunch–Kaufman-pivoted LDLᵀ factorization of a symmetric
|
|
16
|
+
* (possibly indefinite) matrix, with 1x1/2x2 diagonal blocks.
|
|
17
|
+
*
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Thomas algorithm — O(n) solve of a tridiagonal system `Ax = d`.
|
|
22
|
+
*
|
|
23
|
+
* `A` is the tridiagonal matrix with subdiagonal `sub` (length n−1),
|
|
24
|
+
* diagonal `diag` (length n), and superdiagonal `sup` (length n−1). No
|
|
25
|
+
* pivoting is performed (as with any tridiagonal Thomas solve); the matrix
|
|
26
|
+
* should be diagonally dominant or otherwise stable without it.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* thomasSolve([-1, -1], [2, 2, 2], [-1, -1], [1, 0, 1]) // => [1, 1, 1]
|
|
30
|
+
*/
|
|
31
|
+
export declare function thomasSolve(sub: number[], diag: number[], sup: number[], d: number[]): number[];
|
|
32
|
+
/**
|
|
33
|
+
* Banded-aware Gaussian elimination — solve `Ax = b` for a matrix with `l`
|
|
34
|
+
* nonzero lower diagonals and `u` nonzero upper diagonals (all other entries
|
|
35
|
+
* are assumed zero, though `A` is passed as a full dense matrix). Only the
|
|
36
|
+
* O(n(l+u)) entries inside the band are touched during elimination and
|
|
37
|
+
* back-substitution. No pivoting is performed — as with {@link thomasSolve},
|
|
38
|
+
* the matrix should be diagonally dominant or otherwise stable without it.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* solveBanded(1, 1, [[2, -1, 0], [-1, 2, -1], [0, -1, 2]], [1, 0, 1]) // => [1, 1, 1]
|
|
42
|
+
*/
|
|
43
|
+
export declare function solveBanded(l: number, u: number, A: number[][], b: number[]): number[];
|
|
44
|
+
/**
|
|
45
|
+
* Levinson–Durbin recursion — O(n²) solve of a Toeplitz system `Tx = b`
|
|
46
|
+
* given only the first column `c` and first row `r` (`c[0]` must equal
|
|
47
|
+
* `r[0]`, the shared diagonal value). `T[i][j] = c[i-j]` for `i >= j`, else
|
|
48
|
+
* `r[j-i]`.
|
|
49
|
+
*
|
|
50
|
+
* Order-recursively builds the solution together with two auxiliary
|
|
51
|
+
* "predictor" vectors — one for `T`, one for `Tᵀ` (mutually coupled via the
|
|
52
|
+
* persymmetry `J T J = Tᵀ` that every Toeplitz matrix has, `J` the
|
|
53
|
+
* reversal/exchange matrix) — which is what makes a general (non-symmetric)
|
|
54
|
+
* Toeplitz system solvable in O(n²) rather than O(n³).
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* toeplitzSolve([2, 1], [2, 1], [1, 2]) // => [0, 1]
|
|
58
|
+
*/
|
|
59
|
+
export declare function toeplitzSolve(c: number[], r: number[], b: number[]): number[];
|
|
60
|
+
/** Result of {@link ldl}. */
|
|
61
|
+
export interface LDLResult {
|
|
62
|
+
/** Unit lower-triangular factor. */
|
|
63
|
+
L: number[][];
|
|
64
|
+
/** Block-diagonal factor (1x1 or 2x2 blocks along the diagonal). */
|
|
65
|
+
D: number[][];
|
|
66
|
+
/**
|
|
67
|
+
* Permutation such that `(P A Pᵀ)[i][j] = A[perm[i]][perm[j]]` and
|
|
68
|
+
* `L D Lᵀ = P A Pᵀ`.
|
|
69
|
+
*/
|
|
70
|
+
perm: number[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Bunch–Kaufman-pivoted LDLᵀ factorization of a symmetric (possibly
|
|
74
|
+
* indefinite) matrix `A`, useful for symmetric systems `cholesky` can't
|
|
75
|
+
* handle because they aren't positive-definite (e.g. KKT / saddle-point
|
|
76
|
+
* systems from constrained optimization).
|
|
77
|
+
*
|
|
78
|
+
* Reconstruction identity: `L D Lᵀ = P A Pᵀ`, where `P` is the permutation
|
|
79
|
+
* matrix with `P[i][perm[i]] = 1`, i.e. `(P A Pᵀ)[i][j] = A[perm[i]][perm[j]]`.
|
|
80
|
+
* `L` is unit lower-triangular; `D` is block-diagonal with 1x1 or 2x2 blocks
|
|
81
|
+
* (2x2 blocks appear where a pivot would otherwise be too small relative to
|
|
82
|
+
* the rest of its column, per the standard Bunch–Kaufman pivot selection).
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* const { L, D, perm } = ldl([[1, 2, 3], [2, 1, 4], [3, 4, 1]]);
|
|
86
|
+
* // L D L^T reconstructs A with rows/cols permuted by perm.
|
|
87
|
+
*/
|
|
88
|
+
export declare function ldl(A: number[][]): LDLResult;
|
|
89
|
+
//# sourceMappingURL=structured-solvers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structured-solvers.d.ts","sourceRoot":"","sources":["../../src/numeric/structured-solvers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CA+B/F;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAwCtF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CA8E7E;AAED,6BAA6B;AAC7B,MAAM,WAAW,SAAS;IACxB,oCAAoC;IACpC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;IACd,oEAAoE;IACpE,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;IACd;;;OAGG;IACH,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,SAAS,CAwG5C"}
|
package/dist/typed/algebra.d.ts
CHANGED
|
@@ -191,7 +191,13 @@ export declare function variables(expr: string): string[];
|
|
|
191
191
|
export declare function substitute(expr: string, vars: Record<string, string>): string;
|
|
192
192
|
/**
|
|
193
193
|
* Expand an expression string by distributing multiplication over addition.
|
|
194
|
-
*
|
|
194
|
+
*
|
|
195
|
+
* **Univariate polynomials** (a single variable, integer/no non-integer
|
|
196
|
+
* powers, no function calls) are expanded EXACTLY via `polyFromExpression` +
|
|
197
|
+
* `polyToString`: `expand('(x+1)^3')` → `'1*x^3 + 3*x^2 + 3*x + 1'`.
|
|
198
|
+
*
|
|
199
|
+
* Everything else (multiple variables, non-polynomial pieces) falls back to
|
|
200
|
+
* the original regex-based distributor below.
|
|
195
201
|
*
|
|
196
202
|
* @param expr - Expression string
|
|
197
203
|
* @returns Expanded expression string
|
|
@@ -199,12 +205,22 @@ export declare function substitute(expr: string, vars: Record<string, string>):
|
|
|
199
205
|
* @example
|
|
200
206
|
* ```typescript
|
|
201
207
|
* expand('(a+b)*(c+d)'); // 'a*c + a*d + b*c + b*d'
|
|
208
|
+
* expand('(x+1)^3'); // '1*x^3 + 3*x^2 + 3*x + 1'
|
|
202
209
|
* ```
|
|
203
210
|
*/
|
|
204
211
|
export declare function expand(expr: string): string;
|
|
205
212
|
/**
|
|
206
213
|
* Factor an expression string.
|
|
207
|
-
*
|
|
214
|
+
*
|
|
215
|
+
* **Univariate polynomials** (a single variable, integer coefficients,
|
|
216
|
+
* degree ≥ 2) are factored over ℚ via the rational-root theorem: candidate
|
|
217
|
+
* roots ±(divisors of the constant term)/(divisors of the leading
|
|
218
|
+
* coefficient) are tested, each confirmed root's linear factor is divided
|
|
219
|
+
* out exactly, and any irreducible remainder is left as-is:
|
|
220
|
+
* `factor('x^2-1')` → `'(x - 1)*(x + 1)'`.
|
|
221
|
+
*
|
|
222
|
+
* Everything else (multiple variables, no rational root) falls back to the
|
|
223
|
+
* original common-integer-factor extraction below.
|
|
208
224
|
*
|
|
209
225
|
* @param expr - Expression string
|
|
210
226
|
* @returns Factored expression string
|
|
@@ -235,7 +251,17 @@ export declare function collect(expr: string, variable: string): string;
|
|
|
235
251
|
*/
|
|
236
252
|
export declare function cancel(expr: string): string;
|
|
237
253
|
/**
|
|
238
|
-
* Combine
|
|
254
|
+
* Combine a sum of rational terms into a single fraction over a common
|
|
255
|
+
* (not necessarily lowest) denominator.
|
|
256
|
+
*
|
|
257
|
+
* **Univariate rationals** (a single variable, e.g. `1/x + 1/(x+1)`) are
|
|
258
|
+
* combined EXACTLY: the common denominator is the product of every term's
|
|
259
|
+
* denominator, and the numerator is the exact polynomial sum
|
|
260
|
+
* `Σ numᵢ · Π_{j≠i} denⱼ`, simplified via `polyFromExpression`/`polyToString`:
|
|
261
|
+
* `together('1/x + 1/(x+1)')` → `'(2*x + 1)/((x)*((x+1)))'`.
|
|
262
|
+
*
|
|
263
|
+
* Everything else (no variable, i.e. purely numeric) falls back to the
|
|
264
|
+
* original numeric-fraction addition below.
|
|
239
265
|
*
|
|
240
266
|
* @param expr - Expression string
|
|
241
267
|
* @returns Combined expression
|
|
@@ -244,6 +270,17 @@ export declare function together(expr: string): string;
|
|
|
244
270
|
/**
|
|
245
271
|
* Partial fraction decomposition.
|
|
246
272
|
*
|
|
273
|
+
* **Univariate rationals with a fully-factorable denominator** (distinct
|
|
274
|
+
* rational roots only — repeated roots are out of scope) are decomposed via
|
|
275
|
+
* the cover-up/residue method: `apart('1/(x^2-1)')` →
|
|
276
|
+
* `'1/(2*(x - 1)) - 1/(2*(x + 1))'`. An improper fraction (numerator degree ≥
|
|
277
|
+
* denominator degree) is first split into a polynomial quotient + proper
|
|
278
|
+
* remainder via `polynomialQuotient`/`polynomialRemainder`.
|
|
279
|
+
*
|
|
280
|
+
* Everything else (no variable — i.e. purely numeric — multiple variables,
|
|
281
|
+
* or a denominator that doesn't factor into distinct rational linear
|
|
282
|
+
* factors) falls back to the original numeric-only path below.
|
|
283
|
+
*
|
|
247
284
|
* @param expr - Expression string
|
|
248
285
|
* @returns Decomposed expression
|
|
249
286
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"algebra.d.ts","sourceRoot":"","sources":["../../src/typed/algebra.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"algebra.d.ts","sourceRoot":"","sources":["../../src/typed/algebra.ts"],"names":[],"mappings":"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"}
|