A Rusty Quantum Interpreter

2023-08-14

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 ndarray for linear algebra instead of implementing it by hand! However, it does have a couple of features not present in the original (or OCaml) implementation(s):

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. Please feel free to take a look and let me know what you think!