From e268cebab05ed1d6c19edf37218c9dcc6b21c9a5 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Thu, 12 Oct 2023 11:11:19 +0200 Subject: [PATCH] Refactor index.d.ts to not use `export = math` (see #2919) --- test/typescript-tests/testTypes.ts | 2 +- tsconfig.json | 4 +- types/index.d.ts | 13212 ++++++++++++++------------- 3 files changed, 6764 insertions(+), 6454 deletions(-) diff --git a/test/typescript-tests/testTypes.ts b/test/typescript-tests/testTypes.ts index 23a1a34fd9..04f8555c0b 100644 --- a/test/typescript-tests/testTypes.ts +++ b/test/typescript-tests/testTypes.ts @@ -1980,7 +1980,7 @@ Extend functionality with import */ declare module 'mathjs' { - interface MathJsStatic { + interface MathJsInstance { testFun(): number value: number } diff --git a/tsconfig.json b/tsconfig.json index be75577370..65e05c024d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,11 +5,11 @@ "paths": { "mathjs": ["./types/index.d.ts"] }, - "moduleResolution": "node", + "moduleResolution": "nodenext", "typeRoots": [], "types": [], "lib": ["ES6", "DOM"], - "module": "ESNEXT", + "module": "NodeNext", "noEmit": true, "noImplicitAny": true, "noImplicitThis": true, diff --git a/types/index.d.ts b/types/index.d.ts index a013d1c2d5..e7b5d9597b 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,10 +1,8 @@ import { Decimal } from 'decimal.js' -declare const math: math.MathJsStatic export as namespace math -export = math -type NoLiteralType = T extends number +export type NoLiteralType = T extends number ? number : T extends string ? string @@ -12,6588 +10,6900 @@ type NoLiteralType = T extends number ? boolean : T -declare namespace math { - // TODO: introduce generics for MathCollection, MathMatrix, and MathArray - type MathNumericType = number | BigNumber | Fraction | Complex - type MathScalarType = MathNumericType | Unit - type MathArray = MathNumericType[] | MathNumericType[][] // TODO: MathArray can also contain Unit - type MathCollection = MathArray | Matrix - type MathType = MathScalarType | MathCollection - type MathExpression = string | string[] | MathCollection +// TODO: introduce generics for MathCollection, MathMatrix, and MathArray +export type MathNumericType = number | BigNumber | Fraction | Complex +export type MathScalarType = MathNumericType | Unit +export type MathArray = MathNumericType[] | MathNumericType[][] // TODO: MathArray can also contain Unit +export type MathCollection = MathArray | Matrix +export type MathType = MathScalarType | MathCollection +export type MathExpression = string | string[] | MathCollection +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export type FactoryFunction = (scope: any) => T + +// FactoryFunctionMap can be nested; all nested objects will be flattened +export interface FactoryFunctionMap { // eslint-disable-next-line @typescript-eslint/no-explicit-any - type FactoryFunction = (scope: any) => T + [key: string]: FactoryFunction | FactoryFunctionMap +} - // FactoryFunctionMap can be nested; all nested objects will be flattened - interface FactoryFunctionMap { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - [key: string]: FactoryFunction | FactoryFunctionMap - } +/** Available options for parse */ +export interface ParseOptions { + /** a set of custom nodes */ + nodes?: Record +} +/** + * Parse an expression. Returns a node tree, which can be evaluated by + * invoking node.evaluate(). + * + * Note the evaluating arbitrary expressions may involve security risks, + * see [https://mathjs.org/docs/expressions/security.html](https://mathjs.org/docs/expressions/security.html) for more information. + * + * Syntax: + * + * math.parse(expr) + * math.parse(expr, options) + * math.parse([expr1, expr2, expr3, ...]) + * math.parse([expr1, expr2, expr3, ...], options) + * + * Example: + * + * const node1 = math.parse('sqrt(3^2 + 4^2)') + * node1.compile().evaluate() // 5 + * + * let scope = {a:3, b:4} + * const node2 = math.parse('a * b') // 12 + * const code2 = node2.compile() + * code2.evaluate(scope) // 12 + * scope.a = 5 + * code2.evaluate(scope) // 20 + * + * const nodes = math.parse(['a = 3', 'b = 4', 'a * b']) + * nodes[2].compile().evaluate() // 12 + * + * See also: + * + * evaluate, compile + */ +export interface ParseFunction { + /** + * Parse an expression. Returns a node tree, which can be evaluated by + * invoking node.evaluate(); + * + * @param expr Expression to be parsed + * @param options Available options + * @returns A node + */ + (expr: MathExpression, options?: ParseOptions): MathNode - /** Available options for parse */ - interface ParseOptions { - /** a set of custom nodes */ - nodes?: Record - } /** * Parse an expression. Returns a node tree, which can be evaluated by - * invoking node.evaluate(). + * invoking node.evaluate(); * - * Note the evaluating arbitrary expressions may involve security risks, - * see [https://mathjs.org/docs/expressions/security.html](https://mathjs.org/docs/expressions/security.html) for more information. + * @param exprs Expressions to be parsed + * @param options Available options + * @returns An array of nodes + */ + (exprs: MathExpression[], options?: ParseOptions): MathNode[] + + /** + * Checks whether the current character `c` is a valid alpha character: * - * Syntax: + * - A latin letter (upper or lower case) Ascii: a-z, A-Z + * - An underscore Ascii: _ + * - A dollar sign Ascii: $ + * - A latin letter with accents Unicode: \u00C0 - \u02AF + * - A greek letter Unicode: \u0370 - \u03FF + * - A mathematical alphanumeric symbol Unicode: \u{1D400} - \u{1D7FF} excluding invalid code points * - * math.parse(expr) - * math.parse(expr, options) - * math.parse([expr1, expr2, expr3, ...]) - * math.parse([expr1, expr2, expr3, ...], options) + * The previous and next characters are needed to determine whether + * this character is part of a unicode surrogate pair. * - * Example: + * @param c Current character in the expression + * @param cPrev Previous character + * @param cNext Next character + */ + isAlpha(c: string, cPrev: string, cNext: string): boolean + /** + * Test whether a character is a valid latin, greek, or letter-like character * - * const node1 = math.parse('sqrt(3^2 + 4^2)') - * node1.compile().evaluate() // 5 + * @param c + */ + isValidLatinOrGreek(c: string): boolean + /** + * Test whether two given 16 bit characters form a surrogate pair of a + * unicode math symbol. * - * let scope = {a:3, b:4} - * const node2 = math.parse('a * b') // 12 - * const code2 = node2.compile() - * code2.evaluate(scope) // 12 - * scope.a = 5 - * code2.evaluate(scope) // 20 + * https://unicode-table.com/en/ + * https://www.wikiwand.com/en/Mathematical_operators_and_symbols_in_Unicode * - * const nodes = math.parse(['a = 3', 'b = 4', 'a * b']) - * nodes[2].compile().evaluate() // 12 + * Note: In ES6 will be unicode aware: + * https://stackoverflow.com/questions/280712/javascript-unicode-regexes + * https://mathiasbynens.be/notes/es6-unicode-regex + * + * @param high + * @param low + */ + isValidMathSymbol(high: string, low: string): boolean + /** + * Check whether given character c is a white space character: space, tab, or enter * - * See also: + * @param c + * @param nestingLevel + */ + isWhitespace(c: string, nestingLevel: number): boolean + /** + * Test whether the character c is a decimal mark (dot). + * This is the case when it's not the start of a delimiter '.*', './', or '.^' * - * evaluate, compile - */ - interface ParseFunction { - /** - * Parse an expression. Returns a node tree, which can be evaluated by - * invoking node.evaluate(); - * - * @param expr Expression to be parsed - * @param options Available options - * @returns A node - */ - (expr: MathExpression, options?: ParseOptions): MathNode - - /** - * Parse an expression. Returns a node tree, which can be evaluated by - * invoking node.evaluate(); - * - * @param exprs Expressions to be parsed - * @param options Available options - * @returns An array of nodes - */ - (exprs: MathExpression[], options?: ParseOptions): MathNode[] - - /** - * Checks whether the current character `c` is a valid alpha character: - * - * - A latin letter (upper or lower case) Ascii: a-z, A-Z - * - An underscore Ascii: _ - * - A dollar sign Ascii: $ - * - A latin letter with accents Unicode: \u00C0 - \u02AF - * - A greek letter Unicode: \u0370 - \u03FF - * - A mathematical alphanumeric symbol Unicode: \u{1D400} - \u{1D7FF} excluding invalid code points - * - * The previous and next characters are needed to determine whether - * this character is part of a unicode surrogate pair. - * - * @param c Current character in the expression - * @param cPrev Previous character - * @param cNext Next character - */ - isAlpha(c: string, cPrev: string, cNext: string): boolean - /** - * Test whether a character is a valid latin, greek, or letter-like character - * - * @param c - */ - isValidLatinOrGreek(c: string): boolean - /** - * Test whether two given 16 bit characters form a surrogate pair of a - * unicode math symbol. - * - * https://unicode-table.com/en/ - * https://www.wikiwand.com/en/Mathematical_operators_and_symbols_in_Unicode - * - * Note: In ES6 will be unicode aware: - * https://stackoverflow.com/questions/280712/javascript-unicode-regexes - * https://mathiasbynens.be/notes/es6-unicode-regex - * - * @param high - * @param low - */ - isValidMathSymbol(high: string, low: string): boolean - /** - * Check whether given character c is a white space character: space, tab, or enter - * - * @param c - * @param nestingLevel - */ - isWhitespace(c: string, nestingLevel: number): boolean - /** - * Test whether the character c is a decimal mark (dot). - * This is the case when it's not the start of a delimiter '.*', './', or '.^' - * - * @param c - * @param cNext - */ - isDecimalMark(c: string, cNext: string): boolean - /** - * checks if the given char c is a digit or dot - * - * @param c a string with one character - */ - isDigitDot(c: string): boolean - /** - * checks if the given char c is a digit - * - * @param c a string with one character - */ - isDigit(c: string): boolean - /** - * checks if the given char c is a hex digit - * - * @param c a string with one character - */ - isHexDigit(c: string): boolean - } + * @param c + * @param cNext + */ + isDecimalMark(c: string, cNext: string): boolean + /** + * checks if the given char c is a digit or dot + * + * @param c a string with one character + */ + isDigitDot(c: string): boolean + /** + * checks if the given char c is a digit + * + * @param c a string with one character + */ + isDigit(c: string): boolean + /** + * checks if the given char c is a hex digit + * + * @param c a string with one character + */ + isHexDigit(c: string): boolean +} - interface NodeCtor { - new (): MathNode - } +export interface NodeCtor { + new (): MathNode +} - interface AccessorNode extends MathNode { - type: 'AccessorNode' - isAccessorNode: true - object: TObject +export interface AccessorNode + extends MathNode { + type: 'AccessorNode' + isAccessorNode: true + object: TObject + index: IndexNode + name: string +} +export interface AccessorNodeCtor { + new ( + object: TObject, index: IndexNode - name: string - } - interface AccessorNodeCtor { - new ( - object: TObject, - index: IndexNode - ): AccessorNode - } + ): AccessorNode +} - interface ArrayNode extends MathNode { - type: 'ArrayNode' - isArrayNode: true - items: TItems - } - interface ArrayNodeCtor { - new ( - items: MathNode[] - ): ArrayNode - } +export interface ArrayNode + extends MathNode { + type: 'ArrayNode' + isArrayNode: true + items: TItems +} +export interface ArrayNodeCtor { + new ( + items: MathNode[] + ): ArrayNode +} - interface AssignmentNode - extends MathNode { - type: 'AssignmentNode' - isAssignmentNode: true - object: SymbolNode | AccessorNode - index: IndexNode | null +export interface AssignmentNode + extends MathNode { + type: 'AssignmentNode' + isAssignmentNode: true + object: SymbolNode | AccessorNode + index: IndexNode | null + value: TValue + name: string +} +export interface AssignmentNodeCtor { + new ( + object: SymbolNode, value: TValue - name: string - } - interface AssignmentNodeCtor { - new ( - object: SymbolNode, - value: TValue - ): AssignmentNode - new ( - object: SymbolNode | AccessorNode, - index: IndexNode, - value: TValue - ): AssignmentNode - } + ): AssignmentNode + new ( + object: SymbolNode | AccessorNode, + index: IndexNode, + value: TValue + ): AssignmentNode +} - interface BlockNode extends MathNode { - type: 'BlockNode' - isBlockNode: true - blocks: Array<{ node: TNode; visible: boolean }> - } - interface BlockNodeCtor { - new ( - arr: Array<{ node: TNode } | { node: TNode; visible: boolean }> - ): BlockNode - } +export interface BlockNode extends MathNode { + type: 'BlockNode' + isBlockNode: true + blocks: Array<{ node: TNode; visible: boolean }> +} +export interface BlockNodeCtor { + new ( + arr: Array<{ node: TNode } | { node: TNode; visible: boolean }> + ): BlockNode +} - interface ConditionalNode< +export interface ConditionalNode< + TCond extends MathNode = MathNode, + TTrueNode extends MathNode = MathNode, + TFalseNode extends MathNode = MathNode +> extends MathNode { + type: 'ConditionalNode' + isConditionalNode: boolean + condition: TCond + trueExpr: TTrueNode + falseExpr: TFalseNode +} +export interface ConditionalNodeCtor { + new < TCond extends MathNode = MathNode, TTrueNode extends MathNode = MathNode, TFalseNode extends MathNode = MathNode - > extends MathNode { - type: 'ConditionalNode' - isConditionalNode: boolean - condition: TCond - trueExpr: TTrueNode + >( + condition: TCond, + trueExpr: TTrueNode, falseExpr: TFalseNode - } - interface ConditionalNodeCtor { - new < - TCond extends MathNode = MathNode, - TTrueNode extends MathNode = MathNode, - TFalseNode extends MathNode = MathNode - >( - condition: TCond, - trueExpr: TTrueNode, - falseExpr: TFalseNode - ): ConditionalNode - } + ): ConditionalNode +} - interface ConstantNode - extends MathNode { - type: 'ConstantNode' - isConstantNode: true - // eslint-disable-next-line @typescript-eslint/no-explicit-any +export interface ConstantNode + extends MathNode { + type: 'ConstantNode' + isConstantNode: true + // eslint-disable-next-line @typescript-eslint/no-explicit-any + value: TValue +} + +export interface ConstantNodeCtor { + new ( value: TValue - } + ): ConstantNode +} + +export interface FunctionAssignmentNode + extends MathNode { + type: 'FunctionAssignmentNode' + isFunctionAssignmentNode: true + name: string + params: string[] + expr: TExpr +} +export interface FunctionAssignmentNodeCtor { + new ( + name: string, + params: string[], + expr: TExpr + ): FunctionAssignmentNode +} + +export interface FunctionNode< + TFn = SymbolNode, + TArgs extends MathNode[] = MathNode[] +> extends MathNode { + type: 'FunctionNode' + isFunctionNode: true + fn: TFn + args: TArgs +} +export interface FunctionNodeCtor { + new ( + fn: TFn, + args: TArgs + ): FunctionNode + // eslint-disable-next-line @typescript-eslint/no-explicit-any + onUndefinedFunction: (name: string) => any +} + +export interface IndexNode + extends MathNode { + type: 'IndexNode' + isIndexNode: true + dimensions: TDims + dotNotation: boolean +} +export interface IndexNodeCtor { + new (dimensions: TDims): IndexNode + new ( + dimensions: TDims, + dotNotation: boolean + ): IndexNode +} + +export interface ObjectNode< + TProps extends Record = Record +> extends MathNode { + type: 'ObjectNode' + isObjectNode: true + properties: TProps +} +export interface ObjectNodeCtor { + new = Record>( + properties: TProps + ): ObjectNode +} + +export type OperatorNodeMap = { + xor: 'xor' + and: 'and' + or: 'or' + bitOr: '|' + bitXor: '^|' + bitAnd: '&' + equal: '==' + unequal: '!=' + smaller: '<' + larger: '>' + smallerEq: '<=' + largerEq: '>=' + leftShift: '<<' + rightArithShift: '>>' + rightLogShift: '>>>' + to: 'to' + add: '+' + subtract: '-' + multiply: '*' + divide: '/' + dotMultiply: '.*' + dotDivide: './' + mod: 'mod' + unaryPlus: '+' + unaryMinus: '-' + bitNot: '~' + not: 'not' + pow: '^' + dotPow: '.^' + factorial: '!' +} + +export type OperatorNodeOp = OperatorNodeMap[keyof OperatorNodeMap] +export type OperatorNodeFn = keyof OperatorNodeMap + +export interface OperatorNode< + TOp extends OperatorNodeMap[TFn] = never, + TFn extends OperatorNodeFn = never, + TArgs extends MathNode[] = MathNode[] +> extends MathNode { + type: 'OperatorNode' + isOperatorNode: true + op: TOp + fn: TFn + args: TArgs + implicit: boolean + isUnary(): boolean + isBinary(): boolean +} + +export interface OperatorNodeCtor extends MathNode { + new < + TOp extends OperatorNodeMap[TFn], + TFn extends OperatorNodeFn, + TArgs extends MathNode[] + >( + op: TOp, + fn: TFn, + args: TArgs, + implicit?: boolean + ): OperatorNode +} +export interface ParenthesisNode + extends MathNode { + type: 'ParenthesisNode' + isParenthesisNode: true + content: TContent +} +export interface ParenthesisNodeCtor { + new (content: TContent): ParenthesisNode +} + +export interface RangeNode< + TStart extends MathNode = MathNode, + TEnd extends MathNode = MathNode, + TStep extends MathNode = MathNode +> extends MathNode { + type: 'RangeNode' + isRangeNode: true + start: TStart + end: TEnd + step: TStep | null +} +export interface RangeNodeCtor { + new < + TStart extends MathNode = MathNode, + TEnd extends MathNode = MathNode, + TStep extends MathNode = MathNode + >( + start: TStart, + end: TEnd, + step?: TStep + ): RangeNode +} + +export interface RelationalNode + extends MathNode { + type: 'RelationalNode' + isRelationalNode: true + conditionals: string[] + params: TParams +} +export interface RelationalNodeCtor { + new ( + conditionals: string[], + params: TParams + ): RelationalNode +} + +export interface SymbolNode extends MathNode { + type: 'SymbolNode' + isSymbolNode: true + name: string +} +export interface SymbolNodeCtor { + new (name: string): SymbolNode + // eslint-disable-next-line @typescript-eslint/no-explicit-any + onUndefinedSymbol: (name: string) => any +} + +/** + * @deprecated since version 11.3. Prefer `MathNode` instead + */ +export type MathNodeCommon = MathNode + +export type MathJsFunctionName = keyof MathJsInstance + +export interface LUDecomposition { + L: MathCollection + U: MathCollection + p: number[] +} + +export interface SLUDecomposition extends LUDecomposition { + q: number[] +} + +export interface QRDecomposition { + Q: MathCollection + R: MathCollection +} + +export interface SchurDecomposition { + U: MathCollection + T: MathCollection +} + +export interface FractionDefinition { + a: number + b: number +} + +export interface MathJsInstance extends MathJsFactory { + e: number + pi: number + i: number + Infinity: number + LN2: number + LN10: number + LOG2E: number + LOG10E: number + NaN: number + phi: number + SQRT1_2: number + SQRT2: number + tau: number + + // Class-like constructors + Node: NodeCtor + AccessorNode: AccessorNodeCtor + ArrayNode: ArrayNodeCtor + AssignmentNode: AssignmentNodeCtor + BlockNode: BlockNodeCtor + ConditionalNode: ConditionalNodeCtor + ConstantNode: ConstantNodeCtor + FunctionAssignmentNode: FunctionAssignmentNodeCtor + FunctionNode: FunctionNodeCtor + IndexNode: IndexNodeCtor + ObjectNode: ObjectNodeCtor + OperatorNode: OperatorNodeCtor + ParenthesisNode: ParenthesisNodeCtor + RangeNode: RangeNodeCtor + RelationalNode: RelationalNodeCtor + SymbolNode: SymbolNodeCtor + + Matrix: MatrixCtor + + /** + * If null were to be included in this interface, it would be + * auto-suggested as an import in VSCode. This causes issues because + * `null` is not a valid label. + * + * @see https://github.com/josdejong/mathjs/issues/2019 + */ + // null: number; + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + uninitialized: any + version: string + + expression: MathNode + + /** + * Returns reviver function that can be used as reviver in JSON.parse function. + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + reviver(): (key: any, value: any) => any + + /** + * Returns replacer function that can be used as replacer in JSON.stringify function. + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + replacer(): (key: any, value: any) => any + + /************************************************************************* + * Core functions + ************************************************************************/ + + /** + * Set configuration options for math.js, and get current options. Will + * emit a ‘config’ event, with arguments (curr, prev, changes). + * @param options Available options: {number} epsilon Minimum relative + * difference between two compared values, used by all comparison + * functions. {string} matrix A string ‘Matrix’ (default) or ‘Array’. + * {string} number A string ‘number’ (default), ‘BigNumber’, or + * ‘Fraction’ {number} precision The number of significant digits for + * BigNumbers. Not applicable for Numbers. {string} parenthesis How to + * display parentheses in LaTeX and string output. {string} randomSeed + * Random seed for seeded pseudo random number generator. Set to null to + * randomly seed. + * @returns Returns the current configuration + */ + config: (options: ConfigOptions) => ConfigOptions + /** + * Create a typed-function which checks the types of the arguments and + * can match them against multiple provided signatures. The + * typed-function automatically converts inputs in order to find a + * matching signature. Typed functions throw informative errors in case + * of wrong input arguments. + * @param name Optional name for the typed-function + * @param signatures Object with one or multiple function signatures + * @returns The created typed-function. + */ + typed: ( + name: string, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + signatures: Record any> + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ) => (...args: any[]) => any + + /************************************************************************* + * Construction functions + ************************************************************************/ + + /** + * Create a BigNumber, which can store numbers with arbitrary precision. + * When a matrix is provided, all elements will be converted to + * BigNumber. + * @param x Value for the big number, 0 by default. + * @returns The created bignumber + */ + bignumber( + x?: number | string | Fraction | BigNumber | Unit | boolean | null + ): BigNumber + bignumber(x: T): T + + /** + * Create a boolean or convert a string or number to a boolean. In case + * of a number, true is returned for non-zero numbers, and false in case + * of zero. Strings can be 'true' or 'false', or can contain a number. + * When value is a matrix, all elements will be converted to boolean. + * @param x A value of any type + * @returns The boolean value + */ + boolean(x: string | number | boolean | null): boolean + boolean(x: MathCollection): MathCollection + + /** + * Wrap any value in a chain, allowing to perform chained operations on + * the value. All methods available in the math.js library can be called + * upon the chain, and then will be evaluated with the value itself as + * first argument. The chain can be closed by executing chain.done(), + * which returns the final value. The chain has a number of special + * functions: done() Finalize the chain and return the chain's value. + * valueOf() The same as done() toString() Executes math.format() onto + * the chain's value, returning a string representation of the value. + * @param value A value of any type on which to start a chained + * operation. + * @returns The created chain + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + chain(value?: TValue): MathJsChain + + /** + * Create a complex value or convert a value to a complex value. + * @param args Arguments specifying the real and imaginary part of the + * complex number + * @returns Returns a complex value + */ + complex(arg?: MathNumericType | string | PolarCoordinates): Complex + complex(arg?: MathCollection): MathCollection + /** + * @param re Argument specifying the real part of the complex number + * @param im Argument specifying the imaginary part of the complex + * number + * @returns Returns a complex value + */ + complex(re: number, im: number): Complex + + /** + * Create a user-defined unit and register it with the Unit type. + * @param name The name of the new unit. Must be unique. Example: ‘knot’ + * @param definition Definition of the unit in terms of existing units. + * For example, ‘0.514444444 m / s’. + * @param options (optional) An object containing any of the following + * properties:
- prefixes {string} “none”, “short”, “long”, + * “binary_short”, or “binary_long”. The default is “none”.
- + * aliases {Array} Array of strings. Example: [‘knots’, ‘kt’, + * ‘kts’]
- offset {Numeric} An offset to apply when converting from + * the unit. For example, the offset for celsius is 273.15. Default is + * 0. + * @returns The new unit + */ + createUnit( + name: string, + definition?: string | UnitDefinition | Unit, + options?: CreateUnitOptions + ): Unit + /** + * Create a user-defined unit and register it with the Unit type. + * @param units Definition of the unit + * @param options + * @returns The new unit + */ + createUnit( + units: Record, + options?: CreateUnitOptions + ): Unit + + /** + * Create a fraction convert a value to a fraction. + * @param value Arguments specifying the numerator and denominator of the + * fraction + * @returns Returns a fraction + */ + fraction( + value: number | string | BigNumber | Unit | Fraction | FractionDefinition + ): Fraction + fraction(values: MathCollection): MathCollection + /** + * @param numerator Argument specifying the numerator of the fraction + * @param denominator Argument specifying the denominator of the + * fraction + * @returns Returns a fraction + */ + fraction(numerator: number, denominator: number): Fraction + + /** + * Create an index. An Index can store ranges having start, step, and + * end for multiple dimensions. Matrix.get, Matrix.set, and math.subset + * accept an Index as input. + * @param ranges Zero or more ranges or numbers. + * @returns Returns the created index + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + index(...ranges: any[]): Index + + /** + * Create a Matrix. The function creates a new math.type.Matrix object + * from an Array. A Matrix has utility functions to manipulate the data + * in the matrix, like getting the size and getting or setting values in + * the matrix. Supported storage formats are 'dense' and 'sparse'. + * @param format The Matrix storage format + * @returns The created Matrix + */ + matrix(format?: 'sparse' | 'dense'): Matrix + /** + * @param data A multi dimensional array + * @param format The Matrix storage format + * @param dataType The Matrix data type + * @returns The created Matrix + */ + matrix( + data: MathCollection | string[], + format?: 'sparse' | 'dense', + dataType?: string + ): Matrix + + /** + * Create a number or convert a string, boolean, or unit to a number. + * When value is a matrix, all elements will be converted to number. + * @param value Value to be converted + * @returns The created number + */ + number( + value?: string | number | BigNumber | Fraction | boolean | Unit | null + ): number + number(value?: MathCollection): number | MathCollection + /** + * @param value Value to be converted + * @param valuelessUnit A valueless unit, used to convert a unit to a + * number + * @returns The created number + */ + number(unit: Unit, valuelessUnit: Unit | string): number + + /** + * Create a Sparse Matrix. The function creates a new math.type.Matrix + * object from an Array. A Matrix has utility functions to manipulate + * the data in the matrix, like getting the size and getting or setting + * values in the matrix. + * @param data A two dimensional array + * @param dataType Sparse Matrix data type + * @returns The created matrix + */ + sparse(data?: MathCollection, dataType?: string): Matrix + + /** + * Split a unit in an array of units whose sum is equal to the original + * unit. + * @param unit A unit to be split + * @param parts An array of strings or valueless units + * @returns An array of units + */ + splitUnit(unit: Unit, parts: Unit[]): Unit[] + + /** + * Create a string or convert any object into a string. Elements of + * Arrays and Matrices are processed element wise. + * @param value A value to convert to a string + * @returns The created string + */ + string(value: MathNumericType | string | Unit | null): string + string(value: MathCollection): MathCollection + + /** + * Create a unit. Depending on the passed arguments, the function will + * create and return a new math.type.Unit object. When a matrix is + * provided, all elements will be converted to units. + * @param unit The unit to be created + * @returns The created unit + */ + unit(unit: string): Unit + /** + * @param unit The unit to be created + * @returns The created unit + */ + unit(unit: Unit): Unit + /** + * @param value The value of the unit to be created + * @param unit The unit to be created + * @returns The created unit + */ + unit(value: MathNumericType, unit: string): Unit + unit(value: MathCollection, unit: string): Unit[] + + /************************************************************************* + * Expression functions + ************************************************************************/ + + /** + * Parse and compile an expression. Returns a an object with a function + * evaluate([scope]) to evaluate the compiled expression. + * @param expr The expression to be compiled + * @returns An object with the compiled expression + */ + compile(expr: MathExpression): EvalFunction + /** + * @param exprs The expressions to be compiled + * @returns An array of objects with the compiled expressions + */ + compile(exprs: MathExpression[]): EvalFunction[] + + // TODO properly type this + /** + * Evaluate an expression. + * @param expr The expression to be evaluated + * @param scope Scope to read/write variables + * @returns The result of the expression + */ + evaluate( + expr: MathExpression | Matrix, + scope?: object + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ): any + evaluate( + expr: MathExpression[], + scope?: object + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ): any[] + + /** + * Retrieve help on a function or data type. Help files are retrieved + * from the documentation in math.expression.docs. + * @param search A function or function name for which to get help + * @returns A help object + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + help(search: () => any): Help + + /** + * Parse an expression. Returns a node tree, which can be evaluated by + * invoking node.evaluate(); + */ + parse: ParseFunction + + /** + * Create a parser. The function creates a new math.expression.Parser + * object. + * @returns A Parser object + */ + parser(): Parser + + /************************************************************************* + * Algebra functions + ************************************************************************/ + /** + * @param expr The expression to differentiate + * @param variable The variable over which to differentiate + * @param options There is one option available, simplify, which is true + * by default. When false, output will not be simplified. + * @returns The derivative of expr + */ + derivative( + expr: MathNode | string, + variable: MathNode | string, + options?: { simplify: boolean } + ): MathNode + + /** + * Solves the linear equation system by forwards substitution. Matrix + * must be a lower triangular matrix. + * @param L A N x N matrix or array (L) + * @param b A column vector with the b values + * @returns A column vector with the linear system solution (x) + */ + lsolve(L: Matrix, b: MathCollection): Matrix + lsolve(L: MathArray, b: MathCollection): MathArray + + /** + * Calculate the Matrix LU decomposition with partial pivoting. Matrix A + * is decomposed in two matrices (L, U) and a row permutation vector p + * where A[p,:] = L * U + * @param A A two dimensional matrix or array for which to get the LUP + * decomposition. + * @returns The lower triangular matrix, the upper triangular matrix and + * the permutation matrix. + */ + lup(A?: MathCollection): LUDecomposition + + /** + * Solves the linear system A * x = b where A is an [n x n] matrix and b + * is a [n] column vector. + * @param A Invertible Matrix or the Matrix LU decomposition + * @param b Column Vector + * @param order The Symbolic Ordering and Analysis order, see slu for + * details. Matrix must be a SparseMatrix + * @param threshold Partial pivoting threshold (1 for partial pivoting), + * see slu for details. Matrix must be a SparseMatrix. + * @returns Column vector with the solution to the linear system A * x = + * b + */ + lusolve( + A: Matrix, + b: MathCollection, + order?: number, + threshold?: number + ): Matrix + + lusolve( + A: MathArray, + b: MathCollection, + order?: number, + threshold?: number + ): MathArray + + lusolve(A: LUDecomposition, b: MathCollection): Matrix + + /* Finds the roots of a polynomial of degree three or less. Coefficients are given constant first + * followed by linear and higher powers in order; coefficients beyond the degree of the polynomial + * need not be specified. + * @param {number|Complex} constantCoeff + * @param {number|Complex} linearCoeff + * @param {number|Complex} quadraticCoeff + * @param {number|Complex} cubicCoeff + * @returns {Array} array of roots of specified polynomial + */ + polynomialRoot( + constantCoeff: number | Complex, + linearCoeff: number | Complex, + quadraticCoeff?: number | Complex, + cubicCoeff?: number | Complex + ): (number | Complex)[] - interface ConstantNodeCtor { - new ( - value: TValue - ): ConstantNode + /** + * Calculate the Matrix QR decomposition. Matrix A is decomposed in two + * matrices (Q, R) where Q is an orthogonal matrix and R is an upper + * triangular matrix. + * @param A A two dimensional matrix or array for which to get the QR + * decomposition. + * @returns Q: the orthogonal matrix and R: the upper triangular matrix + */ + qr(A: MathCollection): QRDecomposition + + rationalize( + expr: MathNode | string, + optional?: object | boolean, + detailed?: false + ): MathNode + /** + * Transform a rationalizable expression in a rational fraction. If + * rational fraction is one variable polynomial then converts the + * numerator and denominator in canonical form, with decreasing + * exponents, returning the coefficients of numerator. + * @param expr The expression to check if is a polynomial expression + * @param optional scope of expression or true for already evaluated + * rational expression at input + * @param detailed optional True if return an object, false if return + * expression node (default) + * @returns The rational polynomial of expr + */ + rationalize( + expr: MathNode | string, + optional?: object | boolean, + detailed?: true + ): { + expression: MathNode | string + variables: string[] + coefficients: MathType[] } - interface FunctionAssignmentNode - extends MathNode { - type: 'FunctionAssignmentNode' - isFunctionAssignmentNode: true - name: string - params: string[] - expr: TExpr - } - interface FunctionAssignmentNodeCtor { - new ( - name: string, - params: string[], - expr: TExpr - ): FunctionAssignmentNode - } + /** + * Simplify an expression tree. + * @param expr The expression to be simplified + * @param [rules] (optional) A list of rules are applied to an expression, repeating + * over the list until no further changes are made. It’s possible to + * pass a custom set of rules to the function as second argument. A rule + * can be specified as an object, string, or function. + * @param [scope] (optional) Scope to variables + * @param [options] (optional) An object with simplify options + * @returns Returns the simplified form of expr + */ + simplify: Simplify + + simplifyConstant(expr: MathNode | string, options?: SimplifyOptions): MathNode + simplifyCore(expr: MathNode | string, options?: SimplifyOptions): MathNode + + /** + * Replaces variable nodes with their scoped values + * @param node Tree to replace variable nodes in + * @param scope Scope to read/write variables + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + resolve(node: MathNode | string, scope?: Record): MathNode + resolve( + node: (MathNode | string)[], + // eslint-disable-next-line @typescript-eslint/no-explicit-any + scope?: Record + ): MathNode[] + // eslint-disable-next-line @typescript-eslint/no-explicit-any + resolve(node: Matrix, scope?: Record): Matrix + + /** + * Calculate the Sparse Matrix LU decomposition with full pivoting. + * Sparse Matrix A is decomposed in two matrices (L, U) and two + * permutation vectors (pinv, q) where P * A * Q = L * U + * @param A A two dimensional sparse matrix for which to get the LU + * decomposition. + * @param order The Symbolic Ordering and Analysis order: 0 - Natural + * ordering, no permutation vector q is returned 1 - Matrix must be + * square, symbolic ordering and analisis is performed on M = A + A' 2 - + * Symbolic ordering and analysis is performed on M = A' * A. Dense + * columns from A' are dropped, A recreated from A'. This is appropriate + * for LU factorization of non-symmetric matrices. 3 - Symbolic ordering + * and analysis is performed on M = A' * A. This is best used for LU + * factorization is matrix M has no dense rows. A dense row is a row + * with more than 10*sqr(columns) entries. + * @param threshold Partial pivoting threshold (1 for partial pivoting) + * @returns The lower triangular matrix, the upper triangular matrix and + * the permutation vectors. + */ + slu(A: Matrix, order: number, threshold: number): SLUDecomposition + + /** + * Solves the linear equation system by backward substitution. Matrix + * must be an upper triangular matrix. U * x = b + * @param U A N x N matrix or array (U) + * @param b A column vector with the b values + * @returns A column vector with the linear system solution (x) + */ + usolve(U: Matrix, b: MathCollection): Matrix + usolve(U: MathArray, b: MathCollection): MathArray + + /************************************************************************* + * Arithmetic functions + ************************************************************************/ + + /** + * Calculate the absolute value of a number. For matrices, the function + * is evaluated element wise. + * @param x A number or matrix for which to get the absolute value + * @returns Absolute value of x + */ + abs(x: T): T + + /** + * Add two values, x + y. For matrices, the function is evaluated + * element wise. + * @param x First value to add + * @param y Second value to add + * @returns Sum of x and y + */ + add(x: T, y: T): T + add(x: MathType, y: MathType): MathType + + /** + * Calculate the cubic root of a value. + * @param x Value for which to calculate the cubic root. + * @param allRoots Optional, false by default. Only applicable when x is + * a number or complex number. If true, all complex roots are returned, + * if false (default) the principal root is returned. + * @returns Returns the cubic root of x + */ + cbrt(x: Complex, allRoots?: boolean): Complex + cbrt(x: T): T + + // Rounding functions, grouped for similarity, even though it breaks + // the alphabetic order among arithmetic functions. + + /** + * Round a value towards plus infinity If x is complex, both real and + * imaginary part are rounded towards plus infinity. For matrices, the + * function is evaluated element wise. + * @param x Number to be rounded + * @param n Number of decimals Default value: 0. + * @returns Rounded value + */ + ceil( + x: T, + n?: number | BigNumber + ): NoLiteralType + ceil(x: MathNumericType, n: U): U + + /** + * Round a value towards zero. For matrices, the function is evaluated + * element wise. + * @param x Number to be rounded + * @param n Number of decimals Default value: 0. + * @returns Rounded value + */ + fix( + x: T, + n?: number | BigNumber + ): NoLiteralType + fix(x: MathNumericType, n: U): U + + /** + * Round a value towards minus infinity. For matrices, the function is + * evaluated element wise. + * @param x Number to be rounded + * @param n Number of decimals Default value: 0. + * @returns Rounded value + */ + floor( + x: T, + n?: number | BigNumber + ): NoLiteralType + floor(x: MathNumericType, n: U): U + + /** + * Round a value towards the nearest integer. For matrices, the function + * is evaluated element wise. + * @param x Number to be rounded + * @param n Number of decimals Default value: 0. + * @returns Rounded value of x + */ + round( + x: T, + n?: number | BigNumber + ): NoLiteralType + round(x: MathNumericType, n: U): U + + // End of group of rounding functions + + /** + * Compute the cube of a value, x * x * x. For matrices, the function is + * evaluated element wise. + * @param x Number for which to calculate the cube + * @returns Cube of x + */ + cube(x: T): T + + /** + * Divide two values, x / y. To divide matrices, x is multiplied with + * the inverse of y: x * inv(y). + * @param x Numerator + * @param y Denominator + * @returns Quotient, x / y + */ + divide(x: Unit, y: Unit): Unit | number + divide(x: Unit, y: number): Unit + divide(x: number, y: number): number + divide(x: MathType, y: MathType): MathType + + /** + * Divide two matrices element wise. The function accepts both matrices + * and scalar values. + * @param x Numerator + * @param y Denominator + * @returns Quotient, x ./ y + */ + dotDivide(x: T, y: MathType): T + dotDivide(x: MathType, y: T): T + dotDivide(x: Unit, y: MathType): Unit + dotDivide(x: MathType, y: Unit): Unit + dotDivide(x: MathNumericType, y: MathNumericType): MathNumericType + + /** + * Multiply two matrices element wise. The function accepts both + * matrices and scalar values. + * @param x Left hand value + * @param y Right hand value + * @returns Multiplication of x and y + */ + dotMultiply(x: T, y: MathType): T + dotMultiply(x: MathType, y: T): T + dotMultiply(x: Unit, y: MathType): Unit + dotMultiply(x: MathType, y: Unit): Unit + dotMultiply(x: MathNumericType, y: MathNumericType): MathNumericType + + /** + * Calculates the power of x to y element wise. + * @param x The base + * @param y The exponent + * @returns The value of x to the power y + */ + dotPow(x: T, y: MathType): T + + /** + * Calculate the exponent of a value. For matrices, the function is + * evaluated element wise. + * @param x A number or matrix to exponentiate + * @returns Exponent of x + */ + exp(x: T): T + + /** + * Calculate the value of subtracting 1 from the exponential value. For + * matrices, the function is evaluated element wise. + * @param x A number or matrix to apply expm1 + * @returns Exponent of x + */ + expm1(x: T): T + + /** + * Calculate the greatest common divisor for two or more values or + * arrays. For matrices, the function is evaluated element wise. + * @param args Two or more integer numbers + * @returns The greatest common divisor + */ + gcd(...args: T[]): T + gcd(args: T[]): T + + /** + * Calculate the hypotenusa of a list with values. The hypotenusa is + * defined as: hypot(a, b, c, ...) = sqrt(a^2 + b^2 + c^2 + ...) For + * matrix input, the hypotenusa is calculated for all values in the + * matrix. + * @param args A list with numeric values or an Array or Matrix. Matrix + * and Array input is flattened and returns a single number for the + * whole matrix. + * @returns Returns the hypothenuse of the input values. + */ + hypot(...args: T[]): T + + /** + * Calculate the least common multiple for two or more values or arrays. + * lcm is defined as: lcm(a, b) = abs(a * b) / gcd(a, b) For matrices, + * the function is evaluated element wise. + * @param a An integer number + * @param b An integer number + * @returns The least common multiple + */ + lcm(a: T, b: T): T + + /** + * Calculate the logarithm of a value. + * @param x Value for which to calculate the logarithm. + * @param base Optional base for the logarithm. If not provided, the + * natural logarithm of x is calculated. Default value: e. + * @returns Returns the logarithm of x + */ + log( + x: T, + base?: number | BigNumber | Complex + ): NoLiteralType + + /** + * Calculate the 10-base of a value. This is the same as calculating + * log(x, 10). For matrices, the function is evaluated element wise. + * @param x Value for which to calculate the logarithm. + * @returns Returns the 10-base logarithm of x + */ + log10(x: T): T + + /** + * Calculate the logarithm of a value+1. For matrices, the function is + * evaluated element wise. + * @param x Value for which to calculate the logarithm. + * @returns Returns the logarithm of x+1 + */ + log1p( + x: T, + base?: number | BigNumber | Complex + ): T + + /** + * Calculate the 2-base of a value. This is the same as calculating + * log(x, 2). For matrices, the function is evaluated element wise. + * @param x Value for which to calculate the logarithm. + * @returns Returns the 2-base logarithm of x + */ + log2(x: T): T + + /** + * Calculates the modulus, the remainder of an integer division. For + * matrices, the function is evaluated element wise. The modulus is + * defined as: x - y * floor(x / y) + * @see http://en.wikipedia.org/wiki/Modulo_operation. + * @param x Dividend + * @param y Divisor + * @returns Returns the remainder of x divided by y + */ + mod( + x: T, + y: number | BigNumber | Fraction | MathCollection + ): NoLiteralType + + /** + * Multiply two values, x * y. The result is squeezed. For matrices, the + * matrix product is calculated. + * @param x The first value to multiply + * @param y The second value to multiply + * @returns Multiplication of x and y + */ + + multiply(x: T, y: MathType): Matrix + multiply(x: MathType, y: T): Matrix + + multiply(x: T, y: T[]): T + multiply(x: T[], y: T): T + multiply(x: T, y: T): T + multiply(x: Unit, y: Unit): Unit + multiply(x: number, y: number): number + multiply(x: MathType, y: MathType): MathType + + /** + * Calculate the norm of a number, vector or matrix. The second + * parameter p is optional. If not provided, it defaults to 2. + * @param x Value for which to calculate the norm + * @param p Vector space. Supported numbers include Infinity and + * -Infinity. Supported strings are: 'inf', '-inf', and 'fro' (The + * Frobenius norm) Default value: 2. + * @returns the p-norm + */ + norm( + x: number | BigNumber | Complex | MathCollection, + p?: number | BigNumber | string + ): number | BigNumber + + /** + * Calculate the nth root of a value. The principal nth root of a + * positive real number A, is the positive real solution of the equation + * x^root = A For matrices, the function is evaluated element wise. + * @param a Value for which to calculate the nth root + * @param root The root. Default value: 2. + * @return The nth root of a + */ + nthRoot( + a: number | BigNumber | MathCollection | Complex, + root?: number | BigNumber + ): number | Complex | MathCollection + + /** + * Calculates the power of x to y, x ^ y. Matrix exponentiation is + * supported for square matrices x, and positive integer exponents y. + * @param x The base + * @param y The exponent + * @returns x to the power y + */ + pow(x: MathType, y: number | BigNumber | Complex): MathType + + /** + * Compute the sign of a value. The sign of a value x is: 1 when x > 1 + * -1 when x < 0 0 when x == 0 For matrices, the function is evaluated + * element wise. + * @param x The number for which to determine the sign + * @returns The sign of x + */ + sign(x: T): T + + /** + * Calculate the square root of a value. For matrices, use either + * sqrtm for the matrix square root, or map(M, sqrt) to take the + * square root element wise. + * @param x Value for which to calculate the square root + * @returns Returns the square root of x + */ + sqrt(x: number): number | Complex + sqrt(x: T): T + + /** + * Compute the square of a value, x * x. + * @param x Number for which to calculate the square + * @returns Squared value + */ + square(x: T): T + + /** + * Subtract two values, x - y. For matrices, the function is evaluated + * element wise. + * @param x Initial value + * @param y Value to subtract from x + * @returns Subtraction of x and y + */ + subtract(x: T, y: T): T + subtract(x: MathType, y: MathType): MathType + + /** + * Inverse the sign of a value, apply a unary minus operation. For + * matrices, the function is evaluated element wise. Boolean values and + * strings will be converted to a number. For complex numbers, both real + * and complex value are inverted. + * @param x Number to be inverted + * @returns Retursn the value with inverted sign + */ + unaryMinus(x: T): T + + /** + * Unary plus operation. Boolean values and strings will be converted to + * a number, numeric values will be returned as is. For matrices, the + * function is evaluated element wise. + * @param x Input value + * @returns Returns the input value when numeric, converts to a number + * when input is non-numeric. + */ + unaryPlus(x: T): T + + /** + * Calculate the extended greatest common divisor for two values. See + * http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm. + * @param a An integer number + * @param b An integer number + * @returns Returns an array containing 3 integers [div, m, n] where div + * = gcd(a, b) and a*m + b*n = div + */ + xgcd(a: number | BigNumber, b: number | BigNumber): MathArray + + /************************************************************************* + * Bitwise functions + ************************************************************************/ + + /** + * Bitwise AND two values, x & y. For matrices, the function is + * evaluated element wise. + * @param x First value to and + * @param y Second value to and + * @returns AND of x and y + */ + bitAnd( + x: T, + y: number | BigNumber | MathCollection + ): NoLiteralType + + /** + * Bitwise NOT value, ~x. For matrices, the function is evaluated + * element wise. For units, the function is evaluated on the best prefix + * base. + * @param x Value to not + * @returns NOT of x + */ + bitNot(x: T): T + + /** + * Bitwise OR two values, x | y. For matrices, the function is evaluated + * element wise. For units, the function is evaluated on the lowest + * print base. + * @param x First value to or + * @param y Second value to or + * @returns OR of x and y + */ + bitOr(x: T, y: T): T + + /** + * Bitwise XOR two values, x ^ y. For matrices, the function is + * evaluated element wise. + * @param x First value to xor + * @param y Second value to xor + * @returns XOR of x and y + */ + bitXor( + x: T, + y: number | BigNumber | MathCollection + ): NoLiteralType + + /** + * Bitwise left logical shift of a value x by y number of bits, x << y. + * For matrices, the function is evaluated element wise. For units, the + * function is evaluated on the best prefix base. + * @param x Value to be shifted + * @param y Amount of shifts + * @returns x shifted left y times + */ + leftShift( + x: T, + y: number | BigNumber + ): NoLiteralType + + /** + * Bitwise right arithmetic shift of a value x by y number of bits, x >> + * y. For matrices, the function is evaluated element wise. For units, + * the function is evaluated on the best prefix base. + * @param x Value to be shifted + * @param y Amount of shifts + * @returns x sign-filled shifted right y times + */ + rightArithShift( + x: T, + y: number | BigNumber + ): NoLiteralType + + /** + * Bitwise right logical shift of value x by y number of bits, x >>> y. + * For matrices, the function is evaluated element wise. For units, the + * function is evaluated on the best prefix base. + * @param x Value to be shifted + * @param y Amount of shifts + * @returns x zero-filled shifted right y times + */ + rightLogShift( + x: T, + y: number + ): NoLiteralType + + /************************************************************************* + * Combinatorics functions + ************************************************************************/ + + /** + * The Bell Numbers count the number of partitions of a set. A partition + * is a pairwise disjoint subset of S whose union is S. bellNumbers only + * takes integer arguments. The following condition must be enforced: n + * >= 0 + * @param n Total number of objects in the set + * @returns B(n) + */ + bellNumbers(n: T): T + + /** + * The Catalan Numbers enumerate combinatorial structures of many + * different types. catalan only takes integer arguments. The following + * condition must be enforced: n >= 0 + * @param n nth Catalan number + * @returns Cn(n) + */ + catalan(n: T): T + + /** + * The composition counts of n into k parts. Composition only takes + * integer arguments. The following condition must be enforced: k <= n. + * @param n Total number of objects in the set + * @param k Number of objects in the subset + * @returns Returns the composition counts of n into k parts. + */ + composition( + n: T, + k: number | BigNumber + ): NoLiteralType + + /** + * The Stirling numbers of the second kind, counts the number of ways to + * partition a set of n labelled objects into k nonempty unlabelled + * subsets. stirlingS2 only takes integer arguments. The following + * condition must be enforced: k <= n. If n = k or k = 1, then s(n,k) = + * 1 + * @param n Total number of objects in the set + * @param k Number of objects in the subset + * @returns S(n,k) + */ + stirlingS2( + n: T, + k: number | BigNumber + ): NoLiteralType + + /************************************************************************* + * Complex functions + ************************************************************************/ + + /** + * Compute the argument of a complex value. For a complex number a + bi, + * the argument is computed as atan2(b, a). For matrices, the function + * is evaluated element wise. + * @param x A complex number or array with complex numbers + * @returns The argument of x + */ + arg(x: number | Complex): number + arg(x: BigNumber | Complex): BigNumber + arg(x: T): T + + /** + * Compute the complex conjugate of a complex value. If x = a+bi, the + * complex conjugate of x is a - bi. For matrices, the function is + * evaluated element wise. + * @param x A complex number or array with complex numbers + * @returns The complex conjugate of x + */ + conj( + x: T + ): NoLiteralType + + /** + * Get the imaginary part of a complex number. For a complex number a + + * bi, the function returns b. For matrices, the function is evaluated + * element wise. + * @param x A complex number or array with complex numbers + * @returns The imaginary part of x + */ + im(x: MathJsChain): MathJsChain + im(x: MathJsChain): MathJsChain + + /** + * Get the real part of a complex number. For a complex number a + bi, + * the function returns a. For matrices, the function is evaluated + * element wise. + * @param x A complex number or array of complex numbers + * @returns The real part of x + */ + re(x: MathJsChain): MathJsChain + re(x: MathJsChain): MathJsChain + + /************************************************************************* + * Geometry functions + ************************************************************************/ + + /** + * Calculates: The eucledian distance between two points in 2 and 3 + * dimensional spaces. Distance between point and a line in 2 and 3 + * dimensional spaces. Pairwise distance between a set of 2D or 3D + * points NOTE: When substituting coefficients of a line(a, b and c), + * use ax + by + c = 0 instead of ax + by = c For parametric equation of + * a 3D line, x0, y0, z0, a, b, c are from: (x−x0, y−y0, z−z0) = t(a, b, + * c) + * @param x Coordinates of the first point + * @param y Coordinates of the second point OR coefficients of a line in 3D OR first end-point of a line if the calculation is for distance between point and a line in 2D + * @param z Coordinates of second end-point of a line if the calculation is for distance between point and a line in 2D + * @returns Returns the distance from two/three points + */ + distance( + x: MathCollection | object, + y: MathCollection | object, + z?: MathCollection | object + ): number | BigNumber + + /** + * Calculates the point of intersection of two lines in two or three + * dimensions and of a line and a plane in three dimensions. The inputs + * are in the form of arrays or 1 dimensional matrices. The line + * intersection functions return null if the lines do not meet. Note: + * Fill the plane coefficients as x + y + z = c and not as x + y + z + c + * = 0. + * @param w Co-ordinates of first end-point of first line + * @param x Co-ordinates of second end-point of first line + * @param y Co-ordinates of first end-point of second line OR + * Coefficients of the plane's equation + * @param z Co-ordinates of second end-point of second line OR null if + * the calculation is for line and plane + * @returns Returns the point of intersection of lines/lines-planes + */ + intersect( + w: MathCollection, + x: MathCollection, + y: MathCollection, + z?: MathCollection + ): MathArray + + /************************************************************************* + * Logical functions + ************************************************************************/ + + /** + * Logical and. Test whether two values are both defined with a + * nonzero/nonempty value. For matrices, the function is evaluated + * element wise. + * @param x First value to and + * @param y Second value to and + * @returns Returns true when both inputs are defined with a + * nonzero/nonempty value. + */ + and( + x: number | BigNumber | Complex | Unit | MathCollection, + y: number | BigNumber | Complex | Unit | MathCollection + ): boolean | MathCollection + + /** + * Logical not. Flips boolean value of a given parameter. For matrices, + * the function is evaluated element wise. + * @param x First value to not + * @returns Returns true when input is a zero or empty value. + */ + not( + x: number | BigNumber | Complex | Unit | MathCollection + ): boolean | MathCollection + + /** + * Logical or. Test if at least one value is defined with a + * nonzero/nonempty value. For matrices, the function is evaluated + * element wise. + * @param x First value to or + * @param y Second value to or + * @returns Returns true when one of the inputs is defined with a + * nonzero/nonempty value. + */ + or( + x: number | BigNumber | Complex | Unit | MathCollection, + y: number | BigNumber | Complex | Unit | MathCollection + ): boolean | MathCollection + + /** + * Logical xor. Test whether one and only one value is defined with a + * nonzero/nonempty value. For matrices, the function is evaluated + * element wise. + * @param x First value to xor + * @param y Second value to xor + * @returns Returns true when one and only one input is defined with a + * nonzero/nonempty value. + */ + xor( + x: number | BigNumber | Complex | Unit | MathCollection, + y: number | BigNumber | Complex | Unit | MathCollection + ): boolean | MathCollection + + /************************************************************************* + * Matrix functions + ************************************************************************/ + + /** + * Apply a function that maps an array to a scalar along a given axis of a + * matrix or array. Returns a new matrix or array with one less dimension + * than the input. + * @param array The input Matrix + * @param dim The dimension along which the callback is applied + * @param callback The callback function that is applied. This Function should take an + * array or 1-d matrix as an input and return a number. + * @returns The residual matrix with the function applied over some dimension. + */ + apply( + array: T, + dim: number, + callback: (array: MathCollection) => number + ): T + + /** + * Concatenate two or more matrices. dim: number is a zero-based + * dimension over which to concatenate the matrices. By default the last + * dimension of the matrices. + * @param args Two or more matrices + * @returns Concatenated matrix + */ + concat(...args: Array): MathCollection + + /** + * Calculate the cross product for two vectors in three dimensional + * space. The cross product of A = [a1, a2, a3] and B =[b1, b2, b3] is + * defined as: cross(A, B) = [ a2 * b3 - a3 * b2, a3 * b1 - a1 * b3, a1 + * * b2 - a2 * b1 ] + * @param x First vector + * @param y Second vector + * @returns Returns the cross product of x and y + */ + cross(x: MathCollection, y: MathCollection): MathCollection + + /** + * Calculate the determinant of a matrix. + * @param x A Matrix + * @returns the determinant of x + */ + det(x: MathCollection): number + + /** + * Create a diagonal matrix or retrieve the diagonal of a matrix. When x + * is a vector, a matrix with vector x on the diagonal will be returned. + * When x is a two dimensional matrix, the matrixes kth diagonal will be + * returned as vector. When k is positive, the values are placed on the + * super diagonal. When k is negative, the values are placed on the sub + * diagonal. + * @param X A two dimensional matrix or a vector + * @param k The diagonal where the vector will be filled in or + * retrieved. Default value: 0. + * @param format The matrix storage format. Default value: 'dense'. + * @returns Diagonal matrix from input vector, or diagonal from input + * matrix + */ + diag(X: MathCollection, format?: string): Matrix + diag( + X: MathCollection, + k: number | BigNumber, + format?: string + ): MathCollection + + /** + * Calculate the dot product of two vectors. The dot product of A = [a1, + * a2, a3, ..., an] and B = [b1, b2, b3, ..., bn] is defined as: dot(A, + * B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn + * @param x First vector + * @param y Second vector + * @returns Returns the dot product of x and y + */ + dot(x: MathCollection, y: MathCollection): number + + /** + * Compute eigenvalues and eigenvectors of a matrix. + * The eigenvalues are sorted by their absolute value, ascending. + * An eigenvalue with multiplicity k will be listed k times. + * The eigenvectors are returned as an array of objects, each with a + * `value` and a `vector`. If the algorithm fails to converge, + * it will throw an error – in that case, however, you may still find useful + * information in err.values and err.vectors + * @param x Matrix to be diagonalized + * @param prec Precision, default value: 1e-15 + * @returns Object containing an array of eigenvalues and a matrix with eigenvectors as columns. + */ + eigs( + x: MathCollection, + prec?: number | BigNumber + ): { + values: MathCollection + eigenvectors: { + value: number | BigNumber + vector: MathCollection + }[] + } + + /** + * Compute the matrix exponential, expm(A) = e^A. The matrix must be + * square. Not to be confused with exp(a), which performs element-wise + * exponentiation. The exponential is calculated using the Padé + * approximant with scaling and squaring; see “Nineteen Dubious Ways to + * Compute the Exponential of a Matrix,” by Moler and Van Loan. + * @param x A square matrix + * @returns The exponential of x + */ + expm(x: Matrix): Matrix + + /** + * Solves the real-valued Sylvester equation AX-XB=C for X, where A, B and C are + * matrices of appropriate dimensions, being A and B squared. The method used is + * the Bartels-Stewart algorithm. + * https://en.wikipedia.org/wiki/Sylvester_equation + * @param A Matrix A + * @param B Matrix B + * @param C Matrix C + * @returns Matrix X, solving the Sylvester equation + */ + sylvester( + A: MathCollection, + B: MathCollection, + C: MathCollection + ): MathCollection + + /** + * Performs a real Schur decomposition of the real matrix A = UTU' where U is orthogonal + * and T is upper quasi-triangular. + * https://en.wikipedia.org/wiki/Schur_decomposition + * @param A Matrix A + * @returns Object containing both matrix U and T of the Schur Decomposition A=UTU' + */ + schur(A: MathCollection): SchurDecomposition + + /** + * Solves the Continuous-time Lyapunov equation AP+PA'=Q for P, where Q is a positive semidefinite + * matrix. + * https://en.wikipedia.org/wiki/Lyapunov_equation + * @param A Matrix A + * @param Q Matrix Q + * @returns Matrix P solution to the Continuous-time Lyapunov equation AP+PA'=Q + */ + lyap(A: MathCollection, Q: MathCollection): MathCollection + + /** + * Create a 2-dimensional identity matrix with size m x n or n x n. The + * matrix has ones on the diagonal and zeros elsewhere. + * @param size The size for the matrix + * @param format The Matrix storage format + * @returns A matrix with ones on the diagonal + */ + identity( + size: number | number[] | MathCollection, + format?: string + ): MathCollection | number + /** + * @param m The x dimension for the matrix + * @param n The y dimension for the matrix + * @param format The Matrix storage format + * @returns A matrix with ones on the diagonal + */ + identity(m: number, n: number, format?: string): MathCollection | number + + /** + * Filter the items in an array or one dimensional matrix. + * @param x A one dimensional matrix or array to filter + * @param test A function or regular expression to test items. All + * entries for which test returns true are returned. When test is a + * function, it is invoked with three parameters: the value of the + * element, the index of the element, and the matrix/array being + * traversed. The function must return a boolean. + */ + filter( + x: MathCollection | string[], + test: + | (( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + value: any, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + index: any, + matrix: MathCollection | string[] + ) => boolean) + | RegExp + ): MathCollection + + /** + * Flatten a multi dimensional matrix into a single dimensional matrix. + * @param x Matrix to be flattened + * @returns Returns the flattened matrix + */ + flatten(x: T): T + + /** + * Iterate over all elements of a matrix/array, and executes the given + * callback function. + * @param x The matrix to iterate on. + * @param callback The callback function is invoked with three + * parameters: the value of the element, the index of the element, and + * the Matrix/array being traversed. + */ + forEach( + x: T, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + callback: (value: any, index: any, matrix: T) => void + ): void + + /** + * Calculate the inverse of a square matrix. + * @param x Matrix to be inversed + * @returns The inverse of x + */ + inv(x: T): NoLiteralType + + /** + * Calculate the kronecker product of two matrices or vectors + * @param x First vector + * @param y Second vector + * @returns Returns the kronecker product of x and y + */ + kron(x: MathCollection, y: MathCollection): Matrix + + /** + * Iterate over all elements of a matrix/array, and executes the given + * callback function. + * @param x The matrix to iterate on. + * @param callback The callback function is invoked with three + * parameters: the value of the element, the index of the element, and + * the Matrix/array being traversed. + * @returns Transformed map of x + */ + map( + x: T, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + callback: (value: any, index: any, matrix: T) => MathType | string + ): T + + /** + * Create a matrix filled with ones. The created matrix can have one or + * multiple dimensions. + * @param size The size of each dimension of the matrix + * @param format The matrix storage format + * @returns A matrix filled with ones + */ + ones( + size?: number | number[] | BigNumber | BigNumber[], + format?: string + ): MathCollection + /** + * @param m The x dimension of the matrix + * @param n The y dimension of the matrix + * @param format The matrix storage format + * @returns A matrix filled with ones + */ + ones( + m: number | BigNumber, + n: number | BigNumber, + format?: string + ): MathCollection + /** + * @param m The x dimension of the matrix + * @param n The y dimension of the matrix + * @param p The z dimension of the matrix + * @param format The matrix storage format + * @returns A matrix filled with ones + */ + ones( + m: number | BigNumber, + n: number | BigNumber, + p: number | BigNumber, + format?: string + ): MathCollection + /** Actually ones can take an arbitrary number of dimensions before the + ** optional format, not sure how to write that in TypeScript + **/ + + /** + * Partition-based selection of an array or 1D matrix. Will find the kth + * smallest value, and mutates the input array. Uses Quickselect. + * @param x A one dimensional matrix or array to sort + * @param k The kth smallest value to be retrieved; zero-based index + * @param compare An optional comparator function. The function is + * called as compare(a, b), and must return 1 when a > b, -1 when a < b, + * and 0 when a == b. Default value: 'asc'. + * @returns Returns the kth lowest value. + */ + partitionSelect( + x: MathCollection, + k: number, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + compare?: 'asc' | 'desc' | ((a: any, b: any) => number) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ): any + + /** + * Calculate the Moore–Penrose inverse of a matrix. + * @param x Matrix to be inversed + * @return The inverse of `x`. + */ + pinv(x: T): T + + /** + * Create an array from a range. By default, the range end is excluded. + * This can be customized by providing an extra parameter includeEnd. + * @param str A string 'start:end' or 'start:step:end' + * @param start Start of the range + * @param end End of the range, excluded by default, included when + * parameter includeEnd=true + * @param step Step size. Default value is 1. + * @param includeEnd: Option to specify whether to include the end or + * not. False by default + * @returns Parameters describing the ranges start, end, and optional + * step. + */ + range(str: string, includeEnd?: boolean): Matrix + range( + start: number | BigNumber, + end: number | BigNumber, + includeEnd?: boolean + ): Matrix + range( + start: number | BigNumber | Unit, + end: number | BigNumber | Unit, + step: number | BigNumber | Unit, + includeEnd?: boolean + ): Matrix + + /** + * Reshape a multi dimensional array to fit the specified dimensions + * @param x Matrix to be reshaped + * @param sizes One dimensional array with integral sizes for each + * dimension + * @returns A reshaped clone of matrix x + */ + reshape(x: T, sizes: number[]): T + + /** + * Resize a matrix + * @param x Matrix to be resized + * @param size One dimensional array with numbers + * @param defaultValue Zero by default, except in case of a string, in + * that case defaultValue = ' ' Default value: 0. + * @returns A resized clone of matrix x + */ + resize( + x: T, + size: MathCollection, + defaultValue?: number | string + ): T + + /** + * Return a Rotation Matrix for a given angle in radians + * @param {number | BigNumber | Complex | Unit} theta Rotation angle + * @param {Array | Matrix} [v] Rotation axis + * @param {string} [format] Result Matrix storage format. Default value: 'dense'. + * @return {Matrix} Rotation Matrix + */ + rotationMatrix( + theta?: number | BigNumber | Complex | Unit, + axis?: T, + format?: 'sparse' | 'dense' + ): T + + /** + * Return a row from a Matrix. + * @param value An array or matrix + * @param row The index of the row + * @returns The retrieved row + */ + row(value: T, row: number): T + + /** + * Return a column from a Matrix. + * @param value An array or matrix + * @param column The index of the column + * @returns The retrieved column + */ + column(value: T, column: number): T + + /** + * Return a rotated matrix. + * @param {Array | Matrix} w Vector to rotate + * @param {number | BigNumber | Complex | Unit} theta Rotation angle + * @param {Array | Matrix} [v] Rotation axis + * @return {Array | Matrix} Multiplication of the rotation matrix and w + */ + rotate( + w: T, + theta: number | BigNumber | Complex | Unit, + v?: T + ): T + + /** + * Calculate the size of a matrix or scalar. + * @param A matrix + * @returns A vector with the size of x + */ + size( + x: boolean | number | Complex | Unit | string | MathCollection + ): MathCollection + + /** + * Sort the items in a matrix + * @param x A one dimensional matrix or array to sort + * @param compare An optional _comparator function or name. The function + * is called as compare(a, b), and must return 1 when a > b, -1 when a < + * b, and 0 when a == b. Default value: ‘asc’ + * @returns Returns the sorted matrix + */ + sort( + x: T, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + compare: ((a: any, b: any) => number) | 'asc' | 'desc' | 'natural' + ): T + + /** + * Calculate the principal square root of a square matrix. The principal + * square root matrix X of another matrix A is such that X * X = A. + * @param A The square matrix A + * @returns The principal square root of matrix A + */ + sqrtm(A: T): T + + /** + * Squeeze a matrix, remove inner and outer singleton dimensions from a + * matrix. + * @param x Matrix to be squeezed + * @returns Squeezed matrix + */ + squeeze(x: T): T + + /** + * Get or set a subset of a matrix or string. + * @param value An array, matrix, or string + * @param index For each dimension, an index or list of indices to get or set. + * @param replacement An array, matrix, or scalar. If provided, the + * subset is replaced with replacement. If not provided, the subset is + * returned + * @param defaultValue Default value, filled in on new entries when the + * matrix is resized. If not provided, math.matrix elements will be left + * undefined. Default value: undefined. + * @returns Either the retrieved subset or the updated matrix + */ + subset( + value: T, + index: Index, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + replacement?: any, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + defaultValue?: any + ): T + + /** + * Calculate the trace of a matrix: the sum of the elements on the main + * diagonal of a square matrix. + * @param x A matrix + * @returns The trace of x + */ + trace(x: MathCollection): number + + /** + * Transpose a matrix. All values of the matrix are reflected over its + * main diagonal. Only two dimensional matrices are supported. + * @param x Matrix to be transposed + * @returns The transposed matrix + */ + transpose(x: T): T + + /** + * Create a matrix filled with zeros. The created matrix can have one or + * multiple dimensions. + * @param size The size of each dimension of the matrix + * @param format The matrix storage format + * @returns A matrix filled with zeros + */ + zeros( + size?: number | number[] | BigNumber | BigNumber[], + format?: string + ): MathCollection + /** + * @param m The x dimension of the matrix + * @param n The y dimension of the matrix + * @param format The matrix storage format + * @returns A matrix filled with zeros + */ + zeros( + m: number | BigNumber, + n: number | BigNumber, + format?: string + ): MathCollection + /** + * @param m The x dimension of the matrix + * @param n The y dimension of the matrix + * @param p The z dimension of the matrix + * @param format The matrix storage format + * @returns A matrix filled with zeros + */ + zeros( + m: number | BigNumber, + n: number | BigNumber, + p: number | BigNumber, + format?: string + ): MathCollection + /** Actually zeros can take any number of dimensions before the + ** optional format, not sure how to write that in TypeScript + **/ + + /** + * Calculate N-dimensional fourier transform + * @param {Array | Matrix} arr An array or matrix + * @return {Array | Matrix} N-dimensional fourier transformation of the array + */ + fft(arr: T): T + + /** + * Calculate N-dimensional inverse fourier transform + * @param {Array | Matrix} arr An array or matrix + * @return {Array | Matrix} N-dimensional fourier transformation of the array + */ + ifft(arr: T): T + + /************************************************************************* + * Probability functions + ************************************************************************/ + + /** + * Compute the number of ways of picking k unordered outcomes from n + * possibilities. Combinations only takes integer arguments. The + * following condition must be enforced: k <= n. + * @param n Total number of objects in the set + * @param k Number of objects in the subset + * @returns Number of possible combinations + */ + combinations( + n: T, + k: number | BigNumber + ): NoLiteralType + + /** + * Compute the factorial of a value Factorial only supports an integer + * value as argument. For matrices, the function is evaluated element + * wise. + * @param n An integer number + * @returns The factorial of n + */ + factorial( + n: T + ): NoLiteralType + + /** + * Compute the gamma function of a value using Lanczos approximation for + * small values, and an extended Stirling approximation for large + * values. + * @param n A real or complex number + * @returns The gamma of n + */ + gamma(n: T): NoLiteralType + + /** + * Calculate the Kullback-Leibler (KL) divergence between two + * distributions + * @param q First vector + * @param p Second vector + * @returns Returns disance between q and p + */ + kldivergence(q: MathCollection, p: MathCollection): number + + /** + * Compute the log gamma function of a value, using Lanczos approximation for numbers and Stirling series for complex numbers. + * @param n A real or complex number + * @returns The log gamma of `n` + */ + lgamma(n: T): NoLiteralType + + /** + * Multinomial Coefficients compute the number of ways of picking a1, + * a2, ..., ai unordered outcomes from n possibilities. multinomial + * takes one array of integers as an argument. The following condition + * must be enforced: every ai <= 0 + * @param a Integer number of objects in the subset + * @returns multinomial coefficent + */ + multinomial(a: T[]): NoLiteralType + + /** + * Compute the number of ways of obtaining an ordered subset of k + * elements from a set of n elements. Permutations only takes integer + * arguments. The following condition must be enforced: k <= n. + * @param n The number of objects in total + * @param k The number of objects in the subset + * @returns The number of permutations + */ + permutations( + n: T, + k?: number | BigNumber + ): NoLiteralType + + /** + * Random pick a value from a one dimensional array. Array element is + * picked using a random function with uniform distribution. + * @param array A one dimensional array + * @param number An int or float + * @param weights An array of ints or floats + * @returns Returns a single random value from array when number is 1 or + * undefined. Returns an array with the configured number of elements + * when number is > 1. + */ + pickRandom(array: T[]): T + pickRandom(array: T[], number: number): T[] + pickRandom(array: T[], number: number, weights: number[]): T[] + + /** + * Return a random number larger or equal to min and smaller than max + * using a uniform distribution. + * @param size If provided, an array or matrix with given size and + * filled with random values is returned + * @param min Minimum boundary for the random value, included + * @param max Maximum boundary for the random value, excluded + * @returns A random number + */ + random(min?: number, max?: number): number + random(size: T, min?: number, max?: number): T + + /** + * Return a random integer number larger or equal to min and smaller + * than max using a uniform distribution. + * @param size If provided, an array or matrix with given size and + * filled with random values is returned + * @param min Minimum boundary for the random value, included + * @param max Maximum boundary for the random value, excluded + * @returns A random number + */ + randomInt(min: number, max?: number): number + randomInt(size: T, min?: number, max?: number): T + + /************************************************************************* + * Relational functions + ************************************************************************/ + + /** + * Compare two values. Returns 1 when x > y, -1 when x < y, and 0 when x + * == y. x and y are considered equal when the relative difference + * between x and y is smaller than the configured epsilon. The function + * cannot be used to compare values smaller than approximately 2.22e-16. + * For matrices, the function is evaluated element wise. + * @param x First value to compare + * @param y Second value to compare + * @returns Returns the result of the comparison: 1 when x > y, -1 when + * x < y, and 0 when x == y. + */ + compare( + x: MathType | string, + y: MathType | string + ): number | BigNumber | Fraction | MathCollection + + /** + * Compare two values of any type in a deterministic, natural way. For + * numeric values, the function works the same as math.compare. For + * types of values that can’t be compared mathematically, the function + * compares in a natural way. + * @param x First value to compare + * @param y Second value to compare + * @returns Returns the result of the comparison: 1 when x > y, -1 when + * x < y, and 0 when x == y. + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + compareNatural(x: any, y: any): number + + /** + * Compare two strings lexically. Comparison is case sensitive. Returns + * 1 when x > y, -1 when x < y, and 0 when x == y. For matrices, the + * function is evaluated element wise. + * @param x First string to compare + * @param y Second string to compare + * @returns Returns the result of the comparison: 1 when x > y, -1 when + * x < y, and 0 when x == y. + */ + compareText( + x: string | MathCollection, + y: string | MathCollection + ): number | MathCollection + + /** + * Test element wise whether two matrices are equal. The function + * accepts both matrices and scalar values. + * @param x First matrix to compare + * @param y Second amtrix to compare + * @returns Returns true when the input matrices have the same size and + * each of their elements is equal. + */ + deepEqual(x: MathType, y: MathType): MathType + + /** + * Test whether two values are equal. + * + * The function tests whether the relative difference between x and y is + * smaller than the configured epsilon. The function cannot be used to + * compare values smaller than approximately 2.22e-16. For matrices, the + * function is evaluated element wise. In case of complex numbers, x.re + * must equal y.re, and x.im must equal y.im. Values null and undefined + * are compared strictly, thus null is only equal to null and nothing + * else, and undefined is only equal to undefined and nothing else. + * @param x First value to compare + * @param y Second value to compare + * @returns Returns true when the compared values are equal, else + * returns false + */ + equal(x: MathType | string, y: MathType | string): boolean | MathCollection + + /** + * Check equality of two strings. Comparison is case sensitive. For + * matrices, the function is evaluated element wise. + * @param x First string to compare + * @param y Second string to compare + * @returns Returns true if the values are equal, and false if not. + */ + equalText( + x: string | MathCollection, + y: string | MathCollection + ): number | MathCollection + + /** + * Test whether value x is larger than y. The function returns true when + * x is larger than y and the relative difference between x and y is + * larger than the configured epsilon. The function cannot be used to + * compare values smaller than approximately 2.22e-16. For matrices, the + * function is evaluated element wise. + * @param x First value to compare + * @param y Second value to vcompare + * @returns Returns true when x is larger than y, else returns false + */ + larger(x: MathType | string, y: MathType | string): boolean | MathCollection + + /** + * Test whether value x is larger or equal to y. The function returns + * true when x is larger than y or the relative difference between x and + * y is smaller than the configured epsilon. The function cannot be used + * to compare values smaller than approximately 2.22e-16. For matrices, + * the function is evaluated element wise. + * @param x First value to compare + * @param y Second value to vcompare + * @returns Returns true when x is larger than or equal to y, else + * returns false + */ + largerEq(x: MathType | string, y: MathType | string): boolean | MathCollection + + /** + * Test whether value x is smaller than y. The function returns true + * when x is smaller than y and the relative difference between x and y + * is smaller than the configured epsilon. The function cannot be used + * to compare values smaller than approximately 2.22e-16. For matrices, + * the function is evaluated element wise. + * @param x First value to compare + * @param y Second value to vcompare + * @returns Returns true when x is smaller than y, else returns false + */ + smaller(x: MathType | string, y: MathType | string): boolean | MathCollection + + /** + * Test whether value x is smaller or equal to y. The function returns + * true when x is smaller than y or the relative difference between x + * and y is smaller than the configured epsilon. The function cannot be + * used to compare values smaller than approximately 2.22e-16. For + * matrices, the function is evaluated element wise. + * @param x First value to compare + * @param y Second value to vcompare + * @returns Returns true when x is smaller than or equal to y, else + * returns false + */ + smallerEq( + x: MathType | string, + y: MathType | string + ): boolean | MathCollection + + /** + * Test whether two values are unequal. The function tests whether the + * relative difference between x and y is larger than the configured + * epsilon. The function cannot be used to compare values smaller than + * approximately 2.22e-16. For matrices, the function is evaluated + * element wise. In case of complex numbers, x.re must unequal y.re, or + * x.im must unequal y.im. Values null and undefined are compared + * strictly, thus null is unequal with everything except null, and + * undefined is unequal with everything except undefined. + * @param x First value to compare + * @param y Second value to vcompare + * @returns Returns true when the compared values are unequal, else + * returns false + */ + unequal(x: MathType | string, y: MathType | string): boolean | MathCollection + + /************************************************************************* + * Set functions + ************************************************************************/ + + /** + * Create the cartesian product of two (multi)sets. Multi-dimension + * arrays will be converted to single-dimension arrays and the values + * will be sorted in ascending order before the operation. + * @param a1 A (multi)set + * @param a2 A (multi)set + * @returns The cartesian product of two (multi)sets + */ + setCartesian(a1: T, a2: MathCollection): T + + /** + * Create the difference of two (multi)sets: every element of set1, that + * is not the element of set2. Multi-dimension arrays will be converted + * to single-dimension arrays before the operation + * @param a1 A (multi)set + * @param a2 A (multi)set + * @returns The difference of two (multi)sets + */ + setDifference(a1: T, a2: MathCollection): T + + /** + * Collect the distinct elements of a multiset. A multi-dimension array + * will be converted to a single-dimension array before the operation. + * @param a A multiset + * @returns A set containing the distinct elements of the multiset + */ + setDistinct(a: T): T + + /** + * Create the intersection of two (multi)sets. Multi-dimension arrays + * will be converted to single-dimension arrays before the operation. + * @param a1 A (multi)set + * @param a2 A (multi)set + * @returns The intersection of two (multi)sets + */ + setIntersect(a1: T, a2: MathCollection): T + + /** + * Check whether a (multi)set is a subset of another (multi)set. (Every + * element of set1 is the element of set2.) Multi-dimension arrays will + * be converted to single-dimension arrays before the operation. + * @param a1 A (multi)set + * @param a2 A (multi)set + * @returns True if a1 is subset of a2, else false + */ + setIsSubset(a1: MathCollection, a2: MathCollection): boolean + + /** + * Count the multiplicity of an element in a multiset. A multi-dimension + * array will be converted to a single-dimension array before the + * operation. + * @param e An element in the multiset + * @param a A multiset + * @returns The number of how many times the multiset contains the + * element + */ + setMultiplicity(e: MathNumericType, a: MathCollection): number + + /** + * Create the powerset of a (multi)set. (The powerset contains very + * possible subsets of a (multi)set.) A multi-dimension array will be + * converted to a single-dimension array before the operation. + * @param a A multiset + * @returns The powerset of the (multi)set + */ + setPowerset(a: T): T + + /** + * Count the number of elements of a (multi)set. When a second parameter + * is ‘true’, count only the unique values. A multi-dimension array will + * be converted to a single-dimension array before the operation. + * @param a A multiset + * @returns The number of elements of the (multi)set + */ + setSize(a: MathCollection): number + + /** + * Create the symmetric difference of two (multi)sets. Multi-dimension + * arrays will be converted to single-dimension arrays before the + * operation. + * @param a1 A (multi)set + * @param a2 A (multi)set + * @returns The symmetric difference of two (multi)sets + */ + setSymDifference(a1: T, a2: MathCollection): T + + /** + * Create the union of two (multi)sets. Multi-dimension arrays will be + * converted to single-dimension arrays before the operation. + * @param a1 A (multi)set + * @param a2 A (multi)set + * @returns The union of two (multi)sets + */ + setUnion(a1: T, a2: MathCollection): T + + /************************************************************************* + * Signal functions + ************************************************************************/ + /** + * Compute the transfer function of a zero-pole-gain model. + * @param z Zeroes of the model + * @param p Poles of the model + * @param k Gain of the model + * @returns The transfer function as array of numerator and denominator + */ + zpk2tf(z: T, p: T, k?: number): T + + /** + * Calculates the frequency response of a filter given its numerator and denominator coefficients. + * @param b The numerator polynomial of the filter + * @param a The denominator polynomial of the filter + * @param w The range of frequencies in which the response is to be calculated + * @returns The frequency response + * + */ + freqz(b: T, a: T, w?: number | T): { w: T; h: T } + + /************************************************************************* + * Special functions + ************************************************************************/ + + /** + * Compute the erf function of a value using a rational Chebyshev + * approximations for different intervals of x. + * @param x A real number + * @returns The erf of x + */ + erf(x: T): NoLiteralType + + /** + * Compute the Riemann Zeta function of a value using an infinite series + * and Riemann's Functional equation. + * @param s A real, complex or BigNumber + * @returns The Riemann Zeta of s + */ + zeta(s: T): T + + /************************************************************************* + * Statistics functions + ************************************************************************/ + + /** + * Compute the median absolute deviation of a matrix or a list with + * values. The median absolute deviation is defined as the median of the + * absolute deviations from the median. + * @param array A single matrix or multiple scalar values. + * @returns The median absolute deviation + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + mad(array: MathCollection): any + + /** + * Compute the maximum value of a matrix or a list with values. In case + * of a multi dimensional array, the maximum of the flattened array will + * be calculated. When dim is provided, the maximum over the selected + * dimension will be calculated. Parameter dim is zero-based. + * @param args Multiple scalar values + * @returns The maximum value + */ + max(...args: T[]): T + /** + * @param args Multiple scalar values + * @returns The maximum value + */ + max(...args: MathScalarType[]): MathScalarType + /** + * @param A A single matrix + * @param dimension The maximum over the selected dimension + * @returns The maximum value + */ + max( + A: T[] | T[][], + dimension?: number | BigNumber + ): T + /** + * @param A A single matrix + * @param dimension The maximum over the selected dimension + * @returns The maximum value + */ + max(A: MathCollection, dimension?: number | BigNumber): MathScalarType + + /** + * Compute the mean value of matrix or a list with values. In case of a + * multi dimensional array, the mean of the flattened array will be + * calculated. When dim is provided, the maximum over the selected + * dimension will be calculated. Parameter dim is zero-based. + * @param args Multiple scalar values + * @returns The mean of all values + */ + mean(...args: T[]): T + /** + * @param args Multiple scalar values + * @returns The mean value + */ + mean(...args: MathScalarType[]): MathScalarType + /** + * @param A A single matrix + * @param dimension The mean over the selected dimension + * @returns The mean value + */ + mean( + A: T[] | T[][], + dimension?: number | BigNumber + ): T + /** + * @param A A single matrix + * @param dimension The mean over the selected dimension + * @returns The mean value + */ + mean(A: MathCollection, dimension?: number | BigNumber): MathScalarType + + /** + * Compute the median of a matrix or a list with values. The values are + * sorted and the middle value is returned. In case of an even number of + * values, the average of the two middle values is returned. Supported + * types of values are: Number, BigNumber, Unit In case of a (multi + * dimensional) array or matrix, the median of all elements will be + * calculated. + * @param args Multiple scalar values + * @returns The median value + */ + median(...args: T[]): T + /** + * @param args Multiple scalar values + * @returns The median value + */ + median(...args: MathScalarType[]): MathScalarType + /** + * @param A A single matrix + * @returns The median value + */ + median(A: T[] | T[][]): T + /** + * @param A A single matrix + * @returns The median value + */ + median(A: MathCollection): MathScalarType + + /** + * Compute the minimum value of a matrix or a list of values. In case of + * a multi dimensional array, the minimum of the flattened array will be + * calculated. When dim is provided, the minimum over the selected + * dimension will be calculated. Parameter dim is zero-based. + * @param args multiple scalar values + * @returns The minimum value + */ + min(...args: T[]): T + /** + * @param args Multiple scalar values + * @returns The minimum value + */ + min(...args: MathScalarType[]): MathScalarType + /** + * @param A A single matrix + * @param dimension The minimum over the selected dimension + * @returns The minimum value + */ + min( + A: T[] | T[][], + dimension?: number | BigNumber + ): T + /** + * @param A A single matrix + * @param dimension The minimum over the selected dimension + * @returns The minimum value + */ + min(A: MathCollection, dimension?: number | BigNumber): MathScalarType + + /** + * Computes the mode of a set of numbers or a list with values(numbers + * or characters). If there are more than one modes, it returns a list + * of those values. + * @param args Multiple scalar values + * @returns The mode of all values + */ + mode(...args: T[]): T + /** + * @param args Multiple scalar values + * @returns The mode of all values + */ + mode(...args: MathScalarType[]): MathScalarType + /** + * @param A A single matrix + * @returns The median value + */ + mode(A: T[] | T[][]): T + /** + * @param A A single matrix + * @returns The mode of all values + */ + mode(A: MathCollection): MathScalarType + + /** + * Compute the product of a matrix or a list with values. In case of a + * (multi dimensional) array or matrix, the sum of all elements will be + * calculated. + * @param args Multiple scalar values + * @returns The product of all values + */ + prod(...args: T[]): T + /** + * @param args Multiple scalar values + * @returns The product of all values + */ + prod(...args: MathScalarType[]): MathScalarType + /** + * @param A A single matrix + * @returns The product of all values + */ + prod(A: T[] | T[][]): T + /** + * @param A A single matrix + * @returns The product of all values + */ + prod(A: MathCollection): MathScalarType + + /** + * Compute the prob order quantile of a matrix or a list with values. + * The sequence is sorted and the middle value is returned. Supported + * types of sequence values are: Number, BigNumber, Unit Supported types + * of probability are: Number, BigNumber In case of a (multi + * dimensional) array or matrix, the prob order quantile of all elements + * will be calculated. + * @param A A single matrix or array + * @param probOrN prob is the order of the quantile, while N is the + * amount of evenly distributed steps of probabilities; only one of + * these options can be provided + * @param sorted =false is data sorted in ascending order + * @returns Quantile(s) + */ + quantileSeq( + A: MathCollection, + prob: number | BigNumber | MathArray, + sorted?: boolean + ): number | BigNumber | Unit | MathArray + + /** + * Compute the standard deviation of a matrix or a list with values. The + * standard deviations is defined as the square root of the variance: + * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or + * matrix, the standard deviation over all elements will be calculated. + * Optionally, the type of normalization can be specified as second + * parameter. The parameter normalization can be one of the following + * values: 'unbiased' (default) The sum of squared errors is divided by + * (n - 1) 'uncorrected' The sum of squared errors is divided by n + * 'biased' The sum of squared errors is divided by (n + 1) + * @param args variadic argument of number to calculate standard deviation + * @returns The standard deviation + */ + std(...args: T[]): T + /** + * @param args Multiple scalar values + * @returns The standard deviation + */ + std(...args: MathScalarType[]): MathScalarType + /** + * Compute the standard deviation of a matrix or a list with values. The + * standard deviations is defined as the square root of the variance: + * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or + * matrix, the standard deviation over all elements will be calculated. + * Optionally, the type of normalization can be specified as second + * parameter. The parameter normalization can be one of the following + * values: 'unbiased' (default) The sum of squared errors is divided by + * (n - 1) 'uncorrected' The sum of squared errors is divided by n + * 'biased' The sum of squared errors is divided by (n + 1) + * @param array A single matrix to compute standard deviation. + * @param dimension A dimension to calculate standard deviation + * @param normalization Determines how to normalize the variance. Choose + * ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: + * ‘unbiased’. + * @returns The standard deviation array + */ + std( + array: MathCollection, + dimension?: number, + normalization?: 'unbiased' | 'uncorrected' | 'biased' + ): MathNumericType[] + /** + * Compute the standard deviation of a matrix or a list with values. The + * standard deviations is defined as the square root of the variance: + * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or + * matrix, the standard deviation over all elements will be calculated. + * Optionally, the type of normalization can be specified as second + * parameter. The parameter normalization can be one of the following + * values: 'unbiased' (default) The sum of squared errors is divided by + * (n - 1) 'uncorrected' The sum of squared errors is divided by n + * 'biased' The sum of squared errors is divided by (n + 1) + * @param array A single matrix or multiple scalar values + * @param normalization Determines how to normalize the variance. Choose + * ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: + * ‘unbiased’. + * @returns The standard deviation + */ + std( + array: MathCollection, + normalization: 'unbiased' | 'uncorrected' | 'biased' + ): MathNumericType + + /** + * Compute the sum of a matrix or a list with values. In case of a + * (multi dimensional) array or matrix, the sum of all elements will be + * calculated. + * @param args A single matrix or multiple scalar values + * @returns The sum of all values + */ + sum(...args: T[]): T + /** + * @param args Multiple scalar values + * @returns The sum of all values + */ + sum(...args: MathScalarType[]): MathScalarType + /** + * @param A A single matrix + * @param dimension The sum over the selected dimension + * @returns The sum of all values + */ + sum( + A: T[] | T[][], + dimension?: number | BigNumber + ): T + /** + * @param A A single matrix + * @param dimension The sum over the selected dimension + * @returns The sum of all values + */ + sum(A: MathCollection, dimension?: number | BigNumber): MathScalarType + + /** + * Count the number of elements of a matrix, array or string. + * @param x A matrix, array or string. + * @returns The number of members passed in parameters + */ + count(x: MathCollection | string): number + + /** + * Compute the cumulative sum of a matrix or a list with values. + * In case of a (multi dimensional) array or matrix, the cumulative sums + * along a specified dimension (defaulting to the first) will be calculated. + * @param args A single matrix or multiple scalar values + * @returns The cumulative sums of the the values. + */ + cumsum(...args: MathType[]): MathType[] + /** + * @param array A single matrix + * @param dim The dimension along which to sum (defaults to 0) + * @returns The cumulative sums along the given dimension + */ + cumsum(array: MathCollection, dim?: number): MathCollection + + /** + * Compute the variance of a matrix or a list with values. In case of a + * (multi dimensional) array or matrix, the variance over all elements + * will be calculated. Optionally, the type of normalization can be + * specified as second parameter. The parameter normalization can be one + * of the following values: 'unbiased' (default) The sum of squared + * errors is divided by (n - 1) 'uncorrected' The sum of squared errors + * is divided by n 'biased' The sum of squared errors is divided by (n + + * 1) Note that older browser may not like the variable name var. In + * that case, the function can be called as math['var'](...) instead of + * math.variance(...). + * @param args A single matrix or multiple scalar values + * @returns The variance + */ + variance(...args: MathNumericType[]): MathNumericType + /** + * Compute the variance of a matrix or a list with values. In case of a + * (multi dimensional) array or matrix, the variance over all elements + * will be calculated. Optionally, the type of normalization can be + * specified as second parameter. The parameter normalization can be one + * of the following values: 'unbiased' (default) The sum of squared + * errors is divided by (n - 1) 'uncorrected' The sum of squared errors + * is divided by n 'biased' The sum of squared errors is divided by (n + + * 1) Note that older browser may not like the variable name var. In + * that case, the function can be called as math['var'](...) instead of + * math.variance(...). + * @param array A matrix to compute variance. + * @param dimension A dimension to compute variance on + * @param normalization normalization Determines how to normalize the + * variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. + * Default value: ‘unbiased’. + * @returns variance matrix. + */ + variance( + array: MathCollection, + dimension?: number, + normalization?: 'unbiased' | 'uncorrected' | 'biased' + ): MathNumericType[] + /** + * @param array A single matrix + * @param normalization normalization Determines how to normalize the + * variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. + * Default value: ‘unbiased’. + * @returns The variance + */ + variance( + array: MathCollection, + normalization: 'unbiased' | 'uncorrected' | 'biased' + ): MathNumericType + + /** + * Calculate the correlation coefficient between two matrix. + * @param {Array | Matrix} x The first array or matrix to compute correlation coefficient + * @param {Array | Matrix} y The second array or matrix to compute correlation coefficient + * @returns correlation coefficient + */ + corr(x: MathCollection, y: MathCollection): MathType + + /************************************************************************* + * String functions + ************************************************************************/ + + /** + * Format a value of any type into a string. + * @param value The value to be formatted + * @param options An object with formatting options. + * @param callback A custom formatting function, invoked for all numeric + * elements in value, for example all elements of a matrix, or the real + * and imaginary parts of a complex number. This callback can be used to + * override the built-in numeric notation with any type of formatting. + * Function callback is called with value as parameter and must return a + * string. + * @see http://mathjs.org/docs/reference/functions/format.html + * @returns The formatted value + */ + format( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + value: any, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + options?: FormatOptions | number | ((item: any) => string), + // eslint-disable-next-line @typescript-eslint/no-explicit-any + callback?: (value: any) => string + ): string + + /** + * Interpolate values into a string template. + * @param template A string containing variable placeholders. + * @param values An object containing variables which will be filled in + * in the template. + * @param precision Number of digits to format numbers. If not provided, + * the value will not be rounded. + * @param options Formatting options, or the number of digits to format + * numbers. See function math.format for a description of all options. + * @returns Interpolated string + */ + print( + template: string, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + values: any, + precision?: number, + options?: number | object + ): void + + /************************************************************************* + * Trigonometry functions + ************************************************************************/ + + /** + * Calculate the inverse cosine of a value. + * @param x Function input + * @returns The arc cosine of x + */ + acos(x: number): number | Complex + acos(x: T): T + + /** + * Calculate the hyperbolic arccos of a value, defined as acosh(x) = + * ln(sqrt(x^2 - 1) + x). + * @param x Function input + * @returns The hyperbolic arccosine of x + */ + acosh(x: number): number | Complex + acosh(x: T): T + + /** + * Calculate the inverse cotangent of a value. + * @param x Function input + * @returns The arc cotangent of x + */ + acot(x: number): number + acot(x: T): T + + /** + * Calculate the hyperbolic arccotangent of a value, defined as acoth(x) + * = (ln((x+1)/x) + ln(x/(x-1))) / 2. + * @param x Function input + * @returns The hyperbolic arccotangent of x + */ + acoth(x: number): number + acoth(x: T): T + + /** + * Calculate the inverse cosecant of a value. + * @param x Function input + * @returns The arc cosecant of x + */ + acsc(x: number): number | Complex + acsc(x: T): T + + /** + * Calculate the hyperbolic arccosecant of a value, defined as acsch(x) + * = ln(1/x + sqrt(1/x^2 + 1)). + * @param x Function input + * @returns The hyperbolic arccosecant of x + */ + acsch(x: number): number + acsch(x: T): T + + /** + * Calculate the inverse secant of a value. + * @param x Function input + * @returns The arc secant of x + */ + asec(x: number): number | Complex + asec(x: T): T + + /** + * Calculate the hyperbolic arcsecant of a value, defined as asech(x) = + * ln(sqrt(1/x^2 - 1) + 1/x). + * @param x Function input + * @returns The hyperbolic arcsecant of x + */ + asech(x: number): number | Complex + asech(x: T): T + + /** + * Calculate the inverse sine of a value. + * @param x Function input + * @returns The arc sine of x + */ + asin(x: number): number | Complex + asin(x: T): T + + /** + * Calculate the hyperbolic arcsine of a value, defined as asinh(x) = + * ln(x + sqrt(x^2 + 1)). + * @param x Function input + * @returns The hyperbolic arcsine of x + */ + asinh(x: T): T + + /** + * Calculate the inverse tangent of a value. + * @param x Function input + * @returns The arc tangent of x + */ + atan(x: T): T + + /** + * Calculate the inverse tangent function with two arguments, y/x. By + * providing two arguments, the right quadrant of the computed angle can + * be determined. For matrices, the function is evaluated element wise. + * @param x Function input + * @returns Four quadrant inverse tangent + */ + atan2(y: T, x: T): T + + /** + * Calculate the hyperbolic arctangent of a value, defined as atanh(x) = + * ln((1 + x)/(1 - x)) / 2. + * @param x Function input + * @returns The hyperbolic arctangent of x + */ + atanh(x: number): number | Complex + atanh(x: T): T + + /** + * Calculate the cosine of a value. + * @param x Function input + * @returns The cosine of x + */ + cos(x: number | Unit): number + cos(x: T): T + + /** + * Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2 + * * (exp(x) + exp(-x)). + * @param x Function input + * @returns The hyperbolic cosine of x + */ + cosh(x: number | Unit): number + cosh(x: T): T + + /** + * Calculate the cotangent of a value. cot(x) is defined as 1 / tan(x). + * @param x Function input + * @returns The cotangent of x + */ + cot(x: number | Unit): number + cot(x: T): T + + /** + * Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1 + * / tanh(x). + * @param x Function input + * @returns The hyperbolic cotangent of x + */ + coth(x: number | Unit): number + coth(x: T): T + + /** + * Calculate the cosecant of a value, defined as csc(x) = 1/sin(x). + * @param x Function input + * @returns The cosecant hof x + */ + csc(x: number | Unit): number + csc(x: T): T + + /** + * Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1 + * / sinh(x). + * @param x Function input + * @returns The hyperbolic cosecant of x + */ + csch(x: number | Unit): number + csch(x: T): T + + /** + * Calculate the secant of a value, defined as sec(x) = 1/cos(x). + * @param x Function input + * @returns The secant of x + */ + sec(x: number | Unit): number + sec(x: T): T + + /** + * Calculate the hyperbolic secant of a value, defined as sech(x) = 1 / + * cosh(x). + * @param x Function input + * @returns The hyperbolic secant of x + */ + sech(x: number | Unit): number + sech(x: T): T + + /** + * Calculate the sine of a value. + * @param x Function input + * @returns The sine of x + */ + sin(x: number | Unit): number + sin(x: T): T + + /** + * Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 * + * (exp(x) - exp(-x)). + * @param x Function input + * @returns The hyperbolic sine of x + */ + sinh(x: number | Unit): number + sinh(x: T): T + + /** + * Calculate the tangent of a value. tan(x) is equal to sin(x) / cos(x). + * @param x Function input + * @returns The tangent of x + */ + tan(x: number | Unit): number + tan(x: T): T + + /** + * Calculate the hyperbolic tangent of a value, defined as tanh(x) = + * (exp(2 * x) - 1) / (exp(2 * x) + 1). + * @param x Function input + * @returns The hyperbolic tangent of x + */ + tanh(x: number | Unit): number + tanh(x: T): T + + /************************************************************************* + * Unit functions + ************************************************************************/ + + /** + * Change the unit of a value. For matrices, the function is evaluated + * element wise. + * @param x The unit to be converted. + * @param unit New unit. Can be a string like "cm" or a unit without + * value. + * @returns Value with changed, fixed unit + */ + to(x: Unit | MathCollection, unit: Unit | string): Unit | MathCollection + + /************************************************************************* + * Utils + ************************************************************************/ + isNumber(x: unknown): x is number + + isBigNumber(x: unknown): x is BigNumber + + isComplex(x: unknown): x is Complex + + isFraction(x: unknown): x is Fraction + + isUnit(x: unknown): x is Unit + + isString(x: unknown): x is string + + isArray: ArrayConstructor['isArray'] + + isMatrix(x: unknown): x is Matrix + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + isCollection(x: unknown): x is Matrix | any[] + + isDenseMatrix(x: unknown): x is Matrix + + isSparseMatrix(x: unknown): x is Matrix + + isRange(x: unknown): boolean + + isIndex(x: unknown): x is Index + + isBoolean(x: unknown): x is boolean + + isResultSet(x: unknown): boolean + + isHelp(x: unknown): x is Help + + isFunction(x: unknown): boolean + + isDate(x: unknown): x is Date + + isRegExp(x: unknown): x is RegExp + + isObject(x: unknown): boolean + + isNull(x: unknown): x is null + + isUndefined(x: unknown): x is undefined + + isAccessorNode(x: unknown): x is AccessorNode + + isArrayNode(x: unknown): x is ArrayNode + + isAssignmentNode(x: unknown): x is AssignmentNode + + isBlockNode(x: unknown): x is BlockNode + + isConditionalNode(x: unknown): x is ConditionalNode + + isConstantNode(x: unknown): x is ConstantNode + + isFunctionAssignmentNode(x: unknown): x is FunctionAssignmentNode + + isFunctionNode(x: unknown): x is FunctionNode + + isIndexNode(x: unknown): x is IndexNode + + isNode(x: unknown): x is MathNode + + isObjectNode(x: unknown): x is ObjectNode + + isOperatorNode(x: unknown): x is OperatorNode + + isParenthesisNode(x: unknown): x is ParenthesisNode + + isRangeNode(x: unknown): x is RangeNode + + isRelationalNode(x: unknown): x is RelationalNode + + isSymbolNode(x: unknown): x is SymbolNode + + isChain(x: unknown): x is MathJsChain + + /************************************************************************* + * Functions -> Utils + ************************************************************************/ + + /** + * Clone an object. + * @param x Object to be cloned + * @returns A clone of object x + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + clone(x: TType): TType + + /** + * Test whether a value is an numeric value. In case of a string, + * true is returned if the string contains a numeric value. + * @param x Value to be tested + * @returns Returns true when x is a number, BigNumber, Fraction, Boolean, or a String containing number. + * Returns false for other types. + * Throws an error in case of unknown types. + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + hasNumericValue(x: any): boolean | boolean[] + + /** + * Test whether a value is an integer number. The function supports + * number, BigNumber, and Fraction. The function is evaluated + * element-wise in case of Array or Matrix input. + * @param x Value to be tested + * @returns Returns true when x contains a numeric, integer value. + * Throws an error in case of an unknown data type. + */ + isInteger(x: number | BigNumber | Fraction | MathCollection): boolean + + /** + * Test whether a value is NaN (not a number). The function supports + * types number, BigNumber, Fraction, Unit and Complex. The function is + * evaluated element-wise in case of Array or Matrix input. + * @param x Value to be tested + * @returns Returns true when x is NaN. Throws an error in case of an + * unknown data type. + */ + isNaN(x: number | BigNumber | Fraction | MathCollection | Unit): boolean + + /** + * Test whether a value is negative: smaller than zero. The function + * supports types number, BigNumber, Fraction, and Unit. The function is + * evaluated element-wise in case of Array or Matrix input. + * @param x Value to be tested + * @returns Returns true when x is larger than zero. Throws an error in + * case of an unknown data type. + */ + isNegative(x: number | BigNumber | Fraction | MathCollection | Unit): boolean + + /** + * Test whether a value is an numeric value. The function is evaluated + * element-wise in case of Array or Matrix input. + * @param x Value to be tested + * @returns Returns true when x is a number, BigNumber, Fraction, or + * boolean. Returns false for other types. Throws an error in case of + * unknown types. + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + isNumeric(x: any): x is number | BigNumber | Fraction | boolean + + /** + * Test whether a value is positive: larger than zero. The function + * supports types number, BigNumber, Fraction, and Unit. The function is + * evaluated element-wise in case of Array or Matrix input. + * @param x Value to be tested + * @returns Returns true when x is larger than zero. Throws an error in + * case of an unknown data type. + */ + isPositive(x: number | BigNumber | Fraction | MathCollection | Unit): boolean + + /** + * Test whether a value is prime: has no divisors other than itself and + * one. The function supports type number, bignumber. The function is + * evaluated element-wise in case of Array or Matrix input. + * @param x Value to be tested + * @returns Returns true when x is larger than zero. Throws an error in + * case of an unknown data type. + */ + isPrime(x: number | BigNumber | MathCollection): boolean + + /** + * Test whether a value is zero. The function can check for zero for + * types number, BigNumber, Fraction, Complex, and Unit. The function is + * evaluated element-wise in case of Array or Matrix input. + * @param x Value to be tested + * @returns Returns true when x is zero. Throws an error in case of an + * unknown data type. + */ + isZero(x: MathType): boolean + + /** + * Determine the type of a variable. + * @param x The variable for which to test the type + * @returns Returns the name of the type. Primitive types are lower + * case, non-primitive types are upper-camel-case. For example ‘number’, + * ‘string’, ‘Array’, ‘Date’. + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + typeOf(x: any): string + + /** + * Import functions from an object or a module + * To avoid errors when using one of the imported functions extend module like this: + * + * @example + * // imported_math_functions.ts + * declare module 'mathjs' { + * interface MathJsInterface { + * hello(a: number): number; + * } + * } + * + * @param object An object with functions to be imported. + * @param options An object with import options. + */ + import(object: ImportObject | ImportObject[], options?: ImportOptions): void +} + +/** + * @deprecated The interface MathJsStatic is renamed to MathJsInstance + */ +export type MathJsStatic = MathJsInstance + +/** + * @deprecated use MathJsFactory instead and import dependency maps directly from the library + */ +export type FactoryDependencies = void + +/************************************************************************* + * Factory and Dependencies + ************************************************************************/ +export interface MathJsFactory { + create: ( + factories: FactoryFunctionMap, + config?: ConfigOptions + ) => MathJsInstance + + factory: ( + name: string, + dependencies: TDeps, + create: ( + injected: Pick> + ) => T, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + meta?: any + ) => FactoryFunction +} + +export const { + all, + typedDependencies, + ResultSetDependencies, + BigNumberDependencies, + ComplexDependencies, + FractionDependencies, + RangeDependencies, + MatrixDependencies, + DenseMatrixDependencies, + cloneDependencies, + isIntegerDependencies, + isNegativeDependencies, + isNumericDependencies, + hasNumericValueDependencies, + isPositiveDependencies, + isZeroDependencies, + isNaNDependencies, + typeOfDependencies, + typeofDependencies, + equalScalarDependencies, + SparseMatrixDependencies, + numberDependencies, + stringDependencies, + booleanDependencies, + bignumberDependencies, + complexDependencies, + fractionDependencies, + matrixDependencies, + splitUnitDependencies, + unaryMinusDependencies, + unaryPlusDependencies, + absDependencies, + applyDependencies, + addScalarDependencies, + cbrtDependencies, + ceilDependencies, + cubeDependencies, + expDependencies, + expm1Dependencies, + fixDependencies, + floorDependencies, + gcdDependencies, + lcmDependencies, + log10Dependencies, + log2Dependencies, + modDependencies, + multiplyScalarDependencies, + multiplyDependencies, + nthRootDependencies, + signDependencies, + sqrtDependencies, + squareDependencies, + subtractDependencies, + xgcdDependencies, + dotMultiplyDependencies, + bitAndDependencies, + bitNotDependencies, + bitOrDependencies, + bitXorDependencies, + argDependencies, + conjDependencies, + imDependencies, + reDependencies, + notDependencies, + orDependencies, + xorDependencies, + concatDependencies, + columnDependencies, + crossDependencies, + diagDependencies, + eyeDependencies, + filterDependencies, + flattenDependencies, + forEachDependencies, + getMatrixDataTypeDependencies, + identityDependencies, + kronDependencies, + mapDependencies, + onesDependencies, + rangeDependencies, + reshapeDependencies, + resizeDependencies, + rowDependencies, + sizeDependencies, + squeezeDependencies, + subsetDependencies, + transposeDependencies, + ctransposeDependencies, + zerosDependencies, + erfDependencies, + modeDependencies, + prodDependencies, + formatDependencies, + printDependencies, + toDependencies, + isPrimeDependencies, + numericDependencies, + divideScalarDependencies, + powDependencies, + roundDependencies, + logDependencies, + log1pDependencies, + nthRootsDependencies, + dotPowDependencies, + dotDivideDependencies, + lsolveDependencies, + usolveDependencies, + leftShiftDependencies, + rightArithShiftDependencies, + rightLogShiftDependencies, + andDependencies, + compareDependencies, + compareNaturalDependencies, + compareTextDependencies, + equalDependencies, + equalTextDependencies, + smallerDependencies, + smallerEqDependencies, + largerDependencies, + largerEqDependencies, + deepEqualDependencies, + unequalDependencies, + partitionSelectDependencies, + sortDependencies, + maxDependencies, + minDependencies, + ImmutableDenseMatrixDependencies, + IndexDependencies, + FibonacciHeapDependencies, + SpaDependencies, + UnitDependencies, + unitDependencies, + sparseDependencies, + createUnitDependencies, + acosDependencies, + acoshDependencies, + acotDependencies, + acothDependencies, + acscDependencies, + acschDependencies, + asecDependencies, + asechDependencies, + asinDependencies, + asinhDependencies, + atanDependencies, + atan2Dependencies, + atanhDependencies, + cosDependencies, + coshDependencies, + cotDependencies, + cothDependencies, + cscDependencies, + cschDependencies, + secDependencies, + sechDependencies, + sinDependencies, + sinhDependencies, + tanDependencies, + tanhDependencies, + setCartesianDependencies, + setDifferenceDependencies, + setDistinctDependencies, + setIntersectDependencies, + setIsSubsetDependencies, + setMultiplicityDependencies, + setPowersetDependencies, + setSizeDependencies, + setSymDifferenceDependencies, + setUnionDependencies, + zpk2tfDependencies, + freqzDependencies, + addDependencies, + hypotDependencies, + normDependencies, + dotDependencies, + traceDependencies, + indexDependencies, + NodeDependencies, + AccessorNodeDependencies, + ArrayNodeDependencies, + AssignmentNodeDependencies, + BlockNodeDependencies, + ConditionalNodeDependencies, + ConstantNodeDependencies, + FunctionAssignmentNodeDependencies, + IndexNodeDependencies, + ObjectNodeDependencies, + OperatorNodeDependencies, + ParenthesisNodeDependencies, + RangeNodeDependencies, + RelationalNodeDependencies, + SymbolNodeDependencies, + FunctionNodeDependencies, + parseDependencies, + compileDependencies, + evaluateDependencies, + evalDependencies, + ParserDependencies, + parserDependencies, + lupDependencies, + qrDependencies, + sluDependencies, + lusolveDependencies, + HelpDependencies, + ChainDependencies, + helpDependencies, + chainDependencies, + detDependencies, + invDependencies, + expmDependencies, + sqrtmDependencies, + sylvesterDependencies, + schurDependencies, + lyapDependencies, + divideDependencies, + distanceDependencies, + intersectDependencies, + sumDependencies, + meanDependencies, + medianDependencies, + madDependencies, + varianceDependencies, + varDependencies, + quantileSeqDependencies, + stdDependencies, + combinationsDependencies, + gammaDependencies, + factorialDependencies, + kldivergenceDependencies, + multinomialDependencies, + permutationsDependencies, + pickRandomDependencies, + randomDependencies, + randomIntDependencies, + stirlingS2Dependencies, + bellNumbersDependencies, + catalanDependencies, + compositionDependencies, + simplifyDependencies, + derivativeDependencies, + rationalizeDependencies, + reviverDependencies, + eDependencies, + EDependencies, + falseDependencies, + iDependencies, + InfinityDependencies, + LN10Dependencies, + LN2Dependencies, + LOG10EDependencies, + LOG2EDependencies, + NaNDependencies, + nullDependencies, + phiDependencies, + piDependencies, + PIDependencies, + SQRT1_2Dependencies, + SQRT2Dependencies, + tauDependencies, + trueDependencies, + versionDependencies, + atomicMassDependencies, + avogadroDependencies, + bohrMagnetonDependencies, + bohrRadiusDependencies, + boltzmannDependencies, + classicalElectronRadiusDependencies, + conductanceQuantumDependencies, + coulombDependencies, + deuteronMassDependencies, + efimovFactorDependencies, + electricConstantDependencies, + electronMassDependencies, + elementaryChargeDependencies, + faradayDependencies, + fermiCouplingDependencies, + fineStructureDependencies, + firstRadiationDependencies, + gasConstantDependencies, + gravitationConstantDependencies, + gravityDependencies, + hartreeEnergyDependencies, + inverseConductanceQuantumDependencies, + klitzingDependencies, + loschmidtDependencies, + magneticConstantDependencies, + magneticFluxQuantumDependencies, + molarMassDependencies, + molarMassC12Dependencies, + molarPlanckConstantDependencies, + molarVolumeDependencies, + neutronMassDependencies, + nuclearMagnetonDependencies, + planckChargeDependencies, + planckConstantDependencies, + planckLengthDependencies, + planckMassDependencies, + planckTemperatureDependencies, + planckTimeDependencies, + protonMassDependencies, + quantumOfCirculationDependencies, + reducedPlanckConstantDependencies, + rydbergDependencies, + sackurTetrodeDependencies, + secondRadiationDependencies, + speedOfLightDependencies, + stefanBoltzmannDependencies, + thomsonCrossSectionDependencies, + vacuumImpedanceDependencies, + weakMixingAngleDependencies, + wienDisplacementDependencies, + applyTransformDependencies, + columnTransformDependencies, + filterTransformDependencies, + forEachTransformDependencies, + indexTransformDependencies, + mapTransformDependencies, + maxTransformDependencies, + meanTransformDependencies, + minTransformDependencies, + rangeTransformDependencies, + rowTransformDependencies, + subsetTransformDependencies, + concatTransformDependencies, + stdTransformDependencies, + sumTransformDependencies, + varianceTransformDependencies +}: Record + +export interface Matrix { + type: string + storage(): string + datatype(): string + create(data: MathArray, datatype?: string): void + density(): number + // eslint-disable-next-line @typescript-eslint/no-explicit-any + subset(index: Index, replacement?: any, defaultValue?: any): Matrix + apply( + dim: number, + callback: (array: MathCollection) => number + ): MathCollection + // eslint-disable-next-line @typescript-eslint/no-explicit-any + get(index: number[]): any + // eslint-disable-next-line @typescript-eslint/no-explicit-any + set(index: number[], value: any, defaultValue?: number | string): Matrix + resize(size: MathCollection, defaultValue?: number | string): Matrix + clone(): Matrix + size(): number[] + map( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + callback: (a: any, b: number[], c: Matrix) => any, + skipZeros?: boolean + ): Matrix + forEach( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + callback: (a: any, b: number[], c: Matrix) => void, + skipZeros?: boolean + ): void + toArray(): MathArray + valueOf(): MathArray + // eslint-disable-next-line @typescript-eslint/no-explicit-any + format(options?: FormatOptions | number | ((value: any) => string)): string + toString(): string + // eslint-disable-next-line @typescript-eslint/no-explicit-any + toJSON(): any + // eslint-disable-next-line @typescript-eslint/no-explicit-any + diagonal(k?: number | BigNumber): any[] + swapRows(i: number, j: number): Matrix +} + +export interface MatrixCtor { + new (): Matrix +} + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface BigNumber extends Decimal {} + +export interface Fraction { + s: number + n: number + d: number +} + +export interface Complex { + re: number + im: number + clone(): Complex + equals(other: Complex): boolean + format(precision?: number): string + fromJSON(json: object): Complex + fromPolar(polar: object): Complex + fromPolar(r: number, phi: number): Complex + toJSON(): object + toPolar(): PolarCoordinates + toString(): string + compare(a: Complex, b: Complex): number +} + +export interface PolarCoordinates { + r: number + phi: number +} + +export interface MathJSON { + mathjs?: string + value: number + unit: string + fixPrefix?: boolean +} + +export interface UnitComponent { + power: number + prefix: string + unit: { + name: string + base: { + dimensions: number[] + key: string + } + prefixes: Record + value: number + offset: number + dimensions: number[] + } +} + +export interface UnitPrefix { + name: string + value: number + scientific: boolean +} + +export interface Unit { + valueOf(): string + clone(): Unit + // eslint-disable-next-line @typescript-eslint/no-explicit-any + hasBase(base: any): boolean + equalBase(unit: Unit): boolean + equals(unit: Unit): boolean + multiply(unit: Unit): Unit + divide(unit: Unit): Unit | number + pow(unit: Unit): Unit + abs(unit: Unit): Unit + to(unit: string): Unit + toNumber(unit?: string): number + toNumeric(unit?: string): number | Fraction | BigNumber + toSI(): Unit + toString(): string + toJSON(): MathJSON + formatUnits(): string + format(options: FormatOptions): string + simplify(): Unit + splitUnit(parts: ReadonlyArray): Unit[] + + units: UnitComponent[] + dimensions: number[] + value: number + fixPrefix: boolean + skipAutomaticSimplification: true +} + +export interface CreateUnitOptions { + prefixes?: 'none' | 'short' | 'long' | 'binary_short' | 'binary_long' + aliases?: string[] + offset?: number + override?: boolean +} + +export type SimplifyContext = Partial< + Record< + OperatorNodeFn, + { + trivial: boolean + total: boolean + commutative: boolean + associative: boolean + } + > +> + +export interface SimplifyOptions { + /** A boolean which is `true` by default. */ + exactFractions?: boolean + /** + * When `exactFractions` is true, a fraction will be returned only + * when both numerator and denominator are smaller than `fractionsLimit`. + * Default value is 10000. + */ + fractionsLimit?: number + /** A boolean which is `false` by default. */ + consoleDebug?: boolean + /** + * gives properties of each operator, which determine what simplifications + * are allowed. Properties are commutative, associative, total (whether + * the operation is defined for all arguments), and trivial (whether + * the operation applied to a single argument leaves that argument + * unchanged). + */ + context?: SimplifyContext +} + +export type SimplifyRule = + | { + l: string + r: string + repeat?: boolean + assuming?: SimplifyContext + imposeContext?: SimplifyContext + } + | { + s: string + repeat?: boolean + assuming?: SimplifyContext + imposeContext?: SimplifyContext + } + | string + | ((node: MathNode) => MathNode) + +export interface Simplify { + (expr: MathNode | string): MathNode + ( + expr: MathNode | string, + rules: SimplifyRule[], + scope?: object, + options?: SimplifyOptions + ): MathNode + (expr: MathNode | string, scope: object, options?: SimplifyOptions): MathNode + + rules: SimplifyRule[] +} + +export interface UnitDefinition { + definition?: string | Unit + prefixes?: string + offset?: number + aliases?: string[] + baseName?: string +} + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface Index {} + +export interface EvalFunction { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + evaluate(scope?: any): any +} + +export interface MathNode { + isNode: true + comment: string + type: string + + isUpdateNode?: boolean + + /** + * Create a shallow clone of the node. The node itself is cloned, its + * childs are not cloned. + */ + clone(): this + /** + * Create a deep clone of the node. Both the node as well as all its + * childs are cloned recursively. + */ + cloneDeep(): this + /** + * Compile an expression into optimized JavaScript code. compile returns + * an object with a function evaluate([scope]) to evaluate. Example: + */ + compile(): EvalFunction + /** + * Compile and eval an expression, this is the equivalent of doing + * node.compile().evaluate(scope). Example: + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + evaluate(expr?: any): any + /** + * Test whether this node equals an other node. Does a deep comparison + * of the values of both nodes. + */ + equals(other: MathNode): boolean + /** + * + * Filter nodes in an expression tree. The callback function is called + * as callback(node: MathNode, path: string, parent: MathNode) : boolean + * for every node in the tree, and must return a boolean. The function + * filter returns an array with nodes for which the test returned true. + * Parameter path is a string containing a relative JSON Path. + * + * Example: + * + * ``` + * var node = math.parse('x^2 + x/4 + 3*y'); + * var filtered = node.filter(function (node) { + * return node.isSymbolMathNode && node.name == 'x'; + * }); + * // returns an array with two entries: two SymbolMathNodes 'x' + * ``` + * + * The callback function is called as callback(node: MathNode, path: + * string, parent: MathNode) : boolean for every node in the tree, and + * must return a boolean. The function filter returns an array with + * nodes for which the test returned true. Parameter path is a string + * containing a relative JSON Path. + * @return Returns an array with nodes for which test returned true + */ + filter( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + callback: (node: MathNode, path: string, parent: MathNode) => any + ): MathNode[] + + /** + * [forEach description] + */ + forEach( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + callback: (node: MathNode, path: string, parent: MathNode) => void + ): void + + /** + * Transform a node. Creates a new MathNode having it’s child's be the + * results of calling the provided callback function for each of the + * child's of the original node. The callback function is called as + * `callback(child: MathNode, path: string, parent: MathNode)` and must + * return a MathNode. Parameter path is a string containing a relative + * JSON Path. + * + * + * See also transform, which is a recursive version of map. + */ + map( + callback: (node: MathNode, path: string, parent: MathNode) => MathNode + ): MathNode + + /** + * Get a HTML representation of the parsed expression. + */ + toHTML(options?: object): string + + /** + * Get a string representation of the parsed expression. This is not + * exactly the same as the original input. + */ + toString(options?: object): string + + /** + * Get a LaTeX representation of the expression. + */ + toTex(options?: object): string + + /** + * Recursively transform an expression tree via a transform function. + * Similar to Array.map, but recursively executed on all nodes in the + * expression tree. The callback function is a mapping function + * accepting a node, and returning a replacement for the node or the + * original node. Function callback is called as callback(node: + * MathNode, path: string, parent: MathNode) for every node in the tree, + * and must return a MathNode. Parameter path is a string containing a + * relative JSON Path. + * + * For example, to replace all nodes of type SymbolMathNode having name + * ‘x’ with a ConstantMathNode with value 3: + * ```js + * var node = math.parse('x^2 + 5*x'); + * var transformed = node.transform(function (node, path, parent) { + * if (node.SymbolMathNode && node.name == 'x') { + * return new math.expression.node.ConstantMathNode(3); + * } + * else { + * return node; + * } + * }); + * transformed.toString(); // returns '(3 ^ 2) + (5 * 3)' + * ``` + */ + transform( + callback: (node: this, path: string, parent: MathNode) => TResult + ): TResult + + /** + * `traverse(callback)` + * + * Recursively traverse all nodes in a node tree. Executes given + * callback for this node and each of its child nodes. Similar to + * Array.forEach, except recursive. The callback function is a mapping + * function accepting a node, and returning a replacement for the node + * or the original node. Function callback is called as callback(node: + * MathNode, path: string, parent: MathNode) for every node in the tree. + * Parameter path is a string containing a relative JSON Path. Example: + * + * ``` + * var node = math.parse('3 * x + 2'); + * node.traverse(function (node, path, parent) { + * switch (node.type) { + * case 'OperatorMathNode': console.log(node.type, node.op); break; + * case 'ConstantMathNode': console.log(node.type, node.value); break; + * case 'SymbolMathNode': console.log(node.type, node.name); break; + * default: console.log(node.type); + * } + * }); + * // outputs: + * // OperatorMathNode + + * // OperatorMathNode * + * // ConstantMathNode 3 + * // SymbolMathNode x + * // ConstantMathNode 2 + * ``` + */ + traverse( + callback: (node: MathNode, path: string, parent: MathNode) => void + ): void +} + +export interface Parser { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + evaluate(expr: string | string[]): any + // eslint-disable-next-line @typescript-eslint/no-explicit-any + get(variable: string): any + // eslint-disable-next-line @typescript-eslint/no-explicit-any + getAll(): { [key: string]: any } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + set: (variable: string, value: any) => void + clear: () => void +} + +export interface Distribution { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + random(size: any, min?: any, max?: any): any + // eslint-disable-next-line @typescript-eslint/no-explicit-any + randomInt(min: any, max?: any): any + // eslint-disable-next-line @typescript-eslint/no-explicit-any + pickRandom(array: any): any +} + +export interface FormatOptions { + /** + * Number notation. Choose from: 'fixed' Always use regular number + * notation. For example '123.40' and '14000000' 'exponential' Always + * use exponential notation. For example '1.234e+2' and '1.4e+7' 'auto' + * (default) Regular number notation for numbers having an absolute + * value between lower and upper bounds, and uses exponential notation + * elsewhere. Lower bound is included, upper bound is excluded. For + * example '123.4' and '1.4e7'. + */ + notation?: 'fixed' | 'exponential' | 'engineering' | 'auto' + + /** + * A number between 0 and 16 to round the digits of the number. In case + * of notations 'exponential' and 'auto', precision defines the total + * number of significant digits returned and is undefined by default. In + * case of notation 'fixed', precision defines the number of significant + * digits after the decimal point, and is 0 by default. + */ + precision?: number + + /** + * Exponent determining the lower boundary for formatting a value with + * an exponent when notation='auto. Default value is -3. + */ + lowerExp?: number + + /** + * Exponent determining the upper boundary for formatting a value with + * an exponent when notation='auto. Default value is 5. + */ + upperExp?: number + + /** + * Available values: 'ratio' (default) or 'decimal'. For example + * format(fraction(1, 3)) will output '1/3' when 'ratio' is configured, + * and will output 0.(3) when 'decimal' is configured. + */ + fraction?: string +} + +export interface Help { + toString(): string + toJSON(): string +} + +export interface ConfigOptions { + epsilon?: number + matrix?: 'Matrix' | 'Array' + number?: 'number' | 'BigNumber' | 'Fraction' + precision?: number + predictable?: boolean + randomSeed?: string | null +} + +export interface MathJsChain { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + done(): TValue + + /************************************************************************* + * Construction functions + ************************************************************************/ + + /** + * Create a BigNumber, which can store numbers with arbitrary precision. + * When a matrix is provided, all elements will be converted to + * BigNumber. + */ + bignumber( + this: MathJsChain< + number | string | Fraction | BigNumber | Unit | boolean | null + > + ): MathJsChain + bignumber(this: MathJsChain): MathJsChain + + /** + * Create a boolean or convert a string or number to a boolean. In case + * of a number, true is returned for non-zero numbers, and false in case + * of zero. Strings can be 'true' or 'false', or can contain a number. + * When value is a matrix, all elements will be converted to boolean. + */ + boolean( + this: MathJsChain + ): MathJsChain + boolean(this: MathJsChain): MathJsChain + + /** + * Create a complex value or convert a value to a complex value. + * @param im Argument specifying the imaginary part of the complex + * number + */ + complex( + this: MathJsChain, + im?: number + ): MathJsChain + complex(this: MathJsChain): MathJsChain + + /** + * Create a user-defined unit and register it with the Unit type. + * @param definition Definition of the unit in terms of existing units. + * For example, ‘0.514444444 m / s’. + * @param options (optional) An object containing any of the following + * properties:
- prefixes {string} “none”, “short”, “long”, + * “binary_short”, or “binary_long”. The default is “none”.
- + * aliases {Array} Array of strings. Example: [‘knots’, ‘kt’, + * ‘kts’]
- offset {Numeric} An offset to apply when converting from + * the unit. For example, the offset for celsius is 273.15. Default is + * 0. + */ + createUnit( + this: MathJsChain, + definition?: string | UnitDefinition | Unit, + options?: CreateUnitOptions + ): MathJsChain + /** + * Create a user-defined unit and register it with the Unit type. + * @param options (optional) An object containing any of the following + * properties:
- prefixes {string} “none”, “short”, “long”, + * “binary_short”, or “binary_long”. The default is “none”.
- + * aliases {Array} Array of strings. Example: [‘knots’, ‘kt’, + * ‘kts’]
- offset {Numeric} An offset to apply when converting from + * the unit. For example, the offset for celsius is 273.15. Default is + * 0. + */ + createUnit( + this: MathJsChain>, + options?: CreateUnitOptions + ): MathJsChain + + /** + * Create a fraction convert a value to a fraction. + * @param denominator Argument specifying the denominator of the + * fraction + */ + fraction( + this: MathJsChain< + number | string | BigNumber | Unit | Fraction | FractionDefinition + >, + denominator?: number + ): MathJsChain + fraction(this: MathJsChain): MathJsChain + + /** + * Create an index. An Index can store ranges having start, step, and + * end for multiple dimensions. Matrix.get, Matrix.set, and math.subset + * accept an Index as input. + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + index(this: MathJsChain): MathJsChain + + /** + * Create a Matrix. The function creates a new math.type.Matrix object + * from an Array. A Matrix has utility functions to manipulate the data + * in the matrix, like getting the size and getting or setting values in + * the matrix. Supported storage formats are 'dense' and 'sparse'. + */ + matrix( + this: MathJsChain, + format?: 'sparse' | 'dense', + dataType?: string + ): MathJsChain + + /** + * Create a number or convert a string, boolean, or unit to a number. + * When value is a matrix, all elements will be converted to number. + * @param valuelessUnit A valueless unit, used to convert a unit to a + * number + */ + number( + this: MathJsChain< + string | number | BigNumber | Fraction | boolean | Unit | null + >, + valuelessUnit?: Unit | string + ): MathJsChain + number( + this: MathJsChain, + valuelessUnit?: Unit | string + ): MathJsChain + + /** + * Create a Sparse Matrix. The function creates a new math.type.Matrix + * object from an Array. A Matrix has utility functions to manipulate + * the data in the matrix, like getting the size and getting or setting + * values in the matrix. + * @param dataType Sparse Matrix data type + */ + sparse( + this: MathJsChain, + dataType?: string + ): MathJsChain + + /** + * Split a unit in an array of units whose sum is equal to the original + * unit. + * @param parts An array of strings or valueless units + */ + splitUnit(this: MathJsChain, parts: Unit[]): MathJsChain + + /** + * Create a string or convert any object into a string. Elements of + * Arrays and Matrices are processed element wise. + */ + string( + this: MathJsChain + ): MathJsChain + string(this: MathJsChain): MathJsChain + + /** + * Create a unit. Depending on the passed arguments, the function will + * create and return a new math.type.Unit object. When a matrix is + * provided, all elements will be converted to units. + * @param unit The unit to be created + */ + unit(this: MathJsChain, unit?: string): MathJsChain + unit(this: MathJsChain, unit?: string): MathJsChain + unit(this: MathJsChain, unit?: string): MathJsChain + + /************************************************************************* + * Expression functions + ************************************************************************/ + + /** + * Parse and compile an expression. Returns a an object with a function + * evaluate([scope]) to evaluate the compiled expression. + */ + compile(this: MathJsChain): MathJsChain + + // TODO properly type this + /** + * Evaluate an expression. + * @param scope Scope to read/write variables + */ + evaluate( + this: MathJsChain, + scope?: object + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ): MathJsChain + evaluate( + this: MathJsChain, + scope?: object + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ): MathJsChain + + /** + * Retrieve help on a function or data type. Help files are retrieved + * from the documentation in math.expression.docs. + */ + help(this: MathJsChain): MathJsChain + + /** + * @param options Available options: nodes - a set of custome nodes + */ + parse( + this: MathJsChain, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + options?: any + ): MathJsChain + + /** + * Parse an expression. Returns a node tree, which can be evaluated by + * invoking node.evaluate(); + * @param options Available options: nodes - a set of custome nodes + */ + parse( + this: MathJsChain, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + options?: any + ): MathJsChain + + /** + * Replaces variable nodes with their scoped values + * @param scope Scope to read/write variables + */ + resolve( + this: MathJsChain, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + scope?: Record + ): MathJsChain + resolve( + this: MathJsChain, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + scope?: Record + ): MathJsChain + + /************************************************************************* + * Algebra functions + ************************************************************************/ + /** + * @param variable The variable over which to differentiate + * @param options There is one option available, simplify, which is true + * by default. When false, output will not be simplified. + */ + derivative( + this: MathJsChain, + variable: MathNode | string, + options?: { simplify: boolean } + ): MathJsChain + + /** + * Solves the linear equation system by forwards substitution. Matrix + * must be a lower triangular matrix. + * @param b A column vector with the b values + */ + lsolve(this: MathJsChain, b: MathCollection): MathJsChain + lsolve( + this: MathJsChain, + b: MathCollection + ): MathJsChain + + /** + * Calculate the Matrix LU decomposition with partial pivoting. Matrix A + * is decomposed in two matrices (L, U) and a row permutation vector p + * where A[p,:] = L * U + */ + lup(this: MathJsChain): MathJsChain + + /** + * Solves the linear system A * x = b where A is an [n x n] matrix and b + * is a [n] column vector. + * @param b Column Vector + * @param order The Symbolic Ordering and Analysis order, see slu for + * details. Matrix must be a SparseMatrix + * @param threshold Partial pivoting threshold (1 for partial pivoting), + * see slu for details. Matrix must be a SparseMatrix. + */ + lusolve( + this: MathJsChain, + b: MathCollection, + order?: number, + threshold?: number + ): MathJsChain + + lusolve( + this: MathJsChain, + b: MathCollection, + order?: number, + threshold?: number + ): MathJsChain + + lusolve( + this: MathJsChain, + b: MathCollection + ): MathJsChain + + /** + * Calculate the Matrix QR decomposition. Matrix A is decomposed in two + * matrices (Q, R) where Q is an orthogonal matrix and R is an upper + * triangular matrix. + */ + qr(this: MathJsChain): MathJsChain + + /** + * Transform a rationalizable expression in a rational fraction. If + * rational fraction is one variable polynomial then converts the + * numerator and denominator in canonical form, with decreasing + * exponents, returning the coefficients of numerator. + * @param optional scope of expression or true for already evaluated + * rational expression at input + * @param detailed optional True if return an object, false if return + * expression node (default) + */ + rationalize( + this: MathJsChain, + optional?: object | boolean, + detailed?: boolean + ): MathJsChain + + /** + * Simplify an expression tree. + * @param rules A list of rules are applied to an expression, repeating + * over the list until no further changes are made. It’s possible to + * pass a custom set of rules to the function as second argument. A rule + * can be specified as an object, string, or function. + * @param scope Scope to variables + * @param options Options to configure the behavior of simplify + */ + simplify( + this: MathJsChain, + rules?: SimplifyRule[], + scope?: Map | object, + options?: SimplifyOptions + ): MathJsChain + + simplifyConstant( + this: MathJsChain, + options?: SimplifyOptions + ): MathJsChain + simplifyCore( + this: MathJsChain, + options?: SimplifyOptions + ): MathJsChain + + /** + * Calculate the Sparse Matrix LU decomposition with full pivoting. + * Sparse Matrix A is decomposed in two matrices (L, U) and two + * permutation vectors (pinv, q) where P * A * Q = L * U + * @param order The Symbolic Ordering and Analysis order: 0 - Natural + * ordering, no permutation vector q is returned 1 - Matrix must be + * square, symbolic ordering and analisis is performed on M = A + A' 2 - + * Symbolic ordering and analysis is performed on M = A' * A. Dense + * columns from A' are dropped, A recreated from A'. This is appropriate + * for LU factorization of non-symmetric matrices. 3 - Symbolic ordering + * and analysis is performed on M = A' * A. This is best used for LU + * factorization is matrix M has no dense rows. A dense row is a row + * with more than 10*sqr(columns) entries. + * @param threshold Partial pivoting threshold (1 for partial pivoting) + */ + slu( + this: MathJsChain, + order: number, + threshold: number + ): MathJsChain + + /** + * Solves the linear equation system by backward substitution. Matrix + * must be an upper triangular matrix. U * x = b + * @param b A column vector with the b values + */ + usolve(this: MathJsChain, b: MathCollection): MathJsChain + usolve( + this: MathJsChain, + b: MathCollection + ): MathJsChain + + /************************************************************************* + * Arithmetic functions + ************************************************************************/ + + /** + * Calculate the absolute value of a number. For matrices, the function + * is evaluated element wise. + */ + abs(this: MathJsChain): MathJsChain + + /** + * Add two values, x + y. For matrices, the function is evaluated + * element wise. + * @param y Second value to add + */ + add(this: MathJsChain, y: T): MathJsChain + add(this: MathJsChain, y: MathType): MathJsChain + + /** + * Apply a function that maps an array to a scalar along a given axis of the + * matrix or array. Returns a new matrix or array with one less dimension + * than the input. + * @param dim The dimension along which the callback is applied + * @param callback The callback function that is applied. This Function should take an + * array or 1-d matrix as an input and return a number. + * @returns The residual matrix with the function applied over some dimension. + */ + apply( + this: MathJsChain, + dim: number, + callback: (array: Array | Matrix) => number + ): MathJsChain + + /** + * Calculate the cubic root of a value. For matrices, the function is + * evaluated element wise. + * @param allRoots Optional, false by default. Only applicable when x is + * a number or complex number. If true, all complex roots are returned, + * if false (default) the principal root is returned. + */ + cbrt( + this: MathJsChain, + allRoots?: boolean + ): MathJsChain + + // Rounding functions grouped for similarity + + /** + * Round a value towards plus infinity If x is complex, both real and + * imaginary part are rounded towards plus infinity. For matrices, the + * function is evaluated element wise. + * @param n Number of decimals Default value: 0. + */ + ceil( + this: MathJsChain, + n?: number | BigNumber | MathCollection + ): MathJsChain + + /** + * Round a value towards zero. For matrices, the function is evaluated + * element wise. + * @param n Number of decimals Default value: 0. + */ + fix( + this: MathJsChain, + n?: number | BigNumber | MathCollection + ): MathJsChain + + /** + * Round a value towards minus infinity. For matrices, the function is + * evaluated element wise. + * @param n Number of decimals Default value: 0. + */ + floor( + this: MathJsChain, + n?: number | BigNumber | MathCollection + ): MathJsChain + + /** + * Round a value towards the nearest integer. For matrices, the function + * is evaluated element wise. + * @param n Number of decimals Default value: 0. + */ + round( + this: MathJsChain, + n?: number | BigNumber | MathCollection + ): MathJsChain + + // End of rounding group + + /** + * Compute the cube of a value, x * x * x. For matrices, the function is + * evaluated element wise. + */ + cube(this: MathJsChain): MathJsChain + + /** + * Divide two values, x / y. To divide matrices, x is multiplied with + * the inverse of y: x * inv(y). + * @param y Denominator + */ + divide(this: MathJsChain, y: Unit): MathJsChain + divide(this: MathJsChain, y: number): MathJsChain + divide(this: MathJsChain, y: number): MathJsChain + divide(this: MathJsChain, y: MathType): MathJsChain + + /** + * Divide two matrices element wise. The function accepts both matrices + * and scalar values. + * @param y Denominator + */ + dotDivide( + this: MathJsChain, + y: MathType + ): MathJsChain + dotDivide( + this: MathJsChain, + y: T + ): MathJsChain + dotDivide(this: MathJsChain, y: MathType): MathJsChain + dotDivide(this: MathJsChain, y: Unit): MathJsChain + dotDivide( + this: MathJsChain, + y: MathNumericType + ): MathJsChain + + /** + * Multiply two matrices element wise. The function accepts both + * matrices and scalar values. + * @param y Right hand value + */ + dotMultiply( + this: MathJsChain, + y: MathType + ): MathJsChain + dotMultiply( + this: MathJsChain, + y: T + ): MathJsChain + dotMultiply(this: MathJsChain, y: MathType): MathJsChain + dotMultiply(this: MathJsChain, y: Unit): MathJsChain + dotMultiply( + this: MathJsChain, + y: MathNumericType + ): MathJsChain + + /** + * Calculates the power of x to y element wise. + * @param y The exponent + */ + dotPow(this: MathJsChain, y: MathType): MathJsChain + + /** + * Calculate the exponent of a value. For matrices, the function is + * evaluated element wise. + */ + exp( + this: MathJsChain + ): MathJsChain + + /** + * Calculate the value of subtracting 1 from the exponential value. For + * matrices, the function is evaluated element wise. + */ + expm1( + this: MathJsChain + ): MathJsChain + + /** + * Calculate the greatest common divisor for two or more values or + * arrays. For matrices, the function is evaluated element wise. + */ + gcd( + this: MathJsChain, + ...args: T[] + ): MathJsChain + + /** + * Calculate the hypotenusa of a list with values. The hypotenusa is + * defined as: hypot(a, b, c, ...) = sqrt(a^2 + b^2 + c^2 + ...) For + * matrix input, the hypotenusa is calculated for all values in the + * matrix. + */ + hypot(this: MathJsChain): MathJsChain + + /** + * Calculate the least common multiple for two or more values or arrays. + * lcm is defined as: lcm(a, b) = abs(a * b) / gcd(a, b) For matrices, + * the function is evaluated element wise. + * @param b An integer number + */ + lcm( + this: MathJsChain, + b: T + ): MathJsChain + + /** + * Calculate the logarithm of a value. For matrices, the function is + * evaluated element wise. + * @param base Optional base for the logarithm. If not provided, the + * natural logarithm of x is calculated. Default value: e. + */ + log( + this: MathJsChain, + base?: number | BigNumber | Complex + ): MathJsChain> + + /** + * Calculate the 10-base of a value. This is the same as calculating + * log(x, 10). For matrices, the function is evaluated element wise. + */ + + log10( + this: MathJsChain + ): MathJsChain + + /** + * Calculate the logarithm of a value+1. For matrices, the function is + * evaluated element wise. + */ + log1p( + this: MathJsChain, + base?: number | BigNumber | Complex + ): MathJsChain + log1p( + this: MathJsChain, + base?: number | BigNumber | Complex + ): MathJsChain + log1p( + this: MathJsChain, + base?: number | BigNumber | Complex + ): MathJsChain + log1p( + this: MathJsChain, + base?: number | BigNumber | Complex + ): MathJsChain + log1p( + this: MathJsChain, + base?: number | BigNumber | Complex + ): MathJsChain + + /** + * Calculate the 2-base of a value. This is the same as calculating + * log(x, 2). For matrices, the function is evaluated element wise. + */ + + log2( + this: MathJsChain + ): MathJsChain + + /** + * Calculates the modulus, the remainder of an integer division. For + * matrices, the function is evaluated element wise. The modulus is + * defined as: x - y * floor(x / y) + * @see http://en.wikipedia.org/wiki/Modulo_operation. + * @param y Divisor + */ + mod( + this: MathJsChain, + y: number | BigNumber | Fraction | MathCollection + ): MathJsChain> + + /** + * Multiply two values, x * y. The result is squeezed. For matrices, the + * matrix product is calculated. + * @param y The second value to multiply + */ + multiply( + this: MathJsChain, + y: MathType + ): MathJsChain + multiply(this: MathJsChain, y: Unit): MathJsChain + multiply(this: MathJsChain, y: number): MathJsChain + multiply(this: MathJsChain, y: MathType): MathJsChain + + /** + * Calculate the norm of a number, vector or matrix. The second + * parameter p is optional. If not provided, it defaults to 2. + * @param p Vector space. Supported numbers include Infinity and + * -Infinity. Supported strings are: 'inf', '-inf', and 'fro' (The + * Frobenius norm) Default value: 2. + */ + norm( + this: MathJsChain, + p?: number | BigNumber | string + ): MathJsChain + + /** + * Calculate the nth root of a value. The principal nth root of a + * positive real number A, is the positive real solution of the equation + * x^root = A For matrices, the function is evaluated element wise. + * @param root The root. Default value: 2. + */ + nthRoot( + this: MathJsChain, + root?: number | BigNumber + ): MathJsChain + + /** + * Calculates the power of x to y, x ^ y. Matrix exponentiation is + * supported for square matrices x, and positive integer exponents y. + * @param y The exponent + */ + pow( + this: MathJsChain, + y: number | BigNumber | Complex + ): MathJsChain + + /** + * Compute the sign of a value. The sign of a value x is: 1 when x > 1 + * -1 when x < 0 0 when x == 0 For matrices, the function is evaluated + * element wise. + * @param x The number for which to determine the sign + * @returns The sign of x + */ + sign(this: MathJsChain): MathJsChain + + /** + * Calculate the square root of a value. For matrices, the function is + * evaluated element wise. + */ + + sqrt( + this: MathJsChain + ): MathJsChain + + /** + * Compute the square of a value, x * x. For matrices, the function is + * evaluated element wise. + */ + + square(this: MathJsChain): MathJsChain + + /** + * Subtract two values, x - y. For matrices, the function is evaluated + * element wise. + * @param y Value to subtract from x + */ + subtract(this: MathJsChain, y: T): MathJsChain + + /** + * Inverse the sign of a value, apply a unary minus operation. For + * matrices, the function is evaluated element wise. Boolean values and + * strings will be converted to a number. For complex numbers, both real + * and complex value are inverted. + */ + + unaryMinus(this: MathJsChain): MathJsChain + + /** + * Unary plus operation. Boolean values and strings will be converted to + * a number, numeric values will be returned as is. For matrices, the + * function is evaluated element wise. + */ + + unaryPlus(this: MathJsChain): MathJsChain + + /** + * Calculate the extended greatest common divisor for two values. See + * http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm. + * @param b An integer number + */ + xgcd( + this: MathJsChain, + b: number | BigNumber + ): MathJsChain + + /** + * Count the number of elements of a matrix, array or string. + */ + count(this: MathJsChain): MathJsChain + count(this: MathJsChain): MathJsChain + + /** + * Compute the sum of a matrix or a list with values. In case of a + * (multi dimensional) array or matrix, the sum of all elements will be + * calculated. + */ + sum( + this: MathJsChain> + ): MathJsChain + sum(this: MathJsChain): MathJsChain + /************************************************************************* + * Bitwise functions + ************************************************************************/ + + /** + * Bitwise AND two values, x & y. For matrices, the function is + * evaluated element wise. + * @param y Second value to and + */ + bitAnd( + this: MathJsChain, + y: number | BigNumber | MathCollection + ): MathJsChain> + + /** + * Bitwise NOT value, ~x. For matrices, the function is evaluated + * element wise. For units, the function is evaluated on the best prefix + * base. + */ + + bitNot( + this: MathJsChain + ): MathJsChain + + /** + * Bitwise OR two values, x | y. For matrices, the function is evaluated + * element wise. For units, the function is evaluated on the lowest + * print base. + * @param y Second value to or + */ + bitOr( + this: MathJsChain, + y: T + ): MathJsChain + + /** + * Bitwise XOR two values, x ^ y. For matrices, the function is + * evaluated element wise. + * @param y Second value to xor + */ + bitXor( + this: MathJsChain, + y: number | BigNumber | MathCollection + ): MathJsChain> + + /** + * Bitwise left logical shift of a value x by y number of bits, x << y. + * For matrices, the function is evaluated element wise. For units, the + * function is evaluated on the best prefix base. + * @param y Amount of shifts + */ + leftShift( + this: MathJsChain, + y: number | BigNumber + ): MathJsChain> + + /** + * Bitwise right arithmetic shift of a value x by y number of bits, x >> + * y. For matrices, the function is evaluated element wise. For units, + * the function is evaluated on the best prefix base. + * @param y Amount of shifts + */ + rightArithShift( + this: MathJsChain, + y: number | BigNumber + ): MathJsChain> + + /** + * Bitwise right logical shift of value x by y number of bits, x >>> y. + * For matrices, the function is evaluated element wise. For units, the + * function is evaluated on the best prefix base. + * @param y Amount of shifts + */ + rightLogShift( + this: MathJsChain, + y: number + ): MathJsChain> + + /************************************************************************* + * Combinatorics functions + ************************************************************************/ + + /** + * The Bell Numbers count the number of partitions of a set. A partition + * is a pairwise disjoint subset of S whose union is S. bellNumbers only + * takes integer arguments. The following condition must be enforced: n + * >= 0 + */ + + bellNumbers(this: MathJsChain): MathJsChain + bellNumbers(this: MathJsChain): MathJsChain + + /** + * The Catalan Numbers enumerate combinatorial structures of many + * different types. catalan only takes integer arguments. The following + * condition must be enforced: n >= 0 + */ + + catalan(this: MathJsChain): MathJsChain + catalan(this: MathJsChain): MathJsChain + + /** + * The composition counts of n into k parts. Composition only takes + * integer arguments. The following condition must be enforced: k <= n. + * @param k Number of objects in the subset + */ + composition( + this: MathJsChain, + k: number | BigNumber + ): MathJsChain> + + /** + * The Stirling numbers of the second kind, counts the number of ways to + * partition a set of n labelled objects into k nonempty unlabelled + * subsets. stirlingS2 only takes integer arguments. The following + * condition must be enforced: k <= n. If n = k or k = 1, then s(n,k) = + * 1 + * @param k Number of objects in the subset + */ + stirlingS2( + this: MathJsChain, + k: number | BigNumber + ): MathJsChain> + + /************************************************************************* + * Complex functions + ************************************************************************/ + + /** + * Compute the argument of a complex value. For a complex number a + bi, + * the argument is computed as atan2(b, a). For matrices, the function + * is evaluated element wise. + */ + + arg(this: MathJsChain): MathJsChain + arg(this: MathJsChain): MathJsChain + arg(this: MathJsChain): MathJsChain + arg(this: MathJsChain): MathJsChain + + /** + * Compute the complex conjugate of a complex value. If x = a+bi, the + * complex conjugate of x is a - bi. For matrices, the function is + * evaluated element wise. + */ + conj( + this: MathJsChain + ): MathJsChain> + + /** + * Get the imaginary part of a complex number. For a complex number a + + * bi, the function returns b. For matrices, the function is evaluated + * element wise. + */ + im(this: MathJsChain): MathJsChain + im(this: MathJsChain): MathJsChain + im(this: MathJsChain): MathJsChain + + /** + * Get the real part of a complex number. For a complex number a + bi, + * the function returns a. For matrices, the function is evaluated + * element wise. + */ + re(this: MathJsChain): MathJsChain + re(this: MathJsChain): MathJsChain + re(this: MathJsChain): MathJsChain + + /************************************************************************* + * Geometry functions + ************************************************************************/ + + /** + * Calculates: The eucledian distance between two points in 2 and 3 + * dimensional spaces. Distance between point and a line in 2 and 3 + * dimensional spaces. Pairwise distance between a set of 2D or 3D + * points NOTE: When substituting coefficients of a line(a, b and c), + * use ax + by + c = 0 instead of ax + by = c For parametric equation of + * a 3D line, x0, y0, z0, a, b, c are from: (x−x0, y−y0, z−z0) = t(a, b, + * c) + * @param y Coordinates of the second point + */ + distance( + this: MathJsChain, + y: MathCollection | object + ): MathJsChain + + /** + * Calculates the point of intersection of two lines in two or three + * dimensions and of a line and a plane in three dimensions. The inputs + * are in the form of arrays or 1 dimensional matrices. The line + * intersection functions return null if the lines do not meet. Note: + * Fill the plane coefficients as x + y + z = c and not as x + y + z + c + * = 0. + * @param x Co-ordinates of second end-point of first line + * @param y Co-ordinates of first end-point of second line OR + * Coefficients of the plane's equation + * @param z Co-ordinates of second end-point of second line OR null if + * the calculation is for line and plane + */ + intersect( + this: MathJsChain, + x: MathCollection, + y: MathCollection, + z?: MathCollection + ): MathJsChain + + /************************************************************************* + * Logical functions + ************************************************************************/ + + /** + * Logical and. Test whether two values are both defined with a + * nonzero/nonempty value. For matrices, the function is evaluated + * element wise. + * @param y Second value to and + */ + and( + this: MathJsChain, + y: number | BigNumber | Complex | Unit | MathCollection + ): MathJsChain + + /** + * Logical not. Flips boolean value of a given parameter. For matrices, + * the function is evaluated element wise. + */ + not( + this: MathJsChain + ): MathJsChain + + /** + * Logical or. Test if at least one value is defined with a + * nonzero/nonempty value. For matrices, the function is evaluated + * element wise. + * @param y Second value to or + */ + or( + this: MathJsChain, + y: number | BigNumber | Complex | Unit | MathCollection + ): MathJsChain + + /** + * Logical xor. Test whether one and only one value is defined with a + * nonzero/nonempty value. For matrices, the function is evaluated + * element wise. + * @param y Second value to xor + */ + xor( + this: MathJsChain, + y: number | BigNumber | Complex | Unit | MathCollection + ): MathJsChain + + /************************************************************************* + * Matrix functions + ************************************************************************/ + + /** + * Concatenate two or more matrices. dim: number is a zero-based + * dimension over which to concatenate the matrices. By default the last + * dimension of the matrices. + */ + + concat( + this: MathJsChain> + ): MathJsChain + + /** + * Calculate the cross product for two vectors in three dimensional + * space. The cross product of A = [a1, a2, a3] and B =[b1, b2, b3] is + * defined as: cross(A, B) = [ a2 * b3 - a3 * b2, a3 * b1 - a1 * b3, a1 + * * b2 - a2 * b1 ] + * @param y Second vector + */ + cross( + this: MathJsChain, + y: MathCollection + ): MathJsChain + + /** + * Calculate the determinant of a matrix. + */ + + det(this: MathJsChain): MathJsChain + + /** + * Create a diagonal matrix or retrieve the diagonal of a matrix. When x + * is a vector, a matrix with vector x on the diagonal will be returned. + * When x is a two dimensional matrix, the matrixes kth diagonal will be + * returned as vector. When k is positive, the values are placed on the + * super diagonal. When k is negative, the values are placed on the sub + * diagonal. + * @param k The diagonal where the vector will be filled in or + * retrieved. Default value: 0. + * @param format The matrix storage format. Default value: 'dense'. + */ + diag(this: MathJsChain, format?: string): MathJsChain + diag( + this: MathJsChain, + k: number | BigNumber, + format?: string + ): MathJsChain + + /** + * Calculate the dot product of two vectors. The dot product of A = [a1, + * a2, a3, ..., an] and B = [b1, b2, b3, ..., bn] is defined as: dot(A, + * B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn + * @param y Second vector + */ + dot(this: MathJsChain, y: MathCollection): MathJsChain + + /** + * Compute the matrix exponential, expm(A) = e^A. The matrix must be + * square. Not to be confused with exp(a), which performs element-wise + * exponentiation. The exponential is calculated using the Padé + * approximant with scaling and squaring; see “Nineteen Dubious Ways to + * Compute the Exponential of a Matrix,” by Moler and Van Loan. + */ + + expm(this: MathJsChain): MathJsChain + + /** + * Performs a real Schur decomposition of the real matrix A = UTU' where U is orthogonal + * and T is upper quasi-triangular. + * https://en.wikipedia.org/wiki/Schur_decomposition + * @returns Object containing both matrix U and T of the Schur Decomposition A=UTU' + */ + schur(this: MathJsChain): SchurDecomposition + + /** + * Solves the Continuous-time Lyapunov equation AP+PA'=Q for P, where Q is a positive semidefinite + * matrix. + * https://en.wikipedia.org/wiki/Lyapunov_equation + * @param Q Matrix Q + * @returns Matrix P solution to the Continuous-time Lyapunov equation AP+PA'=Q + */ + lyap( + this: MathJsChain, + Q: MathCollection + ): MathJsChain + + /** + * Create a 2-dimensional identity matrix with size m x n or n x n. The + * matrix has ones on the diagonal and zeros elsewhere. + * @param format The Matrix storage format + */ + identity( + this: MathJsChain, + format?: string + ): MathJsChain + + /** + * @param n The y dimension for the matrix + * @param format The Matrix storage format + */ + identity( + this: MathJsChain, + n: number, + format?: string + ): MathJsChain + + /** + * Filter the items in an array or one dimensional matrix. + */ + filter( + this: MathJsChain, + test: + | (( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + value: any, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + index: any, + matrix: MathCollection | string[] + ) => boolean) + | RegExp + ): MathJsChain + + /** + * Flatten a multi dimensional matrix into a single dimensional matrix. + */ + + flatten(x: MathJsChain): MathJsChain + + /** + * Iterate over all elements of a matrix/array, and executes the given + * callback function. + */ + forEach( + this: MathJsChain, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + callback: (value: any, index: any, matrix: T) => void + ): void + + /** + * Calculate the inverse of a square matrix. + */ + + inv( + this: MathJsChain + ): MathJsChain> + + /** + * Calculate the kronecker product of two matrices or vectors + * @param y Second vector + */ + kron( + this: MathJsChain, + y: MathCollection + ): MathJsChain + + /** + * Iterate over all elements of a matrix/array, and executes the given + * callback function. + * @param callback The callback function is invoked with three + * parameters: the value of the element, the index of the element, and + * the Matrix/array being traversed. + */ + map( + this: MathJsChain, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + callback: (value: any, index: any, matrix: T) => MathType | string + ): MathJsChain + + /** + * Create a matrix filled with ones. The created matrix can have one or + * multiple dimensions. + * @param format The matrix storage format + */ + ones( + this: MathJsChain, + format?: string + ): MathJsChain + + /** + * Partition-based selection of an array or 1D matrix. Will find the kth + * smallest value, and mutates the input array. Uses Quickselect. + * @param k The kth smallest value to be retrieved; zero-based index + * @param compare An optional comparator function. The function is + * called as compare(a, b), and must return 1 when a > b, -1 when a < b, + * and 0 when a == b. Default value: 'asc'. + */ + partitionSelect( + this: MathJsChain, + k: number, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + compare?: 'asc' | 'desc' | ((a: any, b: any) => number) + ): MathJsChain + + /** + * Create an array from a range. By default, the range end is excluded. + * This can be customized by providing an extra parameter includeEnd. + * @param end End of the range, excluded by default, included when + * parameter includeEnd=true + * @param step Step size. Default value is 1. + * @param includeEnd: Option to specify whether to include the end or + * not. False by default + */ + range(this: MathJsChain, includeEnd?: boolean): MathJsChain + range( + this: MathJsChain, + end: number | BigNumber, + includeEnd?: boolean + ): MathJsChain + range( + this: MathJsChain, + end: number | BigNumber | Unit, + step: number | BigNumber | Unit, + includeEnd?: boolean + ): MathJsChain + + /** + * Reshape a multi dimensional array to fit the specified dimensions + * @param sizes One dimensional array with integral sizes for each + * dimension + */ + reshape( + this: MathJsChain, + sizes: number[] + ): MathJsChain + + /** + * Resize a matrix + * @param size One dimensional array with numbers + * @param defaultValue Zero by default, except in case of a string, in + * that case defaultValue = ' ' Default value: 0. + */ + resize( + this: MathJsChain, + size: MathCollection, + defaultValue?: number | string + ): MathJsChain + + /** + * Calculate the size of a matrix or scalar. + */ + size( + this: MathJsChain< + boolean | number | Complex | Unit | string | MathCollection + > + ): MathJsChain + + /** + * Sort the items in a matrix + * @param compare An optional _comparator function or name. The function + * is called as compare(a, b), and must return 1 when a > b, -1 when a < + * b, and 0 when a == b. Default value: ‘asc’ + */ + sort( + this: MathJsChain, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + compare: ((a: any, b: any) => number) | 'asc' | 'desc' | 'natural' + ): MathJsChain + + /** + * Calculate the principal square root of a square matrix. The principal + * square root matrix X of another matrix A is such that X * X = A. + */ + + sqrtm(A: MathJsChain): MathJsChain + + /** + * Squeeze a matrix, remove inner and outer singleton dimensions from a + * matrix. + */ + + squeeze(x: MathJsChain): MathJsChain + + /** + * Get or set a subset of a matrix or string. + * @param index For each dimension, an index or list of indices to get or set + * @param replacement An array, matrix, or scalar. If provided, the + * subset is replaced with replacement. If not provided, the subset is + * returned + * @param defaultValue Default value, filled in on new entries when the + * matrix is resized. If not provided, math.matrix elements will be left + * undefined. Default value: undefined. + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + subset( + this: MathJsChain, + index: Index, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + replacement?: any, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + defaultValue?: any + ): MathJsChain + + /** + * Calculate the trace of a matrix: the sum of the elements on the main + * diagonal of a square matrix. + */ + + trace(this: MathJsChain): MathJsChain + + /** + * Transpose a matrix. All values of the matrix are reflected over its + * main diagonal. Only two dimensional matrices are supported. + */ + + transpose(x: MathJsChain): MathJsChain + + /** + * Create a matrix filled with zeros. The created matrix can have one or + * multiple dimensions. + * @param format The matrix storage format + * @returns A matrix filled with zeros + */ + zeros( + this: MathJsChain, + format?: string + ): MathJsChain + + /************************************************************************* + * Probability functions + ************************************************************************/ + + /** + * Compute the number of ways of picking k unordered outcomes from n + * possibilities. Combinations only takes integer arguments. The + * following condition must be enforced: k <= n. + * @param k Number of objects in the subset + */ + combinations( + n: MathJsChain, + k: number | BigNumber + ): MathJsChain> + + /** + * Compute the factorial of a value Factorial only supports an integer + * value as argument. For matrices, the function is evaluated element + * wise. + */ + + factorial( + n: MathJsChain + ): MathJsChain> + + /** + * Compute the gamma function of a value using Lanczos approximation for + * small values, and an extended Stirling approximation for large + * values. For matrices, the function is evaluated element wise. + */ + + gamma( + n: MathJsChain + ): MathJsChain> + + /** + * Calculate the Kullback-Leibler (KL) divergence between two + * distributions + * @param p Second vector + */ + kldivergence( + this: MathJsChain, + p: MathCollection + ): MathJsChain + + /** + * Multinomial Coefficients compute the number of ways of picking a1, + * a2, ..., ai unordered outcomes from n possibilities. multinomial + * takes one array of integers as an argument. The following condition + * must be enforced: every ai <= 0 + */ + + multinomial( + a: MathJsChain + ): MathJsChain> + + /** + * Compute the number of ways of obtaining an ordered subset of k + * elements from a set of n elements. Permutations only takes integer + * arguments. The following condition must be enforced: k <= n. + * @param k The number of objects in the subset + */ + permutations( + n: MathJsChain, + k?: number | BigNumber + ): MathJsChain> + + /** + * Random pick a value from a one dimensional array. Array element is + * picked using a random function with uniform distribution. + * @param number An int or float + * @param weights An array of ints or floats + */ + pickRandom(this: MathJsChain): MathJsChain + pickRandom(this: MathJsChain, number: number): MathJsChain + pickRandom( + this: MathJsChain, + number: number, + weights: number[] + ): MathJsChain + + /** + * Return a random number larger or equal to min and smaller than max + * using a uniform distribution. + * @param min Minimum boundary for the random value, included + * @param max Maximum boundary for the random value, excluded + */ + random(this: MathJsChain, max?: number): MathJsChain + + // tslint:disable-next-line unified-signatures + random( + this: MathJsChain, + min?: number, + max?: number + ): MathJsChain + + /** + * Return a random integer number larger or equal to min and smaller + * than max using a uniform distribution. + * @param min Minimum boundary for the random value, included + * @param max Maximum boundary for the random value, excluded + */ + randomInt( + this: MathJsChain, + max?: number + ): MathJsChain + randomInt( + this: MathJsChain, + max?: number + ): MathJsChain + // tslint:disable-next-line unified-signatures + randomInt( + this: MathJsChain, + min: number, + max: number + ): MathJsChain + + /************************************************************************* + * Relational functions + ************************************************************************/ + + /** + * Compare two values. Returns 1 when x > y, -1 when x < y, and 0 when x + * == y. x and y are considered equal when the relative difference + * between x and y is smaller than the configured epsilon. The function + * cannot be used to compare values smaller than approximately 2.22e-16. + * For matrices, the function is evaluated element wise. + * @param y Second value to compare + */ + compare( + this: MathJsChain, + y: MathType | string + ): MathJsChain + + /** + * Compare two values of any type in a deterministic, natural way. For + * numeric values, the function works the same as math.compare. For + * types of values that can’t be compared mathematically, the function + * compares in a natural way. + * @param y Second value to compare + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + compareNatural(this: MathJsChain, y: any): MathJsChain + + /** + * Compare two strings lexically. Comparison is case sensitive. Returns + * 1 when x > y, -1 when x < y, and 0 when x == y. For matrices, the + * function is evaluated element wise. + * @param y Second string to compare + */ + compareText( + this: MathJsChain, + y: string | MathCollection + ): MathJsChain + + /** + * Test element wise whether two matrices are equal. The function + * accepts both matrices and scalar values. + * @param y Second amtrix to compare + */ + deepEqual(this: MathJsChain, y: MathType): MathJsChain + + /** + * Test whether two values are equal. + * + * The function tests whether the relative difference between x and y is + * smaller than the configured epsilon. The function cannot be used to + * compare values smaller than approximately 2.22e-16. For matrices, the + * function is evaluated element wise. In case of complex numbers, x.re + * must equal y.re, and x.im must equal y.im. Values null and undefined + * are compared strictly, thus null is only equal to null and nothing + * else, and undefined is only equal to undefined and nothing else. + * @param y Second value to compare + */ + equal( + this: MathJsChain, + y: MathType | string + ): MathJsChain + + /** + * Check equality of two strings. Comparison is case sensitive. For + * matrices, the function is evaluated element wise. + * @param y Second string to compare + */ + equalText( + this: MathJsChain, + y: string | MathCollection + ): MathJsChain + + /** + * Test whether value x is larger than y. The function returns true when + * x is larger than y and the relative difference between x and y is + * larger than the configured epsilon. The function cannot be used to + * compare values smaller than approximately 2.22e-16. For matrices, the + * function is evaluated element wise. + * @param y Second value to compare + */ + larger( + this: MathJsChain, + y: MathType | string + ): MathJsChain + + /** + * Test whether value x is larger or equal to y. The function returns + * true when x is larger than y or the relative difference between x and + * y is smaller than the configured epsilon. The function cannot be used + * to compare values smaller than approximately 2.22e-16. For matrices, + * the function is evaluated element wise. + * @param y Second value to vcompare + */ + largerEq( + this: MathJsChain, + y: MathType | string + ): MathJsChain + + /** + * Test whether value x is smaller than y. The function returns true + * when x is smaller than y and the relative difference between x and y + * is smaller than the configured epsilon. The function cannot be used + * to compare values smaller than approximately 2.22e-16. For matrices, + * the function is evaluated element wise. + * @param y Second value to vcompare + */ + smaller( + this: MathJsChain, + y: MathType | string + ): MathJsChain + + /** + * Test whether value x is smaller or equal to y. The function returns + * true when x is smaller than y or the relative difference between x + * and y is smaller than the configured epsilon. The function cannot be + * used to compare values smaller than approximately 2.22e-16. For + * matrices, the function is evaluated element wise. + * @param y Second value to compare + */ + smallerEq( + this: MathJsChain, + y: MathType | string + ): MathJsChain + + /** + * Test whether two values are unequal. The function tests whether the + * relative difference between x and y is larger than the configured + * epsilon. The function cannot be used to compare values smaller than + * approximately 2.22e-16. For matrices, the function is evaluated + * element wise. In case of complex numbers, x.re must unequal y.re, or + * x.im must unequal y.im. Values null and undefined are compared + * strictly, thus null is unequal with everything except null, and + * undefined is unequal with everything except undefined. + * @param y Second value to vcompare + */ + unequal( + this: MathJsChain, + y: MathType | string + ): MathJsChain + + /************************************************************************* + * Set functions + ************************************************************************/ + + /** + * Create the cartesian product of two (multi)sets. Multi-dimension + * arrays will be converted to single-dimension arrays and the values + * will be sorted in ascending order before the operation. + * @param a2 A (multi)set + */ + setCartesian( + this: MathJsChain, + a2: MathCollection + ): MathJsChain + + /** + * Create the difference of two (multi)sets: every element of set1, that + * is not the element of set2. Multi-dimension arrays will be converted + * to single-dimension arrays before the operation + * @param a2 A (multi)set + */ + setDifference( + this: MathJsChain, + a2: MathCollection + ): MathJsChain + + /** + * Collect the distinct elements of a multiset. A multi-dimension array + * will be converted to a single-dimension array before the operation. + */ + + setDistinct(a: MathJsChain): MathJsChain + + /** + * Create the intersection of two (multi)sets. Multi-dimension arrays + * will be converted to single-dimension arrays before the operation. + * @param a2 A (multi)set + */ + setIntersect( + this: MathJsChain, + a2: MathCollection + ): MathJsChain + + /** + * Check whether a (multi)set is a subset of another (multi)set. (Every + * element of set1 is the element of set2.) Multi-dimension arrays will + * be converted to single-dimension arrays before the operation. + * @param a2 A (multi)set + */ + setIsSubset( + this: MathJsChain, + a2: MathCollection + ): MathJsChain + + /** + * Count the multiplicity of an element in a multiset. A multi-dimension + * array will be converted to a single-dimension array before the + * operation. + * @param a A multiset + */ + setMultiplicity( + e: MathJsChain, + a: MathCollection + ): MathJsChain + + /** + * Create the powerset of a (multi)set. (The powerset contains very + * possible subsets of a (multi)set.) A multi-dimension array will be + * converted to a single-dimension array before the operation. + */ + + setPowerset(a: MathJsChain): MathJsChain + + /** + * Count the number of elements of a (multi)set. When a second parameter + * is ‘true’, count only the unique values. A multi-dimension array will + * be converted to a single-dimension array before the operation. + */ + + setSize(this: MathJsChain): MathJsChain + + /** + * Create the symmetric difference of two (multi)sets. Multi-dimension + * arrays will be converted to single-dimension arrays before the + * operation. + * @param a2 A (multi)set + */ + setSymDifference( + this: MathJsChain, + a2: MathCollection + ): MathJsChain + + /** + * Create the union of two (multi)sets. Multi-dimension arrays will be + * converted to single-dimension arrays before the operation. + * @param a2 A (multi)set + */ + setUnion( + this: MathJsChain, + a2: MathCollection + ): MathJsChain + + /************************************************************************* + * Signal functions + ************************************************************************/ + /** + * Compute the transfer function of a zero-pole-gain model. + */ + zpk2tf( + this: MathJsChain, // chained variable will be used as z + p: T, + k?: number + ): MathJsChain + + /** + * Calculates the frequency response of a filter given its numerator and denominator coefficients. + */ + freqz( + this: MathJsChain, + a: T, + w?: T | number + ): MathJsChain<{ w: T; h: T }> - interface FunctionNode< - TFn = SymbolNode, - TArgs extends MathNode[] = MathNode[] - > extends MathNode { - type: 'FunctionNode' - isFunctionNode: true - fn: TFn - args: TArgs - } - interface FunctionNodeCtor { - new ( - fn: TFn, - args: TArgs - ): FunctionNode - // eslint-disable-next-line @typescript-eslint/no-explicit-any - onUndefinedFunction: (name: string) => any - } + /************************************************************************* + * Special functions + ************************************************************************/ - interface IndexNode extends MathNode { - type: 'IndexNode' - isIndexNode: true - dimensions: TDims - dotNotation: boolean - } - interface IndexNodeCtor { - new (dimensions: TDims): IndexNode - new ( - dimensions: TDims, - dotNotation: boolean - ): IndexNode - } + /** + * Compute the erf function of a value using a rational Chebyshev + * approximations for different intervals of x. + */ + erf( + this: MathJsChain + ): MathJsChain> - interface ObjectNode< - TProps extends Record = Record - > extends MathNode { - type: 'ObjectNode' - isObjectNode: true - properties: TProps - } - interface ObjectNodeCtor { - new = Record>( - properties: TProps - ): ObjectNode - } + /** + * Compute the Riemann Zeta function of a value using an infinite series + * and Riemann's Functional equation. + */ + zeta( + this: MathJsChain + ): MathJsChain - type OperatorNodeMap = { - xor: 'xor' - and: 'and' - or: 'or' - bitOr: '|' - bitXor: '^|' - bitAnd: '&' - equal: '==' - unequal: '!=' - smaller: '<' - larger: '>' - smallerEq: '<=' - largerEq: '>=' - leftShift: '<<' - rightArithShift: '>>' - rightLogShift: '>>>' - to: 'to' - add: '+' - subtract: '-' - multiply: '*' - divide: '/' - dotMultiply: '.*' - dotDivide: './' - mod: 'mod' - unaryPlus: '+' - unaryMinus: '-' - bitNot: '~' - not: 'not' - pow: '^' - dotPow: '.^' - factorial: '!' - } + /************************************************************************* + * Statistics functions + ************************************************************************/ - type OperatorNodeOp = OperatorNodeMap[keyof OperatorNodeMap] - type OperatorNodeFn = keyof OperatorNodeMap - - interface OperatorNode< - TOp extends OperatorNodeMap[TFn] = never, - TFn extends OperatorNodeFn = never, - TArgs extends MathNode[] = MathNode[] - > extends MathNode { - type: 'OperatorNode' - isOperatorNode: true - op: TOp - fn: TFn - args: TArgs - implicit: boolean - isUnary(): boolean - isBinary(): boolean - } + /** + * Compute the median absolute deviation of a matrix or a list with + * values. The median absolute deviation is defined as the median of the + * absolute deviations from the median. + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + mad(this: MathJsChain): MathJsChain - interface OperatorNodeCtor extends MathNode { - new < - TOp extends OperatorNodeMap[TFn], - TFn extends OperatorNodeFn, - TArgs extends MathNode[] - >( - op: TOp, - fn: TFn, - args: TArgs, - implicit?: boolean - ): OperatorNode - } - interface ParenthesisNode - extends MathNode { - type: 'ParenthesisNode' - isParenthesisNode: true - content: TContent - } - interface ParenthesisNodeCtor { - new ( - content: TContent - ): ParenthesisNode - } + /** + * Compute the maximum value of a matrix or a list with values. In case + * of a multi dimensional array, the maximum of the flattened array will + * be calculated. When dim is provided, the maximum over the selected + * dimension will be calculated. Parameter dim is zero-based. + * @param dim The maximum over the selected dimension + */ - interface RangeNode< - TStart extends MathNode = MathNode, - TEnd extends MathNode = MathNode, - TStep extends MathNode = MathNode - > extends MathNode { - type: 'RangeNode' - isRangeNode: true - start: TStart - end: TEnd - step: TStep | null - } - interface RangeNodeCtor { - new < - TStart extends MathNode = MathNode, - TEnd extends MathNode = MathNode, - TStep extends MathNode = MathNode - >( - start: TStart, - end: TEnd, - step?: TStep - ): RangeNode - } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + max(this: MathJsChain, dim?: number): MathJsChain + // eslint-disable-next-line @typescript-eslint/no-explicit-any + max(this: MathJsChain, dim?: number): MathJsChain - interface RelationalNode - extends MathNode { - type: 'RelationalNode' - isRelationalNode: true - conditionals: string[] - params: TParams - } - interface RelationalNodeCtor { - new ( - conditionals: string[], - params: TParams - ): RelationalNode - } + /** + * Compute the mean value of matrix or a list with values. In case of a + * multi dimensional array, the mean of the flattened array will be + * calculated. When dim is provided, the maximum over the selected + * dimension will be calculated. Parameter dim is zero-based. + * @param dim The mean over the selected dimension + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + mean(this: MathJsChain, dim?: number): MathJsChain + // eslint-disable-next-line @typescript-eslint/no-explicit-any + mean(this: MathJsChain, dim?: number): MathJsChain - interface SymbolNode extends MathNode { - type: 'SymbolNode' - isSymbolNode: true - name: string - } - interface SymbolNodeCtor { - new (name: string): SymbolNode - // eslint-disable-next-line @typescript-eslint/no-explicit-any - onUndefinedSymbol: (name: string) => any - } + /** + * Compute the median of a matrix or a list with values. The values are + * sorted and the middle value is returned. In case of an even number of + * values, the average of the two middle values is returned. Supported + * types of values are: Number, BigNumber, Unit In case of a (multi + * dimensional) array or matrix, the median of all elements will be + * calculated. + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + median(this: MathJsChain, dim?: number): MathJsChain + // eslint-disable-next-line @typescript-eslint/no-explicit-any + median(this: MathJsChain, dim?: number): MathJsChain /** - * @deprecated since version 11.3. Prefer `MathNode` instead + * Compute the minimum value of a matrix or a list of values. In case of + * a multi dimensional array, the minimum of the flattened array will be + * calculated. When dim is provided, the minimum over the selected + * dimension will be calculated. Parameter dim is zero-based. + * @param dim The minimum over the selected dimension */ - type MathNodeCommon = MathNode + // eslint-disable-next-line @typescript-eslint/no-explicit-any + min(this: MathJsChain): MathJsChain + // eslint-disable-next-line @typescript-eslint/no-explicit-any + min(this: MathJsChain, dim?: number): MathJsChain - type MathJsFunctionName = keyof MathJsStatic + /** + * Computes the mode of a set of numbers or a list with values(numbers + * or characters). If there are more than one modes, it returns a list + * of those values. + */ - interface LUDecomposition { - L: MathCollection - U: MathCollection - p: number[] - } + mode(this: MathJsChain): MathJsChain - interface SLUDecomposition extends LUDecomposition { - q: number[] - } + /** + * Compute the product of a matrix or a list with values. In case of a + * (multi dimensional) array or matrix, the sum of all elements will be + * calculated. + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + prod(this: MathJsChain): MathJsChain - interface QRDecomposition { - Q: MathCollection - R: MathCollection - } + /** + * Compute the prob order quantile of a matrix or a list with values. + * The sequence is sorted and the middle value is returned. Supported + * types of sequence values are: Number, BigNumber, Unit Supported types + * of probability are: Number, BigNumber In case of a (multi + * dimensional) array or matrix, the prob order quantile of all elements + * will be calculated. + * @param probOrN prob is the order of the quantile, while N is the + * amount of evenly distributed steps of probabilities; only one of + * these options can be provided + * @param sorted =false is data sorted in ascending order + */ + quantileSeq( + A: MathJsChain, + prob: number | BigNumber | MathArray, + sorted?: boolean + ): MathJsChain - interface SchurDecomposition { - U: MathCollection - T: MathCollection - } + /** + * Compute the standard deviation of a matrix or a list with values. The + * standard deviations is defined as the square root of the variance: + * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or + * matrix, the standard deviation over all elements will be calculated. + * Optionally, the type of normalization can be specified as second + * parameter. The parameter normalization can be one of the following + * values: 'unbiased' (default) The sum of squared errors is divided by + * (n - 1) 'uncorrected' The sum of squared errors is divided by n + * 'biased' The sum of squared errors is divided by (n + 1) + * @param dim A dimension to compute standard deviation. + * @param normalization Determines how to normalize the variance. Choose + * ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: + * ‘unbiased’. + * @returns The standard deviation + */ + std( + this: MathJsChain, + dim?: number, + normalization?: 'unbiased' | 'uncorrected' | 'biased' + ): MathJsChain - interface FractionDefinition { - a: number - b: number - } + /** + * Compute the standard deviation of a matrix or a list with values. The + * standard deviations is defined as the square root of the variance: + * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or + * matrix, the standard deviation over all elements will be calculated. + * Optionally, the type of normalization can be specified as second + * parameter. The parameter normalization can be one of the following + * values: 'unbiased' (default) The sum of squared errors is divided by + * (n - 1) 'uncorrected' The sum of squared errors is divided by n + * 'biased' The sum of squared errors is divided by (n + 1) + * @param normalization Determines how to normalize the variance. Choose + * ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: + * ‘unbiased’. + * @returns The standard deviation + */ + std( + this: MathJsChain, + dimension?: number, + normalization?: 'unbiased' | 'uncorrected' | 'biased' + ): MathJsChain - interface MathJsStatic extends FactoryDependencies { - e: number - pi: number - i: number - Infinity: number - LN2: number - LN10: number - LOG2E: number - LOG10E: number - NaN: number - phi: number - SQRT1_2: number - SQRT2: number - tau: number - - // Class-like constructors - Node: NodeCtor - AccessorNode: AccessorNodeCtor - ArrayNode: ArrayNodeCtor - AssignmentNode: AssignmentNodeCtor - BlockNode: BlockNodeCtor - ConditionalNode: ConditionalNodeCtor - ConstantNode: ConstantNodeCtor - FunctionAssignmentNode: FunctionAssignmentNodeCtor - FunctionNode: FunctionNodeCtor - IndexNode: IndexNodeCtor - ObjectNode: ObjectNodeCtor - OperatorNode: OperatorNodeCtor - ParenthesisNode: ParenthesisNodeCtor - RangeNode: RangeNodeCtor - RelationalNode: RelationalNodeCtor - SymbolNode: SymbolNodeCtor - - Matrix: MatrixCtor - - /** - * If null were to be included in this interface, it would be - * auto-suggested as an import in VSCode. This causes issues because - * `null` is not a valid label. - * - * @see https://github.com/josdejong/mathjs/issues/2019 - */ - // null: number; + /** + * Compute the sum of a matrix or a list with values. In case of a + * (multi dimensional) array or matrix, the sum of all elements will be + * calculated. + */ + std( + this: MathJsChain, + normalization: 'unbiased' | 'uncorrected' | 'biased' + ): MathJsChain - // eslint-disable-next-line @typescript-eslint/no-explicit-any - uninitialized: any - version: string + /** + * Compute the variance of a matrix or a list with values. In case of a + * (multi dimensional) array or matrix, the variance over all elements + * will be calculated. Optionally, the type of normalization can be + * specified as second parameter. The parameter normalization can be one + * of the following values: 'unbiased' (default) The sum of squared + * errors is divided by (n - 1) 'uncorrected' The sum of squared errors + * is divided by n 'biased' The sum of squared errors is divided by (n + + * 1) Note that older browser may not like the variable name var. In + * that case, the function can be called as math['var'](...) instead of + * math.variance(...). + * @param dim a dimension to compute variance. + * @param normalization normalization Determines how to normalize the + * variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. + * Default value: ‘unbiased’. + * @returns The variance + */ + variance( + this: MathJsChain>> + ): MathJsChain - expression: MathNode + /** + * Compute the variance of a matrix or a list with values. In case of a + * (multi dimensional) array or matrix, the variance over all elements + * will be calculated. Optionally, the type of normalization can be + * specified as second parameter. The parameter normalization can be one + * of the following values: 'unbiased' (default) The sum of squared + * errors is divided by (n - 1) 'uncorrected' The sum of squared errors + * is divided by n 'biased' The sum of squared errors is divided by (n + + * 1) Note that older browser may not like the variable name var. In + * that case, the function can be called as math['var'](...) instead of + * math.variance(...). + * @param normalization normalization Determines how to normalize the + * variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. + * Default value: ‘unbiased’. + * @returns The variance + */ + variance( + this: MathJsChain, + dimension?: number, + normalization?: 'unbiased' | 'uncorrected' | 'biased' + ): MathJsChain - /** - * Returns reviver function that can be used as reviver in JSON.parse function. - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - reviver(): (key: any, value: any) => any + variance( + this: MathJsChain, + normalization: 'unbiased' | 'uncorrected' | 'biased' + ): MathJsChain - /** - * Returns replacer function that can be used as replacer in JSON.stringify function. - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - replacer(): (key: any, value: any) => any - - /************************************************************************* - * Core functions - ************************************************************************/ - - /** - * Set configuration options for math.js, and get current options. Will - * emit a ‘config’ event, with arguments (curr, prev, changes). - * @param options Available options: {number} epsilon Minimum relative - * difference between two compared values, used by all comparison - * functions. {string} matrix A string ‘Matrix’ (default) or ‘Array’. - * {string} number A string ‘number’ (default), ‘BigNumber’, or - * ‘Fraction’ {number} precision The number of significant digits for - * BigNumbers. Not applicable for Numbers. {string} parenthesis How to - * display parentheses in LaTeX and string output. {string} randomSeed - * Random seed for seeded pseudo random number generator. Set to null to - * randomly seed. - * @returns Returns the current configuration - */ - config: (options: ConfigOptions) => ConfigOptions - /** - * Create a typed-function which checks the types of the arguments and - * can match them against multiple provided signatures. The - * typed-function automatically converts inputs in order to find a - * matching signature. Typed functions throw informative errors in case - * of wrong input arguments. - * @param name Optional name for the typed-function - * @param signatures Object with one or multiple function signatures - * @returns The created typed-function. - */ - typed: ( - name: string, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - signatures: Record any> - // eslint-disable-next-line @typescript-eslint/no-explicit-any - ) => (...args: any[]) => any - - /************************************************************************* - * Construction functions - ************************************************************************/ - - /** - * Create a BigNumber, which can store numbers with arbitrary precision. - * When a matrix is provided, all elements will be converted to - * BigNumber. - * @param x Value for the big number, 0 by default. - * @returns The created bignumber - */ - bignumber( - x?: number | string | Fraction | BigNumber | Unit | boolean | null - ): BigNumber - bignumber(x: T): T - - /** - * Create a boolean or convert a string or number to a boolean. In case - * of a number, true is returned for non-zero numbers, and false in case - * of zero. Strings can be 'true' or 'false', or can contain a number. - * When value is a matrix, all elements will be converted to boolean. - * @param x A value of any type - * @returns The boolean value - */ - boolean(x: string | number | boolean | null): boolean - boolean(x: MathCollection): MathCollection - - /** - * Wrap any value in a chain, allowing to perform chained operations on - * the value. All methods available in the math.js library can be called - * upon the chain, and then will be evaluated with the value itself as - * first argument. The chain can be closed by executing chain.done(), - * which returns the final value. The chain has a number of special - * functions: done() Finalize the chain and return the chain's value. - * valueOf() The same as done() toString() Executes math.format() onto - * the chain's value, returning a string representation of the value. - * @param value A value of any type on which to start a chained - * operation. - * @returns The created chain - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - chain(value?: TValue): MathJsChain - - /** - * Create a complex value or convert a value to a complex value. - * @param args Arguments specifying the real and imaginary part of the - * complex number - * @returns Returns a complex value - */ - complex(arg?: MathNumericType | string | PolarCoordinates): Complex - complex(arg?: MathCollection): MathCollection - /** - * @param re Argument specifying the real part of the complex number - * @param im Argument specifying the imaginary part of the complex - * number - * @returns Returns a complex value - */ - complex(re: number, im: number): Complex - - /** - * Create a user-defined unit and register it with the Unit type. - * @param name The name of the new unit. Must be unique. Example: ‘knot’ - * @param definition Definition of the unit in terms of existing units. - * For example, ‘0.514444444 m / s’. - * @param options (optional) An object containing any of the following - * properties:
- prefixes {string} “none”, “short”, “long”, - * “binary_short”, or “binary_long”. The default is “none”.
- - * aliases {Array} Array of strings. Example: [‘knots’, ‘kt’, - * ‘kts’]
- offset {Numeric} An offset to apply when converting from - * the unit. For example, the offset for celsius is 273.15. Default is - * 0. - * @returns The new unit - */ - createUnit( - name: string, - definition?: string | UnitDefinition | Unit, - options?: CreateUnitOptions - ): Unit - /** - * Create a user-defined unit and register it with the Unit type. - * @param units Definition of the unit - * @param options - * @returns The new unit - */ - createUnit( - units: Record, - options?: CreateUnitOptions - ): Unit - - /** - * Create a fraction convert a value to a fraction. - * @param value Arguments specifying the numerator and denominator of the - * fraction - * @returns Returns a fraction - */ - fraction( - value: number | string | BigNumber | Unit | Fraction | FractionDefinition - ): Fraction - fraction(values: MathCollection): MathCollection - /** - * @param numerator Argument specifying the numerator of the fraction - * @param denominator Argument specifying the denominator of the - * fraction - * @returns Returns a fraction - */ - fraction(numerator: number, denominator: number): Fraction - - /** - * Create an index. An Index can store ranges having start, step, and - * end for multiple dimensions. Matrix.get, Matrix.set, and math.subset - * accept an Index as input. - * @param ranges Zero or more ranges or numbers. - * @returns Returns the created index - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - index(...ranges: any[]): Index - - /** - * Create a Matrix. The function creates a new math.type.Matrix object - * from an Array. A Matrix has utility functions to manipulate the data - * in the matrix, like getting the size and getting or setting values in - * the matrix. Supported storage formats are 'dense' and 'sparse'. - * @param format The Matrix storage format - * @returns The created Matrix - */ - matrix(format?: 'sparse' | 'dense'): Matrix - /** - * @param data A multi dimensional array - * @param format The Matrix storage format - * @param dataType The Matrix data type - * @returns The created Matrix - */ - matrix( - data: MathCollection | string[], - format?: 'sparse' | 'dense', - dataType?: string - ): Matrix - - /** - * Create a number or convert a string, boolean, or unit to a number. - * When value is a matrix, all elements will be converted to number. - * @param value Value to be converted - * @returns The created number - */ - number( - value?: string | number | BigNumber | Fraction | boolean | Unit | null - ): number - number(value?: MathCollection): number | MathCollection - /** - * @param value Value to be converted - * @param valuelessUnit A valueless unit, used to convert a unit to a - * number - * @returns The created number - */ - number(unit: Unit, valuelessUnit: Unit | string): number - - /** - * Create a Sparse Matrix. The function creates a new math.type.Matrix - * object from an Array. A Matrix has utility functions to manipulate - * the data in the matrix, like getting the size and getting or setting - * values in the matrix. - * @param data A two dimensional array - * @param dataType Sparse Matrix data type - * @returns The created matrix - */ - sparse(data?: MathCollection, dataType?: string): Matrix - - /** - * Split a unit in an array of units whose sum is equal to the original - * unit. - * @param unit A unit to be split - * @param parts An array of strings or valueless units - * @returns An array of units - */ - splitUnit(unit: Unit, parts: Unit[]): Unit[] - - /** - * Create a string or convert any object into a string. Elements of - * Arrays and Matrices are processed element wise. - * @param value A value to convert to a string - * @returns The created string - */ - string(value: MathNumericType | string | Unit | null): string - string(value: MathCollection): MathCollection - - /** - * Create a unit. Depending on the passed arguments, the function will - * create and return a new math.type.Unit object. When a matrix is - * provided, all elements will be converted to units. - * @param unit The unit to be created - * @returns The created unit - */ - unit(unit: string): Unit - /** - * @param unit The unit to be created - * @returns The created unit - */ - unit(unit: Unit): Unit - /** - * @param value The value of the unit to be created - * @param unit The unit to be created - * @returns The created unit - */ - unit(value: MathNumericType, unit: string): Unit - unit(value: MathCollection, unit: string): Unit[] - - /************************************************************************* - * Expression functions - ************************************************************************/ - - /** - * Parse and compile an expression. Returns a an object with a function - * evaluate([scope]) to evaluate the compiled expression. - * @param expr The expression to be compiled - * @returns An object with the compiled expression - */ - compile(expr: MathExpression): EvalFunction - /** - * @param exprs The expressions to be compiled - * @returns An array of objects with the compiled expressions - */ - compile(exprs: MathExpression[]): EvalFunction[] - - // TODO properly type this - /** - * Evaluate an expression. - * @param expr The expression to be evaluated - * @param scope Scope to read/write variables - * @returns The result of the expression - */ - evaluate( - expr: MathExpression | Matrix, - scope?: object - // eslint-disable-next-line @typescript-eslint/no-explicit-any - ): any - evaluate( - expr: MathExpression[], - scope?: object - // eslint-disable-next-line @typescript-eslint/no-explicit-any - ): any[] - - /** - * Retrieve help on a function or data type. Help files are retrieved - * from the documentation in math.expression.docs. - * @param search A function or function name for which to get help - * @returns A help object - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - help(search: () => any): Help - - /** - * Parse an expression. Returns a node tree, which can be evaluated by - * invoking node.evaluate(); - */ - parse: ParseFunction - - /** - * Create a parser. The function creates a new math.expression.Parser - * object. - * @returns A Parser object - */ - parser(): Parser - - /************************************************************************* - * Algebra functions - ************************************************************************/ - /** - * @param expr The expression to differentiate - * @param variable The variable over which to differentiate - * @param options There is one option available, simplify, which is true - * by default. When false, output will not be simplified. - * @returns The derivative of expr - */ - derivative( - expr: MathNode | string, - variable: MathNode | string, - options?: { simplify: boolean } - ): MathNode - - /** - * Solves the linear equation system by forwards substitution. Matrix - * must be a lower triangular matrix. - * @param L A N x N matrix or array (L) - * @param b A column vector with the b values - * @returns A column vector with the linear system solution (x) - */ - lsolve(L: Matrix, b: MathCollection): Matrix - lsolve(L: MathArray, b: MathCollection): MathArray - - /** - * Calculate the Matrix LU decomposition with partial pivoting. Matrix A - * is decomposed in two matrices (L, U) and a row permutation vector p - * where A[p,:] = L * U - * @param A A two dimensional matrix or array for which to get the LUP - * decomposition. - * @returns The lower triangular matrix, the upper triangular matrix and - * the permutation matrix. - */ - lup(A?: MathCollection): LUDecomposition - - /** - * Solves the linear system A * x = b where A is an [n x n] matrix and b - * is a [n] column vector. - * @param A Invertible Matrix or the Matrix LU decomposition - * @param b Column Vector - * @param order The Symbolic Ordering and Analysis order, see slu for - * details. Matrix must be a SparseMatrix - * @param threshold Partial pivoting threshold (1 for partial pivoting), - * see slu for details. Matrix must be a SparseMatrix. - * @returns Column vector with the solution to the linear system A * x = - * b - */ - lusolve( - A: Matrix, - b: MathCollection, - order?: number, - threshold?: number - ): Matrix - - lusolve( - A: MathArray, - b: MathCollection, - order?: number, - threshold?: number - ): MathArray - - lusolve(A: LUDecomposition, b: MathCollection): Matrix - - /* Finds the roots of a polynomial of degree three or less. Coefficients are given constant first - * followed by linear and higher powers in order; coefficients beyond the degree of the polynomial - * need not be specified. - * @param {number|Complex} constantCoeff - * @param {number|Complex} linearCoeff - * @param {number|Complex} quadraticCoeff - * @param {number|Complex} cubicCoeff - * @returns {Array} array of roots of specified polynomial - */ - polynomialRoot( - constantCoeff: number | Complex, - linearCoeff: number | Complex, - quadraticCoeff?: number | Complex, - cubicCoeff?: number | Complex - ): (number | Complex)[] - - /** - * Calculate the Matrix QR decomposition. Matrix A is decomposed in two - * matrices (Q, R) where Q is an orthogonal matrix and R is an upper - * triangular matrix. - * @param A A two dimensional matrix or array for which to get the QR - * decomposition. - * @returns Q: the orthogonal matrix and R: the upper triangular matrix - */ - qr(A: MathCollection): QRDecomposition - - rationalize( - expr: MathNode | string, - optional?: object | boolean, - detailed?: false - ): MathNode - /** - * Transform a rationalizable expression in a rational fraction. If - * rational fraction is one variable polynomial then converts the - * numerator and denominator in canonical form, with decreasing - * exponents, returning the coefficients of numerator. - * @param expr The expression to check if is a polynomial expression - * @param optional scope of expression or true for already evaluated - * rational expression at input - * @param detailed optional True if return an object, false if return - * expression node (default) - * @returns The rational polynomial of expr - */ - rationalize( - expr: MathNode | string, - optional?: object | boolean, - detailed?: true - ): { - expression: MathNode | string - variables: string[] - coefficients: MathType[] - } + /************************************************************************* + * String functions + ************************************************************************/ - /** - * Simplify an expression tree. - * @param expr The expression to be simplified - * @param [rules] (optional) A list of rules are applied to an expression, repeating - * over the list until no further changes are made. It’s possible to - * pass a custom set of rules to the function as second argument. A rule - * can be specified as an object, string, or function. - * @param [scope] (optional) Scope to variables - * @param [options] (optional) An object with simplify options - * @returns Returns the simplified form of expr - */ - simplify: Simplify - - simplifyConstant( - expr: MathNode | string, - options?: SimplifyOptions - ): MathNode - simplifyCore(expr: MathNode | string, options?: SimplifyOptions): MathNode - - /** - * Replaces variable nodes with their scoped values - * @param node Tree to replace variable nodes in - * @param scope Scope to read/write variables - */ + /** + * Format a value of any type into a string. + * @param options An object with formatting options. + * @param callback A custom formatting function, invoked for all numeric + * elements in value, for example all elements of a matrix, or the real + * and imaginary parts of a complex number. This callback can be used to + * override the built-in numeric notation with any type of formatting. + * Function callback is called with value as parameter and must return a + * string. + * @see http://mathjs.org/docs/reference/functions/format.html + */ + format( // eslint-disable-next-line @typescript-eslint/no-explicit-any - resolve(node: MathNode | string, scope?: Record): MathNode - resolve( - node: (MathNode | string)[], - // eslint-disable-next-line @typescript-eslint/no-explicit-any - scope?: Record - ): MathNode[] + this: MathJsChain, // eslint-disable-next-line @typescript-eslint/no-explicit-any - resolve(node: Matrix, scope?: Record): Matrix - - /** - * Calculate the Sparse Matrix LU decomposition with full pivoting. - * Sparse Matrix A is decomposed in two matrices (L, U) and two - * permutation vectors (pinv, q) where P * A * Q = L * U - * @param A A two dimensional sparse matrix for which to get the LU - * decomposition. - * @param order The Symbolic Ordering and Analysis order: 0 - Natural - * ordering, no permutation vector q is returned 1 - Matrix must be - * square, symbolic ordering and analisis is performed on M = A + A' 2 - - * Symbolic ordering and analysis is performed on M = A' * A. Dense - * columns from A' are dropped, A recreated from A'. This is appropriate - * for LU factorization of non-symmetric matrices. 3 - Symbolic ordering - * and analysis is performed on M = A' * A. This is best used for LU - * factorization is matrix M has no dense rows. A dense row is a row - * with more than 10*sqr(columns) entries. - * @param threshold Partial pivoting threshold (1 for partial pivoting) - * @returns The lower triangular matrix, the upper triangular matrix and - * the permutation vectors. - */ - slu(A: Matrix, order: number, threshold: number): SLUDecomposition - - /** - * Solves the linear equation system by backward substitution. Matrix - * must be an upper triangular matrix. U * x = b - * @param U A N x N matrix or array (U) - * @param b A column vector with the b values - * @returns A column vector with the linear system solution (x) - */ - usolve(U: Matrix, b: MathCollection): Matrix - usolve(U: MathArray, b: MathCollection): MathArray - - /************************************************************************* - * Arithmetic functions - ************************************************************************/ - - /** - * Calculate the absolute value of a number. For matrices, the function - * is evaluated element wise. - * @param x A number or matrix for which to get the absolute value - * @returns Absolute value of x - */ - abs(x: T): T - - /** - * Add two values, x + y. For matrices, the function is evaluated - * element wise. - * @param x First value to add - * @param y Second value to add - * @returns Sum of x and y - */ - add(x: T, y: T): T - add(x: MathType, y: MathType): MathType - - /** - * Calculate the cubic root of a value. - * @param x Value for which to calculate the cubic root. - * @param allRoots Optional, false by default. Only applicable when x is - * a number or complex number. If true, all complex roots are returned, - * if false (default) the principal root is returned. - * @returns Returns the cubic root of x - */ - cbrt(x: Complex, allRoots?: boolean): Complex - cbrt(x: T): T - - // Rounding functions, grouped for similarity, even though it breaks - // the alphabetic order among arithmetic functions. - - /** - * Round a value towards plus infinity If x is complex, both real and - * imaginary part are rounded towards plus infinity. For matrices, the - * function is evaluated element wise. - * @param x Number to be rounded - * @param n Number of decimals Default value: 0. - * @returns Rounded value - */ - ceil( - x: T, - n?: number | BigNumber - ): NoLiteralType - ceil(x: MathNumericType, n: U): U - - /** - * Round a value towards zero. For matrices, the function is evaluated - * element wise. - * @param x Number to be rounded - * @param n Number of decimals Default value: 0. - * @returns Rounded value - */ - fix( - x: T, - n?: number | BigNumber - ): NoLiteralType - fix(x: MathNumericType, n: U): U - - /** - * Round a value towards minus infinity. For matrices, the function is - * evaluated element wise. - * @param x Number to be rounded - * @param n Number of decimals Default value: 0. - * @returns Rounded value - */ - floor( - x: T, - n?: number | BigNumber - ): NoLiteralType - floor(x: MathNumericType, n: U): U - - /** - * Round a value towards the nearest integer. For matrices, the function - * is evaluated element wise. - * @param x Number to be rounded - * @param n Number of decimals Default value: 0. - * @returns Rounded value of x - */ - round( - x: T, - n?: number | BigNumber - ): NoLiteralType - round(x: MathNumericType, n: U): U - - // End of group of rounding functions - - /** - * Compute the cube of a value, x * x * x. For matrices, the function is - * evaluated element wise. - * @param x Number for which to calculate the cube - * @returns Cube of x - */ - cube(x: T): T - - /** - * Divide two values, x / y. To divide matrices, x is multiplied with - * the inverse of y: x * inv(y). - * @param x Numerator - * @param y Denominator - * @returns Quotient, x / y - */ - divide(x: Unit, y: Unit): Unit | number - divide(x: Unit, y: number): Unit - divide(x: number, y: number): number - divide(x: MathType, y: MathType): MathType - - /** - * Divide two matrices element wise. The function accepts both matrices - * and scalar values. - * @param x Numerator - * @param y Denominator - * @returns Quotient, x ./ y - */ - dotDivide(x: T, y: MathType): T - dotDivide(x: MathType, y: T): T - dotDivide(x: Unit, y: MathType): Unit - dotDivide(x: MathType, y: Unit): Unit - dotDivide(x: MathNumericType, y: MathNumericType): MathNumericType - - /** - * Multiply two matrices element wise. The function accepts both - * matrices and scalar values. - * @param x Left hand value - * @param y Right hand value - * @returns Multiplication of x and y - */ - dotMultiply(x: T, y: MathType): T - dotMultiply(x: MathType, y: T): T - dotMultiply(x: Unit, y: MathType): Unit - dotMultiply(x: MathType, y: Unit): Unit - dotMultiply(x: MathNumericType, y: MathNumericType): MathNumericType - - /** - * Calculates the power of x to y element wise. - * @param x The base - * @param y The exponent - * @returns The value of x to the power y - */ - dotPow(x: T, y: MathType): T - - /** - * Calculate the exponent of a value. For matrices, the function is - * evaluated element wise. - * @param x A number or matrix to exponentiate - * @returns Exponent of x - */ - exp(x: T): T - - /** - * Calculate the value of subtracting 1 from the exponential value. For - * matrices, the function is evaluated element wise. - * @param x A number or matrix to apply expm1 - * @returns Exponent of x - */ - expm1(x: T): T - - /** - * Calculate the greatest common divisor for two or more values or - * arrays. For matrices, the function is evaluated element wise. - * @param args Two or more integer numbers - * @returns The greatest common divisor - */ - gcd( - ...args: T[] - ): T - gcd(args: T[]): T - - /** - * Calculate the hypotenusa of a list with values. The hypotenusa is - * defined as: hypot(a, b, c, ...) = sqrt(a^2 + b^2 + c^2 + ...) For - * matrix input, the hypotenusa is calculated for all values in the - * matrix. - * @param args A list with numeric values or an Array or Matrix. Matrix - * and Array input is flattened and returns a single number for the - * whole matrix. - * @returns Returns the hypothenuse of the input values. - */ - hypot(...args: T[]): T - - /** - * Calculate the least common multiple for two or more values or arrays. - * lcm is defined as: lcm(a, b) = abs(a * b) / gcd(a, b) For matrices, - * the function is evaluated element wise. - * @param a An integer number - * @param b An integer number - * @returns The least common multiple - */ - lcm(a: T, b: T): T - - /** - * Calculate the logarithm of a value. - * @param x Value for which to calculate the logarithm. - * @param base Optional base for the logarithm. If not provided, the - * natural logarithm of x is calculated. Default value: e. - * @returns Returns the logarithm of x - */ - log( - x: T, - base?: number | BigNumber | Complex - ): NoLiteralType - - /** - * Calculate the 10-base of a value. This is the same as calculating - * log(x, 10). For matrices, the function is evaluated element wise. - * @param x Value for which to calculate the logarithm. - * @returns Returns the 10-base logarithm of x - */ - log10(x: T): T - - /** - * Calculate the logarithm of a value+1. For matrices, the function is - * evaluated element wise. - * @param x Value for which to calculate the logarithm. - * @returns Returns the logarithm of x+1 - */ - log1p( - x: T, - base?: number | BigNumber | Complex - ): T - - /** - * Calculate the 2-base of a value. This is the same as calculating - * log(x, 2). For matrices, the function is evaluated element wise. - * @param x Value for which to calculate the logarithm. - * @returns Returns the 2-base logarithm of x - */ - log2(x: T): T - - /** - * Calculates the modulus, the remainder of an integer division. For - * matrices, the function is evaluated element wise. The modulus is - * defined as: x - y * floor(x / y) - * @see http://en.wikipedia.org/wiki/Modulo_operation. - * @param x Dividend - * @param y Divisor - * @returns Returns the remainder of x divided by y - */ - mod( - x: T, - y: number | BigNumber | Fraction | MathCollection - ): NoLiteralType - - /** - * Multiply two values, x * y. The result is squeezed. For matrices, the - * matrix product is calculated. - * @param x The first value to multiply - * @param y The second value to multiply - * @returns Multiplication of x and y - */ - - multiply(x: T, y: MathType): Matrix - multiply(x: MathType, y: T): Matrix - - multiply(x: T, y: T[]): T - multiply(x: T[], y: T): T - multiply(x: T, y: T): T - multiply(x: Unit, y: Unit): Unit - multiply(x: number, y: number): number - multiply(x: MathType, y: MathType): MathType - - /** - * Calculate the norm of a number, vector or matrix. The second - * parameter p is optional. If not provided, it defaults to 2. - * @param x Value for which to calculate the norm - * @param p Vector space. Supported numbers include Infinity and - * -Infinity. Supported strings are: 'inf', '-inf', and 'fro' (The - * Frobenius norm) Default value: 2. - * @returns the p-norm - */ - norm( - x: number | BigNumber | Complex | MathCollection, - p?: number | BigNumber | string - ): number | BigNumber - - /** - * Calculate the nth root of a value. The principal nth root of a - * positive real number A, is the positive real solution of the equation - * x^root = A For matrices, the function is evaluated element wise. - * @param a Value for which to calculate the nth root - * @param root The root. Default value: 2. - * @return The nth root of a - */ - nthRoot( - a: number | BigNumber | MathCollection | Complex, - root?: number | BigNumber - ): number | Complex | MathCollection - - /** - * Calculates the power of x to y, x ^ y. Matrix exponentiation is - * supported for square matrices x, and positive integer exponents y. - * @param x The base - * @param y The exponent - * @returns x to the power y - */ - pow(x: MathType, y: number | BigNumber | Complex): MathType - - /** - * Compute the sign of a value. The sign of a value x is: 1 when x > 1 - * -1 when x < 0 0 when x == 0 For matrices, the function is evaluated - * element wise. - * @param x The number for which to determine the sign - * @returns The sign of x - */ - sign(x: T): T - - /** - * Calculate the square root of a value. For matrices, use either - * sqrtm for the matrix square root, or map(M, sqrt) to take the - * square root element wise. - * @param x Value for which to calculate the square root - * @returns Returns the square root of x - */ - sqrt(x: number): number | Complex - sqrt(x: T): T - - /** - * Compute the square of a value, x * x. - * @param x Number for which to calculate the square - * @returns Squared value - */ - square(x: T): T - - /** - * Subtract two values, x - y. For matrices, the function is evaluated - * element wise. - * @param x Initial value - * @param y Value to subtract from x - * @returns Subtraction of x and y - */ - subtract(x: T, y: T): T - subtract(x: MathType, y: MathType): MathType - - /** - * Inverse the sign of a value, apply a unary minus operation. For - * matrices, the function is evaluated element wise. Boolean values and - * strings will be converted to a number. For complex numbers, both real - * and complex value are inverted. - * @param x Number to be inverted - * @returns Retursn the value with inverted sign - */ - unaryMinus(x: T): T - - /** - * Unary plus operation. Boolean values and strings will be converted to - * a number, numeric values will be returned as is. For matrices, the - * function is evaluated element wise. - * @param x Input value - * @returns Returns the input value when numeric, converts to a number - * when input is non-numeric. - */ - unaryPlus(x: T): T - - /** - * Calculate the extended greatest common divisor for two values. See - * http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm. - * @param a An integer number - * @param b An integer number - * @returns Returns an array containing 3 integers [div, m, n] where div - * = gcd(a, b) and a*m + b*n = div - */ - xgcd(a: number | BigNumber, b: number | BigNumber): MathArray - - /************************************************************************* - * Bitwise functions - ************************************************************************/ - - /** - * Bitwise AND two values, x & y. For matrices, the function is - * evaluated element wise. - * @param x First value to and - * @param y Second value to and - * @returns AND of x and y - */ - bitAnd( - x: T, - y: number | BigNumber | MathCollection - ): NoLiteralType - - /** - * Bitwise NOT value, ~x. For matrices, the function is evaluated - * element wise. For units, the function is evaluated on the best prefix - * base. - * @param x Value to not - * @returns NOT of x - */ - bitNot(x: T): T - - /** - * Bitwise OR two values, x | y. For matrices, the function is evaluated - * element wise. For units, the function is evaluated on the lowest - * print base. - * @param x First value to or - * @param y Second value to or - * @returns OR of x and y - */ - bitOr(x: T, y: T): T - - /** - * Bitwise XOR two values, x ^ y. For matrices, the function is - * evaluated element wise. - * @param x First value to xor - * @param y Second value to xor - * @returns XOR of x and y - */ - bitXor( - x: T, - y: number | BigNumber | MathCollection - ): NoLiteralType - - /** - * Bitwise left logical shift of a value x by y number of bits, x << y. - * For matrices, the function is evaluated element wise. For units, the - * function is evaluated on the best prefix base. - * @param x Value to be shifted - * @param y Amount of shifts - * @returns x shifted left y times - */ - leftShift( - x: T, - y: number | BigNumber - ): NoLiteralType - - /** - * Bitwise right arithmetic shift of a value x by y number of bits, x >> - * y. For matrices, the function is evaluated element wise. For units, - * the function is evaluated on the best prefix base. - * @param x Value to be shifted - * @param y Amount of shifts - * @returns x sign-filled shifted right y times - */ - rightArithShift( - x: T, - y: number | BigNumber - ): NoLiteralType - - /** - * Bitwise right logical shift of value x by y number of bits, x >>> y. - * For matrices, the function is evaluated element wise. For units, the - * function is evaluated on the best prefix base. - * @param x Value to be shifted - * @param y Amount of shifts - * @returns x zero-filled shifted right y times - */ - rightLogShift( - x: T, - y: number - ): NoLiteralType - - /************************************************************************* - * Combinatorics functions - ************************************************************************/ - - /** - * The Bell Numbers count the number of partitions of a set. A partition - * is a pairwise disjoint subset of S whose union is S. bellNumbers only - * takes integer arguments. The following condition must be enforced: n - * >= 0 - * @param n Total number of objects in the set - * @returns B(n) - */ - bellNumbers(n: T): T - - /** - * The Catalan Numbers enumerate combinatorial structures of many - * different types. catalan only takes integer arguments. The following - * condition must be enforced: n >= 0 - * @param n nth Catalan number - * @returns Cn(n) - */ - catalan(n: T): T - - /** - * The composition counts of n into k parts. Composition only takes - * integer arguments. The following condition must be enforced: k <= n. - * @param n Total number of objects in the set - * @param k Number of objects in the subset - * @returns Returns the composition counts of n into k parts. - */ - composition( - n: T, - k: number | BigNumber - ): NoLiteralType - - /** - * The Stirling numbers of the second kind, counts the number of ways to - * partition a set of n labelled objects into k nonempty unlabelled - * subsets. stirlingS2 only takes integer arguments. The following - * condition must be enforced: k <= n. If n = k or k = 1, then s(n,k) = - * 1 - * @param n Total number of objects in the set - * @param k Number of objects in the subset - * @returns S(n,k) - */ - stirlingS2( - n: T, - k: number | BigNumber - ): NoLiteralType - - /************************************************************************* - * Complex functions - ************************************************************************/ - - /** - * Compute the argument of a complex value. For a complex number a + bi, - * the argument is computed as atan2(b, a). For matrices, the function - * is evaluated element wise. - * @param x A complex number or array with complex numbers - * @returns The argument of x - */ - arg(x: number | Complex): number - arg(x: BigNumber | Complex): BigNumber - arg(x: T): T - - /** - * Compute the complex conjugate of a complex value. If x = a+bi, the - * complex conjugate of x is a - bi. For matrices, the function is - * evaluated element wise. - * @param x A complex number or array with complex numbers - * @returns The complex conjugate of x - */ - conj( - x: T - ): NoLiteralType - - /** - * Get the imaginary part of a complex number. For a complex number a + - * bi, the function returns b. For matrices, the function is evaluated - * element wise. - * @param x A complex number or array with complex numbers - * @returns The imaginary part of x - */ - im(x: MathJsChain): MathJsChain - im(x: MathJsChain): MathJsChain - - /** - * Get the real part of a complex number. For a complex number a + bi, - * the function returns a. For matrices, the function is evaluated - * element wise. - * @param x A complex number or array of complex numbers - * @returns The real part of x - */ - re(x: MathJsChain): MathJsChain - re(x: MathJsChain): MathJsChain - - /************************************************************************* - * Geometry functions - ************************************************************************/ - - /** - * Calculates: The eucledian distance between two points in 2 and 3 - * dimensional spaces. Distance between point and a line in 2 and 3 - * dimensional spaces. Pairwise distance between a set of 2D or 3D - * points NOTE: When substituting coefficients of a line(a, b and c), - * use ax + by + c = 0 instead of ax + by = c For parametric equation of - * a 3D line, x0, y0, z0, a, b, c are from: (x−x0, y−y0, z−z0) = t(a, b, - * c) - * @param x Coordinates of the first point - * @param y Coordinates of the second point OR coefficients of a line in 3D OR first end-point of a line if the calculation is for distance between point and a line in 2D - * @param z Coordinates of second end-point of a line if the calculation is for distance between point and a line in 2D - * @returns Returns the distance from two/three points - */ - distance( - x: MathCollection | object, - y: MathCollection | object, - z?: MathCollection | object - ): number | BigNumber - - /** - * Calculates the point of intersection of two lines in two or three - * dimensions and of a line and a plane in three dimensions. The inputs - * are in the form of arrays or 1 dimensional matrices. The line - * intersection functions return null if the lines do not meet. Note: - * Fill the plane coefficients as x + y + z = c and not as x + y + z + c - * = 0. - * @param w Co-ordinates of first end-point of first line - * @param x Co-ordinates of second end-point of first line - * @param y Co-ordinates of first end-point of second line OR - * Coefficients of the plane's equation - * @param z Co-ordinates of second end-point of second line OR null if - * the calculation is for line and plane - * @returns Returns the point of intersection of lines/lines-planes - */ - intersect( - w: MathCollection, - x: MathCollection, - y: MathCollection, - z?: MathCollection - ): MathArray - - /************************************************************************* - * Logical functions - ************************************************************************/ - - /** - * Logical and. Test whether two values are both defined with a - * nonzero/nonempty value. For matrices, the function is evaluated - * element wise. - * @param x First value to and - * @param y Second value to and - * @returns Returns true when both inputs are defined with a - * nonzero/nonempty value. - */ - and( - x: number | BigNumber | Complex | Unit | MathCollection, - y: number | BigNumber | Complex | Unit | MathCollection - ): boolean | MathCollection - - /** - * Logical not. Flips boolean value of a given parameter. For matrices, - * the function is evaluated element wise. - * @param x First value to not - * @returns Returns true when input is a zero or empty value. - */ - not( - x: number | BigNumber | Complex | Unit | MathCollection - ): boolean | MathCollection - - /** - * Logical or. Test if at least one value is defined with a - * nonzero/nonempty value. For matrices, the function is evaluated - * element wise. - * @param x First value to or - * @param y Second value to or - * @returns Returns true when one of the inputs is defined with a - * nonzero/nonempty value. - */ - or( - x: number | BigNumber | Complex | Unit | MathCollection, - y: number | BigNumber | Complex | Unit | MathCollection - ): boolean | MathCollection - - /** - * Logical xor. Test whether one and only one value is defined with a - * nonzero/nonempty value. For matrices, the function is evaluated - * element wise. - * @param x First value to xor - * @param y Second value to xor - * @returns Returns true when one and only one input is defined with a - * nonzero/nonempty value. - */ - xor( - x: number | BigNumber | Complex | Unit | MathCollection, - y: number | BigNumber | Complex | Unit | MathCollection - ): boolean | MathCollection - - /************************************************************************* - * Matrix functions - ************************************************************************/ - - /** - * Apply a function that maps an array to a scalar along a given axis of a - * matrix or array. Returns a new matrix or array with one less dimension - * than the input. - * @param array The input Matrix - * @param dim The dimension along which the callback is applied - * @param callback The callback function that is applied. This Function should take an - * array or 1-d matrix as an input and return a number. - * @returns The residual matrix with the function applied over some dimension. - */ - apply( - array: T, - dim: number, - callback: (array: MathCollection) => number - ): T - - /** - * Concatenate two or more matrices. dim: number is a zero-based - * dimension over which to concatenate the matrices. By default the last - * dimension of the matrices. - * @param args Two or more matrices - * @returns Concatenated matrix - */ - concat(...args: Array): MathCollection - - /** - * Calculate the cross product for two vectors in three dimensional - * space. The cross product of A = [a1, a2, a3] and B =[b1, b2, b3] is - * defined as: cross(A, B) = [ a2 * b3 - a3 * b2, a3 * b1 - a1 * b3, a1 - * * b2 - a2 * b1 ] - * @param x First vector - * @param y Second vector - * @returns Returns the cross product of x and y - */ - cross(x: MathCollection, y: MathCollection): MathCollection - - /** - * Calculate the determinant of a matrix. - * @param x A Matrix - * @returns the determinant of x - */ - det(x: MathCollection): number - - /** - * Create a diagonal matrix or retrieve the diagonal of a matrix. When x - * is a vector, a matrix with vector x on the diagonal will be returned. - * When x is a two dimensional matrix, the matrixes kth diagonal will be - * returned as vector. When k is positive, the values are placed on the - * super diagonal. When k is negative, the values are placed on the sub - * diagonal. - * @param X A two dimensional matrix or a vector - * @param k The diagonal where the vector will be filled in or - * retrieved. Default value: 0. - * @param format The matrix storage format. Default value: 'dense'. - * @returns Diagonal matrix from input vector, or diagonal from input - * matrix - */ - diag(X: MathCollection, format?: string): Matrix - diag( - X: MathCollection, - k: number | BigNumber, - format?: string - ): MathCollection - - /** - * Calculate the dot product of two vectors. The dot product of A = [a1, - * a2, a3, ..., an] and B = [b1, b2, b3, ..., bn] is defined as: dot(A, - * B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn - * @param x First vector - * @param y Second vector - * @returns Returns the dot product of x and y - */ - dot(x: MathCollection, y: MathCollection): number - - /** - * Compute eigenvalues and eigenvectors of a matrix. - * The eigenvalues are sorted by their absolute value, ascending. - * An eigenvalue with multiplicity k will be listed k times. - * The eigenvectors are returned as an array of objects, each with a - * `value` and a `vector`. If the algorithm fails to converge, - * it will throw an error – in that case, however, you may still find useful - * information in err.values and err.vectors - * @param x Matrix to be diagonalized - * @param prec Precision, default value: 1e-15 - * @returns Object containing an array of eigenvalues and a matrix with eigenvectors as columns. - */ - eigs( - x: MathCollection, - prec?: number | BigNumber - ): { - values: MathCollection - eigenvectors: { - value: number | BigNumber - vector: MathCollection - }[] - } - - /** - * Compute the matrix exponential, expm(A) = e^A. The matrix must be - * square. Not to be confused with exp(a), which performs element-wise - * exponentiation. The exponential is calculated using the Padé - * approximant with scaling and squaring; see “Nineteen Dubious Ways to - * Compute the Exponential of a Matrix,” by Moler and Van Loan. - * @param x A square matrix - * @returns The exponential of x - */ - expm(x: Matrix): Matrix - - /** - * Solves the real-valued Sylvester equation AX-XB=C for X, where A, B and C are - * matrices of appropriate dimensions, being A and B squared. The method used is - * the Bartels-Stewart algorithm. - * https://en.wikipedia.org/wiki/Sylvester_equation - * @param A Matrix A - * @param B Matrix B - * @param C Matrix C - * @returns Matrix X, solving the Sylvester equation - */ - sylvester( - A: MathCollection, - B: MathCollection, - C: MathCollection - ): MathCollection - - /** - * Performs a real Schur decomposition of the real matrix A = UTU' where U is orthogonal - * and T is upper quasi-triangular. - * https://en.wikipedia.org/wiki/Schur_decomposition - * @param A Matrix A - * @returns Object containing both matrix U and T of the Schur Decomposition A=UTU' - */ - schur(A: MathCollection): SchurDecomposition - - /** - * Solves the Continuous-time Lyapunov equation AP+PA'=Q for P, where Q is a positive semidefinite - * matrix. - * https://en.wikipedia.org/wiki/Lyapunov_equation - * @param A Matrix A - * @param Q Matrix Q - * @returns Matrix P solution to the Continuous-time Lyapunov equation AP+PA'=Q - */ - lyap(A: MathCollection, Q: MathCollection): MathCollection - - /** - * Create a 2-dimensional identity matrix with size m x n or n x n. The - * matrix has ones on the diagonal and zeros elsewhere. - * @param size The size for the matrix - * @param format The Matrix storage format - * @returns A matrix with ones on the diagonal - */ - identity( - size: number | number[] | MathCollection, - format?: string - ): MathCollection | number - /** - * @param m The x dimension for the matrix - * @param n The y dimension for the matrix - * @param format The Matrix storage format - * @returns A matrix with ones on the diagonal - */ - identity(m: number, n: number, format?: string): MathCollection | number - - /** - * Filter the items in an array or one dimensional matrix. - * @param x A one dimensional matrix or array to filter - * @param test A function or regular expression to test items. All - * entries for which test returns true are returned. When test is a - * function, it is invoked with three parameters: the value of the - * element, the index of the element, and the matrix/array being - * traversed. The function must return a boolean. - */ - filter( - x: MathCollection | string[], - test: - | (( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - value: any, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - index: any, - matrix: MathCollection | string[] - ) => boolean) - | RegExp - ): MathCollection - - /** - * Flatten a multi dimensional matrix into a single dimensional matrix. - * @param x Matrix to be flattened - * @returns Returns the flattened matrix - */ - flatten(x: T): T - - /** - * Iterate over all elements of a matrix/array, and executes the given - * callback function. - * @param x The matrix to iterate on. - * @param callback The callback function is invoked with three - * parameters: the value of the element, the index of the element, and - * the Matrix/array being traversed. - */ - forEach( - x: T, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - callback: (value: any, index: any, matrix: T) => void - ): void - - /** - * Calculate the inverse of a square matrix. - * @param x Matrix to be inversed - * @returns The inverse of x - */ - inv(x: T): NoLiteralType - - /** - * Calculate the kronecker product of two matrices or vectors - * @param x First vector - * @param y Second vector - * @returns Returns the kronecker product of x and y - */ - kron(x: MathCollection, y: MathCollection): Matrix - - /** - * Iterate over all elements of a matrix/array, and executes the given - * callback function. - * @param x The matrix to iterate on. - * @param callback The callback function is invoked with three - * parameters: the value of the element, the index of the element, and - * the Matrix/array being traversed. - * @returns Transformed map of x - */ - map( - x: T, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - callback: (value: any, index: any, matrix: T) => MathType | string - ): T - - /** - * Create a matrix filled with ones. The created matrix can have one or - * multiple dimensions. - * @param size The size of each dimension of the matrix - * @param format The matrix storage format - * @returns A matrix filled with ones - */ - ones( - size?: number | number[] | BigNumber | BigNumber[], - format?: string - ): MathCollection - /** - * @param m The x dimension of the matrix - * @param n The y dimension of the matrix - * @param format The matrix storage format - * @returns A matrix filled with ones - */ - ones( - m: number | BigNumber, - n: number | BigNumber, - format?: string - ): MathCollection - /** - * @param m The x dimension of the matrix - * @param n The y dimension of the matrix - * @param p The z dimension of the matrix - * @param format The matrix storage format - * @returns A matrix filled with ones - */ - ones( - m: number | BigNumber, - n: number | BigNumber, - p: number | BigNumber, - format?: string - ): MathCollection - /** Actually ones can take an arbitrary number of dimensions before the - ** optional format, not sure how to write that in TypeScript - **/ - - /** - * Partition-based selection of an array or 1D matrix. Will find the kth - * smallest value, and mutates the input array. Uses Quickselect. - * @param x A one dimensional matrix or array to sort - * @param k The kth smallest value to be retrieved; zero-based index - * @param compare An optional comparator function. The function is - * called as compare(a, b), and must return 1 when a > b, -1 when a < b, - * and 0 when a == b. Default value: 'asc'. - * @returns Returns the kth lowest value. - */ - partitionSelect( - x: MathCollection, - k: number, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - compare?: 'asc' | 'desc' | ((a: any, b: any) => number) - // eslint-disable-next-line @typescript-eslint/no-explicit-any - ): any - - /** - * Calculate the Moore–Penrose inverse of a matrix. - * @param x Matrix to be inversed - * @return The inverse of `x`. - */ - pinv(x: T): T - - /** - * Create an array from a range. By default, the range end is excluded. - * This can be customized by providing an extra parameter includeEnd. - * @param str A string 'start:end' or 'start:step:end' - * @param start Start of the range - * @param end End of the range, excluded by default, included when - * parameter includeEnd=true - * @param step Step size. Default value is 1. - * @param includeEnd: Option to specify whether to include the end or - * not. False by default - * @returns Parameters describing the ranges start, end, and optional - * step. - */ - range(str: string, includeEnd?: boolean): Matrix - range( - start: number | BigNumber, - end: number | BigNumber, - includeEnd?: boolean - ): Matrix - range( - start: number | BigNumber | Unit, - end: number | BigNumber | Unit, - step: number | BigNumber | Unit, - includeEnd?: boolean - ): Matrix - - /** - * Reshape a multi dimensional array to fit the specified dimensions - * @param x Matrix to be reshaped - * @param sizes One dimensional array with integral sizes for each - * dimension - * @returns A reshaped clone of matrix x - */ - reshape(x: T, sizes: number[]): T - - /** - * Resize a matrix - * @param x Matrix to be resized - * @param size One dimensional array with numbers - * @param defaultValue Zero by default, except in case of a string, in - * that case defaultValue = ' ' Default value: 0. - * @returns A resized clone of matrix x - */ - resize( - x: T, - size: MathCollection, - defaultValue?: number | string - ): T - - /** - * Return a Rotation Matrix for a given angle in radians - * @param {number | BigNumber | Complex | Unit} theta Rotation angle - * @param {Array | Matrix} [v] Rotation axis - * @param {string} [format] Result Matrix storage format. Default value: 'dense'. - * @return {Matrix} Rotation Matrix - */ - rotationMatrix( - theta?: number | BigNumber | Complex | Unit, - axis?: T, - format?: 'sparse' | 'dense' - ): T - - /** - * Return a row from a Matrix. - * @param value An array or matrix - * @param row The index of the row - * @returns The retrieved row - */ - row(value: T, row: number): T - - /** - * Return a column from a Matrix. - * @param value An array or matrix - * @param column The index of the column - * @returns The retrieved column - */ - column(value: T, column: number): T - - /** - * Return a rotated matrix. - * @param {Array | Matrix} w Vector to rotate - * @param {number | BigNumber | Complex | Unit} theta Rotation angle - * @param {Array | Matrix} [v] Rotation axis - * @return {Array | Matrix} Multiplication of the rotation matrix and w - */ - rotate( - w: T, - theta: number | BigNumber | Complex | Unit, - v?: T - ): T - - /** - * Calculate the size of a matrix or scalar. - * @param A matrix - * @returns A vector with the size of x - */ - size( - x: boolean | number | Complex | Unit | string | MathCollection - ): MathCollection - - /** - * Sort the items in a matrix - * @param x A one dimensional matrix or array to sort - * @param compare An optional _comparator function or name. The function - * is called as compare(a, b), and must return 1 when a > b, -1 when a < - * b, and 0 when a == b. Default value: ‘asc’ - * @returns Returns the sorted matrix - */ - sort( - x: T, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - compare: ((a: any, b: any) => number) | 'asc' | 'desc' | 'natural' - ): T - - /** - * Calculate the principal square root of a square matrix. The principal - * square root matrix X of another matrix A is such that X * X = A. - * @param A The square matrix A - * @returns The principal square root of matrix A - */ - sqrtm(A: T): T - - /** - * Squeeze a matrix, remove inner and outer singleton dimensions from a - * matrix. - * @param x Matrix to be squeezed - * @returns Squeezed matrix - */ - squeeze(x: T): T - - /** - * Get or set a subset of a matrix or string. - * @param value An array, matrix, or string - * @param index For each dimension, an index or list of indices to get or set. - * @param replacement An array, matrix, or scalar. If provided, the - * subset is replaced with replacement. If not provided, the subset is - * returned - * @param defaultValue Default value, filled in on new entries when the - * matrix is resized. If not provided, math.matrix elements will be left - * undefined. Default value: undefined. - * @returns Either the retrieved subset or the updated matrix - */ - subset( - value: T, - index: Index, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - replacement?: any, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - defaultValue?: any - ): T - - /** - * Calculate the trace of a matrix: the sum of the elements on the main - * diagonal of a square matrix. - * @param x A matrix - * @returns The trace of x - */ - trace(x: MathCollection): number - - /** - * Transpose a matrix. All values of the matrix are reflected over its - * main diagonal. Only two dimensional matrices are supported. - * @param x Matrix to be transposed - * @returns The transposed matrix - */ - transpose(x: T): T - - /** - * Create a matrix filled with zeros. The created matrix can have one or - * multiple dimensions. - * @param size The size of each dimension of the matrix - * @param format The matrix storage format - * @returns A matrix filled with zeros - */ - zeros( - size?: number | number[] | BigNumber | BigNumber[], - format?: string - ): MathCollection - /** - * @param m The x dimension of the matrix - * @param n The y dimension of the matrix - * @param format The matrix storage format - * @returns A matrix filled with zeros - */ - zeros( - m: number | BigNumber, - n: number | BigNumber, - format?: string - ): MathCollection - /** - * @param m The x dimension of the matrix - * @param n The y dimension of the matrix - * @param p The z dimension of the matrix - * @param format The matrix storage format - * @returns A matrix filled with zeros - */ - zeros( - m: number | BigNumber, - n: number | BigNumber, - p: number | BigNumber, - format?: string - ): MathCollection - /** Actually zeros can take any number of dimensions before the - ** optional format, not sure how to write that in TypeScript - **/ - - /** - * Calculate N-dimensional fourier transform - * @param {Array | Matrix} arr An array or matrix - * @return {Array | Matrix} N-dimensional fourier transformation of the array - */ - fft(arr: T): T - - /** - * Calculate N-dimensional inverse fourier transform - * @param {Array | Matrix} arr An array or matrix - * @return {Array | Matrix} N-dimensional fourier transformation of the array - */ - ifft(arr: T): T - - /************************************************************************* - * Probability functions - ************************************************************************/ - - /** - * Compute the number of ways of picking k unordered outcomes from n - * possibilities. Combinations only takes integer arguments. The - * following condition must be enforced: k <= n. - * @param n Total number of objects in the set - * @param k Number of objects in the subset - * @returns Number of possible combinations - */ - combinations( - n: T, - k: number | BigNumber - ): NoLiteralType - - /** - * Compute the factorial of a value Factorial only supports an integer - * value as argument. For matrices, the function is evaluated element - * wise. - * @param n An integer number - * @returns The factorial of n - */ - factorial( - n: T - ): NoLiteralType - - /** - * Compute the gamma function of a value using Lanczos approximation for - * small values, and an extended Stirling approximation for large - * values. - * @param n A real or complex number - * @returns The gamma of n - */ - gamma(n: T): NoLiteralType - - /** - * Calculate the Kullback-Leibler (KL) divergence between two - * distributions - * @param q First vector - * @param p Second vector - * @returns Returns disance between q and p - */ - kldivergence(q: MathCollection, p: MathCollection): number - - /** - * Compute the log gamma function of a value, using Lanczos approximation for numbers and Stirling series for complex numbers. - * @param n A real or complex number - * @returns The log gamma of `n` - */ - lgamma(n: T): NoLiteralType - - /** - * Multinomial Coefficients compute the number of ways of picking a1, - * a2, ..., ai unordered outcomes from n possibilities. multinomial - * takes one array of integers as an argument. The following condition - * must be enforced: every ai <= 0 - * @param a Integer number of objects in the subset - * @returns multinomial coefficent - */ - multinomial(a: T[]): NoLiteralType - - /** - * Compute the number of ways of obtaining an ordered subset of k - * elements from a set of n elements. Permutations only takes integer - * arguments. The following condition must be enforced: k <= n. - * @param n The number of objects in total - * @param k The number of objects in the subset - * @returns The number of permutations - */ - permutations( - n: T, - k?: number | BigNumber - ): NoLiteralType - - /** - * Random pick a value from a one dimensional array. Array element is - * picked using a random function with uniform distribution. - * @param array A one dimensional array - * @param number An int or float - * @param weights An array of ints or floats - * @returns Returns a single random value from array when number is 1 or - * undefined. Returns an array with the configured number of elements - * when number is > 1. - */ - pickRandom(array: T[]): T - pickRandom(array: T[], number: number): T[] - pickRandom(array: T[], number: number, weights: number[]): T[] - - /** - * Return a random number larger or equal to min and smaller than max - * using a uniform distribution. - * @param size If provided, an array or matrix with given size and - * filled with random values is returned - * @param min Minimum boundary for the random value, included - * @param max Maximum boundary for the random value, excluded - * @returns A random number - */ - random(min?: number, max?: number): number - random(size: T, min?: number, max?: number): T - - /** - * Return a random integer number larger or equal to min and smaller - * than max using a uniform distribution. - * @param size If provided, an array or matrix with given size and - * filled with random values is returned - * @param min Minimum boundary for the random value, included - * @param max Maximum boundary for the random value, excluded - * @returns A random number - */ - randomInt(min: number, max?: number): number - randomInt(size: T, min?: number, max?: number): T - - /************************************************************************* - * Relational functions - ************************************************************************/ - - /** - * Compare two values. Returns 1 when x > y, -1 when x < y, and 0 when x - * == y. x and y are considered equal when the relative difference - * between x and y is smaller than the configured epsilon. The function - * cannot be used to compare values smaller than approximately 2.22e-16. - * For matrices, the function is evaluated element wise. - * @param x First value to compare - * @param y Second value to compare - * @returns Returns the result of the comparison: 1 when x > y, -1 when - * x < y, and 0 when x == y. - */ - compare( - x: MathType | string, - y: MathType | string - ): number | BigNumber | Fraction | MathCollection - - /** - * Compare two values of any type in a deterministic, natural way. For - * numeric values, the function works the same as math.compare. For - * types of values that can’t be compared mathematically, the function - * compares in a natural way. - * @param x First value to compare - * @param y Second value to compare - * @returns Returns the result of the comparison: 1 when x > y, -1 when - * x < y, and 0 when x == y. - */ + value: any, // eslint-disable-next-line @typescript-eslint/no-explicit-any - compareNatural(x: any, y: any): number - - /** - * Compare two strings lexically. Comparison is case sensitive. Returns - * 1 when x > y, -1 when x < y, and 0 when x == y. For matrices, the - * function is evaluated element wise. - * @param x First string to compare - * @param y Second string to compare - * @returns Returns the result of the comparison: 1 when x > y, -1 when - * x < y, and 0 when x == y. - */ - compareText( - x: string | MathCollection, - y: string | MathCollection - ): number | MathCollection - - /** - * Test element wise whether two matrices are equal. The function - * accepts both matrices and scalar values. - * @param x First matrix to compare - * @param y Second amtrix to compare - * @returns Returns true when the input matrices have the same size and - * each of their elements is equal. - */ - deepEqual(x: MathType, y: MathType): MathType - - /** - * Test whether two values are equal. - * - * The function tests whether the relative difference between x and y is - * smaller than the configured epsilon. The function cannot be used to - * compare values smaller than approximately 2.22e-16. For matrices, the - * function is evaluated element wise. In case of complex numbers, x.re - * must equal y.re, and x.im must equal y.im. Values null and undefined - * are compared strictly, thus null is only equal to null and nothing - * else, and undefined is only equal to undefined and nothing else. - * @param x First value to compare - * @param y Second value to compare - * @returns Returns true when the compared values are equal, else - * returns false - */ - equal(x: MathType | string, y: MathType | string): boolean | MathCollection - - /** - * Check equality of two strings. Comparison is case sensitive. For - * matrices, the function is evaluated element wise. - * @param x First string to compare - * @param y Second string to compare - * @returns Returns true if the values are equal, and false if not. - */ - equalText( - x: string | MathCollection, - y: string | MathCollection - ): number | MathCollection - - /** - * Test whether value x is larger than y. The function returns true when - * x is larger than y and the relative difference between x and y is - * larger than the configured epsilon. The function cannot be used to - * compare values smaller than approximately 2.22e-16. For matrices, the - * function is evaluated element wise. - * @param x First value to compare - * @param y Second value to vcompare - * @returns Returns true when x is larger than y, else returns false - */ - larger(x: MathType | string, y: MathType | string): boolean | MathCollection - - /** - * Test whether value x is larger or equal to y. The function returns - * true when x is larger than y or the relative difference between x and - * y is smaller than the configured epsilon. The function cannot be used - * to compare values smaller than approximately 2.22e-16. For matrices, - * the function is evaluated element wise. - * @param x First value to compare - * @param y Second value to vcompare - * @returns Returns true when x is larger than or equal to y, else - * returns false - */ - largerEq( - x: MathType | string, - y: MathType | string - ): boolean | MathCollection - - /** - * Test whether value x is smaller than y. The function returns true - * when x is smaller than y and the relative difference between x and y - * is smaller than the configured epsilon. The function cannot be used - * to compare values smaller than approximately 2.22e-16. For matrices, - * the function is evaluated element wise. - * @param x First value to compare - * @param y Second value to vcompare - * @returns Returns true when x is smaller than y, else returns false - */ - smaller( - x: MathType | string, - y: MathType | string - ): boolean | MathCollection - - /** - * Test whether value x is smaller or equal to y. The function returns - * true when x is smaller than y or the relative difference between x - * and y is smaller than the configured epsilon. The function cannot be - * used to compare values smaller than approximately 2.22e-16. For - * matrices, the function is evaluated element wise. - * @param x First value to compare - * @param y Second value to vcompare - * @returns Returns true when x is smaller than or equal to y, else - * returns false - */ - smallerEq( - x: MathType | string, - y: MathType | string - ): boolean | MathCollection - - /** - * Test whether two values are unequal. The function tests whether the - * relative difference between x and y is larger than the configured - * epsilon. The function cannot be used to compare values smaller than - * approximately 2.22e-16. For matrices, the function is evaluated - * element wise. In case of complex numbers, x.re must unequal y.re, or - * x.im must unequal y.im. Values null and undefined are compared - * strictly, thus null is unequal with everything except null, and - * undefined is unequal with everything except undefined. - * @param x First value to compare - * @param y Second value to vcompare - * @returns Returns true when the compared values are unequal, else - * returns false - */ - unequal( - x: MathType | string, - y: MathType | string - ): boolean | MathCollection - - /************************************************************************* - * Set functions - ************************************************************************/ - - /** - * Create the cartesian product of two (multi)sets. Multi-dimension - * arrays will be converted to single-dimension arrays and the values - * will be sorted in ascending order before the operation. - * @param a1 A (multi)set - * @param a2 A (multi)set - * @returns The cartesian product of two (multi)sets - */ - setCartesian(a1: T, a2: MathCollection): T - - /** - * Create the difference of two (multi)sets: every element of set1, that - * is not the element of set2. Multi-dimension arrays will be converted - * to single-dimension arrays before the operation - * @param a1 A (multi)set - * @param a2 A (multi)set - * @returns The difference of two (multi)sets - */ - setDifference(a1: T, a2: MathCollection): T - - /** - * Collect the distinct elements of a multiset. A multi-dimension array - * will be converted to a single-dimension array before the operation. - * @param a A multiset - * @returns A set containing the distinct elements of the multiset - */ - setDistinct(a: T): T - - /** - * Create the intersection of two (multi)sets. Multi-dimension arrays - * will be converted to single-dimension arrays before the operation. - * @param a1 A (multi)set - * @param a2 A (multi)set - * @returns The intersection of two (multi)sets - */ - setIntersect(a1: T, a2: MathCollection): T - - /** - * Check whether a (multi)set is a subset of another (multi)set. (Every - * element of set1 is the element of set2.) Multi-dimension arrays will - * be converted to single-dimension arrays before the operation. - * @param a1 A (multi)set - * @param a2 A (multi)set - * @returns True if a1 is subset of a2, else false - */ - setIsSubset(a1: MathCollection, a2: MathCollection): boolean - - /** - * Count the multiplicity of an element in a multiset. A multi-dimension - * array will be converted to a single-dimension array before the - * operation. - * @param e An element in the multiset - * @param a A multiset - * @returns The number of how many times the multiset contains the - * element - */ - setMultiplicity(e: MathNumericType, a: MathCollection): number - - /** - * Create the powerset of a (multi)set. (The powerset contains very - * possible subsets of a (multi)set.) A multi-dimension array will be - * converted to a single-dimension array before the operation. - * @param a A multiset - * @returns The powerset of the (multi)set - */ - setPowerset(a: T): T - - /** - * Count the number of elements of a (multi)set. When a second parameter - * is ‘true’, count only the unique values. A multi-dimension array will - * be converted to a single-dimension array before the operation. - * @param a A multiset - * @returns The number of elements of the (multi)set - */ - setSize(a: MathCollection): number - - /** - * Create the symmetric difference of two (multi)sets. Multi-dimension - * arrays will be converted to single-dimension arrays before the - * operation. - * @param a1 A (multi)set - * @param a2 A (multi)set - * @returns The symmetric difference of two (multi)sets - */ - setSymDifference(a1: T, a2: MathCollection): T - - /** - * Create the union of two (multi)sets. Multi-dimension arrays will be - * converted to single-dimension arrays before the operation. - * @param a1 A (multi)set - * @param a2 A (multi)set - * @returns The union of two (multi)sets - */ - setUnion(a1: T, a2: MathCollection): T - - /************************************************************************* - * Signal functions - ************************************************************************/ - /** - * Compute the transfer function of a zero-pole-gain model. - * @param z Zeroes of the model - * @param p Poles of the model - * @param k Gain of the model - * @returns The transfer function as array of numerator and denominator - */ - zpk2tf(z: T, p: T, k?: number): T - - /** - * Calculates the frequency response of a filter given its numerator and denominator coefficients. - * @param b The numerator polynomial of the filter - * @param a The denominator polynomial of the filter - * @param w The range of frequencies in which the response is to be calculated - * @returns The frequency response - * - */ - freqz(b: T, a: T, w?: number | T): { w: T; h: T } - - /************************************************************************* - * Special functions - ************************************************************************/ - - /** - * Compute the erf function of a value using a rational Chebyshev - * approximations for different intervals of x. - * @param x A real number - * @returns The erf of x - */ - erf(x: T): NoLiteralType - - /** - * Compute the Riemann Zeta function of a value using an infinite series - * and Riemann's Functional equation. - * @param s A real, complex or BigNumber - * @returns The Riemann Zeta of s - */ - zeta(s: T): T - - /************************************************************************* - * Statistics functions - ************************************************************************/ - - /** - * Compute the median absolute deviation of a matrix or a list with - * values. The median absolute deviation is defined as the median of the - * absolute deviations from the median. - * @param array A single matrix or multiple scalar values. - * @returns The median absolute deviation - */ + options?: FormatOptions | number | ((item: any) => string), // eslint-disable-next-line @typescript-eslint/no-explicit-any - mad(array: MathCollection): any - - /** - * Compute the maximum value of a matrix or a list with values. In case - * of a multi dimensional array, the maximum of the flattened array will - * be calculated. When dim is provided, the maximum over the selected - * dimension will be calculated. Parameter dim is zero-based. - * @param args Multiple scalar values - * @returns The maximum value - */ - max(...args: T[]): T - /** - * @param args Multiple scalar values - * @returns The maximum value - */ - max(...args: MathScalarType[]): MathScalarType - /** - * @param A A single matrix - * @param dimension The maximum over the selected dimension - * @returns The maximum value - */ - max( - A: T[] | T[][], - dimension?: number | BigNumber - ): T - /** - * @param A A single matrix - * @param dimension The maximum over the selected dimension - * @returns The maximum value - */ - max(A: MathCollection, dimension?: number | BigNumber): MathScalarType - - /** - * Compute the mean value of matrix or a list with values. In case of a - * multi dimensional array, the mean of the flattened array will be - * calculated. When dim is provided, the maximum over the selected - * dimension will be calculated. Parameter dim is zero-based. - * @param args Multiple scalar values - * @returns The mean of all values - */ - mean(...args: T[]): T - /** - * @param args Multiple scalar values - * @returns The mean value - */ - mean(...args: MathScalarType[]): MathScalarType - /** - * @param A A single matrix - * @param dimension The mean over the selected dimension - * @returns The mean value - */ - mean( - A: T[] | T[][], - dimension?: number | BigNumber - ): T - /** - * @param A A single matrix - * @param dimension The mean over the selected dimension - * @returns The mean value - */ - mean(A: MathCollection, dimension?: number | BigNumber): MathScalarType - - /** - * Compute the median of a matrix or a list with values. The values are - * sorted and the middle value is returned. In case of an even number of - * values, the average of the two middle values is returned. Supported - * types of values are: Number, BigNumber, Unit In case of a (multi - * dimensional) array or matrix, the median of all elements will be - * calculated. - * @param args Multiple scalar values - * @returns The median value - */ - median(...args: T[]): T - /** - * @param args Multiple scalar values - * @returns The median value - */ - median(...args: MathScalarType[]): MathScalarType - /** - * @param A A single matrix - * @returns The median value - */ - median(A: T[] | T[][]): T - /** - * @param A A single matrix - * @returns The median value - */ - median(A: MathCollection): MathScalarType - - /** - * Compute the minimum value of a matrix or a list of values. In case of - * a multi dimensional array, the minimum of the flattened array will be - * calculated. When dim is provided, the minimum over the selected - * dimension will be calculated. Parameter dim is zero-based. - * @param args multiple scalar values - * @returns The minimum value - */ - min(...args: T[]): T - /** - * @param args Multiple scalar values - * @returns The minimum value - */ - min(...args: MathScalarType[]): MathScalarType - /** - * @param A A single matrix - * @param dimension The minimum over the selected dimension - * @returns The minimum value - */ - min( - A: T[] | T[][], - dimension?: number | BigNumber - ): T - /** - * @param A A single matrix - * @param dimension The minimum over the selected dimension - * @returns The minimum value - */ - min(A: MathCollection, dimension?: number | BigNumber): MathScalarType - - /** - * Computes the mode of a set of numbers or a list with values(numbers - * or characters). If there are more than one modes, it returns a list - * of those values. - * @param args Multiple scalar values - * @returns The mode of all values - */ - mode(...args: T[]): T - /** - * @param args Multiple scalar values - * @returns The mode of all values - */ - mode(...args: MathScalarType[]): MathScalarType - /** - * @param A A single matrix - * @returns The median value - */ - mode(A: T[] | T[][]): T - /** - * @param A A single matrix - * @returns The mode of all values - */ - mode(A: MathCollection): MathScalarType - - /** - * Compute the product of a matrix or a list with values. In case of a - * (multi dimensional) array or matrix, the sum of all elements will be - * calculated. - * @param args Multiple scalar values - * @returns The product of all values - */ - prod(...args: T[]): T - /** - * @param args Multiple scalar values - * @returns The product of all values - */ - prod(...args: MathScalarType[]): MathScalarType - /** - * @param A A single matrix - * @returns The product of all values - */ - prod(A: T[] | T[][]): T - /** - * @param A A single matrix - * @returns The product of all values - */ - prod(A: MathCollection): MathScalarType - - /** - * Compute the prob order quantile of a matrix or a list with values. - * The sequence is sorted and the middle value is returned. Supported - * types of sequence values are: Number, BigNumber, Unit Supported types - * of probability are: Number, BigNumber In case of a (multi - * dimensional) array or matrix, the prob order quantile of all elements - * will be calculated. - * @param A A single matrix or array - * @param probOrN prob is the order of the quantile, while N is the - * amount of evenly distributed steps of probabilities; only one of - * these options can be provided - * @param sorted =false is data sorted in ascending order - * @returns Quantile(s) - */ - quantileSeq( - A: MathCollection, - prob: number | BigNumber | MathArray, - sorted?: boolean - ): number | BigNumber | Unit | MathArray - - /** - * Compute the standard deviation of a matrix or a list with values. The - * standard deviations is defined as the square root of the variance: - * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or - * matrix, the standard deviation over all elements will be calculated. - * Optionally, the type of normalization can be specified as second - * parameter. The parameter normalization can be one of the following - * values: 'unbiased' (default) The sum of squared errors is divided by - * (n - 1) 'uncorrected' The sum of squared errors is divided by n - * 'biased' The sum of squared errors is divided by (n + 1) - * @param args variadic argument of number to calculate standard deviation - * @returns The standard deviation - */ - std(...args: T[]): T - /** - * @param args Multiple scalar values - * @returns The standard deviation - */ - std(...args: MathScalarType[]): MathScalarType - /** - * Compute the standard deviation of a matrix or a list with values. The - * standard deviations is defined as the square root of the variance: - * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or - * matrix, the standard deviation over all elements will be calculated. - * Optionally, the type of normalization can be specified as second - * parameter. The parameter normalization can be one of the following - * values: 'unbiased' (default) The sum of squared errors is divided by - * (n - 1) 'uncorrected' The sum of squared errors is divided by n - * 'biased' The sum of squared errors is divided by (n + 1) - * @param array A single matrix to compute standard deviation. - * @param dimension A dimension to calculate standard deviation - * @param normalization Determines how to normalize the variance. Choose - * ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: - * ‘unbiased’. - * @returns The standard deviation array - */ - std( - array: MathCollection, - dimension?: number, - normalization?: 'unbiased' | 'uncorrected' | 'biased' - ): MathNumericType[] - /** - * Compute the standard deviation of a matrix or a list with values. The - * standard deviations is defined as the square root of the variance: - * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or - * matrix, the standard deviation over all elements will be calculated. - * Optionally, the type of normalization can be specified as second - * parameter. The parameter normalization can be one of the following - * values: 'unbiased' (default) The sum of squared errors is divided by - * (n - 1) 'uncorrected' The sum of squared errors is divided by n - * 'biased' The sum of squared errors is divided by (n + 1) - * @param array A single matrix or multiple scalar values - * @param normalization Determines how to normalize the variance. Choose - * ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: - * ‘unbiased’. - * @returns The standard deviation - */ - std( - array: MathCollection, - normalization: 'unbiased' | 'uncorrected' | 'biased' - ): MathNumericType - - /** - * Compute the sum of a matrix or a list with values. In case of a - * (multi dimensional) array or matrix, the sum of all elements will be - * calculated. - * @param args A single matrix or multiple scalar values - * @returns The sum of all values - */ - sum(...args: T[]): T - /** - * @param args Multiple scalar values - * @returns The sum of all values - */ - sum(...args: MathScalarType[]): MathScalarType - /** - * @param A A single matrix - * @param dimension The sum over the selected dimension - * @returns The sum of all values - */ - sum( - A: T[] | T[][], - dimension?: number | BigNumber - ): T - /** - * @param A A single matrix - * @param dimension The sum over the selected dimension - * @returns The sum of all values - */ - sum(A: MathCollection, dimension?: number | BigNumber): MathScalarType - - /** - * Count the number of elements of a matrix, array or string. - * @param x A matrix, array or string. - * @returns The number of members passed in parameters - */ - count(x: MathCollection | string): number - - /** - * Compute the cumulative sum of a matrix or a list with values. - * In case of a (multi dimensional) array or matrix, the cumulative sums - * along a specified dimension (defaulting to the first) will be calculated. - * @param args A single matrix or multiple scalar values - * @returns The cumulative sums of the the values. - */ - cumsum(...args: MathType[]): MathType[] - /** - * @param array A single matrix - * @param dim The dimension along which to sum (defaults to 0) - * @returns The cumulative sums along the given dimension - */ - cumsum(array: MathCollection, dim?: number): MathCollection - - /** - * Compute the variance of a matrix or a list with values. In case of a - * (multi dimensional) array or matrix, the variance over all elements - * will be calculated. Optionally, the type of normalization can be - * specified as second parameter. The parameter normalization can be one - * of the following values: 'unbiased' (default) The sum of squared - * errors is divided by (n - 1) 'uncorrected' The sum of squared errors - * is divided by n 'biased' The sum of squared errors is divided by (n + - * 1) Note that older browser may not like the variable name var. In - * that case, the function can be called as math['var'](...) instead of - * math.variance(...). - * @param args A single matrix or multiple scalar values - * @returns The variance - */ - variance(...args: MathNumericType[]): MathNumericType - /** - * Compute the variance of a matrix or a list with values. In case of a - * (multi dimensional) array or matrix, the variance over all elements - * will be calculated. Optionally, the type of normalization can be - * specified as second parameter. The parameter normalization can be one - * of the following values: 'unbiased' (default) The sum of squared - * errors is divided by (n - 1) 'uncorrected' The sum of squared errors - * is divided by n 'biased' The sum of squared errors is divided by (n + - * 1) Note that older browser may not like the variable name var. In - * that case, the function can be called as math['var'](...) instead of - * math.variance(...). - * @param array A matrix to compute variance. - * @param dimension A dimension to compute variance on - * @param normalization normalization Determines how to normalize the - * variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. - * Default value: ‘unbiased’. - * @returns variance matrix. - */ - variance( - array: MathCollection, - dimension?: number, - normalization?: 'unbiased' | 'uncorrected' | 'biased' - ): MathNumericType[] - /** - * @param array A single matrix - * @param normalization normalization Determines how to normalize the - * variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. - * Default value: ‘unbiased’. - * @returns The variance - */ - variance( - array: MathCollection, - normalization: 'unbiased' | 'uncorrected' | 'biased' - ): MathNumericType - - /** - * Calculate the correlation coefficient between two matrix. - * @param {Array | Matrix} x The first array or matrix to compute correlation coefficient - * @param {Array | Matrix} y The second array or matrix to compute correlation coefficient - * @returns correlation coefficient - */ - corr(x: MathCollection, y: MathCollection): MathType - - /************************************************************************* - * String functions - ************************************************************************/ - - /** - * Format a value of any type into a string. - * @param value The value to be formatted - * @param options An object with formatting options. - * @param callback A custom formatting function, invoked for all numeric - * elements in value, for example all elements of a matrix, or the real - * and imaginary parts of a complex number. This callback can be used to - * override the built-in numeric notation with any type of formatting. - * Function callback is called with value as parameter and must return a - * string. - * @see http://mathjs.org/docs/reference/functions/format.html - * @returns The formatted value - */ - format( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - value: any, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - options?: FormatOptions | number | ((item: any) => string), - // eslint-disable-next-line @typescript-eslint/no-explicit-any - callback?: (value: any) => string - ): string - - /** - * Interpolate values into a string template. - * @param template A string containing variable placeholders. - * @param values An object containing variables which will be filled in - * in the template. - * @param precision Number of digits to format numbers. If not provided, - * the value will not be rounded. - * @param options Formatting options, or the number of digits to format - * numbers. See function math.format for a description of all options. - * @returns Interpolated string - */ - print( - template: string, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - values: any, - precision?: number, - options?: number | object - ): void - - /************************************************************************* - * Trigonometry functions - ************************************************************************/ - - /** - * Calculate the inverse cosine of a value. - * @param x Function input - * @returns The arc cosine of x - */ - acos(x: number): number | Complex - acos(x: T): T - - /** - * Calculate the hyperbolic arccos of a value, defined as acosh(x) = - * ln(sqrt(x^2 - 1) + x). - * @param x Function input - * @returns The hyperbolic arccosine of x - */ - acosh(x: number): number | Complex - acosh(x: T): T - - /** - * Calculate the inverse cotangent of a value. - * @param x Function input - * @returns The arc cotangent of x - */ - acot(x: number): number - acot(x: T): T - - /** - * Calculate the hyperbolic arccotangent of a value, defined as acoth(x) - * = (ln((x+1)/x) + ln(x/(x-1))) / 2. - * @param x Function input - * @returns The hyperbolic arccotangent of x - */ - acoth(x: number): number - acoth(x: T): T - - /** - * Calculate the inverse cosecant of a value. - * @param x Function input - * @returns The arc cosecant of x - */ - acsc(x: number): number | Complex - acsc(x: T): T - - /** - * Calculate the hyperbolic arccosecant of a value, defined as acsch(x) - * = ln(1/x + sqrt(1/x^2 + 1)). - * @param x Function input - * @returns The hyperbolic arccosecant of x - */ - acsch(x: number): number - acsch(x: T): T - - /** - * Calculate the inverse secant of a value. - * @param x Function input - * @returns The arc secant of x - */ - asec(x: number): number | Complex - asec(x: T): T - - /** - * Calculate the hyperbolic arcsecant of a value, defined as asech(x) = - * ln(sqrt(1/x^2 - 1) + 1/x). - * @param x Function input - * @returns The hyperbolic arcsecant of x - */ - asech(x: number): number | Complex - asech(x: T): T - - /** - * Calculate the inverse sine of a value. - * @param x Function input - * @returns The arc sine of x - */ - asin(x: number): number | Complex - asin(x: T): T - - /** - * Calculate the hyperbolic arcsine of a value, defined as asinh(x) = - * ln(x + sqrt(x^2 + 1)). - * @param x Function input - * @returns The hyperbolic arcsine of x - */ - asinh(x: T): T - - /** - * Calculate the inverse tangent of a value. - * @param x Function input - * @returns The arc tangent of x - */ - atan(x: T): T - - /** - * Calculate the inverse tangent function with two arguments, y/x. By - * providing two arguments, the right quadrant of the computed angle can - * be determined. For matrices, the function is evaluated element wise. - * @param x Function input - * @returns Four quadrant inverse tangent - */ - atan2(y: T, x: T): T - - /** - * Calculate the hyperbolic arctangent of a value, defined as atanh(x) = - * ln((1 + x)/(1 - x)) / 2. - * @param x Function input - * @returns The hyperbolic arctangent of x - */ - atanh(x: number): number | Complex - atanh(x: T): T - - /** - * Calculate the cosine of a value. - * @param x Function input - * @returns The cosine of x - */ - cos(x: number | Unit): number - cos(x: T): T - - /** - * Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2 - * * (exp(x) + exp(-x)). - * @param x Function input - * @returns The hyperbolic cosine of x - */ - cosh(x: number | Unit): number - cosh(x: T): T - - /** - * Calculate the cotangent of a value. cot(x) is defined as 1 / tan(x). - * @param x Function input - * @returns The cotangent of x - */ - cot(x: number | Unit): number - cot(x: T): T - - /** - * Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1 - * / tanh(x). - * @param x Function input - * @returns The hyperbolic cotangent of x - */ - coth(x: number | Unit): number - coth(x: T): T - - /** - * Calculate the cosecant of a value, defined as csc(x) = 1/sin(x). - * @param x Function input - * @returns The cosecant hof x - */ - csc(x: number | Unit): number - csc(x: T): T - - /** - * Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1 - * / sinh(x). - * @param x Function input - * @returns The hyperbolic cosecant of x - */ - csch(x: number | Unit): number - csch(x: T): T - - /** - * Calculate the secant of a value, defined as sec(x) = 1/cos(x). - * @param x Function input - * @returns The secant of x - */ - sec(x: number | Unit): number - sec(x: T): T - - /** - * Calculate the hyperbolic secant of a value, defined as sech(x) = 1 / - * cosh(x). - * @param x Function input - * @returns The hyperbolic secant of x - */ - sech(x: number | Unit): number - sech(x: T): T - - /** - * Calculate the sine of a value. - * @param x Function input - * @returns The sine of x - */ - sin(x: number | Unit): number - sin(x: T): T - - /** - * Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 * - * (exp(x) - exp(-x)). - * @param x Function input - * @returns The hyperbolic sine of x - */ - sinh(x: number | Unit): number - sinh(x: T): T - - /** - * Calculate the tangent of a value. tan(x) is equal to sin(x) / cos(x). - * @param x Function input - * @returns The tangent of x - */ - tan(x: number | Unit): number - tan(x: T): T - - /** - * Calculate the hyperbolic tangent of a value, defined as tanh(x) = - * (exp(2 * x) - 1) / (exp(2 * x) + 1). - * @param x Function input - * @returns The hyperbolic tangent of x - */ - tanh(x: number | Unit): number - tanh(x: T): T - - /************************************************************************* - * Unit functions - ************************************************************************/ - - /** - * Change the unit of a value. For matrices, the function is evaluated - * element wise. - * @param x The unit to be converted. - * @param unit New unit. Can be a string like "cm" or a unit without - * value. - * @returns Value with changed, fixed unit - */ - to(x: Unit | MathCollection, unit: Unit | string): Unit | MathCollection - - /************************************************************************* - * Utils - ************************************************************************/ - isNumber(x: unknown): x is number - - isBigNumber(x: unknown): x is BigNumber - - isComplex(x: unknown): x is Complex - - isFraction(x: unknown): x is Fraction - - isUnit(x: unknown): x is Unit - - isString(x: unknown): x is string - - isArray: ArrayConstructor['isArray'] - - isMatrix(x: unknown): x is Matrix + callback?: (value: any) => string + ): MathJsChain + /** + * Interpolate values into a string template. + * @param values An object containing variables which will be filled in + * in the template. + * @param precision Number of digits to format numbers. If not provided, + * the value will not be rounded. + * @param options Formatting options, or the number of digits to format + * numbers. See function math.format for a description of all options. + */ + print( + this: MathJsChain, // eslint-disable-next-line @typescript-eslint/no-explicit-any - isCollection(x: unknown): x is Matrix | any[] + values: any, + precision?: number, + options?: number | object + ): MathJsChain - isDenseMatrix(x: unknown): x is Matrix + /************************************************************************* + * Trigonometry functions + ************************************************************************/ - isSparseMatrix(x: unknown): x is Matrix + /** + * Calculate the inverse cosine of a value. For matrices, the function + * is evaluated element wise. + */ - isRange(x: unknown): boolean + acos( + this: MathJsChain + ): MathJsChain - isIndex(x: unknown): x is Index + /** + * Calculate the hyperbolic arccos of a value, defined as acosh(x) = + * ln(sqrt(x^2 - 1) + x). For matrices, the function is evaluated + * element wise. + */ - isBoolean(x: unknown): x is boolean + acosh( + this: MathJsChain + ): MathJsChain - isResultSet(x: unknown): boolean + /** + * Calculate the inverse cotangent of a value. For matrices, the + * function is evaluated element wise. + */ - isHelp(x: unknown): x is Help + acot( + this: MathJsChain + ): MathJsChain - isFunction(x: unknown): boolean + /** + * Calculate the hyperbolic arccotangent of a value, defined as acoth(x) + * = (ln((x+1)/x) + ln(x/(x-1))) / 2. For matrices, the function is + * evaluated element wise. + */ - isDate(x: unknown): x is Date + acoth( + this: MathJsChain + ): MathJsChain - isRegExp(x: unknown): x is RegExp + /** + * Calculate the inverse cosecant of a value. For matrices, the function + * is evaluated element wise. + */ - isObject(x: unknown): boolean + acsc( + this: MathJsChain + ): MathJsChain - isNull(x: unknown): x is null + /** + * Calculate the hyperbolic arccosecant of a value, defined as acsch(x) + * = ln(1/x + sqrt(1/x^2 + 1)). For matrices, the function is evaluated + * element wise. + */ - isUndefined(x: unknown): x is undefined + acsch( + this: MathJsChain + ): MathJsChain - isAccessorNode(x: unknown): x is AccessorNode + /** + * Calculate the inverse secant of a value. For matrices, the function + * is evaluated element wise. + */ - isArrayNode(x: unknown): x is ArrayNode + asec( + this: MathJsChain + ): MathJsChain - isAssignmentNode(x: unknown): x is AssignmentNode + /** + * Calculate the hyperbolic arcsecant of a value, defined as asech(x) = + * ln(sqrt(1/x^2 - 1) + 1/x). For matrices, the function is evaluated + * element wise. + */ - isBlockNode(x: unknown): x is BlockNode + asech( + this: MathJsChain + ): MathJsChain - isConditionalNode(x: unknown): x is ConditionalNode + /** + * Calculate the inverse sine of a value. For matrices, the function is + * evaluated element wise. + */ - isConstantNode(x: unknown): x is ConstantNode + asin( + this: MathJsChain + ): MathJsChain - isFunctionAssignmentNode(x: unknown): x is FunctionAssignmentNode + /** + * Calculate the hyperbolic arcsine of a value, defined as asinh(x) = + * ln(x + sqrt(x^2 + 1)). For matrices, the function is evaluated + * element wise. + */ - isFunctionNode(x: unknown): x is FunctionNode + asinh( + this: MathJsChain + ): MathJsChain - isIndexNode(x: unknown): x is IndexNode + /** + * Calculate the inverse tangent of a value. For matrices, the function + * is evaluated element wise. + */ - isNode(x: unknown): x is MathNode + atan( + this: MathJsChain + ): MathJsChain - isObjectNode(x: unknown): x is ObjectNode + /** + * Calculate the inverse tangent function with two arguments, y/x. By + * providing two arguments, the right quadrant of the computed angle can + * be determined. For matrices, the function is evaluated element wise. + */ - isOperatorNode( - x: unknown - ): x is OperatorNode + atan2( + this: MathJsChain, + x: number + ): MathJsChain - isParenthesisNode(x: unknown): x is ParenthesisNode + /** + * Calculate the hyperbolic arctangent of a value, defined as atanh(x) = + * ln((1 + x)/(1 - x)) / 2. For matrices, the function is evaluated + * element wise. + */ - isRangeNode(x: unknown): x is RangeNode + atanh( + this: MathJsChain + ): MathJsChain - isRelationalNode(x: unknown): x is RelationalNode + /** + * Calculate the cosine of a value. For matrices, the function is + * evaluated element wise. + */ - isSymbolNode(x: unknown): x is SymbolNode + cos( + this: MathJsChain + ): MathJsChain - isChain(x: unknown): x is MathJsChain + /** + * Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2 + * * (exp(x) + exp(-x)). For matrices, the function is evaluated element + * wise. + */ - /************************************************************************* - * Functions -> Utils - ************************************************************************/ + cosh( + this: MathJsChain + ): MathJsChain - /** - * Clone an object. - * @param x Object to be cloned - * @returns A clone of object x - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - clone(x: TType): TType - - /** - * Test whether a value is an numeric value. In case of a string, - * true is returned if the string contains a numeric value. - * @param x Value to be tested - * @returns Returns true when x is a number, BigNumber, Fraction, Boolean, or a String containing number. - * Returns false for other types. - * Throws an error in case of unknown types. - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - hasNumericValue(x: any): boolean | boolean[] - - /** - * Test whether a value is an integer number. The function supports - * number, BigNumber, and Fraction. The function is evaluated - * element-wise in case of Array or Matrix input. - * @param x Value to be tested - * @returns Returns true when x contains a numeric, integer value. - * Throws an error in case of an unknown data type. - */ - isInteger(x: number | BigNumber | Fraction | MathCollection): boolean - - /** - * Test whether a value is NaN (not a number). The function supports - * types number, BigNumber, Fraction, Unit and Complex. The function is - * evaluated element-wise in case of Array or Matrix input. - * @param x Value to be tested - * @returns Returns true when x is NaN. Throws an error in case of an - * unknown data type. - */ - isNaN(x: number | BigNumber | Fraction | MathCollection | Unit): boolean - - /** - * Test whether a value is negative: smaller than zero. The function - * supports types number, BigNumber, Fraction, and Unit. The function is - * evaluated element-wise in case of Array or Matrix input. - * @param x Value to be tested - * @returns Returns true when x is larger than zero. Throws an error in - * case of an unknown data type. - */ - isNegative( - x: number | BigNumber | Fraction | MathCollection | Unit - ): boolean - - /** - * Test whether a value is an numeric value. The function is evaluated - * element-wise in case of Array or Matrix input. - * @param x Value to be tested - * @returns Returns true when x is a number, BigNumber, Fraction, or - * boolean. Returns false for other types. Throws an error in case of - * unknown types. - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - isNumeric(x: any): x is number | BigNumber | Fraction | boolean - - /** - * Test whether a value is positive: larger than zero. The function - * supports types number, BigNumber, Fraction, and Unit. The function is - * evaluated element-wise in case of Array or Matrix input. - * @param x Value to be tested - * @returns Returns true when x is larger than zero. Throws an error in - * case of an unknown data type. - */ - isPositive( - x: number | BigNumber | Fraction | MathCollection | Unit - ): boolean - - /** - * Test whether a value is prime: has no divisors other than itself and - * one. The function supports type number, bignumber. The function is - * evaluated element-wise in case of Array or Matrix input. - * @param x Value to be tested - * @returns Returns true when x is larger than zero. Throws an error in - * case of an unknown data type. - */ - isPrime(x: number | BigNumber | MathCollection): boolean - - /** - * Test whether a value is zero. The function can check for zero for - * types number, BigNumber, Fraction, Complex, and Unit. The function is - * evaluated element-wise in case of Array or Matrix input. - * @param x Value to be tested - * @returns Returns true when x is zero. Throws an error in case of an - * unknown data type. - */ - isZero(x: MathType): boolean - - /** - * Determine the type of a variable. - * @param x The variable for which to test the type - * @returns Returns the name of the type. Primitive types are lower - * case, non-primitive types are upper-camel-case. For example ‘number’, - * ‘string’, ‘Array’, ‘Date’. - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - typeOf(x: any): string - - /** - * Import functions from an object or a module - * To avoid errors when using one of the imported functions extend module like this: - * - * @example - * // imported_math_functions.ts - * declare module 'mathjs' { - * interface MathJsStatic { - * hello(a: number): number; - * } - * } - * - * @param object An object with functions to be imported. - * @param options An object with import options. - */ - import(object: ImportObject | ImportObject[], options?: ImportOptions): void - } + /** + * Calculate the cotangent of a value. cot(x) is defined as 1 / tan(x). + * For matrices, the function is evaluated element wise. + */ - /************************************************************************* - * Factory and Dependencies - ************************************************************************/ - interface FactoryDependencies { - create: ( - factories: FactoryFunctionMap, - config?: ConfigOptions - ) => MathJsStatic - factory: ( - name: string, - dependencies: TDeps, - create: ( - injected: Pick> - ) => T, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - meta?: any - ) => FactoryFunction - all: FactoryFunctionMap - - typedDependencies: FactoryFunctionMap - ResultSetDependencies: FactoryFunctionMap - BigNumberDependencies: FactoryFunctionMap - ComplexDependencies: FactoryFunctionMap - FractionDependencies: FactoryFunctionMap - RangeDependencies: FactoryFunctionMap - MatrixDependencies: FactoryFunctionMap - DenseMatrixDependencies: FactoryFunctionMap - cloneDependencies: FactoryFunctionMap - isIntegerDependencies: FactoryFunctionMap - isNegativeDependencies: FactoryFunctionMap - isNumericDependencies: FactoryFunctionMap - hasNumericValueDependencies: FactoryFunctionMap - isPositiveDependencies: FactoryFunctionMap - isZeroDependencies: FactoryFunctionMap - isNaNDependencies: FactoryFunctionMap - typeOfDependencies: FactoryFunctionMap - typeofDependencies: FactoryFunctionMap - equalScalarDependencies: FactoryFunctionMap - SparseMatrixDependencies: FactoryFunctionMap - numberDependencies: FactoryFunctionMap - stringDependencies: FactoryFunctionMap - booleanDependencies: FactoryFunctionMap - bignumberDependencies: FactoryFunctionMap - complexDependencies: FactoryFunctionMap - fractionDependencies: FactoryFunctionMap - matrixDependencies: FactoryFunctionMap - splitUnitDependencies: FactoryFunctionMap - unaryMinusDependencies: FactoryFunctionMap - unaryPlusDependencies: FactoryFunctionMap - absDependencies: FactoryFunctionMap - applyDependencies: FactoryFunctionMap - addScalarDependencies: FactoryFunctionMap - cbrtDependencies: FactoryFunctionMap - ceilDependencies: FactoryFunctionMap - cubeDependencies: FactoryFunctionMap - expDependencies: FactoryFunctionMap - expm1Dependencies: FactoryFunctionMap - fixDependencies: FactoryFunctionMap - floorDependencies: FactoryFunctionMap - gcdDependencies: FactoryFunctionMap - lcmDependencies: FactoryFunctionMap - log10Dependencies: FactoryFunctionMap - log2Dependencies: FactoryFunctionMap - modDependencies: FactoryFunctionMap - multiplyScalarDependencies: FactoryFunctionMap - multiplyDependencies: FactoryFunctionMap - nthRootDependencies: FactoryFunctionMap - signDependencies: FactoryFunctionMap - sqrtDependencies: FactoryFunctionMap - squareDependencies: FactoryFunctionMap - subtractDependencies: FactoryFunctionMap - xgcdDependencies: FactoryFunctionMap - dotMultiplyDependencies: FactoryFunctionMap - bitAndDependencies: FactoryFunctionMap - bitNotDependencies: FactoryFunctionMap - bitOrDependencies: FactoryFunctionMap - bitXorDependencies: FactoryFunctionMap - argDependencies: FactoryFunctionMap - conjDependencies: FactoryFunctionMap - imDependencies: FactoryFunctionMap - reDependencies: FactoryFunctionMap - notDependencies: FactoryFunctionMap - orDependencies: FactoryFunctionMap - xorDependencies: FactoryFunctionMap - concatDependencies: FactoryFunctionMap - columnDependencies: FactoryFunctionMap - crossDependencies: FactoryFunctionMap - diagDependencies: FactoryFunctionMap - eyeDependencies: FactoryFunctionMap - filterDependencies: FactoryFunctionMap - flattenDependencies: FactoryFunctionMap - forEachDependencies: FactoryFunctionMap - getMatrixDataTypeDependencies: FactoryFunctionMap - identityDependencies: FactoryFunctionMap - kronDependencies: FactoryFunctionMap - mapDependencies: FactoryFunctionMap - onesDependencies: FactoryFunctionMap - rangeDependencies: FactoryFunctionMap - reshapeDependencies: FactoryFunctionMap - resizeDependencies: FactoryFunctionMap - rowDependencies: FactoryFunctionMap - sizeDependencies: FactoryFunctionMap - squeezeDependencies: FactoryFunctionMap - subsetDependencies: FactoryFunctionMap - transposeDependencies: FactoryFunctionMap - ctransposeDependencies: FactoryFunctionMap - zerosDependencies: FactoryFunctionMap - erfDependencies: FactoryFunctionMap - modeDependencies: FactoryFunctionMap - prodDependencies: FactoryFunctionMap - formatDependencies: FactoryFunctionMap - printDependencies: FactoryFunctionMap - toDependencies: FactoryFunctionMap - isPrimeDependencies: FactoryFunctionMap - numericDependencies: FactoryFunctionMap - divideScalarDependencies: FactoryFunctionMap - powDependencies: FactoryFunctionMap - roundDependencies: FactoryFunctionMap - logDependencies: FactoryFunctionMap - log1pDependencies: FactoryFunctionMap - nthRootsDependencies: FactoryFunctionMap - dotPowDependencies: FactoryFunctionMap - dotDivideDependencies: FactoryFunctionMap - lsolveDependencies: FactoryFunctionMap - usolveDependencies: FactoryFunctionMap - leftShiftDependencies: FactoryFunctionMap - rightArithShiftDependencies: FactoryFunctionMap - rightLogShiftDependencies: FactoryFunctionMap - andDependencies: FactoryFunctionMap - compareDependencies: FactoryFunctionMap - compareNaturalDependencies: FactoryFunctionMap - compareTextDependencies: FactoryFunctionMap - equalDependencies: FactoryFunctionMap - equalTextDependencies: FactoryFunctionMap - smallerDependencies: FactoryFunctionMap - smallerEqDependencies: FactoryFunctionMap - largerDependencies: FactoryFunctionMap - largerEqDependencies: FactoryFunctionMap - deepEqualDependencies: FactoryFunctionMap - unequalDependencies: FactoryFunctionMap - partitionSelectDependencies: FactoryFunctionMap - sortDependencies: FactoryFunctionMap - maxDependencies: FactoryFunctionMap - minDependencies: FactoryFunctionMap - ImmutableDenseMatrixDependencies: FactoryFunctionMap - IndexDependencies: FactoryFunctionMap - FibonacciHeapDependencies: FactoryFunctionMap - SpaDependencies: FactoryFunctionMap - UnitDependencies: FactoryFunctionMap - unitDependencies: FactoryFunctionMap - sparseDependencies: FactoryFunctionMap - createUnitDependencies: FactoryFunctionMap - acosDependencies: FactoryFunctionMap - acoshDependencies: FactoryFunctionMap - acotDependencies: FactoryFunctionMap - acothDependencies: FactoryFunctionMap - acscDependencies: FactoryFunctionMap - acschDependencies: FactoryFunctionMap - asecDependencies: FactoryFunctionMap - asechDependencies: FactoryFunctionMap - asinDependencies: FactoryFunctionMap - asinhDependencies: FactoryFunctionMap - atanDependencies: FactoryFunctionMap - atan2Dependencies: FactoryFunctionMap - atanhDependencies: FactoryFunctionMap - cosDependencies: FactoryFunctionMap - coshDependencies: FactoryFunctionMap - cotDependencies: FactoryFunctionMap - cothDependencies: FactoryFunctionMap - cscDependencies: FactoryFunctionMap - cschDependencies: FactoryFunctionMap - secDependencies: FactoryFunctionMap - sechDependencies: FactoryFunctionMap - sinDependencies: FactoryFunctionMap - sinhDependencies: FactoryFunctionMap - tanDependencies: FactoryFunctionMap - tanhDependencies: FactoryFunctionMap - setCartesianDependencies: FactoryFunctionMap - setDifferenceDependencies: FactoryFunctionMap - setDistinctDependencies: FactoryFunctionMap - setIntersectDependencies: FactoryFunctionMap - setIsSubsetDependencies: FactoryFunctionMap - setMultiplicityDependencies: FactoryFunctionMap - setPowersetDependencies: FactoryFunctionMap - setSizeDependencies: FactoryFunctionMap - setSymDifferenceDependencies: FactoryFunctionMap - setUnionDependencies: FactoryFunctionMap - zpk2tfDependencies: FactoryFunctionMap - freqzDependencies: FactoryFunctionMap - addDependencies: FactoryFunctionMap - hypotDependencies: FactoryFunctionMap - normDependencies: FactoryFunctionMap - dotDependencies: FactoryFunctionMap - traceDependencies: FactoryFunctionMap - indexDependencies: FactoryFunctionMap - NodeDependencies: FactoryFunctionMap - AccessorNodeDependencies: FactoryFunctionMap - ArrayNodeDependencies: FactoryFunctionMap - AssignmentNodeDependencies: FactoryFunctionMap - BlockNodeDependencies: FactoryFunctionMap - ConditionalNodeDependencies: FactoryFunctionMap - ConstantNodeDependencies: FactoryFunctionMap - FunctionAssignmentNodeDependencies: FactoryFunctionMap - IndexNodeDependencies: FactoryFunctionMap - ObjectNodeDependencies: FactoryFunctionMap - OperatorNodeDependencies: FactoryFunctionMap - ParenthesisNodeDependencies: FactoryFunctionMap - RangeNodeDependencies: FactoryFunctionMap - RelationalNodeDependencies: FactoryFunctionMap - SymbolNodeDependencies: FactoryFunctionMap - FunctionNodeDependencies: FactoryFunctionMap - parseDependencies: FactoryFunctionMap - compileDependencies: FactoryFunctionMap - evaluateDependencies: FactoryFunctionMap - evalDependencies: FactoryFunctionMap - ParserDependencies: FactoryFunctionMap - parserDependencies: FactoryFunctionMap - lupDependencies: FactoryFunctionMap - qrDependencies: FactoryFunctionMap - sluDependencies: FactoryFunctionMap - lusolveDependencies: FactoryFunctionMap - HelpDependencies: FactoryFunctionMap - ChainDependencies: FactoryFunctionMap - helpDependencies: FactoryFunctionMap - chainDependencies: FactoryFunctionMap - detDependencies: FactoryFunctionMap - invDependencies: FactoryFunctionMap - expmDependencies: FactoryFunctionMap - sqrtmDependencies: FactoryFunctionMap - sylvesterDependencies: FactoryFunctionMap - schurDependencies: FactoryFunctionMap - lyapDependencies: FactoryFunctionMap - divideDependencies: FactoryFunctionMap - distanceDependencies: FactoryFunctionMap - intersectDependencies: FactoryFunctionMap - sumDependencies: FactoryFunctionMap - meanDependencies: FactoryFunctionMap - medianDependencies: FactoryFunctionMap - madDependencies: FactoryFunctionMap - varianceDependencies: FactoryFunctionMap - varDependencies: FactoryFunctionMap - quantileSeqDependencies: FactoryFunctionMap - stdDependencies: FactoryFunctionMap - combinationsDependencies: FactoryFunctionMap - gammaDependencies: FactoryFunctionMap - factorialDependencies: FactoryFunctionMap - kldivergenceDependencies: FactoryFunctionMap - multinomialDependencies: FactoryFunctionMap - permutationsDependencies: FactoryFunctionMap - pickRandomDependencies: FactoryFunctionMap - randomDependencies: FactoryFunctionMap - randomIntDependencies: FactoryFunctionMap - stirlingS2Dependencies: FactoryFunctionMap - bellNumbersDependencies: FactoryFunctionMap - catalanDependencies: FactoryFunctionMap - compositionDependencies: FactoryFunctionMap - simplifyDependencies: FactoryFunctionMap - derivativeDependencies: FactoryFunctionMap - rationalizeDependencies: FactoryFunctionMap - reviverDependencies: FactoryFunctionMap - eDependencies: FactoryFunctionMap - EDependencies: FactoryFunctionMap - falseDependencies: FactoryFunctionMap - iDependencies: FactoryFunctionMap - InfinityDependencies: FactoryFunctionMap - LN10Dependencies: FactoryFunctionMap - LN2Dependencies: FactoryFunctionMap - LOG10EDependencies: FactoryFunctionMap - LOG2EDependencies: FactoryFunctionMap - NaNDependencies: FactoryFunctionMap - nullDependencies: FactoryFunctionMap - phiDependencies: FactoryFunctionMap - piDependencies: FactoryFunctionMap - PIDependencies: FactoryFunctionMap - SQRT1_2Dependencies: FactoryFunctionMap - SQRT2Dependencies: FactoryFunctionMap - tauDependencies: FactoryFunctionMap - trueDependencies: FactoryFunctionMap - versionDependencies: FactoryFunctionMap - atomicMassDependencies: FactoryFunctionMap - avogadroDependencies: FactoryFunctionMap - bohrMagnetonDependencies: FactoryFunctionMap - bohrRadiusDependencies: FactoryFunctionMap - boltzmannDependencies: FactoryFunctionMap - classicalElectronRadiusDependencies: FactoryFunctionMap - conductanceQuantumDependencies: FactoryFunctionMap - coulombDependencies: FactoryFunctionMap - deuteronMassDependencies: FactoryFunctionMap - efimovFactorDependencies: FactoryFunctionMap - electricConstantDependencies: FactoryFunctionMap - electronMassDependencies: FactoryFunctionMap - elementaryChargeDependencies: FactoryFunctionMap - faradayDependencies: FactoryFunctionMap - fermiCouplingDependencies: FactoryFunctionMap - fineStructureDependencies: FactoryFunctionMap - firstRadiationDependencies: FactoryFunctionMap - gasConstantDependencies: FactoryFunctionMap - gravitationConstantDependencies: FactoryFunctionMap - gravityDependencies: FactoryFunctionMap - hartreeEnergyDependencies: FactoryFunctionMap - inverseConductanceQuantumDependencies: FactoryFunctionMap - klitzingDependencies: FactoryFunctionMap - loschmidtDependencies: FactoryFunctionMap - magneticConstantDependencies: FactoryFunctionMap - magneticFluxQuantumDependencies: FactoryFunctionMap - molarMassDependencies: FactoryFunctionMap - molarMassC12Dependencies: FactoryFunctionMap - molarPlanckConstantDependencies: FactoryFunctionMap - molarVolumeDependencies: FactoryFunctionMap - neutronMassDependencies: FactoryFunctionMap - nuclearMagnetonDependencies: FactoryFunctionMap - planckChargeDependencies: FactoryFunctionMap - planckConstantDependencies: FactoryFunctionMap - planckLengthDependencies: FactoryFunctionMap - planckMassDependencies: FactoryFunctionMap - planckTemperatureDependencies: FactoryFunctionMap - planckTimeDependencies: FactoryFunctionMap - protonMassDependencies: FactoryFunctionMap - quantumOfCirculationDependencies: FactoryFunctionMap - reducedPlanckConstantDependencies: FactoryFunctionMap - rydbergDependencies: FactoryFunctionMap - sackurTetrodeDependencies: FactoryFunctionMap - secondRadiationDependencies: FactoryFunctionMap - speedOfLightDependencies: FactoryFunctionMap - stefanBoltzmannDependencies: FactoryFunctionMap - thomsonCrossSectionDependencies: FactoryFunctionMap - vacuumImpedanceDependencies: FactoryFunctionMap - weakMixingAngleDependencies: FactoryFunctionMap - wienDisplacementDependencies: FactoryFunctionMap - applyTransformDependencies: FactoryFunctionMap - columnTransformDependencies: FactoryFunctionMap - filterTransformDependencies: FactoryFunctionMap - forEachTransformDependencies: FactoryFunctionMap - indexTransformDependencies: FactoryFunctionMap - mapTransformDependencies: FactoryFunctionMap - maxTransformDependencies: FactoryFunctionMap - meanTransformDependencies: FactoryFunctionMap - minTransformDependencies: FactoryFunctionMap - rangeTransformDependencies: FactoryFunctionMap - rowTransformDependencies: FactoryFunctionMap - subsetTransformDependencies: FactoryFunctionMap - concatTransformDependencies: FactoryFunctionMap - stdTransformDependencies: FactoryFunctionMap - sumTransformDependencies: FactoryFunctionMap - varianceTransformDependencies: FactoryFunctionMap - } + cot( + this: MathJsChain + ): MathJsChain - interface Matrix { - type: string - storage(): string - datatype(): string - create(data: MathArray, datatype?: string): void - density(): number - // eslint-disable-next-line @typescript-eslint/no-explicit-any - subset(index: Index, replacement?: any, defaultValue?: any): Matrix - apply( - dim: number, - callback: (array: MathCollection) => number - ): MathCollection - // eslint-disable-next-line @typescript-eslint/no-explicit-any - get(index: number[]): any - // eslint-disable-next-line @typescript-eslint/no-explicit-any - set(index: number[], value: any, defaultValue?: number | string): Matrix - resize(size: MathCollection, defaultValue?: number | string): Matrix - clone(): Matrix - size(): number[] - map( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - callback: (a: any, b: number[], c: Matrix) => any, - skipZeros?: boolean - ): Matrix - forEach( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - callback: (a: any, b: number[], c: Matrix) => void, - skipZeros?: boolean - ): void - toArray(): MathArray - valueOf(): MathArray - // eslint-disable-next-line @typescript-eslint/no-explicit-any - format(options?: FormatOptions | number | ((value: any) => string)): string - toString(): string - // eslint-disable-next-line @typescript-eslint/no-explicit-any - toJSON(): any - // eslint-disable-next-line @typescript-eslint/no-explicit-any - diagonal(k?: number | BigNumber): any[] - swapRows(i: number, j: number): Matrix - } + /** + * Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1 + * / tanh(x). For matrices, the function is evaluated element wise. + */ - interface MatrixCtor { - new (): Matrix - } + coth( + this: MathJsChain + ): MathJsChain - // eslint-disable-next-line @typescript-eslint/no-empty-interface - interface BigNumber extends Decimal {} + /** + * Calculate the cosecant of a value, defined as csc(x) = 1/sin(x). For + * matrices, the function is evaluated element wise. + */ - interface Fraction { - s: number - n: number - d: number - } + csc( + this: MathJsChain + ): MathJsChain - interface Complex { - re: number - im: number - clone(): Complex - equals(other: Complex): boolean - format(precision?: number): string - fromJSON(json: object): Complex - fromPolar(polar: object): Complex - fromPolar(r: number, phi: number): Complex - toJSON(): object - toPolar(): PolarCoordinates - toString(): string - compare(a: Complex, b: Complex): number - } + /** + * Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1 + * / sinh(x). For matrices, the function is evaluated element wise. + */ - interface PolarCoordinates { - r: number - phi: number - } + csch( + this: MathJsChain + ): MathJsChain - interface MathJSON { - mathjs?: string - value: number - unit: string - fixPrefix?: boolean - } + /** + * Calculate the secant of a value, defined as sec(x) = 1/cos(x). For + * matrices, the function is evaluated element wise. + */ - interface UnitComponent { - power: number - prefix: string - unit: { - name: string - base: { - dimensions: number[] - key: string - } - prefixes: Record - value: number - offset: number - dimensions: number[] - } - } + sec( + this: MathJsChain + ): MathJsChain - interface UnitPrefix { - name: string - value: number - scientific: boolean - } + /** + * Calculate the hyperbolic secant of a value, defined as sech(x) = 1 / + * cosh(x). For matrices, the function is evaluated element wise. + */ - interface Unit { - valueOf(): string - clone(): Unit - // eslint-disable-next-line @typescript-eslint/no-explicit-any - hasBase(base: any): boolean - equalBase(unit: Unit): boolean - equals(unit: Unit): boolean - multiply(unit: Unit): Unit - divide(unit: Unit): Unit | number - pow(unit: Unit): Unit - abs(unit: Unit): Unit - to(unit: string): Unit - toNumber(unit?: string): number - toNumeric(unit?: string): number | Fraction | BigNumber - toSI(): Unit - toString(): string - toJSON(): MathJSON - formatUnits(): string - format(options: FormatOptions): string - simplify(): Unit - splitUnit(parts: ReadonlyArray): Unit[] - - units: UnitComponent[] - dimensions: number[] - value: number - fixPrefix: boolean - skipAutomaticSimplification: true - } + sech( + this: MathJsChain + ): MathJsChain - interface CreateUnitOptions { - prefixes?: 'none' | 'short' | 'long' | 'binary_short' | 'binary_long' - aliases?: string[] - offset?: number - override?: boolean - } + /** + * Calculate the sine of a value. For matrices, the function is + * evaluated element wise. + */ - type SimplifyContext = Partial< - Record< - OperatorNodeFn, - { - trivial: boolean - total: boolean - commutative: boolean - associative: boolean - } - > - > + sin( + this: MathJsChain + ): MathJsChain - interface SimplifyOptions { - /** A boolean which is `true` by default. */ - exactFractions?: boolean - /** - * When `exactFractions` is true, a fraction will be returned only - * when both numerator and denominator are smaller than `fractionsLimit`. - * Default value is 10000. - */ - fractionsLimit?: number - /** A boolean which is `false` by default. */ - consoleDebug?: boolean - /** - * gives properties of each operator, which determine what simplifications - * are allowed. Properties are commutative, associative, total (whether - * the operation is defined for all arguments), and trivial (whether - * the operation applied to a single argument leaves that argument - * unchanged). - */ - context?: SimplifyContext - } + /** + * Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 * + * (exp(x) - exp(-x)). For matrices, the function is evaluated element + * wise. + */ - type SimplifyRule = - | { - l: string - r: string - repeat?: boolean - assuming?: SimplifyContext - imposeContext?: SimplifyContext - } - | { - s: string - repeat?: boolean - assuming?: SimplifyContext - imposeContext?: SimplifyContext - } - | string - | ((node: MathNode) => MathNode) - - interface Simplify { - (expr: MathNode | string): MathNode - ( - expr: MathNode | string, - rules: SimplifyRule[], - scope?: object, - options?: SimplifyOptions - ): MathNode - ( - expr: MathNode | string, - scope: object, - options?: SimplifyOptions - ): MathNode - - rules: SimplifyRule[] - } + sinh( + this: MathJsChain + ): MathJsChain - interface UnitDefinition { - definition?: string | Unit - prefixes?: string - offset?: number - aliases?: string[] - baseName?: string - } + /** + * Calculate the tangent of a value. tan(x) is equal to sin(x) / cos(x). + * For matrices, the function is evaluated element wise. + */ - // eslint-disable-next-line @typescript-eslint/no-empty-interface - interface Index {} + tan( + this: MathJsChain + ): MathJsChain - interface EvalFunction { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - evaluate(scope?: any): any - } + /** + * Calculate the hyperbolic tangent of a value, defined as tanh(x) = + * (exp(2 * x) - 1) / (exp(2 * x) + 1). For matrices, the function is + * evaluated element wise. + */ - interface MathNode { - isNode: true - comment: string - type: string - - isUpdateNode?: boolean - - /** - * Create a shallow clone of the node. The node itself is cloned, its - * childs are not cloned. - */ - clone(): this - /** - * Create a deep clone of the node. Both the node as well as all its - * childs are cloned recursively. - */ - cloneDeep(): this - /** - * Compile an expression into optimized JavaScript code. compile returns - * an object with a function evaluate([scope]) to evaluate. Example: - */ - compile(): EvalFunction - /** - * Compile and eval an expression, this is the equivalent of doing - * node.compile().evaluate(scope). Example: - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - evaluate(expr?: any): any - /** - * Test whether this node equals an other node. Does a deep comparison - * of the values of both nodes. - */ - equals(other: MathNode): boolean - /** - * - * Filter nodes in an expression tree. The callback function is called - * as callback(node: MathNode, path: string, parent: MathNode) : boolean - * for every node in the tree, and must return a boolean. The function - * filter returns an array with nodes for which the test returned true. - * Parameter path is a string containing a relative JSON Path. - * - * Example: - * - * ``` - * var node = math.parse('x^2 + x/4 + 3*y'); - * var filtered = node.filter(function (node) { - * return node.isSymbolMathNode && node.name == 'x'; - * }); - * // returns an array with two entries: two SymbolMathNodes 'x' - * ``` - * - * The callback function is called as callback(node: MathNode, path: - * string, parent: MathNode) : boolean for every node in the tree, and - * must return a boolean. The function filter returns an array with - * nodes for which the test returned true. Parameter path is a string - * containing a relative JSON Path. - * @return Returns an array with nodes for which test returned true - */ - filter( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - callback: (node: MathNode, path: string, parent: MathNode) => any - ): MathNode[] - - /** - * [forEach description] - */ - forEach( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - callback: (node: MathNode, path: string, parent: MathNode) => void - ): void - - /** - * Transform a node. Creates a new MathNode having it’s child's be the - * results of calling the provided callback function for each of the - * child's of the original node. The callback function is called as - * `callback(child: MathNode, path: string, parent: MathNode)` and must - * return a MathNode. Parameter path is a string containing a relative - * JSON Path. - * - * - * See also transform, which is a recursive version of map. - */ - map( - callback: (node: MathNode, path: string, parent: MathNode) => MathNode - ): MathNode - - /** - * Get a HTML representation of the parsed expression. - */ - toHTML(options?: object): string - - /** - * Get a string representation of the parsed expression. This is not - * exactly the same as the original input. - */ - toString(options?: object): string - - /** - * Get a LaTeX representation of the expression. - */ - toTex(options?: object): string - - /** - * Recursively transform an expression tree via a transform function. - * Similar to Array.map, but recursively executed on all nodes in the - * expression tree. The callback function is a mapping function - * accepting a node, and returning a replacement for the node or the - * original node. Function callback is called as callback(node: - * MathNode, path: string, parent: MathNode) for every node in the tree, - * and must return a MathNode. Parameter path is a string containing a - * relative JSON Path. - * - * For example, to replace all nodes of type SymbolMathNode having name - * ‘x’ with a ConstantMathNode with value 3: - * ```js - * var node = math.parse('x^2 + 5*x'); - * var transformed = node.transform(function (node, path, parent) { - * if (node.SymbolMathNode && node.name == 'x') { - * return new math.expression.node.ConstantMathNode(3); - * } - * else { - * return node; - * } - * }); - * transformed.toString(); // returns '(3 ^ 2) + (5 * 3)' - * ``` - */ - transform( - callback: (node: this, path: string, parent: MathNode) => TResult - ): TResult - - /** - * `traverse(callback)` - * - * Recursively traverse all nodes in a node tree. Executes given - * callback for this node and each of its child nodes. Similar to - * Array.forEach, except recursive. The callback function is a mapping - * function accepting a node, and returning a replacement for the node - * or the original node. Function callback is called as callback(node: - * MathNode, path: string, parent: MathNode) for every node in the tree. - * Parameter path is a string containing a relative JSON Path. Example: - * - * ``` - * var node = math.parse('3 * x + 2'); - * node.traverse(function (node, path, parent) { - * switch (node.type) { - * case 'OperatorMathNode': console.log(node.type, node.op); break; - * case 'ConstantMathNode': console.log(node.type, node.value); break; - * case 'SymbolMathNode': console.log(node.type, node.name); break; - * default: console.log(node.type); - * } - * }); - * // outputs: - * // OperatorMathNode + - * // OperatorMathNode * - * // ConstantMathNode 3 - * // SymbolMathNode x - * // ConstantMathNode 2 - * ``` - */ - traverse( - callback: (node: MathNode, path: string, parent: MathNode) => void - ): void - } + tanh( + this: MathJsChain + ): MathJsChain - interface Parser { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - evaluate(expr: string | string[]): any - // eslint-disable-next-line @typescript-eslint/no-explicit-any - get(variable: string): any - // eslint-disable-next-line @typescript-eslint/no-explicit-any - getAll(): { [key: string]: any } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - set: (variable: string, value: any) => void - clear: () => void - } + /************************************************************************* + * Unit functions + ************************************************************************/ - interface Distribution { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - random(size: any, min?: any, max?: any): any - // eslint-disable-next-line @typescript-eslint/no-explicit-any - randomInt(min: any, max?: any): any - // eslint-disable-next-line @typescript-eslint/no-explicit-any - pickRandom(array: any): any - } + /** + * Change the unit of a value. For matrices, the function is evaluated + * element wise. + * @param unit New unit. Can be a string like "cm" or a unit without + * value. + */ + to( + this: MathJsChain, + unit: Unit | string + ): MathJsChain - interface FormatOptions { - /** - * Number notation. Choose from: 'fixed' Always use regular number - * notation. For example '123.40' and '14000000' 'exponential' Always - * use exponential notation. For example '1.234e+2' and '1.4e+7' 'auto' - * (default) Regular number notation for numbers having an absolute - * value between lower and upper bounds, and uses exponential notation - * elsewhere. Lower bound is included, upper bound is excluded. For - * example '123.4' and '1.4e7'. - */ - notation?: 'fixed' | 'exponential' | 'engineering' | 'auto' - - /** - * A number between 0 and 16 to round the digits of the number. In case - * of notations 'exponential' and 'auto', precision defines the total - * number of significant digits returned and is undefined by default. In - * case of notation 'fixed', precision defines the number of significant - * digits after the decimal point, and is 0 by default. - */ - precision?: number - - /** - * Exponent determining the lower boundary for formatting a value with - * an exponent when notation='auto. Default value is -3. - */ - lowerExp?: number - - /** - * Exponent determining the upper boundary for formatting a value with - * an exponent when notation='auto. Default value is 5. - */ - upperExp?: number - - /** - * Available values: 'ratio' (default) or 'decimal'. For example - * format(fraction(1, 3)) will output '1/3' when 'ratio' is configured, - * and will output 0.(3) when 'decimal' is configured. - */ - fraction?: string - } + /************************************************************************* + * Utils functions + ************************************************************************/ - interface Help { - toString(): string - toJSON(): string - } + /** + * Clone an object. + */ - interface ConfigOptions { - epsilon?: number - matrix?: 'Matrix' | 'Array' - number?: 'number' | 'BigNumber' | 'Fraction' - precision?: number - predictable?: boolean - randomSeed?: string | null - } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + clone(this: MathJsChain): MathJsChain - interface MathJsChain { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - done(): TValue - - /************************************************************************* - * Construction functions - ************************************************************************/ - - /** - * Create a BigNumber, which can store numbers with arbitrary precision. - * When a matrix is provided, all elements will be converted to - * BigNumber. - */ - bignumber( - this: MathJsChain< - number | string | Fraction | BigNumber | Unit | boolean | null - > - ): MathJsChain - bignumber(this: MathJsChain): MathJsChain - - /** - * Create a boolean or convert a string or number to a boolean. In case - * of a number, true is returned for non-zero numbers, and false in case - * of zero. Strings can be 'true' or 'false', or can contain a number. - * When value is a matrix, all elements will be converted to boolean. - */ - boolean( - this: MathJsChain - ): MathJsChain - boolean(this: MathJsChain): MathJsChain - - /** - * Create a complex value or convert a value to a complex value. - * @param im Argument specifying the imaginary part of the complex - * number - */ - complex( - this: MathJsChain, - im?: number - ): MathJsChain - complex(this: MathJsChain): MathJsChain - - /** - * Create a user-defined unit and register it with the Unit type. - * @param definition Definition of the unit in terms of existing units. - * For example, ‘0.514444444 m / s’. - * @param options (optional) An object containing any of the following - * properties:
- prefixes {string} “none”, “short”, “long”, - * “binary_short”, or “binary_long”. The default is “none”.
- - * aliases {Array} Array of strings. Example: [‘knots’, ‘kt’, - * ‘kts’]
- offset {Numeric} An offset to apply when converting from - * the unit. For example, the offset for celsius is 273.15. Default is - * 0. - */ - createUnit( - this: MathJsChain, - definition?: string | UnitDefinition | Unit, - options?: CreateUnitOptions - ): MathJsChain - /** - * Create a user-defined unit and register it with the Unit type. - * @param options (optional) An object containing any of the following - * properties:
- prefixes {string} “none”, “short”, “long”, - * “binary_short”, or “binary_long”. The default is “none”.
- - * aliases {Array} Array of strings. Example: [‘knots’, ‘kt’, - * ‘kts’]
- offset {Numeric} An offset to apply when converting from - * the unit. For example, the offset for celsius is 273.15. Default is - * 0. - */ - createUnit( - this: MathJsChain>, - options?: CreateUnitOptions - ): MathJsChain - - /** - * Create a fraction convert a value to a fraction. - * @param denominator Argument specifying the denominator of the - * fraction - */ - fraction( - this: MathJsChain< - number | string | BigNumber | Unit | Fraction | FractionDefinition - >, - denominator?: number - ): MathJsChain - fraction(this: MathJsChain): MathJsChain - - /** - * Create an index. An Index can store ranges having start, step, and - * end for multiple dimensions. Matrix.get, Matrix.set, and math.subset - * accept an Index as input. - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - index(this: MathJsChain): MathJsChain - - /** - * Create a Matrix. The function creates a new math.type.Matrix object - * from an Array. A Matrix has utility functions to manipulate the data - * in the matrix, like getting the size and getting or setting values in - * the matrix. Supported storage formats are 'dense' and 'sparse'. - */ - matrix( - this: MathJsChain, - format?: 'sparse' | 'dense', - dataType?: string - ): MathJsChain - - /** - * Create a number or convert a string, boolean, or unit to a number. - * When value is a matrix, all elements will be converted to number. - * @param valuelessUnit A valueless unit, used to convert a unit to a - * number - */ - number( - this: MathJsChain< - string | number | BigNumber | Fraction | boolean | Unit | null - >, - valuelessUnit?: Unit | string - ): MathJsChain - number( - this: MathJsChain, - valuelessUnit?: Unit | string - ): MathJsChain - - /** - * Create a Sparse Matrix. The function creates a new math.type.Matrix - * object from an Array. A Matrix has utility functions to manipulate - * the data in the matrix, like getting the size and getting or setting - * values in the matrix. - * @param dataType Sparse Matrix data type - */ - sparse( - this: MathJsChain, - dataType?: string - ): MathJsChain - - /** - * Split a unit in an array of units whose sum is equal to the original - * unit. - * @param parts An array of strings or valueless units - */ - splitUnit(this: MathJsChain, parts: Unit[]): MathJsChain - - /** - * Create a string or convert any object into a string. Elements of - * Arrays and Matrices are processed element wise. - */ - string( - this: MathJsChain - ): MathJsChain - string(this: MathJsChain): MathJsChain - - /** - * Create a unit. Depending on the passed arguments, the function will - * create and return a new math.type.Unit object. When a matrix is - * provided, all elements will be converted to units. - * @param unit The unit to be created - */ - unit(this: MathJsChain, unit?: string): MathJsChain - unit(this: MathJsChain, unit?: string): MathJsChain - unit(this: MathJsChain, unit?: string): MathJsChain - - /************************************************************************* - * Expression functions - ************************************************************************/ - - /** - * Parse and compile an expression. Returns a an object with a function - * evaluate([scope]) to evaluate the compiled expression. - */ - compile(this: MathJsChain): MathJsChain - - // TODO properly type this - /** - * Evaluate an expression. - * @param scope Scope to read/write variables - */ - evaluate( - this: MathJsChain, - scope?: object - // eslint-disable-next-line @typescript-eslint/no-explicit-any - ): MathJsChain - evaluate( - this: MathJsChain, - scope?: object - // eslint-disable-next-line @typescript-eslint/no-explicit-any - ): MathJsChain - - /** - * Retrieve help on a function or data type. Help files are retrieved - * from the documentation in math.expression.docs. - */ - help(this: MathJsChain): MathJsChain - - /** - * @param options Available options: nodes - a set of custome nodes - */ - parse( - this: MathJsChain, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - options?: any - ): MathJsChain - - /** - * Parse an expression. Returns a node tree, which can be evaluated by - * invoking node.evaluate(); - * @param options Available options: nodes - a set of custome nodes - */ - parse( - this: MathJsChain, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - options?: any - ): MathJsChain - - /** - * Replaces variable nodes with their scoped values - * @param scope Scope to read/write variables - */ - resolve( - this: MathJsChain, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - scope?: Record - ): MathJsChain - resolve( - this: MathJsChain, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - scope?: Record - ): MathJsChain - - /************************************************************************* - * Algebra functions - ************************************************************************/ - /** - * @param variable The variable over which to differentiate - * @param options There is one option available, simplify, which is true - * by default. When false, output will not be simplified. - */ - derivative( - this: MathJsChain, - variable: MathNode | string, - options?: { simplify: boolean } - ): MathJsChain - - /** - * Solves the linear equation system by forwards substitution. Matrix - * must be a lower triangular matrix. - * @param b A column vector with the b values - */ - lsolve(this: MathJsChain, b: MathCollection): MathJsChain - lsolve( - this: MathJsChain, - b: MathCollection - ): MathJsChain - - /** - * Calculate the Matrix LU decomposition with partial pivoting. Matrix A - * is decomposed in two matrices (L, U) and a row permutation vector p - * where A[p,:] = L * U - */ - lup(this: MathJsChain): MathJsChain - - /** - * Solves the linear system A * x = b where A is an [n x n] matrix and b - * is a [n] column vector. - * @param b Column Vector - * @param order The Symbolic Ordering and Analysis order, see slu for - * details. Matrix must be a SparseMatrix - * @param threshold Partial pivoting threshold (1 for partial pivoting), - * see slu for details. Matrix must be a SparseMatrix. - */ - lusolve( - this: MathJsChain, - b: MathCollection, - order?: number, - threshold?: number - ): MathJsChain - - lusolve( - this: MathJsChain, - b: MathCollection, - order?: number, - threshold?: number - ): MathJsChain - - lusolve( - this: MathJsChain, - b: MathCollection - ): MathJsChain - - /** - * Calculate the Matrix QR decomposition. Matrix A is decomposed in two - * matrices (Q, R) where Q is an orthogonal matrix and R is an upper - * triangular matrix. - */ - qr(this: MathJsChain): MathJsChain - - /** - * Transform a rationalizable expression in a rational fraction. If - * rational fraction is one variable polynomial then converts the - * numerator and denominator in canonical form, with decreasing - * exponents, returning the coefficients of numerator. - * @param optional scope of expression or true for already evaluated - * rational expression at input - * @param detailed optional True if return an object, false if return - * expression node (default) - */ - rationalize( - this: MathJsChain, - optional?: object | boolean, - detailed?: boolean - ): MathJsChain - - /** - * Simplify an expression tree. - * @param rules A list of rules are applied to an expression, repeating - * over the list until no further changes are made. It’s possible to - * pass a custom set of rules to the function as second argument. A rule - * can be specified as an object, string, or function. - * @param scope Scope to variables - * @param options Options to configure the behavior of simplify - */ - simplify( - this: MathJsChain, - rules?: SimplifyRule[], - scope?: Map | object, - options?: SimplifyOptions - ): MathJsChain - - simplifyConstant( - this: MathJsChain, - options?: SimplifyOptions - ): MathJsChain - simplifyCore( - this: MathJsChain, - options?: SimplifyOptions - ): MathJsChain - - /** - * Calculate the Sparse Matrix LU decomposition with full pivoting. - * Sparse Matrix A is decomposed in two matrices (L, U) and two - * permutation vectors (pinv, q) where P * A * Q = L * U - * @param order The Symbolic Ordering and Analysis order: 0 - Natural - * ordering, no permutation vector q is returned 1 - Matrix must be - * square, symbolic ordering and analisis is performed on M = A + A' 2 - - * Symbolic ordering and analysis is performed on M = A' * A. Dense - * columns from A' are dropped, A recreated from A'. This is appropriate - * for LU factorization of non-symmetric matrices. 3 - Symbolic ordering - * and analysis is performed on M = A' * A. This is best used for LU - * factorization is matrix M has no dense rows. A dense row is a row - * with more than 10*sqr(columns) entries. - * @param threshold Partial pivoting threshold (1 for partial pivoting) - */ - slu( - this: MathJsChain, - order: number, - threshold: number - ): MathJsChain - - /** - * Solves the linear equation system by backward substitution. Matrix - * must be an upper triangular matrix. U * x = b - * @param b A column vector with the b values - */ - usolve(this: MathJsChain, b: MathCollection): MathJsChain - usolve( - this: MathJsChain, - b: MathCollection - ): MathJsChain - - /************************************************************************* - * Arithmetic functions - ************************************************************************/ - - /** - * Calculate the absolute value of a number. For matrices, the function - * is evaluated element wise. - */ - abs(this: MathJsChain): MathJsChain - - /** - * Add two values, x + y. For matrices, the function is evaluated - * element wise. - * @param y Second value to add - */ - add(this: MathJsChain, y: T): MathJsChain - add(this: MathJsChain, y: MathType): MathJsChain - - /** - * Apply a function that maps an array to a scalar along a given axis of the - * matrix or array. Returns a new matrix or array with one less dimension - * than the input. - * @param dim The dimension along which the callback is applied - * @param callback The callback function that is applied. This Function should take an - * array or 1-d matrix as an input and return a number. - * @returns The residual matrix with the function applied over some dimension. - */ - apply( - this: MathJsChain, - dim: number, - callback: (array: Array | Matrix) => number - ): MathJsChain - - /** - * Calculate the cubic root of a value. For matrices, the function is - * evaluated element wise. - * @param allRoots Optional, false by default. Only applicable when x is - * a number or complex number. If true, all complex roots are returned, - * if false (default) the principal root is returned. - */ - cbrt( - this: MathJsChain, - allRoots?: boolean - ): MathJsChain - - // Rounding functions grouped for similarity - - /** - * Round a value towards plus infinity If x is complex, both real and - * imaginary part are rounded towards plus infinity. For matrices, the - * function is evaluated element wise. - * @param n Number of decimals Default value: 0. - */ - ceil( - this: MathJsChain, - n?: number | BigNumber | MathCollection - ): MathJsChain - - /** - * Round a value towards zero. For matrices, the function is evaluated - * element wise. - * @param n Number of decimals Default value: 0. - */ - fix( - this: MathJsChain, - n?: number | BigNumber | MathCollection - ): MathJsChain - - /** - * Round a value towards minus infinity. For matrices, the function is - * evaluated element wise. - * @param n Number of decimals Default value: 0. - */ - floor( - this: MathJsChain, - n?: number | BigNumber | MathCollection - ): MathJsChain - - /** - * Round a value towards the nearest integer. For matrices, the function - * is evaluated element wise. - * @param n Number of decimals Default value: 0. - */ - round( - this: MathJsChain, - n?: number | BigNumber | MathCollection - ): MathJsChain - - // End of rounding group - - /** - * Compute the cube of a value, x * x * x. For matrices, the function is - * evaluated element wise. - */ - cube(this: MathJsChain): MathJsChain - - /** - * Divide two values, x / y. To divide matrices, x is multiplied with - * the inverse of y: x * inv(y). - * @param y Denominator - */ - divide(this: MathJsChain, y: Unit): MathJsChain - divide(this: MathJsChain, y: number): MathJsChain - divide(this: MathJsChain, y: number): MathJsChain - divide(this: MathJsChain, y: MathType): MathJsChain - - /** - * Divide two matrices element wise. The function accepts both matrices - * and scalar values. - * @param y Denominator - */ - dotDivide( - this: MathJsChain, - y: MathType - ): MathJsChain - dotDivide( - this: MathJsChain, - y: T - ): MathJsChain - dotDivide(this: MathJsChain, y: MathType): MathJsChain - dotDivide(this: MathJsChain, y: Unit): MathJsChain - dotDivide( - this: MathJsChain, - y: MathNumericType - ): MathJsChain - - /** - * Multiply two matrices element wise. The function accepts both - * matrices and scalar values. - * @param y Right hand value - */ - dotMultiply( - this: MathJsChain, - y: MathType - ): MathJsChain - dotMultiply( - this: MathJsChain, - y: T - ): MathJsChain - dotMultiply(this: MathJsChain, y: MathType): MathJsChain - dotMultiply(this: MathJsChain, y: Unit): MathJsChain - dotMultiply( - this: MathJsChain, - y: MathNumericType - ): MathJsChain - - /** - * Calculates the power of x to y element wise. - * @param y The exponent - */ - dotPow( - this: MathJsChain, - y: MathType - ): MathJsChain - - /** - * Calculate the exponent of a value. For matrices, the function is - * evaluated element wise. - */ - exp( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the value of subtracting 1 from the exponential value. For - * matrices, the function is evaluated element wise. - */ - expm1( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the greatest common divisor for two or more values or - * arrays. For matrices, the function is evaluated element wise. - */ - gcd( - this: MathJsChain, - ...args: T[] - ): MathJsChain - - /** - * Calculate the hypotenusa of a list with values. The hypotenusa is - * defined as: hypot(a, b, c, ...) = sqrt(a^2 + b^2 + c^2 + ...) For - * matrix input, the hypotenusa is calculated for all values in the - * matrix. - */ - hypot(this: MathJsChain): MathJsChain - - /** - * Calculate the least common multiple for two or more values or arrays. - * lcm is defined as: lcm(a, b) = abs(a * b) / gcd(a, b) For matrices, - * the function is evaluated element wise. - * @param b An integer number - */ - lcm( - this: MathJsChain, - b: T - ): MathJsChain - - /** - * Calculate the logarithm of a value. For matrices, the function is - * evaluated element wise. - * @param base Optional base for the logarithm. If not provided, the - * natural logarithm of x is calculated. Default value: e. - */ - log( - this: MathJsChain, - base?: number | BigNumber | Complex - ): MathJsChain> - - /** - * Calculate the 10-base of a value. This is the same as calculating - * log(x, 10). For matrices, the function is evaluated element wise. - */ - - log10( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the logarithm of a value+1. For matrices, the function is - * evaluated element wise. - */ - log1p( - this: MathJsChain, - base?: number | BigNumber | Complex - ): MathJsChain - log1p( - this: MathJsChain, - base?: number | BigNumber | Complex - ): MathJsChain - log1p( - this: MathJsChain, - base?: number | BigNumber | Complex - ): MathJsChain - log1p( - this: MathJsChain, - base?: number | BigNumber | Complex - ): MathJsChain - log1p( - this: MathJsChain, - base?: number | BigNumber | Complex - ): MathJsChain - - /** - * Calculate the 2-base of a value. This is the same as calculating - * log(x, 2). For matrices, the function is evaluated element wise. - */ - - log2( - this: MathJsChain - ): MathJsChain - - /** - * Calculates the modulus, the remainder of an integer division. For - * matrices, the function is evaluated element wise. The modulus is - * defined as: x - y * floor(x / y) - * @see http://en.wikipedia.org/wiki/Modulo_operation. - * @param y Divisor - */ - mod( - this: MathJsChain, - y: number | BigNumber | Fraction | MathCollection - ): MathJsChain> - - /** - * Multiply two values, x * y. The result is squeezed. For matrices, the - * matrix product is calculated. - * @param y The second value to multiply - */ - multiply( - this: MathJsChain, - y: MathType - ): MathJsChain - multiply(this: MathJsChain, y: Unit): MathJsChain - multiply(this: MathJsChain, y: number): MathJsChain - multiply(this: MathJsChain, y: MathType): MathJsChain - - /** - * Calculate the norm of a number, vector or matrix. The second - * parameter p is optional. If not provided, it defaults to 2. - * @param p Vector space. Supported numbers include Infinity and - * -Infinity. Supported strings are: 'inf', '-inf', and 'fro' (The - * Frobenius norm) Default value: 2. - */ - norm( - this: MathJsChain, - p?: number | BigNumber | string - ): MathJsChain - - /** - * Calculate the nth root of a value. The principal nth root of a - * positive real number A, is the positive real solution of the equation - * x^root = A For matrices, the function is evaluated element wise. - * @param root The root. Default value: 2. - */ - nthRoot( - this: MathJsChain, - root?: number | BigNumber - ): MathJsChain - - /** - * Calculates the power of x to y, x ^ y. Matrix exponentiation is - * supported for square matrices x, and positive integer exponents y. - * @param y The exponent - */ - pow( - this: MathJsChain, - y: number | BigNumber | Complex - ): MathJsChain - - /** - * Compute the sign of a value. The sign of a value x is: 1 when x > 1 - * -1 when x < 0 0 when x == 0 For matrices, the function is evaluated - * element wise. - * @param x The number for which to determine the sign - * @returns The sign of x - */ - sign(this: MathJsChain): MathJsChain - - /** - * Calculate the square root of a value. For matrices, the function is - * evaluated element wise. - */ - - sqrt( - this: MathJsChain - ): MathJsChain - - /** - * Compute the square of a value, x * x. For matrices, the function is - * evaluated element wise. - */ - - square(this: MathJsChain): MathJsChain - - /** - * Subtract two values, x - y. For matrices, the function is evaluated - * element wise. - * @param y Value to subtract from x - */ - subtract(this: MathJsChain, y: T): MathJsChain - - /** - * Inverse the sign of a value, apply a unary minus operation. For - * matrices, the function is evaluated element wise. Boolean values and - * strings will be converted to a number. For complex numbers, both real - * and complex value are inverted. - */ - - unaryMinus(this: MathJsChain): MathJsChain - - /** - * Unary plus operation. Boolean values and strings will be converted to - * a number, numeric values will be returned as is. For matrices, the - * function is evaluated element wise. - */ - - unaryPlus(this: MathJsChain): MathJsChain - - /** - * Calculate the extended greatest common divisor for two values. See - * http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm. - * @param b An integer number - */ - xgcd( - this: MathJsChain, - b: number | BigNumber - ): MathJsChain - - /** - * Count the number of elements of a matrix, array or string. - */ - count(this: MathJsChain): MathJsChain - count(this: MathJsChain): MathJsChain - - /** - * Compute the sum of a matrix or a list with values. In case of a - * (multi dimensional) array or matrix, the sum of all elements will be - * calculated. - */ - sum( - this: MathJsChain> - ): MathJsChain - sum(this: MathJsChain): MathJsChain - /************************************************************************* - * Bitwise functions - ************************************************************************/ - - /** - * Bitwise AND two values, x & y. For matrices, the function is - * evaluated element wise. - * @param y Second value to and - */ - bitAnd( - this: MathJsChain, - y: number | BigNumber | MathCollection - ): MathJsChain> - - /** - * Bitwise NOT value, ~x. For matrices, the function is evaluated - * element wise. For units, the function is evaluated on the best prefix - * base. - */ - - bitNot( - this: MathJsChain - ): MathJsChain - - /** - * Bitwise OR two values, x | y. For matrices, the function is evaluated - * element wise. For units, the function is evaluated on the lowest - * print base. - * @param y Second value to or - */ - bitOr( - this: MathJsChain, - y: T - ): MathJsChain - - /** - * Bitwise XOR two values, x ^ y. For matrices, the function is - * evaluated element wise. - * @param y Second value to xor - */ - bitXor( - this: MathJsChain, - y: number | BigNumber | MathCollection - ): MathJsChain> - - /** - * Bitwise left logical shift of a value x by y number of bits, x << y. - * For matrices, the function is evaluated element wise. For units, the - * function is evaluated on the best prefix base. - * @param y Amount of shifts - */ - leftShift( - this: MathJsChain, - y: number | BigNumber - ): MathJsChain> - - /** - * Bitwise right arithmetic shift of a value x by y number of bits, x >> - * y. For matrices, the function is evaluated element wise. For units, - * the function is evaluated on the best prefix base. - * @param y Amount of shifts - */ - rightArithShift( - this: MathJsChain, - y: number | BigNumber - ): MathJsChain> - - /** - * Bitwise right logical shift of value x by y number of bits, x >>> y. - * For matrices, the function is evaluated element wise. For units, the - * function is evaluated on the best prefix base. - * @param y Amount of shifts - */ - rightLogShift( - this: MathJsChain, - y: number - ): MathJsChain> - - /************************************************************************* - * Combinatorics functions - ************************************************************************/ - - /** - * The Bell Numbers count the number of partitions of a set. A partition - * is a pairwise disjoint subset of S whose union is S. bellNumbers only - * takes integer arguments. The following condition must be enforced: n - * >= 0 - */ - - bellNumbers(this: MathJsChain): MathJsChain - bellNumbers(this: MathJsChain): MathJsChain - - /** - * The Catalan Numbers enumerate combinatorial structures of many - * different types. catalan only takes integer arguments. The following - * condition must be enforced: n >= 0 - */ - - catalan(this: MathJsChain): MathJsChain - catalan(this: MathJsChain): MathJsChain - - /** - * The composition counts of n into k parts. Composition only takes - * integer arguments. The following condition must be enforced: k <= n. - * @param k Number of objects in the subset - */ - composition( - this: MathJsChain, - k: number | BigNumber - ): MathJsChain> - - /** - * The Stirling numbers of the second kind, counts the number of ways to - * partition a set of n labelled objects into k nonempty unlabelled - * subsets. stirlingS2 only takes integer arguments. The following - * condition must be enforced: k <= n. If n = k or k = 1, then s(n,k) = - * 1 - * @param k Number of objects in the subset - */ - stirlingS2( - this: MathJsChain, - k: number | BigNumber - ): MathJsChain> - - /************************************************************************* - * Complex functions - ************************************************************************/ - - /** - * Compute the argument of a complex value. For a complex number a + bi, - * the argument is computed as atan2(b, a). For matrices, the function - * is evaluated element wise. - */ - - arg(this: MathJsChain): MathJsChain - arg(this: MathJsChain): MathJsChain - arg(this: MathJsChain): MathJsChain - arg(this: MathJsChain): MathJsChain - - /** - * Compute the complex conjugate of a complex value. If x = a+bi, the - * complex conjugate of x is a - bi. For matrices, the function is - * evaluated element wise. - */ - conj( - this: MathJsChain - ): MathJsChain> - - /** - * Get the imaginary part of a complex number. For a complex number a + - * bi, the function returns b. For matrices, the function is evaluated - * element wise. - */ - im(this: MathJsChain): MathJsChain - im(this: MathJsChain): MathJsChain - im(this: MathJsChain): MathJsChain - - /** - * Get the real part of a complex number. For a complex number a + bi, - * the function returns a. For matrices, the function is evaluated - * element wise. - */ - re(this: MathJsChain): MathJsChain - re(this: MathJsChain): MathJsChain - re(this: MathJsChain): MathJsChain - - /************************************************************************* - * Geometry functions - ************************************************************************/ - - /** - * Calculates: The eucledian distance between two points in 2 and 3 - * dimensional spaces. Distance between point and a line in 2 and 3 - * dimensional spaces. Pairwise distance between a set of 2D or 3D - * points NOTE: When substituting coefficients of a line(a, b and c), - * use ax + by + c = 0 instead of ax + by = c For parametric equation of - * a 3D line, x0, y0, z0, a, b, c are from: (x−x0, y−y0, z−z0) = t(a, b, - * c) - * @param y Coordinates of the second point - */ - distance( - this: MathJsChain, - y: MathCollection | object - ): MathJsChain - - /** - * Calculates the point of intersection of two lines in two or three - * dimensions and of a line and a plane in three dimensions. The inputs - * are in the form of arrays or 1 dimensional matrices. The line - * intersection functions return null if the lines do not meet. Note: - * Fill the plane coefficients as x + y + z = c and not as x + y + z + c - * = 0. - * @param x Co-ordinates of second end-point of first line - * @param y Co-ordinates of first end-point of second line OR - * Coefficients of the plane's equation - * @param z Co-ordinates of second end-point of second line OR null if - * the calculation is for line and plane - */ - intersect( - this: MathJsChain, - x: MathCollection, - y: MathCollection, - z?: MathCollection - ): MathJsChain - - /************************************************************************* - * Logical functions - ************************************************************************/ - - /** - * Logical and. Test whether two values are both defined with a - * nonzero/nonempty value. For matrices, the function is evaluated - * element wise. - * @param y Second value to and - */ - and( - this: MathJsChain, - y: number | BigNumber | Complex | Unit | MathCollection - ): MathJsChain - - /** - * Logical not. Flips boolean value of a given parameter. For matrices, - * the function is evaluated element wise. - */ - not( - this: MathJsChain - ): MathJsChain - - /** - * Logical or. Test if at least one value is defined with a - * nonzero/nonempty value. For matrices, the function is evaluated - * element wise. - * @param y Second value to or - */ - or( - this: MathJsChain, - y: number | BigNumber | Complex | Unit | MathCollection - ): MathJsChain - - /** - * Logical xor. Test whether one and only one value is defined with a - * nonzero/nonempty value. For matrices, the function is evaluated - * element wise. - * @param y Second value to xor - */ - xor( - this: MathJsChain, - y: number | BigNumber | Complex | Unit | MathCollection - ): MathJsChain - - /************************************************************************* - * Matrix functions - ************************************************************************/ - - /** - * Concatenate two or more matrices. dim: number is a zero-based - * dimension over which to concatenate the matrices. By default the last - * dimension of the matrices. - */ - - concat( - this: MathJsChain> - ): MathJsChain - - /** - * Calculate the cross product for two vectors in three dimensional - * space. The cross product of A = [a1, a2, a3] and B =[b1, b2, b3] is - * defined as: cross(A, B) = [ a2 * b3 - a3 * b2, a3 * b1 - a1 * b3, a1 - * * b2 - a2 * b1 ] - * @param y Second vector - */ - cross( - this: MathJsChain, - y: MathCollection - ): MathJsChain - - /** - * Calculate the determinant of a matrix. - */ - - det(this: MathJsChain): MathJsChain - - /** - * Create a diagonal matrix or retrieve the diagonal of a matrix. When x - * is a vector, a matrix with vector x on the diagonal will be returned. - * When x is a two dimensional matrix, the matrixes kth diagonal will be - * returned as vector. When k is positive, the values are placed on the - * super diagonal. When k is negative, the values are placed on the sub - * diagonal. - * @param k The diagonal where the vector will be filled in or - * retrieved. Default value: 0. - * @param format The matrix storage format. Default value: 'dense'. - */ - diag( - this: MathJsChain, - format?: string - ): MathJsChain - diag( - this: MathJsChain, - k: number | BigNumber, - format?: string - ): MathJsChain - - /** - * Calculate the dot product of two vectors. The dot product of A = [a1, - * a2, a3, ..., an] and B = [b1, b2, b3, ..., bn] is defined as: dot(A, - * B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn - * @param y Second vector - */ - dot( - this: MathJsChain, - y: MathCollection - ): MathJsChain - - /** - * Compute the matrix exponential, expm(A) = e^A. The matrix must be - * square. Not to be confused with exp(a), which performs element-wise - * exponentiation. The exponential is calculated using the Padé - * approximant with scaling and squaring; see “Nineteen Dubious Ways to - * Compute the Exponential of a Matrix,” by Moler and Van Loan. - */ - - expm(this: MathJsChain): MathJsChain - - /** - * Performs a real Schur decomposition of the real matrix A = UTU' where U is orthogonal - * and T is upper quasi-triangular. - * https://en.wikipedia.org/wiki/Schur_decomposition - * @returns Object containing both matrix U and T of the Schur Decomposition A=UTU' - */ - schur(this: MathJsChain): SchurDecomposition - - /** - * Solves the Continuous-time Lyapunov equation AP+PA'=Q for P, where Q is a positive semidefinite - * matrix. - * https://en.wikipedia.org/wiki/Lyapunov_equation - * @param Q Matrix Q - * @returns Matrix P solution to the Continuous-time Lyapunov equation AP+PA'=Q - */ - lyap( - this: MathJsChain, - Q: MathCollection - ): MathJsChain - - /** - * Create a 2-dimensional identity matrix with size m x n or n x n. The - * matrix has ones on the diagonal and zeros elsewhere. - * @param format The Matrix storage format - */ - identity( - this: MathJsChain, - format?: string - ): MathJsChain - - /** - * @param n The y dimension for the matrix - * @param format The Matrix storage format - */ - identity( - this: MathJsChain, - n: number, - format?: string - ): MathJsChain - - /** - * Filter the items in an array or one dimensional matrix. - */ - filter( - this: MathJsChain, - test: - | (( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - value: any, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - index: any, - matrix: MathCollection | string[] - ) => boolean) - | RegExp - ): MathJsChain - - /** - * Flatten a multi dimensional matrix into a single dimensional matrix. - */ - - flatten(x: MathJsChain): MathJsChain - - /** - * Iterate over all elements of a matrix/array, and executes the given - * callback function. - */ - forEach( - this: MathJsChain, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - callback: (value: any, index: any, matrix: T) => void - ): void - - /** - * Calculate the inverse of a square matrix. - */ - - inv( - this: MathJsChain - ): MathJsChain> - - /** - * Calculate the kronecker product of two matrices or vectors - * @param y Second vector - */ - kron( - this: MathJsChain, - y: MathCollection - ): MathJsChain - - /** - * Iterate over all elements of a matrix/array, and executes the given - * callback function. - * @param callback The callback function is invoked with three - * parameters: the value of the element, the index of the element, and - * the Matrix/array being traversed. - */ - map( - this: MathJsChain, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - callback: (value: any, index: any, matrix: T) => MathType | string - ): MathJsChain - - /** - * Create a matrix filled with ones. The created matrix can have one or - * multiple dimensions. - * @param format The matrix storage format - */ - ones( - this: MathJsChain, - format?: string - ): MathJsChain - - /** - * Partition-based selection of an array or 1D matrix. Will find the kth - * smallest value, and mutates the input array. Uses Quickselect. - * @param k The kth smallest value to be retrieved; zero-based index - * @param compare An optional comparator function. The function is - * called as compare(a, b), and must return 1 when a > b, -1 when a < b, - * and 0 when a == b. Default value: 'asc'. - */ - partitionSelect( - this: MathJsChain, - k: number, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - compare?: 'asc' | 'desc' | ((a: any, b: any) => number) - ): MathJsChain - - /** - * Create an array from a range. By default, the range end is excluded. - * This can be customized by providing an extra parameter includeEnd. - * @param end End of the range, excluded by default, included when - * parameter includeEnd=true - * @param step Step size. Default value is 1. - * @param includeEnd: Option to specify whether to include the end or - * not. False by default - */ - range(this: MathJsChain, includeEnd?: boolean): MathJsChain - range( - this: MathJsChain, - end: number | BigNumber, - includeEnd?: boolean - ): MathJsChain - range( - this: MathJsChain, - end: number | BigNumber | Unit, - step: number | BigNumber | Unit, - includeEnd?: boolean - ): MathJsChain - - /** - * Reshape a multi dimensional array to fit the specified dimensions - * @param sizes One dimensional array with integral sizes for each - * dimension - */ - reshape( - this: MathJsChain, - sizes: number[] - ): MathJsChain - - /** - * Resize a matrix - * @param size One dimensional array with numbers - * @param defaultValue Zero by default, except in case of a string, in - * that case defaultValue = ' ' Default value: 0. - */ - resize( - this: MathJsChain, - size: MathCollection, - defaultValue?: number | string - ): MathJsChain - - /** - * Calculate the size of a matrix or scalar. - */ - size( - this: MathJsChain< - boolean | number | Complex | Unit | string | MathCollection - > - ): MathJsChain - - /** - * Sort the items in a matrix - * @param compare An optional _comparator function or name. The function - * is called as compare(a, b), and must return 1 when a > b, -1 when a < - * b, and 0 when a == b. Default value: ‘asc’ - */ - sort( - this: MathJsChain, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - compare: ((a: any, b: any) => number) | 'asc' | 'desc' | 'natural' - ): MathJsChain - - /** - * Calculate the principal square root of a square matrix. The principal - * square root matrix X of another matrix A is such that X * X = A. - */ - - sqrtm(A: MathJsChain): MathJsChain - - /** - * Squeeze a matrix, remove inner and outer singleton dimensions from a - * matrix. - */ - - squeeze(x: MathJsChain): MathJsChain - - /** - * Get or set a subset of a matrix or string. - * @param index For each dimension, an index or list of indices to get or set - * @param replacement An array, matrix, or scalar. If provided, the - * subset is replaced with replacement. If not provided, the subset is - * returned - * @param defaultValue Default value, filled in on new entries when the - * matrix is resized. If not provided, math.matrix elements will be left - * undefined. Default value: undefined. - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - subset( - this: MathJsChain, - index: Index, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - replacement?: any, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - defaultValue?: any - ): MathJsChain - - /** - * Calculate the trace of a matrix: the sum of the elements on the main - * diagonal of a square matrix. - */ - - trace(this: MathJsChain): MathJsChain - - /** - * Transpose a matrix. All values of the matrix are reflected over its - * main diagonal. Only two dimensional matrices are supported. - */ - - transpose(x: MathJsChain): MathJsChain - - /** - * Create a matrix filled with zeros. The created matrix can have one or - * multiple dimensions. - * @param format The matrix storage format - * @returns A matrix filled with zeros - */ - zeros( - this: MathJsChain, - format?: string - ): MathJsChain - - /************************************************************************* - * Probability functions - ************************************************************************/ - - /** - * Compute the number of ways of picking k unordered outcomes from n - * possibilities. Combinations only takes integer arguments. The - * following condition must be enforced: k <= n. - * @param k Number of objects in the subset - */ - combinations( - n: MathJsChain, - k: number | BigNumber - ): MathJsChain> - - /** - * Compute the factorial of a value Factorial only supports an integer - * value as argument. For matrices, the function is evaluated element - * wise. - */ - - factorial( - n: MathJsChain - ): MathJsChain> - - /** - * Compute the gamma function of a value using Lanczos approximation for - * small values, and an extended Stirling approximation for large - * values. For matrices, the function is evaluated element wise. - */ - - gamma( - n: MathJsChain - ): MathJsChain> - - /** - * Calculate the Kullback-Leibler (KL) divergence between two - * distributions - * @param p Second vector - */ - kldivergence( - this: MathJsChain, - p: MathCollection - ): MathJsChain - - /** - * Multinomial Coefficients compute the number of ways of picking a1, - * a2, ..., ai unordered outcomes from n possibilities. multinomial - * takes one array of integers as an argument. The following condition - * must be enforced: every ai <= 0 - */ - - multinomial( - a: MathJsChain - ): MathJsChain> - - /** - * Compute the number of ways of obtaining an ordered subset of k - * elements from a set of n elements. Permutations only takes integer - * arguments. The following condition must be enforced: k <= n. - * @param k The number of objects in the subset - */ - permutations( - n: MathJsChain, - k?: number | BigNumber - ): MathJsChain> - - /** - * Random pick a value from a one dimensional array. Array element is - * picked using a random function with uniform distribution. - * @param number An int or float - * @param weights An array of ints or floats - */ - pickRandom(this: MathJsChain): MathJsChain - pickRandom(this: MathJsChain, number: number): MathJsChain - pickRandom( - this: MathJsChain, - number: number, - weights: number[] - ): MathJsChain - - /** - * Return a random number larger or equal to min and smaller than max - * using a uniform distribution. - * @param min Minimum boundary for the random value, included - * @param max Maximum boundary for the random value, excluded - */ - random(this: MathJsChain, max?: number): MathJsChain - - // tslint:disable-next-line unified-signatures - random( - this: MathJsChain, - min?: number, - max?: number - ): MathJsChain - - /** - * Return a random integer number larger or equal to min and smaller - * than max using a uniform distribution. - * @param min Minimum boundary for the random value, included - * @param max Maximum boundary for the random value, excluded - */ - randomInt( - this: MathJsChain, - max?: number - ): MathJsChain - randomInt( - this: MathJsChain, - max?: number - ): MathJsChain - // tslint:disable-next-line unified-signatures - randomInt( - this: MathJsChain, - min: number, - max: number - ): MathJsChain - - /************************************************************************* - * Relational functions - ************************************************************************/ - - /** - * Compare two values. Returns 1 when x > y, -1 when x < y, and 0 when x - * == y. x and y are considered equal when the relative difference - * between x and y is smaller than the configured epsilon. The function - * cannot be used to compare values smaller than approximately 2.22e-16. - * For matrices, the function is evaluated element wise. - * @param y Second value to compare - */ - compare( - this: MathJsChain, - y: MathType | string - ): MathJsChain - - /** - * Compare two values of any type in a deterministic, natural way. For - * numeric values, the function works the same as math.compare. For - * types of values that can’t be compared mathematically, the function - * compares in a natural way. - * @param y Second value to compare - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - compareNatural(this: MathJsChain, y: any): MathJsChain - - /** - * Compare two strings lexically. Comparison is case sensitive. Returns - * 1 when x > y, -1 when x < y, and 0 when x == y. For matrices, the - * function is evaluated element wise. - * @param y Second string to compare - */ - compareText( - this: MathJsChain, - y: string | MathCollection - ): MathJsChain - - /** - * Test element wise whether two matrices are equal. The function - * accepts both matrices and scalar values. - * @param y Second amtrix to compare - */ - deepEqual(this: MathJsChain, y: MathType): MathJsChain - - /** - * Test whether two values are equal. - * - * The function tests whether the relative difference between x and y is - * smaller than the configured epsilon. The function cannot be used to - * compare values smaller than approximately 2.22e-16. For matrices, the - * function is evaluated element wise. In case of complex numbers, x.re - * must equal y.re, and x.im must equal y.im. Values null and undefined - * are compared strictly, thus null is only equal to null and nothing - * else, and undefined is only equal to undefined and nothing else. - * @param y Second value to compare - */ - equal( - this: MathJsChain, - y: MathType | string - ): MathJsChain - - /** - * Check equality of two strings. Comparison is case sensitive. For - * matrices, the function is evaluated element wise. - * @param y Second string to compare - */ - equalText( - this: MathJsChain, - y: string | MathCollection - ): MathJsChain - - /** - * Test whether value x is larger than y. The function returns true when - * x is larger than y and the relative difference between x and y is - * larger than the configured epsilon. The function cannot be used to - * compare values smaller than approximately 2.22e-16. For matrices, the - * function is evaluated element wise. - * @param y Second value to compare - */ - larger( - this: MathJsChain, - y: MathType | string - ): MathJsChain - - /** - * Test whether value x is larger or equal to y. The function returns - * true when x is larger than y or the relative difference between x and - * y is smaller than the configured epsilon. The function cannot be used - * to compare values smaller than approximately 2.22e-16. For matrices, - * the function is evaluated element wise. - * @param y Second value to vcompare - */ - largerEq( - this: MathJsChain, - y: MathType | string - ): MathJsChain - - /** - * Test whether value x is smaller than y. The function returns true - * when x is smaller than y and the relative difference between x and y - * is smaller than the configured epsilon. The function cannot be used - * to compare values smaller than approximately 2.22e-16. For matrices, - * the function is evaluated element wise. - * @param y Second value to vcompare - */ - smaller( - this: MathJsChain, - y: MathType | string - ): MathJsChain - - /** - * Test whether value x is smaller or equal to y. The function returns - * true when x is smaller than y or the relative difference between x - * and y is smaller than the configured epsilon. The function cannot be - * used to compare values smaller than approximately 2.22e-16. For - * matrices, the function is evaluated element wise. - * @param y Second value to compare - */ - smallerEq( - this: MathJsChain, - y: MathType | string - ): MathJsChain - - /** - * Test whether two values are unequal. The function tests whether the - * relative difference between x and y is larger than the configured - * epsilon. The function cannot be used to compare values smaller than - * approximately 2.22e-16. For matrices, the function is evaluated - * element wise. In case of complex numbers, x.re must unequal y.re, or - * x.im must unequal y.im. Values null and undefined are compared - * strictly, thus null is unequal with everything except null, and - * undefined is unequal with everything except undefined. - * @param y Second value to vcompare - */ - unequal( - this: MathJsChain, - y: MathType | string - ): MathJsChain - - /************************************************************************* - * Set functions - ************************************************************************/ - - /** - * Create the cartesian product of two (multi)sets. Multi-dimension - * arrays will be converted to single-dimension arrays and the values - * will be sorted in ascending order before the operation. - * @param a2 A (multi)set - */ - setCartesian( - this: MathJsChain, - a2: MathCollection - ): MathJsChain - - /** - * Create the difference of two (multi)sets: every element of set1, that - * is not the element of set2. Multi-dimension arrays will be converted - * to single-dimension arrays before the operation - * @param a2 A (multi)set - */ - setDifference( - this: MathJsChain, - a2: MathCollection - ): MathJsChain - - /** - * Collect the distinct elements of a multiset. A multi-dimension array - * will be converted to a single-dimension array before the operation. - */ - - setDistinct(a: MathJsChain): MathJsChain - - /** - * Create the intersection of two (multi)sets. Multi-dimension arrays - * will be converted to single-dimension arrays before the operation. - * @param a2 A (multi)set - */ - setIntersect( - this: MathJsChain, - a2: MathCollection - ): MathJsChain - - /** - * Check whether a (multi)set is a subset of another (multi)set. (Every - * element of set1 is the element of set2.) Multi-dimension arrays will - * be converted to single-dimension arrays before the operation. - * @param a2 A (multi)set - */ - setIsSubset( - this: MathJsChain, - a2: MathCollection - ): MathJsChain - - /** - * Count the multiplicity of an element in a multiset. A multi-dimension - * array will be converted to a single-dimension array before the - * operation. - * @param a A multiset - */ - setMultiplicity( - e: MathJsChain, - a: MathCollection - ): MathJsChain - - /** - * Create the powerset of a (multi)set. (The powerset contains very - * possible subsets of a (multi)set.) A multi-dimension array will be - * converted to a single-dimension array before the operation. - */ - - setPowerset(a: MathJsChain): MathJsChain - - /** - * Count the number of elements of a (multi)set. When a second parameter - * is ‘true’, count only the unique values. A multi-dimension array will - * be converted to a single-dimension array before the operation. - */ - - setSize(this: MathJsChain): MathJsChain - - /** - * Create the symmetric difference of two (multi)sets. Multi-dimension - * arrays will be converted to single-dimension arrays before the - * operation. - * @param a2 A (multi)set - */ - setSymDifference( - this: MathJsChain, - a2: MathCollection - ): MathJsChain - - /** - * Create the union of two (multi)sets. Multi-dimension arrays will be - * converted to single-dimension arrays before the operation. - * @param a2 A (multi)set - */ - setUnion( - this: MathJsChain, - a2: MathCollection - ): MathJsChain - - /************************************************************************* - * Signal functions - ************************************************************************/ - /** - * Compute the transfer function of a zero-pole-gain model. - */ - zpk2tf( - this: MathJsChain, // chained variable will be used as z - p: T, - k?: number - ): MathJsChain - - /** - * Calculates the frequency response of a filter given its numerator and denominator coefficients. - */ - freqz( - this: MathJsChain, - a: T, - w?: T | number - ): MathJsChain<{ w: T; h: T }> - - /************************************************************************* - * Special functions - ************************************************************************/ - - /** - * Compute the erf function of a value using a rational Chebyshev - * approximations for different intervals of x. - */ - erf( - this: MathJsChain - ): MathJsChain> - - /** - * Compute the Riemann Zeta function of a value using an infinite series - * and Riemann's Functional equation. - */ - zeta( - this: MathJsChain - ): MathJsChain - - /************************************************************************* - * Statistics functions - ************************************************************************/ - - /** - * Compute the median absolute deviation of a matrix or a list with - * values. The median absolute deviation is defined as the median of the - * absolute deviations from the median. - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - mad(this: MathJsChain): MathJsChain + /** + * Test whether a value is an integer number. The function supports + * number, BigNumber, and Fraction. The function is evaluated + * element-wise in case of Array or Matrix input. + */ - /** - * Compute the maximum value of a matrix or a list with values. In case - * of a multi dimensional array, the maximum of the flattened array will - * be calculated. When dim is provided, the maximum over the selected - * dimension will be calculated. Parameter dim is zero-based. - * @param dim The maximum over the selected dimension - */ + isInteger( + this: MathJsChain + ): MathJsChain - // eslint-disable-next-line @typescript-eslint/no-explicit-any - max(this: MathJsChain, dim?: number): MathJsChain - // eslint-disable-next-line @typescript-eslint/no-explicit-any - max(this: MathJsChain, dim?: number): MathJsChain - - /** - * Compute the mean value of matrix or a list with values. In case of a - * multi dimensional array, the mean of the flattened array will be - * calculated. When dim is provided, the maximum over the selected - * dimension will be calculated. Parameter dim is zero-based. - * @param dim The mean over the selected dimension - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - mean(this: MathJsChain, dim?: number): MathJsChain - // eslint-disable-next-line @typescript-eslint/no-explicit-any - mean(this: MathJsChain, dim?: number): MathJsChain - - /** - * Compute the median of a matrix or a list with values. The values are - * sorted and the middle value is returned. In case of an even number of - * values, the average of the two middle values is returned. Supported - * types of values are: Number, BigNumber, Unit In case of a (multi - * dimensional) array or matrix, the median of all elements will be - * calculated. - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - median(this: MathJsChain, dim?: number): MathJsChain - // eslint-disable-next-line @typescript-eslint/no-explicit-any - median(this: MathJsChain, dim?: number): MathJsChain - - /** - * Compute the minimum value of a matrix or a list of values. In case of - * a multi dimensional array, the minimum of the flattened array will be - * calculated. When dim is provided, the minimum over the selected - * dimension will be calculated. Parameter dim is zero-based. - * @param dim The minimum over the selected dimension - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - min(this: MathJsChain): MathJsChain - // eslint-disable-next-line @typescript-eslint/no-explicit-any - min(this: MathJsChain, dim?: number): MathJsChain + /** + * Test whether a value is NaN (not a number). The function supports + * types number, BigNumber, Fraction, Unit and Complex. The function is + * evaluated element-wise in case of Array or Matrix input. + */ - /** - * Computes the mode of a set of numbers or a list with values(numbers - * or characters). If there are more than one modes, it returns a list - * of those values. - */ + isNaN( + this: MathJsChain + ): MathJsChain - mode(this: MathJsChain): MathJsChain + /** + * Test whether a value is negative: smaller than zero. The function + * supports types number, BigNumber, Fraction, and Unit. The function is + * evaluated element-wise in case of Array or Matrix input. + */ - /** - * Compute the product of a matrix or a list with values. In case of a - * (multi dimensional) array or matrix, the sum of all elements will be - * calculated. - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - prod(this: MathJsChain): MathJsChain - - /** - * Compute the prob order quantile of a matrix or a list with values. - * The sequence is sorted and the middle value is returned. Supported - * types of sequence values are: Number, BigNumber, Unit Supported types - * of probability are: Number, BigNumber In case of a (multi - * dimensional) array or matrix, the prob order quantile of all elements - * will be calculated. - * @param probOrN prob is the order of the quantile, while N is the - * amount of evenly distributed steps of probabilities; only one of - * these options can be provided - * @param sorted =false is data sorted in ascending order - */ - quantileSeq( - A: MathJsChain, - prob: number | BigNumber | MathArray, - sorted?: boolean - ): MathJsChain - - /** - * Compute the standard deviation of a matrix or a list with values. The - * standard deviations is defined as the square root of the variance: - * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or - * matrix, the standard deviation over all elements will be calculated. - * Optionally, the type of normalization can be specified as second - * parameter. The parameter normalization can be one of the following - * values: 'unbiased' (default) The sum of squared errors is divided by - * (n - 1) 'uncorrected' The sum of squared errors is divided by n - * 'biased' The sum of squared errors is divided by (n + 1) - * @param dim A dimension to compute standard deviation. - * @param normalization Determines how to normalize the variance. Choose - * ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: - * ‘unbiased’. - * @returns The standard deviation - */ - std( - this: MathJsChain, - dim?: number, - normalization?: 'unbiased' | 'uncorrected' | 'biased' - ): MathJsChain - - /** - * Compute the standard deviation of a matrix or a list with values. The - * standard deviations is defined as the square root of the variance: - * std(A) = sqrt(variance(A)). In case of a (multi dimensional) array or - * matrix, the standard deviation over all elements will be calculated. - * Optionally, the type of normalization can be specified as second - * parameter. The parameter normalization can be one of the following - * values: 'unbiased' (default) The sum of squared errors is divided by - * (n - 1) 'uncorrected' The sum of squared errors is divided by n - * 'biased' The sum of squared errors is divided by (n + 1) - * @param normalization Determines how to normalize the variance. Choose - * ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. Default value: - * ‘unbiased’. - * @returns The standard deviation - */ - std( - this: MathJsChain, - dimension?: number, - normalization?: 'unbiased' | 'uncorrected' | 'biased' - ): MathJsChain - - /** - * Compute the sum of a matrix or a list with values. In case of a - * (multi dimensional) array or matrix, the sum of all elements will be - * calculated. - */ - std( - this: MathJsChain, - normalization: 'unbiased' | 'uncorrected' | 'biased' - ): MathJsChain - - /** - * Compute the variance of a matrix or a list with values. In case of a - * (multi dimensional) array or matrix, the variance over all elements - * will be calculated. Optionally, the type of normalization can be - * specified as second parameter. The parameter normalization can be one - * of the following values: 'unbiased' (default) The sum of squared - * errors is divided by (n - 1) 'uncorrected' The sum of squared errors - * is divided by n 'biased' The sum of squared errors is divided by (n + - * 1) Note that older browser may not like the variable name var. In - * that case, the function can be called as math['var'](...) instead of - * math.variance(...). - * @param dim a dimension to compute variance. - * @param normalization normalization Determines how to normalize the - * variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. - * Default value: ‘unbiased’. - * @returns The variance - */ - variance( - this: MathJsChain>> - ): MathJsChain - - /** - * Compute the variance of a matrix or a list with values. In case of a - * (multi dimensional) array or matrix, the variance over all elements - * will be calculated. Optionally, the type of normalization can be - * specified as second parameter. The parameter normalization can be one - * of the following values: 'unbiased' (default) The sum of squared - * errors is divided by (n - 1) 'uncorrected' The sum of squared errors - * is divided by n 'biased' The sum of squared errors is divided by (n + - * 1) Note that older browser may not like the variable name var. In - * that case, the function can be called as math['var'](...) instead of - * math.variance(...). - * @param normalization normalization Determines how to normalize the - * variance. Choose ‘unbiased’ (default), ‘uncorrected’, or ‘biased’. - * Default value: ‘unbiased’. - * @returns The variance - */ - variance( - this: MathJsChain, - dimension?: number, - normalization?: 'unbiased' | 'uncorrected' | 'biased' - ): MathJsChain - - variance( - this: MathJsChain, - normalization: 'unbiased' | 'uncorrected' | 'biased' - ): MathJsChain - - /************************************************************************* - * String functions - ************************************************************************/ - - /** - * Format a value of any type into a string. - * @param options An object with formatting options. - * @param callback A custom formatting function, invoked for all numeric - * elements in value, for example all elements of a matrix, or the real - * and imaginary parts of a complex number. This callback can be used to - * override the built-in numeric notation with any type of formatting. - * Function callback is called with value as parameter and must return a - * string. - * @see http://mathjs.org/docs/reference/functions/format.html - */ - format( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - this: MathJsChain, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - value: any, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - options?: FormatOptions | number | ((item: any) => string), - // eslint-disable-next-line @typescript-eslint/no-explicit-any - callback?: (value: any) => string - ): MathJsChain - - /** - * Interpolate values into a string template. - * @param values An object containing variables which will be filled in - * in the template. - * @param precision Number of digits to format numbers. If not provided, - * the value will not be rounded. - * @param options Formatting options, or the number of digits to format - * numbers. See function math.format for a description of all options. - */ - print( - this: MathJsChain, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - values: any, - precision?: number, - options?: number | object - ): MathJsChain - - /************************************************************************* - * Trigonometry functions - ************************************************************************/ - - /** - * Calculate the inverse cosine of a value. For matrices, the function - * is evaluated element wise. - */ - - acos( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the hyperbolic arccos of a value, defined as acosh(x) = - * ln(sqrt(x^2 - 1) + x). For matrices, the function is evaluated - * element wise. - */ - - acosh( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the inverse cotangent of a value. For matrices, the - * function is evaluated element wise. - */ - - acot( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the hyperbolic arccotangent of a value, defined as acoth(x) - * = (ln((x+1)/x) + ln(x/(x-1))) / 2. For matrices, the function is - * evaluated element wise. - */ - - acoth( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the inverse cosecant of a value. For matrices, the function - * is evaluated element wise. - */ - - acsc( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the hyperbolic arccosecant of a value, defined as acsch(x) - * = ln(1/x + sqrt(1/x^2 + 1)). For matrices, the function is evaluated - * element wise. - */ - - acsch( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the inverse secant of a value. For matrices, the function - * is evaluated element wise. - */ - - asec( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the hyperbolic arcsecant of a value, defined as asech(x) = - * ln(sqrt(1/x^2 - 1) + 1/x). For matrices, the function is evaluated - * element wise. - */ - - asech( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the inverse sine of a value. For matrices, the function is - * evaluated element wise. - */ - - asin( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the hyperbolic arcsine of a value, defined as asinh(x) = - * ln(x + sqrt(x^2 + 1)). For matrices, the function is evaluated - * element wise. - */ - - asinh( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the inverse tangent of a value. For matrices, the function - * is evaluated element wise. - */ - - atan( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the inverse tangent function with two arguments, y/x. By - * providing two arguments, the right quadrant of the computed angle can - * be determined. For matrices, the function is evaluated element wise. - */ - - atan2( - this: MathJsChain, - x: number - ): MathJsChain - - /** - * Calculate the hyperbolic arctangent of a value, defined as atanh(x) = - * ln((1 + x)/(1 - x)) / 2. For matrices, the function is evaluated - * element wise. - */ - - atanh( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the cosine of a value. For matrices, the function is - * evaluated element wise. - */ - - cos( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2 - * * (exp(x) + exp(-x)). For matrices, the function is evaluated element - * wise. - */ - - cosh( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the cotangent of a value. cot(x) is defined as 1 / tan(x). - * For matrices, the function is evaluated element wise. - */ - - cot( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1 - * / tanh(x). For matrices, the function is evaluated element wise. - */ - - coth( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the cosecant of a value, defined as csc(x) = 1/sin(x). For - * matrices, the function is evaluated element wise. - */ - - csc( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1 - * / sinh(x). For matrices, the function is evaluated element wise. - */ - - csch( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the secant of a value, defined as sec(x) = 1/cos(x). For - * matrices, the function is evaluated element wise. - */ - - sec( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the hyperbolic secant of a value, defined as sech(x) = 1 / - * cosh(x). For matrices, the function is evaluated element wise. - */ - - sech( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the sine of a value. For matrices, the function is - * evaluated element wise. - */ - - sin( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 * - * (exp(x) - exp(-x)). For matrices, the function is evaluated element - * wise. - */ - - sinh( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the tangent of a value. tan(x) is equal to sin(x) / cos(x). - * For matrices, the function is evaluated element wise. - */ - - tan( - this: MathJsChain - ): MathJsChain - - /** - * Calculate the hyperbolic tangent of a value, defined as tanh(x) = - * (exp(2 * x) - 1) / (exp(2 * x) + 1). For matrices, the function is - * evaluated element wise. - */ - - tanh( - this: MathJsChain - ): MathJsChain - - /************************************************************************* - * Unit functions - ************************************************************************/ - - /** - * Change the unit of a value. For matrices, the function is evaluated - * element wise. - * @param unit New unit. Can be a string like "cm" or a unit without - * value. - */ - to( - this: MathJsChain, - unit: Unit | string - ): MathJsChain - - /************************************************************************* - * Utils functions - ************************************************************************/ - - /** - * Clone an object. - */ + isNegative( + this: MathJsChain + ): MathJsChain - // eslint-disable-next-line @typescript-eslint/no-explicit-any - clone(this: MathJsChain): MathJsChain - - /** - * Test whether a value is an integer number. The function supports - * number, BigNumber, and Fraction. The function is evaluated - * element-wise in case of Array or Matrix input. - */ - - isInteger( - this: MathJsChain - ): MathJsChain - - /** - * Test whether a value is NaN (not a number). The function supports - * types number, BigNumber, Fraction, Unit and Complex. The function is - * evaluated element-wise in case of Array or Matrix input. - */ - - isNaN( - this: MathJsChain - ): MathJsChain - - /** - * Test whether a value is negative: smaller than zero. The function - * supports types number, BigNumber, Fraction, and Unit. The function is - * evaluated element-wise in case of Array or Matrix input. - */ - - isNegative( - this: MathJsChain - ): MathJsChain - - /** - * Test whether a value is an numeric value. The function is evaluated - * element-wise in case of Array or Matrix input. - */ + /** + * Test whether a value is an numeric value. The function is evaluated + * element-wise in case of Array or Matrix input. + */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - isNumeric(this: MathJsChain): MathJsChain + // eslint-disable-next-line @typescript-eslint/no-explicit-any + isNumeric(this: MathJsChain): MathJsChain - /** - * Test whether a value is positive: larger than zero. The function - * supports types number, BigNumber, Fraction, and Unit. The function is - * evaluated element-wise in case of Array or Matrix input. - */ + /** + * Test whether a value is positive: larger than zero. The function + * supports types number, BigNumber, Fraction, and Unit. The function is + * evaluated element-wise in case of Array or Matrix input. + */ - isPositive( - this: MathJsChain - ): MathJsChain + isPositive( + this: MathJsChain + ): MathJsChain - /** - * Test whether a value is prime: has no divisors other than itself and - * one. The function supports type number, bignumber. The function is - * evaluated element-wise in case of Array or Matrix input. - */ + /** + * Test whether a value is prime: has no divisors other than itself and + * one. The function supports type number, bignumber. The function is + * evaluated element-wise in case of Array or Matrix input. + */ - isPrime( - this: MathJsChain - ): MathJsChain + isPrime( + this: MathJsChain + ): MathJsChain - /** - * Test whether a value is zero. The function can check for zero for - * types number, BigNumber, Fraction, Complex, and Unit. The function is - * evaluated element-wise in case of Array or Matrix input. - */ + /** + * Test whether a value is zero. The function can check for zero for + * types number, BigNumber, Fraction, Complex, and Unit. The function is + * evaluated element-wise in case of Array or Matrix input. + */ - isZero(this: MathJsChain): MathJsChain + isZero(this: MathJsChain): MathJsChain - /** - * Determine the type of a variable. - */ + /** + * Determine the type of a variable. + */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - typeOf(this: MathJsChain): MathJsChain - } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + typeOf(this: MathJsChain): MathJsChain +} - interface ImportOptions { - override?: boolean - silent?: boolean - wrap?: boolean - } +export interface ImportOptions { + override?: boolean + silent?: boolean + wrap?: boolean +} - interface ImportObject { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - [key: string]: any - } +export interface ImportObject { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [key: string]: any } + +export const { + // config // Don't export config: no config available in the static instance + + // core functions + create, + factory, + typed, + + // constants + e, + pi, + i, + // Infinity // not needed: is available as global variable too + LN2, + LN10, + LOG2E, + LOG10E, + // NaN, // not needed: is available as global variable too + phi, + SQRT1_2, + SQRT2, + tau, + + // Class-like constructors + Node, + AccessorNode, + ArrayNode, + AssignmentNode, + BlockNode, + ConditionalNode, + ConstantNode, + FunctionAssignmentNode, + FunctionNode, + IndexNode, + ObjectNode, + OperatorNode, + ParenthesisNode, + RangeNode, + RelationalNode, + SymbolNode, + Matrix, + + uninitialized, + version, + expression, + reviver, + replacer, + + bignumber, + boolean, + chain, + complex, + createUnit, + fraction, + index, + matrix, + number, + sparse, + splitUnit, + string, + unit, + compile, + evaluate, + help, + parse, + parser, + + // algebra + derivative, + lsolve, + lup, + lusolve, + polynomialRoot, + qr, + rationalize, + simplify, + simplifyConstant, + simplifyCore, + resolve, + slu, + usolve, + + // arithmetic functions + abs, + add, + cbrt, + ceil, + fix, + floor, + round, + cube, + divide, + dotDivide, + dotMultiply, + dotPow, + exp, + expm1, + gcd, + hypot, + lcm, + log, + log10, + log1p, + log2, + mod, + multiply, + norm, + nthRoot, + pow, + sign, + sqrt, + square, + subtract, + unaryMinus, + unaryPlus, + xgcd, + + // bitwise + bitAnd, + bitNot, + bitOr, + bitXor, + leftShift, + rightArithShift, + rightLogShift, + + // combinatorics + bellNumbers, + catalan, + composition, + stirlingS2, + + // complex + arg, + conj, + im, + re, + + // geometry + distance, + intersect, + + // logical + and, + not, + or, + xor, + + // matrix functions + apply, + concat, + cross, + det, + diag, + dot, + eigs, + expm, + sylvester, + schur, + lyap, + identity, + filter, + flatten, + forEach, + inv, + kron, + map, + ones, + partitionSelect, + pinv, + range, + reshape, + resize, + rotationMatrix, + row, + column, + rotate, + size, + sort, + sqrtm, + squeeze, + subset, + trace, + transpose, + zeros, + fft, + ifft, + + // probability + combinations, + factorial, + gamma, + kldivergence, + lgamma, + multinomial, + permutations, + pickRandom, + random, + randomInt, + + // relational functions + compare, + compareNatural, + compareText, + deepEqual, + equal, + equalText, + larger, + largerEq, + smaller, + smallerEq, + unequal, + + // set functions + setCartesian, + setDifference, + setDistinct, + setIntersect, + setIsSubset, + setMultiplicity, + setPowerset, + setSize, + setSymDifference, + setUnion, + + // special functions + zpk2tf, + freqz, + erf, + zeta, + + // Statistics functions + mad, + max, + mean, + median, + min, + mode, + prod, + quantileSeq, + std, + sum, + count, + cumsum, + variance, + corr, + + // String functions + format, + print, + + // Trigonometry functions + acos, + acosh, + acot, + acoth, + acsc, + acsch, + asec, + asech, + asin, + asinh, + atan, + atan2, + atanh, + cos, + cosh, + cot, + coth, + csc, + csch, + sec, + sech, + sin, + sinh, + tan, + tanh, + + // unit functions + to, + + // util functions + isNumber, + isBigNumber, + isComplex, + isFraction, + isUnit, + isString, + isArray, + isMatrix, + isCollection, + isDenseMatrix, + isSparseMatrix, + isRange, + isIndex, + isBoolean, + isResultSet, + isHelp, + isFunction, + isDate, + isRegExp, + isObject, + isNull, + isUndefined, + isAccessorNode, + isArrayNode, + isAssignmentNode, + isBlockNode, + isConditionalNode, + isConstantNode, + isFunctionAssignmentNode, + isFunctionNode, + isIndexNode, + isNode, + isObjectNode, + isOperatorNode, + isParenthesisNode, + isRangeNode, + isRelationalNode, + isSymbolNode, + isChain, + clone, + hasNumericValue, + isInteger, + isNaN, + isNegative, + isNumeric, + isPositive, + isPrime, + isZero, + typeOf +}: MathJsInstance