import { Fraction, NthRoot, SquareRoot, Term, Expression, Polynomial, AP, GP, Angle, Trig, Exp, Ln, Complex, ComplexExp, Vector, Line, Plane, ExpFn, LnFn, PowerFn, PolynomialFn, LinearFn, CosFn, SinFn, integrate, differentiate, maclaurin, DE, gcd, factorize, solveQuadratic, getRandomInt, getRandomFrac, getRandomLinear, getRandomQuadratic, getRandomVec, RationalFunction } from 'math-edu'; import { factorial } from 'simple-statistics'; // '../../../../math-edu/src/index'; /** * Interval class * default: `{left: -Infinity, right: Infinity, lOpen: true, rOpen: true}`; * @param left number or Fraction of the lower bound * @param lOpen whether the left bound is 'open' or 'closed' * */ declare class Interval { //// instance properties left: number | Fraction; right: number | Fraction; lOpen: boolean; rOpen: boolean; //// // constructor //// /** * Creates a new interval instance * defaults to `{left: -Infinity, right: Infinity, lOpen: true, rOpen: true}` */ constructor(left?: number | Fraction, right?: number | Fraction, lOpen?: boolean, rOpen?: boolean); //// // instance methods //// /** * @param options defaults to `{rangeMode: true, variableAtom: 'x'}` * where we will return the interval as an inequality * @returns LaTeX string representing the interval */ toString(options?: IntervalToStringOptions): string; /** * clones the Interval object */ clone(): Interval; /** * check if number or Fraction is inside this Interval */ contains(x: number | Fraction): boolean; /** * check if number or Fraction is at the boundary * @param left to test the left bound (false for right bound) (defaults to true) * @param open whether new number or Fraction is excluded (open: true) or included * @returns if value at boundary the same, return false if this has `(` while open is `[` */ atBoundary(x: number | Fraction, open: boolean, left?: boolean): boolean; /** * check if this Interval is a subset of a given Interval */ subsetEq(interval2: Interval): boolean; /** * gets the intersection of the two intervals * @returns `null` if disjoint */ intersect(interval2: Interval): Interval | null; /** * gets union of two intervals * @return an array of 1 or 2 intervals, depending on whether the intervals overlap * array will be arranged in ascending order */ union(interval2: Interval): Interval[]; /** * addition by a constant */ plus(x: number | Fraction): Interval; /** * multiplication by a constant */ times(x: number | Fraction): Interval; /** * exponentiation by `n` */ pow(n: number): Interval | Interval[]; //// // static methods //// /** * check if the first interval/intervals is a subset of the second intervals */ static IntervalsSubsetEq(intervals1: Interval | Interval[], intervals2: Interval | Interval[]): boolean; } interface IntervalToStringOptions { rangeMode?: boolean; variableAtom?: string; } /** * BasicFunction class * This class is meant to capture the domain and range characteristics of a function, * allowing us to make new functions through composition and inverse * The BasicFunction class encapsulates the simplest function types * * @expression Expression representing the function * @domain Interval or Interval[] representing the domain * @range Interval or Interval[] representing the range * @zeros Fraction[] representing the zeros of the function * @invertible whether the function is invertible * @type a [string, number | Fraction] array showing how this function is made * the first entry is either 'ax', 'x+b' or 'x^a' and the second entry is a * * WARNING: the range may not be simplified if complicated domains are provided * */ declare class BasicFunction { //// instance properties expression: Expression; domain: Interval | Interval[]; range: Interval | Interval[]; zeros: Fraction[]; invertible: boolean; type: [ "ax" | "x+a" | "x^a", number | Fraction ]; variableAtom: string; /** * Constructs a BasicFunction from one of three basic types: * @param type `ax`, `x+b` or `x^a` representing multiplication, addition or powers * @param a * @param options allows a custom domain and `variableAtom` (default `'x'`) */ constructor(type: "ax" | "x+a" | "x^a", a?: number | Fraction, options?: BasicFunctionOptions); /** * toString method: outputs latex string representing the function * @param options defaults to `{name: 'f', definitionMode: false}` * definitionMode true gives us the f:x\mapsto notation while false gives us the f(x) notation */ toString(options?: BasicFunctionToStringOptions): string; /** * Returns the inverse function * WARNING: currently only supported for 'ax' and 'x+b' type, with 'x^a' types only supported for a=-1 */ inverse(): BasicFunction; /** * @returns the GeneralFunction representation of this basic function */ toGeneralFunction(): GeneralFunction; clone(): BasicFunction; } ///////////////////////////////////////////////////////////////// // GeneralFunction //////////////////////////////////////////////////////////////// /** * GeneralFunction class * * @expression Expression representing the function * @domain Interval or Interval[] representing the domain * @range Interval or Interval[] representing the range * * WARNING: the range may not be simplified if complicated domains are provided * */ declare class GeneralFunction { expression: Expression; domain: Interval | Interval[]; range: Interval | Interval[]; constructor(expression: Expression, domain: Interval | Interval[], range: Interval | Interval[]); /** * toString method: outputs latex string representing the function * @param options defaults to `{name: 'f', definitionMode: false}` * definitionMode true gives us the f:x\mapsto notation while false gives us the f(x) notation */ toString(options?: BasicFunctionToStringOptions): string; } ///////////////////////////////////////////////////////////////// // FunctionChain //////////////////////////////////////////////////////////////// /** * FunctionChain class * The FunctionChain class builds a function through composition of * `BasicFunction`s (addition, scalar multiplication and exponentiation) * * @expression Expression representing the function * @domain Interval or Interval[] representing the domain * @range Interval or Interval[] representing the range * @chain a BasicFunction[] array showing how this function is composed * the order is such that the first entry is first. e.g. [f, g] will represent the function g \\circ f * * WARNING: the range may not be simplified if complicated domains are provided * */ declare class FunctionChain extends GeneralFunction { //// instance properties chain: BasicFunction[]; /** * given f, g, h, ... return the General Function representation of ...hgf(x) */ constructor(...basicFunctions: BasicFunction[]); /** * inverse */ inverse(): FunctionChain; } /** * @returns $g \\circ f$ * @param f the first argument (a `GeneralFunction`) * @param g is the second argument (a `BasicFunction`) * * WARNING: to ensure no errors, please check if they can be composed with the "canCompose function" */ declare function compose(f: GeneralFunction, g: BasicFunction): GeneralFunction; /** * checks if $g \\circ f$ is defined * i.e. if $R_f \\subseteq D_g$. */ declare function canCompose(f: BasicFunction | GeneralFunction, g: BasicFunction | GeneralFunction): boolean; interface BasicFunctionOptions { domain?: Interval | Interval[]; variableAtom?: string; } interface BasicFunctionToStringOptions { name?: string; definitionMode?: boolean; } declare class Normal { /** * class representing normally distributed random variable X ~ N(mu, sigma^2) */ mean: number; variance: number; //// // constructor //// /** * Creates a new normal r.v. instance * * @param mean population mean mu * @param variance population variance sigma^2 * */ constructor(mean: number, variance?: number); /** * adds two independently distributed normal r.v. * */ plus(Y: number | Normal): Normal; /** * multiplies by a scalar, nX ~ (n mu, n^2 sigma^2) * */ times(n: number): Normal; /** * divides by a scalar, 1/n X ~ (mu/n, sigma^2/n^2) * */ divide(n: number): Normal; /** * subtracts independently distributed normal r.v., this - Y * */ minus(Y: number | Normal): Normal; /** * sum X1 + ... + Xn ~ N(n mu, n sigma^2) */ sum(n: number): Normal; /** * sample mean XBar ~ N (mu, sigma^2 / n) */ bar(n: number): Normal; //// probability methods /** * less than * * @returns P(X < x) */ lessThan(x: number): number; /** * more than * * @returns P(X > x) */ moreThan(x: number): number; /** * between * * @returns P(x1 < X < x2) */ between(x1: number, x2: number): number; /** * invNorm * * @mode defaults to 'left' for left tail, accepts 'right' or 'center' * * @return x such that P(X < x) = p */ invNorm(p: number, mode?: string): number; /** * toString: returns `X ~ N(mu, sigma^2)` * * @param name symbol representing the r.v. (default `X`) */ toString(name?: string): string; } /** * binomPdf(n,p,x) * * @returns P(X=x) * * uses the implementation by [simple-statistics package](https://simplestatistics.org/) */ declare function binomPdf(n: number, p: number, x: number): number; /** * binomCdf(n,p,x) * * @returns P(X \leq x) * * uses the implementation by [simple-statistics package](https://simplestatistics.org/) */ declare function binomCdf(n: number, p: number, x: number): number; /** * binomCdfRange(n,p,x1,x2) * * @returns P(x1 \\leq X \leq x2) * * uses the implementation by [simple-statistics package](https://simplestatistics.org/) */ declare function binomCdfRange(n: number, p: number, lower: number, upper: number): number; /** * normCdf(mu, sigma, limits) * * @param limits defaults to {lower: -infinity, upper: infinity} (implemented by the MAX_VALUE property) * * @returns P(lower < X < upper) * * uses the implementation by [simple-statistics package](https://simplestatistics.org/) */ declare function normCdf(mu: number, sigma: number, limits: Limits): number; /** * invNorm(p, mu, sigma, mode) * * @param mu mean. defaults to 0 * @param sigma standard deviation. defaults to 1 * @param mode defaults to 'left' for left tail. Alternatives: 'right', 'center' for right and center * * @returns x such that P(X < x) = p for left tail. for 'center' mode, P(x1 < X < x2) = p, only x2 will be returned. * * uses the implementation of the inverse error function from [math-erfinv](https://github.com/math-io/erfinv) */ declare function invNorm(p: number, mu?: number, sigma?: number, mode?: string): number; /** * zTest(mu, sigma, xBar, n, tail) * * @param tail `'left'`(default), `'right'` or `'two'` * @returns p-value * * uses the implementation by [simple-statistics package](https://simplestatistics.org/) */ declare function zTest(mu: number, sigma: number, xBar: number, n: number, tail?: string): number; interface Limits { lower?: number; upper?: number; } declare function numberWithCommas(x: number): string; /** * implementation of the bisection method for numerical root finding. * * @param f function * @param lower lower bound (sign must be different at lower and upper) * @param upper upper bound (sign must be different at lower and upper) * @param precision number of digits after the decimal point to match before terminating */ declare function bisection(f: (x: number) => number, lower: number, upper: number, precision?: number): number; /** * implementation of Simpson's 1/3 rule for numerical integration. * * @param intervals number of intervals (defaults to 100) */ declare function simpsons(f: (x: number) => number, lower: number, upper: number, intervals?: number): number; /** * apply Cramer's rule to 2x2 [[a b], [d e]] = [[c], [f]] * or to 3x3 [[a b c], [e f g], [i j k] = [[d], [h], [l]]] */ declare function cramers(...args: number[]): number[]; /** * determinant of [[a b], [c d]] 2x2 matrix or [[a b c], [d e f], [g h i]] 3x3 matrix * * WARNING: does not work for any other sizes */ declare function determinant(...args: number[]): number; // '../../../../math-edu/src/index'; // get n random integers between lb and up /** * get `n` random integers between `min` and `max` (inclusive) * @param options `{unique: true, min: -9, max: 9, avoid: number[]}` * @return array of integers */ declare function getRandomInts(n: number, options?: randomIntsOptions): number[]; //// // interfaces //// /** * */ interface randomIntsOptions { /** whether the integers returned must be unique (or if repetition is allowed) */ unique?: boolean; /** min (inclusive) */ min?: number; /** max (inclusive) */ max?: number; /** numbers to avoid */ avoid?: number[]; } // '../../../../math-edu/src/index'; /** * generate a "nice" quadratic: * first root: a fraction of denominator 1 to 2 * second root: a fraction of denominator 1 to 4, different from the first root * numerators -9 to 9 (or negative) * @returns a `Polynomial` class representing the quadratic */ declare function getNiceQuadratic(avoid?: number[]): niceQuadraticOutput; /** * Output for `getRandomQuadratic`: */ interface niceQuadraticOutput { quadratic: Polynomial; coefficients: [ number, number, number ]; roots: [ Fraction, Fraction ]; // only rational outputs at the moment } // '../../../../math-edu/src/index'; /** * Generates a random Vector perpendicular to the given Vector * * @param options defaults: `{max: 9}` * where max refers to the maximum absolute value of each component * */ declare function getRandomPerp(v: Vector, options?: randomPerpOptions): Vector; /** * Options for generating perpendicular vectors */ interface randomPerpOptions { max?: number; } /** * encode into a string used to represent a "qn code" * the qn code will help debugging and for users to retrieve a specific qn * that was randomly generated */ declare function encode(...args: (number | string)[]): string; /** * decode a "qn code" * @returns an array with the numbers or str being represented by the code */ declare function decode(str: string): (number | string)[]; export { Fraction, NthRoot, SquareRoot, Term, Expression, Polynomial, Angle, Trig, Exp, Ln, Complex, ComplexExp, Vector, Line, Plane, AP, GP, gcd, factorize, solveQuadratic, getRandomInt, getRandomFrac, getRandomLinear, getRandomQuadratic, getRandomVec, RationalFunction, ExpFn, LnFn, PowerFn, PolynomialFn, LinearFn, SinFn, CosFn, differentiate, maclaurin, integrate, DE, Interval, BasicFunction, GeneralFunction, FunctionChain, compose, canCompose, getRandomInts, getRandomPerp, getNiceQuadratic, simpsons, bisection, cramers, determinant, Normal, binomPdf, binomCdf, binomCdfRange, normCdf, invNorm, zTest, factorial, numberWithCommas, encode, decode };