0% found this document useful (0 votes)
14 views4 pages

QCEXP@8

The document outlines the implementation of Deutsch's Algorithm, a quantum algorithm that determines if a given function is constant or balanced with only one evaluation. It describes the quantum circuit setup, including the use of Hadamard gates and oracles, and provides a Qiskit code implementation for testing both constant and balanced functions. The conclusion emphasizes the algorithm's demonstration of quantum speedup and its foundational role in quantum computing.

Uploaded by

rahulcounsellor1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

QCEXP@8

The document outlines the implementation of Deutsch's Algorithm, a quantum algorithm that determines if a given function is constant or balanced with only one evaluation. It describes the quantum circuit setup, including the use of Hadamard gates and oracles, and provides a Qiskit code implementation for testing both constant and balanced functions. The conclusion emphasizes the algorithm's demonstration of quantum speedup and its foundational role in quantum computing.

Uploaded by

rahulcounsellor1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Mitesh Singh / B22 / 2101111

EXPERIMENT 8

AIM: Write a Program to implement Deutsch’s Algorithm

THEORY:

Deutsch’s Algorithm is one of the first quantum algorithms that demonstrates quantum
speedup over classical algorithms. It solves the problem of determining whether a given
function is constant or balanced with just one function evaluation, whereas a classical
algorithm would require two evaluations.

Problem Statement

We are given a black-box function (oracle) f: {0,1} → {0,1}, which takes a single-bit input
and produces a single-bit output. The function can be either:

• Constant (always 0 or always 1), or


• Balanced (f(0) ≠ f(1)).

Our goal is to determine whether f is constant or balanced with one function call.

Mathematical Formulation

In the classical case, we need to evaluate both f(0) and f(1) to determine the function type.

In the quantum case, we can use superposition and interference to determine the function
type in a single query.

Quantum Circuit for Deutsch’s Algorithm

1. Start with two qubits:


o q0 (input qubit) initialized to |0⟩
o q1 (output qubit) initialized to |1⟩
2. Apply Hadamard (H) gates to both qubits to create a superposition state.
3. Pass the qubits through a quantum oracle, which applies the transformation:

∣x,y⟩→∣x,y⊕f(x)⟩|x, y⟩ → |x, y ⊕ f(x)⟩∣x,y⟩→∣x,y⊕f(x)⟩

4. Apply another Hadamard gate to the first qubit.


5. Measure the first qubit:
o If the result is |0⟩, f(x) is constant.
o If the result is |1⟩, f(x) is balanced.
Mitesh Singh / B22 / 2101111

Quantum Circuit Representation

The circuit consists of the following gates:

• H-gate (Hadamard gate): Creates superposition.


• Uf (Oracle gate): Encodes the function f(x).
• H-gate (Hadamard again): Interferes the amplitudes to extract information.

Uf represents the oracle, which we implement differently for constant and balanced
functions.

CODE:

Here’s the implementation using Qiskit:

Qiskit Implementation:-

import numpy as np
from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator
from qiskit.visualization import plot_histogram

def deutsch_algorithm(oracle):
qc = QuantumCircuit(2, 1)
qc.h(0)
qc.h(1)
qc.append(oracle.to_instruction(), [0, 1])
qc.h(0)
qc.measure(0, 0)

simulator = AerSimulator()
transpiled_qc = transpile(qc, simulator)
job = simulator.run(transpiled_qc, shots=1024)
result = job.result()
counts = result.get_counts()

return "Constant Function" if '0' in counts else "Balanced Function"

def constant_oracle():
qc = QuantumCircuit(2)
return qc

def balanced_oracle():
qc = QuantumCircuit(2)
Mitesh Singh / B22 / 2101111

qc.cx(0, 1)
return qc

print("Testing Constant Function:")


print(deutsch_algorithm(constant_oracle()))

print("Testing Balanced Function:")


print(deutsch_algorithm(balanced_oracle()))

IMPLEMENTATION
1. Define the Deutsch Algorithm (deutsch_algorithm)
o Initializes the quantum circuit with 2 qubits and 1 classical bit.
o Applies Hadamard gates to both qubits to create superposition.
o Applies the oracle function (constant or balanced).
o Applies another Hadamard gate to the first qubit to extract information.
o Measures the first qubit and interprets the result.
2. Define the Oracle Functions
o Constant Oracle (constant_oracle): Does nothing since f(x) is the same for
all inputs.
o Balanced Oracle (balanced_oracle): Uses a CNOT (CX) gate to flip the
target qubit when the control is 1.
3. Run Deutsch’s Algorithm
o Executes the circuit on a quantum simulator.
o Outputs either "Constant Function" or "Balanced Function".

Expected Output
Testing Constant Function:
Constant Function

Testing Balanced Function:


Balanced Function

This confirms that Deutsch’s algorithm correctly determines the nature of the function in
just one evaluation, showcasing quantum advantage.
Mitesh Singh / B22 / 2101111

CONCLUSION:-
Deutsch Algorithm provides an elegant demonstration of quantum speedup, leveraging
superposition and interference to solve the problem with just one function evaluation
instead of two. By encoding the function properties into a quantum state and using the
Hadamard transformation, the algorithm efficiently distinguishes between constant and
balanced functions. The implementation showcases how quantum oracles work and how
quantum gates like Hadamard (H) and CNOT (CX) enable computational advantages. This
fundamental concept is extended in the Deutsch-Jozsa Algorithm, which generalizes the
problem for n-bit functions, further highlighting the power of quantum computing in solving
specific problems exponentially faster than classical methods.

You might also like