# Calculating measurement result of quantum swap circuit

Consider the following circuit, where $$F_n$$ swaps two n-qubit states. If the inital state is $$|0\rangle \otimes |\psi\rangle \otimes |\phi\rangle = |0\rangle|\psi\rangle|\phi\rangle$$, the state before measurement is (unless I'm wrong):

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

How to calculate the post measurement distribution for the first qubit, in terms of $$|\psi\rangle$$ and $$|\phi\rangle$$?

While DaftWullie's answer gives you everything you need to calculate the answer in this particular case, I'd like to focus on a particular approach which is helpful in situations like yours, where you have an $$n$$ qubit state state$$\def\ket#1{\lvert#1\rangle}\def\bra#1{\!\langle#1\rvert}$$ $$\ket{\Psi} = \ket{0}\ket{\alpha} + \ket{1}\ket{\beta}\,,$$ where $$\ket{\alpha}$$ and $$\ket{\beta}$$ are not necessarily normalised vectors on $$n-1$$ qubits. (Notice that at least one of $$\ket{\alpha}$$ and $$\ket{\beta}$$ must be sub-normalised in this case if $$\ket{\Psi}$$ has norm 1.) We can then ask: given such a $$\ket{\Psi}$$, what distribution do we expect on $$\ket{0}$$ and $$\ket{1}$$?

If you had a very slightly different representation for $$\ket{\Psi}$$, of the form $$\ket{\Psi} = u_0 \ket{0}\ket{\alpha'} + u_1 \ket{1}\ket{\beta'}\,,$$ where $$\ket{\alpha'}$$ and $$\ket{\beta'}$$ were indeed normalised, then you'd probably be comfortable with this: you'd just recognise that the probability of '0' is $$\lvert u_0 \rvert^2$$ and the probability of '1' is $$\lvert u_1 \rvert^2$$. But we can obtain this just by considering the norms of $$\ket{\alpha}$$ and $$\ket{\beta}$$, and computing $$u_0 = \sqrt{\langle \alpha \vert \alpha \rangle}\,,\qquad u_1 = \sqrt{\langle \beta \vert \beta \rangle}$$ and (if both $$u_0$$ and $$u_1$$ are non-zero) defining the normalised versions $$\ket{\alpha'} \propto \ket{\alpha}$$ and $$\ket{\beta'} \propto \ket{\beta}$$ by $$\ket{\alpha'} = \tfrac{1}{u_0} \ket{\alpha}\,,\qquad\ket{\beta'} = \tfrac{1}{u_1} \ket{\beta}\,.$$

## Short-cutting to the measurement probabilities

But actually, the states $$\ket{\alpha'}$$ and $$\ket{\beta'}$$ are beside the point: what you actually wanted are $$u_0$$ and $$u_1$$, or more precisely, $$\Pr\!\big[\,0\,\big] = \lvert u_0 \rvert^2 = \langle \alpha \vert \alpha \rangle\,,\qquad \Pr\!\big[\,1\,\big] = \lvert u_1 \rvert^2 = \langle \beta \vert \beta \rangle\,.$$ So you can just compute those inner products without even worrying about representing the state $$\ket{\Psi}$$ in one particular way or another, and in particular without giving any thought as to whether or which of $$\ket{\alpha}$$ or $$\ket{\beta}$$ is normalised.

Example.

In your particular case, you have: $$\ket{\alpha} = \frac{1}{2} \bigl( \ket{\psi}\ket{\phi} + \ket{\phi}\ket{\psi} \bigr) , \qquad \ket{\beta} = \frac{1}{2} \bigl( \ket{\psi} \ket{\phi} - \ket{\phi} \ket{\psi} \bigr);$$ then computing the probability of obtaining either '0' or '1' is just a question of computing some inner products, and in particular will give interesting results when $$\ket{\psi}$$ and $$\ket{\phi}$$ are either orthogonal (in which case $$\ket{\alpha}$$ and $$\ket{\beta}$$ are both clearly maximally entangled, normalisation aside) or parallel (in which case $$\ket{\beta}$$ is clearly zero).

Let's start from the state $$|\Psi\rangle=\frac12\left(|0\rangle(|\psi\rangle|\phi\rangle+|\phi\rangle|\psi\rangle)+|1\rangle(|\psi\rangle|\phi\rangle-|\phi\rangle|\psi\rangle)\right).$$ There are a couple of ways to do the calculation. If you want to be formal, which typically leads to fewer mistakes, you identify the measurement operators on a single spin $$P_0=|0\rangle\langle 0|\otimes\mathbb{I}^{2n}\qquad P_1=|1\rangle\langle 1|\otimes\mathbb{I}^{2n}$$ and you evaluate the probabilities of the two outcomes as $$p_i=\langle\Psi|P_i|\Psi\rangle$$

Slightly less formally, but equivalent, you can collect the terms for $$|0\rangle$$ and $$|1\rangle$$, much as you have, but make sure the state on the other qubits is normalised. $$|\Psi\rangle=\frac12\left(\sqrt{2+2|\langle\psi|\phi\rangle|^2}|0\rangle\frac{|\psi\rangle|\phi\rangle+|\phi\rangle|\psi\rangle}{\sqrt{2+2|\langle\psi|\phi\rangle|^2}}+\sqrt{2-2|\langle\psi|\phi\rangle|^2}|1\rangle\frac{|\psi\rangle|\phi\rangle-|\phi\rangle|\psi\rangle}{\sqrt{2-2|\langle\psi|\phi\rangle|^2}}\right).$$ Then you can read of the probability amplitude for finding the state in $$|0\rangle$$ or $$|1\rangle$$, and take the mod-square to get the probability

A general way you can predict the measurement outcomes is to calculate the density matrix as:

$$\rho = |\Psi \rangle \langle \Psi|$$ and calculate the partial trace over qubits $$B$$ and $$C$$: $$\rho_A = \rm{Tr}_{B,C} \left(\rho \right)$$.

You then have a 2x2 density matrix where the two diagonals tell you the probabilities of getting $$|0\rangle$$ or $$|1\rangle$$ respectively.

• @NieldeBeaudrap: I deleted the old answer and kept only the density matrix part, which you said was correct: "Inasmuch as you are basically saying that it is possible to represent the state as a density matrix and then take the marginal on the first qubit, yeah." – user1271772 Oct 22 '18 at 18:50