"The **GHZ Game** quantum kata is a series of exercises designed\n",
"to get you familiar with the GHZ game.\n",
"\n",
"In it three players (Alice, Bob and Charlie) try to win the following game:\n",
"\n",
"Each of them is given a bit (r, s and t respectively), and\n",
"they have to return new bits (a, b and c respectively) so\n",
"that r ∨ s ∨ t = a ⊕ b ⊕ c. The input bits will have\n",
"zero or two bits set to true and three or one bits set to false.\n",
"The trick is, the players can not communicate during the game.\n",
"\n",
"* You can read more about the GHZ game in the [lecture notes](https://cs.uwaterloo.ca/~watrous/CPSC519/LectureNotes/20.pdf) by John Watrous. \n",
"* Another description can be found in the [lecture notes](https://staff.fnwi.uva.nl/m.walter/physics491/lecture1.pdf) by Michael Walter.\n",
"\n",
"Each task is wrapped in one operation preceded by the description of the task.\n",
"Your goal is to fill in the blank (marked with the `// ...` comments)\n",
"with some Q# code that solves the task. To verify your answer, run the cell using Ctrl/⌘+Enter.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To begin, first prepare this notebook for execution (if you skip this step, you'll get \"Syntax does not match any known patterns\" error when you try to execute Q# code in the next cells):"
"> The package versions in the output of the cell above should always match. If you are running the Notebooks locally and the versions do not match, please install the IQ# version that matches the version of the `Microsoft.Quantum.Katas` package.\n",
"> <details>\n",
"> <summary><u>How to install the right IQ# version</u></summary>\n",
"In the quantum version of the game, the players still can not\n",
"communicate during the game, but they are allowed to share \n",
"qubits from an entangled triple before the start of the game.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 2.1. Entangled triple\n",
"\n",
"**Input:** An array of three qubits in the $|000\\rangle$ state.\n",
"\n",
"**Goal:** Create the entangled state $|\\Phi\\rangle = \\frac{1}{2} \\big(|000\\rangle - |011\\rangle - |101\\rangle - |110\\rangle \\big)$ on these qubits."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%kata T21_CreateEntangledTriple_Test \n",
"\n",
"operation CreateEntangledTriple (qs : Qubit[]) : Unit {\n",
" // ...\n",
" fail \"Task 2.1 not implemented yet\";\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 2.2. Quantum strategy\n",
"\n",
"**Inputs:**\n",
"\n",
" 1. The input bit for one of the players (r, s or t),\n",
"\n",
" 2. That player's qubit of the entangled triple shared between the players.\n",
"\n",
"**Goal:** Measure the qubit in the Z basis if the bit is 0 (false), or the X basis if the bit is 1 (true), and return the result.\n",
"\n",
"The state of the qubit after the operation does not matter."