  The controlled-SWAP and controlled-controlled-NOT gates are at the heart of
the original proposal of reversible classical computation by Fredkin and
Toffoli. Their widespread use in quantum computation, both in the
implementation of classical logic subroutines of quantum algorithms and in
quantum schemes with no direct classical counterparts, has made it imperative
early on to pursue their efficient decomposition in terms of the lower-level
gate sets native to different physical platforms. Here, we add to this body of
literature by providing several logically equivalent circuits for the Toffoli
and Fredkin gates under all-to-all and linear qubit connectivity, the latter
with two different routings for control and target qubits. Besides achieving
the lowest CNOT counts in the literature for all these configurations, we also
demonstrate the remarkable effectiveness of the obtained decompositions at
mitigating coherent errors on near-term quantum computers via equivalent
circuit averaging. We first quantify the performance of the method in silico
with a coherent-noise model before validating it experimentally on a
superconducting quantum processor. In addition, we consider the case where the
three qubits on which the Toffoli or Fredkin gates act nontrivially are not
adjacent, proposing a novel scheme to reorder them that saves one CNOT for
every SWAP. This scheme also finds use in the shallow implementation of
long-range CNOTs. Our results highlight the importance of considering different
entangling gate structures and connectivity constraints when designing
efficient quantum circuits.
