An Introduction To Quantum Computing With Qiskit Implementations
An Introduction To Quantum Computing With Qiskit Implementations
An Introduction to Quantum
Computing with Qiskit
Implementations
3 Quantum Gates 3
1
1 Abstract
This report mainly includes essential quantum computing concepts, offering insights
into qubits, superposition, gates, algorithms, and their practical implementation. Aim
of the study is to being able to understand The Deutsch-Jozsa Algorithm.
2.1 Qubits
Definition 2.1 (Qubit). A qubit (quantum bit) is the fundamental unit of quantum in-
formation. It is the quantum analogue of a classical bit. Unlike classical bits, which can
only be in states 0 or 1, qubits can exist in a linear combination of both states thus can
be represented as ∀α,β ∈ C , |ψ⟩ = α |0⟩ + β |1⟩ where |0⟩ and |1⟩ are the basis states
corresponding to classical 0 and 1.
If there are more than one qubits to examine together, they are expressed using the
tensor product. For example two state |0⟩ qubits written as
|0⟩ ⊗ |0⟩ = |00⟩ .
Definition 2.2 (Auxiliary Qubit). An auxiliary qubit is an additional qubit used in quan-
tum computation to aid in performing specific operations or manipulations on the pri-
mary input qubits. It plays a supportive role rather than being directly involved in the
main computational task.
Definition 2.3 (Basis States). The fundamental states in which a quantum system can
be measured are called basis states. In a qubit system, the two basis states are conven-
tionally denoted as |0⟩ and |1⟩. These states are orthogonal and represent the classical
binary values 0 and 1 respectively. They are represented as column vectors:
1 0
|0⟩ = , |1⟩ =
0 1
2.2 Superposition
Any qubit exist in the linear combination of basis states called superpositions. It is
the ability of a quantum system to exist in a combination of multiple states simultane-
ously.
∀α,β ∈ C , |ψ⟩ = α |0⟩ + β |1⟩ is a general qubit in superposition of two basis states
|0⟩ and |1⟩.
2.3 Measurement
Measurement is the procedure of evaluating the state of a qubit. Any qubit carries
probabilistic information about which basis state it’s closer to or which basis state it
2
prefers more to collapse to. Measuring the qubit collapses its quantum state to one
of the basis states, with the probabilities of measurement outcomes determined by the
norm square of the amplitudes.
In a quantum circuit diagram, measurement is represented as a meter symbol:
3 Quantum Gates
Quantum gates carry around and manipulate the quantum information by transform-
ing the state of a qubit into other states. This can be visualized as rotations on Bloch
Sphere.
Gates are linear maps, meaning, we can distribute them across superpositions. They
also keep the total probability of a qubit being one of the two states equal to 1 thus
normalization condition, ∥α∥2 + ∥β ∥2 = 1, is satisfied after the gate has acted.
Since gates are linear maps, we can express them using matrices. Due to normal-
ization condition, matrices that represent them must be unitary. All unitary matrices
express a quantum gate. Most common quantum gates are: Pauli X-Gate (NOT Gate),
Pauli Y-Gate, Pauli Z-Gate, Hadamard Gate, CNOT Gate (Controlled NOT Gate), Tof-
foli Gate (CCNOT Gate).
Definition 3.1 (Pauli X-Gate (NOT Gate)). Flips the state of a qubit, changing |0⟩ to
|1⟩ and vice versa. Matrix representation:
0 1
1 0
Circuit representation:
Truth table:
Input Output
|0⟩ |1⟩
|1⟩ |0⟩
Definition 3.2 (Pauli Y-Gate). Introduces a phase shift and swaps |0⟩ and |1⟩ states.
Matrix representation:
0 −i
i 0
Circuit representation:
3
Y
Truth table:
Input Output
|0⟩ i |1⟩
|1⟩ −i |0⟩
Definition 3.3 (Pauli Z-Gate). Introduces a phase shift to the |1⟩ state. Matrix repre-
sentation:
1 0
0 −1
Circuit representation:
Truth table:
Input Output
|0⟩ |0⟩
|1⟩ − |1⟩
|0⟩+|1⟩
Definition 3.4 (Hadamard Gate). Creates superposition by transforming |0⟩ to √
2
|0⟩−|1⟩
and |1⟩ to √
2
. Matrix representation:
1 1 1
√
2 1 −1
Circuit representation:
Truth table:
Input Output
|0⟩+|1⟩
|0⟩ √
2
|0⟩−|1⟩
|1⟩ √
2
Definition 3.5 (CNOT Gate (Controlled NOT Gate)). Acts on two qubits. Applies a
Pauli-X gate to the target qubit(flips the target qubit) if the control qubit is |1⟩. Matrix
representation:
1 0 0 0
0 1 0 0
0 0 0 1
0 0 1 0
4
Circuit representation:
control
target
Truth table:
Input Output
|00⟩ |00⟩
|01⟩ |01⟩
|10⟩ |11⟩
|11⟩ |10⟩
Definition 3.6 (Toffoli Gate (CCNOT Gate)). Acts on three qubits. Applies a Pauli-X
gate to the target qubit if both control qubits are |1⟩.
1 0 0 0
0 1 0 0
0 0 0 1
0 0 1 0
Circuit representation:
control
control
target
Truth table:
Input Output
|000⟩ |000⟩
|001⟩ |001⟩
|010⟩ |010⟩
|011⟩ |011⟩
|100⟩ |100⟩
|101⟩ |101⟩
|110⟩ |111⟩
|111⟩ |110⟩
4.1 Entanglement
Entanglement is relationship between two or more quantum systems when these
systems are interconnected in a way that state of one system instantaneously affects
5
the state of other. It forms the basis for protocols like quantum teleportation and quan-
tum cryptography. Additionally, quantum computers can use entanglement to perform
certain computations more efficiently than classical computers through algorithms.
Auxiliary Input
Figure 1:Non-reversible function Figure 2:Reversible function
6
computing methods, behavior of the function can be determined with only 1 execution
for any n, which means O(1) complexity.
7
x f (x) 0 ⊕ f (x) 0 ⊕ f (x) x f (x) 0 ⊕ f (x) 0 ⊕ f (x)
0 0 0 1 0 1 1 0
0 0 0 1 0 1 1 0
1
[|0⟩ (|0⟩ − |1⟩) + |1⟩ (|0⟩ − |1⟩)]
if f = 0
|ψ2 ⟩ = 2
1 [|0⟩ (|1⟩ − |0⟩) + |1⟩ (|1⟩ − |0⟩)]
if f = 1
2
1
(|0⟩ + |1⟩) + (|0⟩ − |1⟩)
if f =0
= 2
− 1 (|0⟩ + |1⟩) + (|0⟩ − |1⟩) if f
=1
2
(−1) f (0)
|ψ2 ⟩ = (|0⟩ + |1⟩)(|0⟩ − |1⟩)
2
(|0⟩ + |1⟩) (|0⟩ − |1⟩)
= (−1) f (0) √ √
2 2
f (0)
= (−1) |+⟩|−⟩
1
[|0⟩ (|0⟩ − |1⟩) + |1⟩ (|1⟩ − |0⟩)] if f = f2
|ψ2 ⟩ = 2
1 [|0⟩ (|0⟩ − |1⟩) + |1⟩ (|1⟩ − |0⟩)] if f = f3
2
(−1) f (0)
|ψ2 ⟩ = (|0⟩ − |1⟩) · (|0⟩ − |1⟩)
2
(|0⟩ − |1⟩) (|0⟩ − |1⟩)
= (−1) f (0) √ · √
2 2
f (0)
= (−1) |−⟩ · |−⟩
8
This can be generalized as follows.
(
|0⊗n ⟩|−⟩ if f = constant
|ψ3 ⟩ = ±
±|1⊗n ⟩|−⟩ if f = balanced
9
12 # Next , format ’b ’ as a binary string of length ’n ’,
padded with zeros :
13 b_str = format (b , ’0 ’+ str ( n ) + ’b ’)
14 # Next , we place the first X - gates . Each digit in our
binary string
15 # corresponds to a qubit , if the digit is 0 , we do nothing
, if it ’s 1
16 # we apply an X - gate to that qubit :
17 for qubit in range ( len ( b_str ) ) :
18 if b_str [ qubit ] == ’1 ’:
19 oracle_qc . x ( qubit )
20 # Do the controlled - NOT gates for each qubit , using the
output qubit as the target :
21 for qubit in range ( n ) :
22 oracle_qc . cx ( qubit , n )
23 # Next , place the final X - gates
24 for qubit in range ( len ( b_str ) ) :
25 if b_str [ qubit ] == ’1 ’:
26 oracle_qc . x ( qubit )
27
15 for i in range ( n ) :
16 dj_circuit . measure (i , i )
17
18 return dj_circuit
Listing 3: Adding all the elements to the circuit
10
2 dj_circuit = dj_algorithm ( oracle_gate , n )
Listing 4: Specifying the oracle
11
Figure 4: Simulation result for constant function.
References
[1] Deutsch-Jozsa Algorithm. en. URL : https : / / learn . qiskit . org (visited on
08/22/2023).
[2] Michael A. Nielsen and Isaac L. Chuang. Quantum Computation and Quantum
Information: 10th Anniversary Edition. 1st ed. Cambridge University Press, June
2012. ISBN: 9781107002173 9780511976667. DOI: 10.1017/CBO9780511976667.
URL : https://www.cambridge.org/core/product/identifier/9780511976667/
type/book (visited on 08/21/2023).
12