  Quantum Compiling Algorithms decompose (exactly, without approximations) an
arbitrary $2^\nb$ unitary matrix acting on $\nb$ qubits, into a sequence of
elementary operations (SEO). There are many possible ways of decomposing a
unitary matrix into a SEO, and some of these decompositions have shorter length
(are more efficient) than others. Finding an optimum (shortest) decomposition
is a very hard task, and is not our intention here. A less ambitious, more
doable task is to find methods for optimizing small segments of a SEO. Call
these methods piecewise optimizations. Piecewise optimizations involve
replacing a small quantum circuit by an equivalent one with fewer CNOTs. Two
circuits are said to be equivalent if one of them multiplied by some external
local operations equals the other. This equivalence relation between circuits
has its own class functions, which we call circuit invariants. Dressed CNOTs
are a simple yet very useful generalization of standard CNOTs. After discussing
circuit invariants and dressed CNOTs, we give some methods for simplifying
2-qubit and 3-qubit circuits. We include with this paper software (written in
Octave/Matlab) that checks many of the algorithms proposed in the paper.
