|
33 | 33 | "cell_type": "markdown", |
34 | 34 | "metadata": {}, |
35 | 35 | "source": [ |
36 | | - "The task is to prepare a quantum number `x` in a superposition of all possible integers between $0$ to $15$, i.e., $|x\\rangle = \\frac{1}{\\sqrt{16}}(|0\\rangle + |1\\rangle + \\dots + |15\\rangle)$. Then, prepare another quantum number `y` that is in the state $|17\\rangle$ only if $|x\\rangle$ is in the state $|15\\rangle$, otherwise the state of `y` should be $|0\\rangle$. Mathematically, the task is to prepare this state:\n", |
37 | | - "$\\begin{equation}\n", |
38 | | - "|x\\rangle|y\\rangle = \\frac{1}{\\sqrt{16}}(|0\\rangle|0\\rangle+|1\\rangle|0\\rangle+\\dots+|14\\rangle|0\\rangle+|15\\rangle|17\\rangle).\n", |
39 | | - "\\end{equation}$\n", |
| 36 | + "The task is to prepare a quantum number `x` in a superposition of all possible integers between $0$ to $15$, i.e., $|x\\rangle = \\frac{1}{\\sqrt{16}}(|0\\rangle + |1\\rangle + \\dots + |15\\rangle)$. \n", |
| 37 | + "Then, prepare another quantum number `y` that is in the state $|17\\rangle$ only if $|x\\rangle$ is in the state $|15\\rangle$, otherwise the state of `y` should be $|0\\rangle$. Mathematically, the task is to prepare this state:\n", |
| 38 | + "$$\n", |
| 39 | + "|x\\rangle|y\\rangle = \\frac{1}{\\sqrt{16}}(|0\\rangle|0\\rangle+|1\\rangle|0\\rangle+\\dots+|14\\rangle|0\\rangle+|15\\rangle|17\\rangle)\n", |
| 40 | + "$$\n", |
40 | 41 | "\n", |
41 | 42 | "How to approach this task? You have already seen how to create a uniform superposition with the `hadamard_transform`. Now, conditioned on the value of $|x\\rangle$ being $|15\\rangle$, prepare the state of $|y\\rangle$ to be $|17\\rangle$ with the `inplace_xor` function." |
42 | 43 | ] |
|
72 | 73 | "cell_type": "markdown", |
73 | 74 | "metadata": {}, |
74 | 75 | "source": [ |
75 | | - "In the Python syntax, `control` is a Python function with two arguments. The `ctrl` argument is the condition for which the `stmt_block` operand is applied. The `stmt_block` argument is the specific operation/function to apply, given that the condition is satisfied. Passing a function as an argument for another function is done with the `lambda:` keyword, used to define inline functions. **So, anytime you pass a function as an argument in the Python SDK, use the prefix `lambda:`**. [read more](https://docs.classiq.io/latest/qmod-reference/language-reference/operators/?h=lambda).\n", |
| 76 | + "In the Python syntax, `control` is a Python function with two arguments. The `ctrl` argument is the condition for which the `stmt_block` operand is applied. The `stmt_block` argument is the specific operation/function to apply, given that the condition is satisfied. Passing a function as an argument for another function is done with the `lambda:` keyword, used to define inline functions. **So, anytime you pass a function as an argument in the Python SDK, use the prefix `lambda:`** ([read more](https://docs.classiq.io/latest/qmod-reference/language-reference/operators/?h=lambda)).\n", |
76 | 77 | "\n", |
77 | 78 | "In the native syntax, `control` is embedded in the Qmod language such that the condition is specified with the `()` parentheses, and the operand to apply is specified within the scope of the `control`, i.e., within the `{}` curly brackets.\n", |
78 | 79 | "\n", |
|
193 | 194 | "\n", |
194 | 195 | "* In the Python SDK, write the quantum operations just like any other Python function. The arguments of the quantum operation that are functions by themselves must be passed with the `lambda:` keyword. In the above example, the `stmt_block` argument of the `control` function is a function by itself (`inplace_xor`), hence it is prefixed with `lambda:`.\n", |
195 | 196 | "\n", |
196 | | - "* Other quantum operations are `power` (raising a unitary to some power), `invert` (applying the inverse of a unitary), and `within_apply` (applying two unitaries $U$ and $V$ as $UVU^\\dagger$). See a detailed [description of the quantum operators](https://docs.classiq.io/latest/qmod-reference/language-reference/statements/power/).\n" |
| 197 | + "* Other quantum operations are `power` (raising a unitary to some power), `invert` (applying the inverse of a unitary), `within_apply` (applying two unitaries $U$ and $V$ as $UVU^\\dagger$) and `bind` (rewiring qubit(s) referenced by a source variable to a destination variable). For more information, see the detailed description of [each quantum operator](https://docs.classiq.io/latest/qmod-reference/language-reference/statements/power/).\n" |
197 | 198 | ] |
198 | 199 | }, |
199 | 200 | { |
200 | 201 | "cell_type": "code", |
201 | | - "execution_count": 7, |
| 202 | + "execution_count": 12, |
202 | 203 | "metadata": {}, |
203 | 204 | "outputs": [], |
204 | 205 | "source": [ |
|
0 commit comments