simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

index.d.ts (201512B)


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