mathjs 10.5.3 → 10.6.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 (33) hide show
  1. package/HISTORY.md +14 -0
  2. package/lib/browser/math.js +5 -5
  3. package/lib/browser/math.js.map +1 -1
  4. package/lib/cjs/entry/dependenciesAny/dependenciesFft.generated.js +41 -0
  5. package/lib/cjs/entry/dependenciesAny/dependenciesIfft.generated.js +29 -0
  6. package/lib/cjs/entry/dependenciesAny.generated.js +16 -0
  7. package/lib/cjs/entry/impureFunctionsAny.generated.js +66 -64
  8. package/lib/cjs/entry/pureFunctionsAny.generated.js +189 -171
  9. package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +6 -0
  10. package/lib/cjs/expression/embeddedDocs/function/matrix/fft.js +15 -0
  11. package/lib/cjs/expression/embeddedDocs/function/matrix/ifft.js +15 -0
  12. package/lib/cjs/factoriesAny.js +16 -0
  13. package/lib/cjs/function/algebra/derivative.js +1 -1
  14. package/lib/cjs/function/matrix/fft.js +128 -0
  15. package/lib/cjs/function/matrix/ifft.js +49 -0
  16. package/lib/cjs/header.js +2 -2
  17. package/lib/cjs/version.js +1 -1
  18. package/lib/esm/entry/dependenciesAny/dependenciesFft.generated.js +24 -0
  19. package/lib/esm/entry/dependenciesAny/dependenciesIfft.generated.js +16 -0
  20. package/lib/esm/entry/dependenciesAny.generated.js +2 -0
  21. package/lib/esm/entry/impureFunctionsAny.generated.js +63 -61
  22. package/lib/esm/entry/pureFunctionsAny.generated.js +161 -145
  23. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +4 -0
  24. package/lib/esm/expression/embeddedDocs/function/matrix/fft.js +8 -0
  25. package/lib/esm/expression/embeddedDocs/function/matrix/ifft.js +8 -0
  26. package/lib/esm/factoriesAny.js +2 -0
  27. package/lib/esm/function/algebra/derivative.js +1 -1
  28. package/lib/esm/function/matrix/fft.js +104 -0
  29. package/lib/esm/function/matrix/ifft.js +38 -0
  30. package/lib/esm/version.js +1 -1
  31. package/package.json +4 -1
  32. package/types/index.d.ts +995 -270
  33. package/types/index.ts +694 -6
package/types/index.d.ts CHANGED
@@ -353,6 +353,26 @@ declare namespace math {
353
353
 
354
354
  type MathJsFunctionName = keyof MathJsStatic
355
355
 
356
+ interface LUDecomposition {
357
+ L: MathCollection
358
+ U: MathCollection
359
+ p: number[]
360
+ }
361
+
362
+ interface SLUDecomposition extends LUDecomposition {
363
+ q: number[]
364
+ }
365
+
366
+ interface QRDecomposition {
367
+ Q: MathCollection
368
+ R: MathCollection
369
+ }
370
+
371
+ interface FractionDefinition {
372
+ a: number
373
+ b: number
374
+ }
375
+
356
376
  interface MathJsStatic extends FactoryDependencies {
357
377
  e: number
358
378
  pi: number
@@ -468,9 +488,8 @@ declare namespace math {
468
488
  * @param x A value of any type
469
489
  * @returns The boolean value
470
490
  */
471
- boolean(
472
- x: string | number | boolean | MathCollection | null
473
- ): boolean | MathCollection
491
+ boolean(x: string | number | boolean | null): boolean
492
+ boolean(x: MathCollection): MathCollection
474
493
 
475
494
  /**
476
495
  * Wrap any value in a chain, allowing to perform chained operations on
@@ -486,7 +505,7 @@ declare namespace math {
486
505
  * @returns The created chain
487
506
  */
488
507
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
489
- chain(value?: any): MathJsChain
508
+ chain<TValue>(value?: TValue): MathJsChain<TValue>
490
509
 
491
510
  /**
492
511
  * Create a complex value or convert a value to a complex value.
@@ -540,9 +559,10 @@ declare namespace math {
540
559
  * fraction
541
560
  * @returns Returns a fraction
542
561
  */
543
- fraction(value: number | string | BigNumber | Fraction | object): Fraction
544
- fraction(values: MathArray): MathArray
545
- fraction(values: Matrix): Matrix
562
+ fraction(
563
+ value: number | string | BigNumber | Fraction | FractionDefinition
564
+ ): Fraction
565
+ fraction(values: MathCollection): MathCollection
546
566
  /**
547
567
  * @param numerator Argument specifying the numerator of the fraction
548
568
  * @param denominator Argument specifying the denominator of the
@@ -589,16 +609,9 @@ declare namespace math {
589
609
  * @returns The created number
590
610
  */
591
611
  number(
592
- value?:
593
- | string
594
- | number
595
- | BigNumber
596
- | Fraction
597
- | boolean
598
- | MathCollection
599
- | Unit
600
- | null
601
- ): number | MathCollection
612
+ value?: string | number | BigNumber | Fraction | boolean | Unit | null
613
+ ): number
614
+ number(value?: MathCollection): number | MathCollection
602
615
  /**
603
616
  * @param value Value to be converted
604
617
  * @param valuelessUnit A valueless unit, used to convert a unit to a
@@ -633,7 +646,8 @@ declare namespace math {
633
646
  * @param value A value to convert to a string
634
647
  * @returns The created string
635
648
  */
636
- string(value: MathType | null): string | MathCollection
649
+ string(value: MathNumericType | string | Unit | null): string
650
+ string(value: MathCollection): MathCollection
637
651
 
638
652
  /**
639
653
  * Create a unit. Depending on the passed arguments, the function will
@@ -653,7 +667,8 @@ declare namespace math {
653
667
  * @param unit The unit to be created
654
668
  * @returns The created unit
655
669
  */
656
- unit(value: number | MathCollection | BigNumber, unit: string): Unit
670
+ unit(value: number | BigNumber, unit: string): Unit
671
+ unit(value: MathCollection, unit: string): Unit[]
657
672
 
658
673
  /*************************************************************************
659
674
  * Expression functions
@@ -672,6 +687,7 @@ declare namespace math {
672
687
  */
673
688
  compile(exprs: MathExpression[]): EvalFunction[]
674
689
 
690
+ // TODO properly type this
675
691
  /**
676
692
  * Evaluate an expression.
677
693
  * @param expr The expression to be evaluated
@@ -679,10 +695,15 @@ declare namespace math {
679
695
  * @returns The result of the expression
680
696
  */
681
697
  evaluate(
682
- expr: MathExpression | MathExpression[] | Matrix,
698
+ expr: MathExpression | Matrix,
683
699
  scope?: object
684
700
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
685
701
  ): any
702
+ evaluate(
703
+ expr: MathExpression[],
704
+ scope?: object
705
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
706
+ ): any[]
686
707
 
687
708
  /**
688
709
  * Retrieve help on a function or data type. Help files are retrieved
@@ -729,7 +750,8 @@ declare namespace math {
729
750
  * @param b A column vector with the b values
730
751
  * @returns A column vector with the linear system solution (x)
731
752
  */
732
- lsolve(L: Matrix | MathArray, b: Matrix | MathArray): Matrix | MathArray
753
+ lsolve(L: Matrix, b: Matrix | MathArray): Matrix
754
+ lsolve(L: MathArray, b: Matrix | MathArray): MathArray
733
755
 
734
756
  /**
735
757
  * Calculate the Matrix LU decomposition with partial pivoting. Matrix A
@@ -740,11 +762,7 @@ declare namespace math {
740
762
  * @returns The lower triangular matrix, the upper triangular matrix and
741
763
  * the permutation matrix.
742
764
  */
743
- lup(A?: Matrix | MathArray): {
744
- L: MathCollection
745
- U: MathCollection
746
- P: number[]
747
- }
765
+ lup(A?: Matrix | MathArray): LUDecomposition
748
766
 
749
767
  /**
750
768
  * Solves the linear system A * x = b where A is an [n x n] matrix and b
@@ -759,11 +777,18 @@ declare namespace math {
759
777
  * b
760
778
  */
761
779
  lusolve(
762
- A: Matrix | MathArray | number,
780
+ A: Matrix,
763
781
  b: Matrix | MathArray,
764
782
  order?: number,
765
783
  threshold?: number
766
- ): Matrix | MathArray
784
+ ): Matrix
785
+
786
+ lusolve(
787
+ A: MathArray,
788
+ b: Matrix | MathArray,
789
+ order?: number,
790
+ threshold?: number
791
+ ): MathArray
767
792
 
768
793
  /**
769
794
  * Calculate the Matrix QR decomposition. Matrix A is decomposed in two
@@ -773,7 +798,7 @@ declare namespace math {
773
798
  * decomposition.
774
799
  * @returns Q: the orthogonal matrix and R: the upper triangular matrix
775
800
  */
776
- qr(A: Matrix | MathArray): { Q: MathCollection; R: MathCollection }
801
+ qr(A: Matrix | MathArray): QRDecomposition
777
802
 
778
803
  rationalize(
779
804
  expr: MathNode | string,
@@ -844,7 +869,7 @@ declare namespace math {
844
869
  * @returns The lower triangular matrix, the upper triangular matrix and
845
870
  * the permutation vectors.
846
871
  */
847
- slu(A: Matrix, order: number, threshold: number): object
872
+ slu(A: Matrix, order: number, threshold: number): SLUDecomposition
848
873
 
849
874
  /**
850
875
  * Solves the linear equation system by backward substitution. Matrix
@@ -853,7 +878,8 @@ declare namespace math {
853
878
  * @param b A column vector with the b values
854
879
  * @returns A column vector with the linear system solution (x)
855
880
  */
856
- usolve(U: Matrix | MathArray, b: Matrix | MathArray): Matrix | MathArray
881
+ usolve(U: Matrix, b: Matrix | MathArray): Matrix
882
+ usolve(U: MathArray, b: Matrix | MathArray): MathArray
857
883
 
858
884
  /*************************************************************************
859
885
  * Arithmetic functions
@@ -894,11 +920,9 @@ declare namespace math {
894
920
  */
895
921
  cbrt(x: number, allRoots?: boolean): number
896
922
  cbrt(x: BigNumber, allRoots?: boolean): BigNumber
897
- cbrt(x: Fraction, allRoots?: boolean): Fraction
898
923
  cbrt(x: Complex, allRoots?: boolean): Complex
899
924
  cbrt(x: MathArray, allRoots?: boolean): MathArray
900
925
  cbrt(x: Matrix, allRoots?: boolean): Matrix
901
- cbrt(x: Unit, allRoots?: boolean): Unit
902
926
 
903
927
  // Rounding functions, grouped for similarity, even though it breaks
904
928
  // the alphabetic order among arithmetic functions.
@@ -1456,9 +1480,9 @@ declare namespace math {
1456
1480
  * @param x A complex number or array with complex numbers
1457
1481
  * @returns The imaginary part of x
1458
1482
  */
1459
- im(
1460
- x: number | BigNumber | Complex | MathCollection
1461
- ): number | BigNumber | MathCollection
1483
+ im(x: MathJsChain<number | Complex>): MathJsChain<number>
1484
+ im(x: MathJsChain<BigNumber>): MathJsChain<BigNumber>
1485
+ im(x: MathJsChain<MathCollection>): MathJsChain<MathCollection>
1462
1486
 
1463
1487
  /**
1464
1488
  * Get the real part of a complex number. For a complex number a + bi,
@@ -1467,9 +1491,9 @@ declare namespace math {
1467
1491
  * @param x A complex number or array of complex numbers
1468
1492
  * @returns The real part of x
1469
1493
  */
1470
- re(
1471
- x: number | BigNumber | Complex | MathCollection
1472
- ): number | BigNumber | MathCollection
1494
+ re(x: MathJsChain<number | Complex>): MathJsChain<number>
1495
+ re(x: MathJsChain<BigNumber>): MathJsChain<BigNumber>
1496
+ re(x: MathJsChain<MathCollection>): MathJsChain<MathCollection>
1473
1497
 
1474
1498
  /*************************************************************************
1475
1499
  * Geometry functions
@@ -1973,6 +1997,20 @@ declare namespace math {
1973
1997
  */
1974
1998
  zeros(m: number, n: number, format?: string): MathCollection
1975
1999
 
2000
+ /**
2001
+ * Calculate N-dimensional fourier transform
2002
+ * @param {Array | Matrix} arr An array or matrix
2003
+ * @return {Array | Matrix} N-dimensional fourier transformation of the array
2004
+ */
2005
+ fft<T extends MathCollection>(arr: T): T
2006
+
2007
+ /**
2008
+ * Calculate N-dimensional inverse fourier transform
2009
+ * @param {Array | Matrix} arr An array or matrix
2010
+ * @return {Array | Matrix} N-dimensional fourier transformation of the array
2011
+ */
2012
+ ifft<T extends MathCollection>(arr: T): T
2013
+
1976
2014
  /*************************************************************************
1977
2015
  * Probability functions
1978
2016
  ************************************************************************/
@@ -2596,6 +2634,7 @@ declare namespace math {
2596
2634
  * @returns The variance
2597
2635
  */
2598
2636
  variance(...args: Array<number | BigNumber | Fraction>): number
2637
+
2599
2638
  /**
2600
2639
  * Compute the variance of a matrix or a list with values. In case of a
2601
2640
  * (multi dimensional) array or matrix, the variance over all elements
@@ -3064,7 +3103,7 @@ declare namespace math {
3064
3103
 
3065
3104
  isSymbolNode(x: unknown): x is SymbolNode
3066
3105
 
3067
- isChain(x: unknown): x is MathJsChain
3106
+ isChain(x: unknown): x is MathJsChain<unknown>
3068
3107
 
3069
3108
  /*************************************************************************
3070
3109
  * Functions -> Utils
@@ -3076,7 +3115,7 @@ declare namespace math {
3076
3115
  * @returns A clone of object x
3077
3116
  */
3078
3117
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3079
- clone(x: any): any
3118
+ clone<TType>(x: TType): TType
3080
3119
 
3081
3120
  /**
3082
3121
  * Test whether a value is an numeric value. In case of a string,
@@ -3746,12 +3785,12 @@ declare namespace math {
3746
3785
  * Create a shallow clone of the node. The node itself is cloned, its
3747
3786
  * childs are not cloned.
3748
3787
  */
3749
- clone(): MathNode
3788
+ clone(): this
3750
3789
  /**
3751
3790
  * Create a deep clone of the node. Both the node as well as all its
3752
3791
  * childs are cloned recursively.
3753
3792
  */
3754
- cloneDeep(): MathNode
3793
+ cloneDeep(): this
3755
3794
  /**
3756
3795
  * Compile an expression into optimized JavaScript code. compile returns
3757
3796
  * an object with a function evaluate([scope]) to evaluate. Example:
@@ -3977,9 +4016,9 @@ declare namespace math {
3977
4016
  randomSeed?: string | null
3978
4017
  }
3979
4018
 
3980
- interface MathJsChain {
4019
+ interface MathJsChain<TValue> {
3981
4020
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3982
- done(): any
4021
+ done(): TValue
3983
4022
 
3984
4023
  /*************************************************************************
3985
4024
  * Construction functions
@@ -3990,7 +4029,12 @@ declare namespace math {
3990
4029
  * When a matrix is provided, all elements will be converted to
3991
4030
  * BigNumber.
3992
4031
  */
3993
- bignumber(): MathJsChain
4032
+ bignumber(
4033
+ this: MathJsChain<
4034
+ number | string | Fraction | BigNumber | boolean | Fraction | null
4035
+ >
4036
+ ): MathJsChain<BigNumber>
4037
+ bignumber<T extends MathCollection>(this: MathJsChain<T>): MathJsChain<T>
3994
4038
 
3995
4039
  /**
3996
4040
  * Create a boolean or convert a string or number to a boolean. In case
@@ -3998,14 +4042,21 @@ declare namespace math {
3998
4042
  * of zero. Strings can be 'true' or 'false', or can contain a number.
3999
4043
  * When value is a matrix, all elements will be converted to boolean.
4000
4044
  */
4001
- boolean(): MathJsChain
4045
+ boolean(
4046
+ this: MathJsChain<string | number | boolean | null>
4047
+ ): MathJsChain<boolean>
4048
+ boolean(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
4002
4049
 
4003
4050
  /**
4004
4051
  * Create a complex value or convert a value to a complex value.
4005
4052
  * @param im Argument specifying the imaginary part of the complex
4006
4053
  * number
4007
4054
  */
4008
- complex(im?: number): MathJsChain
4055
+ complex(
4056
+ this: MathJsChain<Complex | string | PolarCoordinates>,
4057
+ im?: number
4058
+ ): MathJsChain<Complex>
4059
+ complex(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
4009
4060
 
4010
4061
  /**
4011
4062
  * Create a user-defined unit and register it with the Unit type.
@@ -4020,9 +4071,10 @@ declare namespace math {
4020
4071
  * 0.
4021
4072
  */
4022
4073
  createUnit(
4074
+ this: MathJsChain<string>,
4023
4075
  definition?: string | UnitDefinition,
4024
4076
  options?: CreateUnitOptions
4025
- ): MathJsChain
4077
+ ): MathJsChain<Unit>
4026
4078
  /**
4027
4079
  * Create a user-defined unit and register it with the Unit type.
4028
4080
  * @param options (optional) An object containing any of the following
@@ -4033,21 +4085,31 @@ declare namespace math {
4033
4085
  * the unit. For example, the offset for celsius is 273.15. Default is
4034
4086
  * 0.
4035
4087
  */
4036
- createUnit(options?: CreateUnitOptions): MathJsChain
4088
+ createUnit(
4089
+ this: MathJsChain<Record<string, string | UnitDefinition>>,
4090
+ options?: CreateUnitOptions
4091
+ ): MathJsChain<Unit>
4037
4092
 
4038
4093
  /**
4039
4094
  * Create a fraction convert a value to a fraction.
4040
4095
  * @param denominator Argument specifying the denominator of the
4041
4096
  * fraction
4042
4097
  */
4043
- fraction(denominator?: number | string | MathCollection): MathJsChain
4098
+ fraction(
4099
+ this: MathJsChain<
4100
+ number | string | BigNumber | Fraction | FractionDefinition
4101
+ >,
4102
+ denominator?: number
4103
+ ): MathJsChain<Fraction>
4104
+ fraction(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
4044
4105
 
4045
4106
  /**
4046
4107
  * Create an index. An Index can store ranges having start, step, and
4047
4108
  * end for multiple dimensions. Matrix.get, Matrix.set, and math.subset
4048
4109
  * accept an Index as input.
4049
4110
  */
4050
- index(): MathJsChain
4111
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4112
+ index(this: MathJsChain<any[]>): MathJsChain<Index>
4051
4113
 
4052
4114
  /**
4053
4115
  * Create a Matrix. The function creates a new math.type.Matrix object
@@ -4055,7 +4117,11 @@ declare namespace math {
4055
4117
  * in the matrix, like getting the size and getting or setting values in
4056
4118
  * the matrix. Supported storage formats are 'dense' and 'sparse'.
4057
4119
  */
4058
- matrix(format?: 'sparse' | 'dense', dataType?: string): MathJsChain
4120
+ matrix(
4121
+ this: MathJsChain<MathCollection>,
4122
+ format?: 'sparse' | 'dense',
4123
+ dataType?: string
4124
+ ): MathJsChain<Matrix>
4059
4125
 
4060
4126
  /**
4061
4127
  * Create a number or convert a string, boolean, or unit to a number.
@@ -4063,7 +4129,16 @@ declare namespace math {
4063
4129
  * @param valuelessUnit A valueless unit, used to convert a unit to a
4064
4130
  * number
4065
4131
  */
4066
- number(valuelessUnit?: Unit | string): MathJsChain
4132
+ number(
4133
+ this: MathJsChain<
4134
+ string | number | BigNumber | Fraction | boolean | Unit | null
4135
+ >,
4136
+ valuelessUnit?: Unit | string
4137
+ ): MathJsChain<number>
4138
+ number(
4139
+ this: MathJsChain<MathCollection>,
4140
+ valuelessUnit?: Unit | string
4141
+ ): MathJsChain<MathCollection>
4067
4142
 
4068
4143
  /**
4069
4144
  * Create a Sparse Matrix. The function creates a new math.type.Matrix
@@ -4072,20 +4147,26 @@ declare namespace math {
4072
4147
  * values in the matrix.
4073
4148
  * @param dataType Sparse Matrix data type
4074
4149
  */
4075
- sparse(dataType?: string): MathJsChain
4150
+ sparse(
4151
+ this: MathJsChain<MathCollection>,
4152
+ dataType?: string
4153
+ ): MathJsChain<Matrix>
4076
4154
 
4077
4155
  /**
4078
4156
  * Split a unit in an array of units whose sum is equal to the original
4079
4157
  * unit.
4080
4158
  * @param parts An array of strings or valueless units
4081
4159
  */
4082
- splitUnit(parts: Unit[]): MathJsChain
4160
+ splitUnit(this: MathJsChain<Unit>, parts: Unit[]): MathJsChain<Unit[]>
4083
4161
 
4084
4162
  /**
4085
4163
  * Create a string or convert any object into a string. Elements of
4086
4164
  * Arrays and Matrices are processed element wise.
4087
4165
  */
4088
- string(): MathJsChain
4166
+ string(
4167
+ this: MathJsChain<MathNumericType | string | Unit | null>
4168
+ ): MathJsChain<string>
4169
+ string(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
4089
4170
 
4090
4171
  /**
4091
4172
  * Create a unit. Depending on the passed arguments, the function will
@@ -4093,7 +4174,13 @@ declare namespace math {
4093
4174
  * provided, all elements will be converted to units.
4094
4175
  * @param unit The unit to be created
4095
4176
  */
4096
- unit(unit?: string): MathJsChain
4177
+ unit(this: MathJsChain<string>, unit?: string): MathJsChain<Unit>
4178
+ unit(this: MathJsChain<Unit>, unit?: string): MathJsChain<Unit>
4179
+ unit(
4180
+ this: MathJsChain<number | BigNumber>,
4181
+ unit?: string
4182
+ ): MathJsChain<Unit>
4183
+ unit(this: MathJsChain<MathCollection>, unit?: string): MathJsChain<Unit[]>
4097
4184
 
4098
4185
  /*************************************************************************
4099
4186
  * Expression functions
@@ -4103,45 +4190,64 @@ declare namespace math {
4103
4190
  * Parse and compile an expression. Returns a an object with a function
4104
4191
  * evaluate([scope]) to evaluate the compiled expression.
4105
4192
  */
4106
- compile(): MathJsChain
4193
+ compile(this: MathJsChain<MathExpression>): MathJsChain<EvalFunction>
4107
4194
 
4195
+ // TODO properly type this
4108
4196
  /**
4109
4197
  * Evaluate an expression.
4110
4198
  * @param scope Scope to read/write variables
4111
4199
  */
4112
- evaluate(scope?: object): MathJsChain
4200
+ evaluate(
4201
+ this: MathJsChain<MathExpression | Matrix>,
4202
+ scope?: object
4203
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4204
+ ): MathJsChain<any>
4205
+ evaluate(
4206
+ this: MathJsChain<MathExpression[]>,
4207
+ scope?: object
4208
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4209
+ ): MathJsChain<any[]>
4113
4210
 
4114
4211
  /**
4115
4212
  * Retrieve help on a function or data type. Help files are retrieved
4116
4213
  * from the documentation in math.expression.docs.
4117
4214
  */
4118
- help(): MathJsChain
4215
+ help(this: MathJsChain<unknown>): MathJsChain<unknown>
4119
4216
 
4120
- /**
4121
- * Parse an expression. Returns a node tree, which can be evaluated by
4122
- * invoking node.evaluate();
4123
- * @param options Available options: nodes - a set of custome nodes
4124
- */
4125
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4126
- parse(options?: any): MathJsChain
4127
4217
  /**
4128
4218
  * @param options Available options: nodes - a set of custome nodes
4129
4219
  */
4130
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4131
- parse(options?: any): MathJsChain
4220
+ parse(
4221
+ this: MathJsChain<MathExpression[]>,
4222
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4223
+ options?: any
4224
+ ): MathJsChain<MathNode[]>
4132
4225
 
4133
4226
  /**
4134
- * Create a parser. The function creates a new math.expression.Parser
4135
- * object.
4227
+ * Parse an expression. Returns a node tree, which can be evaluated by
4228
+ * invoking node.evaluate();
4229
+ * @param options Available options: nodes - a set of custome nodes
4136
4230
  */
4137
- parser(): MathJsChain
4231
+ parse(
4232
+ this: MathJsChain<MathExpression>,
4233
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4234
+ options?: any
4235
+ ): MathJsChain<MathNode>
4138
4236
 
4139
4237
  /**
4140
4238
  * Replaces variable nodes with their scoped values
4141
4239
  * @param scope Scope to read/write variables
4142
4240
  */
4143
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4144
- resolve(scope?: Record<string, any>): MathJsChain
4241
+ resolve(
4242
+ this: MathJsChain<MathNode>,
4243
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4244
+ scope?: Record<string, any>
4245
+ ): MathJsChain<MathNode>
4246
+ resolve(
4247
+ this: MathJsChain<MathNode[]>,
4248
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4249
+ scope?: Record<string, any>
4250
+ ): MathJsChain<MathNode[]>
4145
4251
 
4146
4252
  /*************************************************************************
4147
4253
  * Algebra functions
@@ -4152,23 +4258,31 @@ declare namespace math {
4152
4258
  * by default. When false, output will not be simplified.
4153
4259
  */
4154
4260
  derivative(
4261
+ this: MathJsChain<MathNode | string>,
4155
4262
  variable: MathNode | string,
4156
4263
  options?: { simplify: boolean }
4157
- ): MathJsChain
4264
+ ): MathJsChain<MathNode>
4158
4265
 
4159
4266
  /**
4160
4267
  * Solves the linear equation system by forwards substitution. Matrix
4161
4268
  * must be a lower triangular matrix.
4162
4269
  * @param b A column vector with the b values
4163
4270
  */
4164
- lsolve(b: Matrix | MathArray): MathJsChain
4271
+ lsolve(
4272
+ this: MathJsChain<Matrix>,
4273
+ b: Matrix | MathArray
4274
+ ): MathJsChain<Matrix>
4275
+ lsolve(
4276
+ this: MathJsChain<MathArray>,
4277
+ b: Matrix | MathArray
4278
+ ): MathJsChain<MathArray>
4165
4279
 
4166
4280
  /**
4167
4281
  * Calculate the Matrix LU decomposition with partial pivoting. Matrix A
4168
4282
  * is decomposed in two matrices (L, U) and a row permutation vector p
4169
4283
  * where A[p,:] = L * U
4170
4284
  */
4171
- lup(): MathJsChain
4285
+ lup(this: MathJsChain<Matrix | MathArray>): MathJsChain<LUDecomposition>
4172
4286
 
4173
4287
  /**
4174
4288
  * Solves the linear system A * x = b where A is an [n x n] matrix and b
@@ -4180,17 +4294,25 @@ declare namespace math {
4180
4294
  * see slu for details. Matrix must be a SparseMatrix.
4181
4295
  */
4182
4296
  lusolve(
4297
+ this: MathJsChain<Matrix>,
4183
4298
  b: Matrix | MathArray,
4184
4299
  order?: number,
4185
4300
  threshold?: number
4186
- ): MathJsChain
4301
+ ): MathJsChain<Matrix>
4302
+
4303
+ lusolve(
4304
+ this: MathJsChain<MathArray>,
4305
+ b: Matrix | MathArray,
4306
+ order?: number,
4307
+ threshold?: number
4308
+ ): MathJsChain<MathArray>
4187
4309
 
4188
4310
  /**
4189
4311
  * Calculate the Matrix QR decomposition. Matrix A is decomposed in two
4190
4312
  * matrices (Q, R) where Q is an orthogonal matrix and R is an upper
4191
4313
  * triangular matrix.
4192
4314
  */
4193
- qr(): MathJsChain
4315
+ qr(this: MathJsChain<Matrix | MathArray>): MathJsChain<QRDecomposition>
4194
4316
 
4195
4317
  /**
4196
4318
  * Transform a rationalizable expression in a rational fraction. If
@@ -4202,7 +4324,11 @@ declare namespace math {
4202
4324
  * @param detailed optional True if return an object, false if return
4203
4325
  * expression node (default)
4204
4326
  */
4205
- rationalize(optional?: object | boolean, detailed?: boolean): MathJsChain
4327
+ rationalize(
4328
+ this: MathJsChain<MathNode | string>,
4329
+ optional?: object | boolean,
4330
+ detailed?: boolean
4331
+ ): MathJsChain<MathNode>
4206
4332
 
4207
4333
  /**
4208
4334
  * Simplify an expression tree.
@@ -4212,8 +4338,13 @@ declare namespace math {
4212
4338
  * can be specified as an object, string, or function.
4213
4339
  * @param scope Scope to variables
4214
4340
  */
4215
- simplify(rules?: SimplifyRule[], scope?: object): MathJsChain
4341
+ simplify(
4342
+ this: MathJsChain<MathNode | string>,
4343
+ rules?: SimplifyRule[],
4344
+ scope?: object
4345
+ ): MathJsChain<MathNode>
4216
4346
 
4347
+ // TODO check that this should even be here...
4217
4348
  simplifyCore(expr: MathNode): MathNode
4218
4349
 
4219
4350
  /**
@@ -4231,14 +4362,25 @@ declare namespace math {
4231
4362
  * with more than 10*sqr(columns) entries.
4232
4363
  * @param threshold Partial pivoting threshold (1 for partial pivoting)
4233
4364
  */
4234
- slu(order: number, threshold: number): MathJsChain
4365
+ slu(
4366
+ this: MathJsChain<Matrix>,
4367
+ order: number,
4368
+ threshold: number
4369
+ ): MathJsChain<SLUDecomposition>
4235
4370
 
4236
4371
  /**
4237
4372
  * Solves the linear equation system by backward substitution. Matrix
4238
4373
  * must be an upper triangular matrix. U * x = b
4239
4374
  * @param b A column vector with the b values
4240
4375
  */
4241
- usolve(b: Matrix | MathArray): MathJsChain
4376
+ usolve(
4377
+ this: MathJsChain<Matrix>,
4378
+ b: Matrix | MathArray
4379
+ ): MathJsChain<Matrix>
4380
+ usolve(
4381
+ this: MathJsChain<MathArray>,
4382
+ b: Matrix | MathArray
4383
+ ): MathJsChain<MathArray>
4242
4384
 
4243
4385
  /*************************************************************************
4244
4386
  * Arithmetic functions
@@ -4248,14 +4390,21 @@ declare namespace math {
4248
4390
  * Calculate the absolute value of a number. For matrices, the function
4249
4391
  * is evaluated element wise.
4250
4392
  */
4251
- abs(): MathJsChain
4393
+ abs(this: MathJsChain<number>): MathJsChain<number>
4394
+ abs(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4395
+ abs(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4396
+ abs(this: MathJsChain<Complex>): MathJsChain<Complex>
4397
+ abs(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4398
+ abs(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4399
+ abs(this: MathJsChain<Unit>): MathJsChain<Unit>
4252
4400
 
4253
4401
  /**
4254
4402
  * Add two values, x + y. For matrices, the function is evaluated
4255
4403
  * element wise.
4256
4404
  * @param y Second value to add
4257
4405
  */
4258
- add(y: MathType): MathJsChain
4406
+ add<T extends MathType>(this: MathJsChain<T>, y: T): MathJsChain<T>
4407
+ add(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4259
4408
 
4260
4409
  /**
4261
4410
  * Apply a function that maps an array to a scalar along a given axis of the
@@ -4266,10 +4415,11 @@ declare namespace math {
4266
4415
  * array or 1-d matrix as an input and return a number.
4267
4416
  * @returns The residual matrix with the function applied over some dimension.
4268
4417
  */
4269
- apply(
4418
+ apply<T extends MathCollection>(
4419
+ this: MathJsChain<T>,
4270
4420
  dim: number,
4271
4421
  callback: (array: Array<MathType> | Matrix) => number
4272
- ): MathJsChain
4422
+ ): MathJsChain<T>
4273
4423
 
4274
4424
  /**
4275
4425
  * Calculate the cubic root of a value. For matrices, the function is
@@ -4278,7 +4428,17 @@ declare namespace math {
4278
4428
  * a number or complex number. If true, all complex roots are returned,
4279
4429
  * if false (default) the principal root is returned.
4280
4430
  */
4281
- cbrt(allRoots?: boolean): MathJsChain
4431
+ cbrt(this: MathJsChain<number>, allRoots?: boolean): MathJsChain<number>
4432
+ cbrt(
4433
+ this: MathJsChain<BigNumber>,
4434
+ allRoots?: boolean
4435
+ ): MathJsChain<BigNumber>
4436
+ cbrt(this: MathJsChain<Complex>, allRoots?: boolean): MathJsChain<Complex>
4437
+ cbrt(
4438
+ this: MathJsChain<MathArray>,
4439
+ allRoots?: boolean
4440
+ ): MathJsChain<MathArray>
4441
+ cbrt(this: MathJsChain<Matrix>, allRoots?: boolean): MathJsChain<Matrix>
4282
4442
 
4283
4443
  // Rounding functions grouped for similarity
4284
4444
 
@@ -4288,28 +4448,56 @@ declare namespace math {
4288
4448
  * function is evaluated element wise.
4289
4449
  * @param n Number of decimals Default value: 0.
4290
4450
  */
4291
- ceil(n?: number | BigNumber | MathCollection): MathJsChain
4451
+ ceil(
4452
+ this: MathJsChain<MathNumericType>,
4453
+ n?: number | BigNumber | MathCollection
4454
+ ): MathJsChain<MathNumericType>
4455
+ ceil(
4456
+ this: MathJsChain<MathCollection>,
4457
+ n?: number | BigNumber | MathCollection
4458
+ ): MathJsChain<MathCollection>
4292
4459
 
4293
4460
  /**
4294
4461
  * Round a value towards zero. For matrices, the function is evaluated
4295
4462
  * element wise.
4296
4463
  * @param n Number of decimals Default value: 0.
4297
4464
  */
4298
- fix(n?: number | BigNumber | MathCollection): MathJsChain
4465
+ fix(
4466
+ this: MathJsChain<MathNumericType>,
4467
+ n?: number | BigNumber | MathCollection
4468
+ ): MathJsChain<MathNumericType>
4469
+ fix(
4470
+ this: MathJsChain<MathCollection>,
4471
+ n?: number | BigNumber | MathCollection
4472
+ ): MathJsChain<MathCollection>
4299
4473
 
4300
4474
  /**
4301
4475
  * Round a value towards minus infinity. For matrices, the function is
4302
4476
  * evaluated element wise.
4303
4477
  * @param n Number of decimals Default value: 0.
4304
4478
  */
4305
- floor(n?: number | BigNumber | MathCollection): MathJsChain
4479
+ floor(
4480
+ this: MathJsChain<MathNumericType>,
4481
+ n?: number | BigNumber | MathCollection
4482
+ ): MathJsChain<MathNumericType>
4483
+ floor(
4484
+ this: MathJsChain<MathCollection>,
4485
+ n?: number | BigNumber | MathCollection
4486
+ ): MathJsChain<MathCollection>
4306
4487
 
4307
4488
  /**
4308
4489
  * Round a value towards the nearest integer. For matrices, the function
4309
4490
  * is evaluated element wise.
4310
4491
  * @param n Number of decimals Default value: 0.
4311
4492
  */
4312
- round(n?: number | BigNumber | MathCollection): MathJsChain
4493
+ round(
4494
+ this: MathJsChain<MathNumericType>,
4495
+ n?: number | BigNumber | MathCollection
4496
+ ): MathJsChain<MathNumericType>
4497
+ round(
4498
+ this: MathJsChain<MathCollection>,
4499
+ n?: number | BigNumber | MathCollection
4500
+ ): MathJsChain<MathCollection>
4313
4501
 
4314
4502
  // End of rounding group
4315
4503
 
@@ -4317,52 +4505,79 @@ declare namespace math {
4317
4505
  * Compute the cube of a value, x * x * x. For matrices, the function is
4318
4506
  * evaluated element wise.
4319
4507
  */
4320
- cube(): MathJsChain
4508
+ cube(this: MathJsChain<number>): MathJsChain<number>
4509
+ cube(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4510
+ cube(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4511
+ cube(this: MathJsChain<Complex>): MathJsChain<Complex>
4512
+ cube(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4513
+ cube(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4514
+ cube(this: MathJsChain<Unit>): MathJsChain<Unit>
4321
4515
 
4322
4516
  /**
4323
4517
  * Divide two values, x / y. To divide matrices, x is multiplied with
4324
4518
  * the inverse of y: x * inv(y).
4325
4519
  * @param y Denominator
4326
4520
  */
4327
- divide(y: MathType): MathJsChain
4521
+ divide(this: MathJsChain<Unit>, y: Unit): MathJsChain<Unit | number>
4522
+ divide(this: MathJsChain<Unit>, y: number): MathJsChain<Unit>
4523
+ divide(this: MathJsChain<number>, y: number): MathJsChain<number>
4524
+ divide(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4328
4525
 
4329
4526
  /**
4330
4527
  * Divide two matrices element wise. The function accepts both matrices
4331
4528
  * and scalar values.
4332
4529
  * @param y Denominator
4333
4530
  */
4334
- dotDivide(y: MathType): MathJsChain
4531
+ dotDivide(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4335
4532
 
4336
4533
  /**
4337
4534
  * Multiply two matrices element wise. The function accepts both
4338
4535
  * matrices and scalar values.
4339
4536
  * @param y Right hand value
4340
4537
  */
4341
- dotMultiply(y: MathType): MathJsChain
4538
+ dotMultiply(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4342
4539
 
4343
4540
  /**
4344
4541
  * Calculates the power of x to y element wise.
4345
4542
  * @param y The exponent
4346
4543
  */
4347
- dotPow(y: MathType): MathJsChain
4544
+ dotPow(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4348
4545
 
4349
4546
  /**
4350
4547
  * Calculate the exponent of a value. For matrices, the function is
4351
4548
  * evaluated element wise.
4352
4549
  */
4353
- exp(): MathJsChain
4550
+ exp(this: MathJsChain<number>): MathJsChain<number>
4551
+ exp(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4552
+ exp(this: MathJsChain<Complex>): MathJsChain<Complex>
4553
+ exp(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4554
+ exp(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4354
4555
 
4355
4556
  /**
4356
4557
  * Calculate the value of subtracting 1 from the exponential value. For
4357
4558
  * matrices, the function is evaluated element wise.
4358
4559
  */
4359
- expm1(): MathJsChain
4560
+ expm1(this: MathJsChain<number>): MathJsChain<number>
4561
+ expm1(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4562
+ expm1(this: MathJsChain<Complex>): MathJsChain<Complex>
4563
+ expm1(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4564
+ expm1(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4360
4565
 
4361
4566
  /**
4362
4567
  * Calculate the greatest common divisor for two or more values or
4363
4568
  * arrays. For matrices, the function is evaluated element wise.
4364
4569
  */
4365
- gcd(): MathJsChain
4570
+ gcd(this: MathJsChain<number[]>, ...args: number[]): MathJsChain<number>
4571
+ gcd(
4572
+ this: MathJsChain<BigNumber[]>,
4573
+ ...args: BigNumber[]
4574
+ ): MathJsChain<BigNumber>
4575
+ gcd(this: MathJsChain<Complex[]>, ...args: Fraction[]): MathJsChain<Complex>
4576
+ gcd(
4577
+ this: MathJsChain<MathArray[]>,
4578
+ ...args: MathArray[]
4579
+ ): MathJsChain<MathArray>
4580
+ gcd(this: MathJsChain<Matrix[]>, ...args: Matrix[]): MathJsChain<Matrix>
4366
4581
 
4367
4582
  /**
4368
4583
  * Calculate the hypotenusa of a list with values. The hypotenusa is
@@ -4370,7 +4585,8 @@ declare namespace math {
4370
4585
  * matrix input, the hypotenusa is calculated for all values in the
4371
4586
  * matrix.
4372
4587
  */
4373
- hypot(): MathJsChain
4588
+ hypot(this: MathJsChain<number[]>): MathJsChain<number>
4589
+ hypot(this: MathJsChain<BigNumber[]>): MathJsChain<BigNumber>
4374
4590
 
4375
4591
  /**
4376
4592
  * Calculate the least common multiple for two or more values or arrays.
@@ -4378,7 +4594,10 @@ declare namespace math {
4378
4594
  * the function is evaluated element wise.
4379
4595
  * @param b An integer number
4380
4596
  */
4381
- lcm(b: number | BigNumber | MathCollection): MathJsChain
4597
+ lcm(this: MathJsChain<number>, b: number): MathJsChain<number>
4598
+ lcm(this: MathJsChain<BigNumber>, b: BigNumber): MathJsChain<BigNumber>
4599
+ lcm(this: MathJsChain<MathArray>, b: MathArray): MathJsChain<MathArray>
4600
+ lcm(this: MathJsChain<Matrix>, b: Matrix): MathJsChain<Matrix>
4382
4601
 
4383
4602
  /**
4384
4603
  * Calculate the logarithm of a value. For matrices, the function is
@@ -4386,24 +4605,58 @@ declare namespace math {
4386
4605
  * @param base Optional base for the logarithm. If not provided, the
4387
4606
  * natural logarithm of x is calculated. Default value: e.
4388
4607
  */
4389
- log(base?: number | BigNumber | Complex): MathJsChain
4608
+ log<T extends number | BigNumber | Complex | MathCollection>(
4609
+ this: MathJsChain<T>,
4610
+ base?: number | BigNumber | Complex
4611
+ ): MathJsChain<NoLiteralType<T>>
4390
4612
 
4391
4613
  /**
4392
4614
  * Calculate the 10-base of a value. This is the same as calculating
4393
4615
  * log(x, 10). For matrices, the function is evaluated element wise.
4394
4616
  */
4395
- log10(): MathJsChain
4617
+
4618
+ log10(this: MathJsChain<number>): MathJsChain<number>
4619
+ log10(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4620
+ log10(this: MathJsChain<Complex>): MathJsChain<Complex>
4621
+ log10(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4622
+ log10(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4396
4623
 
4397
4624
  /**
4398
4625
  * Calculate the logarithm of a value+1. For matrices, the function is
4399
4626
  * evaluated element wise.
4400
4627
  */
4401
- log1p(base?: number | BigNumber | Complex): MathJsChain
4628
+ log1p(
4629
+ this: MathJsChain<number>,
4630
+ base?: number | BigNumber | Complex
4631
+ ): MathJsChain<number>
4632
+ log1p(
4633
+ this: MathJsChain<BigNumber>,
4634
+ base?: number | BigNumber | Complex
4635
+ ): MathJsChain<BigNumber>
4636
+ log1p(
4637
+ this: MathJsChain<Complex>,
4638
+ base?: number | BigNumber | Complex
4639
+ ): MathJsChain<Complex>
4640
+ log1p(
4641
+ this: MathJsChain<MathArray>,
4642
+ base?: number | BigNumber | Complex
4643
+ ): MathJsChain<MathArray>
4644
+ log1p(
4645
+ this: MathJsChain<Matrix>,
4646
+ base?: number | BigNumber | Complex
4647
+ ): MathJsChain<Matrix>
4648
+
4402
4649
  /**
4403
4650
  * Calculate the 2-base of a value. This is the same as calculating
4404
4651
  * log(x, 2). For matrices, the function is evaluated element wise.
4405
4652
  */
4406
- log2(): MathJsChain
4653
+
4654
+ log2(this: MathJsChain<number>): MathJsChain<number>
4655
+ log2(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4656
+ log2(this: MathJsChain<Complex>): MathJsChain<Complex>
4657
+ log2(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4658
+ log2(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4659
+
4407
4660
  /**
4408
4661
  * Calculates the modulus, the remainder of an integer division. For
4409
4662
  * matrices, the function is evaluated element wise. The modulus is
@@ -4411,14 +4664,23 @@ declare namespace math {
4411
4664
  * @see http://en.wikipedia.org/wiki/Modulo_operation.
4412
4665
  * @param y Divisor
4413
4666
  */
4414
- mod(y: number | BigNumber | Fraction | MathCollection): MathJsChain
4667
+ mod<T extends number | BigNumber | Fraction | MathCollection>(
4668
+ this: MathJsChain<T>,
4669
+ y: number | BigNumber | Fraction | MathCollection
4670
+ ): MathJsChain<NoLiteralType<T>>
4415
4671
 
4416
4672
  /**
4417
4673
  * Multiply two values, x * y. The result is squeezed. For matrices, the
4418
4674
  * matrix product is calculated.
4419
4675
  * @param y The second value to multiply
4420
4676
  */
4421
- multiply(y: MathType): MathJsChain
4677
+ multiply<T extends Matrix | MathArray>(
4678
+ this: MathJsChain<T>,
4679
+ y: MathType
4680
+ ): MathJsChain<T>
4681
+ multiply(this: MathJsChain<Unit>, y: Unit): MathJsChain<Unit>
4682
+ multiply(this: MathJsChain<number>, y: number): MathJsChain<number>
4683
+ multiply(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4422
4684
 
4423
4685
  /**
4424
4686
  * Calculate the norm of a number, vector or matrix. The second
@@ -4427,7 +4689,10 @@ declare namespace math {
4427
4689
  * -Infinity. Supported strings are: 'inf', '-inf', and 'fro' (The
4428
4690
  * Frobenius norm) Default value: 2.
4429
4691
  */
4430
- norm(p?: number | BigNumber | string): MathJsChain
4692
+ norm(
4693
+ this: MathJsChain<number | BigNumber | Complex | MathCollection>,
4694
+ p?: number | BigNumber | string
4695
+ ): MathJsChain<number | BigNumber>
4431
4696
 
4432
4697
  /**
4433
4698
  * Calculate the nth root of a value. The principal nth root of a
@@ -4435,14 +4700,20 @@ declare namespace math {
4435
4700
  * x^root = A For matrices, the function is evaluated element wise.
4436
4701
  * @param root The root. Default value: 2.
4437
4702
  */
4438
- nthRoot(root?: number | BigNumber): MathJsChain
4703
+ nthRoot(
4704
+ this: MathJsChain<number | BigNumber | MathCollection | Complex>,
4705
+ root?: number | BigNumber
4706
+ ): MathJsChain<number | Complex | MathCollection>
4439
4707
 
4440
4708
  /**
4441
4709
  * Calculates the power of x to y, x ^ y. Matrix exponentiation is
4442
4710
  * supported for square matrices x, and positive integer exponents y.
4443
4711
  * @param y The exponent
4444
4712
  */
4445
- pow(y: number | BigNumber): MathJsChain
4713
+ pow(
4714
+ this: MathJsChain<MathType>,
4715
+ y: number | BigNumber | Complex
4716
+ ): MathJsChain<MathType>
4446
4717
 
4447
4718
  /**
4448
4719
  * Compute the sign of a value. The sign of a value x is: 1 when x > 1
@@ -4451,26 +4722,46 @@ declare namespace math {
4451
4722
  * @param x The number for which to determine the sign
4452
4723
  * @returns The sign of x
4453
4724
  */
4454
- sign(x: number | BigNumber): MathJsChain
4725
+ sign(this: MathJsChain<number>): MathJsChain<number>
4726
+ sign(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4727
+ sign(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4728
+ sign(this: MathJsChain<Complex>): MathJsChain<Complex>
4729
+ sign(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4730
+ sign(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4731
+ sign(this: MathJsChain<Unit>): MathJsChain<Unit>
4455
4732
 
4456
4733
  /**
4457
4734
  * Calculate the square root of a value. For matrices, the function is
4458
4735
  * evaluated element wise.
4459
4736
  */
4460
- sqrt(): MathJsChain
4737
+
4738
+ sqrt(this: MathJsChain<number>): MathJsChain<number>
4739
+ sqrt(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4740
+ sqrt(this: MathJsChain<Complex>): MathJsChain<Complex>
4741
+ sqrt(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4742
+ sqrt(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4743
+ sqrt(this: MathJsChain<Unit>): MathJsChain<Unit>
4461
4744
 
4462
4745
  /**
4463
4746
  * Compute the square of a value, x * x. For matrices, the function is
4464
4747
  * evaluated element wise.
4465
4748
  */
4466
- square(): MathJsChain
4749
+
4750
+ square(this: MathJsChain<number>): MathJsChain<number>
4751
+ square(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4752
+ square(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4753
+ square(this: MathJsChain<Complex>): MathJsChain<Complex>
4754
+ square(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4755
+ square(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4756
+ square(this: MathJsChain<Unit>): MathJsChain<Unit>
4467
4757
 
4468
4758
  /**
4469
4759
  * Subtract two values, x - y. For matrices, the function is evaluated
4470
4760
  * element wise.
4471
4761
  * @param y Value to subtract from x
4472
4762
  */
4473
- subtract(y: MathType): MathJsChain
4763
+ subtract<T extends MathType>(this: MathJsChain<T>, y: T): MathJsChain<T>
4764
+ subtract(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4474
4765
 
4475
4766
  /**
4476
4767
  * Inverse the sign of a value, apply a unary minus operation. For
@@ -4478,21 +4769,39 @@ declare namespace math {
4478
4769
  * strings will be converted to a number. For complex numbers, both real
4479
4770
  * and complex value are inverted.
4480
4771
  */
4481
- unaryMinus(): MathJsChain
4772
+
4773
+ unaryMinus(this: MathJsChain<number>): MathJsChain<number>
4774
+ unaryMinus(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4775
+ unaryMinus(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4776
+ unaryMinus(this: MathJsChain<Complex>): MathJsChain<Complex>
4777
+ unaryMinus(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4778
+ unaryMinus(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4779
+ unaryMinus(this: MathJsChain<Unit>): MathJsChain<Unit>
4482
4780
 
4483
4781
  /**
4484
4782
  * Unary plus operation. Boolean values and strings will be converted to
4485
4783
  * a number, numeric values will be returned as is. For matrices, the
4486
4784
  * function is evaluated element wise.
4487
4785
  */
4488
- unaryPlus(): MathJsChain
4786
+
4787
+ unaryPlus(this: MathJsChain<number>): MathJsChain<number>
4788
+ unaryPlus(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4789
+ unaryPlus(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4790
+ unaryPlus(this: MathJsChain<string>): MathJsChain<string>
4791
+ unaryPlus(this: MathJsChain<Complex>): MathJsChain<Complex>
4792
+ unaryPlus(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4793
+ unaryPlus(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4794
+ unaryPlus(this: MathJsChain<Unit>): MathJsChain<Unit>
4489
4795
 
4490
4796
  /**
4491
4797
  * Calculate the extended greatest common divisor for two values. See
4492
4798
  * http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm.
4493
4799
  * @param b An integer number
4494
4800
  */
4495
- xgcd(b: number | BigNumber): MathJsChain
4801
+ xgcd(
4802
+ this: MathJsChain<number | BigNumber>,
4803
+ b: number | BigNumber
4804
+ ): MathJsChain<MathArray>
4496
4805
 
4497
4806
  /*************************************************************************
4498
4807
  * Bitwise functions
@@ -4503,14 +4812,21 @@ declare namespace math {
4503
4812
  * evaluated element wise.
4504
4813
  * @param y Second value to and
4505
4814
  */
4506
- bitAnd(y: number | BigNumber | MathCollection): MathJsChain
4815
+ bitAnd<T extends number | BigNumber | MathCollection>(
4816
+ this: MathJsChain<T>,
4817
+ y: number | BigNumber | MathCollection
4818
+ ): MathJsChain<NoLiteralType<T>>
4507
4819
 
4508
4820
  /**
4509
4821
  * Bitwise NOT value, ~x. For matrices, the function is evaluated
4510
4822
  * element wise. For units, the function is evaluated on the best prefix
4511
4823
  * base.
4512
4824
  */
4513
- bitNot(): MathJsChain
4825
+
4826
+ bitNot(this: MathJsChain<number>): MathJsChain<number>
4827
+ bitNot(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4828
+ bitNot(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4829
+ bitNot(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4514
4830
 
4515
4831
  /**
4516
4832
  * Bitwise OR two values, x | y. For matrices, the function is evaluated
@@ -4518,14 +4834,20 @@ declare namespace math {
4518
4834
  * print base.
4519
4835
  * @param y Second value to or
4520
4836
  */
4521
- bitOr(y: number | BigNumber | MathCollection): MathJsChain
4837
+ bitOr(this: MathJsChain<number>, y: number): MathJsChain<number>
4838
+ bitOr(this: MathJsChain<BigNumber>, y: BigNumber): MathJsChain<BigNumber>
4839
+ bitOr(this: MathJsChain<MathArray>, y: MathArray): MathJsChain<MathArray>
4840
+ bitOr(this: MathJsChain<Matrix>, y: Matrix): MathJsChain<Matrix>
4522
4841
 
4523
4842
  /**
4524
4843
  * Bitwise XOR two values, x ^ y. For matrices, the function is
4525
4844
  * evaluated element wise.
4526
4845
  * @param y Second value to xor
4527
4846
  */
4528
- bitXor(y: number | BigNumber | MathCollection): MathJsChain
4847
+ bitXor<T extends number | BigNumber | MathCollection>(
4848
+ this: MathJsChain<T>,
4849
+ y: number | BigNumber | MathCollection
4850
+ ): MathJsChain<NoLiteralType<T>>
4529
4851
 
4530
4852
  /**
4531
4853
  * Bitwise left logical shift of a value x by y number of bits, x << y.
@@ -4533,7 +4855,10 @@ declare namespace math {
4533
4855
  * function is evaluated on the best prefix base.
4534
4856
  * @param y Amount of shifts
4535
4857
  */
4536
- leftShift(y: number | BigNumber): MathJsChain
4858
+ leftShift<T extends number | BigNumber | MathCollection>(
4859
+ this: MathJsChain<T>,
4860
+ y: number | BigNumber
4861
+ ): MathJsChain<NoLiteralType<T>>
4537
4862
 
4538
4863
  /**
4539
4864
  * Bitwise right arithmetic shift of a value x by y number of bits, x >>
@@ -4541,7 +4866,10 @@ declare namespace math {
4541
4866
  * the function is evaluated on the best prefix base.
4542
4867
  * @param y Amount of shifts
4543
4868
  */
4544
- rightArithShift(y: number | BigNumber): MathJsChain
4869
+ rightArithShift<T extends number | BigNumber | MathCollection>(
4870
+ this: MathJsChain<T>,
4871
+ y: number | BigNumber
4872
+ ): MathJsChain<NoLiteralType<T>>
4545
4873
 
4546
4874
  /**
4547
4875
  * Bitwise right logical shift of value x by y number of bits, x >>> y.
@@ -4549,7 +4877,10 @@ declare namespace math {
4549
4877
  * function is evaluated on the best prefix base.
4550
4878
  * @param y Amount of shifts
4551
4879
  */
4552
- rightLogShift(y: number): MathJsChain
4880
+ rightLogShift<T extends number | MathCollection>(
4881
+ this: MathJsChain<T>,
4882
+ y: number
4883
+ ): MathJsChain<NoLiteralType<T>>
4553
4884
 
4554
4885
  /*************************************************************************
4555
4886
  * Combinatorics functions
@@ -4561,21 +4892,28 @@ declare namespace math {
4561
4892
  * takes integer arguments. The following condition must be enforced: n
4562
4893
  * >= 0
4563
4894
  */
4564
- bellNumbers(): MathJsChain
4895
+
4896
+ bellNumbers(this: MathJsChain<number>): MathJsChain<number>
4897
+ bellNumbers(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4565
4898
 
4566
4899
  /**
4567
4900
  * The Catalan Numbers enumerate combinatorial structures of many
4568
4901
  * different types. catalan only takes integer arguments. The following
4569
4902
  * condition must be enforced: n >= 0
4570
4903
  */
4571
- catalan(): MathJsChain
4904
+
4905
+ catalan(this: MathJsChain<number>): MathJsChain<number>
4906
+ catalan(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4572
4907
 
4573
4908
  /**
4574
4909
  * The composition counts of n into k parts. Composition only takes
4575
4910
  * integer arguments. The following condition must be enforced: k <= n.
4576
4911
  * @param k Number of objects in the subset
4577
4912
  */
4578
- composition(k: number | BigNumber): MathJsChain
4913
+ composition<T extends number | BigNumber>(
4914
+ this: MathJsChain<T>,
4915
+ k: number | BigNumber
4916
+ ): MathJsChain<NoLiteralType<T>>
4579
4917
 
4580
4918
  /**
4581
4919
  * The Stirling numbers of the second kind, counts the number of ways to
@@ -4585,7 +4923,10 @@ declare namespace math {
4585
4923
  * 1
4586
4924
  * @param k Number of objects in the subset
4587
4925
  */
4588
- stirlingS2(k: number | BigNumber): MathJsChain
4926
+ stirlingS2<T extends number | BigNumber>(
4927
+ this: MathJsChain<T>,
4928
+ k: number | BigNumber
4929
+ ): MathJsChain<NoLiteralType<T>>
4589
4930
 
4590
4931
  /*************************************************************************
4591
4932
  * Complex functions
@@ -4596,28 +4937,38 @@ declare namespace math {
4596
4937
  * the argument is computed as atan2(b, a). For matrices, the function
4597
4938
  * is evaluated element wise.
4598
4939
  */
4599
- arg(): MathJsChain
4940
+
4941
+ arg(this: MathJsChain<number | Complex>): MathJsChain<number>
4942
+ arg(this: MathJsChain<BigNumber | Complex>): MathJsChain<BigNumber>
4943
+ arg(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4944
+ arg(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4600
4945
 
4601
4946
  /**
4602
4947
  * Compute the complex conjugate of a complex value. If x = a+bi, the
4603
4948
  * complex conjugate of x is a - bi. For matrices, the function is
4604
4949
  * evaluated element wise.
4605
4950
  */
4606
- conj(): MathJsChain
4951
+ conj<T extends number | BigNumber | Complex | MathCollection>(
4952
+ this: MathJsChain<T>
4953
+ ): MathJsChain<NoLiteralType<T>>
4607
4954
 
4608
4955
  /**
4609
4956
  * Get the imaginary part of a complex number. For a complex number a +
4610
4957
  * bi, the function returns b. For matrices, the function is evaluated
4611
4958
  * element wise.
4612
4959
  */
4613
- im(): MathJsChain
4960
+ im(this: MathJsChain<number | Complex>): MathJsChain<number>
4961
+ im(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4962
+ im(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
4614
4963
 
4615
4964
  /**
4616
4965
  * Get the real part of a complex number. For a complex number a + bi,
4617
4966
  * the function returns a. For matrices, the function is evaluated
4618
4967
  * element wise.
4619
4968
  */
4620
- re(): MathJsChain
4969
+ re(this: MathJsChain<number | Complex>): MathJsChain<number>
4970
+ re(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4971
+ re(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
4621
4972
 
4622
4973
  /*************************************************************************
4623
4974
  * Geometry functions
@@ -4633,7 +4984,10 @@ declare namespace math {
4633
4984
  * c)
4634
4985
  * @param y Coordinates of the second point
4635
4986
  */
4636
- distance(y: MathCollection | object): MathJsChain
4987
+ distance(
4988
+ this: MathJsChain<MathCollection | object>,
4989
+ y: MathCollection | object
4990
+ ): MathJsChain<number | BigNumber>
4637
4991
 
4638
4992
  /**
4639
4993
  * Calculates the point of intersection of two lines in two or three
@@ -4649,10 +5003,11 @@ declare namespace math {
4649
5003
  * the calculation is for line and plane
4650
5004
  */
4651
5005
  intersect(
5006
+ this: MathJsChain<MathCollection>,
4652
5007
  x: MathCollection,
4653
5008
  y: MathCollection,
4654
5009
  z: MathCollection
4655
- ): MathJsChain
5010
+ ): MathJsChain<MathArray>
4656
5011
 
4657
5012
  /*************************************************************************
4658
5013
  * Logical functions
@@ -4664,13 +5019,18 @@ declare namespace math {
4664
5019
  * element wise.
4665
5020
  * @param y Second value to and
4666
5021
  */
4667
- and(y: number | BigNumber | Complex | Unit | MathCollection): MathJsChain
5022
+ and(
5023
+ this: MathJsChain<number | BigNumber | Complex | Unit | MathCollection>,
5024
+ y: number | BigNumber | Complex | Unit | MathCollection
5025
+ ): MathJsChain<boolean | MathCollection>
4668
5026
 
4669
5027
  /**
4670
5028
  * Logical not. Flips boolean value of a given parameter. For matrices,
4671
5029
  * the function is evaluated element wise.
4672
5030
  */
4673
- not(): MathJsChain
5031
+ not(
5032
+ this: MathJsChain<number | BigNumber | Complex | Unit | MathCollection>
5033
+ ): MathJsChain<boolean | MathCollection>
4674
5034
 
4675
5035
  /**
4676
5036
  * Logical or. Test if at least one value is defined with a
@@ -4678,7 +5038,10 @@ declare namespace math {
4678
5038
  * element wise.
4679
5039
  * @param y Second value to or
4680
5040
  */
4681
- or(y: number | BigNumber | Complex | Unit | MathCollection): MathJsChain
5041
+ or(
5042
+ this: MathJsChain<number | BigNumber | Complex | Unit | MathCollection>,
5043
+ y: number | BigNumber | Complex | Unit | MathCollection
5044
+ ): MathJsChain<boolean | MathCollection>
4682
5045
 
4683
5046
  /**
4684
5047
  * Logical xor. Test whether one and only one value is defined with a
@@ -4686,7 +5049,10 @@ declare namespace math {
4686
5049
  * element wise.
4687
5050
  * @param y Second value to xor
4688
5051
  */
4689
- xor(y: number | BigNumber | Complex | Unit | MathCollection): MathJsChain
5052
+ xor(
5053
+ this: MathJsChain<number | BigNumber | Complex | Unit | MathCollection>,
5054
+ y: number | BigNumber | Complex | Unit | MathCollection
5055
+ ): MathJsChain<boolean | MathCollection>
4690
5056
 
4691
5057
  /*************************************************************************
4692
5058
  * Matrix functions
@@ -4697,7 +5063,10 @@ declare namespace math {
4697
5063
  * dimension over which to concatenate the matrices. By default the last
4698
5064
  * dimension of the matrices.
4699
5065
  */
4700
- concat(): MathJsChain
5066
+
5067
+ concat(
5068
+ this: MathJsChain<Array<MathCollection | number | BigNumber>>
5069
+ ): MathJsChain<MathCollection>
4701
5070
 
4702
5071
  /**
4703
5072
  * Calculate the cross product for two vectors in three dimensional
@@ -4706,12 +5075,16 @@ declare namespace math {
4706
5075
  * * b2 - a2 * b1 ]
4707
5076
  * @param y Second vector
4708
5077
  */
4709
- cross(y: MathCollection): MathJsChain
5078
+ cross(
5079
+ this: MathJsChain<MathCollection>,
5080
+ y: MathCollection
5081
+ ): MathJsChain<Matrix | MathArray>
4710
5082
 
4711
5083
  /**
4712
5084
  * Calculate the determinant of a matrix.
4713
5085
  */
4714
- det(): MathJsChain
5086
+
5087
+ det(this: MathJsChain<MathCollection>): MathJsChain<number>
4715
5088
 
4716
5089
  /**
4717
5090
  * Create a diagonal matrix or retrieve the diagonal of a matrix. When x
@@ -4724,8 +5097,15 @@ declare namespace math {
4724
5097
  * retrieved. Default value: 0.
4725
5098
  * @param format The matrix storage format. Default value: 'dense'.
4726
5099
  */
4727
- diag(format?: string): MathJsChain
4728
- diag(k: number | BigNumber, format?: string): MathJsChain
5100
+ diag(
5101
+ this: MathJsChain<MathCollection>,
5102
+ format?: string
5103
+ ): MathJsChain<Matrix>
5104
+ diag(
5105
+ this: MathJsChain<MathCollection>,
5106
+ k: number | BigNumber,
5107
+ format?: string
5108
+ ): MathJsChain<Matrix | MathArray>
4729
5109
 
4730
5110
  /**
4731
5111
  * Calculate the dot product of two vectors. The dot product of A = [a1,
@@ -4733,7 +5113,10 @@ declare namespace math {
4733
5113
  * B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn
4734
5114
  * @param y Second vector
4735
5115
  */
4736
- dot(y: MathCollection): MathJsChain
5116
+ dot(
5117
+ this: MathJsChain<MathCollection>,
5118
+ y: MathCollection
5119
+ ): MathJsChain<number>
4737
5120
 
4738
5121
  /**
4739
5122
  * Compute the matrix exponential, expm(A) = e^A. The matrix must be
@@ -4742,52 +5125,77 @@ declare namespace math {
4742
5125
  * approximant with scaling and squaring; see “Nineteen Dubious Ways to
4743
5126
  * Compute the Exponential of a Matrix,” by Moler and Van Loan.
4744
5127
  */
4745
- expm(): MathJsChain
5128
+
5129
+ expm(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4746
5130
 
4747
5131
  /**
4748
5132
  * Create a 2-dimensional identity matrix with size m x n or n x n. The
4749
5133
  * matrix has ones on the diagonal and zeros elsewhere.
4750
5134
  * @param format The Matrix storage format
4751
5135
  */
4752
- identity(format?: string): MathJsChain
5136
+ identity(
5137
+ this: MathJsChain<number | number[] | Matrix | MathArray>,
5138
+ format?: string
5139
+ ): MathJsChain<Matrix | MathArray | number>
5140
+
4753
5141
  /**
4754
5142
  * @param n The y dimension for the matrix
4755
5143
  * @param format The Matrix storage format
4756
5144
  */
4757
- identity(n: number, format?: string): MathJsChain
5145
+ identity(
5146
+ this: MathJsChain<number>,
5147
+ n: number,
5148
+ format?: string
5149
+ ): MathJsChain<Matrix | MathArray | number>
4758
5150
 
4759
5151
  /**
4760
5152
  * Filter the items in an array or one dimensional matrix.
4761
5153
  */
4762
5154
  filter(
4763
- test: // eslint-disable-next-line @typescript-eslint/no-explicit-any
4764
- ((value: any, index: any, matrix: Matrix | MathArray) => boolean) | RegExp
4765
- ): MathJsChain
5155
+ this: MathJsChain<Matrix | MathArray | string[]>,
5156
+ test:
5157
+ | ((
5158
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5159
+ value: any,
5160
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5161
+ index: any,
5162
+ matrix: Matrix | MathArray | string[]
5163
+ ) => boolean)
5164
+ | RegExp
5165
+ ): MathJsChain<Matrix | MathArray>
4766
5166
 
4767
5167
  /**
4768
5168
  * Flatten a multi dimensional matrix into a single dimensional matrix.
4769
5169
  */
4770
- flatten(): MathJsChain
5170
+
5171
+ flatten<T extends MathCollection>(x: MathJsChain<T>): MathJsChain<T>
4771
5172
 
4772
5173
  /**
4773
5174
  * Iterate over all elements of a matrix/array, and executes the given
4774
5175
  * callback function.
4775
5176
  */
4776
- forEach(
5177
+ forEach<T extends Matrix | MathArray>(
5178
+ this: MathJsChain<T>,
4777
5179
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4778
- callback: (value: any, index: any, matrix: Matrix | MathArray) => void
4779
- ): MathJsChain
5180
+ callback: (value: any, index: any, matrix: T) => void
5181
+ ): MathJsChain<T>
4780
5182
 
4781
5183
  /**
4782
5184
  * Calculate the inverse of a square matrix.
4783
5185
  */
4784
- inv(): MathJsChain
5186
+
5187
+ inv<T extends number | Complex | MathCollection>(
5188
+ this: MathJsChain<T>
5189
+ ): MathJsChain<NoLiteralType<T>>
4785
5190
 
4786
5191
  /**
4787
5192
  * Calculate the kronecker product of two matrices or vectors
4788
5193
  * @param y Second vector
4789
5194
  */
4790
- kron(y: Matrix | MathArray): MathJsChain
5195
+ kron(
5196
+ this: MathJsChain<Matrix | MathArray>,
5197
+ y: Matrix | MathArray
5198
+ ): MathJsChain<Matrix>
4791
5199
 
4792
5200
  /**
4793
5201
  * Iterate over all elements of a matrix/array, and executes the given
@@ -4796,26 +5204,31 @@ declare namespace math {
4796
5204
  * parameters: the value of the element, the index of the element, and
4797
5205
  * the Matrix/array being traversed.
4798
5206
  */
4799
- map(
4800
- callback: (
4801
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4802
- value: any,
4803
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4804
- index: any,
4805
- matrix: Matrix | MathArray
4806
- ) => Matrix | MathArray
4807
- ): MathJsChain
5207
+ map<T extends Matrix | MathArray>(
5208
+ this: MathJsChain<T>,
5209
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5210
+ callback: (value: any, index: any, matrix: T) => MathType | string
5211
+ ): MathJsChain<T>
4808
5212
 
4809
5213
  /**
4810
5214
  * Create a matrix filled with ones. The created matrix can have one or
4811
5215
  * multiple dimensions.
4812
5216
  * @param format The matrix storage format
4813
5217
  */
4814
- ones(format?: string): MathJsChain
5218
+ ones(
5219
+ this: MathJsChain<number | number[]>,
5220
+ format?: string
5221
+ ): MathJsChain<MathCollection>
5222
+
4815
5223
  /**
4816
5224
  * @param format The matrix storage format
4817
5225
  */
4818
- ones(n: number, format?: string): MathJsChain
5226
+ ones(
5227
+ this: MathJsChain<number>,
5228
+ n: number,
5229
+ format?: string
5230
+ ): MathJsChain<MathCollection>
5231
+
4819
5232
  /**
4820
5233
  * Partition-based selection of an array or 1D matrix. Will find the kth
4821
5234
  * smallest value, and mutates the input array. Uses Quickselect.
@@ -4825,10 +5238,11 @@ declare namespace math {
4825
5238
  * and 0 when a == b. Default value: 'asc'.
4826
5239
  */
4827
5240
  partitionSelect(
5241
+ this: MathJsChain<MathCollection>,
4828
5242
  k: number,
4829
5243
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4830
5244
  compare?: 'asc' | 'desc' | ((a: any, b: any) => number)
4831
- ): MathJsChain
5245
+ ): MathJsChain<MathCollection>
4832
5246
 
4833
5247
  /**
4834
5248
  * Create an array from a range. By default, the range end is excluded.
@@ -4839,20 +5253,28 @@ declare namespace math {
4839
5253
  * @param includeEnd: Option to specify whether to include the end or
4840
5254
  * not. False by default
4841
5255
  */
4842
- range(includeEnd?: boolean): Matrix
4843
- range(end: number | BigNumber, includeEnd?: boolean): MathJsChain
5256
+ range(this: MathJsChain<string>, includeEnd?: boolean): MathJsChain<Matrix>
5257
+ range(
5258
+ this: MathJsChain<number | BigNumber>,
5259
+ end: number | BigNumber,
5260
+ includeEnd?: boolean
5261
+ ): MathJsChain<Matrix>
4844
5262
  range(
5263
+ this: MathJsChain<number | BigNumber>,
4845
5264
  end: number | BigNumber,
4846
5265
  step: number | BigNumber,
4847
5266
  includeEnd?: boolean
4848
- ): MathJsChain
5267
+ ): MathJsChain<Matrix>
4849
5268
 
4850
5269
  /**
4851
5270
  * Reshape a multi dimensional array to fit the specified dimensions
4852
5271
  * @param sizes One dimensional array with integral sizes for each
4853
5272
  * dimension
4854
5273
  */
4855
- reshape(sizes: number[]): MathJsChain
5274
+ reshape<T extends MathCollection>(
5275
+ this: MathJsChain<T>,
5276
+ sizes: number[]
5277
+ ): MathJsChain<T>
4856
5278
 
4857
5279
  /**
4858
5280
  * Resize a matrix
@@ -4860,12 +5282,20 @@ declare namespace math {
4860
5282
  * @param defaultValue Zero by default, except in case of a string, in
4861
5283
  * that case defaultValue = ' ' Default value: 0.
4862
5284
  */
4863
- resize(size: MathCollection, defaultValue?: number | string): MathJsChain
5285
+ resize<T extends MathCollection>(
5286
+ this: MathJsChain<T>,
5287
+ size: MathCollection,
5288
+ defaultValue?: number | string
5289
+ ): MathJsChain<T>
4864
5290
 
4865
5291
  /**
4866
5292
  * Calculate the size of a matrix or scalar.
4867
5293
  */
4868
- size(): MathJsChain
5294
+ size(
5295
+ this: MathJsChain<
5296
+ boolean | number | Complex | Unit | string | MathCollection
5297
+ >
5298
+ ): MathJsChain<MathCollection>
4869
5299
 
4870
5300
  /**
4871
5301
  * Sort the items in a matrix
@@ -4873,22 +5303,25 @@ declare namespace math {
4873
5303
  * is called as compare(a, b), and must return 1 when a > b, -1 when a <
4874
5304
  * b, and 0 when a == b. Default value: ‘asc’
4875
5305
  */
4876
- sort(
5306
+ sort<T extends Matrix | MathArray>(
5307
+ this: MathJsChain<T>,
4877
5308
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4878
5309
  compare: ((a: any, b: any) => number) | 'asc' | 'desc' | 'natural'
4879
- ): MathJsChain
5310
+ ): MathJsChain<T>
4880
5311
 
4881
5312
  /**
4882
5313
  * Calculate the principal square root of a square matrix. The principal
4883
5314
  * square root matrix X of another matrix A is such that X * X = A.
4884
5315
  */
4885
- sqrtm(): MathJsChain
5316
+
5317
+ sqrtm<T extends MathCollection>(A: MathJsChain<T>): MathJsChain<T>
4886
5318
 
4887
5319
  /**
4888
5320
  * Squeeze a matrix, remove inner and outer singleton dimensions from a
4889
5321
  * matrix.
4890
5322
  */
4891
- squeeze(): MathJsChain
5323
+
5324
+ squeeze<T extends MathCollection>(x: MathJsChain<T>): MathJsChain<T>
4892
5325
 
4893
5326
  /**
4894
5327
  * Get or set a subset of a matrix or string.
@@ -4901,19 +5334,28 @@ declare namespace math {
4901
5334
  * undefined. Default value: undefined.
4902
5335
  */
4903
5336
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4904
- subset(index: Index, replacement?: any, defaultValue?: any): MathJsChain
5337
+ subset<T extends MathCollection | string>(
5338
+ this: MathJsChain<T>,
5339
+ index: Index,
5340
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5341
+ replacement?: any,
5342
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5343
+ defaultValue?: any
5344
+ ): MathJsChain<T>
4905
5345
 
4906
5346
  /**
4907
5347
  * Calculate the trace of a matrix: the sum of the elements on the main
4908
5348
  * diagonal of a square matrix.
4909
5349
  */
4910
- trace(): MathJsChain
5350
+
5351
+ trace(this: MathJsChain<MathCollection>): MathJsChain<number>
4911
5352
 
4912
5353
  /**
4913
5354
  * Transpose a matrix. All values of the matrix are reflected over its
4914
5355
  * main diagonal. Only two dimensional matrices are supported.
4915
5356
  */
4916
- transpose(): MathJsChain
5357
+
5358
+ transpose<T extends MathCollection>(x: MathJsChain<T>): MathJsChain<T>
4917
5359
 
4918
5360
  /**
4919
5361
  * Create a matrix filled with zeros. The created matrix can have one or
@@ -4921,12 +5363,20 @@ declare namespace math {
4921
5363
  * @param format The matrix storage format
4922
5364
  * @returns A matrix filled with zeros
4923
5365
  */
4924
- zeros(format?: string): MathJsChain
5366
+ zeros(
5367
+ this: MathJsChain<number | number[]>,
5368
+ format?: string
5369
+ ): MathJsChain<MathCollection>
5370
+
4925
5371
  /**
4926
5372
  * @param n The y dimension of the matrix
4927
5373
  * @param format The matrix storage format
4928
5374
  */
4929
- zeros(n: number, format?: string): MathJsChain
5375
+ zeros(
5376
+ this: MathJsChain<number>,
5377
+ n: number,
5378
+ format?: string
5379
+ ): MathJsChain<MathCollection>
4930
5380
 
4931
5381
  /*************************************************************************
4932
5382
  * Probability functions
@@ -4938,28 +5388,40 @@ declare namespace math {
4938
5388
  * following condition must be enforced: k <= n.
4939
5389
  * @param k Number of objects in the subset
4940
5390
  */
4941
- combinations(k: number | BigNumber): MathJsChain
5391
+ combinations<T extends number | BigNumber>(
5392
+ n: MathJsChain<T>,
5393
+ k: number | BigNumber
5394
+ ): MathJsChain<NoLiteralType<T>>
4942
5395
 
4943
5396
  /**
4944
5397
  * Compute the factorial of a value Factorial only supports an integer
4945
5398
  * value as argument. For matrices, the function is evaluated element
4946
5399
  * wise.
4947
5400
  */
4948
- factorial(): MathJsChain
5401
+
5402
+ factorial<T extends number | BigNumber | MathCollection>(
5403
+ n: MathJsChain<T>
5404
+ ): MathJsChain<NoLiteralType<T>>
4949
5405
 
4950
5406
  /**
4951
5407
  * Compute the gamma function of a value using Lanczos approximation for
4952
5408
  * small values, and an extended Stirling approximation for large
4953
5409
  * values. For matrices, the function is evaluated element wise.
4954
5410
  */
4955
- gamma(): MathJsChain
5411
+
5412
+ gamma<T extends number | BigNumber | Complex | MathCollection>(
5413
+ n: MathJsChain<T>
5414
+ ): MathJsChain<NoLiteralType<T>>
4956
5415
 
4957
5416
  /**
4958
5417
  * Calculate the Kullback-Leibler (KL) divergence between two
4959
5418
  * distributions
4960
5419
  * @param p Second vector
4961
5420
  */
4962
- kldivergence(p: MathCollection): MathJsChain
5421
+ kldivergence(
5422
+ this: MathJsChain<MathCollection>,
5423
+ p: MathCollection
5424
+ ): MathJsChain<number>
4963
5425
 
4964
5426
  /**
4965
5427
  * Multinomial Coefficients compute the number of ways of picking a1,
@@ -4967,7 +5429,10 @@ declare namespace math {
4967
5429
  * takes one array of integers as an argument. The following condition
4968
5430
  * must be enforced: every ai <= 0
4969
5431
  */
4970
- multinomial(): MathJsChain
5432
+
5433
+ multinomial<T extends number | BigNumber>(
5434
+ a: MathJsChain<T[]>
5435
+ ): MathJsChain<NoLiteralType<T>>
4971
5436
 
4972
5437
  /**
4973
5438
  * Compute the number of ways of obtaining an ordered subset of k
@@ -4975,7 +5440,10 @@ declare namespace math {
4975
5440
  * arguments. The following condition must be enforced: k <= n.
4976
5441
  * @param k The number of objects in the subset
4977
5442
  */
4978
- permutations(k?: number | BigNumber): MathJsChain
5443
+ permutations<T extends number | BigNumber>(
5444
+ n: MathJsChain<T>,
5445
+ k?: number | BigNumber
5446
+ ): MathJsChain<NoLiteralType<T>>
4979
5447
 
4980
5448
  /**
4981
5449
  * Random pick a value from a one dimensional array. Array element is
@@ -4983,7 +5451,11 @@ declare namespace math {
4983
5451
  * @param number An int or float
4984
5452
  * @param weights An array of ints or floats
4985
5453
  */
4986
- pickRandom(number?: number, weights?: number[]): MathJsChain
5454
+ pickRandom(
5455
+ array: MathJsChain<number[]>,
5456
+ number?: number,
5457
+ weights?: number[]
5458
+ ): MathJsChain<number | number[]>
4987
5459
 
4988
5460
  /**
4989
5461
  * Return a random number larger or equal to min and smaller than max
@@ -4991,9 +5463,14 @@ declare namespace math {
4991
5463
  * @param min Minimum boundary for the random value, included
4992
5464
  * @param max Maximum boundary for the random value, excluded
4993
5465
  */
4994
- random(max?: number): MathJsChain
5466
+ random(this: MathJsChain<number>, max?: number): MathJsChain<number>
5467
+
4995
5468
  // tslint:disable-next-line unified-signatures
4996
- random(min: number, max: number): MathJsChain
5469
+ random<T extends MathCollection>(
5470
+ this: MathJsChain<T>,
5471
+ min?: number,
5472
+ max?: number
5473
+ ): MathJsChain<T>
4997
5474
 
4998
5475
  /**
4999
5476
  * Return a random integer number larger or equal to min and smaller
@@ -5001,9 +5478,20 @@ declare namespace math {
5001
5478
  * @param min Minimum boundary for the random value, included
5002
5479
  * @param max Maximum boundary for the random value, excluded
5003
5480
  */
5004
- randomInt(max?: number): MathJsChain
5481
+ randomInt<T extends MathCollection>(
5482
+ this: MathJsChain<T>,
5483
+ max?: number
5484
+ ): MathJsChain<T>
5485
+ randomInt<T extends MathCollection>(
5486
+ this: MathJsChain<T>,
5487
+ max?: number
5488
+ ): MathJsChain<T>
5005
5489
  // tslint:disable-next-line unified-signatures
5006
- randomInt(min: number, max: number): MathJsChain
5490
+ randomInt<T extends MathCollection>(
5491
+ this: MathJsChain<T>,
5492
+ min: number,
5493
+ max: number
5494
+ ): MathJsChain<T>
5007
5495
 
5008
5496
  /*************************************************************************
5009
5497
  * Relational functions
@@ -5017,7 +5505,10 @@ declare namespace math {
5017
5505
  * For matrices, the function is evaluated element wise.
5018
5506
  * @param y Second value to compare
5019
5507
  */
5020
- compare(y: MathType | string): MathJsChain
5508
+ compare(
5509
+ this: MathJsChain<MathType | string>,
5510
+ y: MathType | string
5511
+ ): MathJsChain<number | BigNumber | Fraction | MathCollection>
5021
5512
 
5022
5513
  /**
5023
5514
  * Compare two values of any type in a deterministic, natural way. For
@@ -5027,7 +5518,7 @@ declare namespace math {
5027
5518
  * @param y Second value to compare
5028
5519
  */
5029
5520
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5030
- compareNatural(y: any): MathJsChain
5521
+ compareNatural(this: MathJsChain<any>, y: any): MathJsChain<number>
5031
5522
 
5032
5523
  /**
5033
5524
  * Compare two strings lexically. Comparison is case sensitive. Returns
@@ -5035,14 +5526,22 @@ declare namespace math {
5035
5526
  * function is evaluated element wise.
5036
5527
  * @param y Second string to compare
5037
5528
  */
5038
- compareText(y: string | MathCollection): MathJsChain
5529
+ compareText(
5530
+ this: MathJsChain<string | MathCollection>,
5531
+ y: string | MathCollection
5532
+ ): MathJsChain<number | MathCollection>
5039
5533
 
5040
5534
  /**
5041
5535
  * Test element wise whether two matrices are equal. The function
5042
5536
  * accepts both matrices and scalar values.
5043
5537
  * @param y Second amtrix to compare
5044
5538
  */
5045
- deepEqual(y: MathType): MathJsChain
5539
+ deepEqual(
5540
+ this: MathJsChain<MathType>,
5541
+ y: MathType
5542
+ ): MathJsChain<
5543
+ number | BigNumber | Fraction | Complex | Unit | MathCollection
5544
+ >
5046
5545
 
5047
5546
  /**
5048
5547
  * Test whether two values are equal.
@@ -5056,14 +5555,20 @@ declare namespace math {
5056
5555
  * else, and undefined is only equal to undefined and nothing else.
5057
5556
  * @param y Second value to compare
5058
5557
  */
5059
- equal(y: MathType | string): MathJsChain
5558
+ equal(
5559
+ this: MathJsChain<MathType | string>,
5560
+ y: MathType | string
5561
+ ): MathJsChain<boolean | MathCollection>
5060
5562
 
5061
5563
  /**
5062
5564
  * Check equality of two strings. Comparison is case sensitive. For
5063
5565
  * matrices, the function is evaluated element wise.
5064
5566
  * @param y Second string to compare
5065
5567
  */
5066
- equalText(y: string | MathCollection): MathJsChain
5568
+ equalText(
5569
+ this: MathJsChain<string | MathCollection>,
5570
+ y: string | MathCollection
5571
+ ): MathJsChain<number | MathCollection>
5067
5572
 
5068
5573
  /**
5069
5574
  * Test whether value x is larger than y. The function returns true when
@@ -5073,7 +5578,10 @@ declare namespace math {
5073
5578
  * function is evaluated element wise.
5074
5579
  * @param y Second value to compare
5075
5580
  */
5076
- larger(y: MathType | string): MathJsChain
5581
+ larger(
5582
+ this: MathJsChain<MathType | string>,
5583
+ y: MathType | string
5584
+ ): MathJsChain<boolean | MathCollection>
5077
5585
 
5078
5586
  /**
5079
5587
  * Test whether value x is larger or equal to y. The function returns
@@ -5083,7 +5591,10 @@ declare namespace math {
5083
5591
  * the function is evaluated element wise.
5084
5592
  * @param y Second value to vcompare
5085
5593
  */
5086
- largerEq(y: MathType | string): MathJsChain
5594
+ largerEq(
5595
+ this: MathJsChain<MathType | string>,
5596
+ y: MathType | string
5597
+ ): MathJsChain<boolean | MathCollection>
5087
5598
 
5088
5599
  /**
5089
5600
  * Test whether value x is smaller than y. The function returns true
@@ -5093,7 +5604,10 @@ declare namespace math {
5093
5604
  * the function is evaluated element wise.
5094
5605
  * @param y Second value to vcompare
5095
5606
  */
5096
- smaller(y: MathType | string): MathJsChain
5607
+ smaller(
5608
+ this: MathJsChain<MathType | string>,
5609
+ y: MathType | string
5610
+ ): MathJsChain<boolean | MathCollection>
5097
5611
 
5098
5612
  /**
5099
5613
  * Test whether value x is smaller or equal to y. The function returns
@@ -5103,7 +5617,10 @@ declare namespace math {
5103
5617
  * matrices, the function is evaluated element wise.
5104
5618
  * @param y Second value to compare
5105
5619
  */
5106
- smallerEq(y: MathType | string): MathJsChain
5620
+ smallerEq(
5621
+ this: MathJsChain<MathType | string>,
5622
+ y: MathType | string
5623
+ ): MathJsChain<boolean | MathCollection>
5107
5624
 
5108
5625
  /**
5109
5626
  * Test whether two values are unequal. The function tests whether the
@@ -5116,7 +5633,10 @@ declare namespace math {
5116
5633
  * undefined is unequal with everything except undefined.
5117
5634
  * @param y Second value to vcompare
5118
5635
  */
5119
- unequal(y: MathType | string): MathJsChain
5636
+ unequal(
5637
+ this: MathJsChain<MathType | string>,
5638
+ y: MathType | string
5639
+ ): MathJsChain<boolean | MathCollection>
5120
5640
 
5121
5641
  /*************************************************************************
5122
5642
  * Set functions
@@ -5128,7 +5648,10 @@ declare namespace math {
5128
5648
  * will be sorted in ascending order before the operation.
5129
5649
  * @param a2 A (multi)set
5130
5650
  */
5131
- setCartesian(a2: MathCollection): MathJsChain
5651
+ setCartesian<T extends MathCollection>(
5652
+ this: MathJsChain<T>,
5653
+ a2: MathCollection
5654
+ ): MathJsChain<T>
5132
5655
 
5133
5656
  /**
5134
5657
  * Create the difference of two (multi)sets: every element of set1, that
@@ -5136,20 +5659,27 @@ declare namespace math {
5136
5659
  * to single-dimension arrays before the operation
5137
5660
  * @param a2 A (multi)set
5138
5661
  */
5139
- setDifference(a2: MathCollection): MathJsChain
5662
+ setDifference<T extends MathCollection>(
5663
+ this: MathJsChain<T>,
5664
+ a2: MathCollection
5665
+ ): MathJsChain<T>
5140
5666
 
5141
5667
  /**
5142
5668
  * Collect the distinct elements of a multiset. A multi-dimension array
5143
5669
  * will be converted to a single-dimension array before the operation.
5144
5670
  */
5145
- setDistinct(): MathJsChain
5671
+
5672
+ setDistinct<T extends MathCollection>(a: MathJsChain<T>): MathJsChain<T>
5146
5673
 
5147
5674
  /**
5148
5675
  * Create the intersection of two (multi)sets. Multi-dimension arrays
5149
5676
  * will be converted to single-dimension arrays before the operation.
5150
5677
  * @param a2 A (multi)set
5151
5678
  */
5152
- setIntersect(a2: MathCollection): MathJsChain
5679
+ setIntersect<T extends MathCollection>(
5680
+ this: MathJsChain<T>,
5681
+ a2: MathCollection
5682
+ ): MathJsChain<T>
5153
5683
 
5154
5684
  /**
5155
5685
  * Check whether a (multi)set is a subset of another (multi)set. (Every
@@ -5157,7 +5687,10 @@ declare namespace math {
5157
5687
  * be converted to single-dimension arrays before the operation.
5158
5688
  * @param a2 A (multi)set
5159
5689
  */
5160
- setIsSubset(a2: MathCollection): MathJsChain
5690
+ setIsSubset(
5691
+ this: MathJsChain<MathCollection>,
5692
+ a2: MathCollection
5693
+ ): MathJsChain<boolean>
5161
5694
 
5162
5695
  /**
5163
5696
  * Count the multiplicity of an element in a multiset. A multi-dimension
@@ -5165,21 +5698,26 @@ declare namespace math {
5165
5698
  * operation.
5166
5699
  * @param a A multiset
5167
5700
  */
5168
- setMultiplicity(a: MathCollection): MathJsChain
5701
+ setMultiplicity(
5702
+ e: MathJsChain<number | BigNumber | Fraction | Complex>,
5703
+ a: MathCollection
5704
+ ): MathJsChain<number>
5169
5705
 
5170
5706
  /**
5171
5707
  * Create the powerset of a (multi)set. (The powerset contains very
5172
5708
  * possible subsets of a (multi)set.) A multi-dimension array will be
5173
5709
  * converted to a single-dimension array before the operation.
5174
5710
  */
5175
- setPowerset(): MathJsChain
5711
+
5712
+ setPowerset<T extends MathCollection>(a: MathJsChain<T>): MathJsChain<T>
5176
5713
 
5177
5714
  /**
5178
5715
  * Count the number of elements of a (multi)set. When a second parameter
5179
5716
  * is ‘true’, count only the unique values. A multi-dimension array will
5180
5717
  * be converted to a single-dimension array before the operation.
5181
5718
  */
5182
- setSize(): MathJsChain
5719
+
5720
+ setSize(this: MathJsChain<MathCollection>): MathJsChain<number>
5183
5721
 
5184
5722
  /**
5185
5723
  * Create the symmetric difference of two (multi)sets. Multi-dimension
@@ -5187,14 +5725,20 @@ declare namespace math {
5187
5725
  * operation.
5188
5726
  * @param a2 A (multi)set
5189
5727
  */
5190
- setSymDifference(a2: MathCollection): MathJsChain
5728
+ setSymDifference<T extends MathCollection>(
5729
+ this: MathJsChain<T>,
5730
+ a2: MathCollection
5731
+ ): MathJsChain<T>
5191
5732
 
5192
5733
  /**
5193
5734
  * Create the union of two (multi)sets. Multi-dimension arrays will be
5194
5735
  * converted to single-dimension arrays before the operation.
5195
5736
  * @param a2 A (multi)set
5196
5737
  */
5197
- setUnion(a2: MathCollection): MathJsChain
5738
+ setUnion<T extends MathCollection>(
5739
+ this: MathJsChain<T>,
5740
+ a2: MathCollection
5741
+ ): MathJsChain<T>
5198
5742
 
5199
5743
  /*************************************************************************
5200
5744
  * Special functions
@@ -5204,7 +5748,9 @@ declare namespace math {
5204
5748
  * Compute the erf function of a value using a rational Chebyshev
5205
5749
  * approximations for different intervals of x.
5206
5750
  */
5207
- erf(): MathJsChain
5751
+ erf<T extends number | MathCollection>(
5752
+ this: MathJsChain<T>
5753
+ ): MathJsChain<NoLiteralType<T>>
5208
5754
 
5209
5755
  /*************************************************************************
5210
5756
  * Statistics functions
@@ -5215,7 +5761,8 @@ declare namespace math {
5215
5761
  * values. The median absolute deviation is defined as the median of the
5216
5762
  * absolute deviations from the median.
5217
5763
  */
5218
- mad(): MathJsChain
5764
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5765
+ mad(this: MathJsChain<MathCollection>): MathJsChain<any>
5219
5766
 
5220
5767
  /**
5221
5768
  * Compute the maximum value of a matrix or a list with values. In case
@@ -5224,7 +5771,11 @@ declare namespace math {
5224
5771
  * dimension will be calculated. Parameter dim is zero-based.
5225
5772
  * @param dim The maximum over the selected dimension
5226
5773
  */
5227
- max(dim?: number): MathJsChain
5774
+
5775
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5776
+ max(this: MathJsChain<MathType[]>, dim?: number): MathJsChain<any>
5777
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5778
+ max(this: MathJsChain<MathCollection>, dim?: number): MathJsChain<any>
5228
5779
 
5229
5780
  /**
5230
5781
  * Compute the mean value of matrix or a list with values. In case of a
@@ -5233,7 +5784,10 @@ declare namespace math {
5233
5784
  * dimension will be calculated. Parameter dim is zero-based.
5234
5785
  * @param dim The mean over the selected dimension
5235
5786
  */
5236
- mean(dim?: number): MathJsChain
5787
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5788
+ mean(this: MathJsChain<MathType[]>, dim?: number): MathJsChain<any>
5789
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5790
+ mean(this: MathJsChain<MathCollection>, dim?: number): MathJsChain<any>
5237
5791
 
5238
5792
  /**
5239
5793
  * Compute the median of a matrix or a list with values. The values are
@@ -5243,7 +5797,10 @@ declare namespace math {
5243
5797
  * dimensional) array or matrix, the median of all elements will be
5244
5798
  * calculated.
5245
5799
  */
5246
- median(): MathJsChain
5800
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5801
+ median(this: MathJsChain<MathType[]>, dim?: number): MathJsChain<any>
5802
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5803
+ median(this: MathJsChain<MathCollection>, dim?: number): MathJsChain<any>
5247
5804
 
5248
5805
  /**
5249
5806
  * Compute the maximum value of a matrix or a list of values. In case of
@@ -5252,21 +5809,26 @@ declare namespace math {
5252
5809
  * dimension will be calculated. Parameter dim is zero-based.
5253
5810
  * @param dim The minimum over the selected dimension
5254
5811
  */
5255
- min(dim?: number): MathJsChain
5812
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5813
+ min(this: MathJsChain<MathType[]>): MathJsChain<MathType[]>
5814
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5815
+ min(this: MathJsChain<MathCollection>, dim?: number): MathJsChain<any>
5256
5816
 
5257
5817
  /**
5258
5818
  * Computes the mode of a set of numbers or a list with values(numbers
5259
5819
  * or characters). If there are more than one modes, it returns a list
5260
5820
  * of those values.
5261
5821
  */
5262
- mode(): MathJsChain
5822
+
5823
+ mode(this: MathJsChain<MathType[]>): MathJsChain<MathType[]>
5263
5824
 
5264
5825
  /**
5265
5826
  * Compute the product of a matrix or a list with values. In case of a
5266
5827
  * (multi dimensional) array or matrix, the sum of all elements will be
5267
5828
  * calculated.
5268
5829
  */
5269
- prod(): MathJsChain
5830
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5831
+ prod(this: MathJsChain<MathType[]>): MathJsChain<any>
5270
5832
 
5271
5833
  /**
5272
5834
  * Compute the prob order quantile of a matrix or a list with values.
@@ -5281,9 +5843,11 @@ declare namespace math {
5281
5843
  * @param sorted =false is data sorted in ascending order
5282
5844
  */
5283
5845
  quantileSeq(
5846
+ A: MathJsChain<MathCollection>,
5284
5847
  prob: number | BigNumber | MathArray,
5285
5848
  sorted?: boolean
5286
- ): MathJsChain
5849
+ ): MathJsChain<number | BigNumber | Unit | MathArray>
5850
+
5287
5851
  /**
5288
5852
  * Compute the standard deviation of a matrix or a list with values. The
5289
5853
  * standard deviations is defined as the square root of the variance:
@@ -5301,9 +5865,11 @@ declare namespace math {
5301
5865
  * @returns The standard deviation
5302
5866
  */
5303
5867
  std(
5868
+ this: MathJsChain<number[]>,
5304
5869
  dim?: number,
5305
5870
  normalization?: 'unbiased' | 'uncorrected' | 'biased'
5306
- ): MathJsChain
5871
+ ): MathJsChain<number>
5872
+
5307
5873
  /**
5308
5874
  * Compute the standard deviation of a matrix or a list with values. The
5309
5875
  * standard deviations is defined as the square root of the variance:
@@ -5319,14 +5885,22 @@ declare namespace math {
5319
5885
  * ‘unbiased’.
5320
5886
  * @returns The standard deviation
5321
5887
  */
5322
- std(normalization: 'unbiased' | 'uncorrected' | 'biased'): MathJsChain
5888
+ std(
5889
+ this: MathJsChain<MathCollection>,
5890
+ dimension?: number,
5891
+ normalization?: 'unbiased' | 'uncorrected' | 'biased'
5892
+ ): MathJsChain<number[]>
5323
5893
 
5324
5894
  /**
5325
5895
  * Compute the sum of a matrix or a list with values. In case of a
5326
5896
  * (multi dimensional) array or matrix, the sum of all elements will be
5327
5897
  * calculated.
5328
5898
  */
5329
- sum(): MathJsChain
5899
+ std(
5900
+ this: MathJsChain<MathCollection>,
5901
+ normalization: 'unbiased' | 'uncorrected' | 'biased'
5902
+ ): MathJsChain<number>
5903
+
5330
5904
  /**
5331
5905
  * Compute the variance of a matrix or a list with values. In case of a
5332
5906
  * (multi dimensional) array or matrix, the variance over all elements
@@ -5345,9 +5919,9 @@ declare namespace math {
5345
5919
  * @returns The variance
5346
5920
  */
5347
5921
  variance(
5348
- dim?: number,
5349
- normalization?: 'unbiased' | 'uncorrected' | 'biased'
5350
- ): MathJsChain
5922
+ this: MathJsChain<Array<Array<number | BigNumber | Fraction>>>
5923
+ ): MathJsChain<number>
5924
+
5351
5925
  /**
5352
5926
  * Compute the variance of a matrix or a list with values. In case of a
5353
5927
  * (multi dimensional) array or matrix, the variance over all elements
@@ -5364,7 +5938,16 @@ declare namespace math {
5364
5938
  * Default value: ‘unbiased’.
5365
5939
  * @returns The variance
5366
5940
  */
5367
- variance(normalization: 'unbiased' | 'uncorrected' | 'biased'): MathJsChain
5941
+ variance(
5942
+ this: MathJsChain<MathCollection>,
5943
+ dimension?: number,
5944
+ normalization?: 'unbiased' | 'uncorrected' | 'biased'
5945
+ ): MathJsChain<number[]>
5946
+
5947
+ variance(
5948
+ this: MathJsChain<MathCollection>,
5949
+ normalization: 'unbiased' | 'uncorrected' | 'biased'
5950
+ ): MathJsChain<number>
5368
5951
 
5369
5952
  /*************************************************************************
5370
5953
  * String functions
@@ -5382,13 +5965,15 @@ declare namespace math {
5382
5965
  * @see http://mathjs.org/docs/reference/functions/format.html
5383
5966
  */
5384
5967
  format(
5968
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5969
+ this: MathJsChain<any>,
5385
5970
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5386
5971
  value: any,
5387
5972
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5388
5973
  options?: FormatOptions | number | ((item: any) => string),
5389
5974
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5390
5975
  callback?: (value: any) => string
5391
- ): MathJsChain
5976
+ ): MathJsChain<string>
5392
5977
 
5393
5978
  /**
5394
5979
  * Interpolate values into a string template.
@@ -5400,11 +5985,12 @@ declare namespace math {
5400
5985
  * numbers. See function math.format for a description of all options.
5401
5986
  */
5402
5987
  print(
5988
+ this: MathJsChain<string>,
5403
5989
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5404
5990
  values: any,
5405
5991
  precision?: number,
5406
5992
  options?: number | object
5407
- ): MathJsChain
5993
+ ): MathJsChain<string>
5408
5994
 
5409
5995
  /*************************************************************************
5410
5996
  * Trigonometry functions
@@ -5414,161 +6000,271 @@ declare namespace math {
5414
6000
  * Calculate the inverse cosine of a value. For matrices, the function
5415
6001
  * is evaluated element wise.
5416
6002
  */
5417
- acos(): MathJsChain
6003
+
6004
+ acos(this: MathJsChain<number>): MathJsChain<number>
6005
+ acos(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6006
+ acos(this: MathJsChain<Complex>): MathJsChain<Complex>
6007
+ acos(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6008
+ acos(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5418
6009
 
5419
6010
  /**
5420
6011
  * Calculate the hyperbolic arccos of a value, defined as acosh(x) =
5421
6012
  * ln(sqrt(x^2 - 1) + x). For matrices, the function is evaluated
5422
6013
  * element wise.
5423
6014
  */
5424
- acosh(): MathJsChain
6015
+
6016
+ acosh(this: MathJsChain<number>): MathJsChain<number>
6017
+ acosh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6018
+ acosh(this: MathJsChain<Complex>): MathJsChain<Complex>
6019
+ acosh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6020
+ acosh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5425
6021
 
5426
6022
  /**
5427
6023
  * Calculate the inverse cotangent of a value. For matrices, the
5428
6024
  * function is evaluated element wise.
5429
6025
  */
5430
- acot(): MathJsChain
6026
+
6027
+ acot(this: MathJsChain<number>): MathJsChain<number>
6028
+ acot(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6029
+ acot(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6030
+ acot(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5431
6031
 
5432
6032
  /**
5433
6033
  * Calculate the hyperbolic arccotangent of a value, defined as acoth(x)
5434
6034
  * = (ln((x+1)/x) + ln(x/(x-1))) / 2. For matrices, the function is
5435
6035
  * evaluated element wise.
5436
6036
  */
5437
- acoth(): MathJsChain
6037
+
6038
+ acoth(this: MathJsChain<number>): MathJsChain<number>
6039
+ acoth(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6040
+ acoth(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6041
+ acoth(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5438
6042
 
5439
6043
  /**
5440
6044
  * Calculate the inverse cosecant of a value. For matrices, the function
5441
6045
  * is evaluated element wise.
5442
6046
  */
5443
- acsc(): MathJsChain
6047
+
6048
+ acsc(this: MathJsChain<number>): MathJsChain<number>
6049
+ acsc(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6050
+ acsc(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6051
+ acsc(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5444
6052
 
5445
6053
  /**
5446
6054
  * Calculate the hyperbolic arccosecant of a value, defined as acsch(x)
5447
6055
  * = ln(1/x + sqrt(1/x^2 + 1)). For matrices, the function is evaluated
5448
6056
  * element wise.
5449
6057
  */
5450
- acsch(): MathJsChain
6058
+
6059
+ acsch(this: MathJsChain<number>): MathJsChain<number>
6060
+ acsch(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6061
+ acsch(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6062
+ acsch(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5451
6063
 
5452
6064
  /**
5453
6065
  * Calculate the inverse secant of a value. For matrices, the function
5454
6066
  * is evaluated element wise.
5455
6067
  */
5456
- asec(): MathJsChain
6068
+
6069
+ asec(this: MathJsChain<number>): MathJsChain<number>
6070
+ asec(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6071
+ asec(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6072
+ asec(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5457
6073
 
5458
6074
  /**
5459
6075
  * Calculate the hyperbolic arcsecant of a value, defined as asech(x) =
5460
6076
  * ln(sqrt(1/x^2 - 1) + 1/x). For matrices, the function is evaluated
5461
6077
  * element wise.
5462
6078
  */
5463
- asech(): MathJsChain
6079
+
6080
+ asech(this: MathJsChain<number>): MathJsChain<number>
6081
+ asech(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6082
+ asech(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6083
+ asech(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5464
6084
 
5465
6085
  /**
5466
6086
  * Calculate the inverse sine of a value. For matrices, the function is
5467
6087
  * evaluated element wise.
5468
6088
  */
5469
- asin(): MathJsChain
6089
+
6090
+ asin(this: MathJsChain<number>): MathJsChain<number>
6091
+ asin(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6092
+ asin(this: MathJsChain<Complex>): MathJsChain<Complex>
6093
+ asin(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6094
+ asin(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5470
6095
 
5471
6096
  /**
5472
6097
  * Calculate the hyperbolic arcsine of a value, defined as asinh(x) =
5473
6098
  * ln(x + sqrt(x^2 + 1)). For matrices, the function is evaluated
5474
6099
  * element wise.
5475
6100
  */
5476
- asinh(): MathJsChain
6101
+
6102
+ asinh(this: MathJsChain<number>): MathJsChain<number>
6103
+ asinh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6104
+ asinh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6105
+ asinh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5477
6106
 
5478
6107
  /**
5479
6108
  * Calculate the inverse tangent of a value. For matrices, the function
5480
6109
  * is evaluated element wise.
5481
6110
  */
5482
- atan(): MathJsChain
6111
+
6112
+ atan(this: MathJsChain<number>): MathJsChain<number>
6113
+ atan(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6114
+ atan(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6115
+ atan(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5483
6116
 
5484
6117
  /**
5485
6118
  * Calculate the inverse tangent function with two arguments, y/x. By
5486
6119
  * providing two arguments, the right quadrant of the computed angle can
5487
6120
  * be determined. For matrices, the function is evaluated element wise.
5488
6121
  */
5489
- atan2(): MathJsChain
6122
+
6123
+ atan2(this: MathJsChain<number>, x: number): MathJsChain<number>
6124
+ atan2(
6125
+ this: MathJsChain<MathCollection>,
6126
+ x: MathCollection
6127
+ ): MathJsChain<MathCollection>
5490
6128
 
5491
6129
  /**
5492
6130
  * Calculate the hyperbolic arctangent of a value, defined as atanh(x) =
5493
6131
  * ln((1 + x)/(1 - x)) / 2. For matrices, the function is evaluated
5494
6132
  * element wise.
5495
6133
  */
5496
- atanh(): MathJsChain
6134
+
6135
+ atanh(this: MathJsChain<number>): MathJsChain<number>
6136
+ atanh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6137
+ atanh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6138
+ atanh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5497
6139
 
5498
6140
  /**
5499
6141
  * Calculate the cosine of a value. For matrices, the function is
5500
6142
  * evaluated element wise.
5501
6143
  */
5502
- cos(): MathJsChain
6144
+
6145
+ cos(this: MathJsChain<number | Unit>): MathJsChain<number>
6146
+ cos(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6147
+ cos(this: MathJsChain<Complex>): MathJsChain<Complex>
6148
+ cos(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6149
+ cos(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5503
6150
 
5504
6151
  /**
5505
6152
  * Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2
5506
6153
  * * (exp(x) + exp(-x)). For matrices, the function is evaluated element
5507
6154
  * wise.
5508
6155
  */
5509
- cosh(): MathJsChain
6156
+
6157
+ cosh(this: MathJsChain<number | Unit>): MathJsChain<number>
6158
+ cosh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6159
+ cosh(this: MathJsChain<Complex>): MathJsChain<Complex>
6160
+ cosh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6161
+ cosh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5510
6162
 
5511
6163
  /**
5512
6164
  * Calculate the cotangent of a value. cot(x) is defined as 1 / tan(x).
5513
6165
  * For matrices, the function is evaluated element wise.
5514
6166
  */
5515
- cot(): MathJsChain
6167
+
6168
+ cot(this: MathJsChain<number | Unit>): MathJsChain<number>
6169
+ cot(this: MathJsChain<Complex>): MathJsChain<Complex>
6170
+ cot(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6171
+ cot(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5516
6172
 
5517
6173
  /**
5518
6174
  * Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1
5519
6175
  * / tanh(x). For matrices, the function is evaluated element wise.
5520
6176
  */
5521
- coth(): MathJsChain
6177
+
6178
+ coth(this: MathJsChain<number | Unit>): MathJsChain<number>
6179
+ coth(this: MathJsChain<Complex>): MathJsChain<Complex>
6180
+ coth(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6181
+ coth(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5522
6182
 
5523
6183
  /**
5524
6184
  * Calculate the cosecant of a value, defined as csc(x) = 1/sin(x). For
5525
6185
  * matrices, the function is evaluated element wise.
5526
6186
  */
5527
- csc(): MathJsChain
6187
+
6188
+ csc(this: MathJsChain<number | Unit>): MathJsChain<number>
6189
+ csc(this: MathJsChain<Complex>): MathJsChain<Complex>
6190
+ csc(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6191
+ csc(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5528
6192
 
5529
6193
  /**
5530
6194
  * Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1
5531
6195
  * / sinh(x). For matrices, the function is evaluated element wise.
5532
6196
  */
5533
- csch(): MathJsChain
6197
+
6198
+ csch(this: MathJsChain<number | Unit>): MathJsChain<number>
6199
+ csch(this: MathJsChain<Complex>): MathJsChain<Complex>
6200
+ csch(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6201
+ csch(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5534
6202
 
5535
6203
  /**
5536
6204
  * Calculate the secant of a value, defined as sec(x) = 1/cos(x). For
5537
6205
  * matrices, the function is evaluated element wise.
5538
6206
  */
5539
- sec(): MathJsChain
6207
+
6208
+ sec(this: MathJsChain<number | Unit>): MathJsChain<number>
6209
+ sec(this: MathJsChain<Complex>): MathJsChain<Complex>
6210
+ sec(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6211
+ sec(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5540
6212
 
5541
6213
  /**
5542
6214
  * Calculate the hyperbolic secant of a value, defined as sech(x) = 1 /
5543
6215
  * cosh(x). For matrices, the function is evaluated element wise.
5544
6216
  */
5545
- sech(): MathJsChain
6217
+
6218
+ sech(this: MathJsChain<number | Unit>): MathJsChain<number>
6219
+ sech(this: MathJsChain<Complex>): MathJsChain<Complex>
6220
+ sech(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6221
+ sech(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5546
6222
 
5547
6223
  /**
5548
6224
  * Calculate the sine of a value. For matrices, the function is
5549
6225
  * evaluated element wise.
5550
6226
  */
5551
- sin(): MathJsChain
6227
+
6228
+ sin(this: MathJsChain<number | Unit>): MathJsChain<number>
6229
+ sin(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6230
+ sin(this: MathJsChain<Complex>): MathJsChain<Complex>
6231
+ sin(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6232
+ sin(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5552
6233
 
5553
6234
  /**
5554
6235
  * Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 *
5555
6236
  * (exp(x) - exp(-x)). For matrices, the function is evaluated element
5556
6237
  * wise.
5557
6238
  */
5558
- sinh(): MathJsChain
6239
+
6240
+ sinh(this: MathJsChain<number | Unit>): MathJsChain<number>
6241
+ sinh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6242
+ sinh(this: MathJsChain<Complex>): MathJsChain<Complex>
6243
+ sinh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6244
+ sinh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5559
6245
 
5560
6246
  /**
5561
6247
  * Calculate the tangent of a value. tan(x) is equal to sin(x) / cos(x).
5562
6248
  * For matrices, the function is evaluated element wise.
5563
6249
  */
5564
- tan(): MathJsChain
6250
+
6251
+ tan(this: MathJsChain<number | Unit>): MathJsChain<number>
6252
+ tan(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6253
+ tan(this: MathJsChain<Complex>): MathJsChain<Complex>
6254
+ tan(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6255
+ tan(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5565
6256
 
5566
6257
  /**
5567
6258
  * Calculate the hyperbolic tangent of a value, defined as tanh(x) =
5568
6259
  * (exp(2 * x) - 1) / (exp(2 * x) + 1). For matrices, the function is
5569
6260
  * evaluated element wise.
5570
6261
  */
5571
- tanh(): MathJsChain
6262
+
6263
+ tanh(this: MathJsChain<number | Unit>): MathJsChain<number>
6264
+ tanh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6265
+ tanh(this: MathJsChain<Complex>): MathJsChain<Complex>
6266
+ tanh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6267
+ tanh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5572
6268
 
5573
6269
  /*************************************************************************
5574
6270
  * Unit functions
@@ -5580,7 +6276,10 @@ declare namespace math {
5580
6276
  * @param unit New unit. Can be a string like "cm" or a unit without
5581
6277
  * value.
5582
6278
  */
5583
- to(unit: Unit | string): MathJsChain
6279
+ to(
6280
+ this: MathJsChain<Unit | MathCollection>,
6281
+ unit: Unit | string
6282
+ ): MathJsChain<Unit | MathCollection>
5584
6283
 
5585
6284
  /*************************************************************************
5586
6285
  * Utils functions
@@ -5589,60 +6288,86 @@ declare namespace math {
5589
6288
  /**
5590
6289
  * Clone an object.
5591
6290
  */
5592
- clone(): MathJsChain
6291
+
6292
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6293
+ clone<TValue>(this: MathJsChain<TValue>): MathJsChain<TValue>
5593
6294
 
5594
6295
  /**
5595
6296
  * Test whether a value is an integer number. The function supports
5596
6297
  * number, BigNumber, and Fraction. The function is evaluated
5597
6298
  * element-wise in case of Array or Matrix input.
5598
6299
  */
5599
- isInteger(): MathJsChain
6300
+
6301
+ isInteger(
6302
+ this: MathJsChain<number | BigNumber | Fraction | MathCollection>
6303
+ ): MathJsChain<boolean>
5600
6304
 
5601
6305
  /**
5602
6306
  * Test whether a value is NaN (not a number). The function supports
5603
6307
  * types number, BigNumber, Fraction, Unit and Complex. The function is
5604
6308
  * evaluated element-wise in case of Array or Matrix input.
5605
6309
  */
5606
- isNaN(): MathJsChain
6310
+
6311
+ isNaN(
6312
+ this: MathJsChain<number | BigNumber | Fraction | MathCollection | Unit>
6313
+ ): MathJsChain<boolean>
5607
6314
 
5608
6315
  /**
5609
6316
  * Test whether a value is negative: smaller than zero. The function
5610
6317
  * supports types number, BigNumber, Fraction, and Unit. The function is
5611
6318
  * evaluated element-wise in case of Array or Matrix input.
5612
6319
  */
5613
- isNegative(): MathJsChain
6320
+
6321
+ isNegative(
6322
+ this: MathJsChain<number | BigNumber | Fraction | MathCollection | Unit>
6323
+ ): MathJsChain<boolean>
5614
6324
 
5615
6325
  /**
5616
6326
  * Test whether a value is an numeric value. The function is evaluated
5617
6327
  * element-wise in case of Array or Matrix input.
5618
6328
  */
5619
- isNumeric(): MathJsChain
6329
+
6330
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6331
+ isNumeric(this: MathJsChain<any>): MathJsChain<boolean>
5620
6332
 
5621
6333
  /**
5622
6334
  * Test whether a value is positive: larger than zero. The function
5623
6335
  * supports types number, BigNumber, Fraction, and Unit. The function is
5624
6336
  * evaluated element-wise in case of Array or Matrix input.
5625
6337
  */
5626
- isPositive(): MathJsChain
6338
+
6339
+ isPositive(
6340
+ this: MathJsChain<number | BigNumber | Fraction | MathCollection | Unit>
6341
+ ): MathJsChain<boolean>
5627
6342
 
5628
6343
  /**
5629
6344
  * Test whether a value is prime: has no divisors other than itself and
5630
6345
  * one. The function supports type number, bignumber. The function is
5631
6346
  * evaluated element-wise in case of Array or Matrix input.
5632
6347
  */
5633
- isPrime(): MathJsChain
6348
+
6349
+ isPrime(
6350
+ this: MathJsChain<number | BigNumber | MathCollection>
6351
+ ): MathJsChain<boolean>
5634
6352
 
5635
6353
  /**
5636
6354
  * Test whether a value is zero. The function can check for zero for
5637
6355
  * types number, BigNumber, Fraction, Complex, and Unit. The function is
5638
6356
  * evaluated element-wise in case of Array or Matrix input.
5639
6357
  */
5640
- isZero(): MathJsChain
6358
+
6359
+ isZero(
6360
+ this: MathJsChain<
6361
+ number | BigNumber | Fraction | MathCollection | Unit | Complex
6362
+ >
6363
+ ): MathJsChain<boolean>
5641
6364
 
5642
6365
  /**
5643
6366
  * Determine the type of a variable.
5644
6367
  */
5645
- typeOf(): MathJsChain
6368
+
6369
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6370
+ typeOf(this: MathJsChain<any>): MathJsChain<string>
5646
6371
  }
5647
6372
 
5648
6373
  interface ImportOptions {