P is for Practical | |
PerlMonks |
Re: Control Structuresby mstone (Deacon) |
on May 10, 2005 at 19:38 UTC ( [id://455728]=note: print w/replies, xml ) | Need Help?? |
Well, speaking with tongue partially in cheek, I suppose Fredekin gates and generalized Toffoli gates would be nice. The code versions of each look roughly like so:
The Fredekin gate takes a three-item list as input and returns a three-item list as output. If the first item is FALSE, the return list is identical to the input list. If the first item is TRUE, the last two items of the return list are swapped. The Toffoli gate is more general, and does roughly the opposite. It takes an N-item list as input, and returns an N-item list as output. If any item from 0 to N-1 is FALSE, the output list is indentical to the input list. If all the items from 0 to N-1 are TRUE, the logic value of the final item is flipped.. TRUE is replaced by FALSE, or FALSE is replaced by TRUE. Both gates are universal, meaning you can build a complete Turing machine using nothing but arrays of either kind of gate. The Fredekin gate also maintains perfect energy balance, meaning it never changes the number of TRUE or FALSE statements. The Toffoli gate can change the number of TRUE and FALSE statements, which makes it slightly more powerful than the Fredekin gate (i.e.: you'll need fewer gates and scratch inputs to solve a problem with Toffoli gates), but as a consequence, the Toffoli gate runs 'hotter'. Changing in the number of TRUE and FALSE statements involves energy transfer, and ultimately, that energy will be released as heat. Both can serve as basic building blocks for quantum and/or reversible computation. And as an aside, the Fredekin gate is actually kind of useful in everyday programming. It's good for situations where you need to choose between two options based on the value of a third item. And situations like that show up frequently when you try to arrange code for logical correctness.
In Section
Meditations
|
|