@pawells/math-extended 1.1.1 → 2.0.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.
Files changed (97) hide show
  1. package/build/angles.d.ts +28 -18
  2. package/build/angles.d.ts.map +1 -1
  3. package/build/angles.js +28 -18
  4. package/build/angles.js.map +1 -1
  5. package/build/clamp.d.ts +5 -3
  6. package/build/clamp.d.ts.map +1 -1
  7. package/build/clamp.js +5 -3
  8. package/build/clamp.js.map +1 -1
  9. package/build/interpolation.d.ts +158 -96
  10. package/build/interpolation.d.ts.map +1 -1
  11. package/build/interpolation.js +158 -96
  12. package/build/interpolation.js.map +1 -1
  13. package/build/matrices/_exports.d.ts +13 -0
  14. package/build/matrices/_exports.d.ts.map +1 -0
  15. package/build/matrices/_exports.js +13 -0
  16. package/build/matrices/_exports.js.map +1 -0
  17. package/build/matrices/arithmetic.d.ts +170 -181
  18. package/build/matrices/arithmetic.d.ts.map +1 -1
  19. package/build/matrices/arithmetic.js +192 -202
  20. package/build/matrices/arithmetic.js.map +1 -1
  21. package/build/matrices/asserts.d.ts +240 -109
  22. package/build/matrices/asserts.d.ts.map +1 -1
  23. package/build/matrices/asserts.js +287 -87
  24. package/build/matrices/asserts.js.map +1 -1
  25. package/build/matrices/core.d.ts +29 -29
  26. package/build/matrices/core.js +1 -1
  27. package/build/matrices/decompositions.d.ts +102 -104
  28. package/build/matrices/decompositions.d.ts.map +1 -1
  29. package/build/matrices/decompositions.js +87 -89
  30. package/build/matrices/decompositions.js.map +1 -1
  31. package/build/matrices/index.d.ts +3 -2
  32. package/build/matrices/index.d.ts.map +1 -1
  33. package/build/matrices/index.js +5 -2
  34. package/build/matrices/index.js.map +1 -1
  35. package/build/matrices/linear-algebra.d.ts +12 -12
  36. package/build/matrices/linear-algebra.js +4 -4
  37. package/build/matrices/normalization.d.ts +8 -8
  38. package/build/matrices/transformations.d.ts +184 -165
  39. package/build/matrices/transformations.d.ts.map +1 -1
  40. package/build/matrices/transformations.js +99 -80
  41. package/build/matrices/transformations.js.map +1 -1
  42. package/build/matrices/types.d.ts +12 -12
  43. package/build/matrices/types.d.ts.map +1 -1
  44. package/build/quaternions/_exports.d.ts +11 -0
  45. package/build/quaternions/_exports.d.ts.map +1 -0
  46. package/build/quaternions/_exports.js +11 -0
  47. package/build/quaternions/_exports.js.map +1 -0
  48. package/build/quaternions/asserts.d.ts +115 -7
  49. package/build/quaternions/asserts.d.ts.map +1 -1
  50. package/build/quaternions/asserts.js +162 -8
  51. package/build/quaternions/asserts.js.map +1 -1
  52. package/build/quaternions/conversions.d.ts +31 -21
  53. package/build/quaternions/conversions.d.ts.map +1 -1
  54. package/build/quaternions/conversions.js +28 -18
  55. package/build/quaternions/conversions.js.map +1 -1
  56. package/build/quaternions/core.d.ts +67 -39
  57. package/build/quaternions/core.d.ts.map +1 -1
  58. package/build/quaternions/core.js +67 -39
  59. package/build/quaternions/core.js.map +1 -1
  60. package/build/quaternions/index.d.ts +3 -2
  61. package/build/quaternions/index.d.ts.map +1 -1
  62. package/build/quaternions/index.js +5 -2
  63. package/build/quaternions/index.js.map +1 -1
  64. package/build/quaternions/interpolation.d.ts +15 -9
  65. package/build/quaternions/interpolation.d.ts.map +1 -1
  66. package/build/quaternions/interpolation.js +15 -9
  67. package/build/quaternions/interpolation.js.map +1 -1
  68. package/build/quaternions/predefined.d.ts +9 -3
  69. package/build/quaternions/predefined.d.ts.map +1 -1
  70. package/build/quaternions/predefined.js +9 -3
  71. package/build/quaternions/predefined.js.map +1 -1
  72. package/build/quaternions/types.d.ts +3 -3
  73. package/build/vectors/_exports.d.ts +10 -0
  74. package/build/vectors/_exports.d.ts.map +1 -0
  75. package/build/vectors/_exports.js +10 -0
  76. package/build/vectors/_exports.js.map +1 -0
  77. package/build/vectors/asserts.d.ts +153 -49
  78. package/build/vectors/asserts.d.ts.map +1 -1
  79. package/build/vectors/asserts.js +202 -52
  80. package/build/vectors/asserts.js.map +1 -1
  81. package/build/vectors/core.d.ts +216 -137
  82. package/build/vectors/core.d.ts.map +1 -1
  83. package/build/vectors/core.js +212 -149
  84. package/build/vectors/core.js.map +1 -1
  85. package/build/vectors/index.d.ts +1 -0
  86. package/build/vectors/index.d.ts.map +1 -1
  87. package/build/vectors/index.js +3 -0
  88. package/build/vectors/index.js.map +1 -1
  89. package/build/vectors/interpolation.d.ts +39 -27
  90. package/build/vectors/interpolation.d.ts.map +1 -1
  91. package/build/vectors/interpolation.js +39 -27
  92. package/build/vectors/interpolation.js.map +1 -1
  93. package/build/vectors/predefined.d.ts +48 -24
  94. package/build/vectors/predefined.d.ts.map +1 -1
  95. package/build/vectors/predefined.js +38 -18
  96. package/build/vectors/predefined.js.map +1 -1
  97. package/package.json +3 -3
@@ -4,7 +4,7 @@ import { AssertMatrix, AssertMatrixRow, AssertMatrixValue } from './asserts.js';
4
4
  * Creates a matrix with specified dimensions, initialized with zeros.
5
5
  * @param rows - Number of rows (non-negative integer). If only this parameter is provided, creates a square matrix.
6
6
  * @param cols - Number of columns (non-negative integer). Optional for square matrices.
7
- * @returns {IMatrix | IMatrix1 | IMatrix2 | IMatrix3 | IMatrix4} Zero-filled matrix with specified dimensions
7
+ * @returns {TMatrix | TMatrix1 | TMatrix2 | TMatrix3 | TMatrix4} Zero-filled matrix with specified dimensions
8
8
  * @throws {Error} If rows or cols are negative or not integers
9
9
  * @example MatrixCreate() // [[0]] (1x1 matrix)
10
10
  * @example MatrixCreate(2) // [[0, 0], [0, 0]] (2x2 matrix)
@@ -1,4 +1,4 @@
1
- import { IMatrix } from './types.js';
1
+ import { TMatrix } from './types.js';
2
2
  /**
3
3
  * Result of eigenvalue decomposition containing eigenvalues and their corresponding eigenvectors.
4
4
  *
@@ -10,7 +10,7 @@ type TEigenDecompositionResult = {
10
10
  /** Array of eigenvalues λ in descending order */
11
11
  eigenvalues: number[];
12
12
  /** Matrix where each column is an eigenvector corresponding to the eigenvalue at the same index */
13
- eigenvectors: IMatrix;
13
+ eigenvectors: TMatrix;
14
14
  };
15
15
  /**
16
16
  * Result of LU decomposition with partial pivoting where P × A = L × U.
@@ -22,9 +22,9 @@ type TEigenDecompositionResult = {
22
22
  */
23
23
  type TLUDecompositionResult = {
24
24
  /** Lower triangular matrix with 1's on the diagonal */
25
- readonly L: IMatrix;
25
+ readonly L: TMatrix;
26
26
  /** Upper triangular matrix containing the pivots */
27
- readonly U: IMatrix;
27
+ readonly U: TMatrix;
28
28
  /** Permutation vector: P[i] is the original row index that now occupies row i */
29
29
  readonly P: number[];
30
30
  };
@@ -37,9 +37,9 @@ type TLUDecompositionResult = {
37
37
  */
38
38
  type TQRDecompositionResult = {
39
39
  /** Orthogonal matrix where Q^T × Q = I */
40
- readonly Q: IMatrix;
40
+ readonly Q: TMatrix;
41
41
  /** Upper triangular matrix */
42
- readonly R: IMatrix;
42
+ readonly R: TMatrix;
43
43
  };
44
44
  /**
45
45
  * Result of Singular Value Decomposition (SVD) where A = U × Σ × V^T.
@@ -51,11 +51,11 @@ type TQRDecompositionResult = {
51
51
  */
52
52
  type TSVDDecompositionResult = {
53
53
  /** Matrix of left singular vectors (orthogonal columns) */
54
- readonly U: IMatrix;
54
+ readonly U: TMatrix;
55
55
  /** Array of singular values σ in descending order (diagonal elements of Σ matrix) */
56
56
  readonly S: number[];
57
57
  /** Transpose of the matrix of right singular vectors (V^T where V has orthogonal columns) */
58
- readonly VT: IMatrix;
58
+ readonly VT: TMatrix;
59
59
  };
60
60
  /**
61
61
  * Performs Cholesky decomposition for symmetric positive definite matrices A = L × L^T.
@@ -77,22 +77,22 @@ type TSVDDecompositionResult = {
77
77
  * @throws {Error} If matrix is not square, not symmetric, or not positive definite
78
78
  *
79
79
  * @example
80
- * ```ts
81
- * // Symmetric positive definite matrix
82
- * const A = [[4, 2], [2, 3]];
83
- * const L = MatrixCholesky(A);
84
- * // L = [[2, 0], [1, √2]] ≈ [[2, 0], [1, 1.414]]
85
- *
86
- * // Verify: L × L^T should equal A
87
- * const LT = MatrixTranspose(L);
88
- * const reconstructed = MatrixMultiply(L, LT);
89
- * // reconstructed ≈ [[4, 2], [2, 3]]
90
- * ```
91
- *
92
- * @complexity Time: O(n³/3), Space: O(n²) - About 2x faster than general LU decomposition
93
- * @see {@link MatrixLU} For general square matrices that may not be positive definite
80
+ * ```typescript
81
+ * ```ts
82
+ * // Symmetric positive definite matrix
83
+ * const A = [[4, 2], [2, 3]];
84
+ * const L = MatrixCholesky(A);
85
+ * // L = [[2, 0], [1, √2]] ≈ [[2, 0], [1, 1.414]]
86
+ * // Verify: L × L^T should equal A
87
+ * const LT = MatrixTranspose(L);
88
+ * const reconstructed = MatrixMultiply(L, LT);
89
+ * // reconstructed ≈ [[4, 2], [2, 3]]
90
+ * ```
91
+ * @complexity Time: O(n³/3), Space: O(n²) - About 2x faster than general LU decomposition
92
+ * @see {@link MatrixLU} For general square matrices that may not be positive definite
93
+ * ```
94
94
  */
95
- export declare function MatrixCholesky(matrix: IMatrix): IMatrix;
95
+ export declare function MatrixCholesky(matrix: TMatrix): TMatrix;
96
96
  /**
97
97
  * Performs eigenvalue decomposition for square matrices to find A × v = λ × v.
98
98
  *
@@ -117,24 +117,24 @@ export declare function MatrixCholesky(matrix: IMatrix): IMatrix;
117
117
  * @throws {Error} If matrix is not square, contains invalid values, or has complex eigenvalues
118
118
  *
119
119
  * @example
120
- * ```ts
121
- * // Simple 2x2 matrix
122
- * const A = [[3, 1], [0, 2]];
123
- * const { eigenvalues, eigenvectors } = MatrixEigen(A);
124
- * // eigenvalues: [3, 2]
125
- * // eigenvectors: matrix where each column corresponds to an eigenvalue
126
- *
127
- * // Verify eigenvalue equation: A × v = λ × v
128
- * const v = Matrix_GetColumn(eigenvectors, 0); // First eigenvector
129
- * const Av = MatrixMultiplyVector(A, v);
130
- * const lambdaV = Matrix_ScaleVector(v, eigenvalues[0]);
131
- * // Av should approximately equal lambdaV
132
- * ```
133
- *
134
- * @complexity O(n³) time for an n×n matrix
135
- * @see {@link MatrixEigenQRIteration} For the iterative algorithm used for larger matrices
120
+ * ```typescript
121
+ * ```ts
122
+ * // Simple 2x2 matrix
123
+ * const A = [[3, 1], [0, 2]];
124
+ * const { eigenvalues, eigenvectors } = MatrixEigen(A);
125
+ * // eigenvalues: [3, 2]
126
+ * // eigenvectors: matrix where each column corresponds to an eigenvalue
127
+ * // Verify eigenvalue equation: A × v = λ × v
128
+ * const v = Matrix_GetColumn(eigenvectors, 0); // First eigenvector
129
+ * const Av = MatrixMultiplyVector(A, v);
130
+ * const lambdaV = Matrix_ScaleVector(v, eigenvalues[0]);
131
+ * // Av should approximately equal lambdaV
132
+ * ```
133
+ * @complexity O(n³) time for an n×n matrix
134
+ * @see {@link MatrixEigenQRIteration} For the iterative algorithm used for larger matrices
135
+ * ```
136
136
  */
137
- export declare function MatrixEigen(matrix: IMatrix): TEigenDecompositionResult;
137
+ export declare function MatrixEigen(matrix: TMatrix): TEigenDecompositionResult;
138
138
  /**
139
139
  * Simplified QR iteration algorithm for eigenvalue computation of larger matrices.
140
140
  *
@@ -158,7 +158,7 @@ export declare function MatrixEigen(matrix: IMatrix): TEigenDecompositionResult;
158
158
  * @complexity O(n³) per iteration, typically converges in O(n) iterations
159
159
  * @see {@link MatrixQR} For the QR decomposition used in each iteration
160
160
  */
161
- export declare function MatrixEigenQRIteration(matrix: IMatrix, iterations?: number): TEigenDecompositionResult;
161
+ export declare function MatrixEigenQRIteration(matrix: TMatrix, iterations?: number): TEigenDecompositionResult;
162
162
  /**
163
163
  * Performs LU decomposition of a square matrix with partial pivoting: P × A = L × U.
164
164
  *
@@ -183,21 +183,21 @@ export declare function MatrixEigenQRIteration(matrix: IMatrix, iterations?: num
183
183
  * @throws {MatrixError} If matrix is not square, singular (zero pivot), or contains invalid values
184
184
  *
185
185
  * @example
186
- * ```ts
187
- * const A = [[2, 1], [1, 1]];
188
- * const { L, U, P } = MatrixLU(A);
189
- * // L = [[1, 0], [0.5, 1]], U = [[2, 1], [0, 0.5]], P = [0, 1]
190
- *
191
- * // Verify: L × U should equal P-permuted A
192
- * const product = MatrixMultiply(L, U);
193
- * // product ≈ [[2, 1], [1, 1]]
194
- * ```
195
- *
196
- * @complexity Time: O(n³/3), Space: O()
197
- * @see {@link MatrixCholesky} For symmetric positive definite matrices (more efficient)
198
- * @see {@link MatrixSolve} For solving Ax = b directly
186
+ * ```typescript
187
+ * ```ts
188
+ * const A = [[2, 1], [1, 1]];
189
+ * const { L, U, P } = MatrixLU(A);
190
+ * // L = [[1, 0], [0.5, 1]], U = [[2, 1], [0, 0.5]], P = [0, 1]
191
+ * // Verify: L × U should equal P-permuted A
192
+ * const product = MatrixMultiply(L, U);
193
+ * // product ≈ [[2, 1], [1, 1]]
194
+ * ```
195
+ * @complexity Time: O(n³/3), Space: O(n²)
196
+ * @see {@link MatrixCholesky} For symmetric positive definite matrices (more efficient)
197
+ * @see {@link MatrixSolve} For solving Ax = b directly
198
+ * ```
199
199
  */
200
- export declare function MatrixLU(matrix: IMatrix): TLUDecompositionResult;
200
+ export declare function MatrixLU(matrix: TMatrix): TLUDecompositionResult;
201
201
  /**
202
202
  * Performs QR decomposition A = Q × R using Modified Gram-Schmidt orthogonalization.
203
203
  *
@@ -222,25 +222,24 @@ export declare function MatrixLU(matrix: IMatrix): TLUDecompositionResult;
222
222
  * @throws {Error} If matrix has more columns than rows or columns are linearly dependent
223
223
  *
224
224
  * @example
225
- * ```ts
226
- * const A = [[1, 1], [1, 0], [0, 1]]; // 3×2 matrix
227
- * const { Q, R } = MatrixQR(A);
228
- * // Q: 3×2 orthogonal matrix with Q^T × Q = I₂
229
- * // R: 2×2 upper triangular matrix
230
- *
231
- * // Verify: Q × R should equal A
232
- * const reconstructed = MatrixMultiply(Q, R);
233
- * // reconstructed ≈ A
234
- *
235
- * // Check orthogonality: Q^T × Q should be identity
236
- * const QT = MatrixTranspose(Q);
237
- * const identity = MatrixMultiply(QT, Q);
238
- * ```
239
- *
240
- * @complexity Time: O(mn²), Space: O(mn) where m ≥ n
241
- * @see {@link MatrixGramSchmidt} {@link MatrixLU} {@link MatrixEigenQRIteration}
225
+ * ```typescript
226
+ * ```ts
227
+ * const A = [[1, 1], [1, 0], [0, 1]]; // 3×2 matrix
228
+ * const { Q, R } = MatrixQR(A);
229
+ * // Q: 3×2 orthogonal matrix with Q^T × Q = I₂
230
+ * // R: 2×2 upper triangular matrix
231
+ * // Verify: Q × R should equal A
232
+ * const reconstructed = MatrixMultiply(Q, R);
233
+ * // reconstructed ≈ A
234
+ * // Check orthogonality: Q^T × Q should be identity
235
+ * const QT = MatrixTranspose(Q);
236
+ * const identity = MatrixMultiply(QT, Q);
237
+ * ```
238
+ * @complexity Time: O(mn²), Space: O(mn) where m ≥ n
239
+ * @see {@link MatrixGramSchmidt} {@link MatrixLU} {@link MatrixEigenQRIteration}
240
+ * ```
242
241
  */
243
- export declare function MatrixQR(matrix: IMatrix, allowDependentColumns?: boolean): TQRDecompositionResult;
242
+ export declare function MatrixQR(matrix: TMatrix, allowDependentColumns?: boolean): TQRDecompositionResult;
244
243
  /**
245
244
  * Performs Singular Value Decomposition (SVD) of a matrix A = U × Σ × V^T.
246
245
  *
@@ -274,28 +273,26 @@ export declare function MatrixQR(matrix: IMatrix, allowDependentColumns?: boolea
274
273
  * @throws {Error} If matrix contains invalid values (NaN, Infinity)
275
274
  *
276
275
  * @example
277
- * ```ts
278
- * const A = [[1, 2], [3, 4], [5, 6]]; // 3×2 matrix
279
- * const { U, S, VT } = MatrixSVD(A);
280
- * // U: 3×2 matrix with orthonormal columns
281
- * // S: [σ₁, σ₂] singular values in descending order
282
- * // VT: 2×2 orthogonal matrix (V transposed)
283
- *
284
- * // Verify reconstruction: U × diag(S) × VT ≈ A
285
- * const Sigma = Matrix_Diagonal(S);
286
- * const reconstructed = MatrixMultiply(MatrixMultiply(U, Sigma), VT);
287
- *
288
- * // Matrix rank from singular values (count non-zero values)
289
- * const rank = S.filter(s => s > 1e-10).length;
290
- *
291
- * // Condition number for stability analysis
292
- * const conditionNumber = S[0] / S[S.length - 1];
293
- * ```
294
- *
295
- * @complexity Time: O(min(m²n, mn²)), Space: O(m² + n²)
296
- * @see {@link MatrixQR} {@link MatrixEigenQRIteration} {@link Matrix_PseudoInverse}
276
+ * ```typescript
277
+ * ```ts
278
+ * const A = [[1, 2], [3, 4], [5, 6]]; // 3×2 matrix
279
+ * const { U, S, VT } = MatrixSVD(A);
280
+ * // U: 3×2 matrix with orthonormal columns
281
+ * // S: [σ₁, σ₂] singular values in descending order
282
+ * // VT: 2×2 orthogonal matrix (V transposed)
283
+ * // Verify reconstruction: U × diag(S) × VT ≈ A
284
+ * const Sigma = Matrix_Diagonal(S);
285
+ * const reconstructed = MatrixMultiply(MatrixMultiply(U, Sigma), VT);
286
+ * // Matrix rank from singular values (count non-zero values)
287
+ * const rank = S.filter(s => s > 1e-10).length;
288
+ * // Condition number for stability analysis
289
+ * const conditionNumber = S[0] / S[S.length - 1];
290
+ * ```
291
+ * @complexity Time: O(min(m²n, mn²)), Space: O(m² + n²)
292
+ * @see {@link MatrixQR} {@link MatrixEigenQRIteration} {@link Matrix_PseudoInverse}
293
+ * ```
297
294
  */
298
- export declare function MatrixSVD(matrix: IMatrix): TSVDDecompositionResult;
295
+ export declare function MatrixSVD(matrix: TMatrix): TSVDDecompositionResult;
299
296
  /**
300
297
  * Solves the linear system Ax = b for the unknown vector x.
301
298
  * Uses LU decomposition with partial pivoting internally: decomposes A into P, L, U,
@@ -310,16 +307,17 @@ export declare function MatrixSVD(matrix: IMatrix): TSVDDecompositionResult;
310
307
  * @throws {MatrixError} If A is not square, singular, or b has the wrong length
311
308
  *
312
309
  * @example
313
- * // 2x + y = 8
314
- * // 5x + 3y = 20
315
- * MatrixSolve([[2, 1], [5, 3]], [8, 20]); // [4, 0]
316
- *
317
- * @example
318
- * // Solve a 3×3 system
319
- * const A = [[1, 2, -1], [2, 1, 1], [3, -1, 2]];
320
- * const b = [4, 7, 2];
321
- * MatrixSolve(A, b); // solution vector x
310
+ * ```typescript
311
+ * // 2x + y = 8
312
+ * // 5x + 3y = 20
313
+ * MatrixSolve([[2, 1], [5, 3]], [8, 20]); // [4, 0]
314
+ * @example
315
+ * // Solve a 3×3 system
316
+ * const A = [[1, 2, -1], [2, 1, 1], [3, -1, 2]];
317
+ * const b = [4, 7, 2];
318
+ * MatrixSolve(A, b); // solution vector x
319
+ * ```
322
320
  */
323
- export declare function MatrixSolve(a: IMatrix, b: number[]): number[];
321
+ export declare function MatrixSolve(a: TMatrix, b: number[]): number[];
324
322
  export {};
325
323
  //# sourceMappingURL=decompositions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"decompositions.d.ts","sourceRoot":"","sources":["../../src/matrices/decompositions.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAKrC;;;;;;GAMG;AACH,KAAK,yBAAyB,GAAG;IAChC,iDAAiD;IACjD,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,mGAAmG;IACnG,YAAY,EAAE,OAAO,CAAC;CACtB,CAAC;AACF;;;;;;;GAOG;AACH,KAAK,sBAAsB,GAAG;IAC7B,uDAAuD;IAEvD,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC;IACpB,oDAAoD;IAEpD,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC;IACpB,iFAAiF;IAEjF,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AACF;;;;;;GAMG;AACH,KAAK,sBAAsB,GAAG;IAC7B,0CAA0C;IAE1C,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC;IACpB,8BAA8B;IAE9B,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AACF;;;;;;;GAOG;AACH,KAAK,uBAAuB,GAAG;IAC9B,2DAA2D;IAE3D,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC;IACpB,qFAAqF;IAErF,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,6FAA6F;IAE7F,QAAQ,CAAC,EAA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C,MAAM,EAAE,OAAO,EAAE,qBAAqB,UAAQ,GAAG,sBAAsB,CAiI/F;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,uBAAuB,CA2FlE;AACD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CA2D7D"}
@@ -25,20 +25,20 @@ const EIGEN_CONVERGENCE_TOLERANCE = 1e-10;
25
25
  * @throws {Error} If matrix is not square, not symmetric, or not positive definite
26
26
  *
27
27
  * @example
28
- * ```ts
29
- * // Symmetric positive definite matrix
30
- * const A = [[4, 2], [2, 3]];
31
- * const L = MatrixCholesky(A);
32
- * // L = [[2, 0], [1, √2]] ≈ [[2, 0], [1, 1.414]]
33
- *
34
- * // Verify: L × L^T should equal A
35
- * const LT = MatrixTranspose(L);
36
- * const reconstructed = MatrixMultiply(L, LT);
37
- * // reconstructed ≈ [[4, 2], [2, 3]]
38
- * ```
39
- *
40
- * @complexity Time: O(n³/3), Space: O(n²) - About 2x faster than general LU decomposition
41
- * @see {@link MatrixLU} For general square matrices that may not be positive definite
28
+ * ```typescript
29
+ * ```ts
30
+ * // Symmetric positive definite matrix
31
+ * const A = [[4, 2], [2, 3]];
32
+ * const L = MatrixCholesky(A);
33
+ * // L = [[2, 0], [1, √2]] ≈ [[2, 0], [1, 1.414]]
34
+ * // Verify: L × L^T should equal A
35
+ * const LT = MatrixTranspose(L);
36
+ * const reconstructed = MatrixMultiply(L, LT);
37
+ * // reconstructed ≈ [[4, 2], [2, 3]]
38
+ * ```
39
+ * @complexity Time: O(n³/3), Space: O(n²) - About 2x faster than general LU decomposition
40
+ * @see {@link MatrixLU} For general square matrices that may not be positive definite
41
+ * ```
42
42
  */
43
43
  export function MatrixCholesky(matrix) {
44
44
  AssertMatrix(matrix, { square: true });
@@ -120,22 +120,22 @@ export function MatrixCholesky(matrix) {
120
120
  * @throws {Error} If matrix is not square, contains invalid values, or has complex eigenvalues
121
121
  *
122
122
  * @example
123
- * ```ts
124
- * // Simple 2x2 matrix
125
- * const A = [[3, 1], [0, 2]];
126
- * const { eigenvalues, eigenvectors } = MatrixEigen(A);
127
- * // eigenvalues: [3, 2]
128
- * // eigenvectors: matrix where each column corresponds to an eigenvalue
129
- *
130
- * // Verify eigenvalue equation: A × v = λ × v
131
- * const v = Matrix_GetColumn(eigenvectors, 0); // First eigenvector
132
- * const Av = MatrixMultiplyVector(A, v);
133
- * const lambdaV = Matrix_ScaleVector(v, eigenvalues[0]);
134
- * // Av should approximately equal lambdaV
135
- * ```
136
- *
137
- * @complexity O(n³) time for an n×n matrix
138
- * @see {@link MatrixEigenQRIteration} For the iterative algorithm used for larger matrices
123
+ * ```typescript
124
+ * ```ts
125
+ * // Simple 2x2 matrix
126
+ * const A = [[3, 1], [0, 2]];
127
+ * const { eigenvalues, eigenvectors } = MatrixEigen(A);
128
+ * // eigenvalues: [3, 2]
129
+ * // eigenvectors: matrix where each column corresponds to an eigenvalue
130
+ * // Verify eigenvalue equation: A × v = λ × v
131
+ * const v = Matrix_GetColumn(eigenvectors, 0); // First eigenvector
132
+ * const Av = MatrixMultiplyVector(A, v);
133
+ * const lambdaV = Matrix_ScaleVector(v, eigenvalues[0]);
134
+ * // Av should approximately equal lambdaV
135
+ * ```
136
+ * @complexity O(n³) time for an n×n matrix
137
+ * @see {@link MatrixEigenQRIteration} For the iterative algorithm used for larger matrices
138
+ * ```
139
139
  */
140
140
  export function MatrixEigen(matrix) {
141
141
  AssertMatrix(matrix, { square: true });
@@ -338,19 +338,19 @@ export function MatrixEigenQRIteration(matrix, iterations = 50) {
338
338
  * @throws {MatrixError} If matrix is not square, singular (zero pivot), or contains invalid values
339
339
  *
340
340
  * @example
341
- * ```ts
342
- * const A = [[2, 1], [1, 1]];
343
- * const { L, U, P } = MatrixLU(A);
344
- * // L = [[1, 0], [0.5, 1]], U = [[2, 1], [0, 0.5]], P = [0, 1]
345
- *
346
- * // Verify: L × U should equal P-permuted A
347
- * const product = MatrixMultiply(L, U);
348
- * // product ≈ [[2, 1], [1, 1]]
349
- * ```
350
- *
351
- * @complexity Time: O(n³/3), Space: O()
352
- * @see {@link MatrixCholesky} For symmetric positive definite matrices (more efficient)
353
- * @see {@link MatrixSolve} For solving Ax = b directly
341
+ * ```typescript
342
+ * ```ts
343
+ * const A = [[2, 1], [1, 1]];
344
+ * const { L, U, P } = MatrixLU(A);
345
+ * // L = [[1, 0], [0.5, 1]], U = [[2, 1], [0, 0.5]], P = [0, 1]
346
+ * // Verify: L × U should equal P-permuted A
347
+ * const product = MatrixMultiply(L, U);
348
+ * // product ≈ [[2, 1], [1, 1]]
349
+ * ```
350
+ * @complexity Time: O(n³/3), Space: O(n²)
351
+ * @see {@link MatrixCholesky} For symmetric positive definite matrices (more efficient)
352
+ * @see {@link MatrixSolve} For solving Ax = b directly
353
+ * ```
354
354
  */
355
355
  export function MatrixLU(matrix) {
356
356
  AssertMatrix(matrix, { square: true });
@@ -438,23 +438,22 @@ export function MatrixLU(matrix) {
438
438
  * @throws {Error} If matrix has more columns than rows or columns are linearly dependent
439
439
  *
440
440
  * @example
441
- * ```ts
442
- * const A = [[1, 1], [1, 0], [0, 1]]; // 3×2 matrix
443
- * const { Q, R } = MatrixQR(A);
444
- * // Q: 3×2 orthogonal matrix with Q^T × Q = I₂
445
- * // R: 2×2 upper triangular matrix
446
- *
447
- * // Verify: Q × R should equal A
448
- * const reconstructed = MatrixMultiply(Q, R);
449
- * // reconstructed ≈ A
450
- *
451
- * // Check orthogonality: Q^T × Q should be identity
452
- * const QT = MatrixTranspose(Q);
453
- * const identity = MatrixMultiply(QT, Q);
454
- * ```
455
- *
456
- * @complexity Time: O(mn²), Space: O(mn) where m ≥ n
457
- * @see {@link MatrixGramSchmidt} {@link MatrixLU} {@link MatrixEigenQRIteration}
441
+ * ```typescript
442
+ * ```ts
443
+ * const A = [[1, 1], [1, 0], [0, 1]]; // 3×2 matrix
444
+ * const { Q, R } = MatrixQR(A);
445
+ * // Q: 3×2 orthogonal matrix with Q^T × Q = I₂
446
+ * // R: 2×2 upper triangular matrix
447
+ * // Verify: Q × R should equal A
448
+ * const reconstructed = MatrixMultiply(Q, R);
449
+ * // reconstructed ≈ A
450
+ * // Check orthogonality: Q^T × Q should be identity
451
+ * const QT = MatrixTranspose(Q);
452
+ * const identity = MatrixMultiply(QT, Q);
453
+ * ```
454
+ * @complexity Time: O(mn²), Space: O(mn) where m ≥ n
455
+ * @see {@link MatrixGramSchmidt} {@link MatrixLU} {@link MatrixEigenQRIteration}
456
+ * ```
458
457
  */
459
458
  export function MatrixQR(matrix, allowDependentColumns = false) {
460
459
  AssertMatrix(matrix);
@@ -602,26 +601,24 @@ export function MatrixQR(matrix, allowDependentColumns = false) {
602
601
  * @throws {Error} If matrix contains invalid values (NaN, Infinity)
603
602
  *
604
603
  * @example
605
- * ```ts
606
- * const A = [[1, 2], [3, 4], [5, 6]]; // 3×2 matrix
607
- * const { U, S, VT } = MatrixSVD(A);
608
- * // U: 3×2 matrix with orthonormal columns
609
- * // S: [σ₁, σ₂] singular values in descending order
610
- * // VT: 2×2 orthogonal matrix (V transposed)
611
- *
612
- * // Verify reconstruction: U × diag(S) × VT ≈ A
613
- * const Sigma = Matrix_Diagonal(S);
614
- * const reconstructed = MatrixMultiply(MatrixMultiply(U, Sigma), VT);
615
- *
616
- * // Matrix rank from singular values (count non-zero values)
617
- * const rank = S.filter(s => s > 1e-10).length;
618
- *
619
- * // Condition number for stability analysis
620
- * const conditionNumber = S[0] / S[S.length - 1];
621
- * ```
622
- *
623
- * @complexity Time: O(min(m²n, mn²)), Space: O(m² + n²)
624
- * @see {@link MatrixQR} {@link MatrixEigenQRIteration} {@link Matrix_PseudoInverse}
604
+ * ```typescript
605
+ * ```ts
606
+ * const A = [[1, 2], [3, 4], [5, 6]]; // 3×2 matrix
607
+ * const { U, S, VT } = MatrixSVD(A);
608
+ * // U: 3×2 matrix with orthonormal columns
609
+ * // S: [σ₁, σ₂] singular values in descending order
610
+ * // VT: 2×2 orthogonal matrix (V transposed)
611
+ * // Verify reconstruction: U × diag(S) × VT ≈ A
612
+ * const Sigma = Matrix_Diagonal(S);
613
+ * const reconstructed = MatrixMultiply(MatrixMultiply(U, Sigma), VT);
614
+ * // Matrix rank from singular values (count non-zero values)
615
+ * const rank = S.filter(s => s > 1e-10).length;
616
+ * // Condition number for stability analysis
617
+ * const conditionNumber = S[0] / S[S.length - 1];
618
+ * ```
619
+ * @complexity Time: O(min(m²n, mn²)), Space: O(m² + n²)
620
+ * @see {@link MatrixQR} {@link MatrixEigenQRIteration} {@link Matrix_PseudoInverse}
621
+ * ```
625
622
  */
626
623
  export function MatrixSVD(matrix) {
627
624
  AssertMatrix(matrix);
@@ -701,15 +698,16 @@ export function MatrixSVD(matrix) {
701
698
  * @throws {MatrixError} If A is not square, singular, or b has the wrong length
702
699
  *
703
700
  * @example
704
- * // 2x + y = 8
705
- * // 5x + 3y = 20
706
- * MatrixSolve([[2, 1], [5, 3]], [8, 20]); // [4, 0]
707
- *
708
- * @example
709
- * // Solve a 3×3 system
710
- * const A = [[1, 2, -1], [2, 1, 1], [3, -1, 2]];
711
- * const b = [4, 7, 2];
712
- * MatrixSolve(A, b); // solution vector x
701
+ * ```typescript
702
+ * // 2x + y = 8
703
+ * // 5x + 3y = 20
704
+ * MatrixSolve([[2, 1], [5, 3]], [8, 20]); // [4, 0]
705
+ * @example
706
+ * // Solve a 3×3 system
707
+ * const A = [[1, 2, -1], [2, 1, 1], [3, -1, 2]];
708
+ * const b = [4, 7, 2];
709
+ * MatrixSolve(A, b); // solution vector x
710
+ * ```
713
711
  */
714
712
  export function MatrixSolve(a, b) {
715
713
  AssertMatrix(a, { square: true });