@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
package/dist/index.d.ts CHANGED
@@ -1,2597 +1,28 @@
1
- import { F as FactoryFunction$1 } from './index-B4LIOfHN.js';
2
- export { U as Unit, a as UnitInstance, i as isUnitValue } from './index-B4LIOfHN.js';
3
- import { TypedInstance, ReferTo, ReferToSelf, TypedFunction, SignatureFunction } from 'typed-function';
4
- export { ReferTo, ReferToSelf, SignatureFunction, TypedFunction, TypedInstance, create, default as typed } from 'typed-function';
5
-
6
- /**
7
- * Base interfaces for MathTS types
8
- * @module @danielsimonjr/mathts-core/types/interfaces
9
- */
10
- /**
11
- * Base interface for all MathTS numeric types
12
- */
13
- interface MathTSValue {
14
- readonly type: string;
15
- valueOf(): number | bigint;
16
- toString(): string;
17
- toJSON(): unknown;
18
- }
19
- /**
20
- * Scalar types that support arithmetic
21
- */
22
- interface Scalar extends MathTSValue {
23
- add(other: Scalar): Scalar;
24
- subtract(other: Scalar): Scalar;
25
- multiply(other: Scalar): Scalar;
26
- divide(other: Scalar): Scalar;
27
- negate(): Scalar;
28
- abs(): Scalar | number;
29
- }
30
- /**
31
- * Available computation backends
32
- */
33
- type BackendType = 'js' | 'wasm' | 'gpu';
34
- /**
35
- * Supported numeric types
36
- */
37
- type NumericType = 'float32' | 'float64' | 'int32' | 'int64' | 'complex64' | 'complex128';
38
- /**
39
- * Matrix backend interface
40
- */
41
- interface MatrixBackend {
42
- readonly name: BackendType;
43
- readonly isAvailable: boolean;
44
- matmul(a: Float64Array, b: Float64Array, m: number, n: number, k: number): Float64Array;
45
- transpose(data: Float64Array, rows: number, cols: number): Float64Array;
46
- add(a: Float64Array, b: Float64Array): Float64Array;
47
- subtract(a: Float64Array, b: Float64Array): Float64Array;
48
- scale(data: Float64Array, scalar: number): Float64Array;
49
- lu(data: Float64Array, n: number): {
50
- L: Float64Array;
51
- U: Float64Array;
52
- P: Int32Array;
53
- };
54
- qr(data: Float64Array, m: number, n: number): {
55
- Q: Float64Array;
56
- R: Float64Array;
57
- };
58
- svd(data: Float64Array, m: number, n: number): {
59
- U: Float64Array;
60
- S: Float64Array;
61
- V: Float64Array;
62
- };
63
- eig(data: Float64Array, n: number): {
64
- values: Float64Array;
65
- vectors: Float64Array;
66
- };
67
- }
68
- /**
69
- * Matrix interface with backend abstraction
70
- */
71
- interface IMatrix<T = number> extends MathTSValue {
72
- readonly rows: number;
73
- readonly cols: number;
74
- readonly size: readonly [number, number];
75
- readonly length: number;
76
- readonly backend: MatrixBackend;
77
- get(row: number, col: number): T;
78
- set(row: number, col: number, value: T): void;
79
- row(index: number): IMatrix<T>;
80
- column(index: number): IMatrix<T>;
81
- slice(rowStart: number, rowEnd: number, colStart: number, colEnd: number): IMatrix<T>;
82
- transpose(): IMatrix<T>;
83
- reshape(rows: number, cols: number): IMatrix<T>;
84
- flatten(): T[];
85
- add(other: IMatrix<T> | T): IMatrix<T>;
86
- subtract(other: IMatrix<T> | T): IMatrix<T>;
87
- multiply(other: IMatrix<T> | T): IMatrix<T>;
88
- toArray(): T[][];
89
- toBuffer(): ArrayBuffer;
90
- clone(): IMatrix<T>;
91
- }
92
- /**
93
- * Complex number interface
94
- */
95
- interface IComplex extends Scalar {
96
- readonly re: number;
97
- readonly im: number;
98
- conjugate(): IComplex;
99
- arg(): number;
100
- sqrt(): IComplex;
101
- exp(): IComplex;
102
- log(): IComplex;
103
- }
104
- /**
105
- * Fraction interface for exact rational arithmetic
106
- */
107
- interface IFraction extends Scalar {
108
- readonly numerator: bigint;
109
- readonly denominator: bigint;
110
- simplify(): IFraction;
111
- toNumber(): number;
112
- }
113
- /**
114
- * BigNumber interface for arbitrary precision decimals
115
- */
116
- interface IBigNumber extends MathTSValue {
117
- add(other: IBigNumber | number | string): IBigNumber;
118
- subtract(other: IBigNumber | number | string): IBigNumber;
119
- multiply(other: IBigNumber | number | string): IBigNumber;
120
- divide(other: IBigNumber | number | string): IBigNumber;
121
- negate(): IBigNumber;
122
- abs(): IBigNumber;
123
- pow(n: number | bigint): IBigNumber;
124
- sqrt(): IBigNumber;
125
- isNaN(): boolean;
126
- isFinite(): boolean;
127
- isInfinite(): boolean;
128
- isZero(): boolean;
129
- isPositive(): boolean;
130
- isNegative(): boolean;
131
- isInteger(): boolean;
132
- equals(other: IBigNumber): boolean;
133
- lessThan(other: IBigNumber): boolean;
134
- greaterThan(other: IBigNumber): boolean;
135
- compareTo(other: IBigNumber): number;
136
- toFixed(decimalPlaces?: number): string;
137
- toExponential(decimalPlaces?: number): string;
138
- toPrecision(significantDigits?: number): string;
139
- toBigInt(): bigint;
140
- }
141
- /**
142
- * Matrix dimensions
143
- */
144
- interface MatrixDimensions {
145
- rows: number;
146
- cols: number;
147
- }
148
-
149
- /**
150
- * Complex number implementation
151
- * @module @danielsimonjr/mathts-core/types/complex
152
- */
153
-
154
- /**
155
- * Check if a value is a Complex number
156
- */
157
- declare function isComplex(value: unknown): value is Complex;
158
- /**
159
- * Complex number class with full arithmetic support
160
- * Implements the IComplex interface for type-safe complex number operations.
161
- */
162
- declare class Complex implements IComplex {
163
- readonly type = "Complex";
164
- readonly re: number;
165
- readonly im: number;
166
- constructor(re: number, im?: number);
167
- /**
168
- * Create a Complex from polar form (r, θ)
169
- * @param r - magnitude (radius)
170
- * @param theta - angle in radians
171
- */
172
- static fromPolar(r: number, theta: number): Complex;
173
- /**
174
- * Create a Complex from a real number
175
- */
176
- static fromNumber(n: number): Complex;
177
- /**
178
- * Create a Complex from a JSON object
179
- */
180
- static fromJSON(json: {
181
- re: number;
182
- im: number;
183
- }): Complex;
184
- /**
185
- * Parse a complex number from a string
186
- * Supports formats: "3+4i", "3-4i", "3", "4i", "-4i", "i", "-i"
187
- */
188
- static parse(str: string): Complex;
189
- /**
190
- * Compare two complex numbers lexicographically (re first, then im)
191
- * @returns -1, 0, or 1
192
- */
193
- static compare(a: Complex, b: Complex): number;
194
- valueOf(): number;
195
- toString(): string;
196
- toJSON(): {
197
- mathjs: string;
198
- re: number;
199
- im: number;
200
- };
201
- /**
202
- * Return polar representation
203
- */
204
- toPolar(): {
205
- r: number;
206
- phi: number;
207
- };
208
- /**
209
- * Format with options (precision, notation, etc.)
210
- */
211
- format(options?: {
212
- precision?: number;
213
- notation?: 'fixed' | 'exponential' | 'auto';
214
- }): string;
215
- /**
216
- * Complex conjugate (a + bi → a - bi)
217
- */
218
- conjugate(): Complex;
219
- /**
220
- * Magnitude (absolute value) |z| = √(re² + im²)
221
- */
222
- abs(): number;
223
- /**
224
- * Phase angle (argument) in radians, range (-π, π]
225
- */
226
- arg(): number;
227
- /**
228
- * Squared magnitude |z|² = re² + im²
229
- * More efficient than abs() when you don't need the square root
230
- */
231
- abs2(): number;
232
- /**
233
- * Addition: (a + bi) + (c + di) = (a + c) + (b + d)i
234
- */
235
- add(other: Scalar): Complex;
236
- /**
237
- * Subtraction: (a + bi) - (c + di) = (a - c) + (b - d)i
238
- */
239
- subtract(other: Scalar): Complex;
240
- /**
241
- * Multiplication: (a + bi)(c + di) = (ac - bd) + (ad + bc)i
242
- */
243
- multiply(other: Scalar): Complex;
244
- /**
245
- * Division: (a + bi)/(c + di) = ((ac + bd) + (bc - ad)i) / (c² + d²)
246
- */
247
- divide(other: Scalar): Complex;
248
- sub(other: Scalar): Complex;
249
- mul(other: Scalar): Complex;
250
- div(other: Scalar): Complex;
251
- neg(): Complex;
252
- /**
253
- * Negation: -(a + bi) = -a - bi
254
- */
255
- negate(): Complex;
256
- /**
257
- * Multiplicative inverse: 1/z = z̄/|z|²
258
- */
259
- inverse(): Complex;
260
- /**
261
- * Square root using the principal branch (Re ≥ 0; Im has the sign of `this.im`).
262
- *
263
- * Algebraic form, not polar: one hypot + one sqrt instead of hypot + atan2 +
264
- * cos + sin. Same branch cut as C99 / the previous polar implementation,
265
- * including `sqrt(-x - 0i) = −√x · i`.
266
- */
267
- sqrt(): Complex;
268
- /**
269
- * n-th root (returns principal root)
270
- */
271
- nthRoot(n: number): Complex;
272
- /**
273
- * All n-th roots
274
- */
275
- nthRoots(n: number): Complex[];
276
- /**
277
- * Exponential: e^(a+bi) = e^a · (cos(b) + i·sin(b))
278
- */
279
- exp(): Complex;
280
- /**
281
- * Natural logarithm: ln(z) = ln|z| + i·arg(z)
282
- */
283
- log(): Complex;
284
- /**
285
- * Logarithm base 10
286
- */
287
- log10(): Complex;
288
- /**
289
- * Logarithm base 2
290
- */
291
- log2(): Complex;
292
- /**
293
- * Power: z^w = e^(w·ln(z))
294
- */
295
- pow(n: number | Complex): Complex;
296
- /**
297
- * Sine: sin(a + bi) = sin(a)cosh(b) + i·cos(a)sinh(b)
298
- */
299
- sin(): Complex;
300
- /**
301
- * Cosine: cos(a + bi) = cos(a)cosh(b) - i·sin(a)sinh(b)
302
- */
303
- cos(): Complex;
304
- /**
305
- * Tangent: tan(x+iy) = (sin 2x + i sinh 2y) / (cos 2x + cosh 2y)
306
- *
307
- * Closed form — no intermediate `sin`/`cos` Complex allocations.
308
- */
309
- tan(): Complex;
310
- /**
311
- * Cotangent: cot(x+iy) = (sin 2x − i sinh 2y) / (cosh 2y − cos 2x)
312
- */
313
- cot(): Complex;
314
- /**
315
- * Secant: sec(z) = 1 / cos(z)
316
- */
317
- sec(): Complex;
318
- /**
319
- * Cosecant: csc(z) = 1 / sin(z)
320
- */
321
- csc(): Complex;
322
- /**
323
- * Hyperbolic sine: sinh(z) = (e^z - e^(-z)) / 2
324
- */
325
- sinh(): Complex;
326
- /**
327
- * Hyperbolic cosine: cosh(z) = (e^z + e^(-z)) / 2
328
- */
329
- cosh(): Complex;
330
- /**
331
- * Hyperbolic tangent: tanh(x+iy) = (sinh 2x + i sin 2y) / (cosh 2x + cos 2y)
332
- */
333
- tanh(): Complex;
334
- /**
335
- * Hyperbolic cotangent: coth(x+iy) = (sinh 2x − i sin 2y) / (cosh 2x − cos 2y)
336
- */
337
- coth(): Complex;
338
- /**
339
- * Hyperbolic secant: sech(z) = 1 / cosh(z)
340
- */
341
- sech(): Complex;
342
- /**
343
- * Hyperbolic cosecant: csch(z) = 1 / sinh(z)
344
- */
345
- csch(): Complex;
346
- /**
347
- * Arc sine: asin(z) = -i·ln(iz + √(1 - z²))
348
- */
349
- asin(): Complex;
350
- /**
351
- * Arc cosine: acos(z) = π/2 - asin(z)
352
- */
353
- acos(): Complex;
354
- /**
355
- * Arc tangent: atan(z) = (i/2)·ln((i + z)/(i - z))
356
- */
357
- atan(): Complex;
358
- /**
359
- * Inverse hyperbolic sine: asinh(z) = ln(z + √(z² + 1))
360
- */
361
- asinh(): Complex;
362
- /**
363
- * Inverse hyperbolic cosine: acosh(z) = ln(z + √(z-1)·√(z+1))
364
- *
365
- * The principal value has non-negative real part (C99 Annex G / DLMF 4.37 /
366
- * NumPy convention). Using the factored `√(z-1)·√(z+1)` rather than `√(z²-1)`
367
- * selects the correct Riemann sheet for Re(z) < 0 and on the real-axis branch
368
- * cuts (z < 1), where `√(z²-1)` lands on the wrong branch — the previous form
369
- * returned a negative real part (e.g. acosh(-1+0.5i)) and the wrong sign of π
370
- * on z < -1.
371
- */
372
- acosh(): Complex;
373
- /**
374
- * Inverse hyperbolic tangent: atanh(z) = (1/2)·ln((1 + z)/(1 - z))
375
- */
376
- atanh(): Complex;
377
- /**
378
- * Check equality within tolerance
379
- */
380
- equals(other: Complex, epsilon?: number): boolean;
381
- /**
382
- * Check if this is a real number (im ≈ 0)
383
- */
384
- isReal(epsilon?: number): boolean;
385
- /**
386
- * Check if this is purely imaginary (re ≈ 0, im ≠ 0)
387
- */
388
- isImaginary(epsilon?: number): boolean;
389
- /**
390
- * Check if this is zero
391
- */
392
- isZero(epsilon?: number): boolean;
393
- /**
394
- * Check if this is NaN
395
- */
396
- isNaN(): boolean;
397
- /**
398
- * Check if this is infinite
399
- */
400
- isInfinite(): boolean;
401
- /**
402
- * Clone this complex number
403
- */
404
- clone(): Complex;
405
- /**
406
- * Round real and imaginary parts to specified decimals
407
- */
408
- round(decimals?: number): Complex;
409
- /**
410
- * Floor real and imaginary parts
411
- */
412
- floor(): Complex;
413
- /**
414
- * Ceil real and imaginary parts
415
- */
416
- ceil(): Complex;
417
- /**
418
- * Sign function: z / |z| (unit complex number in same direction)
419
- */
420
- sign(): Complex;
421
- }
422
- /**
423
- * Imaginary unit constant: i = √(-1)
424
- */
425
- declare const I: Complex;
426
- /**
427
- * Common constants
428
- */
429
- declare const COMPLEX_ZERO: Complex;
430
- declare const COMPLEX_ONE: Complex;
431
- declare const COMPLEX_NEG_ONE: Complex;
432
-
433
- interface BigNumber$1 {
434
- toNumber(): number;
435
- }
436
- /**
437
- * Callback function for Range forEach operations
438
- */
439
- type RangeForEachCallback = (value: number, index: number[], range: unknown) => void;
440
- /**
441
- * Callback function for Range map operations
442
- */
443
- type RangeMapCallback<T> = (value: number, index: number[], range: unknown) => T;
444
- /**
445
- * Formatting options for Range display
446
- */
447
- interface RangeFormatOptions {
448
- precision?: number;
449
- notation?: 'fixed' | 'exponential' | 'engineering' | 'auto';
450
- [key: string]: unknown;
451
- }
452
- /**
453
- * JSON representation of a Range
454
- */
455
- interface RangeJSON {
456
- mathjs: 'Range';
457
- start: number;
458
- end: number;
459
- step: number;
460
- }
461
- declare const createRangeClass: FactoryFunction$1<{
462
- new (start?: number | bigint | BigNumber$1 | null, end?: number | bigint | BigNumber$1 | null, step?: number | bigint | BigNumber$1 | null): {
463
- /**
464
- * Type identifier
465
- */
466
- readonly type: string;
467
- /**
468
- * Range type flag
469
- */
470
- readonly isRange: boolean;
471
- /**
472
- * Start value of the range (inclusive)
473
- */
474
- start: number;
475
- /**
476
- * End value of the range (exclusive)
477
- */
478
- end: number;
479
- /**
480
- * Step size for the range
481
- */
482
- step: number;
483
- /**
484
- * Cached primitive array representation
485
- */
486
- "__#private@#cache": number[] | null;
487
- "__#private@#cacheStart"?: number;
488
- "__#private@#cacheEnd"?: number;
489
- "__#private@#cacheStep"?: number;
490
- /**
491
- * Create a clone of the range
492
- * @return {Range} clone
493
- */
494
- clone(): /*elided*/ any;
495
- /**
496
- * Retrieve the size of the range.
497
- * Returns an array containing one number, the number of elements in the range.
498
- * @memberof Range
499
- * @returns {number[]} size
500
- */
501
- size(): number[];
502
- /**
503
- * Calculate the minimum value in the range
504
- * @memberof Range
505
- * @return {number | undefined} min
506
- */
507
- min(): number | undefined;
508
- /**
509
- * Calculate the maximum value in the range
510
- * @memberof Range
511
- * @return {number | undefined} max
512
- */
513
- max(): number | undefined;
514
- /**
515
- * Execute a callback function for each value in the range.
516
- * @memberof Range
517
- * @param {function} callback The callback method is invoked with three
518
- * parameters: the value of the element, the index
519
- * of the element, and the Range being traversed.
520
- */
521
- forEach(callback: RangeForEachCallback): void;
522
- /**
523
- * Execute a callback function for each value in the Range, and return the
524
- * results as an array
525
- * @memberof Range
526
- * @param {function} callback The callback method is invoked with three
527
- * parameters: the value of the element, the index
528
- * of the element, and the Matrix being traversed.
529
- * @returns {Array} array
530
- */
531
- map<T>(callback: RangeMapCallback<T>): T[];
532
- /**
533
- * Create an Array with a copy of the Ranges data
534
- * @memberof Range
535
- * @returns {Array} array
536
- */
537
- toArray(): number[];
538
- /**
539
- * Get the primitive value of the Range, a one dimensional array
540
- * @memberof Range
541
- * @returns {Array} array
542
- */
543
- valueOf(): number[];
544
- /**
545
- * Get a string representation of the range, with optional formatting options.
546
- * Output is formatted as 'start:step:end', for example '2:6' or '0:0.2:11'
547
- * @memberof Range
548
- * @param {Object | number | function} [options] Formatting options. See
549
- * lib/utils/number:format for a
550
- * description of the available
551
- * options.
552
- * @returns {string} str
553
- */
554
- format(options?: RangeFormatOptions | number | ((value: number) => string)): string;
555
- /**
556
- * Get a string representation of the range.
557
- * @memberof Range
558
- * @returns {string}
559
- */
560
- toString(): string;
561
- /**
562
- * Get a JSON representation of the range
563
- * @memberof Range
564
- * @returns {Object} Returns a JSON object structured as:
565
- * `{"mathjs": "Range", "start": 2, "end": 4, "step": 1}`
566
- */
567
- toJSON(): RangeJSON;
568
- };
569
- /**
570
- * Parse a string into a range,
571
- * The string contains the start, optional step, and end, separated by a colon.
572
- * If the string does not contain a valid range, null is returned.
573
- * For example str='0:2:11'.
574
- * @memberof Range
575
- * @param {string} str
576
- * @return {Range | null} range
577
- */
578
- parse(str: string): {
579
- /**
580
- * Type identifier
581
- */
582
- readonly type: string;
583
- /**
584
- * Range type flag
585
- */
586
- readonly isRange: boolean;
587
- /**
588
- * Start value of the range (inclusive)
589
- */
590
- start: number;
591
- /**
592
- * End value of the range (exclusive)
593
- */
594
- end: number;
595
- /**
596
- * Step size for the range
597
- */
598
- step: number;
599
- /**
600
- * Cached primitive array representation
601
- */
602
- "__#private@#cache": number[] | null;
603
- "__#private@#cacheStart"?: number;
604
- "__#private@#cacheEnd"?: number;
605
- "__#private@#cacheStep"?: number;
606
- /**
607
- * Create a clone of the range
608
- * @return {Range} clone
609
- */
610
- clone(): /*elided*/ any;
611
- /**
612
- * Retrieve the size of the range.
613
- * Returns an array containing one number, the number of elements in the range.
614
- * @memberof Range
615
- * @returns {number[]} size
616
- */
617
- size(): number[];
618
- /**
619
- * Calculate the minimum value in the range
620
- * @memberof Range
621
- * @return {number | undefined} min
622
- */
623
- min(): number | undefined;
624
- /**
625
- * Calculate the maximum value in the range
626
- * @memberof Range
627
- * @return {number | undefined} max
628
- */
629
- max(): number | undefined;
630
- /**
631
- * Execute a callback function for each value in the range.
632
- * @memberof Range
633
- * @param {function} callback The callback method is invoked with three
634
- * parameters: the value of the element, the index
635
- * of the element, and the Range being traversed.
636
- */
637
- forEach(callback: RangeForEachCallback): void;
638
- /**
639
- * Execute a callback function for each value in the Range, and return the
640
- * results as an array
641
- * @memberof Range
642
- * @param {function} callback The callback method is invoked with three
643
- * parameters: the value of the element, the index
644
- * of the element, and the Matrix being traversed.
645
- * @returns {Array} array
646
- */
647
- map<T>(callback: RangeMapCallback<T>): T[];
648
- /**
649
- * Create an Array with a copy of the Ranges data
650
- * @memberof Range
651
- * @returns {Array} array
652
- */
653
- toArray(): number[];
654
- /**
655
- * Get the primitive value of the Range, a one dimensional array
656
- * @memberof Range
657
- * @returns {Array} array
658
- */
659
- valueOf(): number[];
660
- /**
661
- * Get a string representation of the range, with optional formatting options.
662
- * Output is formatted as 'start:step:end', for example '2:6' or '0:0.2:11'
663
- * @memberof Range
664
- * @param {Object | number | function} [options] Formatting options. See
665
- * lib/utils/number:format for a
666
- * description of the available
667
- * options.
668
- * @returns {string} str
669
- */
670
- format(options?: RangeFormatOptions | number | ((value: number) => string)): string;
671
- /**
672
- * Get a string representation of the range.
673
- * @memberof Range
674
- * @returns {string}
675
- */
676
- toString(): string;
677
- /**
678
- * Get a JSON representation of the range
679
- * @memberof Range
680
- * @returns {Object} Returns a JSON object structured as:
681
- * `{"mathjs": "Range", "start": 2, "end": 4, "step": 1}`
682
- */
683
- toJSON(): RangeJSON;
684
- } | null;
685
- /**
686
- * Instantiate a Range from a JSON object
687
- * @memberof Range
688
- * @param {Object} json A JSON object structured as:
689
- * `{"mathjs": "Range", "start": 2, "end": 4, "step": 1}`
690
- * @return {Range}
691
- */
692
- fromJSON(json: RangeJSON): {
693
- /**
694
- * Type identifier
695
- */
696
- readonly type: string;
697
- /**
698
- * Range type flag
699
- */
700
- readonly isRange: boolean;
701
- /**
702
- * Start value of the range (inclusive)
703
- */
704
- start: number;
705
- /**
706
- * End value of the range (exclusive)
707
- */
708
- end: number;
709
- /**
710
- * Step size for the range
711
- */
712
- step: number;
713
- /**
714
- * Cached primitive array representation
715
- */
716
- "__#private@#cache": number[] | null;
717
- "__#private@#cacheStart"?: number;
718
- "__#private@#cacheEnd"?: number;
719
- "__#private@#cacheStep"?: number;
720
- /**
721
- * Create a clone of the range
722
- * @return {Range} clone
723
- */
724
- clone(): /*elided*/ any;
725
- /**
726
- * Retrieve the size of the range.
727
- * Returns an array containing one number, the number of elements in the range.
728
- * @memberof Range
729
- * @returns {number[]} size
730
- */
731
- size(): number[];
732
- /**
733
- * Calculate the minimum value in the range
734
- * @memberof Range
735
- * @return {number | undefined} min
736
- */
737
- min(): number | undefined;
738
- /**
739
- * Calculate the maximum value in the range
740
- * @memberof Range
741
- * @return {number | undefined} max
742
- */
743
- max(): number | undefined;
744
- /**
745
- * Execute a callback function for each value in the range.
746
- * @memberof Range
747
- * @param {function} callback The callback method is invoked with three
748
- * parameters: the value of the element, the index
749
- * of the element, and the Range being traversed.
750
- */
751
- forEach(callback: RangeForEachCallback): void;
752
- /**
753
- * Execute a callback function for each value in the Range, and return the
754
- * results as an array
755
- * @memberof Range
756
- * @param {function} callback The callback method is invoked with three
757
- * parameters: the value of the element, the index
758
- * of the element, and the Matrix being traversed.
759
- * @returns {Array} array
760
- */
761
- map<T>(callback: RangeMapCallback<T>): T[];
762
- /**
763
- * Create an Array with a copy of the Ranges data
764
- * @memberof Range
765
- * @returns {Array} array
766
- */
767
- toArray(): number[];
768
- /**
769
- * Get the primitive value of the Range, a one dimensional array
770
- * @memberof Range
771
- * @returns {Array} array
772
- */
773
- valueOf(): number[];
774
- /**
775
- * Get a string representation of the range, with optional formatting options.
776
- * Output is formatted as 'start:step:end', for example '2:6' or '0:0.2:11'
777
- * @memberof Range
778
- * @param {Object | number | function} [options] Formatting options. See
779
- * lib/utils/number:format for a
780
- * description of the available
781
- * options.
782
- * @returns {string} str
783
- */
784
- format(options?: RangeFormatOptions | number | ((value: number) => string)): string;
785
- /**
786
- * Get a string representation of the range.
787
- * @memberof Range
788
- * @returns {string}
789
- */
790
- toString(): string;
791
- /**
792
- * Get a JSON representation of the range
793
- * @memberof Range
794
- * @returns {Object} Returns a JSON object structured as:
795
- * `{"mathjs": "Range", "start": 2, "end": 4, "step": 1}`
796
- */
797
- toJSON(): RangeJSON;
798
- };
799
- }>;
800
- /**
801
- * Ready-made `Range` class (the factory instantiated with no dependencies),
802
- * exported for direct use from the package index — mirrors how core ships a
803
- * ready-made `Complex`/`Fraction`/`Unit` alongside its factory.
804
- */
805
- declare const Range: {
806
- new (start?: number | bigint | BigNumber$1 | null, end?: number | bigint | BigNumber$1 | null, step?: number | bigint | BigNumber$1 | null): {
807
- /**
808
- * Type identifier
809
- */
810
- readonly type: string;
811
- /**
812
- * Range type flag
813
- */
814
- readonly isRange: boolean;
815
- /**
816
- * Start value of the range (inclusive)
817
- */
818
- start: number;
819
- /**
820
- * End value of the range (exclusive)
821
- */
822
- end: number;
823
- /**
824
- * Step size for the range
825
- */
826
- step: number;
827
- /**
828
- * Cached primitive array representation
829
- */
830
- "__#private@#cache": number[] | null;
831
- "__#private@#cacheStart"?: number;
832
- "__#private@#cacheEnd"?: number;
833
- "__#private@#cacheStep"?: number;
834
- /**
835
- * Create a clone of the range
836
- * @return {Range} clone
837
- */
838
- clone(): /*elided*/ any;
839
- /**
840
- * Retrieve the size of the range.
841
- * Returns an array containing one number, the number of elements in the range.
842
- * @memberof Range
843
- * @returns {number[]} size
844
- */
845
- size(): number[];
846
- /**
847
- * Calculate the minimum value in the range
848
- * @memberof Range
849
- * @return {number | undefined} min
850
- */
851
- min(): number | undefined;
852
- /**
853
- * Calculate the maximum value in the range
854
- * @memberof Range
855
- * @return {number | undefined} max
856
- */
857
- max(): number | undefined;
858
- /**
859
- * Execute a callback function for each value in the range.
860
- * @memberof Range
861
- * @param {function} callback The callback method is invoked with three
862
- * parameters: the value of the element, the index
863
- * of the element, and the Range being traversed.
864
- */
865
- forEach(callback: RangeForEachCallback): void;
866
- /**
867
- * Execute a callback function for each value in the Range, and return the
868
- * results as an array
869
- * @memberof Range
870
- * @param {function} callback The callback method is invoked with three
871
- * parameters: the value of the element, the index
872
- * of the element, and the Matrix being traversed.
873
- * @returns {Array} array
874
- */
875
- map<T>(callback: RangeMapCallback<T>): T[];
876
- /**
877
- * Create an Array with a copy of the Ranges data
878
- * @memberof Range
879
- * @returns {Array} array
880
- */
881
- toArray(): number[];
882
- /**
883
- * Get the primitive value of the Range, a one dimensional array
884
- * @memberof Range
885
- * @returns {Array} array
886
- */
887
- valueOf(): number[];
888
- /**
889
- * Get a string representation of the range, with optional formatting options.
890
- * Output is formatted as 'start:step:end', for example '2:6' or '0:0.2:11'
891
- * @memberof Range
892
- * @param {Object | number | function} [options] Formatting options. See
893
- * lib/utils/number:format for a
894
- * description of the available
895
- * options.
896
- * @returns {string} str
897
- */
898
- format(options?: RangeFormatOptions | number | ((value: number) => string)): string;
899
- /**
900
- * Get a string representation of the range.
901
- * @memberof Range
902
- * @returns {string}
903
- */
904
- toString(): string;
905
- /**
906
- * Get a JSON representation of the range
907
- * @memberof Range
908
- * @returns {Object} Returns a JSON object structured as:
909
- * `{"mathjs": "Range", "start": 2, "end": 4, "step": 1}`
910
- */
911
- toJSON(): RangeJSON;
912
- };
913
- /**
914
- * Parse a string into a range,
915
- * The string contains the start, optional step, and end, separated by a colon.
916
- * If the string does not contain a valid range, null is returned.
917
- * For example str='0:2:11'.
918
- * @memberof Range
919
- * @param {string} str
920
- * @return {Range | null} range
921
- */
922
- parse(str: string): {
923
- /**
924
- * Type identifier
925
- */
926
- readonly type: string;
927
- /**
928
- * Range type flag
929
- */
930
- readonly isRange: boolean;
931
- /**
932
- * Start value of the range (inclusive)
933
- */
934
- start: number;
935
- /**
936
- * End value of the range (exclusive)
937
- */
938
- end: number;
939
- /**
940
- * Step size for the range
941
- */
942
- step: number;
943
- /**
944
- * Cached primitive array representation
945
- */
946
- "__#private@#cache": number[] | null;
947
- "__#private@#cacheStart"?: number;
948
- "__#private@#cacheEnd"?: number;
949
- "__#private@#cacheStep"?: number;
950
- /**
951
- * Create a clone of the range
952
- * @return {Range} clone
953
- */
954
- clone(): /*elided*/ any;
955
- /**
956
- * Retrieve the size of the range.
957
- * Returns an array containing one number, the number of elements in the range.
958
- * @memberof Range
959
- * @returns {number[]} size
960
- */
961
- size(): number[];
962
- /**
963
- * Calculate the minimum value in the range
964
- * @memberof Range
965
- * @return {number | undefined} min
966
- */
967
- min(): number | undefined;
968
- /**
969
- * Calculate the maximum value in the range
970
- * @memberof Range
971
- * @return {number | undefined} max
972
- */
973
- max(): number | undefined;
974
- /**
975
- * Execute a callback function for each value in the range.
976
- * @memberof Range
977
- * @param {function} callback The callback method is invoked with three
978
- * parameters: the value of the element, the index
979
- * of the element, and the Range being traversed.
980
- */
981
- forEach(callback: RangeForEachCallback): void;
982
- /**
983
- * Execute a callback function for each value in the Range, and return the
984
- * results as an array
985
- * @memberof Range
986
- * @param {function} callback The callback method is invoked with three
987
- * parameters: the value of the element, the index
988
- * of the element, and the Matrix being traversed.
989
- * @returns {Array} array
990
- */
991
- map<T>(callback: RangeMapCallback<T>): T[];
992
- /**
993
- * Create an Array with a copy of the Ranges data
994
- * @memberof Range
995
- * @returns {Array} array
996
- */
997
- toArray(): number[];
998
- /**
999
- * Get the primitive value of the Range, a one dimensional array
1000
- * @memberof Range
1001
- * @returns {Array} array
1002
- */
1003
- valueOf(): number[];
1004
- /**
1005
- * Get a string representation of the range, with optional formatting options.
1006
- * Output is formatted as 'start:step:end', for example '2:6' or '0:0.2:11'
1007
- * @memberof Range
1008
- * @param {Object | number | function} [options] Formatting options. See
1009
- * lib/utils/number:format for a
1010
- * description of the available
1011
- * options.
1012
- * @returns {string} str
1013
- */
1014
- format(options?: RangeFormatOptions | number | ((value: number) => string)): string;
1015
- /**
1016
- * Get a string representation of the range.
1017
- * @memberof Range
1018
- * @returns {string}
1019
- */
1020
- toString(): string;
1021
- /**
1022
- * Get a JSON representation of the range
1023
- * @memberof Range
1024
- * @returns {Object} Returns a JSON object structured as:
1025
- * `{"mathjs": "Range", "start": 2, "end": 4, "step": 1}`
1026
- */
1027
- toJSON(): RangeJSON;
1028
- } | null;
1029
- /**
1030
- * Instantiate a Range from a JSON object
1031
- * @memberof Range
1032
- * @param {Object} json A JSON object structured as:
1033
- * `{"mathjs": "Range", "start": 2, "end": 4, "step": 1}`
1034
- * @return {Range}
1035
- */
1036
- fromJSON(json: RangeJSON): {
1037
- /**
1038
- * Type identifier
1039
- */
1040
- readonly type: string;
1041
- /**
1042
- * Range type flag
1043
- */
1044
- readonly isRange: boolean;
1045
- /**
1046
- * Start value of the range (inclusive)
1047
- */
1048
- start: number;
1049
- /**
1050
- * End value of the range (exclusive)
1051
- */
1052
- end: number;
1053
- /**
1054
- * Step size for the range
1055
- */
1056
- step: number;
1057
- /**
1058
- * Cached primitive array representation
1059
- */
1060
- "__#private@#cache": number[] | null;
1061
- "__#private@#cacheStart"?: number;
1062
- "__#private@#cacheEnd"?: number;
1063
- "__#private@#cacheStep"?: number;
1064
- /**
1065
- * Create a clone of the range
1066
- * @return {Range} clone
1067
- */
1068
- clone(): /*elided*/ any;
1069
- /**
1070
- * Retrieve the size of the range.
1071
- * Returns an array containing one number, the number of elements in the range.
1072
- * @memberof Range
1073
- * @returns {number[]} size
1074
- */
1075
- size(): number[];
1076
- /**
1077
- * Calculate the minimum value in the range
1078
- * @memberof Range
1079
- * @return {number | undefined} min
1080
- */
1081
- min(): number | undefined;
1082
- /**
1083
- * Calculate the maximum value in the range
1084
- * @memberof Range
1085
- * @return {number | undefined} max
1086
- */
1087
- max(): number | undefined;
1088
- /**
1089
- * Execute a callback function for each value in the range.
1090
- * @memberof Range
1091
- * @param {function} callback The callback method is invoked with three
1092
- * parameters: the value of the element, the index
1093
- * of the element, and the Range being traversed.
1094
- */
1095
- forEach(callback: RangeForEachCallback): void;
1096
- /**
1097
- * Execute a callback function for each value in the Range, and return the
1098
- * results as an array
1099
- * @memberof Range
1100
- * @param {function} callback The callback method is invoked with three
1101
- * parameters: the value of the element, the index
1102
- * of the element, and the Matrix being traversed.
1103
- * @returns {Array} array
1104
- */
1105
- map<T>(callback: RangeMapCallback<T>): T[];
1106
- /**
1107
- * Create an Array with a copy of the Ranges data
1108
- * @memberof Range
1109
- * @returns {Array} array
1110
- */
1111
- toArray(): number[];
1112
- /**
1113
- * Get the primitive value of the Range, a one dimensional array
1114
- * @memberof Range
1115
- * @returns {Array} array
1116
- */
1117
- valueOf(): number[];
1118
- /**
1119
- * Get a string representation of the range, with optional formatting options.
1120
- * Output is formatted as 'start:step:end', for example '2:6' or '0:0.2:11'
1121
- * @memberof Range
1122
- * @param {Object | number | function} [options] Formatting options. See
1123
- * lib/utils/number:format for a
1124
- * description of the available
1125
- * options.
1126
- * @returns {string} str
1127
- */
1128
- format(options?: RangeFormatOptions | number | ((value: number) => string)): string;
1129
- /**
1130
- * Get a string representation of the range.
1131
- * @memberof Range
1132
- * @returns {string}
1133
- */
1134
- toString(): string;
1135
- /**
1136
- * Get a JSON representation of the range
1137
- * @memberof Range
1138
- * @returns {Object} Returns a JSON object structured as:
1139
- * `{"mathjs": "Range", "start": 2, "end": 4, "step": 1}`
1140
- */
1141
- toJSON(): RangeJSON;
1142
- };
1143
- };
1144
-
1145
- declare class Dual {
1146
- /** Function value (the real part). */
1147
- readonly value: number;
1148
- /** First derivative (the ε coefficient). */
1149
- readonly deriv: number;
1150
- constructor(value: number, deriv?: number);
1151
- /** A constant (derivative 0). */
1152
- static constant(v: number): Dual;
1153
- /** A seed variable (derivative 1) — the point of differentiation. */
1154
- static variable(v: number): Dual;
1155
- add(o: Dual): Dual;
1156
- sub(o: Dual): Dual;
1157
- mul(o: Dual): Dual;
1158
- div(o: Dual): Dual;
1159
- neg(): Dual;
1160
- /** Power with a constant real exponent: d(xᵏ) = k·xᵏ⁻¹·dx. */
1161
- powConst(k: number): Dual;
1162
- /** General power a^b: d = a^b·(b'·ln a + b·a'/a). */
1163
- pow(o: Dual): Dual;
1164
- private unary;
1165
- sin(): Dual;
1166
- cos(): Dual;
1167
- tan(): Dual;
1168
- exp(): Dual;
1169
- log(): Dual;
1170
- sqrt(): Dual;
1171
- square(): Dual;
1172
- abs(): Dual;
1173
- sinh(): Dual;
1174
- cosh(): Dual;
1175
- tanh(): Dual;
1176
- toString(): string;
1177
- }
1178
- /** Type guard for {@link Dual}. */
1179
- declare function isDual(x: unknown): x is Dual;
1180
-
1181
- /**
1182
- * Canonical elementary-function derivative rules for forward-mode automatic
1183
- * differentiation. This is the single source of truth for the chain rules,
1184
- * shared by the scalar {@link Dual} (core) and the tensor `DualTensor`
1185
- * (autograd) so neither reinvents them.
1186
- *
1187
- * Each rule is a pair of pure `number → number` functions:
1188
- * - `primal(x)` — f(x)
1189
- * - `deriv(x, y)` — f′(x), given both x and the already-computed y = f(x),
1190
- * so output-reusing derivatives (exp, tanh, sqrt, cbrt, expm1) stay cheap.
1191
- *
1192
- * Keeping these as plain scalar functions (no `Dual`/`Tensor` allocation) is
1193
- * what lets autograd's `Float64Array` element-wise loop stay allocation-free.
1194
- * It is also the propagation path: a future accelerated `primal` in the
1195
- * standard layer (WASM/SIMD batch kernels) can be swapped in here and every
1196
- * consumer inherits the speedup without touching this contract.
1197
- */
1198
- /** A forward-mode derivative rule for a unary elementary function. */
1199
- interface DualUnaryRule {
1200
- /** f(x). */
1201
- readonly primal: (x: number) => number;
1202
- /** f′(x), given x and y = f(x) (y lets exp/tanh/sqrt/… avoid recomputation). */
1203
- readonly deriv: (x: number, y: number) => number;
1204
- }
1205
- /**
1206
- * The canonical table. Derivatives are stated in the cheapest exact form
1207
- * (reusing y where that avoids a redundant transcendental call).
1208
- */
1209
- declare const DUAL_UNARY_RULES: {
1210
- exp: {
1211
- primal: (x: number) => number;
1212
- deriv: (_x: number, y: number) => number;
1213
- };
1214
- expm1: {
1215
- primal: (x: number) => number;
1216
- deriv: (_x: number, y: number) => number;
1217
- };
1218
- log: {
1219
- primal: (x: number) => number;
1220
- deriv: (x: number) => number;
1221
- };
1222
- log2: {
1223
- primal: (x: number) => number;
1224
- deriv: (x: number) => number;
1225
- };
1226
- log10: {
1227
- primal: (x: number) => number;
1228
- deriv: (x: number) => number;
1229
- };
1230
- log1p: {
1231
- primal: (x: number) => number;
1232
- deriv: (x: number) => number;
1233
- };
1234
- sin: {
1235
- primal: (x: number) => number;
1236
- deriv: (x: number) => number;
1237
- };
1238
- cos: {
1239
- primal: (x: number) => number;
1240
- deriv: (x: number) => number;
1241
- };
1242
- tan: {
1243
- primal: (x: number) => number;
1244
- deriv: (x: number) => number;
1245
- };
1246
- asin: {
1247
- primal: (x: number) => number;
1248
- deriv: (x: number) => number;
1249
- };
1250
- acos: {
1251
- primal: (x: number) => number;
1252
- deriv: (x: number) => number;
1253
- };
1254
- atan: {
1255
- primal: (x: number) => number;
1256
- deriv: (x: number) => number;
1257
- };
1258
- sinh: {
1259
- primal: (x: number) => number;
1260
- deriv: (x: number) => number;
1261
- };
1262
- cosh: {
1263
- primal: (x: number) => number;
1264
- deriv: (x: number) => number;
1265
- };
1266
- tanh: {
1267
- primal: (x: number) => number;
1268
- deriv: (_x: number, y: number) => number;
1269
- };
1270
- asinh: {
1271
- primal: (x: number) => number;
1272
- deriv: (x: number) => number;
1273
- };
1274
- acosh: {
1275
- primal: (x: number) => number;
1276
- deriv: (x: number) => number;
1277
- };
1278
- atanh: {
1279
- primal: (x: number) => number;
1280
- deriv: (x: number) => number;
1281
- };
1282
- sqrt: {
1283
- primal: (x: number) => number;
1284
- deriv: (_x: number, y: number) => number;
1285
- };
1286
- cbrt: {
1287
- primal: (x: number) => number;
1288
- deriv: (_x: number, y: number) => number;
1289
- };
1290
- square: {
1291
- primal: (x: number) => number;
1292
- deriv: (x: number) => number;
1293
- };
1294
- reciprocal: {
1295
- primal: (x: number) => number;
1296
- deriv: (x: number) => number;
1297
- };
1298
- abs: {
1299
- primal: (x: number) => number;
1300
- deriv: (x: number) => number;
1301
- };
1302
- sign: {
1303
- primal: (x: number) => number;
1304
- deriv: () => number;
1305
- };
1306
- };
1307
- /** Name of a rule in {@link DUAL_UNARY_RULES}. */
1308
- type DualUnaryRuleName = keyof typeof DUAL_UNARY_RULES;
1309
-
1310
- /**
1311
- * Named mathematical constants (plain `number`).
1312
- *
1313
- * These mirror the constants documented in `docs/reference/constants.md` and the
1314
- * familiar `Math.*` values, exported as first-class named bindings so callers can
1315
- * `import { PI, E, TAU } from '@danielsimonjr/mathts-core'`. The imaginary unit
1316
- * `I` and the type-specific constants (`COMPLEX_*`, `BIGNUMBER_*`, `FRACTION_*`)
1317
- * live with their respective types.
1318
- */
1319
- /** Ratio of a circle's circumference to its diameter. */
1320
- declare const PI: number;
1321
- /** Euler's number, the base of the natural logarithm. */
1322
- declare const E: number;
1323
- /** Full-circle constant, `2·PI`. */
1324
- declare const TAU: number;
1325
- /** Golden ratio, `(1 + √5) / 2`. */
1326
- declare const PHI: number;
1327
- /** Square root of 2. */
1328
- declare const SQRT2: number;
1329
- /** Square root of one-half. */
1330
- declare const SQRT1_2: number;
1331
- /** Natural logarithm of 2. */
1332
- declare const LN2: number;
1333
- /** Natural logarithm of 10. */
1334
- declare const LN10: number;
1335
- /** Base-2 logarithm of E. */
1336
- declare const LOG2E: number;
1337
- /** Base-10 logarithm of E. */
1338
- declare const LOG10E: number;
1339
-
1340
- /**
1341
- * Fraction (rational number) implementation
1342
- * @module @danielsimonjr/mathts-core/types/fraction
1343
- */
1344
-
1345
- /**
1346
- * Check if a value is a Fraction
1347
- */
1348
- declare function isFraction(value: unknown): value is Fraction;
1349
- /**
1350
- * Fraction class for exact rational arithmetic
1351
- * Uses bigint for arbitrary precision numerator and denominator.
1352
- * All fractions are automatically reduced to lowest terms.
1353
- */
1354
- declare class Fraction implements IFraction {
1355
- readonly type = "Fraction";
1356
- readonly numerator: bigint;
1357
- readonly denominator: bigint;
1358
- constructor(numerator: bigint | number | string | Fraction, denominator?: bigint | number | string | Fraction);
1359
- /**
1360
- * Create a Fraction from a number (with optional precision)
1361
- */
1362
- static fromNumber(n: number, maxDenominator?: bigint): Fraction;
1363
- /**
1364
- * Create a Fraction from a decimal string
1365
- */
1366
- static fromDecimalString(str: string): Fraction;
1367
- /**
1368
- * Parse a fraction from a string
1369
- * Supports formats: "3/4", "-3/4", "3", "3.14", "0.(3)"
1370
- */
1371
- static parse(str: string): Fraction;
1372
- /**
1373
- * Create a Fraction from a JSON object
1374
- */
1375
- static fromJSON(json: {
1376
- n: string;
1377
- d: string;
1378
- } | {
1379
- numerator: string;
1380
- denominator: string;
1381
- }): Fraction;
1382
- /**
1383
- * Compare two fractions
1384
- * @returns -1, 0, or 1
1385
- */
1386
- static compare(a: Fraction, b: Fraction): number;
1387
- valueOf(): number;
1388
- toString(): string;
1389
- toJSON(): {
1390
- mathjs: string;
1391
- n: string;
1392
- d: string;
1393
- };
1394
- /**
1395
- * Convert to number
1396
- */
1397
- toNumber(): number;
1398
- /**
1399
- * Convert to decimal string with specified precision
1400
- */
1401
- toDecimal(precision?: number): string;
1402
- /**
1403
- * Convert to LaTeX string
1404
- */
1405
- toLatex(): string;
1406
- /**
1407
- * Convert to mixed number representation
1408
- */
1409
- toMixed(): {
1410
- whole: bigint;
1411
- numerator: bigint;
1412
- denominator: bigint;
1413
- };
1414
- /**
1415
- * Addition: a/b + c/d = (ad + bc) / bd
1416
- */
1417
- add(other: Scalar): Fraction;
1418
- /**
1419
- * Subtraction: a/b - c/d = (ad - bc) / bd
1420
- */
1421
- subtract(other: Scalar): Fraction;
1422
- /**
1423
- * Multiplication: a/b * c/d = ac / bd
1424
- */
1425
- multiply(other: Scalar): Fraction;
1426
- /**
1427
- * Division: a/b ÷ c/d = ad / bc
1428
- */
1429
- divide(other: Scalar): Fraction;
1430
- mul(other: Scalar): Fraction;
1431
- sub(other: Scalar): Fraction;
1432
- div(other: Scalar): Fraction;
1433
- /**
1434
- * Negation: -(a/b) = -a/b
1435
- */
1436
- negate(): Fraction;
1437
- /**
1438
- * Absolute value: |a/b|
1439
- */
1440
- abs(): Fraction;
1441
- /**
1442
- * Reciprocal: b/a
1443
- */
1444
- inverse(): Fraction;
1445
- /**
1446
- * Power (integer exponent)
1447
- */
1448
- pow(n: number | bigint): Fraction;
1449
- /**
1450
- * Modulo operation
1451
- */
1452
- mod(other: Fraction): Fraction;
1453
- /**
1454
- * Check equality
1455
- */
1456
- equals(other: Fraction): boolean;
1457
- /**
1458
- * Check if less than
1459
- */
1460
- lessThan(other: Fraction): boolean;
1461
- /**
1462
- * Check if less than or equal
1463
- */
1464
- lessThanOrEqual(other: Fraction): boolean;
1465
- /**
1466
- * Check if greater than
1467
- */
1468
- greaterThan(other: Fraction): boolean;
1469
- /**
1470
- * Check if greater than or equal
1471
- */
1472
- greaterThanOrEqual(other: Fraction): boolean;
1473
- /**
1474
- * Compare with another fraction
1475
- * @returns -1, 0, or 1
1476
- */
1477
- compareTo(other: Fraction): number;
1478
- compare(other: Fraction): number;
1479
- /**
1480
- * Return fraction already in lowest terms (no-op since constructor reduces)
1481
- */
1482
- simplify(): Fraction;
1483
- /**
1484
- * Check if this is zero
1485
- */
1486
- isZero(): boolean;
1487
- /**
1488
- * Check if this is positive
1489
- */
1490
- isPositive(): boolean;
1491
- /**
1492
- * Check if this is negative
1493
- */
1494
- isNegative(): boolean;
1495
- /**
1496
- * Check if this is an integer
1497
- */
1498
- isInteger(): boolean;
1499
- /**
1500
- * Check if this is a unit fraction (1/n)
1501
- */
1502
- isUnit(): boolean;
1503
- /**
1504
- * Floor: largest integer ≤ this
1505
- */
1506
- floor(): Fraction;
1507
- /**
1508
- * Ceiling: smallest integer ≥ this
1509
- */
1510
- ceil(): Fraction;
1511
- /**
1512
- * Round to nearest integer
1513
- */
1514
- round(): Fraction;
1515
- /**
1516
- * Truncate (round toward zero)
1517
- */
1518
- trunc(): Fraction;
1519
- /**
1520
- * Get the sign: -1, 0, or 1
1521
- */
1522
- sign(): number;
1523
- /**
1524
- * Clone this fraction
1525
- */
1526
- clone(): Fraction;
1527
- /**
1528
- * Get the GCD of numerator and denominator (always 1 since we reduce)
1529
- */
1530
- gcd(): bigint;
1531
- /**
1532
- * Get continued fraction representation
1533
- */
1534
- toContinuedFraction(): bigint[];
1535
- /**
1536
- * Create fraction from continued fraction
1537
- */
1538
- static fromContinuedFraction(cf: bigint[]): Fraction;
1539
- /**
1540
- * Mediant of two fractions: (a+c)/(b+d)
1541
- * Used in Stern-Brocot tree and Farey sequences
1542
- */
1543
- mediant(other: Fraction): Fraction;
1544
- }
1545
- /**
1546
- * Common fraction constants
1547
- */
1548
- declare const FRACTION_ZERO: Fraction;
1549
- declare const FRACTION_ONE: Fraction;
1550
- declare const FRACTION_NEG_ONE: Fraction;
1551
- declare const FRACTION_HALF: Fraction;
1552
- declare const FRACTION_THIRD: Fraction;
1553
- declare const FRACTION_QUARTER: Fraction;
1554
-
1555
- /**
1556
- * BigNumber (arbitrary precision decimal) implementation
1557
- * @module @danielsimonjr/mathts-core/types/bignumber
1558
- */
1559
-
1560
- /**
1561
- * Check if a value is a BigNumber
1562
- */
1563
- declare function isBigNumber(value: unknown): value is BigNumber;
1564
- /**
1565
- * Configuration for BigNumber operations
1566
- */
1567
- interface BigNumberConfig {
1568
- /** Number of significant digits (default: 64) */
1569
- precision: number;
1570
- /** Rounding mode (default: 'halfUp') */
1571
- rounding: RoundingMode;
1572
- /** Minimum exponent (default: -1e9) */
1573
- minExponent: number;
1574
- /** Maximum exponent (default: 1e9) */
1575
- maxExponent: number;
1576
- }
1577
- type RoundingMode = 'up' | 'down' | 'ceil' | 'floor' | 'halfUp' | 'halfDown' | 'halfEven' | 'halfCeil' | 'halfFloor';
1578
- /**
1579
- * BigNumber class for arbitrary precision decimal arithmetic
1580
- *
1581
- * Internally stores: sign * coefficient * 10^exponent
1582
- * where coefficient is a bigint with the significant digits.
1583
- */
1584
- declare class BigNumber implements MathTSValue {
1585
- readonly type = "BigNumber";
1586
- /**
1587
- * Duck-typing marker for Decimal.js / mathjs formatter compatibility.
1588
- * Allows external code that checks `obj.isBigNumber === true` to identify
1589
- * this class without an `instanceof` check.
1590
- */
1591
- readonly isBigNumber = true;
1592
- private readonly _sign;
1593
- private readonly _coefficient;
1594
- private readonly _exponent;
1595
- private readonly _isNaN;
1596
- private readonly _isInfinite;
1597
- private constructor();
1598
- /**
1599
- * Create a BigNumber from a number
1600
- */
1601
- static fromNumber(n: number): BigNumber;
1602
- /**
1603
- * Create a BigNumber from a string
1604
- */
1605
- static parse(str: string): BigNumber;
1606
- /**
1607
- * Create from bigint
1608
- */
1609
- static fromBigInt(n: bigint): BigNumber;
1610
- /**
1611
- * Create a BigNumber from a JSON object
1612
- */
1613
- static fromJSON(json: {
1614
- value: string;
1615
- }): BigNumber;
1616
- /**
1617
- * Get/set global configuration
1618
- */
1619
- static config(newConfig?: Partial<BigNumberConfig>): BigNumberConfig;
1620
- /**
1621
- * Reset configuration to defaults
1622
- */
1623
- static resetConfig(): void;
1624
- /**
1625
- * Compare two BigNumbers
1626
- * @returns -1, 0, or 1
1627
- */
1628
- static compare(a: BigNumber, b: BigNumber): number;
1629
- private static compareMagnitude;
1630
- valueOf(): number;
1631
- /**
1632
- * Convert to a JS number.
1633
- * Alias for `valueOf()` — provided for Decimal.js / mathjs formatter
1634
- * duck-typing compatibility.
1635
- */
1636
- toNumber(): number;
1637
- toString(): string;
1638
- toJSON(): {
1639
- mathjs: string;
1640
- value: string;
1641
- };
1642
- /**
1643
- * Convert to fixed-point notation.
1644
- *
1645
- * When called with no argument (or `undefined`) returns the full fixed-point
1646
- * string representation without rounding — matching Decimal.js semantics where
1647
- * `toFixed()` is equivalent to a lossless fixed-point stringify.
1648
- * When called with a non-negative integer `decimalPlaces`, rounds and formats
1649
- * to exactly that many digits after the decimal point.
1650
- */
1651
- toFixed(decimalPlaces?: number): string;
1652
- private toFixedInternal;
1653
- /**
1654
- * Convert to exponential notation
1655
- */
1656
- toExponential(decimalPlaces?: number): string;
1657
- /**
1658
- * Convert to precision
1659
- */
1660
- toPrecision(significantDigits?: number): string;
1661
- /**
1662
- * Convert to bigint (truncated)
1663
- */
1664
- toBigInt(): bigint;
1665
- /**
1666
- * Binary string representation, e.g. `255 -> '0b11111111'`, `0.5 -> '0b0.1'`.
1667
- * Mirrors Decimal.js `toBinary()`. Negatives carry a leading `-`.
1668
- */
1669
- toBinary(): string;
1670
- /**
1671
- * Octal string representation, e.g. `8 -> '0o10'`.
1672
- * Mirrors Decimal.js `toOctal()`.
1673
- */
1674
- toOctal(): string;
1675
- /**
1676
- * Hexadecimal string representation, e.g. `255 -> '0xff'`, `10.5 -> '0xa.8'`.
1677
- * Mirrors Decimal.js `toHexadecimal()`.
1678
- */
1679
- toHexadecimal(): string;
1680
- /**
1681
- * Shared radix formatter for {@link toBinary}/{@link toOctal}/{@link toHexadecimal}.
1682
- * Integers and terminating fractions are exact; a non-terminating fraction is
1683
- * truncated at `maxFractionDigits` radix digits (a safety bound — the common
1684
- * use is integer formatting).
1685
- */
1686
- private toRadixString;
1687
- /**
1688
- * Addition
1689
- */
1690
- add(other: Scalar | BigNumber | number | string): BigNumber;
1691
- /**
1692
- * Subtraction
1693
- */
1694
- subtract(other: Scalar | BigNumber | number | string): BigNumber;
1695
- /**
1696
- * Alias for subtract — mathjs / Decimal.js compatibility.
1697
- */
1698
- sub(other: Scalar | BigNumber | number | string): BigNumber;
1699
- /**
1700
- * Multiplication
1701
- */
1702
- multiply(other: Scalar | BigNumber | number | string): BigNumber;
1703
- /**
1704
- * Alias for multiply — mathjs / Decimal.js compatibility.
1705
- */
1706
- mul(other: Scalar | BigNumber | number | string): BigNumber;
1707
- /**
1708
- * Alias for multiply — Decimal.js calling convention (used by the Unit).
1709
- */
1710
- times(other: Scalar | BigNumber | number | string): BigNumber;
1711
- /**
1712
- * Division
1713
- */
1714
- divide(other: Scalar | BigNumber | number | string): BigNumber;
1715
- /**
1716
- * Alias for divide — Decimal.js calling convention (used by the Unit).
1717
- */
1718
- div(other: Scalar | BigNumber | number | string): BigNumber;
1719
- /**
1720
- * Negation
1721
- */
1722
- negate(): BigNumber;
1723
- /**
1724
- * Absolute value
1725
- */
1726
- abs(): BigNumber;
1727
- /**
1728
- * Power (integer exponent)
1729
- */
1730
- pow(n: number | bigint): BigNumber;
1731
- /**
1732
- * Square root
1733
- */
1734
- sqrt(): BigNumber;
1735
- equals(other: BigNumber | number | string): boolean;
1736
- lessThan(other: BigNumber | number | string): boolean;
1737
- lessThanOrEqual(other: BigNumber | number | string): boolean;
1738
- greaterThan(other: BigNumber | number | string): boolean;
1739
- greaterThanOrEqual(other: BigNumber | number | string): boolean;
1740
- compareTo(other: BigNumber | number | string): number;
1741
- compare(other: BigNumber | number | string): number;
1742
- /**
1743
- * Returns true iff this > other.
1744
- * Accepts the same argument types as `add`/`multiply` (BigNumber, number, or string).
1745
- * Named `gt` for Decimal.js / mathjs formatter compatibility.
1746
- */
1747
- gt(other: BigNumber | number | string): boolean;
1748
- /**
1749
- * Round to specified decimal places
1750
- */
1751
- round(decimalPlaces?: number, mode?: RoundingMode): BigNumber;
1752
- private shouldRound;
1753
- /**
1754
- * Round to specified precision (significant digits)
1755
- */
1756
- roundToPrecision(precision: number, mode?: RoundingMode): BigNumber;
1757
- floor(): BigNumber;
1758
- ceil(): BigNumber;
1759
- trunc(): BigNumber;
1760
- /**
1761
- * Round to `n` significant decimal digits and return a new BigNumber.
1762
- * Delegates to `roundToPrecision`, using the global rounding mode unless
1763
- * an explicit `roundingMode` is supplied.
1764
- *
1765
- * Named `toSignificantDigits` for Decimal.js / mathjs formatter compatibility.
1766
- * When `n` is undefined the value is returned unchanged (no rounding).
1767
- */
1768
- toSignificantDigits(n?: number, roundingMode?: RoundingMode): BigNumber;
1769
- /**
1770
- * The decimal exponent of this number: `floor(log10(|x|))`.
1771
- *
1772
- * Matches Decimal.js semantics:
1773
- * - `12345` → `4` (5 digits → the most-significant place is 10^4)
1774
- * - `0.0123` → `-2` (first significant digit is at 10^-2)
1775
- * - `100` → `2`
1776
- * - `0.01` → `-2`
1777
- * - `0` → `0` (by convention; `isZero()` can be used to distinguish)
1778
- *
1779
- * For special values (NaN, ±Infinity) returns 0 — callers check
1780
- * `isFinite()` / `isNaN()` before using `.e`.
1781
- */
1782
- get e(): number;
1783
- /**
1784
- * Modulo (remainder after division)
1785
- * Result has the same sign as the dividend (this).
1786
- */
1787
- mod(other: Scalar | BigNumber | number | string): BigNumber;
1788
- /**
1789
- * Sine of this BigNumber (in radians)
1790
- * Uses Taylor series: sin(x) = x - x^3/3! + x^5/5! - ...
1791
- */
1792
- sin(): BigNumber;
1793
- /**
1794
- * Cosine of this BigNumber (in radians)
1795
- * Uses Taylor series: cos(x) = 1 - x^2/2! + x^4/4! - ...
1796
- */
1797
- cos(): BigNumber;
1798
- /**
1799
- * Tangent of this BigNumber (in radians)
1800
- * tan(x) = sin(x) / cos(x)
1801
- */
1802
- tan(): BigNumber;
1803
- /**
1804
- * Arcsine of this BigNumber
1805
- * Returns value in [-PI/2, PI/2]
1806
- */
1807
- asin(): BigNumber;
1808
- /**
1809
- * Arccosine of this BigNumber
1810
- * Returns value in [0, PI]
1811
- */
1812
- acos(): BigNumber;
1813
- /**
1814
- * Arctangent of this BigNumber
1815
- * Returns value in (-PI/2, PI/2)
1816
- * Uses Taylor series with argument reduction for convergence.
1817
- */
1818
- atan(): BigNumber;
1819
- /**
1820
- * Two-argument arctangent: atan2(y, x)
1821
- * this = y, argument = x
1822
- * Returns angle in (-PI, PI]
1823
- */
1824
- atan2(x: BigNumber): BigNumber;
1825
- /**
1826
- * Hyperbolic sine: sinh(x) = (e^x - e^(-x)) / 2
1827
- */
1828
- sinh(): BigNumber;
1829
- /**
1830
- * Hyperbolic cosine: cosh(x) = (e^x + e^(-x)) / 2
1831
- */
1832
- cosh(): BigNumber;
1833
- /**
1834
- * Hyperbolic tangent: tanh(x) = sinh(x) / cosh(x)
1835
- */
1836
- tanh(): BigNumber;
1837
- /**
1838
- * Inverse hyperbolic sine: asinh(x) = ln(x + sqrt(x^2 + 1))
1839
- */
1840
- asinh(): BigNumber;
1841
- /**
1842
- * Inverse hyperbolic cosine: acosh(x) = ln(x + sqrt(x^2 - 1))
1843
- * Domain: x >= 1
1844
- */
1845
- acosh(): BigNumber;
1846
- /**
1847
- * Inverse hyperbolic tangent: atanh(x) = 0.5 * ln((1+x)/(1-x))
1848
- * Domain: -1 < x < 1
1849
- */
1850
- atanh(): BigNumber;
1851
- /**
1852
- * Exponential function: e^x
1853
- * Uses Taylor series: e^x = 1 + x + x^2/2! + x^3/3! + ...
1854
- * With argument reduction: e^x = (e^(x/2^k))^(2^k) for faster convergence.
1855
- */
1856
- exp(): BigNumber;
1857
- /**
1858
- * Natural logarithm: ln(x)
1859
- * Uses the AGM (arithmetic-geometric mean) method for fast convergence.
1860
- * Fallback: series ln((1+y)/(1-y)) = 2*(y + y^3/3 + y^5/5 + ...) where y = (x-1)/(x+1)
1861
- */
1862
- ln(): BigNumber;
1863
- /**
1864
- * Base-10 logarithm: log10(x) = ln(x) / ln(10)
1865
- */
1866
- log10(): BigNumber;
1867
- /**
1868
- * Base-2 logarithm: log2(x) = ln(x) / ln(2)
1869
- */
1870
- log2(): BigNumber;
1871
- /**
1872
- * Cube root
1873
- * Uses Newton-Raphson iteration.
1874
- */
1875
- cbrt(): BigNumber;
1876
- /**
1877
- * e^x - 1 (more precise than exp(x) - 1 for small x)
1878
- * Uses Taylor series directly: expm1(x) = x + x^2/2! + x^3/3! + ...
1879
- */
1880
- expm1(): BigNumber;
1881
- /**
1882
- * ln(1 + x) (more precise than ln(1 + x) for small x)
1883
- */
1884
- log1p(): BigNumber;
1885
- /**
1886
- * Hypotenuse: sqrt(this^2 + other^2)
1887
- */
1888
- hypot(other: BigNumber): BigNumber;
1889
- /** Reduce angle to [-PI, PI] range */
1890
- private _reduceAngle;
1891
- /** Taylor series for sin(x), assumes x is in [-PI, PI] */
1892
- private _sinTaylor;
1893
- /** Taylor series for cos(x), assumes x is in [-PI, PI] */
1894
- private _cosTaylor;
1895
- /** Taylor series for atan(x), assumes |x| <= 0.5 */
1896
- private _atanTaylor;
1897
- isNaN(): boolean;
1898
- isFinite(): boolean;
1899
- isInfinite(): boolean;
1900
- isZero(): boolean;
1901
- isPositive(): boolean;
1902
- isNegative(): boolean;
1903
- isInteger(): boolean;
1904
- sign(): number;
1905
- clone(): BigNumber;
1906
- private ensureBigNumber;
1907
- private alignExponents;
1908
- private normalize;
1909
- }
1910
- /**
1911
- * Common BigNumber constants
1912
- */
1913
- declare const BIGNUMBER_ZERO: BigNumber;
1914
- declare const BIGNUMBER_ONE: BigNumber;
1915
- declare const BIGNUMBER_NEG_ONE: BigNumber;
1916
- declare const BIGNUMBER_TEN: BigNumber;
1917
- declare const BIGNUMBER_PI: BigNumber;
1918
- declare const BIGNUMBER_E: BigNumber;
1919
- declare const BIGNUMBER_LN2: BigNumber;
1920
- declare const BIGNUMBER_LN10: BigNumber;
1921
-
1922
- /** Any scalar core can do arithmetic on. */
1923
- type NumericScalar = number | bigint | Complex | Fraction | BigNumber;
1924
- /** Add two scalar values, `x + y`. */
1925
- declare function addScalar(x: NumericScalar, y: NumericScalar): NumericScalar;
1926
- /** Subtract two scalar values, `x − y` (order preserved through promotion). */
1927
- declare function subtractScalar(x: NumericScalar, y: NumericScalar): NumericScalar;
1928
- /** Multiply two scalar values, `x · y`. */
1929
- declare function multiplyScalar(x: NumericScalar, y: NumericScalar): NumericScalar;
1930
- /** Divide two scalar values, `x ÷ y` (order preserved through promotion). */
1931
- declare function divideScalar(x: NumericScalar, y: NumericScalar): NumericScalar;
1932
- /**
1933
- * Raise `base` to the power `exp`, treating `exp` as a real exponent.
1934
- *
1935
- * The exact `.pow()` of an exact type (Fraction/BigNumber) only supports INTEGER
1936
- * exponents. A non-integer exponent of an exact base is generally irrational, so
1937
- * it cannot stay exact — those cases fall back to double-precision `Math.pow`,
1938
- * returning a plain `number`. (Without this guard, `BigNumber.pow(0.5)` silently
1939
- * returned 1 and `Fraction.pow(0.5)` threw `BigInt(0.5)`.)
1940
- */
1941
- declare function pow(base: NumericScalar, exp: NumericScalar): NumericScalar;
1942
- /** Absolute value. `abs(Complex)` returns the magnitude (a real number). */
1943
- declare function abs(x: NumericScalar): NumericScalar;
1944
- /** Round toward zero (truncate). Complex components are truncated independently. */
1945
- declare function fix(x: NumericScalar): NumericScalar;
1946
- /**
1947
- * Round to the nearest integer, half toward +∞ — matching `Math.round` and
1948
- * `Fraction.round`. `BigNumber.round` defaults to half-away-from-zero, so it is
1949
- * given `'halfCeil'` explicitly; otherwise negative half-integers would round
1950
- * type-dependently (`round(-2.5)` = −2 for number/Fraction but −3 for BigNumber).
1951
- * Complex components are rounded independently.
1952
- */
1953
- declare function round(x: NumericScalar): NumericScalar;
1954
- /**
1955
- * Equality. Floating-point operands compare with the configured tolerance
1956
- * (`relTol`/`absTol`); exact types (Fraction, BigNumber) compare exactly —
1957
- * tolerance is meaningless for an exact rational/decimal.
1958
- */
1959
- declare function equal(x: NumericScalar, y: NumericScalar, relTol?: number, absTol?: number): boolean;
1960
- /**
1961
- * True for values math treats as real-numeric: `number`, `bigint`, `boolean`,
1962
- * `Fraction`, `BigNumber`. Mirrors mathjs semantics — `boolean` counts (it
1963
- * coerces to 0/1), while `Complex` is intentionally NOT numeric (callers test it
1964
- * separately), so `isNumeric(complex)` is `false`. The relocated Unit uses this as
1965
- * its value-type gate (`isNumeric(value) || isComplex(value)`), and mathjs accepts
1966
- * `new Unit(true)` — so booleans must pass.
1967
- */
1968
- declare function isNumeric(x: unknown): boolean;
1969
- /**
1970
- * Convert any scalar to a plain JS `number`. A non-real `Complex` (nonzero
1971
- * imaginary part) has no real-number value and throws.
1972
- */
1973
- declare function number(x: NumericScalar): number;
1974
-
1975
- /**
1976
- * Typed error classes for the Unit. Kept in their own module (with no Unit
1977
- * imports) so both the merged `Unit` (`Unit.ts`) and the `core/src/types/unit.ts`
1978
- * compatibility surface can import them without a circular dependency, and so
1979
- * callers can `catch (e) { if (e instanceof UnitParseError) … }` as before the
1980
- * two Unit implementations merged.
1981
- */
1982
- /** Thrown when a unit notation string cannot be parsed against the registry. */
1983
- declare class UnitParseError extends Error {
1984
- readonly name = "UnitParseError";
1985
- constructor(message: string);
1986
- }
1987
- /** Thrown when an operation requires two units to share a base dimension and they do not. */
1988
- declare class DimensionMismatchError extends Error {
1989
- readonly name = "DimensionMismatchError";
1990
- constructor(message: string);
1991
- }
1992
-
1993
- /**
1994
- * Unit definitions for the Unit type.
1995
- *
1996
- * The seven SI base units, plus common derived and imperial units. Each
1997
- * definition stores its multiplicative factor (to base SI) and dimensional
1998
- * exponents. Temperatures carry an additive offset for the K↔°C↔°F
1999
- * conversions.
2000
- *
2001
- * @module @danielsimonjr/mathts-core/types/unit-definitions
2002
- */
2003
- /**
2004
- * The seven SI base dimensions, expressed as a vector of (possibly fractional)
2005
- * exponents.
2006
- */
2007
- interface Dimensions {
2008
- /** Length, base unit metre */
2009
- length: number;
2010
- /** Mass, base unit kilogram */
2011
- mass: number;
2012
- /** Time, base unit second */
2013
- time: number;
2014
- /** Electric current, base unit ampere */
2015
- current: number;
2016
- /** Thermodynamic temperature, base unit kelvin */
2017
- temperature: number;
2018
- /** Amount of substance, base unit mole */
2019
- amount: number;
2020
- /** Luminous intensity, base unit candela */
2021
- luminosity: number;
2022
- }
2023
- /**
2024
- * The zero-dimensional vector (a dimensionless quantity).
2025
- */
2026
- declare const DIMENSIONLESS: Dimensions;
2027
- /**
2028
- * Construct a Dimensions record from a partial spec.
2029
- *
2030
- * Missing fields default to 0, so `dim({ length: 1 })` returns the dimension
2031
- * vector for length.
2032
- */
2033
- declare function dim(partial: Partial<Dimensions>): Dimensions;
2034
- /**
2035
- * Definition of a single named unit.
2036
- */
2037
- interface UnitDef {
2038
- /** Multiplicative factor: value-in-base = input * multiplier (+ offset). */
2039
- multiplier: number;
2040
- /** Additive offset, used for non-multiplicative units like °C and °F. */
2041
- offset?: number;
2042
- /** Dimensional signature. */
2043
- dimensions: Dimensions;
2044
- /** Whether SI prefixes (k, M, µ, …) may be applied to this notation. */
2045
- prefixable?: boolean;
2046
- }
2047
- /**
2048
- * The seven SI base units.
2049
- */
2050
- declare const BASE_UNITS: Record<string, UnitDef>;
2051
- /**
2052
- * Common derived units (SI named units, imperial units, and convenience units).
2053
- *
2054
- * This is *not* exhaustive — it covers the most common ~40 units needed for
2055
- * dimensional-analysis tests. Add more as needed by downstream callers.
2056
- */
2057
- declare const DERIVED_UNITS: Record<string, UnitDef>;
2058
- /**
2059
- * Combined registry — both base and derived units in one map.
2060
- */
2061
- declare const ALL_UNITS: Record<string, UnitDef>;
2062
- /**
2063
- * Convenience aliases mapping common Unicode/ASCII variants to the canonical
2064
- * notation key. Used by the parser; not part of the registered notation set.
2065
- */
2066
- declare const UNIT_ALIASES: Record<string, string>;
2067
- /**
2068
- * Lookup an exact (non-prefixed) unit definition.
2069
- */
2070
- declare function getUnitDef(name: string): UnitDef | undefined;
2071
-
2072
- /**
2073
- * SI prefixes for the Unit type.
2074
- *
2075
- * Maps single- and double-letter prefixes to their multiplicative factor in
2076
- * base units. The full SI prefix range (from y = 1e-24 to Y = 1e24) is
2077
- * supported, plus the binary prefixes used for digital information units.
2078
- *
2079
- * @module @danielsimonjr/mathts-core/types/unit-prefixes
2080
- */
2081
- /**
2082
- * Standard SI prefixes (mass/length/energy/etc.).
2083
- *
2084
- * Note the ambiguity-resolution priority: longer prefixes (e.g. `da`)
2085
- * must be tried before single-letter ones (`d`, `a`) in parsers.
2086
- */
2087
- declare const SI_PREFIXES: Record<string, number>;
2088
- /**
2089
- * Set of "good" prefixes to use in `toBest()` selection.
2090
- *
2091
- * Excludes `h`, `da`, `d`, `c` (commonly only used for centimeters and similar
2092
- * legacy notations); using these in `toBest()` would produce awkward outputs
2093
- * like "0.4 hg" instead of "40 g".
2094
- */
2095
- declare const BEST_PREFIXES: ReadonlyArray<string>;
2096
- /**
2097
- * Look up an SI prefix multiplier. Returns `undefined` if not a known prefix.
2098
- */
2099
- declare function getPrefix(name: string): number | undefined;
2100
-
2101
- /**
2102
- * MathTS typed-function Integration
2103
- *
2104
- * Creates a configured typed-function instance with MathTS types
2105
- * for runtime type dispatch across numeric types, matrices, and more.
2106
- *
2107
- * This module directly uses the typed-function library API without
2108
- * any intermediate abstraction layers.
2109
- *
2110
- * Supports WASM-accelerated dispatch when available.
2111
- *
2112
- * @packageDocumentation
2113
- */
2114
-
2115
- /**
2116
- * Initialize WASM dispatch for typed-function (optional, improves performance)
2117
- *
2118
- * Uses the unified typed.init() API to enable WASM-accelerated dispatch
2119
- * with automatic fallback to pure JS when WASM is unavailable.
2120
- *
2121
- * @param options - Initialization options
2122
- * @returns Promise resolving to true if WASM was initialized successfully
2123
- */
2124
- declare function initTypedWasm(options?: {
2125
- preferWasm?: boolean;
2126
- }): Promise<boolean>;
2127
- /**
2128
- * Check if WASM dispatch is available
2129
- */
2130
- declare function isTypedWasmAvailable(): boolean;
2131
-
2132
- /**
2133
- * Any concrete implementation accepted when *declaring* a typed signature.
2134
- *
2135
- * typed-function's published `SignatureFunction` is `(...args: unknown[]) =>
2136
- * unknown`, which is correct for *internal/output* positions (where the stored
2137
- * impl is later CALLED with validated args) but wrong as an *input* type:
2138
- * under `strictFunctionTypes`, function parameters are contravariant, so a
2139
- * concrete impl such as `(a: number, b: number) => number` is NOT assignable
2140
- * to an `unknown[]` parameter list (`unknown` is not assignable to `number`).
2141
- * The correct top-type for "any function" in an input position uses `never`
2142
- * parameters — every function is assignable to it because `never` is
2143
- * assignable to every parameter type. This is exactly the set of values
2144
- * typed-function genuinely accepts when declaring signatures.
2145
- */
2146
- type SignatureImpl = (...args: never[]) => unknown;
2147
- /** Signature record accepted by the MathTS typed factory (see {@link SignatureImpl}). */
2148
- type SignatureRecord = Record<string, SignatureImpl | ReferTo | ReferToSelf>;
2149
- /**
2150
- * The MathTS typed-function factory type.
2151
- *
2152
- * Structurally identical to typed-function's {@link TypedInstance} except its
2153
- * call signatures accept implementations declared with concrete parameter
2154
- * types (see {@link SignatureImpl}). All instance methods are inherited
2155
- * unchanged via `Omit<TypedInstance, never>` (a mapped type, which drops the
2156
- * overly-strict published call signatures while preserving every method).
2157
- */
2158
- interface MathTSTyped extends Omit<TypedInstance, never> {
2159
- (name: string, signatures: SignatureRecord): TypedFunction;
2160
- (signatures: SignatureRecord): TypedFunction;
2161
- (...args: Array<string | SignatureRecord | TypedFunction | (SignatureImpl & {
2162
- signature: string;
2163
- })>): TypedFunction;
2164
- referToSelf: (callback: (self: TypedFunction) => SignatureImpl) => ReferToSelf;
2165
- referTo: (...args: [...string[], (...fns: SignatureFunction[]) => SignatureImpl]) => ReferTo;
2166
- }
2167
- /**
2168
- * Type definition for typed-function
2169
- */
2170
- interface TypeDef {
2171
- name: string;
2172
- test: (x: unknown) => boolean;
2173
- }
2174
- /**
2175
- * Conversion definition for typed-function
2176
- */
2177
- interface ConversionDef {
2178
- from: string;
2179
- to: string;
2180
- convert: (value: unknown) => unknown;
2181
- }
2182
- declare const isNumber: (x: unknown) => x is number;
2183
- declare const isBoolean: (x: unknown) => x is boolean;
2184
- declare const isString: (x: unknown) => x is string;
2185
- declare const isBigInt: (x: unknown) => x is bigint;
2186
- declare const isArray: (x: unknown) => x is unknown[];
2187
- declare const isFunction: (x: unknown) => x is (...args: unknown[]) => unknown;
2188
- declare const isObject: (x: unknown) => x is object;
2189
- declare const isNull: (x: unknown) => x is null;
2190
- declare const isUndefined: (x: unknown) => x is undefined;
2191
- /**
2192
- * Check if value is a Matrix (duck typing until Matrix class is implemented)
2193
- */
2194
- declare const isMatrix: (x: unknown) => boolean;
2195
- /**
2196
- * Check if value is a DenseMatrix
2197
- */
2198
- declare const isDenseMatrix: (x: unknown) => boolean;
2199
- /**
2200
- * Check if value is a SparseMatrix
2201
- */
2202
- declare const isSparseMatrix: (x: unknown) => boolean;
2203
- /**
2204
- * Check if value is a Unit
2205
- *
2206
- * Recognises both the native {@link Unit} class (which exposes `value`,
2207
- * `dimensions`, and `notation`) and the legacy duck-typed shape used by
2208
- * mathjs-compatibility shims (`{ value, unit, type }`).
2209
- */
2210
- declare const isUnit: (x: unknown) => boolean;
2211
- /**
2212
- * Extended type definition with optional WASM mask support
2213
- */
2214
- interface MathTSTypeDef extends TypeDef {
2215
- /** Optional WASM type mask for accelerated dispatch (auto-registered when WASM available) */
2216
- wasmMask?: number;
2217
- }
2218
- /**
2219
- * MathTS-specific types to add to typed-function.
2220
- * Note: Most primitive types (number, boolean, string, etc.) are already built into typed-function
2221
- *
2222
- * When WASM is available, custom type masks are automatically registered for efficient dispatch.
2223
- */
2224
- declare const MATHTS_TYPES: MathTSTypeDef[];
2225
- declare const MATHTS_CONVERSIONS: ConversionDef[];
2226
- /**
2227
- * Create a new MathTS typed instance
2228
- *
2229
- * This creates an isolated typed universe with MathTS types and conversions.
2230
- * Uses typed-function's addType() API which automatically registers WASM
2231
- * type masks when available.
2232
- *
2233
- * @returns A new typed-function instance configured for MathTS
2234
- *
2235
- * @example
2236
- * ```typescript
2237
- * const myTyped = createMathTSTyped();
2238
- *
2239
- * const add = myTyped('add', {
2240
- * 'number, number': (a, b) => a + b,
2241
- * 'Complex, Complex': (a, b) => a.add(b),
2242
- * 'Fraction, Fraction': (a, b) => a.add(b),
2243
- * 'BigNumber, BigNumber': (a, b) => a.add(b),
2244
- * });
2245
- * ```
2246
- */
2247
- declare function createMathTSTyped(): TypedInstance;
2248
- /**
2249
- * Default MathTS typed instance
2250
- *
2251
- * This is the primary typed-function instance used throughout MathTS.
2252
- * It comes pre-configured with all MathTS types and conversions.
2253
- *
2254
- * @example
2255
- * ```typescript
2256
- * import { mathTyped, Complex, Fraction, BigNumber } from '@danielsimonjr/mathts-core';
2257
- *
2258
- * // Create a polymorphic add function
2259
- * const add = mathTyped('add', {
2260
- * 'number, number': (a, b) => a + b,
2261
- * 'Complex, Complex': (a, b) => a.add(b),
2262
- * 'Fraction, Fraction': (a, b) => a.add(b),
2263
- * 'BigNumber, BigNumber': (a, b) => a.add(b),
2264
- * });
2265
- *
2266
- * // Works with automatic type coercion
2267
- * add(1, 2); // 3
2268
- * add(new Complex(1, 2), new Complex(3, 4)); // Complex(4, 6)
2269
- * add(new Fraction(1, 2), new Fraction(1, 3)); // Fraction(5, 6)
2270
- * add(1, new Complex(2, 3)); // Complex(3, 3) - auto-converts
2271
- * ```
2272
- */
2273
- declare const mathTyped: MathTSTyped;
2274
-
2275
- /**
2276
- * TypeRegistry class for managing custom type registrations
2277
- * This is a MathTS utility, not from typed-function
2278
- */
2279
- declare class TypeRegistry {
2280
- private types;
2281
- private conversions;
2282
- private instance;
2283
- /**
2284
- * Register a new type
2285
- */
2286
- registerType<T>(name: string, test: (x: unknown) => x is T): this;
2287
- /**
2288
- * Register a type conversion
2289
- */
2290
- registerConversion<From, To>(from: string, to: string, convert: (value: From) => To): this;
2291
- /**
2292
- * Check if a type is registered
2293
- */
2294
- hasType(name: string): boolean;
2295
- /**
2296
- * Check if a conversion is registered
2297
- */
2298
- hasConversion(from: string, to: string): boolean;
2299
- /**
2300
- * Get all registered type names
2301
- */
2302
- getTypeNames(): string[];
2303
- /**
2304
- * Build a typed-function instance from the registry
2305
- */
2306
- build(): TypedInstance;
2307
- /**
2308
- * Clear all registered types and conversions
2309
- */
2310
- clear(): void;
2311
- }
2312
- /**
2313
- * Helper to create a typed function with the MathTS typed instance
2314
- */
2315
- declare function createTypedFunction<T>(name: string, signatures: {
2316
- [signature: string]: (...args: unknown[]) => T;
2317
- }, typedInstance?: TypedInstance): (...args: unknown[]) => T;
2318
-
2319
- declare function registerNativeTypes(): void;
2320
-
2321
- /**
2322
- * MathTS Function Factory
2323
- *
2324
- * Provides a factory pattern for creating MathTS functions with:
2325
- * - Typed function dispatch via typed-function
2326
- * - Dependency injection for inter-function references
2327
- * - Backend selection integration
2328
- * - Lazy loading support
2329
- *
2330
- * @packageDocumentation
2331
- */
2332
-
2333
- /**
2334
- * Configuration for MathTS instance
2335
- */
2336
- interface MathTSConfig {
2337
- /** Numeric precision (for BigNumber) */
2338
- precision: number;
2339
- /** Default matrix type */
2340
- matrix: 'Matrix' | 'Array';
2341
- /** Number type for parsing */
2342
- number: 'number' | 'BigNumber' | 'Fraction';
2343
- /** Enable predictable randomness */
2344
- randomSeed: string | null;
2345
- /** Epsilon for floating point comparison */
2346
- epsilon: number;
2347
- /** Preferred backend for matrix operations */
2348
- preferredBackend: 'auto' | 'js' | 'wasm' | 'gpu';
2349
- /** Minimum elements to use WASM backend */
2350
- wasmThreshold: number;
2351
- /** Minimum elements to use GPU backend */
2352
- gpuThreshold: number;
2353
- /** Enable parallel processing */
2354
- parallelEnabled: boolean;
2355
- /** Minimum elements to parallelize */
2356
- parallelThreshold: number;
2357
- }
2358
- /**
2359
- * Default MathTS configuration
2360
- */
2361
- declare const DEFAULT_CONFIG: MathTSConfig;
2362
- /**
2363
- * Factory function definition
2364
- */
2365
- interface FactoryFunction<T = TypedFunction> {
2366
- /** Name of the function */
2367
- name: string;
2368
- /** Dependencies required by this function */
2369
- dependencies: string[];
2370
- /** Factory that creates the function given dependencies */
2371
- factory: (deps: FactoryDependencies) => T;
2372
- }
2373
- /**
2374
- * Dependencies passed to factory functions
2375
- */
2376
- interface FactoryDependencies {
2377
- /** MathTS configuration */
2378
- config: MathTSConfig;
2379
- /** typed-function instance */
2380
- typed: TypedInstance;
2381
- /** Registered functions (for cross-references) */
2382
- [key: string]: unknown;
2383
- }
2384
- /**
2385
- * Import definition for a factory function
2386
- */
2387
- type FactoryImport = FactoryFunction | (() => Promise<FactoryFunction>);
2388
- /**
2389
- * MathTS function registry
2390
- */
2391
- declare class FunctionRegistry {
2392
- private factories;
2393
- private instances;
2394
- private dependencies;
2395
- private creating;
2396
- constructor(config?: Partial<MathTSConfig>, typed?: TypedInstance);
2397
- /**
2398
- * Register a factory function
2399
- */
2400
- register(factory: FactoryFunction): void;
2401
- /**
2402
- * Register multiple factory functions
2403
- */
2404
- registerAll(factories: FactoryFunction[]): void;
2405
- /**
2406
- * Get or create a function by name
2407
- */
2408
- get(name: string): TypedFunction;
2409
- /**
2410
- * Check if a function is registered
2411
- */
2412
- has(name: string): boolean;
2413
- /**
2414
- * Get all registered function names
2415
- */
2416
- names(): string[];
2417
- /**
2418
- * Update configuration
2419
- */
2420
- updateConfig(config: Partial<MathTSConfig>): void;
2421
- /**
2422
- * Get current configuration
2423
- */
2424
- getConfig(): MathTSConfig;
2425
- }
2426
- /**
2427
- * Create a factory function definition
2428
- *
2429
- * @example
2430
- * ```typescript
2431
- * export const addFactory = createFactory('add', ['typed'], ({ typed }) =>
2432
- * typed('add', {
2433
- * 'number, number': (a, b) => a + b,
2434
- * 'Complex, Complex': (a, b) => ({ re: a.re + b.re, im: a.im + b.im }),
2435
- * })
2436
- * );
2437
- * ```
2438
- */
2439
- declare function createFactory<T = TypedFunction>(name: string, dependencies: string[], factory: (deps: FactoryDependencies) => T): FactoryFunction<T>;
2440
- declare const registry: FunctionRegistry;
2441
- declare const math: {
2442
- /**
2443
- * Get a registered function
2444
- */
2445
- get: (name: string) => TypedFunction;
2446
- /**
2447
- * Register a factory function
2448
- */
2449
- register: (factory: FactoryFunction) => void;
2450
- /**
2451
- * Get configuration
2452
- */
2453
- config: () => MathTSConfig;
2454
- /**
2455
- * Update configuration
2456
- */
2457
- configure: (config: Partial<MathTSConfig>) => void;
2458
- };
2459
-
2460
- /**
2461
- * Numerically stable reduction primitives.
2462
- *
2463
- * Floating-point addition is not associative, so *how* you accumulate decides how much error you
2464
- * carry. These are the algorithms the established numerical stack uses, and the reason it is
2465
- * trusted.
2466
- *
2467
- * Measured on this repo's own reductions before these existed — 1e6 copies of `0.1`, exact answer
2468
- * 100000:
2469
- *
2470
- * | accumulation | relative error |
2471
- * | ------------------------------- | -------------- |
2472
- * | naive `s += x` | **1.3e-11** |
2473
- * | pairwise (this, = NumPy's algo) | **2.9e-16** |
2474
- * | Neumaier compensated (`fsum`) | **0** (exact) |
2475
- *
2476
- * NumPy 2.3.4 reports 2.9e-16 on the same input — we are now at parity. Before this, we were
2477
- * ~46,000× worse than NumPy on a bog-standard `sum`, and `mean`, `std`, `var` and every statistic
2478
- * inherit that error.
2479
- *
2480
- * @packageDocumentation
2481
- */
2482
- /**
2483
- * Sum with **pairwise (cascade) summation** — the algorithm behind `np.sum`.
2484
- *
2485
- * Naive accumulation lets the running total grow large while the addends stay small, so each
2486
- * addition rounds off a little more of the total: error grows as **O(n)·ε**. Pairwise summation
2487
- * adds numbers of *comparable magnitude* by recursively halving the range, so error grows as
2488
- * **O(log n)·ε** — for n = 10⁶ that is the difference between ~1e-11 and ~1e-16.
2489
- *
2490
- * It costs the same number of additions as the naive loop. There is no speed/accuracy trade here;
2491
- * the naive version is simply worse.
2492
- *
2493
- * Not exact: for that, use {@link neumaierSum}. Pairwise is the right default because it is free.
2494
- */
2495
- declare function pairwiseSum(xs: ArrayLike<number>, start?: number, end?: number): number;
2496
- /**
2497
- * Sum with **Neumaier compensation** — correctly rounded for practical purposes, the equivalent
2498
- * of Python's `math.fsum`.
2499
- *
2500
- * Tracks the low-order bits that each addition throws away and folds them back in at the end. It
2501
- * recovers information that pairwise summation cannot: `[1e16, 1, -1e16]` sums to **1** here,
2502
- * while both naive and pairwise (and `np.sum`) give **0**, because the `1` is annihilated the
2503
- * moment it meets `1e16`.
2504
- *
2505
- * ~2-4× slower than {@link pairwiseSum}, so it is opt-in rather than the default. Reach for it
2506
- * when catastrophic cancellation is possible: near-zero results from large terms, long-running
2507
- * accumulators, conservation checks.
2508
- *
2509
- * (Neumaier's variant, not classic Kahan: Kahan loses the compensation when the *addend* is
2510
- * larger than the running sum, which is precisely the `1e16` case.)
2511
- */
2512
- declare function neumaierSum(xs: ArrayLike<number>): number;
2513
- /**
2514
- * Euclidean (2-)norm that does **not** overflow or underflow — BLAS's `dnrm2` scaling.
2515
- *
2516
- * The obvious `sqrt(Σxᵢ²)` squares before it adds, so it dies well inside the representable
2517
- * range: `‖[1e200, 1e200, 1e200, 1e200]‖` overflows to `Infinity` (the true answer, 2e200, is
2518
- * perfectly representable), and `‖[1e-200] × 4‖` **flushes to 0** — a silent wrong answer, which
2519
- * is worse.
2520
- *
2521
- * NumPy has this bug too: `np.linalg.norm([1e200]*4)` returns `inf` with an overflow warning.
2522
- * LAPACK does not, and neither do we.
2523
- *
2524
- * The fix is to carry a running scale: keep the largest magnitude seen out of the sum of squares,
2525
- * so the accumulator only ever holds ratios in [0, 1].
2526
- */
2527
- declare function norm2(xs: ArrayLike<number>): number;
2528
- /**
2529
- * Dot product `Σ aᵢ·bᵢ` with **pairwise (cascade) summation** of the products — the accuracy of
2530
- * {@link pairwiseSum} applied to a dot without materialising the product array.
2531
- *
2532
- * A naive `s += a[i]*b[i]` loop carries the same **O(n)·ε** error as a naive sum; measured against
2533
- * an exact reference on an ill-conditioned dot (large mean × small factor, n = 10⁶) it is ~18×
2534
- * worse than `np.dot`, which sums pairwise. This closes that gap — and, like {@link pairwiseSum},
2535
- * costs the same number of flops as the naive loop.
2536
- *
2537
- * The two ranges are assumed the same length; callers guard that. Reads only `[start, end)`.
2538
- */
2539
- declare function pairwiseDot(a: ArrayLike<number>, b: ArrayLike<number>, start?: number, end?: number): number;
2540
- /**
2541
- * Euclidean distance `‖a − b‖₂` that does **not** overflow or underflow — {@link norm2}'s BLAS
2542
- * `dnrm2` scaling applied to the elementwise difference.
2543
- *
2544
- * `distance` is just a 2-norm, so the obvious `sqrt(Σ(aᵢ−bᵢ)²)` inherits norm's pathology: it
2545
- * squares before it adds, overflowing to `Infinity` and — the dangerous case — **flushing to a
2546
- * silent 0** for small differences well inside the representable range. NumPy's `linalg.norm` has
2547
- * the same bug; scaling on the largest *difference* seen avoids both. The scale tracks the residual
2548
- * `a − b`, not the inputs, so it stays accurate even when `a` and `b` are individually huge.
2549
- *
2550
- * The two ranges are assumed the same length; callers guard that.
2551
- */
2552
- declare function scaledDistance(a: ArrayLike<number>, b: ArrayLike<number>): number;
2553
- /**
2554
- * Sum of squared deviations from the mean, `Σ(xᵢ − x̄)²` — the **corrected two-pass** form, the
2555
- * numerator of a numerically stable variance.
2556
- *
2557
- * Variance is where large means bite: the deviations `xᵢ − x̄` can be O(1) while the values sit on
2558
- * a huge pedestal, so any error in `x̄` rides straight into every deviation. Two things fix it:
2559
- * 1. compute the mean with {@link pairwiseSum}, not a naive running total; and
2560
- * 2. subtract the residual mean-bias term `(Σd)²/n` — `Σd` is zero in exact arithmetic but not in
2561
- * floating point, and that leftover is exactly the systematic error a plain `Σd²` carries.
2562
- *
2563
- * Measured on 1e9-pedestal data: the plain naive two-pass (what shipped) lands ~1e-7 relative error;
2564
- * this lands ~1e-16 — better than `np.var`, which uses the uncorrected two-pass (~1e-13).
2565
- *
2566
- * The deviation vector is never materialised: both pairwise sums walk `xs` in
2567
- * registers, so variance/std no longer pay an extra n-long allocation.
2568
- *
2569
- * Divide the result by `n` (uncorrected), `n − 1` (unbiased/sample), or `n + 1` (biased) for the
2570
- * corresponding variance. Returns 0 for fewer than two elements.
2571
- */
2572
- declare function sumSquaredDeviations(xs: ArrayLike<number>): number;
2573
- /**
2574
- * Cumulative sum with **Neumaier compensation** — each prefix total is written to `out[i]` carrying
2575
- * the low-order bits a naive running sum throws away.
2576
- *
2577
- * A cumulative sum is an inherently sequential prefix scan, so pairwise summation does not apply:
2578
- * you need every intermediate total, not just the final one. `np.cumsum` therefore accumulates
2579
- * naively and its tail drifts by **O(n)·ε** (relErr ~1.3e-11 over 10⁶ terms). Carrying a running
2580
- * compensation costs a few extra flops per element, no extra memory, and makes every prefix exact
2581
- * for practical purposes — a strict improvement over NumPy where accumulated drift matters (e.g.
2582
- * integrating a signal).
2583
- *
2584
- * Writes `out[i]` for `i` in `[0, xs.length)`; `out` may be a `number[]` or a `Float64Array`.
2585
- */
2586
- declare function neumaierCumsum(xs: ArrayLike<number>, out: {
2587
- [index: number]: number;
2588
- }): void;
2589
-
2590
1
  /**
2591
2
  * @danielsimonjr/mathts-core - Core types and utilities for MathTS
2592
3
  * @packageDocumentation
2593
4
  */
2594
-
2595
- declare const VERSION: string;
2596
-
2597
- export { ALL_UNITS, BASE_UNITS, BEST_PREFIXES, BIGNUMBER_E, BIGNUMBER_LN10, BIGNUMBER_LN2, BIGNUMBER_NEG_ONE, BIGNUMBER_ONE, BIGNUMBER_PI, BIGNUMBER_TEN, BIGNUMBER_ZERO, type BackendType, BigNumber, type BigNumberConfig, COMPLEX_NEG_ONE, COMPLEX_ONE, COMPLEX_ZERO, Complex, type ConversionDef, DEFAULT_CONFIG, DERIVED_UNITS, DIMENSIONLESS, DUAL_UNARY_RULES, DimensionMismatchError, type Dimensions, Dual, type DualUnaryRule, type DualUnaryRuleName, E, FRACTION_HALF, FRACTION_NEG_ONE, FRACTION_ONE, FRACTION_QUARTER, FRACTION_THIRD, FRACTION_ZERO, type FactoryDependencies, type FactoryFunction, type FactoryImport, Fraction, FunctionRegistry, I, type IBigNumber, type IComplex, type IFraction, type IMatrix, LN10, LN2, LOG10E, LOG2E, MATHTS_CONVERSIONS, MATHTS_TYPES, type MathTSConfig, type MathTSValue, type MatrixBackend, type MatrixDimensions, type NumericScalar, type NumericType, PHI, PI, Range, type RangeForEachCallback, type RangeFormatOptions, type RangeJSON, type RangeMapCallback, type RoundingMode, SI_PREFIXES, SQRT1_2, SQRT2, type Scalar, TAU, type TypeDef, TypeRegistry, UNIT_ALIASES, type UnitDef, UnitParseError, VERSION, abs, addScalar, createFactory, createMathTSTyped, createRangeClass, createTypedFunction, dim, divideScalar, equal, fix, getPrefix, getUnitDef, initTypedWasm, isArray, isBigInt, isBigNumber, isBoolean, isComplex, isDenseMatrix, isDual, isFraction, isFunction, isMatrix, isNull, isNumber, isNumeric, isObject, isSparseMatrix, isString, isTypedWasmAvailable, isUndefined, isUnit, math, mathTyped, multiplyScalar, neumaierCumsum, neumaierSum, norm2, number, pairwiseDot, pairwiseSum, pow, registerNativeTypes, registry, round, scaledDistance, subtractScalar, sumSquaredDeviations };
5
+ export type { MathTSValue, Scalar, BackendType, NumericType, MatrixBackend, IMatrix, IComplex, IFraction, IBigNumber, MatrixDimensions, } from './types/interfaces.js';
6
+ export { Complex, isComplex, I, COMPLEX_ZERO, COMPLEX_ONE, COMPLEX_NEG_ONE, } from './types/complex.js';
7
+ export { createRangeClass, Range } from './types/matrix/Range.js';
8
+ export type { RangeForEachCallback, RangeMapCallback, RangeFormatOptions, RangeJSON, } from './types/matrix/Range.js';
9
+ export { Dual, isDual } from './types/dual.js';
10
+ export { DUAL_UNARY_RULES } from './types/dual-rules.js';
11
+ export type { DualUnaryRule, DualUnaryRuleName } from './types/dual-rules.js';
12
+ export { PI, E, TAU, PHI, SQRT2, SQRT1_2, LN2, LN10, LOG2E, LOG10E } from './constants.js';
13
+ export { Fraction, isFraction, FRACTION_ZERO, FRACTION_ONE, FRACTION_NEG_ONE, FRACTION_HALF, FRACTION_THIRD, FRACTION_QUARTER, } from './types/fraction.js';
14
+ export { BigNumber, isBigNumber, BIGNUMBER_ZERO, BIGNUMBER_ONE, BIGNUMBER_NEG_ONE, BIGNUMBER_TEN, BIGNUMBER_PI, BIGNUMBER_E, BIGNUMBER_LN2, BIGNUMBER_LN10, } from './types/bignumber.js';
15
+ export type { BigNumberConfig, RoundingMode } from './types/bignumber.js';
16
+ export { addScalar, subtractScalar, multiplyScalar, divideScalar, pow, abs, fix, round, equal, isNumeric, number, } from './arithmetic/scalar.js';
17
+ export type { NumericScalar } from './arithmetic/scalar.js';
18
+ export { Unit, isUnit as isUnitValue, DimensionMismatchError, UnitParseError, DIMENSIONLESS, dim, } from './types/unit.js';
19
+ export type { Dimensions, UnitDef, UnitInstance } from './types/unit.js';
20
+ export { BASE_UNITS, DERIVED_UNITS, ALL_UNITS, UNIT_ALIASES, getUnitDef, } from './types/unit-definitions.js';
21
+ export { SI_PREFIXES, BEST_PREFIXES, getPrefix } from './types/unit-prefixes.js';
22
+ export { mathTyped, createMathTSTyped, typed, create, createTypedFunction, TypeRegistry, MATHTS_TYPES, MATHTS_CONVERSIONS, isNumber, isBoolean, isString, isBigInt, isArray, isFunction, isObject, isNull, isUndefined, isMatrix, isDenseMatrix, isSparseMatrix, isUnit, initTypedWasm, isTypedWasmAvailable, registerNativeTypes, } from './typed/index.js';
23
+ export type { TypedFunction, TypedInstance, TypeDef, ConversionDef, SignatureFunction, ReferTo, ReferToSelf, } from './typed/index.js';
24
+ export { FunctionRegistry, createFactory, registry, math, DEFAULT_CONFIG, } from './factory/index.js';
25
+ export type { MathTSConfig, FactoryFunction, FactoryDependencies, FactoryImport, } from './factory/index.js';
26
+ export declare const VERSION: string;
27
+ export { pairwiseSum, neumaierSum, norm2, pairwiseDot, scaledDistance, neumaierCumsum, sumSquaredDeviations, } from './numeric/stable.js';
28
+ //# sourceMappingURL=index.d.ts.map