Solve this BEFORE lesson.md. Goal: when the lesson says
"x, y, z, h, s, sdg, t, tdg, p, rx, ry, rz, u, sx, sxdg, id are methods on the circuit,"
you know exactly what 2×2 matrix each name is and what it does to a state.
Video back-up: freeCodeCamp Quantum Computing – Math and Theory for Beginners
(resource-artifactory/videos/freecodecamp-qc-math/) and Watrous Lesson 01 Single Systems,
Lesson 02 Multiple Systems (resource-artifactory/videos/watrous-uqic/).
Notes: resource-artifactory/notes/video-notes/.
Modulus (length):∣z∣=a2+b2. Note ∣z∣2=z⋅z∗ where z∗=a−bi is the conjugate.
Euler form:z=reiφ=r(cosφ+isinφ).
The unit circle values you will use constantly:
φ
eiφ
0
1
π/4
21+i
π/2
i
π
−1
3π/2 (or −π/2)
−i
2π
1 (wraps around)
Multiplying by eiφ rotates a complex number by angle φ and never changes its length. That's why phases don't change measurement probabilities on their own.
All four give 50/50 outcomes in the standard basis — they differ only in relative phase, which other gates can later convert into probability differences. That's the whole trick of quantum interference.
A gate is a 2n×2n matrix U applied by multiplication: ∣ψout⟩=U∣ψin⟩.
It must be unitary: U†U=I (where U† = conjugate-transpose, called the adjoint or dagger).
Unitary ⇔ preserves lengths ⇔ probabilities always sum to 1 ⇔ reversible (inverse is U†).
Rz(θ) vs P(θ): same up to the global phasee−iθ/2 — physically identical alone, but the difference matters once controlled. (This is exactly the lesson's p(pi) == z exact vs rz(pi) = -iZ trap.)
Square-root-of-X:
SX=X=21(1+i1−i1−i1+i),SX⋅SX=X;sxdg=SX†
The universal one-qubit gate u: every single-qubit unitary (up to global phase) is
Basis order: ∣00⟩,∣01⟩,∣10⟩,∣11⟩ = indices 0,1,2,3 (binary!). Gates combine the same way: applying A to one qubit and B to the other is A⊗B, a 4×4 matrix. n qubits ⇒ 2n amplitudes — that's the exponential state space.
Qiskit's little-endian twist: qubit 0 is the LEAST significant bit. A state written ∣q1q0⟩ means the left symbol is qubit 1. x(0) on 2 qubits gives bitstring '01'. Matrix-wise Qiskit's 2-qubit operator for "A on q1, B on q0" is A⊗B — matching a.tensor(b) putting b on the lower wires.
Controlled gates. CNOT (cx) flips the target iff the control is ∣1⟩. With control = q0 (Qiskit order, control on the low qubit):
CX0→1=1000000100100100(in the little-endian basis ∣q1q0⟩:∣01⟩↔∣11⟩)
General recipe: C-U=∣0⟩⟨0∣ctl⊗I+∣1⟩⟨1∣ctl⊗U. Because CZ's action (−1 only on ∣11⟩) doesn't care which qubit is "control," CZ/CP/SWAP-type gates are symmetric; CX/CY/CH are not — exactly the lesson's symmetric/asymmetric table.
Entanglement. A state is entangled iff it cannot be written as ∣a⟩⊗∣b⟩. The Bell state
∣Φ+⟩=21(∣00⟩+∣11⟩)=(H on q0, then CX)∣00⟩
has no such factorization (try it: you'd need a0b0=a1b1=21 but a0b1=0 — impossible).
Measuring in the computational basis: outcome x with probability ∣⟨x∣ψ⟩∣2 = |amplitude|², then the state collapses to ∣x⟩. Measurement is NOT unitary and NOT reversible — that's why inverse() refuses circuits containing measure.
P1. Normalize (34i) and give the probability of measuring 1.
P2. Compute H∣1⟩ by matrix multiplication. Which named state is it?
P3. Show S⋅S=Z and T†T=I by multiplying matrices.
P4. Compute HZH and identify the resulting gate.
P5. What does X do to ∣−⟩? Give the resulting state and explain why measuring it in the standard basis can't tell the difference.
P6. Verify Rz(π)=e−iπ/2Z=−iZ. Why is Rz(π) alone physically identical to Z?
P7. Write out ∣+⟩⊗∣1⟩ as a 4-vector. If this is "q1 = |+⟩, q0 = |1⟩" in Qiskit convention, which bitstrings can be measured and with what probabilities?
P8. Prove 21(∣00⟩+∣11⟩) is entangled (no product decomposition exists).
P9. Apply CNOT (control q0, target q1) to ∣+⟩ on q0 and ∣0⟩ on q1, i.e. the state 21(∣00⟩+∣01⟩) written as ∣q1q0⟩. What comes out?
A4.HZH=X. (Compute: ZH=21(1−111), then H(ZH)=(0110).) H swaps the X and Z bases.
A5.X∣−⟩=21(X∣0⟩−X∣1⟩)=21(∣1⟩−∣0⟩)=−∣−⟩. Only a global phase changed; standard-basis probabilities are 50/50 before AND after, and global phase is unobservable.
A6.Rz(π)=(e−iπ/200eiπ/2)=(−i00i)=−i(100−1)=−iZ. The factor −i is a global phase ⇒ same physical action as Z (but Operator(rz(π)) == Operator(z) is False while .equiv is True).
A7.∣+⟩⊗∣1⟩=21(11)⊗(01)=21(0,1,0,1)T, i.e. 21(∣01⟩+∣11⟩) reading ∣q1q0⟩. Measured bitstrings: '01' and '11', 50% each — q0 is always 1 (rightmost bit), q1 is random. In code: plus.tensor(one) since a.tensor(b) puts b (here ∣1⟩) on qubit 0.
A8. Suppose (a0∣0⟩+a1∣1⟩)⊗(b0∣0⟩+b1∣1⟩) has amplitudes a0b0=21, a0b1=0, a1b0=0, a1b1=21. From a0b1=0: either a0=0 (contradicts a0b0=0) or b1=0 (contradicts a1b1=0). No factorization ⇒ entangled. ∎
A9. CNOT maps ∣00⟩↦∣00⟩ and (control q0 = 1) ∣01⟩↦∣11⟩. Result: 21(∣00⟩+∣11⟩)=∣Φ+⟩ — the Bell state. This is exactly h(0); cx(0,1) from the lesson.
A10.U(π/2,0,π): cos4π=sin4π=21, so the matrix is (2121−eiπ21eiπ21)=21(111−1)=H. ✓
Self-check before starting lesson.md: you should be able to write from memory the matrices for X, Y, Z, H, S, T, P(λ), Rx, Ry, Rz, and CNOT, and state the Born rule and the tensor-product recipe. If not, redo P2–P4 and re-read §3.