Inverting circuit signal

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
imajor
Fast Inserter
Fast Inserter
Posts: 164
Joined: Thu Aug 14, 2014 11:02 am
Contact:

Inverting circuit signal

Post by imajor »

Hi all,

I'm wondering if it is possible to invert ALL entries of a circuit signal. So for example if the circuit signal contains iron, I want a signal which contains everything but iron. My plan was to use a decider combinator where the condition would be *(each) = 0, and the output would be 1 to *(each), so I wanted the combinator to invert all entries separately. It doesn't work, because I guess it ignores all the entries where the value is 0, so it will only invert those where the value is not 0. So the output of the combinator will be zero.

Thanks in advance

Aeternus
Filter Inserter
Filter Inserter
Posts: 835
Joined: Wed Mar 29, 2017 2:10 am
Contact:

Re: Inverting circuit signal

Post by Aeternus »

Depends on the inversion - numerically or logically. Mathematically you'd do EACH *-1 and output Value to EACH with an arithmatic combinator.
Logically, an EACH = 0 with output 1 to EACH via a decider combi in theory should work. Not sure how the game responds to this, because it -should- set any unused channel to 1 in the output, potentially making for a rather messy cluster inverter.

[Edit] I suppose inactive channels are ignored. Additional option: Add a constant combinator with value 1 on each channel you want to test for, then connect that up to the decider combi via the other color cable. Then test for "EACH = 1" with an output of 1 to EACH instead. Bit of a kludge, but it should work.

imajor
Fast Inserter
Fast Inserter
Posts: 164
Joined: Thu Aug 14, 2014 11:02 am
Contact:

Re: Inverting circuit signal

Post by imajor »

Yes, that is what I was expecting too. But it seems the theory do not match the practice here:

Image

The constant combinator has 100 conveyor belts, that is the input for the decider comb as you can see. But there is no output at all, I would expect the output to be 1 for each item type except the conveyor belt. If I change the comb to a fixed item type instead of the EACH wild card it works as expected:

Image

So I think that the EACH wild card is not working the way we think it would work. If the input is zero for a given item type, the operation is not executed, and the output will be zero as well. I don't think it is a bug, I guess it is a design decision. However I'm not sure it is correctly documented.

User avatar
Deadly-Bagel
Smart Inserter
Smart Inserter
Posts: 1498
Joined: Wed Jul 13, 2016 10:12 am
Contact:

Re: Inverting circuit signal

Post by Deadly-Bagel »

You're assuming that a signal of 0 has a value of 0, that is not technically the case. Sure, you can add a condition for [signal] = 0, but actually the value is null.

Basically those options only work for signals with a value, and nobody wants this to work any other way. You would need to set up a chain of Constant Combinators outputting the signals you want, or you might be able to write a mod for an item to do it for you.
Money might be the root of all evil, but ignorance is the heart.

imajor
Fast Inserter
Fast Inserter
Posts: 164
Joined: Thu Aug 14, 2014 11:02 am
Contact:

Re: Inverting circuit signal

Post by imajor »

Deadly-Bagel wrote:You're assuming that a signal of 0 has a value of 0, that is not technically the case. Sure, you can add a condition for [signal] = 0, but actually the value is null.

Basically those options only work for signals with a value, and nobody wants this to work any other way. You would need to set up a chain of Constant Combinators outputting the signals you want, or you might be able to write a mod for an item to do it for you.
Sorry I'm a bit confused. Are you saying that when a signal is empty, it is different than having the value zero? If so, why my second example worked? I'm checking if the lab signal is zero, and that condition becomes true, as you can see on my second shot the output of the combinator is one. If it is working for a specific item, why isn't it working for each?

Caine
Fast Inserter
Fast Inserter
Posts: 213
Joined: Sun Dec 17, 2017 1:46 pm
Contact:

Re: Inverting circuit signal

Post by Caine »

Deadly-Bagel wrote:You're assuming that a signal of 0 has a value of 0, that is not technically the case. Sure, you can add a condition for [signal] = 0, but actually the value is null.

Basically those options only work for signals with a value, and nobody wants this to work any other way.
Well, I am not so sure about that last part. Every once in a while I find myself thinking that propagating a zero signal would be useful. This could be done by propagating explicitly output zeroes (e.g. by a constant combinator) and otherwise let it be null (which is not propagated at all). I suppose the argument against it is that it is not very intuitive.

You can sort of work around the problem by shifting the entire domain and correcting afterwards, but it is not very clean.

mrvn
Smart Inserter
Smart Inserter
Posts: 5699
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Inverting circuit signal

Post by mrvn »

Wires carry a vector of signals with their values. Zero signals are dropped from the vector to save memory and processing.

When comparing specific items a missing signal is equal to 0. Not so for the 3 specials: Everything, Anything and Each. Those only consider the signals actually present. Note that Everything whatever is true if no signals are present while Anything whatever needs at least one signal.

imajor
Fast Inserter
Fast Inserter
Posts: 164
Joined: Thu Aug 14, 2014 11:02 am
Contact:

Re: Inverting circuit signal

Post by imajor »

mrvn wrote:Wires carry a vector of signals with their values. Zero signals are dropped from the vector to save memory and processing.

When comparing specific items a missing signal is equal to 0. Not so for the 3 specials: Everything, Anything and Each. Those only consider the signals actually present. Note that Everything whatever is true if no signals are present while Anything whatever needs at least one signal.
Thanks, that perfectly explains it and matches what I experienced. Meanwhile I was able to solve my problem without the need to invert the signal vector: viewtopic.php?f=8&t=58231

TheOnefinn
Inserter
Inserter
Posts: 23
Joined: Fri Feb 02, 2018 3:05 pm
Contact:

Re: Inverting circuit sign

Post by TheOnefinn »

You would have to manually construct a signal with everything set to 1 (eg by chaining constant combis with a batch in each) then you can subtract your input signal from your “all signal” wire (you want -1 in each of your input signals) and anything that’s > 0 will be your result.
Caine wrote:
Deadly-Bagel wrote:You're assuming that a signal of 0 has a value of 0, that is not technically the case. Sure, you can add a condition for [signal] = 0, but actually the value is null.

Basically those options only work for signals with a value, and nobody wants this to work any other way.
Well, I am not so sure about that last part. Every once in a while I find myself thinking that propagating a zero signal would be useful. This could be done by propagating explicitly output zeroes (e.g. by a constant combinator) and otherwise let it be null (which is not propagated at all). I suppose the argument against it is that it is not very intuitive.

You can sort of work around the problem by shifting the entire domain and correcting afterwards, but it is not very clean.
Currently the only way to remove a signal out of a set is be setting its value to zero, explicit zeros would break that.

Edit: I guess you could add a Each != 0 decider after the arith+diode, but it doubles the latency and adds a third combi to the single signal filter case.

Edit2: actually it could replace the diode if you can guarantee the signal to be filtered isn’t 0 itself.

Caine
Fast Inserter
Fast Inserter
Posts: 213
Joined: Sun Dec 17, 2017 1:46 pm
Contact:

Re: Inverting circuit sign

Post by Caine »

TheOnefinn wrote:Currently the only way to remove a signal out of a set is be setting its value to zero, explicit zeros would break that.

Edit: I guess you could add a Each != 0 decider after the arith+diode, but it doubles the latency and adds a third combi to the single signal filter case.

Edit2: actually it could replace the diode if you can guarantee the signal to be filtered isn’t 0 itself.
Yes that are pros and cons. E.g. the fact that quantification works only on propagated signals is confusing a lot of people regarding the behaviour of any and all.
I am still undecided which one is best, so I am letting the idea incubate for a while. We should collect those pros and cons some day (if it has not been done already).

Post Reply

Return to “Gameplay Help”