# Quantum Superposition with Classiq

Superposition is a key concept in all quantum algorithms. In this tutorial, we show how to create an equal superposition on 3 qubits, using the Hadamard transform.

from classiq import *

@qfunc
apply_to_all(H, reg_a)

@qfunc
def main(register_a: Output[QArray[QBit]]) -> None:
allocate(3, register_a)

model = create_model(main)
write_qmod(model, "equal_superposition_3_qubits")

qprog = synthesize(model)

circuit = QuantumProgram.from_qprog(qprog)

circuit.show()

Opening: https://platform.classiq.io/circuit/e7b5ca3a-763e-461a-8bf2-4e1c16ba72b3?version=0.45.0.dev0%2Bcf1b9b7ccc


## Mathematical Background

The 2x2 Hadamard matrix $$H$$ is used to transform a single qubit's state. It is defined as:

$H = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}$

Application to 3 Qubits: Applying the Hadamard transform $$H$$ to each of three qubits initially in the state $$|000\rangle$$ results in the superposition of all possible states. The combined operation for three qubits is the tensor product $$H \otimes H \otimes H$$:

$(H \otimes H \otimes H) |000\rangle = \frac{1}{\sqrt{8}} (|000\rangle + |001\rangle + |010\rangle + |011\rangle + |100\rangle + |101\rangle + |110\rangle + |111\rangle)$

This represents an equal superposition of all eight possible states of the three qubits.