Home Page
Blue Dust Blog
Projects
Quit!
Discussions
X Seeks Y
Links
About Us!
Quit!
Retro Hacking World  Photo Album  ASP-FTP 
Small Sites  Brand New Writers  Tori Amos in Lego  QuBit 
FTP Explorer 

Visit the site!
  The Site
  
Background
...to technical

I went to see a talk by Damien Conway in Holborn a short while ago. It was hosted by the London Perl Mongers in, of all places, the Conway Hall! Damien talked for a couple of hours on a number of topics. His main focus was, however, his 'Quantum::Superpositions' library for PERL. This enabled programmers to use variables that could hold more than 1 value - at the same time!

He demonstrated that using superpositions it was easy to write searches and the like (because the one variable holds all the values, you just need one conditional 'if X=any(superposition)'. He also demonstrated various other algorithms using superpositions, such as GCD and prime numbers. It was most intriguing.

On the way home I decided to re-write the library for the C++ community. On 2/6/2001 I finished it!

 
Technical
...to links

There are two parts to the library, the variable handlers and the quantum manipulators. Without the latter, the library isn't much more than an exercise in set operations ( 2+{1,2,3} = {3,4,5} ). This code was written first using the STL vector template. Although it might seem more natural to use the one for 'set' I wanted my first excursion into STL to include more familar ground. I started by implementing operator overloading to make the code appear natural C++.

Once I had a proof of concept (e.g. {3,4} * {10,20} produced {30,40,60,80} ) I converted the code into a template, allowing superpositions of any type (and not just ints). I also copied the 'C' code from the '.cpp' file I was using to test, into the '.h' file for final production. Templated code has to exist in the '.h', since without it, the compiler can not implement the functions. I discovered this the hard way!

Finally, the quantum code was added. Quite quickly, really. The 'any', 'all' and 'eigenstates' methods were used (ahem, 'stolen'!) from Damien's PERL original and a number of utility functions (AddRange, for instance) were added to support the end user.

The demo programs were converted from PERL and uploaded. Throughout, I tried to maintain the spirit of the PERL, but because the syntax of both languages differ, I decided to maintain a C++ approach to the code as opposed to trying to mimic PERL.

 
Links
...to next step
Open inthisor newwindow
Quantum::SuperpositionsThe original library on CPAN
www.cs.monash.edu.au/~damianDamien's Homepage
www.cpan.orgThe home of PERL modules
www.ioccc.orgObsfucated C Contest
www.perl.com/CPAN-local/misc/japhJust Another Perl Hacker
 
Taking it further
...to related

Modify the code to use STLs 'set'.
Would anyone find it useful to make it compatible with the rest of STL?

 
Related Projects