Most existing quantum algorithms are discovered accidentally or adapted from classical algorithms, and there is the need for a systematic theory to understand and design quantum circuits. Here we ...