UNPKG

238 kBTypeScriptView Raw
1import { Decimal } from 'decimal.js'
2
3declare const math: math.MathJsStatic
4export as namespace math
5export = math
6
7type NoLiteralType<T> = T extends number
8 ? number
9 : T extends string
10 ? string
11 : T extends boolean
12 ? boolean
13 : T
14
15declare namespace math {
16 type MathNumericType = number | BigNumber | Fraction | Complex
17 type MathArray = MathNumericType[] | MathNumericType[][]
18 type MathCollection = MathArray | Matrix
19 type MathType = MathNumericType | Unit | MathCollection
20 type MathExpression = string | string[] | MathCollection
21
22 // eslint-disable-next-line @typescript-eslint/no-explicit-any
23 type FactoryFunction<T> = (scope: any) => T
24
25 // FactoryFunctionMap can be nested; all nested objects will be flattened
26 interface FactoryFunctionMap {
27 // eslint-disable-next-line @typescript-eslint/no-explicit-any
28 [key: string]: FactoryFunction<any> | FactoryFunctionMap
29 }
30
31 /** Available options for parse */
32 interface ParseOptions {
33 /** a set of custom nodes */
34 nodes?: Record<string, MathNode>
35 }
36 /**
37 * Parse an expression. Returns a node tree, which can be evaluated by
38 * invoking node.evaluate().
39 *
40 * Note the evaluating arbitrary expressions may involve security risks,
41 * see [https://mathjs.org/docs/expressions/security.html](https://mathjs.org/docs/expressions/security.html) for more information.
42 *
43 * Syntax:
44 *
45 * math.parse(expr)
46 * math.parse(expr, options)
47 * math.parse([expr1, expr2, expr3, ...])
48 * math.parse([expr1, expr2, expr3, ...], options)
49 *
50 * Example:
51 *
52 * const node1 = math.parse('sqrt(3^2 + 4^2)')
53 * node1.compile().evaluate() // 5
54 *
55 * let scope = {a:3, b:4}
56 * const node2 = math.parse('a * b') // 12
57 * const code2 = node2.compile()
58 * code2.evaluate(scope) // 12
59 * scope.a = 5
60 * code2.evaluate(scope) // 20
61 *
62 * const nodes = math.parse(['a = 3', 'b = 4', 'a * b'])
63 * nodes[2].compile().evaluate() // 12
64 *
65 * See also:
66 *
67 * evaluate, compile
68 */
69 interface ParseFunction {
70 /**
71 * Parse an expression. Returns a node tree, which can be evaluated by
72 * invoking node.evaluate();
73 *
74 * @param expr Expression to be parsed
75 * @param options Available options
76 * @returns A node
77 */
78 (expr: MathExpression, options?: ParseOptions): MathNode
79
80 /**
81 * Parse an expression. Returns a node tree, which can be evaluated by
82 * invoking node.evaluate();
83 *
84 * @param exprs Expressions to be parsed
85 * @param options Available options
86 * @returns An array of nodes
87 */
88 (exprs: MathExpression[], options?: ParseOptions): MathNode[]
89
90 /**
91 * Checks whether the current character `c` is a valid alpha character:
92 *
93 * - A latin letter (upper or lower case) Ascii: a-z, A-Z
94 * - An underscore Ascii: _
95 * - A dollar sign Ascii: $
96 * - A latin letter with accents Unicode: \u00C0 - \u02AF
97 * - A greek letter Unicode: \u0370 - \u03FF
98 * - A mathematical alphanumeric symbol Unicode: \u{1D400} - \u{1D7FF} excluding invalid code points
99 *
100 * The previous and next characters are needed to determine whether
101 * this character is part of a unicode surrogate pair.
102 *
103 * @param c Current character in the expression
104 * @param cPrev Previous character
105 * @param cNext Next character
106 */
107 isAlpha(c: string, cPrev: string, cNext: string): boolean
108 /**
109 * Test whether a character is a valid latin, greek, or letter-like character
110 *
111 * @param c
112 */
113 isValidLatinOrGreek(c: string): boolean
114 /**
115 * Test whether two given 16 bit characters form a surrogate pair of a
116 * unicode math symbol.
117 *
118 * https://unicode-table.com/en/
119 * https://www.wikiwand.com/en/Mathematical_operators_and_symbols_in_Unicode
120 *
121 * Note: In ES6 will be unicode aware:
122 * https://stackoverflow.com/questions/280712/javascript-unicode-regexes
123 * https://mathiasbynens.be/notes/es6-unicode-regex
124 *
125 * @param high
126 * @param low
127 */
128 isValidMathSymbol(high: string, low: string): boolean
129 /**
130 * Check whether given character c is a white space character: space, tab, or enter
131 *
132 * @param c
133 * @param nestingLevel
134 */
135 isWhitespace(c: string, nestingLevel: number): boolean
136 /**
137 * Test whether the character c is a decimal mark (dot).
138 * This is the case when it's not the start of a delimiter '.*', './', or '.^'
139 *
140 * @param c
141 * @param cNext
142 */
143 isDecimalMark(c: string, cNext: string): boolean
144 /**
145 * checks if the given char c is a digit or dot
146 *
147 * @param c a string with one character
148 */
149 isDigitDot(c: string): boolean
150 /**
151 * checks if the given char c is a digit
152 *
153 * @param c a string with one character
154 */
155 isDigit(c: string): boolean
156 /**
157 * checks if the given char c is a hex digit
158 *
159 * @param c a string with one character
160 */
161 isHexDigit(c: string): boolean
162 }
163
164 interface AccessorNode extends MathNodeCommon {
165 type: 'AccessorNode'
166 isAccessorNode: true
167 object: MathNode
168 index: IndexNode
169 name: string
170 }
171 interface AccessorNodeCtor {
172 new (object: MathNode, index: IndexNode): AccessorNode
173 }
174
175 interface ArrayNode extends MathNodeCommon {
176 type: 'ArrayNode'
177 isArrayNode: true
178 items: MathNode[]
179 }
180 interface ArrayNodeCtor {
181 new (items: MathNode[]): ArrayNode
182 }
183
184 interface AssignmentNode extends MathNodeCommon {
185 type: 'AssignmentNode'
186 isAssignmentNode: true
187 object: SymbolNode | AccessorNode
188 index: IndexNode | null
189 value: MathNode
190 name: string
191 }
192 interface AssignmentNodeCtor {
193 new (object: SymbolNode, value: MathNode): AssignmentNode
194 new (
195 object: SymbolNode | AccessorNode,
196 index: IndexNode,
197 value: MathNode
198 ): AssignmentNode
199 }
200
201 interface BlockNode extends MathNodeCommon {
202 type: 'BlockNode'
203 isBlockNode: true
204 blocks: Array<{ node: MathNode; visible: boolean }>
205 }
206 interface BlockNodeCtor {
207 new (
208 arr: Array<{ node: MathNode } | { node: MathNode; visible: boolean }>
209 ): BlockNode
210 }
211
212 interface ConditionalNode extends MathNodeCommon {
213 type: 'ConditionalNode'
214 isConditionalNode: boolean
215 condition: MathNode
216 trueExpr: MathNode
217 falseExpr: MathNode
218 }
219 interface ConditionalNodeCtor {
220 new (
221 condition: MathNode,
222 trueExpr: MathNode,
223 falseExpr: MathNode
224 ): ConditionalNode
225 }
226
227 interface ConstantNode extends MathNodeCommon {
228 type: 'ConstantNode'
229 isConstantNode: true
230 // eslint-disable-next-line @typescript-eslint/no-explicit-any
231 value: any
232 }
233
234 interface ConstantNodeCtor {
235 new (constant: number): ConstantNode
236 }
237
238 interface FunctionAssignmentNode extends MathNodeCommon {
239 type: 'FunctionAssignmentNode'
240 isFunctionAssignmentNode: true
241 name: string
242 params: string[]
243 expr: MathNode
244 }
245 interface FunctionAssignmentNodeCtor {
246 new (name: string, params: string[], expr: MathNode): FunctionAssignmentNode
247 }
248
249 interface FunctionNode extends MathNodeCommon {
250 type: 'FunctionNode'
251 isFunctionNode: true
252 fn: SymbolNode
253 args: MathNode[]
254 }
255 interface FunctionNodeCtor {
256 new (fn: MathNode | string, args: MathNode[]): FunctionNode
257 }
258
259 interface IndexNode extends MathNodeCommon {
260 type: 'IndexNode'
261 isIndexNode: true
262 dimensions: MathNode[]
263 dotNotation: boolean
264 }
265 interface IndexNodeCtor {
266 new (dimensions: MathNode[]): IndexNode
267 new (dimensions: MathNode[], dotNotation: boolean): IndexNode
268 }
269
270 interface ObjectNode extends MathNodeCommon {
271 type: 'ObjectNode'
272 isObjectNode: true
273 properties: Record<string, MathNode>
274 }
275 interface ObjectNodeCtor {
276 new (properties: Record<string, MathNode>): ObjectNode
277 }
278
279 type OperatorNodeMap = {
280 xor: 'xor'
281 and: 'and'
282 bitOr: '|'
283 bitXor: '^|'
284 bitAnd: '&'
285 equal: '=='
286 unequal: '!='
287 smaller: '<'
288 larger: '>'
289 smallerEq: '<='
290 leftShift: '<<'
291 rightArithShift: '>>'
292 rightLogShift: '>>>'
293 to: 'to'
294 add: '+'
295 subtract: '-'
296 multiply: '*'
297 divide: '/'
298 dotMultiply: '.*'
299 dotDivide: './'
300 mod: 'mod'
301 unaryPlus: '+'
302 unaryMinus: '-'
303 bitNot: '~'
304 not: 'not'
305 pow: '^'
306 dotPow: '.^'
307 factorial: '!'
308 }
309
310 type OperatorNodeOp = OperatorNodeMap[keyof OperatorNodeMap]
311 type OperatorNodeFn = keyof OperatorNodeMap
312
313 interface OperatorNode<
314 TOp extends OperatorNodeMap[TFn] = never,
315 TFn extends OperatorNodeFn = never,
316 TArgs extends MathNode[] = MathNode[]
317 > extends MathNodeCommon {
318 type: 'OperatorNode'
319 isOperatorNode: true
320 op: TOp
321 fn: TFn
322 args: TArgs
323 implicit: boolean
324 isUnary(): boolean
325 isBinary(): boolean
326 }
327
328 interface OperatorNodeCtor extends MathNodeCommon {
329 new <
330 TOp extends OperatorNodeMap[TFn],
331 TFn extends OperatorNodeFn,
332 TArgs extends MathNode[]
333 >(
334 op: TOp,
335 fn: TFn,
336 args: TArgs,
337 implicit?: boolean
338 ): OperatorNode<TOp, TFn, TArgs>
339 }
340 interface ParenthesisNode extends MathNodeCommon {
341 type: 'ParenthesisNode'
342 isParenthesisNode: true
343 content: MathNode
344 }
345 interface ParenthesisNodeCtor {
346 new (content: MathNode): ParenthesisNode
347 }
348
349 interface RangeNode extends MathNodeCommon {
350 type: 'RangeNode'
351 isRangeNode: true
352 start: MathNode
353 end: MathNode
354 step: MathNode | null
355 }
356 interface RangeNodeCtor {
357 new (start: MathNode, end: MathNode, step?: MathNode): RangeNode
358 }
359
360 interface RelationalNode extends MathNodeCommon {
361 type: 'RelationalNode'
362 isRelationalNode: true
363 conditionals: string[]
364 params: MathNode[]
365 }
366 interface RelationalNodeCtor {
367 new (conditionals: string[], params: MathNode[]): RelationalNode
368 }
369
370 interface SymbolNode extends MathNodeCommon {
371 type: 'SymbolNode'
372 isSymbolNode: true
373 name: string
374 }
375 interface SymbolNodeCtor {
376 new (name: string): SymbolNode
377 }
378
379 type MathNode =
380 | AccessorNode
381 | ArrayNode
382 | AssignmentNode
383 | BlockNode
384 | ConditionalNode
385 | ConstantNode
386 | FunctionAssignmentNode
387 | FunctionNode
388 | IndexNode
389 | ObjectNode
390 | OperatorNode<OperatorNodeOp, OperatorNodeFn>
391 | ParenthesisNode
392 | RangeNode
393 | RelationalNode
394 | SymbolNode
395
396 type MathJsFunctionName = keyof MathJsStatic
397
398 interface LUDecomposition {
399 L: MathCollection
400 U: MathCollection
401 p: number[]
402 }
403
404 interface SLUDecomposition extends LUDecomposition {
405 q: number[]
406 }
407
408 interface QRDecomposition {
409 Q: MathCollection
410 R: MathCollection
411 }
412
413 interface FractionDefinition {
414 a: number
415 b: number
416 }
417
418 interface MathJsStatic extends FactoryDependencies {
419 e: number
420 pi: number
421 i: number
422 Infinity: number
423 LN2: number
424 LN10: number
425 LOG2E: number
426 LOG10E: number
427 NaN: number
428 phi: number
429 SQRT1_2: number
430 SQRT2: number
431 tau: number
432
433 // Class-like constructors
434 AccessorNode: AccessorNodeCtor
435 ArrayNode: ArrayNodeCtor
436 AssignmentNode: AssignmentNodeCtor
437 BlockNode: BlockNodeCtor
438 ConditionalNode: ConditionalNodeCtor
439 ConstantNode: ConstantNodeCtor
440 FunctionAssignmentNode: FunctionAssignmentNodeCtor
441 FunctionNode: FunctionNodeCtor
442 IndexNode: IndexNodeCtor
443 ObjectNode: ObjectNodeCtor
444 OperatorNode: OperatorNodeCtor
445 ParenthesisNode: ParenthesisNodeCtor
446 RangeNode: RangeNodeCtor
447 RelationalNode: RelationalNodeCtor
448 SymbolNode: SymbolNodeCtor
449
450 Matrix: MatrixCtor
451
452 /**
453 * If null were to be included in this interface, it would be
454 * auto-suggested as an import in VSCode. This causes issues because
455 * `null` is not a valid label.
456 *
457 * @see https://github.com/josdejong/mathjs/issues/2019
458 */
459 // null: number;
460
461 // eslint-disable-next-line @typescript-eslint/no-explicit-any
462 uninitialized: any
463 version: string
464
465 expression: MathNode
466
467 /**
468 * Returns reviver function that can be used as reviver in JSON.parse function.
469 */
470 // eslint-disable-next-line @typescript-eslint/no-explicit-any
471 reviver(): (key: any, value: any) => any
472
473 /*************************************************************************
474 * Core functions
475 ************************************************************************/
476
477 /**
478 * Set configuration options for math.js, and get current options. Will
479 * emit a ‘config’ event, with arguments (curr, prev, changes).
480 * @param options Available options: {number} epsilon Minimum relative
481 * difference between two compared values, used by all comparison
482 * functions. {string} matrix A string ‘Matrix’ (default) or ‘Array’.
483 * {string} number A string ‘number’ (default), ‘BigNumber’, or
484 * ‘Fraction’ {number} precision The number of significant digits for
485 * BigNumbers. Not applicable for Numbers. {string} parenthesis How to
486 * display parentheses in LaTeX and string output. {string} randomSeed
487 * Random seed for seeded pseudo random number generator. Set to null to
488 * randomly seed.
489 * @returns Returns the current configuration
490 */
491 config: (options: ConfigOptions) => ConfigOptions
492 /**
493 * Create a typed-function which checks the types of the arguments and
494 * can match them against multiple provided signatures. The
495 * typed-function automatically converts inputs in order to find a
496 * matching signature. Typed functions throw informative errors in case
497 * of wrong input arguments.
498 * @param name Optional name for the typed-function
499 * @param signatures Object with one or multiple function signatures
500 * @returns The created typed-function.
501 */
502 typed: (
503 name: string,
504 // eslint-disable-next-line @typescript-eslint/no-explicit-any
505 signatures: Record<string, (...args: any[]) => any>
506 // eslint-disable-next-line @typescript-eslint/no-explicit-any
507 ) => (...args: any[]) => any
508
509 /*************************************************************************
510 * Construction functions
511 ************************************************************************/
512
513 /**
514 * Create a BigNumber, which can store numbers with arbitrary precision.
515 * When a matrix is provided, all elements will be converted to
516 * BigNumber.
517 * @param x Value for the big number, 0 by default.
518 * @returns The created bignumber
519 */
520 bignumber(
521 x?: number | string | Fraction | BigNumber | boolean | Fraction | null
522 ): BigNumber
523 bignumber<T extends MathCollection>(x: T): T
524
525 /**
526 * Create a boolean or convert a string or number to a boolean. In case
527 * of a number, true is returned for non-zero numbers, and false in case
528 * of zero. Strings can be 'true' or 'false', or can contain a number.
529 * When value is a matrix, all elements will be converted to boolean.
530 * @param x A value of any type
531 * @returns The boolean value
532 */
533 boolean(x: string | number | boolean | null): boolean
534 boolean(x: MathCollection): MathCollection
535
536 /**
537 * Wrap any value in a chain, allowing to perform chained operations on
538 * the value. All methods available in the math.js library can be called
539 * upon the chain, and then will be evaluated with the value itself as
540 * first argument. The chain can be closed by executing chain.done(),
541 * which returns the final value. The chain has a number of special
542 * functions: done() Finalize the chain and return the chain's value.
543 * valueOf() The same as done() toString() Executes math.format() onto
544 * the chain's value, returning a string representation of the value.
545 * @param value A value of any type on which to start a chained
546 * operation.
547 * @returns The created chain
548 */
549 // eslint-disable-next-line @typescript-eslint/no-explicit-any
550 chain<TValue>(value?: TValue): MathJsChain<TValue>
551
552 /**
553 * Create a complex value or convert a value to a complex value.
554 * @param args Arguments specifying the real and imaginary part of the
555 * complex number
556 * @returns Returns a complex value
557 */
558 complex(arg?: Complex | string | PolarCoordinates): Complex
559 complex(arg?: MathCollection): MathCollection
560 /**
561 * @param re Argument specifying the real part of the complex number
562 * @param im Argument specifying the imaginary part of the complex
563 * number
564 * @returns Returns a complex value
565 */
566 complex(re: number, im: number): Complex
567
568 /**
569 * Create a user-defined unit and register it with the Unit type.
570 * @param name The name of the new unit. Must be unique. Example: ‘knot’
571 * @param definition Definition of the unit in terms of existing units.
572 * For example, ‘0.514444444 m / s’.
573 * @param options (optional) An object containing any of the following
574 * properties:</br>- prefixes {string} “none”, “short”, “long”,
575 * “binary_short”, or “binary_long”. The default is “none”.</br>-
576 * aliases {Array} Array of strings. Example: [‘knots’, ‘kt’,
577 * ‘kts’]</br>- offset {Numeric} An offset to apply when converting from
578 * the unit. For example, the offset for celsius is 273.15. Default is
579 * 0.
580 * @returns The new unit
581 */
582 createUnit(
583 name: string,
584 definition?: string | UnitDefinition,
585 options?: CreateUnitOptions
586 ): Unit
587 /**
588 * Create a user-defined unit and register it with the Unit type.
589 * @param units Definition of the unit
590 * @param options
591 * @returns The new unit
592 */
593 createUnit(
594 units: Record<string, string | UnitDefinition>,
595 options?: CreateUnitOptions
596 ): Unit
597
598 /**
599 * Create a fraction convert a value to a fraction.
600 * @param args Arguments specifying the numerator and denominator of the
601 * fraction
602 * @returns Returns a fraction
603 */
604 fraction(
605 value: number | string | BigNumber | Fraction | FractionDefinition
606 ): Fraction
607 fraction(values: MathCollection): MathCollection
608 /**
609 * @param numerator Argument specifying the numerator of the fraction
610 * @param denominator Argument specifying the denominator of the
611 * fraction
612 * @returns Returns a fraction
613 */
614 fraction(numerator: number, denominator: number): Fraction
615
616 /**
617 * Create an index. An Index can store ranges having start, step, and
618 * end for multiple dimensions. Matrix.get, Matrix.set, and math.subset
619 * accept an Index as input.
620 * @param ranges Zero or more ranges or numbers.
621 * @returns Returns the created index
622 */
623 // eslint-disable-next-line @typescript-eslint/no-explicit-any
624 index(...ranges: any[]): Index
625
626 /**
627 * Create a Matrix. The function creates a new math.type.Matrix object
628 * from an Array. A Matrix has utility functions to manipulate the data
629 * in the matrix, like getting the size and getting or setting values in
630 * the matrix. Supported storage formats are 'dense' and 'sparse'.
631 * @param format The Matrix storage format
632 * @returns The created Matrix
633 */
634 matrix(format?: 'sparse' | 'dense'): Matrix
635 /**
636 * @param data A multi dimensional array
637 * @param format The Matrix storage format
638 * @param dataType The Matrix data type
639 * @returns The created Matrix
640 */
641 matrix(
642 data: MathCollection,
643 format?: 'sparse' | 'dense',
644 dataType?: string
645 ): Matrix
646
647 /**
648 * Create a number or convert a string, boolean, or unit to a number.
649 * When value is a matrix, all elements will be converted to number.
650 * @param value Value to be converted
651 * @returns The created number
652 */
653 number(
654 value?: string | number | BigNumber | Fraction | boolean | Unit | null
655 ): number
656 number(value?: MathCollection): number | MathCollection
657 /**
658 * @param value Value to be converted
659 * @param valuelessUnit A valueless unit, used to convert a unit to a
660 * number
661 * @returns The created number
662 */
663 number(unit: Unit, valuelessUnit: Unit | string): number
664
665 /**
666 * Create a Sparse Matrix. The function creates a new math.type.Matrix
667 * object from an Array. A Matrix has utility functions to manipulate
668 * the data in the matrix, like getting the size and getting or setting
669 * values in the matrix.
670 * @param data A two dimensional array
671 * @param dataType Sparse Matrix data type
672 * @returns The created matrix
673 */
674 sparse(data?: MathCollection, dataType?: string): Matrix
675
676 /**
677 * Split a unit in an array of units whose sum is equal to the original
678 * unit.
679 * @param unit A unit to be split
680 * @param parts An array of strings or valueless units
681 * @returns An array of units
682 */
683 splitUnit(unit: Unit, parts: Unit[]): Unit[]
684
685 /**
686 * Create a string or convert any object into a string. Elements of
687 * Arrays and Matrices are processed element wise.
688 * @param value A value to convert to a string
689 * @returns The created string
690 */
691 string(value: MathNumericType | string | Unit | null): string
692 string(value: MathCollection): MathCollection
693
694 /**
695 * Create a unit. Depending on the passed arguments, the function will
696 * create and return a new math.type.Unit object. When a matrix is
697 * provided, all elements will be converted to units.
698 * @param unit The unit to be created
699 * @returns The created unit
700 */
701 unit(unit: string): Unit
702 /**
703 * @param unit The unit to be created
704 * @returns The created unit
705 */
706 unit(unit: Unit): Unit
707 /**
708 * @param value The value of the unit to be created
709 * @param unit The unit to be created
710 * @returns The created unit
711 */
712 unit(value: number | BigNumber, unit: string): Unit
713 unit(value: MathCollection, unit: string): Unit[]
714
715 /*************************************************************************
716 * Expression functions
717 ************************************************************************/
718
719 /**
720 * Parse and compile an expression. Returns a an object with a function
721 * evaluate([scope]) to evaluate the compiled expression.
722 * @param expr The expression to be compiled
723 * @returns An object with the compiled expression
724 */
725 compile(expr: MathExpression): EvalFunction
726 /**
727 * @param exprs The expressions to be compiled
728 * @returns An array of objects with the compiled expressions
729 */
730 compile(exprs: MathExpression[]): EvalFunction[]
731
732 // TODO properly type this
733 /**
734 * Evaluate an expression.
735 * @param expr The expression to be evaluated
736 * @param scope Scope to read/write variables
737 * @returns The result of the expression
738 */
739 evaluate(
740 expr: MathExpression | Matrix,
741 scope?: object
742 // eslint-disable-next-line @typescript-eslint/no-explicit-any
743 ): any
744 evaluate(
745 expr: MathExpression[],
746 scope?: object
747 // eslint-disable-next-line @typescript-eslint/no-explicit-any
748 ): any[]
749
750 /**
751 * Retrieve help on a function or data type. Help files are retrieved
752 * from the documentation in math.expression.docs.
753 * @param search A function or function name for which to get help
754 * @returns A help object
755 */
756 // eslint-disable-next-line @typescript-eslint/no-explicit-any
757 help(search: () => any): Help
758
759 /**
760 * Parse an expression. Returns a node tree, which can be evaluated by
761 * invoking node.evaluate();
762 */
763 parse: ParseFunction
764
765 /**
766 * Create a parser. The function creates a new math.expression.Parser
767 * object.
768 * @returns A Parser object
769 */
770 parser(): Parser
771
772 /*************************************************************************
773 * Algebra functions
774 ************************************************************************/
775 /**
776 * @param expr The expression to differentiate
777 * @param variable The variable over which to differentiate
778 * @param options There is one option available, simplify, which is true
779 * by default. When false, output will not be simplified.
780 * @returns The derivative of expr
781 */
782 derivative(
783 expr: MathNode | string,
784 variable: MathNode | string,
785 options?: { simplify: boolean }
786 ): MathNode
787
788 /**
789 * Solves the linear equation system by forwards substitution. Matrix
790 * must be a lower triangular matrix.
791 * @param L A N x N matrix or array (L)
792 * @param b A column vector with the b values
793 * @returns A column vector with the linear system solution (x)
794 */
795 lsolve(L: Matrix, b: Matrix | MathArray): Matrix
796 lsolve(L: MathArray, b: Matrix | MathArray): MathArray
797
798 /**
799 * Calculate the Matrix LU decomposition with partial pivoting. Matrix A
800 * is decomposed in two matrices (L, U) and a row permutation vector p
801 * where A[p,:] = L * U
802 * @param A A two dimensional matrix or array for which to get the LUP
803 * decomposition.
804 * @returns The lower triangular matrix, the upper triangular matrix and
805 * the permutation matrix.
806 */
807 lup(A?: Matrix | MathArray): LUDecomposition
808
809 /**
810 * Solves the linear system A * x = b where A is an [n x n] matrix and b
811 * is a [n] column vector.
812 * @param A Invertible Matrix or the Matrix LU decomposition
813 * @param b Column Vector
814 * @param order The Symbolic Ordering and Analysis order, see slu for
815 * details. Matrix must be a SparseMatrix
816 * @param threshold Partial pivoting threshold (1 for partial pivoting),
817 * see slu for details. Matrix must be a SparseMatrix.
818 * @returns Column vector with the solution to the linear system A * x =
819 * b
820 */
821 lusolve(
822 A: Matrix,
823 b: Matrix | MathArray,
824 order?: number,
825 threshold?: number
826 ): Matrix
827
828 lusolve(
829 A: MathArray,
830 b: Matrix | MathArray,
831 order?: number,
832 threshold?: number
833 ): MathArray
834
835 /**
836 * Calculate the Matrix QR decomposition. Matrix A is decomposed in two
837 * matrices (Q, R) where Q is an orthogonal matrix and R is an upper
838 * triangular matrix.
839 * @param A A two dimensional matrix or array for which to get the QR
840 * decomposition.
841 * @returns Q: the orthogonal matrix and R: the upper triangular matrix
842 */
843 qr(A: Matrix | MathArray): QRDecomposition
844
845 rationalize(
846 expr: MathNode | string,
847 optional?: object | boolean,
848 detailed?: false
849 ): MathNode
850 /**
851 * Transform a rationalizable expression in a rational fraction. If
852 * rational fraction is one variable polynomial then converts the
853 * numerator and denominator in canonical form, with decreasing
854 * exponents, returning the coefficients of numerator.
855 * @param expr The expression to check if is a polynomial expression
856 * @param optional scope of expression or true for already evaluated
857 * rational expression at input
858 * @param detailed optional True if return an object, false if return
859 * expression node (default)
860 * @returns The rational polynomial of expr
861 */
862 rationalize(
863 expr: MathNode | string,
864 optional?: object | boolean,
865 detailed?: true
866 ): {
867 expression: MathNode | string
868 variables: string[]
869 coefficients: MathType[]
870 }
871
872 /**
873 * Simplify an expression tree.
874 * @param expr The expression to be simplified
875 * @param [rules] (optional) A list of rules are applied to an expression, repeating
876 * over the list until no further changes are made. It’s possible to
877 * pass a custom set of rules to the function as second argument. A rule
878 * can be specified as an object, string, or function.
879 * @param [scope] (optional) Scope to variables
880 * @param [options] (optional) An object with simplify options
881 * @returns Returns the simplified form of expr
882 */
883 simplify: Simplify
884
885 /**
886 * Replaces variable nodes with their scoped values
887 * @param node Tree to replace variable nodes in
888 * @param scope Scope to read/write variables
889 */
890 // eslint-disable-next-line @typescript-eslint/no-explicit-any
891 resolve(node: MathNode, scope?: Record<string, any>): MathNode
892 // eslint-disable-next-line @typescript-eslint/no-explicit-any
893 resolve(node: MathNode[], scope?: Record<string, any>): MathNode[]
894
895 /**
896 * Calculate the Sparse Matrix LU decomposition with full pivoting.
897 * Sparse Matrix A is decomposed in two matrices (L, U) and two
898 * permutation vectors (pinv, q) where P * A * Q = L * U
899 * @param A A two dimensional sparse matrix for which to get the LU
900 * decomposition.
901 * @param order The Symbolic Ordering and Analysis order: 0 - Natural
902 * ordering, no permutation vector q is returned 1 - Matrix must be
903 * square, symbolic ordering and analisis is performed on M = A + A' 2 -
904 * Symbolic ordering and analysis is performed on M = A' * A. Dense
905 * columns from A' are dropped, A recreated from A'. This is appropriate
906 * for LU factorization of non-symmetric matrices. 3 - Symbolic ordering
907 * and analysis is performed on M = A' * A. This is best used for LU
908 * factorization is matrix M has no dense rows. A dense row is a row
909 * with more than 10*sqr(columns) entries.
910 * @param threshold Partial pivoting threshold (1 for partial pivoting)
911 * @returns The lower triangular matrix, the upper triangular matrix and
912 * the permutation vectors.
913 */
914 slu(A: Matrix, order: number, threshold: number): SLUDecomposition
915
916 /**
917 * Solves the linear equation system by backward substitution. Matrix
918 * must be an upper triangular matrix. U * x = b
919 * @param U A N x N matrix or array (U)
920 * @param b A column vector with the b values
921 * @returns A column vector with the linear system solution (x)
922 */
923 usolve(U: Matrix, b: Matrix | MathArray): Matrix
924 usolve(U: MathArray, b: Matrix | MathArray): MathArray
925
926 /*************************************************************************
927 * Arithmetic functions
928 ************************************************************************/
929
930 /**
931 * Calculate the absolute value of a number. For matrices, the function
932 * is evaluated element wise.
933 * @param x A number or matrix for which to get the absolute value
934 * @returns Absolute value of x
935 */
936 abs(x: number): number
937 abs(x: BigNumber): BigNumber
938 abs(x: Fraction): Fraction
939 abs(x: Complex): Complex
940 abs(x: MathArray): MathArray
941 abs(x: Matrix): Matrix
942 abs(x: Unit): Unit
943
944 /**
945 * Add two values, x + y. For matrices, the function is evaluated
946 * element wise.
947 * @param x First value to add
948 * @param y Second value to add
949 * @returns Sum of x and y
950 */
951 add<T extends MathType>(x: T, y: T): T
952 add(x: MathType, y: MathType): MathType
953
954 /**
955 * Calculate the cubic root of a value. For matrices, the function is
956 * evaluated element wise.
957 * @param x Value for which to calculate the cubic root.
958 * @param allRoots Optional, false by default. Only applicable when x is
959 * a number or complex number. If true, all complex roots are returned,
960 * if false (default) the principal root is returned.
961 * @returns Returns the cubic root of x
962 */
963 cbrt(x: number, allRoots?: boolean): number
964 cbrt(x: BigNumber, allRoots?: boolean): BigNumber
965 cbrt(x: Complex, allRoots?: boolean): Complex
966 cbrt(x: MathArray, allRoots?: boolean): MathArray
967 cbrt(x: Matrix, allRoots?: boolean): Matrix
968
969 // Rounding functions, grouped for similarity, even though it breaks
970 // the alphabetic order among arithmetic functions.
971
972 /**
973 * Round a value towards plus infinity If x is complex, both real and
974 * imaginary part are rounded towards plus infinity. For matrices, the
975 * function is evaluated element wise.
976 * @param x Number to be rounded
977 * @param n Number of decimals Default value: 0.
978 * @returns Rounded value
979 */
980 ceil<T extends MathNumericType | MathCollection>(
981 x: T,
982 n?: number | BigNumber
983 ): NoLiteralType<T>
984 ceil<U extends MathCollection>(x: MathNumericType, n: U): U
985
986 /**
987 * Round a value towards zero. For matrices, the function is evaluated
988 * element wise.
989 * @param x Number to be rounded
990 * @param n Number of decimals Default value: 0.
991 * @returns Rounded value
992 */
993 fix<T extends MathNumericType | MathCollection>(
994 x: T,
995 n?: number | BigNumber
996 ): NoLiteralType<T>
997 fix<U extends MathCollection>(x: MathNumericType, n: U): U
998
999 /**
1000 * Round a value towards minus infinity. For matrices, the function is
1001 * evaluated element wise.
1002 * @param x Number to be rounded
1003 * @param n Number of decimals Default value: 0.
1004 * @returns Rounded value
1005 */
1006 floor<T extends MathNumericType | MathCollection>(
1007 x: T,
1008 n?: number | BigNumber
1009 ): NoLiteralType<T>
1010 floor<U extends MathCollection>(x: MathNumericType, n: U): U
1011
1012 /**
1013 * Round a value towards the nearest integer. For matrices, the function
1014 * is evaluated element wise.
1015 * @param x Number to be rounded
1016 * @param n Number of decimals Default value: 0.
1017 * @returns Rounded value of x
1018 */
1019 round<T extends MathNumericType | MathCollection>(
1020 x: T,
1021 n?: number | BigNumber
1022 ): NoLiteralType<T>
1023 round<U extends MathCollection>(x: MathNumericType, n: U): U
1024
1025 // End of group of rounding functions
1026
1027 /**
1028 * Compute the cube of a value, x * x * x. For matrices, the function is
1029 * evaluated element wise.
1030 * @param x Number for which to calculate the cube
1031 * @returns Cube of x
1032 */
1033 cube(x: number): number
1034 cube(x: BigNumber): BigNumber
1035 cube(x: Fraction): Fraction
1036 cube(x: Complex): Complex
1037 cube(x: MathArray): MathArray
1038 cube(x: Matrix): Matrix
1039 cube(x: Unit): Unit
1040
1041 /**
1042 * Divide two values, x / y. To divide matrices, x is multiplied with
1043 * the inverse of y: x * inv(y).
1044 * @param x Numerator
1045 * @param y Denominator
1046 * @returns Quotient, x / y
1047 */
1048 divide(x: Unit, y: Unit): Unit | number
1049 divide(x: Unit, y: number): Unit
1050 divide(x: number, y: number): number
1051 divide(x: MathType, y: MathType): MathType
1052
1053 /**
1054 * Divide two matrices element wise. The function accepts both matrices
1055 * and scalar values.
1056 * @param x Numerator
1057 * @param y Denominator
1058 * @returns Quotient, x ./ y
1059 */
1060 dotDivide(x: MathType, y: MathType): MathType
1061
1062 /**
1063 * Multiply two matrices element wise. The function accepts both
1064 * matrices and scalar values.
1065 * @param x Left hand value
1066 * @param y Right hand value
1067 * @returns Multiplication of x and y
1068 */
1069 dotMultiply(x: MathType, y: MathType): MathType
1070
1071 /**
1072 * Calculates the power of x to y element wise.
1073 * @param x The base
1074 * @param y The exponent
1075 * @returns The value of x to the power y
1076 */
1077 dotPow(x: MathType, y: MathType): MathType
1078
1079 /**
1080 * Calculate the exponent of a value. For matrices, the function is
1081 * evaluated element wise.
1082 * @param x A number or matrix to exponentiate
1083 * @returns Exponent of x
1084 */
1085 exp(x: number): number
1086 exp(x: BigNumber): BigNumber
1087 exp(x: Complex): Complex
1088 exp(x: MathArray): MathArray
1089 exp(x: Matrix): Matrix
1090
1091 /**
1092 * Calculate the value of subtracting 1 from the exponential value. For
1093 * matrices, the function is evaluated element wise.
1094 * @param x A number or matrix to apply expm1
1095 * @returns Exponent of x
1096 */
1097 expm1(x: number): number
1098 expm1(x: BigNumber): BigNumber
1099 expm1(x: Complex): Complex
1100 expm1(x: MathArray): MathArray
1101 expm1(x: Matrix): Matrix
1102
1103 /**
1104 * Calculate the greatest common divisor for two or more values or
1105 * arrays. For matrices, the function is evaluated element wise.
1106 * @param args Two or more integer numbers
1107 * @returns The greatest common divisor
1108 */
1109 gcd(...args: number[]): number
1110 gcd(...args: BigNumber[]): BigNumber
1111 gcd(...args: Fraction[]): Fraction
1112 gcd(...args: MathArray[]): MathArray
1113 gcd(...args: Matrix[]): Matrix
1114
1115 /**
1116 * Calculate the hypotenusa of a list with values. The hypotenusa is
1117 * defined as: hypot(a, b, c, ...) = sqrt(a^2 + b^2 + c^2 + ...) For
1118 * matrix input, the hypotenusa is calculated for all values in the
1119 * matrix.
1120 * @param args A list with numeric values or an Array or Matrix. Matrix
1121 * and Array input is flattened and returns a single number for the
1122 * whole matrix.
1123 * @returns Returns the hypothenuse of the input values.
1124 */
1125 hypot(...args: number[]): number
1126 hypot(...args: BigNumber[]): BigNumber
1127
1128 /**
1129 * Calculate the least common multiple for two or more values or arrays.
1130 * lcm is defined as: lcm(a, b) = abs(a * b) / gcd(a, b) For matrices,
1131 * the function is evaluated element wise.
1132 * @param a An integer number
1133 * @param b An integer number
1134 * @returns The least common multiple
1135 */
1136 lcm(a: number, b: number): number
1137 lcm(a: BigNumber, b: BigNumber): BigNumber
1138 lcm(a: MathArray, b: MathArray): MathArray
1139 lcm(a: Matrix, b: Matrix): Matrix
1140
1141 /**
1142 * Calculate the logarithm of a value. For matrices, the function is
1143 * evaluated element wise.
1144 * @param x Value for which to calculate the logarithm.
1145 * @param base Optional base for the logarithm. If not provided, the
1146 * natural logarithm of x is calculated. Default value: e.
1147 * @returns Returns the logarithm of x
1148 */
1149 log<T extends number | BigNumber | Complex | MathCollection>(
1150 x: T,
1151 base?: number | BigNumber | Complex
1152 ): NoLiteralType<T>
1153
1154 /**
1155 * Calculate the 10-base of a value. This is the same as calculating
1156 * log(x, 10). For matrices, the function is evaluated element wise.
1157 * @param x Value for which to calculate the logarithm.
1158 * @returns Returns the 10-base logarithm of x
1159 */
1160 log10(x: number): number
1161 log10(x: BigNumber): BigNumber
1162 log10(x: Complex): Complex
1163 log10(x: MathArray): MathArray
1164 log10(x: Matrix): Matrix
1165
1166 /**
1167 * Calculate the logarithm of a value+1. For matrices, the function is
1168 * evaluated element wise.
1169 * @param x Value for which to calculate the logarithm.
1170 * @returns Returns the logarithm of x+1
1171 */
1172 log1p(x: number, base?: number | BigNumber | Complex): number
1173 log1p(x: BigNumber, base?: number | BigNumber | Complex): BigNumber
1174 log1p(x: Complex, base?: number | BigNumber | Complex): Complex
1175 log1p(x: MathArray, base?: number | BigNumber | Complex): MathArray
1176 log1p(x: Matrix, base?: number | BigNumber | Complex): Matrix
1177
1178 /**
1179 * Calculate the 2-base of a value. This is the same as calculating
1180 * log(x, 2). For matrices, the function is evaluated element wise.
1181 * @param x Value for which to calculate the logarithm.
1182 * @returns Returns the 2-base logarithm of x
1183 */
1184 log2(x: number): number
1185 log2(x: BigNumber): BigNumber
1186 log2(x: Complex): Complex
1187 log2(x: MathArray): MathArray
1188 log2(x: Matrix): Matrix
1189
1190 /**
1191 * Calculates the modulus, the remainder of an integer division. For
1192 * matrices, the function is evaluated element wise. The modulus is
1193 * defined as: x - y * floor(x / y)
1194 * @see http://en.wikipedia.org/wiki/Modulo_operation.
1195 * @param x Dividend
1196 * @param y Divisor
1197 * @returns Returns the remainder of x divided by y
1198 */
1199 mod<T extends number | BigNumber | Fraction | MathCollection>(
1200 x: T,
1201 y: number | BigNumber | Fraction | MathCollection
1202 ): NoLiteralType<T>
1203
1204 /**
1205 * Multiply two values, x * y. The result is squeezed. For matrices, the
1206 * matrix product is calculated.
1207 * @param x The first value to multiply
1208 * @param y The second value to multiply
1209 * @returns Multiplication of x and y
1210 */
1211 multiply<T extends Matrix | MathArray>(x: T, y: MathType): T
1212 multiply(x: Unit, y: Unit): Unit
1213 multiply(x: number, y: number): number
1214 multiply(x: MathType, y: MathType): MathType
1215
1216 /**
1217 * Calculate the norm of a number, vector or matrix. The second
1218 * parameter p is optional. If not provided, it defaults to 2.
1219 * @param x Value for which to calculate the norm
1220 * @param p Vector space. Supported numbers include Infinity and
1221 * -Infinity. Supported strings are: 'inf', '-inf', and 'fro' (The
1222 * Frobenius norm) Default value: 2.
1223 * @returns the p-norm
1224 */
1225 norm(
1226 x: number | BigNumber | Complex | MathCollection,
1227 p?: number | BigNumber | string
1228 ): number | BigNumber
1229
1230 /**
1231 * Calculate the nth root of a value. The principal nth root of a
1232 * positive real number A, is the positive real solution of the equation
1233 * x^root = A For matrices, the function is evaluated element wise.
1234 * @param a Value for which to calculate the nth root
1235 * @param root The root. Default value: 2.
1236 * @return The nth root of a
1237 */
1238 nthRoot(
1239 a: number | BigNumber | MathCollection | Complex,
1240 root?: number | BigNumber
1241 ): number | Complex | MathCollection
1242
1243 /**
1244 * Calculates the power of x to y, x ^ y. Matrix exponentiation is
1245 * supported for square matrices x, and positive integer exponents y.
1246 * @param x The base
1247 * @param y The exponent
1248 * @returns x to the power y
1249 */
1250 pow(x: MathType, y: number | BigNumber | Complex): MathType
1251
1252 /**
1253 * Compute the sign of a value. The sign of a value x is: 1 when x > 1
1254 * -1 when x < 0 0 when x == 0 For matrices, the function is evaluated
1255 * element wise.
1256 * @param x The number for which to determine the sign
1257 * @returns The sign of x
1258 */
1259 sign(x: number): number
1260 sign(x: BigNumber): BigNumber
1261 sign(x: Fraction): Fraction
1262 sign(x: Complex): Complex
1263 sign(x: MathArray): MathArray
1264 sign(x: Matrix): Matrix
1265 sign(x: Unit): Unit
1266
1267 /**
1268 * Calculate the square root of a value. For matrices, the function is
1269 * evaluated element wise.
1270 * @param x Value for which to calculate the square root
1271 * @returns Returns the square root of x
1272 */
1273 sqrt(x: number): number
1274 sqrt(x: BigNumber): BigNumber
1275 sqrt(x: Complex): Complex
1276 sqrt(x: MathArray): MathArray
1277 sqrt(x: Matrix): Matrix
1278 sqrt(x: Unit): Unit
1279
1280 /**
1281 * Compute the square of a value, x * x. For matrices, the function is
1282 * evaluated element wise.
1283 * @param x Number for which to calculate the square
1284 * @returns Squared value
1285 */
1286 square(x: number): number
1287 square(x: BigNumber): BigNumber
1288 square(x: Fraction): Fraction
1289 square(x: Complex): Complex
1290 square(x: MathArray): MathArray
1291 square(x: Matrix): Matrix
1292 square(x: Unit): Unit
1293
1294 /**
1295 * Subtract two values, x - y. For matrices, the function is evaluated
1296 * element wise.
1297 * @param x Initial value
1298 * @param y Value to subtract from x
1299 * @returns Subtraction of x and y
1300 */
1301 subtract<T extends MathType>(x: T, y: T): T
1302 subtract(x: MathType, y: MathType): MathType
1303
1304 /**
1305 * Inverse the sign of a value, apply a unary minus operation. For
1306 * matrices, the function is evaluated element wise. Boolean values and
1307 * strings will be converted to a number. For complex numbers, both real
1308 * and complex value are inverted.
1309 * @param x Number to be inverted
1310 * @returns Retursn the value with inverted sign
1311 */
1312 unaryMinus(x: number): number
1313 unaryMinus(x: BigNumber): BigNumber
1314 unaryMinus(x: Fraction): Fraction
1315 unaryMinus(x: Complex): Complex
1316 unaryMinus(x: MathArray): MathArray
1317 unaryMinus(x: Matrix): Matrix
1318 unaryMinus(x: Unit): Unit
1319
1320 /**
1321 * Unary plus operation. Boolean values and strings will be converted to
1322 * a number, numeric values will be returned as is. For matrices, the
1323 * function is evaluated element wise.
1324 * @param x Input value
1325 * @returns Returns the input value when numeric, converts to a number
1326 * when input is non-numeric.
1327 */
1328 unaryPlus(x: number): number
1329 unaryPlus(x: BigNumber): BigNumber
1330 unaryPlus(x: Fraction): Fraction
1331 unaryPlus(x: string): string
1332 unaryPlus(x: Complex): Complex
1333 unaryPlus(x: MathArray): MathArray
1334 unaryPlus(x: Matrix): Matrix
1335 unaryPlus(x: Unit): Unit
1336
1337 /**
1338 * Calculate the extended greatest common divisor for two values. See
1339 * http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm.
1340 * @param a An integer number
1341 * @param b An integer number
1342 * @returns Returns an array containing 3 integers [div, m, n] where div
1343 * = gcd(a, b) and a*m + b*n = div
1344 */
1345 xgcd(a: number | BigNumber, b: number | BigNumber): MathArray
1346
1347 /*************************************************************************
1348 * Bitwise functions
1349 ************************************************************************/
1350
1351 /**
1352 * Bitwise AND two values, x & y. For matrices, the function is
1353 * evaluated element wise.
1354 * @param x First value to and
1355 * @param y Second value to and
1356 * @returns AND of x and y
1357 */
1358 bitAnd<T extends number | BigNumber | MathCollection>(
1359 x: T,
1360 y: number | BigNumber | MathCollection
1361 ): NoLiteralType<T>
1362
1363 /**
1364 * Bitwise NOT value, ~x. For matrices, the function is evaluated
1365 * element wise. For units, the function is evaluated on the best prefix
1366 * base.
1367 * @param x Value to not
1368 * @returns NOT of x
1369 */
1370 bitNot(x: number): number
1371 bitNot(x: BigNumber): BigNumber
1372 bitNot(x: MathArray): MathArray
1373 bitNot(x: Matrix): Matrix
1374
1375 /**
1376 * Bitwise OR two values, x | y. For matrices, the function is evaluated
1377 * element wise. For units, the function is evaluated on the lowest
1378 * print base.
1379 * @param x First value to or
1380 * @param y Second value to or
1381 * @returns OR of x and y
1382 */
1383 bitOr(x: number, y: number): number
1384 bitOr(x: BigNumber, y: BigNumber): BigNumber
1385 bitOr(x: MathArray, y: MathArray): MathArray
1386 bitOr(x: Matrix, y: Matrix): Matrix
1387
1388 /**
1389 * Bitwise XOR two values, x ^ y. For matrices, the function is
1390 * evaluated element wise.
1391 * @param x First value to xor
1392 * @param y Second value to xor
1393 * @returns XOR of x and y
1394 */
1395 bitXor<T extends number | BigNumber | MathCollection>(
1396 x: T,
1397 y: number | BigNumber | MathCollection
1398 ): NoLiteralType<T>
1399
1400 /**
1401 * Bitwise left logical shift of a value x by y number of bits, x << y.
1402 * For matrices, the function is evaluated element wise. For units, the
1403 * function is evaluated on the best prefix base.
1404 * @param x Value to be shifted
1405 * @param y Amount of shifts
1406 * @returns x shifted left y times
1407 */
1408 leftShift<T extends number | BigNumber | MathCollection>(
1409 x: T,
1410 y: number | BigNumber
1411 ): NoLiteralType<T>
1412
1413 /**
1414 * Bitwise right arithmetic shift of a value x by y number of bits, x >>
1415 * y. For matrices, the function is evaluated element wise. For units,
1416 * the function is evaluated on the best prefix base.
1417 * @param x Value to be shifted
1418 * @param y Amount of shifts
1419 * @returns x sign-filled shifted right y times
1420 */
1421 rightArithShift<T extends number | BigNumber | MathCollection>(
1422 x: T,
1423 y: number | BigNumber
1424 ): NoLiteralType<T>
1425
1426 /**
1427 * Bitwise right logical shift of value x by y number of bits, x >>> y.
1428 * For matrices, the function is evaluated element wise. For units, the
1429 * function is evaluated on the best prefix base.
1430 * @param x Value to be shifted
1431 * @param y Amount of shifts
1432 * @returns x zero-filled shifted right y times
1433 */
1434 rightLogShift<T extends number | MathCollection>(
1435 x: T,
1436 y: number
1437 ): NoLiteralType<T>
1438
1439 /*************************************************************************
1440 * Combinatorics functions
1441 ************************************************************************/
1442
1443 /**
1444 * The Bell Numbers count the number of partitions of a set. A partition
1445 * is a pairwise disjoint subset of S whose union is S. bellNumbers only
1446 * takes integer arguments. The following condition must be enforced: n
1447 * >= 0
1448 * @param n Total number of objects in the set
1449 * @returns B(n)
1450 */
1451 bellNumbers(n: number): number
1452 bellNumbers(n: BigNumber): BigNumber
1453
1454 /**
1455 * The Catalan Numbers enumerate combinatorial structures of many
1456 * different types. catalan only takes integer arguments. The following
1457 * condition must be enforced: n >= 0
1458 * @param n nth Catalan number
1459 * @returns Cn(n)
1460 */
1461 catalan(n: number): number
1462 catalan(n: BigNumber): BigNumber
1463
1464 /**
1465 * The composition counts of n into k parts. Composition only takes
1466 * integer arguments. The following condition must be enforced: k <= n.
1467 * @param n Total number of objects in the set
1468 * @param k Number of objects in the subset
1469 * @returns Returns the composition counts of n into k parts.
1470 */
1471 composition<T extends number | BigNumber>(
1472 n: T,
1473 k: number | BigNumber
1474 ): NoLiteralType<T>
1475
1476 /**
1477 * The Stirling numbers of the second kind, counts the number of ways to
1478 * partition a set of n labelled objects into k nonempty unlabelled
1479 * subsets. stirlingS2 only takes integer arguments. The following
1480 * condition must be enforced: k <= n. If n = k or k = 1, then s(n,k) =
1481 * 1
1482 * @param n Total number of objects in the set
1483 * @param k Number of objects in the subset
1484 * @returns S(n,k)
1485 */
1486 stirlingS2<T extends number | BigNumber>(
1487 n: T,
1488 k: number | BigNumber
1489 ): NoLiteralType<T>
1490
1491 /*************************************************************************
1492 * Complex functions
1493 ************************************************************************/
1494
1495 /**
1496 * Compute the argument of a complex value. For a complex number a + bi,
1497 * the argument is computed as atan2(b, a). For matrices, the function
1498 * is evaluated element wise.
1499 * @param x A complex number or array with complex numbers
1500 * @returns The argument of x
1501 */
1502 arg(x: number | Complex): number
1503 arg(x: BigNumber | Complex): BigNumber
1504 arg(x: MathArray): MathArray
1505 arg(x: Matrix): Matrix
1506
1507 /**
1508 * Compute the complex conjugate of a complex value. If x = a+bi, the
1509 * complex conjugate of x is a - bi. For matrices, the function is
1510 * evaluated element wise.
1511 * @param x A complex number or array with complex numbers
1512 * @returns The complex conjugate of x
1513 */
1514 conj<T extends number | BigNumber | Complex | MathCollection>(
1515 x: T
1516 ): NoLiteralType<T>
1517
1518 /**
1519 * Get the imaginary part of a complex number. For a complex number a +
1520 * bi, the function returns b. For matrices, the function is evaluated
1521 * element wise.
1522 * @param x A complex number or array with complex numbers
1523 * @returns The imaginary part of x
1524 */
1525 im(x: MathJsChain<number | Complex>): MathJsChain<number>
1526 im(x: MathJsChain<BigNumber>): MathJsChain<BigNumber>
1527 im(x: MathJsChain<MathCollection>): MathJsChain<MathCollection>
1528
1529 /**
1530 * Get the real part of a complex number. For a complex number a + bi,
1531 * the function returns a. For matrices, the function is evaluated
1532 * element wise.
1533 * @param x A complex number or array of complex numbers
1534 * @returns The real part of x
1535 */
1536 re(x: MathJsChain<number | Complex>): MathJsChain<number>
1537 re(x: MathJsChain<BigNumber>): MathJsChain<BigNumber>
1538 re(x: MathJsChain<MathCollection>): MathJsChain<MathCollection>
1539
1540 /*************************************************************************
1541 * Geometry functions
1542 ************************************************************************/
1543
1544 /**
1545 * Calculates: The eucledian distance between two points in 2 and 3
1546 * dimensional spaces. Distance between point and a line in 2 and 3
1547 * dimensional spaces. Pairwise distance between a set of 2D or 3D
1548 * points NOTE: When substituting coefficients of a line(a, b and c),
1549 * use ax + by + c = 0 instead of ax + by = c For parametric equation of
1550 * a 3D line, x0, y0, z0, a, b, c are from: (x−x0, y−y0, z−z0) = t(a, b,
1551 * c)
1552 * @param x Coordinates of the first point
1553 * @param y Coordinates of the second point
1554 * @returns Returns the distance from two/three points
1555 */
1556 distance(
1557 x: MathCollection | object,
1558 y: MathCollection | object
1559 ): number | BigNumber
1560
1561 /**
1562 * Calculates the point of intersection of two lines in two or three
1563 * dimensions and of a line and a plane in three dimensions. The inputs
1564 * are in the form of arrays or 1 dimensional matrices. The line
1565 * intersection functions return null if the lines do not meet. Note:
1566 * Fill the plane coefficients as x + y + z = c and not as x + y + z + c
1567 * = 0.
1568 * @param w Co-ordinates of first end-point of first line
1569 * @param x Co-ordinates of second end-point of first line
1570 * @param y Co-ordinates of first end-point of second line OR
1571 * Coefficients of the plane's equation
1572 * @param z Co-ordinates of second end-point of second line OR null if
1573 * the calculation is for line and plane
1574 * @returns Returns the point of intersection of lines/lines-planes
1575 */
1576 intersect(
1577 w: MathCollection,
1578 x: MathCollection,
1579 y: MathCollection,
1580 z: MathCollection
1581 ): MathArray
1582
1583 /*************************************************************************
1584 * Logical functions
1585 ************************************************************************/
1586
1587 /**
1588 * Logical and. Test whether two values are both defined with a
1589 * nonzero/nonempty value. For matrices, the function is evaluated
1590 * element wise.
1591 * @param x First value to and
1592 * @param y Second value to and
1593 * @returns Returns true when both inputs are defined with a
1594 * nonzero/nonempty value.
1595 */
1596 and(
1597 x: number | BigNumber | Complex | Unit | MathCollection,
1598 y: number | BigNumber | Complex | Unit | MathCollection
1599 ): boolean | MathCollection
1600
1601 /**
1602 * Logical not. Flips boolean value of a given parameter. For matrices,
1603 * the function is evaluated element wise.
1604 * @param x First value to not
1605 * @returns Returns true when input is a zero or empty value.
1606 */
1607 not(
1608 x: number | BigNumber | Complex | Unit | MathCollection
1609 ): boolean | MathCollection
1610
1611 /**
1612 * Logical or. Test if at least one value is defined with a
1613 * nonzero/nonempty value. For matrices, the function is evaluated
1614 * element wise.
1615 * @param x First value to or
1616 * @param y Second value to or
1617 * @returns Returns true when one of the inputs is defined with a
1618 * nonzero/nonempty value.
1619 */
1620 or(
1621 x: number | BigNumber | Complex | Unit | MathCollection,
1622 y: number | BigNumber | Complex | Unit | MathCollection
1623 ): boolean | MathCollection
1624
1625 /**
1626 * Logical xor. Test whether one and only one value is defined with a
1627 * nonzero/nonempty value. For matrices, the function is evaluated
1628 * element wise.
1629 * @param x First value to xor
1630 * @param y Second value to xor
1631 * @returns Returns true when one and only one input is defined with a
1632 * nonzero/nonempty value.
1633 */
1634 xor(
1635 x: number | BigNumber | Complex | Unit | MathCollection,
1636 y: number | BigNumber | Complex | Unit | MathCollection
1637 ): boolean | MathCollection
1638
1639 /*************************************************************************
1640 * Matrix functions
1641 ************************************************************************/
1642
1643 /**
1644 * Apply a function that maps an array to a scalar along a given axis of a
1645 * matrix or array. Returns a new matrix or array with one less dimension
1646 * than the input.
1647 * @param array The input Matrix
1648 * @param dim The dimension along which the callback is applied
1649 * @param callback The callback function that is applied. This Function should take an
1650 * array or 1-d matrix as an input and return a number.
1651 * @returns The residual matrix with the function applied over some dimension.
1652 */
1653 apply<T extends MathCollection>(
1654 array: T,
1655 dim: number,
1656 callback: (array: MathCollection) => number
1657 ): T
1658
1659 /**
1660 * Concatenate two or more matrices. dim: number is a zero-based
1661 * dimension over which to concatenate the matrices. By default the last
1662 * dimension of the matrices.
1663 * @param args Two or more matrices
1664 * @returns Concatenated matrix
1665 */
1666 concat(...args: Array<MathCollection | number | BigNumber>): MathCollection
1667
1668 /**
1669 * Calculate the cross product for two vectors in three dimensional
1670 * space. The cross product of A = [a1, a2, a3] and B =[b1, b2, b3] is
1671 * defined as: cross(A, B) = [ a2 * b3 - a3 * b2, a3 * b1 - a1 * b3, a1
1672 * * b2 - a2 * b1 ]
1673 * @param x First vector
1674 * @param y Second vector
1675 * @returns Returns the cross product of x and y
1676 */
1677 cross(x: MathCollection, y: MathCollection): Matrix | MathArray
1678
1679 /**
1680 * Calculate the determinant of a matrix.
1681 * @param x A Matrix
1682 * @returns the determinant of x
1683 */
1684 det(x: MathCollection): number
1685
1686 /**
1687 * Create a diagonal matrix or retrieve the diagonal of a matrix. When x
1688 * is a vector, a matrix with vector x on the diagonal will be returned.
1689 * When x is a two dimensional matrix, the matrixes kth diagonal will be
1690 * returned as vector. When k is positive, the values are placed on the
1691 * super diagonal. When k is negative, the values are placed on the sub
1692 * diagonal.
1693 * @param X A two dimensional matrix or a vector
1694 * @param k The diagonal where the vector will be filled in or
1695 * retrieved. Default value: 0.
1696 * @param format The matrix storage format. Default value: 'dense'.
1697 * @returns Diagonal matrix from input vector, or diagonal from input
1698 * matrix
1699 */
1700 diag(X: MathCollection, format?: string): Matrix
1701 diag(
1702 X: MathCollection,
1703 k: number | BigNumber,
1704 format?: string
1705 ): Matrix | MathArray
1706
1707 /**
1708 * Calculate the dot product of two vectors. The dot product of A = [a1,
1709 * a2, a3, ..., an] and B = [b1, b2, b3, ..., bn] is defined as: dot(A,
1710 * B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn
1711 * @param x First vector
1712 * @param y Second vector
1713 * @returns Returns the dot product of x and y
1714 */
1715 dot(x: MathCollection, y: MathCollection): number
1716
1717 /**
1718 * Compute eigenvalues and eigenvectors of a matrix.
1719 * The eigenvalues are sorted by their absolute value, ascending.
1720 * An eigenvalue with multiplicity k will be listed k times.
1721 * The eigenvectors are returned as columns of a matrix – the eigenvector
1722 * that belongs to the j-th eigenvalue in the list (eg. values[j]) is the
1723 * j-th column (eg. column(vectors, j)). If the algorithm fails to converge,
1724 * it will throw an error – in that case, however, you may still find useful
1725 * information in err.values and err.vectors
1726 * @param x Matrix to be diagonalized
1727 * @param prec Precision, default value: 1e-15
1728 * @returns Object containing an array of eigenvalues and a matrix with eigenvectors as columns.
1729 */
1730 eigs(
1731 x: MathCollection,
1732 prec?: number | BigNumber
1733 ): { values: MathCollection; vectors: MathCollection }
1734
1735 /**
1736 * Compute the matrix exponential, expm(A) = e^A. The matrix must be
1737 * square. Not to be confused with exp(a), which performs element-wise
1738 * exponentiation. The exponential is calculated using the Padé
1739 * approximant with scaling and squaring; see “Nineteen Dubious Ways to
1740 * Compute the Exponential of a Matrix,” by Moler and Van Loan.
1741 * @param x A square matrix
1742 * @returns The exponential of x
1743 */
1744 expm(x: Matrix): Matrix
1745
1746 /**
1747 * Create a 2-dimensional identity matrix with size m x n or n x n. The
1748 * matrix has ones on the diagonal and zeros elsewhere.
1749 * @param size The size for the matrix
1750 * @param format The Matrix storage format
1751 * @returns A matrix with ones on the diagonal
1752 */
1753 identity(
1754 size: number | number[] | Matrix | MathArray,
1755 format?: string
1756 ): Matrix | MathArray | number
1757 /**
1758 * @param m The x dimension for the matrix
1759 * @param n The y dimension for the matrix
1760 * @param format The Matrix storage format
1761 * @returns A matrix with ones on the diagonal
1762 */
1763 identity(m: number, n: number, format?: string): Matrix | MathArray | number
1764
1765 /**
1766 * Filter the items in an array or one dimensional matrix.
1767 * @param x A one dimensional matrix or array to filter
1768 * @param test A function or regular expression to test items. All
1769 * entries for which test returns true are returned. When test is a
1770 * function, it is invoked with three parameters: the value of the
1771 * element, the index of the element, and the matrix/array being
1772 * traversed. The function must return a boolean.
1773 */
1774 filter(
1775 x: Matrix | MathArray | string[],
1776 test:
1777 | ((
1778 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1779 value: any,
1780 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1781 index: any,
1782 matrix: Matrix | MathArray | string[]
1783 ) => boolean)
1784 | RegExp
1785 ): Matrix | MathArray
1786
1787 /**
1788 * Flatten a multi dimensional matrix into a single dimensional matrix.
1789 * @param x Matrix to be flattened
1790 * @returns Returns the flattened matrix
1791 */
1792 flatten<T extends MathCollection>(x: T): T
1793
1794 /**
1795 * Iterate over all elements of a matrix/array, and executes the given
1796 * callback function.
1797 * @param x The matrix to iterate on.
1798 * @param callback The callback function is invoked with three
1799 * parameters: the value of the element, the index of the element, and
1800 * the Matrix/array being traversed.
1801 */
1802 forEach<T extends Matrix | MathArray>(
1803 x: T,
1804 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1805 callback: (value: any, index: any, matrix: T) => void
1806 ): void
1807
1808 /**
1809 * Calculate the inverse of a square matrix.
1810 * @param x Matrix to be inversed
1811 * @returns The inverse of x
1812 */
1813 inv<T extends number | Complex | MathCollection>(x: T): NoLiteralType<T>
1814
1815 /**
1816 * Calculate the kronecker product of two matrices or vectors
1817 * @param x First vector
1818 * @param y Second vector
1819 * @returns Returns the kronecker product of x and y
1820 */
1821 kron(x: Matrix | MathArray, y: Matrix | MathArray): Matrix
1822
1823 /**
1824 * Iterate over all elements of a matrix/array, and executes the given
1825 * callback function.
1826 * @param x The matrix to iterate on.
1827 * @param callback The callback function is invoked with three
1828 * parameters: the value of the element, the index of the element, and
1829 * the Matrix/array being traversed.
1830 * @returns Transformed map of x
1831 */
1832 map<T extends Matrix | MathArray>(
1833 x: T,
1834 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1835 callback: (value: any, index: any, matrix: T) => MathType | string
1836 ): T
1837
1838 /**
1839 * Create a matrix filled with ones. The created matrix can have one or
1840 * multiple dimensions.
1841 * @param size The size of each dimension of the matrix
1842 * @param format The matrix storage format
1843 * @returns A matrix filled with ones
1844 */
1845 ones(size: number | number[], format?: string): MathCollection
1846 /**
1847 * @param m The x dimension of the matrix
1848 * @param n The y dimension of the amtrix
1849 * @param format The matrix storage format
1850 * @returns A matrix filled with ones
1851 */
1852 ones(m: number, n: number, format?: string): MathCollection
1853
1854 /**
1855 * Partition-based selection of an array or 1D matrix. Will find the kth
1856 * smallest value, and mutates the input array. Uses Quickselect.
1857 * @param x A one dimensional matrix or array to sort
1858 * @param k The kth smallest value to be retrieved; zero-based index
1859 * @param compare An optional comparator function. The function is
1860 * called as compare(a, b), and must return 1 when a > b, -1 when a < b,
1861 * and 0 when a == b. Default value: 'asc'.
1862 * @returns Returns the kth lowest value.
1863 */
1864 partitionSelect(
1865 x: MathCollection,
1866 k: number,
1867 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1868 compare?: 'asc' | 'desc' | ((a: any, b: any) => number)
1869 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1870 ): any
1871
1872 /**
1873 * Create an array from a range. By default, the range end is excluded.
1874 * This can be customized by providing an extra parameter includeEnd.
1875 * @param str A string 'start:end' or 'start:step:end'
1876 * @param start Start of the range
1877 * @param end End of the range, excluded by default, included when
1878 * parameter includeEnd=true
1879 * @param step Step size. Default value is 1.
1880 * @param includeEnd: Option to specify whether to include the end or
1881 * not. False by default
1882 * @returns Parameters describing the ranges start, end, and optional
1883 * step.
1884 */
1885 range(str: string, includeEnd?: boolean): Matrix
1886 range(
1887 start: number | BigNumber,
1888 end: number | BigNumber,
1889 includeEnd?: boolean
1890 ): Matrix
1891 range(
1892 start: number | BigNumber,
1893 end: number | BigNumber,
1894 step: number | BigNumber,
1895 includeEnd?: boolean
1896 ): Matrix
1897
1898 /**
1899 * Reshape a multi dimensional array to fit the specified dimensions
1900 * @param x Matrix to be reshaped
1901 * @param sizes One dimensional array with integral sizes for each
1902 * dimension
1903 * @returns A reshaped clone of matrix x
1904 */
1905 reshape<T extends MathCollection>(x: T, sizes: number[]): T
1906
1907 /**
1908 * Resize a matrix
1909 * @param x Matrix to be resized
1910 * @param size One dimensional array with numbers
1911 * @param defaultValue Zero by default, except in case of a string, in
1912 * that case defaultValue = ' ' Default value: 0.
1913 * @returns A resized clone of matrix x
1914 */
1915 resize<T extends MathCollection>(
1916 x: T,
1917 size: MathCollection,
1918 defaultValue?: number | string
1919 ): T
1920
1921 /**
1922 * Return a row from a Matrix.
1923 * @param value An array or matrix
1924 * @param row The index of the row
1925 * @returns The retrieved row
1926 */
1927 row<T extends MathCollection>(value: T, row: number): T
1928
1929 /**
1930 * Return a column from a Matrix.
1931 * @param value An array or matrix
1932 * @param column The index of the column
1933 * @returns The retrieved column
1934 */
1935 column<T extends MathCollection>(value: T, column: number): T
1936
1937 /**
1938 * Return a rotated matrix.
1939 * @param {Array | Matrix} w Vector to rotate
1940 * @param {number | BigNumber | Complex | Unit} theta Rotation angle
1941 * @param {Array | Matrix} [v] Rotation axis
1942 * @return {Array | Matrix} Multiplication of the rotation matrix and w
1943 */
1944 rotate<T extends MathCollection>(
1945 w: T,
1946 theta: number | BigNumber | Complex | Unit,
1947 v?: T
1948 ): T
1949
1950 /**
1951 * Calculate the size of a matrix or scalar.
1952 * @param A matrix
1953 * @returns A vector with the size of x
1954 */
1955 size(
1956 x: boolean | number | Complex | Unit | string | MathCollection
1957 ): MathCollection
1958
1959 /**
1960 * Sort the items in a matrix
1961 * @param x A one dimensional matrix or array to sort
1962 * @param compare An optional _comparator function or name. The function
1963 * is called as compare(a, b), and must return 1 when a > b, -1 when a <
1964 * b, and 0 when a == b. Default value: ‘asc
1965 * @returns Returns the sorted matrix
1966 */
1967 sort<T extends Matrix | MathArray>(
1968 x: T,
1969 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1970 compare: ((a: any, b: any) => number) | 'asc' | 'desc' | 'natural'
1971 ): T
1972
1973 /**
1974 * Calculate the principal square root of a square matrix. The principal
1975 * square root matrix X of another matrix A is such that X * X = A.
1976 * @param A The square matrix A
1977 * @returns The principal square root of matrix A
1978 */
1979 sqrtm<T extends MathCollection>(A: T): T
1980
1981 /**
1982 * Squeeze a matrix, remove inner and outer singleton dimensions from a
1983 * matrix.
1984 * @param x Matrix to be squeezed
1985 * @returns Squeezed matrix
1986 */
1987 squeeze<T extends MathCollection>(x: T): T
1988
1989 /**
1990 * Get or set a subset of a matrix or string.
1991 * @param value An array, matrix, or string
1992 * @param index For each dimension, an index or list of indices to get or set.
1993 * @param replacement An array, matrix, or scalar. If provided, the
1994 * subset is replaced with replacement. If not provided, the subset is
1995 * returned
1996 * @param defaultValue Default value, filled in on new entries when the
1997 * matrix is resized. If not provided, math.matrix elements will be left
1998 * undefined. Default value: undefined.
1999 * @returns Either the retrieved subset or the updated matrix
2000 */
2001 subset<T extends MathCollection | string>(
2002 value: T,
2003 index: Index,
2004 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2005 replacement?: any,
2006 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2007 defaultValue?: any
2008 ): T
2009
2010 /**
2011 * Calculate the trace of a matrix: the sum of the elements on the main
2012 * diagonal of a square matrix.
2013 * @param x A matrix
2014 * @returns The trace of x
2015 */
2016 trace(x: MathCollection): number
2017
2018 /**
2019 * Transpose a matrix. All values of the matrix are reflected over its
2020 * main diagonal. Only two dimensional matrices are supported.
2021 * @param x Matrix to be transposed
2022 * @returns The transposed matrix
2023 */
2024 transpose<T extends MathCollection>(x: T): T
2025
2026 /**
2027 * Create a matrix filled with zeros. The created matrix can have one or
2028 * multiple dimensions.
2029 * @param size The size of each dimension of the matrix
2030 * @param format The matrix storage format
2031 * @returns A matrix filled with zeros
2032 */
2033 zeros(size: number | number[], format?: string): MathCollection
2034 /**
2035 * @param m The x dimension of the matrix
2036 * @param n The y dimension of the matrix
2037 * @param format The matrix storage format
2038 * @returns A matrix filled with zeros
2039 */
2040 zeros(m: number, n: number, format?: string): MathCollection
2041
2042 /**
2043 * Calculate N-dimensional fourier transform
2044 * @param {Array | Matrix} arr An array or matrix
2045 * @return {Array | Matrix} N-dimensional fourier transformation of the array
2046 */
2047 fft<T extends MathCollection>(arr: T): T
2048
2049 /**
2050 * Calculate N-dimensional inverse fourier transform
2051 * @param {Array | Matrix} arr An array or matrix
2052 * @return {Array | Matrix} N-dimensional fourier transformation of the array
2053 */
2054 ifft<T extends MathCollection>(arr: T): T
2055
2056 /*************************************************************************
2057 * Probability functions
2058 ************************************************************************/
2059
2060 /**
2061 * Compute the number of ways of picking k unordered outcomes from n
2062 * possibilities. Combinations only takes integer arguments. The
2063 * following condition must be enforced: k <= n.
2064 * @param n Total number of objects in the set
2065 * @param k Number of objects in the subset
2066 * @returns Number of possible combinations
2067 */
2068 combinations<T extends number | BigNumber>(
2069 n: T,
2070 k: number | BigNumber
2071 ): NoLiteralType<T>
2072
2073 /**
2074 * Compute the factorial of a value Factorial only supports an integer
2075 * value as argument. For matrices, the function is evaluated element
2076 * wise.
2077 * @param n An integer number
2078 * @returns The factorial of n
2079 */
2080 factorial<T extends number | BigNumber | MathCollection>(
2081 n: T
2082 ): NoLiteralType<T>
2083
2084 /**
2085 * Compute the gamma function of a value using Lanczos approximation for
2086 * small values, and an extended Stirling approximation for large
2087 * values. For matrices, the function is evaluated element wise.
2088 * @param n A real or complex number
2089 * @returns The gamma of n
2090 */
2091 gamma<T extends number | BigNumber | Complex | MathCollection>(
2092 n: T
2093 ): NoLiteralType<T>
2094
2095 /**
2096 * Calculate the Kullback-Leibler (KL) divergence between two
2097 * distributions
2098 * @param q First vector
2099 * @param p Second vector
2100 * @returns Returns disance between q and p
2101 */
2102 kldivergence(q: MathCollection, p: MathCollection): number
2103
2104 /**
2105 * Compute the log gamma function of a value, using Lanczos approximation for numbers and Stirling series for complex numbers.
2106 * @param n A real or complex number
2107 * @returns The log gamma of `n`
2108 */
2109 lgamma<T extends number | Complex>(n: T): NoLiteralType<T>
2110
2111 /**
2112 * Multinomial Coefficients compute the number of ways of picking a1,
2113 * a2, ..., ai unordered outcomes from n possibilities. multinomial
2114 * takes one array of integers as an argument. The following condition
2115 * must be enforced: every ai <= 0
2116 * @param a Integer number of objects in the subset
2117 * @returns multinomial coefficent
2118 */
2119 multinomial<T extends number | BigNumber>(a: T[]): NoLiteralType<T>
2120
2121 /**
2122 * Compute the number of ways of obtaining an ordered subset of k
2123 * elements from a set of n elements. Permutations only takes integer
2124 * arguments. The following condition must be enforced: k <= n.
2125 * @param n The number of objects in total
2126 * @param k The number of objects in the subset
2127 * @returns The number of permutations
2128 */
2129 permutations<T extends number | BigNumber>(
2130 n: T,
2131 k?: number | BigNumber
2132 ): NoLiteralType<T>
2133
2134 /**
2135 * Random pick a value from a one dimensional array. Array element is
2136 * picked using a random function with uniform distribution.
2137 * @param array A one dimensional array
2138 * @param number An int or float
2139 * @param weights An array of ints or floats
2140 * @returns Returns a single random value from array when number is 1 or
2141 * undefined. Returns an array with the configured number of elements
2142 * when number is > 1.
2143 */
2144 pickRandom(
2145 array: number[],
2146 number?: number,
2147 weights?: number[]
2148 ): number | number[]
2149
2150 /**
2151 * Return a random number larger or equal to min and smaller than max
2152 * using a uniform distribution.
2153 * @param size If provided, an array or matrix with given size and
2154 * filled with random values is returned
2155 * @param min Minimum boundary for the random value, included
2156 * @param max Maximum boundary for the random value, excluded
2157 * @returns A random number
2158 */
2159 random(min?: number, max?: number): number
2160 random<T extends MathCollection>(size: T, min?: number, max?: number): T
2161
2162 /**
2163 * Return a random integer number larger or equal to min and smaller
2164 * than max using a uniform distribution.
2165 * @param size If provided, an array or matrix with given size and
2166 * filled with random values is returned
2167 * @param min Minimum boundary for the random value, included
2168 * @param max Maximum boundary for the random value, excluded
2169 * @returns A random number
2170 */
2171 randomInt(min: number, max?: number): number
2172 randomInt<T extends MathCollection>(size: T, min?: number, max?: number): T
2173
2174 /*************************************************************************
2175 * Relational functions
2176 ************************************************************************/
2177
2178 /**
2179 * Compare two values. Returns 1 when x > y, -1 when x < y, and 0 when x
2180 * == y. x and y are considered equal when the relative difference
2181 * between x and y is smaller than the configured epsilon. The function
2182 * cannot be used to compare values smaller than approximately 2.22e-16.
2183 * For matrices, the function is evaluated element wise.
2184 * @param x First value to compare
2185 * @param y Second value to compare
2186 * @returns Returns the result of the comparison: 1 when x > y, -1 when
2187 * x < y, and 0 when x == y.
2188 */
2189 compare(
2190 x: MathType | string,
2191 y: MathType | string
2192 ): number | BigNumber | Fraction | MathCollection
2193
2194 /**
2195 * Compare two values of any type in a deterministic, natural way. For
2196 * numeric values, the function works the same as math.compare. For
2197 * types of values that cant be compared mathematically, the function
2198 * compares in a natural way.
2199 * @param x First value to compare
2200 * @param y Second value to compare
2201 * @returns Returns the result of the comparison: 1 when x > y, -1 when
2202 * x < y, and 0 when x == y.
2203 */
2204 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2205 compareNatural(x: any, y: any): number
2206
2207 /**
2208 * Compare two strings lexically. Comparison is case sensitive. Returns
2209 * 1 when x > y, -1 when x < y, and 0 when x == y. For matrices, the
2210 * function is evaluated element wise.
2211 * @param x First string to compare
2212 * @param y Second string to compare
2213 * @returns Returns the result of the comparison: 1 when x > y, -1 when
2214 * x < y, and 0 when x == y.
2215 */
2216 compareText(
2217 x: string | MathCollection,
2218 y: string | MathCollection
2219 ): number | MathCollection
2220
2221 /**
2222 * Test element wise whether two matrices are equal. The function
2223 * accepts both matrices and scalar values.
2224 * @param x First matrix to compare
2225 * @param y Second amtrix to compare
2226 * @returns Returns true when the input matrices have the same size and
2227 * each of their elements is equal.
2228 */
2229 deepEqual(
2230 x: MathType,
2231 y: MathType
2232 ): number | BigNumber | Fraction | Complex | Unit | MathCollection
2233
2234 /**
2235 * Test whether two values are equal.
2236 *
2237 * The function tests whether the relative difference between x and y is
2238 * smaller than the configured epsilon. The function cannot be used to
2239 * compare values smaller than approximately 2.22e-16. For matrices, the
2240 * function is evaluated element wise. In case of complex numbers, x.re
2241 * must equal y.re, and x.im must equal y.im. Values null and undefined
2242 * are compared strictly, thus null is only equal to null and nothing
2243 * else, and undefined is only equal to undefined and nothing else.
2244 * @param x First value to compare
2245 * @param y Second value to compare
2246 * @returns Returns true when the compared values are equal, else
2247 * returns false
2248 */
2249 equal(x: MathType | string, y: MathType | string): boolean | MathCollection
2250
2251 /**
2252 * Check equality of two strings. Comparison is case sensitive. For
2253 * matrices, the function is evaluated element wise.
2254 * @param x First string to compare
2255 * @param y Second string to compare
2256 * @returns Returns true if the values are equal, and false if not.
2257 */
2258 equalText(
2259 x: string | MathCollection,
2260 y: string | MathCollection
2261 ): number | MathCollection
2262
2263 /**
2264 * Test whether value x is larger than y. The function returns true when
2265 * x is larger than y and the relative difference between x and y is
2266 * larger than the configured epsilon. The function cannot be used to
2267 * compare values smaller than approximately 2.22e-16. For matrices, the
2268 * function is evaluated element wise.
2269 * @param x First value to compare
2270 * @param y Second value to vcompare
2271 * @returns Returns true when x is larger than y, else returns false
2272 */
2273 larger(x: MathType | string, y: MathType | string): boolean | MathCollection
2274
2275 /**
2276 * Test whether value x is larger or equal to y. The function returns
2277 * true when x is larger than y or the relative difference between x and
2278 * y is smaller than the configured epsilon. The function cannot be used
2279 * to compare values smaller than approximately 2.22e-16. For matrices,
2280 * the function is evaluated element wise.
2281 * @param x First value to compare
2282 * @param y Second value to vcompare
2283 * @returns Returns true when x is larger than or equal to y, else
2284 * returns false
2285 */
2286 largerEq(
2287 x: MathType | string,
2288 y: MathType | string
2289 ): boolean | MathCollection
2290
2291 /**
2292 * Test whether value x is smaller than y. The function returns true
2293 * when x is smaller than y and the relative difference between x and y
2294 * is smaller than the configured epsilon. The function cannot be used
2295 * to compare values smaller than approximately 2.22e-16. For matrices,
2296 * the function is evaluated element wise.
2297 * @param x First value to compare
2298 * @param y Second value to vcompare
2299 * @returns Returns true when x is smaller than y, else returns false
2300 */
2301 smaller(
2302 x: MathType | string,
2303 y: MathType | string
2304 ): boolean | MathCollection
2305
2306 /**
2307 * Test whether value x is smaller or equal to y. The function returns
2308 * true when x is smaller than y or the relative difference between x
2309 * and y is smaller than the configured epsilon. The function cannot be
2310 * used to compare values smaller than approximately 2.22e-16. For
2311 * matrices, the function is evaluated element wise.
2312 * @param x First value to compare
2313 * @param y Second value to vcompare
2314 * @returns Returns true when x is smaller than or equal to y, else
2315 * returns false
2316 */
2317 smallerEq(
2318 x: MathType | string,
2319 y: MathType | string
2320 ): boolean | MathCollection
2321
2322 /**
2323 * Test whether two values are unequal. The function tests whether the
2324 * relative difference between x and y is larger than the configured
2325 * epsilon. The function cannot be used to compare values smaller than
2326 * approximately 2.22e-16. For matrices, the function is evaluated
2327 * element wise. In case of complex numbers, x.re must unequal y.re, or
2328 * x.im must unequal y.im. Values null and undefined are compared
2329 * strictly, thus null is unequal with everything except null, and
2330 * undefined is unequal with everything except undefined.
2331 * @param x First value to compare
2332 * @param y Second value to vcompare
2333 * @returns Returns true when the compared values are unequal, else
2334 * returns false
2335 */
2336 unequal(
2337 x: MathType | string,
2338 y: MathType | string
2339 ): boolean | MathCollection
2340
2341 /*************************************************************************
2342 * Set functions
2343 ************************************************************************/
2344
2345 /**
2346 * Create the cartesian product of two (multi)sets. Multi-dimension
2347 * arrays will be converted to single-dimension arrays and the values
2348 * will be sorted in ascending order before the operation.
2349 * @param a1 A (multi)set
2350 * @param a2 A (multi)set
2351 * @returns The cartesian product of two (multi)sets
2352 */
2353 setCartesian<T extends MathCollection>(a1: T, a2: MathCollection): T
2354
2355 /**
2356 * Create the difference of two (multi)sets: every element of set1, that
2357 * is not the element of set2. Multi-dimension arrays will be converted
2358 * to single-dimension arrays before the operation
2359 * @param a1 A (multi)set
2360 * @param a2 A (multi)set
2361 * @returns The difference of two (multi)sets
2362 */
2363 setDifference<T extends MathCollection>(a1: T, a2: MathCollection): T
2364
2365 /**
2366 * Collect the distinct elements of a multiset. A multi-dimension array
2367 * will be converted to a single-dimension array before the operation.
2368 * @param a A multiset
2369 * @returns A set containing the distinct elements of the multiset
2370 */
2371 setDistinct<T extends MathCollection>(a: T): T
2372
2373 /**
2374 * Create the intersection of two (multi)sets. Multi-dimension arrays
2375 * will be converted to single-dimension arrays before the operation.
2376 * @param a1 A (multi)set
2377 * @param a2 A (multi)set
2378 * @returns The intersection of two (multi)sets
2379 */
2380 setIntersect<T extends MathCollection>(a1: T, a2: MathCollection): T
2381
2382 /**
2383 * Check whether a (multi)set is a subset of another (multi)set. (Every
2384 * element of set1 is the element of set2.) Multi-dimension arrays will
2385 * be converted to single-dimension arrays before the operation.
2386 * @param a1 A (multi)set
2387 * @param a2 A (multi)set
2388 * @returns True if a1 is subset of a2, else false
2389 */
2390 setIsSubset(a1: MathCollection, a2: MathCollection): boolean
2391
2392 /**
2393 * Count the multiplicity of an element in a multiset. A multi-dimension
2394 * array will be converted to a single-dimension array before the
2395 * operation.
2396 * @param e An element in the multiset
2397 * @param a A multiset
2398 * @returns The number of how many times the multiset contains the
2399 * element
2400 */
2401 setMultiplicity(
2402 e: number | BigNumber | Fraction | Complex,
2403 a: MathCollection
2404 ): number
2405
2406 /**
2407 * Create the powerset of a (multi)set. (The powerset contains very
2408 * possible subsets of a (multi)set.) A multi-dimension array will be
2409 * converted to a single-dimension array before the operation.
2410 * @param a A multiset
2411 * @returns The powerset of the (multi)set
2412 */
2413 setPowerset<T extends MathCollection>(a: T): T
2414
2415 /**
2416 * Count the number of elements of a (multi)set. When a second parameter
2417 * istrue’, count only the unique values. A multi-dimension array will
2418 * be converted to a single-dimension array before the operation.
2419 * @param a A multiset
2420 * @returns The number of elements of the (multi)set
2421 */
2422 setSize(a: MathCollection): number
2423
2424 /**
2425 * Create the symmetric difference of two (multi)sets. Multi-dimension
2426 * arrays will be converted to single-dimension arrays before the
2427 * operation.
2428 * @param a1 A (multi)set
2429 * @param a2 A (multi)set
2430 * @returns The symmetric difference of two (multi)sets
2431 */
2432 setSymDifference<T extends MathCollection>(a1: T, a2: MathCollection): T
2433
2434 /**
2435 * Create the union of two (multi)sets. Multi-dimension arrays will be
2436 * converted to single-dimension arrays before the operation.
2437 * @param a1 A (multi)set
2438 * @param a2 A (multi)set
2439 * @returns The union of two (multi)sets
2440 */
2441 setUnion<T extends MathCollection>(a1: T, a2: MathCollection): T
2442
2443 /*************************************************************************
2444 * Special functions
2445 ************************************************************************/
2446
2447 /**
2448 * Compute the erf function of a value using a rational Chebyshev
2449 * approximations for different intervals of x.
2450 * @param x A real number
2451 * @returns The erf of x
2452 */
2453 erf<T extends number | MathCollection>(x: T): NoLiteralType<T>
2454
2455 /*************************************************************************
2456 * Statistics functions
2457 ************************************************************************/
2458
2459 /**
2460 * Compute the median absolute deviation of a matrix or a list with
2461 * values. The median absolute deviation is defined as the median of the
2462 * absolute deviations from the median.
2463 * @param array A single matrix or multiple scalar values.
2464 * @returns The median absolute deviation
2465 */
2466 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2467 mad(array: MathCollection): any
2468
2469 /**
2470 * Compute the maximum value of a matrix or a list with values. In case
2471 * of a multi dimensional array, the maximum of the flattened array will
2472 * be calculated. When dim is provided, the maximum over the selected
2473 * dimension will be calculated. Parameter dim is zero-based.
2474 * @param args A single matrix or multiple scalar values
2475 * @returns The maximum value
2476 */
2477 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2478 max(...args: MathType[]): any
2479 /**
2480 * @param A A single matrix
2481 * @param dim The maximum over the selected dimension
2482 * @returns The maximum value
2483 */
2484 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2485 max(A: MathCollection, dim?: number): any
2486
2487 /**
2488 * Compute the mean value of matrix or a list with values. In case of a
2489 * multi dimensional array, the mean of the flattened array will be
2490 * calculated. When dim is provided, the maximum over the selected
2491 * dimension will be calculated. Parameter dim is zero-based.
2492 * @param args A single matrix or multiple scalar values
2493 * @returns The mean of all values
2494 */
2495 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2496 mean(...args: MathType[]): any
2497 /**
2498 * @param A A single matrix
2499 * @param dim The mean over the selected dimension
2500 * @returns The mean of all values
2501 */
2502 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2503 mean(A: MathCollection, dim?: number): any
2504
2505 /**
2506 * Compute the median of a matrix or a list with values. The values are
2507 * sorted and the middle value is returned. In case of an even number of
2508 * values, the average of the two middle values is returned. Supported
2509 * types of values are: Number, BigNumber, Unit In case of a (multi
2510 * dimensional) array or matrix, the median of all elements will be
2511 * calculated.
2512 * @param args A single matrix or or multiple scalar values
2513 * @returns The median
2514 */
2515 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2516 median(...args: MathType[]): any
2517
2518 /**
2519 * Compute the maximum value of a matrix or a list of values. In case of
2520 * a multi dimensional array, the maximum of the flattened array will be
2521 * calculated. When dim is provided, the maximum over the selected
2522 * dimension will be calculated. Parameter dim is zero-based.
2523 * @param args A single matrix or or multiple scalar values
2524 * @returns The minimum value
2525 */
2526 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2527 min(...args: MathType[]): any
2528 /**
2529 * @param A A single matrix
2530 * @param dim The minimum over the selected dimension
2531 * @returns The minimum value
2532 */
2533 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2534 min(A: MathCollection, dim?: number): any
2535
2536 /**
2537 * Computes the mode of a set of numbers or a list with values(numbers
2538 * or characters). If there are more than one modes, it returns a list
2539 * of those values.
2540 * @param args A single matrix
2541 * @returns The mode of all values
2542 */
2543 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2544 mode(...args: MathType[]): any
2545
2546 /**
2547 * Compute the product of a matrix or a list with values. In case of a
2548 * (multi dimensional) array or matrix, the sum of all elements will be
2549 * calculated.
2550 * @param args A single matrix or multiple scalar values
2551 * @returns The product of all values
2552 */
2553 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2554 prod(...args: MathType[]): any
2555
2556 /**
2557 * Compute the prob order quantile of a matrix or a list with values.
2558 * The sequence is sorted and the middle value is returned. Supported
2559 * types of sequence values are: Number, BigNumber, Unit Supported types
2560 * of probability are: Number, BigNumber In case of a (multi
2561 * dimensional) array or matrix, the prob order quantile of all elements
2562 * will be calculated.
2563 * @param A A single matrix or array
2564 * @param probOrN prob is the order of the quantile, while N is the
2565 * amount of evenly distributed steps of probabilities; only one of
2566 * these options can be provided
2567 * @param sorted =false is data sorted in ascending order
2568 * @returns Quantile(s)
2569 */
2570 quantileSeq(
2571 A: MathCollection,
2572 prob: number | BigNumber | MathArray,
2573 sorted?: boolean
2574 ): number | BigNumber | Unit | MathArray
2575
2576 /**
2577 * Compute the standard deviation of a matrix or a list with values. The
2578 * standard deviations is defined as the square root of the variance:
2579 * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or
2580 * matrix, the standard deviation over all elements will be calculated.
2581 * Optionally, the type of normalization can be specified as second
2582 * parameter. The parameter normalization can be one of the following
2583 * values: 'unbiased' (default) The sum of squared errors is divided by
2584 * (n - 1) 'uncorrected' The sum of squared errors is divided by n
2585 * 'biased' The sum of squared errors is divided by (n + 1)
2586 * @param a variadic argument of number to calculate standard deviation
2587 * @returns The standard deviation array
2588 */
2589 std(...values: number[]): number
2590 /**
2591 * Compute the standard deviation of a matrix or a list with values. The
2592 * standard deviations is defined as the square root of the variance:
2593 * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or
2594 * matrix, the standard deviation over all elements will be calculated.
2595 * Optionally, the type of normalization can be specified as second
2596 * parameter. The parameter normalization can be one of the following
2597 * values: 'unbiased' (default) The sum of squared errors is divided by
2598 * (n - 1) 'uncorrected' The sum of squared errors is divided by n
2599 * 'biased' The sum of squared errors is divided by (n + 1)
2600 * @param array A single matrix to compute standard deviation.
2601 * @param dimension A dimension to calculate standard deviation
2602 * @param normalization Determines how to normalize the variance. Choose
2603 * ‘unbiased’ (default), ‘uncorrected’, orbiased’. Default value:
2604 * ‘unbiased’.
2605 * @returns The standard deviation array
2606 */
2607 std(
2608 array: MathCollection,
2609 dimension?: number,
2610 normalization?: 'unbiased' | 'uncorrected' | 'biased'
2611 ): number[]
2612 /**
2613 * Compute the standard deviation of a matrix or a list with values. The
2614 * standard deviations is defined as the square root of the variance:
2615 * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or
2616 * matrix, the standard deviation over all elements will be calculated.
2617 * Optionally, the type of normalization can be specified as second
2618 * parameter. The parameter normalization can be one of the following
2619 * values: 'unbiased' (default) The sum of squared errors is divided by
2620 * (n - 1) 'uncorrected' The sum of squared errors is divided by n
2621 * 'biased' The sum of squared errors is divided by (n + 1)
2622 * @param array A single matrix or multiple scalar values
2623 * @param normalization Determines how to normalize the variance. Choose
2624 * ‘unbiased’ (default), ‘uncorrected’, orbiased’. Default value:
2625 * ‘unbiased’.
2626 * @returns The standard deviation
2627 */
2628 std(
2629 array: MathCollection,
2630 normalization: 'unbiased' | 'uncorrected' | 'biased'
2631 ): number
2632
2633 /**
2634 * Compute the sum of a matrix or a list with values. In case of a
2635 * (multi dimensional) array or matrix, the sum of all elements will be
2636 * calculated.
2637 * @param args A single matrix or multiple scalar values
2638 * @returns The sum of all values
2639 */
2640 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2641 sum(...args: Array<number | BigNumber | Fraction>): any
2642 /**
2643 * @param array A single matrix
2644 * @returns The sum of all values
2645 */
2646 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2647 sum(array: MathCollection): any
2648
2649 /**
2650 * Compute the cumulative sum of a matrix or a list with values.
2651 * In case of a (multi dimensional) array or matrix, the cumulative sums
2652 * along a specified dimension (defaulting to the first) will be calculated.
2653 * @param args A single matrix or multiple scalar values
2654 * @returns The cumulative sums of the the values.
2655 */
2656 cumsum(...args: MathType[]): MathType[]
2657 /**
2658 * @param array A single matrix
2659 * @param dim The dimension along which to sum (defaults to 0)
2660 * @returns The cumulative sums along the given dimension
2661 */
2662 cumsum(array: MathCollection, dim?: number): MathCollection
2663
2664 /**
2665 * Compute the variance of a matrix or a list with values. In case of a
2666 * (multi dimensional) array or matrix, the variance over all elements
2667 * will be calculated. Optionally, the type of normalization can be
2668 * specified as second parameter. The parameter normalization can be one
2669 * of the following values: 'unbiased' (default) The sum of squared
2670 * errors is divided by (n - 1) 'uncorrected' The sum of squared errors
2671 * is divided by n 'biased' The sum of squared errors is divided by (n +
2672 * 1) Note that older browser may not like the variable name var. In
2673 * that case, the function can be called as math['var'](...) instead of
2674 * math.variance(...).
2675 * @param args A single matrix or multiple scalar values
2676 * @returns The variance
2677 */
2678 variance(...args: Array<number | BigNumber | Fraction>): number
2679
2680 /**
2681 * Compute the variance of a matrix or a list with values. In case of a
2682 * (multi dimensional) array or matrix, the variance over all elements
2683 * will be calculated. Optionally, the type of normalization can be
2684 * specified as second parameter. The parameter normalization can be one
2685 * of the following values: 'unbiased' (default) The sum of squared
2686 * errors is divided by (n - 1) 'uncorrected' The sum of squared errors
2687 * is divided by n 'biased' The sum of squared errors is divided by (n +
2688 * 1) Note that older browser may not like the variable name var. In
2689 * that case, the function can be called as math['var'](...) instead of
2690 * math.variance(...).
2691 * @param array A matrix to compute variance.
2692 * @param dimension A dimension to compute variance on
2693 * @param normalization normalization Determines how to normalize the
2694 * variance. Chooseunbiased’ (default), ‘uncorrected’, orbiased’.
2695 * Default value: ‘unbiased’.
2696 * @returns variance matrix.
2697 */
2698 variance(
2699 array: MathCollection,
2700 dimension?: number,
2701 normalization?: 'unbiased' | 'uncorrected' | 'biased'
2702 ): number[]
2703 /**
2704 * @param array A single matrix
2705 * @param normalization normalization Determines how to normalize the
2706 * variance. Chooseunbiased’ (default), ‘uncorrected’, orbiased’.
2707 * Default value: ‘unbiased’.
2708 * @returns The variance
2709 */
2710 variance(
2711 array: MathCollection,
2712 normalization: 'unbiased' | 'uncorrected' | 'biased'
2713 ): number
2714
2715 /*************************************************************************
2716 * String functions
2717 ************************************************************************/
2718
2719 /**
2720 * Format a value of any type into a string.
2721 * @param value The value to be formatted
2722 * @param options An object with formatting options.
2723 * @param callback A custom formatting function, invoked for all numeric
2724 * elements in value, for example all elements of a matrix, or the real
2725 * and imaginary parts of a complex number. This callback can be used to
2726 * override the built-in numeric notation with any type of formatting.
2727 * Function callback is called with value as parameter and must return a
2728 * string.
2729 * @see http://mathjs.org/docs/reference/functions/format.html
2730 * @returns The formatted value
2731 */
2732 format(
2733 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2734 value: any,
2735 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2736 options?: FormatOptions | number | ((item: any) => string),
2737 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2738 callback?: (value: any) => string
2739 ): string
2740
2741 /**
2742 * Interpolate values into a string template.
2743 * @param template A string containing variable placeholders.
2744 * @param values An object containing variables which will be filled in
2745 * in the template.
2746 * @param precision Number of digits to format numbers. If not provided,
2747 * the value will not be rounded.
2748 * @param options Formatting options, or the number of digits to format
2749 * numbers. See function math.format for a description of all options.
2750 * @returns Interpolated string
2751 */
2752 print(
2753 template: string,
2754 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2755 values: any,
2756 precision?: number,
2757 options?: number | object
2758 ): void
2759
2760 /*************************************************************************
2761 * Trigonometry functions
2762 ************************************************************************/
2763
2764 /**
2765 * Calculate the inverse cosine of a value. For matrices, the function
2766 * is evaluated element wise.
2767 * @param x Function input
2768 * @returns The arc cosine of x
2769 */
2770 acos(x: number): number
2771 acos(x: BigNumber): BigNumber
2772 acos(x: Complex): Complex
2773 acos(x: MathArray): MathArray
2774 acos(x: Matrix): Matrix
2775
2776 /**
2777 * Calculate the hyperbolic arccos of a value, defined as acosh(x) =
2778 * ln(sqrt(x^2 - 1) + x). For matrices, the function is evaluated
2779 * element wise.
2780 * @param x Function input
2781 * @returns The hyperbolic arccosine of x
2782 */
2783 acosh(x: number): number
2784 acosh(x: BigNumber): BigNumber
2785 acosh(x: Complex): Complex
2786 acosh(x: MathArray): MathArray
2787 acosh(x: Matrix): Matrix
2788
2789 /**
2790 * Calculate the inverse cotangent of a value. For matrices, the
2791 * function is evaluated element wise.
2792 * @param x Function input
2793 * @returns The arc cotangent of x
2794 */
2795 acot(x: number): number
2796 acot(x: BigNumber): BigNumber
2797 acot(x: MathArray): MathArray
2798 acot(x: Matrix): Matrix
2799
2800 /**
2801 * Calculate the hyperbolic arccotangent of a value, defined as acoth(x)
2802 * = (ln((x+1)/x) + ln(x/(x-1))) / 2. For matrices, the function is
2803 * evaluated element wise.
2804 * @param x Function input
2805 * @returns The hyperbolic arccotangent of x
2806 */
2807 acoth(x: number): number
2808 acoth(x: BigNumber): BigNumber
2809 acoth(x: MathArray): MathArray
2810 acoth(x: Matrix): Matrix
2811
2812 /**
2813 * Calculate the inverse cosecant of a value. For matrices, the function
2814 * is evaluated element wise.
2815 * @param x Function input
2816 * @returns The arc cosecant of x
2817 */
2818 acsc(x: number): number
2819 acsc(x: BigNumber): BigNumber
2820 acsc(x: MathArray): MathArray
2821 acsc(x: Matrix): Matrix
2822
2823 /**
2824 * Calculate the hyperbolic arccosecant of a value, defined as acsch(x)
2825 * = ln(1/x + sqrt(1/x^2 + 1)). For matrices, the function is evaluated
2826 * element wise.
2827 * @param x Function input
2828 * @returns The hyperbolic arccosecant of x
2829 */
2830 acsch(x: number): number
2831 acsch(x: BigNumber): BigNumber
2832 acsch(x: MathArray): MathArray
2833 acsch(x: Matrix): Matrix
2834
2835 /**
2836 * Calculate the inverse secant of a value. For matrices, the function
2837 * is evaluated element wise.
2838 * @param x Function input
2839 * @returns The arc secant of x
2840 */
2841 asec(x: number): number
2842 asec(x: BigNumber): BigNumber
2843 asec(x: MathArray): MathArray
2844 asec(x: Matrix): Matrix
2845
2846 /**
2847 * Calculate the hyperbolic arcsecant of a value, defined as asech(x) =
2848 * ln(sqrt(1/x^2 - 1) + 1/x). For matrices, the function is evaluated
2849 * element wise.
2850 * @param x Function input
2851 * @returns The hyperbolic arcsecant of x
2852 */
2853 asech(x: number): number
2854 asech(x: BigNumber): BigNumber
2855 asech(x: MathArray): MathArray
2856 asech(x: Matrix): Matrix
2857
2858 /**
2859 * Calculate the inverse sine of a value. For matrices, the function is
2860 * evaluated element wise.
2861 * @param x Function input
2862 * @returns The arc sine of x
2863 */
2864 asin(x: number): number
2865 asin(x: BigNumber): BigNumber
2866 asin(x: Complex): Complex
2867 asin(x: MathArray): MathArray
2868 asin(x: Matrix): Matrix
2869
2870 /**
2871 * Calculate the hyperbolic arcsine of a value, defined as asinh(x) =
2872 * ln(x + sqrt(x^2 + 1)). For matrices, the function is evaluated
2873 * element wise.
2874 * @param x Function input
2875 * @returns The hyperbolic arcsine of x
2876 */
2877 asinh(x: number): number
2878 asinh(x: BigNumber): BigNumber
2879 asinh(x: MathArray): MathArray
2880 asinh(x: Matrix): Matrix
2881
2882 /**
2883 * Calculate the inverse tangent of a value. For matrices, the function
2884 * is evaluated element wise.
2885 * @param x Function input
2886 * @returns The arc tangent of x
2887 */
2888 atan(x: number): number
2889 atan(x: BigNumber): BigNumber
2890 atan(x: MathArray): MathArray
2891 atan(x: Matrix): Matrix
2892
2893 /**
2894 * Calculate the inverse tangent function with two arguments, y/x. By
2895 * providing two arguments, the right quadrant of the computed angle can
2896 * be determined. For matrices, the function is evaluated element wise.
2897 * @param x Function input
2898 * @returns Four quadrant inverse tangent
2899 */
2900 atan2(y: number, x: number): number
2901 atan2(y: MathCollection, x: MathCollection): MathCollection
2902
2903 /**
2904 * Calculate the hyperbolic arctangent of a value, defined as atanh(x) =
2905 * ln((1 + x)/(1 - x)) / 2. For matrices, the function is evaluated
2906 * element wise.
2907 * @param x Function input
2908 * @returns The hyperbolic arctangent of x
2909 */
2910 atanh(x: number): number
2911 atanh(x: BigNumber): BigNumber
2912 atanh(x: MathArray): MathArray
2913 atanh(x: Matrix): Matrix
2914
2915 /**
2916 * Calculate the cosine of a value. For matrices, the function is
2917 * evaluated element wise.
2918 * @param x Function input
2919 * @returns The cosine of x
2920 */
2921 cos(x: number | Unit): number
2922 cos(x: BigNumber): BigNumber
2923 cos(x: Complex): Complex
2924 cos(x: MathArray): MathArray
2925 cos(x: Matrix): Matrix
2926
2927 /**
2928 * Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2
2929 * * (exp(x) + exp(-x)). For matrices, the function is evaluated element
2930 * wise.
2931 * @param x Function input
2932 * @returns The hyperbolic cosine of x
2933 */
2934 cosh(x: number | Unit): number
2935 cosh(x: BigNumber): BigNumber
2936 cosh(x: Complex): Complex
2937 cosh(x: MathArray): MathArray
2938 cosh(x: Matrix): Matrix
2939
2940 /**
2941 * Calculate the cotangent of a value. cot(x) is defined as 1 / tan(x).
2942 * For matrices, the function is evaluated element wise.
2943 * @param x Function input
2944 * @returns The cotangent of x
2945 */
2946 cot(x: number | Unit): number
2947 cot(x: Complex): Complex
2948 cot(x: MathArray): MathArray
2949 cot(x: Matrix): Matrix
2950
2951 /**
2952 * Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1
2953 * / tanh(x). For matrices, the function is evaluated element wise.
2954 * @param x Function input
2955 * @returns The hyperbolic cotangent of x
2956 */
2957 coth(x: number | Unit): number
2958 coth(x: Complex): Complex
2959 coth(x: MathArray): MathArray
2960 coth(x: Matrix): Matrix
2961
2962 /**
2963 * Calculate the cosecant of a value, defined as csc(x) = 1/sin(x). For
2964 * matrices, the function is evaluated element wise.
2965 * @param x Function input
2966 * @returns The cosecant hof x
2967 */
2968 csc(x: number | Unit): number
2969 csc(x: Complex): Complex
2970 csc(x: MathArray): MathArray
2971 csc(x: Matrix): Matrix
2972
2973 /**
2974 * Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1
2975 * / sinh(x). For matrices, the function is evaluated element wise.
2976 * @param x Function input
2977 * @returns The hyperbolic cosecant of x
2978 */
2979 csch(x: number | Unit): number
2980 csch(x: Complex): Complex
2981 csch(x: MathArray): MathArray
2982 csch(x: Matrix): Matrix
2983
2984 /**
2985 * Calculate the secant of a value, defined as sec(x) = 1/cos(x). For
2986 * matrices, the function is evaluated element wise.
2987 * @param x Function input
2988 * @returns The secant of x
2989 */
2990 sec(x: number | Unit): number
2991 sec(x: Complex): Complex
2992 sec(x: MathArray): MathArray
2993 sec(x: Matrix): Matrix
2994
2995 /**
2996 * Calculate the hyperbolic secant of a value, defined as sech(x) = 1 /
2997 * cosh(x). For matrices, the function is evaluated element wise.
2998 * @param x Function input
2999 * @returns The hyperbolic secant of x
3000 */
3001 sech(x: number | Unit): number
3002 sech(x: Complex): Complex
3003 sech(x: MathArray): MathArray
3004 sech(x: Matrix): Matrix
3005
3006 /**
3007 * Calculate the sine of a value. For matrices, the function is
3008 * evaluated element wise.
3009 * @param x Function input
3010 * @returns The sine of x
3011 */
3012 sin(x: number | Unit): number
3013 sin(x: BigNumber): BigNumber
3014 sin(x: Complex): Complex
3015 sin(x: MathArray): MathArray
3016 sin(x: Matrix): Matrix
3017
3018 /**
3019 * Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 *
3020 * (exp(x) - exp(-x)). For matrices, the function is evaluated element
3021 * wise.
3022 * @param x Function input
3023 * @returns The hyperbolic sine of x
3024 */
3025 sinh(x: number | Unit): number
3026 sinh(x: BigNumber): BigNumber
3027 sinh(x: Complex): Complex
3028 sinh(x: MathArray): MathArray
3029 sinh(x: Matrix): Matrix
3030
3031 /**
3032 * Calculate the tangent of a value. tan(x) is equal to sin(x) / cos(x).
3033 * For matrices, the function is evaluated element wise.
3034 * @param x Function input
3035 * @returns The tangent of x
3036 */
3037 tan(x: number | Unit): number
3038 tan(x: BigNumber): BigNumber
3039 tan(x: Complex): Complex
3040 tan(x: MathArray): MathArray
3041 tan(x: Matrix): Matrix
3042
3043 /**
3044 * Calculate the hyperbolic tangent of a value, defined as tanh(x) =
3045 * (exp(2 * x) - 1) / (exp(2 * x) + 1). For matrices, the function is
3046 * evaluated element wise.
3047 * @param x Function input
3048 * @returns The hyperbolic tangent of x
3049 */
3050 tanh(x: number | Unit): number
3051 tanh(x: BigNumber): BigNumber
3052 tanh(x: Complex): Complex
3053 tanh(x: MathArray): MathArray
3054 tanh(x: Matrix): Matrix
3055
3056 /*************************************************************************
3057 * Unit functions
3058 ************************************************************************/
3059
3060 /**
3061 * Change the unit of a value. For matrices, the function is evaluated
3062 * element wise.
3063 * @param x The unit to be converted.
3064 * @param unit New unit. Can be a string like "cm" or a unit without
3065 * value.
3066 * @returns Value with changed, fixed unit
3067 */
3068 to(x: Unit | MathCollection, unit: Unit | string): Unit | MathCollection
3069
3070 /*************************************************************************
3071 * Utils
3072 ************************************************************************/
3073 isNumber(x: unknown): x is number
3074
3075 isBigNumber(x: unknown): x is BigNumber
3076
3077 isComplex(x: unknown): x is Complex
3078
3079 isFraction(x: unknown): x is Fraction
3080
3081 isUnit(x: unknown): x is Unit
3082
3083 isString(x: unknown): x is string
3084
3085 isArray: ArrayConstructor['isArray']
3086
3087 isMatrix(x: unknown): x is Matrix
3088
3089 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3090 isCollection(x: unknown): x is Matrix | any[]
3091
3092 isDenseMatrix(x: unknown): x is Matrix
3093
3094 isSparseMatrix(x: unknown): x is Matrix
3095
3096 isRange(x: unknown): boolean
3097
3098 isIndex(x: unknown): x is Index
3099
3100 isBoolean(x: unknown): x is boolean
3101
3102 isResultSet(x: unknown): boolean
3103
3104 isHelp(x: unknown): x is Help
3105
3106 isFunction(x: unknown): boolean
3107
3108 isDate(x: unknown): x is Date
3109
3110 isRegExp(x: unknown): x is RegExp
3111
3112 isObject(x: unknown): boolean
3113
3114 isNull(x: unknown): x is null
3115
3116 isUndefined(x: unknown): x is undefined
3117
3118 isAccessorNode(x: unknown): x is AccessorNode
3119
3120 isArrayNode(x: unknown): x is ArrayNode
3121
3122 isAssignmentNode(x: unknown): x is AssignmentNode
3123
3124 isBlockNode(x: unknown): x is BlockNode
3125
3126 isConditionalNode(x: unknown): x is ConditionalNode
3127
3128 isConstantNode(x: unknown): x is ConstantNode
3129
3130 isFunctionAssignmentNode(x: unknown): x is FunctionAssignmentNode
3131
3132 isFunctionNode(x: unknown): x is FunctionNode
3133
3134 isIndexNode(x: unknown): x is IndexNode
3135
3136 isNode(x: unknown): x is MathNodeCommon
3137
3138 isObjectNode(x: unknown): x is ObjectNode
3139
3140 isOperatorNode(
3141 x: unknown
3142 ): x is OperatorNode<OperatorNodeOp, OperatorNodeFn>
3143
3144 isParenthesisNode(x: unknown): x is ParenthesisNode
3145
3146 isRangeNode(x: unknown): x is RangeNode
3147
3148 isSymbolNode(x: unknown): x is SymbolNode
3149
3150 isChain(x: unknown): x is MathJsChain<unknown>
3151
3152 /*************************************************************************
3153 * Functions -> Utils
3154 ************************************************************************/
3155
3156 /**
3157 * Clone an object.
3158 * @param x Object to be cloned
3159 * @returns A clone of object x
3160 */
3161 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3162 clone<TType>(x: TType): TType
3163
3164 /**
3165 * Test whether a value is an numeric value. In case of a string,
3166 * true is returned if the string contains a numeric value.
3167 * @param x Value to be tested
3168 * @returns Returns true when x is a number, BigNumber, Fraction, Boolean, or a String containing number.
3169 * Returns false for other types.
3170 * Throws an error in case of unknown types.
3171 */
3172 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3173 hasNumericValue(x: any): boolean | boolean[]
3174
3175 /**
3176 * Test whether a value is an integer number. The function supports
3177 * number, BigNumber, and Fraction. The function is evaluated
3178 * element-wise in case of Array or Matrix input.
3179 * @param x Value to be tested
3180 * @returns Returns true when x contains a numeric, integer value.
3181 * Throws an error in case of an unknown data type.
3182 */
3183 isInteger(x: number | BigNumber | Fraction | MathCollection): boolean
3184
3185 /**
3186 * Test whether a value is NaN (not a number). The function supports
3187 * types number, BigNumber, Fraction, Unit and Complex. The function is
3188 * evaluated element-wise in case of Array or Matrix input.
3189 * @param x Value to be tested
3190 * @returns Returns true when x is NaN. Throws an error in case of an
3191 * unknown data type.
3192 */
3193 isNaN(x: number | BigNumber | Fraction | MathCollection | Unit): boolean
3194
3195 /**
3196 * Test whether a value is negative: smaller than zero. The function
3197 * supports types number, BigNumber, Fraction, and Unit. The function is
3198 * evaluated element-wise in case of Array or Matrix input.
3199 * @param x Value to be tested
3200 * @returns Returns true when x is larger than zero. Throws an error in
3201 * case of an unknown data type.
3202 */
3203 isNegative(
3204 x: number | BigNumber | Fraction | MathCollection | Unit
3205 ): boolean
3206
3207 /**
3208 * Test whether a value is an numeric value. The function is evaluated
3209 * element-wise in case of Array or Matrix input.
3210 * @param x Value to be tested
3211 * @returns Returns true when x is a number, BigNumber, Fraction, or
3212 * boolean. Returns false for other types. Throws an error in case of
3213 * unknown types.
3214 */
3215 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3216 isNumeric(x: any): x is number | BigNumber | Fraction | boolean
3217
3218 /**
3219 * Test whether a value is positive: larger than zero. The function
3220 * supports types number, BigNumber, Fraction, and Unit. The function is
3221 * evaluated element-wise in case of Array or Matrix input.
3222 * @param x Value to be tested
3223 * @returns Returns true when x is larger than zero. Throws an error in
3224 * case of an unknown data type.
3225 */
3226 isPositive(
3227 x: number | BigNumber | Fraction | MathCollection | Unit
3228 ): boolean
3229
3230 /**
3231 * Test whether a value is prime: has no divisors other than itself and
3232 * one. The function supports type number, bignumber. The function is
3233 * evaluated element-wise in case of Array or Matrix input.
3234 * @param x Value to be tested
3235 * @returns Returns true when x is larger than zero. Throws an error in
3236 * case of an unknown data type.
3237 */
3238 isPrime(x: number | BigNumber | MathCollection): boolean
3239
3240 /**
3241 * Test whether a value is zero. The function can check for zero for
3242 * types number, BigNumber, Fraction, Complex, and Unit. The function is
3243 * evaluated element-wise in case of Array or Matrix input.
3244 * @param x Value to be tested
3245 * @returns Returns true when x is zero. Throws an error in case of an
3246 * unknown data type.
3247 */
3248 isZero(
3249 x: number | BigNumber | Fraction | MathCollection | Unit | Complex
3250 ): boolean
3251
3252 /**
3253 * Determine the type of a variable.
3254 * @param x The variable for which to test the type
3255 * @returns Returns the name of the type. Primitive types are lower
3256 * case, non-primitive types are upper-camel-case. For examplenumber’,
3257 * ‘string’, ‘Array’, ‘Date’.
3258 */
3259 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3260 typeOf(x: any): string
3261
3262 /**
3263 * Import functions from an object or a module
3264 * To avoid errors when using one of the imported functions extend module like this:
3265 *
3266 * @example
3267 * // imported_math_functions.ts
3268 * declare module 'mathjs' {
3269 * interface MathJsStatic {
3270 * hello(a: number): number;
3271 * }
3272 * }
3273 *
3274 * @param object An object with functions to be imported.
3275 * @param options An object with import options.
3276 */
3277 import(object: ImportObject | ImportObject[], options?: ImportOptions): void
3278 }
3279
3280 /*************************************************************************
3281 * Factory and Dependencies
3282 ************************************************************************/
3283 interface FactoryDependencies {
3284 create: (
3285 factories: FactoryFunctionMap,
3286 config?: ConfigOptions
3287 ) => MathJsStatic
3288 factory: <T>(
3289 name: string,
3290 dependencies: MathJsFunctionName[],
3291 create: (injected: Partial<MathJsStatic>) => T,
3292 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3293 meta?: any
3294 ) => FactoryFunction<T>
3295 all: FactoryFunctionMap
3296
3297 typedDependencies: FactoryFunctionMap
3298 ResultSetDependencies: FactoryFunctionMap
3299 BigNumberDependencies: FactoryFunctionMap
3300 ComplexDependencies: FactoryFunctionMap
3301 FractionDependencies: FactoryFunctionMap
3302 RangeDependencies: FactoryFunctionMap
3303 MatrixDependencies: FactoryFunctionMap
3304 DenseMatrixDependencies: FactoryFunctionMap
3305 cloneDependencies: FactoryFunctionMap
3306 isIntegerDependencies: FactoryFunctionMap
3307 isNegativeDependencies: FactoryFunctionMap
3308 isNumericDependencies: FactoryFunctionMap
3309 hasNumericValueDependencies: FactoryFunctionMap
3310 isPositiveDependencies: FactoryFunctionMap
3311 isZeroDependencies: FactoryFunctionMap
3312 isNaNDependencies: FactoryFunctionMap
3313 typeOfDependencies: FactoryFunctionMap
3314 typeofDependencies: FactoryFunctionMap
3315 equalScalarDependencies: FactoryFunctionMap
3316 SparseMatrixDependencies: FactoryFunctionMap
3317 numberDependencies: FactoryFunctionMap
3318 stringDependencies: FactoryFunctionMap
3319 booleanDependencies: FactoryFunctionMap
3320 bignumberDependencies: FactoryFunctionMap
3321 complexDependencies: FactoryFunctionMap
3322 fractionDependencies: FactoryFunctionMap
3323 matrixDependencies: FactoryFunctionMap
3324 splitUnitDependencies: FactoryFunctionMap
3325 unaryMinusDependencies: FactoryFunctionMap
3326 unaryPlusDependencies: FactoryFunctionMap
3327 absDependencies: FactoryFunctionMap
3328 applyDependencies: FactoryFunctionMap
3329 addScalarDependencies: FactoryFunctionMap
3330 cbrtDependencies: FactoryFunctionMap
3331 ceilDependencies: FactoryFunctionMap
3332 cubeDependencies: FactoryFunctionMap
3333 expDependencies: FactoryFunctionMap
3334 expm1Dependencies: FactoryFunctionMap
3335 fixDependencies: FactoryFunctionMap
3336 floorDependencies: FactoryFunctionMap
3337 gcdDependencies: FactoryFunctionMap
3338 lcmDependencies: FactoryFunctionMap
3339 log10Dependencies: FactoryFunctionMap
3340 log2Dependencies: FactoryFunctionMap
3341 modDependencies: FactoryFunctionMap
3342 multiplyScalarDependencies: FactoryFunctionMap
3343 multiplyDependencies: FactoryFunctionMap
3344 nthRootDependencies: FactoryFunctionMap
3345 signDependencies: FactoryFunctionMap
3346 sqrtDependencies: FactoryFunctionMap
3347 squareDependencies: FactoryFunctionMap
3348 subtractDependencies: FactoryFunctionMap
3349 xgcdDependencies: FactoryFunctionMap
3350 dotMultiplyDependencies: FactoryFunctionMap
3351 bitAndDependencies: FactoryFunctionMap
3352 bitNotDependencies: FactoryFunctionMap
3353 bitOrDependencies: FactoryFunctionMap
3354 bitXorDependencies: FactoryFunctionMap
3355 argDependencies: FactoryFunctionMap
3356 conjDependencies: FactoryFunctionMap
3357 imDependencies: FactoryFunctionMap
3358 reDependencies: FactoryFunctionMap
3359 notDependencies: FactoryFunctionMap
3360 orDependencies: FactoryFunctionMap
3361 xorDependencies: FactoryFunctionMap
3362 concatDependencies: FactoryFunctionMap
3363 columnDependencies: FactoryFunctionMap
3364 crossDependencies: FactoryFunctionMap
3365 diagDependencies: FactoryFunctionMap
3366 eyeDependencies: FactoryFunctionMap
3367 filterDependencies: FactoryFunctionMap
3368 flattenDependencies: FactoryFunctionMap
3369 forEachDependencies: FactoryFunctionMap
3370 getMatrixDataTypeDependencies: FactoryFunctionMap
3371 identityDependencies: FactoryFunctionMap
3372 kronDependencies: FactoryFunctionMap
3373 mapDependencies: FactoryFunctionMap
3374 onesDependencies: FactoryFunctionMap
3375 rangeDependencies: FactoryFunctionMap
3376 reshapeDependencies: FactoryFunctionMap
3377 resizeDependencies: FactoryFunctionMap
3378 rowDependencies: FactoryFunctionMap
3379 sizeDependencies: FactoryFunctionMap
3380 squeezeDependencies: FactoryFunctionMap
3381 subsetDependencies: FactoryFunctionMap
3382 transposeDependencies: FactoryFunctionMap
3383 ctransposeDependencies: FactoryFunctionMap
3384 zerosDependencies: FactoryFunctionMap
3385 erfDependencies: FactoryFunctionMap
3386 modeDependencies: FactoryFunctionMap
3387 prodDependencies: FactoryFunctionMap
3388 formatDependencies: FactoryFunctionMap
3389 printDependencies: FactoryFunctionMap
3390 toDependencies: FactoryFunctionMap
3391 isPrimeDependencies: FactoryFunctionMap
3392 numericDependencies: FactoryFunctionMap
3393 divideScalarDependencies: FactoryFunctionMap
3394 powDependencies: FactoryFunctionMap
3395 roundDependencies: FactoryFunctionMap
3396 logDependencies: FactoryFunctionMap
3397 log1pDependencies: FactoryFunctionMap
3398 nthRootsDependencies: FactoryFunctionMap
3399 dotPowDependencies: FactoryFunctionMap
3400 dotDivideDependencies: FactoryFunctionMap
3401 lsolveDependencies: FactoryFunctionMap
3402 usolveDependencies: FactoryFunctionMap
3403 leftShiftDependencies: FactoryFunctionMap
3404 rightArithShiftDependencies: FactoryFunctionMap
3405 rightLogShiftDependencies: FactoryFunctionMap
3406 andDependencies: FactoryFunctionMap
3407 compareDependencies: FactoryFunctionMap
3408 compareNaturalDependencies: FactoryFunctionMap
3409 compareTextDependencies: FactoryFunctionMap
3410 equalDependencies: FactoryFunctionMap
3411 equalTextDependencies: FactoryFunctionMap
3412 smallerDependencies: FactoryFunctionMap
3413 smallerEqDependencies: FactoryFunctionMap
3414 largerDependencies: FactoryFunctionMap
3415 largerEqDependencies: FactoryFunctionMap
3416 deepEqualDependencies: FactoryFunctionMap
3417 unequalDependencies: FactoryFunctionMap
3418 partitionSelectDependencies: FactoryFunctionMap
3419 sortDependencies: FactoryFunctionMap
3420 maxDependencies: FactoryFunctionMap
3421 minDependencies: FactoryFunctionMap
3422 ImmutableDenseMatrixDependencies: FactoryFunctionMap
3423 IndexDependencies: FactoryFunctionMap
3424 FibonacciHeapDependencies: FactoryFunctionMap
3425 SpaDependencies: FactoryFunctionMap
3426 UnitDependencies: FactoryFunctionMap
3427 unitDependencies: FactoryFunctionMap
3428 sparseDependencies: FactoryFunctionMap
3429 createUnitDependencies: FactoryFunctionMap
3430 acosDependencies: FactoryFunctionMap
3431 acoshDependencies: FactoryFunctionMap
3432 acotDependencies: FactoryFunctionMap
3433 acothDependencies: FactoryFunctionMap
3434 acscDependencies: FactoryFunctionMap
3435 acschDependencies: FactoryFunctionMap
3436 asecDependencies: FactoryFunctionMap
3437 asechDependencies: FactoryFunctionMap
3438 asinDependencies: FactoryFunctionMap
3439 asinhDependencies: FactoryFunctionMap
3440 atanDependencies: FactoryFunctionMap
3441 atan2Dependencies: FactoryFunctionMap
3442 atanhDependencies: FactoryFunctionMap
3443 cosDependencies: FactoryFunctionMap
3444 coshDependencies: FactoryFunctionMap
3445 cotDependencies: FactoryFunctionMap
3446 cothDependencies: FactoryFunctionMap
3447 cscDependencies: FactoryFunctionMap
3448 cschDependencies: FactoryFunctionMap
3449 secDependencies: FactoryFunctionMap
3450 sechDependencies: FactoryFunctionMap
3451 sinDependencies: FactoryFunctionMap
3452 sinhDependencies: FactoryFunctionMap
3453 tanDependencies: FactoryFunctionMap
3454 tanhDependencies: FactoryFunctionMap
3455 setCartesianDependencies: FactoryFunctionMap
3456 setDifferenceDependencies: FactoryFunctionMap
3457 setDistinctDependencies: FactoryFunctionMap
3458 setIntersectDependencies: FactoryFunctionMap
3459 setIsSubsetDependencies: FactoryFunctionMap
3460 setMultiplicityDependencies: FactoryFunctionMap
3461 setPowersetDependencies: FactoryFunctionMap
3462 setSizeDependencies: FactoryFunctionMap
3463 setSymDifferenceDependencies: FactoryFunctionMap
3464 setUnionDependencies: FactoryFunctionMap
3465 addDependencies: FactoryFunctionMap
3466 hypotDependencies: FactoryFunctionMap
3467 normDependencies: FactoryFunctionMap
3468 dotDependencies: FactoryFunctionMap
3469 traceDependencies: FactoryFunctionMap
3470 indexDependencies: FactoryFunctionMap
3471 NodeDependencies: FactoryFunctionMap
3472 AccessorNodeDependencies: FactoryFunctionMap
3473 ArrayNodeDependencies: FactoryFunctionMap
3474 AssignmentNodeDependencies: FactoryFunctionMap
3475 BlockNodeDependencies: FactoryFunctionMap
3476 ConditionalNodeDependencies: FactoryFunctionMap
3477 ConstantNodeDependencies: FactoryFunctionMap
3478 FunctionAssignmentNodeDependencies: FactoryFunctionMap
3479 IndexNodeDependencies: FactoryFunctionMap
3480 ObjectNodeDependencies: FactoryFunctionMap
3481 OperatorNodeDependencies: FactoryFunctionMap
3482 ParenthesisNodeDependencies: FactoryFunctionMap
3483 RangeNodeDependencies: FactoryFunctionMap
3484 RelationalNodeDependencies: FactoryFunctionMap
3485 SymbolNodeDependencies: FactoryFunctionMap
3486 FunctionNodeDependencies: FactoryFunctionMap
3487 parseDependencies: FactoryFunctionMap
3488 compileDependencies: FactoryFunctionMap
3489 evaluateDependencies: FactoryFunctionMap
3490 evalDependencies: FactoryFunctionMap
3491 ParserDependencies: FactoryFunctionMap
3492 parserDependencies: FactoryFunctionMap
3493 lupDependencies: FactoryFunctionMap
3494 qrDependencies: FactoryFunctionMap
3495 sluDependencies: FactoryFunctionMap
3496 lusolveDependencies: FactoryFunctionMap
3497 HelpDependencies: FactoryFunctionMap
3498 ChainDependencies: FactoryFunctionMap
3499 helpDependencies: FactoryFunctionMap
3500 chainDependencies: FactoryFunctionMap
3501 detDependencies: FactoryFunctionMap
3502 invDependencies: FactoryFunctionMap
3503 expmDependencies: FactoryFunctionMap
3504 sqrtmDependencies: FactoryFunctionMap
3505 divideDependencies: FactoryFunctionMap
3506 distanceDependencies: FactoryFunctionMap
3507 intersectDependencies: FactoryFunctionMap
3508 sumDependencies: FactoryFunctionMap
3509 meanDependencies: FactoryFunctionMap
3510 medianDependencies: FactoryFunctionMap
3511 madDependencies: FactoryFunctionMap
3512 varianceDependencies: FactoryFunctionMap
3513 varDependencies: FactoryFunctionMap
3514 quantileSeqDependencies: FactoryFunctionMap
3515 stdDependencies: FactoryFunctionMap
3516 combinationsDependencies: FactoryFunctionMap
3517 gammaDependencies: FactoryFunctionMap
3518 factorialDependencies: FactoryFunctionMap
3519 kldivergenceDependencies: FactoryFunctionMap
3520 multinomialDependencies: FactoryFunctionMap
3521 permutationsDependencies: FactoryFunctionMap
3522 pickRandomDependencies: FactoryFunctionMap
3523 randomDependencies: FactoryFunctionMap
3524 randomIntDependencies: FactoryFunctionMap
3525 stirlingS2Dependencies: FactoryFunctionMap
3526 bellNumbersDependencies: FactoryFunctionMap
3527 catalanDependencies: FactoryFunctionMap
3528 compositionDependencies: FactoryFunctionMap
3529 simplifyDependencies: FactoryFunctionMap
3530 derivativeDependencies: FactoryFunctionMap
3531 rationalizeDependencies: FactoryFunctionMap
3532 reviverDependencies: FactoryFunctionMap
3533 eDependencies: FactoryFunctionMap
3534 EDependencies: FactoryFunctionMap
3535 falseDependencies: FactoryFunctionMap
3536 iDependencies: FactoryFunctionMap
3537 InfinityDependencies: FactoryFunctionMap
3538 LN10Dependencies: FactoryFunctionMap
3539 LN2Dependencies: FactoryFunctionMap
3540 LOG10EDependencies: FactoryFunctionMap
3541 LOG2EDependencies: FactoryFunctionMap
3542 NaNDependencies: FactoryFunctionMap
3543 nullDependencies: FactoryFunctionMap
3544 phiDependencies: FactoryFunctionMap
3545 piDependencies: FactoryFunctionMap
3546 PIDependencies: FactoryFunctionMap
3547 SQRT1_2Dependencies: FactoryFunctionMap
3548 SQRT2Dependencies: FactoryFunctionMap
3549 tauDependencies: FactoryFunctionMap
3550 trueDependencies: FactoryFunctionMap
3551 versionDependencies: FactoryFunctionMap
3552 atomicMassDependencies: FactoryFunctionMap
3553 avogadroDependencies: FactoryFunctionMap
3554 bohrMagnetonDependencies: FactoryFunctionMap
3555 bohrRadiusDependencies: FactoryFunctionMap
3556 boltzmannDependencies: FactoryFunctionMap
3557 classicalElectronRadiusDependencies: FactoryFunctionMap
3558 conductanceQuantumDependencies: FactoryFunctionMap
3559 coulombDependencies: FactoryFunctionMap
3560 deuteronMassDependencies: FactoryFunctionMap
3561 efimovFactorDependencies: FactoryFunctionMap
3562 electricConstantDependencies: FactoryFunctionMap
3563 electronMassDependencies: FactoryFunctionMap
3564 elementaryChargeDependencies: FactoryFunctionMap
3565 faradayDependencies: FactoryFunctionMap
3566 fermiCouplingDependencies: FactoryFunctionMap
3567 fineStructureDependencies: FactoryFunctionMap
3568 firstRadiationDependencies: FactoryFunctionMap
3569 gasConstantDependencies: FactoryFunctionMap
3570 gravitationConstantDependencies: FactoryFunctionMap
3571 gravityDependencies: FactoryFunctionMap
3572 hartreeEnergyDependencies: FactoryFunctionMap
3573 inverseConductanceQuantumDependencies: FactoryFunctionMap
3574 klitzingDependencies: FactoryFunctionMap
3575 loschmidtDependencies: FactoryFunctionMap
3576 magneticConstantDependencies: FactoryFunctionMap
3577 magneticFluxQuantumDependencies: FactoryFunctionMap
3578 molarMassDependencies: FactoryFunctionMap
3579 molarMassC12Dependencies: FactoryFunctionMap
3580 molarPlanckConstantDependencies: FactoryFunctionMap
3581 molarVolumeDependencies: FactoryFunctionMap
3582 neutronMassDependencies: FactoryFunctionMap
3583 nuclearMagnetonDependencies: FactoryFunctionMap
3584 planckChargeDependencies: FactoryFunctionMap
3585 planckConstantDependencies: FactoryFunctionMap
3586 planckLengthDependencies: FactoryFunctionMap
3587 planckMassDependencies: FactoryFunctionMap
3588 planckTemperatureDependencies: FactoryFunctionMap
3589 planckTimeDependencies: FactoryFunctionMap
3590 protonMassDependencies: FactoryFunctionMap
3591 quantumOfCirculationDependencies: FactoryFunctionMap
3592 reducedPlanckConstantDependencies: FactoryFunctionMap
3593 rydbergDependencies: FactoryFunctionMap
3594 sackurTetrodeDependencies: FactoryFunctionMap
3595 secondRadiationDependencies: FactoryFunctionMap
3596 speedOfLightDependencies: FactoryFunctionMap
3597 stefanBoltzmannDependencies: FactoryFunctionMap
3598 thomsonCrossSectionDependencies: FactoryFunctionMap
3599 vacuumImpedanceDependencies: FactoryFunctionMap
3600 weakMixingAngleDependencies: FactoryFunctionMap
3601 wienDisplacementDependencies: FactoryFunctionMap
3602 applyTransformDependencies: FactoryFunctionMap
3603 columnTransformDependencies: FactoryFunctionMap
3604 filterTransformDependencies: FactoryFunctionMap
3605 forEachTransformDependencies: FactoryFunctionMap
3606 indexTransformDependencies: FactoryFunctionMap
3607 mapTransformDependencies: FactoryFunctionMap
3608 maxTransformDependencies: FactoryFunctionMap
3609 meanTransformDependencies: FactoryFunctionMap
3610 minTransformDependencies: FactoryFunctionMap
3611 rangeTransformDependencies: FactoryFunctionMap
3612 rowTransformDependencies: FactoryFunctionMap
3613 subsetTransformDependencies: FactoryFunctionMap
3614 concatTransformDependencies: FactoryFunctionMap
3615 stdTransformDependencies: FactoryFunctionMap
3616 sumTransformDependencies: FactoryFunctionMap
3617 varianceTransformDependencies: FactoryFunctionMap
3618 }
3619
3620 interface Matrix {
3621 type: string
3622 storage(): string
3623 datatype(): string
3624 create(data: MathArray, datatype?: string): void
3625 density(): number
3626 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3627 subset(index: Index, replacement?: any, defaultValue?: any): Matrix
3628 apply(
3629 dim: number,
3630 callback: (array: MathCollection) => number
3631 ): Matrix | MathArray
3632 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3633 get(index: number[]): any
3634 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3635 set(index: number[], value: any, defaultValue?: number | string): Matrix
3636 resize(size: MathCollection, defaultValue?: number | string): Matrix
3637 clone(): Matrix
3638 size(): number[]
3639 map(
3640 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3641 callback: (a: any, b: number, c: Matrix) => any,
3642 skipZeros?: boolean
3643 ): Matrix
3644 forEach(
3645 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3646 callback: (a: any, b: number, c: Matrix) => void,
3647 skipZeros?: boolean
3648 ): void
3649 toArray(): MathArray
3650 valueOf(): MathArray
3651 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3652 format(options?: FormatOptions | number | ((value: any) => string)): string
3653 toString(): string
3654 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3655 toJSON(): any
3656 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3657 diagonal(k?: number | BigNumber): any[]
3658 swapRows(i: number, j: number): Matrix
3659 }
3660
3661 interface MatrixCtor {
3662 new (): Matrix
3663 }
3664
3665 // eslint-disable-next-line @typescript-eslint/no-empty-interface
3666 interface BigNumber extends Decimal {}
3667
3668 interface Fraction {
3669 s: number
3670 n: number
3671 d: number
3672 }
3673
3674 interface Complex {
3675 re: number
3676 im: number
3677 clone(): Complex
3678 equals(other: Complex): boolean
3679 format(precision?: number): string
3680 fromJSON(json: object): Complex
3681 fromPolar(polar: object): Complex
3682 fromPolar(r: number, phi: number): Complex
3683 toJSON(): object
3684 toPolar(): PolarCoordinates
3685 toString(): string
3686 compare(a: Complex, b: Complex): number
3687 }
3688
3689 interface PolarCoordinates {
3690 r: number
3691 phi: number
3692 }
3693
3694 interface MathJSON {
3695 mathjs?: string
3696 value: number
3697 unit: string
3698 fixPrefix?: boolean
3699 }
3700
3701 interface UnitComponent {
3702 power: number
3703 prefix: string
3704 unit: {
3705 name: string
3706 base: {
3707 dimensions: number[]
3708 key: string
3709 }
3710 prefixes: Record<string, UnitPrefix>
3711 value: number
3712 offset: number
3713 dimensions: number[]
3714 }
3715 }
3716
3717 interface UnitPrefix {
3718 name: string
3719 value: number
3720 scientific: boolean
3721 }
3722
3723 interface Unit {
3724 valueOf(): string
3725 clone(): Unit
3726 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3727 hasBase(base: any): boolean
3728 equalBase(unit: Unit): boolean
3729 equals(unit: Unit): boolean
3730 multiply(unit: Unit): Unit
3731 divide(unit: Unit): Unit
3732 pow(unit: Unit): Unit
3733 abs(unit: Unit): Unit
3734 to(unit: string): Unit
3735 toNumber(unit?: string): number
3736 toNumeric(unit?: string): number | Fraction | BigNumber
3737 toSI(): Unit
3738 toString(): string
3739 toJSON(): MathJSON
3740 formatUnits(): string
3741 format(options: FormatOptions): string
3742 simplify(): Unit
3743 splitUnit(parts: ReadonlyArray<string | Unit>): Unit[]
3744
3745 units: UnitComponent[]
3746 dimensions: number[]
3747 value: number
3748 fixPrefix: boolean
3749 skipAutomaticSimplification: true
3750 }
3751
3752 interface CreateUnitOptions {
3753 prefixes?: 'none' | 'short' | 'long' | 'binary_short' | 'binary_long'
3754 aliases?: string[]
3755 offset?: number
3756 override?: boolean
3757 }
3758
3759 interface SimplifyOptions {
3760 /** A boolean which is `true` by default. */
3761 exactFractions?: boolean
3762 /**
3763 * When `exactFractions` is true, a fraction will be returned only
3764 * when both numerator and denominator are smaller than `fractionsLimit`.
3765 * Default value is 10000.
3766 */
3767 fractionsLimit?: number
3768 }
3769
3770 type SimplifyRule =
3771 | { l: string; r: string }
3772 | string
3773 | ((node: MathNode) => MathNode)
3774
3775 interface Simplify {
3776 (
3777 expr: MathNode | string,
3778 rules?: SimplifyRule[],
3779 scope?: object,
3780 options?: SimplifyOptions
3781 ): MathNode
3782 (
3783 expr: MathNode | string,
3784 scope?: object,
3785 options?: SimplifyOptions
3786 ): MathNode
3787
3788 rules: SimplifyRule[]
3789 }
3790
3791 interface UnitDefinition {
3792 definition?: string | Unit
3793 prefixes?: string
3794 offset?: number
3795 aliases?: string[]
3796 }
3797
3798 // eslint-disable-next-line @typescript-eslint/no-empty-interface
3799 interface Index {}
3800
3801 interface EvalFunction {
3802 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3803 evaluate(scope?: any): any
3804 }
3805
3806 interface MathNodeCommon {
3807 isNode: true
3808 comment: string
3809 type:
3810 | 'AccessorNode'
3811 | 'ArrayNode'
3812 | 'AssignmentNode'
3813 | 'BlockNode'
3814 | 'ConditionalNode'
3815 | 'ConstantNode'
3816 | 'FunctionAssignmentNode'
3817 | 'FunctionNode'
3818 | 'IndexNode'
3819 | 'ObjectNode'
3820 | 'OperatorNode'
3821 | 'ParenthesisNode'
3822 | 'RangeNode'
3823 | 'RelationalNode'
3824 | 'SymbolNode'
3825
3826 isUpdateNode?: boolean
3827
3828 /**
3829 * Create a shallow clone of the node. The node itself is cloned, its
3830 * childs are not cloned.
3831 */
3832 clone(): this
3833 /**
3834 * Create a deep clone of the node. Both the node as well as all its
3835 * childs are cloned recursively.
3836 */
3837 cloneDeep(): this
3838 /**
3839 * Compile an expression into optimized JavaScript code. compile returns
3840 * an object with a function evaluate([scope]) to evaluate. Example:
3841 */
3842 compile(): EvalFunction
3843 /**
3844 * Compile and eval an expression, this is the equivalent of doing
3845 * node.compile().evaluate(scope). Example:
3846 */
3847 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3848 evaluate(expr?: any): any
3849 /**
3850 * Test whether this node equals an other node. Does a deep comparison
3851 * of the values of both nodes.
3852 */
3853 equals(other: MathNode): boolean
3854 /**
3855 *
3856 * Filter nodes in an expression tree. The callback function is called
3857 * as callback(node: MathNode, path: string, parent: MathNode) : boolean
3858 * for every node in the tree, and must return a boolean. The function
3859 * filter returns an array with nodes for which the test returned true.
3860 * Parameter path is a string containing a relative JSON Path.
3861 *
3862 * Example:
3863 *
3864 * ```
3865 * var node = math.parse('x^2 + x/4 + 3*y');
3866 * var filtered = node.filter(function (node) {
3867 * return node.isSymbolMathNode && node.name == 'x';
3868 * });
3869 * // returns an array with two entries: two SymbolMathNodes 'x'
3870 * ```
3871 *
3872 * The callback function is called as callback(node: MathNode, path:
3873 * string, parent: MathNode) : boolean for every node in the tree, and
3874 * must return a boolean. The function filter returns an array with
3875 * nodes for which the test returned true. Parameter path is a string
3876 * containing a relative JSON Path.
3877 * @return Returns an array with nodes for which test returned true
3878 */
3879 filter(
3880 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3881 callback: (node: MathNode, path: string, parent: MathNode) => any
3882 ): MathNode[]
3883
3884 /**
3885 * [forEach description]
3886 */
3887 forEach(
3888 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3889 callback: (node: MathNode, path: string, parent: MathNode) => any
3890 ): MathNode[]
3891
3892 /**
3893 * Transform a node. Creates a new MathNode having its child's be the
3894 * results of calling the provided callback function for each of the
3895 * child's of the original node. The callback function is called as
3896 * `callback(child: MathNode, path: string, parent: MathNode)` and must
3897 * return a MathNode. Parameter path is a string containing a relative
3898 * JSON Path.
3899 *
3900 *
3901 * See also transform, which is a recursive version of map.
3902 */
3903 map(
3904 callback: (node: MathNode, path: string, parent: MathNode) => MathNode
3905 ): MathNode
3906
3907 /**
3908 * Get a HTML representation of the parsed expression.
3909 */
3910 toHTML(options?: object): string
3911
3912 /**
3913 * Get a string representation of the parsed expression. This is not
3914 * exactly the same as the original input.
3915 */
3916 toString(options?: object): string
3917
3918 /**
3919 * Get a LaTeX representation of the expression.
3920 */
3921 toTex(options?: object): string
3922
3923 /**
3924 * Recursively transform an expression tree via a transform function.
3925 * Similar to Array.map, but recursively executed on all nodes in the
3926 * expression tree. The callback function is a mapping function
3927 * accepting a node, and returning a replacement for the node or the
3928 * original node. Function callback is called as callback(node:
3929 * MathNode, path: string, parent: MathNode) for every node in the tree,
3930 * and must return a MathNode. Parameter path is a string containing a
3931 * relative JSON Path.
3932 *
3933 * For example, to replace all nodes of type SymbolMathNode having name
3934 * ‘xwith a ConstantMathNode with value 3:
3935 * ```js
3936 * var node = math.parse('x^2 + 5*x');
3937 * var transformed = node.transform(function (node, path, parent) {
3938 * if (node.SymbolMathNode && node.name == 'x') {
3939 * return new math.expression.node.ConstantMathNode(3);
3940 * }
3941 * else {
3942 * return node;
3943 * }
3944 * });
3945 * transformed.toString(); // returns '(3 ^ 2) + (5 * 3)'
3946 * ```
3947 */
3948 transform(
3949 callback: (node: MathNode, path: string, parent: MathNode) => MathNode
3950 ): MathNode
3951
3952 /**
3953 * `traverse(callback)`
3954 *
3955 * Recursively traverse all nodes in a node tree. Executes given
3956 * callback for this node and each of its child nodes. Similar to
3957 * Array.forEach, except recursive. The callback function is a mapping
3958 * function accepting a node, and returning a replacement for the node
3959 * or the original node. Function callback is called as callback(node:
3960 * MathNode, path: string, parent: MathNode) for every node in the tree.
3961 * Parameter path is a string containing a relative JSON Path. Example:
3962 *
3963 * ```
3964 * var node = math.parse('3 * x + 2');
3965 * node.traverse(function (node, path, parent) {
3966 * switch (node.type) {
3967 * case 'OperatorMathNode': console.log(node.type, node.op); break;
3968 * case 'ConstantMathNode': console.log(node.type, node.value); break;
3969 * case 'SymbolMathNode': console.log(node.type, node.name); break;
3970 * default: console.log(node.type);
3971 * }
3972 * });
3973 * // outputs:
3974 * // OperatorMathNode +
3975 * // OperatorMathNode *
3976 * // ConstantMathNode 3
3977 * // SymbolMathNode x
3978 * // ConstantMathNode 2
3979 * ```
3980 */
3981 traverse(
3982 callback: (node: MathNode, path: string, parent: MathNode) => void
3983 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3984 ): any
3985 }
3986
3987 interface Parser {
3988 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3989 evaluate(expr: string | string[]): any
3990 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3991 get(variable: string): any
3992 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3993 getAll(): { [key: string]: any }
3994 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3995 set: (variable: string, value: any) => void
3996 clear: () => void
3997 }
3998
3999 interface Distribution {
4000 // eslint-disable-next-line @typescript-eslint/no-explicit-any
4001 random(size: any, min?: any, max?: any): any
4002 // eslint-disable-next-line @typescript-eslint/no-explicit-any
4003 randomInt(min: any, max?: any): any
4004 // eslint-disable-next-line @typescript-eslint/no-explicit-any
4005 pickRandom(array: any): any
4006 }
4007
4008 interface FormatOptions {
4009 /**
4010 * Number notation. Choose from: 'fixed' Always use regular number
4011 * notation. For example '123.40' and '14000000' 'exponential' Always
4012 * use exponential notation. For example '1.234e+2' and '1.4e+7' 'auto'
4013 * (default) Regular number notation for numbers having an absolute
4014 * value between lower and upper bounds, and uses exponential notation
4015 * elsewhere. Lower bound is included, upper bound is excluded. For
4016 * example '123.4' and '1.4e7'.
4017 */
4018 notation?: 'fixed' | 'exponential' | 'engineering' | 'auto'
4019
4020 /**
4021 * A number between 0 and 16 to round the digits of the number. In case
4022 * of notations 'exponential' and 'auto', precision defines the total
4023 * number of significant digits returned and is undefined by default. In
4024 * case of notation 'fixed', precision defines the number of significant
4025 * digits after the decimal point, and is 0 by default.
4026 */
4027 precision?: number
4028
4029 /**
4030 * Exponent determining the lower boundary for formatting a value with
4031 * an exponent when notation='auto. Default value is -3.
4032 */
4033 lowerExp?: number
4034
4035 /**
4036 * Exponent determining the upper boundary for formatting a value with
4037 * an exponent when notation='auto. Default value is 5.
4038 */
4039 upperExp?: number
4040
4041 /**
4042 * Available values: 'ratio' (default) or 'decimal'. For example
4043 * format(fraction(1, 3)) will output '1/3' when 'ratio' is configured,
4044 * and will output 0.(3) when 'decimal' is configured.
4045 */
4046 fraction?: string
4047 }
4048
4049 interface Help {
4050 toString(): string
4051 toJSON(): string
4052 }
4053
4054 interface ConfigOptions {
4055 epsilon?: number
4056 matrix?: 'Matrix' | 'Array'
4057 number?: 'number' | 'BigNumber' | 'Fraction'
4058 precision?: number
4059 predictable?: boolean
4060 randomSeed?: string | null
4061 }
4062
4063 interface MathJsChain<TValue> {
4064 // eslint-disable-next-line @typescript-eslint/no-explicit-any
4065 done(): TValue
4066
4067 /*************************************************************************
4068 * Construction functions
4069 ************************************************************************/
4070
4071 /**
4072 * Create a BigNumber, which can store numbers with arbitrary precision.
4073 * When a matrix is provided, all elements will be converted to
4074 * BigNumber.
4075 */
4076 bignumber(
4077 this: MathJsChain<
4078 number | string | Fraction | BigNumber | boolean | Fraction | null
4079 >
4080 ): MathJsChain<BigNumber>
4081 bignumber<T extends MathCollection>(this: MathJsChain<T>): MathJsChain<T>
4082
4083 /**
4084 * Create a boolean or convert a string or number to a boolean. In case
4085 * of a number, true is returned for non-zero numbers, and false in case
4086 * of zero. Strings can be 'true' or 'false', or can contain a number.
4087 * When value is a matrix, all elements will be converted to boolean.
4088 */
4089 boolean(
4090 this: MathJsChain<string | number | boolean | null>
4091 ): MathJsChain<boolean>
4092 boolean(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
4093
4094 /**
4095 * Create a complex value or convert a value to a complex value.
4096 * @param im Argument specifying the imaginary part of the complex
4097 * number
4098 */
4099 complex(
4100 this: MathJsChain<Complex | string | PolarCoordinates>,
4101 im?: number
4102 ): MathJsChain<Complex>
4103 complex(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
4104
4105 /**
4106 * Create a user-defined unit and register it with the Unit type.
4107 * @param definition Definition of the unit in terms of existing units.
4108 * For example, ‘0.514444444 m / s’.
4109 * @param options (optional) An object containing any of the following
4110 * properties:</br>- prefixes {string} “none”, “short”, “long”,
4111 * “binary_short”, or “binary_long”. The default is “none”.</br>-
4112 * aliases {Array} Array of strings. Example: [‘knots’, ‘kt’,
4113 * ‘kts’]</br>- offset {Numeric} An offset to apply when converting from
4114 * the unit. For example, the offset for celsius is 273.15. Default is
4115 * 0.
4116 */
4117 createUnit(
4118 this: MathJsChain<string>,
4119 definition?: string | UnitDefinition,
4120 options?: CreateUnitOptions
4121 ): MathJsChain<Unit>
4122 /**
4123 * Create a user-defined unit and register it with the Unit type.
4124 * @param options (optional) An object containing any of the following
4125 * properties:</br>- prefixes {string} “none”, “short”, “long”,
4126 * “binary_short”, or “binary_long”. The default is “none”.</br>-
4127 * aliases {Array} Array of strings. Example: [‘knots’, ‘kt’,
4128 * ‘kts’]</br>- offset {Numeric} An offset to apply when converting from
4129 * the unit. For example, the offset for celsius is 273.15. Default is
4130 * 0.
4131 */
4132 createUnit(
4133 this: MathJsChain<Record<string, string | UnitDefinition>>,
4134 options?: CreateUnitOptions
4135 ): MathJsChain<Unit>
4136
4137 /**
4138 * Create a fraction convert a value to a fraction.
4139 * @param denominator Argument specifying the denominator of the
4140 * fraction
4141 */
4142 fraction(
4143 this: MathJsChain<
4144 number | string | BigNumber | Fraction | FractionDefinition
4145 >,
4146 denominator?: number
4147 ): MathJsChain<Fraction>
4148 fraction(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
4149
4150 /**
4151 * Create an index. An Index can store ranges having start, step, and
4152 * end for multiple dimensions. Matrix.get, Matrix.set, and math.subset
4153 * accept an Index as input.
4154 */
4155 // eslint-disable-next-line @typescript-eslint/no-explicit-any
4156 index(this: MathJsChain<any[]>): MathJsChain<Index>
4157
4158 /**
4159 * Create a Matrix. The function creates a new math.type.Matrix object
4160 * from an Array. A Matrix has utility functions to manipulate the data
4161 * in the matrix, like getting the size and getting or setting values in
4162 * the matrix. Supported storage formats are 'dense' and 'sparse'.
4163 */
4164 matrix(
4165 this: MathJsChain<MathCollection>,
4166 format?: 'sparse' | 'dense',
4167 dataType?: string
4168 ): MathJsChain<Matrix>
4169
4170 /**
4171 * Create a number or convert a string, boolean, or unit to a number.
4172 * When value is a matrix, all elements will be converted to number.
4173 * @param valuelessUnit A valueless unit, used to convert a unit to a
4174 * number
4175 */
4176 number(
4177 this: MathJsChain<
4178 string | number | BigNumber | Fraction | boolean | Unit | null
4179 >,
4180 valuelessUnit?: Unit | string
4181 ): MathJsChain<number>
4182 number(
4183 this: MathJsChain<MathCollection>,
4184 valuelessUnit?: Unit | string
4185 ): MathJsChain<MathCollection>
4186
4187 /**
4188 * Create a Sparse Matrix. The function creates a new math.type.Matrix
4189 * object from an Array. A Matrix has utility functions to manipulate
4190 * the data in the matrix, like getting the size and getting or setting
4191 * values in the matrix.
4192 * @param dataType Sparse Matrix data type
4193 */
4194 sparse(
4195 this: MathJsChain<MathCollection>,
4196 dataType?: string
4197 ): MathJsChain<Matrix>
4198
4199 /**
4200 * Split a unit in an array of units whose sum is equal to the original
4201 * unit.
4202 * @param parts An array of strings or valueless units
4203 */
4204 splitUnit(this: MathJsChain<Unit>, parts: Unit[]): MathJsChain<Unit[]>
4205
4206 /**
4207 * Create a string or convert any object into a string. Elements of
4208 * Arrays and Matrices are processed element wise.
4209 */
4210 string(
4211 this: MathJsChain<MathNumericType | string | Unit | null>
4212 ): MathJsChain<string>
4213 string(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
4214
4215 /**
4216 * Create a unit. Depending on the passed arguments, the function will
4217 * create and return a new math.type.Unit object. When a matrix is
4218 * provided, all elements will be converted to units.
4219 * @param unit The unit to be created
4220 */
4221 unit(this: MathJsChain<string>, unit?: string): MathJsChain<Unit>
4222 unit(this: MathJsChain<Unit>, unit?: string): MathJsChain<Unit>
4223 unit(
4224 this: MathJsChain<number | BigNumber>,
4225 unit?: string
4226 ): MathJsChain<Unit>
4227 unit(this: MathJsChain<MathCollection>, unit?: string): MathJsChain<Unit[]>
4228
4229 /*************************************************************************
4230 * Expression functions
4231 ************************************************************************/
4232
4233 /**
4234 * Parse and compile an expression. Returns a an object with a function
4235 * evaluate([scope]) to evaluate the compiled expression.
4236 */
4237 compile(this: MathJsChain<MathExpression>): MathJsChain<EvalFunction>
4238
4239 // TODO properly type this
4240 /**
4241 * Evaluate an expression.
4242 * @param scope Scope to read/write variables
4243 */
4244 evaluate(
4245 this: MathJsChain<MathExpression | Matrix>,
4246 scope?: object
4247 // eslint-disable-next-line @typescript-eslint/no-explicit-any
4248 ): MathJsChain<any>
4249 evaluate(
4250 this: MathJsChain<MathExpression[]>,
4251 scope?: object
4252 // eslint-disable-next-line @typescript-eslint/no-explicit-any
4253 ): MathJsChain<any[]>
4254
4255 /**
4256 * Retrieve help on a function or data type. Help files are retrieved
4257 * from the documentation in math.expression.docs.
4258 */
4259 help(this: MathJsChain<unknown>): MathJsChain<unknown>
4260
4261 /**
4262 * @param options Available options: nodes - a set of custome nodes
4263 */
4264 parse(
4265 this: MathJsChain<MathExpression[]>,
4266 // eslint-disable-next-line @typescript-eslint/no-explicit-any
4267 options?: any
4268 ): MathJsChain<MathNode[]>
4269
4270 /**
4271 * Parse an expression. Returns a node tree, which can be evaluated by
4272 * invoking node.evaluate();
4273 * @param options Available options: nodes - a set of custome nodes
4274 */
4275 parse(
4276 this: MathJsChain<MathExpression>,
4277 // eslint-disable-next-line @typescript-eslint/no-explicit-any
4278 options?: any
4279 ): MathJsChain<MathNode>
4280
4281 /**
4282 * Replaces variable nodes with their scoped values
4283 * @param scope Scope to read/write variables
4284 */
4285 resolve(
4286 this: MathJsChain<MathNode>,
4287 // eslint-disable-next-line @typescript-eslint/no-explicit-any
4288 scope?: Record<string, any>
4289 ): MathJsChain<MathNode>
4290 resolve(
4291 this: MathJsChain<MathNode[]>,
4292 // eslint-disable-next-line @typescript-eslint/no-explicit-any
4293 scope?: Record<string, any>
4294 ): MathJsChain<MathNode[]>
4295
4296 /*************************************************************************
4297 * Algebra functions
4298 ************************************************************************/
4299 /**
4300 * @param variable The variable over which to differentiate
4301 * @param options There is one option available, simplify, which is true
4302 * by default. When false, output will not be simplified.
4303 */
4304 derivative(
4305 this: MathJsChain<MathNode | string>,
4306 variable: MathNode | string,
4307 options?: { simplify: boolean }
4308 ): MathJsChain<MathNode>
4309
4310 /**
4311 * Solves the linear equation system by forwards substitution. Matrix
4312 * must be a lower triangular matrix.
4313 * @param b A column vector with the b values
4314 */
4315 lsolve(
4316 this: MathJsChain<Matrix>,
4317 b: Matrix | MathArray
4318 ): MathJsChain<Matrix>
4319 lsolve(
4320 this: MathJsChain<MathArray>,
4321 b: Matrix | MathArray
4322 ): MathJsChain<MathArray>
4323
4324 /**
4325 * Calculate the Matrix LU decomposition with partial pivoting. Matrix A
4326 * is decomposed in two matrices (L, U) and a row permutation vector p
4327 * where A[p,:] = L * U
4328 */
4329 lup(this: MathJsChain<Matrix | MathArray>): MathJsChain<LUDecomposition>
4330
4331 /**
4332 * Solves the linear system A * x = b where A is an [n x n] matrix and b
4333 * is a [n] column vector.
4334 * @param b Column Vector
4335 * @param order The Symbolic Ordering and Analysis order, see slu for
4336 * details. Matrix must be a SparseMatrix
4337 * @param threshold Partial pivoting threshold (1 for partial pivoting),
4338 * see slu for details. Matrix must be a SparseMatrix.
4339 */
4340 lusolve(
4341 this: MathJsChain<Matrix>,
4342 b: Matrix | MathArray,
4343 order?: number,
4344 threshold?: number
4345 ): MathJsChain<Matrix>
4346
4347 lusolve(
4348 this: MathJsChain<MathArray>,
4349 b: Matrix | MathArray,
4350 order?: number,
4351 threshold?: number
4352 ): MathJsChain<MathArray>
4353
4354 /**
4355 * Calculate the Matrix QR decomposition. Matrix A is decomposed in two
4356 * matrices (Q, R) where Q is an orthogonal matrix and R is an upper
4357 * triangular matrix.
4358 */
4359 qr(this: MathJsChain<Matrix | MathArray>): MathJsChain<QRDecomposition>
4360
4361 /**
4362 * Transform a rationalizable expression in a rational fraction. If
4363 * rational fraction is one variable polynomial then converts the
4364 * numerator and denominator in canonical form, with decreasing
4365 * exponents, returning the coefficients of numerator.
4366 * @param optional scope of expression or true for already evaluated
4367 * rational expression at input
4368 * @param detailed optional True if return an object, false if return
4369 * expression node (default)
4370 */
4371 rationalize(
4372 this: MathJsChain<MathNode | string>,
4373 optional?: object | boolean,
4374 detailed?: boolean
4375 ): MathJsChain<MathNode>
4376
4377 /**
4378 * Simplify an expression tree.
4379 * @param rules A list of rules are applied to an expression, repeating
4380 * over the list until no further changes are made. It’s possible to
4381 * pass a custom set of rules to the function as second argument. A rule
4382 * can be specified as an object, string, or function.
4383 * @param scope Scope to variables
4384 */
4385 simplify(
4386 this: MathJsChain<MathNode | string>,
4387 rules?: SimplifyRule[],
4388 scope?: object
4389 ): MathJsChain<MathNode>
4390
4391 // TODO check that this should even be here...
4392 simplifyCore(expr: MathNode): MathNode
4393
4394 /**
4395 * Calculate the Sparse Matrix LU decomposition with full pivoting.
4396 * Sparse Matrix A is decomposed in two matrices (L, U) and two
4397 * permutation vectors (pinv, q) where P * A * Q = L * U
4398 * @param order The Symbolic Ordering and Analysis order: 0 - Natural
4399 * ordering, no permutation vector q is returned 1 - Matrix must be
4400 * square, symbolic ordering and analisis is performed on M = A + A' 2 -
4401 * Symbolic ordering and analysis is performed on M = A' * A. Dense
4402 * columns from A' are dropped, A recreated from A'. This is appropriate
4403 * for LU factorization of non-symmetric matrices. 3 - Symbolic ordering
4404 * and analysis is performed on M = A' * A. This is best used for LU
4405 * factorization is matrix M has no dense rows. A dense row is a row
4406 * with more than 10*sqr(columns) entries.
4407 * @param threshold Partial pivoting threshold (1 for partial pivoting)
4408 */
4409 slu(
4410 this: MathJsChain<Matrix>,
4411 order: number,
4412 threshold: number
4413 ): MathJsChain<SLUDecomposition>
4414
4415 /**
4416 * Solves the linear equation system by backward substitution. Matrix
4417 * must be an upper triangular matrix. U * x = b
4418 * @param b A column vector with the b values
4419 */
4420 usolve(
4421 this: MathJsChain<Matrix>,
4422 b: Matrix | MathArray
4423 ): MathJsChain<Matrix>
4424 usolve(
4425 this: MathJsChain<MathArray>,
4426 b: Matrix | MathArray
4427 ): MathJsChain<MathArray>
4428
4429 /*************************************************************************
4430 * Arithmetic functions
4431 ************************************************************************/
4432
4433 /**
4434 * Calculate the absolute value of a number. For matrices, the function
4435 * is evaluated element wise.
4436 */
4437 abs(this: MathJsChain<number>): MathJsChain<number>
4438 abs(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4439 abs(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4440 abs(this: MathJsChain<Complex>): MathJsChain<Complex>
4441 abs(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4442 abs(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4443 abs(this: MathJsChain<Unit>): MathJsChain<Unit>
4444
4445 /**
4446 * Add two values, x + y. For matrices, the function is evaluated
4447 * element wise.
4448 * @param y Second value to add
4449 */
4450 add<T extends MathType>(this: MathJsChain<T>, y: T): MathJsChain<T>
4451 add(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4452
4453 /**
4454 * Apply a function that maps an array to a scalar along a given axis of the
4455 * matrix or array. Returns a new matrix or array with one less dimension
4456 * than the input.
4457 * @param dim The dimension along which the callback is applied
4458 * @param callback The callback function that is applied. This Function should take an
4459 * array or 1-d matrix as an input and return a number.
4460 * @returns The residual matrix with the function applied over some dimension.
4461 */
4462 apply<T extends MathCollection>(
4463 this: MathJsChain<T>,
4464 dim: number,
4465 callback: (array: Array<MathType> | Matrix) => number
4466 ): MathJsChain<T>
4467
4468 /**
4469 * Calculate the cubic root of a value. For matrices, the function is
4470 * evaluated element wise.
4471 * @param allRoots Optional, false by default. Only applicable when x is
4472 * a number or complex number. If true, all complex roots are returned,
4473 * if false (default) the principal root is returned.
4474 */
4475 cbrt(this: MathJsChain<number>, allRoots?: boolean): MathJsChain<number>
4476 cbrt(
4477 this: MathJsChain<BigNumber>,
4478 allRoots?: boolean
4479 ): MathJsChain<BigNumber>
4480 cbrt(this: MathJsChain<Complex>, allRoots?: boolean): MathJsChain<Complex>
4481 cbrt(
4482 this: MathJsChain<MathArray>,
4483 allRoots?: boolean
4484 ): MathJsChain<MathArray>
4485 cbrt(this: MathJsChain<Matrix>, allRoots?: boolean): MathJsChain<Matrix>
4486
4487 // Rounding functions grouped for similarity
4488
4489 /**
4490 * Round a value towards plus infinity If x is complex, both real and
4491 * imaginary part are rounded towards plus infinity. For matrices, the
4492 * function is evaluated element wise.
4493 * @param n Number of decimals Default value: 0.
4494 */
4495 ceil(
4496 this: MathJsChain<MathNumericType>,
4497 n?: number | BigNumber | MathCollection
4498 ): MathJsChain<MathNumericType>
4499 ceil(
4500 this: MathJsChain<MathCollection>,
4501 n?: number | BigNumber | MathCollection
4502 ): MathJsChain<MathCollection>
4503
4504 /**
4505 * Round a value towards zero. For matrices, the function is evaluated
4506 * element wise.
4507 * @param n Number of decimals Default value: 0.
4508 */
4509 fix(
4510 this: MathJsChain<MathNumericType>,
4511 n?: number | BigNumber | MathCollection
4512 ): MathJsChain<MathNumericType>
4513 fix(
4514 this: MathJsChain<MathCollection>,
4515 n?: number | BigNumber | MathCollection
4516 ): MathJsChain<MathCollection>
4517
4518 /**
4519 * Round a value towards minus infinity. For matrices, the function is
4520 * evaluated element wise.
4521 * @param n Number of decimals Default value: 0.
4522 */
4523 floor(
4524 this: MathJsChain<MathNumericType>,
4525 n?: number | BigNumber | MathCollection
4526 ): MathJsChain<MathNumericType>
4527 floor(
4528 this: MathJsChain<MathCollection>,
4529 n?: number | BigNumber | MathCollection
4530 ): MathJsChain<MathCollection>
4531
4532 /**
4533 * Round a value towards the nearest integer. For matrices, the function
4534 * is evaluated element wise.
4535 * @param n Number of decimals Default value: 0.
4536 */
4537 round(
4538 this: MathJsChain<MathNumericType>,
4539 n?: number | BigNumber | MathCollection
4540 ): MathJsChain<MathNumericType>
4541 round(
4542 this: MathJsChain<MathCollection>,
4543 n?: number | BigNumber | MathCollection
4544 ): MathJsChain<MathCollection>
4545
4546 // End of rounding group
4547
4548 /**
4549 * Compute the cube of a value, x * x * x. For matrices, the function is
4550 * evaluated element wise.
4551 */
4552 cube(this: MathJsChain<number>): MathJsChain<number>
4553 cube(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4554 cube(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4555 cube(this: MathJsChain<Complex>): MathJsChain<Complex>
4556 cube(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4557 cube(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4558 cube(this: MathJsChain<Unit>): MathJsChain<Unit>
4559
4560 /**
4561 * Divide two values, x / y. To divide matrices, x is multiplied with
4562 * the inverse of y: x * inv(y).
4563 * @param y Denominator
4564 */
4565 divide(this: MathJsChain<Unit>, y: Unit): MathJsChain<Unit | number>
4566 divide(this: MathJsChain<Unit>, y: number): MathJsChain<Unit>
4567 divide(this: MathJsChain<number>, y: number): MathJsChain<number>
4568 divide(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4569
4570 /**
4571 * Divide two matrices element wise. The function accepts both matrices
4572 * and scalar values.
4573 * @param y Denominator
4574 */
4575 dotDivide(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4576
4577 /**
4578 * Multiply two matrices element wise. The function accepts both
4579 * matrices and scalar values.
4580 * @param y Right hand value
4581 */
4582 dotMultiply(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4583
4584 /**
4585 * Calculates the power of x to y element wise.
4586 * @param y The exponent
4587 */
4588 dotPow(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4589
4590 /**
4591 * Calculate the exponent of a value. For matrices, the function is
4592 * evaluated element wise.
4593 */
4594 exp(this: MathJsChain<number>): MathJsChain<number>
4595 exp(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4596 exp(this: MathJsChain<Complex>): MathJsChain<Complex>
4597 exp(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4598 exp(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4599
4600 /**
4601 * Calculate the value of subtracting 1 from the exponential value. For
4602 * matrices, the function is evaluated element wise.
4603 */
4604 expm1(this: MathJsChain<number>): MathJsChain<number>
4605 expm1(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4606 expm1(this: MathJsChain<Complex>): MathJsChain<Complex>
4607 expm1(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4608 expm1(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4609
4610 /**
4611 * Calculate the greatest common divisor for two or more values or
4612 * arrays. For matrices, the function is evaluated element wise.
4613 */
4614 gcd(this: MathJsChain<number[]>, ...args: number[]): MathJsChain<number>
4615 gcd(
4616 this: MathJsChain<BigNumber[]>,
4617 ...args: BigNumber[]
4618 ): MathJsChain<BigNumber>
4619 gcd(this: MathJsChain<Complex[]>, ...args: Fraction[]): MathJsChain<Complex>
4620 gcd(
4621 this: MathJsChain<MathArray[]>,
4622 ...args: MathArray[]
4623 ): MathJsChain<MathArray>
4624 gcd(this: MathJsChain<Matrix[]>, ...args: Matrix[]): MathJsChain<Matrix>
4625
4626 /**
4627 * Calculate the hypotenusa of a list with values. The hypotenusa is
4628 * defined as: hypot(a, b, c, ...) = sqrt(a^2 + b^2 + c^2 + ...) For
4629 * matrix input, the hypotenusa is calculated for all values in the
4630 * matrix.
4631 */
4632 hypot(this: MathJsChain<number[]>): MathJsChain<number>
4633 hypot(this: MathJsChain<BigNumber[]>): MathJsChain<BigNumber>
4634
4635 /**
4636 * Calculate the least common multiple for two or more values or arrays.
4637 * lcm is defined as: lcm(a, b) = abs(a * b) / gcd(a, b) For matrices,
4638 * the function is evaluated element wise.
4639 * @param b An integer number
4640 */
4641 lcm(this: MathJsChain<number>, b: number): MathJsChain<number>
4642 lcm(this: MathJsChain<BigNumber>, b: BigNumber): MathJsChain<BigNumber>
4643 lcm(this: MathJsChain<MathArray>, b: MathArray): MathJsChain<MathArray>
4644 lcm(this: MathJsChain<Matrix>, b: Matrix): MathJsChain<Matrix>
4645
4646 /**
4647 * Calculate the logarithm of a value. For matrices, the function is
4648 * evaluated element wise.
4649 * @param base Optional base for the logarithm. If not provided, the
4650 * natural logarithm of x is calculated. Default value: e.
4651 */
4652 log<T extends number | BigNumber | Complex | MathCollection>(
4653 this: MathJsChain<T>,
4654 base?: number | BigNumber | Complex
4655 ): MathJsChain<NoLiteralType<T>>
4656
4657 /**
4658 * Calculate the 10-base of a value. This is the same as calculating
4659 * log(x, 10). For matrices, the function is evaluated element wise.
4660 */
4661
4662 log10(this: MathJsChain<number>): MathJsChain<number>
4663 log10(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4664 log10(this: MathJsChain<Complex>): MathJsChain<Complex>
4665 log10(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4666 log10(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4667
4668 /**
4669 * Calculate the logarithm of a value+1. For matrices, the function is
4670 * evaluated element wise.
4671 */
4672 log1p(
4673 this: MathJsChain<number>,
4674 base?: number | BigNumber | Complex
4675 ): MathJsChain<number>
4676 log1p(
4677 this: MathJsChain<BigNumber>,
4678 base?: number | BigNumber | Complex
4679 ): MathJsChain<BigNumber>
4680 log1p(
4681 this: MathJsChain<Complex>,
4682 base?: number | BigNumber | Complex
4683 ): MathJsChain<Complex>
4684 log1p(
4685 this: MathJsChain<MathArray>,
4686 base?: number | BigNumber | Complex
4687 ): MathJsChain<MathArray>
4688 log1p(
4689 this: MathJsChain<Matrix>,
4690 base?: number | BigNumber | Complex
4691 ): MathJsChain<Matrix>
4692
4693 /**
4694 * Calculate the 2-base of a value. This is the same as calculating
4695 * log(x, 2). For matrices, the function is evaluated element wise.
4696 */
4697
4698 log2(this: MathJsChain<number>): MathJsChain<number>
4699 log2(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4700 log2(this: MathJsChain<Complex>): MathJsChain<Complex>
4701 log2(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4702 log2(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4703
4704 /**
4705 * Calculates the modulus, the remainder of an integer division. For
4706 * matrices, the function is evaluated element wise. The modulus is
4707 * defined as: x - y * floor(x / y)
4708 * @see http://en.wikipedia.org/wiki/Modulo_operation.
4709 * @param y Divisor
4710 */
4711 mod<T extends number | BigNumber | Fraction | MathCollection>(
4712 this: MathJsChain<T>,
4713 y: number | BigNumber | Fraction | MathCollection
4714 ): MathJsChain<NoLiteralType<T>>
4715
4716 /**
4717 * Multiply two values, x * y. The result is squeezed. For matrices, the
4718 * matrix product is calculated.
4719 * @param y The second value to multiply
4720 */
4721 multiply<T extends Matrix | MathArray>(
4722 this: MathJsChain<T>,
4723 y: MathType
4724 ): MathJsChain<T>
4725 multiply(this: MathJsChain<Unit>, y: Unit): MathJsChain<Unit>
4726 multiply(this: MathJsChain<number>, y: number): MathJsChain<number>
4727 multiply(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4728
4729 /**
4730 * Calculate the norm of a number, vector or matrix. The second
4731 * parameter p is optional. If not provided, it defaults to 2.
4732 * @param p Vector space. Supported numbers include Infinity and
4733 * -Infinity. Supported strings are: 'inf', '-inf', and 'fro' (The
4734 * Frobenius norm) Default value: 2.
4735 */
4736 norm(
4737 this: MathJsChain<number | BigNumber | Complex | MathCollection>,
4738 p?: number | BigNumber | string
4739 ): MathJsChain<number | BigNumber>
4740
4741 /**
4742 * Calculate the nth root of a value. The principal nth root of a
4743 * positive real number A, is the positive real solution of the equation
4744 * x^root = A For matrices, the function is evaluated element wise.
4745 * @param root The root. Default value: 2.
4746 */
4747 nthRoot(
4748 this: MathJsChain<number | BigNumber | MathCollection | Complex>,
4749 root?: number | BigNumber
4750 ): MathJsChain<number | Complex | MathCollection>
4751
4752 /**
4753 * Calculates the power of x to y, x ^ y. Matrix exponentiation is
4754 * supported for square matrices x, and positive integer exponents y.
4755 * @param y The exponent
4756 */
4757 pow(
4758 this: MathJsChain<MathType>,
4759 y: number | BigNumber | Complex
4760 ): MathJsChain<MathType>
4761
4762 /**
4763 * Compute the sign of a value. The sign of a value x is: 1 when x > 1
4764 * -1 when x < 0 0 when x == 0 For matrices, the function is evaluated
4765 * element wise.
4766 * @param x The number for which to determine the sign
4767 * @returns The sign of x
4768 */
4769 sign(this: MathJsChain<number>): MathJsChain<number>
4770 sign(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4771 sign(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4772 sign(this: MathJsChain<Complex>): MathJsChain<Complex>
4773 sign(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4774 sign(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4775 sign(this: MathJsChain<Unit>): MathJsChain<Unit>
4776
4777 /**
4778 * Calculate the square root of a value. For matrices, the function is
4779 * evaluated element wise.
4780 */
4781
4782 sqrt(this: MathJsChain<number>): MathJsChain<number>
4783 sqrt(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4784 sqrt(this: MathJsChain<Complex>): MathJsChain<Complex>
4785 sqrt(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4786 sqrt(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4787 sqrt(this: MathJsChain<Unit>): MathJsChain<Unit>
4788
4789 /**
4790 * Compute the square of a value, x * x. For matrices, the function is
4791 * evaluated element wise.
4792 */
4793
4794 square(this: MathJsChain<number>): MathJsChain<number>
4795 square(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4796 square(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4797 square(this: MathJsChain<Complex>): MathJsChain<Complex>
4798 square(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4799 square(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4800 square(this: MathJsChain<Unit>): MathJsChain<Unit>
4801
4802 /**
4803 * Subtract two values, x - y. For matrices, the function is evaluated
4804 * element wise.
4805 * @param y Value to subtract from x
4806 */
4807 subtract<T extends MathType>(this: MathJsChain<T>, y: T): MathJsChain<T>
4808 subtract(this: MathJsChain<MathType>, y: MathType): MathJsChain<MathType>
4809
4810 /**
4811 * Inverse the sign of a value, apply a unary minus operation. For
4812 * matrices, the function is evaluated element wise. Boolean values and
4813 * strings will be converted to a number. For complex numbers, both real
4814 * and complex value are inverted.
4815 */
4816
4817 unaryMinus(this: MathJsChain<number>): MathJsChain<number>
4818 unaryMinus(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4819 unaryMinus(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4820 unaryMinus(this: MathJsChain<Complex>): MathJsChain<Complex>
4821 unaryMinus(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4822 unaryMinus(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4823 unaryMinus(this: MathJsChain<Unit>): MathJsChain<Unit>
4824
4825 /**
4826 * Unary plus operation. Boolean values and strings will be converted to
4827 * a number, numeric values will be returned as is. For matrices, the
4828 * function is evaluated element wise.
4829 */
4830
4831 unaryPlus(this: MathJsChain<number>): MathJsChain<number>
4832 unaryPlus(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4833 unaryPlus(this: MathJsChain<Fraction>): MathJsChain<Fraction>
4834 unaryPlus(this: MathJsChain<string>): MathJsChain<string>
4835 unaryPlus(this: MathJsChain<Complex>): MathJsChain<Complex>
4836 unaryPlus(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4837 unaryPlus(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4838 unaryPlus(this: MathJsChain<Unit>): MathJsChain<Unit>
4839
4840 /**
4841 * Calculate the extended greatest common divisor for two values. See
4842 * http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm.
4843 * @param b An integer number
4844 */
4845 xgcd(
4846 this: MathJsChain<number | BigNumber>,
4847 b: number | BigNumber
4848 ): MathJsChain<MathArray>
4849
4850 /*************************************************************************
4851 * Bitwise functions
4852 ************************************************************************/
4853
4854 /**
4855 * Bitwise AND two values, x & y. For matrices, the function is
4856 * evaluated element wise.
4857 * @param y Second value to and
4858 */
4859 bitAnd<T extends number | BigNumber | MathCollection>(
4860 this: MathJsChain<T>,
4861 y: number | BigNumber | MathCollection
4862 ): MathJsChain<NoLiteralType<T>>
4863
4864 /**
4865 * Bitwise NOT value, ~x. For matrices, the function is evaluated
4866 * element wise. For units, the function is evaluated on the best prefix
4867 * base.
4868 */
4869
4870 bitNot(this: MathJsChain<number>): MathJsChain<number>
4871 bitNot(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4872 bitNot(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4873 bitNot(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4874
4875 /**
4876 * Bitwise OR two values, x | y. For matrices, the function is evaluated
4877 * element wise. For units, the function is evaluated on the lowest
4878 * print base.
4879 * @param y Second value to or
4880 */
4881 bitOr(this: MathJsChain<number>, y: number): MathJsChain<number>
4882 bitOr(this: MathJsChain<BigNumber>, y: BigNumber): MathJsChain<BigNumber>
4883 bitOr(this: MathJsChain<MathArray>, y: MathArray): MathJsChain<MathArray>
4884 bitOr(this: MathJsChain<Matrix>, y: Matrix): MathJsChain<Matrix>
4885
4886 /**
4887 * Bitwise XOR two values, x ^ y. For matrices, the function is
4888 * evaluated element wise.
4889 * @param y Second value to xor
4890 */
4891 bitXor<T extends number | BigNumber | MathCollection>(
4892 this: MathJsChain<T>,
4893 y: number | BigNumber | MathCollection
4894 ): MathJsChain<NoLiteralType<T>>
4895
4896 /**
4897 * Bitwise left logical shift of a value x by y number of bits, x << y.
4898 * For matrices, the function is evaluated element wise. For units, the
4899 * function is evaluated on the best prefix base.
4900 * @param y Amount of shifts
4901 */
4902 leftShift<T extends number | BigNumber | MathCollection>(
4903 this: MathJsChain<T>,
4904 y: number | BigNumber
4905 ): MathJsChain<NoLiteralType<T>>
4906
4907 /**
4908 * Bitwise right arithmetic shift of a value x by y number of bits, x >>
4909 * y. For matrices, the function is evaluated element wise. For units,
4910 * the function is evaluated on the best prefix base.
4911 * @param y Amount of shifts
4912 */
4913 rightArithShift<T extends number | BigNumber | MathCollection>(
4914 this: MathJsChain<T>,
4915 y: number | BigNumber
4916 ): MathJsChain<NoLiteralType<T>>
4917
4918 /**
4919 * Bitwise right logical shift of value x by y number of bits, x >>> y.
4920 * For matrices, the function is evaluated element wise. For units, the
4921 * function is evaluated on the best prefix base.
4922 * @param y Amount of shifts
4923 */
4924 rightLogShift<T extends number | MathCollection>(
4925 this: MathJsChain<T>,
4926 y: number
4927 ): MathJsChain<NoLiteralType<T>>
4928
4929 /*************************************************************************
4930 * Combinatorics functions
4931 ************************************************************************/
4932
4933 /**
4934 * The Bell Numbers count the number of partitions of a set. A partition
4935 * is a pairwise disjoint subset of S whose union is S. bellNumbers only
4936 * takes integer arguments. The following condition must be enforced: n
4937 * >= 0
4938 */
4939
4940 bellNumbers(this: MathJsChain<number>): MathJsChain<number>
4941 bellNumbers(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4942
4943 /**
4944 * The Catalan Numbers enumerate combinatorial structures of many
4945 * different types. catalan only takes integer arguments. The following
4946 * condition must be enforced: n >= 0
4947 */
4948
4949 catalan(this: MathJsChain<number>): MathJsChain<number>
4950 catalan(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
4951
4952 /**
4953 * The composition counts of n into k parts. Composition only takes
4954 * integer arguments. The following condition must be enforced: k <= n.
4955 * @param k Number of objects in the subset
4956 */
4957 composition<T extends number | BigNumber>(
4958 this: MathJsChain<T>,
4959 k: number | BigNumber
4960 ): MathJsChain<NoLiteralType<T>>
4961
4962 /**
4963 * The Stirling numbers of the second kind, counts the number of ways to
4964 * partition a set of n labelled objects into k nonempty unlabelled
4965 * subsets. stirlingS2 only takes integer arguments. The following
4966 * condition must be enforced: k <= n. If n = k or k = 1, then s(n,k) =
4967 * 1
4968 * @param k Number of objects in the subset
4969 */
4970 stirlingS2<T extends number | BigNumber>(
4971 this: MathJsChain<T>,
4972 k: number | BigNumber
4973 ): MathJsChain<NoLiteralType<T>>
4974
4975 /*************************************************************************
4976 * Complex functions
4977 ************************************************************************/
4978
4979 /**
4980 * Compute the argument of a complex value. For a complex number a + bi,
4981 * the argument is computed as atan2(b, a). For matrices, the function
4982 * is evaluated element wise.
4983 */
4984
4985 arg(this: MathJsChain<number | Complex>): MathJsChain<number>
4986 arg(this: MathJsChain<BigNumber | Complex>): MathJsChain<BigNumber>
4987 arg(this: MathJsChain<MathArray>): MathJsChain<MathArray>
4988 arg(this: MathJsChain<Matrix>): MathJsChain<Matrix>
4989
4990 /**
4991 * Compute the complex conjugate of a complex value. If x = a+bi, the
4992 * complex conjugate of x is a - bi. For matrices, the function is
4993 * evaluated element wise.
4994 */
4995 conj<T extends number | BigNumber | Complex | MathCollection>(
4996 this: MathJsChain<T>
4997 ): MathJsChain<NoLiteralType<T>>
4998
4999 /**
5000 * Get the imaginary part of a complex number. For a complex number a +
5001 * bi, the function returns b. For matrices, the function is evaluated
5002 * element wise.
5003 */
5004 im(this: MathJsChain<number | Complex>): MathJsChain<number>
5005 im(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
5006 im(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
5007
5008 /**
5009 * Get the real part of a complex number. For a complex number a + bi,
5010 * the function returns a. For matrices, the function is evaluated
5011 * element wise.
5012 */
5013 re(this: MathJsChain<number | Complex>): MathJsChain<number>
5014 re(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
5015 re(this: MathJsChain<MathCollection>): MathJsChain<MathCollection>
5016
5017 /*************************************************************************
5018 * Geometry functions
5019 ************************************************************************/
5020
5021 /**
5022 * Calculates: The eucledian distance between two points in 2 and 3
5023 * dimensional spaces. Distance between point and a line in 2 and 3
5024 * dimensional spaces. Pairwise distance between a set of 2D or 3D
5025 * points NOTE: When substituting coefficients of a line(a, b and c),
5026 * use ax + by + c = 0 instead of ax + by = c For parametric equation of
5027 * a 3D line, x0, y0, z0, a, b, c are from: (x−x0, y−y0, z−z0) = t(a, b,
5028 * c)
5029 * @param y Coordinates of the second point
5030 */
5031 distance(
5032 this: MathJsChain<MathCollection | object>,
5033 y: MathCollection | object
5034 ): MathJsChain<number | BigNumber>
5035
5036 /**
5037 * Calculates the point of intersection of two lines in two or three
5038 * dimensions and of a line and a plane in three dimensions. The inputs
5039 * are in the form of arrays or 1 dimensional matrices. The line
5040 * intersection functions return null if the lines do not meet. Note:
5041 * Fill the plane coefficients as x + y + z = c and not as x + y + z + c
5042 * = 0.
5043 * @param x Co-ordinates of second end-point of first line
5044 * @param y Co-ordinates of first end-point of second line OR
5045 * Coefficients of the plane's equation
5046 * @param z Co-ordinates of second end-point of second line OR null if
5047 * the calculation is for line and plane
5048 */
5049 intersect(
5050 this: MathJsChain<MathCollection>,
5051 x: MathCollection,
5052 y: MathCollection,
5053 z: MathCollection
5054 ): MathJsChain<MathArray>
5055
5056 /*************************************************************************
5057 * Logical functions
5058 ************************************************************************/
5059
5060 /**
5061 * Logical and. Test whether two values are both defined with a
5062 * nonzero/nonempty value. For matrices, the function is evaluated
5063 * element wise.
5064 * @param y Second value to and
5065 */
5066 and(
5067 this: MathJsChain<number | BigNumber | Complex | Unit | MathCollection>,
5068 y: number | BigNumber | Complex | Unit | MathCollection
5069 ): MathJsChain<boolean | MathCollection>
5070
5071 /**
5072 * Logical not. Flips boolean value of a given parameter. For matrices,
5073 * the function is evaluated element wise.
5074 */
5075 not(
5076 this: MathJsChain<number | BigNumber | Complex | Unit | MathCollection>
5077 ): MathJsChain<boolean | MathCollection>
5078
5079 /**
5080 * Logical or. Test if at least one value is defined with a
5081 * nonzero/nonempty value. For matrices, the function is evaluated
5082 * element wise.
5083 * @param y Second value to or
5084 */
5085 or(
5086 this: MathJsChain<number | BigNumber | Complex | Unit | MathCollection>,
5087 y: number | BigNumber | Complex | Unit | MathCollection
5088 ): MathJsChain<boolean | MathCollection>
5089
5090 /**
5091 * Logical xor. Test whether one and only one value is defined with a
5092 * nonzero/nonempty value. For matrices, the function is evaluated
5093 * element wise.
5094 * @param y Second value to xor
5095 */
5096 xor(
5097 this: MathJsChain<number | BigNumber | Complex | Unit | MathCollection>,
5098 y: number | BigNumber | Complex | Unit | MathCollection
5099 ): MathJsChain<boolean | MathCollection>
5100
5101 /*************************************************************************
5102 * Matrix functions
5103 ************************************************************************/
5104
5105 /**
5106 * Concatenate two or more matrices. dim: number is a zero-based
5107 * dimension over which to concatenate the matrices. By default the last
5108 * dimension of the matrices.
5109 */
5110
5111 concat(
5112 this: MathJsChain<Array<MathCollection | number | BigNumber>>
5113 ): MathJsChain<MathCollection>
5114
5115 /**
5116 * Calculate the cross product for two vectors in three dimensional
5117 * space. The cross product of A = [a1, a2, a3] and B =[b1, b2, b3] is
5118 * defined as: cross(A, B) = [ a2 * b3 - a3 * b2, a3 * b1 - a1 * b3, a1
5119 * * b2 - a2 * b1 ]
5120 * @param y Second vector
5121 */
5122 cross(
5123 this: MathJsChain<MathCollection>,
5124 y: MathCollection
5125 ): MathJsChain<Matrix | MathArray>
5126
5127 /**
5128 * Calculate the determinant of a matrix.
5129 */
5130
5131 det(this: MathJsChain<MathCollection>): MathJsChain<number>
5132
5133 /**
5134 * Create a diagonal matrix or retrieve the diagonal of a matrix. When x
5135 * is a vector, a matrix with vector x on the diagonal will be returned.
5136 * When x is a two dimensional matrix, the matrixes kth diagonal will be
5137 * returned as vector. When k is positive, the values are placed on the
5138 * super diagonal. When k is negative, the values are placed on the sub
5139 * diagonal.
5140 * @param k The diagonal where the vector will be filled in or
5141 * retrieved. Default value: 0.
5142 * @param format The matrix storage format. Default value: 'dense'.
5143 */
5144 diag(
5145 this: MathJsChain<MathCollection>,
5146 format?: string
5147 ): MathJsChain<Matrix>
5148 diag(
5149 this: MathJsChain<MathCollection>,
5150 k: number | BigNumber,
5151 format?: string
5152 ): MathJsChain<Matrix | MathArray>
5153
5154 /**
5155 * Calculate the dot product of two vectors. The dot product of A = [a1,
5156 * a2, a3, ..., an] and B = [b1, b2, b3, ..., bn] is defined as: dot(A,
5157 * B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn
5158 * @param y Second vector
5159 */
5160 dot(
5161 this: MathJsChain<MathCollection>,
5162 y: MathCollection
5163 ): MathJsChain<number>
5164
5165 /**
5166 * Compute the matrix exponential, expm(A) = e^A. The matrix must be
5167 * square. Not to be confused with exp(a), which performs element-wise
5168 * exponentiation. The exponential is calculated using the Padé
5169 * approximant with scaling and squaring; see “Nineteen Dubious Ways to
5170 * Compute the Exponential of a Matrix,” by Moler and Van Loan.
5171 */
5172
5173 expm(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5174
5175 /**
5176 * Create a 2-dimensional identity matrix with size m x n or n x n. The
5177 * matrix has ones on the diagonal and zeros elsewhere.
5178 * @param format The Matrix storage format
5179 */
5180 identity(
5181 this: MathJsChain<number | number[] | Matrix | MathArray>,
5182 format?: string
5183 ): MathJsChain<Matrix | MathArray | number>
5184
5185 /**
5186 * @param n The y dimension for the matrix
5187 * @param format The Matrix storage format
5188 */
5189 identity(
5190 this: MathJsChain<number>,
5191 n: number,
5192 format?: string
5193 ): MathJsChain<Matrix | MathArray | number>
5194
5195 /**
5196 * Filter the items in an array or one dimensional matrix.
5197 */
5198 filter(
5199 this: MathJsChain<Matrix | MathArray | string[]>,
5200 test:
5201 | ((
5202 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5203 value: any,
5204 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5205 index: any,
5206 matrix: Matrix | MathArray | string[]
5207 ) => boolean)
5208 | RegExp
5209 ): MathJsChain<Matrix | MathArray>
5210
5211 /**
5212 * Flatten a multi dimensional matrix into a single dimensional matrix.
5213 */
5214
5215 flatten<T extends MathCollection>(x: MathJsChain<T>): MathJsChain<T>
5216
5217 /**
5218 * Iterate over all elements of a matrix/array, and executes the given
5219 * callback function.
5220 */
5221 forEach<T extends Matrix | MathArray>(
5222 this: MathJsChain<T>,
5223 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5224 callback: (value: any, index: any, matrix: T) => void
5225 ): MathJsChain<T>
5226
5227 /**
5228 * Calculate the inverse of a square matrix.
5229 */
5230
5231 inv<T extends number | Complex | MathCollection>(
5232 this: MathJsChain<T>
5233 ): MathJsChain<NoLiteralType<T>>
5234
5235 /**
5236 * Calculate the kronecker product of two matrices or vectors
5237 * @param y Second vector
5238 */
5239 kron(
5240 this: MathJsChain<Matrix | MathArray>,
5241 y: Matrix | MathArray
5242 ): MathJsChain<Matrix>
5243
5244 /**
5245 * Iterate over all elements of a matrix/array, and executes the given
5246 * callback function.
5247 * @param callback The callback function is invoked with three
5248 * parameters: the value of the element, the index of the element, and
5249 * the Matrix/array being traversed.
5250 */
5251 map<T extends Matrix | MathArray>(
5252 this: MathJsChain<T>,
5253 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5254 callback: (value: any, index: any, matrix: T) => MathType | string
5255 ): MathJsChain<T>
5256
5257 /**
5258 * Create a matrix filled with ones. The created matrix can have one or
5259 * multiple dimensions.
5260 * @param format The matrix storage format
5261 */
5262 ones(
5263 this: MathJsChain<number | number[]>,
5264 format?: string
5265 ): MathJsChain<MathCollection>
5266
5267 /**
5268 * @param format The matrix storage format
5269 */
5270 ones(
5271 this: MathJsChain<number>,
5272 n: number,
5273 format?: string
5274 ): MathJsChain<MathCollection>
5275
5276 /**
5277 * Partition-based selection of an array or 1D matrix. Will find the kth
5278 * smallest value, and mutates the input array. Uses Quickselect.
5279 * @param k The kth smallest value to be retrieved; zero-based index
5280 * @param compare An optional comparator function. The function is
5281 * called as compare(a, b), and must return 1 when a > b, -1 when a < b,
5282 * and 0 when a == b. Default value: 'asc'.
5283 */
5284 partitionSelect(
5285 this: MathJsChain<MathCollection>,
5286 k: number,
5287 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5288 compare?: 'asc' | 'desc' | ((a: any, b: any) => number)
5289 ): MathJsChain<MathCollection>
5290
5291 /**
5292 * Create an array from a range. By default, the range end is excluded.
5293 * This can be customized by providing an extra parameter includeEnd.
5294 * @param end End of the range, excluded by default, included when
5295 * parameter includeEnd=true
5296 * @param step Step size. Default value is 1.
5297 * @param includeEnd: Option to specify whether to include the end or
5298 * not. False by default
5299 */
5300 range(this: MathJsChain<string>, includeEnd?: boolean): MathJsChain<Matrix>
5301 range(
5302 this: MathJsChain<number | BigNumber>,
5303 end: number | BigNumber,
5304 includeEnd?: boolean
5305 ): MathJsChain<Matrix>
5306 range(
5307 this: MathJsChain<number | BigNumber>,
5308 end: number | BigNumber,
5309 step: number | BigNumber,
5310 includeEnd?: boolean
5311 ): MathJsChain<Matrix>
5312
5313 /**
5314 * Reshape a multi dimensional array to fit the specified dimensions
5315 * @param sizes One dimensional array with integral sizes for each
5316 * dimension
5317 */
5318 reshape<T extends MathCollection>(
5319 this: MathJsChain<T>,
5320 sizes: number[]
5321 ): MathJsChain<T>
5322
5323 /**
5324 * Resize a matrix
5325 * @param size One dimensional array with numbers
5326 * @param defaultValue Zero by default, except in case of a string, in
5327 * that case defaultValue = ' ' Default value: 0.
5328 */
5329 resize<T extends MathCollection>(
5330 this: MathJsChain<T>,
5331 size: MathCollection,
5332 defaultValue?: number | string
5333 ): MathJsChain<T>
5334
5335 /**
5336 * Calculate the size of a matrix or scalar.
5337 */
5338 size(
5339 this: MathJsChain<
5340 boolean | number | Complex | Unit | string | MathCollection
5341 >
5342 ): MathJsChain<MathCollection>
5343
5344 /**
5345 * Sort the items in a matrix
5346 * @param compare An optional _comparator function or name. The function
5347 * is called as compare(a, b), and must return 1 when a > b, -1 when a <
5348 * b, and 0 when a == b. Default value: ‘asc
5349 */
5350 sort<T extends Matrix | MathArray>(
5351 this: MathJsChain<T>,
5352 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5353 compare: ((a: any, b: any) => number) | 'asc' | 'desc' | 'natural'
5354 ): MathJsChain<T>
5355
5356 /**
5357 * Calculate the principal square root of a square matrix. The principal
5358 * square root matrix X of another matrix A is such that X * X = A.
5359 */
5360
5361 sqrtm<T extends MathCollection>(A: MathJsChain<T>): MathJsChain<T>
5362
5363 /**
5364 * Squeeze a matrix, remove inner and outer singleton dimensions from a
5365 * matrix.
5366 */
5367
5368 squeeze<T extends MathCollection>(x: MathJsChain<T>): MathJsChain<T>
5369
5370 /**
5371 * Get or set a subset of a matrix or string.
5372 * @param index For each dimension, an index or list of indices to get or set
5373 * @param replacement An array, matrix, or scalar. If provided, the
5374 * subset is replaced with replacement. If not provided, the subset is
5375 * returned
5376 * @param defaultValue Default value, filled in on new entries when the
5377 * matrix is resized. If not provided, math.matrix elements will be left
5378 * undefined. Default value: undefined.
5379 */
5380 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5381 subset<T extends MathCollection | string>(
5382 this: MathJsChain<T>,
5383 index: Index,
5384 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5385 replacement?: any,
5386 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5387 defaultValue?: any
5388 ): MathJsChain<T>
5389
5390 /**
5391 * Calculate the trace of a matrix: the sum of the elements on the main
5392 * diagonal of a square matrix.
5393 */
5394
5395 trace(this: MathJsChain<MathCollection>): MathJsChain<number>
5396
5397 /**
5398 * Transpose a matrix. All values of the matrix are reflected over its
5399 * main diagonal. Only two dimensional matrices are supported.
5400 */
5401
5402 transpose<T extends MathCollection>(x: MathJsChain<T>): MathJsChain<T>
5403
5404 /**
5405 * Create a matrix filled with zeros. The created matrix can have one or
5406 * multiple dimensions.
5407 * @param format The matrix storage format
5408 * @returns A matrix filled with zeros
5409 */
5410 zeros(
5411 this: MathJsChain<number | number[]>,
5412 format?: string
5413 ): MathJsChain<MathCollection>
5414
5415 /**
5416 * @param n The y dimension of the matrix
5417 * @param format The matrix storage format
5418 */
5419 zeros(
5420 this: MathJsChain<number>,
5421 n: number,
5422 format?: string
5423 ): MathJsChain<MathCollection>
5424
5425 /*************************************************************************
5426 * Probability functions
5427 ************************************************************************/
5428
5429 /**
5430 * Compute the number of ways of picking k unordered outcomes from n
5431 * possibilities. Combinations only takes integer arguments. The
5432 * following condition must be enforced: k <= n.
5433 * @param k Number of objects in the subset
5434 */
5435 combinations<T extends number | BigNumber>(
5436 n: MathJsChain<T>,
5437 k: number | BigNumber
5438 ): MathJsChain<NoLiteralType<T>>
5439
5440 /**
5441 * Compute the factorial of a value Factorial only supports an integer
5442 * value as argument. For matrices, the function is evaluated element
5443 * wise.
5444 */
5445
5446 factorial<T extends number | BigNumber | MathCollection>(
5447 n: MathJsChain<T>
5448 ): MathJsChain<NoLiteralType<T>>
5449
5450 /**
5451 * Compute the gamma function of a value using Lanczos approximation for
5452 * small values, and an extended Stirling approximation for large
5453 * values. For matrices, the function is evaluated element wise.
5454 */
5455
5456 gamma<T extends number | BigNumber | Complex | MathCollection>(
5457 n: MathJsChain<T>
5458 ): MathJsChain<NoLiteralType<T>>
5459
5460 /**
5461 * Calculate the Kullback-Leibler (KL) divergence between two
5462 * distributions
5463 * @param p Second vector
5464 */
5465 kldivergence(
5466 this: MathJsChain<MathCollection>,
5467 p: MathCollection
5468 ): MathJsChain<number>
5469
5470 /**
5471 * Multinomial Coefficients compute the number of ways of picking a1,
5472 * a2, ..., ai unordered outcomes from n possibilities. multinomial
5473 * takes one array of integers as an argument. The following condition
5474 * must be enforced: every ai <= 0
5475 */
5476
5477 multinomial<T extends number | BigNumber>(
5478 a: MathJsChain<T[]>
5479 ): MathJsChain<NoLiteralType<T>>
5480
5481 /**
5482 * Compute the number of ways of obtaining an ordered subset of k
5483 * elements from a set of n elements. Permutations only takes integer
5484 * arguments. The following condition must be enforced: k <= n.
5485 * @param k The number of objects in the subset
5486 */
5487 permutations<T extends number | BigNumber>(
5488 n: MathJsChain<T>,
5489 k?: number | BigNumber
5490 ): MathJsChain<NoLiteralType<T>>
5491
5492 /**
5493 * Random pick a value from a one dimensional array. Array element is
5494 * picked using a random function with uniform distribution.
5495 * @param number An int or float
5496 * @param weights An array of ints or floats
5497 */
5498 pickRandom(
5499 array: MathJsChain<number[]>,
5500 number?: number,
5501 weights?: number[]
5502 ): MathJsChain<number | number[]>
5503
5504 /**
5505 * Return a random number larger or equal to min and smaller than max
5506 * using a uniform distribution.
5507 * @param min Minimum boundary for the random value, included
5508 * @param max Maximum boundary for the random value, excluded
5509 */
5510 random(this: MathJsChain<number>, max?: number): MathJsChain<number>
5511
5512 // tslint:disable-next-line unified-signatures
5513 random<T extends MathCollection>(
5514 this: MathJsChain<T>,
5515 min?: number,
5516 max?: number
5517 ): MathJsChain<T>
5518
5519 /**
5520 * Return a random integer number larger or equal to min and smaller
5521 * than max using a uniform distribution.
5522 * @param min Minimum boundary for the random value, included
5523 * @param max Maximum boundary for the random value, excluded
5524 */
5525 randomInt<T extends MathCollection>(
5526 this: MathJsChain<T>,
5527 max?: number
5528 ): MathJsChain<T>
5529 randomInt<T extends MathCollection>(
5530 this: MathJsChain<T>,
5531 max?: number
5532 ): MathJsChain<T>
5533 // tslint:disable-next-line unified-signatures
5534 randomInt<T extends MathCollection>(
5535 this: MathJsChain<T>,
5536 min: number,
5537 max: number
5538 ): MathJsChain<T>
5539
5540 /*************************************************************************
5541 * Relational functions
5542 ************************************************************************/
5543
5544 /**
5545 * Compare two values. Returns 1 when x > y, -1 when x < y, and 0 when x
5546 * == y. x and y are considered equal when the relative difference
5547 * between x and y is smaller than the configured epsilon. The function
5548 * cannot be used to compare values smaller than approximately 2.22e-16.
5549 * For matrices, the function is evaluated element wise.
5550 * @param y Second value to compare
5551 */
5552 compare(
5553 this: MathJsChain<MathType | string>,
5554 y: MathType | string
5555 ): MathJsChain<number | BigNumber | Fraction | MathCollection>
5556
5557 /**
5558 * Compare two values of any type in a deterministic, natural way. For
5559 * numeric values, the function works the same as math.compare. For
5560 * types of values that cant be compared mathematically, the function
5561 * compares in a natural way.
5562 * @param y Second value to compare
5563 */
5564 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5565 compareNatural(this: MathJsChain<any>, y: any): MathJsChain<number>
5566
5567 /**
5568 * Compare two strings lexically. Comparison is case sensitive. Returns
5569 * 1 when x > y, -1 when x < y, and 0 when x == y. For matrices, the
5570 * function is evaluated element wise.
5571 * @param y Second string to compare
5572 */
5573 compareText(
5574 this: MathJsChain<string | MathCollection>,
5575 y: string | MathCollection
5576 ): MathJsChain<number | MathCollection>
5577
5578 /**
5579 * Test element wise whether two matrices are equal. The function
5580 * accepts both matrices and scalar values.
5581 * @param y Second amtrix to compare
5582 */
5583 deepEqual(
5584 this: MathJsChain<MathType>,
5585 y: MathType
5586 ): MathJsChain<
5587 number | BigNumber | Fraction | Complex | Unit | MathCollection
5588 >
5589
5590 /**
5591 * Test whether two values are equal.
5592 *
5593 * The function tests whether the relative difference between x and y is
5594 * smaller than the configured epsilon. The function cannot be used to
5595 * compare values smaller than approximately 2.22e-16. For matrices, the
5596 * function is evaluated element wise. In case of complex numbers, x.re
5597 * must equal y.re, and x.im must equal y.im. Values null and undefined
5598 * are compared strictly, thus null is only equal to null and nothing
5599 * else, and undefined is only equal to undefined and nothing else.
5600 * @param y Second value to compare
5601 */
5602 equal(
5603 this: MathJsChain<MathType | string>,
5604 y: MathType | string
5605 ): MathJsChain<boolean | MathCollection>
5606
5607 /**
5608 * Check equality of two strings. Comparison is case sensitive. For
5609 * matrices, the function is evaluated element wise.
5610 * @param y Second string to compare
5611 */
5612 equalText(
5613 this: MathJsChain<string | MathCollection>,
5614 y: string | MathCollection
5615 ): MathJsChain<number | MathCollection>
5616
5617 /**
5618 * Test whether value x is larger than y. The function returns true when
5619 * x is larger than y and the relative difference between x and y is
5620 * larger than the configured epsilon. The function cannot be used to
5621 * compare values smaller than approximately 2.22e-16. For matrices, the
5622 * function is evaluated element wise.
5623 * @param y Second value to compare
5624 */
5625 larger(
5626 this: MathJsChain<MathType | string>,
5627 y: MathType | string
5628 ): MathJsChain<boolean | MathCollection>
5629
5630 /**
5631 * Test whether value x is larger or equal to y. The function returns
5632 * true when x is larger than y or the relative difference between x and
5633 * y is smaller than the configured epsilon. The function cannot be used
5634 * to compare values smaller than approximately 2.22e-16. For matrices,
5635 * the function is evaluated element wise.
5636 * @param y Second value to vcompare
5637 */
5638 largerEq(
5639 this: MathJsChain<MathType | string>,
5640 y: MathType | string
5641 ): MathJsChain<boolean | MathCollection>
5642
5643 /**
5644 * Test whether value x is smaller than y. The function returns true
5645 * when x is smaller than y and the relative difference between x and y
5646 * is smaller than the configured epsilon. The function cannot be used
5647 * to compare values smaller than approximately 2.22e-16. For matrices,
5648 * the function is evaluated element wise.
5649 * @param y Second value to vcompare
5650 */
5651 smaller(
5652 this: MathJsChain<MathType | string>,
5653 y: MathType | string
5654 ): MathJsChain<boolean | MathCollection>
5655
5656 /**
5657 * Test whether value x is smaller or equal to y. The function returns
5658 * true when x is smaller than y or the relative difference between x
5659 * and y is smaller than the configured epsilon. The function cannot be
5660 * used to compare values smaller than approximately 2.22e-16. For
5661 * matrices, the function is evaluated element wise.
5662 * @param y Second value to compare
5663 */
5664 smallerEq(
5665 this: MathJsChain<MathType | string>,
5666 y: MathType | string
5667 ): MathJsChain<boolean | MathCollection>
5668
5669 /**
5670 * Test whether two values are unequal. The function tests whether the
5671 * relative difference between x and y is larger than the configured
5672 * epsilon. The function cannot be used to compare values smaller than
5673 * approximately 2.22e-16. For matrices, the function is evaluated
5674 * element wise. In case of complex numbers, x.re must unequal y.re, or
5675 * x.im must unequal y.im. Values null and undefined are compared
5676 * strictly, thus null is unequal with everything except null, and
5677 * undefined is unequal with everything except undefined.
5678 * @param y Second value to vcompare
5679 */
5680 unequal(
5681 this: MathJsChain<MathType | string>,
5682 y: MathType | string
5683 ): MathJsChain<boolean | MathCollection>
5684
5685 /*************************************************************************
5686 * Set functions
5687 ************************************************************************/
5688
5689 /**
5690 * Create the cartesian product of two (multi)sets. Multi-dimension
5691 * arrays will be converted to single-dimension arrays and the values
5692 * will be sorted in ascending order before the operation.
5693 * @param a2 A (multi)set
5694 */
5695 setCartesian<T extends MathCollection>(
5696 this: MathJsChain<T>,
5697 a2: MathCollection
5698 ): MathJsChain<T>
5699
5700 /**
5701 * Create the difference of two (multi)sets: every element of set1, that
5702 * is not the element of set2. Multi-dimension arrays will be converted
5703 * to single-dimension arrays before the operation
5704 * @param a2 A (multi)set
5705 */
5706 setDifference<T extends MathCollection>(
5707 this: MathJsChain<T>,
5708 a2: MathCollection
5709 ): MathJsChain<T>
5710
5711 /**
5712 * Collect the distinct elements of a multiset. A multi-dimension array
5713 * will be converted to a single-dimension array before the operation.
5714 */
5715
5716 setDistinct<T extends MathCollection>(a: MathJsChain<T>): MathJsChain<T>
5717
5718 /**
5719 * Create the intersection of two (multi)sets. Multi-dimension arrays
5720 * will be converted to single-dimension arrays before the operation.
5721 * @param a2 A (multi)set
5722 */
5723 setIntersect<T extends MathCollection>(
5724 this: MathJsChain<T>,
5725 a2: MathCollection
5726 ): MathJsChain<T>
5727
5728 /**
5729 * Check whether a (multi)set is a subset of another (multi)set. (Every
5730 * element of set1 is the element of set2.) Multi-dimension arrays will
5731 * be converted to single-dimension arrays before the operation.
5732 * @param a2 A (multi)set
5733 */
5734 setIsSubset(
5735 this: MathJsChain<MathCollection>,
5736 a2: MathCollection
5737 ): MathJsChain<boolean>
5738
5739 /**
5740 * Count the multiplicity of an element in a multiset. A multi-dimension
5741 * array will be converted to a single-dimension array before the
5742 * operation.
5743 * @param a A multiset
5744 */
5745 setMultiplicity(
5746 e: MathJsChain<number | BigNumber | Fraction | Complex>,
5747 a: MathCollection
5748 ): MathJsChain<number>
5749
5750 /**
5751 * Create the powerset of a (multi)set. (The powerset contains very
5752 * possible subsets of a (multi)set.) A multi-dimension array will be
5753 * converted to a single-dimension array before the operation.
5754 */
5755
5756 setPowerset<T extends MathCollection>(a: MathJsChain<T>): MathJsChain<T>
5757
5758 /**
5759 * Count the number of elements of a (multi)set. When a second parameter
5760 * istrue’, count only the unique values. A multi-dimension array will
5761 * be converted to a single-dimension array before the operation.
5762 */
5763
5764 setSize(this: MathJsChain<MathCollection>): MathJsChain<number>
5765
5766 /**
5767 * Create the symmetric difference of two (multi)sets. Multi-dimension
5768 * arrays will be converted to single-dimension arrays before the
5769 * operation.
5770 * @param a2 A (multi)set
5771 */
5772 setSymDifference<T extends MathCollection>(
5773 this: MathJsChain<T>,
5774 a2: MathCollection
5775 ): MathJsChain<T>
5776
5777 /**
5778 * Create the union of two (multi)sets. Multi-dimension arrays will be
5779 * converted to single-dimension arrays before the operation.
5780 * @param a2 A (multi)set
5781 */
5782 setUnion<T extends MathCollection>(
5783 this: MathJsChain<T>,
5784 a2: MathCollection
5785 ): MathJsChain<T>
5786
5787 /*************************************************************************
5788 * Special functions
5789 ************************************************************************/
5790
5791 /**
5792 * Compute the erf function of a value using a rational Chebyshev
5793 * approximations for different intervals of x.
5794 */
5795 erf<T extends number | MathCollection>(
5796 this: MathJsChain<T>
5797 ): MathJsChain<NoLiteralType<T>>
5798
5799 /*************************************************************************
5800 * Statistics functions
5801 ************************************************************************/
5802
5803 /**
5804 * Compute the median absolute deviation of a matrix or a list with
5805 * values. The median absolute deviation is defined as the median of the
5806 * absolute deviations from the median.
5807 */
5808 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5809 mad(this: MathJsChain<MathCollection>): MathJsChain<any>
5810
5811 /**
5812 * Compute the maximum value of a matrix or a list with values. In case
5813 * of a multi dimensional array, the maximum of the flattened array will
5814 * be calculated. When dim is provided, the maximum over the selected
5815 * dimension will be calculated. Parameter dim is zero-based.
5816 * @param dim The maximum over the selected dimension
5817 */
5818
5819 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5820 max(this: MathJsChain<MathType[]>, dim?: number): MathJsChain<any>
5821 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5822 max(this: MathJsChain<MathCollection>, dim?: number): MathJsChain<any>
5823
5824 /**
5825 * Compute the mean value of matrix or a list with values. In case of a
5826 * multi dimensional array, the mean of the flattened array will be
5827 * calculated. When dim is provided, the maximum over the selected
5828 * dimension will be calculated. Parameter dim is zero-based.
5829 * @param dim The mean over the selected dimension
5830 */
5831 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5832 mean(this: MathJsChain<MathType[]>, dim?: number): MathJsChain<any>
5833 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5834 mean(this: MathJsChain<MathCollection>, dim?: number): MathJsChain<any>
5835
5836 /**
5837 * Compute the median of a matrix or a list with values. The values are
5838 * sorted and the middle value is returned. In case of an even number of
5839 * values, the average of the two middle values is returned. Supported
5840 * types of values are: Number, BigNumber, Unit In case of a (multi
5841 * dimensional) array or matrix, the median of all elements will be
5842 * calculated.
5843 */
5844 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5845 median(this: MathJsChain<MathType[]>, dim?: number): MathJsChain<any>
5846 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5847 median(this: MathJsChain<MathCollection>, dim?: number): MathJsChain<any>
5848
5849 /**
5850 * Compute the maximum value of a matrix or a list of values. In case of
5851 * a multi dimensional array, the maximum of the flattened array will be
5852 * calculated. When dim is provided, the maximum over the selected
5853 * dimension will be calculated. Parameter dim is zero-based.
5854 * @param dim The minimum over the selected dimension
5855 */
5856 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5857 min(this: MathJsChain<MathType[]>): MathJsChain<MathType[]>
5858 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5859 min(this: MathJsChain<MathCollection>, dim?: number): MathJsChain<any>
5860
5861 /**
5862 * Computes the mode of a set of numbers or a list with values(numbers
5863 * or characters). If there are more than one modes, it returns a list
5864 * of those values.
5865 */
5866
5867 mode(this: MathJsChain<MathType[]>): MathJsChain<MathType[]>
5868
5869 /**
5870 * Compute the product of a matrix or a list with values. In case of a
5871 * (multi dimensional) array or matrix, the sum of all elements will be
5872 * calculated.
5873 */
5874 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5875 prod(this: MathJsChain<MathType[]>): MathJsChain<any>
5876
5877 /**
5878 * Compute the prob order quantile of a matrix or a list with values.
5879 * The sequence is sorted and the middle value is returned. Supported
5880 * types of sequence values are: Number, BigNumber, Unit Supported types
5881 * of probability are: Number, BigNumber In case of a (multi
5882 * dimensional) array or matrix, the prob order quantile of all elements
5883 * will be calculated.
5884 * @param probOrN prob is the order of the quantile, while N is the
5885 * amount of evenly distributed steps of probabilities; only one of
5886 * these options can be provided
5887 * @param sorted =false is data sorted in ascending order
5888 */
5889 quantileSeq(
5890 A: MathJsChain<MathCollection>,
5891 prob: number | BigNumber | MathArray,
5892 sorted?: boolean
5893 ): MathJsChain<number | BigNumber | Unit | MathArray>
5894
5895 /**
5896 * Compute the standard deviation of a matrix or a list with values. The
5897 * standard deviations is defined as the square root of the variance:
5898 * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or
5899 * matrix, the standard deviation over all elements will be calculated.
5900 * Optionally, the type of normalization can be specified as second
5901 * parameter. The parameter normalization can be one of the following
5902 * values: 'unbiased' (default) The sum of squared errors is divided by
5903 * (n - 1) 'uncorrected' The sum of squared errors is divided by n
5904 * 'biased' The sum of squared errors is divided by (n + 1)
5905 * @param dim A dimension to compute standard deviation.
5906 * @param normalization Determines how to normalize the variance. Choose
5907 * ‘unbiased’ (default), ‘uncorrected’, orbiased’. Default value:
5908 * ‘unbiased’.
5909 * @returns The standard deviation
5910 */
5911 std(
5912 this: MathJsChain<number[]>,
5913 dim?: number,
5914 normalization?: 'unbiased' | 'uncorrected' | 'biased'
5915 ): MathJsChain<number>
5916
5917 /**
5918 * Compute the standard deviation of a matrix or a list with values. The
5919 * standard deviations is defined as the square root of the variance:
5920 * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or
5921 * matrix, the standard deviation over all elements will be calculated.
5922 * Optionally, the type of normalization can be specified as second
5923 * parameter. The parameter normalization can be one of the following
5924 * values: 'unbiased' (default) The sum of squared errors is divided by
5925 * (n - 1) 'uncorrected' The sum of squared errors is divided by n
5926 * 'biased' The sum of squared errors is divided by (n + 1)
5927 * @param normalization Determines how to normalize the variance. Choose
5928 * ‘unbiased’ (default), ‘uncorrected’, orbiased’. Default value:
5929 * ‘unbiased’.
5930 * @returns The standard deviation
5931 */
5932 std(
5933 this: MathJsChain<MathCollection>,
5934 dimension?: number,
5935 normalization?: 'unbiased' | 'uncorrected' | 'biased'
5936 ): MathJsChain<number[]>
5937
5938 /**
5939 * Compute the sum of a matrix or a list with values. In case of a
5940 * (multi dimensional) array or matrix, the sum of all elements will be
5941 * calculated.
5942 */
5943 std(
5944 this: MathJsChain<MathCollection>,
5945 normalization: 'unbiased' | 'uncorrected' | 'biased'
5946 ): MathJsChain<number>
5947
5948 /**
5949 * Compute the variance of a matrix or a list with values. In case of a
5950 * (multi dimensional) array or matrix, the variance over all elements
5951 * will be calculated. Optionally, the type of normalization can be
5952 * specified as second parameter. The parameter normalization can be one
5953 * of the following values: 'unbiased' (default) The sum of squared
5954 * errors is divided by (n - 1) 'uncorrected' The sum of squared errors
5955 * is divided by n 'biased' The sum of squared errors is divided by (n +
5956 * 1) Note that older browser may not like the variable name var. In
5957 * that case, the function can be called as math['var'](...) instead of
5958 * math.variance(...).
5959 * @param dim a dimension to compute variance.
5960 * @param normalization normalization Determines how to normalize the
5961 * variance. Chooseunbiased’ (default), ‘uncorrected’, orbiased’.
5962 * Default value: ‘unbiased’.
5963 * @returns The variance
5964 */
5965 variance(
5966 this: MathJsChain<Array<Array<number | BigNumber | Fraction>>>
5967 ): MathJsChain<number>
5968
5969 /**
5970 * Compute the variance of a matrix or a list with values. In case of a
5971 * (multi dimensional) array or matrix, the variance over all elements
5972 * will be calculated. Optionally, the type of normalization can be
5973 * specified as second parameter. The parameter normalization can be one
5974 * of the following values: 'unbiased' (default) The sum of squared
5975 * errors is divided by (n - 1) 'uncorrected' The sum of squared errors
5976 * is divided by n 'biased' The sum of squared errors is divided by (n +
5977 * 1) Note that older browser may not like the variable name var. In
5978 * that case, the function can be called as math['var'](...) instead of
5979 * math.variance(...).
5980 * @param normalization normalization Determines how to normalize the
5981 * variance. Chooseunbiased’ (default), ‘uncorrected’, orbiased’.
5982 * Default value: ‘unbiased’.
5983 * @returns The variance
5984 */
5985 variance(
5986 this: MathJsChain<MathCollection>,
5987 dimension?: number,
5988 normalization?: 'unbiased' | 'uncorrected' | 'biased'
5989 ): MathJsChain<number[]>
5990
5991 variance(
5992 this: MathJsChain<MathCollection>,
5993 normalization: 'unbiased' | 'uncorrected' | 'biased'
5994 ): MathJsChain<number>
5995
5996 /*************************************************************************
5997 * String functions
5998 ************************************************************************/
5999
6000 /**
6001 * Format a value of any type into a string.
6002 * @param options An object with formatting options.
6003 * @param callback A custom formatting function, invoked for all numeric
6004 * elements in value, for example all elements of a matrix, or the real
6005 * and imaginary parts of a complex number. This callback can be used to
6006 * override the built-in numeric notation with any type of formatting.
6007 * Function callback is called with value as parameter and must return a
6008 * string.
6009 * @see http://mathjs.org/docs/reference/functions/format.html
6010 */
6011 format(
6012 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6013 this: MathJsChain<any>,
6014 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6015 value: any,
6016 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6017 options?: FormatOptions | number | ((item: any) => string),
6018 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6019 callback?: (value: any) => string
6020 ): MathJsChain<string>
6021
6022 /**
6023 * Interpolate values into a string template.
6024 * @param values An object containing variables which will be filled in
6025 * in the template.
6026 * @param precision Number of digits to format numbers. If not provided,
6027 * the value will not be rounded.
6028 * @param options Formatting options, or the number of digits to format
6029 * numbers. See function math.format for a description of all options.
6030 */
6031 print(
6032 this: MathJsChain<string>,
6033 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6034 values: any,
6035 precision?: number,
6036 options?: number | object
6037 ): MathJsChain<string>
6038
6039 /*************************************************************************
6040 * Trigonometry functions
6041 ************************************************************************/
6042
6043 /**
6044 * Calculate the inverse cosine of a value. For matrices, the function
6045 * is evaluated element wise.
6046 */
6047
6048 acos(this: MathJsChain<number>): MathJsChain<number>
6049 acos(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6050 acos(this: MathJsChain<Complex>): MathJsChain<Complex>
6051 acos(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6052 acos(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6053
6054 /**
6055 * Calculate the hyperbolic arccos of a value, defined as acosh(x) =
6056 * ln(sqrt(x^2 - 1) + x). For matrices, the function is evaluated
6057 * element wise.
6058 */
6059
6060 acosh(this: MathJsChain<number>): MathJsChain<number>
6061 acosh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6062 acosh(this: MathJsChain<Complex>): MathJsChain<Complex>
6063 acosh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6064 acosh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6065
6066 /**
6067 * Calculate the inverse cotangent of a value. For matrices, the
6068 * function is evaluated element wise.
6069 */
6070
6071 acot(this: MathJsChain<number>): MathJsChain<number>
6072 acot(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6073 acot(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6074 acot(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6075
6076 /**
6077 * Calculate the hyperbolic arccotangent of a value, defined as acoth(x)
6078 * = (ln((x+1)/x) + ln(x/(x-1))) / 2. For matrices, the function is
6079 * evaluated element wise.
6080 */
6081
6082 acoth(this: MathJsChain<number>): MathJsChain<number>
6083 acoth(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6084 acoth(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6085 acoth(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6086
6087 /**
6088 * Calculate the inverse cosecant of a value. For matrices, the function
6089 * is evaluated element wise.
6090 */
6091
6092 acsc(this: MathJsChain<number>): MathJsChain<number>
6093 acsc(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6094 acsc(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6095 acsc(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6096
6097 /**
6098 * Calculate the hyperbolic arccosecant of a value, defined as acsch(x)
6099 * = ln(1/x + sqrt(1/x^2 + 1)). For matrices, the function is evaluated
6100 * element wise.
6101 */
6102
6103 acsch(this: MathJsChain<number>): MathJsChain<number>
6104 acsch(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6105 acsch(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6106 acsch(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6107
6108 /**
6109 * Calculate the inverse secant of a value. For matrices, the function
6110 * is evaluated element wise.
6111 */
6112
6113 asec(this: MathJsChain<number>): MathJsChain<number>
6114 asec(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6115 asec(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6116 asec(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6117
6118 /**
6119 * Calculate the hyperbolic arcsecant of a value, defined as asech(x) =
6120 * ln(sqrt(1/x^2 - 1) + 1/x). For matrices, the function is evaluated
6121 * element wise.
6122 */
6123
6124 asech(this: MathJsChain<number>): MathJsChain<number>
6125 asech(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6126 asech(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6127 asech(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6128
6129 /**
6130 * Calculate the inverse sine of a value. For matrices, the function is
6131 * evaluated element wise.
6132 */
6133
6134 asin(this: MathJsChain<number>): MathJsChain<number>
6135 asin(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6136 asin(this: MathJsChain<Complex>): MathJsChain<Complex>
6137 asin(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6138 asin(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6139
6140 /**
6141 * Calculate the hyperbolic arcsine of a value, defined as asinh(x) =
6142 * ln(x + sqrt(x^2 + 1)). For matrices, the function is evaluated
6143 * element wise.
6144 */
6145
6146 asinh(this: MathJsChain<number>): MathJsChain<number>
6147 asinh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6148 asinh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6149 asinh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6150
6151 /**
6152 * Calculate the inverse tangent of a value. For matrices, the function
6153 * is evaluated element wise.
6154 */
6155
6156 atan(this: MathJsChain<number>): MathJsChain<number>
6157 atan(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6158 atan(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6159 atan(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6160
6161 /**
6162 * Calculate the inverse tangent function with two arguments, y/x. By
6163 * providing two arguments, the right quadrant of the computed angle can
6164 * be determined. For matrices, the function is evaluated element wise.
6165 */
6166
6167 atan2(this: MathJsChain<number>, x: number): MathJsChain<number>
6168 atan2(
6169 this: MathJsChain<MathCollection>,
6170 x: MathCollection
6171 ): MathJsChain<MathCollection>
6172
6173 /**
6174 * Calculate the hyperbolic arctangent of a value, defined as atanh(x) =
6175 * ln((1 + x)/(1 - x)) / 2. For matrices, the function is evaluated
6176 * element wise.
6177 */
6178
6179 atanh(this: MathJsChain<number>): MathJsChain<number>
6180 atanh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6181 atanh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6182 atanh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6183
6184 /**
6185 * Calculate the cosine of a value. For matrices, the function is
6186 * evaluated element wise.
6187 */
6188
6189 cos(this: MathJsChain<number | Unit>): MathJsChain<number>
6190 cos(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6191 cos(this: MathJsChain<Complex>): MathJsChain<Complex>
6192 cos(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6193 cos(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6194
6195 /**
6196 * Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2
6197 * * (exp(x) + exp(-x)). For matrices, the function is evaluated element
6198 * wise.
6199 */
6200
6201 cosh(this: MathJsChain<number | Unit>): MathJsChain<number>
6202 cosh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6203 cosh(this: MathJsChain<Complex>): MathJsChain<Complex>
6204 cosh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6205 cosh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6206
6207 /**
6208 * Calculate the cotangent of a value. cot(x) is defined as 1 / tan(x).
6209 * For matrices, the function is evaluated element wise.
6210 */
6211
6212 cot(this: MathJsChain<number | Unit>): MathJsChain<number>
6213 cot(this: MathJsChain<Complex>): MathJsChain<Complex>
6214 cot(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6215 cot(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6216
6217 /**
6218 * Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1
6219 * / tanh(x). For matrices, the function is evaluated element wise.
6220 */
6221
6222 coth(this: MathJsChain<number | Unit>): MathJsChain<number>
6223 coth(this: MathJsChain<Complex>): MathJsChain<Complex>
6224 coth(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6225 coth(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6226
6227 /**
6228 * Calculate the cosecant of a value, defined as csc(x) = 1/sin(x). For
6229 * matrices, the function is evaluated element wise.
6230 */
6231
6232 csc(this: MathJsChain<number | Unit>): MathJsChain<number>
6233 csc(this: MathJsChain<Complex>): MathJsChain<Complex>
6234 csc(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6235 csc(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6236
6237 /**
6238 * Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1
6239 * / sinh(x). For matrices, the function is evaluated element wise.
6240 */
6241
6242 csch(this: MathJsChain<number | Unit>): MathJsChain<number>
6243 csch(this: MathJsChain<Complex>): MathJsChain<Complex>
6244 csch(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6245 csch(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6246
6247 /**
6248 * Calculate the secant of a value, defined as sec(x) = 1/cos(x). For
6249 * matrices, the function is evaluated element wise.
6250 */
6251
6252 sec(this: MathJsChain<number | Unit>): MathJsChain<number>
6253 sec(this: MathJsChain<Complex>): MathJsChain<Complex>
6254 sec(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6255 sec(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6256
6257 /**
6258 * Calculate the hyperbolic secant of a value, defined as sech(x) = 1 /
6259 * cosh(x). For matrices, the function is evaluated element wise.
6260 */
6261
6262 sech(this: MathJsChain<number | Unit>): MathJsChain<number>
6263 sech(this: MathJsChain<Complex>): MathJsChain<Complex>
6264 sech(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6265 sech(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6266
6267 /**
6268 * Calculate the sine of a value. For matrices, the function is
6269 * evaluated element wise.
6270 */
6271
6272 sin(this: MathJsChain<number | Unit>): MathJsChain<number>
6273 sin(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6274 sin(this: MathJsChain<Complex>): MathJsChain<Complex>
6275 sin(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6276 sin(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6277
6278 /**
6279 * Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 *
6280 * (exp(x) - exp(-x)). For matrices, the function is evaluated element
6281 * wise.
6282 */
6283
6284 sinh(this: MathJsChain<number | Unit>): MathJsChain<number>
6285 sinh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6286 sinh(this: MathJsChain<Complex>): MathJsChain<Complex>
6287 sinh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6288 sinh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6289
6290 /**
6291 * Calculate the tangent of a value. tan(x) is equal to sin(x) / cos(x).
6292 * For matrices, the function is evaluated element wise.
6293 */
6294
6295 tan(this: MathJsChain<number | Unit>): MathJsChain<number>
6296 tan(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6297 tan(this: MathJsChain<Complex>): MathJsChain<Complex>
6298 tan(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6299 tan(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6300
6301 /**
6302 * Calculate the hyperbolic tangent of a value, defined as tanh(x) =
6303 * (exp(2 * x) - 1) / (exp(2 * x) + 1). For matrices, the function is
6304 * evaluated element wise.
6305 */
6306
6307 tanh(this: MathJsChain<number | Unit>): MathJsChain<number>
6308 tanh(this: MathJsChain<BigNumber>): MathJsChain<BigNumber>
6309 tanh(this: MathJsChain<Complex>): MathJsChain<Complex>
6310 tanh(this: MathJsChain<MathArray>): MathJsChain<MathArray>
6311 tanh(this: MathJsChain<Matrix>): MathJsChain<Matrix>
6312
6313 /*************************************************************************
6314 * Unit functions
6315 ************************************************************************/
6316
6317 /**
6318 * Change the unit of a value. For matrices, the function is evaluated
6319 * element wise.
6320 * @param unit New unit. Can be a string like "cm" or a unit without
6321 * value.
6322 */
6323 to(
6324 this: MathJsChain<Unit | MathCollection>,
6325 unit: Unit | string
6326 ): MathJsChain<Unit | MathCollection>
6327
6328 /*************************************************************************
6329 * Utils functions
6330 ************************************************************************/
6331
6332 /**
6333 * Clone an object.
6334 */
6335
6336 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6337 clone<TValue>(this: MathJsChain<TValue>): MathJsChain<TValue>
6338
6339 /**
6340 * Test whether a value is an integer number. The function supports
6341 * number, BigNumber, and Fraction. The function is evaluated
6342 * element-wise in case of Array or Matrix input.
6343 */
6344
6345 isInteger(
6346 this: MathJsChain<number | BigNumber | Fraction | MathCollection>
6347 ): MathJsChain<boolean>
6348
6349 /**
6350 * Test whether a value is NaN (not a number). The function supports
6351 * types number, BigNumber, Fraction, Unit and Complex. The function is
6352 * evaluated element-wise in case of Array or Matrix input.
6353 */
6354
6355 isNaN(
6356 this: MathJsChain<number | BigNumber | Fraction | MathCollection | Unit>
6357 ): MathJsChain<boolean>
6358
6359 /**
6360 * Test whether a value is negative: smaller than zero. The function
6361 * supports types number, BigNumber, Fraction, and Unit. The function is
6362 * evaluated element-wise in case of Array or Matrix input.
6363 */
6364
6365 isNegative(
6366 this: MathJsChain<number | BigNumber | Fraction | MathCollection | Unit>
6367 ): MathJsChain<boolean>
6368
6369 /**
6370 * Test whether a value is an numeric value. The function is evaluated
6371 * element-wise in case of Array or Matrix input.
6372 */
6373
6374 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6375 isNumeric(this: MathJsChain<any>): MathJsChain<boolean>
6376
6377 /**
6378 * Test whether a value is positive: larger than zero. The function
6379 * supports types number, BigNumber, Fraction, and Unit. The function is
6380 * evaluated element-wise in case of Array or Matrix input.
6381 */
6382
6383 isPositive(
6384 this: MathJsChain<number | BigNumber | Fraction | MathCollection | Unit>
6385 ): MathJsChain<boolean>
6386
6387 /**
6388 * Test whether a value is prime: has no divisors other than itself and
6389 * one. The function supports type number, bignumber. The function is
6390 * evaluated element-wise in case of Array or Matrix input.
6391 */
6392
6393 isPrime(
6394 this: MathJsChain<number | BigNumber | MathCollection>
6395 ): MathJsChain<boolean>
6396
6397 /**
6398 * Test whether a value is zero. The function can check for zero for
6399 * types number, BigNumber, Fraction, Complex, and Unit. The function is
6400 * evaluated element-wise in case of Array or Matrix input.
6401 */
6402
6403 isZero(
6404 this: MathJsChain<
6405 number | BigNumber | Fraction | MathCollection | Unit | Complex
6406 >
6407 ): MathJsChain<boolean>
6408
6409 /**
6410 * Determine the type of a variable.
6411 */
6412
6413 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6414 typeOf(this: MathJsChain<any>): MathJsChain<string>
6415 }
6416
6417 interface ImportOptions {
6418 override?: boolean
6419 silent?: boolean
6420 wrap?: boolean
6421 }
6422
6423 interface ImportObject {
6424 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6425 [key: string]: any
6426 }
6427}
6428
\No newline at end of file