# Amplitude encoding: distinction between negative and positive real values

I want to encode two vectors into qubits and compute a distance between them that corresponds/is proportional to the euclidian distance of the real vectors.

The encoding I use is

• A) qiskit initialize method
def get_encoding_circuit(*vv):

sz = int(np.log2(len(vv[0])))

qc = QuantumCircuit(len(vv)*sz)

for i, v in enumerate(vv):
qc.initialize(v, range(i*sz, (i+1)*sz))

return qc


and

• B) amplitude encoding as shown here

The distance metric I use is given by the overlap from

• I) qiskit's state_fidelity method and
• II) a Swap Test circuit.

For example in $$\mathbb{R^2}$$, $$u$$ and $$v$$ given as

$$u = \begin{bmatrix} 1 \\ 1 \end{bmatrix} \quad v = \begin{bmatrix} -1 \\ -1 \end{bmatrix}$$

are encoded as

$$|u\rangle = \begin{bmatrix} 0.70711 \\ 0.70711 \end{bmatrix} \quad |v\rangle = \begin{bmatrix} - 0.70711 \\ - 0.70711 \end{bmatrix}$$

The problem I have (with any combination of A), B) I), II)) is that $$|u\rangle$$ and $$|v\rangle$$ have an overlap of 1, so are equivalent. The reason is that the encoding of $$v$$ is equal to the encoding of $$u$$, just with a global phase added,

s.t. the fidelity (as computed by qiskit) for example is

$$| \langle u|v\rangle |^2 = 1.0$$

but $$\text{dist_eucl}(u,v)$$ is far from 0.

What encoding can I use that will produce distinct qubits for positive and negative real inputs?

Edit/Followup:

I finally used the statepreparation described here For real vectors in the range $$[-1,1]$$ I obtain quantum distances corresponding to euclidian distances:

• The behaviour of Qubits is best described with vectors; but those vectors are probability amplitudes that describe a data register; they do not correspond to Euclidean Distance in any clear way; even when thinking about Qubits using a Bloch Sphere. How would your algorithm work calculate the distance between (1,0) and (5,0)? Commented Sep 22, 2021 at 19:34
• Undoubtedly this task can be done using a Quantum Computer...however this simplification of trying to encode a real vector as a single qubit likely will not lead anywhere. Commented Sep 22, 2021 at 19:34

As you've noticed, global phase is a problem here. One option that you could pursue (I'm not claiming it's a good option) is to use a two-qubit encoding. Let's say you want to encode a vector $$u\in\mathbb{C}^2$$ (you asked about real, which is obviously a simplifying case) $$u=\left[\begin{array}{c} ae^{i\theta_1} \\ be^{i\theta_2} \end{array}\right]$$ where $$a,b\geq 0$$. You could encode this as $$\frac{1}{\sqrt{a^2+b^2}}\left[\begin{array}{c} a \\ be^{i(\theta_2-\theta_1)} \end{array}\right]\otimes \left[\begin{array}{c} \cos2\theta_1 \\ \sin2\theta_1 \end{array}\right]$$