-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
4938 lines (4485 loc) · 196 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for mathjs 6.0
// Project: https://mathjs.org/
// Definitions by: Ilya Shestakov <https://github.com/siavol>,
// Andy Patterson <https://github.com/andnp>,
// Brad Besserman <https://github.com/bradbesserman>,
// Pawel Krol <https://github.com/pawkrol>,
// Charlee Li <https://github.com/charlee>,
// Mark Wiemer <https://github.com/mark-wiemer>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
import { Decimal } from "decimal.js";
declare const math: math.MathJsStatic;
export as namespace math;
export = math;
type NoLiteralType<T> =
T extends number ? number :
T extends string ? string :
T extends boolean ? boolean :
T;
declare namespace math {
type MathArray = number[] | number[][];
type MathType =
| number
| BigNumber
| Fraction
| Complex
| Unit
| MathArray
| Matrix;
type MathExpression = string | string[] | MathArray | Matrix;
type FactoryFunction<T> = (scope: any) => T;
// FactoryFunctionMap can be nested; all nested objects will be flattened
interface FactoryFunctionMap {
[key: string]: FactoryFunction<any> | FactoryFunctionMap;
}
type MathJsFunctionName = keyof MathJsStatic;
interface MathJsStatic extends FactoryDependencies {
e: number;
pi: number;
i: number;
Infinity: number;
LN2: number;
LN10: number;
LOG2E: number;
LOG10E: number;
NaN: number;
null: number;
phi: number;
SQRT1_2: number;
SQRT2: number;
tau: number;
uninitialized: any;
version: string;
expression: MathNode;
json: MathJsJson;
/*************************************************************************
* Core functions
************************************************************************/
/**
* Set configuration options for math.js, and get current options. Will
* emit a ‘config’ event, with arguments (curr, prev, changes).
* @param options Available options: {number} epsilon Minimum relative
* difference between two compared values, used by all comparison
* functions. {string} matrix A string ‘Matrix’ (default) or ‘Array’.
* {string} number A string ‘number’ (default), ‘BigNumber’, or
* ‘Fraction’ {number} precision The number of significant digits for
* BigNumbers. Not applicable for Numbers. {string} parenthesis How to
* display parentheses in LaTeX and string output. {string} randomSeed
* Random seed for seeded pseudo random number generator. Set to null to
* randomly seed.
* @returns Returns the current configuration
*/
config: (options: ConfigOptions) => ConfigOptions;
/**
* Create a typed-function which checks the types of the arguments and
* can match them against multiple provided signatures. The
* typed-function automatically converts inputs in order to find a
* matching signature. Typed functions throw informative errors in case
* of wrong input arguments.
* @param name Optional name for the typed-function
* @param signatures Object with one or multiple function signatures
* @returns The created typed-function.
*/
typed: (name: string, signatures: Record<string, (...args: any[]) => any>) => ((...args: any[]) => any);
/*************************************************************************
* Construction functions
************************************************************************/
/**
* Create a BigNumber, which can store numbers with arbitrary precision.
* When a matrix is provided, all elements will be converted to
* BigNumber.
* @param x Value for the big number, 0 by default.
* @returns The created bignumber
*/
bignumber(
x?:
| number
| string
| Fraction
| BigNumber
| MathArray
| Matrix
| boolean
| Fraction
| null
): BigNumber;
/**
* Create a boolean or convert a string or number to a boolean. In case
* of a number, true is returned for non-zero numbers, and false in case
* of zero. Strings can be 'true' or 'false', or can contain a number.
* When value is a matrix, all elements will be converted to boolean.
* @param x A value of any type
* @returns The boolean value
*/
boolean(
x: string | number | boolean | MathArray | Matrix | null
): boolean | MathArray | Matrix;
/**
* Wrap any value in a chain, allowing to perform chained operations on
* the value. All methods available in the math.js library can be called
* upon the chain, and then will be evaluated with the value itself as
* first argument. The chain can be closed by executing chain.done(),
* which returns the final value. The chain has a number of special
* functions: done() Finalize the chain and return the chain's value.
* valueOf() The same as done() toString() Executes math.format() onto
* the chain's value, returning a string representation of the value.
* @param value A value of any type on which to start a chained
* operation.
* @returns The created chain
*/
chain(value?: any): MathJsChain;
/**
* Create a complex value or convert a value to a complex value.
* @param args Arguments specifying the real and imaginary part of the
* complex number
* @returns Returns a complex value
*/
complex(arg?: Complex | string | PolarCoordinates): Complex;
complex(arg?: MathArray | Matrix): MathArray | Matrix;
/**
* @param re Argument specifying the real part of the complex number
* @param im Argument specifying the imaginary part of the complex
* number
* @returns Returns a complex value
*/
complex(re: number, im: number): Complex;
/**
* Create a user-defined unit and register it with the Unit type.
* @param name The name of the new unit. Must be unique. Example: ‘knot’
* @param definition Definition of the unit in terms of existing units.
* For example, ‘0.514444444 m / s’.
* @param options (optional) An object containing any of the following
* properties:</br>- prefixes {string} “none”, “short”, “long”,
* “binary_short”, or “binary_long”. The default is “none”.</br>-
* aliases {Array} Array of strings. Example: [‘knots’, ‘kt’,
* ‘kts’]</br>- offset {Numeric} An offset to apply when converting from
* the unit. For example, the offset for celsius is 273.15. Default is
* 0.
* @returns The new unit
*/
createUnit(
name: string,
definition?: string | UnitDefinition,
options?: CreateUnitOptions
): Unit;
/**
* Create a user-defined unit and register it with the Unit type.
* @param units Definition of the unit
* @param options
* @returns The new unit
*/
createUnit(
units: Record<string, string | UnitDefinition>,
options?: CreateUnitOptions
): Unit;
/**
* Create a fraction convert a value to a fraction.
* @param args Arguments specifying the numerator and denominator of the
* fraction
* @returns Returns a fraction
*/
fraction(
args: Fraction | MathArray | Matrix
): Fraction | MathArray | Matrix;
/**
* @param numerator Argument specifying the numerator of the fraction
* @param denominator Argument specifying the denominator of the
* fraction
* @returns Returns a fraction
*/
fraction(
numerator: number | string | MathArray | Matrix,
denominator?: number | string | MathArray | Matrix
): Fraction | MathArray | Matrix;
/**
* Create an index. An Index can store ranges having start, step, and
* end for multiple dimensions. Matrix.get, Matrix.set, and math.subset
* accept an Index as input.
* @param ranges Zero or more ranges or numbers.
* @returns Returns the created index
*/
index(...ranges: any[]): Index;
/**
* Create a Matrix. The function creates a new math.type.Matrix object
* from an Array. A Matrix has utility functions to manipulate the data
* in the matrix, like getting the size and getting or setting values in
* the matrix. Supported storage formats are 'dense' and 'sparse'.
* @param format The Matrix storage format
* @returns The created Matrix
*/
matrix(format?: "sparse" | "dense"): Matrix;
/**
* @param data A multi dimensional array
* @param format The Matrix storage format
* @param dataType The Matrix data type
* @returns The created Matrix
*/
matrix(
data: MathArray | Matrix,
format?: "sparse" | "dense",
dataType?: string
): Matrix;
/**
* Create a number or convert a string, boolean, or unit to a number.
* When value is a matrix, all elements will be converted to number.
* @param value Value to be converted
* @returns The created number
*/
number(
value?:
| string
| number
| BigNumber
| Fraction
| boolean
| MathArray
| Matrix
| Unit
| null
): number | MathArray | Matrix;
/**
* @param value Value to be converted
* @param valuelessUnit A valueless unit, used to convert a unit to a
* number
* @returns The created number
*/
number(unit: Unit, valuelessUnit: Unit | string): number;
/**
* Create a Sparse Matrix. The function creates a new math.type.Matrix
* object from an Array. A Matrix has utility functions to manipulate
* the data in the matrix, like getting the size and getting or setting
* values in the matrix.
* @param data A two dimensional array
* @param dataType Sparse Matrix data type
* @returns The created matrix
*/
sparse(data?: MathArray | Matrix, dataType?: string): Matrix;
/**
* Split a unit in an array of units whose sum is equal to the original
* unit.
* @param unit A unit to be split
* @param parts An array of strings or valueless units
* @returns An array of units
*/
splitUnit(unit: Unit, parts: Unit[]): Unit[];
/**
* Create a string or convert any object into a string. Elements of
* Arrays and Matrices are processed element wise.
* @param value A value to convert to a string
* @returns The created string
*/
string(
value: MathType | null
): string | MathArray | Matrix;
/**
* Create a unit. Depending on the passed arguments, the function will
* create and return a new math.type.Unit object. When a matrix is
* provided, all elements will be converted to units.
* @param unit The unit to be created
* @returns The created unit
*/
unit(unit: string): Unit;
/**
* @param value The value of the unit to be created
* @param unit The unit to be created
* @returns The created unit
*/
unit(value: number | MathArray | Matrix, unit: string): Unit;
/*************************************************************************
* Expression functions
************************************************************************/
/**
* Parse and compile an expression. Returns a an object with a function
* evaluate([scope]) to evaluate the compiled expression.
* @param expr The expression to be compiled
* @returns An object with the compiled expression
*/
compile(expr: MathExpression): EvalFunction;
/**
* @param exprs The expressions to be compiled
* @returns An array of objects with the compiled expressions
*/
compile(exprs: MathExpression[]): EvalFunction[];
/**
* Evaluate an expression.
* @param expr The expression to be evaluated
* @param scope Scope to read/write variables
* @returns The result of the expression
*/
evaluate(
expr: MathExpression | MathExpression[] | Matrix,
scope?: object
): any;
/**
* Retrieve help on a function or data type. Help files are retrieved
* from the documentation in math.expression.docs.
* @param search A function or function name for which to get help
* @returns A help object
*/
help(search: () => any): Help;
/**
* Parse an expression. Returns a node tree, which can be evaluated by
* invoking node.evaluate();
* @param expr Expression to be parsed
* @param options Available options: nodes - a set of custome nodes
* @returns A node
*/
parse(expr: MathExpression, options?: any): MathNode;
/**
* @param exprs Expressions to be parsed
* @param options Available options: nodes - a set of custome nodes
* @returns An arry of nodes
*/
parse(exprs: MathExpression[], options?: any): MathNode[];
/**
* Create a parser. The function creates a new math.expression.Parser
* object.
* @returns A Parser object
*/
parser(): Parser;
/*************************************************************************
* Algebra functions
************************************************************************/
/**
* @param expr The expression to differentiate
* @param variable The variable over which to differentiate
* @param options There is one option available, simplify, which is true
* by default. When false, output will not be simplified.
* @returns The derivative of expr
*/
derivative(
expr: MathNode | string,
variable: MathNode | string,
options?: {simplify: boolean}
): MathNode;
/**
* Solves the linear equation system by forwards substitution. Matrix
* must be a lower triangular matrix.
* @param L A N x N matrix or array (L)
* @param b A column vector with the b values
* @returns A column vector with the linear system solution (x)
*/
lsolve(
L: Matrix | MathArray,
b: Matrix | MathArray
): Matrix | MathArray;
/**
* Calculate the Matrix LU decomposition with partial pivoting. Matrix A
* is decomposed in two matrices (L, U) and a row permutation vector p
* where A[p,:] = L * U
* @param A A two dimensional matrix or array for which to get the LUP
* decomposition.
* @returns The lower triangular matrix, the upper triangular matrix and
* the permutation matrix.
*/
lup(
A?: Matrix | MathArray
): { L: MathArray | Matrix; U: MathArray | Matrix; P: number[] };
/**
* Solves the linear system A * x = b where A is an [n x n] matrix and b
* is a [n] column vector.
* @param A Invertible Matrix or the Matrix LU decomposition
* @param b Column Vector
* @param order The Symbolic Ordering and Analysis order, see slu for
* details. Matrix must be a SparseMatrix
* @param threshold Partial pivoting threshold (1 for partial pivoting),
* see slu for details. Matrix must be a SparseMatrix.
* @returns Column vector with the solution to the linear system A * x =
* b
*/
lusolve(
A: Matrix | MathArray | number,
b: Matrix | MathArray,
order?: number,
threshold?: number
): Matrix | MathArray;
/**
* Calculate the Matrix QR decomposition. Matrix A is decomposed in two
* matrices (Q, R) where Q is an orthogonal matrix and R is an upper
* triangular matrix.
* @param A A two dimensional matrix or array for which to get the QR
* decomposition.
* @returns Q: the orthogonal matrix and R: the upper triangular matrix
*/
qr(
A: Matrix | MathArray
): { Q: MathArray | Matrix; R: MathArray | Matrix };
/**
* Transform a rationalizable expression in a rational fraction. If
* rational fraction is one variable polynomial then converts the
* numerator and denominator in canonical form, with decreasing
* exponents, returning the coefficients of numerator.
* @param expr The expression to check if is a polynomial expression
* @param optional scope of expression or true for already evaluated
* rational expression at input
* @param detailed optional True if return an object, false if return
* expression node (default)
* @returns The rational polynomial of expr
*/
rationalize(expr: MathNode | string, optional?: object | boolean, detailed?: true): { expression: MathNode | string, variables: string[], coefficients: MathType[] };
rationalize(expr: MathNode | string, optional?: object | boolean, detailed?: false): MathNode;
/**
* Simplify an expression tree.
* @param expr The expression to be simplified
* @param rules A list of rules are applied to an expression, repeating
* over the list until no further changes are made. It’s possible to
* pass a custom set of rules to the function as second argument. A rule
* can be specified as an object, string, or function.
* @param scope Scope to variables
* @returns Returns the simplified form of expr
*/
simplify(
expr: MathNode | string,
rules?: Array<({ l: string; r: string } | string | ((node: MathNode) => MathNode))>,
scope?: object
): MathNode;
/**
* Calculate the Sparse Matrix LU decomposition with full pivoting.
* Sparse Matrix A is decomposed in two matrices (L, U) and two
* permutation vectors (pinv, q) where P * A * Q = L * U
* @param A A two dimensional sparse matrix for which to get the LU
* decomposition.
* @param order The Symbolic Ordering and Analysis order: 0 - Natural
* ordering, no permutation vector q is returned 1 - Matrix must be
* square, symbolic ordering and analisis is performed on M = A + A' 2 -
* Symbolic ordering and analysis is performed on M = A' * A. Dense
* columns from A' are dropped, A recreated from A'. This is appropriate
* for LU factorization of non-symmetric matrices. 3 - Symbolic ordering
* and analysis is performed on M = A' * A. This is best used for LU
* factorization is matrix M has no dense rows. A dense row is a row
* with more than 10*sqr(columns) entries.
* @param threshold Partial pivoting threshold (1 for partial pivoting)
* @returns The lower triangular matrix, the upper triangular matrix and
* the permutation vectors.
*/
slu(A: Matrix, order: number, threshold: number): object;
/**
* Solves the linear equation system by backward substitution. Matrix
* must be an upper triangular matrix. U * x = b
* @param U A N x N matrix or array (U)
* @param b A column vector with the b values
* @returns A column vector with the linear system solution (x)
*/
usolve(
U: Matrix | MathArray,
b: Matrix | MathArray
): Matrix | MathArray;
/*************************************************************************
* Arithmetic functions
************************************************************************/
/**
* Calculate the absolute value of a number. For matrices, the function
* is evaluated element wise.
* @param x A number or matrix for which to get the absolute value
* @returns Absolute value of x
*/
abs(x: number): number;
abs(x: BigNumber): BigNumber;
abs(x: Fraction): Fraction;
abs(x: Complex): Complex;
abs(x: MathArray): MathArray;
abs(x: Matrix): Matrix;
abs(x: Unit): Unit;
/**
* Add two values, x + y. For matrices, the function is evaluated
* element wise.
* @param x First value to add
* @param y Second value to add
* @returns Sum of x and y
*/
add(x: MathType, y: MathType): MathType;
/**
* Calculate the cubic root of a value. For matrices, the function is
* evaluated element wise.
* @param x Value for which to calculate the cubic root.
* @param allRoots Optional, false by default. Only applicable when x is
* a number or complex number. If true, all complex roots are returned,
* if false (default) the principal root is returned.
* @returns Returns the cubic root of x
*/
cbrt(x: number, allRoots?: boolean): number;
cbrt(x: BigNumber, allRoots?: boolean): BigNumber;
cbrt(x: Fraction, allRoots?: boolean): Fraction;
cbrt(x: Complex, allRoots?: boolean): Complex;
cbrt(x: MathArray, allRoots?: boolean): MathArray;
cbrt(x: Matrix, allRoots?: boolean): Matrix;
cbrt(x: Unit, allRoots?: boolean): Unit;
/**
* Round a value towards plus infinity If x is complex, both real and
* imaginary part are rounded towards plus infinity. For matrices, the
* function is evaluated element wise.
* @param x Number to be rounded
* @returns Rounded value
*/
ceil(x: number): number;
ceil(x: BigNumber): BigNumber;
ceil(x: Fraction): Fraction;
ceil(x: Complex): Complex;
ceil(x: MathArray): MathArray;
ceil(x: Matrix): Matrix;
ceil(x: Unit): Unit;
/**
* Compute the cube of a value, x * x * x. For matrices, the function is
* evaluated element wise.
* @param x Number for which to calculate the cube
* @returns Cube of x
*/
cube(x: number): number;
cube(x: BigNumber): BigNumber;
cube(x: Fraction): Fraction;
cube(x: Complex): Complex;
cube(x: MathArray): MathArray;
cube(x: Matrix): Matrix;
cube(x: Unit): Unit;
/**
* Divide two values, x / y. To divide matrices, x is multiplied with
* the inverse of y: x * inv(y).
* @param x Numerator
* @param y Denominator
* @returns Quotient, x / y
*/
divide(x: Unit, y: Unit): Unit;
divide(x: number, y: number): number;
divide(x: MathType, y: MathType): MathType;
/**
* Divide two matrices element wise. The function accepts both matrices
* and scalar values.
* @param x Numerator
* @param y Denominator
* @returns Quotient, x ./ y
*/
dotDivide(x: MathType, y: MathType): MathType;
/**
* Multiply two matrices element wise. The function accepts both
* matrices and scalar values.
* @param x Left hand value
* @param y Right hand value
* @returns Multiplication of x and y
*/
dotMultiply(x: MathType, y: MathType): MathType;
/**
* Calculates the power of x to y element wise.
* @param x The base
* @param y The exponent
* @returns The value of x to the power y
*/
dotPow(x: MathType, y: MathType): MathType;
/**
* Calculate the exponent of a value. For matrices, the function is
* evaluated element wise.
* @param x A number or matrix to exponentiate
* @returns Exponent of x
*/
exp(x: number): number;
exp(x: BigNumber): BigNumber;
exp(x: Complex): Complex;
exp(x: MathArray): MathArray;
exp(x: Matrix): Matrix;
/**
* Calculate the value of subtracting 1 from the exponential value. For
* matrices, the function is evaluated element wise.
* @param x A number or matrix to apply expm1
* @returns Exponent of x
*/
expm1(x: number): number;
expm1(x: BigNumber): BigNumber;
expm1(x: Complex): Complex;
expm1(x: MathArray): MathArray;
expm1(x: Matrix): Matrix;
/**
* Round a value towards zero. For matrices, the function is evaluated
* element wise.
* @param x Number to be rounded
* @returns Rounded value
*/
fix(x: number): number;
fix(x: BigNumber): BigNumber;
fix(x: Fraction): Fraction;
fix(x: Complex): Complex;
fix(x: MathArray): MathArray;
fix(x: Matrix): Matrix;
/**
* Round a value towards minus infinity. For matrices, the function is
* evaluated element wise.
* @param Number to be rounded
* @returns Rounded value
*/
floor(x: number): number;
floor(x: BigNumber): BigNumber;
floor(x: Fraction): Fraction;
floor(x: Complex): Complex;
floor(x: MathArray): MathArray;
floor(x: Matrix): Matrix;
/**
* Calculate the greatest common divisor for two or more values or
* arrays. For matrices, the function is evaluated element wise.
* @param args Two or more integer numbers
* @returns The greatest common divisor
*/
gcd(...args: number[]): number;
gcd(...args: BigNumber[]): BigNumber;
gcd(...args: Fraction[]): Fraction;
gcd(...args: MathArray[]): MathArray;
gcd(...args: Matrix[]): Matrix;
/**
* Calculate the hypotenusa of a list with values. The hypotenusa is
* defined as: hypot(a, b, c, ...) = sqrt(a^2 + b^2 + c^2 + ...) For
* matrix input, the hypotenusa is calculated for all values in the
* matrix.
* @param args A list with numeric values or an Array or Matrix. Matrix
* and Array input is flattened and returns a single number for the
* whole matrix.
* @returns Returns the hypothenuse of the input values.
*/
hypot(...args: number[]): number;
hypot(...args: BigNumber[]): BigNumber;
/**
* Calculate the least common multiple for two or more values or arrays.
* lcm is defined as: lcm(a, b) = abs(a * b) / gcd(a, b) For matrices,
* the function is evaluated element wise.
* @param a An integer number
* @param b An integer number
* @returns The least common multiple
*/
lcm(a: number, b: number): number;
lcm(a: BigNumber, b: BigNumber): BigNumber;
lcm(a: MathArray, b: MathArray): MathArray;
lcm(a: Matrix, b: Matrix): Matrix;
/**
* Calculate the logarithm of a value. For matrices, the function is
* evaluated element wise.
* @param x Value for which to calculate the logarithm.
* @param base Optional base for the logarithm. If not provided, the
* natural logarithm of x is calculated. Default value: e.
* @returns Returns the logarithm of x
*/
log<T extends number | BigNumber | Complex | MathArray | Matrix>(
x: T,
base?: number | BigNumber | Complex
): NoLiteralType<T>;
/**
* Calculate the 10-base of a value. This is the same as calculating
* log(x, 10). For matrices, the function is evaluated element wise.
* @param x Value for which to calculate the logarithm.
* @returns Returns the 10-base logarithm of x
*/
log10(x: number): number;
log10(x: BigNumber): BigNumber;
log10(x: Complex): Complex;
log10(x: MathArray): MathArray;
log10(x: Matrix): Matrix;
/**
* Calculate the logarithm of a value+1. For matrices, the function is
* evaluated element wise.
* @param x Value for which to calculate the logarithm.
* @returns Returns the logarithm of x+1
*/
log1p(x: number, base?: number | BigNumber | Complex): number;
log1p(x: BigNumber, base?: number | BigNumber | Complex): BigNumber;
log1p(x: Complex, base?: number | BigNumber | Complex): Complex;
log1p(x: MathArray, base?: number | BigNumber | Complex): MathArray;
log1p(x: Matrix, base?: number | BigNumber | Complex): Matrix;
/**
* Calculate the 2-base of a value. This is the same as calculating
* log(x, 2). For matrices, the function is evaluated element wise.
* @param x Value for which to calculate the logarithm.
* @returns Returns the 2-base logarithm of x
*/
log2(x: number): number;
log2(x: BigNumber): BigNumber;
log2(x: Complex): Complex;
log2(x: MathArray): MathArray;
log2(x: Matrix): Matrix;
/**
* Calculates the modulus, the remainder of an integer division. For
* matrices, the function is evaluated element wise. The modulus is
* defined as: x - y * floor(x / y)
* @see http://en.wikipedia.org/wiki/Modulo_operation.
* @param x Dividend
* @param y Divisor
* @returns Returns the remainder of x divided by y
*/
mod<T extends number | BigNumber | Fraction | MathArray | Matrix>(
x: T,
y: number | BigNumber | Fraction | MathArray | Matrix
): NoLiteralType<T>;
/**
* Multiply two values, x * y. The result is squeezed. For matrices, the
* matrix product is calculated.
* @param x The first value to multiply
* @param y The second value to multiply
* @returns Multiplication of x and y
*/
multiply<T extends Matrix | MathArray>(x: T, y: MathType): T;
multiply(x: Unit, y: Unit): Unit;
multiply(x: number, y: number): number;
multiply(x: MathType, y: MathType): MathType;
/**
* Calculate the norm of a number, vector or matrix. The second
* parameter p is optional. If not provided, it defaults to 2.
* @param x Value for which to calculate the norm
* @param p Vector space. Supported numbers include Infinity and
* -Infinity. Supported strings are: 'inf', '-inf', and 'fro' (The
* Frobenius norm) Default value: 2.
* @returns the p-norm
*/
norm(
x: number | BigNumber | Complex | MathArray | Matrix,
p?: number | BigNumber | string
): number | BigNumber;
/**
* Calculate the nth root of a value. The principal nth root of a
* positive real number A, is the positive real solution of the equation
* x^root = A For matrices, the function is evaluated element wise.
* @param a Value for which to calculate the nth root
* @param root The root. Default value: 2.
* @return The nth root of a
*/
nthRoot(
a: number | BigNumber | MathArray | Matrix | Complex,
root?: number | BigNumber
): number | Complex | MathArray | Matrix;
/**
* Calculates the power of x to y, x ^ y. Matrix exponentiation is
* supported for square matrices x, and positive integer exponents y.
* @param x The base
* @param y The exponent
* @returns x to the power y
*/
pow(x: MathType, y: number | BigNumber | Complex): MathType;
/**
* Round a value towards the nearest integer. For matrices, the function
* is evaluated element wise.
* @param x Number to be rounded
* @param n Number of decimals Default value: 0.
* @returns Rounded value of x
*/
round<T extends number | BigNumber | Fraction | Complex | MathArray | Matrix>(
x: T,
n?: number | BigNumber | MathArray
): NoLiteralType<T>;
/**
* Compute the sign of a value. The sign of a value x is: 1 when x > 1
* -1 when x < 0 0 when x == 0 For matrices, the function is evaluated
* element wise.
* @param x The number for which to determine the sign
* @returns The sign of x
*/
sign(x: number): number;
sign(x: BigNumber): BigNumber;
sign(x: Fraction): Fraction;
sign(x: Complex): Complex;
sign(x: MathArray): MathArray;
sign(x: Matrix): Matrix;
sign(x: Unit): Unit;
/**
* Calculate the square root of a value. For matrices, the function is
* evaluated element wise.
* @param x Value for which to calculate the square root
* @returns Returns the square root of x
*/
sqrt(x: number): number;
sqrt(x: BigNumber): BigNumber;
sqrt(x: Complex): Complex;
sqrt(x: MathArray): MathArray;
sqrt(x: Matrix): Matrix;
sqrt(x: Unit): Unit;
/**
* Compute the square of a value, x * x. For matrices, the function is
* evaluated element wise.
* @param x Number for which to calculate the square
* @returns Squared value
*/
square(x: number): number;
square(x: BigNumber): BigNumber;
square(x: Fraction): Fraction;
square(x: Complex): Complex;
square(x: MathArray): MathArray;
square(x: Matrix): Matrix;
square(x: Unit): Unit;
/**
* Subtract two values, x - y. For matrices, the function is evaluated
* element wise.
* @param x Initial value
* @param y Value to subtract from x
* @returns Subtraction of x and y
*/
subtract(x: MathType, y: MathType): MathType;
/**
* Inverse the sign of a value, apply a unary minus operation. For
* matrices, the function is evaluated element wise. Boolean values and
* strings will be converted to a number. For complex numbers, both real
* and complex value are inverted.
* @param x Number to be inverted
* @returns Retursn the value with inverted sign
*/
unaryMinus(x: number): number;
unaryMinus(x: BigNumber): BigNumber;
unaryMinus(x: Fraction): Fraction;
unaryMinus(x: Complex): Complex;
unaryMinus(x: MathArray): MathArray;
unaryMinus(x: Matrix): Matrix;
unaryMinus(x: Unit): Unit;
/**
* Unary plus operation. Boolean values and strings will be converted to
* a number, numeric values will be returned as is. For matrices, the
* function is evaluated element wise.
* @param x Input value
* @returns Returns the input value when numeric, converts to a number
* when input is non-numeric.
*/
unaryPlus(x: number): number;
unaryPlus(x: BigNumber): BigNumber;
unaryPlus(x: Fraction): Fraction;
unaryPlus(x: string): string;
unaryPlus(x: Complex): Complex;
unaryPlus(x: MathArray): MathArray;
unaryPlus(x: Matrix): Matrix;
unaryPlus(x: Unit): Unit;
/**
* Calculate the extended greatest common divisor for two values. See
* http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm.
* @param a An integer number
* @param b An integer number
* @returns Returns an array containing 3 integers [div, m, n] where div
* = gcd(a, b) and a*m + b*n = div
*/
xgcd(a: number | BigNumber, b: number | BigNumber): MathArray;
/*************************************************************************
* Bitwise functions
************************************************************************/
/**
* Bitwise AND two values, x & y. For matrices, the function is
* evaluated element wise.
* @param x First value to and
* @param y Second value to and
* @returns AND of x and y
*/
bitAnd<T extends number | BigNumber | MathArray | Matrix>(
x: T,
y: number | BigNumber | MathArray | Matrix
): NoLiteralType<T>;
/**
* Bitwise NOT value, ~x. For matrices, the function is evaluated
* element wise. For units, the function is evaluated on the best prefix
* base.
* @param x Value to not
* @returns NOT of x
*/
bitNot(x: number): number;
bitNot(x: BigNumber): BigNumber;
bitNot(x: MathArray): MathArray;
bitNot(x: Matrix): Matrix;
/**
* Bitwise OR two values, x | y. For matrices, the function is evaluated
* element wise. For units, the function is evaluated on the lowest
* print base.
* @param x First value to or
* @param y Second value to or
* @returns OR of x and y
*/
bitOr(x: number, y: number): number;
bitOr(x: BigNumber, y: BigNumber): BigNumber;
bitOr(x: MathArray, y: MathArray): MathArray;
bitOr(x: Matrix, y: Matrix): Matrix;
/**
* Bitwise XOR two values, x ^ y. For matrices, the function is
* evaluated element wise.
* @param x First value to xor
* @param y Second value to xor
* @returns XOR of x and y
*/
bitXor<T extends number | BigNumber | MathArray | Matrix>(
x: T,
y: number | BigNumber | MathArray | Matrix
): NoLiteralType<T>;
/**
* Bitwise left logical shift of a value x by y number of bits, x << y.
* For matrices, the function is evaluated element wise. For units, the
* function is evaluated on the best prefix base.
* @param x Value to be shifted
* @param y Amount of shifts
* @returns x shifted left y times
*/
leftShift<T extends number | BigNumber | MathArray | Matrix>(
x: T,
y: number | BigNumber
): NoLiteralType<T>;
/**
* Bitwise right arithmetic shift of a value x by y number of bits, x >>
* y. For matrices, the function is evaluated element wise. For units,
* the function is evaluated on the best prefix base.
* @param x Value to be shifted
* @param y Amount of shifts
* @returns x sign-filled shifted right y times
*/
rightArithShift<T extends number | BigNumber | MathArray | Matrix>(
x: T,
y: number | BigNumber