02-11-2016 03:22 PM - edited 02-11-2016 03:26 PM
Just curious why it is done this way. The situations in outputs 1 and 2 have bitten me a couple of times now.
02-11-2016 03:26 PM - edited 02-11-2016 03:29 PM
Hi Greg,
atleast this fact is mentioned in the help for the "AND array" function…
Trying to guess I think "AND array" works like this:
02-11-2016 03:29 PM
Is there a FALSE in the Array? No. Therefore the result must be TRUE.
02-12-2016 02:21 AM - edited 02-12-2016 02:28 AM
Most of the time I've used "AND array", the TRUE result of empty array was the desired outcome. That being said, I just had this happen to me a few days ago. Thankfully it only took a couple of minutes to figure out what happened.
For Output 2, if I end up comparing an array with an empty array, usually something has gone horribly wrong and I have thrown some kind of error. Since the code related to the comparison (as well as the comparison itself) is in a subVI with an error case structure, it never does the compare and sends out a default "FALSE". Thankfully I can say that I haven't (knowingly) suffered this case... yet.
Output 2 is a startling result, but still behaving as designed.
02-12-2016 04:18 AM
From my point of view, I tend to agree with GregFreeman.
The definition of the and-gate is perfectly clear and precise.
A HIGH output (1) results only if both (or all) the inputs to the AND gate are HIGH (1)
Even if this behavior is mentioned in the help for the "AND array" function, I find this behavior is inappropriate. (this current behavior seems illogical to me)
With an empty boolean array ... all inputs are not "high" ... so, according to the definition of the and-gate, I think that the gate output should be" low"
(IMHO, with my poor english)
02-12-2016 04:45 AM
The first thing to understand is that this is a matter of defining how the function behaves in this edge case, since it's ambiguous. While it's clear that most people's instincts are that it should return F, my guess would be that the thinking behind it is something similar to the empty array multiply, which is defined to return 1 (and does so in LV) - https://en.wikipedia.org/wiki/Empty_product
While I agree that it is confusing to most people, I believe that most of the time I find this behavior to be better, because it helps code be correct without having to add any logic to handle empty arrays, similar to how zero based indexing works most of the time. There are, of course, counter examples, as already shown here.
02-12-2016 04:55 AM
@ouadji wrote:A HIGH output (1) results only if both (or all) the inputs to the AND gate are HIGH (1)
Playing Devil's Advocate here...
So you have an empty Boolean array. None of the elements are FALSE (since you have none), therefore they must all be TRUE. What I'm getting at is that it behaves as a check for the absence of a FALSE. From that standpoint, it makes perfect sense.
Conversely, the OR Array Elements is looking for any TRUE value. So an empty array will have no TRUE values, therefore the result is a FALSE.
02-12-2016 05:26 AM
A quick expansion of the search from before indicates that apparently this is the mathematical background - https://en.wikipedia.org/wiki/Vacuous_truth
And that other languages do the same (example, example).
02-12-2016 06:02 AM - edited 02-12-2016 06:15 AM
@ crossrulz : " the OR Array Elements is looking for any TRUE value. So an empty array will have no TRUE values, therefore the result is a FALSE."
indeed ! ... ... (ok, understood !)
@ tst : the Empty product ... " the result of multiplying no factors is by convention equal to the multiplicative identity 1 "
I didn"t know this theory, I'm going to think more deeply about all this.
(thank you tst for the additional links)
In any case, this debate is very interesting !
02-12-2016 09:33 AM - edited 02-12-2016 09:34 AM
@ouadji wrote:From my point of view, I tend to agree with GregFreeman.
The definition of the and-gate is perfectly clear and precise.
A HIGH output (1) results only if both (or all) the inputs to the AND gate are HIGH (1)
Even if this behavior is mentioned in the help for the "AND array" function, I find this behavior is inappropriate. (this current behavior seems illogical to me)
With an empty boolean array ... all inputs are not "high" ... so, according to the definition of the and-gate, I think that the gate output should be" low"
(IMHO, with my poor english)
Yes but an empty array is equiliivant to the "gray area" in TTL logic because it is neither high nor low.
A TTL gate output with a Gray level input is undetermined, at leat LabVIEW has a determined output, that is a lot eaiser to trouble shoot than if it could go either way like a logi gate.