The Hadamard gate is one of the fundamental transformation gates of quantum computing. I’d say there is no quantum circuit without it. This is because the Hadamard gate allows the qubit to move away from the basis state vectors |0⟩ and |1⟩.
Qubits in basis states
A qubit in either basis state |0⟩ or |1⟩ almost behaves like a classical bit. A qubit in state |0⟩ is 0, and a qubit in state |1⟩ is 1. Always.
You can even work with qubits in these two states, and you won’t see anything you couldn’t do with classical bits. Let’s consider the exclusive-OR operator (⊗), for instance. You can reason about it in a classical truth table.
The following quantum circuit implements an XOR operation (⊗) with 𝑃 and 𝑄 are 1.
The X-gates put the two input qubits into state |1⟩. The CNOT-gates flip the target qubit from |0⟩ to |1⟩ for either input qubit is in state |1⟩. If both input qubits are in state |1⟩, one CNOT flips the target to |1⟩, and the other flips it back to |0⟩.
The measurement probabilities of this circuit confirm this. As we see, when 𝑃 and 𝑄 are 1, then 𝑃⊗𝑄 is 0.
Note: The qubits read from right (upper) to left (lower). The output qubit is at the left.
A qubit in superposition
Things get interesting when we put our input qubits into superposition by applying the Hadamard gate on them. Let’s first look at what happens when we apply the Hadamard gate on a single qubit.
When we run this circuit, we measure the qubit as either 0 or 1. Each with a probability of 50%
And, we can use qubits in superposition to compute various states simultaneously. In the following circuit, we do not put the input qubits into state |1⟩, but we apply Hadamard gates on them.
This quantum circuit produces all four possible states at once. When we run the circuit only once, we get either one of the four possible states. But, the output qubit always represents 𝑃⊗Q.
The Hadamard gate reverts itself
The Hadamard gate has another characteristic. It reverts itself.
The following circuit depicts a qubit in state |0⟩ to which we apply two Hadamard gates.
We see that the qubit is back in state |0⟩. We always measure it as 0.
|+⟩ and |−⟩
If we only look at the measurement probabilities of a qubit, it doesn’t matter if we apply the Hadamard gate on a qubit in state |0⟩ or a qubit in state |1⟩. The following circuit puts the qubit into |1⟩ before it applies the Hadamard gate.
As we see, the result is the same as above when we applied the Hadamard gate on a qubit in state |0⟩.
But both states are different.
The Hadamard gate turns the state |0⟩ into |+⟩, and it turns the state |1⟩ into |−⟩.
To see the difference between these states, we need to look at a graphical representation of the qubit — the Bloch Sphere.
In the Bloch Sphere, the distance between the qubit state vector and the two poles of the sphere determines the probabilities of measuring a qubit as 0 or 1. For both states, |+⟩ and |−⟩ reside on the equator. Their distances to the poles are the same.
But it is essential to tell the difference between |+⟩ and |−⟩ because of the reversibility of the Hadamard gate. When we apply it twice on state |0⟩, we want to result in state |0⟩ again. But if we apply it twice on state |1⟩, we want it to result in |1⟩ again.
And this is what the Hadamard gate does.
The following circuit puts the qubit into |1⟩ before it applies the Hadamard gate twice.
The result is a qubit in state |1⟩ that we always measure as 1.
Flipping between |+⟩ and |−⟩
|+⟩ and |−⟩ are two different quantum states, and the Hadamard gate tells us that they are different.
But we can not only reach these states as a result of the Hadamard gate. We can also flip between |+⟩ and |−⟩ by applying the Z-gate.
This is a fundamental concept in quantum algorithms.
Many famous algorithms, such as Deutsch’s, Bernstein-Vazirani’s, and Simon’s algorithm, use Hadamard gates to put the qubits into state |+⟩. Then they flip some of the qubits from |+⟩ to |−⟩ (in a meaningful way, of course). Finally, they apply Hadamard gates on the qubits again. As a result, we measure some qubits as 0 and others as 1 — and we have a result.
Why don’t we just put the qubits directly from |0⟩ to |1⟩ in a meaningful way?
You already saw the answer. Do you remember when we applied the XOR operation on qubits in superposition? We were able to calculate all possible states at once. And, this is where the quantum advantage comes from.
Conclusion
The Hadamard gate is essential in quantum computing. It puts a qubit into superposition — a state that is the basis for tapping the quantum advantage.
Furthermore, the Hadamard gate vividly illustrates some of the concepts of quantum computing. For example, it shows that quantum gates must be reversible and that there is more in a quantum state than the measurement probabilities.
Finally, the Hadamard gate is the building block of the most important quantum algorithms. These algorithms build upon the ability to flip qubits from |+⟩ to |−⟩ and thus, to produce the solution to the given problem.