How can I calculate the inner product of two quantum registers of different sizes?

I found an algorithm that can compute the distance of two quantum states. It is based on a subroutine known as swap test (a fidelity estimator or inner product of two state, btw I don't understand what fidelity mean).

My question is about inner product. How can I calculate the inner product of two quantum registers which contains different number of qubits?

The description of the algorithm is found in this paper. Based on the 3rd step that appear on the image, I want to prove it by giving an example.

Let: $|a| = 5$, $|b| = 5$, and $Z = 50$ $$|a\rangle = \frac{3}{5}|0\rangle + \frac{4}{5}|1\rangle$$ $$|b\rangle = \frac{4}{5}|0\rangle + \frac{3}{5}|1\rangle$$ All we want is the fidelity of the following two states $|\psi\rangle$ and $|\phi\rangle$ and to calculate the distance between $|a\rangle$ and $|b\rangle$is given as: ${|a-b|}^2 = 2Z|\langle\phi|\psi\rangle|^2$ so $$|\psi\rangle = \frac{3}{5\sqrt{2}}|00\rangle + \frac{4}{5\sqrt{2}}|01\rangle+ + \frac{4}{5\sqrt{2}}|10\rangle + + \frac{3}{5\sqrt{2}}|11\rangle$$ $$|\phi\rangle = \frac{5}{\sqrt{50}} (|0\rangle + |1\rangle)$$ then how to compute $$\langle\phi|\psi\rangle = ??$$

• In a few words, you can't. The inner product is defined for 2 vectors of the same space (i.e. 2 vectors of the same dimension) whereas your vectors (or quantum states) don't have the same size. – Nelimee Aug 7 '18 at 12:47

I guess you're looking at equations (130) and (131)? So, here, you have $|\psi\rangle=(|0\rangle|a\rangle+|1\rangle|b\rangle)/\sqrt{2}$ and $|\phi\rangle=|a| |0\rangle+|b| |1\rangle$. When it says to calculate $\langle\phi|\psi\rangle$, what it really means is $$(\langle\phi|\otimes\mathbb{I})|\psi\rangle,$$ padding everything with identity matrices to make them all the same size. Thus, the calculation becomes $$\frac{1}{\sqrt{2Z}}\left(\begin{array}{cccc} |a| & 0 & |b| & 0 \\ 0 & |a| & 0 & |b| \end{array}\right)\cdot\left(\begin{array}{c} a_0 \\ a_1 \\ b_0 \\ b_1 \end{array}\right),$$ where $a_0$ and $a_1$ are the elements of your vector $|a\rangle$. If you work this through, you'll get $$\frac{1}{\sqrt{2Z}}(|a| |a\rangle+|b| |b\rangle).$$ I have no idea where the negative sign has come from in equation (133).

• once again sir, what do you mean padding every thing? how can i interpret this in quantum circuit form ?? – Aman Aug 12 '18 at 11:10
• @Aman I mean that when two operators (or states, in this case) are defined for different sets of qubits, then way that you make them the same size is that you insert a tensor product with the 2x2 identity matrix for every qubit that is not in the given set. – DaftWullie Aug 13 '18 at 6:29
• @Aman: You can only swap qubit registers. What is happening is that you swap the first register with the first qubit of the second register. This leaves the question of what to do with the remaining qubit of the second register. You apply the identity operation to it, which explains where the identity above came from. – Peter Shor Mar 17 at 13:25

Actually, there should be a minus. There is a mistake in the paper. Wittek uses a minus in his (expensive) book.

Indeed say : $$|\psi\rangle = \frac{1}{\sqrt{2}} (|0,a\rangle + |1,b\rangle)$$ $$|\phi\rangle = \frac{1}{\sqrt{Z}} (|a||0\rangle - |b||1\rangle)$$

Then : $$\langle \phi |\psi\rangle = \frac{1}{\sqrt{2Z}} (|a|\langle 0| - |b|\langle 1|) (|0,a\rangle + |1,b\rangle)$$ $$= \frac{1}{\sqrt{2Z}}( |a|\langle 0|0\rangle|a\rangle - |b|\langle 1|0 \rangle|a\rangle + |a|\langle 0|1 \rangle|b\rangle - |b|\langle 1| 1 \rangle |b\rangle )$$

$$= \frac{1}{\sqrt{2Z}} (|a| |a\rangle - 0 + 0 - |b| |b\rangle) = \frac{1}{\sqrt{2Z}} (|a| |a\rangle - |b| |b\rangle)$$

Now for the part of the question where you ask how to swap quantum registers of different numbers of qubits, the answer is you don't really do that. You actually swap the ancilla qubit of $$|\psi\rangle$$ with $$|\phi\rangle$$. This is not told in the reference but it is said in the original reference it is based on.

• Thank you sir, but in |ψ⟩ do we have 3 qubits or 2 qubits ? – Aman Aug 10 '18 at 13:58
• You have the number of qubits necessary for a and b (say N) and you add another one so N+1. – cnada Aug 10 '18 at 14:13