diff --git a/katas/content/single_qubit_gates/amplitude_change/solution.md b/katas/content/single_qubit_gates/amplitude_change/solution.md index 561d1c2a78..589ea6b829 100644 --- a/katas/content/single_qubit_gates/amplitude_change/solution.md +++ b/katas/content/single_qubit_gates/amplitude_change/solution.md @@ -1,4 +1,4 @@ -We can recognize that we need to use one of the rotation gates Rx, Ry, and Rz (named because they "rotate" the qubit state in the three dimensional space visualized as the Bloch sphere about the x, y, and z axes, respectively), since they involve angle parameters. Of these three gates, only Ry rotates the basis states $\ket{0}$ and $\ket{1}$ to have real amplitudes (the other two gates introduce complex coefficients). +You can recognize that you need to use one of the rotation gates Rx, Ry, and Rz (named because they "rotate" the qubit state in the three dimensional space visualized as the Bloch sphere about the x, y, and z axes, respectively), since they involve angle parameters. Of these three gates, only Ry rotates the basis states $\ket{0}$ and $\ket{1}$ to have real amplitudes (the other two gates introduce complex coefficients). As a reminder, @@ -20,8 +20,8 @@ R_y(\theta)\ket{0} = $$ Recall that when applying a gate, you can tell what its matrix does to the basis states by looking at its columns: the first column of the matrix is the state into which it will transform the $\ket{0}$ state, and the second column is the state into which it will transform the $\ket{1}$ state. -One of the examples used by the testing harness has $\beta = 0.6, \gamma = 0.8$ and $\alpha = \frac{\pi}{3} = 1.0472$. -Since $\cos \frac{\pi}{3} = 0.5$ and $\sin \frac{\pi}{3} = 0.8660$, working to 4 decimal places, we can use $\frac{\theta}{2} = \alpha$ to compute: +One of the examples used by the testing harness has $\beta = 0.6, \gamma = 0.8$ and $\alpha = \frac{\pi}{3} ≈ 1.0472$. +Since $\cos \frac{\pi}{3} = 0.5$ and $\sin \frac{\pi}{3} = 0.8660$, working to 4 decimal places, you can use $\frac{\theta}{2} = \alpha$ to compute: $$ R_{y}(\theta) \ket{\psi}= @@ -33,7 +33,7 @@ R_{y}(\theta) \ket{\psi}= \begin{bmatrix}-0.3928\\ 0.9196\\ \end{bmatrix} $$ -Notice that we used $\frac{\theta}{2} = \alpha$; this means that in the Q# code we need to pass the angle $\theta = 2\alpha$. +Notice that $\frac{\theta}{2} = \alpha$; this means that in the Q# code you need to pass the angle $\theta = 2\alpha$. @[solution]({ "id": "single_qubit_gates__amplitude_change_solution", diff --git a/katas/content/single_qubit_gates/basis_change/solution.md b/katas/content/single_qubit_gates/basis_change/solution.md index 3f53e0b1f5..6de576453f 100644 --- a/katas/content/single_qubit_gates/basis_change/solution.md +++ b/katas/content/single_qubit_gates/basis_change/solution.md @@ -1,4 +1,4 @@ -We can recognize that the Hadamard gate changes states $\ket{0}$ and $\ket{1}$ to $\ket{+}$ and $\ket{-}$, respectively, and vice versa. +You can recognize that the Hadamard gate changes states $\ket{0}$ and $\ket{1}$ to $\ket{+}$ and $\ket{-}$, respectively, and vice versa. As a reminder, the Hadamard gate is defined by the following matrix: @@ -6,7 +6,7 @@ $$ \frac{1}{\sqrt{2}}\begin{bmatrix}1 & 1 \\1 & -1\end{bmatrix} $$ -For example, we can work out $H\ket{1}$ as follows: +For example, you can work out $H\ket{1}$ as follows: $$ H\ket{1}= @@ -17,7 +17,7 @@ H\ket{1}= \frac{1}{\sqrt{2}} \big(\ket{0} - \ket{1}\big) = \ket{-} $$ -Similarly, we can consider the effect of the Hadamard gate on the superposition state $\ket{\psi} = 0.6\ket{0} + 0.8\ket{1}$ (rounding the numbers to 4 decimal places): +Similarly, you can consider the effect of the Hadamard gate on the superposition state $\ket{\psi} = 0.6\ket{0} + 0.8\ket{1}$ (rounding the numbers to 4 decimal places): $$ H|\psi⟩ = diff --git a/katas/content/single_qubit_gates/complex_phase/solution.md b/katas/content/single_qubit_gates/complex_phase/solution.md index 3455033b35..d18f534da3 100644 --- a/katas/content/single_qubit_gates/complex_phase/solution.md +++ b/katas/content/single_qubit_gates/complex_phase/solution.md @@ -1,11 +1,11 @@ -We know that: +You know that: $$ R1(\alpha)= \begin{bmatrix}1 & 0 \\ 0 & \color{red}{e^{i\alpha}}\end{bmatrix} $$ -So we have: +So you have: $$ R1(\beta \ket{0} + \gamma \ket{1}) = @@ -18,8 +18,8 @@ $$ > Suppose now that $\alpha = \frac{\pi}{2}$. > Then $e^{i\alpha}= \cos\frac{\pi}{2} + i\sin\frac{\pi}{2}$. -> And, since $\cos\frac{\pi}{2}= 0$ and $\sin\frac{\pi}{2} = 1$, then we have that $\cos\frac{\pi}{2} + i \sin\frac{\pi}{2} = i$, and -> $R1(\frac{\pi}{2}) = S$, which we used in the second solution to the task "Relative Phase i". +> And, since $\cos\frac{\pi}{2}= 0$ and $\sin\frac{\pi}{2} = 1$, then you have that $\cos\frac{\pi}{2} + i \sin\frac{\pi}{2} = i$, and +> $R1(\frac{\pi}{2}) = S$, which you used in the second solution to the task "Relative Phase i". @[solution]({ "id": "single_qubit_gates__complex_phase_solution", diff --git a/katas/content/single_qubit_gates/global_phase_i/solution.md b/katas/content/single_qubit_gates/global_phase_i/solution.md index bfbd3d0f0c..e8a448e252 100644 --- a/katas/content/single_qubit_gates/global_phase_i/solution.md +++ b/katas/content/single_qubit_gates/global_phase_i/solution.md @@ -1,12 +1,12 @@ -We need to apply a gate which applies a global phase of $i$, i.e. $\ket{\psi} \rightarrow i\ket{\psi}$. +You need to apply a gate which applies a global phase of $i$, that is, $\ket{\psi} \rightarrow i\ket{\psi}$. The matrix representation of such a gate is $\begin{bmatrix} i & 0 \\ 0 & i \end{bmatrix} = i\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} = iI$. -Since we are restricted to the Pauli gates, we use the property that a product of any two distinct Pauli gates equals the third gate with a $+i$ or a $-i$ global phase, therefore the product of all three Pauli gates is $XYZ = iI$. +Since you're restricted to the Pauli gates, you can use the property that a product of any two distinct Pauli gates equals the third gate with a $+i$ or a $-i$ global phase, therefore the product of all three Pauli gates is $XYZ = iI$. $$ \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}\begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} = \begin{bmatrix} i & 0 \\ 0 & i \end{bmatrix} $$ -> Remember the rightmost gates in mathematical notation are applied first in Q# code. Hence we first apply the $Z$ gate, followed by the $Y$ gate, and finally the $X$ gate. +> Remember the rightmost gates in mathematical notation are applied first in Q# code. Hence you first apply the $Z$ gate, followed by the $Y$ gate, and finally the $X$ gate. @[solution]({ "id": "single_qubit_gates__global_phase_i_solution", diff --git a/katas/content/single_qubit_gates/global_phase_minusone/index.md b/katas/content/single_qubit_gates/global_phase_minusone/index.md index 9d4d763f53..0ed2b5b89a 100644 --- a/katas/content/single_qubit_gates/global_phase_minusone/index.md +++ b/katas/content/single_qubit_gates/global_phase_minusone/index.md @@ -2,6 +2,6 @@ **Goal**: Change the state of the qubit to $- \beta \ket{0} - \gamma \ket{1}$. -> This change on its own is not observable - there is no experiment you can do on a standalone qubit to figure out whether it acquired the global phase or not. +> This change on its own is not observable - there's no experiment you can do on a standalone qubit to figure out whether it acquired the global phase or not. > However, you can use a controlled version of this operation to observe the global phase it introduces. > This is used in later katas as part of more complicated tasks. diff --git a/katas/content/single_qubit_gates/global_phase_minusone/solution.md b/katas/content/single_qubit_gates/global_phase_minusone/solution.md index 5b15cb430e..93cffd61d4 100644 --- a/katas/content/single_qubit_gates/global_phase_minusone/solution.md +++ b/katas/content/single_qubit_gates/global_phase_minusone/solution.md @@ -1,10 +1,10 @@ -A global phase is a phase factor that multiplies the entire quantum state. It is not observable when measuring the qubit's state, as the probabilities remain unchanged. However, it is significant when considering quantum state transformations. +A global phase is a phase factor that multiplies the entire quantum state. It isn't observable when measuring the qubit's state, as the probabilities remain unchanged. However, it's significant when considering quantum state transformations. Our task is to implement an operation that transforms the given qubit state from $\ket{\psi} = \beta \ket{0} + \gamma \ket{1}$ to $- \beta \ket{0} - \gamma \ket{1}$. -To do that, we utilize a sequence of gates. The Pauli Z gate followed by the Pauli X gate can be used to achieve this effect when applied in succession twice. +To do that, you use a sequence of gates. The Pauli Z gate followed by the Pauli X gate can be used to achieve this effect when applied in succession twice. -1. **Apply the Pauli Z gate**: The Z gate multiplies the $\ket{1}$ state by $-1$ but does not change the $\ket{0}$ state, converting our state $\beta \ket{0} + \gamma \ket{1}$ to $\beta \ket{0} - \gamma \ket{1}$. +1. **Apply the Pauli Z gate**: The Z gate multiplies the $\ket{1}$ state by $-1$ but doen't change the $\ket{0}$ state, converting our state $\beta \ket{0} + \gamma \ket{1}$ to $\beta \ket{0} - \gamma \ket{1}$. The matrix representation of the Z gate is: @@ -13,7 +13,7 @@ To do that, we utilize a sequence of gates. The Pauli Z gate followed by the Pau \begin{bmatrix}1 & 0 \\ 0 & -1 \end{bmatrix} $$ -2. **Apply the Pauli X gate**: The X gate flips the $\ket{0}$ and $\ket{1}$ basis states, converting our $\beta \ket{0} - \gamma \ket{1}$ state to $\beta \ket{1} - \gamma \ket{0}$. +2. **Apply the Pauli X gate**: The X gate flips the $\ket{0}$ and $\ket{1}$ basis states, converting $\beta \ket{0} - \gamma \ket{1}$ state to $\beta \ket{1} - \gamma \ket{0}$. The matrix representation of the X gate is: @@ -22,7 +22,7 @@ To do that, we utilize a sequence of gates. The Pauli Z gate followed by the Pau \begin{bmatrix}0 & 1 \\ 1 & 0\end{bmatrix} $$ -3. **Repeat the Z and X gates**: Applying the Z gate again will multiply the $\ket{1}$ state (that used to be $\ket{0}$), converting our state $\beta \ket{1} - \gamma \ket{0}$ to $- \beta \ket{1} - \gamma \ket{0}$. Finally, the second X gate will restore the original basis states, but now with both amplitudes having acquired an additional phase of $-1$. This means our state has been multiplied by $-1$, achieving the required global phase change. +3. **Repeat the Z and X gates**: Applying the Z gate again will multiply the $\ket{1}$ state (that used to be $\ket{0}$), converting the state $\beta \ket{1} - \gamma \ket{0}$ to $- \beta \ket{1} - \gamma \ket{0}$. Finally, the second X gate will restore the original basis states, but now with both amplitudes having acquired an additional phase of $-1$. This means the state has been multiplied by $-1$, achieving the required global phase change. @[solution]({ "id": "single_qubit_gates__global_phase_minusone_solution", diff --git a/katas/content/single_qubit_gates/index.md b/katas/content/single_qubit_gates/index.md index e27966609b..04d3acee84 100644 --- a/katas/content/single_qubit_gates/index.md +++ b/katas/content/single_qubit_gates/index.md @@ -15,15 +15,17 @@ This kata introduces you to single-qubit gates. Quantum gates are the quantum co **What you should know to start working on this kata:** -- Basic linear algebra +- Basic knowledge of linear algebra - The concept of qubit +If you need a refresher on these topics, you can check out the previous katas. + @[section]({ "id": "single_qubit_gates__basics", "title": "The Basics" }) -There are certain properties common to all quantum gates. This section will introduce those properties, using the $X$ gate as an example. +There are certain properties common to all quantum gates. This section introduces those properties, using the $X$ gate as an example. ## Matrix Representation @@ -74,7 +76,7 @@ Matrix multiplication is associative, so this is equivalent to multiplying the $ >Note that matrix multiplication isn’t commutative, thus $(BA) \neq (AB)$. -All quantum gates are reversible - there is another gate which will undo any given gate's transformation, returning the qubit to its original state. +All quantum gates are reversible, that is, there exists another gate which will undo any given gate's transformation, returning the qubit to its original state. This means that when dealing with quantum gates, information about qubit states is never lost, as opposed to classical logic gates, some of which destroy information. Quantum gates are represented by unitary matrices, so the inverse of a gate is its adjoint; these terms are also used interchangeably in quantum computing. @@ -84,7 +86,7 @@ There is a simple way to find out what a gate does to the two computational basi $$A = \begin{bmatrix} \epsilon & \zeta \\ \eta & \mu \end{bmatrix}$$ -Watch what happens when we apply it to these states: +Watch what happens when applying $A$ to these states: $$ A\ket{0} = @@ -102,7 +104,7 @@ A\ket{1} = \begin{bmatrix} \zeta \\ \mu \end{bmatrix} = \zeta\ket{0} + \mu\ket{1} $$ -Notice that applying the gate to the $\ket{0}$ state transforms it into the state written as the first column of the gate's matrix. Likewise, applying the gate to the $\ket{1}$ state transforms it into the state written as the second column. This holds true for any quantum gate, including, of course, the $X$ gate: +Notice that applying the $A$ gate to the $\ket{0}$ state transforms it into the state written as the first column of the gate's matrix. Likewise, applying the $A$ gate to the $\ket{1}$ state transforms it into the state written as the second column. This holds true for any quantum gate, including, of course, the $X$ gate: $$X = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}$$ @@ -126,7 +128,7 @@ That is, applying a gate to a qubit in superposition is equivalent to applying t "title": "Ket-Bra Representation" }) -There is another way to represent quantum gates, this time using Dirac notation. However, the kets we've been using aren't enough to represent arbitrary matrices. We need to introduce another piece of notation: the **bra** (this is why Dirac notation is sometimes called **bra-ket notation**). +There is another way to represent quantum gates, this time using Dirac notation. However, kets aren't enough to represent arbitrary matrices. An additional notation is required: the **bra** (this is why Dirac notation is sometimes called **bra-ket notation**). Recall that kets represent column vectors; a bra is a ket's row vector counterpart. For any ket $\ket{\psi}$, the corresponding bra is its adjoint (conjugate transpose): $\bra{\psi} = \ket{\psi}^\dagger$. @@ -161,7 +163,7 @@ Some examples: Kets and bras give us a neat way to express inner and outer products. The inner product of $\ket{\phi}$ and $\ket{\psi}$ is the matrix product of $\bra{\phi}$ and $\ket{\psi}$, denoted as $\braket{\phi|\psi}$, and their outer product is the matrix product of $\ket{\phi}$ and $\bra{\psi}$, denoted as $\ket{\phi}\bra{\psi}$. Notice that the norm of $\ket{\psi}$ is $\sqrt{\braket{\psi|\psi}}$. -This brings us to representing matrices. Recall that the outer product of two vectors of the same size produces a square matrix. We can use a linear combination of several outer products of simple vectors (such as basis vectors) to express any square matrix. For example, the $X$ gate can be expressed as follows: +This leads to the representation of matrices via outer products. Recall that the outer product of two vectors of the same size produces a square matrix. You can use a linear combination of several outer products of simple vectors (such as basis vectors) to express any square matrix. For example, the $X$ gate can be expressed as follows: $$X = \ket{0}\bra{1} + \ket{1}\bra{0}$$ @@ -177,7 +179,7 @@ This representation can be used to carry out calculations in Dirac notation with $$X\ket{0} = \big(\ket{0}\bra{1} + \ket{1}\bra{0}\big)\ket{0} = \ket{0}\braket{1|0} + \ket{1}\braket{0|0} = \ket{0}\big(\braket{1|0}\big) + \ket{1}\big(\braket{0|0}\big) = \ket{0}(0) + \ket{1}(1) = \ket{1}$$ -> That last step may seem a bit confusing. Recall that $\ket{0}$ and $\ket{1}$ form an **orthonormal basis**. That is, they are both normalized, and they are orthogonal to each other. +> That last step may seem a bit confusing. Recall that $\ket{0}$ and $\ket{1}$ form an **orthonormal basis**. That is, they're both normalized, and they're orthogonal to each other. > > A vector is normalized if its norm is equal to $1$, which only happens if its inner product with itself is equal to $1$. This means that $\braket{0|0} = \braket{1|1} = 1$ > @@ -193,7 +195,7 @@ $$A = a_{00} \ket{0}\bra{0} + a_{01} \ket{0}\bra{1} + a_{10} \ket{1}\bra{0} + a_ "title": "Ket-Bra Decomposition" }) -This section describes a more formal process of finding the ket-bra decompositions of quantum gates. This section is not necessary to start working with quantum gates, so feel free to skip it for now, and come back to it later. +This section describes a more formal process of finding the ket-bra decompositions of quantum gates. This section isn't necessary to start working with quantum gates, so feel free to skip it for now, and come back to it later. You can use the properties of _eigenvalues_ and _eigenvectors_ to find the ket-bra decomposition of any gate. Given a gate $A$ and the orthogonal vectors $\ket{\phi}$ and $\ket{\psi}$, if: @@ -221,7 +223,7 @@ $$= \ket{0}\bra{1} + \ket{1}\bra{0}$$ "title": "Pauli Gates" }) -This section introduces some of the common single-qubit gates, including their matrix form, their ket-bra decomposition, and a brief "cheatsheet" listing their effect on some common qubit states. +This section introduces some of the common single-qubit gates, including their matrix form, their ket-bra decomposition, and a brief "cheat sheet" listing their effect on some common qubit states. You can use a tool called Quirk to visualize how these gates interact with various qubit states. @@ -312,16 +314,16 @@ Here are several properties of the Pauli gates that are easy to verify and conve The following example contains code demonstrating how to apply gates in Q#. It sets up a series of quantum states, and then shows the result of applying the $X$ gate to each one. -In the previous kata we discussed that qubit state in Q# cannot be directly assigned or accessed. The same logic is extended to quantum gates: applying a gate to a qubit modifies the internal state of that qubit, but doesn't return the resulting state of the qubit. This is why we never assign the output of these gates to any variables in this demo - they don't produce any output. +The previous kata mentioned that qubit state in Q# cannot be directly assigned or accessed. The same logic is extended to quantum gates: applying a gate to a qubit modifies the internal state of that qubit but doesn't return the resulting state of the qubit. That's the reason why you never assign the output of these gates to any variables in this demo - they don't produce any output. -The same principle applies to applying several gates in a row to a qubit. In the mathematical notation, applying an $X$ gate followed by a $Z$ gate to a state $\ket{\psi}$ is denoted as $Z(X(\ket{\psi}))$, because the result of applying a gate to a state is another state. In Q#, applying a gate doesn't return anything, so you can't use its output as an input to another gate - something like `Z(X(q))` will not produce the expected result. Instead, to apply several gates to the same qubit, you need to call them separately in the order in which they are applied: +The same principle applies to applying several gates in a row to a qubit. In the mathematical notation, applying an $X$ gate followed by a $Z$ gate to a state $\ket{\psi}$ is denoted as $Z(X(\ket{\psi}))$, because the result of applying a gate to a state is another state. In Q#, applying a gate doesn't return anything, so you can't use its output as an input to another gate - something like `Z(X(q))` won't produce the expected result. Instead, to apply several gates to the same qubit, you need to call them separately in the order in which they're applied: ```qsharp X(q); Z(q); ``` -All the basic gates we will be covering in this kata are part of the Intrinsic namespace. We're also using the function DumpMachine to print the state of the quantum simulator. +All the basic gates covered in this kata are part of the Intrinsic namespace. Additionally, the function `DumpMachine` from the Diagnostics namespace is used to print the state of the quantum simulator. @[example]({"id": "single_qubit_gates__pauli_gates_in_qsharp_demo", "codePath": "./examples/PauliGates.qs"}) @@ -367,7 +369,7 @@ All the basic gates we will be covering in this kata are part of the Intrinsic n "title": "Identity Gate" }) -The identity gate is mostly here for completeness, at least for now. It will come in handy when dealing with multi-qubit systems and multi-qubit gates. It is represented by the identity matrix, and does not affect the state of the qubit. +The identity gate is mostly here for completeness, at least for now. It will come in handy when dealing with multi-qubit systems and multi-qubit gates. It's represented by the identity matrix, and doesn't affect the state of the qubit.