From 81c5a50039af00bfde9d5dea2446613394661b36 Mon Sep 17 00:00:00 2001 From: Adam Kania <48769688+remilvus@users.noreply.github.com> Date: Thu, 28 Jul 2022 11:55:27 +0200 Subject: [PATCH 01/15] Fix latex rendering --- .../SingleQubitGates/SingleQubitGates.ipynb | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/tutorials/SingleQubitGates/SingleQubitGates.ipynb b/tutorials/SingleQubitGates/SingleQubitGates.ipynb index 29e1803115f..6f4a01a0bd4 100644 --- a/tutorials/SingleQubitGates/SingleQubitGates.ipynb +++ b/tutorials/SingleQubitGates/SingleQubitGates.ipynb @@ -47,8 +47,9 @@ "\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n", "\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} =\n", "\\begin{bmatrix} 0 \\cdot 1 + 1 \\cdot 0 \\\\ 1 \\cdot 1 + 0 \\cdot 0 \\end{bmatrix} =\n", - "\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} \\\\\n", - "X|1\\rangle =\n", + "\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}$$\n", + "\n", + "$$X|1\\rangle =\n", "\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n", "\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} =\n", "\\begin{bmatrix} 0 \\cdot 0 + 1 \\cdot 1 \\\\ 1 \\cdot 0 + 0 \\cdot 1 \\end{bmatrix} =\n", @@ -56,8 +57,9 @@ "\n", "The general case:\n", "\n", - "$$|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle \\\\\n", - "X|\\psi\\rangle =\n", + "$$|\\psi\\rangle = \\alpha|0\\rangle + \\beta|1\\rangle$$\n", + "\n", + "$$X|\\psi\\rangle =\n", "\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n", "\\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix} =\n", "\\begin{bmatrix} 0 \\cdot \\alpha + 1 \\cdot \\beta \\\\ 1 \\cdot \\alpha + 0 \\cdot \\beta \\end{bmatrix} =\n", @@ -92,8 +94,9 @@ "\\begin{bmatrix} \\epsilon & \\zeta \\\\ \\eta & \\mu \\end{bmatrix}\n", "\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} =\n", "\\begin{bmatrix} \\epsilon \\cdot 1 + \\zeta \\cdot 0 \\\\ \\eta \\cdot 1 + \\mu \\cdot 0 \\end{bmatrix} =\n", - "\\begin{bmatrix} \\epsilon \\\\ \\eta \\end{bmatrix} = \\epsilon|0\\rangle + \\eta|1\\rangle \\\\\n", - "A|1\\rangle =\n", + "\\begin{bmatrix} \\epsilon \\\\ \\eta \\end{bmatrix} = \\epsilon|0\\rangle + \\eta|1\\rangle$$\n", + "\n", + "$$A|1\\rangle =\n", "\\begin{bmatrix} \\epsilon & \\zeta \\\\ \\eta & \\mu \\end{bmatrix}\n", "\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} =\n", "\\begin{bmatrix} \\epsilon \\cdot 0 + \\zeta \\cdot 1 \\\\ \\eta \\cdot 0 + \\mu \\cdot 1 \\end{bmatrix} =\n", @@ -101,9 +104,11 @@ "\n", "Notice that applying the gate to the $|0\\rangle$ state transforms it into the state written as the first column of the gate's matrix. Likewise, applying the gate to the $|1\\rangle$ state transforms it into the state written as the second column. This holds true for any quantum gate, including, of course, the $X$ gate:\n", "\n", - "$$X = \\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix} \\\\\n", - "X|0\\rangle = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} = |1\\rangle \\\\\n", - "X|1\\rangle = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} = |0\\rangle$$\n", + "$$X = \\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$$\n", + "\n", + "$$X|0\\rangle = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} = |1\\rangle$$\n", + "\n", + "$$X|1\\rangle = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} = |0\\rangle$$\n", "\n", "Once you understand how a gate affects the computational basis states, you can easily find how it affects any state.\n", "Recall that any qubit state vector can be written as a linear combination of the basis states:\n", @@ -169,8 +174,9 @@ "\n", "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:\n", "\n", - "$$X = |0\\rangle\\langle1| + |1\\rangle\\langle0| \\\\\n", - "|0\\rangle\\langle1| + |1\\rangle\\langle0| =\n", + "$$X = |0\\rangle\\langle1| + |1\\rangle\\langle0|$$\n", + "\n", + "$$|0\\rangle\\langle1| + |1\\rangle\\langle0| =\n", "\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 0 & 1 \\end{bmatrix} +\n", "\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}\\begin{bmatrix} 1 & 0 \\end{bmatrix} =\n", "\\begin{bmatrix} 0 & 1 \\\\ 0 & 0 \\end{bmatrix} + \\begin{bmatrix} 0 & 0 \\\\ 1 & 0 \\end{bmatrix} =\n", @@ -207,8 +213,9 @@ ">\n", "> You can use the properties of [eigenvalues and eigenvectors](../LinearAlgebra/LinearAlgebra.ipynb#Part-III:-Eigenvalues-and-Eigenvectors) to find the ket-bra decomposition of any gate. Given a gate $A$, and its orthogonal eigenvectors $|\\phi\\rangle$ and $|\\psi\\rangle$, if:\n", ">\n", - "> $$A|\\phi\\rangle = x_\\phi|\\phi\\rangle \\\\\n", - "A|\\psi\\rangle = x_\\psi|\\psi\\rangle$$\n", + "> $$A|\\phi\\rangle = x_\\phi|\\phi\\rangle$$\n", + "\n", + "$$A|\\psi\\rangle = x_\\psi|\\psi\\rangle$$\n", ">\n", "> Then:\n", ">\n", @@ -216,14 +223,15 @@ ">\n", "> Let's use our $X$ gate as a simple example. The $X$ gate has two eigenvectors: $|+\\rangle = \\frac{1}{\\sqrt{2}}\\big(|0\\rangle + |1\\rangle\\big)$ and $|-\\rangle = \\frac{1}{\\sqrt{2}}\\big(|0\\rangle - |1\\rangle\\big)$. Their eigenvalues are $1$ and $-1$ respectively:\n", ">\n", - "> $$X|+\\rangle = |+\\rangle \\\\\n", - "X|-\\rangle = -|-\\rangle$$\n", + "> $$X|+\\rangle = |+\\rangle$$\n", + "\n", + "$$X|-\\rangle = -|-\\rangle$$\n", ">\n", "> Here's what the decomposition looks like:\n", ">\n", - "> $$X = |+\\rangle\\langle+| - |-\\rangle\\langle-| = \\\\\n", - "= \\frac{1}{2}\\big[\\big(|0\\rangle + |1\\rangle\\big)\\big(\\langle0| + \\langle1|\\big) - \\big(|0\\rangle - |1\\rangle\\big)\\big(\\langle0| - \\langle1|\\big)\\big] = \\\\\n", - "= \\frac{1}{2}\\big(\\color{red}{|0\\rangle\\langle0|} + |0\\rangle\\langle1| + |1\\rangle\\langle0| + \\color{red}{|1\\rangle\\langle1|} - \\color{red}{|0\\rangle\\langle0|} + |0\\rangle\\langle1| + |1\\rangle\\langle0| - \\color{red}{|1\\rangle\\langle1|}\\big) = \\\\\n", + "> $$X = |+\\rangle\\langle+| - |-\\rangle\\langle-| =$$\n", + "$$= \\frac{1}{2}\\big[\\big(|0\\rangle + |1\\rangle\\big)\\big(\\langle0| + \\langle1|\\big) - \\big(|0\\rangle - |1\\rangle\\big)\\big(\\langle0| - \\langle1|\\big)\\big] = \\\\\n", + "= \\frac{1}{2}\\big({\\color{red}{|0\\rangle\\langle0|}} + |0\\rangle\\langle1| + |1\\rangle\\langle0| + {\\color{red}{|1\\rangle\\langle1|}} - {\\color{red}{|0\\rangle\\langle0|}} + |0\\rangle\\langle1| + |1\\rangle\\langle0| - {\\color{red}{|1\\rangle\\langle1|}}\\big) = \\\\\n", "= \\frac{1}{2}\\big(2|0\\rangle\\langle1| + 2|1\\rangle\\langle0|\\big) = |0\\rangle\\langle1| + |1\\rangle\\langle0|$$" ] }, From 2e197c10f9ee5c19987555eb43dfbd2812d7deda Mon Sep 17 00:00:00 2001 From: Adam Kania <48769688+remilvus@users.noreply.github.com> Date: Fri, 29 Jul 2022 08:27:28 +0200 Subject: [PATCH 02/15] Fix ket-bra note --- tutorials/SingleQubitGates/SingleQubitGates.ipynb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tutorials/SingleQubitGates/SingleQubitGates.ipynb b/tutorials/SingleQubitGates/SingleQubitGates.ipynb index 6f4a01a0bd4..5a4e8d883de 100644 --- a/tutorials/SingleQubitGates/SingleQubitGates.ipynb +++ b/tutorials/SingleQubitGates/SingleQubitGates.ipynb @@ -214,8 +214,7 @@ "> You can use the properties of [eigenvalues and eigenvectors](../LinearAlgebra/LinearAlgebra.ipynb#Part-III:-Eigenvalues-and-Eigenvectors) to find the ket-bra decomposition of any gate. Given a gate $A$, and its orthogonal eigenvectors $|\\phi\\rangle$ and $|\\psi\\rangle$, if:\n", ">\n", "> $$A|\\phi\\rangle = x_\\phi|\\phi\\rangle$$\n", - "\n", - "$$A|\\psi\\rangle = x_\\psi|\\psi\\rangle$$\n", + "> $$A|\\psi\\rangle = x_\\psi|\\psi\\rangle$$\n", ">\n", "> Then:\n", ">\n", @@ -224,15 +223,14 @@ "> Let's use our $X$ gate as a simple example. The $X$ gate has two eigenvectors: $|+\\rangle = \\frac{1}{\\sqrt{2}}\\big(|0\\rangle + |1\\rangle\\big)$ and $|-\\rangle = \\frac{1}{\\sqrt{2}}\\big(|0\\rangle - |1\\rangle\\big)$. Their eigenvalues are $1$ and $-1$ respectively:\n", ">\n", "> $$X|+\\rangle = |+\\rangle$$\n", - "\n", - "$$X|-\\rangle = -|-\\rangle$$\n", + "> $$X|-\\rangle = -|-\\rangle$$\n", ">\n", "> Here's what the decomposition looks like:\n", ">\n", "> $$X = |+\\rangle\\langle+| - |-\\rangle\\langle-| =$$\n", - "$$= \\frac{1}{2}\\big[\\big(|0\\rangle + |1\\rangle\\big)\\big(\\langle0| + \\langle1|\\big) - \\big(|0\\rangle - |1\\rangle\\big)\\big(\\langle0| - \\langle1|\\big)\\big] = \\\\\n", - "= \\frac{1}{2}\\big({\\color{red}{|0\\rangle\\langle0|}} + |0\\rangle\\langle1| + |1\\rangle\\langle0| + {\\color{red}{|1\\rangle\\langle1|}} - {\\color{red}{|0\\rangle\\langle0|}} + |0\\rangle\\langle1| + |1\\rangle\\langle0| - {\\color{red}{|1\\rangle\\langle1|}}\\big) = \\\\\n", - "= \\frac{1}{2}\\big(2|0\\rangle\\langle1| + 2|1\\rangle\\langle0|\\big) = |0\\rangle\\langle1| + |1\\rangle\\langle0|$$" + "> $$= \\frac{1}{2}\\big[\\big(|0\\rangle + |1\\rangle\\big)\\big(\\langle0| + \\langle1|\\big) - \\big(|0\\rangle - |1\\rangle\\big)\\big(\\langle0| - \\langle1|\\big)\\big] =$$\n", + "> $$= \\frac{1}{2}\\big({\\color{red}{|0\\rangle\\langle0|}} + |0\\rangle\\langle1| + |1\\rangle\\langle0| + {\\color{red}{|1\\rangle\\langle1|}} - {\\color{red}{|0\\rangle\\langle0|}} + |0\\rangle\\langle1| + |1\\rangle\\langle0| - {\\color{red}{|1\\rangle\\langle1|}}\\big) =$$\n", + "> $$= \\frac{1}{2}\\big(2|0\\rangle\\langle1| + 2|1\\rangle\\langle0|\\big) = |0\\rangle\\langle1| + |1\\rangle\\langle0|$$" ] }, { From 7faa5cdca372e8d4e603dfc67e650a67414de224 Mon Sep 17 00:00:00 2001 From: Adam Kania <48769688+remilvus@users.noreply.github.com> Date: Fri, 29 Jul 2022 08:57:31 +0200 Subject: [PATCH 03/15] Fix rendering in ComplexArithmetic --- tutorials/ComplexArithmetic/ComplexArithmetic.ipynb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tutorials/ComplexArithmetic/ComplexArithmetic.ipynb b/tutorials/ComplexArithmetic/ComplexArithmetic.ipynb index 3188b2bf0ae..e0b20103798 100644 --- a/tutorials/ComplexArithmetic/ComplexArithmetic.ipynb +++ b/tutorials/ComplexArithmetic/ComplexArithmetic.ipynb @@ -68,10 +68,10 @@ "\n", "As we said before, $i$ can't be a real number. In that case, we'll call it an **imaginary unit**. However, there is no reason for us to define it as acting any different from any other number, other than the fact that $i^2 = -1$:\n", "\n", - "$$i + i = 2i \\\\\n", - "i - i = 0 \\\\\n", - "-1 \\cdot i = -i \\\\\n", - "(-i)^{2} = -1$$\n", + "$$i + i = 2i$$\n", + "$$i - i = 0$$\n", + "$$-1 \\cdot i = -i$$\n", + "$$(-i)^{2} = -1$$\n", "\n", "We'll call the number $i$ and its real multiples **imaginary numbers**.\n", "\n", @@ -251,8 +251,8 @@ "\n", "Another property of the conjugate is that it distributes over both complex addition and complex multiplication:\n", "\n", - "$$\\overline{x + y} = \\overline{x} + \\overline{y} \\\\\n", - "\\overline{x \\cdot y} = \\overline{x} \\cdot \\overline{y}$$" + "$$\\overline{x + y} = \\overline{x} + \\overline{y}$$\n", + "$$\\overline{x \\cdot y} = \\overline{x} \\cdot \\overline{y}$$" ] }, { From efe0b988ad26d6f1f86cda43034efdce7a69a33a Mon Sep 17 00:00:00 2001 From: Adam Kania <48769688+remilvus@users.noreply.github.com> Date: Fri, 29 Jul 2022 09:04:38 +0200 Subject: [PATCH 04/15] Fin rendering in LinearAlgebra --- tutorials/LinearAlgebra/LinearAlgebra.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tutorials/LinearAlgebra/LinearAlgebra.ipynb b/tutorials/LinearAlgebra/LinearAlgebra.ipynb index aa939469382..a1bb9eea13c 100644 --- a/tutorials/LinearAlgebra/LinearAlgebra.ipynb +++ b/tutorials/LinearAlgebra/LinearAlgebra.ipynb @@ -405,8 +405,8 @@ "\n", "Another, equivalent definition highlights what makes this an interesting property. For any matrices $B$ and $C$ of compatible sizes:\n", "\n", - "$$A^{-1}(AB) = A(A^{-1}B) = B \\\\\n", - "(CA)A^{-1} = (CA^{-1})A = C$$\n", + "$$A^{-1}(AB) = A(A^{-1}B) = B$$\n", + "$$(CA)A^{-1} = (CA^{-1})A = C$$\n", "\n", "A square matrix has a property called the **determinant**, with the determinant of matrix $A$ being written as $|A|$. A matrix is invertible if and only if its determinant isn't equal to $0$.\n", "\n", @@ -948,8 +948,8 @@ " A_{n-1,0} \\cdot \\color{blue} {\\begin{bmatrix}B_{0,0} & \\dotsb & B_{0,l-1} \\\\ \\vdots & \\ddots & \\vdots \\\\ B_{k-1,0} & \\dotsb & B_{k-1,l-1} \\end{bmatrix}} & \\dotsb &\n", " A_{n-1,m-1} \\cdot \\color{red} {\\begin{bmatrix}B_{0,0} & \\dotsb & B_{0,l-1} \\\\ \\vdots & \\ddots & \\vdots \\\\ B_{k-1,0} & \\dotsb & B_{k-1,l-1} \\end{bmatrix}}\n", "\\end{bmatrix}\n", - "= \\\\\n", - "=\n", + "=$$\n", + "$$=\n", "\\begin{bmatrix}\n", " A_{0,0} \\cdot \\color{red} {B_{0,0}} & \\dotsb & A_{0,0} \\cdot \\color{red} {B_{0,l-1}} & \\dotsb & A_{0,m-1} \\cdot \\color{blue} {B_{0,0}} & \\dotsb & A_{0,m-1} \\cdot \\color{blue} {B_{0,l-1}} \\\\\n", " \\vdots & \\ddots & \\vdots & \\dotsb & \\vdots & \\ddots & \\vdots \\\\\n", From 9fa3c341a68e79e42ef6b31bc0d5726c552effb6 Mon Sep 17 00:00:00 2001 From: Adam Kania <48769688+remilvus@users.noreply.github.com> Date: Fri, 29 Jul 2022 16:34:47 +0200 Subject: [PATCH 05/15] Fix rendering in BasicGates --- BasicGates/BasicGates.ipynb | 20 ++-- BasicGates/Workbook_BasicGates.ipynb | 164 ++++++++++++++++++++++++--- 2 files changed, 157 insertions(+), 27 deletions(-) diff --git a/BasicGates/BasicGates.ipynb b/BasicGates/BasicGates.ipynb index 2fe2a0dc12a..c1704739032 100644 --- a/BasicGates/BasicGates.ipynb +++ b/BasicGates/BasicGates.ipynb @@ -214,7 +214,7 @@ "\n", "**Input:** A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.\n", "\n", - "**Goal:** Change the qubit state to $\\alpha |0\\rangle + \\color{red}i\\beta |1\\rangle$ (add a relative phase $i$ to $|1\\rangle$ component of the superposition).\n" + "**Goal:** Change the qubit state to $\\alpha |0\\rangle + {\\color{red}i}\\beta |1\\rangle$ (add a relative phase $i$ to $|1\\rangle$ component of the superposition).\n" ] }, { @@ -251,7 +251,7 @@ "**Goal:** Change the state of the qubit as follows:\n", "- If the qubit is in state $|0\\rangle$, don't change its state.\n", "- If the qubit is in state $|1\\rangle$, change its state to $e^{i\\alpha} |1\\rangle$.\n", - "- If the qubit is in superposition, change its state according to the effect on basis vectors: $\\beta |0\\rangle + \\color{red}{e^{i\\alpha}} \\gamma |1\\rangle$.\n" + "- If the qubit is in superposition, change its state according to the effect on basis vectors: $\\beta |0\\rangle + {\\color{red}{e^{i\\alpha}}} \\gamma |1\\rangle$.\n" ] }, { @@ -479,10 +479,10 @@ "source": [ "### Task 2.2. Two-qubit gate - 2\n", "\n", - "**Input:** Two unentangled qubits (stored in an array of length 2) in state $|+\\rangle \\otimes |+\\rangle = \\frac{1}{2} \\big( |00\\rangle + |01\\rangle + |10\\rangle \\color{blue}+ |11\\rangle \\big)$.\n", + "**Input:** Two unentangled qubits (stored in an array of length 2) in state $|+\\rangle \\otimes |+\\rangle = \\frac{1}{2} \\big( |00\\rangle + |01\\rangle + |10\\rangle {\\color{blue}+} |11\\rangle \\big)$.\n", "\n", "\n", - "**Goal:** Change the two-qubit state to $\\frac{1}{2} \\big( |00\\rangle + |01\\rangle + |10\\rangle \\color{red}- |11\\rangle \\big)$.\n", + "**Goal:** Change the two-qubit state to $\\frac{1}{2} \\big( |00\\rangle + |01\\rangle + |10\\rangle {\\color{red}-} |11\\rangle \\big)$.\n", "\n", "> Note that while the starting state can be represented as a tensor product of single-qubit states,\n", "> the resulting two-qubit state can not be represented in such a way." @@ -514,10 +514,10 @@ "source": [ "### Task 2.3. Two-qubit gate - 3\n", "\n", - "**Input:** Two unentangled qubits (stored in an array of length 2) in an arbitrary two-qubit state $\\alpha |00\\rangle + \\color{blue}\\beta |01\\rangle + \\color{blue}\\gamma |10\\rangle + \\delta |11\\rangle$.\n", + "**Input:** Two unentangled qubits (stored in an array of length 2) in an arbitrary two-qubit state $\\alpha |00\\rangle + {\\color{blue}\\beta} |01\\rangle + {\\color{blue}\\gamma} |10\\rangle + \\delta |11\\rangle$.\n", "\n", "\n", - "**Goal:** Change the two-qubit state to $\\alpha |00\\rangle + \\color{red}\\gamma |01\\rangle + \\color{red}\\beta |10\\rangle + \\delta |11\\rangle$.\n", + "**Goal:** Change the two-qubit state to $\\alpha |00\\rangle + {\\color{red}\\gamma} |01\\rangle + {\\color{red}\\beta} |10\\rangle + \\delta |11\\rangle$.\n", "\n", "> This task can be solved using one intrinsic gate; as an exercise, try to express the solution using several (possibly controlled) Pauli gates." ] @@ -549,9 +549,9 @@ "### Task 2.4. Toffoli gate\n", "\n", "**Input:** Three qubits (stored in an array of length 3) in an arbitrary three-qubit state \n", - "$\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\zeta|101\\rangle + \\color{blue}\\eta|110\\rangle + \\color{blue}\\theta|111\\rangle$.\n", + "$\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\zeta|101\\rangle + {\\color{blue}\\eta}|110\\rangle + {\\color{blue}\\theta}|111\\rangle$.\n", "\n", - "**Goal:** Flip the state of the third qubit if the state of the first two is $|11\\rangle$, i.e., change the three-qubit state to $\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\zeta|101\\rangle + \\color{red}\\theta|110\\rangle + \\color{red}\\eta|111\\rangle$." + "**Goal:** Flip the state of the third qubit if the state of the first two is $|11\\rangle$, i.e., change the three-qubit state to $\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\zeta|101\\rangle + {\\color{red}\\theta}|110\\rangle + {\\color{red}\\eta}|111\\rangle$." ] }, { @@ -581,9 +581,9 @@ "### Task 2.5. Fredkin gate\n", "\n", "**Input:** Three qubits (stored in an array of length 3) in an arbitrary three-qubit state \n", - "$\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\color{blue}\\zeta|101\\rangle + \\color{blue}\\eta|110\\rangle + \\theta|111\\rangle$.\n", + "$\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + {\\color{blue}\\zeta}|101\\rangle + {\\color{blue}\\eta}|110\\rangle + \\theta|111\\rangle$.\n", "\n", - "**Goal:** Swap the states of second and third qubit if and only if the state of the first qubit is $|1\\rangle$, i.e., change the three-qubit state to $\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\color{red}\\eta|101\\rangle + \\color{red}\\zeta|110\\rangle + \\theta|111\\rangle$." + "**Goal:** Swap the states of second and third qubit if and only if the state of the first qubit is $|1\\rangle$, i.e., change the three-qubit state to $\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + {\\color{red}\\eta}|101\\rangle + {\\color{red}\\zeta}|110\\rangle + \\theta|111\\rangle$." ] }, { diff --git a/BasicGates/Workbook_BasicGates.ipynb b/BasicGates/Workbook_BasicGates.ipynb index 0bf5d679257..440513ec9ff 100644 --- a/BasicGates/Workbook_BasicGates.ipynb +++ b/BasicGates/Workbook_BasicGates.ipynb @@ -2,6 +2,7 @@ "cells": [ { "cell_type": "markdown", + "id": "08b341ed", "metadata": { "tags": [] }, @@ -19,6 +20,7 @@ }, { "cell_type": "markdown", + "id": "3518d868", "metadata": {}, "source": [ "**What you should know for this workbook**\n", @@ -35,6 +37,7 @@ }, { "cell_type": "markdown", + "id": "ac84ea42", "metadata": {}, "source": [ "# Part 1. Single-Qubit Gates" @@ -42,6 +45,7 @@ }, { "cell_type": "markdown", + "id": "d8fb9f6f", "metadata": { "jp-MarkdownHeadingCollapsed": true, "tags": [] @@ -62,6 +66,7 @@ }, { "cell_type": "markdown", + "id": "9352232d", "metadata": {}, "source": [ "### Solution" @@ -69,6 +74,7 @@ }, { "cell_type": "markdown", + "id": "8eed54c9", "metadata": {}, "source": [ "We can recognize that the Pauli X gate will change the state $|0\\rangle$ to $|1\\rangle$ and vice versa, and $\\alpha |0\\rangle + \\beta |1\\rangle$ to $\\alpha |1\\rangle + \\beta |0\\rangle$.\n", @@ -78,6 +84,7 @@ }, { "cell_type": "markdown", + "id": "571ec0ad", "metadata": {}, "source": [ "$$\n", @@ -93,6 +100,7 @@ }, { "cell_type": "markdown", + "id": "4783f3bc", "metadata": {}, "source": [ "$$X|0\\rangle= \n", @@ -120,6 +128,7 @@ }, { "cell_type": "markdown", + "id": "ea904409", "metadata": {}, "source": [ "Similarly, we can consider the effect of the X gate on the superposition state $|\\psi\\rangle = 0.6|0\\rangle + 0.8|1\\rangle$:" @@ -127,6 +136,7 @@ }, { "cell_type": "markdown", + "id": "cca0689e", "metadata": {}, "source": [ "$$X|\\psi\\rangle= \n", @@ -155,6 +165,7 @@ { "cell_type": "code", "execution_count": null, + "id": "eb5280e4", "metadata": {}, "outputs": [], "source": [ @@ -167,6 +178,7 @@ }, { "cell_type": "markdown", + "id": "d641d015", "metadata": {}, "source": [ "[Return to Task 1.1 of the Basic Gates kata.](./BasicGates.ipynb#Task-1.1.-State-flip:-$|0\\rangle$-to-$|1\\rangle$-and-vice-versa)" @@ -174,6 +186,7 @@ }, { "cell_type": "markdown", + "id": "b7334694", "metadata": { "tags": [] }, @@ -190,6 +203,7 @@ }, { "cell_type": "markdown", + "id": "37723ac7", "metadata": {}, "source": [ "### Solution" @@ -197,6 +211,7 @@ }, { "cell_type": "markdown", + "id": "9ae4bd06", "metadata": { "tags": [] }, @@ -208,6 +223,7 @@ }, { "cell_type": "markdown", + "id": "4affd231", "metadata": { "tags": [] }, @@ -224,6 +240,7 @@ }, { "cell_type": "markdown", + "id": "3e9cff65", "metadata": { "tags": [] }, @@ -254,6 +271,7 @@ }, { "cell_type": "markdown", + "id": "902e503e", "metadata": {}, "source": [ "Similarly, we can consider the effect of the Hadamard gate on the superposition state $|\\psi\\rangle = 0.6|0\\rangle + 0.8|1\\rangle$ (rounding the numbers to 4 decimal places):" @@ -261,6 +279,7 @@ }, { "cell_type": "markdown", + "id": "6be890e3", "metadata": {}, "source": [ "$$\n", @@ -293,6 +312,7 @@ { "cell_type": "code", "execution_count": null, + "id": "c31ba04d", "metadata": {}, "outputs": [], "source": [ @@ -305,6 +325,7 @@ }, { "cell_type": "markdown", + "id": "0ed1eb80", "metadata": {}, "source": [ "[Return to Task 1.2 of the Basic Gates kata](./BasicGates.ipynb#Task-1.2.-Basis-change:-$|0\\rangle$-to-$|+\\rangle$-and-$|1\\rangle$-to-$|-\\rangle$-(and-vice-versa))." @@ -312,6 +333,7 @@ }, { "cell_type": "markdown", + "id": "040d446b", "metadata": {}, "source": [ " " @@ -319,6 +341,7 @@ }, { "cell_type": "markdown", + "id": "d2f58d77", "metadata": {}, "source": [ "## Task 1.3. Sign flip: $|+\\rangle$ to $|-\\rangle$ and vice versa.\n", @@ -330,6 +353,7 @@ }, { "cell_type": "markdown", + "id": "d98d3f8c", "metadata": {}, "source": [ "### Solution" @@ -337,6 +361,7 @@ }, { "cell_type": "markdown", + "id": "708e93ff", "metadata": {}, "source": [ "The action of the Pauli Z gate is exactly what is required by this question.\n", @@ -347,6 +372,7 @@ }, { "cell_type": "markdown", + "id": "23394efb", "metadata": {}, "source": [ "$$\n", @@ -390,6 +416,7 @@ }, { "cell_type": "markdown", + "id": "a3677492", "metadata": {}, "source": [ "In general applying the Z gate to a single qubit superposition state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$ gives" @@ -397,6 +424,7 @@ }, { "cell_type": "markdown", + "id": "2d1e7e97", "metadata": {}, "source": [ "$$\n", @@ -426,6 +454,7 @@ { "cell_type": "code", "execution_count": null, + "id": "0c4e1d89", "metadata": { "tags": [] }, @@ -440,6 +469,7 @@ }, { "cell_type": "markdown", + "id": "f7807d03", "metadata": {}, "source": [ "[Return to Task 1.3 of the Basic Gates kata](./BasicGates.ipynb#Task-1.3.-Sign-flip:-$|+\\rangle$--to-$|-\\rangle$--and-vice-versa.)." @@ -447,6 +477,7 @@ }, { "cell_type": "markdown", + "id": "0f805114", "metadata": { "tags": [] }, @@ -466,6 +497,7 @@ }, { "cell_type": "markdown", + "id": "6fe379f8", "metadata": {}, "source": [ "### Solution" @@ -473,6 +505,7 @@ }, { "cell_type": "markdown", + "id": "ae7f2616", "metadata": {}, "source": [ "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 $|0\\rangle$ and $|1\\rangle$ to have real amplitudes (the other two gates introduce complex coefficients).\n", @@ -482,6 +515,7 @@ }, { "cell_type": "markdown", + "id": "57777d72", "metadata": {}, "source": [ "$$\n", @@ -495,6 +529,7 @@ }, { "cell_type": "markdown", + "id": "b33786ab", "metadata": {}, "source": [ "Let's see its effect on the $|0\\rangle$ state:" @@ -502,6 +537,7 @@ }, { "cell_type": "markdown", + "id": "731e2fc6", "metadata": {}, "source": [ "$$\n", @@ -530,6 +566,7 @@ }, { "cell_type": "markdown", + "id": "0610a9fe", "metadata": {}, "source": [ "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 $|0\\rangle$ state, and the second column is the state into which it will transform the $|1\\rangle$ state." @@ -537,6 +574,7 @@ }, { "cell_type": "markdown", + "id": "10a1735f", "metadata": {}, "source": [ "In the example used by the testing harness we are given $\\beta = 0.6, \\gamma = 0.8$ and $\\alpha = 1.0471975511965976 = \\frac{\\pi}{3}$." @@ -544,6 +582,7 @@ }, { "cell_type": "markdown", + "id": "7987103d", "metadata": {}, "source": [ "Since $\\cos \\frac{\\pi}{3} = 0.5$ and $\\sin \\frac{\\pi}{3} = 0.8660$, working to 4 decimal places, we can compute:" @@ -551,6 +590,7 @@ }, { "cell_type": "markdown", + "id": "79a3cf4a", "metadata": {}, "source": [ "$$\n", @@ -589,6 +629,7 @@ }, { "cell_type": "markdown", + "id": "a9925bef", "metadata": {}, "source": [ "Notice that we used $\\frac{\\theta}{2} = \\alpha$; this means that in the Q# code we need to pass the angle $\\theta = 2\\alpha$." @@ -597,6 +638,7 @@ { "cell_type": "code", "execution_count": null, + "id": "76806a63", "metadata": {}, "outputs": [], "source": [ @@ -609,6 +651,7 @@ }, { "cell_type": "markdown", + "id": "0f633d2e", "metadata": {}, "source": [ "[Return to Task 1.4 of the Basic Gates kata](./BasicGates.ipynb#Task-1.4.-Amplitude-change:-$|0\\rangle$-to-$\\cos{α}-|0\\rangle-+-\\sin{α}-|1\\rangle$.)." @@ -616,17 +659,19 @@ }, { "cell_type": "markdown", + "id": "f602eca2", "metadata": {}, "source": [ "## Task 1.5. Phase flip\n", "\n", "**Input:** A qubit in state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$.\n", "\n", - "**Goal:** Change the qubit state to $\\alpha |0\\rangle + \\color{red}i\\beta |1\\rangle$ (add a relative phase $i$ to $|1\\rangle$ component of the superposition).\n" + "**Goal:** Change the qubit state to $\\alpha |0\\rangle + {\\color{red}i}\\beta |1\\rangle$ (add a relative phase $i$ to $|1\\rangle$ component of the superposition).\n" ] }, { "cell_type": "markdown", + "id": "53979f74", "metadata": {}, "source": [ "### Solution\n", @@ -636,6 +681,7 @@ }, { "cell_type": "markdown", + "id": "f6bf8c81", "metadata": {}, "source": [ "$$\n", @@ -649,6 +695,7 @@ }, { "cell_type": "markdown", + "id": "529f3a15", "metadata": {}, "source": [ "Let's see the effect of this gate on the general superposition $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$." @@ -656,6 +703,7 @@ }, { "cell_type": "markdown", + "id": "e915ee67", "metadata": {}, "source": [ "$$\n", @@ -682,6 +730,7 @@ }, { "cell_type": "markdown", + "id": "673ab60c", "metadata": {}, "source": [ "It is therefore easy to see that when $|\\psi\\rangle = 0.6|0\\rangle + 0.8|1\\rangle, S|\\psi\\rangle = 0.6|0\\rangle + 0.8i|1\\rangle$." @@ -690,6 +739,7 @@ { "cell_type": "code", "execution_count": null, + "id": "d18c3b7d", "metadata": {}, "outputs": [], "source": [ @@ -702,6 +752,7 @@ }, { "cell_type": "markdown", + "id": "ed15b83a", "metadata": {}, "source": [ "### Solution 2\n", @@ -712,6 +763,7 @@ { "cell_type": "code", "execution_count": null, + "id": "e1709a88", "metadata": {}, "outputs": [], "source": [ @@ -726,6 +778,7 @@ }, { "cell_type": "markdown", + "id": "96ad3638", "metadata": {}, "source": [ "[Return to Task 1.5 of the Basic Gates kata](./BasicGates.ipynb#Task-1.5.-Phase-flip)." @@ -733,6 +786,7 @@ }, { "cell_type": "markdown", + "id": "6f01ebf6", "metadata": {}, "source": [ "## Task 1.6. Phase change\n", @@ -745,11 +799,12 @@ "**Goal:** Change the state of the qubit as follows:\n", "- If the qubit is in state $|0\\rangle$, don't change its state.\n", "- If the qubit is in state $|1\\rangle$, change its state to $e^{i\\alpha} |1\\rangle$.\n", - "- If the qubit is in superposition, change its state according to the effect on basis vectors: $\\beta |0\\rangle + \\color{red}{e^{i\\alpha}} \\gamma |1\\rangle$." + "- If the qubit is in superposition, change its state according to the effect on basis vectors: $\\beta |0\\rangle + {\\color{red}{e^{i\\alpha}}} \\gamma |1\\rangle$." ] }, { "cell_type": "markdown", + "id": "e47dd632", "metadata": {}, "source": [ "### Solution\n", @@ -758,6 +813,7 @@ }, { "cell_type": "markdown", + "id": "99e25061", "metadata": {}, "source": [ "$$\n", @@ -772,6 +828,7 @@ }, { "cell_type": "markdown", + "id": "77bcb993", "metadata": {}, "source": [ "So we have:" @@ -779,6 +836,7 @@ }, { "cell_type": "markdown", + "id": "cb9570f7", "metadata": {}, "source": [ "$$\n", @@ -794,19 +852,20 @@ " =\n", "\\begin{bmatrix}\n", " 1.\\beta + 0.\\gamma\\\\\n", - " 0.\\beta + \\color{red}{e^{i\\alpha}}\\gamma\n", + " 0.\\beta + {\\color{red}{e^{i\\alpha}}}\\gamma\n", " \\end{bmatrix} \n", " =\n", " \\begin{bmatrix}\n", " \\beta\\\\\n", - " \\color{red}{e^{i\\alpha}}\\gamma\n", + " {\\color{red}{e^{i\\alpha}}}\\gamma\n", " \\end{bmatrix} \n", - " = \\beta |0\\rangle + \\color{red}{e^{i\\alpha}} \\gamma |1\\rangle\n", + " = \\beta |0\\rangle + {\\color{red}{e^{i\\alpha}}} \\gamma |1\\rangle\n", "$$" ] }, { "cell_type": "markdown", + "id": "6d87c8ad", "metadata": {}, "source": [ "> Note that the results produced by the test harness can be unexpected.\n", @@ -824,6 +883,7 @@ { "cell_type": "code", "execution_count": null, + "id": "4fe80339", "metadata": {}, "outputs": [], "source": [ @@ -836,6 +896,7 @@ }, { "cell_type": "markdown", + "id": "5c1711c7", "metadata": {}, "source": [ "Suppose now that $\\alpha = \\frac{\\pi}{2}$.\n", @@ -846,6 +907,7 @@ }, { "cell_type": "markdown", + "id": "56490e4e", "metadata": {}, "source": [ "[Return to Task 1.6 of the Basic Gates kata](./BasicGates.ipynb#Task-1.6.-Phase-Change)." @@ -853,6 +915,7 @@ }, { "cell_type": "markdown", + "id": "5e4885b0", "metadata": {}, "source": [ "## Task 1.7. Global phase change\n", @@ -867,6 +930,7 @@ }, { "cell_type": "markdown", + "id": "e74f38aa", "metadata": {}, "source": [ "### Solution\n", @@ -880,6 +944,7 @@ }, { "cell_type": "markdown", + "id": "fee6138f", "metadata": {}, "source": [ "For the problem at hand, we'll use the rotation gate $R_{\\mu}(\\theta) = \\exp(\\frac{\\theta}{2}i\\cdot\\sigma_{\\mu})$ with $\\sigma_{\\mu} = I$. \n", @@ -889,6 +954,7 @@ }, { "cell_type": "markdown", + "id": "0af70ee2", "metadata": {}, "source": [ "$$\n", @@ -928,6 +994,7 @@ }, { "cell_type": "markdown", + "id": "a25311a9", "metadata": {}, "source": [ "The test harness for this test shows the result of applying the *controlled* variant of your solution to be able to detect the phase change." @@ -936,6 +1003,7 @@ { "cell_type": "code", "execution_count": null, + "id": "ce9e8cd8", "metadata": {}, "outputs": [], "source": [ @@ -950,6 +1018,7 @@ }, { "cell_type": "markdown", + "id": "6f1b9945", "metadata": {}, "source": [ "[Return to Task 1.7 of the Basic Gates kata](./BasicGates.ipynb#Task-1.7.-Global-phase-change)." @@ -957,6 +1026,7 @@ }, { "cell_type": "markdown", + "id": "50909364", "metadata": {}, "source": [ "## Task 1.8. Bell state change - 1\n", @@ -968,6 +1038,7 @@ }, { "cell_type": "markdown", + "id": "cf8dec6b", "metadata": {}, "source": [ "### Solution" @@ -975,6 +1046,7 @@ }, { "cell_type": "markdown", + "id": "1e90fc5e", "metadata": {}, "source": [ "We recognize that the goal is another Bell state. In fact, it is one of the four Bell states.\n", @@ -990,6 +1062,7 @@ }, { "cell_type": "markdown", + "id": "63ea5481", "metadata": {}, "source": [ "If we apply the Z gate to the qubit A, it will flip the phase of the basis state $|1_A\\rangle$. As this phase is in a sense spread across the entangled state, with $|1_A\\rangle$ basis state being part of the second half of the superposition, this application has the effect of flipping the sign of the whole basis state $|1_A1_B\\rangle$, as you can see by running the solution below. \n", @@ -1005,6 +1078,7 @@ { "cell_type": "code", "execution_count": null, + "id": "212bf887", "metadata": {}, "outputs": [], "source": [ @@ -1017,6 +1091,7 @@ }, { "cell_type": "markdown", + "id": "7573cc28", "metadata": {}, "source": [ "[Return to Task 1.8 of the Basic Gates kata](./BasicGates.ipynb#Task-1.8.-Bell-state-change---1)." @@ -1024,6 +1099,7 @@ }, { "cell_type": "markdown", + "id": "5031d150", "metadata": {}, "source": [ "## Task 1.9. Bell state change - 2\n", @@ -1035,6 +1111,7 @@ }, { "cell_type": "markdown", + "id": "d2b7a7bc", "metadata": {}, "source": [ "### Solution ##\n", @@ -1048,6 +1125,7 @@ { "cell_type": "code", "execution_count": null, + "id": "fac2ab43", "metadata": { "scrolled": true }, @@ -1062,6 +1140,7 @@ }, { "cell_type": "markdown", + "id": "2fad3a01", "metadata": {}, "source": [ "[Return to Task 1.9 of the Basic Gates kata](./BasicGates.ipynb#Task-1.9.-Bell-state-change---2)." @@ -1069,6 +1148,7 @@ }, { "cell_type": "markdown", + "id": "8d15a443", "metadata": {}, "source": [ "## Task 1.10. Bell state change - 3\n", @@ -1080,6 +1160,7 @@ }, { "cell_type": "markdown", + "id": "ab78ed82", "metadata": {}, "source": [ "### Solution ##\n", @@ -1094,6 +1175,7 @@ { "cell_type": "code", "execution_count": null, + "id": "5cba6fcf", "metadata": {}, "outputs": [], "source": [ @@ -1107,6 +1189,7 @@ }, { "cell_type": "markdown", + "id": "2580bcc0", "metadata": {}, "source": [ "[Return to Task 1.10 of the Basic Gates kata](./BasicGates.ipynb#Task-1.10.-Bell-state-change---3)." @@ -1114,6 +1197,7 @@ }, { "cell_type": "markdown", + "id": "e852abeb", "metadata": {}, "source": [ "# Part II. Multi-Qubit Gates\n", @@ -1129,6 +1213,7 @@ }, { "cell_type": "markdown", + "id": "06172f60", "metadata": {}, "source": [ "### Solution\n", @@ -1143,6 +1228,7 @@ { "cell_type": "code", "execution_count": null, + "id": "3f8c13e6", "metadata": {}, "outputs": [], "source": [ @@ -1155,6 +1241,7 @@ }, { "cell_type": "markdown", + "id": "d1c26753", "metadata": {}, "source": [ "[Return to Task 2.1 of the Basic Gates kata](./BasicGates.ipynb#Task-2.1.-Two-qubit-gate---1)." @@ -1162,18 +1249,20 @@ }, { "cell_type": "markdown", + "id": "acb00b18", "metadata": {}, "source": [ "## Task 2.2. Two-qubit gate - 2\n", "\n", - "**Input:** Two unentangled qubits (stored in an array of length 2) in state $|+\\rangle \\otimes |+\\rangle = \\frac{1}{2} \\big( |00\\rangle + |01\\rangle + |10\\rangle \\color{blue}+ |11\\rangle \\big)$.\n", + "**Input:** Two unentangled qubits (stored in an array of length 2) in state $|+\\rangle \\otimes |+\\rangle = \\frac{1}{2} \\big( |00\\rangle + |01\\rangle + |10\\rangle {\\color{blue}+} |11\\rangle \\big)$.\n", "\n", "\n", - "**Goal:** Change the two-qubit state to $\\frac{1}{2} \\big( |00\\rangle + |01\\rangle + |10\\rangle \\color{red}- |11\\rangle \\big)$." + "**Goal:** Change the two-qubit state to $\\frac{1}{2} \\big( |00\\rangle + |01\\rangle + |10\\rangle {\\color{red}-} |11\\rangle \\big)$." ] }, { "cell_type": "markdown", + "id": "8eb87a61", "metadata": {}, "source": [ "### Solution\n", @@ -1182,6 +1271,7 @@ }, { "cell_type": "markdown", + "id": "190868fc", "metadata": {}, "source": [ "In vector form the transformation we need is \n", @@ -1204,6 +1294,7 @@ }, { "cell_type": "markdown", + "id": "17aa3939", "metadata": {}, "source": [ "All that needs to happen to change the input into the goal is that the $|11\\rangle$ basis state needs to have its sign flipped. \n", @@ -1214,6 +1305,7 @@ }, { "cell_type": "markdown", + "id": "6a90f3d3", "metadata": {}, "source": [ "Similarly to task 2.1, the phase shift only occurs on one of the basis states, so this suggests it might be a conditional shift. If we could have our phase shift applied to `qs[1]` conditional on `qs[0]` being in the state $|1\\rangle$, then we would have a description of our gate. If we now look though a list of gates in the [Single-qubit gates tutorial](../tutorials/SingleQubitGates/SingleQubitGates.ipynb), we'll find the R1 phase shift gate with angle parameter $\\theta$ (radians), defined as\n", @@ -1230,6 +1322,7 @@ }, { "cell_type": "markdown", + "id": "d7146bed", "metadata": {}, "source": [ "The controlled variant of this gate will look like this:\n", @@ -1246,6 +1339,7 @@ }, { "cell_type": "markdown", + "id": "94ab2ff7", "metadata": {}, "source": [ "This gate is almost Pauli I, the identity gate, with the different in just the last column, showing what will happen to the $|11\\rangle$ basis state. Applying it to our input state for $\\alpha = \\pi$, we'll get:" @@ -1253,6 +1347,7 @@ }, { "cell_type": "markdown", + "id": "96773152", "metadata": {}, "source": [ "$$\n", @@ -1278,12 +1373,13 @@ " 1\\cdot\\color{red}{e^{i\\alpha}}\\\\\n", "\\end{bmatrix}\n", "=\n", - "\\frac{1}{2} \\big( |00\\rangle + |01\\rangle + |10\\rangle \\color{red}- |11\\rangle \\big)\n", + "\\frac{1}{2} \\big( |00\\rangle + |01\\rangle + |10\\rangle {\\color{red}-} |11\\rangle \\big)\n", "$$" ] }, { "cell_type": "markdown", + "id": "21b2b412", "metadata": {}, "source": [ "The last thing we notice if we look through the [list of operations in the Microsoft.Quantum.Canon namespace](https://docs.microsoft.com/en-us/qsharp/api/qsharp/microsoft.quantum.canon) is the CZ (Controlled Z) gate, a special case of CR1 that implements exactly this gate." @@ -1292,6 +1388,7 @@ { "cell_type": "code", "execution_count": null, + "id": "bf116783", "metadata": { "scrolled": true }, @@ -1306,6 +1403,7 @@ }, { "cell_type": "markdown", + "id": "df30893f", "metadata": {}, "source": [ "Alternatively, we can express this gate using the intrinsic gate Z and its controlled variant using the Controlled functor:" @@ -1314,6 +1412,7 @@ { "cell_type": "code", "execution_count": null, + "id": "faca3173", "metadata": {}, "outputs": [], "source": [ @@ -1326,6 +1425,7 @@ }, { "cell_type": "markdown", + "id": "e4721003", "metadata": {}, "source": [ "[Return to Task 2.2 of the Basic Gates kata](./BasicGates.ipynb#Task-2.2.-Two-qubit-gate---2)." @@ -1333,20 +1433,22 @@ }, { "cell_type": "markdown", + "id": "024fd8b5", "metadata": {}, "source": [ "## Task 2.3. Two-qubit gate - 3\n", "\n", - "**Input:** Two unentangled qubits (stored in an array of length 2) in an arbitrary two-qubit state $\\alpha |00\\rangle + \\color{blue}\\beta |01\\rangle + \\color{blue}\\gamma |10\\rangle + \\delta |11\\rangle$.\n", + "**Input:** Two unentangled qubits (stored in an array of length 2) in an arbitrary two-qubit state $\\alpha |00\\rangle + {\\color{blue}\\beta} |01\\rangle + {\\color{blue}\\gamma} |10\\rangle + \\delta |11\\rangle$.\n", "\n", "\n", - "**Goal:** Change the two-qubit state to $\\alpha |00\\rangle + \\color{red}\\gamma |01\\rangle + \\color{red}\\beta |10\\rangle + \\delta |11\\rangle$.\n", + "**Goal:** Change the two-qubit state to $\\alpha |00\\rangle + {\\color{red}\\gamma} |01\\rangle + {\\color{red}\\beta} |10\\rangle + \\delta |11\\rangle$.\n", "\n", "> This task can be solved using one intrinsic gate; as an exercise, try to express the solution using several (possibly controlled) Pauli gates." ] }, { "cell_type": "markdown", + "id": "414cea33", "metadata": {}, "source": [ "## Solution\n", @@ -1358,6 +1460,7 @@ }, { "cell_type": "markdown", + "id": "45ead206", "metadata": {}, "source": [ "$$\n", @@ -1373,6 +1476,7 @@ }, { "cell_type": "markdown", + "id": "624f23bd", "metadata": {}, "source": [ "and our input state vector is:" @@ -1380,6 +1484,7 @@ }, { "cell_type": "markdown", + "id": "ea2da222", "metadata": {}, "source": [ "$$\n", @@ -1393,6 +1498,7 @@ }, { "cell_type": "markdown", + "id": "5f1ab7ea", "metadata": {}, "source": [ "So operating on our input state vector with the SWAP gate gives us" @@ -1400,6 +1506,7 @@ }, { "cell_type": "markdown", + "id": "ea5bfd55", "metadata": {}, "source": [ "$$\n", @@ -1423,12 +1530,13 @@ " \\delta\\\\\n", "\\end{bmatrix}\n", "=\n", - "|00\\rangle + \\color{red}\\gamma |01\\rangle + \\color{red}\\beta |10\\rangle + \\delta |11\\rangle\n", + "|00\\rangle + {\\color{red}\\gamma} |01\\rangle + {\\color{red}\\beta} |10\\rangle + \\delta |11\\rangle\n", "$$" ] }, { "cell_type": "markdown", + "id": "70ec1d62", "metadata": {}, "source": [ "and we can confirm this with the task solution:" @@ -1437,6 +1545,7 @@ { "cell_type": "code", "execution_count": null, + "id": "fc61a027", "metadata": {}, "outputs": [], "source": [ @@ -1449,6 +1558,7 @@ }, { "cell_type": "markdown", + "id": "a73e1253", "metadata": {}, "source": [ "> If you run this solution a few times you might see an apparent anomaly. The test harness uses an input state that has positive values of $\\alpha$ and $\\delta$ and negative values of $\\beta$ and $\\gamma$, while\n", @@ -1458,6 +1568,7 @@ }, { "cell_type": "markdown", + "id": "6bbccd7e", "metadata": {}, "source": [ "Let's now follow the hint in the question and try to express the solution using several (possibly controlled) Pauli gates.\n", @@ -1507,6 +1618,7 @@ { "cell_type": "code", "execution_count": null, + "id": "fde34c0d", "metadata": {}, "outputs": [], "source": [ @@ -1521,6 +1633,7 @@ }, { "cell_type": "markdown", + "id": "d59151ae", "metadata": {}, "source": [ "[Return to Task 2.3 of the Basic Gates kata](./BasicGates.ipynb#Task-2.3.-Two-qubit-gate---3)." @@ -1528,14 +1641,15 @@ }, { "cell_type": "markdown", + "id": "dba10187", "metadata": {}, "source": [ "## Task 2.4. Toffoli gate\n", "\n", "**Input:** Three qubits (stored in an array of length 3) in an arbitrary three-qubit state \n", - "$\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\zeta|101\\rangle + \\color{blue}\\eta|110\\rangle + \\color{blue}\\theta|111\\rangle$.\n", + "$\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\zeta|101\\rangle + {\\color{blue}\\eta}|110\\rangle + {\\color{blue}\\theta}|111\\rangle$.\n", "\n", - "**Goal:** Flip the state of the third qubit if the state of the first two is $|11\\rangle$, i.e., change the three-qubit state to $\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\zeta|101\\rangle + \\color{red}\\theta|110\\rangle + \\color{red}\\eta|111\\rangle$.\n", + "**Goal:** Flip the state of the third qubit if the state of the first two is $|11\\rangle$, i.e., change the three-qubit state to $\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\zeta|101\\rangle + {\\color{red}\\theta}|110\\rangle + {\\color{red}\\eta}|111\\rangle$.\n", "\n", "### Solution\n", "\n", @@ -1544,6 +1658,7 @@ }, { "cell_type": "markdown", + "id": "987cce48", "metadata": {}, "source": [ "$$\n", @@ -1562,6 +1677,7 @@ }, { "cell_type": "markdown", + "id": "5ca33aa9", "metadata": {}, "source": [ "and our initial state is:" @@ -1569,6 +1685,7 @@ }, { "cell_type": "markdown", + "id": "fa81e5e2", "metadata": {}, "source": [ "$$\n", @@ -1587,6 +1704,7 @@ }, { "cell_type": "markdown", + "id": "b52168aa", "metadata": {}, "source": [ "So we have:" @@ -1594,6 +1712,7 @@ }, { "cell_type": "markdown", + "id": "f2edd717", "metadata": {}, "source": [ "$$\n", @@ -1629,13 +1748,14 @@ " \\color{red}\\eta\\\\ \n", "\\end{bmatrix}\n", "=\n", - "\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\zeta|101\\rangle + \\color{red}\\theta|110\\rangle + \\color{red}\\eta|111\\rangle\n", + "\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\zeta|101\\rangle + {\\color{red}\\theta}|110\\rangle + {\\color{red}\\eta}|111\\rangle\n", "$$" ] }, { "cell_type": "code", "execution_count": null, + "id": "a19e7f27", "metadata": {}, "outputs": [], "source": [ @@ -1648,6 +1768,7 @@ }, { "cell_type": "markdown", + "id": "3638bc88", "metadata": {}, "source": [ "[Return to Task 2.4 of the Basic Gates kata](./BasicGates.ipynb#Task-2.4.-Toffoli-gate)." @@ -1655,14 +1776,15 @@ }, { "cell_type": "markdown", + "id": "12f55c25", "metadata": {}, "source": [ "## Task 2.5. Fredkin gate\n", "\n", "**Input:** Three qubits (stored in an array of length 3) in an arbitrary three-qubit state \n", - "$\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\color{blue}\\zeta|101\\rangle + \\color{blue}\\eta|110\\rangle + \\theta|111\\rangle$.\n", + "$\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + {\\color{blue}\\zeta}|101\\rangle + {\\color{blue}\\eta}|110\\rangle + \\theta|111\\rangle$.\n", "\n", - "**Goal:** Swap the states of second and third qubit if and only if the state of the first qubit is $|1\\rangle$, i.e., change the three-qubit state to $\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\color{red}\\eta|101\\rangle + \\color{red}\\zeta|110\\rangle + \\theta|111\\rangle$.\n", + "**Goal:** Swap the states of second and third qubit if and only if the state of the first qubit is $|1\\rangle$, i.e., change the three-qubit state to $\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + {\\color{red}\\eta}|101\\rangle + {\\color{red}\\zeta}|110\\rangle + \\theta|111\\rangle$.\n", "\n", "\n", "### Solution\n", @@ -1673,6 +1795,7 @@ }, { "cell_type": "markdown", + "id": "16ef03ce", "metadata": {}, "source": [ "$$\n", @@ -1691,6 +1814,7 @@ }, { "cell_type": "markdown", + "id": "5ca334bd", "metadata": {}, "source": [ "and our initial state is:" @@ -1698,6 +1822,7 @@ }, { "cell_type": "markdown", + "id": "320458ec", "metadata": {}, "source": [ "$$\n", @@ -1716,6 +1841,7 @@ }, { "cell_type": "markdown", + "id": "95174e4a", "metadata": {}, "source": [ "So we have:" @@ -1723,6 +1849,7 @@ }, { "cell_type": "markdown", + "id": "2b28ca69", "metadata": {}, "source": [ "$$\n", @@ -1758,12 +1885,13 @@ " \\theta\\\\ \n", "\\end{bmatrix}\n", "=\n", - "\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + \\color{red}\\eta|101\\rangle + \\color{red}\\zeta|110\\rangle + \\theta|111\\rangle\n", + "\\alpha |000\\rangle + \\beta |001\\rangle + \\gamma |010\\rangle + \\delta |011\\rangle + \\epsilon |100\\rangle + {\\color{red}\\eta}|101\\rangle + {\\color{red}\\zeta}|110\\rangle + \\theta|111\\rangle\n", "$$" ] }, { "cell_type": "markdown", + "id": "a23843de", "metadata": {}, "source": [ "Notice carefully how the qubits are passed to the gate: `[qs[0]], (qs[1], [qs[2])`. The `Controlled` functor produces an operation that takes two parameters: the first one is an array of control qubits (in this case a single-element array consisting of the first qubit), and the second parameter is a tuple of all parameters you'd pass to the original gate (in this gate two single-qubit parameters that would be arguments to a SWAP gate)." @@ -1772,6 +1900,7 @@ { "cell_type": "code", "execution_count": null, + "id": "188c0344", "metadata": {}, "outputs": [], "source": [ @@ -1784,6 +1913,7 @@ }, { "cell_type": "markdown", + "id": "1cc1e356", "metadata": {}, "source": [ "[Return to Task 2.5 of the Basic Gates kata](./BasicGates.ipynb#Task-2.5.-Fredkin-gate)." From 4c9d4ba3b92b32bcdfe6a82da5c88cfa99f0841a Mon Sep 17 00:00:00 2001 From: Adam Kania <48769688+remilvus@users.noreply.github.com> Date: Fri, 29 Jul 2022 16:56:20 +0200 Subject: [PATCH 06/15] Fix rendering in MultiQubitSystems --- tutorials/MultiQubitSystems/MultiQubitSystems.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tutorials/MultiQubitSystems/MultiQubitSystems.ipynb b/tutorials/MultiQubitSystems/MultiQubitSystems.ipynb index 84aa0ed909e..72e5f67a98b 100644 --- a/tutorials/MultiQubitSystems/MultiQubitSystems.ipynb +++ b/tutorials/MultiQubitSystems/MultiQubitSystems.ipynb @@ -170,10 +170,10 @@ "\n", "To simplify this, tensor products of basis states have their own notation:\n", "\n", - "$$|0\\rangle \\otimes |0\\rangle = |00\\rangle \\\\\n", - "|0\\rangle \\otimes |1\\rangle = |01\\rangle \\\\\n", - "|1\\rangle \\otimes |0\\rangle = |10\\rangle \\\\\n", - "|1\\rangle \\otimes |1\\rangle = |11\\rangle$$\n", + "$$|0\\rangle \\otimes |0\\rangle = |00\\rangle$$\n", + "$$|0\\rangle \\otimes |1\\rangle = |01\\rangle$$\n", + "$$|1\\rangle \\otimes |0\\rangle = |10\\rangle$$\n", + "$$|1\\rangle \\otimes |1\\rangle = |11\\rangle$$\n", "\n", "$$|0\\rangle \\otimes |0\\rangle \\otimes |0\\rangle = |000\\rangle$$\n", "\n", From c933001931effc6b847e0414d668c709bd4ad393 Mon Sep 17 00:00:00 2001 From: Adam Kania <48769688+remilvus@users.noreply.github.com> Date: Fri, 29 Jul 2022 17:07:48 +0200 Subject: [PATCH 07/15] Fix renderin in MultiGubitGates for CNOT gate --- .../MultiQubitGates/MultiQubitGates.ipynb | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tutorials/MultiQubitGates/MultiQubitGates.ipynb b/tutorials/MultiQubitGates/MultiQubitGates.ipynb index b61076f38c6..741c35ec8c6 100644 --- a/tutorials/MultiQubitGates/MultiQubitGates.ipynb +++ b/tutorials/MultiQubitGates/MultiQubitGates.ipynb @@ -153,10 +153,10 @@ " \n", " $\\text{CNOT}$\n", " $\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\\\ 0 & 0 & 1 & 0 \\end{bmatrix}$\n", - " $\\text{CNOT}|\\psi\\rangle = \\alpha|00\\rangle + \\beta|01\\rangle + \\color{red}\\delta|10\\rangle + \\color{red}\\gamma|11\\rangle$\n", - " $\\text{CNOT}|00\\rangle = |00\\rangle \\\\\n", - " \\text{CNOT}|01\\rangle = |01\\rangle \\\\\n", - " \\text{CNOT}|10\\rangle = |11\\rangle \\\\\n", + " $\\text{CNOT}|\\psi\\rangle = \\alpha|00\\rangle + \\beta|01\\rangle + {\\color{red}\\delta}|10\\rangle + {\\color{red}\\gamma}|11\\rangle$\n", + " $\\text{CNOT}|00\\rangle = |00\\rangle$<\\br>$\n", + " \\text{CNOT}|01\\rangle = |01\\rangle$<\\br>$\n", + " \\text{CNOT}|10\\rangle = |11\\rangle$<\\br>$\n", " \\text{CNOT}|11\\rangle = |10\\rangle$\n", " CNOT\n", " \n", @@ -225,12 +225,12 @@ "\n", "Let's consider ket-bra representation of the $\\text{CNOT}$ gate:\n", "\n", - "$$\\text{CNOT} = |00\\rangle\\langle00| + |01\\rangle\\langle01| + |10\\rangle\\langle11| + |11\\rangle\\langle10| = \\\\\n", - "= \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 1 & 0 & 0 & 0 \\end{bmatrix} +\n", + "$$\\text{CNOT} = |00\\rangle\\langle00| + |01\\rangle\\langle01| + |10\\rangle\\langle11| + |11\\rangle\\langle10| =$$\n", + "$$= \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 1 & 0 & 0 & 0 \\end{bmatrix} +\n", "\\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 0 & 1 & 0 & 0 \\end{bmatrix} +\n", "\\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix}\\begin{bmatrix} 0 & 0 & 0 & 1 \\end{bmatrix} +\n", - "\\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix}\\begin{bmatrix} 0 & 0 & 1 & 0 \\end{bmatrix} = \\\\ =\n", - "\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 0 \\\\ \\end{bmatrix} + \n", + "\\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix}\\begin{bmatrix} 0 & 0 & 1 & 0 \\end{bmatrix} =$$ \n", + "$$=\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 0 \\\\ \\end{bmatrix} + \n", "\\begin{bmatrix} 0 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 0 \\\\ \\end{bmatrix} + \n", "\\begin{bmatrix} 0 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\\\ 0 & 0 & 0 & 0 \\\\ \\end{bmatrix} + \n", "\\begin{bmatrix} 0 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ \\end{bmatrix} =\n", @@ -239,10 +239,10 @@ "This representation can be used to carry out calculations in Dirac notation without ever switching back to matrix representation:\n", "\n", "$$\\text{CNOT}|10\\rangle \n", - "= \\big(|00\\rangle\\langle00| + |01\\rangle\\langle01| + |10\\rangle\\langle11| + |11\\rangle\\langle10|\\big)|10\\rangle = \\\\\n", - "= |00\\rangle\\langle00|10\\rangle + |01\\rangle\\langle01|10\\rangle + |10\\rangle\\langle11|10\\rangle + |11\\rangle\\langle10|10\\rangle = \\\\\n", - "= |00\\rangle\\big(\\langle00|10\\rangle\\big) + |01\\rangle\\big(\\langle01|10\\rangle\\big) + |10\\rangle\\big(\\langle11|10\\rangle\\big) + |11\\rangle\\big(\\langle10|10\\rangle\\big) = \\\\\n", - "= |00\\rangle(0) + |01\\rangle(0) + |10\\rangle(0) + |11\\rangle(1) = |11\\rangle$$\n", + "= \\big(|00\\rangle\\langle00| + |01\\rangle\\langle01| + |10\\rangle\\langle11| + |11\\rangle\\langle10|\\big)|10\\rangle =$$\n", + "$$= |00\\rangle\\langle00|10\\rangle + |01\\rangle\\langle01|10\\rangle + |10\\rangle\\langle11|10\\rangle + |11\\rangle\\langle10|10\\rangle =$$\n", + "$$= |00\\rangle\\big(\\langle00|10\\rangle\\big) + |01\\rangle\\big(\\langle01|10\\rangle\\big) + |10\\rangle\\big(\\langle11|10\\rangle\\big) + |11\\rangle\\big(\\langle10|10\\rangle\\big) =$$\n", + "$$= |00\\rangle(0) + |01\\rangle(0) + |10\\rangle(0) + |11\\rangle(1) = |11\\rangle$$\n", "\n", "> Notice how a lot of the inner product terms turn out to equal 0, and our expression is easily simplified. We have expressed the CNOT gate in terms of outer product of computational basis states, which are orthonormal, and apply it to another computational basis state, so the individual inner products are going to always be 0 or 1. " ] @@ -294,10 +294,10 @@ "> * Two, as we can clearly see, are computational basis states $|00\\rangle$ and $|01\\rangle$ with eigen values $1$ and $1$, respectively (the basis states that are not affected by the gate). \n", "> * The other two are $|1\\rangle \\otimes |+\\rangle = \\frac{1}{\\sqrt{2}}\\big(|10\\rangle + |11\\rangle\\big)$ and $|1\\rangle \\otimes |-\\rangle = \\frac{1}{\\sqrt{2}}\\big(|10\\rangle - |11\\rangle\\big)$ with eigenvalues $1$ and $-1$, respectively:\n", ">\n", - "> $$\\text{CNOT}|0\\rangle \\otimes |0\\rangle = |0\\rangle \\otimes |1\\rangle \\\\\n", - "\\text{CNOT}|0\\rangle \\otimes |1\\rangle = |0\\rangle \\otimes |1\\rangle \\\\\n", - "\\text{CNOT}|1\\rangle \\otimes |+\\rangle = |1\\rangle \\otimes |+\\rangle \\\\\n", - "\\text{CNOT}|1\\rangle \\otimes |-\\rangle = -|1\\rangle \\otimes |-\\rangle$$\n", + "> $$\\text{CNOT}|0\\rangle \\otimes |0\\rangle = |0\\rangle \\otimes |1\\rangle$$\n", + "$$\\text{CNOT}|0\\rangle \\otimes |1\\rangle = |0\\rangle \\otimes |1\\rangle$$\n", + "$$\\text{CNOT}|1\\rangle \\otimes |+\\rangle = |1\\rangle \\otimes |+\\rangle$$\n", + "$$\\text{CNOT}|1\\rangle \\otimes |-\\rangle = -|1\\rangle \\otimes |-\\rangle$$\n", ">\n", "> Here's what the decomposition looks like:\n", ">\n", @@ -306,7 +306,7 @@ "= |00\\rangle\\langle00| + |01\\rangle\\langle01| + \n", "\\frac{1}{2}\\big[\\big(|10\\rangle + |11\\rangle\\big)\\big(\\langle10| + \\langle11|\\big) - \\big(|10\\rangle - |11\\rangle\\big)\\big(\\langle10| - \\langle11|\\big)\\big] = \\\\\n", "= |00\\rangle\\langle00| + |01\\rangle\\langle01| +\n", - "\\frac{1}{2}\\big(\\color{red}{|10\\rangle\\langle10|} + |10\\rangle\\langle11| + |11\\rangle\\langle10| + \\color{red}{|11\\rangle\\langle11|} - \\color{red}{|10\\rangle\\langle10|} + |10\\rangle\\langle11| + |11\\rangle\\langle10| - \\color{red}{|11\\rangle\\langle11|}\\big) = \\\\\n", + "\\frac{1}{2}\\big({\\color{red}{|10\\rangle\\langle10|}} + |10\\rangle\\langle11| + |11\\rangle\\langle10| + {\\color{red}{|11\\rangle\\langle11|}} - {\\color{red}{|10\\rangle\\langle10|}} + |10\\rangle\\langle11| + |11\\rangle\\langle10| - {\\color{red}{|11\\rangle\\langle11|}}\\big) = \\\\\n", "= |00\\rangle\\langle00| + |01\\rangle\\langle01| + \\frac{1}{2}\\big(2|10\\rangle\\langle11| + 2|11\\rangle\\langle10|\\big) = \\\\ \n", "= |00\\rangle\\langle00| + |01\\rangle\\langle01| + |10\\rangle\\langle11| + |11\\rangle\\langle10|$$" ] From 82ece50d2b49a2aa44188988c3b14f43f5190411 Mon Sep 17 00:00:00 2001 From: Adam Kania <48769688+remilvus@users.noreply.github.com> Date: Fri, 29 Jul 2022 17:12:27 +0200 Subject: [PATCH 08/15] Fix tag --- tutorials/MultiQubitGates/MultiQubitGates.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tutorials/MultiQubitGates/MultiQubitGates.ipynb b/tutorials/MultiQubitGates/MultiQubitGates.ipynb index 741c35ec8c6..e9984462d8e 100644 --- a/tutorials/MultiQubitGates/MultiQubitGates.ipynb +++ b/tutorials/MultiQubitGates/MultiQubitGates.ipynb @@ -154,10 +154,10 @@ " $\\text{CNOT}$\n", " $\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\\\ 0 & 0 & 1 & 0 \\end{bmatrix}$\n", " $\\text{CNOT}|\\psi\\rangle = \\alpha|00\\rangle + \\beta|01\\rangle + {\\color{red}\\delta}|10\\rangle + {\\color{red}\\gamma}|11\\rangle$\n", - " $\\text{CNOT}|00\\rangle = |00\\rangle$<\\br>$\n", - " \\text{CNOT}|01\\rangle = |01\\rangle$<\\br>$\n", - " \\text{CNOT}|10\\rangle = |11\\rangle$<\\br>$\n", - " \\text{CNOT}|11\\rangle = |10\\rangle$\n", + " $\\text{CNOT}|00\\rangle = |00\\rangle$
\n", + " $\\text{CNOT}|01\\rangle = |01\\rangle$
\n", + " $\\text{CNOT}|10\\rangle = |11\\rangle$
\n", + " $\\text{CNOT}|11\\rangle = |10\\rangle$\n", " CNOT\n", " \n", "" From af4c34a0036c4cce21df492a5d75056f1cdeb245 Mon Sep 17 00:00:00 2001 From: Adam Kania <48769688+remilvus@users.noreply.github.com> Date: Fri, 29 Jul 2022 17:24:38 +0200 Subject: [PATCH 09/15] Fix rendering in MultiQubitGates (line breaks) --- .../MultiQubitGates/MultiQubitGates.ipynb | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/tutorials/MultiQubitGates/MultiQubitGates.ipynb b/tutorials/MultiQubitGates/MultiQubitGates.ipynb index e9984462d8e..ce0bce97b8e 100644 --- a/tutorials/MultiQubitGates/MultiQubitGates.ipynb +++ b/tutorials/MultiQubitGates/MultiQubitGates.ipynb @@ -257,10 +257,10 @@ "a_{20} & a_{21} & a_{22} & a_{23} \\\\ \n", "a_{30} & a_{31} & a_{32} & a_{33} \\\\ \\end{bmatrix}$$\n", "will have the following ket-bra representation:\n", - "$$A = a_{00} |00\\rangle\\langle00| + a_{01} |00\\rangle\\langle01| + a_{02} |00\\rangle\\langle10| + a_{03} |00\\rangle\\langle11| +\\\\\n", - "+ a_{10} |01\\rangle\\langle00| + a_{11} |01\\rangle\\langle01| + a_{12} |01\\rangle\\langle10| + a_{13} |01\\rangle\\langle11| +\\\\\n", - "+ a_{20} |10\\rangle\\langle00| + a_{21} |10\\rangle\\langle01| + a_{22} |10\\rangle\\langle10| + a_{23} |10\\rangle\\langle11| +\\\\\n", - "+ a_{30} |11\\rangle\\langle00| + a_{31} |11\\rangle\\langle01| + a_{32} |11\\rangle\\langle10| + a_{33} |11\\rangle\\langle11| \n", + "$$A = a_{00} |00\\rangle\\langle00| + a_{01} |00\\rangle\\langle01| + a_{02} |00\\rangle\\langle10| + a_{03} |00\\rangle\\langle11| +$$\n", + "$$+ a_{10} |01\\rangle\\langle00| + a_{11} |01\\rangle\\langle01| + a_{12} |01\\rangle\\langle10| + a_{13} |01\\rangle\\langle11| +$$\n", + "$$+ a_{20} |10\\rangle\\langle00| + a_{21} |10\\rangle\\langle01| + a_{22} |10\\rangle\\langle10| + a_{23} |10\\rangle\\langle11| +$$\n", + "$$+ a_{30} |11\\rangle\\langle00| + a_{31} |11\\rangle\\langle01| + a_{32} |11\\rangle\\langle10| + a_{33} |11\\rangle\\langle11| \n", "$$\n", "\n", "A similar expression can be extended for matrices that describe $N$-qubit gates, where $N > 2$:\n", @@ -295,9 +295,9 @@ "> * The other two are $|1\\rangle \\otimes |+\\rangle = \\frac{1}{\\sqrt{2}}\\big(|10\\rangle + |11\\rangle\\big)$ and $|1\\rangle \\otimes |-\\rangle = \\frac{1}{\\sqrt{2}}\\big(|10\\rangle - |11\\rangle\\big)$ with eigenvalues $1$ and $-1$, respectively:\n", ">\n", "> $$\\text{CNOT}|0\\rangle \\otimes |0\\rangle = |0\\rangle \\otimes |1\\rangle$$\n", - "$$\\text{CNOT}|0\\rangle \\otimes |1\\rangle = |0\\rangle \\otimes |1\\rangle$$\n", - "$$\\text{CNOT}|1\\rangle \\otimes |+\\rangle = |1\\rangle \\otimes |+\\rangle$$\n", - "$$\\text{CNOT}|1\\rangle \\otimes |-\\rangle = -|1\\rangle \\otimes |-\\rangle$$\n", + "> $$\\text{CNOT}|0\\rangle \\otimes |1\\rangle = |0\\rangle \\otimes |1\\rangle$$\n", + "> $$\\text{CNOT}|1\\rangle \\otimes |+\\rangle = |1\\rangle \\otimes |+\\rangle$$\n", + "> $$\\text{CNOT}|1\\rangle \\otimes |-\\rangle = -|1\\rangle \\otimes |-\\rangle$$\n", ">\n", "> Here's what the decomposition looks like:\n", ">\n", @@ -334,11 +334,11 @@ " \n", " $\\text{SWAP}$\n", " $\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}$\n", - " $\\text{SWAP}|\\psi\\rangle = \\alpha|00\\rangle + \\color{red}\\gamma|01\\rangle + \\color{red}\\beta|10\\rangle + \\delta|11\\rangle$\n", - " $\\text{SWAP}|00\\rangle = |00\\rangle \\\\\n", - " \\text{SWAP}|01\\rangle = |10\\rangle \\\\\n", - " \\text{SWAP}|10\\rangle = |01\\rangle \\\\\n", - " \\text{SWAP}|11\\rangle = |11\\rangle$\n", + " $\\text{SWAP}|\\psi\\rangle = \\alpha|00\\rangle + {\\color{red}\\gamma}|01\\rangle + {\\color{red}\\beta}|10\\rangle + \\delta|11\\rangle$\n", + " $\\text{SWAP}|00\\rangle = |00\\rangle$
\n", + " $\\text{SWAP}|01\\rangle = |10\\rangle$
\n", + " $\\text{SWAP}|10\\rangle = |01\\rangle$
\n", + " $\\text{SWAP}|11\\rangle = |11\\rangle$\n", " SWAP\n", " \n", "" @@ -520,14 +520,14 @@ "$$\n", "\\left(\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix} \\otimes \n", "\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}\\right)\n", - "\\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ x_{010} \\\\ x_{011} \\\\ x_{100} \\\\ x_{101} \\\\ x_{110} \\\\ x_{111} \\end{bmatrix} = \\\\\n", - "= \\left(\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix} \\otimes \n", + "\\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ x_{010} \\\\ x_{011} \\\\ x_{100} \\\\ x_{101} \\\\ x_{110} \\\\ x_{111} \\end{bmatrix} =$$\n", + "$$= \\left(\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix} \\otimes \n", "\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}\\right)\n", "\\left( \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{000} \\\\ x_{001} \\end{bmatrix}\n", "+ \\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{010} \\\\ x_{011} \\end{bmatrix} \n", "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{100} \\\\ x_{101} \\end{bmatrix} \n", - "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{110} \\\\ x_{111} \\end{bmatrix} \\right) = \\\\\n", - "= \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{000} \\\\ x_{001} \\end{bmatrix}\n", + "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{110} \\\\ x_{111} \\end{bmatrix} \\right) =$$\n", + "$$= \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{000} \\\\ x_{001} \\end{bmatrix}\n", "+ \\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes \\color{red}{\\begin{bmatrix} x_{100} \\\\ x_{101} \\end{bmatrix}} \n", "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} \\otimes \\color{red}{\\begin{bmatrix} x_{010} \\\\ x_{011} \\end{bmatrix}} \n", "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{110} \\\\ x_{111} \\end{bmatrix} \n", @@ -538,8 +538,8 @@ "$$\n", "\\left(\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix} \\otimes \n", "\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\\\ 0 & 0 & 1 & 0 \\end{bmatrix} \\right) \n", - "\\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ x_{100} \\\\ x_{101} \\\\ x_{010} \\\\ x_{011} \\\\ x_{110} \\\\ x_{111} \\end{bmatrix} = \\\\\n", - "= \\left(\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix} \\otimes \n", + "\\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ x_{100} \\\\ x_{101} \\\\ x_{010} \\\\ x_{011} \\\\ x_{110} \\\\ x_{111} \\end{bmatrix} =$$\n", + "$$= \\left(\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix} \\otimes \n", "\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\\\ 0 & 0 & 1 & 0 \\end{bmatrix}\\right)\n", "\\left( \\begin{bmatrix} x_{000} \\\\ x_{010} \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} \n", "+ \\begin{bmatrix} x_{001} \\\\ x_{011} \\end{bmatrix} \\otimes \\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} \n", @@ -556,14 +556,14 @@ "$$\n", "\\left(\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix} \\otimes \n", "\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix} \\right)\n", - "\\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ x_{101} \\\\ x_{100} \\\\ x_{010} \\\\ x_{011} \\\\ x_{111} \\\\ x_{110} \\end{bmatrix} = \\\\\n", - "= \\left( \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix} \\otimes \n", + "\\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ x_{101} \\\\ x_{100} \\\\ x_{010} \\\\ x_{011} \\\\ x_{111} \\\\ x_{110} \\end{bmatrix} =$$\n", + "$$= \\left( \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix} \\otimes \n", "\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix} \\right) \n", "\\left( \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{000} \\\\ x_{001} \\end{bmatrix}\n", "+ \\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{101} \\\\ x_{100} \\end{bmatrix} \n", "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{010} \\\\ x_{011} \\end{bmatrix} \n", - "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{111} \\\\ x_{110} \\end{bmatrix} \\right) = \\\\\n", - "= \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{000} \\\\ x_{001} \\end{bmatrix}\n", + "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{111} \\\\ x_{110} \\end{bmatrix} \\right) =$$\n", + "$$= \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{000} \\\\ x_{001} \\end{bmatrix}\n", "+ \\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes \\color{green}{\\begin{bmatrix} x_{010} \\\\ x_{011} \\end{bmatrix}} \n", "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} \\otimes \\color{green}{\\begin{bmatrix} x_{101} \\\\ x_{100} \\end{bmatrix}} \n", "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{110} \\\\ x_{111} \\end{bmatrix}\n", From 797e20eed39e3711db6c72b9b6efc627b136840a Mon Sep 17 00:00:00 2001 From: Adam Kania Date: Fri, 29 Jul 2022 17:56:23 +0200 Subject: [PATCH 10/15] Fix rendering in MultiQubitGates (colors) --- tutorials/MultiQubitGates/MultiQubitGates.ipynb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tutorials/MultiQubitGates/MultiQubitGates.ipynb b/tutorials/MultiQubitGates/MultiQubitGates.ipynb index ce0bce97b8e..0009cfc5782 100644 --- a/tutorials/MultiQubitGates/MultiQubitGates.ipynb +++ b/tutorials/MultiQubitGates/MultiQubitGates.ipynb @@ -406,8 +406,8 @@ "\n", "$$\\text{CINOT}|\\psi\\rangle \n", "= x_{000} \\text{CINOT}|000\\rangle + x_{001} \\text{CINOT}|001\\rangle + x_{010} \\text{CINOT}|010\\rangle + x_{011} \\text{CINOT}|011\\rangle \\\\\n", - "+ \\color{red}{x_{100}} \\text{CINOT}|\\color{red}{100}\\rangle + \\color{red}{x_{101}} \\text{CINOT}|\\color{red}{101}\\rangle + \\color{red}{x_{110}} \\text{CINOT}|\\color{red}{110}\\rangle + \\color{red}{x_{111}} \\text{CINOT}|\\color{red}{111}\\rangle = \\\\\n", - "= x_{000}|000\\rangle + x_{001}|001\\rangle + x_{010}|010\\rangle + x_{011}|011\\rangle + \\color{red}{x_{101}}|100\\rangle + \\color{red}{x_{100}}|101\\rangle + \\color{red}{x_{111}}|110\\rangle + \\color{red}{x_{110}}|111\\rangle $$\n", + "+ {\\color{red}{x_{100}}} \\text{CINOT}|{\\color{red}{100}}\\rangle + {\\color{red}{x_{101}}} \\text{CINOT}|{\\color{red}{101}}\\rangle + {\\color{red}{x_{110}}} \\text{CINOT}|{\\color{red}{110}}\\rangle + {\\color{red}{x_{111}}} \\text{CINOT}|{\\color{red}{111}}\\rangle = \\\\\n", + "= x_{000}|000\\rangle + x_{001}|001\\rangle + x_{010}|010\\rangle + x_{011}|011\\rangle + {\\color{red}{x_{101}}}|100\\rangle + {\\color{red}{x_{100}}}|101\\rangle + {\\color{red}{x_{111}}}|110\\rangle + {\\color{red}{x_{110}}}|111\\rangle $$\n", "\n", "#### Matrix form\n", "\n", @@ -450,20 +450,20 @@ "These can be represented as applying the following gates on the 3 qubits. \n", "\n", "1. $\\text{SWAP} \\otimes I$\n", - "$$x_{000}|000\\rangle + x_{001}|001\\rangle + \\color{red}{x_{100}}|010\\rangle + \\color{red}{x_{101}}|011\\rangle + \n", - "\\color{red}{x_{010}}|100\\rangle + \\color{red}{x_{011}}|101\\rangle + x_{110}|110\\rangle + x_{111}|111\\rangle\n", + "$$x_{000}|000\\rangle + x_{001}|001\\rangle + {\\color{red}{x_{100}}}|010\\rangle + {\\color{red}{x_{101}}}|011\\rangle + \n", + "{\\color{red}{x_{010}}}|100\\rangle + {\\color{red}{x_{011}}}|101\\rangle + x_{110}|110\\rangle + x_{111}|111\\rangle\n", "$$\n", "\n", "2. $I \\otimes \\text{CNOT}$\n", "$$\n", - "x_{000}|000\\rangle + x_{001}|001\\rangle + \\color{blue}{x_{101}}|010\\rangle + \\color{blue}{x_{100}}|011\\rangle + \n", - "{x_{010}}|100\\rangle + {x_{011}}|101\\rangle + \\color{blue}{x_{111}}|110\\rangle + \\color{blue}{x_{110}}|111\\rangle\n", + "x_{000}|000\\rangle + x_{001}|001\\rangle + {\\color{blue}{x_{101}}}|010\\rangle + {\\color{blue}{x_{100}}}|011\\rangle + \n", + "{x_{010}}|100\\rangle + {x_{011}}|101\\rangle + {\\color{blue}{x_{111}}}|110\\rangle + {\\color{blue}{x_{110}}}|111\\rangle\n", "$$\n", "\n", "3. $\\text{SWAP} \\otimes I$\n", "$$\n", "x_{000}|000\\rangle + x_{001}|001\\rangle + {x_{010}}|010\\rangle + {x_{011}}|011\\rangle +\n", - "\\color{green}{x_{101}}|100\\rangle + \\color{green}{x_{100}}|101\\rangle + \\color{green}{x_{111}}|110\\rangle + \\color{green}{x_{110}}|111\\rangle\n", + "{\\color{green}{x_{101}}}|100\\rangle + {\\color{green}{x_{100}}}|101\\rangle + {\\color{green}{x_{111}}}|110\\rangle + {\\color{green}{x_{110}}}|111\\rangle\n", "$$\n", "\n", "The result is the the $\\text{CINOT}$ gate as we intended; so we can write\n", From 24c2610284adf0d427af605c63a4aa68a95aaa46 Mon Sep 17 00:00:00 2001 From: Adam Kania <48769688+remilvus@users.noreply.github.com> Date: Fri, 29 Jul 2022 18:03:32 +0200 Subject: [PATCH 11/15] Fix line break in MultiQubitGates --- tutorials/MultiQubitGates/MultiQubitGates.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tutorials/MultiQubitGates/MultiQubitGates.ipynb b/tutorials/MultiQubitGates/MultiQubitGates.ipynb index 0009cfc5782..8d73721b64e 100644 --- a/tutorials/MultiQubitGates/MultiQubitGates.ipynb +++ b/tutorials/MultiQubitGates/MultiQubitGates.ipynb @@ -405,9 +405,9 @@ "In Dirac notation we can consider the effect of the gate on each basis vector separately: each basis vector $|a_1a_2a_3\\rangle$ remains unchanged if $a_1 = 0$, and becomes $|a_1a_2(\\neg a_3)\\rangle$ if $a_1 = 1$. The full effect on the state becomes:\n", "\n", "$$\\text{CINOT}|\\psi\\rangle \n", - "= x_{000} \\text{CINOT}|000\\rangle + x_{001} \\text{CINOT}|001\\rangle + x_{010} \\text{CINOT}|010\\rangle + x_{011} \\text{CINOT}|011\\rangle \\\\\n", - "+ {\\color{red}{x_{100}}} \\text{CINOT}|{\\color{red}{100}}\\rangle + {\\color{red}{x_{101}}} \\text{CINOT}|{\\color{red}{101}}\\rangle + {\\color{red}{x_{110}}} \\text{CINOT}|{\\color{red}{110}}\\rangle + {\\color{red}{x_{111}}} \\text{CINOT}|{\\color{red}{111}}\\rangle = \\\\\n", - "= x_{000}|000\\rangle + x_{001}|001\\rangle + x_{010}|010\\rangle + x_{011}|011\\rangle + {\\color{red}{x_{101}}}|100\\rangle + {\\color{red}{x_{100}}}|101\\rangle + {\\color{red}{x_{111}}}|110\\rangle + {\\color{red}{x_{110}}}|111\\rangle $$\n", + "= x_{000} \\text{CINOT}|000\\rangle + x_{001} \\text{CINOT}|001\\rangle + x_{010} \\text{CINOT}|010\\rangle + x_{011} \\text{CINOT}|011\\rangle$$\n", + "$$+ {\\color{red}{x_{100}}} \\text{CINOT}|{\\color{red}{100}}\\rangle + {\\color{red}{x_{101}}} \\text{CINOT}|{\\color{red}{101}}\\rangle + {\\color{red}{x_{110}}} \\text{CINOT}|{\\color{red}{110}}\\rangle + {\\color{red}{x_{111}}} \\text{CINOT}|{\\color{red}{111}}\\rangle =$$\n", + "$$= x_{000}|000\\rangle + x_{001}|001\\rangle + x_{010}|010\\rangle + x_{011}|011\\rangle + {\\color{red}{x_{101}}}|100\\rangle + {\\color{red}{x_{100}}}|101\\rangle + {\\color{red}{x_{111}}}|110\\rangle + {\\color{red}{x_{110}}}|111\\rangle $$\n", "\n", "#### Matrix form\n", "\n", From 8dbd90b701304e11b49d4ac8094147a05f6b68e4 Mon Sep 17 00:00:00 2001 From: Adam Kania <48769688+remilvus@users.noreply.github.com> Date: Fri, 29 Jul 2022 18:04:47 +0200 Subject: [PATCH 12/15] Fix line break in MultiQubitGates --- tutorials/MultiQubitGates/MultiQubitGates.ipynb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tutorials/MultiQubitGates/MultiQubitGates.ipynb b/tutorials/MultiQubitGates/MultiQubitGates.ipynb index 8d73721b64e..8e342e6d1e9 100644 --- a/tutorials/MultiQubitGates/MultiQubitGates.ipynb +++ b/tutorials/MultiQubitGates/MultiQubitGates.ipynb @@ -302,13 +302,13 @@ "> Here's what the decomposition looks like:\n", ">\n", "> $$\\text{CNOT} = |00\\rangle\\langle00| + |01\\rangle\\langle01| + \n", - "|1\\rangle \\otimes |+\\rangle\\langle1| \\otimes \\langle +| - |1\\rangle \\otimes| -\\rangle\\langle1| \\otimes \\langle -| = \\\\\n", - "= |00\\rangle\\langle00| + |01\\rangle\\langle01| + \n", - "\\frac{1}{2}\\big[\\big(|10\\rangle + |11\\rangle\\big)\\big(\\langle10| + \\langle11|\\big) - \\big(|10\\rangle - |11\\rangle\\big)\\big(\\langle10| - \\langle11|\\big)\\big] = \\\\\n", - "= |00\\rangle\\langle00| + |01\\rangle\\langle01| +\n", - "\\frac{1}{2}\\big({\\color{red}{|10\\rangle\\langle10|}} + |10\\rangle\\langle11| + |11\\rangle\\langle10| + {\\color{red}{|11\\rangle\\langle11|}} - {\\color{red}{|10\\rangle\\langle10|}} + |10\\rangle\\langle11| + |11\\rangle\\langle10| - {\\color{red}{|11\\rangle\\langle11|}}\\big) = \\\\\n", - "= |00\\rangle\\langle00| + |01\\rangle\\langle01| + \\frac{1}{2}\\big(2|10\\rangle\\langle11| + 2|11\\rangle\\langle10|\\big) = \\\\ \n", - "= |00\\rangle\\langle00| + |01\\rangle\\langle01| + |10\\rangle\\langle11| + |11\\rangle\\langle10|$$" + "|1\\rangle \\otimes |+\\rangle\\langle1| \\otimes \\langle +| - |1\\rangle \\otimes| -\\rangle\\langle1| \\otimes \\langle -| =$$\n", + ">$$= |00\\rangle\\langle00| + |01\\rangle\\langle01| + \n", + "\\frac{1}{2}\\big[\\big(|10\\rangle + |11\\rangle\\big)\\big(\\langle10| + \\langle11|\\big) - \\big(|10\\rangle - |11\\rangle\\big)\\big(\\langle10| - \\langle11|\\big)\\big] =$$\n", + ">$$= |00\\rangle\\langle00| + |01\\rangle\\langle01| +\n", + "\\frac{1}{2}\\big({\\color{red}{|10\\rangle\\langle10|}} + |10\\rangle\\langle11| + |11\\rangle\\langle10| + {\\color{red}{|11\\rangle\\langle11|}} - {\\color{red}{|10\\rangle\\langle10|}} + |10\\rangle\\langle11| + |11\\rangle\\langle10| - {\\color{red}{|11\\rangle\\langle11|}}\\big) =$$\n", + ">$$= |00\\rangle\\langle00| + |01\\rangle\\langle01| + \\frac{1}{2}\\big(2|10\\rangle\\langle11| + 2|11\\rangle\\langle10|\\big) =$$\n", + ">$$= |00\\rangle\\langle00| + |01\\rangle\\langle01| + |10\\rangle\\langle11| + |11\\rangle\\langle10|$$" ] }, { From 9c216fa70130827762d0266d145e4a61fce779e3 Mon Sep 17 00:00:00 2001 From: Adam Kania Date: Fri, 29 Jul 2022 18:18:43 +0200 Subject: [PATCH 13/15] Fix rendering in MultiQubitGates (color) --- .../MultiQubitGates/MultiQubitGates.ipynb | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tutorials/MultiQubitGates/MultiQubitGates.ipynb b/tutorials/MultiQubitGates/MultiQubitGates.ipynb index 8e342e6d1e9..62dc583cd52 100644 --- a/tutorials/MultiQubitGates/MultiQubitGates.ipynb +++ b/tutorials/MultiQubitGates/MultiQubitGates.ipynb @@ -528,10 +528,10 @@ "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{100} \\\\ x_{101} \\end{bmatrix} \n", "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{110} \\\\ x_{111} \\end{bmatrix} \\right) =$$\n", "$$= \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{000} \\\\ x_{001} \\end{bmatrix}\n", - "+ \\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes \\color{red}{\\begin{bmatrix} x_{100} \\\\ x_{101} \\end{bmatrix}} \n", - "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} \\otimes \\color{red}{\\begin{bmatrix} x_{010} \\\\ x_{011} \\end{bmatrix}} \n", + "+ \\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes {\\color{red}{\\begin{bmatrix} x_{100} \\\\ x_{101} \\end{bmatrix}}} \n", + "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} \\otimes {\\color{red}{\\begin{bmatrix} x_{010} \\\\ x_{011} \\end{bmatrix}}} \n", "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{110} \\\\ x_{111} \\end{bmatrix} \n", - "= \\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ \\color{red}{x_{100} \\\\ x_{101} \\\\ x_{010} \\\\ x_{011}} \\\\ x_{110} \\\\ x_{111} \\end{bmatrix}\n", + "= \\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ {\\color{red}{x_{100} \\\\ x_{101} \\\\ x_{010} \\\\ x_{011}}} \\\\ x_{110} \\\\ x_{111} \\end{bmatrix}\n", "$$\n", "\n", "2. $\\text{CNOT}$ 2nd and 3rd qubits.\n", @@ -548,9 +548,9 @@ "= \\\\ \n", "= \\begin{bmatrix} x_{000} \\\\ x_{010} \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} \n", "+ \\begin{bmatrix} x_{001} \\\\ x_{011} \\end{bmatrix} \\otimes \\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} \n", - "+ \\color{blue}{\\begin{bmatrix} x_{101} \\\\ x_{111} \\end{bmatrix}} \\otimes \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix}\n", - "+ \\color{blue}{\\begin{bmatrix} x_{100} \\\\ x_{110} \\end{bmatrix}} \\otimes \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \n", - "= \\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ \\color{blue}{x_{101} \\\\ x_{100}} \\\\ x_{010} \\\\ x_{011} \\\\ \\color{blue}{x_{111} \\\\ x_{110}} \\end{bmatrix}$$\n", + "+ {\\color{blue}{\\begin{bmatrix} x_{101} \\\\ x_{111} \\end{bmatrix}}} \\otimes \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix}\n", + "+ {\\color{blue}{\\begin{bmatrix} x_{100} \\\\ x_{110} \\end{bmatrix}}} \\otimes \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \n", + "= \\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ {\\color{blue}{x_{101} \\\\ x_{100}}} \\\\ x_{010} \\\\ x_{011} \\\\ {\\color{blue}{x_{111} \\\\ x_{110}}} \\end{bmatrix}$$\n", "\n", "3. $\\text{SWAP}$ 1st and 2nd qubits.\n", "$$\n", @@ -564,10 +564,10 @@ "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{010} \\\\ x_{011} \\end{bmatrix} \n", "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{111} \\\\ x_{110} \\end{bmatrix} \\right) =$$\n", "$$= \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{000} \\\\ x_{001} \\end{bmatrix}\n", - "+ \\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes \\color{green}{\\begin{bmatrix} x_{010} \\\\ x_{011} \\end{bmatrix}} \n", - "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} \\otimes \\color{green}{\\begin{bmatrix} x_{101} \\\\ x_{100} \\end{bmatrix}} \n", + "+ \\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes {\\color{green}{\\begin{bmatrix} x_{010} \\\\ x_{011} \\end{bmatrix}}}\n", + "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} \\otimes {\\color{green}{\\begin{bmatrix} x_{101} \\\\ x_{100} \\end{bmatrix}}} \n", "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{110} \\\\ x_{111} \\end{bmatrix}\n", - "= \\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ \\color{green}{x_{010} \\\\ x_{011} \\\\ x_{101} \\\\ x_{100}} \\\\ x_{110} \\\\ x_{111} \\end{bmatrix}\n", + "= \\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ {\\color{green}{x_{010} \\\\ x_{011} \\\\ x_{101} \\\\ x_{100}}} \\\\ x_{110} \\\\ x_{111} \\end{bmatrix}\n", "$$\n", "" ] @@ -843,7 +843,7 @@ "file_extension": ".qs", "mimetype": "text/x-qsharp", "name": "qsharp", - "version": "0.14" + "version": "0.24" } }, "nbformat": 4, From ea948d50ad2f529c05745300d48c5954c0101fa0 Mon Sep 17 00:00:00 2001 From: Adam Kania Date: Fri, 29 Jul 2022 18:24:36 +0200 Subject: [PATCH 14/15] Fix rendering in MultiQubitGates (lines) --- tutorials/MultiQubitGates/MultiQubitGates.ipynb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tutorials/MultiQubitGates/MultiQubitGates.ipynb b/tutorials/MultiQubitGates/MultiQubitGates.ipynb index 62dc583cd52..4c6ad30cd99 100644 --- a/tutorials/MultiQubitGates/MultiQubitGates.ipynb +++ b/tutorials/MultiQubitGates/MultiQubitGates.ipynb @@ -531,7 +531,7 @@ "+ \\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes {\\color{red}{\\begin{bmatrix} x_{100} \\\\ x_{101} \\end{bmatrix}}} \n", "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} \\otimes {\\color{red}{\\begin{bmatrix} x_{010} \\\\ x_{011} \\end{bmatrix}}} \n", "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{110} \\\\ x_{111} \\end{bmatrix} \n", - "= \\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ {\\color{red}{x_{100} \\\\ x_{101} \\\\ x_{010} \\\\ x_{011}}} \\\\ x_{110} \\\\ x_{111} \\end{bmatrix}\n", + "= \\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ {\\color{red}{x_{100}}} \\\\ {\\color{red}{x_{101}}} \\\\ {\\color{red}{x_{010}}} \\\\ {\\color{red}{x_{011}}} \\\\ x_{110} \\\\ x_{111} \\end{bmatrix}\n", "$$\n", "\n", "2. $\\text{CNOT}$ 2nd and 3rd qubits.\n", @@ -545,12 +545,12 @@ "+ \\begin{bmatrix} x_{001} \\\\ x_{011} \\end{bmatrix} \\otimes \\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} \n", "+ \\begin{bmatrix} x_{100} \\\\ x_{110} \\end{bmatrix} \\otimes \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} \n", "+ \\begin{bmatrix} x_{101} \\\\ x_{111} \\end{bmatrix} \\otimes \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\right)\n", - "= \\\\ \n", - "= \\begin{bmatrix} x_{000} \\\\ x_{010} \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} \n", + "=$$ \n", + "$$= \\begin{bmatrix} x_{000} \\\\ x_{010} \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} \n", "+ \\begin{bmatrix} x_{001} \\\\ x_{011} \\end{bmatrix} \\otimes \\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} \n", "+ {\\color{blue}{\\begin{bmatrix} x_{101} \\\\ x_{111} \\end{bmatrix}}} \\otimes \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix}\n", "+ {\\color{blue}{\\begin{bmatrix} x_{100} \\\\ x_{110} \\end{bmatrix}}} \\otimes \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \n", - "= \\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ {\\color{blue}{x_{101} \\\\ x_{100}}} \\\\ x_{010} \\\\ x_{011} \\\\ {\\color{blue}{x_{111} \\\\ x_{110}}} \\end{bmatrix}$$\n", + "= \\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ {\\color{blue}{x_{101}}} \\\\ {\\color{blue}{x_{100}}} \\\\ x_{010} \\\\ x_{011} \\\\ {\\color{blue}{x_{111}}} \\\\ {\\color{blue}{x_{110}}} \\end{bmatrix}$$\n", "\n", "3. $\\text{SWAP}$ 1st and 2nd qubits.\n", "$$\n", @@ -567,7 +567,7 @@ "+ \\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\end{bmatrix} \\otimes {\\color{green}{\\begin{bmatrix} x_{010} \\\\ x_{011} \\end{bmatrix}}}\n", "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{bmatrix} \\otimes {\\color{green}{\\begin{bmatrix} x_{101} \\\\ x_{100} \\end{bmatrix}}} \n", "+ \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\otimes \\begin{bmatrix} x_{110} \\\\ x_{111} \\end{bmatrix}\n", - "= \\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ {\\color{green}{x_{010} \\\\ x_{011} \\\\ x_{101} \\\\ x_{100}}} \\\\ x_{110} \\\\ x_{111} \\end{bmatrix}\n", + "= \\begin{bmatrix} x_{000} \\\\ x_{001} \\\\ {\\color{green}{x_{010}}} \\\\ {\\color{green}{x_{011}}} \\\\ {\\color{green}{x_{101}}} \\\\ {\\color{green}{x_{100}}}\\\\ x_{110} \\\\ x_{111} \\end{bmatrix}\n", "$$\n", "" ] From 6e2c9b99880e6f3bfc845bb63ea51664ca554fb4 Mon Sep 17 00:00:00 2001 From: Mariia Mykhailova Date: Wed, 3 Aug 2022 16:21:25 -0700 Subject: [PATCH 15/15] Fix two typos and remove cell IDs --- BasicGates/Workbook_BasicGates.ipynb | 132 +----------------- .../MultiQubitGates/MultiQubitGates.ipynb | 4 +- 2 files changed, 3 insertions(+), 133 deletions(-) diff --git a/BasicGates/Workbook_BasicGates.ipynb b/BasicGates/Workbook_BasicGates.ipynb index 440513ec9ff..a84928ca0ef 100644 --- a/BasicGates/Workbook_BasicGates.ipynb +++ b/BasicGates/Workbook_BasicGates.ipynb @@ -2,7 +2,6 @@ "cells": [ { "cell_type": "markdown", - "id": "08b341ed", "metadata": { "tags": [] }, @@ -20,7 +19,6 @@ }, { "cell_type": "markdown", - "id": "3518d868", "metadata": {}, "source": [ "**What you should know for this workbook**\n", @@ -37,7 +35,6 @@ }, { "cell_type": "markdown", - "id": "ac84ea42", "metadata": {}, "source": [ "# Part 1. Single-Qubit Gates" @@ -45,7 +42,6 @@ }, { "cell_type": "markdown", - "id": "d8fb9f6f", "metadata": { "jp-MarkdownHeadingCollapsed": true, "tags": [] @@ -66,7 +62,6 @@ }, { "cell_type": "markdown", - "id": "9352232d", "metadata": {}, "source": [ "### Solution" @@ -74,7 +69,6 @@ }, { "cell_type": "markdown", - "id": "8eed54c9", "metadata": {}, "source": [ "We can recognize that the Pauli X gate will change the state $|0\\rangle$ to $|1\\rangle$ and vice versa, and $\\alpha |0\\rangle + \\beta |1\\rangle$ to $\\alpha |1\\rangle + \\beta |0\\rangle$.\n", @@ -84,7 +78,6 @@ }, { "cell_type": "markdown", - "id": "571ec0ad", "metadata": {}, "source": [ "$$\n", @@ -100,7 +93,6 @@ }, { "cell_type": "markdown", - "id": "4783f3bc", "metadata": {}, "source": [ "$$X|0\\rangle= \n", @@ -128,7 +120,6 @@ }, { "cell_type": "markdown", - "id": "ea904409", "metadata": {}, "source": [ "Similarly, we can consider the effect of the X gate on the superposition state $|\\psi\\rangle = 0.6|0\\rangle + 0.8|1\\rangle$:" @@ -136,7 +127,6 @@ }, { "cell_type": "markdown", - "id": "cca0689e", "metadata": {}, "source": [ "$$X|\\psi\\rangle= \n", @@ -165,7 +155,6 @@ { "cell_type": "code", "execution_count": null, - "id": "eb5280e4", "metadata": {}, "outputs": [], "source": [ @@ -178,7 +167,6 @@ }, { "cell_type": "markdown", - "id": "d641d015", "metadata": {}, "source": [ "[Return to Task 1.1 of the Basic Gates kata.](./BasicGates.ipynb#Task-1.1.-State-flip:-$|0\\rangle$-to-$|1\\rangle$-and-vice-versa)" @@ -186,7 +174,6 @@ }, { "cell_type": "markdown", - "id": "b7334694", "metadata": { "tags": [] }, @@ -203,7 +190,6 @@ }, { "cell_type": "markdown", - "id": "37723ac7", "metadata": {}, "source": [ "### Solution" @@ -211,7 +197,6 @@ }, { "cell_type": "markdown", - "id": "9ae4bd06", "metadata": { "tags": [] }, @@ -223,7 +208,6 @@ }, { "cell_type": "markdown", - "id": "4affd231", "metadata": { "tags": [] }, @@ -240,7 +224,6 @@ }, { "cell_type": "markdown", - "id": "3e9cff65", "metadata": { "tags": [] }, @@ -271,7 +254,6 @@ }, { "cell_type": "markdown", - "id": "902e503e", "metadata": {}, "source": [ "Similarly, we can consider the effect of the Hadamard gate on the superposition state $|\\psi\\rangle = 0.6|0\\rangle + 0.8|1\\rangle$ (rounding the numbers to 4 decimal places):" @@ -279,7 +261,6 @@ }, { "cell_type": "markdown", - "id": "6be890e3", "metadata": {}, "source": [ "$$\n", @@ -312,7 +293,6 @@ { "cell_type": "code", "execution_count": null, - "id": "c31ba04d", "metadata": {}, "outputs": [], "source": [ @@ -325,7 +305,6 @@ }, { "cell_type": "markdown", - "id": "0ed1eb80", "metadata": {}, "source": [ "[Return to Task 1.2 of the Basic Gates kata](./BasicGates.ipynb#Task-1.2.-Basis-change:-$|0\\rangle$-to-$|+\\rangle$-and-$|1\\rangle$-to-$|-\\rangle$-(and-vice-versa))." @@ -333,7 +312,6 @@ }, { "cell_type": "markdown", - "id": "040d446b", "metadata": {}, "source": [ " " @@ -341,7 +319,6 @@ }, { "cell_type": "markdown", - "id": "d2f58d77", "metadata": {}, "source": [ "## Task 1.3. Sign flip: $|+\\rangle$ to $|-\\rangle$ and vice versa.\n", @@ -353,7 +330,6 @@ }, { "cell_type": "markdown", - "id": "d98d3f8c", "metadata": {}, "source": [ "### Solution" @@ -361,7 +337,6 @@ }, { "cell_type": "markdown", - "id": "708e93ff", "metadata": {}, "source": [ "The action of the Pauli Z gate is exactly what is required by this question.\n", @@ -372,7 +347,6 @@ }, { "cell_type": "markdown", - "id": "23394efb", "metadata": {}, "source": [ "$$\n", @@ -416,7 +390,6 @@ }, { "cell_type": "markdown", - "id": "a3677492", "metadata": {}, "source": [ "In general applying the Z gate to a single qubit superposition state $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$ gives" @@ -424,7 +397,6 @@ }, { "cell_type": "markdown", - "id": "2d1e7e97", "metadata": {}, "source": [ "$$\n", @@ -454,7 +426,6 @@ { "cell_type": "code", "execution_count": null, - "id": "0c4e1d89", "metadata": { "tags": [] }, @@ -469,7 +440,6 @@ }, { "cell_type": "markdown", - "id": "f7807d03", "metadata": {}, "source": [ "[Return to Task 1.3 of the Basic Gates kata](./BasicGates.ipynb#Task-1.3.-Sign-flip:-$|+\\rangle$--to-$|-\\rangle$--and-vice-versa.)." @@ -477,7 +447,6 @@ }, { "cell_type": "markdown", - "id": "0f805114", "metadata": { "tags": [] }, @@ -497,7 +466,6 @@ }, { "cell_type": "markdown", - "id": "6fe379f8", "metadata": {}, "source": [ "### Solution" @@ -505,7 +473,6 @@ }, { "cell_type": "markdown", - "id": "ae7f2616", "metadata": {}, "source": [ "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 $|0\\rangle$ and $|1\\rangle$ to have real amplitudes (the other two gates introduce complex coefficients).\n", @@ -515,7 +482,6 @@ }, { "cell_type": "markdown", - "id": "57777d72", "metadata": {}, "source": [ "$$\n", @@ -529,7 +495,6 @@ }, { "cell_type": "markdown", - "id": "b33786ab", "metadata": {}, "source": [ "Let's see its effect on the $|0\\rangle$ state:" @@ -537,7 +502,6 @@ }, { "cell_type": "markdown", - "id": "731e2fc6", "metadata": {}, "source": [ "$$\n", @@ -566,7 +530,6 @@ }, { "cell_type": "markdown", - "id": "0610a9fe", "metadata": {}, "source": [ "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 $|0\\rangle$ state, and the second column is the state into which it will transform the $|1\\rangle$ state." @@ -574,7 +537,6 @@ }, { "cell_type": "markdown", - "id": "10a1735f", "metadata": {}, "source": [ "In the example used by the testing harness we are given $\\beta = 0.6, \\gamma = 0.8$ and $\\alpha = 1.0471975511965976 = \\frac{\\pi}{3}$." @@ -582,7 +544,6 @@ }, { "cell_type": "markdown", - "id": "7987103d", "metadata": {}, "source": [ "Since $\\cos \\frac{\\pi}{3} = 0.5$ and $\\sin \\frac{\\pi}{3} = 0.8660$, working to 4 decimal places, we can compute:" @@ -590,7 +551,6 @@ }, { "cell_type": "markdown", - "id": "79a3cf4a", "metadata": {}, "source": [ "$$\n", @@ -629,7 +589,6 @@ }, { "cell_type": "markdown", - "id": "a9925bef", "metadata": {}, "source": [ "Notice that we used $\\frac{\\theta}{2} = \\alpha$; this means that in the Q# code we need to pass the angle $\\theta = 2\\alpha$." @@ -638,7 +597,6 @@ { "cell_type": "code", "execution_count": null, - "id": "76806a63", "metadata": {}, "outputs": [], "source": [ @@ -651,7 +609,6 @@ }, { "cell_type": "markdown", - "id": "0f633d2e", "metadata": {}, "source": [ "[Return to Task 1.4 of the Basic Gates kata](./BasicGates.ipynb#Task-1.4.-Amplitude-change:-$|0\\rangle$-to-$\\cos{α}-|0\\rangle-+-\\sin{α}-|1\\rangle$.)." @@ -659,7 +616,6 @@ }, { "cell_type": "markdown", - "id": "f602eca2", "metadata": {}, "source": [ "## Task 1.5. Phase flip\n", @@ -671,7 +627,6 @@ }, { "cell_type": "markdown", - "id": "53979f74", "metadata": {}, "source": [ "### Solution\n", @@ -681,7 +636,6 @@ }, { "cell_type": "markdown", - "id": "f6bf8c81", "metadata": {}, "source": [ "$$\n", @@ -695,7 +649,6 @@ }, { "cell_type": "markdown", - "id": "529f3a15", "metadata": {}, "source": [ "Let's see the effect of this gate on the general superposition $|\\psi\\rangle = \\alpha |0\\rangle + \\beta |1\\rangle$." @@ -703,7 +656,6 @@ }, { "cell_type": "markdown", - "id": "e915ee67", "metadata": {}, "source": [ "$$\n", @@ -730,7 +682,6 @@ }, { "cell_type": "markdown", - "id": "673ab60c", "metadata": {}, "source": [ "It is therefore easy to see that when $|\\psi\\rangle = 0.6|0\\rangle + 0.8|1\\rangle, S|\\psi\\rangle = 0.6|0\\rangle + 0.8i|1\\rangle$." @@ -739,7 +690,6 @@ { "cell_type": "code", "execution_count": null, - "id": "d18c3b7d", "metadata": {}, "outputs": [], "source": [ @@ -752,7 +702,6 @@ }, { "cell_type": "markdown", - "id": "ed15b83a", "metadata": {}, "source": [ "### Solution 2\n", @@ -763,7 +712,6 @@ { "cell_type": "code", "execution_count": null, - "id": "e1709a88", "metadata": {}, "outputs": [], "source": [ @@ -778,7 +726,6 @@ }, { "cell_type": "markdown", - "id": "96ad3638", "metadata": {}, "source": [ "[Return to Task 1.5 of the Basic Gates kata](./BasicGates.ipynb#Task-1.5.-Phase-flip)." @@ -786,7 +733,6 @@ }, { "cell_type": "markdown", - "id": "6f01ebf6", "metadata": {}, "source": [ "## Task 1.6. Phase change\n", @@ -804,7 +750,6 @@ }, { "cell_type": "markdown", - "id": "e47dd632", "metadata": {}, "source": [ "### Solution\n", @@ -813,7 +758,6 @@ }, { "cell_type": "markdown", - "id": "99e25061", "metadata": {}, "source": [ "$$\n", @@ -828,7 +772,6 @@ }, { "cell_type": "markdown", - "id": "77bcb993", "metadata": {}, "source": [ "So we have:" @@ -836,7 +779,6 @@ }, { "cell_type": "markdown", - "id": "cb9570f7", "metadata": {}, "source": [ "$$\n", @@ -865,7 +807,6 @@ }, { "cell_type": "markdown", - "id": "6d87c8ad", "metadata": {}, "source": [ "> Note that the results produced by the test harness can be unexpected.\n", @@ -883,7 +824,6 @@ { "cell_type": "code", "execution_count": null, - "id": "4fe80339", "metadata": {}, "outputs": [], "source": [ @@ -896,7 +836,6 @@ }, { "cell_type": "markdown", - "id": "5c1711c7", "metadata": {}, "source": [ "Suppose now that $\\alpha = \\frac{\\pi}{2}$.\n", @@ -907,7 +846,6 @@ }, { "cell_type": "markdown", - "id": "56490e4e", "metadata": {}, "source": [ "[Return to Task 1.6 of the Basic Gates kata](./BasicGates.ipynb#Task-1.6.-Phase-Change)." @@ -915,7 +853,6 @@ }, { "cell_type": "markdown", - "id": "5e4885b0", "metadata": {}, "source": [ "## Task 1.7. Global phase change\n", @@ -930,7 +867,6 @@ }, { "cell_type": "markdown", - "id": "e74f38aa", "metadata": {}, "source": [ "### Solution\n", @@ -944,7 +880,6 @@ }, { "cell_type": "markdown", - "id": "fee6138f", "metadata": {}, "source": [ "For the problem at hand, we'll use the rotation gate $R_{\\mu}(\\theta) = \\exp(\\frac{\\theta}{2}i\\cdot\\sigma_{\\mu})$ with $\\sigma_{\\mu} = I$. \n", @@ -954,7 +889,6 @@ }, { "cell_type": "markdown", - "id": "0af70ee2", "metadata": {}, "source": [ "$$\n", @@ -994,7 +928,6 @@ }, { "cell_type": "markdown", - "id": "a25311a9", "metadata": {}, "source": [ "The test harness for this test shows the result of applying the *controlled* variant of your solution to be able to detect the phase change." @@ -1003,7 +936,6 @@ { "cell_type": "code", "execution_count": null, - "id": "ce9e8cd8", "metadata": {}, "outputs": [], "source": [ @@ -1018,7 +950,6 @@ }, { "cell_type": "markdown", - "id": "6f1b9945", "metadata": {}, "source": [ "[Return to Task 1.7 of the Basic Gates kata](./BasicGates.ipynb#Task-1.7.-Global-phase-change)." @@ -1026,7 +957,6 @@ }, { "cell_type": "markdown", - "id": "50909364", "metadata": {}, "source": [ "## Task 1.8. Bell state change - 1\n", @@ -1038,7 +968,6 @@ }, { "cell_type": "markdown", - "id": "cf8dec6b", "metadata": {}, "source": [ "### Solution" @@ -1046,7 +975,6 @@ }, { "cell_type": "markdown", - "id": "1e90fc5e", "metadata": {}, "source": [ "We recognize that the goal is another Bell state. In fact, it is one of the four Bell states.\n", @@ -1062,7 +990,6 @@ }, { "cell_type": "markdown", - "id": "63ea5481", "metadata": {}, "source": [ "If we apply the Z gate to the qubit A, it will flip the phase of the basis state $|1_A\\rangle$. As this phase is in a sense spread across the entangled state, with $|1_A\\rangle$ basis state being part of the second half of the superposition, this application has the effect of flipping the sign of the whole basis state $|1_A1_B\\rangle$, as you can see by running the solution below. \n", @@ -1078,7 +1005,6 @@ { "cell_type": "code", "execution_count": null, - "id": "212bf887", "metadata": {}, "outputs": [], "source": [ @@ -1091,7 +1017,6 @@ }, { "cell_type": "markdown", - "id": "7573cc28", "metadata": {}, "source": [ "[Return to Task 1.8 of the Basic Gates kata](./BasicGates.ipynb#Task-1.8.-Bell-state-change---1)." @@ -1099,7 +1024,6 @@ }, { "cell_type": "markdown", - "id": "5031d150", "metadata": {}, "source": [ "## Task 1.9. Bell state change - 2\n", @@ -1111,7 +1035,6 @@ }, { "cell_type": "markdown", - "id": "d2b7a7bc", "metadata": {}, "source": [ "### Solution ##\n", @@ -1125,7 +1048,6 @@ { "cell_type": "code", "execution_count": null, - "id": "fac2ab43", "metadata": { "scrolled": true }, @@ -1140,7 +1062,6 @@ }, { "cell_type": "markdown", - "id": "2fad3a01", "metadata": {}, "source": [ "[Return to Task 1.9 of the Basic Gates kata](./BasicGates.ipynb#Task-1.9.-Bell-state-change---2)." @@ -1148,7 +1069,6 @@ }, { "cell_type": "markdown", - "id": "8d15a443", "metadata": {}, "source": [ "## Task 1.10. Bell state change - 3\n", @@ -1160,7 +1080,6 @@ }, { "cell_type": "markdown", - "id": "ab78ed82", "metadata": {}, "source": [ "### Solution ##\n", @@ -1175,7 +1094,6 @@ { "cell_type": "code", "execution_count": null, - "id": "5cba6fcf", "metadata": {}, "outputs": [], "source": [ @@ -1189,7 +1107,6 @@ }, { "cell_type": "markdown", - "id": "2580bcc0", "metadata": {}, "source": [ "[Return to Task 1.10 of the Basic Gates kata](./BasicGates.ipynb#Task-1.10.-Bell-state-change---3)." @@ -1197,7 +1114,6 @@ }, { "cell_type": "markdown", - "id": "e852abeb", "metadata": {}, "source": [ "# Part II. Multi-Qubit Gates\n", @@ -1213,7 +1129,6 @@ }, { "cell_type": "markdown", - "id": "06172f60", "metadata": {}, "source": [ "### Solution\n", @@ -1228,7 +1143,6 @@ { "cell_type": "code", "execution_count": null, - "id": "3f8c13e6", "metadata": {}, "outputs": [], "source": [ @@ -1241,7 +1155,6 @@ }, { "cell_type": "markdown", - "id": "d1c26753", "metadata": {}, "source": [ "[Return to Task 2.1 of the Basic Gates kata](./BasicGates.ipynb#Task-2.1.-Two-qubit-gate---1)." @@ -1249,7 +1162,6 @@ }, { "cell_type": "markdown", - "id": "acb00b18", "metadata": {}, "source": [ "## Task 2.2. Two-qubit gate - 2\n", @@ -1262,7 +1174,6 @@ }, { "cell_type": "markdown", - "id": "8eb87a61", "metadata": {}, "source": [ "### Solution\n", @@ -1271,7 +1182,6 @@ }, { "cell_type": "markdown", - "id": "190868fc", "metadata": {}, "source": [ "In vector form the transformation we need is \n", @@ -1294,7 +1204,6 @@ }, { "cell_type": "markdown", - "id": "17aa3939", "metadata": {}, "source": [ "All that needs to happen to change the input into the goal is that the $|11\\rangle$ basis state needs to have its sign flipped. \n", @@ -1305,7 +1214,6 @@ }, { "cell_type": "markdown", - "id": "6a90f3d3", "metadata": {}, "source": [ "Similarly to task 2.1, the phase shift only occurs on one of the basis states, so this suggests it might be a conditional shift. If we could have our phase shift applied to `qs[1]` conditional on `qs[0]` being in the state $|1\\rangle$, then we would have a description of our gate. If we now look though a list of gates in the [Single-qubit gates tutorial](../tutorials/SingleQubitGates/SingleQubitGates.ipynb), we'll find the R1 phase shift gate with angle parameter $\\theta$ (radians), defined as\n", @@ -1322,7 +1230,6 @@ }, { "cell_type": "markdown", - "id": "d7146bed", "metadata": {}, "source": [ "The controlled variant of this gate will look like this:\n", @@ -1339,7 +1246,6 @@ }, { "cell_type": "markdown", - "id": "94ab2ff7", "metadata": {}, "source": [ "This gate is almost Pauli I, the identity gate, with the different in just the last column, showing what will happen to the $|11\\rangle$ basis state. Applying it to our input state for $\\alpha = \\pi$, we'll get:" @@ -1347,7 +1253,6 @@ }, { "cell_type": "markdown", - "id": "96773152", "metadata": {}, "source": [ "$$\n", @@ -1379,7 +1284,6 @@ }, { "cell_type": "markdown", - "id": "21b2b412", "metadata": {}, "source": [ "The last thing we notice if we look through the [list of operations in the Microsoft.Quantum.Canon namespace](https://docs.microsoft.com/en-us/qsharp/api/qsharp/microsoft.quantum.canon) is the CZ (Controlled Z) gate, a special case of CR1 that implements exactly this gate." @@ -1388,7 +1292,6 @@ { "cell_type": "code", "execution_count": null, - "id": "bf116783", "metadata": { "scrolled": true }, @@ -1403,7 +1306,6 @@ }, { "cell_type": "markdown", - "id": "df30893f", "metadata": {}, "source": [ "Alternatively, we can express this gate using the intrinsic gate Z and its controlled variant using the Controlled functor:" @@ -1412,7 +1314,6 @@ { "cell_type": "code", "execution_count": null, - "id": "faca3173", "metadata": {}, "outputs": [], "source": [ @@ -1425,7 +1326,6 @@ }, { "cell_type": "markdown", - "id": "e4721003", "metadata": {}, "source": [ "[Return to Task 2.2 of the Basic Gates kata](./BasicGates.ipynb#Task-2.2.-Two-qubit-gate---2)." @@ -1433,7 +1333,6 @@ }, { "cell_type": "markdown", - "id": "024fd8b5", "metadata": {}, "source": [ "## Task 2.3. Two-qubit gate - 3\n", @@ -1448,7 +1347,6 @@ }, { "cell_type": "markdown", - "id": "414cea33", "metadata": {}, "source": [ "## Solution\n", @@ -1460,7 +1358,6 @@ }, { "cell_type": "markdown", - "id": "45ead206", "metadata": {}, "source": [ "$$\n", @@ -1476,7 +1373,6 @@ }, { "cell_type": "markdown", - "id": "624f23bd", "metadata": {}, "source": [ "and our input state vector is:" @@ -1484,7 +1380,6 @@ }, { "cell_type": "markdown", - "id": "ea2da222", "metadata": {}, "source": [ "$$\n", @@ -1498,7 +1393,6 @@ }, { "cell_type": "markdown", - "id": "5f1ab7ea", "metadata": {}, "source": [ "So operating on our input state vector with the SWAP gate gives us" @@ -1506,7 +1400,6 @@ }, { "cell_type": "markdown", - "id": "ea5bfd55", "metadata": {}, "source": [ "$$\n", @@ -1536,7 +1429,6 @@ }, { "cell_type": "markdown", - "id": "70ec1d62", "metadata": {}, "source": [ "and we can confirm this with the task solution:" @@ -1545,7 +1437,6 @@ { "cell_type": "code", "execution_count": null, - "id": "fc61a027", "metadata": {}, "outputs": [], "source": [ @@ -1558,7 +1449,6 @@ }, { "cell_type": "markdown", - "id": "a73e1253", "metadata": {}, "source": [ "> If you run this solution a few times you might see an apparent anomaly. The test harness uses an input state that has positive values of $\\alpha$ and $\\delta$ and negative values of $\\beta$ and $\\gamma$, while\n", @@ -1568,7 +1458,6 @@ }, { "cell_type": "markdown", - "id": "6bbccd7e", "metadata": {}, "source": [ "Let's now follow the hint in the question and try to express the solution using several (possibly controlled) Pauli gates.\n", @@ -1618,7 +1507,6 @@ { "cell_type": "code", "execution_count": null, - "id": "fde34c0d", "metadata": {}, "outputs": [], "source": [ @@ -1633,7 +1521,6 @@ }, { "cell_type": "markdown", - "id": "d59151ae", "metadata": {}, "source": [ "[Return to Task 2.3 of the Basic Gates kata](./BasicGates.ipynb#Task-2.3.-Two-qubit-gate---3)." @@ -1641,7 +1528,6 @@ }, { "cell_type": "markdown", - "id": "dba10187", "metadata": {}, "source": [ "## Task 2.4. Toffoli gate\n", @@ -1658,7 +1544,6 @@ }, { "cell_type": "markdown", - "id": "987cce48", "metadata": {}, "source": [ "$$\n", @@ -1677,7 +1562,6 @@ }, { "cell_type": "markdown", - "id": "5ca33aa9", "metadata": {}, "source": [ "and our initial state is:" @@ -1685,7 +1569,6 @@ }, { "cell_type": "markdown", - "id": "fa81e5e2", "metadata": {}, "source": [ "$$\n", @@ -1704,7 +1587,6 @@ }, { "cell_type": "markdown", - "id": "b52168aa", "metadata": {}, "source": [ "So we have:" @@ -1712,7 +1594,6 @@ }, { "cell_type": "markdown", - "id": "f2edd717", "metadata": {}, "source": [ "$$\n", @@ -1755,7 +1636,6 @@ { "cell_type": "code", "execution_count": null, - "id": "a19e7f27", "metadata": {}, "outputs": [], "source": [ @@ -1768,7 +1648,6 @@ }, { "cell_type": "markdown", - "id": "3638bc88", "metadata": {}, "source": [ "[Return to Task 2.4 of the Basic Gates kata](./BasicGates.ipynb#Task-2.4.-Toffoli-gate)." @@ -1776,7 +1655,6 @@ }, { "cell_type": "markdown", - "id": "12f55c25", "metadata": {}, "source": [ "## Task 2.5. Fredkin gate\n", @@ -1795,7 +1673,6 @@ }, { "cell_type": "markdown", - "id": "16ef03ce", "metadata": {}, "source": [ "$$\n", @@ -1814,7 +1691,6 @@ }, { "cell_type": "markdown", - "id": "5ca334bd", "metadata": {}, "source": [ "and our initial state is:" @@ -1822,7 +1698,6 @@ }, { "cell_type": "markdown", - "id": "320458ec", "metadata": {}, "source": [ "$$\n", @@ -1841,7 +1716,6 @@ }, { "cell_type": "markdown", - "id": "95174e4a", "metadata": {}, "source": [ "So we have:" @@ -1849,7 +1723,6 @@ }, { "cell_type": "markdown", - "id": "2b28ca69", "metadata": {}, "source": [ "$$\n", @@ -1891,7 +1764,6 @@ }, { "cell_type": "markdown", - "id": "a23843de", "metadata": {}, "source": [ "Notice carefully how the qubits are passed to the gate: `[qs[0]], (qs[1], [qs[2])`. The `Controlled` functor produces an operation that takes two parameters: the first one is an array of control qubits (in this case a single-element array consisting of the first qubit), and the second parameter is a tuple of all parameters you'd pass to the original gate (in this gate two single-qubit parameters that would be arguments to a SWAP gate)." @@ -1900,7 +1772,6 @@ { "cell_type": "code", "execution_count": null, - "id": "188c0344", "metadata": {}, "outputs": [], "source": [ @@ -1913,7 +1784,6 @@ }, { "cell_type": "markdown", - "id": "1cc1e356", "metadata": {}, "source": [ "[Return to Task 2.5 of the Basic Gates kata](./BasicGates.ipynb#Task-2.5.-Fredkin-gate)." @@ -1930,7 +1800,7 @@ "file_extension": ".qs", "mimetype": "text/x-qsharp", "name": "qsharp", - "version": "0.14" + "version": "0.24" }, "widgets": { "application/vnd.jupyter.widget-state+json": { diff --git a/tutorials/MultiQubitGates/MultiQubitGates.ipynb b/tutorials/MultiQubitGates/MultiQubitGates.ipynb index 4c6ad30cd99..8989558631a 100644 --- a/tutorials/MultiQubitGates/MultiQubitGates.ipynb +++ b/tutorials/MultiQubitGates/MultiQubitGates.ipynb @@ -392,7 +392,7 @@ "\n", "#### Q# #\n", "\n", - "In Q# we describe the operation as the sequence of gates that are applied to the qubitsm regardless of whether the qubits are adjacent or not.\n", + "In Q# we describe the operation as the sequence of gates that are applied to the qubits, regardless of whether the qubits are adjacent or not.\n", "\n", "```C#\n", "operation CINOT (qs: Qubit[]) : Unit {\n", @@ -405,7 +405,7 @@ "In Dirac notation we can consider the effect of the gate on each basis vector separately: each basis vector $|a_1a_2a_3\\rangle$ remains unchanged if $a_1 = 0$, and becomes $|a_1a_2(\\neg a_3)\\rangle$ if $a_1 = 1$. The full effect on the state becomes:\n", "\n", "$$\\text{CINOT}|\\psi\\rangle \n", - "= x_{000} \\text{CINOT}|000\\rangle + x_{001} \\text{CINOT}|001\\rangle + x_{010} \\text{CINOT}|010\\rangle + x_{011} \\text{CINOT}|011\\rangle$$\n", + "= x_{000} \\text{CINOT}|000\\rangle + x_{001} \\text{CINOT}|001\\rangle + x_{010} \\text{CINOT}|010\\rangle + x_{011} \\text{CINOT}|011\\rangle+$$\n", "$$+ {\\color{red}{x_{100}}} \\text{CINOT}|{\\color{red}{100}}\\rangle + {\\color{red}{x_{101}}} \\text{CINOT}|{\\color{red}{101}}\\rangle + {\\color{red}{x_{110}}} \\text{CINOT}|{\\color{red}{110}}\\rangle + {\\color{red}{x_{111}}} \\text{CINOT}|{\\color{red}{111}}\\rangle =$$\n", "$$= x_{000}|000\\rangle + x_{001}|001\\rangle + x_{010}|010\\rangle + x_{011}|011\\rangle + {\\color{red}{x_{101}}}|100\\rangle + {\\color{red}{x_{100}}}|101\\rangle + {\\color{red}{x_{111}}}|110\\rangle + {\\color{red}{x_{110}}}|111\\rangle $$\n", "\n",