microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
katas/content/multi_qubit_systems/prepare_superposition/solution.md
18lines · modecode
| 1 | We begin in the same state as the previous excercise: |
| 2 | $$ \begin{bmatrix} 1 \\\ 0 \\\ 0 \\\ 0 \end{bmatrix} = \begin{bmatrix} 1 \\\ 0 \end{bmatrix} \otimes \begin{bmatrix} 1 \\\ 0 \end{bmatrix} = |0\rangle \otimes |0\rangle$$ |
| 3 | |
| 4 | The goal state can be separated as follows: |
| 5 | $$ \frac{1}{\sqrt2} \begin{bmatrix} 1 \\\ -1 \\\ 0 \\\ 0 \end{bmatrix} = \begin{bmatrix} 1 \\\ 0 \end{bmatrix} \otimes \frac{1}{\sqrt2}\begin{bmatrix} 1 \\\ -1 \end{bmatrix} = |0\rangle \otimes \frac{1}{\sqrt2}\big(|0\rangle - |1\rangle\big)$$ |
| 6 | |
| 7 | This means that the first qubit is already in the state we want it to be, but the second qubit needs to be transformed from the $ \begin{bmatrix} 1 \\\ 0 \end{bmatrix} $ into $ \frac{1}{\sqrt{2}}\begin{bmatrix} 1 \\\ -1\end{bmatrix}$ state. |
| 8 | |
| 9 | First, we apply the **X** gate to the second qubit; this performs the following transformation: |
| 10 | $$ X |0\rangle = \begin{bmatrix}0 & 1 \\\ 1 & 0 \end{bmatrix} \cdot \begin{bmatrix}1 \\\ 0 \end{bmatrix} = \begin{bmatrix} 0 \\\ 1 \end{bmatrix} = |1\rangle $$ |
| 11 | |
| 12 | Second, we apply the **H** gate to the second qubit; this transforms its state into the desired one: |
| 13 | $$ H|1\rangle = \frac{1}{\sqrt2}\begin{bmatrix} 1 & 1 \\\ 1 & -1 \end{bmatrix} \cdot \begin{bmatrix} 0 \\\ 1 \end{bmatrix} = \frac{1}{\sqrt2}\begin{bmatrix} 1 \\\ -1 \end{bmatrix}$$ |
| 14 | |
| 15 | @[solution]({ |
| 16 | "id": "multi_qubit_systems__prepare_superposition_solution", |
| 17 | "codePath": "Solution.qs" |
| 18 | }) |