Re: Minimalist signal filtering device
Posted: Mon Nov 29, 2021 11:55 pm
What you're describing (inverting every bit/lamp) is ones complement. To get twos complement you then also need to add 1.mmmPI wrote: ↑Mon Nov 29, 2021 8:24 pmon a joke side : I think i have an idea to replace paper by 32 or 64 lamps. Also i would need a contraption that convert my base 10 number into binary. this way less writing :dTertius wrote: ↑Mon Nov 29, 2021 7:41 pmIf you want to design something that depends on the bit-representation of the values, you need to think in binary values. And you need to know the representation of negative numbers (two's-complement) and why this is used. And if you cannot think in binary (I cannot, too many digits), you need to write all the 32 bits in 0 and 1 on paper and use the paper for thinking.
i have seen couple basic explanation on two's complement, but haven't used much because either no purpose for me personnaly for what i've been doing or maybe when i could use it i didn't recognize it.
It would be the number that is represented by the opposite of the 32 lamps in my idea i think, if a number is represented with 32 lamps on or off, then you imagine the lamp that are on are instead off and vice versa. or you just plug in a unary not gate as pictured on the wiki to every lamp
It's an overflow when you the result doesn't fit in the number of bits you have available, in factorio that's results of 2^32 (or 1 << 32) and above. Calling changing the topmost bit an overflow seems odd to me as well.mmmPI wrote: ↑Mon Nov 29, 2021 8:11 pmIt it is more intuitive to me to call it overflow when it happens due to an operation that result in a very large number rather than when you do 1<<31 which for me is still a bit mysterious since it require thinking about the binary form of the number and i'm not used to it. Where for the large number it's easier for me to picture the numbers written on a cylinder of paper and starting over after a large number.
still 10*-2147483648=0 is not intuitive none of that is x).
Code: Select all
10^0 = 1
10^1 = 10
10^2 = 100
10^3 = 1000
10^4 = 10000
Code: Select all
2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
2^6 = 64
...
2^31 = 2147483648
2^32 = 4294967296
Some of the confusion came from my ignorance of the different ways to represent negative binary number integer. I was mixing up names of binary operation/relation between numbers that i had heard of, and name of convention used to represent negative numbers which was new. Thanks to your explanation i was able to document properly and make the machine i wanted
Another part may come from the misuage of terms and notation i did when i took as example 10 without specifying that it was decimal 10 (1010 in binary) or any other number whose rightmost bit is not 1, the choice of decimal 10 as exemple was not a good choice example. This was in relation with doing x<<31, x need to have the rightmost bit not 0 otherwise the result is 0 and you cannot use this operation for the purpose of the filter. For the purpose of the filter those value x are made equal to 1 by the first decider combinator. Wich allows the <<31 operation to create the largest negative number possible on each channel used in "b". Then the values "a" are added to this number, which gives different values that are all negative. The last decider filter only the negative value, and discard the positive value, this means the values that where only represented in a and not in b are discarded. The values that are passed as output of the last decider combinator are all negative value that could be described as [the smallest number possible + a ]. And then there is a sum due to the wire connection with value that are [the smallest number possible] from the operation <<31, which cancels each other due to overflow only leaving values "a" that were also present in "b".
gGeorg wrote: ↑Wed Dec 01, 2021 5:49 amI could ask you to make it even more readable. add spaces and use coloured concrete for lamps background.
Although we had variable byte definition in far history, the size of byte is standardized for couple of years.
You might ask why 4 bits sections are important? well becouse Hex numbers. Therfore we say High part and Low part of bye. e.g. hi and lo 4bit section.
This is the kind of thing i realized when looking at the signals once the bigger machine was made. It's (relatively) easier to spot the pattern and realize the bitshifting to the right was not necessary since all the lit lamp were the lamp receiving negative signal, ( the >>31 was just transforming a large negative number into -1). i just changed the condition of the lamp and removed the combinator.
Well, yes, in a way you're right. But not completely. You are first extracting, then processing every bit on its own. You're simulating how a computer will process every single bit. I used the computer to do the operations. I was treating the combinator as processor register and acted as if i'm doing assembly programming the processor. I used the number storage of the combinator similar to a register in a CPU and first performed the negation, then the two's complement by increment. There are assembly language instructions for these operations, and this reminded me of these.mmmPI wrote: ↑Wed Dec 01, 2021 9:58 pmYou first turn the number A in its ones complement using a XOR-1 calling it N, then you add 1 to this number calling it T, and then you use the bitshift on all intermediate number A N and T at the same time on parralel channel.
Turning the number negative in decimal first and then displaying it in binary form would be easier and not even require the ones complement but i said it felt like cheating to me !
Not completely without - it's not possible to identify one bit in a lamp condition alone. You need at least one mathematical operation to filter the bit.
That's cool ! I was unaware of those things, that's why i enjoy playing Factorio, i play video games all the time, and realised it would be better if those hours spent could teach me some things more useful for general purposes than the name and range of 12427 different magic spells or war vehicules or the perfect map of imaginary places which i already have plenty in mindTertius wrote: ↑Thu Dec 02, 2021 4:11 am[...]first extracting, then processing every bit on its own.[...] simulating how a computer will process every single bit. I used the computer to do the operations. I was treating the combinator as processor register and acted as if i'm doing assembly programming the processor. I used the number storage of the combinator similar to a register in a CPU and first performed the negation, then the two's complement by increment. There are assembly language instructions for these operations, and this reminded me of these.
That is really how the two's complement is created by a basic CPU. Keep in mind the early CPUs didn't have an assembly instruction for multiply. Only add, subtract, increment by 1, decrement by 1, and, or, xor, neg.
The lamps are like mini NOT gate they do invert the number bit by bit, i've just decided to include that in the rules and there is no rule saying the rules shouldn't change midway
You saved me some time !! i noticed yesterday after posting that all the lamps in the same row used the same condition and thought there must be a way to add some logic to them to avoid using the left bitshift every time with a different value. I fiddle around a bit but couldn't find anything and made it my plan for this morning haha. Instead i just learned from your blueprint.Tertius wrote: ↑Thu Dec 02, 2021 4:11 amit's not possible to identify one bit in a lamp condition alone. You need at least one mathematical operation to filter the bit.
I did this, I spread the bits with an AND operation over the 32 virtual signals 0, 1, 2, ..., 9, A, B,..., V:
I don't compute the complement, I inverted the condition. And for the two's complement, I simply multiplied with -1 to save 1 combinator. The lamp display proves that the combinator arithmetic actually uses the two's complement to represent negative numbers.
I agree with you this is not the kind of cheating where someone unfairly loses, that's not cheating, more like "cheating" . Rules are guidelines here.
Yes, the AND operation I used is a common way to apply a mask to a value. It keeps desired bits and drops undesired bits. You set desired bits to 1 in the mask, and undesired bits to 0. This is so generic, you will find it in every computer algorithm that deals with single bits. I used it for the lamps to just keep the bit the lamp is designated for, then tested for "not zero" as lamp condition.
This is a way to use every single bit of some value. Unfortunately, you can only transmit the information that ore x is needed, but not how much, since you use only 1 bit for this information. Factorio works a bit different, in my opinion. You can have a value for every ingame material at no computing cost, and additionally the virtual signals. I see a single signal similar to a bit in a CPU register. A Factorio circuit network "register" contains all values for all signals. They are similar in spirit, because all the bits in a CPU register are manipulated simultaneously by an operation, while all the signals from a circuit network are manipulated simultaneously as well by a circuit network operation.mmmPI wrote: ↑Thu Dec 02, 2021 9:45 amLet say you only use the 3 first bits and you make it really simple, you can go for a convention that would mean most significant bit is [Iron ore] then [copper ore] then [coal] would be the least significant, then you create a (i) number whose binary form would be 100 or 010 or 001 depending if you want [iron] or [copper] or [coal] and you send 111 if you need all of them.
The train example was not the best choice from me because it imply practical application in a place where better alternative exist.Tertius wrote: ↑Thu Dec 02, 2021 12:36 pmThis is a way to use every single bit of some value. Unfortunately, you can only transmit the information that ore x is needed, but not how much, since you use only 1 bit for this information. Factorio works a bit different, in my opinion. You can have a value for every ingame material at no computing cost, and additionally the virtual signals. I see a single signal similar to a bit in a CPU register. A Factorio circuit network "register" contains all values for all signals. They are similar in spirit, because all the bits in a CPU register are manipulated simultaneously by an operation, while all the signals from a circuit network are manipulated simultaneously as well by a circuit network operation.
8 bits are a byte for a computer, while all signal channels together are a Factorio-byte for Factorio.
So I would not try to stuff information about real items into single bits of the same signal, because they all have their own signal already.
However, you can use virtual signals to provide information about things that don't have their own signal. Wagons for example. If you need to tell which wagon has some property, designate a bit for every wagon, then stuff the bits into some virtual signal. But you can also simply say signal 0 is wagon 0, signal 1 is wagon 1 etc. It's not that you must use single bits. To operate on all signals, you still have the everything, each and anything operators.
Pointwise array filtering:
OUT1 = IN1 if MASK != 0
OUT2 = IN2 if MASK == 0
Combine IN1 and IN2 to make a signal splitter.
Combine OUT1 and OUT2 to make an IF-THEN-ELSE gate.
(IN*)->(OUT*): 2 ticks delay.
(MASK)->(OUT*): 5 ticks delay (4 if already 0|1 signal).
Signal architecture agnostic (32bits/64bits/any bits); overflow proof.
-- by SteelWolf300 --
Thank you for sharing your build. I have a blueprint book for those and yours will definitly fit in there waiting for that time when it is properly examinedSteelWolf300 wrote: ↑Wed Mar 02, 2022 8:08 amHi all, I built this array filter, I wanted to share it!
EDIT: Thanks to this post, I learned about the technicalfactorio solution (whitelist and blacklist produce the exact same outputs)... Yes their version use less combinators, and the mask is handled in two ticks only, but I am still proud of my version, because I came up with this by myself, and you cannot take this away from me