UNPKG

mathjslab

Version:

MathJSLab - An interpreter with language syntax like MATLAB®/Octave, ISBN 978-65-00-82338-7.

301 lines (300 loc) 7.7 kB
/** * Filename: `MathOperation.ts` * Description: Definitions of mathematical operations on elements of various * basic types. */ import { type ElementType } from './MultiArray'; /** * Generic mathematical object. */ type MathObject = ElementType; /** * Unary mathematical operations. */ type UnaryMathOperation = (expression: MathObject) => MathObject; /** * Binary mathematical operations. */ type BinaryMathOperation = (left: MathObject, right: MathObject) => MathObject; /** * Unary mathematical operations. */ type MathOperationType = UnaryMathOperation | BinaryMathOperation; /** * Key of type `MathOperation`. Keys of the `MathOperation` class that are static methods. */ type KeyOfTypeOfMathOperation = Exclude<keyof typeof MathOperation, 'prototype' | 'unaryOperations' | 'binaryOperations' | 'leftAssociativeMultipleOperations'>; /** * # `MathOperation` * * Mathematical operations on generic elements. * */ declare abstract class MathOperation { private static readonly elementWiseOperatorSymbols; private static readonly unaryOperatorSymbols; /** * Creates a copy of `MathObject` object. * @param value * @returns */ static readonly copy: UnaryMathOperation; /** * Element-Wise operations. * @param op * @param left * @param right * @returns */ private static readonly elementWiseOperation; private static readonly hasStructureOperand; private static readonly hasCellOperand; private static readonly throwIfCellBinaryOperand; private static readonly throwIfStructureBinaryOperand; private static readonly throwIfCellUnaryOperand; private static readonly throwIfStructureUnaryOperand; private static readonly hasClassInstanceOperand; private static readonly handleComparisonOrder; private static nextHandleComparisonOrder; private static readonly handleOrder; private static readonly numericScalarValue; private static readonly classInstanceRelationalOperation; /** * Left associative operations. * @param op * @param right * @returns */ private static readonly leftOperation; /** * Plus operation (`+`). * @param left * @param right * @returns */ static readonly plus: BinaryMathOperation; /** * Minus operation (`-`). * @param left * @param right * @returns */ static readonly minus: BinaryMathOperation; /** * Mod operation. * @param left * @param right * @returns */ static readonly mod: BinaryMathOperation; /** * Rem operation. * @param left * @param right * @returns */ static readonly rem: BinaryMathOperation; /** * Times operation (`.*`). * @param left * @param right * @returns */ static readonly times: BinaryMathOperation; /** * Matrix multiplication operator (`*`). * @param left * @param right * @returns */ static readonly mtimes: BinaryMathOperation; /** * Right division operator (`./`). * @param left * @param right * @returns */ static readonly rdivide: BinaryMathOperation; /** * Matrix right division operator (`/`). * @param left * @param right * @returns */ static readonly mrdivide: BinaryMathOperation; /** * Left division operator (`.\`). * @param left * @param right * @returns */ static readonly ldivide: BinaryMathOperation; /** * Matrix left division operator (`\`). * @param left * @param right * @returns */ static readonly mldivide: BinaryMathOperation; /** * Power operator (`.^`). * @param left * @param right * @returns */ static readonly power: BinaryMathOperation; /** * Matrix power operator (`^`). * @param left * @param right * @returns */ static readonly mpower: BinaryMathOperation; /** * * @param right * @returns */ static readonly uplus: UnaryMathOperation; /** * * @param right * @returns */ static readonly uminus: UnaryMathOperation; /** * * @param left * @returns */ static readonly transpose: UnaryMathOperation; /** * * @param left * @returns */ static readonly ctranspose: UnaryMathOperation; /** * * @param left * @param right * @returns */ static readonly lt: BinaryMathOperation; /** * * @param left * @param right * @returns */ static readonly le: BinaryMathOperation; /** * * @param left * @param right * @returns */ static readonly eq: BinaryMathOperation; /** * * @param left * @param right * @returns */ static readonly ge: BinaryMathOperation; /** * * @param left * @param right * @returns */ static readonly gt: BinaryMathOperation; /** * * @param left * @param right * @returns */ static readonly ne: BinaryMathOperation; /** * Scalar logical `&&` helper. * * Public expression evaluation short-circuits before this helper is called. * When it is reached directly, both operands are reduced with the * MATLAB/Octave condition rule: non-empty and all elements logically true. * * @param left Left logical operand. * @param right Right logical operand. * @returns Logical scalar result. */ static readonly mand: BinaryMathOperation; /** * Scalar logical `||` helper. * * Public expression evaluation short-circuits before this helper is called. * When it is reached directly, both operands are reduced with the * MATLAB/Octave condition rule: non-empty and all elements logically true. * * @param left Left logical operand. * @param right Right logical operand. * @returns Logical scalar result. */ static readonly mor: BinaryMathOperation; /** * Logical negation (`~` and Octave `!`) for numeric, logical, and * character-vector values. * * Structures, function handles, and other runtime-only objects are not * implicitly coerced here; MATLAB/Octave require logical operations to be * defined by the operand type itself. * * @param right Operand to negate. * @returns Element-wise logical negation of the operand. */ static readonly not: UnaryMathOperation; /** * * @param left * @param right * @returns */ static readonly and: BinaryMathOperation; /** * * @param left * @param right * @returns */ static readonly or: BinaryMathOperation; /** * * @param left * @param right * @returns */ static readonly xor: BinaryMathOperation; /** * Unary operations. */ static readonly unaryOperations: { [OP in KeyOfTypeOfMathOperation]?: UnaryMathOperation; }; /** * Binary operations */ static readonly binaryOperations: { [OP in KeyOfTypeOfMathOperation]?: BinaryMathOperation; }; /** * Left associative multiple arguments operations. */ static readonly leftAssociativeMultipleOperations: { [OP in KeyOfTypeOfMathOperation]?: BinaryMathOperation; }; } export type { MathObject, UnaryMathOperation, BinaryMathOperation, MathOperationType, KeyOfTypeOfMathOperation }; export { MathOperation }; declare const _default: { MathOperation: typeof MathOperation; }; export default _default;