@danielsimonjr/mathts-core 0.14.1 → 0.15.0

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