The Original
Robert Smith, a.k.a. stylewarning, has a lovely blog post that walks through implementing an interpreter for a “general-purpose quantum programming language called \( \mathscr{L} \).” In only 150 lines of Common Lisp, the implementation is featureful, self-contained, and a delight to read.
Imitation is the highest form of flattery
At first I was content with only reading the post and code, but then I saw someone else had put together an OCaml implementation as well. The game was afoot!
Carcinization
Eventually I put together a Rust implementation. This version weights in at more than twice the line count as the original—even though it relies on faer for linear algebra instead of implementing it by hand!1 However, it does have a couple of features not present in the original (or OCaml) implementation(s):
- constructing a
Machinetakes an unsigned 64-bitseedfor repeatable PRNG behavior; and - with the help of the
pegcrate, I added parsing, so one can pass"H 0\nMEASURE"as a string and get an interpretable quantum program.
Code or it didn’t happen
The implementation is here in my catch-all “workbench” repository. It’s definitely not production-worthy code; it’s got an assert! that will panic if not met, and it uses expect to pave over some errors.2 Please feel free to take a look and let me know what you think!