@danielsimonjr/mathts-functions 0.70.1 → 0.72.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 (115) hide show
  1. package/README.md +26 -1
  2. package/dist/algebra/decomposition/qr.d.ts.map +1 -1
  3. package/dist/cas/real-roots.d.ts +30 -0
  4. package/dist/cas/real-roots.d.ts.map +1 -0
  5. package/dist/descriptive-stats.d.ts +1 -1
  6. package/dist/descriptive-stats.d.ts.map +1 -1
  7. package/dist/factories/evaluate.d.ts.map +1 -1
  8. package/dist/factories/index.d.ts +3 -3
  9. package/dist/factories/index.d.ts.map +1 -1
  10. package/dist/fit-scalar.d.ts +28 -0
  11. package/dist/fit-scalar.d.ts.map +1 -1
  12. package/dist/geometry/curves.d.ts +48 -0
  13. package/dist/geometry/curves.d.ts.map +1 -0
  14. package/dist/geometry/polygon-ops.d.ts +19 -0
  15. package/dist/geometry/polygon-ops.d.ts.map +1 -0
  16. package/dist/geometry/predicates.d.ts +38 -0
  17. package/dist/geometry/predicates.d.ts.map +1 -0
  18. package/dist/index.d.ts +53 -3
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +5495 -892
  21. package/dist/linalg-extra2.d.ts +36 -0
  22. package/dist/linalg-extra2.d.ts.map +1 -0
  23. package/dist/linalg-special-matrices.d.ts +62 -0
  24. package/dist/linalg-special-matrices.d.ts.map +1 -0
  25. package/dist/numbertheory/arithmetic-functions.d.ts +50 -0
  26. package/dist/numbertheory/arithmetic-functions.d.ts.map +1 -0
  27. package/dist/numbertheory/diophantine.d.ts +43 -0
  28. package/dist/numbertheory/diophantine.d.ts.map +1 -0
  29. package/dist/numbertheory/extra.d.ts +12 -6
  30. package/dist/numbertheory/extra.d.ts.map +1 -1
  31. package/dist/numbertheory/integer-matrices.d.ts +26 -0
  32. package/dist/numbertheory/integer-matrices.d.ts.map +1 -0
  33. package/dist/numbertheory/modular.d.ts +27 -0
  34. package/dist/numbertheory/modular.d.ts.map +1 -0
  35. package/dist/numbertheory/sequences.d.ts +36 -0
  36. package/dist/numbertheory/sequences.d.ts.map +1 -0
  37. package/dist/numeric/constrained.d.ts +42 -0
  38. package/dist/numeric/constrained.d.ts.map +1 -0
  39. package/dist/numeric/finite-differences.d.ts +54 -0
  40. package/dist/numeric/finite-differences.d.ts.map +1 -0
  41. package/dist/numeric/gauss-nodes-extra.d.ts +73 -0
  42. package/dist/numeric/gauss-nodes-extra.d.ts.map +1 -0
  43. package/dist/numeric/global-optimizers.d.ts +64 -0
  44. package/dist/numeric/global-optimizers.d.ts.map +1 -0
  45. package/dist/numeric/quadrature-extra.d.ts +64 -0
  46. package/dist/numeric/quadrature-extra.d.ts.map +1 -0
  47. package/dist/numeric/solveODE.d.ts +29 -4
  48. package/dist/numeric/solveODE.d.ts.map +1 -1
  49. package/dist/probability/combinations.d.ts.map +1 -1
  50. package/dist/regression-extra.d.ts +6 -0
  51. package/dist/regression-extra.d.ts.map +1 -1
  52. package/dist/scalar-batch-parallel.d.ts +15 -9
  53. package/dist/scalar-batch-parallel.d.ts.map +1 -1
  54. package/dist/scalar-batch-parallel.js +108 -0
  55. package/dist/{scalar-batch-task-CZd6LPg9.js → scalar-batch-task-DApUqK6j.js} +21 -15
  56. package/dist/scalar-batch.worker.js +1 -1
  57. package/dist/scalar-compile.d.ts +4 -4
  58. package/dist/scalar-compile.d.ts.map +1 -1
  59. package/dist/scalar-dimension.d.ts +25 -0
  60. package/dist/scalar-dimension.d.ts.map +1 -1
  61. package/dist/scalar-eval.d.ts +4 -2
  62. package/dist/scalar-eval.d.ts.map +1 -1
  63. package/dist/scalar-node-bridge.d.ts.map +1 -1
  64. package/dist/scalar-search.d.ts +323 -14
  65. package/dist/scalar-search.d.ts.map +1 -1
  66. package/dist/signal/dtw.d.ts +32 -0
  67. package/dist/signal/dtw.d.ts.map +1 -0
  68. package/dist/signal/freqz.d.ts +17 -2
  69. package/dist/signal/freqz.d.ts.map +1 -1
  70. package/dist/signal/lomb-scargle.d.ts +25 -0
  71. package/dist/signal/lomb-scargle.d.ts.map +1 -0
  72. package/dist/signal/system-response.d.ts +82 -0
  73. package/dist/signal/system-response.d.ts.map +1 -0
  74. package/dist/signal/waveforms.d.ts +52 -0
  75. package/dist/signal/waveforms.d.ts.map +1 -0
  76. package/dist/signal/windows-extra.d.ts +52 -0
  77. package/dist/signal/windows-extra.d.ts.map +1 -0
  78. package/dist/signal/zpk2tf.d.ts +22 -2
  79. package/dist/signal/zpk2tf.d.ts.map +1 -1
  80. package/dist/special/angular-momentum.d.ts +38 -0
  81. package/dist/special/angular-momentum.d.ts.map +1 -0
  82. package/dist/special/erf-extra.d.ts +47 -0
  83. package/dist/special/erf-extra.d.ts.map +1 -0
  84. package/dist/special/exp-integrals.d.ts +38 -0
  85. package/dist/special/exp-integrals.d.ts.map +1 -0
  86. package/dist/special/spherical-bessel.d.ts +28 -0
  87. package/dist/special/spherical-bessel.d.ts.map +1 -0
  88. package/dist/special/zeta-extra.d.ts +36 -0
  89. package/dist/special/zeta-extra.d.ts.map +1 -0
  90. package/dist/stats/distances.d.ts +28 -0
  91. package/dist/stats/distances.d.ts.map +1 -0
  92. package/dist/stats/distributions-extra.d.ts +36 -0
  93. package/dist/stats/distributions-extra.d.ts.map +1 -0
  94. package/dist/stats/effect-sizes.d.ts +21 -0
  95. package/dist/stats/effect-sizes.d.ts.map +1 -0
  96. package/dist/stats/nonparametric-extra.d.ts +52 -0
  97. package/dist/stats/nonparametric-extra.d.ts.map +1 -0
  98. package/dist/stats/robust-stats.d.ts +38 -0
  99. package/dist/stats/robust-stats.d.ts.map +1 -0
  100. package/dist/stats/weighted-stats.d.ts +27 -0
  101. package/dist/stats/weighted-stats.d.ts.map +1 -0
  102. package/dist/typed/algebra.d.ts +7 -3
  103. package/dist/typed/algebra.d.ts.map +1 -1
  104. package/dist/typed/cas.d.ts +2 -0
  105. package/dist/typed/cas.d.ts.map +1 -1
  106. package/dist/typed/hypothesis.d.ts.map +1 -1
  107. package/dist/typed/probability.d.ts.map +1 -1
  108. package/dist/typed/signal.d.ts.map +1 -1
  109. package/dist/typed/special.d.ts.map +1 -1
  110. package/dist/typed/statistics.d.ts.map +1 -1
  111. package/dist/wasm/sort/wasm-bridge.d.ts +3 -13
  112. package/dist/wasm/sort/wasm-bridge.d.ts.map +1 -1
  113. package/dist/wasm/special/scalars.d.ts +27 -0
  114. package/dist/wasm/special/scalars.d.ts.map +1 -1
  115. package/package.json +8 -8
@@ -0,0 +1,36 @@
1
+ type Vec = readonly number[] | Float64Array;
2
+ /**
3
+ * Principal angles between the column spaces of A and B, in radians, sorted in
4
+ * descending order (largest angle first, as documented for scipy.linalg.subspace_angles).
5
+ * Each space is orthonormalised by modified Gram-Schmidt. As scipy does, angles whose
6
+ * sine squared is below 1/2 are taken from the singular values of the residual
7
+ * Qb - Qa Qaᵀ Qb (arcsin), the rest from those of Qaᵀ Qb (arccos), so small angles
8
+ * keep full relative accuracy.
9
+ */
10
+ export declare function subspaceAngles(A: number[][], B: number[][]): number[];
11
+ /**
12
+ * Matrix sign function sign(A) by the determinant-scaled Newton iteration
13
+ * X <- (mu X + (mu X)^-1) / 2 with mu = |det X|^(-1/n). Returns the n x n sign matrix.
14
+ */
15
+ export declare function signm(A: number[][], opts?: {
16
+ tol?: number;
17
+ maxIter?: number;
18
+ }): number[][];
19
+ /**
20
+ * Fractional matrix power A^t = expm(t * logm(A)) for a matrix with a principal
21
+ * logarithm. Integer t is computed exactly by repeated multiplication.
22
+ */
23
+ export declare function fractionalMatrixPower(A: number[][], t: number): number[][];
24
+ /**
25
+ * Cholesky factor of L Lᵀ + x xᵀ, given the lower-triangular factor L.
26
+ * Standard rank-1 update (Golub & Van Loan, Alg. 6.5.4).
27
+ */
28
+ export declare function choleskyUpdate(L: number[][], x: Vec): number[][];
29
+ /**
30
+ * Cholesky factor of L Lᵀ - x xᵀ, given the lower-triangular factor L.
31
+ *
32
+ * @throws RangeError if the downdated matrix is not positive definite
33
+ */
34
+ export declare function choleskyDowndate(L: number[][], x: Vec): number[][];
35
+ export {};
36
+ //# sourceMappingURL=linalg-extra2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linalg-extra2.d.ts","sourceRoot":"","sources":["../src/linalg-extra2.ts"],"names":[],"mappings":"AAMA,KAAK,GAAG,GAAG,SAAS,MAAM,EAAE,GAAG,YAAY,CAAC;AAsC5C;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,CAgCrE;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,MAAM,EAAE,EAAE,CAqB9F;AAuBD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CAI1E;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,EAAE,CAehE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,EAAE,CAmBlE"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Special matrix constructors (Gap-analysis 2026-11-04 Batch E7).
3
+ *
4
+ * Pure index/closed-form constructions: Hilbert and its exact integer inverse,
5
+ * Hadamard (Sylvester), Pascal, DFT, Hankel, block-diagonal, Khatri-Rao,
6
+ * Fiedler, Leslie and Helmert matrices.
7
+ */
8
+ import { Complex } from '@danielsimonjr/mathts-core';
9
+ type Vec = readonly number[] | Float64Array;
10
+ /** Hilbert matrix H_ij = 1 / (i + j + 1) (0-based). */
11
+ export declare function hilbertMatrix(n: number): number[][];
12
+ /**
13
+ * Exact inverse of the n x n Hilbert matrix, from the closed-form integer formula
14
+ * (1-based indices): (-1)^(i+j) (i+j-1) C(n+i-1, n-j) C(n+j-1, n-i) C(i+j-2, i-1)^2.
15
+ */
16
+ export declare function invHilbertMatrix(n: number): number[][];
17
+ /**
18
+ * Hadamard matrix of order n by the Sylvester construction. n must be a power of 2.
19
+ *
20
+ * @throws RangeError if n is not a positive power of 2
21
+ */
22
+ export declare function hadamardMatrix(n: number): number[][];
23
+ /**
24
+ * Pascal matrix. 'symmetric' P_ij = C(i+j, i); 'lower' L_ij = C(i, j); 'upper' is its transpose.
25
+ */
26
+ export declare function pascalMatrix(n: number, kind?: 'symmetric' | 'lower' | 'upper'): number[][];
27
+ /**
28
+ * Discrete Fourier transform matrix F_jk = exp(-2*pi*i*j*k/n) times a normalization:
29
+ * 'none' = 1, 'sqrtn' = 1/sqrt(n), 'n' = 1/n.
30
+ */
31
+ export declare function dftMatrix(n: number, opts?: {
32
+ scale?: 'none' | 'sqrtn' | 'n';
33
+ }): Complex[][];
34
+ /**
35
+ * Hankel matrix with first column c and (optionally) last row r. r[0] is ignored
36
+ * (the corner is c[last]); the default r is all zeros.
37
+ */
38
+ export declare function hankelMatrix(c: Vec, r?: Vec): number[][];
39
+ /** Block-diagonal matrix from a list of (possibly rectangular) blocks. */
40
+ export declare function blockDiag(...blocks: ReadonlyArray<ReadonlyArray<readonly number[]>>): number[][];
41
+ /**
42
+ * Khatri-Rao (column-wise Kronecker) product of A (p x k) and B (q x k):
43
+ * a (p*q x k) matrix whose row i*q + j is A[i] elementwise-times B[j].
44
+ *
45
+ * @throws RangeError if the column counts differ
46
+ */
47
+ export declare function khatriRao(A: number[][], B: number[][]): number[][];
48
+ /** Fiedler matrix F_ij = |a_i - a_j|. */
49
+ export declare function fiedlerMatrix(a: Vec): number[][];
50
+ /**
51
+ * Leslie matrix: first row = fecundities f, subdiagonal = survival rates s.
52
+ *
53
+ * @throws RangeError unless s.length === f.length - 1
54
+ */
55
+ export declare function leslieMatrix(f: Vec, s: Vec): number[][];
56
+ /**
57
+ * Helmert matrix. Returns the (n-1) x n orthonormal contrast rows, or the full
58
+ * n x n orthogonal matrix when `full` is true (first row 1/sqrt(n)).
59
+ */
60
+ export declare function helmertMatrix(n: number, full?: boolean): number[][];
61
+ export {};
62
+ //# sourceMappingURL=linalg-special-matrices.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linalg-special-matrices.d.ts","sourceRoot":"","sources":["../src/linalg-special-matrices.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,KAAK,GAAG,GAAG,SAAS,MAAM,EAAE,GAAG,YAAY,CAAC;AAa5C,uDAAuD;AACvD,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CAEnD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CAUtD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CAmBpD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,CAAC,EAAE,MAAM,EACT,IAAI,GAAE,WAAW,GAAG,OAAO,GAAG,OAAqB,GAClD,MAAM,EAAE,EAAE,CAQZ;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,GAAG,CAAA;CAAO,GAAG,OAAO,EAAE,EAAE,CAS/F;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,EAAE,CAWxD;AAED,0EAA0E;AAC1E,wBAAgB,SAAS,CAAC,GAAG,MAAM,EAAE,aAAa,CAAC,aAAa,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC,GAAG,MAAM,EAAE,EAAE,CAchG;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAYlE;AAED,yCAAyC;AACzC,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,EAAE,CAGhD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,EAAE,CAWvD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,UAAQ,GAAG,MAAM,EAAE,EAAE,CAWjE"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Arithmetic functions and integer power / root helpers: squarefree tests,
3
+ * radical, Omega counts, Liouville, von Mangoldt, Mertens, perfect and
4
+ * prime-power tests, exact integer roots, digit sums, Collatz and primorial.
5
+ */
6
+ /** True when n is a positive integer with no square factor greater than 1. */
7
+ export declare function isSquarefree(n: number): boolean;
8
+ /** Product of the distinct prime factors of n (rad(n)). */
9
+ export declare function radical(n: number): number;
10
+ /** Number of prime factors counted with multiplicity (Omega). */
11
+ export declare function bigOmega(n: number): number;
12
+ /** Number of distinct prime factors (omega). */
13
+ export declare function smallOmega(n: number): number;
14
+ /** Liouville function lambda(n) = (-1)^Omega(n). */
15
+ export declare function liouvilleLambda(n: number): -1 | 1;
16
+ /** von Mangoldt function: ln p when n = p^k (k >= 1), otherwise 0. */
17
+ export declare function vonMangoldt(n: number): number;
18
+ /** Mertens function M(n) = sum of mu(k) for k = 1..n. */
19
+ export declare function mertens(n: number): number;
20
+ /** True when n equals the sum of its proper divisors (n >= 2). */
21
+ export declare function isPerfect(n: number): boolean;
22
+ /** Floor of the square root of a non-negative bigint (Newton iteration). */
23
+ export declare function integerSqrt(n: bigint): bigint;
24
+ /** Floor of the k-th root of a non-negative bigint (binary search). */
25
+ export declare function integerNthRoot(n: bigint, k: number): bigint;
26
+ /**
27
+ * Perfect-power test. Returns `{ base, exp }` with `n = base^exp`, `base > 1`,
28
+ * and `exp` as large as possible; `null` if n is not a perfect power (or n < 2).
29
+ */
30
+ export declare function isPerfectPower(n: number): {
31
+ base: number;
32
+ exp: number;
33
+ } | null;
34
+ /**
35
+ * Prime-power test: `{ p, k }` with `n = p^k`, `k >= 1`; `null` if n is not a
36
+ * prime power (or n < 2).
37
+ */
38
+ export declare function isPrimePower(n: number): {
39
+ p: number;
40
+ k: number;
41
+ } | null;
42
+ /** Sum of the digits of n in the given base (default 10). */
43
+ export declare function digitSum(n: number | bigint, base?: number): number;
44
+ /** Digital root (repeated digit sum until a single digit), base 10. */
45
+ export declare function digitalRoot(n: number): number;
46
+ /** Number of steps for the Collatz (3n+1) sequence to reach 1. */
47
+ export declare function collatzSteps(n: number): number;
48
+ /** Primorial n# = product of all primes <= n (n >= 0). */
49
+ export declare function primorial(n: number): bigint;
50
+ //# sourceMappingURL=arithmetic-functions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arithmetic-functions.d.ts","sourceRoot":"","sources":["../../src/numbertheory/arithmetic-functions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAgDH,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAG/C;AAED,2DAA2D;AAC3D,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAGzC;AAED,iEAAiE;AACjE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAG1C;AAED,gDAAgD;AAChD,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAG5C;AAED,oDAAoD;AACpD,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAEjD;AAED,sEAAsE;AACtE,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAI7C;AAED,yDAAyD;AACzD,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAKzC;AAED,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAG5C;AAED,4EAA4E;AAC5E,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ7C;AAED,uEAAuE;AACvE,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAa3D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAS9E;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAIvE;AAED,6DAA6D;AAC7D,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,SAAK,GAAG,MAAM,CAW9D;AAED,uEAAuE;AACvE,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAK7C;AAED,kEAAkE;AAClE,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAS9C;AAED,0DAA0D;AAC1D,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAe3C"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Diophantine and lattice-style integer problems: linear Diophantine equations,
3
+ * Pell equations, the Frobenius (coin) number, Zeckendorf representation,
4
+ * sums of two squares, Egyptian fractions and Farey sequences.
5
+ */
6
+ /**
7
+ * Particular integer solution of a x + b y = c with the general solution
8
+ * x = x0 + stepX * t, y = y0 + stepY * t. Returns null when no solution exists.
9
+ */
10
+ export declare function linearDiophantine(a: number, b: number, c: number): {
11
+ x: number;
12
+ y: number;
13
+ stepX: number;
14
+ stepY: number;
15
+ } | null;
16
+ /**
17
+ * Fundamental solution (x, y) of Pell's equation x^2 - d y^2 = 1 for a positive
18
+ * non-square integer d, via the continued fraction of sqrt(d). Returns null for
19
+ * non-positive or perfect-square d.
20
+ */
21
+ export declare function pellSolve(d: number): {
22
+ x: bigint;
23
+ y: bigint;
24
+ } | null;
25
+ /**
26
+ * Frobenius number: the largest integer not representable as a non-negative
27
+ * combination of the coins. Requires positive integer coins with gcd 1
28
+ * (otherwise RangeError). Returns -1 when a coin equals 1.
29
+ */
30
+ export declare function frobeniusNumber(coins: readonly number[]): number;
31
+ /** Zeckendorf representation of n >= 0 as distinct, non-consecutive Fibonacci parts (descending). */
32
+ export declare function zeckendorf(n: number): number[];
33
+ /** All pairs [a, b] with 0 <= a <= b and a^2 + b^2 = n, in ascending order of a. */
34
+ export declare function sumOfTwoSquares(n: number): Array<[number, number]>;
35
+ /**
36
+ * Egyptian fraction of p/q (positive integers) by the greedy algorithm: returns
37
+ * the denominators of a decomposition into distinct unit fractions when the
38
+ * greedy steps are distinct (for p/q < 1, the usual case).
39
+ */
40
+ export declare function egyptianFraction(p: number, q: number): number[];
41
+ /** Farey sequence F_n: reduced fractions [num, den] in [0, 1] with den <= n, ascending. */
42
+ export declare function fareySequence(n: number): Array<[number, number]>;
43
+ //# sourceMappingURL=diophantine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diophantine.d.ts","sourceRoot":"","sources":["../../src/numbertheory/diophantine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA6BH;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACR;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAc/D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAgCpE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CA6BhE;AAED,qGAAqG;AACrG,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAa9C;AAED,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAclE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CA6B/D;AAED,2FAA2F;AAC3F,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAahE"}
@@ -71,18 +71,24 @@ export declare function stirlingS1(n: number, k: number): number;
71
71
  */
72
72
  export declare function discreteLog(g: number, h: number, p: number): number;
73
73
  /**
74
- * Smallest primitive root modulo a prime `p`.
74
+ * Smallest primitive root modulo `n`.
75
75
  *
76
- * For each candidate `g = 2, 3, ...`, `g` is a primitive root iff
77
- * `g^((p-1)/q) !== 1 (mod p)` for every prime factor `q` of `p - 1`.
76
+ * A primitive root exists only for `n` in {1, 2, 4, p^k, 2p^k} (p an odd
77
+ * prime); for any other `n` (8, 12, 15, ...) this throws, matching the
78
+ * file's contract of throwing `Error` on invalid input. For such `n`, `g` is a
79
+ * primitive root iff `gcd(g, n) = 1` and `g^(φ(n)/q) !== 1 (mod n)` for every
80
+ * prime factor `q` of `φ(n)`.
78
81
  *
79
- * @param p - An odd prime (p = 2 returns 1 trivially)
80
- * @returns The smallest primitive root modulo p
82
+ * @param n - An integer >= 2 with a primitive root (n = 2 returns 1)
83
+ * @returns The smallest primitive root modulo n
84
+ * @throws Error if n < 2, non-integer, or n has no primitive root
81
85
  *
82
86
  * @example
83
87
  * primitiveRoot(7) // => 3
88
+ * primitiveRoot(4) // => 3
89
+ * primitiveRoot(8) // throws (no primitive root)
84
90
  */
85
- export declare function primitiveRoot(p: number): number;
91
+ export declare function primitiveRoot(n: number): number;
86
92
  /**
87
93
  * Multiplicative order of `a` modulo `n`: the smallest `k > 0` with
88
94
  * `a^k === 1 (mod n)`. Returns `-1` if `gcd(a, n) !== 1` (no order exists).
@@ -1 +1 @@
1
- {"version":3,"file":"extra.d.ts","sourceRoot":"","sources":["../../src/numbertheory/extra.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,SAAK,GAAG,MAAM,EAAE,CAcpE;AAWD;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAkBhD;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAevD;AAqCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CA+BnE;AAoBD;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAmB/C;AAeD;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAehE;AAaD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CA0C5D;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAoBtE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,GAAE,MAAmB,GAAG,CAAC,EAAE,EAAE,CAwBnF"}
1
+ {"version":3,"file":"extra.d.ts","sourceRoot":"","sources":["../../src/numbertheory/extra.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,SAAK,GAAG,MAAM,EAAE,CAcpE;AAWD;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAkBhD;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAevD;AAqCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CA+BnE;AAoBD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CA4B/C;AAeD;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAuBhE;AAaD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CA0C5D;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAoBtE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,GAAE,MAAmB,GAAG,CAAC,EAAE,EAAE,CAwBnF"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Integer normal forms: row-style Hermite normal form, Smith normal form (with
3
+ * invariant factors) and the LLL lattice-basis reduction over floats.
4
+ */
5
+ /**
6
+ * Row-style Hermite normal form (upper-triangular echelon form obtained by
7
+ * unimodular row operations): positive pivots, and entries above each pivot
8
+ * reduced into [0, pivot).
9
+ */
10
+ export declare function hermiteNormalForm(A: ReadonlyArray<readonly (number | bigint)[]>): bigint[][];
11
+ /**
12
+ * Smith normal form: diagonal matrix D with d1 | d2 | ... (positive, zero
13
+ * padding allowed) equivalent to A under unimodular row and column operations.
14
+ * `invariants` lists the diagonal entries d1..d_min(m,n).
15
+ */
16
+ export declare function smithNormalForm(A: ReadonlyArray<readonly (number | bigint)[]>): {
17
+ D: bigint[][];
18
+ invariants: bigint[];
19
+ };
20
+ /**
21
+ * LLL reduction of a lattice basis given as row vectors (Lenstra–Lenstra–Lovász
22
+ * with Lovász parameter `delta`, default 0.75), in floating point with
23
+ * Gram–Schmidt recomputed after each change.
24
+ */
25
+ export declare function lll(basis: ReadonlyArray<readonly number[]>, delta?: number): number[][];
26
+ //# sourceMappingURL=integer-matrices.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integer-matrices.d.ts","sourceRoot":"","sources":["../../src/numbertheory/integer-matrices.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiCH;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE,CAqC5F;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,GAAG;IAC/E,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;IACd,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,CAwEA;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,KAAK,EAAE,aAAa,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,KAAK,SAAO,GAAG,MAAM,EAAE,EAAE,CAsDrF"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Modular arithmetic: modular exponentiation, previous prime, Legendre symbol,
3
+ * modular square roots (Tonelli–Shanks) and Carmichael-number test (Korselt).
4
+ */
5
+ /**
6
+ * Modular exponentiation `base^exp mod mod` by right-to-left binary squaring.
7
+ * The result lies in `[0, mod)`.
8
+ */
9
+ export declare function modPow(base: bigint | number, exp: bigint | number, mod_: bigint | number): bigint;
10
+ /** Largest prime strictly less than `n`. Throws RangeError when `n <= 2`. */
11
+ export declare function prevPrime(n: number): number;
12
+ /**
13
+ * Legendre symbol (a/p) for an odd prime p, via Euler's criterion.
14
+ * Returns 0 when p divides a, 1 for a quadratic residue, -1 otherwise.
15
+ */
16
+ export declare function legendreSymbol(a: number, p: number): -1 | 0 | 1;
17
+ /**
18
+ * Square root of `a` modulo a prime `p` (Tonelli–Shanks). Returns the smallest
19
+ * root in `[0, p)`, or `null` when `a` is a non-residue. For `p = 2` returns `a mod 2`.
20
+ */
21
+ export declare function sqrtMod(a: number, p: number): number | null;
22
+ /**
23
+ * Carmichael test by Korselt's criterion: `n` is composite, squarefree, and
24
+ * `(p - 1)` divides `(n - 1)` for every prime factor `p` of `n`.
25
+ */
26
+ export declare function isCarmichael(n: number): boolean;
27
+ //# sourceMappingURL=modular.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modular.d.ts","sourceRoot":"","sources":["../../src/numbertheory/modular.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA4BH;;;GAGG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAejG;AAED,6EAA6E;AAC7E,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAM3C;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAM/D;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAuC3D;AAoBD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAM/C"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Integer sequences and enumerators: Motzkin, Narayana, Schroder, Delannoy,
3
+ * Pell, tribonacci, Eulerian and Lah numbers, partition and composition
4
+ * generators, Gray code, and binomial coefficients mod a prime (Lucas).
5
+ */
6
+ /** Motzkin number M(n): number of Motzkin paths of length n. */
7
+ export declare function motzkin(n: number): number;
8
+ /** Narayana number N(n, k) = (1/n) C(n,k) C(n,k-1); 0 outside 1 <= k <= n. */
9
+ export declare function narayana(n: number, k: number): number;
10
+ /** Large Schroder number S(n) (1, 2, 6, 22, 90, ...). */
11
+ export declare function schroder(n: number): number;
12
+ /** Delannoy number D(m, n) = sum_k C(m,k) C(n,k) 2^k. */
13
+ export declare function delannoy(m: number, n: number): number;
14
+ /** Pell number P(n): P0 = 0, P1 = 1, P(n) = 2 P(n-1) + P(n-2). */
15
+ export declare function pell(n: number): number;
16
+ /** Tribonacci number T(n) with T(0) = 0, T(1) = 0, T(2) = 1. */
17
+ export declare function tribonacci(n: number): number;
18
+ /**
19
+ * Eulerian number A(n, k): permutations of n with k ascents. Defined for
20
+ * 0 <= k <= n - 1 (and A(0, 0) = 1); 0 otherwise.
21
+ */
22
+ export declare function eulerianNumber(n: number, k: number): number;
23
+ /** Lah number L(n, k) = C(n-1, k-1) n! / k!; 0 unless 1 <= k <= n. */
24
+ export declare function lahNumber(n: number, k: number): number;
25
+ /** All integer partitions of n, in descending lexicographic order. */
26
+ export declare function integerPartitionsGen(n: number): number[][];
27
+ /** All compositions (ordered partitions) of n. There are 2^(n-1) for n >= 1. */
28
+ export declare function compositionsGen(n: number): number[][];
29
+ /** Binary reflected Gray code over `bits` bits: 2^bits codewords. */
30
+ export declare function grayCode(bits: number): number[];
31
+ /**
32
+ * Binomial coefficient C(n, k) modulo a prime p, by Lucas' theorem.
33
+ * `p` must be prime.
34
+ */
35
+ export declare function binomialMod(n: bigint, k: bigint, p: bigint): bigint;
36
+ //# sourceMappingURL=sequences.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sequences.d.ts","sourceRoot":"","sources":["../../src/numbertheory/sequences.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkBH,gEAAgE;AAChE,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAWzC;AAED,8EAA8E;AAC9E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAIrD;AAED,yDAAyD;AACzD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAa1C;AAED,yDAAyD;AACzD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAQrD;AAED,kEAAkE;AAClE,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAQtC;AAED,gEAAgE;AAChE,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAS5C;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAU3D;AAED,sEAAsE;AACtE,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAOtD;AAED,sEAAsE;AACtE,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CAiB1D;AAED,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CAkBrD;AAED,qEAAqE;AACrE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAQ/C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAkBnE"}
@@ -0,0 +1,42 @@
1
+ /** Options for {@link minimizeConstrained}. */
2
+ export interface ConstrainedOptions {
3
+ /** Equality constraints `h(x) = 0`. */
4
+ eq?: ReadonlyArray<(x: number[]) => number>;
5
+ /** Inequality constraints `g(x) ≤ 0`. */
6
+ ineq?: ReadonlyArray<(x: number[]) => number>;
7
+ /** Box constraints `[lo, hi]` per coordinate. */
8
+ bounds?: ReadonlyArray<readonly [number, number]>;
9
+ /** Feasibility tolerance on the maximum constraint violation (default 1e-8). */
10
+ tol?: number;
11
+ /** Maximum number of outer (multiplier) iterations (default 50). */
12
+ maxOuter?: number;
13
+ /** Initial penalty parameter `μ` (default 10). */
14
+ mu0?: number;
15
+ }
16
+ /** Result of {@link minimizeConstrained}. */
17
+ export interface ConstrainedResult {
18
+ /** The constrained minimizer estimate. */
19
+ x: number[];
20
+ /** Objective value `f(x)` (not the augmented Lagrangian). */
21
+ fx: number;
22
+ /** Maximum of `|h_i(x)|` and `max(0, g_j(x))` at the returned point. */
23
+ constraintViolation: number;
24
+ /** Number of outer iterations performed. */
25
+ outerIterations: number;
26
+ /** Whether the constraint violation fell below `tol`. */
27
+ converged: boolean;
28
+ }
29
+ /**
30
+ * Minimize `f` from `x0` subject to the constraints in `opts`.
31
+ *
32
+ * With no equality or inequality constraints this is a single {@link bfgs}
33
+ * call (projected onto `bounds` if given).
34
+ *
35
+ * @example
36
+ * // min x² + y² s.t. x + y = 1 → x ≈ [0.5, 0.5], fx ≈ 0.5
37
+ * minimizeConstrained((v) => v[0] ** 2 + v[1] ** 2, [0, 0], {
38
+ * eq: [(v) => v[0] + v[1] - 1],
39
+ * });
40
+ */
41
+ export declare function minimizeConstrained(f: (x: number[]) => number, x0: readonly number[], opts?: ConstrainedOptions): ConstrainedResult;
42
+ //# sourceMappingURL=constrained.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constrained.d.ts","sourceRoot":"","sources":["../../src/numeric/constrained.ts"],"names":[],"mappings":"AAoBA,+CAA+C;AAC/C,MAAM,WAAW,kBAAkB;IACjC,uCAAuC;IACvC,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC,CAAC;IAC5C,yCAAyC;IACzC,IAAI,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC,CAAC;IAC9C,iDAAiD;IACjD,MAAM,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD,gFAAgF;IAChF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,6CAA6C;AAC7C,MAAM,WAAW,iBAAiB;IAChC,0CAA0C;IAC1C,CAAC,EAAE,MAAM,EAAE,CAAC;IACZ,6DAA6D;IAC7D,EAAE,EAAE,MAAM,CAAC;IACX,wEAAwE;IACxE,mBAAmB,EAAE,MAAM,CAAC;IAC5B,4CAA4C;IAC5C,eAAe,EAAE,MAAM,CAAC;IACxB,yDAAyD;IACzD,SAAS,EAAE,OAAO,CAAC;CACpB;AAKD;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,EAC1B,EAAE,EAAE,SAAS,MAAM,EAAE,EACrB,IAAI,GAAE,kBAAuB,GAC5B,iBAAiB,CA2EnB"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Finite-difference weights and two scalar fixed-point / bracketing solvers.
3
+ *
4
+ * - {@link finiteDifferenceCoefficients}: Fornberg's recursion for the weights
5
+ * of the `derivOrder`-th derivative at 0 from arbitrary offsets.
6
+ * - {@link ridders}: Ridders' bracketing root finder (exponential-fit false
7
+ * position), quadratic convergence on a sign-change bracket.
8
+ * - {@link fixedPoint}: iteration `x ← g(x)`, optionally accelerated by
9
+ * Aitken's Δ² extrapolation at every step.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ /**
14
+ * Weights `c_j` such that `f^{(m)}(0) ≈ Σ_j c_j f(x_j)` for the given offsets
15
+ * `x_j` (Fornberg 1988). The offsets must be distinct and there must be more
16
+ * than `derivOrder` of them.
17
+ *
18
+ * @example
19
+ * finiteDifferenceCoefficients(2, [-1, 0, 1]) // [1, -2, 1]
20
+ * finiteDifferenceCoefficients(1, [-1, 0, 1]) // [-0.5, 0, 0.5]
21
+ */
22
+ export declare function finiteDifferenceCoefficients(derivOrder: number, offsets: readonly number[]): number[];
23
+ /** Options for {@link ridders} and {@link fixedPoint}. */
24
+ export interface ScalarSolveOptions {
25
+ /** Tolerance on the step (relative to `max(1, |x|)`). */
26
+ tol?: number;
27
+ /** Maximum iterations. */
28
+ maxIter?: number;
29
+ }
30
+ /** Options for {@link fixedPoint}. */
31
+ export interface FixedPointOptions extends ScalarSolveOptions {
32
+ /** Apply Aitken Δ² extrapolation to each two-step update (default false). */
33
+ aitken?: boolean;
34
+ }
35
+ /**
36
+ * Root of `f` in the bracket `[a, b]` by Ridders' method. Requires
37
+ * `f(a)·f(b) ≤ 0`; throws `RangeError` otherwise and `Error` if `maxIter` is
38
+ * exhausted.
39
+ *
40
+ * @example
41
+ * ridders((x) => Math.cos(x) - x, 0, 1) // ~0.7390851332151607
42
+ */
43
+ export declare function ridders(f: (x: number) => number, a: number, b: number, opts?: ScalarSolveOptions): number;
44
+ /**
45
+ * Fixed point of `g` from `x0`: iterate `x ← g(x)` until the step is below
46
+ * `tol · max(1, |x|)`. With `aitken: true` each step applies two evaluations
47
+ * of `g` and Aitken's extrapolation `x₂ − (x₂ − x₁)² / (x₂ − 2x₁ + x₀)`.
48
+ * Throws if `maxIter` is exhausted or an iterate is not finite.
49
+ *
50
+ * @example
51
+ * fixedPoint(Math.cos, 1) // ~0.7390851332151607
52
+ */
53
+ export declare function fixedPoint(g: (x: number) => number, x0: number, opts?: FixedPointOptions): number;
54
+ //# sourceMappingURL=finite-differences.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finite-differences.d.ts","sourceRoot":"","sources":["../../src/numeric/finite-differences.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,MAAM,EAAE,CAyCV;AAED,0DAA0D;AAC1D,MAAM,WAAW,kBAAkB;IACjC,yDAAyD;IACzD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,sCAAsC;AACtC,MAAM,WAAW,iBAAkB,SAAQ,kBAAkB;IAC3D,6EAA6E;IAC7E,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CACrB,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,EACxB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,IAAI,GAAE,kBAAuB,GAC5B,MAAM,CAqCR;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,EACxB,EAAE,EAAE,MAAM,EACV,IAAI,GAAE,iBAAsB,GAC3B,MAAM,CAqBR"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Gauss quadrature nodes and weights for classical weight functions.
3
+ *
4
+ * - Hermite (weight `e^{−x²}` on ℝ), Laguerre (weight `x^α e^{−x}` on `[0, ∞)`),
5
+ * Jacobi (weight `(1−x)^α (1+x)^β` on `[−1, 1]`): the nodes are the roots of
6
+ * the degree-n orthogonal polynomial, found by a sign-change scan with
7
+ * bisection; the weights come from the Christoffel formula
8
+ * `w_i = 1 / Σ_{k<n} p_k(x_i)²` with orthonormal `p_k`.
9
+ * - Chebyshev T and U: closed-form nodes and weights.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ /** Nodes (ascending) and matching weights. */
14
+ export interface GaussRule {
15
+ nodes: number[];
16
+ weights: number[];
17
+ }
18
+ /**
19
+ * Hermite Gauss rule: nodes are the roots of H_n; weights satisfy
20
+ * `Σ w_i f(x_i) ≈ ∫ e^{−x²} f(x) dx`.
21
+ *
22
+ * @example
23
+ * rootsHermite(2).nodes // [-0.7071067811865476, 0.7071067811865476]
24
+ */
25
+ export declare function rootsHermite(n: number): GaussRule;
26
+ /**
27
+ * Generalized Laguerre Gauss rule for weight `x^α e^{−x}` on `[0, ∞)`
28
+ * (`α = 0` by default). Weights: `w_i = 1 / Σ_{k<n} k! (L_k^α(x_i))² / Γ(k+α+1)`.
29
+ *
30
+ * @example
31
+ * rootsLaguerre(2).nodes // [0.5857864376269049, 3.414213562373095]
32
+ */
33
+ export declare function rootsLaguerre(n: number, alpha?: number): GaussRule;
34
+ /**
35
+ * Chebyshev first-kind Gauss rule for weight `1/√(1−x²)`: closed-form nodes
36
+ * `cos((2i−1)π/(2n))` and equal weights `π/n`.
37
+ *
38
+ * @example
39
+ * rootsChebyshevT(3).nodes // [-0.8660254037844387, 0, 0.8660254037844387]
40
+ */
41
+ export declare function rootsChebyshevT(n: number): GaussRule;
42
+ /**
43
+ * Chebyshev second-kind Gauss rule for weight `√(1−x²)`: nodes `cos(iπ/(n+1))`
44
+ * and weights `π/(n+1) · sin²(iπ/(n+1))`.
45
+ *
46
+ * @example
47
+ * rootsChebyshevU(1).nodes // [0]
48
+ */
49
+ export declare function rootsChebyshevU(n: number): GaussRule;
50
+ /**
51
+ * Jacobi Gauss rule for weight `(1−x)^α (1+x)^β` on `[−1, 1]`. Weights use
52
+ * the Christoffel formula with the Jacobi norms
53
+ * `h_k = 2^{α+β+1}/(2k+α+β+1) · Γ(k+α+1)Γ(k+β+1)/(Γ(k+α+β+1) k!)`.
54
+ *
55
+ * @example
56
+ * rootsJacobi(3, 0, 0) // Legendre: nodes ±√(3/5), 0
57
+ */
58
+ export declare function rootsJacobi(n: number, alpha: number, beta: number): GaussRule;
59
+ /**
60
+ * Gauss–Hermite approximation of `∫_ℝ e^{−x²} f(x) dx` with `n` nodes.
61
+ *
62
+ * @example
63
+ * gaussHermiteIntegrate((x) => x * x, 5) // √π / 2
64
+ */
65
+ export declare function gaussHermiteIntegrate(f: (x: number) => number, n: number): number;
66
+ /**
67
+ * Gauss–Laguerre approximation of `∫₀^∞ e^{−x} f(x) dx` with `n` nodes.
68
+ *
69
+ * @example
70
+ * gaussLaguerreIntegrate((x) => x * x, 5) // 2
71
+ */
72
+ export declare function gaussLaguerreIntegrate(f: (x: number) => number, n: number): number;
73
+ //# sourceMappingURL=gauss-nodes-extra.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gauss-nodes-extra.d.ts","sourceRoot":"","sources":["../../src/numeric/gauss-nodes-extra.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,8CAA8C;AAC9C,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAiHD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAajD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,SAAS,CAkB7D;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CASpD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAUpD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CA6B7E;AAMD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAKjF;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAKlF"}
@@ -0,0 +1,64 @@
1
+ /** Options shared by the global optimizers. */
2
+ export interface GlobalOptimizeOptions {
3
+ /** Seed for the deterministic RNG (default `0`). */
4
+ seed?: number;
5
+ /** Maximum number of generations / iterations (default 1000 for DE, 10000 for SA). */
6
+ maxIter?: number;
7
+ /** Differential-evolution population size (default `15 · dim`). */
8
+ popSize?: number;
9
+ /** Convergence tolerance (DE: population fitness spread; SA: final temperature). */
10
+ tol?: number;
11
+ /** Differential weight `F` (default 0.8). */
12
+ F?: number;
13
+ /** Crossover probability `CR` (default 0.9). */
14
+ CR?: number;
15
+ }
16
+ /** Result of the global optimizers. */
17
+ export interface GlobalOptimizeResult {
18
+ /** Best point found. */
19
+ x: number[];
20
+ /** Objective value at `x`. */
21
+ fx: number;
22
+ /** Generations (DE) or iterations (SA) performed. */
23
+ iterations: number;
24
+ /** Number of objective evaluations. */
25
+ evaluations: number;
26
+ /** Whether the convergence test was met before the iteration budget ran out. */
27
+ converged: boolean;
28
+ }
29
+ /** Options for {@link simulatedAnnealing}. */
30
+ export interface SimulatedAnnealingOptions extends GlobalOptimizeOptions {
31
+ /** Initial temperature (default 1). */
32
+ T0?: number;
33
+ /** Geometric cooling factor applied per iteration, in (0, 1) (default 0.995). */
34
+ cooling?: number;
35
+ /** Optional box `[lo, hi]` per coordinate; proposals are clipped into it. */
36
+ bounds?: ReadonlyArray<readonly [number, number]>;
37
+ /** Finish with a Nelder-Mead local polish from the best point (default `true`). */
38
+ polish?: boolean;
39
+ }
40
+ /**
41
+ * Minimize `f` over the box `bounds` with differential evolution (`rand/1/bin`).
42
+ *
43
+ * @example
44
+ * differentialEvolution((x) => x[0] ** 2 + x[1] ** 2, [[-5, 5], [-5, 5]], { seed: 1 }).fx
45
+ * // ~0
46
+ */
47
+ export declare function differentialEvolution(f: (x: number[]) => number, bounds: ReadonlyArray<readonly [number, number]>, opts?: GlobalOptimizeOptions): GlobalOptimizeResult;
48
+ /**
49
+ * Minimize `f` from `x0` by simulated annealing (Metropolis acceptance,
50
+ * geometric cooling `T ← cooling · T`). The proposal width for coordinate `i`
51
+ * is `0.1 · (T / T0) · scale_i`, where `scale_i` is the bound width when
52
+ * `bounds` is given and `max(1, |x_i|)` otherwise.
53
+ *
54
+ * Stops when `T < tol` or after `maxIter` iterations. Unless `polish: false`,
55
+ * the best point is then refined by a bounded Nelder-Mead local search (with
56
+ * restarts). `converged` is `true` only when the cooling schedule finished
57
+ * (`T < tol`) AND the polish stopped on its own tolerance rather than its
58
+ * evaluation cap.
59
+ *
60
+ * @example
61
+ * simulatedAnnealing((x) => (x[0] - 3) ** 2, [0], { seed: 7 }).x // ~[3]
62
+ */
63
+ export declare function simulatedAnnealing(f: (x: number[]) => number, x0: readonly number[], opts?: SimulatedAnnealingOptions): GlobalOptimizeResult;
64
+ //# sourceMappingURL=global-optimizers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-optimizers.d.ts","sourceRoot":"","sources":["../../src/numeric/global-optimizers.ts"],"names":[],"mappings":"AAiBA,+CAA+C;AAC/C,MAAM,WAAW,qBAAqB;IACpC,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sFAAsF;IACtF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oFAAoF;IACpF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,gDAAgD;IAChD,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,uCAAuC;AACvC,MAAM,WAAW,oBAAoB;IACnC,wBAAwB;IACxB,CAAC,EAAE,MAAM,EAAE,CAAC;IACZ,8BAA8B;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,qDAAqD;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,gFAAgF;IAChF,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,8CAA8C;AAC9C,MAAM,WAAW,yBAA0B,SAAQ,qBAAqB;IACtE,uCAAuC;IACvC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD,mFAAmF;IACnF,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAoBD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,EAC1B,MAAM,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAChD,IAAI,GAAE,qBAA0B,GAC/B,oBAAoB,CAoEtB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,EAC1B,EAAE,EAAE,SAAS,MAAM,EAAE,EACrB,IAAI,GAAE,yBAA8B,GACnC,oBAAoB,CA4EtB"}