Does this quantum circuit reproduce the oracle in Deutsch's algorithm?

This seems to me a fine quantum oracle for the balanced one bit function $$f(x)=x$$, but putting it in Deutsch's algorithm circuit will give the result $$|0\rangle$$, i.e. the function is evaluated as constant. Where am I wrong?

• Hi and welcome to Quantum Computing SE. It seems to me that the problem is in Z gate. Why you put it on the first qubit? If you want to implement identity function, CNOT is enough. For inputs 0 and 1 on first qubit, the input is always propagated to the second qubit as CNOT works as fan-out. So, just remove the Z gate and try again. See more here: quantum-inspire.com/kbase/deutsch-jozsa-algorithm Commented Aug 21 at 6:11
• Solving Deutsch's problem means finding whether the function is constant or balanced regardless of the oracle internal mechanism. The question is not why putting the CNOT gate but if the oracle function with the CNOT is correct. If it is, Deutsch's algorithm should solve it. Commented Aug 23 at 5:20
• You haven't stated what input states you are using. Conventionally, you would use an input of 0 on the top qubit and 1 on the bottom. Then you'd apply Hadamard gates to both qubits before entering the controlled-not, and you'd also apply a hadamard to the top qubit after the controlled-not (i.e. all the bits around the oracle, not just the oracle itself) Commented Sep 4 at 4:42
• I didn't describe the whole Deutsch's algorithm circuit, but yes, this is the way to do it. The thing is that since the algorithm is based on phase kickback, the Z gate cancel it but makes no difference to the output. My question is what in the definition of the problem doesn't allow such oracle to be used as a balanced function oracle. Commented Sep 6 at 5:39

Suppose input to $$q_0$$ is $$| + \rangle$$, $$q_1$$ is $$| - \rangle$$,

Then the input state would be as follows (in a little endian) :

$$\frac{1}{\sqrt{2}} \left( |0 \rangle - |1 \rangle \right) \otimes \frac{1}{\sqrt{2}} \left( |0 \rangle + |1 \rangle \right)$$

$$=\frac{1}{2} \left( |00 \rangle + |01 \rangle - |10 \rangle - |11 \rangle \right)$$

After your $$CNOT$$ gate the state would become :

$$=\frac{1}{2} \left( |00 \rangle + |11 \rangle - |10 \rangle - |01 \rangle \right)$$

after your $$Z$$ gate the phase on $$|1 \rangle$$ flips, so the state would become :

$$=\frac{1}{2} \left( |00 \rangle - |11 \rangle - |10 \rangle + |01 \rangle \right)$$

At the end of Deutsch's algorithm a Hadamard gate is applied to $$q_0$$, so the final state would be :

$$\left(I \otimes H \right)\frac{1}{2} \left( |00 \rangle - |11 \rangle - |10 \rangle + |01 \rangle \right)$$

$$=\frac{1}{2} \left( |0 \rangle \frac{1}{\sqrt{2}}\left( |0 \rangle + |1 \rangle \right) - |1 \rangle \frac{1}{\sqrt{2}}\left( |0 \rangle - |1 \rangle \right) - |1 \rangle \frac{1}{\sqrt{2}}\left( |0 \rangle + |1 \rangle \right) + |0 \rangle \frac{1}{\sqrt{2}}\left( |0 \rangle - |1 \rangle \right) \right)$$

$$=\frac{1}{\sqrt{2}} \left( |00 \rangle - |10 \rangle \right)$$

You see $$q_0$$ becomes $$|0 \rangle$$.

• I would just add that in case $Z$ gate is not applied, the result is $\frac{1}{\sqrt{2}}(|01\rangle - |11\rangle)$, so qubit $q_0$ is in state $|1\rangle$ which indicates balanced function. Hence, $Z$ gate should be eliminated in order to the oracle really implements function $f(q_0) = q_0$. Commented Aug 21 at 7:37
• For input of |0⟩ or |1⟩ the state is unchanged by the Z gate. For superposition it only changes the phase, just as the phase kickback does. Commented Aug 22 at 4:27