Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ Return the polar representation of $x = re^{i\theta}$, that is, the distance fro
* $r$ should be non-negative: $r \geq 0$
* $\theta$ should be between $-\pi$ and $\pi$: $-\pi < \theta \leq \pi$

<details>
<summary><b>Need a hint?</b></summary>

:::hint
A video explanation of this conversion can be found [here](https://www.youtube.com/watch?v=8RasCV_Lggg).

Q# namespace `Std.Math` includes a useful function `ArcTan2()`.

</details>
:::

> Q# function `ComplexAsComplexPolar` from `Std.Math` namespace converts a complex number of type `Complex` to a complex number of type `ComplexPolar`. For educational purposes, try to do this task by hand.
6 changes: 2 additions & 4 deletions katas/content/complex_arithmetic/complex_addition/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
**Goal:**
Return the sum of $x$ and $y$ as a complex number.

<details>
<summary><b>Need a hint?</b></summary>

:::hint
Adding complex numbers is just like adding polynomials. Add components of the same type - add the real part to the real part, add the imaginary part to the imaginary part.

A video explanation of adding complex numbers can be found [here](https://www.youtube.com/watch?v=SfbjqVyQljk).
</details>
:::

> Q# function `PlusC` from `Std.Math` namespace adds two complex numbers. For educational purposes, try to do this task by hand.
7 changes: 2 additions & 5 deletions katas/content/complex_arithmetic/complex_conjugate/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ A complex number $x = a + bi$.
**Goal:**
Return the complex conjugate of $x$ $\overline{x} = a - bi$.

<details>
<summary><b>Need a hint?</b></summary>

:::hint
A video explanation of the complex conjugate can be found [here](https://www.youtube.com/watch?v=BZxZ_eEuJBM).

</details>
:::
7 changes: 2 additions & 5 deletions katas/content/complex_arithmetic/complex_division/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@

**Goal:** Return the result of the division $\frac{x}{y} = \frac{a + bi}{c + di}$.

<details>
<summary><b>Need a hint?</b></summary>

:::hint
A video explanation of complex division can be found [here](https://www.youtube.com/watch?v=Z8j5RDOibV4).

</details>
:::

> Q# function `DividedByC` from `Std.Math` namespace divides two complex numbers. For educational purposes, try to do this task by hand.
7 changes: 3 additions & 4 deletions katas/content/complex_arithmetic/complex_exponents/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

**Goal:** Return the complex number $e^x = e^{a + bi}$.

<details>
<summary><b>Need a hint?</b></summary>
Q# namespace <code>Std.Math</code> includes a function <code>E()</code> that returns the value of the constant $e$.
</details>
:::hint
Q# namespace <code>Std.Math</code> includes a function <code>E()</code> that returns the value of the constant $e$.
:::
9 changes: 3 additions & 6 deletions katas/content/complex_arithmetic/complex_modulus/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

**Goal:** Return the modulus of this number, $|x|$.

<details>
<summary><b>Need a hint?</b></summary>

A video explanation of absolute value and complex numbers can be found [here](https://www.youtube.com/watch?v=FwuPXchH2rA).

</details>
:::hint
A video explanation of absolute value and complex numbers can be found [here](https://www.youtube.com/watch?v=FwuPXchH2rA).
:::

> Q# function `AbsComplex` from `Std.Math` namespace gets the absolute value of a complex number. For educational purposes, try to do this task by hand.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
**Goal:**
Return the product of $x$ and $y$ as a complex number.

<details>
<summary><b>Need a hint?</b></summary>

:::hint
Multiplying complex numbers is just like multiplying polynomials. Distribute one of the complex numbers:
$$(a + bi)(c + di) = a(c + di) + bi(c + di)$$
Then multiply through, keeping in mind that $i^2=-1$, and group the real and imaginary terms together.

A video explanation of multiplying complex numbers can be found [here](https://www.youtube.com/watch?v=cWn6g8Qqvs4).

</details>
:::

> Q# function `TimesC` from `Std.Math` namespace multiplies two complex numbers. For educational purposes, try to do this task by hand.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

**Goal:** Return the complex number $r^x = r^{a + bi}$.

<details>
<summary><b>Need a hint?</b></summary>
You can use the fact that $r = e^{\ln r}$ to convert exponent bases. Remember though, $\ln r$ is only defined for positive numbers - make sure to check for $r = 0$ separately!
:::hint
You can use the fact that $r = e^{\ln r}$ to convert exponent bases. Remember though, $\ln r$ is only defined for positive numbers - make sure to check for $r = 0$ separately!

Q# namespace `Std.Math` includes useful functions `Log()`, `Sin()`, and `Cos()`.
</details>
:::
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ Return the product of $x$ and $y$ as a complex polar number $x \cdot y = r_{3}e^
* $\theta_3$ should be between $-\pi$ and $\pi$: $-\pi < \theta_3 \leq \pi$
* Try to avoid converting the numbers into their Cartesian form.

<details>
<summary><b>Need a hint?</b></summary>

Remember, a number written in polar form already involves multiplication. What is $r_1e^{i\theta_1} \cdot r_2e^{i\theta_2}$?
:::hint
Remember, a number written in polar form already involves multiplication. What is $r_1e^{i\theta_1} \cdot r_2e^{i\theta_2}$?

Is the value of $\theta$ in the product incorrect? Remember you might have to check your boundaries and adjust it to be in the range requested.
</details>
:::

> Q# function `TimesCP` from `Std.Math` namespace multiplies two complex numbers, but it doesn't normalize the argument of the resulting number. For educational purposes, try to do this task by hand.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ A complex number in polar form $x = re^{i\theta}$.
**Goal:**
Return the Cartesian representation of $x = a + bi$ as a `Complex`.

<details>
<summary><b>Need a hint?</b></summary>

:::hint
A video explanation of this conversion can be found [here](https://www.youtube.com/watch?v=auywa7dydAk).

</details>
:::

> Q# function `ComplexPolarAsComplex` from `Std.Math` namespace converts a complex number of type `ComplexPolar` to a complex number of type `Complex`. For educational purposes, try to do this task by hand.
5 changes: 2 additions & 3 deletions katas/content/deutsch_algo/one_minus_x_oracle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
**Goal:** Apply the phase oracle $U_f$ for $f(x) = 1 - x$ to the qubit.
That is, apply a relative phase $(-1)^{f(x)}$ to each basis state $\ket{x}$.

<details>
<summary><strong>Need a hint?</strong></summary>
:::hint
You can represent the effect of the oracle as

$$U_f \ket{x} = (-1)^{1-x} \ket{x} = (-1) \cdot (-1)^x \ket{x}$$

Can you get this effect by combining some of the previous oracles implementations?
</details>
:::
5 changes: 2 additions & 3 deletions katas/content/deutsch_jozsa/parity_oracle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
**Goal:** Apply the phase oracle $U_f$ for $f(x) = 1 \text{ if x has odd number of 1s, and } 0 \text{ otherwise }$ to the qubits.
That is, apply a relative phase $(-1)^{f(x)}$ to each basis state $\ket{x}$.

<details>
<summary><strong>Need a hint?</strong></summary>
:::hint
Can you represent the function as a sum of expressions that depend on individual bits of $x$ (modulo $2$)?
Can you then represent the effect of the oracle on the array of qubits as a product of effects on each qubit in the array?
</details>
:::
5 changes: 2 additions & 3 deletions katas/content/getting_started/flip_qubit/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Exercises are problems that you have to solve by writing Q# code. In each exerci

**Goal:** Apply the X gate to the qubit, that is, perform a "bit flip" to set the qubit into the $\ket{1}$ state.

<details>
<summary><strong>Need a hint?</strong></summary>
:::hint
For some problems a hint will be provided to help you if you are stuck. For this exercise, read line number 3 in the code below.
</details>
:::
7 changes: 3 additions & 4 deletions katas/content/grovers_search/phase_oracle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Flip the phase of each basis state $\ket{x}$ for which $f(x) = 1$. You can only
The operation you implement is the phase oracle for the same function.

<br/>
<details>
<summary><b>Need a hint?</b></summary>
Recall that you can allocate extra qubits to assist in this operation. Is there a state that you could prepare with an auxiliary qubit which would help you to convert the marking oracle to a phase oracle?
</details>
:::hint
Recall that you can allocate extra qubits to assist in this operation. Is there a state that you could prepare with an auxiliary qubit which would help you to convert the marking oracle to a phase oracle?
:::
7 changes: 2 additions & 5 deletions katas/content/linear_algebra/inverse/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

$$\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}$$

<details>
<summary><b>Need a hint?</b></summary>

:::hint
You can check out [this Wikipedia article](https://en.wikipedia.org/wiki/Invertible_matrix#Inversion_of_2_%C3%97_2_matrices) about invertible matrices.

</details>
:::
5 changes: 2 additions & 3 deletions katas/content/marking_oracles/parity/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ In other words, for each basis state $\ket{x}$, flip the state of the target qub
Leave the qubits in the input register in the same state they started in.
Your solution should work on inputs in superposition, and not use any measurements.

<details>
<summary><strong>Need a hint?</strong></summary>
:::hint
$f(x)$ can be represented as $x_0 \oplus x_1 \oplus ... \oplus x_{N-1}$.
</details>
:::
5 changes: 2 additions & 3 deletions katas/content/marking_oracles/product_negation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ In other words, for each basis state $\ket{x}$, flip the state of the target qub
Leave the qubits in the input register in the same state they started in.
Your solution should work on inputs in superposition, and not use any measurements.

<details>
<summary><strong>Need a hint?</strong></summary>
:::hint
Since each addition is done modulo $2$, you can evaluate the effect of each term independently.
</details>
:::
7 changes: 3 additions & 4 deletions katas/content/multi_qubit_gates/arbitrary_controls/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

> For example, if `controlBits = [true, false, true]`, the controlled $X$ gate should only be applied if the control qubits are in state $\ket{101}$.

<details>
<summary><strong>Need a hint?</strong></summary>
<p>Consider using a library operation for this task. If you want to do it without a library operation, don't forget to reset the qubits back to the state they were originally in.</p>
</details>
:::hint
<p>Consider using a library operation for this task. If you want to do it without a library operation, don't forget to reset the qubits back to the state they were originally in.</p>
:::
7 changes: 3 additions & 4 deletions katas/content/multi_qubit_gates/compound_gate/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ $$

> It's recommended to keep a list of common quantum gates on hand.

<details>
<summary><b>Need a hint?</b></summary>
<p>Start by noticing that the top right and bottom left quadrants of the matrix are filled with $0$s, and the bottom right quadrant equals to the top left one, multiplied by $i$. Does this look like a tensor product of a 1-qubit and 2-qubit matrices? Which ones?</p>
</details>
:::hint
<p>Start by noticing that the top right and bottom left quadrants of the matrix are filled with $0$s, and the bottom right quadrant equals to the top left one, multiplied by $i$. Does this look like a tensor product of a 1-qubit and 2-qubit matrices? Which ones?</p>
:::
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

**Goal:** Apply a controlled $R_x$ gate, using the first qubit as control and the second qubit as target, with $\theta$ as the angle argument for the gate.

<details>
<summary><b>Need a hint?</b></summary>
<p>If you were to apply a regular version of $R_x$ gate, it would take two parameters - angle $\theta$ as the first parameter and the target qubit as the second parameter.</p>
</details>
:::hint
<p>If you were to apply a regular version of $R_x$ gate, it would take two parameters - angle $\theta$ as the first parameter and the target qubit as the second parameter.</p>
:::
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
**Goal:** Modify the qubits to the state $\frac{1}{\sqrt{3}} \big(\ket{00} + \ket{01} + \ket{10}\big)$ using post-selection.

<br/>
<details>
<summary><b>Need a hint?</b></summary>
Consider a 3-qubit state $\frac{1}{2}(\ket{00} + \ket{01} + \ket{11}) \otimes \ket{0} + \frac{1}{2} \ket{11} \otimes \ket{1}$.
:::hint
Consider a 3-qubit state $\frac{1}{2}(\ket{00} + \ket{01} + \ket{11}) \otimes \ket{0} + \frac{1}{2} \ket{11} \otimes \ket{1}$.
What happens when you measure the third qubit?
</details>
:::
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Please note that the state parameter is guaranteed to be the same
if you run the code several times. Your operation will be called
once for every run.

<details>
<summary><b>Need a hint?</b></summary>
On a physical quantum system, there would be no way to obtain these values from a single observation. Since this program runs on a simulator, you can use <code>DumpMachine</code> to inspect the qubits and take a note of their state. Furthermore, the problem statement guarantees that the state will be the same from invocation to invocation. So, you can update the code to return the amplitudes that you've taken note of, then run the code again.
</details>
:::hint
On a physical quantum system, there would be no way to obtain these values from a single observation. Since this program runs on a simulator, you can use <code>DumpMachine</code> to inspect the qubits and take a note of their state. Furthermore, the problem statement guarantees that the state will be the same from invocation to invocation. So, you can update the code to return the amplitudes that you've taken note of, then run the code again.
:::
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

**Goal:** Transform the system into the state $\frac{1}{\sqrt2}\big(\ket{00} - \ket{01}\big) = \frac{1}{\sqrt2}\begin{bmatrix} 1 \\ -1 \\ 0 \\ 0 \end{bmatrix}$.

<details>
<summary><b>Need a hint?</b></summary>
Represent the target state as a tensor product $\ket{0} \otimes \frac{1}{\sqrt2}\big(\ket{0} - \ket{1}\big) = \begin{bmatrix} 1 \\ 0 \end{bmatrix} \otimes \frac{1}{\sqrt2}\begin{bmatrix} 1 \\ -1 \end{bmatrix}$.
</details>
:::hint
Represent the target state as a tensor product $\ket{0} \otimes \frac{1}{\sqrt2}\big(\ket{0} - \ket{1}\big) = \begin{bmatrix} 1 \\ 0 \end{bmatrix} \otimes \frac{1}{\sqrt2}\begin{bmatrix} 1 \\ -1 \end{bmatrix}$.
:::
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

**Goal:** Transform the system into the state $\frac{1}{2}\big(\ket{00} + e^{i\pi/4}\ket{01} + e^{i\pi/2}\ket{10} + e^{3i\pi/4}\ket{11}\big) = \frac{1}{2}\begin{bmatrix} 1 \\ e^{i\pi/4} \\ e^{i\pi/2} \\ e^{3i\pi/4} \end{bmatrix}$.

<details>
<summary><b>Need a hint?</b></summary>
Represent the target state as a tensor product $\frac{1}{\sqrt2}\big(\ket{0} + e^{i\pi/2}\ket{1}\big) \otimes \frac{1}{\sqrt2}\big(\ket{0} + e^{i\pi/4}\ket{1}\big) = \frac{1}{\sqrt2} \begin{bmatrix} 1 \\ e^{i\pi/2} \end{bmatrix} \otimes \frac{1}{\sqrt2}\begin{bmatrix} 1 \\ e^{i\pi/4} \end{bmatrix}$.
</details>
:::hint
Represent the target state as a tensor product $\frac{1}{\sqrt2}\big(\ket{0} + e^{i\pi/2}\ket{1}\big) \otimes \frac{1}{\sqrt2}\big(\ket{0} + e^{i\pi/4}\ket{1}\big) = \frac{1}{\sqrt2} \begin{bmatrix} 1 \\ e^{i\pi/2} \end{bmatrix} \otimes \frac{1}{\sqrt2}\begin{bmatrix} 1 \\ e^{i\pi/4} \end{bmatrix}$.
:::
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

**Goal:** Transform the system into the state $\frac{1}{2}\big(\ket{00} - \ket{01} + \ket{10} - \ket{11}\big) = \frac{1}{2}\begin{bmatrix} 1 \\ -1 \\ 1 \\ -1 \end{bmatrix}$.

<details>
<summary><b>Need a hint?</b></summary>
Represent the target state as a tensor product $\frac{1}{\sqrt2}\big(\ket{0} + \ket{1}\big) \otimes \frac{1}{\sqrt2}\big(\ket{0} - \ket{1}\big) = \frac{1}{\sqrt2} \begin{bmatrix} 1 \\ 1 \end{bmatrix} \otimes \frac{1}{\sqrt2}\begin{bmatrix} 1 \\ -1 \end{bmatrix}$.
</details>
:::hint
Represent the target state as a tensor product $\frac{1}{\sqrt2}\big(\ket{0} + \ket{1}\big) \otimes \frac{1}{\sqrt2}\big(\ket{0} - \ket{1}\big) = \frac{1}{\sqrt2} \begin{bmatrix} 1 \\ 1 \end{bmatrix} \otimes \frac{1}{\sqrt2}\begin{bmatrix} 1 \\ -1 \end{bmatrix}$.
:::
7 changes: 3 additions & 4 deletions katas/content/oracles/bit_pattern_challenge/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ represented by `pattern`.
</details>

<br/>
<details>
<summary><b>Need a hint?</b></summary>
Can you transform the state of the input register based on the <code>pattern</code> value so as to have to flip the phase only for the $\ket{1...1}$ state?
</details>
:::hint
Can you transform the state of the input register based on the <code>pattern</code> value so as to have to flip the phase only for the $\ket{1...1}$ state?
:::
7 changes: 3 additions & 4 deletions katas/content/oracles/bit_pattern_oracle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ represented by `pattern`.
</details>

<br/>
<details>
<summary><b>Need a hint?</b></summary>
You need to flip the state of $\ket{y}$ if $\ket{x}$ matches the given pattern. You may find the Q# library operation <code>ApplyControlledOnBitString</code> useful in your implementation.
</details>
:::hint
You need to flip the state of $\ket{y}$ if $\ket{x}$ matches the given pattern. You may find the Q# library operation <code>ApplyControlledOnBitString</code> useful in your implementation.
:::
7 changes: 3 additions & 4 deletions katas/content/oracles/marking_oracle_as_phase/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Flip the phase of each basis state $\ket{x}$ for which $f(x) = 1$. You can only access $f(x)$ via the marking oracle you are given.

<br/>
<details>
<summary><b>Need a hint?</b></summary>
Recall that you can allocate extra qubits to assist in this operation. Is there a state that you could prepare with an auxiliary qubit which would help you to convert the marking oracle to a phase oracle?
</details>
:::hint
Recall that you can allocate extra qubits to assist in this operation. Is there a state that you could prepare with an auxiliary qubit which would help you to convert the marking oracle to a phase oracle?
:::
11 changes: 5 additions & 6 deletions katas/content/oracles/or_but_kth_oracle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ Flip the sign of the basis state $\ket{x}$ if any of the bits of $x$ (not consid
This is a phase oracle, because you're changing the phase of the input state $\ket{x}$ based on the value of the function $f(x)$.
</details>

<details>
<summary><b>Need a hint?</b></summary>
You can use the previously implemented oracles if needed by copying the code.
<br/>
You can use <a href="https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/itemaccessexpressions#array-item-access-and-array-slicing" target="_blank">array slicing</a> to get parts of the array before and after the $k$-th element.
</details>
:::hint
You can use the previously implemented oracles if needed by copying the code.
<br/>
You can use <a href="https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/itemaccessexpressions#array-item-access-and-array-slicing" target="_blank">array slicing</a> to get parts of the array before and after the $k$-th element.
:::
7 changes: 3 additions & 4 deletions katas/content/oracles/or_oracle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ except for $\ket{00...0}$ (the all zero state).
</details>

<br/>
<details>
<summary><b>Need a hint?</b></summary>
You need to flip the state of $\ket{y}$ for every input except $\ket{00...0}$, or, alternatively, flip it unconditionally and then flip it for the $\ket{00...0}$ state. You may find the Q# library function <code>ApplyControlledOnInt</code> useful in your implementation.
</details>
:::hint
You need to flip the state of $\ket{y}$ for every input except $\ket{00...0}$, or, alternatively, flip it unconditionally and then flip it for the $\ket{00...0}$ state. You may find the Q# library function <code>ApplyControlledOnInt</code> useful in your implementation.
:::
7 changes: 3 additions & 4 deletions katas/content/oracles/phase_oracle_seven/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Don't allocate extra qubits to perform this operation.
* If the query register is in the state $\ket{111}$, flip its sign.
* If the query register is in the state $\ket{010}$ or $\ket{101}$, do nothing.

<details>
<summary><b>Need a hint?</b></summary>
To solve this problem, you need to find a gate that will only flip the sign of the $\ket{111}$ basis state. Which single-qubit gate flips the sign of the basis state $\ket{1}$ but not $\ket{0}$? How can you modify this gate to solve this problem?
</details>
:::hint
To solve this problem, you need to find a gate that will only flip the sign of the $\ket{111}$ basis state. Which single-qubit gate flips the sign of the basis state $\ket{1}$ but not $\ket{0}$? How can you modify this gate to solve this problem?
:::
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
<details>
<summary><b>Need a hint?</b></summary>
You can do this by allocating exactly two qubits and calling <code>Controlled U</code> exactly once.
</details>
</details>
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

The library operation <code>CheckZero</code> (from <code>Std.Diagnostics</code>) allows you to check whether the state of the given qubit is $\ket{0}$.

</details>
</details>
Loading
Loading