Jump to content

'AND' of an empty boolean array is TRUE?


Recommended Posts

Posted

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

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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." :D

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

Posted

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.

Posted

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.

Posted

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

Posted

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.

Posted

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

Posted

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.

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.