UNPKG

mathjslab

Version:

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

776 lines (775 loc) 25.3 kB
import { Decimal } from 'decimal.js'; /** * Binary operations name type. */ export type TBinaryOperationName = 'add' | 'sub' | 'mul' | 'rdiv' | 'ldiv' | 'power' | 'lt' | 'le' | 'eq' | 'ge' | 'gt' | 'ne' | 'and' | 'or' | 'xor' | 'mod' | 'rem' | 'minWise' | 'maxWise'; /** * Unary operations name type. */ export type TUnaryOperationLeftName = 'copy' | 'neg' | 'not'; /** * # ComplexDecimal * * An arbitrary precision complex number library. * * ## References * * https://mathworld.wolfram.com/ComplexNumber.html */ export declare class ComplexDecimal { /** * Functions with one argument (mappings) */ static mapFunction: Record<string, Function>; /** * Functions with two arguments. */ static twoArgFunction: Record<string, Function>; /** * Most restricted number class. */ static readonly numberClass: Record<string, number>; /** * Real, imaginary and type properties. */ re: Decimal; im: Decimal; type: number; parent: any; static setNumberType(value: ComplexDecimal): void; /** * ComplexDecimal constructor * @param re Real part (optional). * @param im Imaginary part (optional). * @param type Class 'complex' | 'logical' (optional). */ constructor(re?: number | string | Decimal, im?: number | string | Decimal, type?: number); /** * Real part of complex number. * @param z value. * @returns Real part of z */ static real(z: ComplexDecimal): ComplexDecimal; /** * Imaginary part of complex number. * @param z value. * @returns Imaginary part of z */ static imag(z: ComplexDecimal): ComplexDecimal; /** * Check if object is a ComplexDecimal compatible. * @param obj Any object to check if is CompleDecimal compatible. * @returns boolean result. */ static isThis(obj: any): boolean; /** * Create new ComplexDecimal. * @param re Real part (optional). * @param im Imaginary part (optional). * @param type Class 'complex' | 'logical' (optional). * @returns new ComplexDecimal(re, im, type). */ static newThis(re?: number | string | Decimal, im?: number | string | Decimal, type?: number): ComplexDecimal; /** * Parse string returning its ComplexDecimal value. * @param value String to parse. * @returns ComplexDecimal parsed value. */ static parse(value: string): ComplexDecimal; /** * Unparse real or imaginary part. * @param value Decimal value * @returns String of unparsed value */ private static unparseDecimal; /** * Unparse ComplexDecimal value. Show true/false if logical value, * otherwise show real and imaginary parts enclosed by parenthesis. If * some part is zero the null part is ommited (and parenthesis is ommited * too). * @param value Value to unparse. * @returns String of unparsed value. */ static unparse(value: ComplexDecimal): string; /** * Unparse real or imaginary part. * @param value Decimal value * @returns string of value unparsed */ private static unparseDecimalML; /** * Unparse ComplexDecimal value as MathML language. Show true/false if * logical value, otherwise show real and imaginary parts enclosed by * parenthesis. If some part is zero the null part is ommited (and * parenthesis is ommited too). * @param value value to unparse. * @returns string of unparsed value. */ static unparseMathML(value: ComplexDecimal): string; /** * Creates a copy of the value. * @param value ComplexDecimal value * @returns copy of value */ static copy(value: ComplexDecimal): ComplexDecimal; /** * Reduce precision of real or imaginary part. * @param value Full precision value. * @returns Reduced precision value. */ private static toMaxPrecisionDecimal; /** * Reduce precision. * @param value Full precision value. * @returns Reduced precision value. */ static toMaxPrecision(value: ComplexDecimal): ComplexDecimal; /** * Get the minimal diference of two consecutive numbers for real or * imaginary part, the floating-point relative accuracy. * @returns Minimal diference of two consecutive numbers. */ private static epsilonDecimal; /** * Get the minimal diference of two consecutive numbers, the * floating-point relative accuracy. * @returns Minimal diference of two consecutive numbers. */ static epsilon(): ComplexDecimal; /** * Test for equality. * @param left Value. * @param right Value. * @returns Returns ComplexDecimal.true() if left and right are equals. */ static eq(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; /** * Test for inequality. * @param left Value. * @param right Value. * @returns Returns ComplexDecimal.true() if left and right are different. */ static ne(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; /** * Comparison made in polar lexicographical ordering. It's ordered by * absolute value, or by polar angle in (-pi,pi] when absolute values are * equal. * @param cmp Type of comparison. * @param left Value. * @param right Value. * @returns Result of comparison as ComplexDecimal.true() or ComplexDecimal.false(). */ private static cmp; /** * Gets the maximum or minimum of an array of ComplexDecimal using real comparison. * @param cmp 'lt' for minimum or 'gt' for maximum. * @param args ComplexDecimal values. * @returns Minimum or maximum of ComplexDecimal values. */ static minMaxArrayReal(cmp: 'lt' | 'gt', ...args: ComplexDecimal[]): ComplexDecimal; static minMaxArrayRealWithIndex(cmp: 'lt' | 'gt', ...args: ComplexDecimal[]): [ComplexDecimal, number]; /** * Gets the maximum or minimum of an array of ComplexDecimal using complex * comparison. The arguments are in polar lexicographical ordering * (ordered by absolute value, or by polar angle in (-pi,pi] when absolute * values are equal). * @param cmp 'lt' for minimum or 'gt' for maximum. * @param args ComplexDecimal values. * @returns Minimum or maximum of ComplexDecimal values. */ static minMaxArrayComplex(cmp: 'lt' | 'gt', ...args: ComplexDecimal[]): ComplexDecimal; static minMaxArrayComplexWithIndex(cmp: 'lt' | 'gt', ...args: ComplexDecimal[]): [ComplexDecimal, number]; /** * Returns the minimum of arguments. The arguments are in polar * lexicographical ordering (ordered by absolute value, or by polar angle * in (-pi,pi] when absolute values are equal). * @param left Value to compare. * @param right Value to compare. * @returns Minimum of left and right */ static min(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; static minWise(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; /** * Returns the maximum of arguments. The arguments are in polar * lexicographical ordering (ordered by absolute value, or by polar angle * in (-pi,pi] when absolute values are equal). * @param left Value to compare. * @param right Value to compare. * @returns Maximum of left and right */ static max(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; static maxWise(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; /** * Less than comparison (lexicographical ordering). * @param left Value. * @param right Value. * @returns Result of comparison left<right as ComplexDecimal.true() or ComplexDecimal.false(). */ static lt(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; /** * Less than or equal comparison (lexicographical ordering). * @param left Value. * @param right Value. * @returns Result of comparison left<=right as ComplexDecimal.true() or ComplexDecimal.false(). */ static le(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; /** * Greater than comparison (lexicographical ordering). * @param left Value. * @param right Value. * @returns Result of comparison left>right as ComplexDecimal.true() or ComplexDecimal.false(). */ static gt(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; /** * Greater than or equal comparison (lexicographical ordering). * @param left Value. * @param right Value. * @returns Result of comparison left>=right as ComplexDecimal.true() or ComplexDecimal.false(). */ static ge(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; /** * ComplexDecimal logical false. * @returns new ComplexDecimal(0, 0, 'logical') */ static false(): ComplexDecimal; /** * ComplexDecimal logical true. * @returns new ComplexDecimal(1, 0, 'logical') */ static true(): ComplexDecimal; /** * Convert numeric values to logicals. * @param value ComplexDecimal decimal value. * @returns ComplexDecimal logical value. */ static logical(value: ComplexDecimal): ComplexDecimal; /** * Logical **AND**. * @param left Value. * @param right Value. * @returns left AND right. */ static and(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; /** * Logical **OR**. * @param left Value. * @param right Value. * @returns left OR right. */ static or(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; /** * Logical **XOR**. * @param left Value. * @param right Value. * @returns left XOR right. */ static xor(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; /** * Logical **NOT**. * @param right Value. * @returns NOT right. */ static not(right: ComplexDecimal): ComplexDecimal; /** * 0 * @returns 0 as ComplexDecimal. */ static zero(): ComplexDecimal; /** * 1 * @returns 1 as ComplexDecimal. */ static one(): ComplexDecimal; /** * 1/2 * @returns 1/2 as ComplexDecimal. */ static onediv2(): ComplexDecimal; /** * -1/2 * @returns -1/2 as ComplexDecimal. */ static minusonediv2(): ComplexDecimal; /** * -1 * @returns -1 as ComplexDecimal. */ static minusone(): ComplexDecimal; /** * pi * @returns pi as ComplexDecimal. */ static pi(): ComplexDecimal; /** * pi/2 * @returns pi/2 as ComplexDecimal. */ static pidiv2(): ComplexDecimal; /** * i * @returns i as ComplexDecimal. */ static onei(): ComplexDecimal; /** * i/2 * @returns i/2 as ComplexDecimal. */ static onediv2i(): ComplexDecimal; /** * -i/2 * @returns -i/2 as ComplexDecimal. */ static minusonediv2i(): ComplexDecimal; /** * -i * @returns -i as ComplexDecimal. */ static minusonei(): ComplexDecimal; /** * 2 * @returns 2 as ComplexDecimal. */ static two(): ComplexDecimal; /** * sqrt(2*pi) * @returns sqrt(2*pi) as ComplexDecimal. */ static sqrt2pi(): ComplexDecimal; /** * e (Napier number). * @returns e as ComplexDecimal. */ static e(): ComplexDecimal; /** * NaN * @returns NaN as ComplexDecimal. */ static NaN_0(): ComplexDecimal; /** * Inf * @returns Inf as ComplexDecimal. */ static inf_0(): ComplexDecimal; /** * Addition of ComplexDecimal numbers. * @param left Value. * @param right Value. * @returns left + right */ static add(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; /** * Subtraction of ComplexDecimal numbers. * @param left Value * @param right Value * @returns left - right */ static sub(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; /** * Negates the ComplexDecimal number. * @param z Value. * @returns -z */ static neg(z: ComplexDecimal): ComplexDecimal; /** * Multiplication of ComplexDecimal numbers. * @param left Value. * @param right Value. * @returns left * right */ static mul(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; /** * Right Division. * @param left Dividend. * @param right Divisor. * @returns left / right. */ static rdiv(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; /** * Left division. For ComplexDecimal the left division is the same of right division. * @param left Dividend. * @param right Divisor. * @returns left \ right. */ static ldiv: typeof ComplexDecimal.rdiv; /** * Inverse. * @param x Denominator * @returns 1/x */ static inv(x: ComplexDecimal): ComplexDecimal; /** * Power of ComplexDecimal numbers. * @param left Base. * @param right Exponent. * @returns left^right */ static power(left: ComplexDecimal, right: ComplexDecimal): ComplexDecimal; /** * Root of ComplexDecimal numbers. * @param x Radicand. * @param n Index. * @returns nth root of x. */ static root(x: ComplexDecimal, n: ComplexDecimal): ComplexDecimal; /** * Absolute value and complex magnitude. * @param z value * @returns Absolute value of z */ static abs(z: ComplexDecimal): ComplexDecimal; /** * Square root of sum of squares (hypotenuse) * @param x vertex. * @param y vertex. * @returns hypotenuse of the two orthogonal vertex x and y. */ static hypot(x: ComplexDecimal, y: ComplexDecimal): ComplexDecimal; /** * Phase angle. * @param z value. * @returns Phase angle of z. */ static arg(z: ComplexDecimal): ComplexDecimal; /** * Complex conjugate * @param z value. * @returns Complex conjugate of z */ static conj(z: ComplexDecimal): ComplexDecimal; /** * Remainder after division (modulo operation). By convention * mod(a,0) = a. * @param x Dividend. * @param y Divisor. * @returns Remainder after division. */ static mod(x: ComplexDecimal, y: ComplexDecimal): ComplexDecimal; /** * Remainder after division. By convention rem(a,0) = NaN. * @param x Dividend. * @param y Divisor. * @returns Remainder after division. */ static rem(x: ComplexDecimal, y: ComplexDecimal): ComplexDecimal; /** * Round toward zero. This operation effectively truncates the number to * integer by removing the decimal portion. * @param z Value. * @returns Integer portion of z. */ static fix(z: ComplexDecimal): ComplexDecimal; /** * Round toward positive infinity. * @param z Value * @returns Smallest integer greater than or equal to z. */ static ceil(z: ComplexDecimal): ComplexDecimal; /** * Round toward negative infinity. * @param z Value * @returns Largest integer less than or equal to z. */ static floor(z: ComplexDecimal): ComplexDecimal; /** * Round to nearest integer. * @param z Value. * @returns Nearest integer of z. */ static round(z: ComplexDecimal): ComplexDecimal; /** * Sign function (signum function). * @param z Value. * @returns * * 1 if the corresponding element of z is greater than 0. * * 0 if the corresponding element of z equals 0. * * -1 if the corresponding element of z is less than 0. * * z/abs(z) if z is complex. */ static sign(z: ComplexDecimal): ComplexDecimal; /** * Square root. * @param z Value. * @returns Square root of z. */ static sqrt(z: ComplexDecimal): ComplexDecimal; /** * Exponential * @param z Value. * @returns Exponential of z. */ static exp(z: ComplexDecimal): ComplexDecimal; /** * Natural logarithm. * @param z Value. * @returns Natural logarithm of z. */ static log(z: ComplexDecimal): ComplexDecimal; /** * Compute the log using a specified base. * @param b Base. * @param l Value. * @returns Logarith base b of l. */ static logb(b: ComplexDecimal, l: ComplexDecimal): ComplexDecimal; /** * Base 2 logarithm * @param z Value * @returns logarithm base 2 of z. */ static log2(z: ComplexDecimal): ComplexDecimal; /** * Common logarithm (base 10) * @param z Value * @returns logarithm base 10 of z. */ static log10(z: ComplexDecimal): ComplexDecimal; /** * Convert angle from degrees to radians. * @param z Angle in degrees. * @returns Angle in radians. */ static deg2rad(z: ComplexDecimal): ComplexDecimal; /** * Convert angle from radians to degrees. * @param z Angle in radians. * @returns Angle in degrees. */ static rad2deg(z: ComplexDecimal): ComplexDecimal; /** * Trignometric sine. * @param z Argument in radians. * @returns Sine of z. */ static sin(z: ComplexDecimal): ComplexDecimal; /** * Trignometric sine in degrees. * @param z Argument in degrees. * @returns Sine of z */ static sind(z: ComplexDecimal): ComplexDecimal; /** * Trignometric cosine. * @param z Argument in radians. * @returns Cosine of z. */ static cos(z: ComplexDecimal): ComplexDecimal; /** * Trignometric cosine in degrees. * @param z Argument in degrees. * @returns Cosine of z */ static cosd(z: ComplexDecimal): ComplexDecimal; /** * Trigonometric tangent. Implemented as: tan(z) = sin(z)/cos(z) * @param z Argument in radians. * @returns Tangent of z. */ static tan(z: ComplexDecimal): ComplexDecimal; /** * Trigonometric tangent in degrees. * @param z Argument in degrees. * @returns Tangent of z. */ static tand(z: ComplexDecimal): ComplexDecimal; /** * Trigonometric cosecant. Implemented as csc(z)=1/sin(z) * @param z Argument in radians. * @returns Cosecant of z. */ static csc(z: ComplexDecimal): ComplexDecimal; /** * Trigonometric cosecant in degrees. * @param z Argument in degrees. * @returns Cosecant of z. */ static cscd(z: ComplexDecimal): ComplexDecimal; /** * Trigonometric secant. Implemented as: sec(z) = 1/cos(z) * @param z Argument in radians. * @returns Secant of z. */ static sec(z: ComplexDecimal): ComplexDecimal; /** * Trigonometric secant in degrees. * @param z Argument in degrees. * @returns Secant of z. */ static secd(z: ComplexDecimal): ComplexDecimal; /** * Trigonometric cotangent. Implemented as: cot(z) = cos(z)/sin(z) * @param z Argument in radians. * @returns Cotangent of z. */ static cot(z: ComplexDecimal): ComplexDecimal; /** * Trigonometric cotangent in degrees. * @param z Argument in degrees. * @returns Cotangent of z. */ static cotd(z: ComplexDecimal): ComplexDecimal; /** * Inverse (arc) sine. Implemented as: asin(z) = I*ln(sqrt(1-z^2)-I*z) * @param z Argument (unitless). * @returns Inverse sine of z in radians. */ static asin(z: ComplexDecimal): ComplexDecimal; /** * Inverse (arc) sine in degrees. * @param z Argument (unitless). * @returns Inverse sine of z in degrees. */ static asind(z: ComplexDecimal): ComplexDecimal; /** * Inverse (arc) cosine. Implemented as: acos(z) = pi/2-asin(z) * @param z Argument (unitless). * @returns Inverse cosine of z in radians. */ static acos(z: ComplexDecimal): ComplexDecimal; /** * Inverse (arc) cosine in degrees. * @param z Argument (unitless). * @returns Inverse cosine of z in degrees. */ static acosd(z: ComplexDecimal): ComplexDecimal; /** * Inverse (arc) tangent. Implemented as: atan(z) = -I/2*ln((I-z)/(I+z)) * @param z Argument (unitless). * @returns Inverse tangent of z in radians. */ static atan(z: ComplexDecimal): ComplexDecimal; /** * Inverse (arc) tangent in degrees. * @param z Argument (unitless). * @returns Inverse tangent of z in degrees. */ static atand(z: ComplexDecimal): ComplexDecimal; /** * Inverse (arc) cosecant. Implemented as: acsc(z) = asin(1/z) * @param z Argument (unitless). * @returns Inverse cosecant of z in radians. */ static acsc(z: ComplexDecimal): ComplexDecimal; /** * Inverse (arc) cosecant in degrees. * @param z Argument (unitless). * @returns Inverse cosecant of z in degrees. */ static acscd(z: ComplexDecimal): ComplexDecimal; /** * Inverse (arc) secant. Implemented as: asec(z) = acos(1/z) * @param z Argument (unitless). * @returns Inverse secant of z in radians. */ static asec(z: ComplexDecimal): ComplexDecimal; /** * Inverse (arc) secant in degrees. * @param z Argument (unitless). * @returns Inverse secant of z in degrees. */ static asecd(z: ComplexDecimal): ComplexDecimal; /** * Inverse (arc) cotangent. Implemented as: acot(z) = atan(1/z) * @param z Argument (unitless). * @returns Inverse cotangent of z in radians. */ static acot(z: ComplexDecimal): ComplexDecimal; /** * Inverse (arc) cotangent in degrees. * @param z Argument (unitless). * @returns Inverse cotangent of z in degrees. */ static acotd(z: ComplexDecimal): ComplexDecimal; /** * Hyperbolic sine. * @param z Argument. * @returns Hyperbolic sine of z. */ static sinh(z: ComplexDecimal): ComplexDecimal; /** * Hyperbolic cosine. * @param z Argument. * @returns Hyperbolic cosine of z. */ static cosh(z: ComplexDecimal): ComplexDecimal; /** * Hyperbolic tangent. Implemented as: tanh(z) = sinh(z)/cosh(z) * @param z Argument. * @returns Hyperbolic tangent of z. */ static tanh(z: ComplexDecimal): ComplexDecimal; /** * Hyperbolic cosecant. Implemented as: csch(z) = 1/sinh(z) * @param z Argument. * @returns Hyperbolic cosecant of z. */ static csch(z: ComplexDecimal): ComplexDecimal; /** * Hyperbolic secant. Implemented as: sech(z) = 1/cosh(z) * @param z Argument. * @returns Hyperbolic secant of z. */ static sech(z: ComplexDecimal): ComplexDecimal; /** * Hyperbolic cotangent. Implemented as: coth(z) = cosh(z)/sinh(z) * @param z Argument. * @returns Hyperbolic cotangent of z. */ static coth(z: ComplexDecimal): ComplexDecimal; /** * Inverse (area) hyperbolic sine. Implemented as: asinh(z) = ln(sqrt(1+z^2)+z) * @param z Argument. * @returns Inverse hyperbolic sine of z. */ static asinh(z: ComplexDecimal): ComplexDecimal; /** * Inverse (area) hyperbolic cosine. Implemented as: acosh(z) = ln(sqrt(-1+z^2)+z) * @param z Argument. * @returns Inverse hyperbolic cosine of z. */ static acosh(z: ComplexDecimal): ComplexDecimal; /** * Inverse (area) hyperbolic tangent. Implemented as: atanh(z) = 1/2*ln((1+z)/(1-z)) * @param z Argument. * @returns Inverse hyperbolic tangent of z. */ static atanh(z: ComplexDecimal): ComplexDecimal; /** * Inverse (area) hyperbolic cosecant. Implemented as: acsch(z) = asinh(1/z) * @param z Argument. * @returns Inverse hyperbolic cosecant of z. */ static acsch(z: ComplexDecimal): ComplexDecimal; /** * Inverse (area) hyperbolic secant. Implemented as: asech(z) = acosh(1/z) * @param z Argument. * @returns Inverse hyperbolic secant of z. */ static asech(z: ComplexDecimal): ComplexDecimal; /** * Inverse (area) hyperbolic cotangent. Implemented as: acoth(z) = atanh(1/z) * @param z Argument. * @returns Inverse hyperbolic cotangent of z. */ static acoth(z: ComplexDecimal): ComplexDecimal; /** * Compute the Gamma function. * The Gamma function is defined as integral with t from 0 to infinity of t^(z-1)*exp(-t) * * ## References * * https://rosettacode.org/wiki/Gamma_function#JavaScript * * https://en.wikipedia.org/wiki/Lanczos_approximation * * https://math.stackexchange.com/questions/19236/algorithm-to-compute-gamma-function * * https://en.wikipedia.org/wiki/Gamma_function#Stirling's_formula * * https://mathworld.wolfram.com/GammaFunction.html * * https://www.geeksforgeeks.org/gamma-function/ * * https://octave.org/doxygen/dev/d0/d77/gamma_8f_source.html * @param z * @returns */ static gamma(z: ComplexDecimal): ComplexDecimal; /** * Factorial. * @param x Argument. * @returns Factorial of x. */ static factorial(x: ComplexDecimal): ComplexDecimal; }