A list of features for mathflow - based on numpy, mathjs and more.
Every mathflow value is a plain number. A function is in scope when it takes
numbers and returns a single number; anything list-shaped is exposed as a
variadic builtin, so a data set is written mean(1, 2, 3) rather than
mean([1, 2, 3]).
Predicates return 1 or 0, since there is no boolean type.
See Not planned for what this rules out, and why.
-
add(a, b, ...): Adds all numbers. -
sub(a, b): Subtracts the second number from the first. -
mul(a, b, ...): Multiplies all numbers. -
div(a, b): Divides the first number by the second. -
mod(a, b): Returns the remainder of division of two numbers. -
abs(x): Returns the absolute value of a number. -
ceil(x): Rounds a number up to the nearest integer. -
floor(x): Rounds a number down to the nearest integer. -
sign(x): Returns the sign of a number:-1,0, or1. -
sqrt(x): Returns the square root of a number. -
pow(x, y): Raisesxto the power ofy. -
cbrt(x): Computes the cube root of a number. -
root(x, n): Computes the n-th root of a number. -
trunc(x): Removes the fractional part of a number. -
round(x, n?): Rounds to the nearest integer or tondecimal places. -
roundToNearest(x, step): Roundsxto the nearest multiple ofstep. -
precision(x, n): Adjusts a number tonsignificant digits. -
clamp(x, min, max): Clamps a value between a minimum and maximum. -
gcd(a, b, ...): Greatest common divisor of all numbers. -
lcm(a, b, ...): Least common multiple of all numbers. -
modExp(base, exponent, modulus): Modular exponentiation. -
lerp(a, b, t): Linear interpolation betweenaandb. -
hermite(p0, m0, p1, m1, t): Cubic Hermite interpolation.
All variadic - mean(1, 2, 3), not mean([1, 2, 3]).
-
sum(...x): Sum of all values. -
prod(...x): Product of all values. -
min(...x): Smallest value. -
max(...x): Largest value. -
mean(...x): Arithmetic mean. -
median(...x): Median value. -
mode(...x): Most frequent value, the smallest of them on a tie. -
quantile(p, ...x): Quantile at probabilityp, interpolated. -
variance(...x): Sample variance, then - 1normalization. -
std(...x): Sample standard deviation. -
mad(...x): Mean absolute deviation. -
entropy(...x): Shannon entropy in nats, over the given distribution. -
geometricMean(...x): Geometric mean. -
harmonicMean(...x): Harmonic mean. -
skewness(...x): Skewness, indicating asymmetry. -
kurtosis(...x): Excess kurtosis -0for a normal distribution.
-
factorial(n): Factorial ofn. -
combinations(n, k): Ways to choosekitems fromn. -
permutations(n, k): Ways to arrangekitems out ofn. -
stirlingApproximation(n): Approximatesn!by Stirling's formula. -
isPrime(n):1ifnis prime, else0. -
fibonacci(n): The n-th Fibonacci number. -
birthdayProblem(n, days?): Chance two ofnshare one ofdaysdays. -
random(min?, max?): Random number - unit,[0, min), or[min, max). -
randomInt(min?, max?): Asrandom, truncated to an integer. -
pickRandom(...x): Randomly selects one of the given values.
-
deg(x): Converts the angle from radians to degrees. -
rad(x): Converts the angle from degrees to radians. -
sin(x),cos(x),tan(x): In the context's angle unit. -
sind(x),cosd(x),tand(x): Always in degrees. -
sec(x),csc(x),cot(x): Reciprocal functions. -
asin(x),acos(x),atan(x): Take a ratio, return an angle. -
atan2(y, x): Angle from the x-axis to the point (x,y). -
sinh(x),cosh(x),tanh(x): Hyperbolic, on plain reals. -
asinh(x),acosh(x),atanh(x): Inverse hyperbolic, on plain reals. -
hypot(a, b, ...): Euclidean norm. -
versin(x),coversin(x): Versine and coversine. -
versind(x),coversind(x): The same, always in degrees.
-
exp(x): Computeseraised to the power ofx. -
expm1(x):e^x - 1, accurate for smallx. -
ln(x): Natural logarithm. -
log(x, base?): Logarithm ofx, base 10 by default. -
log10(x),log2(x): Base-10 and base-2 logarithms. -
log1p(x):log(1 + x), accurate for smallx. -
pow10(x),pow2(x): Powers of 10 and 2.
-
gamma(x): Gamma function, an extension of the factorial. -
lngamma(x): Natural log of the gamma function. -
digamma(x): Logarithmic derivative of the gamma function. -
beta(a, b): Beta function. -
gammaIncomplete(a, x): Lower incomplete gamma, unregularized. -
erf(x),erfc(x): Error function and its complement. -
zeta(s): Riemann zeta function. -
lambertW(x): Lambert W function, principal branch. -
sinc(x): Unnormalizedsin(x)/x, always in radians. -
heaviside(x): Step function,0.5at the origin.
-
totient(n): Euler's totient function. -
mobius(n): Mobius function. -
isPerfectSquare(n):1ifnis a perfect square, else0.
-
futureValue(principal, rate, periods): Future value of an investment. -
presentValue(future, rate, periods): Present value of a future sum. -
compoundInterest(principal, rate, times, periods): Accrued amount. -
annuityPayment(rate, periods, present): Level payment of an annuity.
Ruled out to keep every value a plain number and the library small.
Needs an array value type - matrices and vectors (matrix, det, inv,
transpose, dot, cross, reshape, norm, ...), signal processing
(fft, dft, convolve, correlate), and vector geometry (projection,
angleBetween, reflect, intersect).
Returns a list rather than a number - shuffle, primeFactors,
divisors, range, lagrange, spline.
Needs two independent lists - covariance, corr, weightedMean. These
cannot be written variadically.
Needs a different numeric type - complex and everything on it (re,
im, arg, conj, ...), plus bignumber and fraction.
Symbolic, not numeric - simplify, expand, derivative, integrate,
rationalize, and solving an equation for a variable. These need a computer
algebra system, which is a different project from an evaluator.
Takes a function as a value - numericDerivative. There is no function
type.
Already covered - one name per behaviour, so nothing is implemented twice:
fix is trunc, sigFigs is precision, rand/randi are
random/randomInt, and binomialCoefficient is combinations. parse and
evaluate(expr, scope?) are the public parse and solve APIs.