UNPKG

185 kBTypeScriptView Raw
1import { Decimal } from 'decimal.js';
2
3declare const math: math.MathJsStatic;
4export as namespace math;
5export = math;
6
7type NoLiteralType<T> =
8 T extends number ? number :
9 T extends string ? string :
10 T extends boolean ? boolean :
11 T;
12
13declare namespace math {
14 type MathArray = number[] | number[][];
15 type MathType = number | BigNumber | Fraction | Complex | Unit | MathArray | Matrix;
16 type MathExpression = string | string[] | MathArray | Matrix;
17
18 type FactoryFunction<T> = (scope: any) => T;
19
20 // FactoryFunctionMap can be nested; all nested objects will be flattened
21 interface FactoryFunctionMap {
22 [key: string]: FactoryFunction<any> | FactoryFunctionMap;
23 }
24
25
26 /** Available options for parse */
27 interface ParseOptions {
28 /** a set of custom nodes */
29 nodes?: Record<string, MathNode>;
30 }
31 /**
32 * Parse an expression. Returns a node tree, which can be evaluated by
33 * invoking node.evaluate().
34 *
35 * Note the evaluating arbitrary expressions may involve security risks,
36 * see [https://mathjs.org/docs/expressions/security.html](https://mathjs.org/docs/expressions/security.html) for more information.
37 *
38 * Syntax:
39 *
40 * math.parse(expr)
41 * math.parse(expr, options)
42 * math.parse([expr1, expr2, expr3, ...])
43 * math.parse([expr1, expr2, expr3, ...], options)
44 *
45 * Example:
46 *
47 * const node1 = math.parse('sqrt(3^2 + 4^2)')
48 * node1.compile().evaluate() // 5
49 *
50 * let scope = {a:3, b:4}
51 * const node2 = math.parse('a * b') // 12
52 * const code2 = node2.compile()
53 * code2.evaluate(scope) // 12
54 * scope.a = 5
55 * code2.evaluate(scope) // 20
56 *
57 * const nodes = math.parse(['a = 3', 'b = 4', 'a * b'])
58 * nodes[2].compile().evaluate() // 12
59 *
60 * See also:
61 *
62 * evaluate, compile
63 */
64 interface ParseFunction {
65 /**
66 * Parse an expression. Returns a node tree, which can be evaluated by
67 * invoking node.evaluate();
68 *
69 * @param expr Expression to be parsed
70 * @param options Available options
71 * @returns A node
72 */
73 (expr: MathExpression, options?: ParseOptions): MathNode;
74
75 /**
76 * Parse an expression. Returns a node tree, which can be evaluated by
77 * invoking node.evaluate();
78 *
79 * @param exprs Expressions to be parsed
80 * @param options Available options
81 * @returns An array of nodes
82 */
83 (exprs: MathExpression[], options?: ParseOptions): MathNode[];
84
85 /**
86 * Checks whether the current character `c` is a valid alpha character:
87 *
88 * - A latin letter (upper or lower case) Ascii: a-z, A-Z
89 * - An underscore Ascii: _
90 * - A dollar sign Ascii: $
91 * - A latin letter with accents Unicode: \u00C0 - \u02AF
92 * - A greek letter Unicode: \u0370 - \u03FF
93 * - A mathematical alphanumeric symbol Unicode: \u{1D400} - \u{1D7FF} excluding invalid code points
94 *
95 * The previous and next characters are needed to determine whether
96 * this character is part of a unicode surrogate pair.
97 *
98 * @param c Current character in the expression
99 * @param cPrev Previous character
100 * @param cNext Next character
101 */
102 isAlpha(c: string, cPrev: string, cNext: string): boolean;
103 /**
104 * Test whether a character is a valid latin, greek, or letter-like character
105 *
106 * @param c
107 */
108 isValidLatinOrGreek(c: string): boolean;
109 /**
110 * Test whether two given 16 bit characters form a surrogate pair of a
111 * unicode math symbol.
112 *
113 * https://unicode-table.com/en/
114 * https://www.wikiwand.com/en/Mathematical_operators_and_symbols_in_Unicode
115 *
116 * Note: In ES6 will be unicode aware:
117 * https://stackoverflow.com/questions/280712/javascript-unicode-regexes
118 * https://mathiasbynens.be/notes/es6-unicode-regex
119 *
120 * @param high
121 * @param low
122 */
123 isValidMathSymbol(high: string, low: string): boolean;
124 /**
125 * Check whether given character c is a white space character: space, tab, or enter
126 *
127 * @param c
128 * @param nestingLevel
129 */
130 isWhitespace(c: string, nestingLevel: number): boolean;
131 /**
132 * Test whether the character c is a decimal mark (dot).
133 * This is the case when it's not the start of a delimiter '.*', './', or '.^'
134 *
135 * @param c
136 * @param cNext
137 */
138 isDecimalMark(c: string, cNext: string): boolean;
139 /**
140 * checks if the given char c is a digit or dot
141 *
142 * @param c a string with one character
143 */
144 isDigitDot(c: string): boolean;
145 /**
146 * checks if the given char c is a digit
147 *
148 * @param c a string with one character
149 */
150 isDigit(c: string): boolean;
151 /**
152 * checks if the given char c is a hex digit
153 *
154 * @param c a string with one character
155 */
156 isHexDigit(c: string): boolean;
157 }
158
159 type MathJsFunctionName = keyof MathJsStatic;
160
161 interface MathJsStatic extends FactoryDependencies {
162 e: number;
163 pi: number;
164 i: number;
165 Infinity: number;
166 LN2: number;
167 LN10: number;
168 LOG2E: number;
169 LOG10E: number;
170 NaN: number;
171 phi: number;
172 SQRT1_2: number;
173 SQRT2: number;
174 tau: number;
175
176 /**
177 * If null were to be included in this interface, it would be
178 * auto-suggested as an import in VSCode. This causes issues because
179 * `null` is not a valid label.
180 *
181 * @see https://github.com/josdejong/mathjs/issues/2019
182 */
183 // null: number;
184
185 uninitialized: any;
186 version: string;
187
188 expression: MathNode;
189 json: MathJsJson;
190
191 /*************************************************************************
192 * Core functions
193 ************************************************************************/
194
195 /**
196 * Set configuration options for math.js, and get current options. Will
197 * emit a ‘config’ event, with arguments (curr, prev, changes).
198 * @param options Available options: {number} epsilon Minimum relative
199 * difference between two compared values, used by all comparison
200 * functions. {string} matrix A string ‘Matrix’ (default) or ‘Array’.
201 * {string} number A string ‘number’ (default), ‘BigNumber’, or
202 * ‘Fraction’ {number} precision The number of significant digits for
203 * BigNumbers. Not applicable for Numbers. {string} parenthesis How to
204 * display parentheses in LaTeX and string output. {string} randomSeed
205 * Random seed for seeded pseudo random number generator. Set to null to
206 * randomly seed.
207 * @returns Returns the current configuration
208 */
209 config: (options: ConfigOptions) => ConfigOptions;
210 /**
211 * Create a typed-function which checks the types of the arguments and
212 * can match them against multiple provided signatures. The
213 * typed-function automatically converts inputs in order to find a
214 * matching signature. Typed functions throw informative errors in case
215 * of wrong input arguments.
216 * @param name Optional name for the typed-function
217 * @param signatures Object with one or multiple function signatures
218 * @returns The created typed-function.
219 */
220 typed: (name: string, signatures: Record<string, (...args: any[]) => any>) => (...args: any[]) => any;
221
222 /*************************************************************************
223 * Construction functions
224 ************************************************************************/
225
226 /**
227 * Create a BigNumber, which can store numbers with arbitrary precision.
228 * When a matrix is provided, all elements will be converted to
229 * BigNumber.
230 * @param x Value for the big number, 0 by default.
231 * @returns The created bignumber
232 */
233 bignumber(x?: number | string | Fraction | BigNumber | MathArray | Matrix | boolean | Fraction | null): BigNumber;
234
235 /**
236 * Create a boolean or convert a string or number to a boolean. In case
237 * of a number, true is returned for non-zero numbers, and false in case
238 * of zero. Strings can be 'true' or 'false', or can contain a number.
239 * When value is a matrix, all elements will be converted to boolean.
240 * @param x A value of any type
241 * @returns The boolean value
242 */
243 boolean(x: string | number | boolean | MathArray | Matrix | null): boolean | MathArray | Matrix;
244
245 /**
246 * Wrap any value in a chain, allowing to perform chained operations on
247 * the value. All methods available in the math.js library can be called
248 * upon the chain, and then will be evaluated with the value itself as
249 * first argument. The chain can be closed by executing chain.done(),
250 * which returns the final value. The chain has a number of special
251 * functions: done() Finalize the chain and return the chain's value.
252 * valueOf() The same as done() toString() Executes math.format() onto
253 * the chain's value, returning a string representation of the value.
254 * @param value A value of any type on which to start a chained
255 * operation.
256 * @returns The created chain
257 */
258 chain(value?: any): MathJsChain;
259
260 /**
261 * Create a complex value or convert a value to a complex value.
262 * @param args Arguments specifying the real and imaginary part of the
263 * complex number
264 * @returns Returns a complex value
265 */
266 complex(arg?: Complex | string | PolarCoordinates): Complex;
267 complex(arg?: MathArray | Matrix): MathArray | Matrix;
268 /**
269 * @param re Argument specifying the real part of the complex number
270 * @param im Argument specifying the imaginary part of the complex
271 * number
272 * @returns Returns a complex value
273 */
274 complex(re: number, im: number): Complex;
275
276 /**
277 * Create a user-defined unit and register it with the Unit type.
278 * @param name The name of the new unit. Must be unique. Example: ‘knot’
279 * @param definition Definition of the unit in terms of existing units.
280 * For example, ‘0.514444444 m / s’.
281 * @param options (optional) An object containing any of the following
282 * properties:</br>- prefixes {string} “none”, “short”, “long”,
283 * “binary_short”, or “binary_long”. The default is “none”.</br>-
284 * aliases {Array} Array of strings. Example: [‘knots’, ‘kt’,
285 * ‘kts’]</br>- offset {Numeric} An offset to apply when converting from
286 * the unit. For example, the offset for celsius is 273.15. Default is
287 * 0.
288 * @returns The new unit
289 */
290 createUnit(name: string, definition?: string | UnitDefinition, options?: CreateUnitOptions): Unit;
291 /**
292 * Create a user-defined unit and register it with the Unit type.
293 * @param units Definition of the unit
294 * @param options
295 * @returns The new unit
296 */
297 createUnit(units: Record<string, string | UnitDefinition>, options?: CreateUnitOptions): Unit;
298
299 /**
300 * Create a fraction convert a value to a fraction.
301 * @param args Arguments specifying the numerator and denominator of the
302 * fraction
303 * @returns Returns a fraction
304 */
305 fraction(args: Fraction | MathArray | Matrix): Fraction | MathArray | Matrix;
306 /**
307 * @param numerator Argument specifying the numerator of the fraction
308 * @param denominator Argument specifying the denominator of the
309 * fraction
310 * @returns Returns a fraction
311 */
312 fraction(
313 numerator: number | string | MathArray | Matrix,
314 denominator?: number | string | MathArray | Matrix
315 ): Fraction | MathArray | Matrix;
316
317 /**
318 * Create an index. An Index can store ranges having start, step, and
319 * end for multiple dimensions. Matrix.get, Matrix.set, and math.subset
320 * accept an Index as input.
321 * @param ranges Zero or more ranges or numbers.
322 * @returns Returns the created index
323 */
324 index(...ranges: any[]): Index;
325
326 /**
327 * Create a Matrix. The function creates a new math.type.Matrix object
328 * from an Array. A Matrix has utility functions to manipulate the data
329 * in the matrix, like getting the size and getting or setting values in
330 * the matrix. Supported storage formats are 'dense' and 'sparse'.
331 * @param format The Matrix storage format
332 * @returns The created Matrix
333 */
334 matrix(format?: 'sparse' | 'dense'): Matrix;
335 /**
336 * @param data A multi dimensional array
337 * @param format The Matrix storage format
338 * @param dataType The Matrix data type
339 * @returns The created Matrix
340 */
341 matrix(data: MathArray | Matrix, format?: 'sparse' | 'dense', dataType?: string): Matrix;
342
343 /**
344 * Create a number or convert a string, boolean, or unit to a number.
345 * When value is a matrix, all elements will be converted to number.
346 * @param value Value to be converted
347 * @returns The created number
348 */
349 number(value?: string | number | BigNumber | Fraction | boolean | MathArray | Matrix | Unit | null): number | MathArray | Matrix;
350 /**
351 * @param value Value to be converted
352 * @param valuelessUnit A valueless unit, used to convert a unit to a
353 * number
354 * @returns The created number
355 */
356 number(unit: Unit, valuelessUnit: Unit | string): number;
357
358 /**
359 * Create a Sparse Matrix. The function creates a new math.type.Matrix
360 * object from an Array. A Matrix has utility functions to manipulate
361 * the data in the matrix, like getting the size and getting or setting
362 * values in the matrix.
363 * @param data A two dimensional array
364 * @param dataType Sparse Matrix data type
365 * @returns The created matrix
366 */
367 sparse(data?: MathArray | Matrix, dataType?: string): Matrix;
368
369 /**
370 * Split a unit in an array of units whose sum is equal to the original
371 * unit.
372 * @param unit A unit to be split
373 * @param parts An array of strings or valueless units
374 * @returns An array of units
375 */
376 splitUnit(unit: Unit, parts: Unit[]): Unit[];
377
378 /**
379 * Create a string or convert any object into a string. Elements of
380 * Arrays and Matrices are processed element wise.
381 * @param value A value to convert to a string
382 * @returns The created string
383 */
384 string(value: MathType | null): string | MathArray | Matrix;
385
386 /**
387 * Create a unit. Depending on the passed arguments, the function will
388 * create and return a new math.type.Unit object. When a matrix is
389 * provided, all elements will be converted to units.
390 * @param unit The unit to be created
391 * @returns The created unit
392 */
393 unit(unit: string): Unit;
394 /**
395 * @param value The value of the unit to be created
396 * @param unit The unit to be created
397 * @returns The created unit
398 */
399 unit(value: number | MathArray | Matrix, unit: string): Unit;
400
401 /*************************************************************************
402 * Expression functions
403 ************************************************************************/
404
405 /**
406 * Parse and compile an expression. Returns a an object with a function
407 * evaluate([scope]) to evaluate the compiled expression.
408 * @param expr The expression to be compiled
409 * @returns An object with the compiled expression
410 */
411 compile(expr: MathExpression): EvalFunction;
412 /**
413 * @param exprs The expressions to be compiled
414 * @returns An array of objects with the compiled expressions
415 */
416 compile(exprs: MathExpression[]): EvalFunction[];
417
418 /**
419 * Evaluate an expression.
420 * @param expr The expression to be evaluated
421 * @param scope Scope to read/write variables
422 * @returns The result of the expression
423 */
424 evaluate(expr: MathExpression | MathExpression[] | Matrix, scope?: object): any;
425
426 /**
427 * Retrieve help on a function or data type. Help files are retrieved
428 * from the documentation in math.expression.docs.
429 * @param search A function or function name for which to get help
430 * @returns A help object
431 */
432 help(search: () => any): Help;
433
434 /**
435 * Parse an expression. Returns a node tree, which can be evaluated by
436 * invoking node.evaluate();
437 */
438 parse: ParseFunction;
439
440 /**
441 * Create a parser. The function creates a new math.expression.Parser
442 * object.
443 * @returns A Parser object
444 */
445 parser(): Parser;
446
447 /*************************************************************************
448 * Algebra functions
449 ************************************************************************/
450 /**
451 * @param expr The expression to differentiate
452 * @param variable The variable over which to differentiate
453 * @param options There is one option available, simplify, which is true
454 * by default. When false, output will not be simplified.
455 * @returns The derivative of expr
456 */
457 derivative(expr: MathNode | string, variable: MathNode | string, options?: { simplify: boolean }): MathNode;
458
459 /**
460 * Solves the linear equation system by forwards substitution. Matrix
461 * must be a lower triangular matrix.
462 * @param L A N x N matrix or array (L)
463 * @param b A column vector with the b values
464 * @returns A column vector with the linear system solution (x)
465 */
466 lsolve(L: Matrix | MathArray, b: Matrix | MathArray): Matrix | MathArray;
467
468 /**
469 * Calculate the Matrix LU decomposition with partial pivoting. Matrix A
470 * is decomposed in two matrices (L, U) and a row permutation vector p
471 * where A[p,:] = L * U
472 * @param A A two dimensional matrix or array for which to get the LUP
473 * decomposition.
474 * @returns The lower triangular matrix, the upper triangular matrix and
475 * the permutation matrix.
476 */
477 lup(A?: Matrix | MathArray): { L: MathArray | Matrix; U: MathArray | Matrix; P: number[] };
478
479 /**
480 * Solves the linear system A * x = b where A is an [n x n] matrix and b
481 * is a [n] column vector.
482 * @param A Invertible Matrix or the Matrix LU decomposition
483 * @param b Column Vector
484 * @param order The Symbolic Ordering and Analysis order, see slu for
485 * details. Matrix must be a SparseMatrix
486 * @param threshold Partial pivoting threshold (1 for partial pivoting),
487 * see slu for details. Matrix must be a SparseMatrix.
488 * @returns Column vector with the solution to the linear system A * x =
489 * b
490 */
491 lusolve(A: Matrix | MathArray | number, b: Matrix | MathArray, order?: number, threshold?: number): Matrix | MathArray;
492
493 /**
494 * Calculate the Matrix QR decomposition. Matrix A is decomposed in two
495 * matrices (Q, R) where Q is an orthogonal matrix and R is an upper
496 * triangular matrix.
497 * @param A A two dimensional matrix or array for which to get the QR
498 * decomposition.
499 * @returns Q: the orthogonal matrix and R: the upper triangular matrix
500 */
501 qr(A: Matrix | MathArray): { Q: MathArray | Matrix; R: MathArray | Matrix };
502
503 /**
504 * Transform a rationalizable expression in a rational fraction. If
505 * rational fraction is one variable polynomial then converts the
506 * numerator and denominator in canonical form, with decreasing
507 * exponents, returning the coefficients of numerator.
508 * @param expr The expression to check if is a polynomial expression
509 * @param optional scope of expression or true for already evaluated
510 * rational expression at input
511 * @param detailed optional True if return an object, false if return
512 * expression node (default)
513 * @returns The rational polynomial of expr
514 */
515 rationalize(
516 expr: MathNode | string,
517 optional?: object | boolean,
518 detailed?: true
519 ): { expression: MathNode | string; variables: string[]; coefficients: MathType[] };
520 rationalize(expr: MathNode | string, optional?: object | boolean, detailed?: false): MathNode;
521
522 /**
523 * Simplify an expression tree.
524 * @param expr The expression to be simplified
525 * @param rules A list of rules are applied to an expression, repeating
526 * over the list until no further changes are made. It’s possible to
527 * pass a custom set of rules to the function as second argument. A rule
528 * can be specified as an object, string, or function.
529 * @param scope Scope to variables
530 * @returns Returns the simplified form of expr
531 */
532 simplify(
533 expr: MathNode | string,
534 rules?: Array<{ l: string; r: string } | string | ((node: MathNode) => MathNode)>,
535 scope?: object
536 ): MathNode;
537
538 /**
539 * Calculate the Sparse Matrix LU decomposition with full pivoting.
540 * Sparse Matrix A is decomposed in two matrices (L, U) and two
541 * permutation vectors (pinv, q) where P * A * Q = L * U
542 * @param A A two dimensional sparse matrix for which to get the LU
543 * decomposition.
544 * @param order The Symbolic Ordering and Analysis order: 0 - Natural
545 * ordering, no permutation vector q is returned 1 - Matrix must be
546 * square, symbolic ordering and analisis is performed on M = A + A' 2 -
547 * Symbolic ordering and analysis is performed on M = A' * A. Dense
548 * columns from A' are dropped, A recreated from A'. This is appropriate
549 * for LU factorization of non-symmetric matrices. 3 - Symbolic ordering
550 * and analysis is performed on M = A' * A. This is best used for LU
551 * factorization is matrix M has no dense rows. A dense row is a row
552 * with more than 10*sqr(columns) entries.
553 * @param threshold Partial pivoting threshold (1 for partial pivoting)
554 * @returns The lower triangular matrix, the upper triangular matrix and
555 * the permutation vectors.
556 */
557 slu(A: Matrix, order: number, threshold: number): object;
558
559 /**
560 * Solves the linear equation system by backward substitution. Matrix
561 * must be an upper triangular matrix. U * x = b
562 * @param U A N x N matrix or array (U)
563 * @param b A column vector with the b values
564 * @returns A column vector with the linear system solution (x)
565 */
566 usolve(U: Matrix | MathArray, b: Matrix | MathArray): Matrix | MathArray;
567
568 /*************************************************************************
569 * Arithmetic functions
570 ************************************************************************/
571
572 /**
573 * Calculate the absolute value of a number. For matrices, the function
574 * is evaluated element wise.
575 * @param x A number or matrix for which to get the absolute value
576 * @returns Absolute value of x
577 */
578 abs(x: number): number;
579 abs(x: BigNumber): BigNumber;
580 abs(x: Fraction): Fraction;
581 abs(x: Complex): Complex;
582 abs(x: MathArray): MathArray;
583 abs(x: Matrix): Matrix;
584 abs(x: Unit): Unit;
585
586 /**
587 * Add two values, x + y. For matrices, the function is evaluated
588 * element wise.
589 * @param x First value to add
590 * @param y Second value to add
591 * @returns Sum of x and y
592 */
593 add(x: MathType, y: MathType): MathType;
594
595 /**
596 * Calculate the cubic root of a value. For matrices, the function is
597 * evaluated element wise.
598 * @param x Value for which to calculate the cubic root.
599 * @param allRoots Optional, false by default. Only applicable when x is
600 * a number or complex number. If true, all complex roots are returned,
601 * if false (default) the principal root is returned.
602 * @returns Returns the cubic root of x
603 */
604 cbrt(x: number, allRoots?: boolean): number;
605 cbrt(x: BigNumber, allRoots?: boolean): BigNumber;
606 cbrt(x: Fraction, allRoots?: boolean): Fraction;
607 cbrt(x: Complex, allRoots?: boolean): Complex;
608 cbrt(x: MathArray, allRoots?: boolean): MathArray;
609 cbrt(x: Matrix, allRoots?: boolean): Matrix;
610 cbrt(x: Unit, allRoots?: boolean): Unit;
611
612 /**
613 * Round a value towards plus infinity If x is complex, both real and
614 * imaginary part are rounded towards plus infinity. For matrices, the
615 * function is evaluated element wise.
616 * @param x Number to be rounded
617 * @returns Rounded value
618 */
619 ceil(x: number): number;
620 ceil(x: BigNumber): BigNumber;
621 ceil(x: Fraction): Fraction;
622 ceil(x: Complex): Complex;
623 ceil(x: MathArray): MathArray;
624 ceil(x: Matrix): Matrix;
625 ceil(x: Unit): Unit;
626
627 /**
628 * Compute the cube of a value, x * x * x. For matrices, the function is
629 * evaluated element wise.
630 * @param x Number for which to calculate the cube
631 * @returns Cube of x
632 */
633 cube(x: number): number;
634 cube(x: BigNumber): BigNumber;
635 cube(x: Fraction): Fraction;
636 cube(x: Complex): Complex;
637 cube(x: MathArray): MathArray;
638 cube(x: Matrix): Matrix;
639 cube(x: Unit): Unit;
640
641 /**
642 * Divide two values, x / y. To divide matrices, x is multiplied with
643 * the inverse of y: x * inv(y).
644 * @param x Numerator
645 * @param y Denominator
646 * @returns Quotient, x / y
647 */
648 divide(x: Unit, y: Unit): Unit | number;
649 divide(x: number, y: number): number;
650 divide(x: MathType, y: MathType): MathType;
651
652 /**
653 * Divide two matrices element wise. The function accepts both matrices
654 * and scalar values.
655 * @param x Numerator
656 * @param y Denominator
657 * @returns Quotient, x ./ y
658 */
659 dotDivide(x: MathType, y: MathType): MathType;
660
661 /**
662 * Multiply two matrices element wise. The function accepts both
663 * matrices and scalar values.
664 * @param x Left hand value
665 * @param y Right hand value
666 * @returns Multiplication of x and y
667 */
668 dotMultiply(x: MathType, y: MathType): MathType;
669
670 /**
671 * Calculates the power of x to y element wise.
672 * @param x The base
673 * @param y The exponent
674 * @returns The value of x to the power y
675 */
676 dotPow(x: MathType, y: MathType): MathType;
677
678 /**
679 * Calculate the exponent of a value. For matrices, the function is
680 * evaluated element wise.
681 * @param x A number or matrix to exponentiate
682 * @returns Exponent of x
683 */
684 exp(x: number): number;
685 exp(x: BigNumber): BigNumber;
686 exp(x: Complex): Complex;
687 exp(x: MathArray): MathArray;
688 exp(x: Matrix): Matrix;
689
690 /**
691 * Calculate the value of subtracting 1 from the exponential value. For
692 * matrices, the function is evaluated element wise.
693 * @param x A number or matrix to apply expm1
694 * @returns Exponent of x
695 */
696 expm1(x: number): number;
697 expm1(x: BigNumber): BigNumber;
698 expm1(x: Complex): Complex;
699 expm1(x: MathArray): MathArray;
700 expm1(x: Matrix): Matrix;
701
702 /**
703 * Round a value towards zero. For matrices, the function is evaluated
704 * element wise.
705 * @param x Number to be rounded
706 * @returns Rounded value
707 */
708 fix(x: number): number;
709 fix(x: BigNumber): BigNumber;
710 fix(x: Fraction): Fraction;
711 fix(x: Complex): Complex;
712 fix(x: MathArray): MathArray;
713 fix(x: Matrix): Matrix;
714
715 /**
716 * Round a value towards minus infinity. For matrices, the function is
717 * evaluated element wise.
718 * @param Number to be rounded
719 * @returns Rounded value
720 */
721 floor(x: number): number;
722 floor(x: BigNumber): BigNumber;
723 floor(x: Fraction): Fraction;
724 floor(x: Complex): Complex;
725 floor(x: MathArray): MathArray;
726 floor(x: Matrix): Matrix;
727
728 /**
729 * Calculate the greatest common divisor for two or more values or
730 * arrays. For matrices, the function is evaluated element wise.
731 * @param args Two or more integer numbers
732 * @returns The greatest common divisor
733 */
734 gcd(...args: number[]): number;
735 gcd(...args: BigNumber[]): BigNumber;
736 gcd(...args: Fraction[]): Fraction;
737 gcd(...args: MathArray[]): MathArray;
738 gcd(...args: Matrix[]): Matrix;
739
740 /**
741 * Calculate the hypotenusa of a list with values. The hypotenusa is
742 * defined as: hypot(a, b, c, ...) = sqrt(a^2 + b^2 + c^2 + ...) For
743 * matrix input, the hypotenusa is calculated for all values in the
744 * matrix.
745 * @param args A list with numeric values or an Array or Matrix. Matrix
746 * and Array input is flattened and returns a single number for the
747 * whole matrix.
748 * @returns Returns the hypothenuse of the input values.
749 */
750 hypot(...args: number[]): number;
751 hypot(...args: BigNumber[]): BigNumber;
752
753 /**
754 * Calculate the least common multiple for two or more values or arrays.
755 * lcm is defined as: lcm(a, b) = abs(a * b) / gcd(a, b) For matrices,
756 * the function is evaluated element wise.
757 * @param a An integer number
758 * @param b An integer number
759 * @returns The least common multiple
760 */
761 lcm(a: number, b: number): number;
762 lcm(a: BigNumber, b: BigNumber): BigNumber;
763 lcm(a: MathArray, b: MathArray): MathArray;
764 lcm(a: Matrix, b: Matrix): Matrix;
765
766 /**
767 * Calculate the logarithm of a value. For matrices, the function is
768 * evaluated element wise.
769 * @param x Value for which to calculate the logarithm.
770 * @param base Optional base for the logarithm. If not provided, the
771 * natural logarithm of x is calculated. Default value: e.
772 * @returns Returns the logarithm of x
773 */
774 log<T extends number | BigNumber | Complex | MathArray | Matrix>(x: T, base?: number | BigNumber | Complex): NoLiteralType<T>;
775
776 /**
777 * Calculate the 10-base of a value. This is the same as calculating
778 * log(x, 10). For matrices, the function is evaluated element wise.
779 * @param x Value for which to calculate the logarithm.
780 * @returns Returns the 10-base logarithm of x
781 */
782 log10(x: number): number;
783 log10(x: BigNumber): BigNumber;
784 log10(x: Complex): Complex;
785 log10(x: MathArray): MathArray;
786 log10(x: Matrix): Matrix;
787
788 /**
789 * Calculate the logarithm of a value+1. For matrices, the function is
790 * evaluated element wise.
791 * @param x Value for which to calculate the logarithm.
792 * @returns Returns the logarithm of x+1
793 */
794 log1p(x: number, base?: number | BigNumber | Complex): number;
795 log1p(x: BigNumber, base?: number | BigNumber | Complex): BigNumber;
796 log1p(x: Complex, base?: number | BigNumber | Complex): Complex;
797 log1p(x: MathArray, base?: number | BigNumber | Complex): MathArray;
798 log1p(x: Matrix, base?: number | BigNumber | Complex): Matrix;
799
800 /**
801 * Calculate the 2-base of a value. This is the same as calculating
802 * log(x, 2). For matrices, the function is evaluated element wise.
803 * @param x Value for which to calculate the logarithm.
804 * @returns Returns the 2-base logarithm of x
805 */
806 log2(x: number): number;
807 log2(x: BigNumber): BigNumber;
808 log2(x: Complex): Complex;
809 log2(x: MathArray): MathArray;
810 log2(x: Matrix): Matrix;
811
812 /**
813 * Calculates the modulus, the remainder of an integer division. For
814 * matrices, the function is evaluated element wise. The modulus is
815 * defined as: x - y * floor(x / y)
816 * @see http://en.wikipedia.org/wiki/Modulo_operation.
817 * @param x Dividend
818 * @param y Divisor
819 * @returns Returns the remainder of x divided by y
820 */
821 mod<T extends number | BigNumber | Fraction | MathArray | Matrix>(
822 x: T,
823 y: number | BigNumber | Fraction | MathArray | Matrix
824 ): NoLiteralType<T>;
825
826 /**
827 * Multiply two values, x * y. The result is squeezed. For matrices, the
828 * matrix product is calculated.
829 * @param x The first value to multiply
830 * @param y The second value to multiply
831 * @returns Multiplication of x and y
832 */
833 multiply<T extends Matrix | MathArray>(x: T, y: MathType): T;
834 multiply(x: Unit, y: Unit): Unit;
835 multiply(x: number, y: number): number;
836 multiply(x: MathType, y: MathType): MathType;
837
838 /**
839 * Calculate the norm of a number, vector or matrix. The second
840 * parameter p is optional. If not provided, it defaults to 2.
841 * @param x Value for which to calculate the norm
842 * @param p Vector space. Supported numbers include Infinity and
843 * -Infinity. Supported strings are: 'inf', '-inf', and 'fro' (The
844 * Frobenius norm) Default value: 2.
845 * @returns the p-norm
846 */
847 norm(x: number | BigNumber | Complex | MathArray | Matrix, p?: number | BigNumber | string): number | BigNumber;
848
849 /**
850 * Calculate the nth root of a value. The principal nth root of a
851 * positive real number A, is the positive real solution of the equation
852 * x^root = A For matrices, the function is evaluated element wise.
853 * @param a Value for which to calculate the nth root
854 * @param root The root. Default value: 2.
855 * @return The nth root of a
856 */
857 nthRoot(a: number | BigNumber | MathArray | Matrix | Complex, root?: number | BigNumber): number | Complex | MathArray | Matrix;
858
859 /**
860 * Calculates the power of x to y, x ^ y. Matrix exponentiation is
861 * supported for square matrices x, and positive integer exponents y.
862 * @param x The base
863 * @param y The exponent
864 * @returns x to the power y
865 */
866 pow(x: MathType, y: number | BigNumber | Complex): MathType;
867
868 /**
869 * Round a value towards the nearest integer. For matrices, the function
870 * is evaluated element wise.
871 * @param x Number to be rounded
872 * @param n Number of decimals Default value: 0.
873 * @returns Rounded value of x
874 */
875 round<T extends number | BigNumber | Fraction | Complex | MathArray | Matrix>(
876 x: T,
877 n?: number | BigNumber | MathArray
878 ): NoLiteralType<T>;
879
880 /**
881 * Compute the sign of a value. The sign of a value x is: 1 when x > 1
882 * -1 when x < 0 0 when x == 0 For matrices, the function is evaluated
883 * element wise.
884 * @param x The number for which to determine the sign
885 * @returns The sign of x
886 */
887 sign(x: number): number;
888 sign(x: BigNumber): BigNumber;
889 sign(x: Fraction): Fraction;
890 sign(x: Complex): Complex;
891 sign(x: MathArray): MathArray;
892 sign(x: Matrix): Matrix;
893 sign(x: Unit): Unit;
894
895 /**
896 * Calculate the square root of a value. For matrices, the function is
897 * evaluated element wise.
898 * @param x Value for which to calculate the square root
899 * @returns Returns the square root of x
900 */
901 sqrt(x: number): number;
902 sqrt(x: BigNumber): BigNumber;
903 sqrt(x: Complex): Complex;
904 sqrt(x: MathArray): MathArray;
905 sqrt(x: Matrix): Matrix;
906 sqrt(x: Unit): Unit;
907
908 /**
909 * Compute the square of a value, x * x. For matrices, the function is
910 * evaluated element wise.
911 * @param x Number for which to calculate the square
912 * @returns Squared value
913 */
914 square(x: number): number;
915 square(x: BigNumber): BigNumber;
916 square(x: Fraction): Fraction;
917 square(x: Complex): Complex;
918 square(x: MathArray): MathArray;
919 square(x: Matrix): Matrix;
920 square(x: Unit): Unit;
921
922 /**
923 * Subtract two values, x - y. For matrices, the function is evaluated
924 * element wise.
925 * @param x Initial value
926 * @param y Value to subtract from x
927 * @returns Subtraction of x and y
928 */
929 subtract(x: MathType, y: MathType): MathType;
930
931 /**
932 * Inverse the sign of a value, apply a unary minus operation. For
933 * matrices, the function is evaluated element wise. Boolean values and
934 * strings will be converted to a number. For complex numbers, both real
935 * and complex value are inverted.
936 * @param x Number to be inverted
937 * @returns Retursn the value with inverted sign
938 */
939 unaryMinus(x: number): number;
940 unaryMinus(x: BigNumber): BigNumber;
941 unaryMinus(x: Fraction): Fraction;
942 unaryMinus(x: Complex): Complex;
943 unaryMinus(x: MathArray): MathArray;
944 unaryMinus(x: Matrix): Matrix;
945 unaryMinus(x: Unit): Unit;
946
947 /**
948 * Unary plus operation. Boolean values and strings will be converted to
949 * a number, numeric values will be returned as is. For matrices, the
950 * function is evaluated element wise.
951 * @param x Input value
952 * @returns Returns the input value when numeric, converts to a number
953 * when input is non-numeric.
954 */
955 unaryPlus(x: number): number;
956 unaryPlus(x: BigNumber): BigNumber;
957 unaryPlus(x: Fraction): Fraction;
958 unaryPlus(x: string): string;
959 unaryPlus(x: Complex): Complex;
960 unaryPlus(x: MathArray): MathArray;
961 unaryPlus(x: Matrix): Matrix;
962 unaryPlus(x: Unit): Unit;
963
964 /**
965 * Calculate the extended greatest common divisor for two values. See
966 * http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm.
967 * @param a An integer number
968 * @param b An integer number
969 * @returns Returns an array containing 3 integers [div, m, n] where div
970 * = gcd(a, b) and a*m + b*n = div
971 */
972 xgcd(a: number | BigNumber, b: number | BigNumber): MathArray;
973
974 /*************************************************************************
975 * Bitwise functions
976 ************************************************************************/
977
978 /**
979 * Bitwise AND two values, x & y. For matrices, the function is
980 * evaluated element wise.
981 * @param x First value to and
982 * @param y Second value to and
983 * @returns AND of x and y
984 */
985 bitAnd<T extends number | BigNumber | MathArray | Matrix>(x: T, y: number | BigNumber | MathArray | Matrix): NoLiteralType<T>;
986
987 /**
988 * Bitwise NOT value, ~x. For matrices, the function is evaluated
989 * element wise. For units, the function is evaluated on the best prefix
990 * base.
991 * @param x Value to not
992 * @returns NOT of x
993 */
994 bitNot(x: number): number;
995 bitNot(x: BigNumber): BigNumber;
996 bitNot(x: MathArray): MathArray;
997 bitNot(x: Matrix): Matrix;
998
999 /**
1000 * Bitwise OR two values, x | y. For matrices, the function is evaluated
1001 * element wise. For units, the function is evaluated on the lowest
1002 * print base.
1003 * @param x First value to or
1004 * @param y Second value to or
1005 * @returns OR of x and y
1006 */
1007 bitOr(x: number, y: number): number;
1008 bitOr(x: BigNumber, y: BigNumber): BigNumber;
1009 bitOr(x: MathArray, y: MathArray): MathArray;
1010 bitOr(x: Matrix, y: Matrix): Matrix;
1011
1012 /**
1013 * Bitwise XOR two values, x ^ y. For matrices, the function is
1014 * evaluated element wise.
1015 * @param x First value to xor
1016 * @param y Second value to xor
1017 * @returns XOR of x and y
1018 */
1019 bitXor<T extends number | BigNumber | MathArray | Matrix>(x: T, y: number | BigNumber | MathArray | Matrix): NoLiteralType<T>;
1020
1021 /**
1022 * Bitwise left logical shift of a value x by y number of bits, x << y.
1023 * For matrices, the function is evaluated element wise. For units, the
1024 * function is evaluated on the best prefix base.
1025 * @param x Value to be shifted
1026 * @param y Amount of shifts
1027 * @returns x shifted left y times
1028 */
1029 leftShift<T extends number | BigNumber | MathArray | Matrix>(x: T, y: number | BigNumber): NoLiteralType<T>;
1030
1031 /**
1032 * Bitwise right arithmetic shift of a value x by y number of bits, x >>
1033 * y. For matrices, the function is evaluated element wise. For units,
1034 * the function is evaluated on the best prefix base.
1035 * @param x Value to be shifted
1036 * @param y Amount of shifts
1037 * @returns x sign-filled shifted right y times
1038 */
1039 rightArithShift<T extends number | BigNumber | MathArray | Matrix>(x: T, y: number | BigNumber): NoLiteralType<T>;
1040
1041 /**
1042 * Bitwise right logical shift of value x by y number of bits, x >>> y.
1043 * For matrices, the function is evaluated element wise. For units, the
1044 * function is evaluated on the best prefix base.
1045 * @param x Value to be shifted
1046 * @param y Amount of shifts
1047 * @returns x zero-filled shifted right y times
1048 */
1049 rightLogShift<T extends number | MathArray | Matrix>(x: T, y: number): NoLiteralType<T>;
1050
1051 /*************************************************************************
1052 * Combinatorics functions
1053 ************************************************************************/
1054
1055 /**
1056 * The Bell Numbers count the number of partitions of a set. A partition
1057 * is a pairwise disjoint subset of S whose union is S. bellNumbers only
1058 * takes integer arguments. The following condition must be enforced: n
1059 * >= 0
1060 * @param n Total number of objects in the set
1061 * @returns B(n)
1062 */
1063 bellNumbers(n: number): number;
1064 bellNumbers(n: BigNumber): BigNumber;
1065
1066 /**
1067 * The Catalan Numbers enumerate combinatorial structures of many
1068 * different types. catalan only takes integer arguments. The following
1069 * condition must be enforced: n >= 0
1070 * @param n nth Catalan number
1071 * @returns Cn(n)
1072 */
1073 catalan(n: number): number;
1074 catalan(n: BigNumber): BigNumber;
1075
1076 /**
1077 * The composition counts of n into k parts. Composition only takes
1078 * integer arguments. The following condition must be enforced: k <= n.
1079 * @param n Total number of objects in the set
1080 * @param k Number of objects in the subset
1081 * @returns Returns the composition counts of n into k parts.
1082 */
1083 composition<T extends number | BigNumber>(n: T, k: number | BigNumber): NoLiteralType<T>;
1084
1085 /**
1086 * The Stirling numbers of the second kind, counts the number of ways to
1087 * partition a set of n labelled objects into k nonempty unlabelled
1088 * subsets. stirlingS2 only takes integer arguments. The following
1089 * condition must be enforced: k <= n. If n = k or k = 1, then s(n,k) =
1090 * 1
1091 * @param n Total number of objects in the set
1092 * @param k Number of objects in the subset
1093 * @returns S(n,k)
1094 */
1095 stirlingS2<T extends number | BigNumber>(n: T, k: number | BigNumber): NoLiteralType<T>;
1096
1097 /*************************************************************************
1098 * Complex functions
1099 ************************************************************************/
1100
1101 /**
1102 * Compute the argument of a complex value. For a complex number a + bi,
1103 * the argument is computed as atan2(b, a). For matrices, the function
1104 * is evaluated element wise.
1105 * @param x A complex number or array with complex numbers
1106 * @returns The argument of x
1107 */
1108 arg(x: number | Complex): number;
1109 arg(x: BigNumber | Complex): BigNumber;
1110 arg(x: MathArray): MathArray;
1111 arg(x: Matrix): Matrix;
1112
1113 /**
1114 * Compute the complex conjugate of a complex value. If x = a+bi, the
1115 * complex conjugate of x is a - bi. For matrices, the function is
1116 * evaluated element wise.
1117 * @param x A complex number or array with complex numbers
1118 * @returns The complex conjugate of x
1119 */
1120 conj<T extends number | BigNumber | Complex | MathArray | Matrix>(x: T): NoLiteralType<T>;
1121
1122 /**
1123 * Get the imaginary part of a complex number. For a complex number a +
1124 * bi, the function returns b. For matrices, the function is evaluated
1125 * element wise.
1126 * @param x A complex number or array with complex numbers
1127 * @returns The imaginary part of x
1128 */
1129 im(x: number | BigNumber | Complex | MathArray | Matrix): number | BigNumber | MathArray | Matrix;
1130
1131 /**
1132 * Get the real part of a complex number. For a complex number a + bi,
1133 * the function returns a. For matrices, the function is evaluated
1134 * element wise.
1135 * @param x A complex number or array of complex numbers
1136 * @returns The real part of x
1137 */
1138 re(x: number | BigNumber | Complex | MathArray | Matrix): number | BigNumber | MathArray | Matrix;
1139
1140 /*************************************************************************
1141 * Geometry functions
1142 ************************************************************************/
1143
1144 /**
1145 * Calculates: The eucledian distance between two points in 2 and 3
1146 * dimensional spaces. Distance between point and a line in 2 and 3
1147 * dimensional spaces. Pairwise distance between a set of 2D or 3D
1148 * points NOTE: When substituting coefficients of a line(a, b and c),
1149 * use ax + by + c = 0 instead of ax + by = c For parametric equation of
1150 * a 3D line, x0, y0, z0, a, b, c are from: (x−x0, y−y0, z−z0) = t(a, b,
1151 * c)
1152 * @param x Coordinates of the first point
1153 * @param y Coordinates of the second point
1154 * @returns Returns the distance from two/three points
1155 */
1156 distance(x: MathArray | Matrix | object, y: MathArray | Matrix | object): number | BigNumber;
1157
1158 /**
1159 * Calculates the point of intersection of two lines in two or three
1160 * dimensions and of a line and a plane in three dimensions. The inputs
1161 * are in the form of arrays or 1 dimensional matrices. The line
1162 * intersection functions return null if the lines do not meet. Note:
1163 * Fill the plane coefficients as x + y + z = c and not as x + y + z + c
1164 * = 0.
1165 * @param w Co-ordinates of first end-point of first line
1166 * @param x Co-ordinates of second end-point of first line
1167 * @param y Co-ordinates of first end-point of second line OR
1168 * Coefficients of the plane's equation
1169 * @param z Co-ordinates of second end-point of second line OR null if
1170 * the calculation is for line and plane
1171 * @returns Returns the point of intersection of lines/lines-planes
1172 */
1173 intersect(w: MathArray | Matrix, x: MathArray | Matrix, y: MathArray | Matrix, z: MathArray | Matrix): MathArray;
1174
1175 /*************************************************************************
1176 * Logical functions
1177 ************************************************************************/
1178
1179 /**
1180 * Logical and. Test whether two values are both defined with a
1181 * nonzero/nonempty value. For matrices, the function is evaluated
1182 * element wise.
1183 * @param x First value to and
1184 * @param y Second value to and
1185 * @returns Returns true when both inputs are defined with a
1186 * nonzero/nonempty value.
1187 */
1188 and(
1189 x: number | BigNumber | Complex | Unit | MathArray | Matrix,
1190 y: number | BigNumber | Complex | Unit | MathArray | Matrix
1191 ): boolean | MathArray | Matrix;
1192
1193 /**
1194 * Logical not. Flips boolean value of a given parameter. For matrices,
1195 * the function is evaluated element wise.
1196 * @param x First value to not
1197 * @returns Returns true when input is a zero or empty value.
1198 */
1199 not(x: number | BigNumber | Complex | Unit | MathArray | Matrix): boolean | MathArray | Matrix;
1200
1201 /**
1202 * Logical or. Test if at least one value is defined with a
1203 * nonzero/nonempty value. For matrices, the function is evaluated
1204 * element wise.
1205 * @param x First value to or
1206 * @param y Second value to or
1207 * @returns Returns true when one of the inputs is defined with a
1208 * nonzero/nonempty value.
1209 */
1210 or(
1211 x: number | BigNumber | Complex | Unit | MathArray | Matrix,
1212 y: number | BigNumber | Complex | Unit | MathArray | Matrix
1213 ): boolean | MathArray | Matrix;
1214
1215 /**
1216 * Logical xor. Test whether one and only one value is defined with a
1217 * nonzero/nonempty value. For matrices, the function is evaluated
1218 * element wise.
1219 * @param x First value to xor
1220 * @param y Second value to xor
1221 * @returns Returns true when one and only one input is defined with a
1222 * nonzero/nonempty value.
1223 */
1224 xor(
1225 x: number | BigNumber | Complex | Unit | MathArray | Matrix,
1226 y: number | BigNumber | Complex | Unit | MathArray | Matrix
1227 ): boolean | MathArray | Matrix;
1228
1229 /*************************************************************************
1230 * Matrix functions
1231 ************************************************************************/
1232
1233 /**
1234 * Concatenate two or more matrices. dim: number is a zero-based
1235 * dimension over which to concatenate the matrices. By default the last
1236 * dimension of the matrices.
1237 * @param args Two or more matrices
1238 * @returns Concatenated matrix
1239 */
1240 concat(...args: Array<MathArray | Matrix | number | BigNumber>): MathArray | Matrix;
1241
1242 /**
1243 * Calculate the cross product for two vectors in three dimensional
1244 * space. The cross product of A = [a1, a2, a3] and B =[b1, b2, b3] is
1245 * defined as: cross(A, B) = [ a2 * b3 - a3 * b2, a3 * b1 - a1 * b3, a1
1246 * * b2 - a2 * b1 ]
1247 * @param x First vector
1248 * @param y Second vector
1249 * @returns Returns the cross product of x and y
1250 */
1251 cross(x: MathArray | Matrix, y: MathArray | Matrix): Matrix | MathArray;
1252
1253 /**
1254 * Calculate the determinant of a matrix.
1255 * @param x A Matrix
1256 * @returns the determinant of x
1257 */
1258 det(x: MathArray | Matrix): number;
1259
1260 /**
1261 * Create a diagonal matrix or retrieve the diagonal of a matrix. When x
1262 * is a vector, a matrix with vector x on the diagonal will be returned.
1263 * When x is a two dimensional matrix, the matrixes kth diagonal will be
1264 * returned as vector. When k is positive, the values are placed on the
1265 * super diagonal. When k is negative, the values are placed on the sub
1266 * diagonal.
1267 * @param X A two dimensional matrix or a vector
1268 * @param k The diagonal where the vector will be filled in or
1269 * retrieved. Default value: 0.
1270 * @param format The matrix storage format. Default value: 'dense'.
1271 * @returns Diagonal matrix from input vector, or diagonal from input
1272 * matrix
1273 */
1274 diag(X: MathArray | Matrix, format?: string): Matrix;
1275 diag(X: MathArray | Matrix, k: number | BigNumber, format?: string): Matrix | MathArray;
1276
1277 /**
1278 * Calculate the dot product of two vectors. The dot product of A = [a1,
1279 * a2, a3, ..., an] and B = [b1, b2, b3, ..., bn] is defined as: dot(A,
1280 * B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn
1281 * @param x First vector
1282 * @param y Second vector
1283 * @returns Returns the dot product of x and y
1284 */
1285 dot(x: MathArray | Matrix, y: MathArray | Matrix): number;
1286
1287 /**
1288 * Compute eigenvalues and eigenvectors of a matrix.
1289 * The eigenvalues are sorted by their absolute value, ascending.
1290 * An eigenvalue with multiplicity k will be listed k times.
1291 * The eigenvectors are returned as columns of a matrixthe eigenvector
1292 * that belongs to the j-th eigenvalue in the list (eg. values[j]) is the
1293 * j-th column (eg. column(vectors, j)). If the algorithm fails to converge,
1294 * it will throw an errorin that case, however, you may still find useful
1295 * information in err.values and err.vectors
1296 * @param x Matrix to be diagonalized
1297 * @param prec Precision, default value: 1e-15
1298 * @returns Object containing an array of eigenvalues and a matrix with eigenvectors as columns.
1299 */
1300 eigs(x: MathArray | Matrix, prec?:number|BigNumber): {values: MathArray | Matrix, vectors: MathArray | Matrix}
1301
1302 /**
1303 * Compute the matrix exponential, expm(A) = e^A. The matrix must be
1304 * square. Not to be confused with exp(a), which performs element-wise
1305 * exponentiation. The exponential is calculated using the Padé
1306 * approximant with scaling and squaring; seeNineteen Dubious Ways to
1307 * Compute the Exponential of a Matrix,” by Moler and Van Loan.
1308 * @param x A square matrix
1309 * @returns The exponential of x
1310 */
1311 expm(x: Matrix): Matrix;
1312
1313 /**
1314 * Create a 2-dimensional identity matrix with size m x n or n x n. The
1315 * matrix has ones on the diagonal and zeros elsewhere.
1316 * @param size The size for the matrix
1317 * @param format The Matrix storage format
1318 * @returns A matrix with ones on the diagonal
1319 */
1320 identity(size: number | number[] | Matrix | MathArray, format?: string): Matrix | MathArray | number;
1321 /**
1322 * @param m The x dimension for the matrix
1323 * @param n The y dimension for the matrix
1324 * @param format The Matrix storage format
1325 * @returns A matrix with ones on the diagonal
1326 */
1327 identity(m: number, n: number, format?: string): Matrix | MathArray | number;
1328
1329 /**
1330 * Filter the items in an array or one dimensional matrix.
1331 * @param x A one dimensional matrix or array to filter
1332 * @param test A function or regular expression to test items. All
1333 * entries for which test returns true are returned. When test is a
1334 * function, it is invoked with three parameters: the value of the
1335 * element, the index of the element, and the matrix/array being
1336 * traversed. The function must return a boolean.
1337 */
1338 filter(
1339 x: Matrix | MathArray | string[],
1340 test: ((value: any, index: any, matrix: Matrix | MathArray | string[]) => boolean) | RegExp
1341 ): Matrix | MathArray;
1342
1343 /**
1344 * Flatten a multi dimensional matrix into a single dimensional matrix.
1345 * @param x Matrix to be flattened
1346 * @returns Returns the flattened matrix
1347 */
1348 flatten<T extends MathArray | Matrix>(x: T): T;
1349
1350 /**
1351 * Iterate over all elements of a matrix/array, and executes the given
1352 * callback function.
1353 * @param x The matrix to iterate on.
1354 * @param callback The callback function is invoked with three
1355 * parameters: the value of the element, the index of the element, and
1356 * the Matrix/array being traversed.
1357 */
1358 forEach<T extends Matrix | MathArray>(x: T, callback: (value: any, index: any, matrix: T) => void): void;
1359
1360 /**
1361 * Calculate the inverse of a square matrix.
1362 * @param x Matrix to be inversed
1363 * @returns The inverse of x
1364 */
1365 inv<T extends number | Complex | MathArray | Matrix>(x: T): NoLiteralType<T>;
1366
1367 /**
1368 * Calculate the kronecker product of two matrices or vectors
1369 * @param x First vector
1370 * @param y Second vector
1371 * @returns Returns the kronecker product of x and y
1372 */
1373 kron(x: Matrix | MathArray, y: Matrix | MathArray): Matrix;
1374
1375 /**
1376 * Iterate over all elements of a matrix/array, and executes the given
1377 * callback function.
1378 * @param x The matrix to iterate on.
1379 * @param callback The callback function is invoked with three
1380 * parameters: the value of the element, the index of the element, and
1381 * the Matrix/array being traversed.
1382 * @returns Transformed map of x
1383 */
1384 map<T extends Matrix | MathArray>(x: T, callback: (value: any, index: any, matrix: T) => MathType | string): T;
1385
1386 /**
1387 * Create a matrix filled with ones. The created matrix can have one or
1388 * multiple dimensions.
1389 * @param size The size of each dimension of the matrix
1390 * @param format The matrix storage format
1391 * @returns A matrix filled with ones
1392 */
1393 ones(size: number | number[], format?: string): MathArray | Matrix;
1394 /**
1395 * @param m The x dimension of the matrix
1396 * @param n The y dimension of the amtrix
1397 * @param format The matrix storage format
1398 * @returns A matrix filled with ones
1399 */
1400 ones(m: number, n: number, format?: string): MathArray | Matrix;
1401
1402 /**
1403 * Partition-based selection of an array or 1D matrix. Will find the kth
1404 * smallest value, and mutates the input array. Uses Quickselect.
1405 * @param x A one dimensional matrix or array to sort
1406 * @param k The kth smallest value to be retrieved; zero-based index
1407 * @param compare An optional comparator function. The function is
1408 * called as compare(a, b), and must return 1 when a > b, -1 when a < b,
1409 * and 0 when a == b. Default value: 'asc'.
1410 * @returns Returns the kth lowest value.
1411 */
1412 partitionSelect(x: MathArray | Matrix, k: number, compare?: 'asc' | 'desc' | ((a: any, b: any) => number)): any;
1413
1414 /**
1415 * Create an array from a range. By default, the range end is excluded.
1416 * This can be customized by providing an extra parameter includeEnd.
1417 * @param str A string 'start:end' or 'start:step:end'
1418 * @param start Start of the range
1419 * @param end End of the range, excluded by default, included when
1420 * parameter includeEnd=true
1421 * @param step Step size. Default value is 1.
1422 * @param includeEnd: Option to specify whether to include the end or
1423 * not. False by default
1424 * @returns Parameters describing the ranges start, end, and optional
1425 * step.
1426 */
1427 range(str: string, includeEnd?: boolean): Matrix;
1428 range(start: number | BigNumber, end: number | BigNumber, includeEnd?: boolean): Matrix;
1429 range(start: number | BigNumber, end: number | BigNumber, step: number | BigNumber, includeEnd?: boolean): Matrix;
1430
1431 /**
1432 * Reshape a multi dimensional array to fit the specified dimensions
1433 * @param x Matrix to be reshaped
1434 * @param sizes One dimensional array with integral sizes for each
1435 * dimension
1436 * @returns A reshaped clone of matrix x
1437 */
1438 reshape<T extends MathArray | Matrix>(x: T, sizes: number[]): T;
1439
1440 /**
1441 * Resize a matrix
1442 * @param x Matrix to be resized
1443 * @param size One dimensional array with numbers
1444 * @param defaultValue Zero by default, except in case of a string, in
1445 * that case defaultValue = ' ' Default value: 0.
1446 * @returns A resized clone of matrix x
1447 */
1448 resize<T extends MathArray | Matrix>(x: T, size: MathArray | Matrix, defaultValue?: number | string): T;
1449
1450 /**
1451 * Return a row from a Matrix.
1452 * @param value An array or matrix
1453 * @param row The index of the row
1454 * @returns The retrieved row
1455 */
1456 row<T extends MathArray | Matrix>(
1457 value: T,
1458 row: number
1459 ): T;
1460
1461 /**
1462 * Return a column from a Matrix.
1463 * @param value An array or matrix
1464 * @param column The index of the column
1465 * @returns The retrieved column
1466 */
1467 column<T extends MathArray | Matrix>(
1468 value: T,
1469 column: number
1470 ): T;
1471
1472 /**
1473 * Calculate the size of a matrix or scalar.
1474 * @param A matrix
1475 * @returns A vector with the size of x
1476 */
1477 size(x: boolean | number | Complex | Unit | string | MathArray | Matrix): MathArray | Matrix;
1478
1479 /**
1480 * Sort the items in a matrix
1481 * @param x A one dimensional matrix or array to sort
1482 * @param compare An optional _comparator function or name. The function
1483 * is called as compare(a, b), and must return 1 when a > b, -1 when a <
1484 * b, and 0 when a == b. Default value: ‘asc
1485 * @returns Returns the sorted matrix
1486 */
1487 sort<T extends Matrix | MathArray>(x: T, compare: ((a: any, b: any) => number) | 'asc' | 'desc' | 'natural'): T;
1488
1489 /**
1490 * Calculate the principal square root of a square matrix. The principal
1491 * square root matrix X of another matrix A is such that X * X = A.
1492 * @param A The square matrix A
1493 * @returns The principal square root of matrix A
1494 */
1495 sqrtm<T extends MathArray | Matrix>(A: T): T;
1496
1497 /**
1498 * Squeeze a matrix, remove inner and outer singleton dimensions from a
1499 * matrix.
1500 * @param x Matrix to be squeezed
1501 * @returns Squeezed matrix
1502 */
1503 squeeze<T extends MathArray | Matrix>(x: T): T;
1504
1505 /**
1506 * Get or set a subset of a matrix or string.
1507 * @param value An array, matrix, or string
1508 * @param index An index containing ranges for each dimension
1509 * @param replacement An array, matrix, or scalar. If provided, the
1510 * subset is replaced with replacement. If not provided, the subset is
1511 * returned
1512 * @param defaultValue Default value, filled in on new entries when the
1513 * matrix is resized. If not provided, math.matrix elements will be left
1514 * undefined. Default value: undefined.
1515 * @returns Either the retrieved subset or the updated matrix
1516 */
1517 subset<T extends MathArray | Matrix | string>(value: T, index: Index, replacement?: any, defaultValue?: any): T;
1518
1519 /**
1520 * Calculate the trace of a matrix: the sum of the elements on the main
1521 * diagonal of a square matrix.
1522 * @param x A matrix
1523 * @returns The trace of x
1524 */
1525 trace(x: MathArray | Matrix): number;
1526
1527 /**
1528 * Transpose a matrix. All values of the matrix are reflected over its
1529 * main diagonal. Only two dimensional matrices are supported.
1530 * @param x Matrix to be transposed
1531 * @returns The transposed matrix
1532 */
1533 transpose<T extends MathArray | Matrix>(x: T): T;
1534
1535 /**
1536 * Create a matrix filled with zeros. The created matrix can have one or
1537 * multiple dimensions.
1538 * @param size The size of each dimension of the matrix
1539 * @param format The matrix storage format
1540 * @returns A matrix filled with zeros
1541 */
1542 zeros(size: number | number[], format?: string): MathArray | Matrix;
1543 /**
1544 * @param m The x dimension of the matrix
1545 * @param n The y dimension of the matrix
1546 * @param format The matrix storage format
1547 * @returns A matrix filled with zeros
1548 */
1549 zeros(m: number, n: number, format?: string): MathArray | Matrix;
1550
1551 /*************************************************************************
1552 * Probability functions
1553 ************************************************************************/
1554
1555 /**
1556 * Compute the number of ways of picking k unordered outcomes from n
1557 * possibilities. Combinations only takes integer arguments. The
1558 * following condition must be enforced: k <= n.
1559 * @param n Total number of objects in the set
1560 * @param k Number of objects in the subset
1561 * @returns Number of possible combinations
1562 */
1563 combinations<T extends number | BigNumber>(n: T, k: number | BigNumber): NoLiteralType<T>;
1564
1565 /**
1566 * Compute the factorial of a value Factorial only supports an integer
1567 * value as argument. For matrices, the function is evaluated element
1568 * wise.
1569 * @param n An integer number
1570 * @returns The factorial of n
1571 */
1572 factorial<T extends number | BigNumber | MathArray | Matrix>(n: T): NoLiteralType<T>;
1573
1574 /**
1575 * Compute the gamma function of a value using Lanczos approximation for
1576 * small values, and an extended Stirling approximation for large
1577 * values. For matrices, the function is evaluated element wise.
1578 * @param n A real or complex number
1579 * @returns The gamma of n
1580 */
1581 gamma(n: number | MathArray | Matrix): number | MathArray | Matrix;
1582
1583 /**
1584 * Calculate the Kullback-Leibler (KL) divergence between two
1585 * distributions
1586 * @param q First vector
1587 * @param p Second vector
1588 * @returns Returns disance between q and p
1589 */
1590 kldivergence(q: MathArray | Matrix, p: MathArray | Matrix): number;
1591
1592 /**
1593 * Multinomial Coefficients compute the number of ways of picking a1,
1594 * a2, ..., ai unordered outcomes from n possibilities. multinomial
1595 * takes one array of integers as an argument. The following condition
1596 * must be enforced: every ai <= 0
1597 * @param a Integer number of objects in the subset
1598 * @returns multinomial coefficent
1599 */
1600 multinomial<T extends number | BigNumber>(a: T[]): NoLiteralType<T>;
1601
1602 /**
1603 * Compute the number of ways of obtaining an ordered subset of k
1604 * elements from a set of n elements. Permutations only takes integer
1605 * arguments. The following condition must be enforced: k <= n.
1606 * @param n The number of objects in total
1607 * @param k The number of objects in the subset
1608 * @returns The number of permutations
1609 */
1610 permutations<T extends number | BigNumber>(n: T, k?: number | BigNumber): NoLiteralType<T>;
1611
1612 /**
1613 * Random pick a value from a one dimensional array. Array element is
1614 * picked using a random function with uniform distribution.
1615 * @param array A one dimensional array
1616 * @param number An int or float
1617 * @param weights An array of ints or floats
1618 * @returns Returns a single random value from array when number is 1 or
1619 * undefined. Returns an array with the configured number of elements
1620 * when number is > 1.
1621 */
1622 pickRandom(array: number[], number?: number, weights?: number[]): number | number[];
1623
1624 /**
1625 * Return a random number larger or equal to min and smaller than max
1626 * using a uniform distribution.
1627 * @param size If provided, an array or matrix with given size and
1628 * filled with random values is returned
1629 * @param min Minimum boundary for the random value, included
1630 * @param max Maximum boundary for the random value, excluded
1631 * @returns A random number
1632 */
1633 random(min?: number, max?: number): number;
1634 random<T extends MathArray | Matrix>(size: T, min?: number, max?: number): T;
1635
1636 /**
1637 * Return a random integer number larger or equal to min and smaller
1638 * than max using a uniform distribution.
1639 * @param size If provided, an array or matrix with given size and
1640 * filled with random values is returned
1641 * @param min Minimum boundary for the random value, included
1642 * @param max Maximum boundary for the random value, excluded
1643 * @returns A random number
1644 */
1645 randomInt(min: number, max?: number): number;
1646 randomInt<T extends MathArray | Matrix>(size: T, min?: number, max?: number): T;
1647
1648 /*************************************************************************
1649 * Relational functions
1650 ************************************************************************/
1651
1652 /**
1653 * Compare two values. Returns 1 when x > y, -1 when x < y, and 0 when x
1654 * == y. x and y are considered equal when the relative difference
1655 * between x and y is smaller than the configured epsilon. The function
1656 * cannot be used to compare values smaller than approximately 2.22e-16.
1657 * For matrices, the function is evaluated element wise.
1658 * @param x First value to compare
1659 * @param y Second value to compare
1660 * @returns Returns the result of the comparison: 1 when x > y, -1 when
1661 * x < y, and 0 when x == y.
1662 */
1663 compare(x: MathType | string, y: MathType | string): number | BigNumber | Fraction | MathArray | Matrix;
1664
1665 /**
1666 * Compare two values of any type in a deterministic, natural way. For
1667 * numeric values, the function works the same as math.compare. For
1668 * types of values that cant be compared mathematically, the function
1669 * compares in a natural way.
1670 * @param x First value to compare
1671 * @param y Second value to compare
1672 * @returns Returns the result of the comparison: 1 when x > y, -1 when
1673 * x < y, and 0 when x == y.
1674 */
1675 compareNatural(x: any, y: any): number;
1676
1677 /**
1678 * Compare two strings lexically. Comparison is case sensitive. Returns
1679 * 1 when x > y, -1 when x < y, and 0 when x == y. For matrices, the
1680 * function is evaluated element wise.
1681 * @param x First string to compare
1682 * @param y Second string to compare
1683 * @returns Returns the result of the comparison: 1 when x > y, -1 when
1684 * x < y, and 0 when x == y.
1685 */
1686 compareText(x: string | MathArray | Matrix, y: string | MathArray | Matrix): number | MathArray | Matrix;
1687
1688 /**
1689 * Test element wise whether two matrices are equal. The function
1690 * accepts both matrices and scalar values.
1691 * @param x First matrix to compare
1692 * @param y Second amtrix to compare
1693 * @returns Returns true when the input matrices have the same size and
1694 * each of their elements is equal.
1695 */
1696 deepEqual(x: MathType, y: MathType): number | BigNumber | Fraction | Complex | Unit | MathArray | Matrix;
1697
1698 /**
1699 * Test whether two values are equal.
1700 *
1701 * The function tests whether the relative difference between x and y is
1702 * smaller than the configured epsilon. The function cannot be used to
1703 * compare values smaller than approximately 2.22e-16. For matrices, the
1704 * function is evaluated element wise. In case of complex numbers, x.re
1705 * must equal y.re, and x.im must equal y.im. Values null and undefined
1706 * are compared strictly, thus null is only equal to null and nothing
1707 * else, and undefined is only equal to undefined and nothing else.
1708 * @param x First value to compare
1709 * @param y Second value to compare
1710 * @returns Returns true when the compared values are equal, else
1711 * returns false
1712 */
1713 equal(x: MathType | string, y: MathType | string): boolean | MathArray | Matrix;
1714
1715 /**
1716 * Check equality of two strings. Comparison is case sensitive. For
1717 * matrices, the function is evaluated element wise.
1718 * @param x First string to compare
1719 * @param y Second string to compare
1720 * @returns Returns true if the values are equal, and false if not.
1721 */
1722 equalText(x: string | MathArray | Matrix, y: string | MathArray | Matrix): number | MathArray | Matrix;
1723
1724 /**
1725 * Test whether value x is larger than y. The function returns true when
1726 * x is larger than y and the relative difference between x and y is
1727 * larger than the configured epsilon. The function cannot be used to
1728 * compare values smaller than approximately 2.22e-16. For matrices, the
1729 * function is evaluated element wise.
1730 * @param x First value to compare
1731 * @param y Second value to vcompare
1732 * @returns Returns true when x is larger than y, else returns false
1733 */
1734 larger(x: MathType | string, y: MathType | string): boolean | MathArray | Matrix;
1735
1736 /**
1737 * Test whether value x is larger or equal to y. The function returns
1738 * true when x is larger than y or the relative difference between x and
1739 * y is smaller than the configured epsilon. The function cannot be used
1740 * to compare values smaller than approximately 2.22e-16. For matrices,
1741 * the function is evaluated element wise.
1742 * @param x First value to compare
1743 * @param y Second value to vcompare
1744 * @returns Returns true when x is larger than or equal to y, else
1745 * returns false
1746 */
1747 largerEq(x: MathType | string, y: MathType | string): boolean | MathArray | Matrix;
1748
1749 /**
1750 * Test whether value x is smaller than y. The function returns true
1751 * when x is smaller than y and the relative difference between x and y
1752 * is smaller than the configured epsilon. The function cannot be used
1753 * to compare values smaller than approximately 2.22e-16. For matrices,
1754 * the function is evaluated element wise.
1755 * @param x First value to compare
1756 * @param y Second value to vcompare
1757 * @returns Returns true when x is smaller than y, else returns false
1758 */
1759 smaller(x: MathType | string, y: MathType | string): boolean | MathArray | Matrix;
1760
1761 /**
1762 * Test whether value x is smaller or equal to y. The function returns
1763 * true when x is smaller than y or the relative difference between x
1764 * and y is smaller than the configured epsilon. The function cannot be
1765 * used to compare values smaller than approximately 2.22e-16. For
1766 * matrices, the function is evaluated element wise.
1767 * @param x First value to compare
1768 * @param y Second value to vcompare
1769 * @returns Returns true when x is smaller than or equal to y, else
1770 * returns false
1771 */
1772 smallerEq(x: MathType | string, y: MathType | string): boolean | MathArray | Matrix;
1773
1774 /**
1775 * Test whether two values are unequal. The function tests whether the
1776 * relative difference between x and y is larger than the configured
1777 * epsilon. The function cannot be used to compare values smaller than
1778 * approximately 2.22e-16. For matrices, the function is evaluated
1779 * element wise. In case of complex numbers, x.re must unequal y.re, or
1780 * x.im must unequal y.im. Values null and undefined are compared
1781 * strictly, thus null is unequal with everything except null, and
1782 * undefined is unequal with everything except undefined.
1783 * @param x First value to compare
1784 * @param y Second value to vcompare
1785 * @returns Returns true when the compared values are unequal, else
1786 * returns false
1787 */
1788 unequal(x: MathType | string, y: MathType | string): boolean | MathArray | Matrix;
1789
1790 /*************************************************************************
1791 * Set functions
1792 ************************************************************************/
1793
1794 /**
1795 * Create the cartesian product of two (multi)sets. Multi-dimension
1796 * arrays will be converted to single-dimension arrays before the
1797 * operation.
1798 * @param a1 A (multi)set
1799 * @param a2 A (multi)set
1800 * @returns The cartesian product of two (multi)sets
1801 */
1802 setCartesian<T extends MathArray | Matrix>(a1: T, a2: MathArray | Matrix): T;
1803
1804 /**
1805 * Create the difference of two (multi)sets: every element of set1, that
1806 * is not the element of set2. Multi-dimension arrays will be converted
1807 * to single-dimension arrays before the operation
1808 * @param a1 A (multi)set
1809 * @param a2 A (multi)set
1810 * @returns The difference of two (multi)sets
1811 */
1812 setDifference<T extends MathArray | Matrix>(a1: T, a2: MathArray | Matrix): T;
1813
1814 /**
1815 * Collect the distinct elements of a multiset. A multi-dimension array
1816 * will be converted to a single-dimension array before the operation.
1817 * @param a A multiset
1818 * @returns A set containing the distinct elements of the multiset
1819 */
1820 setDistinct<T extends MathArray | Matrix>(a: T): T;
1821
1822 /**
1823 * Create the intersection of two (multi)sets. Multi-dimension arrays
1824 * will be converted to single-dimension arrays before the operation.
1825 * @param a1 A (multi)set
1826 * @param a2 A (multi)set
1827 * @returns The intersection of two (multi)sets
1828 */
1829 setIntersect<T extends MathArray | Matrix>(a1: T, a2: MathArray | Matrix): T;
1830
1831 /**
1832 * Check whether a (multi)set is a subset of another (multi)set. (Every
1833 * element of set1 is the element of set2.) Multi-dimension arrays will
1834 * be converted to single-dimension arrays before the operation.
1835 * @param a1 A (multi)set
1836 * @param a2 A (multi)set
1837 * @returns True if a1 is subset of a2, else false
1838 */
1839 setIsSubset(a1: MathArray | Matrix, a2: MathArray | Matrix): boolean;
1840
1841 /**
1842 * Count the multiplicity of an element in a multiset. A multi-dimension
1843 * array will be converted to a single-dimension array before the
1844 * operation.
1845 * @param e An element in the multiset
1846 * @param a A multiset
1847 * @returns The number of how many times the multiset contains the
1848 * element
1849 */
1850 setMultiplicity(e: number | BigNumber | Fraction | Complex, a: MathArray | Matrix): number;
1851
1852 /**
1853 * Create the powerset of a (multi)set. (The powerset contains very
1854 * possible subsets of a (multi)set.) A multi-dimension array will be
1855 * converted to a single-dimension array before the operation.
1856 * @param a A multiset
1857 * @returns The powerset of the (multi)set
1858 */
1859 setPowerset<T extends MathArray | Matrix>(a: T): T;
1860
1861 /**
1862 * Count the number of elements of a (multi)set. When a second parameter
1863 * istrue’, count only the unique values. A multi-dimension array will
1864 * be converted to a single-dimension array before the operation.
1865 * @param a A multiset
1866 * @returns The number of elements of the (multi)set
1867 */
1868 setSize(a: MathArray | Matrix): number;
1869
1870 /**
1871 * Create the symmetric difference of two (multi)sets. Multi-dimension
1872 * arrays will be converted to single-dimension arrays before the
1873 * operation.
1874 * @param a1 A (multi)set
1875 * @param a2 A (multi)set
1876 * @returns The symmetric difference of two (multi)sets
1877 */
1878 setSymDifference<T extends MathArray | Matrix>(a1: T, a2: MathArray | Matrix): T;
1879
1880 /**
1881 * Create the union of two (multi)sets. Multi-dimension arrays will be
1882 * converted to single-dimension arrays before the operation.
1883 * @param a1 A (multi)set
1884 * @param a2 A (multi)set
1885 * @returns The union of two (multi)sets
1886 */
1887 setUnion<T extends MathArray | Matrix>(a1: T, a2: MathArray | Matrix): T;
1888
1889 /*************************************************************************
1890 * Special functions
1891 ************************************************************************/
1892
1893 /**
1894 * Compute the erf function of a value using a rational Chebyshev
1895 * approximations for different intervals of x.
1896 * @param x A real number
1897 * @returns The erf of x
1898 */
1899 erf<T extends number | MathArray | Matrix>(x: T): NoLiteralType<T>;
1900
1901 /*************************************************************************
1902 * Statistics functions
1903 ************************************************************************/
1904
1905 /**
1906 * Compute the median absolute deviation of a matrix or a list with
1907 * values. The median absolute deviation is defined as the median of the
1908 * absolute deviations from the median.
1909 * @param array A single matrix or multiple scalar values.
1910 * @returns The median absolute deviation
1911 */
1912 mad(array: MathArray | Matrix): any;
1913
1914 /**
1915 * Compute the maximum value of a matrix or a list with values. In case
1916 * of a multi dimensional array, the maximum of the flattened array will
1917 * be calculated. When dim is provided, the maximum over the selected
1918 * dimension will be calculated. Parameter dim is zero-based.
1919 * @param args A single matrix or multiple scalar values
1920 * @returns The maximum value
1921 */
1922 max(...args: MathType[]): any;
1923 /**
1924 * @param A A single matrix
1925 * @param dim The maximum over the selected dimension
1926 * @returns The maximum value
1927 */
1928 max(A: MathArray | Matrix, dim?: number): any;
1929
1930 /**
1931 * Compute the mean value of matrix or a list with values. In case of a
1932 * multi dimensional array, the mean of the flattened array will be
1933 * calculated. When dim is provided, the maximum over the selected
1934 * dimension will be calculated. Parameter dim is zero-based.
1935 * @param args A single matrix or multiple scalar values
1936 * @returns The mean of all values
1937 */
1938 mean(...args: MathType[]): any;
1939 /**
1940 * @param A A single matrix
1941 * @param dim The mean over the selected dimension
1942 * @returns The mean of all values
1943 */
1944 mean(A: MathArray | Matrix, dim?: number): any;
1945
1946 /**
1947 * Compute the median of a matrix or a list with values. The values are
1948 * sorted and the middle value is returned. In case of an even number of
1949 * values, the average of the two middle values is returned. Supported
1950 * types of values are: Number, BigNumber, Unit In case of a (multi
1951 * dimensional) array or matrix, the median of all elements will be
1952 * calculated.
1953 * @param args A single matrix or or multiple scalar values
1954 * @returns The median
1955 */
1956 median(...args: MathType[]): any;
1957
1958 /**
1959 * Compute the maximum value of a matrix or a list of values. In case of
1960 * a multi dimensional array, the maximum of the flattened array will be
1961 * calculated. When dim is provided, the maximum over the selected
1962 * dimension will be calculated. Parameter dim is zero-based.
1963 * @param args A single matrix or or multiple scalar values
1964 * @returns The minimum value
1965 */
1966 min(...args: MathType[]): any;
1967 /**
1968 * @param A A single matrix
1969 * @param dim The minimum over the selected dimension
1970 * @returns The minimum value
1971 */
1972 min(A: MathArray | Matrix, dim?: number): any;
1973
1974 /**
1975 * Computes the mode of a set of numbers or a list with values(numbers
1976 * or characters). If there are more than one modes, it returns a list
1977 * of those values.
1978 * @param args A single matrix
1979 * @returns The mode of all values
1980 */
1981 mode(...args: MathType[]): any;
1982
1983 /**
1984 * Compute the product of a matrix or a list with values. In case of a
1985 * (multi dimensional) array or matrix, the sum of all elements will be
1986 * calculated.
1987 * @param args A single matrix or multiple scalar values
1988 * @returns The product of all values
1989 */
1990 prod(...args: MathType[]): any;
1991
1992 /**
1993 * Compute the prob order quantile of a matrix or a list with values.
1994 * The sequence is sorted and the middle value is returned. Supported
1995 * types of sequence values are: Number, BigNumber, Unit Supported types
1996 * of probability are: Number, BigNumber In case of a (multi
1997 * dimensional) array or matrix, the prob order quantile of all elements
1998 * will be calculated.
1999 * @param A A single matrix or array
2000 * @param probOrN prob is the order of the quantile, while N is the
2001 * amount of evenly distributed steps of probabilities; only one of
2002 * these options can be provided
2003 * @param sorted =false is data sorted in ascending order
2004 * @returns Quantile(s)
2005 */
2006 quantileSeq(A: MathArray | Matrix, prob: number | BigNumber | MathArray, sorted?: boolean): number | BigNumber | Unit | MathArray;
2007
2008 /**
2009 * Compute the standard deviation of a matrix or a list with values. The
2010 * standard deviations is defined as the square root of the variance:
2011 * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or
2012 * matrix, the standard deviation over all elements will be calculated.
2013 * Optionally, the type of normalization can be specified as second
2014 * parameter. The parameter normalization can be one of the following
2015 * values: 'unbiased' (default) The sum of squared errors is divided by
2016 * (n - 1) 'uncorrected' The sum of squared errors is divided by n
2017 * 'biased' The sum of squared errors is divided by (n + 1)
2018 * @param array A single matrix or multiple scalar values
2019 * @param normalization Determines how to normalize the variance. Choose
2020 * ‘unbiased’ (default), ‘uncorrected’, orbiased’. Default value:
2021 * ‘unbiased’.
2022 * @returns The standard deviation
2023 */
2024 std(array: MathArray | Matrix, normalization?: 'unbiased' | 'uncorrected' | 'biased' | 'unbiased'): number;
2025
2026 /**
2027 * Compute the sum of a matrix or a list with values. In case of a
2028 * (multi dimensional) array or matrix, the sum of all elements will be
2029 * calculated.
2030 * @param args A single matrix or multiple scalar values
2031 * @returns The sum of all values
2032 */
2033 sum(...args: Array<number | BigNumber | Fraction>): any;
2034 /**
2035 * @param array A single matrix
2036 * @returns The sum of all values
2037 */
2038 sum(array: MathArray | Matrix): any;
2039
2040 /**
2041 * Compute the variance of a matrix or a list with values. In case of a
2042 * (multi dimensional) array or matrix, the variance over all elements
2043 * will be calculated. Optionally, the type of normalization can be
2044 * specified as second parameter. The parameter normalization can be one
2045 * of the following values: 'unbiased' (default) The sum of squared
2046 * errors is divided by (n - 1) 'uncorrected' The sum of squared errors
2047 * is divided by n 'biased' The sum of squared errors is divided by (n +
2048 * 1) Note that older browser may not like the variable name var. In
2049 * that case, the function can be called as math['var'](...) instead of
2050 * math.variance(...).
2051 * @param args A single matrix or multiple scalar values
2052 * @returns The variance
2053 */
2054 variance(...args: Array<number | BigNumber | Fraction>): any;
2055 /**
2056 * @param array A single matrix
2057 * @param normalization normalization Determines how to normalize the
2058 * variance. Chooseunbiased’ (default), ‘uncorrected’, orbiased’.
2059 * Default value: ‘unbiased’.
2060 * @returns The variance
2061 */
2062 variance(array: MathArray | Matrix, normalization?: 'unbiased' | 'uncorrected' | 'biased' | 'unbiased'): any;
2063
2064 /*************************************************************************
2065 * String functions
2066 ************************************************************************/
2067
2068 /**
2069 * Format a value of any type into a string.
2070 * @param value The value to be formatted
2071 * @param options An object with formatting options.
2072 * @param callback A custom formatting function, invoked for all numeric
2073 * elements in value, for example all elements of a matrix, or the real
2074 * and imaginary parts of a complex number. This callback can be used to
2075 * override the built-in numeric notation with any type of formatting.
2076 * Function callback is called with value as parameter and must return a
2077 * string.
2078 * @see http://mathjs.org/docs/reference/functions/format.html
2079 * @returns The formatted value
2080 */
2081 format(value: any, options?: FormatOptions | number | ((item: any) => string), callback?: (value: any) => string): string;
2082
2083 /**
2084 * Interpolate values into a string template.
2085 * @param template A string containing variable placeholders.
2086 * @param values An object containing variables which will be filled in
2087 * in the template.
2088 * @param precision Number of digits to format numbers. If not provided,
2089 * the value will not be rounded.
2090 * @param options Formatting options, or the number of digits to format
2091 * numbers. See function math.format for a description of all options.
2092 * @returns Interpolated string
2093 */
2094 print(template: string, values: any, precision?: number, options?: number | object): void;
2095
2096 /*************************************************************************
2097 * Trigonometry functions
2098 ************************************************************************/
2099
2100 /**
2101 * Calculate the inverse cosine of a value. For matrices, the function
2102 * is evaluated element wise.
2103 * @param x Function input
2104 * @returns The arc cosine of x
2105 */
2106 acos(x: number): number;
2107 acos(x: BigNumber): BigNumber;
2108 acos(x: Complex): Complex;
2109 acos(x: MathArray): MathArray;
2110 acos(x: Matrix): Matrix;
2111
2112 /**
2113 * Calculate the hyperbolic arccos of a value, defined as acosh(x) =
2114 * ln(sqrt(x^2 - 1) + x). For matrices, the function is evaluated
2115 * element wise.
2116 * @param x Function input
2117 * @returns The hyperbolic arccosine of x
2118 */
2119 acosh(x: number): number;
2120 acosh(x: BigNumber): BigNumber;
2121 acosh(x: Complex): Complex;
2122 acosh(x: MathArray): MathArray;
2123 acosh(x: Matrix): Matrix;
2124
2125 /**
2126 * Calculate the inverse cotangent of a value. For matrices, the
2127 * function is evaluated element wise.
2128 * @param x Function input
2129 * @returns The arc cotangent of x
2130 */
2131 acot(x: number): number;
2132 acot(x: BigNumber): BigNumber;
2133 acot(x: MathArray): MathArray;
2134 acot(x: Matrix): Matrix;
2135
2136 /**
2137 * Calculate the hyperbolic arccotangent of a value, defined as acoth(x)
2138 * = (ln((x+1)/x) + ln(x/(x-1))) / 2. For matrices, the function is
2139 * evaluated element wise.
2140 * @param x Function input
2141 * @returns The hyperbolic arccotangent of x
2142 */
2143 acoth(x: number): number;
2144 acoth(x: BigNumber): BigNumber;
2145 acoth(x: MathArray): MathArray;
2146 acoth(x: Matrix): Matrix;
2147
2148 /**
2149 * Calculate the inverse cosecant of a value. For matrices, the function
2150 * is evaluated element wise.
2151 * @param x Function input
2152 * @returns The arc cosecant of x
2153 */
2154 acsc(x: number): number;
2155 acsc(x: BigNumber): BigNumber;
2156 acsc(x: MathArray): MathArray;
2157 acsc(x: Matrix): Matrix;
2158
2159 /**
2160 * Calculate the hyperbolic arccosecant of a value, defined as acsch(x)
2161 * = ln(1/x + sqrt(1/x^2 + 1)). For matrices, the function is evaluated
2162 * element wise.
2163 * @param x Function input
2164 * @returns The hyperbolic arccosecant of x
2165 */
2166 acsch(x: number): number;
2167 acsch(x: BigNumber): BigNumber;
2168 acsch(x: MathArray): MathArray;
2169 acsch(x: Matrix): Matrix;
2170
2171 /**
2172 * Calculate the inverse secant of a value. For matrices, the function
2173 * is evaluated element wise.
2174 * @param x Function input
2175 * @returns The arc secant of x
2176 */
2177 asec(x: number): number;
2178 asec(x: BigNumber): BigNumber;
2179 asec(x: MathArray): MathArray;
2180 asec(x: Matrix): Matrix;
2181
2182 /**
2183 * Calculate the hyperbolic arcsecant of a value, defined as asech(x) =
2184 * ln(sqrt(1/x^2 - 1) + 1/x). For matrices, the function is evaluated
2185 * element wise.
2186 * @param x Function input
2187 * @returns The hyperbolic arcsecant of x
2188 */
2189 asech(x: number): number;
2190 asech(x: BigNumber): BigNumber;
2191 asech(x: MathArray): MathArray;
2192 asech(x: Matrix): Matrix;
2193
2194 /**
2195 * Calculate the inverse sine of a value. For matrices, the function is
2196 * evaluated element wise.
2197 * @param x Function input
2198 * @returns The arc sine of x
2199 */
2200 asin(x: number): number;
2201 asin(x: BigNumber): BigNumber;
2202 asin(x: Complex): Complex;
2203 asin(x: MathArray): MathArray;
2204 asin(x: Matrix): Matrix;
2205
2206 /**
2207 * Calculate the hyperbolic arcsine of a value, defined as asinh(x) =
2208 * ln(x + sqrt(x^2 + 1)). For matrices, the function is evaluated
2209 * element wise.
2210 * @param x Function input
2211 * @returns The hyperbolic arcsine of x
2212 */
2213 asinh(x: number): number;
2214 asinh(x: BigNumber): BigNumber;
2215 asinh(x: MathArray): MathArray;
2216 asinh(x: Matrix): Matrix;
2217
2218 /**
2219 * Calculate the inverse tangent of a value. For matrices, the function
2220 * is evaluated element wise.
2221 * @param x Function input
2222 * @returns The arc tangent of x
2223 */
2224 atan(x: number): number;
2225 atan(x: BigNumber): BigNumber;
2226 atan(x: MathArray): MathArray;
2227 atan(x: Matrix): Matrix;
2228
2229 /**
2230 * Calculate the inverse tangent function with two arguments, y/x. By
2231 * providing two arguments, the right quadrant of the computed angle can
2232 * be determined. For matrices, the function is evaluated element wise.
2233 * @param x Function input
2234 * @returns Four quadrant inverse tangent
2235 */
2236 atan2(y: number, x: number): number;
2237 atan2(y: MathArray | Matrix, x: MathArray | Matrix): MathArray | Matrix;
2238
2239 /**
2240 * Calculate the hyperbolic arctangent of a value, defined as atanh(x) =
2241 * ln((1 + x)/(1 - x)) / 2. For matrices, the function is evaluated
2242 * element wise.
2243 * @param x Function input
2244 * @returns The hyperbolic arctangent of x
2245 */
2246 atanh(x: number): number;
2247 atanh(x: BigNumber): BigNumber;
2248 atanh(x: MathArray): MathArray;
2249 atanh(x: Matrix): Matrix;
2250
2251 /**
2252 * Calculate the cosine of a value. For matrices, the function is
2253 * evaluated element wise.
2254 * @param x Function input
2255 * @returns The cosine of x
2256 */
2257 cos(x: number | Unit): number;
2258 cos(x: BigNumber): BigNumber;
2259 cos(x: Complex): Complex;
2260 cos(x: MathArray): MathArray;
2261 cos(x: Matrix): Matrix;
2262
2263 /**
2264 * Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2
2265 * * (exp(x) + exp(-x)). For matrices, the function is evaluated element
2266 * wise.
2267 * @param x Function input
2268 * @returns The hyperbolic cosine of x
2269 */
2270 cosh(x: number | Unit): number;
2271 cosh(x: BigNumber): BigNumber;
2272 cosh(x: Complex): Complex;
2273 cosh(x: MathArray): MathArray;
2274 cosh(x: Matrix): Matrix;
2275
2276 /**
2277 * Calculate the cotangent of a value. cot(x) is defined as 1 / tan(x).
2278 * For matrices, the function is evaluated element wise.
2279 * @param x Function input
2280 * @returns The cotangent of x
2281 */
2282 cot(x: number | Unit): number;
2283 cot(x: Complex): Complex;
2284 cot(x: MathArray): MathArray;
2285 cot(x: Matrix): Matrix;
2286
2287 /**
2288 * Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1
2289 * / tanh(x). For matrices, the function is evaluated element wise.
2290 * @param x Function input
2291 * @returns The hyperbolic cotangent of x
2292 */
2293 coth(x: number | Unit): number;
2294 coth(x: Complex): Complex;
2295 coth(x: MathArray): MathArray;
2296 coth(x: Matrix): Matrix;
2297
2298 /**
2299 * Calculate the cosecant of a value, defined as csc(x) = 1/sin(x). For
2300 * matrices, the function is evaluated element wise.
2301 * @param x Function input
2302 * @returns The cosecant hof x
2303 */
2304 csc(x: number | Unit): number;
2305 csc(x: Complex): Complex;
2306 csc(x: MathArray): MathArray;
2307 csc(x: Matrix): Matrix;
2308
2309 /**
2310 * Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1
2311 * / sinh(x). For matrices, the function is evaluated element wise.
2312 * @param x Function input
2313 * @returns The hyperbolic cosecant of x
2314 */
2315 csch(x: number | Unit): number;
2316 csch(x: Complex): Complex;
2317 csch(x: MathArray): MathArray;
2318 csch(x: Matrix): Matrix;
2319
2320 /**
2321 * Calculate the secant of a value, defined as sec(x) = 1/cos(x). For
2322 * matrices, the function is evaluated element wise.
2323 * @param x Function input
2324 * @returns The secant of x
2325 */
2326 sec(x: number | Unit): number;
2327 sec(x: Complex): Complex;
2328 sec(x: MathArray): MathArray;
2329 sec(x: Matrix): Matrix;
2330
2331 /**
2332 * Calculate the hyperbolic secant of a value, defined as sech(x) = 1 /
2333 * cosh(x). For matrices, the function is evaluated element wise.
2334 * @param x Function input
2335 * @returns The hyperbolic secant of x
2336 */
2337 sech(x: number | Unit): number;
2338 sech(x: Complex): Complex;
2339 sech(x: MathArray): MathArray;
2340 sech(x: Matrix): Matrix;
2341
2342 /**
2343 * Calculate the sine of a value. For matrices, the function is
2344 * evaluated element wise.
2345 * @param x Function input
2346 * @returns The sine of x
2347 */
2348 sin(x: number | Unit): number;
2349 sin(x: BigNumber): BigNumber;
2350 sin(x: Complex): Complex;
2351 sin(x: MathArray): MathArray;
2352 sin(x: Matrix): Matrix;
2353
2354 /**
2355 * Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 *
2356 * (exp(x) - exp(-x)). For matrices, the function is evaluated element
2357 * wise.
2358 * @param x Function input
2359 * @returns The hyperbolic sine of x
2360 */
2361 sinh(x: number | Unit): number;
2362 sinh(x: BigNumber): BigNumber;
2363 sinh(x: Complex): Complex;
2364 sinh(x: MathArray): MathArray;
2365 sinh(x: Matrix): Matrix;
2366
2367 /**
2368 * Calculate the tangent of a value. tan(x) is equal to sin(x) / cos(x).
2369 * For matrices, the function is evaluated element wise.
2370 * @param x Function input
2371 * @returns The tangent of x
2372 */
2373 tan(x: number | Unit): number;
2374 tan(x: BigNumber): BigNumber;
2375 tan(x: Complex): Complex;
2376 tan(x: MathArray): MathArray;
2377 tan(x: Matrix): Matrix;
2378
2379 /**
2380 * Calculate the hyperbolic tangent of a value, defined as tanh(x) =
2381 * (exp(2 * x) - 1) / (exp(2 * x) + 1). For matrices, the function is
2382 * evaluated element wise.
2383 * @param x Function input
2384 * @returns The hyperbolic tangent of x
2385 */
2386 tanh(x: number | Unit): number;
2387 tanh(x: BigNumber): BigNumber;
2388 tanh(x: Complex): Complex;
2389 tanh(x: MathArray): MathArray;
2390 tanh(x: Matrix): Matrix;
2391
2392 /*************************************************************************
2393 * Unit functions
2394 ************************************************************************/
2395
2396 /**
2397 * Change the unit of a value. For matrices, the function is evaluated
2398 * element wise.
2399 * @param x The unit to be converted.
2400 * @param unit New unit. Can be a string like "cm" or a unit without
2401 * value.
2402 * @returns Value with changed, fixed unit
2403 */
2404 to(x: Unit | MathArray | Matrix, unit: Unit | string): Unit | MathArray | Matrix;
2405
2406 /*************************************************************************
2407 * Utils functions
2408 ************************************************************************/
2409
2410 /**
2411 * Clone an object.
2412 * @param x Object to be cloned
2413 * @returns A clone of object x
2414 */
2415 clone(x: any): any;
2416
2417 /**
2418 * Test whether a value is an integer number. The function supports
2419 * number, BigNumber, and Fraction. The function is evaluated
2420 * element-wise in case of Array or Matrix input.
2421 * @param x Value to be tested
2422 * @returns Returns true when x contains a numeric, integer value.
2423 * Throws an error in case of an unknown data type.
2424 */
2425 isInteger(x: number | BigNumber | Fraction | MathArray | Matrix): boolean;
2426
2427 /**
2428 * Test whether a value is NaN (not a number). The function supports
2429 * types number, BigNumber, Fraction, Unit and Complex. The function is
2430 * evaluated element-wise in case of Array or Matrix input.
2431 * @param x Value to be tested
2432 * @returns Returns true when x is NaN. Throws an error in case of an
2433 * unknown data type.
2434 */
2435 isNaN(x: number | BigNumber | Fraction | MathArray | Matrix | Unit): boolean;
2436
2437 /**
2438 * Test whether a value is negative: smaller than zero. The function
2439 * supports types number, BigNumber, Fraction, and Unit. The function is
2440 * evaluated element-wise in case of Array or Matrix input.
2441 * @param x Value to be tested
2442 * @returns Returns true when x is larger than zero. Throws an error in
2443 * case of an unknown data type.
2444 */
2445 isNegative(x: number | BigNumber | Fraction | MathArray | Matrix | Unit): boolean;
2446
2447 /**
2448 * Test whether a value is an numeric value. The function is evaluated
2449 * element-wise in case of Array or Matrix input.
2450 * @param x Value to be tested
2451 * @returns Returns true when x is a number, BigNumber, Fraction, or
2452 * boolean. Returns false for other types. Throws an error in case of
2453 * unknown types.
2454 */
2455 isNumeric(x: any): x is number | BigNumber | Fraction | boolean;
2456
2457 /**
2458 * Test whether a value is positive: larger than zero. The function
2459 * supports types number, BigNumber, Fraction, and Unit. The function is
2460 * evaluated element-wise in case of Array or Matrix input.
2461 * @param x Value to be tested
2462 * @returns Returns true when x is larger than zero. Throws an error in
2463 * case of an unknown data type.
2464 */
2465 isPositive(x: number | BigNumber | Fraction | MathArray | Matrix | Unit): boolean;
2466
2467 /**
2468 * Test whether a value is prime: has no divisors other than itself and
2469 * one. The function supports type number, bignumber. The function is
2470 * evaluated element-wise in case of Array or Matrix input.
2471 * @param x Value to be tested
2472 * @returns Returns true when x is larger than zero. Throws an error in
2473 * case of an unknown data type.
2474 */
2475 isPrime(x: number | BigNumber | MathArray | Matrix): boolean;
2476
2477 /**
2478 * Test whether a value is zero. The function can check for zero for
2479 * types number, BigNumber, Fraction, Complex, and Unit. The function is
2480 * evaluated element-wise in case of Array or Matrix input.
2481 * @param x Value to be tested
2482 * @returns Returns true when x is zero. Throws an error in case of an
2483 * unknown data type.
2484 */
2485 isZero(x: number | BigNumber | Fraction | MathArray | Matrix | Unit | Complex): boolean;
2486
2487 /**
2488 * Determine the type of a variable.
2489 * @param x The variable for which to test the type
2490 * @returns Returns the name of the type. Primitive types are lower
2491 * case, non-primitive types are upper-camel-case. For examplenumber’,
2492 * ‘string’, ‘Array’, ‘Date’.
2493 */
2494 typeOf(x: any): string;
2495
2496 /**
2497 * Import functions from an object or a module
2498 * To avoid errors when using one of the imported functions extend module like this:
2499 *
2500 * @example
2501 * // imported_math_functions.ts
2502 * declare module 'mathjs' {
2503 * interface MathJsStatic {
2504 * hello(a: number): number;
2505 * }
2506 * }
2507 *
2508 * @param object An object with functions to be imported.
2509 * @param options An object with import options.
2510 */
2511 import(object: ImportObject | ImportObject[], options: ImportOptions): void;
2512 }
2513
2514 /*************************************************************************
2515 * Factory and Dependencies
2516 ************************************************************************/
2517 interface FactoryDependencies {
2518 create: (factories: FactoryFunctionMap, config?: ConfigOptions) => Partial<MathJsStatic>;
2519 factory: <T>(
2520 name: string,
2521 dependencies: MathJsFunctionName[],
2522 create: (injected: Partial<MathJsStatic>) => T,
2523 meta?: any
2524 ) => FactoryFunction<T>;
2525 all: FactoryFunctionMap;
2526
2527 typedDependencies: FactoryFunctionMap;
2528 ResultSetDependencies: FactoryFunctionMap;
2529 BigNumberDependencies: FactoryFunctionMap;
2530 ComplexDependencies: FactoryFunctionMap;
2531 FractionDependencies: FactoryFunctionMap;
2532 RangeDependencies: FactoryFunctionMap;
2533 MatrixDependencies: FactoryFunctionMap;
2534 DenseMatrixDependencies: FactoryFunctionMap;
2535 cloneDependencies: FactoryFunctionMap;
2536 isIntegerDependencies: FactoryFunctionMap;
2537 isNegativeDependencies: FactoryFunctionMap;
2538 isNumericDependencies: FactoryFunctionMap;
2539 hasNumericValueDependencies: FactoryFunctionMap;
2540 isPositiveDependencies: FactoryFunctionMap;
2541 isZeroDependencies: FactoryFunctionMap;
2542 isNaNDependencies: FactoryFunctionMap;
2543 typeOfDependencies: FactoryFunctionMap;
2544 typeofDependencies: FactoryFunctionMap;
2545 equalScalarDependencies: FactoryFunctionMap;
2546 SparseMatrixDependencies: FactoryFunctionMap;
2547 numberDependencies: FactoryFunctionMap;
2548 stringDependencies: FactoryFunctionMap;
2549 booleanDependencies: FactoryFunctionMap;
2550 bignumberDependencies: FactoryFunctionMap;
2551 complexDependencies: FactoryFunctionMap;
2552 fractionDependencies: FactoryFunctionMap;
2553 matrixDependencies: FactoryFunctionMap;
2554 splitUnitDependencies: FactoryFunctionMap;
2555 unaryMinusDependencies: FactoryFunctionMap;
2556 unaryPlusDependencies: FactoryFunctionMap;
2557 absDependencies: FactoryFunctionMap;
2558 applyDependencies: FactoryFunctionMap;
2559 addScalarDependencies: FactoryFunctionMap;
2560 cbrtDependencies: FactoryFunctionMap;
2561 ceilDependencies: FactoryFunctionMap;
2562 cubeDependencies: FactoryFunctionMap;
2563 expDependencies: FactoryFunctionMap;
2564 expm1Dependencies: FactoryFunctionMap;
2565 fixDependencies: FactoryFunctionMap;
2566 floorDependencies: FactoryFunctionMap;
2567 gcdDependencies: FactoryFunctionMap;
2568 lcmDependencies: FactoryFunctionMap;
2569 log10Dependencies: FactoryFunctionMap;
2570 log2Dependencies: FactoryFunctionMap;
2571 modDependencies: FactoryFunctionMap;
2572 multiplyScalarDependencies: FactoryFunctionMap;
2573 multiplyDependencies: FactoryFunctionMap;
2574 nthRootDependencies: FactoryFunctionMap;
2575 signDependencies: FactoryFunctionMap;
2576 sqrtDependencies: FactoryFunctionMap;
2577 squareDependencies: FactoryFunctionMap;
2578 subtractDependencies: FactoryFunctionMap;
2579 xgcdDependencies: FactoryFunctionMap;
2580 dotMultiplyDependencies: FactoryFunctionMap;
2581 bitAndDependencies: FactoryFunctionMap;
2582 bitNotDependencies: FactoryFunctionMap;
2583 bitOrDependencies: FactoryFunctionMap;
2584 bitXorDependencies: FactoryFunctionMap;
2585 argDependencies: FactoryFunctionMap;
2586 conjDependencies: FactoryFunctionMap;
2587 imDependencies: FactoryFunctionMap;
2588 reDependencies: FactoryFunctionMap;
2589 notDependencies: FactoryFunctionMap;
2590 orDependencies: FactoryFunctionMap;
2591 xorDependencies: FactoryFunctionMap;
2592 concatDependencies: FactoryFunctionMap;
2593 columnDependencies: FactoryFunctionMap;
2594 crossDependencies: FactoryFunctionMap;
2595 diagDependencies: FactoryFunctionMap;
2596 eyeDependencies: FactoryFunctionMap;
2597 filterDependencies: FactoryFunctionMap;
2598 flattenDependencies: FactoryFunctionMap;
2599 forEachDependencies: FactoryFunctionMap;
2600 getMatrixDataTypeDependencies: FactoryFunctionMap;
2601 identityDependencies: FactoryFunctionMap;
2602 kronDependencies: FactoryFunctionMap;
2603 mapDependencies: FactoryFunctionMap;
2604 onesDependencies: FactoryFunctionMap;
2605 rangeDependencies: FactoryFunctionMap;
2606 reshapeDependencies: FactoryFunctionMap;
2607 resizeDependencies: FactoryFunctionMap;
2608 rowDependencies: FactoryFunctionMap;
2609 sizeDependencies: FactoryFunctionMap;
2610 squeezeDependencies: FactoryFunctionMap;
2611 subsetDependencies: FactoryFunctionMap;
2612 transposeDependencies: FactoryFunctionMap;
2613 ctransposeDependencies: FactoryFunctionMap;
2614 zerosDependencies: FactoryFunctionMap;
2615 erfDependencies: FactoryFunctionMap;
2616 modeDependencies: FactoryFunctionMap;
2617 prodDependencies: FactoryFunctionMap;
2618 formatDependencies: FactoryFunctionMap;
2619 printDependencies: FactoryFunctionMap;
2620 toDependencies: FactoryFunctionMap;
2621 isPrimeDependencies: FactoryFunctionMap;
2622 numericDependencies: FactoryFunctionMap;
2623 divideScalarDependencies: FactoryFunctionMap;
2624 powDependencies: FactoryFunctionMap;
2625 roundDependencies: FactoryFunctionMap;
2626 logDependencies: FactoryFunctionMap;
2627 log1pDependencies: FactoryFunctionMap;
2628 nthRootsDependencies: FactoryFunctionMap;
2629 dotPowDependencies: FactoryFunctionMap;
2630 dotDivideDependencies: FactoryFunctionMap;
2631 lsolveDependencies: FactoryFunctionMap;
2632 usolveDependencies: FactoryFunctionMap;
2633 leftShiftDependencies: FactoryFunctionMap;
2634 rightArithShiftDependencies: FactoryFunctionMap;
2635 rightLogShiftDependencies: FactoryFunctionMap;
2636 andDependencies: FactoryFunctionMap;
2637 compareDependencies: FactoryFunctionMap;
2638 compareNaturalDependencies: FactoryFunctionMap;
2639 compareTextDependencies: FactoryFunctionMap;
2640 equalDependencies: FactoryFunctionMap;
2641 equalTextDependencies: FactoryFunctionMap;
2642 smallerDependencies: FactoryFunctionMap;
2643 smallerEqDependencies: FactoryFunctionMap;
2644 largerDependencies: FactoryFunctionMap;
2645 largerEqDependencies: FactoryFunctionMap;
2646 deepEqualDependencies: FactoryFunctionMap;
2647 unequalDependencies: FactoryFunctionMap;
2648 partitionSelectDependencies: FactoryFunctionMap;
2649 sortDependencies: FactoryFunctionMap;
2650 maxDependencies: FactoryFunctionMap;
2651 minDependencies: FactoryFunctionMap;
2652 ImmutableDenseMatrixDependencies: FactoryFunctionMap;
2653 IndexDependencies: FactoryFunctionMap;
2654 FibonacciHeapDependencies: FactoryFunctionMap;
2655 SpaDependencies: FactoryFunctionMap;
2656 UnitDependencies: FactoryFunctionMap;
2657 unitDependencies: FactoryFunctionMap;
2658 sparseDependencies: FactoryFunctionMap;
2659 createUnitDependencies: FactoryFunctionMap;
2660 acosDependencies: FactoryFunctionMap;
2661 acoshDependencies: FactoryFunctionMap;
2662 acotDependencies: FactoryFunctionMap;
2663 acothDependencies: FactoryFunctionMap;
2664 acscDependencies: FactoryFunctionMap;
2665 acschDependencies: FactoryFunctionMap;
2666 asecDependencies: FactoryFunctionMap;
2667 asechDependencies: FactoryFunctionMap;
2668 asinDependencies: FactoryFunctionMap;
2669 asinhDependencies: FactoryFunctionMap;
2670 atanDependencies: FactoryFunctionMap;
2671 atan2Dependencies: FactoryFunctionMap;
2672 atanhDependencies: FactoryFunctionMap;
2673 cosDependencies: FactoryFunctionMap;
2674 coshDependencies: FactoryFunctionMap;
2675 cotDependencies: FactoryFunctionMap;
2676 cothDependencies: FactoryFunctionMap;
2677 cscDependencies: FactoryFunctionMap;
2678 cschDependencies: FactoryFunctionMap;
2679 secDependencies: FactoryFunctionMap;
2680 sechDependencies: FactoryFunctionMap;
2681 sinDependencies: FactoryFunctionMap;
2682 sinhDependencies: FactoryFunctionMap;
2683 tanDependencies: FactoryFunctionMap;
2684 tanhDependencies: FactoryFunctionMap;
2685 setCartesianDependencies: FactoryFunctionMap;
2686 setDifferenceDependencies: FactoryFunctionMap;
2687 setDistinctDependencies: FactoryFunctionMap;
2688 setIntersectDependencies: FactoryFunctionMap;
2689 setIsSubsetDependencies: FactoryFunctionMap;
2690 setMultiplicityDependencies: FactoryFunctionMap;
2691 setPowersetDependencies: FactoryFunctionMap;
2692 setSizeDependencies: FactoryFunctionMap;
2693 setSymDifferenceDependencies: FactoryFunctionMap;
2694 setUnionDependencies: FactoryFunctionMap;
2695 addDependencies: FactoryFunctionMap;
2696 hypotDependencies: FactoryFunctionMap;
2697 normDependencies: FactoryFunctionMap;
2698 dotDependencies: FactoryFunctionMap;
2699 traceDependencies: FactoryFunctionMap;
2700 indexDependencies: FactoryFunctionMap;
2701 NodeDependencies: FactoryFunctionMap;
2702 AccessorNodeDependencies: FactoryFunctionMap;
2703 ArrayNodeDependencies: FactoryFunctionMap;
2704 AssignmentNodeDependencies: FactoryFunctionMap;
2705 BlockNodeDependencies: FactoryFunctionMap;
2706 ConditionalNodeDependencies: FactoryFunctionMap;
2707 ConstantNodeDependencies: FactoryFunctionMap;
2708 FunctionAssignmentNodeDependencies: FactoryFunctionMap;
2709 IndexNodeDependencies: FactoryFunctionMap;
2710 ObjectNodeDependencies: FactoryFunctionMap;
2711 OperatorNodeDependencies: FactoryFunctionMap;
2712 ParenthesisNodeDependencies: FactoryFunctionMap;
2713 RangeNodeDependencies: FactoryFunctionMap;
2714 RelationalNodeDependencies: FactoryFunctionMap;
2715 SymbolNodeDependencies: FactoryFunctionMap;
2716 FunctionNodeDependencies: FactoryFunctionMap;
2717 parseDependencies: FactoryFunctionMap;
2718 compileDependencies: FactoryFunctionMap;
2719 evaluateDependencies: FactoryFunctionMap;
2720 evalDependencies: FactoryFunctionMap;
2721 ParserDependencies: FactoryFunctionMap;
2722 parserDependencies: FactoryFunctionMap;
2723 lupDependencies: FactoryFunctionMap;
2724 qrDependencies: FactoryFunctionMap;
2725 sluDependencies: FactoryFunctionMap;
2726 lusolveDependencies: FactoryFunctionMap;
2727 HelpDependencies: FactoryFunctionMap;
2728 ChainDependencies: FactoryFunctionMap;
2729 helpDependencies: FactoryFunctionMap;
2730 chainDependencies: FactoryFunctionMap;
2731 detDependencies: FactoryFunctionMap;
2732 invDependencies: FactoryFunctionMap;
2733 expmDependencies: FactoryFunctionMap;
2734 sqrtmDependencies: FactoryFunctionMap;
2735 divideDependencies: FactoryFunctionMap;
2736 distanceDependencies: FactoryFunctionMap;
2737 intersectDependencies: FactoryFunctionMap;
2738 sumDependencies: FactoryFunctionMap;
2739 meanDependencies: FactoryFunctionMap;
2740 medianDependencies: FactoryFunctionMap;
2741 madDependencies: FactoryFunctionMap;
2742 varianceDependencies: FactoryFunctionMap;
2743 varDependencies: FactoryFunctionMap;
2744 quantileSeqDependencies: FactoryFunctionMap;
2745 stdDependencies: FactoryFunctionMap;
2746 combinationsDependencies: FactoryFunctionMap;
2747 gammaDependencies: FactoryFunctionMap;
2748 factorialDependencies: FactoryFunctionMap;
2749 kldivergenceDependencies: FactoryFunctionMap;
2750 multinomialDependencies: FactoryFunctionMap;
2751 permutationsDependencies: FactoryFunctionMap;
2752 pickRandomDependencies: FactoryFunctionMap;
2753 randomDependencies: FactoryFunctionMap;
2754 randomIntDependencies: FactoryFunctionMap;
2755 stirlingS2Dependencies: FactoryFunctionMap;
2756 bellNumbersDependencies: FactoryFunctionMap;
2757 catalanDependencies: FactoryFunctionMap;
2758 compositionDependencies: FactoryFunctionMap;
2759 simplifyDependencies: FactoryFunctionMap;
2760 derivativeDependencies: FactoryFunctionMap;
2761 rationalizeDependencies: FactoryFunctionMap;
2762 reviverDependencies: FactoryFunctionMap;
2763 eDependencies: FactoryFunctionMap;
2764 EDependencies: FactoryFunctionMap;
2765 falseDependencies: FactoryFunctionMap;
2766 iDependencies: FactoryFunctionMap;
2767 InfinityDependencies: FactoryFunctionMap;
2768 LN10Dependencies: FactoryFunctionMap;
2769 LN2Dependencies: FactoryFunctionMap;
2770 LOG10EDependencies: FactoryFunctionMap;
2771 LOG2EDependencies: FactoryFunctionMap;
2772 NaNDependencies: FactoryFunctionMap;
2773 nullDependencies: FactoryFunctionMap;
2774 phiDependencies: FactoryFunctionMap;
2775 piDependencies: FactoryFunctionMap;
2776 PIDependencies: FactoryFunctionMap;
2777 SQRT1_2Dependencies: FactoryFunctionMap;
2778 SQRT2Dependencies: FactoryFunctionMap;
2779 tauDependencies: FactoryFunctionMap;
2780 trueDependencies: FactoryFunctionMap;
2781 versionDependencies: FactoryFunctionMap;
2782 atomicMassDependencies: FactoryFunctionMap;
2783 avogadroDependencies: FactoryFunctionMap;
2784 bohrMagnetonDependencies: FactoryFunctionMap;
2785 bohrRadiusDependencies: FactoryFunctionMap;
2786 boltzmannDependencies: FactoryFunctionMap;
2787 classicalElectronRadiusDependencies: FactoryFunctionMap;
2788 conductanceQuantumDependencies: FactoryFunctionMap;
2789 coulombDependencies: FactoryFunctionMap;
2790 deuteronMassDependencies: FactoryFunctionMap;
2791 efimovFactorDependencies: FactoryFunctionMap;
2792 electricConstantDependencies: FactoryFunctionMap;
2793 electronMassDependencies: FactoryFunctionMap;
2794 elementaryChargeDependencies: FactoryFunctionMap;
2795 faradayDependencies: FactoryFunctionMap;
2796 fermiCouplingDependencies: FactoryFunctionMap;
2797 fineStructureDependencies: FactoryFunctionMap;
2798 firstRadiationDependencies: FactoryFunctionMap;
2799 gasConstantDependencies: FactoryFunctionMap;
2800 gravitationConstantDependencies: FactoryFunctionMap;
2801 gravityDependencies: FactoryFunctionMap;
2802 hartreeEnergyDependencies: FactoryFunctionMap;
2803 inverseConductanceQuantumDependencies: FactoryFunctionMap;
2804 klitzingDependencies: FactoryFunctionMap;
2805 loschmidtDependencies: FactoryFunctionMap;
2806 magneticConstantDependencies: FactoryFunctionMap;
2807 magneticFluxQuantumDependencies: FactoryFunctionMap;
2808 molarMassDependencies: FactoryFunctionMap;
2809 molarMassC12Dependencies: FactoryFunctionMap;
2810 molarPlanckConstantDependencies: FactoryFunctionMap;
2811 molarVolumeDependencies: FactoryFunctionMap;
2812 neutronMassDependencies: FactoryFunctionMap;
2813 nuclearMagnetonDependencies: FactoryFunctionMap;
2814 planckChargeDependencies: FactoryFunctionMap;
2815 planckConstantDependencies: FactoryFunctionMap;
2816 planckLengthDependencies: FactoryFunctionMap;
2817 planckMassDependencies: FactoryFunctionMap;
2818 planckTemperatureDependencies: FactoryFunctionMap;
2819 planckTimeDependencies: FactoryFunctionMap;
2820 protonMassDependencies: FactoryFunctionMap;
2821 quantumOfCirculationDependencies: FactoryFunctionMap;
2822 reducedPlanckConstantDependencies: FactoryFunctionMap;
2823 rydbergDependencies: FactoryFunctionMap;
2824 sackurTetrodeDependencies: FactoryFunctionMap;
2825 secondRadiationDependencies: FactoryFunctionMap;
2826 speedOfLightDependencies: FactoryFunctionMap;
2827 stefanBoltzmannDependencies: FactoryFunctionMap;
2828 thomsonCrossSectionDependencies: FactoryFunctionMap;
2829 vacuumImpedanceDependencies: FactoryFunctionMap;
2830 weakMixingAngleDependencies: FactoryFunctionMap;
2831 wienDisplacementDependencies: FactoryFunctionMap;
2832 applyTransformDependencies: FactoryFunctionMap;
2833 columnTransformDependencies: FactoryFunctionMap;
2834 filterTransformDependencies: FactoryFunctionMap;
2835 forEachTransformDependencies: FactoryFunctionMap;
2836 indexTransformDependencies: FactoryFunctionMap;
2837 mapTransformDependencies: FactoryFunctionMap;
2838 maxTransformDependencies: FactoryFunctionMap;
2839 meanTransformDependencies: FactoryFunctionMap;
2840 minTransformDependencies: FactoryFunctionMap;
2841 rangeTransformDependencies: FactoryFunctionMap;
2842 rowTransformDependencies: FactoryFunctionMap;
2843 subsetTransformDependencies: FactoryFunctionMap;
2844 concatTransformDependencies: FactoryFunctionMap;
2845 stdTransformDependencies: FactoryFunctionMap;
2846 sumTransformDependencies: FactoryFunctionMap;
2847 varianceTransformDependencies: FactoryFunctionMap;
2848 }
2849
2850 interface Matrix {
2851 type: string;
2852 storage(): string;
2853 datatype(): string;
2854 create(data: MathArray, datatype?: string): void;
2855 density(): number;
2856 subset(index: Index, replacement?: any, defaultValue?: any): Matrix;
2857 get(index: number[]): any;
2858 set(index: number[], value: any, defaultValue?: number | string): Matrix;
2859 resize(size: MathArray | Matrix, defaultValue?: number | string): Matrix;
2860 clone(): Matrix;
2861 size(): number[];
2862 map(callback: (a: any, b: number, c: Matrix) => any, skipZeros?: boolean): Matrix;
2863 forEach(callback: (a: any, b: number, c: Matrix) => void, skipZeros?: boolean): void;
2864 toArray(): MathArray;
2865 valueOf(): MathArray;
2866 format(options?: FormatOptions | number | ((value: any) => string)): string;
2867 toString(): string;
2868 toJSON(): any;
2869 diagonal(k?: number | BigNumber): any[];
2870 swapRows(i: number, j: number): Matrix;
2871 }
2872
2873 interface BigNumber extends Decimal {} // tslint:disable-line no-empty-interface
2874
2875 interface Fraction {
2876 s: number;
2877 n: number;
2878 d: number;
2879 }
2880
2881 interface Complex {
2882 re: number;
2883 im: number;
2884 clone(): Complex;
2885 equals(other: Complex): boolean;
2886 format(precision?: number): string;
2887 fromJSON(json: object): Complex;
2888 fromPolar(polar: object): Complex;
2889 fromPolar(r: number, phi: number): Complex;
2890 toJSON(): object;
2891 toPolar(): PolarCoordinates;
2892 toString(): string;
2893 compare(a: Complex, b: Complex): number;
2894 }
2895
2896 interface PolarCoordinates {
2897 r: number;
2898 phi: number;
2899 }
2900
2901 interface MathJSON {
2902 mathjs?: string;
2903 value: number;
2904 unit: string;
2905 fixPrefix?: boolean;
2906 }
2907
2908 interface Unit {
2909 valueOf(): string;
2910 clone(): Unit;
2911 hasBase(base: any): boolean;
2912 equalBase(unit: Unit): boolean;
2913 equals(unit: Unit): boolean;
2914 multiply(unit: Unit): Unit;
2915 divide(unit: Unit): Unit;
2916 pow(unit: Unit): Unit;
2917 abs(unit: Unit): Unit;
2918 to(unit: string): Unit;
2919 toNumber(unit: string): number;
2920 toNumeric(unit: string): number | Fraction | BigNumber;
2921 toSI(): Unit;
2922 toString(): string;
2923 toJSON(): MathJSON;
2924 formatUnits(): string;
2925 format(options: FormatOptions): string;
2926 splitUnit(parts: ReadonlyArray<string | Unit>): Unit[];
2927 }
2928
2929 interface CreateUnitOptions {
2930 prefixes?: 'none' | 'short' | 'long' | 'binary_short' | 'binary_long';
2931 aliases?: string[];
2932 offset?: number;
2933 override?: boolean;
2934 }
2935
2936 interface UnitDefinition {
2937 definition?: string | Unit;
2938 prefixes?: string;
2939 offset?: number;
2940 aliases?: string[];
2941 }
2942
2943 interface Index {} // tslint:disable-line no-empty-interface
2944
2945 interface EvalFunction {
2946 evaluate(scope?: any): any;
2947 }
2948
2949 interface MathNode {
2950 isNode: boolean;
2951 isAccessorNode?: boolean;
2952 isArrayNode?: boolean;
2953 isAssignmentNode?: boolean;
2954 isBlockNode?: boolean;
2955 isConditionalnode?: boolean;
2956 isConstantNode?: boolean;
2957 isFunctionAssignmentNode?: boolean;
2958 isFunctionNode?: boolean;
2959 isIndexNode?: boolean;
2960 isObjectNode?: boolean;
2961 isOperatorNode?: boolean;
2962 isParenthesisNode?: boolean;
2963 isRangeNode?: boolean;
2964 isSymbolNode?: boolean;
2965 isUpdateNode?: boolean;
2966 comment?: string;
2967 content?: MathNode;
2968 op?: string;
2969 fn?: string;
2970 args?: MathNode[];
2971 type: string;
2972 name?: string;
2973 value?: any;
2974
2975 /**
2976 * Create a shallow clone of the node. The node itself is cloned, its
2977 * childs are not cloned.
2978 */
2979 clone(): MathNode;
2980 /**
2981 * Create a deep clone of the node. Both the node as well as all its
2982 * childs are cloned recursively.
2983 */
2984 cloneDeep(): MathNode;
2985 /**
2986 * Compile an expression into optimized JavaScript code. compile returns
2987 * an object with a function evaluate([scope]) to evaluate. Example:
2988 */
2989 compile(): EvalFunction;
2990 /**
2991 * Compile and eval an expression, this is the equivalent of doing
2992 * node.compile().evaluate(scope). Example:
2993 */
2994 evaluate(expr?: any): any;
2995 /**
2996 * Test whether this node equals an other node. Does a deep comparison
2997 * of the values of both nodes.
2998 */
2999 equals(other: MathNode): boolean;
3000 /**
3001 *
3002 * Filter nodes in an expression tree. The callback function is called
3003 * as callback(node: MathNode, path: string, parent: MathNode) : boolean
3004 * for every node in the tree, and must return a boolean. The function
3005 * filter returns an array with nodes for which the test returned true.
3006 * Parameter path is a string containing a relative JSON Path.
3007 *
3008 * Example:
3009 *
3010 * ```
3011 * var node = math.parse('x^2 + x/4 + 3*y');
3012 * var filtered = node.filter(function (node) {
3013 * return node.isSymbolMathNode && node.name == 'x';
3014 * });
3015 * // returns an array with two entries: two SymbolMathNodes 'x'
3016 * ```
3017 *
3018 * The callback function is called as callback(node: MathNode, path:
3019 * string, parent: MathNode) : boolean for every node in the tree, and
3020 * must return a boolean. The function filter returns an array with
3021 * nodes for which the test returned true. Parameter path is a string
3022 * containing a relative JSON Path.
3023 * @return Returns an array with nodes for which test returned true
3024 */
3025 filter(callback: (node: MathNode, path: string, parent: MathNode) => any): MathNode[];
3026
3027 /**
3028 * [forEach description]
3029 */
3030 forEach(callback: (node: MathNode, path: string, parent: MathNode) => any): MathNode[];
3031
3032 /**
3033 * Transform a node. Creates a new MathNode having its child's be the
3034 * results of calling the provided callback function for each of the
3035 * child's of the original node. The callback function is called as
3036 * `callback(child: MathNode, path: string, parent: MathNode)` and must
3037 * return a MathNode. Parameter path is a string containing a relative
3038 * JSON Path.
3039 *
3040 *
3041 * See also transform, which is a recursive version of map.
3042 */
3043 map(callback: (node: MathNode, path: string, parent: MathNode) => MathNode): MathNode;
3044
3045 /**
3046 * Get a HTML representation of the parsed expression.
3047 */
3048 toHtml(options?: object): string;
3049
3050 /**
3051 * Get a string representation of the parsed expression. This is not
3052 * exactly the same as the original input.
3053 */
3054 toString(options?: object): string;
3055
3056 /**
3057 * Get a LaTeX representation of the expression.
3058 */
3059 toTex(options?: object): string;
3060
3061 /**
3062 * Recursively transform an expression tree via a transform function.
3063 * Similar to Array.map, but recursively executed on all nodes in the
3064 * expression tree. The callback function is a mapping function
3065 * accepting a node, and returning a replacement for the node or the
3066 * original node. Function callback is called as callback(node:
3067 * MathNode, path: string, parent: MathNode) for every node in the tree,
3068 * and must return a MathNode. Parameter path is a string containing a
3069 * relative JSON Path.
3070 *
3071 * For example, to replace all nodes of type SymbolMathNode having name
3072 * ‘xwith a ConstantMathNode with value 3:
3073 * ```js
3074 * var node = math.parse('x^2 + 5*x');
3075 * var transformed = node.transform(function (node, path, parent) {
3076 * if (node.SymbolMathNode && node.name == 'x') {
3077 * return new math.expression.node.ConstantMathNode(3);
3078 * }
3079 * else {
3080 * return node;
3081 * }
3082 * });
3083 * transformed.toString(); // returns '(3 ^ 2) + (5 * 3)'
3084 * ```
3085 */
3086 transform(callback: (node: MathNode, path: string, parent: MathNode) => MathNode): MathNode;
3087
3088 /**
3089 * `traverse(callback)`
3090 *
3091 * Recursively traverse all nodes in a node tree. Executes given
3092 * callback for this node and each of its child nodes. Similar to
3093 * Array.forEach, except recursive. The callback function is a mapping
3094 * function accepting a node, and returning a replacement for the node
3095 * or the original node. Function callback is called as callback(node:
3096 * MathNode, path: string, parent: MathNode) for every node in the tree.
3097 * Parameter path is a string containing a relative JSON Path. Example:
3098 *
3099 * ```
3100 * var node = math.parse('3 * x + 2');
3101 * node.traverse(function (node, path, parent) {
3102 * switch (node.type) {
3103 * case 'OperatorMathNode': console.log(node.type, node.op); break;
3104 * case 'ConstantMathNode': console.log(node.type, node.value); break;
3105 * case 'SymbolMathNode': console.log(node.type, node.name); break;
3106 * default: console.log(node.type);
3107 * }
3108 * });
3109 * // outputs:
3110 * // OperatorMathNode +
3111 * // OperatorMathNode *
3112 * // ConstantMathNode 3
3113 * // SymbolMathNode x
3114 * // ConstantMathNode 2
3115 * ```
3116 */
3117 traverse(callback: (node: MathNode, path: string, parent: MathNode) => void): any;
3118 }
3119
3120 interface Parser {
3121 evaluate(expr: string): any;
3122 get(variable: string): any;
3123 getAll(): { [key: string]: any };
3124 set: (variable: string, value: any) => void;
3125 clear: () => void;
3126 }
3127
3128 interface Distribution {
3129 random(size: any, min?: any, max?: any): any;
3130 randomInt(min: any, max?: any): any;
3131 pickRandom(array: any): any;
3132 }
3133
3134 interface FormatOptions {
3135 /**
3136 * Number notation. Choose from: 'fixed' Always use regular number
3137 * notation. For example '123.40' and '14000000' 'exponential' Always
3138 * use exponential notation. For example '1.234e+2' and '1.4e+7' 'auto'
3139 * (default) Regular number notation for numbers having an absolute
3140 * value between lower and upper bounds, and uses exponential notation
3141 * elsewhere. Lower bound is included, upper bound is excluded. For
3142 * example '123.4' and '1.4e7'.
3143 */
3144 notation?: 'fixed' | 'exponential' | 'engineering' | 'auto';
3145
3146 /**
3147 * A number between 0 and 16 to round the digits of the number. In case
3148 * of notations 'exponential' and 'auto', precision defines the total
3149 * number of significant digits returned and is undefined by default. In
3150 * case of notation 'fixed', precision defines the number of significant
3151 * digits after the decimal point, and is 0 by default.
3152 */
3153 precision?: number;
3154
3155 /**
3156 * Exponent determining the lower boundary for formatting a value with
3157 * an exponent when notation='auto. Default value is -3.
3158 */
3159 lowerExp?: number;
3160
3161 /**
3162 * Exponent determining the upper boundary for formatting a value with
3163 * an exponent when notation='auto. Default value is 5.
3164 */
3165 upperExp?: number;
3166
3167 /**
3168 * Available values: 'ratio' (default) or 'decimal'. For example
3169 * format(fraction(1, 3)) will output '1/3' when 'ratio' is configured,
3170 * and will output 0.(3) when 'decimal' is configured.
3171 */
3172 fraction?: string;
3173 }
3174
3175 interface Help {
3176 toString(): string;
3177 toJSON(): string;
3178 }
3179
3180 interface ConfigOptions {
3181 epsilon?: number;
3182 matrix?: string;
3183 number?: string;
3184 precision?: number;
3185 parenthesis?: string;
3186 randomSeed?: string;
3187 }
3188
3189 interface MathJsJson {
3190 /**
3191 * Returns reviver function that can be used as reviver in JSON.parse function.
3192 */
3193 reviver(): (key: any, value: any) => any;
3194 }
3195
3196 interface MathJsChain {
3197 done(): any;
3198
3199 /*************************************************************************
3200 * Construction functions
3201 ************************************************************************/
3202
3203 /**
3204 * Create a BigNumber, which can store numbers with arbitrary precision.
3205 * When a matrix is provided, all elements will be converted to
3206 * BigNumber.
3207 */
3208 bignumber(): MathJsChain;
3209
3210 /**
3211 * Create a boolean or convert a string or number to a boolean. In case
3212 * of a number, true is returned for non-zero numbers, and false in case
3213 * of zero. Strings can be 'true' or 'false', or can contain a number.
3214 * When value is a matrix, all elements will be converted to boolean.
3215 */
3216 boolean(): MathJsChain;
3217
3218 /**
3219 * Create a complex value or convert a value to a complex value.
3220 * @param im Argument specifying the imaginary part of the complex
3221 * number
3222 */
3223 complex(im?: number): MathJsChain;
3224
3225 /**
3226 * Create a user-defined unit and register it with the Unit type.
3227 * @param definition Definition of the unit in terms of existing units.
3228 * For example, ‘0.514444444 m / s’.
3229 * @param options (optional) An object containing any of the following
3230 * properties:</br>- prefixes {string} “none”, “short”, “long”,
3231 * “binary_short”, or “binary_long”. The default is “none”.</br>-
3232 * aliases {Array} Array of strings. Example: [‘knots’, ‘kt’,
3233 * ‘kts’]</br>- offset {Numeric} An offset to apply when converting from
3234 * the unit. For example, the offset for celsius is 273.15. Default is
3235 * 0.
3236 */
3237 createUnit(definition?: string | UnitDefinition, options?: CreateUnitOptions): MathJsChain;
3238 /**
3239 * Create a user-defined unit and register it with the Unit type.
3240 * @param options (optional) An object containing any of the following
3241 * properties:</br>- prefixes {string} “none”, “short”, “long”,
3242 * “binary_short”, or “binary_long”. The default is “none”.</br>-
3243 * aliases {Array} Array of strings. Example: [‘knots’, ‘kt’,
3244 * ‘kts’]</br>- offset {Numeric} An offset to apply when converting from
3245 * the unit. For example, the offset for celsius is 273.15. Default is
3246 * 0.
3247 */
3248 createUnit(options?: CreateUnitOptions): MathJsChain;
3249
3250 /**
3251 * Create a fraction convert a value to a fraction.
3252 * @param denominator Argument specifying the denominator of the
3253 * fraction
3254 */
3255 fraction(denominator?: number | string | MathArray | Matrix): MathJsChain;
3256
3257 /**
3258 * Create an index. An Index can store ranges having start, step, and
3259 * end for multiple dimensions. Matrix.get, Matrix.set, and math.subset
3260 * accept an Index as input.
3261 */
3262 index(): MathJsChain;
3263
3264 /**
3265 * Create a Matrix. The function creates a new math.type.Matrix object
3266 * from an Array. A Matrix has utility functions to manipulate the data
3267 * in the matrix, like getting the size and getting or setting values in
3268 * the matrix. Supported storage formats are 'dense' and 'sparse'.
3269 */
3270 matrix(format?: 'sparse' | 'dense', dataType?: string): MathJsChain;
3271
3272 /**
3273 * Create a number or convert a string, boolean, or unit to a number.
3274 * When value is a matrix, all elements will be converted to number.
3275 * @param valuelessUnit A valueless unit, used to convert a unit to a
3276 * number
3277 */
3278 number(valuelessUnit?: Unit | string): MathJsChain;
3279
3280 /**
3281 * Create a Sparse Matrix. The function creates a new math.type.Matrix
3282 * object from an Array. A Matrix has utility functions to manipulate
3283 * the data in the matrix, like getting the size and getting or setting
3284 * values in the matrix.
3285 * @param dataType Sparse Matrix data type
3286 */
3287 sparse(dataType?: string): MathJsChain;
3288
3289 /**
3290 * Split a unit in an array of units whose sum is equal to the original
3291 * unit.
3292 * @param parts An array of strings or valueless units
3293 */
3294 splitUnit(parts: Unit[]): MathJsChain;
3295
3296 /**
3297 * Create a string or convert any object into a string. Elements of
3298 * Arrays and Matrices are processed element wise.
3299 */
3300 string(): MathJsChain;
3301
3302 /**
3303 * Create a unit. Depending on the passed arguments, the function will
3304 * create and return a new math.type.Unit object. When a matrix is
3305 * provided, all elements will be converted to units.
3306 * @param unit The unit to be created
3307 */
3308 unit(unit?: string): MathJsChain;
3309
3310 /*************************************************************************
3311 * Expression functions
3312 ************************************************************************/
3313
3314 /**
3315 * Parse and compile an expression. Returns a an object with a function
3316 * evaluate([scope]) to evaluate the compiled expression.
3317 */
3318 compile(): MathJsChain;
3319
3320 /**
3321 * Evaluate an expression.
3322 * @param scope Scope to read/write variables
3323 */
3324 evaluate(scope?: object): MathJsChain;
3325
3326 /**
3327 * Retrieve help on a function or data type. Help files are retrieved
3328 * from the documentation in math.expression.docs.
3329 */
3330 help(): MathJsChain;
3331
3332 /**
3333 * Parse an expression. Returns a node tree, which can be evaluated by
3334 * invoking node.evaluate();
3335 * @param options Available options: nodes - a set of custome nodes
3336 */
3337 parse(options?: any): MathJsChain;
3338 /**
3339 * @param options Available options: nodes - a set of custome nodes
3340 */
3341 parse(options?: any): MathJsChain;
3342
3343 /**
3344 * Create a parser. The function creates a new math.expression.Parser
3345 * object.
3346 */
3347 parser(): MathJsChain;
3348
3349 /*************************************************************************
3350 * Algebra functions
3351 ************************************************************************/
3352 /**
3353 * @param variable The variable over which to differentiate
3354 * @param options There is one option available, simplify, which is true
3355 * by default. When false, output will not be simplified.
3356 */
3357 derivative(variable: MathNode | string, options?: { simplify: boolean }): MathJsChain;
3358
3359 /**
3360 * Solves the linear equation system by forwards substitution. Matrix
3361 * must be a lower triangular matrix.
3362 * @param b A column vector with the b values
3363 */
3364 lsolve(b: Matrix | MathArray): MathJsChain;
3365
3366 /**
3367 * Calculate the Matrix LU decomposition with partial pivoting. Matrix A
3368 * is decomposed in two matrices (L, U) and a row permutation vector p
3369 * where A[p,:] = L * U
3370 */
3371 lup(): MathJsChain;
3372
3373 /**
3374 * Solves the linear system A * x = b where A is an [n x n] matrix and b
3375 * is a [n] column vector.
3376 * @param b Column Vector
3377 * @param order The Symbolic Ordering and Analysis order, see slu for
3378 * details. Matrix must be a SparseMatrix
3379 * @param threshold Partial pivoting threshold (1 for partial pivoting),
3380 * see slu for details. Matrix must be a SparseMatrix.
3381 */
3382 lusolve(b: Matrix | MathArray, order?: number, threshold?: number): MathJsChain;
3383
3384 /**
3385 * Calculate the Matrix QR decomposition. Matrix A is decomposed in two
3386 * matrices (Q, R) where Q is an orthogonal matrix and R is an upper
3387 * triangular matrix.
3388 */
3389 qr(): MathJsChain;
3390
3391 /**
3392 * Transform a rationalizable expression in a rational fraction. If
3393 * rational fraction is one variable polynomial then converts the
3394 * numerator and denominator in canonical form, with decreasing
3395 * exponents, returning the coefficients of numerator.
3396 * @param optional scope of expression or true for already evaluated
3397 * rational expression at input
3398 * @param detailed optional True if return an object, false if return
3399 * expression node (default)
3400 */
3401 rationalize(optional?: object | boolean, detailed?: boolean): MathJsChain;
3402
3403 /**
3404 * Simplify an expression tree.
3405 * @param rules A list of rules are applied to an expression, repeating
3406 * over the list until no further changes are made. It’s possible to
3407 * pass a custom set of rules to the function as second argument. A rule
3408 * can be specified as an object, string, or function.
3409 * @param scope Scope to variables
3410 */
3411 simplify(rules?: Array<{ l: string; r: string } | string | ((node: MathNode) => MathNode)>, scope?: object): MathJsChain;
3412
3413 /**
3414 * Calculate the Sparse Matrix LU decomposition with full pivoting.
3415 * Sparse Matrix A is decomposed in two matrices (L, U) and two
3416 * permutation vectors (pinv, q) where P * A * Q = L * U
3417 * @param order The Symbolic Ordering and Analysis order: 0 - Natural
3418 * ordering, no permutation vector q is returned 1 - Matrix must be
3419 * square, symbolic ordering and analisis is performed on M = A + A' 2 -
3420 * Symbolic ordering and analysis is performed on M = A' * A. Dense
3421 * columns from A' are dropped, A recreated from A'. This is appropriate
3422 * for LU factorization of non-symmetric matrices. 3 - Symbolic ordering
3423 * and analysis is performed on M = A' * A. This is best used for LU
3424 * factorization is matrix M has no dense rows. A dense row is a row
3425 * with more than 10*sqr(columns) entries.
3426 * @param threshold Partial pivoting threshold (1 for partial pivoting)
3427 */
3428 slu(order: number, threshold: number): MathJsChain;
3429
3430 /**
3431 * Solves the linear equation system by backward substitution. Matrix
3432 * must be an upper triangular matrix. U * x = b
3433 * @param b A column vector with the b values
3434 */
3435 usolve(b: Matrix | MathArray): MathJsChain;
3436
3437 /*************************************************************************
3438 * Arithmetic functions
3439 ************************************************************************/
3440
3441 /**
3442 * Calculate the absolute value of a number. For matrices, the function
3443 * is evaluated element wise.
3444 */
3445 abs(): MathJsChain;
3446
3447 /**
3448 * Add two values, x + y. For matrices, the function is evaluated
3449 * element wise.
3450 * @param y Second value to add
3451 */
3452 add(y: MathType): MathJsChain;
3453
3454 /**
3455 * Calculate the cubic root of a value. For matrices, the function is
3456 * evaluated element wise.
3457 * @param allRoots Optional, false by default. Only applicable when x is
3458 * a number or complex number. If true, all complex roots are returned,
3459 * if false (default) the principal root is returned.
3460 */
3461 cbrt(allRoots?: boolean): MathJsChain;
3462
3463 /**
3464 * Round a value towards plus infinity If x is complex, both real and
3465 * imaginary part are rounded towards plus infinity. For matrices, the
3466 * function is evaluated element wise.
3467 */
3468 ceil(): MathJsChain;
3469
3470 /**
3471 * Compute the cube of a value, x * x * x. For matrices, the function is
3472 * evaluated element wise.
3473 */
3474 cube(): MathJsChain;
3475
3476 /**
3477 * Divide two values, x / y. To divide matrices, x is multiplied with
3478 * the inverse of y: x * inv(y).
3479 * @param y Denominator
3480 */
3481 divide(y: MathType): MathJsChain;
3482
3483 /**
3484 * Divide two matrices element wise. The function accepts both matrices
3485 * and scalar values.
3486 * @param y Denominator
3487 */
3488 dotDivide(y: MathType): MathJsChain;
3489
3490 /**
3491 * Multiply two matrices element wise. The function accepts both
3492 * matrices and scalar values.
3493 * @param y Right hand value
3494 */
3495 dotMultiply(y: MathType): MathJsChain;
3496
3497 /**
3498 * Calculates the power of x to y element wise.
3499 * @param y The exponent
3500 */
3501 dotPow(y: MathType): MathJsChain;
3502
3503 /**
3504 * Calculate the exponent of a value. For matrices, the function is
3505 * evaluated element wise.
3506 */
3507 exp(): MathJsChain;
3508
3509 /**
3510 * Calculate the value of subtracting 1 from the exponential value. For
3511 * matrices, the function is evaluated element wise.
3512 */
3513 expm1(): MathJsChain;
3514
3515 /**
3516 * Round a value towards zero. For matrices, the function is evaluated
3517 * element wise.
3518 */
3519 fix(): MathJsChain;
3520
3521 /**
3522 * Round a value towards minus infinity. For matrices, the function is
3523 * evaluated element wise.
3524 */
3525 floor(): MathJsChain;
3526
3527 /**
3528 * Calculate the greatest common divisor for two or more values or
3529 * arrays. For matrices, the function is evaluated element wise.
3530 */
3531 gcd(): MathJsChain;
3532
3533 /**
3534 * Calculate the hypotenusa of a list with values. The hypotenusa is
3535 * defined as: hypot(a, b, c, ...) = sqrt(a^2 + b^2 + c^2 + ...) For
3536 * matrix input, the hypotenusa is calculated for all values in the
3537 * matrix.
3538 */
3539 hypot(): MathJsChain;
3540
3541 /**
3542 * Calculate the least common multiple for two or more values or arrays.
3543 * lcm is defined as: lcm(a, b) = abs(a * b) / gcd(a, b) For matrices,
3544 * the function is evaluated element wise.
3545 * @param b An integer number
3546 */
3547 lcm(b: number | BigNumber | MathArray | Matrix): MathJsChain;
3548
3549 /**
3550 * Calculate the logarithm of a value. For matrices, the function is
3551 * evaluated element wise.
3552 * @param base Optional base for the logarithm. If not provided, the
3553 * natural logarithm of x is calculated. Default value: e.
3554 */
3555 log(base?: number | BigNumber | Complex): MathJsChain;
3556
3557 /**
3558 * Calculate the 10-base of a value. This is the same as calculating
3559 * log(x, 10). For matrices, the function is evaluated element wise.
3560 */
3561 log10(): MathJsChain;
3562
3563 /**
3564 * Calculate the logarithm of a value+1. For matrices, the function is
3565 * evaluated element wise.
3566 */
3567 log1p(base?: number | BigNumber | Complex): MathJsChain;
3568 /**
3569 * Calculate the 2-base of a value. This is the same as calculating
3570 * log(x, 2). For matrices, the function is evaluated element wise.
3571 */
3572 log2(): MathJsChain;
3573 /**
3574 * Calculates the modulus, the remainder of an integer division. For
3575 * matrices, the function is evaluated element wise. The modulus is
3576 * defined as: x - y * floor(x / y)
3577 * @see http://en.wikipedia.org/wiki/Modulo_operation.
3578 * @param y Divisor
3579 */
3580 mod(y: number | BigNumber | Fraction | MathArray | Matrix): MathJsChain;
3581
3582 /**
3583 * Multiply two values, x * y. The result is squeezed. For matrices, the
3584 * matrix product is calculated.
3585 * @param y The second value to multiply
3586 */
3587 multiply(y: MathType): MathJsChain;
3588
3589 /**
3590 * Calculate the norm of a number, vector or matrix. The second
3591 * parameter p is optional. If not provided, it defaults to 2.
3592 * @param p Vector space. Supported numbers include Infinity and
3593 * -Infinity. Supported strings are: 'inf', '-inf', and 'fro' (The
3594 * Frobenius norm) Default value: 2.
3595 */
3596 norm(p?: number | BigNumber | string): MathJsChain;
3597
3598 /**
3599 * Calculate the nth root of a value. The principal nth root of a
3600 * positive real number A, is the positive real solution of the equation
3601 * x^root = A For matrices, the function is evaluated element wise.
3602 * @param root The root. Default value: 2.
3603 */
3604 nthRoot(root?: number | BigNumber): MathJsChain;
3605
3606 /**
3607 * Calculates the power of x to y, x ^ y. Matrix exponentiation is
3608 * supported for square matrices x, and positive integer exponents y.
3609 * @param y The exponent
3610 */
3611 pow(y: number | BigNumber): MathJsChain;
3612
3613 /**
3614 * Round a value towards the nearest integer. For matrices, the function
3615 * is evaluated element wise.
3616 * @param n Number of decimals Default value: 0.
3617 */
3618 round(n?: number | BigNumber | MathArray): MathJsChain;
3619
3620 /**
3621 * Compute the sign of a value. The sign of a value x is: 1 when x > 1
3622 * -1 when x < 0 0 when x == 0 For matrices, the function is evaluated
3623 * element wise.
3624 * @param x The number for which to determine the sign
3625 * @returns The sign of x
3626 */
3627 sign(x: number | BigNumber): MathJsChain;
3628
3629 /**
3630 * Calculate the square root of a value. For matrices, the function is
3631 * evaluated element wise.
3632 */
3633 sqrt(): MathJsChain;
3634
3635 /**
3636 * Compute the square of a value, x * x. For matrices, the function is
3637 * evaluated element wise.
3638 */
3639 square(): MathJsChain;
3640
3641 /**
3642 * Subtract two values, x - y. For matrices, the function is evaluated
3643 * element wise.
3644 * @param y Value to subtract from x
3645 */
3646 subtract(y: MathType): MathJsChain;
3647
3648 /**
3649 * Inverse the sign of a value, apply a unary minus operation. For
3650 * matrices, the function is evaluated element wise. Boolean values and
3651 * strings will be converted to a number. For complex numbers, both real
3652 * and complex value are inverted.
3653 */
3654 unaryMinus(): MathJsChain;
3655
3656 /**
3657 * Unary plus operation. Boolean values and strings will be converted to
3658 * a number, numeric values will be returned as is. For matrices, the
3659 * function is evaluated element wise.
3660 */
3661 unaryPlus(): MathJsChain;
3662
3663 /**
3664 * Calculate the extended greatest common divisor for two values. See
3665 * http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm.
3666 * @param b An integer number
3667 */
3668 xgcd(b: number | BigNumber): MathJsChain;
3669
3670 /*************************************************************************
3671 * Bitwise functions
3672 ************************************************************************/
3673
3674 /**
3675 * Bitwise AND two values, x & y. For matrices, the function is
3676 * evaluated element wise.
3677 * @param y Second value to and
3678 */
3679 bitAnd(y: number | BigNumber | MathArray | Matrix): MathJsChain;
3680
3681 /**
3682 * Bitwise NOT value, ~x. For matrices, the function is evaluated
3683 * element wise. For units, the function is evaluated on the best prefix
3684 * base.
3685 */
3686 bitNot(): MathJsChain;
3687
3688 /**
3689 * Bitwise OR two values, x | y. For matrices, the function is evaluated
3690 * element wise. For units, the function is evaluated on the lowest
3691 * print base.
3692 * @param y Second value to or
3693 */
3694 bitOr(y: number | BigNumber | MathArray | Matrix): MathJsChain;
3695
3696 /**
3697 * Bitwise XOR two values, x ^ y. For matrices, the function is
3698 * evaluated element wise.
3699 * @param y Second value to xor
3700 */
3701 bitXor(y: number | BigNumber | MathArray | Matrix): MathJsChain;
3702
3703 /**
3704 * Bitwise left logical shift of a value x by y number of bits, x << y.
3705 * For matrices, the function is evaluated element wise. For units, the
3706 * function is evaluated on the best prefix base.
3707 * @param y Amount of shifts
3708 */
3709 leftShift(y: number | BigNumber): MathJsChain;
3710
3711 /**
3712 * Bitwise right arithmetic shift of a value x by y number of bits, x >>
3713 * y. For matrices, the function is evaluated element wise. For units,
3714 * the function is evaluated on the best prefix base.
3715 * @param y Amount of shifts
3716 */
3717 rightArithShift(y: number | BigNumber): MathJsChain;
3718
3719 /**
3720 * Bitwise right logical shift of value x by y number of bits, x >>> y.
3721 * For matrices, the function is evaluated element wise. For units, the
3722 * function is evaluated on the best prefix base.
3723 * @param y Amount of shifts
3724 */
3725 rightLogShift(y: number): MathJsChain;
3726
3727 /*************************************************************************
3728 * Combinatorics functions
3729 ************************************************************************/
3730
3731 /**
3732 * The Bell Numbers count the number of partitions of a set. A partition
3733 * is a pairwise disjoint subset of S whose union is S. bellNumbers only
3734 * takes integer arguments. The following condition must be enforced: n
3735 * >= 0
3736 */
3737 bellNumbers(): MathJsChain;
3738
3739 /**
3740 * The Catalan Numbers enumerate combinatorial structures of many
3741 * different types. catalan only takes integer arguments. The following
3742 * condition must be enforced: n >= 0
3743 */
3744 catalan(): MathJsChain;
3745
3746 /**
3747 * The composition counts of n into k parts. Composition only takes
3748 * integer arguments. The following condition must be enforced: k <= n.
3749 * @param k Number of objects in the subset
3750 */
3751 composition(k: number | BigNumber): MathJsChain;
3752
3753 /**
3754 * The Stirling numbers of the second kind, counts the number of ways to
3755 * partition a set of n labelled objects into k nonempty unlabelled
3756 * subsets. stirlingS2 only takes integer arguments. The following
3757 * condition must be enforced: k <= n. If n = k or k = 1, then s(n,k) =
3758 * 1
3759 * @param k Number of objects in the subset
3760 */
3761 stirlingS2(k: number | BigNumber): MathJsChain;
3762
3763 /*************************************************************************
3764 * Complex functions
3765 ************************************************************************/
3766
3767 /**
3768 * Compute the argument of a complex value. For a complex number a + bi,
3769 * the argument is computed as atan2(b, a). For matrices, the function
3770 * is evaluated element wise.
3771 */
3772 arg(): MathJsChain;
3773
3774 /**
3775 * Compute the complex conjugate of a complex value. If x = a+bi, the
3776 * complex conjugate of x is a - bi. For matrices, the function is
3777 * evaluated element wise.
3778 */
3779 conj(): MathJsChain;
3780
3781 /**
3782 * Get the imaginary part of a complex number. For a complex number a +
3783 * bi, the function returns b. For matrices, the function is evaluated
3784 * element wise.
3785 */
3786 im(): MathJsChain;
3787
3788 /**
3789 * Get the real part of a complex number. For a complex number a + bi,
3790 * the function returns a. For matrices, the function is evaluated
3791 * element wise.
3792 */
3793 re(): MathJsChain;
3794
3795 /*************************************************************************
3796 * Geometry functions
3797 ************************************************************************/
3798
3799 /**
3800 * Calculates: The eucledian distance between two points in 2 and 3
3801 * dimensional spaces. Distance between point and a line in 2 and 3
3802 * dimensional spaces. Pairwise distance between a set of 2D or 3D
3803 * points NOTE: When substituting coefficients of a line(a, b and c),
3804 * use ax + by + c = 0 instead of ax + by = c For parametric equation of
3805 * a 3D line, x0, y0, z0, a, b, c are from: (x−x0, y−y0, z−z0) = t(a, b,
3806 * c)
3807 * @param y Coordinates of the second point
3808 */
3809 distance(y: MathArray | Matrix | object): MathJsChain;
3810
3811 /**
3812 * Calculates the point of intersection of two lines in two or three
3813 * dimensions and of a line and a plane in three dimensions. The inputs
3814 * are in the form of arrays or 1 dimensional matrices. The line
3815 * intersection functions return null if the lines do not meet. Note:
3816 * Fill the plane coefficients as x + y + z = c and not as x + y + z + c
3817 * = 0.
3818 * @param x Co-ordinates of second end-point of first line
3819 * @param y Co-ordinates of first end-point of second line OR
3820 * Coefficients of the plane's equation
3821 * @param z Co-ordinates of second end-point of second line OR null if
3822 * the calculation is for line and plane
3823 */
3824 intersect(x: MathArray | Matrix, y: MathArray | Matrix, z: MathArray | Matrix): MathJsChain;
3825
3826 /*************************************************************************
3827 * Logical functions
3828 ************************************************************************/
3829
3830 /**
3831 * Logical and. Test whether two values are both defined with a
3832 * nonzero/nonempty value. For matrices, the function is evaluated
3833 * element wise.
3834 * @param y Second value to and
3835 */
3836 and(y: number | BigNumber | Complex | Unit | MathArray | Matrix): MathJsChain;
3837
3838 /**
3839 * Logical not. Flips boolean value of a given parameter. For matrices,
3840 * the function is evaluated element wise.
3841 */
3842 not(): MathJsChain;
3843
3844 /**
3845 * Logical or. Test if at least one value is defined with a
3846 * nonzero/nonempty value. For matrices, the function is evaluated
3847 * element wise.
3848 * @param y Second value to or
3849 */
3850 or(y: number | BigNumber | Complex | Unit | MathArray | Matrix): MathJsChain;
3851
3852 /**
3853 * Logical xor. Test whether one and only one value is defined with a
3854 * nonzero/nonempty value. For matrices, the function is evaluated
3855 * element wise.
3856 * @param y Second value to xor
3857 */
3858 xor(y: number | BigNumber | Complex | Unit | MathArray | Matrix): MathJsChain;
3859
3860 /*************************************************************************
3861 * Matrix functions
3862 ************************************************************************/
3863
3864 /**
3865 * Concatenate two or more matrices. dim: number is a zero-based
3866 * dimension over which to concatenate the matrices. By default the last
3867 * dimension of the matrices.
3868 */
3869 concat(): MathJsChain;
3870
3871 /**
3872 * Calculate the cross product for two vectors in three dimensional
3873 * space. The cross product of A = [a1, a2, a3] and B =[b1, b2, b3] is
3874 * defined as: cross(A, B) = [ a2 * b3 - a3 * b2, a3 * b1 - a1 * b3, a1
3875 * * b2 - a2 * b1 ]
3876 * @param y Second vector
3877 */
3878 cross(y: MathArray | Matrix): MathJsChain;
3879
3880 /**
3881 * Calculate the determinant of a matrix.
3882 */
3883 det(): MathJsChain;
3884
3885 /**
3886 * Create a diagonal matrix or retrieve the diagonal of a matrix. When x
3887 * is a vector, a matrix with vector x on the diagonal will be returned.
3888 * When x is a two dimensional matrix, the matrixes kth diagonal will be
3889 * returned as vector. When k is positive, the values are placed on the
3890 * super diagonal. When k is negative, the values are placed on the sub
3891 * diagonal.
3892 * @param k The diagonal where the vector will be filled in or
3893 * retrieved. Default value: 0.
3894 * @param format The matrix storage format. Default value: 'dense'.
3895 */
3896 diag(format?: string): MathJsChain;
3897 diag(k: number | BigNumber, format?: string): MathJsChain;
3898
3899 /**
3900 * Calculate the dot product of two vectors. The dot product of A = [a1,
3901 * a2, a3, ..., an] and B = [b1, b2, b3, ..., bn] is defined as: dot(A,
3902 * B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn
3903 * @param y Second vector
3904 */
3905 dot(y: MathArray | Matrix): MathJsChain;
3906
3907 /**
3908 * Compute the matrix exponential, expm(A) = e^A. The matrix must be
3909 * square. Not to be confused with exp(a), which performs element-wise
3910 * exponentiation. The exponential is calculated using the Padé
3911 * approximant with scaling and squaring; seeNineteen Dubious Ways to
3912 * Compute the Exponential of a Matrix,” by Moler and Van Loan.
3913 */
3914 expm(): MathJsChain;
3915
3916 /**
3917 * Create a 2-dimensional identity matrix with size m x n or n x n. The
3918 * matrix has ones on the diagonal and zeros elsewhere.
3919 * @param format The Matrix storage format
3920 */
3921 identity(format?: string): MathJsChain;
3922 /**
3923 * @param n The y dimension for the matrix
3924 * @param format The Matrix storage format
3925 */
3926 identity(n: number, format?: string): MathJsChain;
3927
3928 /**
3929 * Filter the items in an array or one dimensional matrix.
3930 */
3931 filter(test: ((value: any, index: any, matrix: Matrix | MathArray) => boolean) | RegExp): MathJsChain;
3932
3933 /**
3934 * Flatten a multi dimensional matrix into a single dimensional matrix.
3935 */
3936 flatten(): MathJsChain;
3937
3938 /**
3939 * Iterate over all elements of a matrix/array, and executes the given
3940 * callback function.
3941 */
3942 forEach(callback: (value: any, index: any, matrix: Matrix | MathArray) => void): MathJsChain;
3943
3944 /**
3945 * Calculate the inverse of a square matrix.
3946 */
3947 inv(): MathJsChain;
3948
3949 /**
3950 * Calculate the kronecker product of two matrices or vectors
3951 * @param y Second vector
3952 */
3953 kron(y: Matrix | MathArray): MathJsChain;
3954
3955 /**
3956 * Iterate over all elements of a matrix/array, and executes the given
3957 * callback function.
3958 * @param callback The callback function is invoked with three
3959 * parameters: the value of the element, the index of the element, and
3960 * the Matrix/array being traversed.
3961 */
3962 map(callback: (value: any, index: any, matrix: Matrix | MathArray) => Matrix | MathArray): MathJsChain;
3963
3964 /**
3965 * Create a matrix filled with ones. The created matrix can have one or
3966 * multiple dimensions.
3967 * @param format The matrix storage format
3968 */
3969 ones(format?: string): MathJsChain;
3970 /**
3971 * @param format The matrix storage format
3972 */
3973 ones(n: number, format?: string): MathJsChain;
3974 /**
3975 * Partition-based selection of an array or 1D matrix. Will find the kth
3976 * smallest value, and mutates the input array. Uses Quickselect.
3977 * @param k The kth smallest value to be retrieved; zero-based index
3978 * @param compare An optional comparator function. The function is
3979 * called as compare(a, b), and must return 1 when a > b, -1 when a < b,
3980 * and 0 when a == b. Default value: 'asc'.
3981 */
3982 partitionSelect(k: number, compare?: 'asc' | 'desc' | ((a: any, b: any) => number)): MathJsChain;
3983
3984 /**
3985 * Create an array from a range. By default, the range end is excluded.
3986 * This can be customized by providing an extra parameter includeEnd.
3987 * @param end End of the range, excluded by default, included when
3988 * parameter includeEnd=true
3989 * @param step Step size. Default value is 1.
3990 * @param includeEnd: Option to specify whether to include the end or
3991 * not. False by default
3992 */
3993 range(includeEnd?: boolean): Matrix;
3994 range(end: number | BigNumber, includeEnd?: boolean): MathJsChain;
3995 range(end: number | BigNumber, step: number | BigNumber, includeEnd?: boolean): MathJsChain;
3996
3997 /**
3998 * Reshape a multi dimensional array to fit the specified dimensions
3999 * @param sizes One dimensional array with integral sizes for each
4000 * dimension
4001 */
4002 reshape(sizes: number[]): MathJsChain;
4003
4004 /**
4005 * Resize a matrix
4006 * @param size One dimensional array with numbers
4007 * @param defaultValue Zero by default, except in case of a string, in
4008 * that case defaultValue = ' ' Default value: 0.
4009 */
4010 resize(size: MathArray | Matrix, defaultValue?: number | string): MathJsChain;
4011
4012 /**
4013 * Calculate the size of a matrix or scalar.
4014 */
4015 size(): MathJsChain;
4016
4017 /**
4018 * Sort the items in a matrix
4019 * @param compare An optional _comparator function or name. The function
4020 * is called as compare(a, b), and must return 1 when a > b, -1 when a <
4021 * b, and 0 when a == b. Default value: ‘asc
4022 */
4023 sort(compare: ((a: any, b: any) => number) | 'asc' | 'desc' | 'natural'): MathJsChain;
4024
4025 /**
4026 * Calculate the principal square root of a square matrix. The principal
4027 * square root matrix X of another matrix A is such that X * X = A.
4028 */
4029 sqrtm(): MathJsChain;
4030
4031 /**
4032 * Squeeze a matrix, remove inner and outer singleton dimensions from a
4033 * matrix.
4034 */
4035 squeeze(): MathJsChain;
4036
4037 /**
4038 * Get or set a subset of a matrix or string.
4039 * @param index An index containing ranges for each dimension
4040 * @param replacement An array, matrix, or scalar. If provided, the
4041 * subset is replaced with replacement. If not provided, the subset is
4042 * returned
4043 * @param defaultValue Default value, filled in on new entries when the
4044 * matrix is resized. If not provided, math.matrix elements will be left
4045 * undefined. Default value: undefined.
4046 */
4047 subset(index: Index, replacement?: any, defaultValue?: any): MathJsChain;
4048
4049 /**
4050 * Calculate the trace of a matrix: the sum of the elements on the main
4051 * diagonal of a square matrix.
4052 */
4053 trace(): MathJsChain;
4054
4055 /**
4056 * Transpose a matrix. All values of the matrix are reflected over its
4057 * main diagonal. Only two dimensional matrices are supported.
4058 */
4059 transpose(): MathJsChain;
4060
4061 /**
4062 * Create a matrix filled with zeros. The created matrix can have one or
4063 * multiple dimensions.
4064 * @param format The matrix storage format
4065 * @returns A matrix filled with zeros
4066 */
4067 zeros(format?: string): MathJsChain;
4068 /**
4069 * @param n The y dimension of the matrix
4070 * @param format The matrix storage format
4071 */
4072 zeros(n: number, format?: string): MathJsChain;
4073
4074 /*************************************************************************
4075 * Probability functions
4076 ************************************************************************/
4077
4078 /**
4079 * Compute the number of ways of picking k unordered outcomes from n
4080 * possibilities. Combinations only takes integer arguments. The
4081 * following condition must be enforced: k <= n.
4082 * @param k Number of objects in the subset
4083 */
4084 combinations(k: number | BigNumber): MathJsChain;
4085
4086 /**
4087 * Compute the factorial of a value Factorial only supports an integer
4088 * value as argument. For matrices, the function is evaluated element
4089 * wise.
4090 */
4091 factorial(): MathJsChain;
4092
4093 /**
4094 * Compute the gamma function of a value using Lanczos approximation for
4095 * small values, and an extended Stirling approximation for large
4096 * values. For matrices, the function is evaluated element wise.
4097 */
4098 gamma(): MathJsChain;
4099
4100 /**
4101 * Calculate the Kullback-Leibler (KL) divergence between two
4102 * distributions
4103 * @param p Second vector
4104 */
4105 kldivergence(p: MathArray | Matrix): MathJsChain;
4106
4107 /**
4108 * Multinomial Coefficients compute the number of ways of picking a1,
4109 * a2, ..., ai unordered outcomes from n possibilities. multinomial
4110 * takes one array of integers as an argument. The following condition
4111 * must be enforced: every ai <= 0
4112 */
4113 multinomial(): MathJsChain;
4114
4115 /**
4116 * Compute the number of ways of obtaining an ordered subset of k
4117 * elements from a set of n elements. Permutations only takes integer
4118 * arguments. The following condition must be enforced: k <= n.
4119 * @param k The number of objects in the subset
4120 */
4121 permutations(k?: number | BigNumber): MathJsChain;
4122
4123 /**
4124 * Random pick a value from a one dimensional array. Array element is
4125 * picked using a random function with uniform distribution.
4126 * @param number An int or float
4127 * @param weights An array of ints or floats
4128 */
4129 pickRandom(number?: number, weights?: number[]): MathJsChain;
4130
4131 /**
4132 * Return a random number larger or equal to min and smaller than max
4133 * using a uniform distribution.
4134 * @param min Minimum boundary for the random value, included
4135 * @param max Maximum boundary for the random value, excluded
4136 */
4137 random(max?: number): MathJsChain;
4138 // tslint:disable-next-line unified-signatures
4139 random(min: number, max: number): MathJsChain;
4140
4141 /**
4142 * Return a random integer number larger or equal to min and smaller
4143 * than max using a uniform distribution.
4144 * @param min Minimum boundary for the random value, included
4145 * @param max Maximum boundary for the random value, excluded
4146 */
4147 randomInt(max?: number): MathJsChain;
4148 // tslint:disable-next-line unified-signatures
4149 randomInt(min: number, max: number): MathJsChain;
4150
4151 /*************************************************************************
4152 * Relational functions
4153 ************************************************************************/
4154
4155 /**
4156 * Compare two values. Returns 1 when x > y, -1 when x < y, and 0 when x
4157 * == y. x and y are considered equal when the relative difference
4158 * between x and y is smaller than the configured epsilon. The function
4159 * cannot be used to compare values smaller than approximately 2.22e-16.
4160 * For matrices, the function is evaluated element wise.
4161 * @param y Second value to compare
4162 */
4163 compare(y: MathType | string): MathJsChain;
4164
4165 /**
4166 * Compare two values of any type in a deterministic, natural way. For
4167 * numeric values, the function works the same as math.compare. For
4168 * types of values that cant be compared mathematically, the function
4169 * compares in a natural way.
4170 * @param y Second value to compare
4171 */
4172 compareNatural(y: any): MathJsChain;
4173
4174 /**
4175 * Compare two strings lexically. Comparison is case sensitive. Returns
4176 * 1 when x > y, -1 when x < y, and 0 when x == y. For matrices, the
4177 * function is evaluated element wise.
4178 * @param y Second string to compare
4179 */
4180 compareText(y: string | MathArray | Matrix): MathJsChain;
4181
4182 /**
4183 * Test element wise whether two matrices are equal. The function
4184 * accepts both matrices and scalar values.
4185 * @param y Second amtrix to compare
4186 */
4187 deepEqual(y: MathType): MathJsChain;
4188
4189 /**
4190 * Test whether two values are equal.
4191 *
4192 * The function tests whether the relative difference between x and y is
4193 * smaller than the configured epsilon. The function cannot be used to
4194 * compare values smaller than approximately 2.22e-16. For matrices, the
4195 * function is evaluated element wise. In case of complex numbers, x.re
4196 * must equal y.re, and x.im must equal y.im. Values null and undefined
4197 * are compared strictly, thus null is only equal to null and nothing
4198 * else, and undefined is only equal to undefined and nothing else.
4199 * @param y Second value to compare
4200 */
4201 equal(y: MathType | string): MathJsChain;
4202
4203 /**
4204 * Check equality of two strings. Comparison is case sensitive. For
4205 * matrices, the function is evaluated element wise.
4206 * @param y Second string to compare
4207 */
4208 equalText(y: string | MathArray | Matrix): MathJsChain;
4209
4210 /**
4211 * Test whether value x is larger than y. The function returns true when
4212 * x is larger than y and the relative difference between x and y is
4213 * larger than the configured epsilon. The function cannot be used to
4214 * compare values smaller than approximately 2.22e-16. For matrices, the
4215 * function is evaluated element wise.
4216 * @param y Second value to compare
4217 */
4218 larger(y: MathType | string): MathJsChain;
4219
4220 /**
4221 * Test whether value x is larger or equal to y. The function returns
4222 * true when x is larger than y or the relative difference between x and
4223 * y is smaller than the configured epsilon. The function cannot be used
4224 * to compare values smaller than approximately 2.22e-16. For matrices,
4225 * the function is evaluated element wise.
4226 * @param y Second value to vcompare
4227 */
4228 largerEq(y: MathType | string): MathJsChain;
4229
4230 /**
4231 * Test whether value x is smaller than y. The function returns true
4232 * when x is smaller than y and the relative difference between x and y
4233 * is smaller than the configured epsilon. The function cannot be used
4234 * to compare values smaller than approximately 2.22e-16. For matrices,
4235 * the function is evaluated element wise.
4236 * @param y Second value to vcompare
4237 */
4238 smaller(y: MathType | string): MathJsChain;
4239
4240 /**
4241 * Test whether value x is smaller or equal to y. The function returns
4242 * true when x is smaller than y or the relative difference between x
4243 * and y is smaller than the configured epsilon. The function cannot be
4244 * used to compare values smaller than approximately 2.22e-16. For
4245 * matrices, the function is evaluated element wise.
4246 * @param y Second value to compare
4247 */
4248 smallerEq(y: MathType | string): MathJsChain;
4249
4250 /**
4251 * Test whether two values are unequal. The function tests whether the
4252 * relative difference between x and y is larger than the configured
4253 * epsilon. The function cannot be used to compare values smaller than
4254 * approximately 2.22e-16. For matrices, the function is evaluated
4255 * element wise. In case of complex numbers, x.re must unequal y.re, or
4256 * x.im must unequal y.im. Values null and undefined are compared
4257 * strictly, thus null is unequal with everything except null, and
4258 * undefined is unequal with everything except undefined.
4259 * @param y Second value to vcompare
4260 */
4261 unequal(y: MathType | string): MathJsChain;
4262
4263 /*************************************************************************
4264 * Set functions
4265 ************************************************************************/
4266
4267 /**
4268 * Create the cartesian product of two (multi)sets. Multi-dimension
4269 * arrays will be converted to single-dimension arrays before the
4270 * operation.
4271 * @param a2 A (multi)set
4272 */
4273 setCartesian(a2: MathArray | Matrix): MathJsChain;
4274
4275 /**
4276 * Create the difference of two (multi)sets: every element of set1, that
4277 * is not the element of set2. Multi-dimension arrays will be converted
4278 * to single-dimension arrays before the operation
4279 * @param a2 A (multi)set
4280 */
4281 setDifference(a2: MathArray | Matrix): MathJsChain;
4282
4283 /**
4284 * Collect the distinct elements of a multiset. A multi-dimension array
4285 * will be converted to a single-dimension array before the operation.
4286 */
4287 setDistinct(): MathJsChain;
4288
4289 /**
4290 * Create the intersection of two (multi)sets. Multi-dimension arrays
4291 * will be converted to single-dimension arrays before the operation.
4292 * @param a2 A (multi)set
4293 */
4294 setIntersect(a2: MathArray | Matrix): MathJsChain;
4295
4296 /**
4297 * Check whether a (multi)set is a subset of another (multi)set. (Every
4298 * element of set1 is the element of set2.) Multi-dimension arrays will
4299 * be converted to single-dimension arrays before the operation.
4300 * @param a2 A (multi)set
4301 */
4302 setIsSubset(a2: MathArray | Matrix): MathJsChain;
4303
4304 /**
4305 * Count the multiplicity of an element in a multiset. A multi-dimension
4306 * array will be converted to a single-dimension array before the
4307 * operation.
4308 * @param a A multiset
4309 */
4310 setMultiplicity(a: MathArray | Matrix): MathJsChain;
4311
4312 /**
4313 * Create the powerset of a (multi)set. (The powerset contains very
4314 * possible subsets of a (multi)set.) A multi-dimension array will be
4315 * converted to a single-dimension array before the operation.
4316 */
4317 setPowerset(): MathJsChain;
4318
4319 /**
4320 * Count the number of elements of a (multi)set. When a second parameter
4321 * istrue’, count only the unique values. A multi-dimension array will
4322 * be converted to a single-dimension array before the operation.
4323 */
4324 setSize(): MathJsChain;
4325
4326 /**
4327 * Create the symmetric difference of two (multi)sets. Multi-dimension
4328 * arrays will be converted to single-dimension arrays before the
4329 * operation.
4330 * @param a2 A (multi)set
4331 */
4332 setSymDifference(a2: MathArray | Matrix): MathJsChain;
4333
4334 /**
4335 * Create the union of two (multi)sets. Multi-dimension arrays will be
4336 * converted to single-dimension arrays before the operation.
4337 * @param a2 A (multi)set
4338 */
4339 setUnion(a2: MathArray | Matrix): MathJsChain;
4340
4341 /*************************************************************************
4342 * Special functions
4343 ************************************************************************/
4344
4345 /**
4346 * Compute the erf function of a value using a rational Chebyshev
4347 * approximations for different intervals of x.
4348 */
4349 erf(): MathJsChain;
4350
4351 /*************************************************************************
4352 * Statistics functions
4353 ************************************************************************/
4354
4355 /**
4356 * Compute the median absolute deviation of a matrix or a list with
4357 * values. The median absolute deviation is defined as the median of the
4358 * absolute deviations from the median.
4359 */
4360 mad(): MathJsChain;
4361
4362 /**
4363 * Compute the maximum value of a matrix or a list with values. In case
4364 * of a multi dimensional array, the maximum of the flattened array will
4365 * be calculated. When dim is provided, the maximum over the selected
4366 * dimension will be calculated. Parameter dim is zero-based.
4367 * @param dim The maximum over the selected dimension
4368 */
4369 max(dim?: number): MathJsChain;
4370
4371 /**
4372 * Compute the mean value of matrix or a list with values. In case of a
4373 * multi dimensional array, the mean of the flattened array will be
4374 * calculated. When dim is provided, the maximum over the selected
4375 * dimension will be calculated. Parameter dim is zero-based.
4376 * @param dim The mean over the selected dimension
4377 */
4378 mean(dim?: number): MathJsChain;
4379
4380 /**
4381 * Compute the median of a matrix or a list with values. The values are
4382 * sorted and the middle value is returned. In case of an even number of
4383 * values, the average of the two middle values is returned. Supported
4384 * types of values are: Number, BigNumber, Unit In case of a (multi
4385 * dimensional) array or matrix, the median of all elements will be
4386 * calculated.
4387 */
4388 median(): MathJsChain;
4389
4390 /**
4391 * Compute the maximum value of a matrix or a list of values. In case of
4392 * a multi dimensional array, the maximum of the flattened array will be
4393 * calculated. When dim is provided, the maximum over the selected
4394 * dimension will be calculated. Parameter dim is zero-based.
4395 * @param dim The minimum over the selected dimension
4396 */
4397 min(dim?: number): MathJsChain;
4398
4399 /**
4400 * Computes the mode of a set of numbers or a list with values(numbers
4401 * or characters). If there are more than one modes, it returns a list
4402 * of those values.
4403 */
4404 mode(): MathJsChain;
4405
4406 /**
4407 * Compute the product of a matrix or a list with values. In case of a
4408 * (multi dimensional) array or matrix, the sum of all elements will be
4409 * calculated.
4410 */
4411 prod(): MathJsChain;
4412
4413 /**
4414 * Compute the prob order quantile of a matrix or a list with values.
4415 * The sequence is sorted and the middle value is returned. Supported
4416 * types of sequence values are: Number, BigNumber, Unit Supported types
4417 * of probability are: Number, BigNumber In case of a (multi
4418 * dimensional) array or matrix, the prob order quantile of all elements
4419 * will be calculated.
4420 * @param probOrN prob is the order of the quantile, while N is the
4421 * amount of evenly distributed steps of probabilities; only one of
4422 * these options can be provided
4423 * @param sorted =false is data sorted in ascending order
4424 */
4425 quantileSeq(prob: number | BigNumber | MathArray, sorted?: boolean): MathJsChain;
4426
4427 /**
4428 * Compute the standard deviation of a matrix or a list with values. The
4429 * standard deviations is defined as the square root of the variance:
4430 * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or
4431 * matrix, the standard deviation over all elements will be calculated.
4432 * Optionally, the type of normalization can be specified as second
4433 * parameter. The parameter normalization can be one of the following
4434 * values: 'unbiased' (default) The sum of squared errors is divided by
4435 * (n - 1) 'uncorrected' The sum of squared errors is divided by n
4436 * 'biased' The sum of squared errors is divided by (n + 1)
4437 * @param array A single matrix or multiple scalar values
4438 * @param normalization Determines how to normalize the variance. Choose
4439 * ‘unbiased’ (default), ‘uncorrected’, orbiased’. Default value:
4440 * ‘unbiased’.
4441 * @returns The standard deviation
4442 */
4443 std(normalization?: 'unbiased' | 'uncorrected' | 'biased' | 'unbiased'): MathJsChain;
4444
4445 /**
4446 * Compute the sum of a matrix or a list with values. In case of a
4447 * (multi dimensional) array or matrix, the sum of all elements will be
4448 * calculated.
4449 */
4450 sum(): MathJsChain;
4451
4452 /**
4453 * Compute the variance of a matrix or a list with values. In case of a
4454 * (multi dimensional) array or matrix, the variance over all elements
4455 * will be calculated. Optionally, the type of normalization can be
4456 * specified as second parameter. The parameter normalization can be one
4457 * of the following values: 'unbiased' (default) The sum of squared
4458 * errors is divided by (n - 1) 'uncorrected' The sum of squared errors
4459 * is divided by n 'biased' The sum of squared errors is divided by (n +
4460 * 1) Note that older browser may not like the variable name var. In
4461 * that case, the function can be called as math['var'](...) instead of
4462 * math.variance(...).
4463 * @param normalization normalization Determines how to normalize the
4464 * variance. Chooseunbiased’ (default), ‘uncorrected’, orbiased’.
4465 * Default value: ‘unbiased’.
4466 * @returns The variance
4467 */
4468 variance(normalization?: 'unbiased' | 'uncorrected' | 'biased' | 'unbiased'): MathJsChain;
4469
4470 /*************************************************************************
4471 * String functions
4472 ************************************************************************/
4473
4474 /**
4475 * Format a value of any type into a string.
4476 * @param options An object with formatting options.
4477 * @param callback A custom formatting function, invoked for all numeric
4478 * elements in value, for example all elements of a matrix, or the real
4479 * and imaginary parts of a complex number. This callback can be used to
4480 * override the built-in numeric notation with any type of formatting.
4481 * Function callback is called with value as parameter and must return a
4482 * string.
4483 * @see http://mathjs.org/docs/reference/functions/format.html
4484 */
4485 format(value: any, options?: FormatOptions | number | ((item: any) => string), callback?: (value: any) => string): MathJsChain;
4486
4487 /**
4488 * Interpolate values into a string template.
4489 * @param values An object containing variables which will be filled in
4490 * in the template.
4491 * @param precision Number of digits to format numbers. If not provided,
4492 * the value will not be rounded.
4493 * @param options Formatting options, or the number of digits to format
4494 * numbers. See function math.format for a description of all options.
4495 */
4496 print(values: any, precision?: number, options?: number | object): MathJsChain;
4497
4498 /*************************************************************************
4499 * Trigonometry functions
4500 ************************************************************************/
4501
4502 /**
4503 * Calculate the inverse cosine of a value. For matrices, the function
4504 * is evaluated element wise.
4505 */
4506 acos(): MathJsChain;
4507
4508 /**
4509 * Calculate the hyperbolic arccos of a value, defined as acosh(x) =
4510 * ln(sqrt(x^2 - 1) + x). For matrices, the function is evaluated
4511 * element wise.
4512 */
4513 acosh(): MathJsChain;
4514
4515 /**
4516 * Calculate the inverse cotangent of a value. For matrices, the
4517 * function is evaluated element wise.
4518 */
4519 acot(): MathJsChain;
4520
4521 /**
4522 * Calculate the hyperbolic arccotangent of a value, defined as acoth(x)
4523 * = (ln((x+1)/x) + ln(x/(x-1))) / 2. For matrices, the function is
4524 * evaluated element wise.
4525 */
4526 acoth(): MathJsChain;
4527
4528 /**
4529 * Calculate the inverse cosecant of a value. For matrices, the function
4530 * is evaluated element wise.
4531 */
4532 acsc(): MathJsChain;
4533
4534 /**
4535 * Calculate the hyperbolic arccosecant of a value, defined as acsch(x)
4536 * = ln(1/x + sqrt(1/x^2 + 1)). For matrices, the function is evaluated
4537 * element wise.
4538 */
4539 acsch(): MathJsChain;
4540
4541 /**
4542 * Calculate the inverse secant of a value. For matrices, the function
4543 * is evaluated element wise.
4544 */
4545 asec(): MathJsChain;
4546
4547 /**
4548 * Calculate the hyperbolic arcsecant of a value, defined as asech(x) =
4549 * ln(sqrt(1/x^2 - 1) + 1/x). For matrices, the function is evaluated
4550 * element wise.
4551 */
4552 asech(): MathJsChain;
4553
4554 /**
4555 * Calculate the inverse sine of a value. For matrices, the function is
4556 * evaluated element wise.
4557 */
4558 asin(): MathJsChain;
4559
4560 /**
4561 * Calculate the hyperbolic arcsine of a value, defined as asinh(x) =
4562 * ln(x + sqrt(x^2 + 1)). For matrices, the function is evaluated
4563 * element wise.
4564 */
4565 asinh(): MathJsChain;
4566
4567 /**
4568 * Calculate the inverse tangent of a value. For matrices, the function
4569 * is evaluated element wise.
4570 */
4571 atan(): MathJsChain;
4572
4573 /**
4574 * Calculate the inverse tangent function with two arguments, y/x. By
4575 * providing two arguments, the right quadrant of the computed angle can
4576 * be determined. For matrices, the function is evaluated element wise.
4577 */
4578 atan2(): MathJsChain;
4579
4580 /**
4581 * Calculate the hyperbolic arctangent of a value, defined as atanh(x) =
4582 * ln((1 + x)/(1 - x)) / 2. For matrices, the function is evaluated
4583 * element wise.
4584 */
4585 atanh(): MathJsChain;
4586
4587 /**
4588 * Calculate the cosine of a value. For matrices, the function is
4589 * evaluated element wise.
4590 */
4591 cos(): MathJsChain;
4592
4593 /**
4594 * Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2
4595 * * (exp(x) + exp(-x)). For matrices, the function is evaluated element
4596 * wise.
4597 */
4598 cosh(): MathJsChain;
4599
4600 /**
4601 * Calculate the cotangent of a value. cot(x) is defined as 1 / tan(x).
4602 * For matrices, the function is evaluated element wise.
4603 */
4604 cot(): MathJsChain;
4605
4606 /**
4607 * Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1
4608 * / tanh(x). For matrices, the function is evaluated element wise.
4609 */
4610 coth(): MathJsChain;
4611
4612 /**
4613 * Calculate the cosecant of a value, defined as csc(x) = 1/sin(x). For
4614 * matrices, the function is evaluated element wise.
4615 */
4616 csc(): MathJsChain;
4617
4618 /**
4619 * Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1
4620 * / sinh(x). For matrices, the function is evaluated element wise.
4621 */
4622 csch(): MathJsChain;
4623
4624 /**
4625 * Calculate the secant of a value, defined as sec(x) = 1/cos(x). For
4626 * matrices, the function is evaluated element wise.
4627 */
4628 sec(): MathJsChain;
4629
4630 /**
4631 * Calculate the hyperbolic secant of a value, defined as sech(x) = 1 /
4632 * cosh(x). For matrices, the function is evaluated element wise.
4633 */
4634 sech(): MathJsChain;
4635
4636 /**
4637 * Calculate the sine of a value. For matrices, the function is
4638 * evaluated element wise.
4639 */
4640 sin(): MathJsChain;
4641
4642 /**
4643 * Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 *
4644 * (exp(x) - exp(-x)). For matrices, the function is evaluated element
4645 * wise.
4646 */
4647 sinh(): MathJsChain;
4648
4649 /**
4650 * Calculate the tangent of a value. tan(x) is equal to sin(x) / cos(x).
4651 * For matrices, the function is evaluated element wise.
4652 */
4653 tan(): MathJsChain;
4654
4655 /**
4656 * Calculate the hyperbolic tangent of a value, defined as tanh(x) =
4657 * (exp(2 * x) - 1) / (exp(2 * x) + 1). For matrices, the function is
4658 * evaluated element wise.
4659 */
4660 tanh(): MathJsChain;
4661
4662 /*************************************************************************
4663 * Unit functions
4664 ************************************************************************/
4665
4666 /**
4667 * Change the unit of a value. For matrices, the function is evaluated
4668 * element wise.
4669 * @param unit New unit. Can be a string like "cm" or a unit without
4670 * value.
4671 */
4672 to(unit: Unit | string): MathJsChain;
4673
4674 /*************************************************************************
4675 * Utils functions
4676 ************************************************************************/
4677
4678 /**
4679 * Clone an object.
4680 */
4681 clone(): MathJsChain;
4682
4683 /**
4684 * Test whether a value is an integer number. The function supports
4685 * number, BigNumber, and Fraction. The function is evaluated
4686 * element-wise in case of Array or Matrix input.
4687 */
4688 isInteger(): MathJsChain;
4689
4690 /**
4691 * Test whether a value is NaN (not a number). The function supports
4692 * types number, BigNumber, Fraction, Unit and Complex. The function is
4693 * evaluated element-wise in case of Array or Matrix input.
4694 */
4695 isNaN(): MathJsChain;
4696
4697 /**
4698 * Test whether a value is negative: smaller than zero. The function
4699 * supports types number, BigNumber, Fraction, and Unit. The function is
4700 * evaluated element-wise in case of Array or Matrix input.
4701 */
4702 isNegative(): MathJsChain;
4703
4704 /**
4705 * Test whether a value is an numeric value. The function is evaluated
4706 * element-wise in case of Array or Matrix input.
4707 */
4708 isNumeric(): MathJsChain;
4709
4710 /**
4711 * Test whether a value is positive: larger than zero. The function
4712 * supports types number, BigNumber, Fraction, and Unit. The function is
4713 * evaluated element-wise in case of Array or Matrix input.
4714 */
4715 isPositive(): MathJsChain;
4716
4717 /**
4718 * Test whether a value is prime: has no divisors other than itself and
4719 * one. The function supports type number, bignumber. The function is
4720 * evaluated element-wise in case of Array or Matrix input.
4721 */
4722 isPrime(): MathJsChain;
4723
4724 /**
4725 * Test whether a value is zero. The function can check for zero for
4726 * types number, BigNumber, Fraction, Complex, and Unit. The function is
4727 * evaluated element-wise in case of Array or Matrix input.
4728 */
4729 isZero(): MathJsChain;
4730
4731 /**
4732 * Determine the type of a variable.
4733 */
4734 typeOf(): MathJsChain;
4735 }
4736
4737 interface ImportOptions {
4738 override?: boolean;
4739 silent?: boolean;
4740 wrap?: boolean;
4741 }
4742
4743 interface ImportObject {
4744 [key: string]: any;
4745 }
4746}
4747
\No newline at end of file