BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Rube Goldberg Code

Well that idea I posted previously is still bugging me so let me share what I have been perplexed by as a ...

 

Challenge Question

 

Can any of you give an example of a code construct where logical inverse operations wired to each other actually makes sense?

 

What I mean by "logical inverse operations" is;

 build array followed by index array,

Two logical NOTs wired in series,

Increment followed by a decrement, etc

 

The only one that comes to mind is the code used to illustrate the precision of CPUs where the number one is added then subtracted to show the result are not always equal.

 

SO...

 

Can you cite any example?

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 361 of 2,635
(12,331 Views)

Good question, i sometimes use the number to boolean array, then array subset amd back to number to chop down a U16 to a U10 or something.  Although this can probably done with masking etc.  Sometimes i code the long way round so as to make it more readable.  (well it makes sense in my crazy head!)

 

Thinking about it, even then it serves a purpose but not in the way you were asking so didnt really answer your question at all 😄 

Message Edited by craigc on 11-20-2008 02:16 PM
LabVIEW 2012
Message 362 of 2,635
(12,327 Views)

Wasn't there a variant bug a while back where the variant data was losing information... Casting the variant to variant fixed it IIRC.... I can't find it, but the knowledge (trivia?) is bouncing around in the cavity where my brain used to be.

 

Shane.

Message 363 of 2,635
(12,315 Views)

I could think of using a delete from array followed by a build array. If you do not know the size of the array and want the last element, you can use the delete from array to get it. Then put it back in. Index array defaults to the first element.

 

However you're probably better off using array size and then index to avoid the memory manager.

 

     Rob

Message 364 of 2,635
(12,312 Views)

craigc wrote:

Good question, i sometimes use the number to boolean array, then array subset amd back to number to chop down a U16 to a U10 or something.  Although this can probably done with masking etc.  Sometimes i code the long way round so as to make it more readable.  (well it makes sense in my crazy head!)

 

Thinking about it, even then it serves a purpose but not in the way you were asking so didnt really answer your question at all 😄 

Message Edited by craigc on 11-20-2008 02:16 PM

I think that is close Craig but the extra stuff in the middle "then array subset" is the part that makes that construct make sense. To help flesh out the rules of the adhoc Challenge, remeber I am looking for invers operations wired directly together. I just have this feeling that I can help develop that "Crazy Idea" into a practical suggestion I can submit to NI. I want to say that wiring inverse operation should either not be allowed or there should be a warning (maybe wiring tool changes to a quesion mark) when they are attempted.

 

The end result is to make it harder for novices to accidently wire up Rube-idium code.

 

But thank you craig for your reply! If nobody else comes up with a valid construct, you will be defauly winner of this Challenge.

 

Ben

 

PS Yes, I will not allow myself to compete. Smiley Wink

 

Edit

 

Shane, I think we need a link for that one.

 

Rob, I think you may have a valid candidate there.

 

 

 

Message Edited by Ben on 11-20-2008 02:31 PM
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 365 of 2,635
(12,311 Views)

I have a inversion construction, that I've actually used quite a bit! 

 

I used a  DBL -> SGL -> DBL inversion, to limit the number of significant digits before a floating point floor operation.    

 

I needed that to improve Labview's  Quotient&Remainder vi.    The Q&R works on floating points, which helped me a lot in making simpler code for a instrument driver.   Unfortunately, it turned out that it gave the wrong results.  1 Q&R 0.2 gives 4, with a remainder of 0.2    Smiley Surprised  

 

Ofcourse, the cause of this problem is the rounding errors in floating point operations.  When you're close to an integer number, the "floor" operation in de Q&R has the same problems with floats as an "equal" operation....   Unfortunately, Labview's Q&R implementation doesn't take care of that. 

However, you CAN get correct results, by first limiting the number of significant digits  (so that you loose those rounding errors)  and then immediately after that, performing the floor.  At that point, you only have quantization errors left, and the IEEE floating points operations do take those into account!    Smiley Happy   

 

So I made my own version of Q&R, where I first make this DBL-> SGL conversion, and then perform the floor operation:

 

 

Actually... in the vi I built,  I was too lazy to add the DBL operation, and just had coercion dots do the work...   Smiley Wink But the principle is the same.  

 

Later on, I've made a proper "round to significant number of digits" vi, so that you're not limited the number of sign. digits in SGL's.  But for the Q&R vi, it's doubtfull that you'd ever run into that limitation.... 

Message 366 of 2,635
(12,257 Views)

Ah. ECC errors.  Faulty memory.

 

The variant thing I was referring to was simply an automatic variant coercion losing names of controls.

 

Using a "To Variant" conversion isntead of a coercian dot solved the problems.   Not quite what I was thinking of (What WAS I thinking of?).

 

Shane.

Message 367 of 2,635
(12,232 Views)

Ben wrote:

Can any of you give an example of a code construct where logical inverse operations wired to each other actually makes sense?


There are many examples in math, for example where you won't get the original input back depending on the value input:

 

--square--square-root--   is equivalent to "abs"

---sine---inverse sine--  or --cosine--inverse cosine--  : returns values folded into the range [-pi, pi] or [0,2Pi] resp.

...

 

(I also wonder if in the case of the "built array from scalar...index array" the compiler would optimize that out or not.)

Message 368 of 2,635
(12,198 Views)

Ahh thanks altenbach,

 

You have just solved a problem I have been having with reading phase difference from a Network analyser.  I knew there must be a way of getting the phase's back to (-pi, pi).  At the moment i have a block of code to check limits and add or subtract pi but this looks much more elegent.  I may even post it in this goldberg thread if all works out 🙂

 

Craig 

LabVIEW 2012
0 Kudos
Message 369 of 2,635
(12,123 Views)

Wow, he's answering questions even when he's not answering questions. No wonder he's a knight.

 

     Rob

0 Kudos
Message 370 of 2,635
(12,096 Views)