Pick a depth. Each prompt opens in your AI pre-loaded with the lesson. Click a row to preview the prompt.
Measurement is the only way classical information leaves a quantum computer, and it is irreversible — it is the unique non-unitary step in the model. The Born rule says: when you measure in the computational basis, you get outcome with probability and outcome with probability , and after the measurement the state collapses to whichever basis state you observed. This is the bottleneck that makes quantum algorithms hard to design: you have one shot per run to extract a number, and you have to engineer the amplitudes so that the useful answer has high probability while the wrong answers cancel by interference. Every quantum cryptanalytic attack — Shor, Grover, Simon — is structured around this constraint, and every quantum-key-distribution protocol uses it as a security primitive (the eavesdropper cannot measure without collapsing).
A measurement in the computational basis is described by the projectors and . Outcome occurs with probability , and the post-measurement state is .
// main.go
// go run main.go
package main
import (
"fmt"
"math"
"math/rand/v2"
)
// measureZ samples `shots` times from a qubit state psi = [alpha, beta]
// and returns counts for outcome 0 and 1, plus the theoretical probabilities.
func measureZ(psi [2]complex128, shots int, rng *rand.Rand) (map[int]int, [2]float64) {
p0 := math.Pow(cmplxAbs(psi[0]), 2)
p1 := math.Pow(cmplxAbs(psi[1]), 2)
counts := map[int]int{0: 0, 1: 0}
for range shots {
if rng.Float64() < p0 {
counts[0]++
} else {
counts[1]++
}
}
return counts, [2]float64{p0, p1}
}
func cmplxAbs(c complex128) float64 {
return math.Sqrt(real(c)*real(c) + imag(c)*imag(c))
}
func main() {
// State: (sqrt(0.7) |0> + sqrt(0.3) |1>)
psi := [2]complex128{complex(math.Sqrt(0.7), 0), complex(math.Sqrt(0.3), 0)}
shots := 10_000
rng := rand.New(rand.NewPCG(42, 0))
counts, theory := measureZ(psi, shots, rng)
fmt.Printf("theoretical (p0, p1) = (%g, %g)\n", theory[0], theory[1])
fmt.Printf("empirical counts = map[0:%d 1:%d]\n", counts[0], counts[1])
fmt.Printf("empirical fractions = map[0:%g 1:%g]\n",
float64(counts[0])/float64(shots),
float64(counts[1])/float64(shots))
}go run main.go