diff --git a/katas/content/deutsch_jozsa/implement_dj/solution.md b/katas/content/deutsch_jozsa/implement_dj/solution.md index 9aa9225074..a6cdd1bf1e 100644 --- a/katas/content/deutsch_jozsa/implement_dj/solution.md +++ b/katas/content/deutsch_jozsa/implement_dj/solution.md @@ -5,8 +5,8 @@ Follow the algorithm as outlined in the previous section: 3. Apply the oracle. The syntax for applying the oracle is the same as for applying any other gate or operation. 4. Apply the $H$ gate to each qubit again. 5. Measure each of the qubits. If any of the measurement results is `One`, the function is balanced. -We cannot return `false` as soon as we encounter a `One` result, though, since we need to return all qubits to $\ket{0}$ state first. -Instead, we'll update the mutable variable that stores our result and continue through the rest of the loop. +You can't return `false` as soon as you encounter a `One` result, though, since you need to return all qubits to $\ket{0}$ state first. +Instead, you update the mutable variable that stores your result and continue through the rest of the loop. @[solution]({ "id": "deutsch_jozsa__implement_dj_solution", diff --git a/katas/content/deutsch_jozsa/index.md b/katas/content/deutsch_jozsa/index.md index 2720eb8377..b53cc8d8bb 100644 --- a/katas/content/deutsch_jozsa/index.md +++ b/katas/content/deutsch_jozsa/index.md @@ -17,9 +17,9 @@ This kata introduces you to Deutsch-Jozsa algorithm - one of the most famous alg **What you should know to start working on this kata:** -- Basic single-qubit gates -- Quantum measurements -- Deutsch algorithm - the single-qubit variant of Deutsch-Jozsa algorithm +- Basic knowledge of single-qubit gates +- Basic knowledge of quantum measurements +- Deutsch algorithm - the single-qubit variant of Deutsch-Jozsa algorithm. If you're not familiar with it, you can find it in the Deutsch algorithm kata. @[section]({ "id": "deutsch_jozsa__problem", @@ -35,14 +35,14 @@ The task is to figure out whether the function is constant or balanced. **Examples** -- $f(x) \equiv 0$ or $f(x) \equiv 1$ are constant functions (and they are actually the only constant functions in existence). +- $f(x) \equiv 0$ or $f(x) \equiv 1$ are constant functions (and they're actually the only constant functions in existence). - $f(x) = x \bmod 2$ (the least significant bit of $x$) or $f(x) = 1 \text{ if the binary notation of }x \text{ has odd number of 1s and 0 otherwise}$ are examples of multi-bit balanced functions. Indeed, for both these functions you can check that for every possible input $x$ for which $f(x) = 0$ there exists an input $x^\prime$ (equal to $x$ with the least significant bit flipped) such that $f(x^\prime) = 1$, and vice versa, which means that the function is balanced. -If we solve this problem classically, how many calls to the given function will we need? +If you solve this problem classically, how many calls to the given function will you need? -The first call will give us no information - regardless of whether it returns $0$ or $1$, the function could still be constant or balanced. -In the best case scenario the second call will return a different value and we'll be able to conclude that the function is balanced in just $2$ calls. -However, if we get the same value for the first two calls, we'll have to keep querying the function until either we get a different value or until we do $2^{N-1}+1$ queries that will return the same value - only in this case we'll know for certain that the function is constant. +The first call will give you no information - regardless of whether it returns $0$ or $1$, the function could still be constant or balanced. +In the best case scenario, the second call will return a different value. You'll be able to conclude that the function is balanced in just $2$ calls. +However, if you get the same value for the first two calls, you'll have to keep querying the function until either the function returns a different value, or until you perform $2^{N-1}+1$ queries that return the same value - only in this case will you know with certainty that the function is constant. What about the quantum scenario? @@ -52,7 +52,7 @@ What about the quantum scenario? "title": "Multi-Qubit Oracles" }) -In the quantum scenario, the classical function we're working with is implemented as a quantum oracle - a "black box" operation used as input to another algorithm. This operation is implemented in a way which allows to perform calculations not only on individual inputs, but also on superpositions of inputs. +In the quantum scenario, the classical function you're working with is implemented as a quantum oracle - a "black box" operation used as input to another algorithm. This operation is implemented in a way which allows you to perform calculations not only on individual inputs, but also on superpositions of inputs. To enable the oracle to act on quantum states instead of classical values, the integer input $x$ is represented in binary $x = (x_{0}, x_{1}, \dots, x_{N-1})$, and encoded into an $N$-qubit register: $\ket{\vec{x} } = \ket{x_{0} } \otimes \ket{x_{1} } \otimes \cdots \otimes \ket{x_{N-1} }$. @@ -62,7 +62,7 @@ $$U_f \ket{\vec{x} } = (-1)^{f(x)} \ket{\vec{x} }$$ The function $f$ can return only two values, 0 or 1, which result in no phase change or multiplication by a relative phase $-1$, respectively. -The effect of such an oracle on any single basis state is not particularly interesting: it just adds a global phase which is not something you can observe. However, if you apply this oracle to a *superposition* of basis states, its effect becomes noticeable. +The effect of such an oracle on any single basis state isn't particularly interesting: it just adds a global phase which isn't something you can observe. However, if you apply this oracle to a *superposition* of basis states, its effect becomes noticeable. Remember that quantum operations are linear: if you define the effect of an operation on the basis states, you'll be able to deduce its effect on superposition states (which are just linear combinations of the basis states) using its linearity. Let's see how to implement several examples of multi-bit constant and balanced functions as phase oracles in Q#. @@ -81,15 +81,15 @@ The second constant function is slightly trickier: if $f(x) \equiv 1$ $$U_f \ket{x} \equiv (-1)^1 \ket{x} = - \ket{x}$$ -Now $U_f$ is a negative identity, i.e., a transformation which applies a global phase of $-1$ to the state. -A lot of algorithms just ignore the global phase accumulated in them, since it is not observable. -However, if we want to be really meticulous, we can use the $R$ gate which performs a given rotation around the given axis. +Now $U_f$ is a negative identity, that is, a transformation which applies a global phase of $-1$ to the state. +A lot of algorithms just ignore the global phase accumulated in them, since it isn't observable. +However, if you want to be meticulous, you can use the $R$ gate which performs a given rotation around the given axis. When called with `PauliI` axis, this operation applies a global phase to the given qubit. -We can use any qubit to apply this gate, for example, `qs[0]`. +You can use any qubit to apply this gate, for example, `qs[0]`. 3. $f(x) = x \bmod 2$ -The binary representation of $x$ is $x = (x_{0}, x_{1}, \dots, x_{N-1})$, with the least significant bit encoded in the last bit (stored in the last qubit of the input array). Then we can rewrite the function as +The binary representation of $x$ is $x = (x_{0}, x_{1}, \dots, x_{N-1})$, with the least significant bit encoded in the last bit (stored in the last qubit of the input array). Then you can rewrite the function as $$f(x) = x_{N-1}$$ @@ -97,13 +97,13 @@ Let's use this in the oracle effect expression: $$U_f \ket{x} = (-1)^{f(x)} \ket{x} = (-1)^{x_{N-1}} \ket{x} = \ket{x_{0} } \otimes \cdots \otimes \ket{x_{N-2} } \otimes (-1)^{x_{N-1}} \ket{x_{N-1}}$$ -This means that we only need to use the last qubit in the implementation: do nothing if it is $\ket{0}$ and apply a phase of $-1$ if it is $\ket{1}$. This is exactly the effect of the $Z$ gate! +This means that you only need to use the last qubit in the implementation: do nothing if it's $\ket{0}$ and apply a phase of $-1$ if it's $\ket{1}$. This is exactly the effect of the $Z$ gate! -We can write out the oracle unitary as follows: +You can write out the oracle unitary as follows: $$U_f = \mathbb{1} \otimes \cdots \otimes \mathbb{1} \otimes Z$$ -In this demo we will see how to implement three multi-bit functions as quantum oracles, and their effect on a quantum state. +In the following demo you'll see how to implement three multi-bit functions as quantum oracles, and their effect on a quantum state. After that, you'll try to implement the oracles for two more functions on your own! @[example]({"id": "deutsch_jozsa__oracle_implementations", "codePath": "./examples/OracleImplementationDemo.qs"}) @@ -127,7 +127,7 @@ After that, you'll try to implement the oracles for two more functions on your o }) Now let's return to the problem of figuring out whether the given function is constant or balanced. -We'll present the algorithm in detail step-by-step and summarize it in the end. +The following sections present the algorithm in detail step-by-step. ### Inputs @@ -141,65 +141,65 @@ The algorithm starts with $N$ qubits in the $\ket{0...0} = \ket{0}^{\otimes N}$ Applying the $H$ gate to one qubit in the $\ket{0}$ state converts it to the $\frac{1}{\sqrt2} \big(\ket{0} + \ket{1} \big)$ state, which is an equal superposition of both basis states on one qubit. -If we apply the $H$ gate to each of the two qubits in the $\ket{00}$ state, we'll get +If you apply the $H$ gate to each of the two qubits in the $\ket{00}$ state, you get $$(H \otimes H) \ket{00} = \big(H \ket{0} \big) \otimes \big(H \ket{0}\big) = \left(\frac{1}{\sqrt2} \big(\ket{0} + \ket{1} \big)\right) \otimes \left(\frac{1}{\sqrt2} \big(\ket{0} + \ket{1} \big)\right) = \frac{1}{2} \big(\ket{00} + \ket{01} + \ket{10} + \ket{11} \big)$$ This is just an equal superposition of all basis states on two qubits! -We can extend the same thinking to applying the $H$ gate to each of the $N$ qubits in the $\ket{0...0}$ state to conclude that this transforms them into a state that is an equal superposition of all basis states on $N$ qubits. +You can extend the same thinking to applying the $H$ gate to each of the $N$ qubits in the $\ket{0...0}$ state to conclude that this transforms them into a state that is an equal superposition of all basis states on $N$ qubits. -Mathematically the transformation "apply $H$ gate to each of the $N$ qubits" can be denoted as $H^{\otimes N}$. After applying this transformation we'll get the following state: +Mathematically, the transformation "apply $H$ gate to each of the $N$ qubits" can be denoted as $H^{\otimes N}$. After applying this transformation, you get the following state: $$H^{\otimes N} \ket{0}^{\otimes N} = \big( H\ket{0} \big)^{\otimes N} = \left( \frac{1}{\sqrt2} \big(\ket{0} + \ket{1} \big) \right)^{\otimes N} = \frac{1}{\sqrt{2^N}} \sum_{x=0}^{2^N-1} \ket{x}$$ ### Step 2. Apply the oracle -This step is the only step in which we use the knowledge of the classical function, given to us as the quantum oracle. -This step will keep the amplitudes of the basis states for which $f(x) = 0$ unchanged, and multiply the amplitudes of the basis states for which $f(x) = 1$ by $-1$. +This step is the only step in which you use the knowledge of the classical function, given as the quantum oracle. +This step keep the amplitudes of the basis states for which $f(x) = 0$ unchanged, and multiply the amplitudes of the basis states for which $f(x) = 1$ by $-1$. -Mathematically the results of oracle application can be written as follows: +Mathematically, the results of oracle application can be written as follows: $$U_f \left(\frac{1}{\sqrt{2^N}} \sum_{x=0}^{2^N-1} \ket{x} \right) = \frac{1}{\sqrt{2^N}} \sum_{x=0}^{2^N-1} U_f\ket{x} = \frac{1}{\sqrt{2^N}} \sum_{x=0}^{2^N-1} (-1)^{f(x)} \ket{x}$$ ### Step 3. Apply Hadamard transform to each qubit again -In this step, let's not worry about the whole expression for the state of the qubits after applying the $H$ gates to them; instead let's calculate only the resulting amplitude of the basis state $\ket{0}^{\otimes N}$. +In this step, you don't need to worry about the whole expression for the state of the qubits after applying the $H$ gates to them; it's enough to calculate only the resulting amplitude of the basis state $\ket{0}^{\otimes N}$. Consider one of the basis states $\ket{x}$ in the expression $\sum_{x=0}^{2^N-1} (-1)^{f(x)} \ket{x}$. It can be written as $\ket{x} = \ket{x_{0} } \otimes \cdots \otimes \ket{x_{N-1}}$, where each $\ket{x_k}$ is either $\ket{0}$ or $\ket{1}$. -When we apply the $H$ gates to $\ket{x}$, we'll get $H^{\otimes N} \ket{x} = H\ket{x_{0} } \otimes \cdots \otimes H\ket{x_{N-1}}$, where each term of the tensor product is either $H\ket{0} = \frac{1}{\sqrt2}\big(\ket{0} + \ket{1} \big) = \ket{+}$ or $H\ket{1} = \frac{1}{\sqrt2}\big(\ket{0} - \ket{1} \big) = \ket{-}$. -If we open the brackets in this tensor product, we'll get a superposition of all $N$-qubit basis states, each of them with amplitude $\frac{1}{\sqrt{2^N}}$ or $-\frac{1}{\sqrt{2^N}}$ — and, since the amplitude of the $\ket{0}$ state in both $\ket{+}$ and $\ket{-}$ is positive, we know that the amplitude of the basis state $\ket{0}^{\otimes N}$ will end up positive, i.e., $\frac{1}{\sqrt{2^N}}$. +When you apply the $H$ gates to $\ket{x}$, we'll get $H^{\otimes N} \ket{x} = H\ket{x_{0} } \otimes \cdots \otimes H\ket{x_{N-1}}$, where each term of the tensor product is either $H\ket{0} = \frac{1}{\sqrt2}\big(\ket{0} + \ket{1} \big) = \ket{+}$ or $H\ket{1} = \frac{1}{\sqrt2}\big(\ket{0} - \ket{1} \big) = \ket{-}$. +If you open the brackets in this tensor product, you get a superposition of all $N$-qubit basis states, each of them with amplitude $\frac{1}{\sqrt{2^N}}$ or $-\frac{1}{\sqrt{2^N}}$ — and, since the amplitude of the $\ket{0}$ state in both $\ket{+}$ and $\ket{-}$ is positive, you know that the amplitude of the basis state $\ket{0}^{\otimes N}$ ends up positive, that is, $\frac{1}{\sqrt{2^N}}$. -Now we can calculate the amplitude of the $\ket{0}^{\otimes N}$ state in the expression $H^{\otimes N} \left( \frac{1}{\sqrt{2^N}} \sum_{x=0}^{2^N-1} (-1)^{f(x)} \ket{x} \right)$: in each of the $2^N$ terms of the sum its amplitude is $\frac{1}{\sqrt{2^N}}$; therefore, we get the total amplitude +Now you can calculate the amplitude of the $\ket{0}^{\otimes N}$ state in the expression $H^{\otimes N} \left( \frac{1}{\sqrt{2^N}} \sum_{x=0}^{2^N-1} (-1)^{f(x)} \ket{x} \right)$: in each of the $2^N$ terms of the sum its amplitude is $\frac{1}{\sqrt{2^N}}$. Therefore, you get the total amplitude $$\frac{1}{\sqrt{2^N}} \sum_{x=0}^{2^N-1} (-1)^{f(x)} \frac{1}{\sqrt{2^N}} = \frac{1}{2^N} \sum_{x=0}^{2^N-1} (-1)^{f(x)}$$ ### Step 4. Perform measurements and interpret the result -So far we did not use the fact that the function we are given is constant or balanced. Let's see how this affects the amplitude of the $\ket{0}^{\otimes N}$ state. +So far, you didn't use the fact that the function you are given is constant or balanced. Let's see how this affects the amplitude of the $\ket{0}^{\otimes N}$ state. -* If the function is constant, $f(x) = C$ (either always $0$ or always $1$), we get +* If the function is constant, $f(x) = C$ (either always $0$ or always $1$), you get $$\frac{1}{2^N} \sum_{x=0}^{2^N-1} (-1)^{f(x)} = \frac{1}{2^N} \sum_{x=0}^{2^N-1} (-1)^{C} = \frac{1}{2^N} \cdot 2^N (-1)^C = (-1)^C$$ Since the sum of squares of amplitudes of all basis states always equals $1$, the amplitudes of the rest of the basis states have to be 0 - this means that the state of the qubits after step 3 *is* $\ket{0}^{\otimes N}$. -* If the function is balanced, i.e., returns $0$ for exactly half of the inputs and $1$ for the other half of the inputs, exactly half of the terms in the sum $\frac{1}{2^N} \sum_{x=0}^{2^N-1} (-1)^{f(x)}$ will be $1$ and the other half of the terms will be $-1$, and they will all cancel out, leaving the amplitude of $\ket{0}^{\otimes N}$ equal to $0$. +* If the function is balanced, that is, returns $0$ for exactly half of the inputs and $1$ for the other half of the inputs, exactly half of the terms in the sum $\frac{1}{2^N} \sum_{x=0}^{2^N-1} (-1)^{f(x)}$ will be $1$ and the other half of the terms will be $-1$, and they will all cancel out, leaving the amplitude of $\ket{0}^{\otimes N}$ equal to $0$. -Now, what happens when we measure all qubits? (Remember that the probability of getting a certain state as a result of measurement equals to the square of the amplitude of this state.) +Now, what happens when you measure all qubits? (Remember that the probability of getting a certain state as a result of measurement equals to the square of the amplitude of this state.) -If the function is constant, the only measurement result we can get is all zeros - the probability of getting any other result is $0$. If the function is balanced, the probability of getting all zeros is $0$, so we'll get any measurement result except this. +If the function is constant, the only measurement result you can get is all zeros - the probability of getting any other result is $0$. If the function is balanced, the probability of getting all zeros is $0$, so you'll get any measurement result except this. -This is exactly the last step of the algorithm: **measure all qubits, if all measurement results are 0, the function is constant, otherwise it is balanced**. +This is exactly the last step of the algorithm: **measure all qubits, if all measurement results are 0, the function is constant, otherwise it's balanced**. ### Summary -In the end the algorithm is very straightforward: +In the end, the algorithm is very straightforward: 1. Apply the $H$ gate to each qubit. 2. Apply the oracle. 3. Apply the $H$ gate to each qubit again. 4. Measure all qubits. -5. If all qubits were measured in $\ket{0}$ state, the function is constant, otherwise it is balanced. +5. If all qubits are measured in $\ket{0}$ state, the function is constant, otherwise it's balanced. Note that this algorithm requires only $1$ oracle call, and always produces the correct result! @@ -239,28 +239,28 @@ The task is to recover the hidden bit string $s$. - $f(x) \equiv 0$ is an example of such a function with $s = 0, \dots, 0$. - $f(x) = 1 \text{ if x has odd number of 1s, and } 0 \text{ otherwise }$ is another example of such a function, with $s = 1, \dots, 1$. -If we solve this problem classically, how many calls to the given function will we need? -We'd need to use one query to recover each bit of $s$ (the query for $k$-th bit can be a bit string with $1$ in the $k$-th bit and zeros in all other positions), for a total of $N$ queries. +If you solve this problem classically, how many calls to the given function will you need? +You'd need to use one query to recover each bit of $s$ (the query for $k$-th bit can be a bit string with $1$ in the $k$-th bit and zeros in all other positions), for a total of $N$ queries. What about the quantum scenario? -It turns out that the algorithm that allows us to solve this problem looks just like Deutsch-Jozsa algorithm, -except for the way we interpret the measurement results on the last step. To see this, we'll need to take another look +It turns out that the algorithm that allows you to solve this problem looks just like Deutsch-Jozsa algorithm, +except for the way you interpret the measurement results on the last step. To see this, you'll need to take another look at the math involved in applying Hadamard gates to multiple qubits. ### Apply Hadamard transform to each qubit: a different view -When we apply an $H$ gate to a single qubit in the basis state $\ket{x}$, we can write the result as the following sum: +When you apply an $H$ gate to a single qubit in the basis state $\ket{x}$, you can write the result as the following sum: $$H\ket{x} = \frac1{\sqrt2} (\ket{0} + (-1)^{x} \ket{1}) = \frac1{\sqrt2} \sum_{z \in {0, 1}} (-1)^{x \cdot z} \ket{z}$$ -If we use this representation to spell out the result of applying an $H$ gate to each qubit of an $N$-qubit basis state -$\ket{x} = \ket{x_0}\ket{x_1} \dots \ket{x_{N-1}}$, we'll get: +If you use this representation to spell out the result of applying an $H$ gate to each qubit of an $N$-qubit basis state +$\ket{x} = \ket{x_0}\ket{x_1} \dots \ket{x_{N-1}}$, you get: $$H\ket{x} = \frac1{\sqrt{2^N}} \sum_{z_k \in {0, 1}} (-1)^{x_0z_0 + \dots + x_{N-1}z_{N-1}} \ket{z_0}\ket{z_1} \dots \ket{z_{N-1}} =$$ $$= \frac1{\sqrt{2^N}} \sum_{z = 0}^{2^N-1} (-1)^{x \cdot z} \ket{z}$$ -With this in mind, let's revisit the algorithm and see how we can write the exact quantum state after it. +With this in mind, let's revisit the algorithm and see how you can write the exact quantum state after it. ### Bernstein-Vazirani algorithm @@ -271,18 +271,18 @@ Bernstein-Vazirani algorithm follows the same outline as Deutsch-Jozsa algorithm 3. Apply the $H$ gate to each qubit again. 4. Measure all qubits. -We know that after the second step the qubits end up in the following state: +You know that after the second step the qubits end up in the following state: $$\frac{1}{\sqrt{2^N}} \sum_{x=0}^{2^N-1} (-1)^{f(x)} \ket{x}$$ -Now, once we apply the Hadamard gates to each qubit, the system state becomes: +Now, once you apply the Hadamard gates to each qubit, the system state becomes: $$\frac{1}{\sqrt{2^N}} \sum_{x=0}^{2^N-1} \sum_{z=0}^{2^N-1} (-1)^{f(x) + x \cdot z} \ket{z}$$ -> In Deutsch-Jozsa algorithm, we looked at the amplitude of the $\ket{0}$ state in this expression, which was +> In Deutsch-Jozsa algorithm, you looked at the amplitude of the $\ket{0}$ state in this expression, which was > $\frac{1}{\sqrt{2^N}} \sum_{x=0}^{2^N-1} (-1)^{f(x)}$. -Now, let's take a look at the amplitude of the $\ket{s}$ state - the state that encodes the hidden bit string we're looking for. +Now, let's take a look at the amplitude of the $\ket{s}$ state - the state that encodes the hidden bit string you're looking for. This amplitude is $$\frac{1}{\sqrt{2^N}} \sum_{x=0}^{2^N-1} (-1)^{f(x) + x \cdot s}$$ @@ -292,7 +292,7 @@ Overall the amplitude of $\ket{s}$ is $$\frac{1}{\sqrt{2^N}} \sum_{x=0}^{2^N-1} 1 = \frac{1}{\sqrt{2^N}} 2^N = 1$$ -This means that our state after applying the Hadamard gates is just $\ket{s}$, and measuring it will give us the bit string $s$! +This means that the state after applying the Hadamard gates is just $\ket{s}$, and measuring it gives you the bit string $s$! And, same as Deutsch-Jozsa algorithm, Bernstein-Vazirani algorithm takes only one oracle call. @[exercise]({ @@ -307,7 +307,7 @@ And, same as Deutsch-Jozsa algorithm, Bernstein-Vazirani algorithm takes only on "title": "Conclusion" }) -Congratulations! In this kata you have learned Deutsch-Jozsa and Bernstein-Vazirani algorithms. +Congratulations! In this kata you learned Deutsch-Jozsa and Bernstein-Vazirani algorithms. - Deutsch-Jozsa algorithm is the simplest example of a quantum algorithm that is exponentially faster than any possible deterministic algorithm for the same problem. - Bernstein-Vazirani algorithm is a similar algorithm that extracts information about the hidden bit string of the given function that is known to be a scalar product function. It offers a linear speedup compared to a classical algorithm for the same problem. diff --git a/katas/content/deutsch_jozsa/msb_oracle/solution.md b/katas/content/deutsch_jozsa/msb_oracle/solution.md index 61410dc3b2..91fa2ba1a6 100644 --- a/katas/content/deutsch_jozsa/msb_oracle/solution.md +++ b/katas/content/deutsch_jozsa/msb_oracle/solution.md @@ -1,4 +1,4 @@ -The binary representation of $x$ is $x = (x_{0}, x_{1}, \dots, x_{N-1})$, with the most significant bit encoded in the first bit (stored in the first qubit of the input array). Then we can rewrite the function as +The binary representation of $x$ is $x = (x_{0}, x_{1}, \dots, x_{N-1})$, with the most significant bit encoded in the first bit (stored in the first qubit of the input array). Then, you can rewrite the function as $$f(x) = x_0$$ @@ -6,7 +6,7 @@ and its effect on the quantum state as $$U_f \ket{x} = (-1)^{f(x)} \ket{x} = (-1)^{x_0} \ket{x} = (-1)^{x_0} \ket{x_{0} } \otimes \ket{x_1} \otimes \cdots \otimes \ket{x_{N-1}}$$ -As we've seen in the previous oracle, this can be achieved by applying a $Z$ gate to the first qubit. +As you've seen in the previous exercise, this can be achieved by applying a $Z$ gate to the first qubit. @[solution]({ "id": "deutsch_jozsa__msb_oracle_solution", diff --git a/katas/content/deutsch_jozsa/parity_oracle/solution.md b/katas/content/deutsch_jozsa/parity_oracle/solution.md index a331213df1..b300d56d9a 100644 --- a/katas/content/deutsch_jozsa/parity_oracle/solution.md +++ b/katas/content/deutsch_jozsa/parity_oracle/solution.md @@ -1,4 +1,4 @@ -In this oracle the answer depends on all bits of the input. We can write $f(x)$ as follows (here $\bigoplus$ denotes sum modulo $2$): +In this oracle the answer depends on all bits of the input. You can write $f(x)$ as follows (here $\bigoplus$ denotes sum modulo $2$): $$f(x) = \bigoplus_{k=0}^{N-1} x_k$$ @@ -6,7 +6,7 @@ Let's substitute this expression in the expression for the oracle effect on the $$U_f \ket{x} = (-1)^{f(x)} \ket{x} = (-1)^{\bigoplus_{k=0}^{N-1} x_k} \ket{x}$$ -Since $(-1)^2 = 1$, we can replace sum modulo $2$ with a regular sum in the exponent. Then we'll be able to rewrite it as a product of individual exponents for each bit: +Since $(-1)^2 = 1$, you can replace sum modulo $2$ with a regular sum in the exponent. Then you'll be able to rewrite it as a product of individual exponents for each bit: $$U_f \ket{x} = (-1)^{\sum_{k=0}^{N-1} x_k} \ket{x} = \prod_{k=0}^{N-1} {(-1)^{x_k}} \ket{x}$$ @@ -14,11 +14,11 @@ Now let's spell out the system state as a tensor product of individual qubit sta $$U_f \ket{x} = \prod_{k=0}^{N-1} {(-1)^{x_k}} \cdot \ket{x_{0} } \otimes \cdots \otimes \ket{x_{N-1}}$$ -Tensor product is a linear operation, so we can bring each $(-1)^{x_k}$ scalar factor in next to the corresponding $\ket{x_k}$: +Tensor product is a linear operation, so you can bring each $(-1)^{x_k}$ scalar factor in next to the corresponding $\ket{x_k}$: $$U_f \ket{x} = (-1)^{x_0} \ket{x_{k}} \otimes \dots \otimes (-1)^{x_{N-1}} \ket{x_{N-1}} = \bigotimes_{k=0}^{N-1} (-1)^{x_k} \ket{x_{k}}$$ -As we've seen in the previous oracle, this can be achieved by applying a $Z$ gate to each qubit. +As you've seen in the previous oracle, this can be achieved by applying a $Z$ gate to each qubit. @[solution]({ "id": "deutsch_jozsa__parity_oracle_solution",