Mathy stuff

๐ŸŽ™๏ธ ReplaceableName ยท 5 points ยท Posted at 18:06:12 on May 16, 2016 ยท (Permalink)*


Let's say you start with two entities (ArmorStands in this case) and you run this command:

execute @e[type=ArmorStand] ~ ~ ~ execute @e[type=ArmorStand] ~ ~ ~ execute @e[type=ArmorStand] ~ ~ ~ summon ArmorStand

With how many ArmorStands you'll be left with?

you'll might think it would be 8 extra ArmorStands (so 10 total), but that's not actually the case because the executes also apply to the ArmorStands created within the proccess.
the actual answer to this case is 2048...

So I wanted to find a function that will take the amount of starting entities and the amount of executes chained, and output the amount of entities at the end of the proccess.
But.. it turns out it's quite a nasty function so I made a post about it in r/math.

https://redd.it/4jmdbb[1]

In this post n means starting armorstands and x means amount of executes chained, when x=0 it just means a summon command with no executes.

This is not that useful because this function blows up quickly but I think that by placing Count agruments in the right places you could get any amount of ArmorStands when starting with only two, so if anyone can come up with some kind of algorithem on how to do it, it would be very cool.

Btw I just changed my reddit user, it was u/TheSteveKiller before.


Skylinerw ยท 3 points ยท Posted at 19:20:04 on May 17, 2016 ยท (Permalink)

Just to toss in a quick explanation on how commands are processed:

Commands that have a "target index" are processed equal to the number of targets obtained by a selector. /execute is one of these commands.

The command block is initially processing two /execute commands; the nested commands are just string data at that point. Each target obtained must completely finish its execution before the next iteration. Because of this, new armor stands exist before the next set of execute commands are run. That continues with each nested execute, since each armor stand running commands must be processed one at a time (and thus new armor stands are created before the next execute command is processed).

You can use the "AffectedEntities" trigger to get the number of commands processed (the name of the trigger is somewhat misleading), though without modding you cannot use it to get the total for this particular setup (since you'd need to add the trigger to the summoned armor stands, but you can't instantiate their score at the same time).

Plagiatus ยท 2 points ยท Posted at 09:35:57 on May 17, 2016 ยท (Permalink)

so.. according to your formula the case above would be f(2,3) = 2048 Armorstands (already a very heavy load, how long would the execution of this take?)
If i now have one more armorstand to begin with (3), so the formula changes to f(3,3), which will most definitely break everything.

Mind = blown.

do you have any idea on why we actually end up with 2048 instead of 8 on the processing site?

Nice work on figuring out that ackermann-esque formula btw!

๐ŸŽ™๏ธ ReplaceableName ยท 2 points ยท Posted at 11:29:13 on May 17, 2016 ยท (Permalink)*

I have a theory let's see if i can explain it.

when an execute is executed it will only execute on the entities that exist in that moment and the from the example I'll show you can see the order of operations.

let's look at a more simple case like f(2,2) which is 8.

you start with two armorstands and run this command:

execute @e[type=ArmorStand] ~ ~ ~ execute @e[type=ArmorStand] ~ ~ ~ summon ArmorStand

I number all ArmorStands, so the first two are 1 and 2 and the rest will be created in the proccess.

first game goes to AS1 and AS1 will go to AS1 and AS2 and summon AS from each one, I'll call it like this:

1,1 + 1,2 = 1,All = 2AS

so 1,1 means it goes to AS1 and then to AS1 again, 1,2 means it goes to AS1 and then to AS2.

After this it will go to AS2 and at that point there will be 4 AS so from AS 2 it will go to all AS from 1 to 4

2,1 + 2,2 + 2,3 + 2,4 = 2,All = 4AS

1,All + 2,All + n = All,All + n = 8AS

n = Starting AS

That's the kind of logic I was going with and from this you can also prove the weird property I showed in r/math.

Plagiatus ยท 2 points ยท Posted at 12:21:03 on May 17, 2016 ยท (Permalink)

yep, that was also what i expected to happen (after your discovery, since the commands are processed after each other, and not at the same time as one would expect).

Very interesting behaviour.

Brb, crashing some servers.

GamerGuppy ยท 2 points ยท Posted at 11:36:49 on May 17, 2016 ยท (Permalink)*

I could be wrong since I'm currently at school and have no time to look at it long, but it seems like a typical nested tree structure to me.

You are looking for: f(A,B)

  • with A = number of entities you started with,
  • and B number of Execute commands.

If the tree was not nested, however, it would simplify to: f(A)

  • with A = number of entities you started with

Then C = A * 2 ^ (A), with C being the new number of entities. Repeat this process (B-1) times by setting A equal to C at each iteration. Tell me if this works for you.

๐ŸŽ™๏ธ ReplaceableName ยท 2 points ยท Posted at 11:51:35 on May 17, 2016 ยท (Permalink)

Well I know that C = A * 2 ^ A is when B = 2 and not when B=1 or B=0 so I'm not sure what you ment.

but if you set 1 in there and run it a couple of times this is what happens:

1*2^1=2 2*2^2=8 8*2^8=2048

so I don't think this works because f(1,B) should be equal to 2 at any B.

GamerGuppy ยท 2 points ยท Posted at 12:08:31 on May 17, 2016 ยท (Permalink)

I still believe it works, it's just that f(1,B) forms an exception. My method is based on iteration, but the way MC interprets a nested execute command for just 1 entity, does not allow for iteration, since after summoning the entity it assumes it is done, and rightfully so, since there was only 1 entity at the time each execute command got parsed. Try the formula in an excel spreadsheet with horizontally the number of entities and vertically the number of execute commands. It seems to only fail for f(1,B) with B > 2.

๐ŸŽ™๏ธ ReplaceableName ยท 1 points ยท Posted at 12:49:21 on May 17, 2016 ยท (Permalink)

f(A,2) will have the same result in my formula and in your formula for any A, and also f(2,3) is the same, but according to yours f(3,3) =402653184 , and according to mine f(3,3)=402653184*2402653184

And it's different for almost all other values as well, and I trust my formula, tell me what you think.

And if I have a chance I want to thank you for your explanation on how do trigonometry in minecraft. I use it all the time now.

Currently I'm trying to create water bending in minecraft using this.

GamerGuppy ยท 2 points ยท Posted at 13:21:33 on May 17, 2016 ยท (Permalink)

Glad to hear the raycasting tutorial was useful to you.

I have to little information to compare our results, since I do not know your exact formula (do you simulate it using an external program?), neither do I know your exact definition of A and B.

f(3,3)=402653184*2402653184 is exactly what my formula gives too. Any chance you forgot one iteration?

๐ŸŽ™๏ธ ReplaceableName ยท 1 points ยท Posted at 13:38:55 on May 17, 2016 ยท (Permalink)

My formula is in the link to the r/math thread in my post, maybe it's not an exact formula but you can work it out using the properties in there.

And my definition for A is the amount of starting AS and B is amount of executes before the summon command (B=0 means only summon), in my post A=n and B=x.

"Repeat this process (B-1) times by setting A equal to C at each iteration"

3*2^3=24  24*2^24=402653184

Isn't that it?

Unless you ment by repeat B-1 time to do it B times total but then f(2,2) will be equal 2048:

2*2^2=8 8*2^8=2048
GamerGuppy ยท 2 points ยท Posted at 19:38:42 on May 17, 2016 ยท (Permalink)

Ah I see what you mean now! Stupid of me. In the future, it might be handy to give a few examples of what I suggested does, directly compared to what it should do. That makes it more easy for me to help, since I did not have time/materials to mimick your formula while in a classroom.

If you are still interested: What I previously forgot to do, is keeping track of how the tree expands based based on the number of entities you start with.

So. Consider A entities and B=1, then the first iteration gives C new entities:

(1)    C = A * 2 ^ A    e.g. f(3,2) = 3 * 2 ^ 3 =24

From this answer we can compute the other values for higher values of B by repeating the same formula over and over again. Now the mistake I made previously, was to assume you only have to iterate once to get to the next value corresponding to B. This is however, dependent on the width and depth of the tree, which is directly dependent on the number of entities you started with. So the number of times you need to iterate, to obtain the next value we call N. We started originally with N = 0. The number of times we need to iterate to obtain the next useful value corresponding to B=2 is:

(2)    N = N*A + (A-1)   e.g. N1 = N0*3 + (3-1) = (3-1) = 2

Okay, so now we know we need to use formula (1) twice to get the value corresponding to B=2. After we obtained that value, we can again use (2) to compute the new value of N. It's a pain, but this seems for me the only way to get close to a formula.