@danielsimonjr/mathts-core 0.14.3 → 0.15.1

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 (90) hide show
  1. package/dist/arithmetic/scalar.d.ts +56 -0
  2. package/dist/arithmetic/scalar.d.ts.map +1 -0
  3. package/dist/array.d.ts +265 -0
  4. package/dist/array.d.ts.map +1 -0
  5. package/dist/bignumber-formatter.d.ts +135 -0
  6. package/dist/bignumber-formatter.d.ts.map +1 -0
  7. package/dist/collection.d.ts +67 -0
  8. package/dist/collection.d.ts.map +1 -0
  9. package/dist/config.d.ts +20 -0
  10. package/dist/config.d.ts.map +1 -0
  11. package/dist/constants.d.ts +30 -0
  12. package/dist/constants.d.ts.map +1 -0
  13. package/dist/customs.d.ts +44 -0
  14. package/dist/customs.d.ts.map +1 -0
  15. package/dist/error/DimensionError.d.ts +28 -0
  16. package/dist/error/DimensionError.d.ts.map +1 -0
  17. package/dist/error/IndexError.d.ts +41 -0
  18. package/dist/error/IndexError.d.ts.map +1 -0
  19. package/dist/error/MathjsError.d.ts +13 -0
  20. package/dist/error/MathjsError.d.ts.map +1 -0
  21. package/dist/factory/factory.d.ts +154 -0
  22. package/dist/factory/factory.d.ts.map +1 -0
  23. package/dist/factory/index.d.ts +6 -0
  24. package/dist/factory/index.d.ts.map +1 -0
  25. package/dist/factory.d.ts +122 -0
  26. package/dist/factory.d.ts.map +1 -0
  27. package/dist/index.d.ts +24 -2593
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +36 -18
  30. package/dist/internal.d.ts +33 -1344
  31. package/dist/internal.d.ts.map +1 -0
  32. package/dist/internal.js +36 -6
  33. package/dist/is.d.ts +256 -0
  34. package/dist/is.d.ts.map +1 -0
  35. package/dist/map.d.ts +147 -0
  36. package/dist/map.d.ts.map +1 -0
  37. package/dist/number.d.ts +314 -0
  38. package/dist/number.d.ts.map +1 -0
  39. package/dist/numeric/stable.d.ts +130 -0
  40. package/dist/numeric/stable.d.ts.map +1 -0
  41. package/dist/object.d.ts +119 -0
  42. package/dist/object.d.ts.map +1 -0
  43. package/dist/shared.d.ts +41 -0
  44. package/dist/shared.d.ts.map +1 -0
  45. package/dist/string.d.ts +70 -0
  46. package/dist/string.d.ts.map +1 -0
  47. package/dist/switch.d.ts +9 -0
  48. package/dist/switch.d.ts.map +1 -0
  49. package/dist/typed/index.d.ts +7 -0
  50. package/dist/typed/index.d.ts.map +1 -0
  51. package/dist/typed/mathts-typed.d.ts +246 -0
  52. package/dist/typed/mathts-typed.d.ts.map +1 -0
  53. package/dist/typed/type-bridge.d.ts +9 -0
  54. package/dist/typed/type-bridge.d.ts.map +1 -0
  55. package/dist/types/bignumber.d.ts +370 -0
  56. package/dist/types/bignumber.d.ts.map +1 -0
  57. package/dist/types/complex.d.ts +284 -0
  58. package/dist/types/complex.d.ts.map +1 -0
  59. package/dist/types/dual-rules.d.ts +129 -0
  60. package/dist/types/dual-rules.d.ts.map +1 -0
  61. package/dist/types/dual.d.ts +39 -0
  62. package/dist/types/dual.d.ts.map +1 -0
  63. package/dist/types/fraction.d.ts +215 -0
  64. package/dist/types/fraction.d.ts.map +1 -0
  65. package/dist/types/interfaces.d.ts +143 -0
  66. package/dist/types/interfaces.d.ts.map +1 -0
  67. package/dist/types/matrix/Range.d.ts +767 -0
  68. package/dist/types/matrix/Range.d.ts.map +1 -0
  69. package/dist/types/unit/Unit.d.ts +3 -0
  70. package/dist/types/unit/Unit.d.ts.map +1 -0
  71. package/dist/types/unit/dependencies.d.ts +4 -0
  72. package/dist/types/unit/dependencies.d.ts.map +1 -0
  73. package/dist/types/unit/errors.d.ts +18 -0
  74. package/dist/types/unit/errors.d.ts.map +1 -0
  75. package/dist/types/unit/index.d.ts +7 -0
  76. package/dist/types/unit/index.d.ts.map +1 -0
  77. package/dist/types/unit/unit-types.d.ts +231 -0
  78. package/dist/types/unit/unit-types.d.ts.map +1 -0
  79. package/dist/types/unit-definitions.d.ts +79 -0
  80. package/dist/types/unit-definitions.d.ts.map +1 -0
  81. package/dist/types/unit-prefixes.d.ts +29 -0
  82. package/dist/types/unit-prefixes.d.ts.map +1 -0
  83. package/dist/types/unit.d.ts +28 -0
  84. package/dist/types/unit.d.ts.map +1 -0
  85. package/dist/types/wasm-loader.d.ts +35 -0
  86. package/dist/types/wasm-loader.d.ts.map +1 -0
  87. package/dist/wasm-loader.d.ts +97 -0
  88. package/dist/wasm-loader.d.ts.map +1 -0
  89. package/package.json +8 -8
  90. package/dist/index-B4LIOfHN.d.ts +0 -449
@@ -0,0 +1,314 @@
1
+ /**
2
+ * Split value representation with sign, coefficients, and exponent
3
+ */
4
+ export interface SplitValue {
5
+ sign: '+' | '-' | '';
6
+ coefficients: number[];
7
+ exponent: number;
8
+ }
9
+ /**
10
+ * Configuration for number type handling
11
+ */
12
+ export interface NumberTypeConfig {
13
+ number: 'number' | 'BigNumber' | 'bigint' | 'Fraction';
14
+ numberFallback: 'number' | 'BigNumber';
15
+ }
16
+ /**
17
+ * Format options for number formatting
18
+ */
19
+ export interface FormatOptions {
20
+ notation?: 'auto' | 'exponential' | 'fixed' | 'engineering' | 'bin' | 'oct' | 'hex';
21
+ precision?: number;
22
+ wordSize?: number;
23
+ lowerExp?: number;
24
+ upperExp?: number;
25
+ }
26
+ /**
27
+ * Normalized format options
28
+ */
29
+ export interface NormalizedFormatOptions {
30
+ notation: 'auto' | 'exponential' | 'fixed' | 'engineering' | 'bin' | 'oct' | 'hex';
31
+ precision: number | undefined;
32
+ wordSize: number | undefined;
33
+ }
34
+ /**
35
+ * Check if a number is integer
36
+ * @param value The value to check
37
+ * @return true if value is an integer
38
+ */
39
+ export declare function isInteger(value: number | boolean): boolean;
40
+ /**
41
+ * Ensure the number type is compatible with the provided value.
42
+ * If not, return 'number' instead.
43
+ *
44
+ * For example:
45
+ *
46
+ * safeNumberType('2.3', { number: 'bigint', numberFallback: 'number' })
47
+ *
48
+ * will return 'number' and not 'bigint' because trying to create a bigint with
49
+ * value 2.3 would throw an exception.
50
+ *
51
+ * @param numberStr The number as a string
52
+ * @param config Configuration with number type preferences
53
+ * @returns The safe number type to use
54
+ */
55
+ export declare function safeNumberType(numberStr: string, config: NumberTypeConfig): 'number' | 'BigNumber' | 'bigint' | 'Fraction';
56
+ /**
57
+ * Calculate the sign of a number
58
+ * @param x The number
59
+ * @returns 1 for positive, -1 for negative, 0 for zero
60
+ */
61
+ export declare const sign: (x: number) => number;
62
+ /**
63
+ * Calculate the base-2 logarithm of a number
64
+ * @param x The number
65
+ * @returns The base-2 logarithm
66
+ */
67
+ export declare const log2: (x: number) => number;
68
+ /**
69
+ * Calculate the base-10 logarithm of a number
70
+ * @param x The number
71
+ * @returns The base-10 logarithm
72
+ */
73
+ export declare const log10: (x: number) => number;
74
+ /**
75
+ * Calculate the natural logarithm of a number + 1
76
+ * @param x The number
77
+ * @returns ln(x + 1)
78
+ */
79
+ export declare const log1p: (x: number) => number;
80
+ /**
81
+ * Calculate cubic root for a number
82
+ *
83
+ * Code from es6-shim.js:
84
+ * https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L1564-L1577
85
+ *
86
+ * @param x The number
87
+ * @returns The cubic root of x
88
+ */
89
+ export declare const cbrt: (x: number) => number;
90
+ /**
91
+ * Calculates exponentiation minus 1
92
+ * @param x The exponent
93
+ * @return exp(x) - 1
94
+ */
95
+ export declare const expm1: (x: number) => number;
96
+ /**
97
+ * Convert a number to a formatted string representation.
98
+ *
99
+ * Syntax:
100
+ *
101
+ * format(value)
102
+ * format(value, options)
103
+ * format(value, precision)
104
+ * format(value, fn)
105
+ *
106
+ * Where:
107
+ *
108
+ * {number} value The value to be formatted
109
+ * {Object} options An object with formatting options. Available options:
110
+ * {string} notation
111
+ * Number notation. Choose from:
112
+ * 'fixed' Always use regular number notation.
113
+ * For example '123.40' and '14000000'
114
+ * 'exponential' Always use exponential notation.
115
+ * For example '1.234e+2' and '1.4e+7'
116
+ * 'engineering' Always use engineering notation.
117
+ * For example '123.4e+0' and '14.0e+6'
118
+ * 'auto' (default) Regular number notation for numbers
119
+ * having an absolute value between
120
+ * `lowerExp` and `upperExp` bounds, and
121
+ * uses exponential notation elsewhere.
122
+ * Lower bound is included, upper bound
123
+ * is excluded.
124
+ * For example '123.4' and '1.4e7'.
125
+ * 'bin', 'oct, or
126
+ * 'hex' Format the number using binary, octal,
127
+ * or hexadecimal notation.
128
+ * For example '0b1101' and '0x10fe'.
129
+ * {number} wordSize The word size in bits to use for formatting
130
+ * in binary, octal, or hexadecimal notation.
131
+ * To be used only with 'bin', 'oct', or 'hex'
132
+ * values for 'notation' option. When this option
133
+ * is defined the value is formatted as a signed
134
+ * twos complement integer of the given word size
135
+ * and the size suffix is appended to the output.
136
+ * For example
137
+ * format(-1, {notation: 'hex', wordSize: 8}) === '0xffi8'.
138
+ * Default value is undefined.
139
+ * {number} precision A number between 0 and 16 to round
140
+ * the digits of the number.
141
+ * In case of notations 'exponential',
142
+ * 'engineering', and 'auto',
143
+ * `precision` defines the total
144
+ * number of significant digits returned.
145
+ * In case of notation 'fixed',
146
+ * `precision` defines the number of
147
+ * significant digits after the decimal
148
+ * point.
149
+ * `precision` is undefined by default,
150
+ * not rounding any digits.
151
+ * {number} lowerExp Exponent determining the lower boundary
152
+ * for formatting a value with an exponent
153
+ * when `notation='auto`.
154
+ * Default value is `-3`.
155
+ * {number} upperExp Exponent determining the upper boundary
156
+ * for formatting a value with an exponent
157
+ * when `notation='auto`.
158
+ * Default value is `5`.
159
+ * {Function} fn A custom formatting function. Can be used to override the
160
+ * built-in notations. Function `fn` is called with `value` as
161
+ * parameter and must return a string. Is useful for example to
162
+ * format all values inside a matrix in a particular way.
163
+ *
164
+ * Examples:
165
+ *
166
+ * format(6.4) // '6.4'
167
+ * format(1240000) // '1.24e6'
168
+ * format(1/3) // '0.3333333333333333'
169
+ * format(1/3, 3) // '0.333'
170
+ * format(21385, 2) // '21000'
171
+ * format(12.071, {notation: 'fixed'}) // '12'
172
+ * format(2.3, {notation: 'fixed', precision: 2}) // '2.30'
173
+ * format(52.8, {notation: 'exponential'}) // '5.28e+1'
174
+ * format(12345678, {notation: 'engineering'}) // '12.345678e+6'
175
+ *
176
+ * @param value The number to format
177
+ * @param options Optional formatting options or custom formatter function or precision
178
+ * @return The formatted value
179
+ */
180
+ export declare function format(value: number, options?: FormatOptions | ((value: number) => string) | number): string;
181
+ /**
182
+ * Normalize format options into an object:
183
+ * {
184
+ * notation: string,
185
+ * precision: number | undefined,
186
+ * wordSize: number | undefined
187
+ * }
188
+ * @param options The input options
189
+ * @returns Normalized format options
190
+ */
191
+ export declare function normalizeFormatOptions(options?: FormatOptions | number): NormalizedFormatOptions;
192
+ /**
193
+ * Split a number into sign, coefficients, and exponent
194
+ * @param value The number or string to split
195
+ * @return Object containing sign, coefficients, and exponent
196
+ */
197
+ export declare function splitNumber(value: number | string): SplitValue;
198
+ /**
199
+ * Format a number in engineering notation. Like '1.23e+6', '2.3e+0', '3.500e-3'
200
+ * @param value The number or string to format
201
+ * @param precision Optional number of significant figures to return
202
+ * @returns The formatted string
203
+ */
204
+ export declare function toEngineering(value: number | string, precision?: number): string;
205
+ /**
206
+ * Format a number with fixed notation.
207
+ * @param value The number or string to format
208
+ * @param precision Optional number of decimals after the decimal point
209
+ * @returns The formatted string
210
+ */
211
+ export declare function toFixed(value: number | string, precision?: number): string;
212
+ /**
213
+ * Format a number in exponential notation. Like '1.23e+5', '2.3e+0', '3.500e-3'
214
+ * @param value The number or string to format
215
+ * @param precision Number of digits in formatted output
216
+ * @returns The formatted string
217
+ */
218
+ export declare function toExponential(value: number | string, precision?: number): string;
219
+ /**
220
+ * Format a number with a certain precision
221
+ * @param value The number or string to format
222
+ * @param precision Optional number of digits
223
+ * @param options Optional formatting options (lowerExp, upperExp)
224
+ * @return The formatted string
225
+ */
226
+ export declare function toPrecision(value: number | string, precision?: number, options?: FormatOptions): string;
227
+ /**
228
+ * Round the number of digits of a number
229
+ * @param split A value split with .splitNumber(value)
230
+ * @param precision A positive integer
231
+ * @return Object containing sign, coefficients, and exponent with rounded digits
232
+ */
233
+ export declare function roundDigits(split: SplitValue, precision?: number): SplitValue;
234
+ /**
235
+ * Count the number of significant digits of a number.
236
+ *
237
+ * For example:
238
+ * 2.34 returns 3
239
+ * 0.0034 returns 2
240
+ * 120.5e+30 returns 4
241
+ *
242
+ * @param value The number
243
+ * @return Number of significant digits
244
+ */
245
+ export declare function digits(value: number): number;
246
+ /**
247
+ * Compares two floating point numbers.
248
+ * @param a First value to compare
249
+ * @param b Second value to compare
250
+ * @param relTol The relative tolerance, indicating the maximum allowed difference relative to the larger absolute value. Must be greater than 0.
251
+ * @param absTol The minimum absolute tolerance, useful for comparisons near zero. Must be at least 0.
252
+ * @return whether the two numbers are nearly equal
253
+ *
254
+ * @throws Error If `relTol` is less than or equal to 0.
255
+ * @throws Error If `absTol` is less than 0.
256
+ *
257
+ * @example
258
+ * nearlyEqual(1.000000001, 1.0, 1e-8); // true
259
+ * nearlyEqual(1.000000002, 1.0, 0); // false
260
+ * nearlyEqual(1.0, 1.009, undefined, 0.01); // true
261
+ * nearlyEqual(0.000000001, 0.0, undefined, 1e-8); // true
262
+ */
263
+ export declare function nearlyEqual(a: number, b: number, relTol?: number, absTol?: number): boolean;
264
+ /**
265
+ * Calculate the hyperbolic arccos of a number
266
+ * @param x The number
267
+ * @return The hyperbolic arccosine
268
+ */
269
+ export declare const acosh: (x: number) => number;
270
+ /**
271
+ * Calculate the hyperbolic arcsine of a number
272
+ * @param x The number
273
+ * @return The hyperbolic arcsine
274
+ */
275
+ export declare const asinh: (x: number) => number;
276
+ /**
277
+ * Calculate the hyperbolic arctangent of a number
278
+ * @param x The number
279
+ * @return The hyperbolic arctangent
280
+ */
281
+ export declare const atanh: (x: number) => number;
282
+ /**
283
+ * Calculate the hyperbolic cosine of a number
284
+ * @param x The number
285
+ * @returns The hyperbolic cosine
286
+ */
287
+ export declare const cosh: (x: number) => number;
288
+ /**
289
+ * Calculate the hyperbolic sine of a number
290
+ * @param x The number
291
+ * @returns The hyperbolic sine
292
+ */
293
+ export declare const sinh: (x: number) => number;
294
+ /**
295
+ * Calculate the hyperbolic tangent of a number
296
+ * @param x The number
297
+ * @returns The hyperbolic tangent
298
+ */
299
+ export declare const tanh: (x: number) => number;
300
+ /**
301
+ * Returns a value with the magnitude of x and the sign of y.
302
+ * @param x The value providing the magnitude
303
+ * @param y The value providing the sign
304
+ * @returns Value with magnitude of x and sign of y
305
+ */
306
+ export declare function copysign(x: number, y: number): number;
307
+ /**
308
+ * Check if x^y is 0 due to infinity
309
+ * @param x The base
310
+ * @param y The exponent
311
+ * @returns true if x^y is 0 due to infinity
312
+ */
313
+ export declare function isPowZeroAtInfinity(x: number, y: number): boolean;
314
+ //# sourceMappingURL=number.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,GAAG,GAAG,GAAG,GAAG,EAAE,CAAC;IACrB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAC;IACvD,cAAc,EAAE,QAAQ,GAAG,WAAW,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,aAAa,GAAG,OAAO,GAAG,aAAa,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;IACpF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,GAA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AE,MAAM,GAAG,MAAM,CAIrD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAEjE"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Numerically stable reduction primitives.
3
+ *
4
+ * Floating-point addition is not associative, so *how* you accumulate decides how much error you
5
+ * carry. These are the algorithms the established numerical stack uses, and the reason it is
6
+ * trusted.
7
+ *
8
+ * Measured on this repo's own reductions before these existed — 1e6 copies of `0.1`, exact answer
9
+ * 100000:
10
+ *
11
+ * | accumulation | relative error |
12
+ * | ------------------------------- | -------------- |
13
+ * | naive `s += x` | **1.3e-11** |
14
+ * | pairwise (this, = NumPy's algo) | **2.9e-16** |
15
+ * | Neumaier compensated (`fsum`) | **0** (exact) |
16
+ *
17
+ * NumPy 2.3.4 reports 2.9e-16 on the same input — we are now at parity. Before this, we were
18
+ * ~46,000× worse than NumPy on a bog-standard `sum`, and `mean`, `std`, `var` and every statistic
19
+ * inherit that error.
20
+ *
21
+ * @packageDocumentation
22
+ */
23
+ /**
24
+ * Sum with **pairwise (cascade) summation** — the algorithm behind `np.sum`.
25
+ *
26
+ * Naive accumulation lets the running total grow large while the addends stay small, so each
27
+ * addition rounds off a little more of the total: error grows as **O(n)·ε**. Pairwise summation
28
+ * adds numbers of *comparable magnitude* by recursively halving the range, so error grows as
29
+ * **O(log n)·ε** — for n = 10⁶ that is the difference between ~1e-11 and ~1e-16.
30
+ *
31
+ * It costs the same number of additions as the naive loop. There is no speed/accuracy trade here;
32
+ * the naive version is simply worse.
33
+ *
34
+ * Not exact: for that, use {@link neumaierSum}. Pairwise is the right default because it is free.
35
+ */
36
+ export declare function pairwiseSum(xs: ArrayLike<number>, start?: number, end?: number): number;
37
+ /**
38
+ * Sum with **Neumaier compensation** — correctly rounded for practical purposes, the equivalent
39
+ * of Python's `math.fsum`.
40
+ *
41
+ * Tracks the low-order bits that each addition throws away and folds them back in at the end. It
42
+ * recovers information that pairwise summation cannot: `[1e16, 1, -1e16]` sums to **1** here,
43
+ * while both naive and pairwise (and `np.sum`) give **0**, because the `1` is annihilated the
44
+ * moment it meets `1e16`.
45
+ *
46
+ * ~2-4× slower than {@link pairwiseSum}, so it is opt-in rather than the default. Reach for it
47
+ * when catastrophic cancellation is possible: near-zero results from large terms, long-running
48
+ * accumulators, conservation checks.
49
+ *
50
+ * (Neumaier's variant, not classic Kahan: Kahan loses the compensation when the *addend* is
51
+ * larger than the running sum, which is precisely the `1e16` case.)
52
+ */
53
+ export declare function neumaierSum(xs: ArrayLike<number>): number;
54
+ /**
55
+ * Euclidean (2-)norm that does **not** overflow or underflow — BLAS's `dnrm2` scaling.
56
+ *
57
+ * The obvious `sqrt(Σxᵢ²)` squares before it adds, so it dies well inside the representable
58
+ * range: `‖[1e200, 1e200, 1e200, 1e200]‖` overflows to `Infinity` (the true answer, 2e200, is
59
+ * perfectly representable), and `‖[1e-200] × 4‖` **flushes to 0** — a silent wrong answer, which
60
+ * is worse.
61
+ *
62
+ * NumPy has this bug too: `np.linalg.norm([1e200]*4)` returns `inf` with an overflow warning.
63
+ * LAPACK does not, and neither do we.
64
+ *
65
+ * The fix is to carry a running scale: keep the largest magnitude seen out of the sum of squares,
66
+ * so the accumulator only ever holds ratios in [0, 1].
67
+ */
68
+ export declare function norm2(xs: ArrayLike<number>): number;
69
+ /**
70
+ * Dot product `Σ aᵢ·bᵢ` with **pairwise (cascade) summation** of the products — the accuracy of
71
+ * {@link pairwiseSum} applied to a dot without materialising the product array.
72
+ *
73
+ * A naive `s += a[i]*b[i]` loop carries the same **O(n)·ε** error as a naive sum; measured against
74
+ * an exact reference on an ill-conditioned dot (large mean × small factor, n = 10⁶) it is ~18×
75
+ * worse than `np.dot`, which sums pairwise. This closes that gap — and, like {@link pairwiseSum},
76
+ * costs the same number of flops as the naive loop.
77
+ *
78
+ * The two ranges are assumed the same length; callers guard that. Reads only `[start, end)`.
79
+ */
80
+ export declare function pairwiseDot(a: ArrayLike<number>, b: ArrayLike<number>, start?: number, end?: number): number;
81
+ /**
82
+ * Euclidean distance `‖a − b‖₂` that does **not** overflow or underflow — {@link norm2}'s BLAS
83
+ * `dnrm2` scaling applied to the elementwise difference.
84
+ *
85
+ * `distance` is just a 2-norm, so the obvious `sqrt(Σ(aᵢ−bᵢ)²)` inherits norm's pathology: it
86
+ * squares before it adds, overflowing to `Infinity` and — the dangerous case — **flushing to a
87
+ * silent 0** for small differences well inside the representable range. NumPy's `linalg.norm` has
88
+ * the same bug; scaling on the largest *difference* seen avoids both. The scale tracks the residual
89
+ * `a − b`, not the inputs, so it stays accurate even when `a` and `b` are individually huge.
90
+ *
91
+ * The two ranges are assumed the same length; callers guard that.
92
+ */
93
+ export declare function scaledDistance(a: ArrayLike<number>, b: ArrayLike<number>): number;
94
+ /**
95
+ * Sum of squared deviations from the mean, `Σ(xᵢ − x̄)²` — the **corrected two-pass** form, the
96
+ * numerator of a numerically stable variance.
97
+ *
98
+ * Variance is where large means bite: the deviations `xᵢ − x̄` can be O(1) while the values sit on
99
+ * a huge pedestal, so any error in `x̄` rides straight into every deviation. Two things fix it:
100
+ * 1. compute the mean with {@link pairwiseSum}, not a naive running total; and
101
+ * 2. subtract the residual mean-bias term `(Σd)²/n` — `Σd` is zero in exact arithmetic but not in
102
+ * floating point, and that leftover is exactly the systematic error a plain `Σd²` carries.
103
+ *
104
+ * Measured on 1e9-pedestal data: the plain naive two-pass (what shipped) lands ~1e-7 relative error;
105
+ * this lands ~1e-16 — better than `np.var`, which uses the uncorrected two-pass (~1e-13).
106
+ *
107
+ * The deviation vector is never materialised: both pairwise sums walk `xs` in
108
+ * registers, so variance/std no longer pay an extra n-long allocation.
109
+ *
110
+ * Divide the result by `n` (uncorrected), `n − 1` (unbiased/sample), or `n + 1` (biased) for the
111
+ * corresponding variance. Returns 0 for fewer than two elements.
112
+ */
113
+ export declare function sumSquaredDeviations(xs: ArrayLike<number>): number;
114
+ /**
115
+ * Cumulative sum with **Neumaier compensation** — each prefix total is written to `out[i]` carrying
116
+ * the low-order bits a naive running sum throws away.
117
+ *
118
+ * A cumulative sum is an inherently sequential prefix scan, so pairwise summation does not apply:
119
+ * you need every intermediate total, not just the final one. `np.cumsum` therefore accumulates
120
+ * naively and its tail drifts by **O(n)·ε** (relErr ~1.3e-11 over 10⁶ terms). Carrying a running
121
+ * compensation costs a few extra flops per element, no extra memory, and makes every prefix exact
122
+ * for practical purposes — a strict improvement over NumPy where accumulated drift matters (e.g.
123
+ * integrating a signal).
124
+ *
125
+ * Writes `out[i]` for `i` in `[0, xs.length)`; `out` may be a `number[]` or a `Float64Array`.
126
+ */
127
+ export declare function neumaierCumsum(xs: ArrayLike<number>, out: {
128
+ [index: number]: number;
129
+ }): void;
130
+ //# sourceMappingURL=stable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stable.d.ts","sourceRoot":"","sources":["../../src/numeric/stable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAWH;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,SAAI,EAAE,GAAG,SAAY,GAAG,MAAM,CAuCrF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAazD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAsBnD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CACzB,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EACpB,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EACpB,KAAK,SAAI,EACT,GAAG,SAAW,GACb,MAAM,CAoCR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAqBjF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAelE;AAiFD;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,IAAI,CAW5F"}
@@ -0,0 +1,119 @@
1
+ import { hasOwnProperty } from './shared.js';
2
+ /**
3
+ * Clone an object
4
+ *
5
+ * clone(x)
6
+ *
7
+ * Can clone any primitive type, array, and object.
8
+ * If x has a function clone, this function will be invoked to clone the object.
9
+ *
10
+ * @param x
11
+ * @return {*} clone
12
+ */
13
+ export declare function clone<T>(x: T): T;
14
+ /**
15
+ * Apply map to all properties of an object
16
+ * @param object
17
+ * @param callback
18
+ * @return {Object} Returns a copy of the object with mapped properties
19
+ */
20
+ export declare function mapObject<T, U>(object: Record<string, T>, callback: (value: T) => U): Record<string, U>;
21
+ /**
22
+ * Extend object a with the properties of object b
23
+ * @param a
24
+ * @param b
25
+ * @return {Object} a
26
+ */
27
+ export declare function extend<T extends Record<string, unknown>, U extends Record<string, unknown>>(a: T, b: U): T & U;
28
+ /**
29
+ * Deep extend an object a with the properties of object b
30
+ * @param a
31
+ * @param b
32
+ * @returns {Object}
33
+ */
34
+ export declare function deepExtend<T>(a: T, b: unknown): T;
35
+ /**
36
+ * Deep test equality of all fields in two pairs of arrays or objects.
37
+ * Compares values and functions strictly (ie. 2 is not the same as '2').
38
+ * @param a
39
+ * @param b
40
+ * @returns {boolean}
41
+ */
42
+ export declare function deepStrictEqual(a: unknown, b: unknown): boolean;
43
+ /**
44
+ * Recursively flatten a nested object.
45
+ * @param nestedObject
46
+ * @return {Object} Returns the flattened object
47
+ */
48
+ export declare function deepFlatten(nestedObject: Record<string, unknown>): Record<string, unknown>;
49
+ /**
50
+ * Test whether the current JavaScript engine supports Object.defineProperty
51
+ * @returns {boolean} returns true if supported
52
+ */
53
+ export declare function canDefineProperty(): boolean;
54
+ /**
55
+ * Attach a lazy loading property to a constant.
56
+ * The given function `fn` is called once when the property is first requested.
57
+ *
58
+ * @param object - Object where to add the property
59
+ * @param prop - Property name
60
+ * @param valueResolver - Function returning the property value. Called
61
+ * without arguments.
62
+ */
63
+ export declare function lazy<T>(object: Record<string, unknown>, prop: string, valueResolver: () => T): void;
64
+ /**
65
+ * Traverse a path into an object.
66
+ * When a namespace is missing, it will be created
67
+ * @param object
68
+ * @param path - A dot separated string like 'name.space'
69
+ * @return {Object} Returns the object at the end of the path
70
+ */
71
+ export declare function traverse(object: Record<string, unknown>, path: string | string[]): Record<string, unknown>;
72
+ export { hasOwnProperty };
73
+ /**
74
+ * Test whether an object is a factory. a factory has fields:
75
+ *
76
+ * - factory: function (type: Object, config: Object, load: function, typed: function [, math: Object]) (required)
77
+ * - name: string (optional)
78
+ * - path: string A dot separated path (optional)
79
+ * - math: boolean If true (false by default), the math namespace is passed
80
+ * as fifth argument of the factory function
81
+ *
82
+ * @param object
83
+ * @returns {boolean}
84
+ */
85
+ export declare function isLegacyFactory(object: unknown): boolean;
86
+ /**
87
+ * Get a nested property from an object
88
+ * @param object
89
+ * @param path
90
+ * @returns {Object}
91
+ */
92
+ export declare function get(object: Record<string, unknown>, path: string | string[]): unknown;
93
+ /**
94
+ * Set a nested property in an object
95
+ * Mutates the object itself
96
+ * If the path doesn't exist, it will be created
97
+ * @param object
98
+ * @param path
99
+ * @param value
100
+ * @returns {Object}
101
+ */
102
+ export declare function set<T extends Record<string, unknown>>(object: T, path: string | string[], value: unknown): T;
103
+ /**
104
+ * Create an object composed of the picked object properties
105
+ * @param object
106
+ * @param properties
107
+ * @param transform - Optional value to transform a value when picking it
108
+ * @return {Object}
109
+ */
110
+ export declare function pick(object: Record<string, unknown>, properties: string[], transform?: (value: unknown, key: string) => unknown): Record<string, unknown>;
111
+ /**
112
+ * Shallow version of pick, creating an object composed of the picked object properties
113
+ * but not for nested properties
114
+ * @param object
115
+ * @param properties
116
+ * @return {Object}
117
+ */
118
+ export declare function pickShallow(object: Record<string, unknown>, properties: string[]): Record<string, unknown>;
119
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAwChC;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,EACzB,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GACxB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAUnB;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzF,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,GACH,CAAC,GAAG,CAAC,CAQP;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CA8DjD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CA6C/D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC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EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,UAAU,EAAE,MAAM,EAAE,GACnB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Shared utility functions used across core utility modules.
3
+ * This file must have ZERO imports from other core utility files
4
+ * to serve as the base of the dependency graph and break circular imports.
5
+ */
6
+ /**
7
+ * A safe hasOwnProperty
8
+ * @param object
9
+ * @param property
10
+ */
11
+ export declare function hasOwnProperty(object: unknown, property: string): boolean;
12
+ /**
13
+ * True when `text` ends with `search`. (Equivalent to `String.prototype.endsWith`;
14
+ * kept as a named helper so relocated modules read the same as their mathjs origin.)
15
+ */
16
+ export declare function endsWith(text: string, search: string): boolean;
17
+ /**
18
+ * Warn to the console at most once per distinct message, deduped for the process
19
+ * lifetime. Used for deprecation notices (e.g. `Unit.toNumber`).
20
+ */
21
+ export declare const warnOnce: (...args: unknown[]) => void;
22
+ /** A function whose results are cached; clear the cache with `delete fn.cache`. */
23
+ export interface MemoizedFunction {
24
+ (...args: unknown[]): unknown;
25
+ cache?: Map<string, unknown>;
26
+ }
27
+ /**
28
+ * Memoize a pure function, caching results in a `Map` keyed by a string hash of the
29
+ * arguments (default `JSON.stringify`; override via `hasher`). Pass `limit` to bound
30
+ * the cache to N most-recently-used entries (LRU eviction via `Map` insertion order —
31
+ * on a hit the key is moved to the most-recent end; on overflow the oldest key is
32
+ * dropped); omit for an unbounded cache. The cache is exposed as `fn.cache` and can be
33
+ * reset with `delete fn.cache` — the next call lazily recreates it. (The relocated
34
+ * `Unit` relies on that reset when `createUnit`/`deleteUnit` invalidate the unit-name
35
+ * lookup cache, and passes `limit: 100` to bound the parse cache.)
36
+ */
37
+ export declare function memoize(fn: (...args: unknown[]) => unknown, { hasher, limit }?: {
38
+ hasher?: (args: unknown[]) => string;
39
+ limit?: number;
40
+ }): MemoizedFunction;
41
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzE;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAG9D;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,YAGe,OAAO,EAAE,KAAG,IAO5C,CAAC;AAEL,mFAAmF;AACnF,MAAM,WAAW,gBAAgB;IAC/B,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC9B,KAAK,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9B;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CACrB,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EACnC,EAAE,MAAM,EAAE,KAAK,EAAE,GAAE;IAAE,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAC/E,gBAAgB,CA2BlB"}