Jump to content

# 'AND' of an empty boolean array is TRUE?

## Recommended Posts

I Google'd for this briefly and came up empty. If I missed another place where this has been posted, accept my apologies!

If I take the logical AND of an empty array of booleans, the result is TRUE. I expected it to be FALSE.

By the same token, the logical OR of an empty array of booleans is FALSE, as I'd expect.

Is this a bug, or another instance where I'm misunderstanding the vagaries of IEEE math?

Attached VI: (LabVIEW 8.2) Download File:post-2992-1241621760.vi

##### Link to comment

From the help:

And Array Elements

Returns TRUE if all the elements in Boolean array are TRUE or if Boolean array is empty. Otherwise, the function returns FALSE. This function accepts an array of any size but returns only a single value based on all values in Boolean array.

##### Link to comment

QUOTE (David Wisti @ May 6 2009, 11:37 AM)

From the help:

And Array Elements

Returns TRUE if all the elements in Boolean array are TRUE or if Boolean array is empty. Otherwise, the function returns FALSE. This function accepts an array of any size but returns only a single value based on all values in Boolean array.

Well, at least it's documented.

##### Link to comment

QUOTE (David Wisti @ May 6 2009, 11:37 AM)

From the help:

And Array Elements

Returns TRUE if all the elements in Boolean array are TRUE or if Boolean array is empty. Otherwise, the function returns FALSE. This function accepts an array of any size but returns only a single value based on all values in Boolean array.

And Multiply Array Elements returns 1 for empty arrays for the same reason as x^0==1 and 0!==1.

No elements to operate => return neutral element for that operation.

##### Link to comment

QUOTE (jpdrolet @ May 6 2009, 11:41 AM)

0!==1.

:thumbup:

##### Link to comment

QUOTE (normandinf @ May 6 2009, 11:42 AM)

:thumbup:

Why the thumb up? 0! is factorial 0 not !0 (logic complement)

##### Link to comment

I had had the same reaction when I first ran into this. I asked a fellow developer and he said that from a computer science perspective, this results is correct. I don't recall the details but this is not considered a bug.

##### Link to comment
QUOTE (jpdrolet @ May 6 2009, 10:50 AM)
Why the thumb up? 0! is factorial 0 not !0 (logic complement)
But the association is 0 !== 1 as in "zero not equals one".

##### Link to comment

QUOTE (jpdrolet @ May 6 2009, 11:50 AM)

Why the thumb up? 0! is factorial 0 not !0 (logic complement)

Sorry for the confusion... I'm not trying to be a smart-######!

Factorial of 0 is equal to 1.

I understood your comment as being "Since 0! = 1, then no elements in array = 1".

Array[T,T,T] would be analog to 3!.

Array[empty] would be analog to 0!, hence 1.

I thought it was the simplest mathematical explanation one could give and I gave a thumbs up.

##### Link to comment

QUOTE (normandinf @ May 6 2009, 07:36 AM)

I'd say it a bug. What do other languages give for an answer? Can anybody try that in C or Java?

I asked a buddy of mine who's a C/Java programmer, and he said, "Null pointer exception."

(no, seriously, that's what he said.)

##### Link to comment

It's a bit like the Error thrown on end of file in file functions. Technically correct, , but counter-intuitive and a pain in the proverbial.

##### Link to comment

Another justification:

##### Link to comment

I think this is called the Identity of a function.

For a AND Array the Identity is True where an OR Array has a FALSE Identity.

Ton

##### Link to comment

QUOTE (Ton @ May 7 2009, 03:46 AM)

I think this is called the Identity of a function.

For a AND Array the Identity is True where an OR Array has a FALSE Identity.

Ton

That is the reason that was given to me.

##### Link to comment

QUOTE (ShaunR @ May 6 2009, 03:01 PM)

It's a bit like the Error thrown on end of file in file functions. Technically correct, , but counter-intuitive and a pain in the proverbial.

Well, you do not get that error before you try to read PAST the end of the file. As such it is not really a pain in the ######. Reading up to and including the last Byte does not give this error at least here for me.

Rolf Kalbermatter

##### Link to comment

QUOTE (rolfk @ May 10 2009, 10:59 AM)

Well, you do not get that error before you try to read PAST the end of the file. As such it is not really a pain in the ######. Reading up to and including the last Byte does not give this error at least here for me.

Rolf Kalbermatter

It means you can't just "Read X Chars" until >= "file size" without getting an error. The choice is you either monitor the chunks in relation to the file size and at "file size -Read X Chars" change the "Read X Chars" accordingly, or ignore the error only on the last iteration. If you have another way, I'd be interested. But I liked the old way where you didn't have to do any of that.

##### Link to comment

QUOTE (ShaunR @ May 10 2009, 09:19 AM)

It means you can't just "Read X Chars" until >= "file size" without getting an error. The choice is you either monitor the chunks in relation to the file size and at "file size -Read X Chars" change the "Read X Chars" accordingly, or ignore the error only on the last iteration. If you have another way, I'd be interested. But I liked the old way where you didn't have to do any of that.

I haven't! I use a small VI that has as input the file size, the desired chunk size and the current file offset and returns the number of chars to read and the new offset. Very simple indeed.

On the other hand, you can also just read until you find an error and then filter the EOF error after the loop. This is actually how you do it in C and many other applications also.

You do need some indication that the file read loop needs to be terminated either by checking the current file offset to the known file length or by another mean. Since you should have an abortion on any errors in the loop anyhow, this makes the VI actually simpler as you simply abort the loop on error and then filter the EOF error out.

Rolf Kalbermatter

##### Link to comment

QUOTE (Justin Goeres @ May 6 2009, 10:58 AM)

If I take the logical AND of an empty array of booleans, the result is TRUE. I expected it to be FALSE.

By the same token, the logical OR of an empty array of booleans is FALSE, as I'd expect.

I remember having this conversation on info-labview 10 or 15 years ago...

It may be logical, but it's annoying. I generally work around it by doing a length test on the boolean array before sending it off to do whatever I want it to do.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×

• #### Activity

• Downloads
• Wiki
×
• Create New...

## Important Information

By using this site, you agree to our Terms of Use.