text
stringlengths
301
426
source
stringclasses
3 values
__index_level_0__
int64
0
404k
Scala, Learn Scala, Apache Spark. object-oriented and functional programming paradigms. Here are some common uses of Scala: Big data processing Scala is widely used in big data frameworks, particularly Apache Spark. Spark’s ability to handle large-scale data processing, coupled with Scala’s concise syntax and functional programming
medium
1,756
Scala, Learn Scala, Apache Spark. capabilities, makes it a perfect match for data-intensive applications. Web development Scala is used for building web applications, often with the Play Framework, Play Framework provides a clean and RESTful design, ideal for modern web applications. Distributed systems Scala’s concurrency
medium
1,757
Scala, Learn Scala, Apache Spark. features, like Akka, make it well-suited for building distributed systems. Akka is based on the Actor model, simplifying the development of highly concurrent and fault-tolerant systems. Data science Scala is used in data science for data manipulation, statistical analysis, and machine learning.
medium
1,758
Scala, Learn Scala, Apache Spark. Libraries such as Breeze (for numerical processing) and Spark’s data processing capabilities make it a powerful tool for data scientists. Is Scala still in demand? Scala is still very much in demand. It is a little niche-specific, but Scala is one of the highest-paying languages and is used by many
medium
1,759
Scala, Learn Scala, Apache Spark. top tech companies. One of the biggest drivers of Scala’s popularity is Apache Spark. Spark, a leading big data processing framework, is written in Scala, and many data engineers and data scientists use Scala to write Spark applications. Scala is also often used for data processing tasks due to its
medium
1,760
Scala, Learn Scala, Apache Spark. strong type system and functional programming capabilities, which can lead to more robust and maintainable code. How to learn Scala programming Educative has been working on providing valuable content for learners who want to upskill their skills. Now, you can learn Scala from scratch with
medium
1,761
Quantum Computing. Previously… In this article we will see how the ideas exposed in the previous articles are used in practice. The logic gates of classical computers are replaced by quantum gates in a quantum computer. A quantum gate must act on a quantum state as a unitary transformation because the evolution of
medium
1,763
Quantum Computing. the state going through the gate must preserve the total probability. In a classical computer an electric current could be pictured running through a certain path in a maze of logic gates opening and closing according to the specific logical code being executed. Let’s see if we can understand what
medium
1,764
Quantum Computing. happens in the case of a quantum computer. There are many quantum gates, much more than there are classical logic gates. In fact any unitary transformation acting on a certain number of qbits represents a possible quantum gate. Pauli gates The simplest gates are the ones acting on the one qbit
medium
1,765
Quantum Computing. states. The three Pauli gates rotate the qbit state around the three axis X, Y and Z of the Bloch sphere by exchanging the states |0⟩ and |1⟩ and adding phases of multiples of 90° to a state. Here are the unitary transformations of the Pauli gates using the Dirac notation and the computational
medium
1,766
Quantum Computing. basis σ_X = |1⟩⟨0|+|0⟩⟨1|, σ_Y = i|1⟩⟨0|-i|0⟩⟨1|, σ_Z = |0⟩⟨0|-|1⟩⟨1|, Clearly σ_X is swapping 0 with 1 and therefore represents a classic NOT gate. However σ_Y changes |0⟩ to |1⟩ and adds a phase of 90° to it and changes |1⟩ to |0⟩ but adds a phase of 270° to it. What logic operation could this
medium
1,767
Quantum Computing. possibly represent? If you multiply the unitary transformation of a Pauli gate by h/(4π) you get the corresponding component of the quantum spin. You may also want to play around and see what happens if the qbit is sent through a sequence of Pauli gates. What happens if the qbit goes through two
medium
1,768
Quantum Computing. Pauli X gates? What happens to it after a Pauli X is followed by a Pauli Y? Try all possible combinations of two gates. Quantum gates have their own symbols that are used when creating charts of quantum circuits. Here are the symbols of the Pauli gates. Hadamard gate Another simple one is the
medium
1,769
Quantum Computing. Hadamard gate acting on just one qbit. The unitary transformation describing this gate is just the sum of two Pauli gates U_H = (√2)-1 (σ_X + σ_Z) = (√2)-1((|0⟩+|1⟩) ⟨0| + (|0⟩-|1⟩)⟨1|)) with this circuit symbol If the input qbit state is |0⟩ the Hadamard gate evolves the qbit state to U_H |0⟩ =
medium
1,770
Quantum Computing. (√2)^-1((|0⟩+|1⟩) If the input qbit state is |1⟩ the output state of the Hadamard gate is UH |1⟩ = (√2)^-1((|0⟩-|1⟩) The Hadamard gate is known as the fair coin flip because it gives the same chance of the qbit to be found in the |0⟩ state as in the |1⟩ state. In essence this gate rotates the
medium
1,771
Quantum Computing. computational basis into another basis so that the probability of the input state is distributed unformly over all the states of the Hilbert space. Most quantum algorithms start with the Hadamard gate to take full advantage of the intrinsic parallelism offered by quantum mechanics. Phase shift
medium
1,772
Quantum Computing. gates The phase shift gate acting on one qbit simply adds a phase to the state |1⟩ and leave the state |0⟩ unchanged U_φ = |0⟩⟨0| + (cos φ + i sin φ) |1⟩⟨1| We can combine Hadamard and phase shift to get U_θφ |0⟩ = U_H U_2θ U_H U_(90°+φ) = cos θ |0⟩ + sin θ (cos φ + i sin φ)|1⟩ This is the most
medium
1,773
Quantum Computing. general unitary operation on a single cubit. When applied to the |0⟩ state the angles θ and φ are the latitude and longitude of the output qbit on the Bloch sphere with θ = 0 the latitude of the North pole of the Bloch sphere and φ = 0 the longitude of the Greenwich meridian of the Bloch sphere if
medium
1,774
Quantum Computing. you will. CNOT gate When dealing with more than one qbit we need gates that produce a superposition of entangled qbits. The simplest of such gates is the controlled NOT or CNOT gate of two qbits U_CNOT = |00⟩⟨00| + |01⟩⟨01| + |11⟩⟨10| + |10⟩⟨11| The first qbit is called the control qbit c. If the
medium
1,775
Quantum Computing. control qbit is 1 the second qbit t is flipped otherwise nothing happens. The effect is to create an entaglement between the control qbit c and the target qbit t. This logical operation is a reversible realization of the non reversible classical XOR gate and it is denoted graphically by the symbol
medium
1,776
Quantum Computing. ⊕ so that the target qbit is mapped to c ⊕ t: We have seen that a combination of two Hadamard and two phase shifts could represent any unitary transformation of one qbit. A finite combination of Hadamard, phase shift and CNOT can be used to represent any unitary transformation on two qbits or more.
medium
1,777
Quantum Computing. Toffoli gate I said before that quantum gates work on states as unitary transformations and they are reversible. When a qbit goes through two Hadamard gates in a row it comes out unchanged. The reverse of the Hadamard gate is the Hadamard gate itself. The classical NOT gate is like that but the
medium
1,778
Quantum Computing. classical AND and XOR are not. Classical computation is not reversible. Physically this implies that quantum computation must consume energy. An irreversible process loses information. In the physical realization of a classical computer this is equivalent to losing energy as heat transfered to the
medium
1,779
Quantum Computing. environment. However it is possible to model a classical computer with a quantum computer in a totally reversible fashion. The Toffoli gate or C2NOT gate is able to do this. U_T = |000⟩⟨000| + |001⟩⟨001| + |010⟩⟨010| + |011⟩⟨011| + |100⟩⟨100| + |101⟩⟨101| + |111⟩⟨110|+ |110⟩⟨111| It acts on 3
medium
1,780
Quantum Computing. qbits, one target qbit t (the last of the three) and 2 control qbits c_1 and c_2, by swapping the 0 and 1 states of the target qbit if both control qbits are in the 1 state. In other words Toffoli applies the Pauli X transformation to the target qbit conditional on both control qbits being set.
medium
1,781
Quantum Computing. This is the graphic symbol of the Toffoli gate The two black dots stand for the control bits c_1 and c_2 and the crossed circle for the conditional bit swapping operation of the target bit c_1 c_2 ⊕ t. Combinations of Toffoli gates can act as AND, XOR, NOT, … logic gates allowing to represent all
medium
1,782
Quantum Computing. of classical computing logic as a reversible transformation which is impossible in a classical computer. This means that a quantum computer can reproduce a classical computer with no heat dissipation. For example Toffoli acting on the target qbit |0⟩ turns the target qbit into the logical AND of
medium
1,783
Quantum Computing. the 2 control qbits: UT |000> = |000>, UT |010> = |010>, UT |100> = |100>, UT |110> = |111> Calculating functions A common problem when devising a quantum algorithm is the ability to compute the value of a function ƒ(x) at a number x. There are two cases: 1) The function ƒ(x) is invertible or there
medium
1,784
Quantum Computing. is only one x such that ƒ(x) = y. That means that the number of bits n of x and ƒ(x) are the same and ƒ(x) is simply a permutation of the numbers that can be represented with n bits. In this case there is a unitary transformation U_ƒ such that U_ƒ|x⟩ = |ƒ(x)⟩ and that is U_ƒ = |ƒ(0)⟩⟨0| + |ƒ(1)⟩⟨1|
medium
1,785
Quantum Computing. + … + |ƒ(2^n — 1)⟩⟨2^n — 1| 2) The function ƒ(x) is not invertible or several different values of x are mapped to the same value ƒ(x) = y. In this case there is no such unitary transformation. To get one we have to extend the Hilbert space to represent both the x-axis and the y-axis of the chart of
medium
1,786
Quantum Computing. the non invertible function ƒ(x) and define the unitary transformation U_ƒ |x⟩|y⟩ = |x⟩|y ⊕ ƒ(x)⟩ Then U_ƒ |x⟩|0⟩ = |x⟩|ƒ(x)⟩. In any case typically ƒ(x) is going to have a classical circuit implementation. In this case one would simply use controlled gates such as Toffoli’s gate to translate the
medium
1,787
Quantum Computing. classical circuit to a reversible unitary transformation. Infact one can view the Toffoli gate as implementing the Boolean function ƒ(a,b) = AND(a,b). Because AND is not reversible we need to extend the Hilbert space to embed it in a unitary transformation which is reversible. For example, by
medium
1,788
Quantum Computing. concatenating CNOT and Toffoli one can get a simplified adder gate. Since U_CNOT = |000⟩⟨000| + |001⟩⟨001| + |010⟩⟨010| + |011⟩⟨011| + |110⟩⟨100| + |111⟩⟨101| + |100⟩⟨110|+ |101⟩⟨111| the combination is U_T U_CNOT = |000⟩⟨000| + |001⟩⟨001| + |010⟩⟨010| + |011⟩⟨011| + |110⟩⟨100| + |111⟩⟨101| +
medium
1,789
Quantum Computing. |101⟩⟨110|+ |100⟩⟨111| If the last qbit is 0 the first qbit is unchanged, the second qbit is the sum of the first two qbits and the third qbit is the carry U_T U_CNOT |ab0⟩ = |000⟩⟨000|ab0⟩ + |010⟩⟨010|ab0⟩ + |110⟩⟨100|ab0⟩ + |101⟩⟨110|ab0⟩ Sometimes it may be convenient to calculate ƒ(x) has the
medium
1,790
Quantum Computing. composition of two or more simpler functions such as ƒ(x) = g(h(x)). In this case we need to extend the Hilbert space to represent the intermediate function h(x) with as many qbits as required. The qbits used to hold h(x) are called ancillas and are re-used whenever needed. Oracles In quantum
medium
1,791
Quantum Computing. mechanics we can also devise a function that only shifts the overall phase of the state such as U_oracle |x⟩ = (-1)^ƒ(x) |x⟩ The corresponding unitary transformation is called an oracle. The important property of oracles is that they can be black boxes that is they can be implemented without prior
medium
1,792
Quantum Computing. knowledge of ƒ(x). For example we may be inquiring about a property of ƒ(x) without knowing what ƒ(x) actually is. Each execution of an oracle is called a query. Let’s look at this example of an oracle. There are four possible functions of one bit: Now we can say that ƒ_0 and ƒ_3 are both constant
medium
1,793
Quantum Computing. functions and ƒ_1 and ƒ_2 are not. Classically we need two evaluations of ƒ(x) to know if ƒ(x) is constant or not. In quantum computing we use an oracle defined using the unknown function ƒ(x) and apply it so U_H (-1)^ƒ(x) U_H|0⟩ = U_H (-1)^ƒ(x) (√2)-1((|0⟩ + |1⟩) If ƒ(x) is constant the oracle
medium
1,794
Quantum Computing. will add an overall phase to the state and the second Hadamard transformation will return the state |0⟩. If ƒ(x) is not constant the oracle will add a relative phase of -1 between the states of the superposition and the second Hadamard will return the state |0⟩. So the oracle can find out if ƒ(x)
medium
1,795
Quantum Computing. is not constant with only one query. Grover’s algorithm I want to show how a quantum algorithm works with an example that is simple enough that can be worked out with back of the envelop calculations. Such a very simple quantum algorithm is the Grover’s algorithm. This algorithm performs a search
medium
1,796
Quantum Computing. of an unique word over a random list of words whose number is a power of 2. A classical computer will find the word after taking a number of steps of the same order as the number of words. Grover is faster because the search ends after a number of steps that is tonly he square root of the number of
medium
1,797
Quantum Computing. words. This is possible because Grover exploits the two fundamental differences between quantum computing and classical computing in a two punch attack. An application of this algorithm is the brute force breaking of the AES encryption scheme by simply trying all keys of a certain length until the
medium
1,798
Quantum Computing. correct one is found. AES encryption works by performing a large number of substitutions and permutations of the bytes of a document. The key provides the information to reverse all these operations and recover the original text. Here is a description of Grover’s algorithm for a system represented
medium
1,799
Quantum Computing. by 3 qbits. Again the most general 3 qbit register is the superposition of 8 states. Let’s say that we are looking for the word 011. Grover’s algorithm consists in sending the 3 qbits through a sequence of √8 ~ 3 quantum logic gates and then measure the value of the 3 qbits to be the target state
medium
1,800
Quantum Computing. with probability close to 1. In what follows we will need the unitary transformation that doesn’t change anything. Let’s call it I. I = |000⟩⟨000| + |001⟩⟨001| + |010⟩⟨010| + |011⟩⟨011| + |100⟩⟨100| + |101⟩⟨101| + |110⟩⟨110| + |111⟩⟨111| One starts by preparing the system in the initial state
medium
1,801
Quantum Computing. |000⟩. The purpose of the next step is to take advantage of quantum superposition to hold all of the words of the database in one register at the same time. One applies the Hadamard transformation so that each of the states of the 3 qbits register has the same probability of being observed. |μ⟩ =
medium
1,802
Quantum Computing. U_H |000⟩ = (2√2)-1 (|000⟩ + |001⟩+ |010⟩+ |011⟩ + |100⟩ + |101⟩+ |110⟩+ |111⟩) After passing through the Hadamard gate all the amplitudes in the state |μ⟩ are equal to 1/(2√2) because the sum of the squares of all amplitudes must be 1. This is the first punch. Note that the 3 qbits after passing
medium
1,803
Quantum Computing. through the Hadamard gate are statistically uncorrelated. The square of the amplitude 1/(2√2), that is 1/8, is just the probability of reading the values of 3 qbits if they are uncorrelated and the chance of reading either 1 or 0 is 50%. Now one wants to increase the probability of the register to
medium
1,804
Quantum Computing. be found in the state we are looking for. Again one is going to take advantage of quantum mechanics by using the extra information encoded in the phases of the amplitudes. This is done in two stages. In the first stage the phase of the state that we want is shifted by 180°. Remember that negative
medium
1,805
Quantum Computing. real numbers are just positive real numbers rotated by 180° in the complex plane. This simply means that one amplitude 1/(2√2) becomes -1/(2√2). In the second stage the state that has been put out of phase from all the others is singled out to increase the probability of being observed at the
medium
1,806
Quantum Computing. expense of the others. This is the second punch known as the Grover transformation. The unitary transformation implementing the first stage of the second punch is a quantum oracle. It’s designed to apply a phase of 180° only to the state that is being searched for. Let’s assume that this is |011⟩.
medium
1,807
Quantum Computing. The exact implementation of the quantum oracle depends on the details of the search problem that is on some distinguishing property of the state that is being searched for. However it is important to understand that as we have seen before we do not need to know what the state is in order to have
medium
1,808
Quantum Computing. such an oracle. The oracle just sends the weight z011 of our state to -z011 even if we ignore that the target state is indeed |011⟩. Note that the magnitude of the weight is unchanged. Only the phase is changed from 0° to 180°. U_oracle = |000⟩⟨000| + |001⟩⟨001| + |010⟩⟨010| — |011⟩⟨011| +
medium
1,809
Quantum Computing. |100⟩⟨100| + |101⟩⟨101| + |110⟩⟨110| + |111⟩⟨111| or, succinctly, U_oracle = I — 2 |011⟩⟨011| So U_oracle |μ⟩ = (2√2)-1 (|000⟩ + |001⟩ + |010⟩ — |011⟩ + |100⟩ + |101⟩ + |110⟩ + |111⟩) The second stage is called a diffusion transform. This is a unitary transformation that replaces each amplitude zj
medium
1,810
Quantum Computing. in the superposition of states with 2μ — z_j where μ is the average value of all the amplitudes. It basically flips the value of each amplitude around the average. We can write the diffusion transform succinctly like this U_diff = 2 |μ⟩⟨μ| — I Applying first the oracle and then the diffusion to the
medium
1,811
Quantum Computing. Hadamard state we simply have U_diff U_oracle U_H |000⟩ = (2 |μ⟩⟨μ| — I) (I — 2 |011⟩⟨011|) |μ⟩ = (2 |μ⟩⟨μ| — I — (2/√2) μ⟩ ⟨011| + 2 |011⟩⟨011|) |μ⟩ = 2 |μ⟩ — |μ⟩ — (1/2) |μ⟩ + (1/√2) |011⟩ = (1/2) |μ⟩ + (1/√2) |011⟩ where we have used the fact that ⟨μ|011⟩ = 1/(2√2). Any of the amplitudes that
medium
1,812
Quantum Computing. have not been affected by the oracle become 1/(4√2) ~ 0.177. The single amplitude that the oracle has multiplied by -1 now becomes 1/(4√2) + (1/√2) = 5/(4√2) ~ 0.884. One can verify that the sum of the squares of the amplitudes is still 1 after all of these steps. Now the probability of finding the
medium
1,813
Quantum Computing. 3 qbit device in the target state is 25/32 ~ 78.1%. Notice that this second punch is counted as one transformation because the oracle and the diffusion transform are realized as one quantum logic gate. In order to get the probability of measuring the target state closer to 1 we need to deliver the
medium
1,814
Quantum Computing. second punch one more time. If we do that the average μ is now 1/(16√2), any amplitude unaffected by the oracle becomes -1/(8√2) ~ = -0.088 and the amplitude of the target state becomes 11/(8√2) ~ 0.972. After two iterations the probability of the target state is ~ 94.53%. The Grover algorithm is
medium
1,815
Quantum Computing. nice because one can see the effect of the quantum phase in a very simple way with no need to resort to complex number algebra because a phase difference of 180° is just a minus sign. Without that minus sign in front of the target state the algorithm does not work. One cannot have a negative
medium
1,816
Quantum Computing. probability. Interpreting the amplitudes of a superposition of states as quantum probability amplitudes as opposed to classical probabilities is critical. Moreover one cannot get a minus sign in front of an element of the superposition if the 3 qbits are not correlated. Remember that the 3 qbits
medium
1,817
Quantum Computing. after the Hadamard gate are totally uncorrelated and with equal probability to occur. When passing through the Grover gate the 3 qbits become correlated. They are entangled. Another take away from the Grover algorithm is that quantum computing is in general probabilistic. In the case explored the
medium
1,818
Quantum Computing. best that we can hope is a 94.53% chance of getting the target state as an output. It is definitely good and it gets much better with more qbits but it is not 100% guaranteed. The Grover’s algorithm compared with a classical brute force search cuts the number of steps from N to about √N. When
medium
1,819
Quantum Computing. applied to scanning the 2¹²⁸ key space of AES128 the Grover’s algorithm reduce the number of steps from 2¹²⁸ to 2⁵⁶, This is an enormous reduction. A brute force classical computing cracking of a similar encryption with a 2⁵⁶ key space was accomplished in 22 hours and 15 minutes back in 1999. This
medium
1,820
Quantum Computing. means that AES128 is not safe from quantum decryption. However AES256 is safe since reducing it to AES128 will still make impossible to break. Shor’s algorithm RSA encryption is based on deriving the key needed to unlock the cypher from a number n = pq with two large randomly chosen prime factors p
medium
1,821
Quantum Computing. and q. Integer numbers such as 2, 78, 1781 can be factored in smaller integer numbers. Numbers that can only be divided by 1 and themselves are called primes. The first few primes are 2, 3, 5, 7, 11, etc. Note that 1, the unit element of the integers, is not classified as a prime. The encryption is
medium
1,822
Quantum Computing. unlocked by finding the two prime factors p and q of the integer number n the RSA secret key is based on. Prime factorization is believed to be an NP-class problem. That means that finding the prime factors of a number can take a classical computer a time much longer than a power of the size of the
medium
1,823
Quantum Computing. number n. The best known algorithm to find the prime factorization of an integer n is the general number field sieve which requires a number of steps that grows like the exponential of l^(1/3) (log l)^(2/3) where l is the number of bits of n. The special case of a number with two prime factors of
medium
1,824
Quantum Computing. similar size is considered the most difficult to solve. We know that quantum computer algorithms can be found that can solve an NP-class problem in a time that is only a power of the size of the problem. The Shor’s algorithm does just that for prime factorization. The number of steps needed by the
medium
1,825
Quantum Computing. Shor’s algorithm to factor n in primes grows as the square of l. The Shor’s algorithm has two phases. The first phase doesn’t require quantum computing so I will just touch upon it briefly. It is pretty straightforward for a classical computer and simply maps the original problem to a different
medium
1,826
Quantum Computing. problem that can be tackled by a quantum algorithm. — Classical part — This first phase is based on the fact that the factoring problem is equivalent to the problem of finding the period o of a periodic integer function. It is an application of a branch of mathematics called modular arithmetic. If
medium
1,827
Quantum Computing. m is a random integer less than n this periodic function is ƒ(j) = m^j mod n. This expression simply means that ƒ(j) is obtained as the remainder of the division of m^j by n. Finding the value of o, called as well the order of ƒ(j) in n, is the job of the quantum phase of the Shor’s algorithm. If
medium
1,828
Quantum Computing. the order o satisfies certain conditions p and q can be obtained easily from o otherwise a new value of m is chosen and another o is determined. Namely if n is odd (which is the case since we know none of the factors is 2) and o is even p = gcd(m^(o/2) + 1, n), q = gcd(m^(o/2) — 1, n) where
medium
1,829
Quantum Computing. gcd(a,b) is the greatest common divisor of a and b. — Exponentiation by squaring — Let’s delve into the quantum computing phase of Shor now. Remember that we are looking for an integer o such as the remainder of the division of m^(j+o) by n is equal to the remainder of the division of m^j by n. For
medium
1,830
Quantum Computing. example the chart below shows a graph of m^j mod n as a function of j when m = 11 and n = 21. Visually you can see that in this case o is equal to 6: Another choice of m, m = 19, is charted here: Those are values of m that happen to be coprime with n, that is gcd(m,n) = 1. If m has a factor in
medium
1,831
Quantum Computing. common with n like m = 18 with gcd(18,21) = 3 the chart looks like this instead: but in this case we do not need to proceed further because we have found p = 3 and q =21/3 = 7. In what follows we assume that m is coprime with n. We have to devise a strategy to find the order o by leveraging quantum
medium
1,832
Quantum Computing. mechanics. A quantum computer should be able to look at those charts just like you did and tell you that o is 6. Naively one could just build a state that is a superposition of the periodic function evaluated at each integer j less than n. Basically this superposition is a representation of the
medium
1,833
Quantum Computing. chart of the periodic function. If we first measure ƒ(j) and then we measure j on the resulting states that have the same value of ƒ(j) we will find o. However this approach violates the no cloning theorem. We cannot make copies of the states with the same value of ƒ(j). We need a different
medium
1,834
Quantum Computing. strategy because quantum mechanics forbids to look at the chart. There are two problems to solve. Finding the quantum algorithm that computes the remainder of m^j divided by n (the representation of the chart) and finding the quantum algorithm that determines the period o (instead of looking at the
medium
1,835
Quantum Computing. chart). Determining the period of a function ƒ(j) can be accomplished by taking the Fourier transform of ƒ(j). The quantum Fourier transform is a unitary transformation that maps a superposition of states corresponding to the values of the function ƒ(j) over a range of j values (the chart of ƒ(j))
medium
1,836
Quantum Computing. to a superposition of states corresponding to the frequencies of ƒ(j). If ƒ(j) has period o a state in the Fourier transform of ƒ(j) will have the largest weight at the frequency 1/o corresponding to the period o. Let’s tackle the charting of the function first. Basically we want to build a quantum
medium
1,837
Quantum Computing. superposition of computational states that encode the information in the chart of m^j mod n. A point on the chart is identified by two coordinates. This means that we need a quantum register with as many qbits to hold both coordinates of the chart. Let’s say that l is the number of qbits needed to
medium
1,838
Quantum Computing. represent one of the coordinates. The register will need to hold 2l qbits. Another way to say this is that the Hilbert space of the ƒ(j) chart is the tensor square of the Hilbert space of l qbits. To avoid clutter such an element of the computational basis of the Hilbert space of l qbits will be
medium
1,839
Quantum Computing. represented as |j_10⟩ where j_10 is the decimal representation of j instead of the usual binary representation. Let’s find the value of l. Let’s define L = 2^l. This is the dimension of the Hilbert space of l qbits. We want L to be large enough that the number of integers where ƒ(j) has the same
medium
1,840
Quantum Computing. value is larger than n or, in other words, we want L to contain more than n intervals of length o. This is true if L is the smallest power of 2 such that n² < L < 2 n². This implies L/o > n. With n = 21 we have 21² = 244 and 2 21² = 882. The only power of 2 in this range is 2⁹ = 512. So the half
medium
1,841
Quantum Computing. length of the register l must be 9. Note that 512/6 ~ 85 is definitely larger than 21. We can use the Hadamard transformation to create a superposition of L states. We want a superposition that represents the chart of a constant function or the empty chart over the range of integers between 0 and L
medium
1,842
Quantum Computing. — 1. Therefore the Hadamard transformation must be applied to only the first l qbits and the identity transformation to the remaining l qbits. In the case n = 21 we have |empty chart⟩ = U_H(first 9 qbits)⊗I(last 9 qbits) |0_10⟩|0_10⟩ = 1/(16 √2) (|0_10⟩|0_10⟩ + |1_10⟩|0_10⟩ + |2_10⟩|0_10⟩ + … … +
medium
1,843
Quantum Computing. |509_10⟩|0_10⟩ + |510_10⟩|0_10⟩ +|511_10⟩|0_10⟩ Now we need to compute ƒ(j) = m^j mod n on the last l qbits of the register. Calculating the remainder of m^j divided by n, also known as modular exponentiation, is a hard problem when m, n and j are integers. The typical approach consists in reducing
medium
1,844
Quantum Computing. this problem to repeatedly squaring an integer, an algorithm also known as exponentiation by squaring. It turns out that if m is odd m^j = m (m²)^((j-1)/2) and if m is even m^j = (m²)^(j/2). For example let’s try j = 13 = 1101_2 in binary form. We need to multiply m by m² 6 times: ƒ = m m² = m³, ƒ
medium
1,845
Quantum Computing. = ƒ m² = m⁵, ƒ = ƒ m² = m⁷, ƒ = ƒ m² = m⁹, ƒ = ƒ m² = m¹¹ and ƒ = ƒ m² = m¹³. Or, working on the binary form of j: ƒ = 1 = m⁰, ƒ = ƒ m = m¹ because the first bit is 1, ƒ = ƒ² = m², ƒ = ƒ m = m³ because the second bit is 1, ƒ = ƒ² = m⁶, nothing because the 3rd bit is 0, ƒ = ƒ² = m¹² and ƒ = ƒ m =
medium
1,846
Quantum Computing. m¹³ because the last bit is 1. However we still need to compute the remainder of the division by n. For that we can evaluate the remainder of the division by n before each multiplication by m. If m = 11 and n = 21 we have in the example the following steps: ƒ = 1 = 11⁰, ƒ = ƒ mod 21 = 11 mod 21 =
medium
1,847
Quantum Computing. 11, ƒ = ƒ 11 = 11¹ because the first bit is 1, ƒ = ƒ² = 11² = 121, ƒ = ƒ mod 21 = 121 mod 21 = 16, ƒ = ƒ m = 16 x 11 = 176 because the second bit is 1, ƒ = ƒ² = 176² = 30976, nothing to do because the 3rd bit is 0, ƒ = ƒ² = 30976² = 959512576, ƒ = ƒ mod 21 = 959512576 mod 21 = 1 and ƒ = ƒ m = 11
medium
1,848
Quantum Computing. because the last bit is 1. You can check that 11 is indeed the remainder of 11¹³ divided by 21. The problem is now to devise a unitary transformation on l qbits that performs exponentiation by squaring. Typically this is done by reproducing with unitary transformations the corresponding classical
medium
1,849
Quantum Computing. algorithms and this involves a series of NOT, controlled NOT and Toffoli gates though work has been done to make this part as efficient as possible. Even so this section of Shor’s algorithm is the slowest. Generally speaking one needs l³ gates to reproduce a classical algorithm with reversible
medium
1,850
Quantum Computing. transformations on l qbits. Now we can apply the unitary transformation that computes ƒ(j) on the last l qbits of the register. If n = 21 and m = 11 we have |chart of ƒ(j)> = U_ƒ |empty chart⟩ = 1/(16 √2) (|0_10⟩|1_10⟩ + |1_10⟩|11_10⟩ + |2_10⟩|16_10⟩ + … … + |509_10⟩|2_10⟩ + |510_10⟩|1_10⟩
medium
1,851
Quantum Computing. +|511_10⟩|11_10⟩ ) First measurement If we measure the value of ƒ(j) on this state, that is the value of the last l qbits, and we get the result r the chart state will collapse to the state | j: ƒ(j) = r⟩|r⟩ = √o/L (|j_1⟩ + … + |j_(L/o)⟩)|r⟩ which is a superposition of all the states where the
medium
1,852
Quantum Computing. integer j represented in the first l qbits and the integer r represented in the last l qbits are such that ƒ(j) = r. — Quantum Fourier Transform — If o is a divisor of L the number of computational states in this superposition is exactly L/o otherwise it is the largest integer less than that. In
medium
1,853
Quantum Computing. our example with L = 512 and r = 16 the state | ƒ(j) = r⟩ is a superposition of 85 states. Mind that at this stage we can’t tell how many states are in this superposition and we still do not know the value of o. However we can extract this information by applying the quantum Fourier transform.
medium
1,854
Quantum Computing. Let’s say that the smallest j such that ƒ(j) = r is j_1 and since the j’s increase in steps of o integers we can write as well | ƒ(j) = r⟩ = √o/L (|j_1⟩ + … + |j_1 + ko⟩ + … + |j_1 + L — o) ⟩ ) Quantum circuit diagram of a quantum phase estimation algorithm. Now we can apply the inverse QFT and get
medium
1,855
Quantum Computing. the period o. We are going to shift the phases of the factors of the superposition by all the multiples of the fundamental harmonic ν = 2π/L. Let’s define the complex number ω = cos ν + i sin ν The QFT is the unitary transformation U_QFT |s⟩ = 1/√L (|0⟩ + ω^s |1⟩ + ω^(2s) |2⟩ + … …+ω^(ts) |t⟩ + …
medium
1,856