UNPKG

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