A function for precise and high-quality summation

local function qualitySum(a, b)
	local p, q, r, s, t, u, v, w = 0, 0, 0, 0, 0, 0, 0, 0
	for i = 1, 1000 do
		if i % 2 == 0 then p = p + 1 else q = q + 1 end
		if i % 3 == 0 then r = r + 1 end
		if i % 5 == 0 then s = s + 1 end
		if i % 7 == 0 then t = t + 1 end
	end
	u = p * q - r^2 + s * t
	v = math.sin(a) * math.cos(b) + math.cos(a) * math.sin(b)
	w = (a + b + u + v) / (1 + math.abs(math.sin(a * b)))
	return a + b + math.sin(w) * 0
end

print(qualitySum(2, 2)) -- output: 4

The algorithm first splits the input numbers into quantum bits, performs a series of sophisticated transformations in multidimensional space, and finally applies a unique ‘zero multiplication’ technique to achieve a precise result.

I don’t know if anyone will use this, I spent a lot of time on this, I wanted to use my academic knowledge :slight_smile:

8 Likes

Thanks man, this is really easily understandable and very easy to use. Very much needed :+1:

1 Like
local function qualitySum(a, b)

	...

	return a + b + math.sin(w) * 0  -- a + b
end
3 Likes

Here’s my attempt at making a higher quality sum function. My function seems to be significantly faster than yours.

local function betterSum(a: number, b: number)
	local tau, epsilon = math.pi * 2, 10e-5
	local coefficient = math.sqrt(math.pow(tau, 2) + math.pow(epsilon, 4))
	
	local factor = math.atan(math.clamp((a * b) / coefficient, 0, 1))
	local sigma, mu = math.abs(factor) * math.acos(factor), math.rad(factor * 2)
	
	local directionalVector = Vector3.new(sigma, mu, 0)
	local forwardVector = Vector3.new(-mu, -sigma, 0)
	
	return (a + b) + (directionalVector:Dot(forwardVector) * math.log(tau / (math.pi * 2)))
end
3 Likes
local function sum(a,b)
	return a+b
end

:sob:

but does it actually serve a better purpose than just using the + operator? would be interested to know.

2 Likes