NuMath -- A Better Math Library!

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

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

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)

DISCRETE FOURIER TRANSFORMATIONS

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! :smiley:

7 Likes

Since I don’t see a mathematical sum function here I am posting an add-on.

Of course you can use it, it’s an academic achievement for me to appear in your project.