The RY(θ) gate rotates a single-qubit state about the Y axis. Applied to the default state, it keeps amplitudes real and acts like a dial for setting a biased coin's outcome probabilities. section 3.2.4
Use the RY gate to:
- Compose same-axis rotations by adding their angles: RY(θ₂)RY(θ₁) = RY(θ₁ + θ₂). section 3.2.4
- Encode a Bernoulli distribution by choosing θ so that cos²(θ/2) = p and sin²(θ/2) = 1 − p. section 3.5.1
- Encode a scaled number in the magnitude of an amplitude by setting θ = 2 arccos(x/scale). section 3.5.2
Encoding p = 0.7
Compute θ = 2 acos(√p), initialize a qubit, apply RY(θ), and inspect the state. The resulting probabilities are 0.7 for outcome 0 and 0.3 for outcome 1. section 3.5.1
from math import acos p = 0.7 theta = 2*acos(sqrt(p)) #1 s = init_state() transform(s, ry(theta)) #2 print_state(s)
Executable pseudocode shows angle calculation, state initialization, RY application, and state inspection for Bernoulli encoding. section 3.5.1

