# What's an use case of the inner product between two q-bits in a quantum algorithm?

$$\newcommand{\q}{\langle #1 | #2 \rangle}$$ I know from linear algebra that the inner product of two vectors is 0 if the vectors are orthogonal. I also know the inner product is positive if the vectors more or less point in the same direction and I know it's negative if the vectors more or less point in opposite directions.

This is the same inner product as in $$\q{x}{y}$$, right? Can you show an example of the inner product being useful in a quantum algorithm? The simplest the better. It doesn't have to be a useful algorithm.

The absolute value of the inner product between two (pure) states $$\lvert\psi\rangle$$ and $$\lvert\phi\rangle$$, $$\lvert\langle\psi\rvert\phi\rangle\rvert$$, can be used to quantify the distance between the two states, and is commonly referred to as fidelity (though the fidelity is often defined as the square of $$\lvert\langle\psi\rvert\phi\rangle\rvert$$).

If the current state is $$\lvert\phi\rangle$$, and $$\lvert\psi\rangle$$ is a possible outcome of a measurement, then $$\lvert\langle\psi\rvert\phi\rangle\rvert^2$$ is the probability of getting the outcome $$\lvert\psi\rangle$$. More generally, $$\lvert\langle\psi\rvert\phi\rangle\rvert^2$$ can be thought of as a measure of indistinguishability of the two states. This quantity will thus be important every time one wants to figure out what is the current state of the system, as a high fidelity implies that a lot of measurements are necessary to tell the two states apart.

An example of a quantum algorithm computing this quantity is the C-SWAP test, which I think was introduced in (Buhrman et al. 2001). One usage of this algorithm that comes to mind is given in (LLoyd et al. 2013), where they use it as a subroutine for their supervised cluster assignment algorithm (see end of pag. 3).

More generally, the inner product between two states is their overlap, which is such a fundamental quantity in quantum mechanics that it is hard to say how it can not be "useful" for any kind of protocol.

There is also an algorithm denoted in this article denoted by DistCalc and it enables you to compute the Euclidian distance between two real vectors $$a$$ and $$b$$ based on the computation of the inner product between two quantum states created from $$a$$ and $$b$$.

Say your vectors $$a$$ and $$b$$ have a dimension $$N$$ which can be expressed as a power of 2 without loss of generalities, then you can compute this distance with a complexity of $$\mathcal{O}(\log N)$$.

• I think the algorithm you are referring to, that is mentioned in that review, is one of those that were first presented in arxiv.org/abs/1307.0411 – glS Oct 1 '18 at 15:19
• True. This is basically used in many algorithms with distance computation like k-means. – cnada Oct 1 '18 at 16:43

If you want to estimate the inner product of two quantum states, use three quantum registers. The first one stores one qubit, the other two registers contains n qubits where n is used to store the value of the two states separetely. Next apply hadamard gate to the first register. Then by using controll swap gate which accepts three inputs, pass the three registers through this gate (where the first register act as a controller). Finally apply a hadamard gate to the first register qubit again and measure the first register alone. If the measurment result is 0.5 being in the ground state i.e. the two states are orthogonal. Unless the more the probability of the ancilla qubit (the first register) being in zero tends to 1, the two states are simillar.