microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
katas/content/random_numbers/random_bit/solution.md
23lines · modecode
| 1 | The state of single qubit can be represented as a two-dimensional column vector $\begin{bmatrix} \alpha\\ \beta \end{bmatrix}$, where $\alpha$ and $\beta$ are complex numbers that satisfy $|\alpha|^2 + |\beta|^2 = 1$. When we measure the qubit, we get either 0 with probability $|\alpha|^2$ or 1 with probability $|\beta|^2$. Essentially we can control probablity of measurement outcome by setting the right amplitudes of basis states. |
| 2 | |
| 3 | When we allocate the qubit in Q#, amplitudes $\alpha$ and $\beta$ are 1 and 0, respectively. Now our goal is set equal amplitudes for $\alpha$ and $\beta$ for absolute randomness. We can achieve that by simply applying Hadamard gate to the initial state $|0\rangle$: |
| 4 | |
| 5 | $$ |
| 6 | H|0\rangle = |
| 7 | \frac{1}{\sqrt{2}} |
| 8 | \begin{bmatrix} 1 & 1 \\\ 1 & -1 \end{bmatrix} |
| 9 | \begin{bmatrix} 1 \\\ 0 \end{bmatrix} = |
| 10 | \frac{1}{\sqrt{2}} |
| 11 | \begin{bmatrix} 1 \cdot 1 + 1 \cdot 0 \\\ 1 \cdot 1 + (-1) \cdot 0 \end{bmatrix} = |
| 12 | \frac{1}{\sqrt{2}} |
| 13 | \begin{bmatrix} 1 \\\ 1 \end{bmatrix} |
| 14 | $$ |
| 15 | |
| 16 | Now, both 0 and 1 measurement outcomes occur with equal probablity of $|\frac{1}{\sqrt{2}}|^2 = \frac{1}{2}$. |
| 17 | |
| 18 | > Note: Since probability is the square of the absolute value of amplitude, we will get the same randomness by applying a Hadamard gate on base state $|1\rangle$. Try it out as an exercise! |
| 19 | |
| 20 | @[solution]({ |
| 21 | "id": "random_numbers__random_bit_solution", |
| 22 | "codePath": "solution.qs" |
| 23 | }) |
| 24 | |