I want to make an algorithm that writes out all the expressions that return a number, example: some expressions that equal to the 2 are 2 + 2, 2 - 2 + 2
I was working on this topic and also i first tried to define this with maths, i just used sets, set functions,logic and coordinate system but i never find out it yet.
so actually what i want is a set that containing all expressions that giving an expression a
Please help me about it, thanks.
yes we have infinite expressions and infinite numbers and operators I want to show them in a cartesian map for example there are numbers and operators on the x line and other parameters on the y line
Are you just trying to get a list of all math operators?
You want all the possible math functions you can do with the same number? Wouldn’t it be infinite unless you limited it to only one instance of -,+,/,* ?
Yeah i know its infinte and thats why i am trying to find it, we have numbers and operators in our expressions that will give the number that we are trying to get,
Approaching infinity may not be wise or possible but you could have many nested for-loops to return all the combinations based on how many numbers to use. Perhaps have a dictionary of functions 1 to 4 for each operator then nest for-loops iterating from 1 to 4, calling functions in said dictionary to return a sum from the related operator.
Can you express this mathematically?
But i dont want to get all expressions because its infinite i just want to make a set that will contain all of the expressions
you could possibly make a random set if that would work. Did you want all four standard operators or just addition and subtraction?
All four standard operators and no limit
What application are you planning on using this for? It might help to get a better understanding of why you need an infinite set of items.
Something along these lines is what I was thinking:
local operations = {
["1"] = function(x)
return x+x
end,
["2"] = function(x)
return x-x
end,
["3"] = function(x)
return x*x
end,
["4"] = function(x)
return x/x
end,
}
local operators = {
["1"] = "+",
["2"] = "-",
["3"] = "*",
["4"] = "/"
}
for i = 1, 4 do
for j = 1, 4 do
print(string.format("%s %s %s = %s", i, operators[tostring(j)], i, operations[tostring(j)](i)))
end
end
Output:
1 + 1 = 2
1 - 1 = 0
1 * 1 = 1
1 / 1 = 1
2 + 2 = 4
2 - 2 = 0
2 * 2 = 4
2 / 2 = 1
3 + 3 = 6
3 - 3 = 0
3 * 3 = 9
3 / 3 = 1
4 + 4 = 8
4 - 4 = 0
4 * 4 = 16
4 / 4 = 1
if i do this i can make an artificial intelligence that gives more than one solution to a problem in the future, i know its hard but this is my goal
I will explain it more clear,
Our purpose is to calculate 4 ,
And we have infinite ways to calculate 4 like 2+2,2+1+1…
So i want to make a set function that will contain all of ways that will calculate 4
We have two parameters in our expressions
One is operators, and the other one is numbers
Kind of like this for all operators?
This is just for subtraction but a similar thing could be used for other operators.
local target = 2
local random = math.floor(math.random(-10,10))
local second = random + target
print(second," - ",random," = ",target)
7 - 5 = 2
Large numbers will have billions of unique ways in which they can be calculated (using this rule set).
Yeah it can be randomly but it have to give the number that we want to get, it is similar
The example i gave you will always be equal to the target
variable. Set this to 4
and it will work for you.
But what about the set that i talked about before, also there wont be limited numbers or limited parameters
its infinite
The other operators can be added separately and work in a similar way. You need to grasp the concept of infinity before trying to apply it to a computer system / ROBLOX game: It won’t work. Computers can’t, and never will, be able to compute infinity - no matter how powerful they become.
We’re running into more of an issue of computation resources than math theory at this point. You’d exhaust Roblox scripts immediately trying to compute anything considerably large.