I think I understand what it does. But i can't agree with output for sertain inputs. For example: if a=1 and b=1 then how the output on 4 line could be xor(a, b). Because as far as I know xor(1,1)=0 and also 1+1=1. It's not consistent.
-
1$\begingroup$ Note that $1 \oplus 1 = 0$ $\endgroup$– KAJ226Apr 26 at 5:00
-
1$\begingroup$ As pointed by KAJ 1+1=10, i.e. zero in the lowest bit with carry to higher one. $\endgroup$– Martin VeselyApr 26 at 5:59
-
1$\begingroup$ Also note that CNOT applied on computational basis states behaves as XOR, just write down action of that gate for all possible combination of zeros and ones on control and target qubits. $\endgroup$– Martin VeselyApr 26 at 6:01
2 Answers
Note that the first CNOT gives you
$$ CNOT |a\rangle |0\rangle = |a\rangle |a \oplus 0 \rangle = |a\rangle |a \rangle$$
and then the second CNOT gives you
$$ CNOT |b\rangle |a\rangle = |b\rangle |b \oplus a\rangle$$
Thus the target qubit state is now in $|b \oplus a\rangle$
The notation of $\oplus$ does not simply denote addition. It denotes bitwise addition modulo 2, i.e. $$ 0\oplus 0=0,\quad 0\oplus1=1\oplus 0=1,\quad 1\oplus 1=0 $$ which is exactly the same as the xor that you were predicting.