# Quantum Algorithms

The essence of the quantum computations might not determine some particular result for a certain function, but establish the global properties of this function. For example, in the Deutsch problem, we don’t find the individual values of a function, but consider the whole superposition of the values and make conclusions about whether the function is constant or balanced.

Also the quantum Fourier transform is a kind of tools that allow us to collect information of interest from a certain initial set of qubit states, to study important properties from this global information.

## Deutsch Algorithm

Consider a boolean function `f: {0,1}n โ {0,1}`. The domain of this function D(f) consists of 2n various n-bit sequences. The range of the function E(f) contains only two elements: 0 and 1.

Consider a special case when n = 1. The domain of f is 1 bit, and the range of f is also 1 bit. Then this problem can be reduced to calculating `(f(0) + f(1)) MOD 2`.

Let the function f(x) be either constant or balanced, we do not know in advance which of these two classes it belongs. Deutsch Problem is to determine which of these two classes the function f(x) belongs to.

### Deutsch-Jozsa Algorithm

Deutsch-Jozsa algorithm is the generalization of Deutsch algorithm, when n > 1. The first n-qubits in state `|0โฉโจn` are used to prepare various argument values of the function f, with the help of the n-qubit Hadamard element Hโจn. The last qubit in the state `|1โฉ` is used to create the corresponding relative phase factor, to create the necessary quantum interference between the corresponding states after the transformation Uf.

If the function f(x) is constant, then after measuring the states of the data register, all its qubits will be in the state `|0โฉ`. Otherwise, the function will be balanced.

## Quantum Fourier Transform

In mathematics, discrete Fourier transform (DFT) is widely used in digital signal processing algorithms. DFT requires a discrete function (as input) or a sample of values from a continuous function: `{x0, x1, ..., xN-1}`. As a result of the DFT, another discrete function is obtained `{y0, y1, ..., yN-1}`.

The direct discrete Fourier transform is defined as:

``yk = 1/โN โN-1j=0 xj e-2ฯi*jk/N``

The inverse discrete Fourier transform is defined as:

``xj = 1/โN โN-1k=0 yk e2ฯi*jk/N``

The quantum discrete Fourier transform is defined in the similar way, suppose in an orthonormal basis `{|0โฉ, |1โฉ, ..., |N-1โฉ}`, the quantum direct Fourier transform is defined as:

``|jโฉ = 1/โN โN-1k=0 e2ฯi*jk/N |kโฉ``

Suppose N = 2n, where n is a natural number. A more convenient form for implementation is:

``|jโฉ = 1/2(n/2) โจnl=1 [|0โฉ + exp(2ฯi * j/2l) |1โฉ]``

The quantum Fourier transform requires O(n2) operations, meanwhile the classical fast Fourier transform requires O(n 2n) operations. However this is not possible in practice due to the reduction postulate and measurement procedure.

## Eigenvalue Algorithm

The quantum Fourier transform can be used to determine the eigenvalue of some unitary operator. Let a unitary operator U have an eigenvector `|uโฉ` and an eigenvalue `e2iฯฯ`, where ฯ is to be determined

To determine the eigenvalue, we will use controlled quantum logic gates capable of:

• preparing the state `|uโฉ` (the eigenstate of these quantum gates) and
• performing the operation U^2j (U to the power 2 to the power j) for the non-negative j.

The procedure consists of 2 stages, each of which uses 2 registers:

1. The first (data) register contains t qubits initially in the state |0โฉ. The number of qubits t defines how accurately we want to determine the eigenvalue ฯ.
2. The second (value) register contains as many qubits as needed for storing the state `|uโฉ`, and it is initial state is an eigenstate for the operator U. During the procedure, the state of the second register remains unchanged.

The first stage is nothing but the quantum Fourier transform of some initial state `|ฯโฉ`. Thus in order to calculate the phase ฯ, we need to perform the inverse quantum Fourier transform on the first register, as a result we obtain the state of `|ฯโฉ` which will be given by a set of qubits in the state of `|ฯ1โฉ|ฯ2โฉ...|ฯtโฉ`. This state will give a good estimation for ฯ, and therefore the eigenvalue of the unitary operator U, which correspond to its eigenstate `|uโฉ`.

## Integer Factorization

There are actual computational problems that can not be solved with the help of classical computers, such as the problem of factorizing large integers. The goal of the factorization algorithm is to determine primes factor p and q for a given integer M = p ร q. Such a task is of great importance for modern classical cryptography or more precisely public key cryptographic systems, which generate and multiply two large primes to encode information. Since the primes are very large it is impossible to factor the result in number with ordinary computer in a reasonable time.

Factorization problem can be reduced to determining the order or the period r of a certain periodic function `yM(x) = ax mod M`, when `ar mod M = 1`, where:

1. `x = 0, 1, ..., N-1`;
2. `L = โกLog2Nโค` is the number of bits needed for recording x;
3. `a` is an arbitrary number that does not have common divisors with M, and 1 < a < M.

When the order r is known, the prime factors of a number M are determined using Euclidean algorithm as the greatest common divisor of numbers `ar/2 ยฑ 1` and `M`.

## Shor’s Algorithm for Integer Factorization

To implement Shor’s algorithm, we use two quantum registers X (data) and Y (value), each of which consists of a set of L qubits in the `|0โฉ` state: `|Xโฉ|Yโฉ = |0โฉโจL|0โฉโจL`, here `|0โฉโจL = |0L-1, 0L-2, ..., 00โฉ`, and `N = 2L โฅ M2 โซ r2`.

The register X contains the arguments (natural numbers) of the function yM(x), the register Y is used to keep the values of the function yM(x).

At the first stage:

1. The state of the register X is transformed by Hadamard transforms into an equiprobable superposition of all Boolean states.
2. Then the register Y is filled with values yM(x) = 2x mod M using a reversible logical operation, and a superposition is obtained.

At the second stage:

1. Measure the value register in the measurement basis, and data register is still unmeasured. Thus the second register is used to prepare periodic superposition in the first register.
2. Now we can find the period r using the Fourier transform which is performed on the state of the first (data) register.
3. Then knowing the period r, we use the classical Euclidean algorithm.

Shor factorization algorithm gives an exponential gain in speed in comparison with the classical factorization algorithms.

## My Certificate

For more on Quantum Algorithms, please refer to the wonderful course here https://www.coursera.org/learn/physical-basis-quantum-computing

I am Kesler Zhu, thank you for visiting my website. Check out more course reviews at https://KZHU.ai

All of your support will be used for maintenance of this site and more great content. I am humbled and grateful for your generosity. Thank you!

 Your generosity and kindness is overwhelming!Donate \$1.99 - Good job!Donate \$4.99 - Keep it up!Donate \$14.99 - Very helpful!Donate \$29.99 - Looking forward to more!