Justin Goeres Posted May 7, 2009 Report Share Posted May 7, 2009 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 Quote Link to comment
Francois Normandin Posted May 7, 2009 Report Share Posted May 7, 2009 QUOTE (Justin Goeres @ May 6 2009, 10:58 AM) Is this a bug, or another instance where I'm misunderstanding the vagaries of IEEE math? I agree it's weird. For the sake of understanding how it could work... this algorithm would produce that result: http://lavag.org/old_files/monthly_05_2009/post-10515-1241624126.png' target="_blank"> I'd say it a bug. What do other languages give for an answer? Can anybody try that in C or Java? Quote Link to comment
David Wisti Posted May 7, 2009 Report Share Posted May 7, 2009 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. Quote Link to comment
Francois Normandin Posted May 7, 2009 Report Share Posted May 7, 2009 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. Quote Link to comment
jpdrolet Posted May 7, 2009 Report Share Posted May 7, 2009 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. Quote Link to comment
Francois Normandin Posted May 7, 2009 Report Share Posted May 7, 2009 QUOTE (jpdrolet @ May 6 2009, 11:41 AM) 0!==1. :thumbup: Quote Link to comment
jpdrolet Posted May 7, 2009 Report Share Posted May 7, 2009 QUOTE (normandinf @ May 6 2009, 11:42 AM) :thumbup: Why the thumb up? 0! is factorial 0 not !0 (logic complement) Quote Link to comment
gmart Posted May 7, 2009 Report Share Posted May 7, 2009 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. Quote Link to comment
Aristos Queue Posted May 7, 2009 Report Share Posted May 7, 2009 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". Quote Link to comment
Francois Normandin Posted May 7, 2009 Report Share Posted May 7, 2009 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. Quote Link to comment
Justin Goeres Posted May 7, 2009 Author Report Share Posted May 7, 2009 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.) Quote Link to comment
ShaunR Posted May 7, 2009 Report Share Posted May 7, 2009 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. Quote Link to comment
jpdrolet Posted May 7, 2009 Report Share Posted May 7, 2009 Another justification: Quote Link to comment
rpodsim Posted May 7, 2009 Report Share Posted May 7, 2009 For more explanation check out these: http://en.wikipedia.org/wiki/Universal_quantification (The case that tests if all values in a set are true) http://en.wikipedia.org/wiki/Vacuous_truth (The case of an empty set) Justin Goeres: That was the first thing I thought of. But LabVIEW doesn't use pointers. (Directly atleast, unless you count references) Quote Link to comment
LAVA 1.0 Content Posted May 8, 2009 Report Share Posted May 8, 2009 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 Quote Link to comment
gmart Posted May 8, 2009 Report Share Posted May 8, 2009 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. Quote Link to comment
Rolf Kalbermatter Posted May 11, 2009 Report Share Posted May 11, 2009 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 Quote Link to comment
ShaunR Posted May 11, 2009 Report Share Posted May 11, 2009 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. Quote Link to comment
Rolf Kalbermatter Posted May 12, 2009 Report Share Posted May 12, 2009 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 Quote Link to comment
Cat Posted May 12, 2009 Report Share Posted May 12, 2009 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. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.