I'm a bit confused about in which case the two unitary gates in a quantum circuit could be canceled? I'm reading an example in this paper. In the following diagram, Figure (b) is a simplified circuit of Figure (a): I'm wondering if Figure (b) is the simplest optimization result of Fig. a? In their diagram, the first and third part of the circuit are grouped together, I do understand that two Hadamard gates are canceled, but why the two C-NOT gates (acting on the second and the ancilla qubit) are also canceled? (in this case, those two C-NOT gates are not next to each other)
My guess is they're canceled since no unitary gates are directly sandwiched between the two control qubits (despite there's another C-NOT between them targeted at the same ancilla qubit). Is this the right explanation? How can I have a better understanding of what's going on?
Thanks!!!