superpose() creates an equal superposition of its arguments.

1. But amplitudes don’t have to be positive numbers. They can also be negative, and more generally, they can be complex numbers.
This gives us another way to manipulate a superposition: we can change the phase of an amplitude.
What is phase?
For now, let’s think of an amplitude as something that has both a size and a direction. The size is called its magnitude. The direction is related to its phase.
180 degrees, or π radians, takes:

Changing the phase of our tea
Suppose we want to rotate the amplitude oficed tea by 180 degrees or π radians, while leaving the others untouched.
We can describe the rotation using an ordinary Python function:
rot_angle is an ordinary Python function. It maps every string to a rotation angle. For iced, it returns π, which means a 180-degree rotation. For everything else, it returns 0, so those amplitudes are left unchanged.
Now we can apply this phase change to our quantum string:

hot, warm, and cold are still:
But the amplitude of iced has been rotated by 180 degrees:
Notice that its magnitude is still 0.5.
So iced has not become more or less likely to be observed just because we changed its phase.
If we observed the tea right now, iced would still have the same probability as before.
The phase change does not change the probability. It changes the phase of the amplitude.
Why does phase matter?
At this point, you might wonder why we changed the phase oficed at all.
Suppose I only like hot or iced tea. I don’t want to get warm or cold tea.
If I observed the tea right now, all four values would still have a 25% chance of being observed. So instead of observing it, I want to transform the superposition first.
I want the amplitudes of warm and cold to become zero, while the amplitudes of hot and iced remain non-zero.
This is where changing the phase becomes useful.
By changing the phase of iced by π, we rotate its amplitude by 180 degrees. Now iced has an amplitude with a different phase from cold. When we apply interfere(), this phase difference causes the amplitudes to cancel in one direction and combine in the other.
Let’s see how this works.
Let’s pair the teas like this:
pair() pairs hot with warm, and cold with iced.
We also need to tell Rhyme which value comes first in each pair:
hot and warm pair, both amplitudes are:
So the new amplitudes are:
and
So hot remains, while warm is cancelled.
Now consider the cold and iced pair.
Their amplitudes are:
The amplitude of iced is negative because we changed its phase earlier.
This time:
while:
So cold is cancelled, while iced remains.
The resulting amplitudes are:
Now only hot and iced have non-zero amplitudes. This is also shown in the debugger:

hot and iced remain with equal amplitudes.
Finally, we can observe the tea:
hot or iced, each with a 50% chance.
Now we can see why the phase change mattered.
By rotating the amplitude of iced by π, we changed its sign. During interference, this caused cold to cancel and iced to remain.
So add_phase() lets us change the amplitudes in a way that can affect the result of a later interference.
The sequence is:
superpose() creates the values in a superposition.
add_phase() changes the phase of their amplitudes.
interfere() combines the amplitudes.
observe() gives us the final value.
That’s phase in Rhyme!