From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why is LabVIEW's array truthiness done this way?

Just curious why it is done this way. The situations in outputs 1 and 2 have bitten me a couple of times now.

 

 

 

 

0 Kudos
Message 1 of 16
(3,346 Views)

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:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 16
(3,326 Views)

Is there a FALSE in the Array?  No.  Therefore the result must be TRUE.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 16
(3,320 Views)

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.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 16
(3,252 Views)

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)

 

 

 

 

 

0 Kudos
Message 5 of 16
(3,221 Views)

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.


___________________
Try to take over the world!
Message 6 of 16
(3,211 Views)

@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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 16
(3,203 Views)

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).


___________________
Try to take over the world!
0 Kudos
Message 8 of 16
(3,183 Views)

@ 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 ! ...    Smiley Wink ...    (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 !

 

 

 

 

0 Kudos
Message 9 of 16
(3,164 Views)

@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. 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 10 of 16
(3,109 Views)