NuMath is basically an expansion of the math library of roblox, it includes vector operations, matrix operations (decompositions, eigenvalues and eigenvectors), complex numbers, integration, derivatives, or calculus in general, statistics functions, special functions, polynomial functions, and a bunch more!
Why NuMath was created, and its purpose?
It was created for more advanced mathematical situations, which the native math library on Lua 5.1 (roblox version of Lua) doesn’t include, like acosh, asinh, and atanh for exemple.
it may not include ALL of the mathematics that you will need, but, that’s why the feedbacks and suggestions exist.
Some of the functions of NuMath are:
SPECIAL PART
-
Gamma function
-
Beta function
-
Bessel functions, first and second kind
-
Chebyslev functions, first and second kind
-
Error function(erf)
-
More context about functions are there:
Gamma function - Wikipedia
Beta function - Wikipedia
Bessel function - Wikipedia
Chebyshev function - Wikipedia
Error function - Wikipedia
MATRIX OPERATIONS
-
Adding
-
Subtracting
-
Multiplication
-
Transpose
-
Inverse
-
Minor matrix
-
Cofactor matrix
-
Determinant
-
Eigenvalues and Eigenvectors
-
LU and SVD decomposition
-
Linear Transformation
-
More context about what is matrix and their operations are there:
Matrix (mathematics) - Wikipedia
MISCELLANEOUS
-
Quadratic formula solver
-
Reciprocal solver
-
Hypotenuse calculator
-
Asinh, Atanh and Acosh
-
“fix” function
-
expm1 – (e^x-)1
-
exp2 - 2^x.
-
log1p - In(1+x)
-
logaddexp(x1,x2) - In(e^x1 + e^x2)
-
logaddexp2(x1,x2) = In(2^x1 + 2^x2)
-
sinc - 1 if x = 0, and sin(pi * x)/pi * x if x is different of 0
-
GCD(Greatest Common Divisor) - uses extended euclidean algorithm - more information here: Extended Euclidean algorithm - Wikipedia
-
LCM (Least Common Multiple)
-
copysign function
-
ULP function
-
nextafter function
-
CBRT (cubic root) - (x)^1/3
-
nan_to_num - converts a extremely high number or a extremely low number(NaN) to a normal number(specifically, 1.79e308)
PRIME NUMBERS
-
Sieve of Eratosthenes - (primecountton)
-
Primality test
CALCULUS
-
ODE solver (first order only, uses RK4 method)
-
Integration (Trapezoidal and Simpson methods)
-
Root finding methods (Bisection, Secant and Newton-Raphson methods)
-
Binomial Coefficient
-
Sum (thanks for the script and suggestion by: matejHRAJE_cz)
-
Derivatives (for any order n, function and evaulation (x = 0 is supported))
-
Factorials
-
More context about functions are there:
Runge–Kutta methods - Wikipedia – more informations for the RK4
Integral - Wikipedia
Root-finding algorithm - Wikipedia
Binomial coefficient - Wikipedia
Derivative - Wikipedia
BINARY OPERATIONS (bitwise included)
-
Conversions: (decimal to binary, binary to decimal, binary to string and string to binary)
-
XOR, OR, AND, NOT, RIGHT SHIFT and LEFTSHIFT bitwise operations
Note: I know that those already exist in bit32, but, i made those since i noticed some discrepancies on the bit32 (correct me if i’m wrong)
LORENZ CIPHER (bonus function)
- Encryption and Decryption methods using Lorenz Cipher
Note: If you are going to use this function, make sure you do this:
local advanced = require(game.ServerScriptService.NUMATH)
local encrypted,keystream = advanced.math.lorenzCipher.encrypt("Lorenz Cipher is cool!")
print(encrypted,keystream) -- you can remove the prints if you want.
local decrypted = advanced.math.lorenzCipher.decrypt(encrypted,keystream)
print(decrypted)
- More information about the Lorenz Cipher:
Lorenz cipher - Wikipedia
DISCRETE FOURIER TRANSFORMATIONS
- Discrete fourier transform and Inverse Fourier Transform (Used FFT to compute, more informations here: Fast Fourier transform - Wikipedia
BEZIER INTERPOLATIONS
- Quadratic and Cubic implementations
VECTOR OPERATIONS
-
Adding
-
Subtracting
-
Multiplication
-
Dot operation
-
Cross operation (Only for 3 dimensional vectors)
-
Normalization
-
Angle Between Vectors
MATHEMATICAL SERIES
-
Taylor series (Supports when a == 0.)
-
Legendre series
-
Fourier Series
STATISTICS
-
Median
-
Mean
-
Variance
-
Percentile
-
Standard Deviation
-
Covariance
POLYNOMIALS
-
Legendre polynomials
-
Hermite polynomials
Those were all of the functions that my NuMath module has to offer.
To implement, get the NuMath module:
And, paste this line on your script:
local advanced = require(game.ServerScriptService.NUMATH)
--Observation: you can place the module on ReplicatedStorage too.
There are constants too, which includes a better approach of pi, an implementation of Euler’s constant and much more mathematical constants.
The complex part is not mentionated their functions here, because, it’s basically the lua library math for complex numbers, but there is the create function (creates an complex number) ,distance between them (2 functions that are not in the lua math library, but the create function is the core of the entire complex part of NuMath itself) and complex exponentiation.
Also, i’m so sorry if the documentation is not clear, it’s because that this is my first post on devforum.
As i said on the beginning, you can give me feedbacks, suggestions of new functions, since this is a tool for all developers in roblox!
I really hope that everyone enjoys this module!