2
$\begingroup$

I want to simulate a circuit similar to the one below in MATLAB. If you have a state matrix describing the state of 3 qubits, I understand that you could apply a CNOT matrix tensored with and identity matrix to $\psi_{0} $ get $\psi_{1}$, but if you want to apply a controlled operation to the 1st and 3rd qubit to get $\psi_2$, how can you do this? It's like you need "remove" the information about the second qubit, apply a CNOT gate, and then somehow integrate the result back with the superposition of the second qubit... I do not understand how to do this.

In general if I have a superposition of N qubits, how do I apply a controlled operation on qubits i and j?

Simple Quantum Circuit

$\endgroup$

2 Answers 2

1
$\begingroup$

I think this will answer your question. How does the CNOT between qubits one and three work? $$\left|000\right\rangle \to \left|000\right\rangle$$ $$\left|001\right\rangle \to \left|001\right\rangle$$ $$\left|010\right\rangle \to \left|010\right\rangle$$ $$\left|011\right\rangle \to \left|011\right\rangle$$ $$\left|100\right\rangle \to \left|101\right\rangle$$ $$\left|101\right\rangle \to \left|100\right\rangle$$ $$\left|110\right\rangle \to \left|111\right\rangle$$ $$\left|111\right\rangle \to \left|110\right\rangle$$

So its matrix would look like:

$$\left(\begin{array}{cccccccc} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ \end{array}\right)$$

$\endgroup$
4
  • $\begingroup$ That's a good start. But what if you wanted to simulate a bigger circuit with say n input qubits. Is there a general form that could simplify and not need to write out a (2^n)x(2^n) matrix? $\endgroup$
    – Scott
    Commented Apr 20, 2014 at 22:03
  • $\begingroup$ @Scott Let me answer your question with this, if there was an efficient way of simulating generic quantum states and their operators on a classical computer, then ... $\endgroup$
    – Ali
    Commented Apr 20, 2014 at 22:24
  • $\begingroup$ @Scott Matlab has support for "sparse" matrices if many entries are zeros. $\endgroup$
    – rob
    Commented May 19, 2014 at 13:40
  • $\begingroup$ @Scott rob is right(actually many modern programming languages support sparse arrays, including Mathematica and Matlab). There are algorithms for sparse matrices, but even in that case you would need to specify $\mathcal O \left(2^n\right)$ elements for your matrices, which is still huge. $\endgroup$
    – Ali
    Commented May 19, 2014 at 16:12
-1
$\begingroup$

The answer is $|\psi_{FINAL}\rangle = CNOT_{12} \cdot CNOT_{13} \cdot |\psi_{INITIAL}\rangle$ ;
where $|\psi_{INITIAL}\rangle = |\psi\rangle \otimes |00\rangle$.

So this operation goes as follows:

  • 1st) if $|\psi\rangle$ is in state $|1\rangle$, then perform NOT on the 3rd qubit ($|0\rangle$ goes to $|1\rangle$ in the 3rd position).
  • 2nd) if $|\psi\rangle$ is in state $|1\rangle$, then perform NOT on the 2nd qubit ($|0\rangle$ goes to $|1\rangle$ in the 2nd position).

The matrix representation is: $$ \begin{matrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ \end{matrix} $$

$\endgroup$
3
  • $\begingroup$ please see math.meta.stackexchange.com/questions/5020/… $\endgroup$ Commented Feb 6, 2022 at 2:56
  • $\begingroup$ @ZeroTheHero dude, I get it; but the answer is actually the correct one. No need for the -1 vote just because it's not fancy. I was short of time at the moment. There. Now it's edited to look fancy. $\endgroup$
    – PMG
    Commented Feb 20, 2022 at 6:04
  • $\begingroup$ Your answer is different from @Ali’s and much less detailed. If there is an error with the other answer (or with yours) there is no way to track it down from your post. Maybe you can expand your answer? It could be the ordering of basis states is different between yours and Ali’s and both answers agree, but then why repeat another answer? $\endgroup$ Commented Feb 20, 2022 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.