Calculating Hamming Distance with the IBM Q Experience José Manuel Bravo [email protected] Prof

Calculating Hamming Distance with the IBM Q Experience José Manuel Bravo Pestecnologia@Gmail.Com Prof

Preprints (www.preprints.org) | NOT PEER-REVIEWED | Posted: 12 April 2018 doi:10.20944/preprints201804.0164.v1 Calculating Hamming distance with the IBM Q Experience José Manuel Bravo [email protected] Prof. Computer Science and Technology, High School, Málaga, Spain Abstract In this brief paper a quantum algorithm to calculate the Hamming distance of two binary strings of equal length (or messages in theory information) is presented. The algorithm calculates the Hamming weight of two binary strings in one query of an oracle. To calculate the hamming distance of these two strings we only have to calculate the Hamming weight of the xor operation of both strings. To test the algorithms the quantum computer prototype that IBM has given open access to on the cloud has been used to test the results. Keywords: quantum algorithm, Hamming weight, Hamming distance Introduction This quantum algorithms uses quantum parallelism as the fundamental feature to evaluate The advantage of the quantum computation a function implemented in a quantum oracle for to solve more efficiently than classical many different values of x at the same time computation some algorithms is one of the most because it exploits the ability of a quantum important key for scientists to continue researching computer to be in superposition of different states. and developing news quantum algorithms. Moreover it uses a property of quantum Grover´s searching quantum algorithm is able to mechanics known as interference. In a quantum select one entry between 2 with output 1 in only computer it is possible for the two alternatives to O(log(n)) queries to an oracle. Shor´s factoring interfere with one another to yield some global quantum algorithms is able to factorize one property of a function f, by using the Hadamard number faster than any classical algorithms gate to recombine the different alternatives. known. Deutch-Jozsa algorithm is able to The essence of the design of this algorithm is determinate if a function is constant or balanced the choice of a function and a final transformation using only one query to a quantum oracle. that allows efficient determination of the Hamming The Hamming weight of two binary strings weight of a message (information which cannot be (messages) of equal length is the number of attained quickly on a classical computer). symbols different of the zero-symbol used in the The quantum algorithm is based on the alphabet. It represents the number of 1´s in the Deutch-Jozsa algorithm [6]. A special function of string or the digit sum of the binary representation. two binary strings is implemented in an oracle and The Hamming weight is widely used in different we only one query to calculate the Hamming disciplines [1][2], including information theory, weight is needed. coding theory, and cryptography , and his efficient IBM releases in 2016 a 5-qubit universal implementation has been widely studied [3][4][5]. quantum computer prototype accessible on the The Hamming distance in information theory cloud. To test the algorithm, two experiments have between two strings is the minimum number of been simulated on the IBM Q Experience substitutions required to change one string into the composer. other. It is used in coding theory to define the error detecting and the error correcting codes. The The Deutsch-Jozsa algorithm running time of classical algorithms is proportional to the Hamming distance or to the number of bits The goal is to find an algorithm which tells if a in the inputs. Using this quantum algorithm it´s function f is constant or balanced with the least possible to calculate the Hamming distance in only possible number of evaluations of an oracle. one query to a quantum oracle. The algorithm is divided into the following The quantum algorithm calculates the steps: Hamming weight between to binary strings. To 1. Prepare an (n+1)-qubit register in the state ⨂ calculate the Hamming distance of these two |Ψ0⟩ = |0⟩ ⨂|1⟩. First n qubits work as inputs we have to calculate previously the xor input qubits of the function, while the (n+1)st operation between them and after that to calculate is an ancilla qubit to store temporary the Hamming weight (hw) of the result. Suppose information. we have to calculate the Hamming distance 2. Apply the Hadamard transformation to the between the binary string A and B (hd (A,B)): register. Then we have the state: A = 1001 B = 1100 1 1 First we calculate A ⊕ B = 0101 and then |Ψ1⟩ = |⟩ ⊗ (|0⟩ − |1⟩) 2 2 hw (A ⊕ B) = hd (A,B) = 2 √ √ © 2018 by the author(s). Distributed under a Creative Commons CC BY license. Preprints (www.preprints.org) | NOT PEER-REVIEWED | Posted: 12 April 2018 doi:10.20944/preprints201804.0164.v1 3. Perform a quantum transformation Bf, 1 0 0 0 0 0 0 0 associated to a function f defined by 0 0 0 0 1 0 0 0 ⎛ ⎞ f|⟩|⟩ = |⟩| ⊕ ()⟩ 0 0 0 0 0 1 0 0 ⎜0 1 0 0 0 0 0 0⎟ where f(x) is any function ⎜ ⎟ ⎜0 0 1 0 0 0 0 0⎟ : {0,1} → {0,1} ⎜0 0 0 0 0 0 1 0⎟ Then we obtain the following state. 0 0 0 1 0 0 0 0 ⎝0 0 0 0 0 0 0 1⎠ 1 () 1 |Ψ2⟩ = (−1) |⟩ ⊗ (|0⟩ − |1⟩) Then we apply the Bf one time and the 2 2 √ √ Hadamard transformations. After the n qubits are measured, we can observe: 4. Apply a Hadamard transformation on the first n qubit. ℎ() = 2 ∙ (1 − |0⟩) (1) ℎ() = 2 ∙ |2⟩ (2) 1 1 ⟩ ()∙ ⟩ ⟩ ⟩ |Ψ3 = (−1) | ⊗ (|0 − |1 ) ⟩ 2 √2 where |2 is the probability of measure the , state |2⟩ and |0⟩ is the probability of measure ∙ = n-1n-1 ⊕ n-2n-2 ⊕ … ⊕ 00 the state |0⟩ for any number n. As you can see if the Hamming weight tell us the number of symbols 5. The first n qubits are measured. Following different of the zero-symbol used in the alphabet, the algorithm if the probability that the the number ⟩ tell us the number measurements all give outcome 0, is 1, the 2 ∙ (1 − |0 ) function f is constant and balanced is that of symbols equal to the zero-symbol in the string. probability is 0. Proof If we want to calculate de Hamming weight of the How to calculate the Hamming weight message of length k ( = ()), we define like the first 2 bits and the last The algorithm to calculate the Hamming 2 bits of the message: weight is based on the Deutsch-Jozsa algorithm so the steps are the same described above. = ⋯ = & The function f associated to the = ⋯ transformation Bf is the following. Suppose we = … have to calculate the Hamming weight of a binary string of length k. In that case we define a function Following the algorithm will be the binary from = () + 1 bits to 1 bit in the following string with all zero´s. Now consider the summation way: On the first 2 inputs of the function we encode the binary string (message) based on (−1)()∙|⟩ (3) the position of each bit on the string (message). On the last 2 inputs of the function we fix the binary string with all zero´s. for the state |0⟩ and |2 ⟩ in : Suppose we want to calculate the Hamming weight of the string a = 10. Then function f will be: (−1)∙(⋯)|0⟩ = 2 (4) () : {0,1} → {0,1} ∈ Input |⟩ F(x) 00 0 (−1)∙(⋯)|2⟩ = −2 (5) 01 1 ∈ 10 0 11 0 Now if we consider the summation (3) for the state |0⟩ and |2 ⟩ in we will obtain the same The transformation Bf: result: f|⟩|⟩ = |⟩| ⊕ ()⟩ (−1)()∙(⋯)|0⟩ = This transformation has associated a unitary (6) ∈ permutation so it can be implemented in a quantum = 2 − 2 ∙ ℎ() computer using a set of universal quantum gates. Preprints (www.preprints.org) | NOT PEER-REVIEWED | Posted: 12 April 2018 doi:10.20944/preprints201804.0164.v1 qubit is an ancilla qubit to store temporary information. (−1)()∙(⋯)|2⟩ = 4. Apply the steps 2, 3, 4 and 5 of the Deutsch- (7) ∈ Jozsa algorithm. ⟩ ⟩ = 2 − 2 ∙ ℎ() 5. The states |2 and |0 are measured: where ℎ() is the Hamming weight of the hd (A,B) = hw(C) = 2 ∙ |2 ⟩ substring . After that we consider the hd (A,B) = hw(C) = 2 ∙ 1 − |0⟩ contribution of (4) and (6) to the amplitude associated with the state|0⟩ and we will obtain Below you can see the probabilities obtained for the Hamming weight (hw) for different n 1 values. ∙ (2 − 2 ∙ ℎ() + 2 ) = 2 (8) ℎ( ) = 1 − hw |⟩ P|⟩ 2 0 1,00 0,00 If we consider the contribution of (5) and (7) 1 0,25 0,25 to the amplitude associated with the state|2⟩, 2 0,00 1,00 we will obtain Table 1 n=1 1 ∙ (2 − 2 ∙ ℎ( ) − 2) = 2 hw |⟩ P|⟩ −ℎ() (9) 0 1,00000 0,00000 = 2 1 0,56250 0,06250 when the state |0⟩ is measured we will obtain: 2 0,25000 0,25000 3 0,06250 0,56250 ℎ( ) |0⟩ = 1 − (8) 4 0,00000 1,00000 2 Table 1 n=2 from where we can easily obtain (1). And if the state |2⟩ is measured we will obtain: hw |⟩ P| ⟩ hw |⟩ P| ⟩ 0 1,00000 0,00000 5 0,14062 0,39062 −ℎ( ) |0⟩ = (10) 2 1 0,76562 0,01562 6 0,06250 0,56250 2 0,56250 0,06250 7 0,01562 0,76562 from where we can easily obtain (2). 3 0,39062 0,14062 8 0,00000 1,00000 Algorithm to calculate the Hamming distance 4 0,25000 0,25000 Table 2 n=3 Suppose we have to calculate the Hamming distance of two binary strings A y B of length k.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    5 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us