Skip to main content

Advertisement

Log in

A novel quantum algorithm for converting between one-hot and binary encodings

  • Published:
Quantum Information Processing Aims and scope Submit manuscript

Abstract

In the domain of quantum computing, two widely employed techniques for encoding a normalized vector of length N, denoted as \(\{ \alpha _i \}\), are one-hot encoding and binary encoding. The one-hot encoding state is represented as \(\vert \psi _{OH}^{(N)} \rangle \) and can be expressed as: \(\vert \psi _{OH}^{(N)} \rangle =\sum _{i=0}^{N-1} \alpha _i \vert 0 \rangle ^{\otimes N-i-1} \vert 1 \rangle \vert 0 \rangle ^{\otimes i}\). On the other hand, the binary encoding state is symbolized as \(\vert \psi _{BI}^{(N)} \rangle \) and is defined as: \(\vert \psi _{BI}^{(N)} \rangle =\sum _{i=0}^{N-1} \alpha _i \vert b_i \rangle \), where \(b_i\) corresponds to the binary representation of i. In this paper, we introduce a method for converting between the one-hot encoding state and the binary encoding state, utilizing the Domain Wall state as an intermediary. The Domain Wall state, denoted as \(\vert \psi _{DW}^{(N)} \rangle \), is defined as: \(\vert \psi _{DW}^{(N)} \rangle =\sum _{i=0}^{N-1} \alpha _i \vert 0 \rangle ^{\otimes N-i-1} \vert 1 \rangle ^{\otimes i}\). Our proposed circuit achieves a depth of \(O(\log ^2 N)\) and a size of O(N).Kindly check and confirm that the corresponding author mail id is correctly identified.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Subscribe and save

Springer+ Basic
$34.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7
Fig. 8
Fig. 9
Fig. 10
Fig. 11

Similar content being viewed by others

Explore related subjects

Discover the latest articles, news and stories from top researchers in related subjects.

Data availability

Data sharing is not applicable to this article as no datasets were generated or analyzed during the current study.

Notes

  1. All circuit depths in this paper are defined as the length of the longest path within the circuit, while circuit sizes denote the total count of gates after decomposing the circuit into CNOT gates and U3 gates.

  2. Here, “odd” refers to the qubit number rather than the index i.

  3. If \(N \ne 2^{2k}\) for some integer k, more ancillas would be needed.

  4. A extra ancillary qubits should added to \(U_O^{(N+1)}\) if the one-hot encoding state is required.

References

  1. Grover, L., Rudolph, T.: Creating superpositions that correspond to efficiently integrable probability distributions. arXiv:quant-ph/0208112. Accessed 31 Dec 2021

  2. Möttönen, M., Vartiainen, J.J., Bergholm, V., Salomaa, M.M.: Transformation of quantum states using uniformly controlled rotations. 5(6), 467–473 (2004). https://doi.org/10.26421/QIC5.6-5

  3. Iten, R., Colbeck, R., Kukuljan, I., Home, J., Christandl, M.: Quantum circuits for isometries. Phys. Rev. A 93(3), 032318 (2016). https://doi.org/10.1103/PhysRevA.93.032318. Accessed 31 Dec 2021

  4. Plesch, M., Brukner, icv: Quantum-state preparation with universal gate decompositions. Phys. Rev. A 83, 032302 (2011). https://doi.org/10.1103/PhysRevA.83.032302

    Article  ADS  Google Scholar 

  5. Mottonen, M., Vartiainen, J.J.: Decompositions of general quantum gates. arXiv:quant-ph/0504100 (2005)

  6. Harrow, A.W., Hassidim, A., Lloyd, S.: Quantum algorithm for linear systems of equations. Phys. Rev. Lett. 103(15), 150502 (2009). https://doi.org/10.1103/PhysRevLett.103.150502. Accessed 31 Dec 2021

  7. Cong, I., Duan, L.: Quantum discriminant analysis for dimensionality reduction and classification. New J, Phys. 18(7), 073011 (2016). https://doi.org/10.1088/1367-2630/18/7/073011. Accessed 31 Dec 2021

  8. Kerenidis, I., Luongo, A.: Classification of the mnist data set with quantum slow feature analysis. Phys. Rev. A 101, 062327 (2020). https://doi.org/10.1103/PhysRevA.101.062327

    Article  ADS  Google Scholar 

  9. Zhao, Z., Fitzsimons, J.K., Rebentrost, P., Dunjko, V., Fitzsimons, J.F.: Smooth input preparation for quantum and quantum-inspired machine learning. Quantum Mach. Intell. 3(1), 1–6 (2021)

    Article  Google Scholar 

  10. Sun, X., Tian, G., Yang, S., Yuan, P., Zhang, S.: Asymptotically optimal circuit depth for quantum state preparation and general unitary synthesis. Confer. Name: IEEE Trans. Comput.-Aided Des. Integr. Circuits Syst. (2023). https://doi.org/10.1109/TCAD.2023.3244885

    Article  Google Scholar 

  11. Johri, S., Debnath, S., Mocherla, A., Singk, A., Prakash, A., Kim, J., Kerenidis, I.: Nearest centroid classification on a trapped ion quantum computer. NPJ Quantum Inf. 7(1), 1–11 (2021)

    Article  Google Scholar 

  12. Kitaev, A.Y.: Quantum measurements and the Abelian Stabilizer Problem. arXiv:quant-ph/9511026 (1995). Accessed 25 Sept 2023

  13. Farhi, E., Goldstone, J., Gutmann, S.: A quantum approximate optimization algorithm arxiv:1411.4028. Accessed 31 Dec 2021

  14. Hadfield, S., Wang, Z., O’Gorman, B., Rieffel, E.G., Venturelli, D., Biswas, R.: From the quantum approximate optimization algorithm to a quantum alternating operator ansatz. Algorithms 12(2), 34 (2019). https://doi.org/10.3390/a12020034. arxiv:1709.03489. Accessed 31 Dec 2021

  15. Finnila, A.B., Gomez, M.A., Sebenik, C., Stenson, C., Doll, J.D.: Quantum annealing: a new method for minimizing multidimensional functions. Chem. Phys. Lett. 219(5), 343–348 (1994). https://doi.org/10.1016/0009-2614(94)00117-0

    Article  ADS  Google Scholar 

  16. Johnson, M.W., Amin, M.H.S., Gildert, S., Lanting, T., Hamze, F., Dickson, N., Harris, R., Berkley, A.J., Johansson, J., Bunyk, P., Chapple, E.M., Enderud, C., Hilton, J.P., Karimi, K., Ladizinsky, E., Ladizinsky, N., Oh, T., Perminov, I., Rich, C., Thom, M.C., Tolkacheva, E., Truncik, C.J.S., Uchaikin, S., Wang, J., Wilson, B., Rose, G.: Quantum annealing with manufactured spins. Nature 473(7346), 194–198 (2011). https://doi.org/10.1038/nature10012. Number: 7346 Publisher: Nature Publishing Group. Accessed 06 Dec 2022

  17. Shukla, A., Vedula, P.: An efficient quantum algorithm for preparation of uniform quantum superposition states. arXiv:2306.11747 [quant-ph] (2023). Accessed 2023-09-15

  18. Cruz, D., Fournier, R., Gremion, F., Jeannerot, A., Komagata, K., Tosic, T., Thiesbrummel, J., Chan, C.L., Macris, N., Dupertuis, M., Javerzac-Galy, C.: Efficient quantum algorithms for GHZ and \$w\$ states, and implementation on the IBM quantum computer. Adv. Quantum Technol. 2(5), 1900015 (2019). https://doi.org/10.1002/qute.201900015. Accessed 09 Jan 2022

  19. Sawaya, N.P.D., Menke, T., Kyaw, T.H., Johri, S., Aspuru-Guzik, A., Guerreschi, G.G.: Resource-efficient digital quantum simulation of d-level systems for photonic, vibrational, and spin-s hamiltonians. NPJ Quantum Inf. 6(1), 49. https://doi.org/10.1038/s41534-020-0278-0. Accessed 08 Dec 2022

  20. Poulin, D., Kitaev, A., Steiger, D.S., Hastings, M.B., Troyer, M.: Quantum algorithm for spectral measurement with a lower gate count. Phys. Rev. Lett. 121, 010501 (2018). https://doi.org/10.1103/PhysRevLett.121.010501

    Article  ADS  Google Scholar 

  21. Klimo, M., Lukáč, P., Tarábek, P.: Deep neural networks classification via binary error-detecting output codes. Appl. Sci. 11(8), 3563. https://doi.org/10.3390/app11083563. Accessed 11 Dec 2022

  22. Khan, M., Faye, J.P.L., Mendes, U.C., Miranskyy, A.: EP-PQM: Efficient parametric probabilistic quantum memory with fewer qubits and gates. IEEE Trans. Quantum Eng. 3, 1–15. https://doi.org/10.1109/TQE.2022.3169987. Conference Name: IEEE Transactions on Quantum Engineering

  23. Plesch, M., Bužek, V.: Efficient compression of quantum information. Phys. Rev. A 81(3), 032317 (2010). https://doi.org/10.1103/PhysRevA.81.032317. Publisher: American Physical Society. Accessed 20 Sept 2023

  24. Bärtschi, A., Eidenbenz, S.J.: Deterministic preparation of Dicke states. In: Gasieniec, L.A., Jansson, J., Levcopoulos, C. (eds.) Fundamentals of Computation Theory—22nd International Symposium, FCT 2019, Copenhagen, Denmark, August 12–14, 2019, Proceedings. Lecture Notes in Computer Science, vol. 11651, pp. 126–139. Springer. https://doi.org/10.1007/978-3-030-25027-0_9. Accessed 31 Dec 2021

  25. Rebentrost, P., Gupt, B., Bromley, T.R.: Quantum computational finance: Monte Carlo pricing of financial derivatives. Phys. Rev. A 98(2), 022321 (2018). https://doi.org/10.1103/PhysRevA.98.022321. Accessed 14 Dec 2021

  26. Woerner, S., Egger, D.J.: Quantum risk analysis. NPJ Quantum Inf. 5(1), 15 (2019). https://doi.org/10.1038/s41534-019-0130-6. Accessed 31 Dec 2021

  27. Chancellor, N.: Domain wall encoding of discrete variables for quantum annealing and QAOA, Quantum Sci. Technol. 4(4), 045004 (2019). arxiv:1903.05068 [quant-ph]. https://doi.org/10.1088/2058-9565/ab33c2. Accessed 08 Dec 2022

  28. Draper, T.G., Kutin, S.A., Rains, E.M., Svore, K.M.: A logarithmic-depth quantum carry-lookahead adder. 6(4), 351–369 (2004). https://doi.org/10.26421/QIC6.4-5-4. Accessed 07 Jan 2022

  29. Saeedi, M., Pedram, M.: Linear-depth quantum circuits for \(n\)-qubit Toffoli gates with no ancilla. Phys. Rev. A 87(6), 062318 (2013). https://doi.org/10.1103/PhysRevA.87.062318. Accessed 06 Jan 2022

  30. Rattew, A.G., Sun, Y., Minssen, P., Pistoia, M.: The efficient preparation of normal distributions in quantum registers. Quantum 5, 609 (2021). https://doi.org/10.22331/q-2021-12-23-609. Accessed 27 Dec 2021

Download references

Funding

This work is sponsored by CCB Fintech Company Limited (No. PO3522083587, HP2300480) and by Chengdu Science and Technology Bureau (No. 2021-YF09-00114-GX).

Author information

Authors and Affiliations

Authors

Contributions

All authors contributed to the study conception and design. The first draft of the manuscript was written by Bingren Chen, and all authors commented on previous versions of the manuscript. All authors read and approved the final manuscript.

Corresponding author

Correspondence to Bingren Chen.

Ethics declarations

Conflict of interest

The authors have no relevant financial or non-financial interests to disclose.

Ethical approval

This study does not include human or animal subjects.

Additional information

Publisher's Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Appendices

The procedure in \(U_O^{(4)}\) and \(U_O^{(5)}\)

Here, we give the transformation of the quantum state in \(U_O^{(4)}\) and \(U_O^{(5)}\).

\(U_O^{(4)}\):

$$\begin{aligned} \vert 000\rangle \xrightarrow {\otimes \vert 1\rangle } \vert 0001\rangle \xrightarrow {CNOT \text { 1 to 2, 3 to 4}} \vert 0001\rangle \xrightarrow {U_O^{(2)} \text { 1 to 3}} \vert 0001\rangle \xrightarrow {CNOT \text { 2 to 3}} \vert 0001\rangle \\ \vert 001\rangle \xrightarrow {\otimes \vert 1\rangle } \vert 0011\rangle \xrightarrow {CNOT \text { 1 to 2, 3 to 4}} \vert 0010\rangle \xrightarrow {U_O^{(2)} \text { 1 to 3}}\vert 0010\rangle \xrightarrow {CNOT \text { 2 to 3}} \vert 0010\rangle \\ \vert 011\rangle \xrightarrow {\otimes \vert 1\rangle } \vert 0111\rangle \xrightarrow {CNOT \text { 1 to 2, 3 to 4}} \vert 0110\rangle \xrightarrow {U_O^{(2)} \text { 1 to 3}}\vert 0110\rangle \xrightarrow {CNOT \text { 2 to 3}} \vert 0100\rangle \\ \vert 111\rangle \xrightarrow {\otimes \vert 1\rangle } \vert 1111\rangle \xrightarrow {CNOT \text { 1 to 2, 3 to 4}} \vert 1010\rangle \xrightarrow {U_O^{(2)} \text { 1 to 3}}\vert 1000\rangle \xrightarrow {CNOT \text { 2 to 3}} \vert 1000 \rangle .\\ \end{aligned}$$

As for \(U_O^{(5)}\), first tensor \(\vert 1\rangle \) with the quantum state.

$$\begin{aligned} \vert 0000\rangle \xrightarrow {\otimes \vert 1\rangle } \vert 00001\rangle \xrightarrow {U_O^{(4)}} \vert 00001\rangle \xrightarrow {CNOT \text { 1 TO 2}} \vert 00001\rangle \\ \vert 0001\rangle \xrightarrow {\otimes \vert 1\rangle } \vert 00011\rangle \xrightarrow {U_O^{(4)}} \vert 00010\rangle \xrightarrow {CNOT \text { 1 TO 2}} \vert 00010\rangle \\ \vert 0011\rangle \xrightarrow {\otimes \vert 1\rangle } \vert 00111\rangle \xrightarrow {U_O^{(4)}} \vert 00100\rangle \xrightarrow {CNOT \text { 1 TO 2}} \vert 00100\rangle \\ \vert 0111\rangle \xrightarrow {\otimes \vert 1\rangle } \vert 01111\rangle \xrightarrow {U_O^{(4)}} \vert 01000\rangle \xrightarrow {CNOT \text { 1 TO 2}} \vert 01000\rangle \\ \vert 1111\rangle \xrightarrow {\otimes \vert 1\rangle } \vert 11111\rangle \xrightarrow {U_O^{(4)}} \vert 11000\rangle \xrightarrow {CNOT \text { 1 TO 2}} \vert 10000\rangle .\\ \end{aligned}$$

The procedure of \(U_B^{(7)}\)

Here, we give the transformation of the quantum state in \(U_B^{(7)}\)

\(U_B^{(7)}\):

$$\begin{aligned} \vert 000000\rangle \xrightarrow {U_B^{(4)} \otimes U_B^{(4)}} \vert 000000\rangle \xrightarrow {adder-plus-1} \vert 000001\rangle \xrightarrow {adder} \vert 001001\rangle \\ \xrightarrow {Toffoli} \vert 001001\rangle \xrightarrow {CNOT} \vert 000001\rangle \xrightarrow {adder-minus-1} \vert 000000\rangle \\ \vert 000001\rangle \xrightarrow {U_B^{(4)} \otimes U_B^{(4)}} \vert 000001\rangle \xrightarrow {adder-plus-1} \vert 000010\rangle \xrightarrow {adder} \vert 010010\rangle \\ \xrightarrow {Toffoli} \vert 010010\rangle \xrightarrow {CNOT} \vert 000010\rangle \xrightarrow {adder-minus-1} \vert 000001\rangle \\ \vert 000011\rangle \xrightarrow {U_B^{(4)} \otimes U_B^{(4)}} \vert 000010\rangle \xrightarrow {adder-plus-1} \vert 000011\rangle \xrightarrow {adder} \vert 011011\rangle \\ \xrightarrow {Toffoli} \vert 011011\rangle \xrightarrow {CNOT} \vert 000011\rangle \xrightarrow {adder-minus-1} \vert 000010\rangle \\ \vert 000111\rangle \xrightarrow {U_B^{(4)} \otimes U_B^{(4)}} \vert 000011\rangle \xrightarrow {adder-plus-1} \vert 000100\rangle \xrightarrow {adder} \vert 100100\rangle \\ \xrightarrow {Toffoli} \vert 100100\rangle \xrightarrow {CNOT} \vert 000100\rangle \xrightarrow {adder-minus-1} \vert 000011\rangle \\ \vert 001111\rangle \xrightarrow {U_B^{(4)} \otimes U_B^{(4)}} \vert 001011\rangle \xrightarrow {adder-plus-1} \vert 001100\rangle \xrightarrow {adder} \vert 101100\rangle \\ \xrightarrow {Toffoli} \vert 101101\rangle \xrightarrow {CNOT} \vert 000101\rangle \xrightarrow {adder-minus-1} \vert 000100\rangle \\ \vert 011111\rangle \xrightarrow {U_B^{(4)} \otimes U_B^{(4)}} \vert 010011\rangle \xrightarrow {adder-plus-1} \vert 010100\rangle \xrightarrow {adder} \vert 110100\rangle \\ \xrightarrow {Toffoli} \vert 110110\rangle \xrightarrow {CNOT} \vert 000110\rangle \xrightarrow {adder-minus-1} \vert 000101\rangle \\ \vert 111111\rangle \xrightarrow {U_B^{(4)} \otimes U_B^{(4)}} \vert 011011\rangle \xrightarrow {adder-plus-1} \vert 011100\rangle \xrightarrow {adder} \vert 111100\rangle \\ \xrightarrow {Toffoli} \vert 111111\rangle \xrightarrow {CNOT} \vert 000111\rangle \xrightarrow {adder-minus-1} \vert 000110\rangle \\ \end{aligned}$$

The adder-plus-d gate

We can leverage the Fourier gate to construct the adder-plus-d gate, as depicted in Fig. 12.

Fig. 12
figure 12

The Fourier adder-plus-d Gate

An adder-plus-d gate, comprised of n qubits (where \(n=\lceil \log _2 \frac{N}{2} \rceil +1\) in our approach), is assembled using a sequence involving a quantum Fourier transformation (QFT) gate, n phase gates, and an inverse quantum Fourier transformation (IQFT) gate. When initiated with the state \(\vert b_j \rangle \), it evolves as follows:

$$\begin{aligned} \frac{1}{2^{n/2}} \mathop {\otimes } \limits _{k=0}^{n-1}(\vert 0 \rangle +e^{2\pi ij \frac{2^k}{2^n}}\vert 1 \rangle ) \end{aligned}$$
(C1)

after undergoing the QFT gate. Subsequently, the collective effect of phase gates \(\mathop \otimes _{k=0}^{n-1} U(2d\pi \frac{2^k}{2^n})\), where \(U(\lambda )\) is defined as

$$\begin{aligned} U(\lambda )= \begin{bmatrix} 1 &{}0 \\ 0 &{}e^{i\lambda } \end{bmatrix}, \end{aligned}$$

transforms the state into:

$$\begin{aligned} \frac{1}{2^{n/2}} \mathop {\otimes } \limits _{k=0}^{n-1}(\vert 0 \rangle +e^{2\pi i(j+d) \frac{2^k}{2^n}}\vert 1 \rangle ), \end{aligned}$$
(C2)

Ultimately, after the application of the IQFT gate, the state transitions to \(\vert b_{j+d} \rangle \).

The Fourier adder-plus-d gate exhibits a computational depth of O(n) and a size of \(O(n \log n)\). For those seeking reduced complexity, the quantum carry lookahead adder (QCLA) method [28] offers a viable alternative. By introducing approximately O(n) ancillary qubits, QCLA can implement the adder with a computational depth of \(O(\log n)\) and a size of O(n).

The recursion converter

In this section, we introduce the recursion converter as presented by Plesch et al. [23]. While Plesch et al. demonstrated that the circuit initially possesses a depth of \(O(N\log ^2 N)\) and a size of \(O(N\log ^2 N)\), it is noteworthy that the circuit depth can be optimized to \(O(N\log N)\) following a scheme proposed by Saeedi et al. This optimization stems from the decomposition of n-qubit Toffoli gates in linear depth.

In Plesch’s framework, the converter is initially designed to facilitate conversion between the one-hot encoding state and the binary encoding state. With a slight modification, the same circuit can be adapted to convert between the Domain Wall state and the binary state. A visual representation of the \(N=6\) qubit converter is presented in Fig. 13.

Fig. 13
figure 13

The converter with binary calculation

Assuming we have already prepared an \(N-2\) qubit converter, denoted as \(U_B^{(N-1)}\), and initialized the state \(\vert \psi _{DW}^{(N)} \rangle \), applying \(U_B^{(N-1)}\) to the last \(N-2\) qubits yields the quantum state:

$$\begin{aligned} \alpha _{N-1} \vert 1\rangle \vert 0\rangle ^{\otimes N-1-\lceil \log _2 N \rceil } \vert b_{N-2}\rangle + \vert 0\rangle \sum _{i=0}^{N-2} \alpha _{i} \vert 0\rangle ^{\otimes N-1-\lceil \log _2 N \rceil } \vert b_i\rangle . \end{aligned}$$
(D3)

Next, a bitwise XOR operation, denoted as \(c=c_1 \ldots c_{\lceil \log _2 N \rceil }=b_{N-1} \oplus b_{N-2}\), is computed. For all i satisfying \(c_i=1\), CNOT gates are applied between the first qubit and the \(N-\lceil \log _2 N \rceil +i\) th qubit. Subsequently, a multiple-qubit Toffoli gate is employed to flip the first qubit if the last \(\lceil \log _2 N \rceil \) qubits are in the state \(\vert b_{N-1}\rangle \). As a result, the final state is transformed into the binary state. Notably, in the original scheme by Plesch et al. [23], c can be replaced with \( b_{N-1}\) to prepare \(\vert \psi _{BI}^{(N-1)}\rangle \) from \(\vert \psi _{OH}^{(N-1)}\rangle \).

Generation of the binomial distribution state

As Fig. 6 shows, we first implement \(R_Y(\theta )^{\otimes N}\) on \(\vert 0\rangle ^{\otimes N}\), where \(\theta =2\arcsin \sqrt{p}\) and \(R_Y(\theta )=\begin{bmatrix} \cos \frac{\theta }{2} &{} -\sin \frac{\theta }{2}\\ \sin \frac{\theta }{2} &{} \cos \frac{\theta }{2}\end{bmatrix}\) and we will obtain

$$\begin{aligned} R_Y(\theta )^{\otimes N}(\vert 0\rangle ^{\otimes N}) = \sum _{k=0}^N \sqrt{f(k,p)}\vert D_k^N \rangle , \end{aligned}$$
(E4)

where \(\vert D_k^{N} \rangle =\left( {\begin{array}{c}N\\ k\end{array}}\right) ^{-\frac{1}{2}} \sum _{x \in \{0,1\}^N, wt(x)=k} \vert x \rangle \) is the Dicke state. Second, we implement the inverse gate of \(U_{N,N-1}\) presented in [24] and the state becomes

$$\begin{aligned} U_{N,N-1} \vert 0 \rangle ^{\otimes N-k} \vert 1 \rangle ^{\otimes k} = \vert D_k^{N} \rangle \end{aligned}$$
(E5)

for each \(k \in \{0, 1, \ldots , N\}\), so \(U_{N,N-1}^{-1}\) satisfies that

$$\begin{aligned} U_{N,N-1}^{-1} \sum _{k=0}^N \sqrt{f(k,p)}\vert D_k^N \rangle = \sum _{i=0}^{N} \sqrt{f(i, p)} \vert 0 \rangle ^{\otimes N-i} \vert 1 \rangle ^{\otimes i}. \end{aligned}$$
(E6)

\(U_{N,N-1}\) can be decomposed to Split & Cyclic Shift gate (\(SCS_{n,k}\)) that is in the form of

$$\begin{aligned} U_{N, N-1}:=\prod _{\ell =2}^{N-1} (S C S_{\ell , \ell -1} \otimes I^{\otimes N-\ell } ) \cdot (I^{\otimes N-k-1} \otimes S C S_{N, N-1} ), \end{aligned}$$
(E7)

where \(SCS_{n,k}\) satisfies that

$$\begin{aligned}&S C S_{n, k} \vert 0\rangle ^{\otimes k+1} =\vert 0\rangle ^{\otimes k+1}, \nonumber \\&S C S_{n, k}\vert 0\rangle ^{\otimes k+1-\ell }\vert 1\rangle ^{\otimes \ell } =\sqrt{\frac{\ell }{n}}\vert 0\rangle ^{\otimes k+1-\ell }\vert 1\rangle ^{\otimes \ell }+\sqrt{\frac{n-\ell }{n}}\vert 0\rangle ^{\otimes k-\ell }\vert 1\rangle ^{\otimes \ell }\vert 0\rangle , \nonumber \\&S C S_{n, k}\vert 1\rangle ^{\otimes k+1} =\vert 1\rangle ^{\otimes k+1} . \end{aligned}$$
(E8)

As proved in [24], \(SCS_{n,k}\) can be decomposed to 1 two-qubit gates and \(k-1\) three-qubit gates shown as in Figs. 14 and 15.

Fig. 14
figure 14

Two-qubit gates \(SCS_2\)

Fig. 15
figure 15

Three-qubit gates \(SCS_3\)

Finally, we apply \(U_B^{(N+1)}\) or \(U_O^{(N+1)}\) to transform the Domain Wall state to the one-hot encoding state or the binary encoding state,Footnote 4 which is denoted as

$$\begin{aligned}{} & {} U_O^{(N+1)} \left( \sum _{i=0}^{N} \sqrt{f(i, p)} \vert 0 \rangle ^{\otimes N-i} \vert 1 \rangle ^{\otimes i} \otimes \vert 1 \rangle \right) =\sum _{i=0}^{N} \sqrt{f(i, p)} \vert 0 \rangle ^{\otimes N-i} \vert 1\rangle \vert 0\rangle ^{\otimes i}\end{aligned}$$
(E9)
$$\begin{aligned}{} & {} U_B^{(N+1)} \left( \sum _{i=0}^{N} \sqrt{f(i, p)} \vert 0 \rangle ^{\otimes N-i} \vert 1 \rangle ^{\otimes i}\right) =\sum _{i=0}^{N} \sqrt{f(i, p)} \vert 0\rangle ^{\otimes N-\lceil \log _2 N \rceil } \vert b_i \rangle . \end{aligned}$$
(E10)

Proof in Sect. 2.4

1.1 F.1 The solution of Eq. (17)

We utilize the binary representation \(b_N=c_n c_{n-1}\cdots c_1\) to denote the number N. Referring to Eq. (17), we can express this as follows:

$$\begin{aligned} d_o(c_n c_{n-1}\cdots c_1)&=d_o(c_n c_{n-1}\cdots c_{2} 0)\\&=d_o(c_n c_{n-1}\cdots c_{2})+2\\&=d_o(c_n c_{n-1}\cdots c_{3})+2*2\\&=d_o(c_n c_{n-1})+2(n-2)\\&=2n-1=O(\log n) \end{aligned}$$

1.2 F.2 The solution of Eq. (18)

We utilize the binary representation \(b_N=c_n c_{n-1}\cdots c_1\) to denote the number N. Referring to Eq. (18), we can express this as follows:

$$\begin{aligned} s_o(c_n c_{n-1}\cdots c_1)&=s_o(c_n c_{n-1}\cdots c_{2} 0)+c_1\\&=s_o(c_n c_{n-1}\cdots c_{2})+N-1\\&=s_o(c_n c_{n-1}\cdots c_{3})+N+\lfloor \frac{N}{2} \rfloor -2\\&=s_o(c_n c_{n-1})+\sum _{i=0}^{n-3} \lfloor \frac{N}{2^i} \rfloor -n+2\\&=c_{n-1}+\sum _{i=0}^{n-3} \lfloor \frac{N}{2^i} \rfloor -n+3 = O(N) \end{aligned}$$

1.3 F.3 The solution of Eq. (19)

When \(2^{m-1}+1 <N \le 2^m+1\) and \(O(\log N)=O(m)\), in expanding-to-\(2^k\), we have

$$\begin{aligned} d_b(N)&=d_b(2^m+1)=d_b(2^{m-1}+1)+O(m)\\ {}&=d_b(2^{m-2}+1)+O(m)+O(m-1)\\&=\sum _{i=1}^m O(i)\\&=O(m^2) = O(\log ^2 N) \end{aligned}$$
$$\begin{aligned} s_b(N)&= s_b(2^m+1)=2s_b(2^{m-1}+1)+O(m)\\ {}&=4s_b(2^{m-2}+1)+O(m)+2O(m-1)\\&=\sum _{i=0}^{m-1} 2^i O(m-i)\\&=O(2^m)=O(N) \end{aligned}$$

1.4 F.4 The solution of Eq. (20)

Let’s note that \(M=N-1\), and \(d(x)=d_b(x+1)\). We represent M in binary as \(b_M=c_n c_{n-1}\cdots c_1\). Therefore, we have the following relationships:

$$\begin{aligned} d(M)&=d\left( \frac{M}{2}\right) +O(n), \text {if }M\text { is even.}\\ d(M)&=d_b(M+1), \text {if }M\text { is odd.} \end{aligned}$$

Hence,

$$\begin{aligned} d_b(N)&=d(c_n c_{n-1}\cdots c_1)\\&=d(c_n c_{n-1}\cdots c_{2} + c_1)+O(n)\\&=d(c_n c_{n-1}\cdots c_{3} + c_{2} \vee c_1)+O(n)+O(n-1)\\&=d(c_n c_{n-1}+c_{n-2}\vee \cdots \vee c_1)+\sum _{i=0}^{n-3} O(n-i) = O(\log ^2 N) \end{aligned}$$

1.5 F.5 The solution of Eq. (21)

Let us note that \(M=N-1\), and \(s(x)=s_b(x+1)\). We represent M in binary as \(b_M=c_n c_{n-1}\cdots c_1\). Therefore, we have the following relationships:

$$\begin{aligned} s(M)&=2s\left( \frac{M}{2}\right) +O(n^2), \text {if }M\text { is even.}\\ s(M)&=s_b(M+1), \text {if }M\text { is odd.} \end{aligned}$$

Hence,

$$\begin{aligned} s_b(N)&=s(c_n c_{n-1}\cdots c_1)\\&=2^1s(c_n c_{n-1}\cdots c_{2} + c_1)+O(n^2)\\&=2^2s(c_n c_{n-1}\cdots c_{3} + c_2 \vee c_1)+O(n^2)+2O((n-1)^2)\\&=2^{n-2}s(c_n c_{n-1}+c_{n-2}\vee \cdots \vee c_1)+\sum _{i=0}^{n-3} 2^i O((n-i)^2)\\&=O(2^n)+2^n\sum _{k=3}^{n}2^{-k}O(k^2)=O(2^n)-O(n^2)=O(N) \end{aligned}$$

1.6 F.6 The solution of Eq. (22)

Let us note that \(M=N-1\), and \(d(x)=d_b(x+1)\). We represent M in binary as \(b_M=c_n c_{n-1}\cdots c_1\). Therefore, we have the following relationships:

$$\begin{aligned} d(M)&=d\left( \frac{M}{2}\right) +O(n), \text {if }M\text { is even.}\\ d(M)&=d_b(M-1)+O(n), \text {if }M\text { is odd.} \end{aligned}$$

Hence,

$$\begin{aligned} d_b(N)&=d(c_n c_{n-1}\cdots c_1)\\&=d(c_n c_{n-1}\cdots c_{2} 0)+c_1 O(n)\\&=d(c_n c_{n-1}\cdots c_{2})+(c_1+1) O(n)\\&=d(c_n c_{n-1}\cdots c_{3})+(c_1+1) O(n)+(c_2+1) O(n-1)\\&=d(c_n c_{n-1})+\sum _{i=1}^{n-2}(c_i+1) O(n-i+1) \\&<2 O(n^2)=O(\log ^2 N)\\ \end{aligned}$$

1.7 F.7 The solution of Eq. (23)

Let us note that \(M=N-1\), and we denote \(s(x)=s_b(x+1)\). We represent M in binary as \(b_M=c_n c_{n-1}\cdots c_1\). Therefore, we have the following relationships:

$$\begin{aligned} s(M)&=2s\left( \frac{M}{2}\right) +O(n^2), \text {if }M\text { is even.}\\ s(M)&=s_b(M-1)+O(n^2), \text {if }M\text { is odd.} \end{aligned}$$

Hence,

$$\begin{aligned} s_b(N)&=s(c_n c_{n-1}\cdots c_1)\\&=s(c_n c_{n-1}\cdots c_{2} 0)+c_1 O(n^2)\\&=2s(c_n c_{n-1}\cdots c_{2})+(c_1+1) O(n^2)\\&=2^2s(c_n c_{n-1}\cdots c_{3})+(c_1+1) O(n^2)+2(c_2+1)O((n-1)^2)\\&=2^{n-2}s(c_n c_{n-1})+\frac{1}{2}\sum _{i=1}^{n-2}2^i(c_i+1) O((n-i+1)^2) \\&<O(2^n)+\sum _{i=1}^{n-2}2^iO((n-i)^2)=O(2^n) +2^n\sum _{k=2}^{n-1}2^{-k}O(k^2)\\&=O(2^n)-O(n^2)=O(N) \end{aligned}$$

Rights and permissions

Springer Nature or its licensor (e.g. a society or other partner) holds exclusive rights to this article under a publishing agreement with the author(s) or other rightsholder(s); author self-archiving of the accepted manuscript version of this article is solely governed by the terms of such publishing agreement and applicable law.

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Chen, B., Wu, H., Yuan, H. et al. A novel quantum algorithm for converting between one-hot and binary encodings. Quantum Inf Process 23, 203 (2024). https://doi.org/10.1007/s11128-024-04403-z

Download citation

  • Received:

  • Accepted:

  • Published:

  • DOI: https://doi.org/10.1007/s11128-024-04403-z

Keywords