1

Let's say we have two vectors a and b, and they have the same size. Is there a quantum circuit to calculate the difference a-b?

To be clear, here's an example:

a = [1.2, 0.7] (the norm is not 1), and b = [1.0, 2.0]

Then, we have

a - b = [0.2, -1.3].

254po
  • 21
  • 4
  • 2
    A related idea. If you want to know the difference quantified by $|\langle \psi |\phi \rangle |^2$, then you can use swap test. – narip Jan 07 '23 at 01:25
  • 1
    Welcome to QCSE. @narip s suggestion is probably your best bet - you can get certain relationships between two different ket’s, but it’s not clear what’s meant by the difference of the vectors. For example, what if $|a\rangle=|b\rangle$? What would you expect your circuit to output? – Mark Spinelli Jan 07 '23 at 04:08
  • The problem is updated. I hope it's more precise. It's a fundamental computation, and I don't know whether quantum computing can overperform classical computers at this task. – 254po Jan 07 '23 at 04:33
  • 1
    There is a smart way to compute the Euclidean distance. Would this be helpful? – rhundt Jan 07 '23 at 15:38
  • 1
    there's no-go theorems about the impossibility of a unitary operation giving as output the superposition of different inputs. See https://quantumcomputing.stackexchange.com/q/11554/55, https://physics.stackexchange.com/q/543883/58382, https://physics.stackexchange.com/q/380268/58382 – glS Jan 07 '23 at 15:41
  • @rhundt, do you mean swap test circuit? Yes, I know that. The output is the square distance. Still, not a vector. – 254po Jan 07 '23 at 20:49
  • @ glS♦, thank you. – 254po Jan 07 '23 at 20:51

1 Answers1

5

Suppose you have two n-qubit vectors $|\psi\rangle = U_1|0\rangle^{\otimes n}$ and $|\phi\rangle = U_2|0\rangle^{\otimes n}$. Then you prepare the (n+1)-qubit 0 state, and apply $H$ to the first qubit:

$$1/\sqrt{2}(|0\rangle+|1\rangle)|0\rangle^{\otimes n}$$

Using the same qubit as the control, you apply $U_1$ if the qubit is in the $|0\rangle$ state, and $U_2$ if it's in the $|1\rangle$ state:

$$1/\sqrt{2} (|0\rangle|\psi\rangle+|1\rangle|\phi\rangle)$$

Then applying $H$ to the first qubit again results in:

$$|0\rangle\frac{|\psi\rangle+|\phi\rangle}{2} + |1\rangle\frac{|\psi\rangle-|\phi\rangle}{2}$$

Now you have the vector $\frac{|\psi\rangle-|\phi\rangle}{2}$ in the second half of the $2^{n+1}$ dimensional quantum state. Furthermore, measuring the first qubit to be in the $|1\rangle$ state will have probability:

$$\| \frac{|\psi\rangle-|\phi\rangle}{2}\|^2 = \frac{1}{4} \| |\psi\rangle-|\phi\rangle\|^2$$

Dani007
  • 532
  • 2
  • 9
  • 1
    Thanks for your comment! It seems like the output is a number. Is there some way to output a vector? For example, a = [1.2, 0.7] (the norm is not 1), and b = [1.0, 2.0]. Then, we have a - b = [0.2, -1.3]. – 254po Jan 07 '23 at 04:27
  • 3
    @254po: to get the vector, you have to measure all qubits. If the first one is in state $|1\rangle$, then rest of qubits represents the difference of the input vectors. Of course, the measurement has to be repeated many times to get probability distribution. The probabilities then have to be square rooted to get the amplitudes representing vector members. However, in this way you get only a absolute values of the members. To get signs or imaginary part, complete quantum tomography has to be employed to reconstruct the state. Note that the tomography is exponential complex in number of qubits. – Martin Vesely Jan 07 '23 at 08:02
  • 1
    @Martin Vesely, thanks for your comment. I think it helps me understand better. – 254po Jan 07 '23 at 20:48