Expand Circuit Network's "Each"
Posted: Wed Jun 22, 2016 1:02 am
TL;DR: Allow "each" on both sides of combinator, implement red and green specific each's. Simple additions, explosion of possibilities.
1. Each on both sides
Part of this leads into the 2nd part, but for now: You cannot do `var/each=each`. It must be `each/var=each`. Obviously, if you put "each" on each side, it simply does each item individually. For example, doing `each-each=each` would clear everything because each item would say `myself-myself=myself` or "put 0 into me".
Seems useless in decider combinators, right? Read on.
2. Separate red/green "each"s.
Right now we have an "each" which adds together the red and green wires. Imagine if you could keep them separate!
For example: `re=each`. If items are on both lines, it will output the difference. If only on the red line, it will output the value on the red line. If only on the green line, the inverse of that value as the output. Very intuitive.
In addition, maybe allow decider combinators to have redEverything, greenEverything, redAnything, and greenAnything? More on that below.
But... why?
There are crazy amounts of possibilities
Modding
Doing mod is easier with multiple values if you can do `var/each=each`! This would also make digit displays more compact instead of having to use funky work arounds.
Array memory!
Grab values from memory! This is a super important one. We could make something like arrays. Give an array of data (let's say we're caching in constant combinators powers of 2, so index 1 returns 2, index 2 return 4, index 3 returns 8, etc). We start with an index constant combinator (e.g. 1 transport belt, 2 fast transport belt, 3 express transport belt, 4 randomItem, 5 randomItem, etc). We hook up our input and index cache to a decider combinator so we can get the "item key":
`each=inputIndex=>each` (only 1 of output)
Wait, but can't we already do this? Yes, but here comes the important part:
Our power-of-2 cache (however this could be anything like a memory cell or something that has a range of values on different items) would store matching items to values according to the above index cache. In our example: (2 transport belt, 4 fast transport belt, 8 express transport belt, 16 randomItem, 32 randomItem, etc). Now, if our previous output is on the red wire and this power-of-2 cache is on a green wire...
`redEach*greenEach=each`
Bam! So, if our inputIndex is 3, we would the first combinator would find an item that equals 3... express transport belt! Then, we do each red item, the equivalent green item. Everything on the red wire (output from before) is 0 except our 1 express transport belt! This means if we multiply by everything in the power-of-2 cache, we're left with 8 transport belt, which is 2^3! We actually mapped a value to a key and were able to access it!
Simpler comparisons
At the moment, we can easily do `inputOne*-1=outputOne` then `outputOne+inputTwo=outputTwo` and `outputTwo>0` to check if outputTwo>outputOne (or flip a few things to compare otherwise), however this method compacts it into: `redEach<greenEach=output`. Simpler isn't necessarily better, however since we already have `each` and are able to attach both red and green wires to combinators, it seems intuitive that you would be able to do that.
More
If people suggest other possibilities, or the devs are not convinced, I will be happy to add them!
BUT WHAT ABOUT
* `each/each=each` just gives 1 (for any item that had a value previously)
* In an arithmetic combinator, you cannot output redEach or greenEach, that doesn't make sense. You'd simply output `each`.
* In a decider combinator, there are two options for how outputs work: 1) Keep it `each only` and make it apply to the left side. Since in a decider combinator it's easy to switch the sides since it makes no different (because you can flip sides), you could flip the sides if you needed to. 2) Keep `each` (which adds red + green wires) and allow `redEach` and `greenEach` to only output the value of those wires (if the requirements are met).
* If it's implemented, `redEverything>greenEverything=>each` means "If everything in the red wire is greater than each respective item in the green wire (except values of 0 I suppose?) then output each item.
* `redAnything>greenAnything=>each` means "If anything in the red wire is larger than the same item on the green wire, output each item.
* `redEach>greenEach=>each` means "Each item can pass if they are larger on the red side than the green".
* `redEach>greenEverything` or `greenAnything=redEverything` is a no no! Only the same type of "each" (each, anything, everything).
* More stuff that I probably missed. Will add on.
Why is this so great?
It's a small change to one part of combinators but opens up many possibilities. If someone is not interested in combinators, it's unlikely it will affect them! All of these are type `virtual`.
Please give feedback!
1. Each on both sides
Part of this leads into the 2nd part, but for now: You cannot do `var/each=each`. It must be `each/var=each`. Obviously, if you put "each" on each side, it simply does each item individually. For example, doing `each-each=each` would clear everything because each item would say `myself-myself=myself` or "put 0 into me".
Seems useless in decider combinators, right? Read on.
2. Separate red/green "each"s.
Right now we have an "each" which adds together the red and green wires. Imagine if you could keep them separate!
For example: `re=each`. If items are on both lines, it will output the difference. If only on the red line, it will output the value on the red line. If only on the green line, the inverse of that value as the output. Very intuitive.
In addition, maybe allow decider combinators to have redEverything, greenEverything, redAnything, and greenAnything? More on that below.
But... why?
There are crazy amounts of possibilities
Modding
Doing mod is easier with multiple values if you can do `var/each=each`! This would also make digit displays more compact instead of having to use funky work arounds.
Array memory!
Grab values from memory! This is a super important one. We could make something like arrays. Give an array of data (let's say we're caching in constant combinators powers of 2, so index 1 returns 2, index 2 return 4, index 3 returns 8, etc). We start with an index constant combinator (e.g. 1 transport belt, 2 fast transport belt, 3 express transport belt, 4 randomItem, 5 randomItem, etc). We hook up our input and index cache to a decider combinator so we can get the "item key":
`each=inputIndex=>each` (only 1 of output)
Wait, but can't we already do this? Yes, but here comes the important part:
Our power-of-2 cache (however this could be anything like a memory cell or something that has a range of values on different items) would store matching items to values according to the above index cache. In our example: (2 transport belt, 4 fast transport belt, 8 express transport belt, 16 randomItem, 32 randomItem, etc). Now, if our previous output is on the red wire and this power-of-2 cache is on a green wire...
`redEach*greenEach=each`
Bam! So, if our inputIndex is 3, we would the first combinator would find an item that equals 3... express transport belt! Then, we do each red item, the equivalent green item. Everything on the red wire (output from before) is 0 except our 1 express transport belt! This means if we multiply by everything in the power-of-2 cache, we're left with 8 transport belt, which is 2^3! We actually mapped a value to a key and were able to access it!
Simpler comparisons
At the moment, we can easily do `inputOne*-1=outputOne` then `outputOne+inputTwo=outputTwo` and `outputTwo>0` to check if outputTwo>outputOne (or flip a few things to compare otherwise), however this method compacts it into: `redEach<greenEach=output`. Simpler isn't necessarily better, however since we already have `each` and are able to attach both red and green wires to combinators, it seems intuitive that you would be able to do that.
More
If people suggest other possibilities, or the devs are not convinced, I will be happy to add them!
BUT WHAT ABOUT
* `each/each=each` just gives 1 (for any item that had a value previously)
* In an arithmetic combinator, you cannot output redEach or greenEach, that doesn't make sense. You'd simply output `each`.
* In a decider combinator, there are two options for how outputs work: 1) Keep it `each only` and make it apply to the left side. Since in a decider combinator it's easy to switch the sides since it makes no different (because you can flip sides), you could flip the sides if you needed to. 2) Keep `each` (which adds red + green wires) and allow `redEach` and `greenEach` to only output the value of those wires (if the requirements are met).
* If it's implemented, `redEverything>greenEverything=>each` means "If everything in the red wire is greater than each respective item in the green wire (except values of 0 I suppose?) then output each item.
* `redAnything>greenAnything=>each` means "If anything in the red wire is larger than the same item on the green wire, output each item.
* `redEach>greenEach=>each` means "Each item can pass if they are larger on the red side than the green".
* `redEach>greenEverything` or `greenAnything=redEverything` is a no no! Only the same type of "each" (each, anything, everything).
* More stuff that I probably missed. Will add on.
Why is this so great?
It's a small change to one part of combinators but opens up many possibilities. If someone is not interested in combinators, it's unlikely it will affect them! All of these are type `virtual`.
Please give feedback!