08-22-2016 01:41 AM
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.
08-22-2016 02:05 AM
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).
08-22-2016 02:09 AM
Check the behaviour of attached snippet
08-22-2016 02:14 AM - edited 08-22-2016 02:17 AM
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
08-22-2016 02:18 AM - edited 08-22-2016 02:19 AM
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…
08-22-2016 02:43 AM
Thanks for all your inputs!
08-22-2016 04:22 PM - edited 08-22-2016 04:29 PM
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
08-22-2016 10:57 PM
@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.
08-23-2016 04:50 AM - edited 08-23-2016 04:51 AM
@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.