LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Anding of Empty Boolean Array Results in True

Hello All,

I have a requirement of ANDING a Boolean array to decide for  a particular case, at times my boolean array acquired becomes empty due to NO DATA AVAILABILITY, during such sceanrio my output from AndArrayElement is TRUE

 

Hope default value can be false instead of true (where most of the default for boolean is FALSE)

I found an alternative way to solve my issue, but still then wanted to bring this issue to forum to know whether any reason for providing TRUE for a default case.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 1 of 9
(4,884 Views)

Hello,

The properties/behaviour of boolean with AND property is

0 AND 0 = 0(FALSE), 0 AND 1 = 0(FALSE), 1 AND 0 = 0(FALSE), 1 AND 1 = 1(TRUE).

If its an empty array then it will take values as 0 means the output should be 0(FALSE). 

0 Kudos
Message 2 of 9
(4,875 Views)

Anding Empty Array.png

 

Check the behaviour of attached snippet

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 3 of 9
(4,866 Views)

From the help: "Returns TRUE if all the elements in Boolean array are TRUE or if Boolean array is empty."

If you want to check if the array is not empty you'll have to add that check.

It sounds logical for an AND array to default to false, but the empty array is undefined, and in this case defaulted to true. Technically i assume LV starts with True and ANDs all elements one at a time, resulting in this behaviour.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 9
(4,862 Views)

Hi,

 

this has been discussed before!

 

AND-Array works in a somewhat different way then expected: it checks for the opposite condition. The result of AND-Array is TRUE, when there is no FALSE element in the array. In an empty array there are no FALSE elements…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 9
(4,859 Views)

Thanks for all your inputs!

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 6 of 9
(4,853 Views)

I *think* the behavior is not a quirk but instead comes from adherence to set theory and/or number theory.  I can't seem to reconstruct all the reasoning, but it comes down to the need for an operation on an empty set to produce the identity value for that operation.  

 

In the case of AND, the identity value is True (anything AND'ed with True results in the same anything).  Thus logically AND'ing all elements of an empty array results in the identity value for AND, i.e., True.

 

In the case of OR, the identity value is False (anything OR'ed with False results in the same anything).  Thus logically OR'ing all elements of an empty array results in the identity value for OR, i.e., False.

 

 

The numeric functions "Add Array Elements" and "Multiply Array Elements" follow the same rule -- operating on an empty array produces the identity value for that operation.  Straightforward enough when adding elements of an empty array to produce a result of 0, but much less intuitive when multiplying elements of an empty array to produce a result of 1.  (Really!  The help even mentions this.)

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 7 of 9
(4,806 Views)

@aku_5 wrote:

Hello,

The properties/behaviour of boolean with AND property is

0 AND 0 = 0(FALSE), 0 AND 1 = 0(FALSE), 1 AND 0 = 0(FALSE), 1 AND 1 = 1(TRUE).

If its an empty array then it will take values as 0 means the output should be 0(FALSE). 


Be careful with this.  You're making a pair of assumptions that you shouldn't be.  1) you're assuming the greyed values are 0.  They're not.  They're undefined.  2) you're assuming showing the unitialized values of an array with 4 elements is the same thing as showing how things will behave with an empty array.  This doesn't show the behavior in the original post nor does it counter it.

 

It sounds like we have a few theories as to why this happens.  Ultimately, the help documentation makes it clear this is the intended behavior.  As it's not what you want, I'd consider a quick Array Size function.  Feed the value into a case structure with the cases '0' and '1, default'  (If you want to be careful, you can do a greater than zero? first and use the true/false cases).  For the 0 case, output a false and run no calculations.  For the default case, feed in your array, AND it, and output the result.  Now, you'll get a false in the case of an empty array and the desired result for any other array.

0 Kudos
Message 8 of 9
(4,787 Views)

@natasftw wrote:

As it's not what you want, I'd consider a quick Array Size function.  Feed the value into a case structure with the cases '0' and '1, default'  (If you want to be careful, you can do a greater than zero? first and use the true/false cases).


Even easier, there is an Empty Array function in the comparison palette.  And I would not even use a case structure.


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 9 of 9
(4,767 Views)