Your First Quantum Circuit and the Machines Behind Regex

Build a Bell state with two gates, see why a phase matters, then turn a regular expression into the smallest machine that reads it.
Two kinds of computing machine sit at opposite ends of computer science: the quantum circuit, which is still being built, and the finite automaton, which runs inside every search box. Both are easier to understand by trying them than by reading about them.
Two gates, one entangled pair
Open the Quantum circuit simulator with 2 qubits. Every qubit starts as 0, so the state is |00>. Add two gates:
- h 0: the Hadamard gate puts qubit 0 into an equal mix of 0 and 1.
- cx 0 1: the CNOT gate flips qubit 1 when qubit 0 is 1.
The table now shows two states, |00> and |11>, each with a 50 % chance, and nothing for |01> or |10>. Measure 1,000 shots and you get roughly 500 of each, never a mixed pair. That is entanglement: each qubit alone is a coin toss, yet the two always agree.
The Bloch spheres tell the same story. A single qubit in a clean state has an arrow touching the sphere. After the CNOT both arrows shrink to the centre, and purity drops from 1 to 0.5. A qubit whose arrow has shrunk is tied to the others.
The phase you cannot see
Load the example called A hidden phase: h 0, z 0, h 0. After the Z gate the chances are still 50/50, the same as before. Only the sign of the |1> amplitude changed. The second H turns that sign into a certain answer: 1, every time. Quantum algorithms such as Grover's search and the quantum Fourier transform are built on this trick of moving information between phases and chances.
Tip: drag the Step through slider to watch the state after each gate. It makes the Grover example much easier to follow.
A regular expression is a small machine
The pattern (a|b)*abb means "any letters a and b, ending in abb". The Automata studio turns it into three machines:
- an NFA built piece by piece from the pattern (Thompson's construction),
- a DFA that tracks every state the NFA could be in (the subset construction),
- the smallest DFA, where states that no word can tell apart are merged.
For this pattern the smallest DFA has only 4 states. Each one remembers how much of "abb" you have just read. Test words in the box and watch which are accepted.
Are two patterns the same?
The Same language? tab compares two expressions. (a|b) and (ab) turn out to be equal: both match every word of a and b. But (a|b)abb and (a|b)bb differ, and the studio gives the shortest word that proves it: bb**, which only the second accepts. That is a handy way to check a homework answer or a validation rule.
Try it
Start with the Bell state, then load Teleportation to see qubit 0's arrow reappear on qubit 2. In the Automata studio, try (a|b)*a(a|b)(a|b) and see why the DFA needs 8 states to remember the last three letters.