UNPKG

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