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.

post-2992-1241621756.png?width=400

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: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 (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.

Link to comment

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...

Important Information

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