Useful Mathmodule [V4!]

MathModule [V4]

Version 2^2


How to set up the module

  • Download the module by any method
  • Place it somewhere
  • Require it as math
local math = require(game.ReplicatedStorage.MathModule)
  • your done! :slight_smile:

~ List of constants in MathModuleV4

V1 constants

Tau
  • name: tau

  • functionality: returns 2π

  • output:

Math.tau --> 6.283185307179586
Null
  • name: null

  • functionality: returns -math.huge

  • output:

Math.null --> -inf
Eulers number
  • name: e

  • functionality: returns e (Eulers number)

  • output:

Math.euler --> 2.718281828459045
Golden Ratio
  • name: phi

  • functionality: returns φ, where φ^2=φ+1

  • output:

Math.phi --> 1.618033988749895
Nan
  • name: nan

  • functionality: returns Not A Number (basically an error number)

  • output:

Math.nan --> nan

V3 constants

Pixel Ratio
  • name: px

  • functionality: returns X where 1 pixel = X mm

  • output:

Math.px --> 0.264583333333333
Small g
  • name: g

  • functionality: returns the Earth’s Gravitational Acceleration

  • output:

Math.g --> 9.807
Pythagoras Constant
  • name: rt2

  • functionality: returns the square root of 2

  • output:

Math.rt2 --> 1.4142135623730951
Supergolden ratio
  • name: psi

  • functionality: returns 𝜓 where 𝜓^3=x^2+1

  • output:

Math.psi --> 1.4655712318767682
Plastic Number
  • name: p

  • functionality: returns ρ, where ρ^3 = ρ+1

  • output:

Math.p --> 1.324717957244746
Epsilon
  • name: eps

  • functionality: Returns a really small number used for approximating things

  • output:

Math.eps --> 8.854187817e-12

V4 constants

Gelfond's Constant
  • name: gel

  • functionality: returns e^pi

  • output:

Math.gel --> 23.140692632779263
Golden Angle
  • name: gAngle

  • functionality: returns θg

  • output:

Math.gAngle --> 2.399963229728653
Natural Logarithm of 2
  • name: ln2

  • functionality: returns ln(2)

  • output:

Math.ln2 --> 0.6931471805599453 
Gauss Constant
  • name: G

  • functionality: returns 1/agm(1,rt2)

  • output:

Math.G --> 0.8346268416740731
Lemniscate Constant
  • name: varpi

  • functionality: returns ϖ, expressed as πG where G is the Gauss Constant

  • output:

Math.varpi --> 2.622057554292119
Universal Parabolic Constant
  • name: P

  • functionality: returns ln(1+rt2)+rt2 where rt2 is sqrt(2)

  • output:

Math.P --> 2.295587149392638
Hexagonal lattice Constant
  • name: mu

  • functionality: returns μ, expressed as sqrt(2+sqrt(2))

  • output:

Math.mu --> 1.8477590650225735
b10 Champernowne Constant
  • name: C10

  • functionality: returns C10, which is just 0.12345…

  • output:

Math.C10 --> 0.12345678910111213
Magic Angle
  • name: mAngle

  • functionality: returns θm, simply arctan(rt2)

  • output:

Math.mAngle --> 0.9553166181245093 
Lévy's Constant
  • name: beta

  • functionality: returns β

  • output:

Math.beta  --> 1.1865691104156255 
Lévy's 2nd Constant
  • name: ebeta

  • functionality: returns e^β

  • output:

Math.ebeta  --> 3.2758229187218113

~ List of basic functions in MathModuleV4

V1 functions

Circumference
  • name: circum

  • Arguments: r (number)
    ~ r → Radius used to calculate the Circumference

  • functionality: returns r * tau

  • Example:

Math.circum(3) --> 18.84955592153876
Cube root
  • name: cbrt

  • Arguments: x (number)
    ~ x → Number that’s cube root will be calculated

  • functionality: returns ∛x

  • Example:

Math.cbrt(64) --> 4
Any Root
  • name: root

  • Arguments: x (number), root (number)
    ~ x → Number that’s root will be calculated
    ~ root → The Root Number

  • functionality: returns ʳᵒᵒᵗ√x

  • Example:

Math.root(16,4) --> 2
Factorial
  • name: fac

  • Arguments: x (number)
    ~ x → Number thats factorial is gonna be calculated

  • functionality: returns x!

  • Example:

Math.fac(5) --> 120
Average
  • name: avg

  • Arguments: ... (numbers)
    ~ → Numbers that are gonna be used to calculate the average

  • functionality: returns the average of …

  • Example:

Math.avg(1,2,3,4,5) --> 3
Summation
  • name: sum

  • Arguments: min (number), max (number), formula (function)
    ~ min → Lower bound of Sum
    ~ max → Higher bound of Sum
    ~ formula → function used on the numbers (optional)

  • functionality: returns the sum of the numbers from x to y with the use of formula

  • Example:

Math.sum(1,5,function(x: number) return x^2 end) --> 55

image

Tetration
  • name: tetr

  • Arguments: x (number), y (number)
    ~ x → Tetration Base
    ~ y → Tetration Power

  • functionality: returns x^^y which is x^x^x… } y times

  • Example:

Math.tetr(3,2) --> 27
Pentation
  • name: pent

  • Arguments: x (number), y (number)
    ~ x → Pentation Base
    ~ y → Pentation Power

  • functionality: returns x^^^y which is x^^x^^x… } y times

  • Example:

Math.pent(3,2) --> 7625597484987

V3 functions

Product
  • name: product

  • Arguments: min (number), max (number), formula (function)
    ~ min → Starting number of a line of numbers
    ~ max → Ending number of a line of numbers
    ~ formula → Formula used on every number (optional)

  • functionality: returns numbers from min to max multiplied with eachother with the use of formula

  • Example:

Math.product(1,4,function(x: number) return x+1 end) --> 120

image

Reciprocal
  • name: rec

  • Arguments: x (number)
    ~ x → Number used for the function

  • functionality: returns 1/x

  • Example:

Math.rec(5) --> 0.2
Zero function (inverse log10)
  • name: zer

  • Arguments: x (number)
    ~ x → Number of zeros wanted

  • functionality: returns 10^x

  • Example:

Math.zer(5) --> 100000
Gamma function
  • name: gamma

  • Arguments: x (number)
    ~ x → Number used in the function

  • functionality: returns (x-1)!

  • Example:

Math.gamma(5) --> 24
Digits
  • name: dgt

  • Arguments: x (number)
    ~ x → Number to get the digits from

  • functionality: returns the digits of X

  • Example:

Math.dgt(12345) --> {1,2,3,4,5}
Chance
  • name: chance

  • Arguments: x (number)
    ~ x → Number to calculate the chance with

  • functionality: returns 1 if random(1,x) equal 1, if not then returns 0

  • Example:

Math.chance(100) --> assumed 0
Range
  • name: range

  • Arguments: ... (numbers)
    ~ → Numbers used to get the range

  • functionality: returns max(…)-min(…)

  • Example:

Math.range(1,3,5,10) --> 9
Abbreviate
  • name: note

  • Arguments: x (number)
    ~ x → Number thats gonna be abbreviated

  • functionality: returns abbreviation of x

  • Example:

Math.note(25069) --> 25k

NOTE: this function has NO LIMITS, and can go up until inf.

Check if Prime
  • name: prime

  • Arguments: x (number)
    ~ x → Number to check the divisors of

  • functionality: returns false if x isnt prime, else: returns true

  • Example:

Math.prime(11) --> true
Raised Chance Random
  • name: yrandom

  • Arguments: x (number)
    ~ x → Number as upper bound

  • functionality: returns a random with the average of 75%x

  • Example:

Math.yrandom(100) --> ~75
Lowered Chance Random
  • name: xrandom

  • Arguments: x (number)
    ~ x → Number as lower bound

  • functionality: returns a random with the average of 25%x

  • Example:

Math.xrandom(100) --> ~25
Riemann Zeta function ( ζ )
  • name: zeta

  • Arguments: x (number)
    ~ x → the number used in the sum

  • functionality: returns ζ(x), the sum from 0 to ∞ with the function 1/(n^x) (~5 decimals accurate)

  • Example:

Math.zeta(3) --> 1.2020569026040608

V4 functions

Fractional Part
  • name: frac

  • Arguments: x (number)
    ~ x → the number thats fractional part will be returned

  • functionality: returns {x}, expressed as x-⌊x⌋

  • Example:

Math.frac(2.5) --> 0.5
b10 to Binary
  • name: binary

  • Arguments: x (number)
    ~ x → the number assumed to be in base-10

  • functionality: returns x in base-2 (binary)

  • Example:

Math.binary(9) --> 1001
Binary to b10
  • name: frombinary

  • Arguments: x (number)
    ~ x → the number assumed to be in base-2

  • functionality: returns x in base-10

  • Example:

Math.frombinary(100) --> 4
Percent
  • name: pct

  • Arguments: x (number), p (number)
    ~ x → the base (100%)
    ~ p → the percent of base (p%)

  • functionality: returns p%x, expressed as (xp)/100

  • Example:

Math.pct(10,75) --> 7.5
Check if coprime
  • name: coprime

  • Arguments: x (number), y (number)
    ~ x → the number to check if its coprime with y
    ~ y → the number to check if its coprime with x

  • functionality: returns true if x;y are coprimes, otherwise returns false

  • Example:

Math.coprime(8,9) --> true
Slope of a function
  • name: slope

  • Arguments: x (number), y (number), formula (function)
    ~ x → starting point of the slope
    ~ y → ending point of the slope
    ~ formula → the function to calculate the slope of

  • functionality: returns Δy/Δx, the slope of formula from point x to y

  • Example:

Math.slope(2,3,function(x: number) return 2*x end) --> 2
Superfactorial
  • name: superfac

  • Arguments: x (number)
    ~ x → the number thats superfactorial is gonna be taken

  • functionality: returns sf(x) or x!ˢ

  • Example:

Math.superfac(3) --> 12
Hyperfactorial
  • name: hyperfac

  • Arguments: x (number)
    ~ x → the number thats hyperfactorial is gonna be taken

  • functionality: returns hf(x) or x!ᴴ

  • Example:

Math.hyperfac(3) --> 108
Approximately equal
  • name: approx

  • Arguments: x (number), y (number), range (number)
    ~ x → arg1
    ~ y → arg2
    ~ range → the maximum difference between arg1 and arg2

  • functionality: returns true if x≈y with maximum range of range

  • Example:

Math.approx(1,2,0.5) --> false
Pi function ( Π )
  • name: primecount

  • Arguments: x (number)
    ~ x → the upper bound of the function

  • functionality: returns Π(x), the number of primes before (or thats equal to) x

  • Example:

Math.primecount(11) --> 5
Iteration
  • name: rep

  • Arguments: x (number), t (number), formula (function)
    ~ x → the starting input to formula
    ~ t → the number of iterations
    ~ formula → the function to be iterated

  • functionality: returns f(f(…f(x)…)) } t times

  • Example:

Math.rep(1,5,function(x: number) return 2*x end) --> 32
Arcfactorial
  • name: arcfac

  • Arguments: x (number)
    ~ x → the number thats arcfactorial is gonna be taken

  • functionality: returns x!⁻¹ … only works if x is a perfect factorial

  • Example:

Math.arcfac(120) --> 5
Diagonal Line Function
  • name: diag

  • Arguments: ... (numbers)
    ~ → side lengths used to calculate the diagonal line

  • functionality: returns a diagonal line with the object side lengths …

  • Example:

Math.diag(1,1) --> 1.4142135623730951
Lambert W Function
  • name: lambertW

  • Arguments: x (number)
    ~ x → the number assumed be greater than or equal to -1/e

  • functionality: returns W₀(x), where W is the inverse of f(x)= xe^x

  • Example:

Math.lambertW(1) --> 0.5671432904097838
SUPER ROOT
  • name: ssrt

  • Arguments: x (number)
    ~ x → the number thats superroot will be taken

  • functionality: returns √xₛ, where √ₛ is the super root, the inverse of tetration

  • Example:

Math.ssrt(27) --> 3

~ List of converting functions in MathModuleV4

Fahrenheit
  • name: toFah

  • Arguments: x (Celsius)

  • functionality: returns x°F

Celsius
  • name: toCel

  • Arguments: x (Fahrenheit)

  • functionality: returns x°C

Inch
  • name: toIn

  • Arguments: x (Centimeter)

  • functionality: returns x inches

Centimeter
  • name: toCm

  • Arguments: x (Inch)

  • functionality: returns x centimeters

Pounds
  • name: toLb

  • Arguments: x (Kilograms)

  • functionality: returns x pounds

Kilograms
  • name: toKg

  • Arguments: x (Pounds)

  • functionality: returns x Kilograms


~ List of trigonometric functions in MathModuleV4

Cotangent
  • name: cot

  • Arguments: x (Radians)

  • functionality: returns cotan(x)

  • Example:

Math.cot(1.5) --> 0.07091484430265245
Secant
  • name: sec

  • Arguments: x (Radians)

  • functionality: returns sec(x)

  • Example:

Math.sec(1.5) --> 14.136832902969903
Cosecant
  • name: csc

  • Arguments: x (Radians)

  • functionality: returns cosec(x)

  • Example:

Math.csc(1.5) --> 1.0025113042467249
Arc-Cotangent
  • name: acot

  • Arguments: x (Radians)

  • functionality: returns arccotan(x)

  • Example:

Math.acot(1.5) --> 0.5880026035475675
Arc-Secant
  • name: asec

  • Arguments: x (Radians)

  • functionality: returns arcsec(x)

  • Example:

Math.asec(1.5) --> 0.8410686705679303
Arc-Cosecant
  • name: acsc

  • Arguments: x (Radians)

  • functionality: returns arccosec(x)

  • Example:

Math.acsc(1.5) --> 0.7297276562269663
Hyperbolic-Cotangent
  • name: coth

  • Arguments: x (Radians)

  • functionality: returns cotanh(x)

  • Example:

Math.coth(1.5) --> 1.104791392982512
Hyperbolic-Secant
  • name: sech

  • Arguments: x (Radians)

  • functionality: returns sech(x)

  • Example:

Math.sech(1.5) --> 0.4250960349422805
Hyperbolic-Cosecant
  • name: csch

  • Arguments: x (Radians)

  • functionality: returns cosech(x)

  • Example:

Math.csch(1.5) --> 0.46964244059522464
Arc-Hyperbolic-Sine
  • name: asinh

  • Arguments: x (Radians)

  • functionality: returns arcsinh(x)

  • Example:

Math.asinh(1.5) --> 1.1947632172871094
Arc-Hyperbolic-Cosine
  • name: acosh

  • Arguments: x (Radians)

  • functionality: returns arccosh(x)

  • Example:

Math.acosh(1.5) --> 0.9624236501192069
Arc-Hyperbolic-Tangent
  • name: atanh

  • Arguments: x (Radians)

  • functionality: returns arctanh(x)

  • Example:

Math.atanh(0.2) --> 0.2027325540540821
Arc-Hyperbolic-Cotangent
  • name: acoth

  • Arguments: x (Radians)

  • functionality: returns arccotanh(x)

  • Example:

Math.acoth(1.5) --> 0.8047189562170501
Arc-Hyperbolic-Secant
  • name: asech

  • Arguments: x (Radians)

  • functionality: returns arcsech(x)

  • Example:

Math.asech(0.5) --> 1.3169578969248166
Arc-Hyperbolic-Cosecant
  • name: acsch

  • Arguments: x (Radians)

  • functionality: returns arccosech(x)

  • Example:

Math.csch(1.5) --> 0.46964244059522464

~ List of Sequences in MathModuleV4

Harmonic Sequence
  • name: harmonic

  • Arguments: x (Number)
    ~ x → the index of the term in the sequence

  • functionality: returns H(x)

  • Example:

Math.harmonic(5) --> 2.283333333333333
Fibonacci Sequence
  • name: fibonacci

  • Arguments: x (Number)
    ~ x → the index of the term in the sequence

  • functionality: returns F(x)

  • Example:

Math.fibonacci(6) --> 8
Triangular Numbers
  • name: triangular

  • Arguments: x (Number)
    ~ x → the index of the term in the sequence

  • functionality: returns T(x)

  • Example:

Math.triangular(5) --> 15
Tetrahedral Numbers
  • name: tetrahedral

  • Arguments: x (Number)
    ~ x → the index of the term in the sequence

  • functionality: returns Te(x)

  • Example:

Math.tetrahedral(5) --> 35
Pentatope Numbers
  • name: pentatope

  • Arguments: x (Number)
    ~ x → the index of the term in the sequence

  • functionality: returns P(x)

  • Example:

Math.pentatope(5) --> 70
Leonardo Sequence
  • name: leonardo

  • Arguments: x (Number)
    ~ x → the index of the term in the sequence

  • functionality: returns L(x)

  • Example:

Math.leonardo(7) --> 41
Pell Sequence
  • name: pell

  • Arguments: x (Number)
    ~ x → the index of the term in the sequence

  • functionality: returns P(x)

  • Example:

Math.pell(5) --> 29
Sylvester Sequence
  • name: sylvester

  • Arguments: x (Number)
    ~ x → the index of the term in the sequence

  • functionality: returns S(x)

  • Example:

Math.sylvester(5) --> 24493

~ List of calculus functions in MathModuleV4

Integral
  • name: integral

  • Arguments: min (number), max (number), formula (function)
    ~ min → lower bound of the integral
    ~ max → upper bound of the integral
    ~ formula → function used in the integral

  • functionality: returns the area under the curve formula from point min to max

  • Accuracy: 5 decimals

  • Example:

Math.integral(0,10,function(x) return 2*x end) --> ~100

Derivative
  • name: derivative

  • Arguments: formula (function)
    ~ formula → the function thats derivative is gonna be returned

  • functionality: returns f’, which is a function so it can be called as derivative(f)(x)

  • Accuracy: 6 decimals

  • Example:

Math.derivative(function(x) return x^2 end)(6) --> ~12

~ Ways to download MathModuleV4

As File

Download here: MathModuleV4.lua

With Copy and Paste

Copy from here: …

local NewMath = {}

----> built-in
NewMath["random"]=math["random"]
NewMath["huge"]=math["huge"]
NewMath["abs"]=math["abs"]
NewMath["sqrt"]=math["sqrt"]
NewMath["min"]=math["min"]
NewMath["rad"]=math["rad"]
NewMath["sign"]=math["sign"]
NewMath["max"]=math["max"]
NewMath["sin"]=math["sin"]
NewMath["fmod"]=math["fmod"]
NewMath["round"]=math["round"]
NewMath["pi"]=math["pi"]
NewMath["cos"]=math["cos"]
NewMath["deg"]=math["deg"]
NewMath["exp"]=math["exp"]
NewMath["log"]=math["log"]
NewMath["pow"]=math["pow"]
NewMath["tan"]=math["tan"]
NewMath["acos"]=math["acos"]
NewMath["asin"]=math["asin"]
NewMath["atan"]=math["atan"]
NewMath["ceil"]=math["ceil"]
NewMath["cosh"]=math["cosh"]
NewMath["modf"]=math["modf"]
NewMath["sinh"]=math["sinh"]
NewMath["tanh"]=math["tanh"]
NewMath["atan2"]=math["atan2"]
NewMath["clamp"]=math["clamp"]
NewMath["floor"]=math["floor"]
NewMath["frexp"]=math["frexp"]
NewMath["ldexp"]=math["ldexp"]
NewMath["log10"]=math["log10"]
NewMath["noise"]=math["noise"]
NewMath["randomseed"]=math["randomseed"]
----> constants
NewMath["tau"]=NewMath.pi*2
NewMath["null"]=-NewMath.huge
NewMath["e"]=NewMath.exp(1)
NewMath["phi"]=((1+(5^0.5))/2)
NewMath["nan"]=0/0
--> V3 constants
NewMath["px"]=0.264583333333333
NewMath["rt2"]=2^0.5
NewMath["g"]=9.807
NewMath["psi"]=(1/3*(1+(((29+3*((93)^0.5))/2)^(1/3))+(((29-3*((93)^0.5))/2)^(1/3))))
NewMath["p"]=(((9+(69^0.5))/18)^(1/3)+((9-(69^0.5))/18)^(1/3))
NewMath["eps"]=((8.854187817)*(10^-12))
--> V4 constants
NewMath["gel"]=NewMath.e^NewMath.pi
NewMath["gAngle"]=NewMath.tau/(NewMath.phi^2)
NewMath["ln2"]=NewMath.log(2)
NewMath["G"]=3.62560990822190822191^2/(2*((2*(NewMath.pi^3))^0.5))
NewMath["varpi"]=NewMath.pi*NewMath.G
NewMath["P"]=NewMath.log(1+NewMath.rt2)+NewMath.rt2
NewMath["mu"]=(2+2^0.5)^0.5
NewMath["C10"]=0.12345678910111213
NewMath["mAngle"]=NewMath.atan(NewMath.rt2)
NewMath["beta"]=(NewMath.pi^2)/(12*NewMath.ln2)
NewMath["ebeta"]=NewMath.e^NewMath.beta
----> functions
NewMath["circum"]=function(r: number)
	return NewMath.tau*r
end
NewMath["cbrt"]=function(x: number)
	return x^(1/3)
end
NewMath["root"]=function(x: number,root: number)
	return x^(1/root)
end
NewMath["fac"]=function(x: number)
	if x == 0 then
		return 1
	end
	local y = x
	for i = 1,x-1 do
		y=y*i
	end
	return y
end
NewMath["avg"]=function(...: number)
	local n = 0
	for _,i in {...} do
		n += i
	end
	n /= #{...}
	return n
end
NewMath["sum"]=function(min: number,max: number,formula: (number)->number?)
	local n = 0
	for i = min,max do
		if formula then
			n += formula(i)
		else
			n += i
		end
	end
	return n
end
NewMath["tetr"]=function(x: number,y: number)
	local n = x
	if not y then
		y = 2
	end
	if y == 0 then
		return 1
	elseif y == -1 then
		return 0
	end
	for i = 1,y-1 do
		n = x^n
	end
	return n
end
NewMath["pent"]=function(x: number,y: number)
	local n = x
	if not y then
		y = 2
	end
	for i = 1,y-1 do
		n = NewMath.tetr(x,n)
	end
	return n
end
--> V3 functions
NewMath["product"]=function(min: number,max: number,formula: (number)->number?)
	local n = 1
	for i = min,max do
		if formula then
			n *= formula(i)
		else
			n *= i
		end
	end
	return n
end
NewMath["rec"]=function(x: number)
	return 1/x
end
NewMath["zer"]=function(z: number)
	return 10^z
end
NewMath["gamma"]=function(x: number)
	return NewMath.fac(x-1)
end
NewMath["dgt"]=function(x: number)
	local nums = {0,1,2,3,4,5,6,7,8,9}
	local digits = {}
	for i,v in tostring(x):split("") do
		if table.find(nums,tonumber(v)) then
			table.insert(digits,tonumber(v))
		end
	end
	return digits
end
NewMath["chance"]=function(x: number)
	local rnd = NewMath.random(1,NewMath.clamp(x,1,10^32))
	if rnd == 1 then
		return rnd
	else
		return rnd*0
	end
end
NewMath["range"]=function(...: number)
	return NewMath.max(...)-NewMath.min(...)
end
NewMath["note"]=function(x: number)
	local rlen = NewMath.floor(NewMath.log10(NewMath.floor(x)))
	local rlen2 = rlen
	rlen2 -= rlen2%3
	return ("%.f"):format(tostring(NewMath.floor(x))):sub(1,(rlen%3)+1)..require(14327149989)[rlen2]
end
NewMath["prime"]=function(x: number)
	for i = 1,x do
		if i ~= 1 and i ~= x then
			if x%i==0 then
				return false
			end
		end
	end
	return true
end
NewMath["yrandom"]=function(x: number)
	return NewMath.random(NewMath.random(0,x),x)
end
NewMath["xrandom"]=function(x: number)
	return NewMath.random(0,NewMath.random(0,x))
end
NewMath["zeta"]=function(x: number)
	local y = 0
	for i = 1,NewMath.clamp(x*10^4,1,10^10) do
		y += (NewMath.rec(i^x))
	end
	return y
end
--> V4 Functions
NewMath["frac"]=function(x: number)
	return x-NewMath.floor(x)
end
NewMath["binary"]=function(x: number)
	local s = ''
	local y = x
	while NewMath.floor(y) > 0 do
		local data = y/2
		y = NewMath.floor(data)
		s ..= NewMath.sign(NewMath.frac(data))
	end
	if NewMath.floor(y) == 0 then
		s = s:reverse()
	end
	return tonumber(s)
end
NewMath["frombinary"]=function(x: number)
	local s = tostring(NewMath.floor(x)):reverse():split('')
	local n = 0
	for x,v in s do
		local i = tonumber(v)
		if i==1 then
			n += 2^(x-1)
		end
	end
	return n
end
NewMath["pct"]=function(x: number, p: number)
	return x*(p/100)
end
NewMath["coprime"]=function(x: number,y: number)
	for i = 1,NewMath.min(x,y) do
		if i ~= 1 then
			if x%i == 0 and y%i == 0 then
				return false
			end
		end
	end
	return true
end
NewMath["slope"]=function(x: number, y: number, formula: (number)->number?)
	return (formula(y)-formula(x))/(y-x)
end
NewMath["superfac"]=function(x: number)
	if x == 0 then
		return 1
	end
	local y = NewMath.fac(x)
	for i = 1,x-1 do
		y=y*(NewMath.fac(i))
	end
	return y
end
NewMath["hyperfac"]=function(x: number)
	if x == 0 then
		return 1
	end
	local y = x^x
	for i = 1,x-1 do
		y=y*(i^i)
	end
	return y
end
NewMath["approx"]=function(x: number,y: number,range: number)
	return NewMath.abs(x-y)<=range
end
NewMath["primecount"]=function(x: number)
	local p = 0
	for i = 1,x do
		if i ~= 1 then
			if NewMath.prime(i)==true then
				p=p+1
			end
		end
	end
	return p
end
NewMath["rep"]=function(x: number,t: number,formula: (number)->number?)
	for i = 1,t do
		x = formula(x)
	end
	return x
end
NewMath["arcfac"]=function(x: number)
	local y = 0
	for i = 1,x do
		x=x/i
		y+=1
		if x == 1 then
			return y
		end
	end
	return NewMath.nan
end
NewMath["diag"]=function(...: number)
	local q = 0
	for _,n in {...} do q+=n^2 end
	return q^.5
end
NewMath["lambertW"]=function(x: number)
	local epsilon = NewMath.eps
	local result = x
	local var = x
	local limit = NewMath.zer(3)
	local r = 0
	while r < limit do
		local exp = NewMath.e^result
		local xexp = result * exp
		local f = xexp - x
		local fPrime = exp * (result + 1)
		var = result
		result = result - f / fPrime
		if NewMath.abs(result-var) < epsilon then
			return result
		end
		r += 1
	end
	return result
end
NewMath["ssrt"]=function(x: number)
	return NewMath.exp(NewMath.lambertW(NewMath.log(x,NewMath.e)))
end
--> Converting [V4]
NewMath["toFah"]=function(x: number)
	return (x-32)*(5/9)
end
NewMath["toCel"]=function(x: number)
	return x*(5/9)+32
end
NewMath["toIn"]=function(x: number)
	return x*0.3937007874
end
NewMath["toCm"]=function(x: number)
	return x/0.3937007874
end
NewMath["toLb"]=function(x: number)
	return x*2.20462262
end
NewMath["toKg"]=function(x: number)
	return x/2.20462262
end
--> Trigonometry [V4]
NewMath["cot"]=function(x: number)
	return 1/NewMath.tan(x)
end
NewMath["sec"]=function(x: number)
	return 1/NewMath.cos(x)
end
NewMath["csc"]=function(x: number)
	return 1/NewMath.sin(x)
end
NewMath["acot"]=function(x: number)
	return (-NewMath.atan(x))+NewMath.pi/2
end
NewMath["asec"]=function(x: number)
	return NewMath.acos(1/x)
end
NewMath["acsc"]=function(x: number)
	return NewMath.asin(1/x)
end
NewMath["coth"]=function(x: number)
	return NewMath.cosh(x)/NewMath.sinh(x)
end
NewMath["sech"]=function(x: number)
	return 1/NewMath.cosh(x)
end
NewMath["csch"]=function(x: number)
	return 1/NewMath.sinh(x)
end
NewMath["asinh"]=function(x: number)
	return NewMath.log(x+NewMath.sqrt(x^2+1))
end
NewMath["acosh"]=function(x: number)
	return NewMath.log(x+NewMath.sqrt(x^2-1))
end
NewMath["atanh"]=function(x: number)
	return NewMath.log((1+x)/(1-x))/2
end
NewMath["acoth"]=function(x: number)
	return NewMath.log((x+1)/(x-1))/2
end
NewMath["asech"]=function(x: number)
	return NewMath.log(NewMath.rec(x)+NewMath.sqrt(1/(x^2)-1))
end
NewMath["acsch"]=function(x: number)
	return NewMath.log(NewMath.rec(x)+NewMath.sqrt(1/(x^2)+1))
end
----> Sequences [V4]
NewMath["harmonic"]=function(x: number)
	return NewMath.sum(1,x,NewMath.rec)
end
NewMath["fibonacci"]=function(x: number)
	local r,f,y,z = x-1,0,1,0
	for i = 0,r do
		z = f
		f = (f+y)
		y = z
	end
	return f
end
NewMath["triangular"]=function(x: number)
	return NewMath.sum(0,NewMath.floor(x))
end
NewMath["leonardo"]=function(x: number)
	if x == 0 or x == 1 then
		return 1
	else
		return NewMath.leonardo(x-1)+NewMath.leonardo(x-2)+1
	end
end
NewMath["pell"]=function(x: number)
	if NewMath.floor(x) == 0 or NewMath.floor(x) == 1 then
		return NewMath.floor(x)
	else
		return 2*NewMath.pell(NewMath.floor(x)-1)+NewMath.pell(NewMath.floor(x)-2)
	end
end
NewMath["tetrahedral"]=function(x: number)
	return NewMath.sum(1,NewMath.floor(x),NewMath.triangular)
end
NewMath["pentatope"]=function(x: number)
	return NewMath.sum(1,NewMath.floor(x),NewMath.tetrahedral)
end
NewMath["sylvester"]=function(x: number)
	if NewMath.floor(x) == 0 or NewMath.floor(x) == 1 then return 2+NewMath.floor(x) end
	return NewMath.product(1,NewMath.floor(x)-1,NewMath.sylvester)+1
end
--> Calculus [V4]
NewMath["derivative"]=function(formula: (number)->number?): <formula>(number)-> number?
	return (function(x: number) return NewMath.slope(x,x+NewMath.eps/10,formula) end)
end
NewMath["integral"]=function(min: number, max: number, formula: (number)->number?)
	local c = 1e-5
	local a = 0
	for v = min,max,c do
		a += formula(v)*c
	end
	return a
end

return NewMath

--COPY AND PASTE FORM
As a model

Download here: create.roblox.com/marketplace/asset/14071364583

image

17 Likes

cool model, you could also add a function to root numbers while preserving the sign using

return math.abs(x) ^ (1 / root) * math.sign(x)
1 Like

You can make this simpler by making NewMath inherit from the original math library. How? With metatables!

local NewMath = {}

NewMath.tau = math.pi * 2

setmetatable(NewMath, {__index = math})

print(NewMath.tau) --> 6.28...
print(NewMath.sign(2)) --> 1
6 Likes

Excited to use this!

I’m unable to click the link to the model🤔… Refreshed, can copy it as a quote, but seems like the hyperlink won’t activate?

Regardless, this looks very helpful. Great work!

2 Likes

@coolalex1835 I mean its a really simple function with not much to use it for so idk if ill add things like this

@bluebxrrybot tysm for the tip but i have one question; if i make it with metatables does “autofill” or whatever write out the functions, ex.: i write math. and will it show the built-ins or i have to write it out for myself? (I forget every function name)

@WoahItsJeebus I fixed the link, now youre able to download it! :slight_smile:

2 Likes

yeah it does!

cool resource btw

2 Likes

a math module shouldn’t be using metatables, it’ll only slow things down for no reason. just stick to specifically setting everything in the roblox math lib in your math module instead.

3 Likes

Do you want us to write a million lines of code indexing things from math???

Metatables can make this process easier, It doesn’t matter if it slows stuff down for no reason, It helps the process, Imagine I make a math module, I would use metatables to help import the math constants to the module

1 Like

It will not slow things down, it only speeds things up. Could you prove that using metatables is slower? If you can, I will stop programming for the rest of my life.

2 Likes

Are you unironically saying that indexing a table which then indexes another table is faster than indexing a table once?

Yes, but it also uses less memory, especially when working with OOP.

1 Like

There aren’t a lot of math functions/constants, and using a metatable will make it harder for Luau to do certain optimizations like constant folding and possibly even fastcalls. Directly setting them in a separate ModuleScript to get rid of the lines of code would get rid of the entire redefinition if that’s what’s troubling you.

Oh yeah no that for sure gets rid of those optimizations. It completely gets rid of what’s described here: Performance - Luau

a math module using OOP makes 0 sense, it does not reduce memory either doing it with metatables unless you really wanna argue that a few bytes are spared this way…

There is no performance impact also that link took me 1000 years to load

image

I don’t get what does “constant folding” and “fastcalls”

also we don’t need more require()s in the code

I am talking about internally, he could make the base of the math module just be a copy of the math library. It wouldn’t change anything for you.

You can search that up in that page I sent, it explains some optimizations it does.

That page like I said took 1000 years to load

image

so I can’t check


also we don’t need a million require()s internally in the code

You can keep saying “a million” this and “a million” that but this time its sadly a single require. Also who is “we”?