@danielsimonjr/mathts-core 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1236 @@
1
+ import { TypedInstance, TypedFunction } from 'typed-function';
2
+ export { ReferTo, ReferToSelf, SignatureFunction, TypedFunction, TypedInstance, create, default as typed } from 'typed-function';
3
+
4
+ /**
5
+ * Base interfaces for MathTS types
6
+ * @module @danielsimonjr/mathts-core/types/interfaces
7
+ */
8
+ /**
9
+ * Base interface for all MathTS numeric types
10
+ */
11
+ interface MathTSValue {
12
+ readonly type: string;
13
+ valueOf(): number | bigint;
14
+ toString(): string;
15
+ toJSON(): unknown;
16
+ }
17
+ /**
18
+ * Scalar types that support arithmetic
19
+ */
20
+ interface Scalar extends MathTSValue {
21
+ add(other: Scalar): Scalar;
22
+ subtract(other: Scalar): Scalar;
23
+ multiply(other: Scalar): Scalar;
24
+ divide(other: Scalar): Scalar;
25
+ negate(): Scalar;
26
+ abs(): Scalar | number;
27
+ }
28
+ /**
29
+ * Available computation backends
30
+ */
31
+ type BackendType = 'js' | 'wasm' | 'gpu';
32
+ /**
33
+ * Supported numeric types
34
+ */
35
+ type NumericType = 'float32' | 'float64' | 'int32' | 'int64' | 'complex64' | 'complex128';
36
+ /**
37
+ * Matrix backend interface
38
+ */
39
+ interface MatrixBackend {
40
+ readonly name: BackendType;
41
+ readonly isAvailable: boolean;
42
+ matmul(a: Float64Array, b: Float64Array, m: number, n: number, k: number): Float64Array;
43
+ transpose(data: Float64Array, rows: number, cols: number): Float64Array;
44
+ add(a: Float64Array, b: Float64Array): Float64Array;
45
+ subtract(a: Float64Array, b: Float64Array): Float64Array;
46
+ scale(data: Float64Array, scalar: number): Float64Array;
47
+ lu(data: Float64Array, n: number): {
48
+ L: Float64Array;
49
+ U: Float64Array;
50
+ P: Int32Array;
51
+ };
52
+ qr(data: Float64Array, m: number, n: number): {
53
+ Q: Float64Array;
54
+ R: Float64Array;
55
+ };
56
+ svd(data: Float64Array, m: number, n: number): {
57
+ U: Float64Array;
58
+ S: Float64Array;
59
+ V: Float64Array;
60
+ };
61
+ eig(data: Float64Array, n: number): {
62
+ values: Float64Array;
63
+ vectors: Float64Array;
64
+ };
65
+ }
66
+ /**
67
+ * Matrix interface with backend abstraction
68
+ */
69
+ interface IMatrix<T = number> extends MathTSValue {
70
+ readonly rows: number;
71
+ readonly cols: number;
72
+ readonly size: readonly [number, number];
73
+ readonly length: number;
74
+ readonly backend: MatrixBackend;
75
+ get(row: number, col: number): T;
76
+ set(row: number, col: number, value: T): void;
77
+ row(index: number): IMatrix<T>;
78
+ column(index: number): IMatrix<T>;
79
+ slice(rowStart: number, rowEnd: number, colStart: number, colEnd: number): IMatrix<T>;
80
+ transpose(): IMatrix<T>;
81
+ reshape(rows: number, cols: number): IMatrix<T>;
82
+ flatten(): T[];
83
+ add(other: IMatrix<T> | T): IMatrix<T>;
84
+ subtract(other: IMatrix<T> | T): IMatrix<T>;
85
+ multiply(other: IMatrix<T> | T): IMatrix<T>;
86
+ toArray(): T[][];
87
+ toBuffer(): ArrayBuffer;
88
+ clone(): IMatrix<T>;
89
+ }
90
+ /**
91
+ * Complex number interface
92
+ */
93
+ interface IComplex extends Scalar {
94
+ readonly re: number;
95
+ readonly im: number;
96
+ conjugate(): IComplex;
97
+ arg(): number;
98
+ sqrt(): IComplex;
99
+ exp(): IComplex;
100
+ log(): IComplex;
101
+ }
102
+ /**
103
+ * Fraction interface for exact rational arithmetic
104
+ */
105
+ interface IFraction extends Scalar {
106
+ readonly numerator: bigint;
107
+ readonly denominator: bigint;
108
+ simplify(): IFraction;
109
+ toNumber(): number;
110
+ }
111
+ /**
112
+ * BigNumber interface for arbitrary precision decimals
113
+ */
114
+ interface IBigNumber extends MathTSValue {
115
+ add(other: IBigNumber | number | string): IBigNumber;
116
+ subtract(other: IBigNumber | number | string): IBigNumber;
117
+ multiply(other: IBigNumber | number | string): IBigNumber;
118
+ divide(other: IBigNumber | number | string): IBigNumber;
119
+ negate(): IBigNumber;
120
+ abs(): IBigNumber;
121
+ pow(n: number | bigint): IBigNumber;
122
+ sqrt(): IBigNumber;
123
+ isNaN(): boolean;
124
+ isFinite(): boolean;
125
+ isInfinite(): boolean;
126
+ isZero(): boolean;
127
+ isPositive(): boolean;
128
+ isNegative(): boolean;
129
+ isInteger(): boolean;
130
+ equals(other: IBigNumber): boolean;
131
+ lessThan(other: IBigNumber): boolean;
132
+ greaterThan(other: IBigNumber): boolean;
133
+ compareTo(other: IBigNumber): number;
134
+ toFixed(decimalPlaces?: number): string;
135
+ toExponential(decimalPlaces?: number): string;
136
+ toPrecision(significantDigits?: number): string;
137
+ toBigInt(): bigint;
138
+ }
139
+ /**
140
+ * Matrix dimensions
141
+ */
142
+ interface MatrixDimensions {
143
+ rows: number;
144
+ cols: number;
145
+ }
146
+
147
+ /**
148
+ * Complex number implementation
149
+ * @module @danielsimonjr/mathts-core/types/complex
150
+ */
151
+
152
+ /**
153
+ * Check if a value is a Complex number
154
+ */
155
+ declare function isComplex(value: unknown): value is Complex;
156
+ /**
157
+ * Complex number class with full arithmetic support
158
+ * Implements the IComplex interface for type-safe complex number operations.
159
+ */
160
+ declare class Complex implements IComplex {
161
+ readonly type = "Complex";
162
+ readonly re: number;
163
+ readonly im: number;
164
+ constructor(re: number, im?: number);
165
+ /**
166
+ * Create a Complex from polar form (r, θ)
167
+ * @param r - magnitude (radius)
168
+ * @param theta - angle in radians
169
+ */
170
+ static fromPolar(r: number, theta: number): Complex;
171
+ /**
172
+ * Create a Complex from a real number
173
+ */
174
+ static fromNumber(n: number): Complex;
175
+ /**
176
+ * Create a Complex from a JSON object
177
+ */
178
+ static fromJSON(json: {
179
+ re: number;
180
+ im: number;
181
+ }): Complex;
182
+ /**
183
+ * Parse a complex number from a string
184
+ * Supports formats: "3+4i", "3-4i", "3", "4i", "-4i", "i", "-i"
185
+ */
186
+ static parse(str: string): Complex;
187
+ /**
188
+ * Compare two complex numbers lexicographically (re first, then im)
189
+ * @returns -1, 0, or 1
190
+ */
191
+ static compare(a: Complex, b: Complex): number;
192
+ valueOf(): number;
193
+ toString(): string;
194
+ toJSON(): {
195
+ mathjs: string;
196
+ re: number;
197
+ im: number;
198
+ };
199
+ /**
200
+ * Return polar representation
201
+ */
202
+ toPolar(): {
203
+ r: number;
204
+ phi: number;
205
+ };
206
+ /**
207
+ * Format with options (precision, notation, etc.)
208
+ */
209
+ format(options?: {
210
+ precision?: number;
211
+ notation?: 'fixed' | 'exponential' | 'auto';
212
+ }): string;
213
+ /**
214
+ * Complex conjugate (a + bi → a - bi)
215
+ */
216
+ conjugate(): Complex;
217
+ /**
218
+ * Magnitude (absolute value) |z| = √(re² + im²)
219
+ */
220
+ abs(): number;
221
+ /**
222
+ * Phase angle (argument) in radians, range (-π, π]
223
+ */
224
+ arg(): number;
225
+ /**
226
+ * Squared magnitude |z|² = re² + im²
227
+ * More efficient than abs() when you don't need the square root
228
+ */
229
+ abs2(): number;
230
+ /**
231
+ * Addition: (a + bi) + (c + di) = (a + c) + (b + d)i
232
+ */
233
+ add(other: Scalar): Complex;
234
+ /**
235
+ * Subtraction: (a + bi) - (c + di) = (a - c) + (b - d)i
236
+ */
237
+ subtract(other: Scalar): Complex;
238
+ /**
239
+ * Multiplication: (a + bi)(c + di) = (ac - bd) + (ad + bc)i
240
+ */
241
+ multiply(other: Scalar): Complex;
242
+ /**
243
+ * Division: (a + bi)/(c + di) = ((ac + bd) + (bc - ad)i) / (c² + d²)
244
+ */
245
+ divide(other: Scalar): Complex;
246
+ /**
247
+ * Negation: -(a + bi) = -a - bi
248
+ */
249
+ negate(): Complex;
250
+ /**
251
+ * Multiplicative inverse: 1/z = z̄/|z|²
252
+ */
253
+ inverse(): Complex;
254
+ /**
255
+ * Square root using principal branch
256
+ * √z = √r · e^(iθ/2) where r = |z|, θ = arg(z)
257
+ */
258
+ sqrt(): Complex;
259
+ /**
260
+ * n-th root (returns principal root)
261
+ */
262
+ nthRoot(n: number): Complex;
263
+ /**
264
+ * All n-th roots
265
+ */
266
+ nthRoots(n: number): Complex[];
267
+ /**
268
+ * Exponential: e^(a+bi) = e^a · (cos(b) + i·sin(b))
269
+ */
270
+ exp(): Complex;
271
+ /**
272
+ * Natural logarithm: ln(z) = ln|z| + i·arg(z)
273
+ */
274
+ log(): Complex;
275
+ /**
276
+ * Logarithm base 10
277
+ */
278
+ log10(): Complex;
279
+ /**
280
+ * Logarithm base 2
281
+ */
282
+ log2(): Complex;
283
+ /**
284
+ * Power: z^w = e^(w·ln(z))
285
+ */
286
+ pow(n: number | Complex): Complex;
287
+ /**
288
+ * Sine: sin(a + bi) = sin(a)cosh(b) + i·cos(a)sinh(b)
289
+ */
290
+ sin(): Complex;
291
+ /**
292
+ * Cosine: cos(a + bi) = cos(a)cosh(b) - i·sin(a)sinh(b)
293
+ */
294
+ cos(): Complex;
295
+ /**
296
+ * Tangent: tan(z) = sin(z) / cos(z)
297
+ */
298
+ tan(): Complex;
299
+ /**
300
+ * Cotangent: cot(z) = cos(z) / sin(z)
301
+ */
302
+ cot(): Complex;
303
+ /**
304
+ * Secant: sec(z) = 1 / cos(z)
305
+ */
306
+ sec(): Complex;
307
+ /**
308
+ * Cosecant: csc(z) = 1 / sin(z)
309
+ */
310
+ csc(): Complex;
311
+ /**
312
+ * Hyperbolic sine: sinh(z) = (e^z - e^(-z)) / 2
313
+ */
314
+ sinh(): Complex;
315
+ /**
316
+ * Hyperbolic cosine: cosh(z) = (e^z + e^(-z)) / 2
317
+ */
318
+ cosh(): Complex;
319
+ /**
320
+ * Hyperbolic tangent: tanh(z) = sinh(z) / cosh(z)
321
+ */
322
+ tanh(): Complex;
323
+ /**
324
+ * Hyperbolic cotangent: coth(z) = cosh(z) / sinh(z)
325
+ */
326
+ coth(): Complex;
327
+ /**
328
+ * Hyperbolic secant: sech(z) = 1 / cosh(z)
329
+ */
330
+ sech(): Complex;
331
+ /**
332
+ * Hyperbolic cosecant: csch(z) = 1 / sinh(z)
333
+ */
334
+ csch(): Complex;
335
+ /**
336
+ * Arc sine: asin(z) = -i·ln(iz + √(1 - z²))
337
+ */
338
+ asin(): Complex;
339
+ /**
340
+ * Arc cosine: acos(z) = π/2 - asin(z)
341
+ */
342
+ acos(): Complex;
343
+ /**
344
+ * Arc tangent: atan(z) = (i/2)·ln((i + z)/(i - z))
345
+ */
346
+ atan(): Complex;
347
+ /**
348
+ * Inverse hyperbolic sine: asinh(z) = ln(z + √(z² + 1))
349
+ */
350
+ asinh(): Complex;
351
+ /**
352
+ * Inverse hyperbolic cosine: acosh(z) = ln(z + √(z² - 1))
353
+ */
354
+ acosh(): Complex;
355
+ /**
356
+ * Inverse hyperbolic tangent: atanh(z) = (1/2)·ln((1 + z)/(1 - z))
357
+ */
358
+ atanh(): Complex;
359
+ /**
360
+ * Check equality within tolerance
361
+ */
362
+ equals(other: Complex, epsilon?: number): boolean;
363
+ /**
364
+ * Check if this is a real number (im ≈ 0)
365
+ */
366
+ isReal(epsilon?: number): boolean;
367
+ /**
368
+ * Check if this is purely imaginary (re ≈ 0, im ≠ 0)
369
+ */
370
+ isImaginary(epsilon?: number): boolean;
371
+ /**
372
+ * Check if this is zero
373
+ */
374
+ isZero(epsilon?: number): boolean;
375
+ /**
376
+ * Check if this is NaN
377
+ */
378
+ isNaN(): boolean;
379
+ /**
380
+ * Check if this is infinite
381
+ */
382
+ isInfinite(): boolean;
383
+ /**
384
+ * Clone this complex number
385
+ */
386
+ clone(): Complex;
387
+ /**
388
+ * Round real and imaginary parts to specified decimals
389
+ */
390
+ round(decimals?: number): Complex;
391
+ /**
392
+ * Floor real and imaginary parts
393
+ */
394
+ floor(): Complex;
395
+ /**
396
+ * Ceil real and imaginary parts
397
+ */
398
+ ceil(): Complex;
399
+ /**
400
+ * Sign function: z / |z| (unit complex number in same direction)
401
+ */
402
+ sign(): Complex;
403
+ }
404
+ /**
405
+ * Imaginary unit constant: i = √(-1)
406
+ */
407
+ declare const I: Complex;
408
+ /**
409
+ * Common constants
410
+ */
411
+ declare const COMPLEX_ZERO: Complex;
412
+ declare const COMPLEX_ONE: Complex;
413
+ declare const COMPLEX_NEG_ONE: Complex;
414
+
415
+ /**
416
+ * Fraction (rational number) implementation
417
+ * @module @danielsimonjr/mathts-core/types/fraction
418
+ */
419
+
420
+ /**
421
+ * Check if a value is a Fraction
422
+ */
423
+ declare function isFraction(value: unknown): value is Fraction;
424
+ /**
425
+ * Fraction class for exact rational arithmetic
426
+ * Uses bigint for arbitrary precision numerator and denominator.
427
+ * All fractions are automatically reduced to lowest terms.
428
+ */
429
+ declare class Fraction implements IFraction {
430
+ readonly type = "Fraction";
431
+ readonly numerator: bigint;
432
+ readonly denominator: bigint;
433
+ constructor(numerator: bigint | number | string, denominator?: bigint | number | string);
434
+ /**
435
+ * Create a Fraction from a number (with optional precision)
436
+ */
437
+ static fromNumber(n: number, maxDenominator?: bigint): Fraction;
438
+ /**
439
+ * Create a Fraction from a decimal string
440
+ */
441
+ static fromDecimalString(str: string): Fraction;
442
+ /**
443
+ * Parse a fraction from a string
444
+ * Supports formats: "3/4", "-3/4", "3", "3.14", "0.(3)"
445
+ */
446
+ static parse(str: string): Fraction;
447
+ /**
448
+ * Create a Fraction from a JSON object
449
+ */
450
+ static fromJSON(json: {
451
+ n: string;
452
+ d: string;
453
+ } | {
454
+ numerator: string;
455
+ denominator: string;
456
+ }): Fraction;
457
+ /**
458
+ * Compare two fractions
459
+ * @returns -1, 0, or 1
460
+ */
461
+ static compare(a: Fraction, b: Fraction): number;
462
+ valueOf(): number;
463
+ toString(): string;
464
+ toJSON(): {
465
+ mathjs: string;
466
+ n: string;
467
+ d: string;
468
+ };
469
+ /**
470
+ * Convert to number
471
+ */
472
+ toNumber(): number;
473
+ /**
474
+ * Convert to decimal string with specified precision
475
+ */
476
+ toDecimal(precision?: number): string;
477
+ /**
478
+ * Convert to LaTeX string
479
+ */
480
+ toLatex(): string;
481
+ /**
482
+ * Convert to mixed number representation
483
+ */
484
+ toMixed(): {
485
+ whole: bigint;
486
+ numerator: bigint;
487
+ denominator: bigint;
488
+ };
489
+ /**
490
+ * Addition: a/b + c/d = (ad + bc) / bd
491
+ */
492
+ add(other: Scalar): Fraction;
493
+ /**
494
+ * Subtraction: a/b - c/d = (ad - bc) / bd
495
+ */
496
+ subtract(other: Scalar): Fraction;
497
+ /**
498
+ * Multiplication: a/b * c/d = ac / bd
499
+ */
500
+ multiply(other: Scalar): Fraction;
501
+ /**
502
+ * Division: a/b ÷ c/d = ad / bc
503
+ */
504
+ divide(other: Scalar): Fraction;
505
+ /**
506
+ * Negation: -(a/b) = -a/b
507
+ */
508
+ negate(): Fraction;
509
+ /**
510
+ * Absolute value: |a/b|
511
+ */
512
+ abs(): Fraction;
513
+ /**
514
+ * Reciprocal: b/a
515
+ */
516
+ inverse(): Fraction;
517
+ /**
518
+ * Power (integer exponent)
519
+ */
520
+ pow(n: number | bigint): Fraction;
521
+ /**
522
+ * Modulo operation
523
+ */
524
+ mod(other: Fraction): Fraction;
525
+ /**
526
+ * Check equality
527
+ */
528
+ equals(other: Fraction): boolean;
529
+ /**
530
+ * Check if less than
531
+ */
532
+ lessThan(other: Fraction): boolean;
533
+ /**
534
+ * Check if less than or equal
535
+ */
536
+ lessThanOrEqual(other: Fraction): boolean;
537
+ /**
538
+ * Check if greater than
539
+ */
540
+ greaterThan(other: Fraction): boolean;
541
+ /**
542
+ * Check if greater than or equal
543
+ */
544
+ greaterThanOrEqual(other: Fraction): boolean;
545
+ /**
546
+ * Compare with another fraction
547
+ * @returns -1, 0, or 1
548
+ */
549
+ compareTo(other: Fraction): number;
550
+ compare(other: Fraction): number;
551
+ /**
552
+ * Return fraction already in lowest terms (no-op since constructor reduces)
553
+ */
554
+ simplify(): Fraction;
555
+ /**
556
+ * Check if this is zero
557
+ */
558
+ isZero(): boolean;
559
+ /**
560
+ * Check if this is positive
561
+ */
562
+ isPositive(): boolean;
563
+ /**
564
+ * Check if this is negative
565
+ */
566
+ isNegative(): boolean;
567
+ /**
568
+ * Check if this is an integer
569
+ */
570
+ isInteger(): boolean;
571
+ /**
572
+ * Check if this is a unit fraction (1/n)
573
+ */
574
+ isUnit(): boolean;
575
+ /**
576
+ * Floor: largest integer ≤ this
577
+ */
578
+ floor(): Fraction;
579
+ /**
580
+ * Ceiling: smallest integer ≥ this
581
+ */
582
+ ceil(): Fraction;
583
+ /**
584
+ * Round to nearest integer
585
+ */
586
+ round(): Fraction;
587
+ /**
588
+ * Truncate (round toward zero)
589
+ */
590
+ trunc(): Fraction;
591
+ /**
592
+ * Get the sign: -1, 0, or 1
593
+ */
594
+ sign(): number;
595
+ /**
596
+ * Clone this fraction
597
+ */
598
+ clone(): Fraction;
599
+ /**
600
+ * Get the GCD of numerator and denominator (always 1 since we reduce)
601
+ */
602
+ gcd(): bigint;
603
+ /**
604
+ * Get continued fraction representation
605
+ */
606
+ toContinuedFraction(): bigint[];
607
+ /**
608
+ * Create fraction from continued fraction
609
+ */
610
+ static fromContinuedFraction(cf: bigint[]): Fraction;
611
+ /**
612
+ * Mediant of two fractions: (a+c)/(b+d)
613
+ * Used in Stern-Brocot tree and Farey sequences
614
+ */
615
+ mediant(other: Fraction): Fraction;
616
+ }
617
+ /**
618
+ * Common fraction constants
619
+ */
620
+ declare const FRACTION_ZERO: Fraction;
621
+ declare const FRACTION_ONE: Fraction;
622
+ declare const FRACTION_NEG_ONE: Fraction;
623
+ declare const FRACTION_HALF: Fraction;
624
+ declare const FRACTION_THIRD: Fraction;
625
+ declare const FRACTION_QUARTER: Fraction;
626
+
627
+ /**
628
+ * BigNumber (arbitrary precision decimal) implementation
629
+ * @module @danielsimonjr/mathts-core/types/bignumber
630
+ */
631
+
632
+ /**
633
+ * Check if a value is a BigNumber
634
+ */
635
+ declare function isBigNumber(value: unknown): value is BigNumber;
636
+ /**
637
+ * Configuration for BigNumber operations
638
+ */
639
+ interface BigNumberConfig {
640
+ /** Number of significant digits (default: 64) */
641
+ precision: number;
642
+ /** Rounding mode (default: 'halfUp') */
643
+ rounding: RoundingMode;
644
+ /** Minimum exponent (default: -1e9) */
645
+ minExponent: number;
646
+ /** Maximum exponent (default: 1e9) */
647
+ maxExponent: number;
648
+ }
649
+ type RoundingMode = 'up' | 'down' | 'ceil' | 'floor' | 'halfUp' | 'halfDown' | 'halfEven' | 'halfCeil' | 'halfFloor';
650
+ /**
651
+ * BigNumber class for arbitrary precision decimal arithmetic
652
+ *
653
+ * Internally stores: sign * coefficient * 10^exponent
654
+ * where coefficient is a bigint with the significant digits.
655
+ */
656
+ declare class BigNumber implements MathTSValue {
657
+ readonly type = "BigNumber";
658
+ private readonly _sign;
659
+ private readonly _coefficient;
660
+ private readonly _exponent;
661
+ private readonly _isNaN;
662
+ private readonly _isInfinite;
663
+ private constructor();
664
+ /**
665
+ * Create a BigNumber from a number
666
+ */
667
+ static fromNumber(n: number): BigNumber;
668
+ /**
669
+ * Create a BigNumber from a string
670
+ */
671
+ static parse(str: string): BigNumber;
672
+ /**
673
+ * Create from bigint
674
+ */
675
+ static fromBigInt(n: bigint): BigNumber;
676
+ /**
677
+ * Create a BigNumber from a JSON object
678
+ */
679
+ static fromJSON(json: {
680
+ value: string;
681
+ }): BigNumber;
682
+ /**
683
+ * Get/set global configuration
684
+ */
685
+ static config(newConfig?: Partial<BigNumberConfig>): BigNumberConfig;
686
+ /**
687
+ * Reset configuration to defaults
688
+ */
689
+ static resetConfig(): void;
690
+ /**
691
+ * Compare two BigNumbers
692
+ * @returns -1, 0, or 1
693
+ */
694
+ static compare(a: BigNumber, b: BigNumber): number;
695
+ private static compareMagnitude;
696
+ valueOf(): number;
697
+ toString(): string;
698
+ toJSON(): {
699
+ mathjs: string;
700
+ value: string;
701
+ };
702
+ /**
703
+ * Convert to fixed-point notation
704
+ */
705
+ toFixed(decimalPlaces?: number): string;
706
+ private toFixedInternal;
707
+ /**
708
+ * Convert to exponential notation
709
+ */
710
+ toExponential(decimalPlaces?: number): string;
711
+ /**
712
+ * Convert to precision
713
+ */
714
+ toPrecision(significantDigits?: number): string;
715
+ /**
716
+ * Convert to bigint (truncated)
717
+ */
718
+ toBigInt(): bigint;
719
+ /**
720
+ * Addition
721
+ */
722
+ add(other: Scalar | BigNumber | number | string): BigNumber;
723
+ /**
724
+ * Subtraction
725
+ */
726
+ subtract(other: Scalar | BigNumber | number | string): BigNumber;
727
+ /**
728
+ * Multiplication
729
+ */
730
+ multiply(other: Scalar | BigNumber | number | string): BigNumber;
731
+ /**
732
+ * Division
733
+ */
734
+ divide(other: Scalar | BigNumber | number | string): BigNumber;
735
+ /**
736
+ * Negation
737
+ */
738
+ negate(): BigNumber;
739
+ /**
740
+ * Absolute value
741
+ */
742
+ abs(): BigNumber;
743
+ /**
744
+ * Power (integer exponent)
745
+ */
746
+ pow(n: number | bigint): BigNumber;
747
+ /**
748
+ * Square root
749
+ */
750
+ sqrt(): BigNumber;
751
+ equals(other: BigNumber): boolean;
752
+ lessThan(other: BigNumber): boolean;
753
+ lessThanOrEqual(other: BigNumber): boolean;
754
+ greaterThan(other: BigNumber): boolean;
755
+ greaterThanOrEqual(other: BigNumber): boolean;
756
+ compareTo(other: BigNumber): number;
757
+ compare(other: BigNumber): number;
758
+ /**
759
+ * Round to specified decimal places
760
+ */
761
+ round(decimalPlaces?: number, mode?: RoundingMode): BigNumber;
762
+ private shouldRound;
763
+ /**
764
+ * Round to specified precision (significant digits)
765
+ */
766
+ roundToPrecision(precision: number, mode?: RoundingMode): BigNumber;
767
+ floor(): BigNumber;
768
+ ceil(): BigNumber;
769
+ trunc(): BigNumber;
770
+ /**
771
+ * Modulo (remainder after division)
772
+ * Result has the same sign as the dividend (this).
773
+ */
774
+ mod(other: Scalar | BigNumber | number | string): BigNumber;
775
+ /**
776
+ * Sine of this BigNumber (in radians)
777
+ * Uses Taylor series: sin(x) = x - x^3/3! + x^5/5! - ...
778
+ */
779
+ sin(): BigNumber;
780
+ /**
781
+ * Cosine of this BigNumber (in radians)
782
+ * Uses Taylor series: cos(x) = 1 - x^2/2! + x^4/4! - ...
783
+ */
784
+ cos(): BigNumber;
785
+ /**
786
+ * Tangent of this BigNumber (in radians)
787
+ * tan(x) = sin(x) / cos(x)
788
+ */
789
+ tan(): BigNumber;
790
+ /**
791
+ * Arcsine of this BigNumber
792
+ * Returns value in [-PI/2, PI/2]
793
+ */
794
+ asin(): BigNumber;
795
+ /**
796
+ * Arccosine of this BigNumber
797
+ * Returns value in [0, PI]
798
+ */
799
+ acos(): BigNumber;
800
+ /**
801
+ * Arctangent of this BigNumber
802
+ * Returns value in (-PI/2, PI/2)
803
+ * Uses Taylor series with argument reduction for convergence.
804
+ */
805
+ atan(): BigNumber;
806
+ /**
807
+ * Two-argument arctangent: atan2(y, x)
808
+ * this = y, argument = x
809
+ * Returns angle in (-PI, PI]
810
+ */
811
+ atan2(x: BigNumber): BigNumber;
812
+ /**
813
+ * Hyperbolic sine: sinh(x) = (e^x - e^(-x)) / 2
814
+ */
815
+ sinh(): BigNumber;
816
+ /**
817
+ * Hyperbolic cosine: cosh(x) = (e^x + e^(-x)) / 2
818
+ */
819
+ cosh(): BigNumber;
820
+ /**
821
+ * Hyperbolic tangent: tanh(x) = sinh(x) / cosh(x)
822
+ */
823
+ tanh(): BigNumber;
824
+ /**
825
+ * Inverse hyperbolic sine: asinh(x) = ln(x + sqrt(x^2 + 1))
826
+ */
827
+ asinh(): BigNumber;
828
+ /**
829
+ * Inverse hyperbolic cosine: acosh(x) = ln(x + sqrt(x^2 - 1))
830
+ * Domain: x >= 1
831
+ */
832
+ acosh(): BigNumber;
833
+ /**
834
+ * Inverse hyperbolic tangent: atanh(x) = 0.5 * ln((1+x)/(1-x))
835
+ * Domain: -1 < x < 1
836
+ */
837
+ atanh(): BigNumber;
838
+ /**
839
+ * Exponential function: e^x
840
+ * Uses Taylor series: e^x = 1 + x + x^2/2! + x^3/3! + ...
841
+ * With argument reduction: e^x = (e^(x/2^k))^(2^k) for faster convergence.
842
+ */
843
+ exp(): BigNumber;
844
+ /**
845
+ * Natural logarithm: ln(x)
846
+ * Uses the AGM (arithmetic-geometric mean) method for fast convergence.
847
+ * Fallback: series ln((1+y)/(1-y)) = 2*(y + y^3/3 + y^5/5 + ...) where y = (x-1)/(x+1)
848
+ */
849
+ ln(): BigNumber;
850
+ /**
851
+ * Base-10 logarithm: log10(x) = ln(x) / ln(10)
852
+ */
853
+ log10(): BigNumber;
854
+ /**
855
+ * Base-2 logarithm: log2(x) = ln(x) / ln(2)
856
+ */
857
+ log2(): BigNumber;
858
+ /**
859
+ * Cube root
860
+ * Uses Newton-Raphson iteration.
861
+ */
862
+ cbrt(): BigNumber;
863
+ /**
864
+ * e^x - 1 (more precise than exp(x) - 1 for small x)
865
+ * Uses Taylor series directly: expm1(x) = x + x^2/2! + x^3/3! + ...
866
+ */
867
+ expm1(): BigNumber;
868
+ /**
869
+ * ln(1 + x) (more precise than ln(1 + x) for small x)
870
+ */
871
+ log1p(): BigNumber;
872
+ /**
873
+ * Hypotenuse: sqrt(this^2 + other^2)
874
+ */
875
+ hypot(other: BigNumber): BigNumber;
876
+ /** Reduce angle to [-PI, PI] range */
877
+ private _reduceAngle;
878
+ /** Taylor series for sin(x), assumes x is in [-PI, PI] */
879
+ private _sinTaylor;
880
+ /** Taylor series for cos(x), assumes x is in [-PI, PI] */
881
+ private _cosTaylor;
882
+ /** Taylor series for atan(x), assumes |x| <= 0.5 */
883
+ private _atanTaylor;
884
+ isNaN(): boolean;
885
+ isFinite(): boolean;
886
+ isInfinite(): boolean;
887
+ isZero(): boolean;
888
+ isPositive(): boolean;
889
+ isNegative(): boolean;
890
+ isInteger(): boolean;
891
+ sign(): number;
892
+ clone(): BigNumber;
893
+ private ensureBigNumber;
894
+ private alignExponents;
895
+ private normalize;
896
+ }
897
+ /**
898
+ * Common BigNumber constants
899
+ */
900
+ declare const BIGNUMBER_ZERO: BigNumber;
901
+ declare const BIGNUMBER_ONE: BigNumber;
902
+ declare const BIGNUMBER_NEG_ONE: BigNumber;
903
+ declare const BIGNUMBER_TEN: BigNumber;
904
+ declare const BIGNUMBER_PI: BigNumber;
905
+ declare const BIGNUMBER_E: BigNumber;
906
+ declare const BIGNUMBER_LN2: BigNumber;
907
+ declare const BIGNUMBER_LN10: BigNumber;
908
+
909
+ /**
910
+ * MathTS typed-function Integration
911
+ *
912
+ * Creates a configured typed-function instance with MathTS types
913
+ * for runtime type dispatch across numeric types, matrices, and more.
914
+ *
915
+ * This module directly uses the typed-function library API without
916
+ * any intermediate abstraction layers.
917
+ *
918
+ * Supports WASM-accelerated dispatch when available.
919
+ *
920
+ * @packageDocumentation
921
+ */
922
+
923
+ /**
924
+ * Initialize WASM dispatch for typed-function (optional, improves performance)
925
+ *
926
+ * Uses the unified typed.init() API to enable WASM-accelerated dispatch
927
+ * with automatic fallback to pure JS when WASM is unavailable.
928
+ *
929
+ * @param options - Initialization options
930
+ * @returns Promise resolving to true if WASM was initialized successfully
931
+ */
932
+ declare function initTypedWasm(options?: {
933
+ preferWasm?: boolean;
934
+ }): Promise<boolean>;
935
+ /**
936
+ * Check if WASM dispatch is available
937
+ */
938
+ declare function isTypedWasmAvailable(): boolean;
939
+
940
+ /**
941
+ * Type definition for typed-function
942
+ */
943
+ interface TypeDef {
944
+ name: string;
945
+ test: (x: unknown) => boolean;
946
+ }
947
+ /**
948
+ * Conversion definition for typed-function
949
+ */
950
+ interface ConversionDef {
951
+ from: string;
952
+ to: string;
953
+ convert: (value: unknown) => unknown;
954
+ }
955
+ declare const isNumber: (x: unknown) => x is number;
956
+ declare const isBoolean: (x: unknown) => x is boolean;
957
+ declare const isString: (x: unknown) => x is string;
958
+ declare const isBigInt: (x: unknown) => x is bigint;
959
+ declare const isArray: (x: unknown) => x is unknown[];
960
+ declare const isFunction: (x: unknown) => x is (...args: unknown[]) => unknown;
961
+ declare const isObject: (x: unknown) => x is object;
962
+ declare const isNull: (x: unknown) => x is null;
963
+ declare const isUndefined: (x: unknown) => x is undefined;
964
+ /**
965
+ * Check if value is a Matrix (duck typing until Matrix class is implemented)
966
+ */
967
+ declare const isMatrix: (x: unknown) => boolean;
968
+ /**
969
+ * Check if value is a DenseMatrix
970
+ */
971
+ declare const isDenseMatrix: (x: unknown) => boolean;
972
+ /**
973
+ * Check if value is a SparseMatrix
974
+ */
975
+ declare const isSparseMatrix: (x: unknown) => boolean;
976
+ /**
977
+ * Check if value is a Unit
978
+ */
979
+ declare const isUnit: (x: unknown) => boolean;
980
+ /**
981
+ * Extended type definition with optional WASM mask support
982
+ */
983
+ interface MathTSTypeDef extends TypeDef {
984
+ /** Optional WASM type mask for accelerated dispatch (auto-registered when WASM available) */
985
+ wasmMask?: number;
986
+ }
987
+ /**
988
+ * MathTS-specific types to add to typed-function.
989
+ * Note: Most primitive types (number, boolean, string, etc.) are already built into typed-function
990
+ *
991
+ * When WASM is available, custom type masks are automatically registered for efficient dispatch.
992
+ */
993
+ declare const MATHTS_TYPES: MathTSTypeDef[];
994
+ declare const MATHTS_CONVERSIONS: ConversionDef[];
995
+ /**
996
+ * Create a new MathTS typed instance
997
+ *
998
+ * This creates an isolated typed universe with MathTS types and conversions.
999
+ * Uses typed-function's addType() API which automatically registers WASM
1000
+ * type masks when available.
1001
+ *
1002
+ * @returns A new typed-function instance configured for MathTS
1003
+ *
1004
+ * @example
1005
+ * ```typescript
1006
+ * const myTyped = createMathTSTyped();
1007
+ *
1008
+ * const add = myTyped('add', {
1009
+ * 'number, number': (a, b) => a + b,
1010
+ * 'Complex, Complex': (a, b) => a.add(b),
1011
+ * 'Fraction, Fraction': (a, b) => a.add(b),
1012
+ * 'BigNumber, BigNumber': (a, b) => a.add(b),
1013
+ * });
1014
+ * ```
1015
+ */
1016
+ declare function createMathTSTyped(): TypedInstance;
1017
+ /**
1018
+ * Default MathTS typed instance
1019
+ *
1020
+ * This is the primary typed-function instance used throughout MathTS.
1021
+ * It comes pre-configured with all MathTS types and conversions.
1022
+ *
1023
+ * @example
1024
+ * ```typescript
1025
+ * import { mathTyped, Complex, Fraction, BigNumber } from '@danielsimonjr/mathts-core';
1026
+ *
1027
+ * // Create a polymorphic add function
1028
+ * const add = mathTyped('add', {
1029
+ * 'number, number': (a, b) => a + b,
1030
+ * 'Complex, Complex': (a, b) => a.add(b),
1031
+ * 'Fraction, Fraction': (a, b) => a.add(b),
1032
+ * 'BigNumber, BigNumber': (a, b) => a.add(b),
1033
+ * });
1034
+ *
1035
+ * // Works with automatic type coercion
1036
+ * add(1, 2); // 3
1037
+ * add(new Complex(1, 2), new Complex(3, 4)); // Complex(4, 6)
1038
+ * add(new Fraction(1, 2), new Fraction(1, 3)); // Fraction(5, 6)
1039
+ * add(1, new Complex(2, 3)); // Complex(3, 3) - auto-converts
1040
+ * ```
1041
+ */
1042
+ declare const mathTyped: TypedInstance;
1043
+
1044
+ /**
1045
+ * TypeRegistry class for managing custom type registrations
1046
+ * This is a MathTS utility, not from typed-function
1047
+ */
1048
+ declare class TypeRegistry {
1049
+ private types;
1050
+ private conversions;
1051
+ private instance;
1052
+ /**
1053
+ * Register a new type
1054
+ */
1055
+ registerType<T>(name: string, test: (x: unknown) => x is T): this;
1056
+ /**
1057
+ * Register a type conversion
1058
+ */
1059
+ registerConversion<From, To>(from: string, to: string, convert: (value: From) => To): this;
1060
+ /**
1061
+ * Check if a type is registered
1062
+ */
1063
+ hasType(name: string): boolean;
1064
+ /**
1065
+ * Check if a conversion is registered
1066
+ */
1067
+ hasConversion(from: string, to: string): boolean;
1068
+ /**
1069
+ * Get all registered type names
1070
+ */
1071
+ getTypeNames(): string[];
1072
+ /**
1073
+ * Build a typed-function instance from the registry
1074
+ */
1075
+ build(): TypedInstance;
1076
+ /**
1077
+ * Clear all registered types and conversions
1078
+ */
1079
+ clear(): void;
1080
+ }
1081
+ /**
1082
+ * Helper to create a typed function with the MathTS typed instance
1083
+ */
1084
+ declare function createTypedFunction<T>(name: string, signatures: {
1085
+ [signature: string]: (...args: unknown[]) => T;
1086
+ }, typedInstance?: TypedInstance): (...args: unknown[]) => T;
1087
+
1088
+ declare function registerNativeTypes(): void;
1089
+
1090
+ /**
1091
+ * MathTS Function Factory
1092
+ *
1093
+ * Provides a factory pattern for creating MathTS functions with:
1094
+ * - Typed function dispatch via typed-function
1095
+ * - Dependency injection for inter-function references
1096
+ * - Backend selection integration
1097
+ * - Lazy loading support
1098
+ *
1099
+ * @packageDocumentation
1100
+ */
1101
+
1102
+ /**
1103
+ * Configuration for MathTS instance
1104
+ */
1105
+ interface MathTSConfig {
1106
+ /** Numeric precision (for BigNumber) */
1107
+ precision: number;
1108
+ /** Default matrix type */
1109
+ matrix: 'Matrix' | 'Array';
1110
+ /** Number type for parsing */
1111
+ number: 'number' | 'BigNumber' | 'Fraction';
1112
+ /** Enable predictable randomness */
1113
+ randomSeed: string | null;
1114
+ /** Epsilon for floating point comparison */
1115
+ epsilon: number;
1116
+ /** Preferred backend for matrix operations */
1117
+ preferredBackend: 'auto' | 'js' | 'wasm' | 'gpu';
1118
+ /** Minimum elements to use WASM backend */
1119
+ wasmThreshold: number;
1120
+ /** Minimum elements to use GPU backend */
1121
+ gpuThreshold: number;
1122
+ /** Enable parallel processing */
1123
+ parallelEnabled: boolean;
1124
+ /** Minimum elements to parallelize */
1125
+ parallelThreshold: number;
1126
+ }
1127
+ /**
1128
+ * Default MathTS configuration
1129
+ */
1130
+ declare const DEFAULT_CONFIG: MathTSConfig;
1131
+ /**
1132
+ * Factory function definition
1133
+ */
1134
+ interface FactoryFunction<T = TypedFunction> {
1135
+ /** Name of the function */
1136
+ name: string;
1137
+ /** Dependencies required by this function */
1138
+ dependencies: string[];
1139
+ /** Factory that creates the function given dependencies */
1140
+ factory: (deps: FactoryDependencies) => T;
1141
+ }
1142
+ /**
1143
+ * Dependencies passed to factory functions
1144
+ */
1145
+ interface FactoryDependencies {
1146
+ /** MathTS configuration */
1147
+ config: MathTSConfig;
1148
+ /** typed-function instance */
1149
+ typed: TypedInstance;
1150
+ /** Registered functions (for cross-references) */
1151
+ [key: string]: unknown;
1152
+ }
1153
+ /**
1154
+ * Import definition for a factory function
1155
+ */
1156
+ type FactoryImport = FactoryFunction | (() => Promise<FactoryFunction>);
1157
+ /**
1158
+ * MathTS function registry
1159
+ */
1160
+ declare class FunctionRegistry {
1161
+ private factories;
1162
+ private instances;
1163
+ private dependencies;
1164
+ private creating;
1165
+ constructor(config?: Partial<MathTSConfig>, typed?: TypedInstance);
1166
+ /**
1167
+ * Register a factory function
1168
+ */
1169
+ register(factory: FactoryFunction): void;
1170
+ /**
1171
+ * Register multiple factory functions
1172
+ */
1173
+ registerAll(factories: FactoryFunction[]): void;
1174
+ /**
1175
+ * Get or create a function by name
1176
+ */
1177
+ get(name: string): TypedFunction;
1178
+ /**
1179
+ * Check if a function is registered
1180
+ */
1181
+ has(name: string): boolean;
1182
+ /**
1183
+ * Get all registered function names
1184
+ */
1185
+ names(): string[];
1186
+ /**
1187
+ * Update configuration
1188
+ */
1189
+ updateConfig(config: Partial<MathTSConfig>): void;
1190
+ /**
1191
+ * Get current configuration
1192
+ */
1193
+ getConfig(): MathTSConfig;
1194
+ }
1195
+ /**
1196
+ * Create a factory function definition
1197
+ *
1198
+ * @example
1199
+ * ```typescript
1200
+ * export const addFactory = createFactory('add', ['typed'], ({ typed }) =>
1201
+ * typed('add', {
1202
+ * 'number, number': (a, b) => a + b,
1203
+ * 'Complex, Complex': (a, b) => ({ re: a.re + b.re, im: a.im + b.im }),
1204
+ * })
1205
+ * );
1206
+ * ```
1207
+ */
1208
+ declare function createFactory<T = TypedFunction>(name: string, dependencies: string[], factory: (deps: FactoryDependencies) => T): FactoryFunction<T>;
1209
+ declare const registry: FunctionRegistry;
1210
+ declare const math: {
1211
+ /**
1212
+ * Get a registered function
1213
+ */
1214
+ get: (name: string) => TypedFunction;
1215
+ /**
1216
+ * Register a factory function
1217
+ */
1218
+ register: (factory: FactoryFunction) => void;
1219
+ /**
1220
+ * Get configuration
1221
+ */
1222
+ config: () => MathTSConfig;
1223
+ /**
1224
+ * Update configuration
1225
+ */
1226
+ configure: (config: Partial<MathTSConfig>) => void;
1227
+ };
1228
+
1229
+ /**
1230
+ * @danielsimonjr/mathts-core - Core types and utilities for MathTS
1231
+ * @packageDocumentation
1232
+ */
1233
+
1234
+ declare const VERSION = "0.1.0";
1235
+
1236
+ export { 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, 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, MATHTS_CONVERSIONS, MATHTS_TYPES, type MathTSConfig, type MathTSValue, type MatrixBackend, type MatrixDimensions, type NumericType, type RoundingMode, type Scalar, type TypeDef, TypeRegistry, VERSION, createFactory, createMathTSTyped, createTypedFunction, initTypedWasm, isArray, isBigInt, isBigNumber, isBoolean, isComplex, isDenseMatrix, isFraction, isFunction, isMatrix, isNull, isNumber, isObject, isSparseMatrix, isString, isTypedWasmAvailable, isUndefined, isUnit, math, mathTyped, registerNativeTypes, registry };