LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why is LabVIEW's array truthiness done this way?

Highlighted

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
(1,505 Views)
Highlighted

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
CLAD expired, using LV2011SP1 + LV2017 (+LV2019 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

0 Kudos
Message 2 of 16
(1,485 Views)
Highlighted

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
Message 3 of 16
(1,479 Views)
Highlighted

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
(1,411 Views)
Highlighted

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
(1,380 Views)
Highlighted

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
(1,370 Views)
Highlighted

@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
0 Kudos
Message 7 of 16
(1,362 Views)
Highlighted

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
(1,342 Views)
Highlighted

@ 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
(1,323 Views)
Highlighted

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

-------------------------------------------------------------------
Unfortunately, most readers of this Forum, including some real Experts, have not mastered the skill of being able to read the code that Posters fail to post. If we cannot see "what you did wrong", we are unable to tell you how to fix it. (Bob Schor 28 August 2018)
0 Kudos
Message 10 of 16
(1,268 Views)