Relative phase: the invisible engine of quantum
Probabilities cannot see it, the next gate can. Global vs relative phase, and the experiment that makes the invisible visible.
For a while, quantum gates felt arbitrary to me. The Z gate flips the sign of |1⟩, and my honest reaction was, so what. The probabilities do not change, you cannot see a sign in a measurement, so why does anyone care about a gate that just decorates the state with a minus. I could apply these gates and get the right matrices out, but they felt like sign juggling with no point.
The thing that fixed it, completely, was one distinction: global phase versus relative phase. There is a phase the probabilities genuinely never see, and you are right to ignore it. And there is a phase that the next gate lives on, which is where all the action is. Telling them apart is the moment gates stop feeling arbitrary and start feeling like writing. I have been promising this post for a few entries now. Here it is.
Quick recap: phase is an angle
From the complex numbers post: every amplitude has a magnitude and a phase, a length and an angle. Square the magnitude and you get the probability. The phase, the angle, does not show up in a single measurement at all. That was the puzzle I left open. If the phase is invisible to measurement, when does it ever matter? The answer is that it depends entirely on which kind of phase you mean.
Global phase: real, and completely meaningless
Take any quantum state and multiply the whole thing by a phase, by e to the i theta for some angle. Every amplitude turns by the same angle. The claim is that this changes nothing you could ever observe, for any measurement at all.
import numpy as np
psi = np.array([1, 0]) # |0>
rotated = np.exp(1j*0.7) * psi # the whole state turned by 0.7 radians
print(np.allclose(np.abs(rotated)**2, np.abs(psi)**2)) # True
Q, _ = np.linalg.qr(np.random.randn(2,2) + 1j*np.random.randn(2,2)) # some other basis
print(np.allclose(np.abs(Q.conj().T @ rotated)**2,
np.abs(Q.conj().T @ psi)**2)) # True, in any basisRun it. The probabilities are identical, because turning every amplitude by the same angle leaves every length unchanged, and probabilities are about lengths. And not only in this basis. The conjugate you take when you square an amplitude cancels the phase exactly, and that cancellation does not care which basis you are squaring in, which is what the second check confirms. This is a global phase, an overall turn applied to the entire state, and it is physically undetectable. Two states that differ only by a global phase are the same state. You can multiply by whatever overall phase you like and it makes no difference to anything. This is also the small print from the gates post, where a rotation came out equal to the X gate up to an overall phase factor. That factor was a global phase, and now you know why it was safe to wave away. Global phase is a label with no physical content. Ignore it freely, with one piece of small print I will come back to. A phase only counts as global when it multiplies the entire state. Put the same phase on one part of a larger state, or on one branch of a controlled operation, and it stops being global and becomes relative, which is the opposite of meaningless. That is a mechanism rather than a caveat, and it gets a post of its own.
Relative phase: invisible to one measurement, and everything
Now the other kind. Instead of turning the whole state, change the phase between its parts. Compare |0⟩ + |1⟩ with |0⟩ minus |1⟩, each over √2. These are the states |+⟩ and |−⟩. They have the same magnitudes on |0⟩ and |1⟩, the same lengths, differing only in the sign, the relative phase, between the two components.
Measure either one in the standard basis and you get the same thing:
plus = np.array([1, 1]) / np.sqrt(2)
minus = np.array([1, -1]) / np.sqrt(2)
print(np.round(np.abs(plus)**2, 3)) # [0.5 0.5]
print(np.round(np.abs(minus)**2, 3)) # [0.5 0.5]
Run it. Both are fifty fifty. In a standard measurement, the relative phase is just as invisible as the global one was. This is exactly why I thought the sign did not matter. If you only ever measure in the standard basis, |+⟩ and |−⟩ look identical, and the minus sign looks like pointless decoration.
But they are not the same state, and you can prove it by measuring differently.
How to make the invisible phase visible
The trick is to apply a gate before you measure, to change the question you are asking. Apply a Hadamard to each.
H = np.array([[1, 1], [1, -1]]) / np.sqrt(2)
print(np.round(H @ plus, 3)) # [1 0] -> |0>, with certainty
print(np.round(H @ minus, 3)) # [0 1] -> |1>, with certainty
Run it. After a Hadamard, |+⟩ becomes |0⟩ and |−⟩ becomes |1⟩. Now they are not fifty fifty and they are not the same. One gives 0 with certainty, the other gives 1 with certainty. The relative phase that was completely invisible a moment ago has become a definite, perfectly distinguishable outcome. The phase was always there, carrying real information. It just took a gate to turn it into something a measurement could read. That is the entire point I had been missing. A relative phase is invisible to one particular measurement and fully real to the right next operation.
So that is what the Z gate was doing
Go back to the gate that started my complaint. The Z gate flips the sign of |1⟩. Watch what that does to |+⟩.
Z = np.array([[1, 0], [0, -1]])
print(np.allclose(Z @ plus, minus)) # True
Run it. Z turns |+⟩ into |−⟩. It did not do nothing. It moved the state from one place to a genuinely different place, a place that the standard measurement could not tell apart from the original but that the very next Hadamard could separate completely. The Z gate writes into the relative phase. It looked pointless only because I was looking at it through a measurement that is blind to exactly the thing it changes. Through the right next gate, Z is decisive. The sign was never decoration. It was data, written where the probabilities could not see it.
S and T write smaller phases
Z is the biggest phase move there is, a half turn that flips the sign, and it is the biggest because phase wraps: anything past a half turn is just a smaller turn the other way. The S and T gates from the gates post write smaller, finer phases, a quarter turn and an eighth turn, exactly the complex number rotations from earlier. Watch them act on |+⟩.
S = np.array([[1, 0], [0, 1j]])
T = np.array([[1, 0], [0, np.exp(1j*np.pi/4)]])
print(np.round(S @ plus, 3)) # [0.707+0j 0+0.707j]
print(np.round(T @ plus, 3)) # [0.707+0j 0.5+0.5j]
Run it. S leaves the |0⟩ part alone and turns the |1⟩ part by ninety degrees, putting an i where there was a one. T does the same with a forty five degree turn. Both leave the magnitudes untouched, so both are still fifty fifty in the standard basis, and both have parked the state at a different spot in its relative phase, a spot the next gate can act on. Z, S, and T are a family of phase writers at different resolutions: half turn, quarter turn, eighth turn. None of them changes a probability on its own. All of them change what the next operation will find.
One naming aside, because it is this post's own distinction in miniature. T is traditionally called the pi over eight gate, even though the phase it writes is pi over four. The reason is that T can also be written as an eighth turn of overall phase times a rotation that splits the phase symmetrically, plus and minus pi over eight, across the two amplitudes. The two spellings differ by exactly a global phase, so they are the same gate, and the name comes from the spelling where the global phase has been pulled out front. A confusing name that dissolves the moment you know which phase is which.
Chaining it: the phase decides the answer
Here is the whole idea in one short chain, the moment the abstract becomes concrete. Start from |+⟩. Take two paths. On the first, go straight to a Hadamard. On the second, apply a Z first, writing a relative phase, then the Hadamard.
print(np.round(H @ plus, 3)) # path 1: |+> -> H -> [1 0] = |0>
print(np.round(H @ (Z @ plus), 3)) # path 2: |+> -> Z -> H -> [0 1] = |1>
Run it. Same starting state, same final gate, and yet one path ends at |0⟩ with certainty and the other at |1⟩ with certainty. The only difference between them was a relative phase, written by the Z, that was completely invisible the instant it was written. The closing Hadamard turned that invisible phase into a definite, opposite answer. This is interference in its smallest form: a phase you cannot measure, made to control an outcome you can. Stare at this until it lands, because every quantum algorithm is this chain scaled up.
What "measuring in a different basis" really means
I have been saying measure in the standard basis and measure differently as if they were obviously distinct things, so let me make that concrete, because it is the mechanism underneath the whole post. The standard basis, the Z basis, asks one specific question: is this qubit |0⟩ or |1⟩. That is the only question a raw measurement knows how to ask. Relative phase is invisible to it because the question it asks does not depend on phase.
To ask a different question, you rotate the state with a gate first, and then ask the same old question. Applying a Hadamard before measuring is, in effect, measuring in the X basis, asking is this |+⟩ or |−⟩ instead of is this |0⟩ or |1⟩. And the X basis question does depend on the relative phase, which is exactly why the Hadamard could tell |+⟩ and |−⟩ apart when the bare measurement could not. So there is no special phase detecting hardware. There is one kind of measurement, blind to phase, and you change what it sees by rotating the state into its line of sight first. A relative phase is information that is invisible in one basis and fully visible in another, and the gate you apply before measuring is how you choose the basis. That reframing is what made the rest click for me: the phase is never hidden in some absolute sense, it is just hidden from the particular question you happen to be asking, and you get to change the question.
Why this is the engine of the whole field
Here is the payoff, and it is the reason this distinction is worth a whole post. Quantum algorithms work, at heart, by writing answers into relative phases and then using a later operation to turn those phases into visible outcomes. You set up a superposition, you use gates to stamp a pattern of relative phases across it, phases that no measurement could yet read, and then you arrange for those phases to interfere, reinforcing the answer you want and cancelling the ones you do not, until a final measurement reads out something that was hidden in the phases all along. The computation lives in the relative phase, invisible, until the last step cashes it out into probability.
That is the mechanism behind the speedups, and it is why phase is not a footnote but the main character. Interference, the thing that makes quantum more than a probabilistic coin, is just relative phases meeting and adding or cancelling.
One piece of honesty before you take that too far. Interference is necessary, not sufficient. There is a whole family of circuits stuffed with relative phase and real interference that an ordinary laptop can simulate efficiently, and, awkwardly, it is the family you build from exactly the H, S and Z above. What takes you out of it is T, the finest phase writer of the three. That is why the universal set from the gates post was H, T and CNOT rather than H, S and CNOT, a detail I had filed as arbitrary at the time. Interference is the engine. T is part of what makes the engine worth having.
You cannot understand a single quantum algorithm without this, and once you have it, the algorithms stop being magic and start being phase choreography. The next few things I write lean entirely on this idea.
To make that less abstract, here is the shape of the simplest real example, the one the algorithm posts will build out properly. Suppose you have a function and you want to know a global property of it, something that would normally take several evaluations to pin down. The quantum trick is to run the function in a way that, instead of returning its answer into a probability, stamps that answer into a relative phase across a superposition. Now the property you care about is encoded in a pattern of phases that no measurement can yet see. Then you apply a Hadamard, or a similar interference step, and those phases reinforce and cancel in just the right way to drive the final measurement straight to the answer, often in a single query where a classical approach would need many. You do not get this for free, and it does not work for every problem, but every case where it does work runs on this same engine: hide the answer in relative phase, then interfere to make it visible. That is the whole game, and you have already seen it in miniature two sections up.
The mental snap
Here is the reframe that did it for me, in two lines. Global phase is the orientation of the whole state, and it means nothing, so throw it away. Relative phase is the internal structure between the parts, and it is everything, because the next gate reads it and interference runs on it. Once I separated those two, every sign flipping gate stopped being arbitrary. A gate that adds a sign is not decorating the state. It is writing into the relative phase, which the next operation will read and act on. Gates went from noise to language the moment I understood which phase actually carries the message.
A quick test before you move on
Close this and answer in your own words.
If you multiply an entire state by e to the i theta, what changes about any measurement of it? If your answer is not nothing, reread the global phase section.
|+⟩ and |−⟩ give the same result in the standard basis. How would you tell them apart? If you cannot say something like apply a Hadamard first, the section on making the phase visible did not land.
And what is the Z gate actually doing to a state, in terms of phase? If your answer is still just flips a sign with no consequence, go back to the section on Z, because that was the whole misunderstanding this post exists to fix.
Where I am learning it
Free. The Bloch sphere helps here, because it draws relative phase and refuses to draw global phase at all, which makes the difference visual instead of abstract. That is worth sitting with, because it is not a gap in the picture, it is the point of it. A qubit state is two complex numbers, four real numbers in total. Normalisation eats one of them. Global phase eats another. The two that survive are exactly the two angles of a point on a sphere, which is why a sphere is a complete picture of a single qubit: it is what is left after you throw global phase away. Relative phase is one of the two coordinates that did survive, and turning it walks the point around its own line of latitude, which for |+⟩ is the equator itself, carrying it from |+⟩ toward |−⟩, a real, visible journey to a distinguishable place. The states that look identical to a standard measurement are the ones at the same height on the sphere, and the relative phase is how far around they have travelled. 3Blue1Brown and the usual explainers cover the geometry. But the thing that actually flipped it for me was the few lines above: take |+⟩ and |−⟩, confirm they measure the same, apply a Hadamard, watch them split. As ever, the distinction I had read a dozen times did not become real until I made the invisible phase turn into a definite outcome on my own machine.
The invisible thing that runs the machine
I spent real time thinking quantum gates were arbitrary because half of what they do is invisible to a measurement. The fix was learning that invisible to a measurement and physically meaningless are not the same thing. Global phase is both, and you can ignore it. Relative phase is invisible to the wrong measurement and decisive to the right next gate, and it is where the entire computation quietly happens.
Once the sign flips stopped looking like decoration and started looking like writing into a channel the probabilities cannot read, the gates clicked, and they have stayed clicked. The most important part of the state is the part you cannot directly see. That is not a paradox. It is the machine.