From e4cd3ea2d63c149b63945992075dd17e7a5fd285 Mon Sep 17 00:00:00 2001 From: Gregory Gridin Date: Tue, 23 Jul 2024 13:59:43 -0700 Subject: [PATCH 01/13] ghz_classical_game initial commit --- .../ghz_classical_game/Placeholder.qs | 7 + .../ghz_classical_game/Solution.qs | 13 ++ .../ghz_classical_game/Verification.qs | 47 +++++ .../ghz_classical_game/index.md | 8 + .../ghz_classical_game/solution.md | 7 + .../ghz_classical_strategy/Placeholder.qs | 19 ++ .../ghz_classical_strategy/Solution.qs | 13 ++ .../ghz_classical_strategy/Verification.qs | 53 +++++ .../ghz_classical_strategy/index.md | 9 + .../ghz_classical_strategy/solution.md | 11 + .../ghz_win_condition/Placeholder.qs | 7 + .../ghz_win_condition/Solution.qs | 7 + .../ghz_win_condition/Verification.qs | 35 ++++ .../nonlocal_games/ghz_win_condition/index.md | 8 + .../ghz_win_condition/solution.md | 9 + katas/content/nonlocal_games/index.md | 195 ++++++++++++++++-- 16 files changed, 433 insertions(+), 15 deletions(-) create mode 100644 katas/content/nonlocal_games/ghz_classical_game/Placeholder.qs create mode 100644 katas/content/nonlocal_games/ghz_classical_game/Solution.qs create mode 100644 katas/content/nonlocal_games/ghz_classical_game/Verification.qs create mode 100644 katas/content/nonlocal_games/ghz_classical_game/index.md create mode 100644 katas/content/nonlocal_games/ghz_classical_game/solution.md create mode 100644 katas/content/nonlocal_games/ghz_classical_strategy/Placeholder.qs create mode 100644 katas/content/nonlocal_games/ghz_classical_strategy/Solution.qs create mode 100644 katas/content/nonlocal_games/ghz_classical_strategy/Verification.qs create mode 100644 katas/content/nonlocal_games/ghz_classical_strategy/index.md create mode 100644 katas/content/nonlocal_games/ghz_classical_strategy/solution.md create mode 100644 katas/content/nonlocal_games/ghz_win_condition/Placeholder.qs create mode 100644 katas/content/nonlocal_games/ghz_win_condition/Solution.qs create mode 100644 katas/content/nonlocal_games/ghz_win_condition/Verification.qs create mode 100644 katas/content/nonlocal_games/ghz_win_condition/index.md create mode 100644 katas/content/nonlocal_games/ghz_win_condition/solution.md diff --git a/katas/content/nonlocal_games/ghz_classical_game/Placeholder.qs b/katas/content/nonlocal_games/ghz_classical_game/Placeholder.qs new file mode 100644 index 0000000000..cb3e69967f --- /dev/null +++ b/katas/content/nonlocal_games/ghz_classical_game/Placeholder.qs @@ -0,0 +1,7 @@ +namespace Kata { + + operation PlayClassicalGHZ (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] { + // Implement your solution here... + return []; + } +} diff --git a/katas/content/nonlocal_games/ghz_classical_game/Solution.qs b/katas/content/nonlocal_games/ghz_classical_game/Solution.qs new file mode 100644 index 0000000000..22d80bd80b --- /dev/null +++ b/katas/content/nonlocal_games/ghz_classical_game/Solution.qs @@ -0,0 +1,13 @@ +namespace Kata { + // Simple implementation of the GHZ classical game + // 3 players, each player has own strategy and receives a bit from the referee + operation PlayClassicalGHZ (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] { + let r = inputs[0]; + let s = inputs[1]; + let t = inputs[2]; + let a = strategies[0](r); + let b = strategies[1](s); + let c = strategies[2](t); + return [a, b, c]; + } +} diff --git a/katas/content/nonlocal_games/ghz_classical_game/Verification.qs b/katas/content/nonlocal_games/ghz_classical_game/Verification.qs new file mode 100644 index 0000000000..0ea7931884 --- /dev/null +++ b/katas/content/nonlocal_games/ghz_classical_game/Verification.qs @@ -0,0 +1,47 @@ +namespace Kata.Verification { + + // All possible starting bits (r, s and t) that the referee can give + // to Alice, Bob and Charlie. + function RefereeBits () : Bool[][] { + return [[false, false, false], + [true, true, false], + [false, true, true], + [true, false, true]]; + } + + operation AliceClassical (x : Bool) : Bool { + return true; + } + + operation BobClassical (y : Bool) : Bool { + return true; + } + + operation CharlieClassical (z : Bool) : Bool { + return true; + } + + operation PlayClassicalGHZ_Reference (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] { + mutable results : (Bool)[] = []; + for i in 0 .. Length(strategies) - 1{ + set results += [strategies[i](inputs[i])]; + } + return results; + } + + @EntryPoint() + operation CheckSolution() : Bool { + // To test the interaction, run it on several deterministic strategies (not necessarily good ones) + let inputs = RefereeBits(); + let strategies = [AliceClassical, BobClassical, CharlieClassical]; + for rst in inputs { + let actual = Kata.PlayClassicalGHZ(strategies, rst); + let expected = PlayClassicalGHZ_Reference(strategies, rst); + if actual != expected { + Message($"Expected {expected}, got {actual} for {rst}"); + return false; + } + } + true + } +} diff --git a/katas/content/nonlocal_games/ghz_classical_game/index.md b/katas/content/nonlocal_games/ghz_classical_game/index.md new file mode 100644 index 0000000000..e52a0fd8ab --- /dev/null +++ b/katas/content/nonlocal_games/ghz_classical_game/index.md @@ -0,0 +1,8 @@ +**Inputs:** + +1. An operations which implement classical strategies (i.e., takes an input bit and produces an output bit), +2. An array of 3 input bits that should be passed to the players. + +**Output:** + +An array of 3 bits that will be produced if each player uses this strategy. diff --git a/katas/content/nonlocal_games/ghz_classical_game/solution.md b/katas/content/nonlocal_games/ghz_classical_game/solution.md new file mode 100644 index 0000000000..42937ae9bb --- /dev/null +++ b/katas/content/nonlocal_games/ghz_classical_game/solution.md @@ -0,0 +1,7 @@ +You are given both the input bits and the strategy each of the players are using, so you have simply to convert them to the output bits and return those. + + +@[solution]({ + "id": "nonlocal_games__ghz_classical_game_solution", + "codePath": "Solution.qs" +}) diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/Placeholder.qs b/katas/content/nonlocal_games/ghz_classical_strategy/Placeholder.qs new file mode 100644 index 0000000000..1e1ee33f51 --- /dev/null +++ b/katas/content/nonlocal_games/ghz_classical_strategy/Placeholder.qs @@ -0,0 +1,19 @@ +namespace Kata { + operation AliceClassical (x : Bool) : Bool { + // Implement your solution here... + + return false; + } + + operation BobClassical (y : Bool) : Bool { + // Implement your solution here... + + return false; + } + + operation CharlieClassical (z : Bool) : Bool { + // Implement your solution here... + + return false; + } +} diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/Solution.qs b/katas/content/nonlocal_games/ghz_classical_strategy/Solution.qs new file mode 100644 index 0000000000..442f440bab --- /dev/null +++ b/katas/content/nonlocal_games/ghz_classical_strategy/Solution.qs @@ -0,0 +1,13 @@ +namespace Kata { + operation AliceClassical (x : Bool) : Bool { + return true; + } + + operation BobClassical (y : Bool) : Bool { + return true; + } + + operation CharlieClassical (z : Bool) : Bool { + return true; + } +} diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/Verification.qs b/katas/content/nonlocal_games/ghz_classical_strategy/Verification.qs new file mode 100644 index 0000000000..f580eb803d --- /dev/null +++ b/katas/content/nonlocal_games/ghz_classical_strategy/Verification.qs @@ -0,0 +1,53 @@ +namespace Kata.Verification { + open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Logical; + open Microsoft.Quantum.Random; + + function WinCondition_Reference (rst : Bool[], abc : Bool[]) : Bool { + return (rst[0] or rst[1] or rst[2]) == Xor(Xor(abc[0], abc[1]), abc[2]); + } + + // All possible starting bits (r, s and t) that the referee can give + // to Alice, Bob and Charlie. + function RefereeBits () : Bool[][] { + return [[false, false, false], + [true, true, false], + [false, true, true], + [true, false, true]]; + } + + operation PlayClassicalGHZ_Reference (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] { + let r = inputs[0]; + let s = inputs[1]; + let t = inputs[2]; + let a = strategies[0](r); + let b = strategies[1](s); + let c = strategies[2](t); + return [a, b, c]; + } + + @EntryPoint() + operation CheckSolution() : Bool { + let inputs = RefereeBits(); + let strategies = [Kata.AliceClassical, Kata.BobClassical, Kata.CharlieClassical]; + + let iterations = 10000; + mutable wins = 0; + for _ in 0 .. iterations - 1 { + for bits in inputs { + let abc = PlayClassicalGHZ_Reference(strategies, bits); + if WinCondition_Reference(bits, abc) { + set wins = wins + 1; + } + } + } + // The solution is correct if the players win 75% (3/4) of the time. + if wins != iterations*Length(inputs)*3/4 { + Message("Alice, Bob, and Charlie's classical strategy is not optimal"); + return false; + } + Message("Correct!"); + true + } +} diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/index.md b/katas/content/nonlocal_games/ghz_classical_strategy/index.md new file mode 100644 index 0000000000..7a9d44045e --- /dev/null +++ b/katas/content/nonlocal_games/ghz_classical_strategy/index.md @@ -0,0 +1,9 @@ +In this task you have to implement three functions, one for each player's classical strategy. +Note that they are covered by one test, so you have to implement all of them to pass the test. +For non-deterministic strategies, DrawRandomBoolean or [DrawRandomInt](https://learn.microsoft.com/en-us/qsharp/api/qsharp-lang/microsoft.quantum.random/drawrandomint) functions from Q# library can be used. + +**Input:** +Alice, Bob, and Charlie's starting bits (X, Y, and Z). + +**Output:** +Alice, Bob, and Charlie's output bits (A, B, and C) to maximize their chance of winning. diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/solution.md b/katas/content/nonlocal_games/ghz_classical_strategy/solution.md new file mode 100644 index 0000000000..a9952ac3d4 --- /dev/null +++ b/katas/content/nonlocal_games/ghz_classical_strategy/solution.md @@ -0,0 +1,11 @@ +If all three players return TRUE, then a ⊕ b ⊕ c = TRUE by necessity (since the sum of their bits is odd). +This will win against inputs 011, 101, and 110 and lose against 000. +Another solution is one player retuns TRUE, and two others return FALSE. + +Since the four above inputs have equal probability, and represent all possible inputs, +this deterministic strategy wins with 75% probability. + +@[solution]({ + "id": "nonlocal_games__ghz_classical_strategy_solution", + "codePath": "Solution.qs" +}) diff --git a/katas/content/nonlocal_games/ghz_win_condition/Placeholder.qs b/katas/content/nonlocal_games/ghz_win_condition/Placeholder.qs new file mode 100644 index 0000000000..3e875360a1 --- /dev/null +++ b/katas/content/nonlocal_games/ghz_win_condition/Placeholder.qs @@ -0,0 +1,7 @@ +namespace Kata { + function WinCondition (rst : Bool[], abc : Bool[]) : Bool { + // Implement your solution here... + + return false; + } +} diff --git a/katas/content/nonlocal_games/ghz_win_condition/Solution.qs b/katas/content/nonlocal_games/ghz_win_condition/Solution.qs new file mode 100644 index 0000000000..702e7553ff --- /dev/null +++ b/katas/content/nonlocal_games/ghz_win_condition/Solution.qs @@ -0,0 +1,7 @@ +namespace Kata { + open Microsoft.Quantum.Logical; + + function WinCondition (rst : Bool[], abc : Bool[]) : Bool { + return (rst[0] or rst[1] or rst[2]) == Xor(Xor(abc[0], abc[1]), abc[2]); + } +} diff --git a/katas/content/nonlocal_games/ghz_win_condition/Verification.qs b/katas/content/nonlocal_games/ghz_win_condition/Verification.qs new file mode 100644 index 0000000000..0ef3a94ed7 --- /dev/null +++ b/katas/content/nonlocal_games/ghz_win_condition/Verification.qs @@ -0,0 +1,35 @@ +namespace Kata.Verification { + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Logical; + + function WinCondition_Reference (rst : Bool[], abc : Bool[]) : Bool { + return (rst[0] or rst[1] or rst[2]) == Xor(Xor(abc[0], abc[1]), abc[2]); + } + + // All possible starting bits (r, s and t) that the referee can give + // to Alice, Bob and Charlie. + function RefereeBits () : Bool[][] { + return [[false, false, false], + [true, true, false], + [false, true, true], + [true, false, true]]; + } + + @EntryPoint() + function CheckSolution() : Bool { + for rst in RefereeBits() { + for i in 0 .. 1 <<< 3 - 1 { + let abc = IntAsBoolArray(i, 3); + let expected = WinCondition_Reference(rst, abc); + let actual = Kata.WinCondition(rst, abc); + + if actual != expected { + Message($"Win condition '{actual}' is wrong for rst={rst}, abc={abc}"); + return false; + } + } + } + Message("Correct!"); + true + } +} diff --git a/katas/content/nonlocal_games/ghz_win_condition/index.md b/katas/content/nonlocal_games/ghz_win_condition/index.md new file mode 100644 index 0000000000..9639a451a0 --- /dev/null +++ b/katas/content/nonlocal_games/ghz_win_condition/index.md @@ -0,0 +1,8 @@ +**Inputs:** + +1. Alice, Bob and Charlie's input bits (r, s and t), stored as an array of length 3, +2. Alice, Bob and Charlie's output bits (a, b and c), stored as an array of length 3. +The input bits will have zero or two bits set to true. + +**Output:** +True if Alice, Bob and Charlie won the GHZ game, that is, if r ∨ s ∨ t = a ⊕ b ⊕ c, and false otherwise. diff --git a/katas/content/nonlocal_games/ghz_win_condition/solution.md b/katas/content/nonlocal_games/ghz_win_condition/solution.md new file mode 100644 index 0000000000..3b2957acc4 --- /dev/null +++ b/katas/content/nonlocal_games/ghz_win_condition/solution.md @@ -0,0 +1,9 @@ +There are four inputs possible, (0,0,0), (0,1,1), (1,0,1), and (1,1,0), each with 25% probability. +Therefore, in order to win, the sum of the output bits has to be even if the input is (0,0,0) and odd otherwise. + +To check whether the win condition holds, you need to compute the expressions $r \vee s \vee t$ and $a \oplus b \oplus c$ and to compare them: if they are equal, the game is won. To compute the expressions, you can use [built-in operators](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions) and logical function `Xor` from the [`Microsoft.Quantum.Logical`](https://learn.microsoft.com/en-us/qsharp/api/qsharp-lang/microsoft.quantum.logical/xor) library. + +@[solution]({ + "id": "nonlocal_games__ghz_win_condition_solution", + "codePath": "Solution.qs" +}) diff --git a/katas/content/nonlocal_games/index.md b/katas/content/nonlocal_games/index.md index f81c197037..4460e27572 100644 --- a/katas/content/nonlocal_games/index.md +++ b/katas/content/nonlocal_games/index.md @@ -12,13 +12,15 @@ so they cannot communicate with each other during the game. Another characteristics of these games is that they are "refereed", which means the players try to win against the referee. **This kata covers the following topics:** - - Clauser, Horne, Shimony, and Hold thought experiment (often abbreviated as CHSH game) - - Greenberger-Horne-Zeilinger game (often abbreviated as GHZ game) - - The Mermin-Peres Magic Square game + +- Clauser, Horne, Shimony, and Hold thought experiment (often abbreviated as CHSH game) +- Greenberger-Horne-Zeilinger game (often abbreviated as GHZ game) +- The Mermin-Peres Magic Square game **What you should know to start working on this kata:** - - Basic linear algebra - - Basic knowledge of quantum gates and measurements + +- Basic linear algebra +- Basic knowledge of quantum gates and measurements @[section]({ "id": "nonlocal_games__chsh_game", @@ -31,15 +33,11 @@ Each of them is given a bit (Alice gets X and Bob gets Y), and they have to return new bits (Alice returns A and Bob returns B) so that X ∧ Y = A ⊕ B. The trick is, they can not communicate during the game. -> * ∧ is the standard bitwise AND operator. -> * ⊕ is the exclusive or, or XOR operator, so (P ⊕ Q) is true if exactly one of P and Q is true. - -@[section]({ - "id": "nonlocal_games__chsh_game_classical", - "title": "Part I. Classical CHSH" -}) +> - ∧ is the standard bitwise AND operator. +> - ⊕ is the exclusive or, or XOR operator, so (P ⊕ Q) is true if exactly one of P and Q is true. To start with, let's take a look at how you would play the classical variant of this game without access to any quantum tools. +Then, let's proceed with quantum strategies for Alice and Bob. @[exercise]({ "id": "nonlocal_games__chsh_classical_win_condition", @@ -53,9 +51,176 @@ To start with, let's take a look at how you would play the classical variant of "path": "./chsh_classical_strategy/" }) +@[exercise]({ + "id": "nonlocal_games__chsh_quantum_alice_strategy", + "title": "Alice's Quantum Strategy", + "path": "./chsh_quantum_alice_strategy/" +}) + +@[exercise]({ + "id": "nonlocal_games__chsh_quantum_bob_strategy", + "title": "Bob's Quantum Strategy", + "path": "./chsh_quantum_bob_strategy/" +}) + +@[section]({ + "id": "nonlocal_games__discussion", + "title": "Discussion: Probability of Victory for Quantum Strategy" +}) + +The above quantum strategy adopted by Alice and Bob offers a win rate of $\frac{2 + \sqrt{2}}{4}$, or about 85.36%. Let's see why this is the case. + +First, consider the outcome if Alice and Bob simply measure their qubits in the Z basis without manipulating them at all. Because of the entanglement inherent to the Bell state they hold, their measurements will always agree (i.e., both true or both false). +This will suffice for victory in the three scenarios (0,0), (0,1) and (1,0) and fail for (1,1), so their win probability is 75%, the same as that for the straightforward classical strategies of invariably returning both true or both false. + +Now let's analyze the optimal quantum strategy. + +> As a reminder, probability "wavefunction" for a two-qubit state is given by the following length-4 vector of amplitudes: +> $$\begin{bmatrix}\psi_{00}\\\psi_{01}\\\psi_{10}\\\psi_{11}\end{bmatrix}$$ +> $|\psi_{ij}|^2$ gives the probability of observing the corresponding basis state $|ij\rangle$ upon measuring the qubit pair. + +The initial state $|00\rangle$ has $\psi_{00} = 1$ and $\psi_{01} = \psi_{10} = \psi_{11} = 0$. +The Bell state we prepare as the first step of the game has an amplitude vector as follows (we'll use decimal approximations for matrix elements): + +$$\begin{bmatrix}1/\sqrt{2}\\0\\0\\1/\sqrt{2}\end{bmatrix} = \begin{bmatrix}0.7071\\0\\0\\0.7071\end{bmatrix}$$ + +Let's analyze the probabilities of outcomes in case of different bits received by players. + +## Case 1: Alice holds bit 0 + +In this case Alice simply measures in the Z basis as above. + +- When Bob's bit is 0, he rotates his qubit clockwise by $\pi/8$, which corresponds to the operator + +$$\begin{bmatrix} + 0.9239 & 0.3827 & 0 & 0\\ + -0.3827 & 0.9239 & 0 & 0\\ + 0 & 0 & 0.9239 & 0.3827\\ + 0 & 0 & -0.3827 & 0.9239 +\end{bmatrix}$$ +This performs the $R_y$ rotation by $\pi/8$ radians clockwise on Bob's qubit while leaving Alice's qubit unchanged. + +- If Bob's bit were 1, he would rotate his qubit counterclockwise by $\pi/8$, applying a very similar operator + +$$\begin{bmatrix} + 0.9239 & -0.3827 & 0 & 0\\ + 0.3827 & 0.9239 & 0 & 0\\ + 0 & 0 & 0.9239 & -0.3827\\ + 0 & 0 & 0.3827 & 0.9239 +\end{bmatrix}$$ + +Therefore, when Alice has bit 0, the application of the rotation operator to the Bell state gives +$$\begin{bmatrix} + 0.6533 \\ + -0.2706 \\ + 0.2706 \\ + 0.6533 +\end{bmatrix} \text{ or } +\begin{bmatrix} + 0.6533\\ + 0.2706\\ + -0.2706\\ + 0.6533 +\end{bmatrix}$$ +depending on whether Bob holds 0 (left-hand case) or 1 (right-hand case). + +The result of AND on their input bits will always be 0; thus they win when their outputs agree. These two cases correspond to the top and bottom elements of the vectors above, with a combined probability of $(0.6533)^2 + (0.6533)^2 = 0.4268 + 0.4268 = 0.8536$, so they have an 85.36% win chance. + +## Case 2: Alice holds bit 1 + +When Alice holds bit 1, she measures in basis X (or, equivalently, Hadamard-transforms her qubit, leaving Bob's be, before making her Z-basis measurement). This corresponds to applying the operator +$$\begin{bmatrix} + 0.7071 & 0 & 0.7071 & 0\\ + 0 & 0.7071 & 0 & 0.7071\\ + 0.7071 & 0 & -0.7071 & 0\\ + 0 & 0.7071 & 0 & -0.7071 +\end{bmatrix}$$ +to the Bell state, resulting in a vector of: +$$\begin{bmatrix} + 0.5\\ + 0.5\\ + 0.5\\ + -0.5 +\end{bmatrix}$$ + +Now, one of the two rotation operators is applied depending on what bit Bob holds, transforming this vector into: +$$\begin{bmatrix} + 0.6533 \\ + 0.2706 \\ + 0.2706 \\ + -0.6533 +\end{bmatrix} \text{ or } +\begin{bmatrix} + 0.2706\\ + 0.6533\\ + 0.6533\\ + -0.2706 + \end{bmatrix}$$ + +When Bob holds 0, they still want to return the same parity, which they again do with 85.36% probability (left-hand vector above). +But when Bob holds 1, the AND condition is now true and the players want to answer in opposite parity. This corresponds to the second and third elements of the right-hand vector above. +Thanks to the "magic" of the combination of the counterclockwise rotation and Hadamard transform, they now do this with probability $(0.6533)^2 + (0.6533)^2 = 0.8536$ and thus 85.36% becomes their win odds once more. + +## Side notes + +- If Bob never rotated his qubit, their entangled state would remain the Bell state if Alice held bit 0 and the state corresponding to $\frac12 \big(|00\rangle + |01\rangle + |10\rangle - |11\rangle\big)$ if Alice held bit 1. + +While she and Bob would have a 100% success probability against Alice's 0 bit, they would have only a 50% chance of success if she held bit 1, and thus their win chance would revert to the 75% of the classical strategy again. +- It can be proven that Alice and Bob cannot surpass an overall win probability of 85.36% in the CHSH game. This entails a higher-level discussion of quantum observable theory, for instance see [Tsirelson's bound](https://en.wikipedia.org/wiki/Tsirelson's_bound). + +@[section]({ + "id": "nonlocal_games__chsh_e2e", + "title": "Running CHSH Game End to End" +}) + +Putting together the building blocks we've implemented into a strategy is very simple: +- Allocate two qubits and prepare a Bell state on them. +- Send one of the qubits to Alice and another to Bob (this step is "virtual", not directly reflected in Q# code, other than making sure that Alice and Bob each act on their qubit only). +- Have Alice and Bob perform their measurements on their respective qubits using `AliceQuantum` and `BobQuantum` operations. +- Release(reset) used qubits +- Return their measurement results. + +In the example below you can compare classical and quantum results: first boolean value indicates win for classical Alice and Bob, second boolean is win for quantum Alice and Bob. +You may play with the code and check if there is a difference in results when +1. referee picks non-random bits +2. Bob's qubit is measured first +3. Alice and Bob get not entangled qubit pair + +@[example]({"id": "nonlocal_games__chsh_e2edemo", "codePath": "./examples/CHSHGameDemo.qs"}) + +@[section]({ + "id": "nonlocal_games__ghz_game", + "title": "GHZ Game" +}) + +In **GHZ Game** three players (Alice, Bob and Charlie) try to win the following game: + +Each of them is given a bit (r, s and t respectively), and they have to return new bits (a, b and c respectively) so +that r ∨ s ∨ t = a ⊕ b ⊕ c. The input bits will have zero or two bits set to true and three or one bits set to false. +The players are free to share information (and even qubits!) before the game starts, but are forbidden from communicating +with each other afterwards. + +- ∨ is the standard bitwise OR operator. +- ⊕ is the exclusive or, or XOR operator, so (P ⊕ Q) is true if exactly one of P and Q is true. + +To start with, take a look at how you would play the classical variant of this game without access to any quantum tools. +Then, let's proceed with quantum strategy and game implementation. + +@[exercise]({ + "id": "nonlocal_games__ghz_win_condition", + "title": "Win Condition", + "path": "./ghz_win_condition/" +}) + +@[exercise]({ + "id": "nonlocal_games__ghz_classical_strategy", + "title": "Classical Strategy", + "path": "./ghz_classical_strategy/" +}) + @[section]({ - "id": "nonlocal_games__conclusion", - "title": "Conclusion" + "id": "nonlocal_games__conclusion", + "title": "Conclusion" }) -Congratulations! In this kata you learned how to use quantum entanglement in nonlocal quantum games to get results that are better than any classical strategy can offer. +Congratulations! In this kata you learned how to use quantum entanglement in nonlocal quantum games to get results that are better than any classical strategy can offer. \ No newline at end of file From d4a3b240fc1974a97b938f57b9b256e5364b54cc Mon Sep 17 00:00:00 2001 From: Gregory Gridin Date: Tue, 23 Jul 2024 21:02:40 -0700 Subject: [PATCH 02/13] Fix for Verification bug --- .../ghz_classical_game/Solution.qs | 5 +- .../ghz_classical_game/Verification.qs | 49 +++--- .../ghz_classical_strategy/Verification.qs | 8 +- katas/content/nonlocal_games/index.md | 148 ++---------------- 4 files changed, 47 insertions(+), 163 deletions(-) diff --git a/katas/content/nonlocal_games/ghz_classical_game/Solution.qs b/katas/content/nonlocal_games/ghz_classical_game/Solution.qs index 22d80bd80b..11e2d417d1 100644 --- a/katas/content/nonlocal_games/ghz_classical_game/Solution.qs +++ b/katas/content/nonlocal_games/ghz_classical_game/Solution.qs @@ -1,7 +1,10 @@ namespace Kata { - // Simple implementation of the GHZ classical game // 3 players, each player has own strategy and receives a bit from the referee operation PlayClassicalGHZ (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] { + + if Length(strategies) != 3 or Length(inputs) != 3 { + return []; + } let r = inputs[0]; let s = inputs[1]; let t = inputs[2]; diff --git a/katas/content/nonlocal_games/ghz_classical_game/Verification.qs b/katas/content/nonlocal_games/ghz_classical_game/Verification.qs index 0ea7931884..2abc2e3d35 100644 --- a/katas/content/nonlocal_games/ghz_classical_game/Verification.qs +++ b/katas/content/nonlocal_games/ghz_classical_game/Verification.qs @@ -9,39 +9,46 @@ namespace Kata.Verification { [true, false, true]]; } - operation AliceClassical (x : Bool) : Bool { - return true; - } - - operation BobClassical (y : Bool) : Bool { - return true; - } - - operation CharlieClassical (z : Bool) : Bool { - return true; + operation TestStrategy (input : Bool, mode : Int) : Bool { + return mode == 0 ? false | mode == 1 ? true | mode == 2 ? input | not input; } operation PlayClassicalGHZ_Reference (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] { - mutable results : (Bool)[] = []; - for i in 0 .. Length(strategies) - 1{ - set results += [strategies[i](inputs[i])]; + + if Length(strategies) != 3 or Length(inputs) != 3 { + return []; } - return results; + let r = inputs[0]; + let s = inputs[1]; + let t = inputs[2]; + let a = strategies[0](r); + let b = strategies[1](s); + let c = strategies[2](t); + return [a, b, c]; } @EntryPoint() operation CheckSolution() : Bool { - // To test the interaction, run it on several deterministic strategies (not necessarily good ones) let inputs = RefereeBits(); - let strategies = [AliceClassical, BobClassical, CharlieClassical]; for rst in inputs { - let actual = Kata.PlayClassicalGHZ(strategies, rst); - let expected = PlayClassicalGHZ_Reference(strategies, rst); - if actual != expected { - Message($"Expected {expected}, got {actual} for {rst}"); - return false; + // To test the interaction, run it on deterministic strategies (not necessarily good ones) + // This logic helps to detect errors in user PlayClassicalGHZ implementation like + // using the wrong sequence of output bits or not using the strategies at all. + for mode_1 in 0 .. 3 { + for mode_2 in 0 .. 3 { + for mode_3 in 0 .. 3 { + let strategies = [TestStrategy(_, mode_1), TestStrategy(_, mode_2), TestStrategy(_, mode_3)]; + let actual = Kata.PlayClassicalGHZ(strategies, rst); + let expected = PlayClassicalGHZ_Reference(strategies, rst); + if actual != expected { + Message($"Expected {expected}, got {actual} for {rst}"); + return false; + } + } + } } } + Message("Correct!"); true } } diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/Verification.qs b/katas/content/nonlocal_games/ghz_classical_strategy/Verification.qs index f580eb803d..c594f6949e 100644 --- a/katas/content/nonlocal_games/ghz_classical_strategy/Verification.qs +++ b/katas/content/nonlocal_games/ghz_classical_strategy/Verification.qs @@ -18,6 +18,10 @@ namespace Kata.Verification { } operation PlayClassicalGHZ_Reference (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] { + + if Length(strategies) != 3 or Length(inputs) != 3 { + return []; + } let r = inputs[0]; let s = inputs[1]; let t = inputs[2]; @@ -43,10 +47,10 @@ namespace Kata.Verification { } } // The solution is correct if the players win 75% (3/4) of the time. - if wins != iterations*Length(inputs)*3/4 { + if wins < iterations*Length(inputs)*3/4 { Message("Alice, Bob, and Charlie's classical strategy is not optimal"); return false; - } + } Message("Correct!"); true } diff --git a/katas/content/nonlocal_games/index.md b/katas/content/nonlocal_games/index.md index 4460e27572..a475f29917 100644 --- a/katas/content/nonlocal_games/index.md +++ b/katas/content/nonlocal_games/index.md @@ -51,143 +51,6 @@ Then, let's proceed with quantum strategies for Alice and Bob. "path": "./chsh_classical_strategy/" }) -@[exercise]({ - "id": "nonlocal_games__chsh_quantum_alice_strategy", - "title": "Alice's Quantum Strategy", - "path": "./chsh_quantum_alice_strategy/" -}) - -@[exercise]({ - "id": "nonlocal_games__chsh_quantum_bob_strategy", - "title": "Bob's Quantum Strategy", - "path": "./chsh_quantum_bob_strategy/" -}) - -@[section]({ - "id": "nonlocal_games__discussion", - "title": "Discussion: Probability of Victory for Quantum Strategy" -}) - -The above quantum strategy adopted by Alice and Bob offers a win rate of $\frac{2 + \sqrt{2}}{4}$, or about 85.36%. Let's see why this is the case. - -First, consider the outcome if Alice and Bob simply measure their qubits in the Z basis without manipulating them at all. Because of the entanglement inherent to the Bell state they hold, their measurements will always agree (i.e., both true or both false). -This will suffice for victory in the three scenarios (0,0), (0,1) and (1,0) and fail for (1,1), so their win probability is 75%, the same as that for the straightforward classical strategies of invariably returning both true or both false. - -Now let's analyze the optimal quantum strategy. - -> As a reminder, probability "wavefunction" for a two-qubit state is given by the following length-4 vector of amplitudes: -> $$\begin{bmatrix}\psi_{00}\\\psi_{01}\\\psi_{10}\\\psi_{11}\end{bmatrix}$$ -> $|\psi_{ij}|^2$ gives the probability of observing the corresponding basis state $|ij\rangle$ upon measuring the qubit pair. - -The initial state $|00\rangle$ has $\psi_{00} = 1$ and $\psi_{01} = \psi_{10} = \psi_{11} = 0$. -The Bell state we prepare as the first step of the game has an amplitude vector as follows (we'll use decimal approximations for matrix elements): - -$$\begin{bmatrix}1/\sqrt{2}\\0\\0\\1/\sqrt{2}\end{bmatrix} = \begin{bmatrix}0.7071\\0\\0\\0.7071\end{bmatrix}$$ - -Let's analyze the probabilities of outcomes in case of different bits received by players. - -## Case 1: Alice holds bit 0 - -In this case Alice simply measures in the Z basis as above. - -- When Bob's bit is 0, he rotates his qubit clockwise by $\pi/8$, which corresponds to the operator - -$$\begin{bmatrix} - 0.9239 & 0.3827 & 0 & 0\\ - -0.3827 & 0.9239 & 0 & 0\\ - 0 & 0 & 0.9239 & 0.3827\\ - 0 & 0 & -0.3827 & 0.9239 -\end{bmatrix}$$ -This performs the $R_y$ rotation by $\pi/8$ radians clockwise on Bob's qubit while leaving Alice's qubit unchanged. - -- If Bob's bit were 1, he would rotate his qubit counterclockwise by $\pi/8$, applying a very similar operator - -$$\begin{bmatrix} - 0.9239 & -0.3827 & 0 & 0\\ - 0.3827 & 0.9239 & 0 & 0\\ - 0 & 0 & 0.9239 & -0.3827\\ - 0 & 0 & 0.3827 & 0.9239 -\end{bmatrix}$$ - -Therefore, when Alice has bit 0, the application of the rotation operator to the Bell state gives -$$\begin{bmatrix} - 0.6533 \\ - -0.2706 \\ - 0.2706 \\ - 0.6533 -\end{bmatrix} \text{ or } -\begin{bmatrix} - 0.6533\\ - 0.2706\\ - -0.2706\\ - 0.6533 -\end{bmatrix}$$ -depending on whether Bob holds 0 (left-hand case) or 1 (right-hand case). - -The result of AND on their input bits will always be 0; thus they win when their outputs agree. These two cases correspond to the top and bottom elements of the vectors above, with a combined probability of $(0.6533)^2 + (0.6533)^2 = 0.4268 + 0.4268 = 0.8536$, so they have an 85.36% win chance. - -## Case 2: Alice holds bit 1 - -When Alice holds bit 1, she measures in basis X (or, equivalently, Hadamard-transforms her qubit, leaving Bob's be, before making her Z-basis measurement). This corresponds to applying the operator -$$\begin{bmatrix} - 0.7071 & 0 & 0.7071 & 0\\ - 0 & 0.7071 & 0 & 0.7071\\ - 0.7071 & 0 & -0.7071 & 0\\ - 0 & 0.7071 & 0 & -0.7071 -\end{bmatrix}$$ -to the Bell state, resulting in a vector of: -$$\begin{bmatrix} - 0.5\\ - 0.5\\ - 0.5\\ - -0.5 -\end{bmatrix}$$ - -Now, one of the two rotation operators is applied depending on what bit Bob holds, transforming this vector into: -$$\begin{bmatrix} - 0.6533 \\ - 0.2706 \\ - 0.2706 \\ - -0.6533 -\end{bmatrix} \text{ or } -\begin{bmatrix} - 0.2706\\ - 0.6533\\ - 0.6533\\ - -0.2706 - \end{bmatrix}$$ - -When Bob holds 0, they still want to return the same parity, which they again do with 85.36% probability (left-hand vector above). -But when Bob holds 1, the AND condition is now true and the players want to answer in opposite parity. This corresponds to the second and third elements of the right-hand vector above. -Thanks to the "magic" of the combination of the counterclockwise rotation and Hadamard transform, they now do this with probability $(0.6533)^2 + (0.6533)^2 = 0.8536$ and thus 85.36% becomes their win odds once more. - -## Side notes - -- If Bob never rotated his qubit, their entangled state would remain the Bell state if Alice held bit 0 and the state corresponding to $\frac12 \big(|00\rangle + |01\rangle + |10\rangle - |11\rangle\big)$ if Alice held bit 1. - -While she and Bob would have a 100% success probability against Alice's 0 bit, they would have only a 50% chance of success if she held bit 1, and thus their win chance would revert to the 75% of the classical strategy again. -- It can be proven that Alice and Bob cannot surpass an overall win probability of 85.36% in the CHSH game. This entails a higher-level discussion of quantum observable theory, for instance see [Tsirelson's bound](https://en.wikipedia.org/wiki/Tsirelson's_bound). - -@[section]({ - "id": "nonlocal_games__chsh_e2e", - "title": "Running CHSH Game End to End" -}) - -Putting together the building blocks we've implemented into a strategy is very simple: -- Allocate two qubits and prepare a Bell state on them. -- Send one of the qubits to Alice and another to Bob (this step is "virtual", not directly reflected in Q# code, other than making sure that Alice and Bob each act on their qubit only). -- Have Alice and Bob perform their measurements on their respective qubits using `AliceQuantum` and `BobQuantum` operations. -- Release(reset) used qubits -- Return their measurement results. - -In the example below you can compare classical and quantum results: first boolean value indicates win for classical Alice and Bob, second boolean is win for quantum Alice and Bob. -You may play with the code and check if there is a difference in results when -1. referee picks non-random bits -2. Bob's qubit is measured first -3. Alice and Bob get not entangled qubit pair - -@[example]({"id": "nonlocal_games__chsh_e2edemo", "codePath": "./examples/CHSHGameDemo.qs"}) - @[section]({ "id": "nonlocal_games__ghz_game", "title": "GHZ Game" @@ -195,8 +58,9 @@ You may play with the code and check if there is a difference in results when In **GHZ Game** three players (Alice, Bob and Charlie) try to win the following game: -Each of them is given a bit (r, s and t respectively), and they have to return new bits (a, b and c respectively) so -that r ∨ s ∨ t = a ⊕ b ⊕ c. The input bits will have zero or two bits set to true and three or one bits set to false. +Each of them is given a bit (r, s and t respectively), and they have to return new bits (a, b and c respectively) +so that **r ∨ s ∨ t = a ⊕ b ⊕ c**. +The input bits will have zero or two bits set to true and three or one bits set to false. The players are free to share information (and even qubits!) before the game starts, but are forbidden from communicating with each other afterwards. @@ -218,6 +82,12 @@ Then, let's proceed with quantum strategy and game implementation. "path": "./ghz_classical_strategy/" }) +@[exercise]({ + "id": "nonlocal_games__ghz_classical_game", + "title": "Classical GHZ Game", + "path": "./ghz_classical_game/" +}) + @[section]({ "id": "nonlocal_games__conclusion", "title": "Conclusion" From 3fc40567816ab2517f7fa5da3f531032a03c3525 Mon Sep 17 00:00:00 2001 From: Gregory Gridin Date: Tue, 23 Jul 2024 21:08:41 -0700 Subject: [PATCH 03/13] Add EOFs --- katas/content/nonlocal_games/ghz_classical_strategy/Solution.qs | 1 + katas/content/nonlocal_games/index.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/Solution.qs b/katas/content/nonlocal_games/ghz_classical_strategy/Solution.qs index 442f440bab..79b5fcf626 100644 --- a/katas/content/nonlocal_games/ghz_classical_strategy/Solution.qs +++ b/katas/content/nonlocal_games/ghz_classical_strategy/Solution.qs @@ -11,3 +11,4 @@ namespace Kata { return true; } } + diff --git a/katas/content/nonlocal_games/index.md b/katas/content/nonlocal_games/index.md index a475f29917..40050e23ec 100644 --- a/katas/content/nonlocal_games/index.md +++ b/katas/content/nonlocal_games/index.md @@ -93,4 +93,4 @@ Then, let's proceed with quantum strategy and game implementation. "title": "Conclusion" }) -Congratulations! In this kata you learned how to use quantum entanglement in nonlocal quantum games to get results that are better than any classical strategy can offer. \ No newline at end of file +Congratulations! In this kata you learned how to use quantum entanglement in nonlocal quantum games to get results that are better than any classical strategy can offer. From 39f9930932711c92e7e6f957abc5ec3b02eebcf1 Mon Sep 17 00:00:00 2001 From: Gregory Gridin Date: Tue, 23 Jul 2024 21:14:17 -0700 Subject: [PATCH 04/13] Adding temp changes --- katas/content/nonlocal_games/index.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/katas/content/nonlocal_games/index.md b/katas/content/nonlocal_games/index.md index 40050e23ec..278023833a 100644 --- a/katas/content/nonlocal_games/index.md +++ b/katas/content/nonlocal_games/index.md @@ -12,13 +12,11 @@ so they cannot communicate with each other during the game. Another characteristics of these games is that they are "refereed", which means the players try to win against the referee. **This kata covers the following topics:** - - Clauser, Horne, Shimony, and Hold thought experiment (often abbreviated as CHSH game) - Greenberger-Horne-Zeilinger game (often abbreviated as GHZ game) - The Mermin-Peres Magic Square game **What you should know to start working on this kata:** - - Basic linear algebra - Basic knowledge of quantum gates and measurements @@ -33,11 +31,15 @@ Each of them is given a bit (Alice gets X and Bob gets Y), and they have to return new bits (Alice returns A and Bob returns B) so that X ∧ Y = A ⊕ B. The trick is, they can not communicate during the game. -> - ∧ is the standard bitwise AND operator. -> - ⊕ is the exclusive or, or XOR operator, so (P ⊕ Q) is true if exactly one of P and Q is true. +> * ∧ is the standard bitwise AND operator. +> * ⊕ is the exclusive or, or XOR operator, so (P ⊕ Q) is true if exactly one of P and Q is true. + +@[section]({ + "id": "nonlocal_games__chsh_game_classical", + "title": "Part I. Classical CHSH" +}) To start with, let's take a look at how you would play the classical variant of this game without access to any quantum tools. -Then, let's proceed with quantum strategies for Alice and Bob. @[exercise]({ "id": "nonlocal_games__chsh_classical_win_condition", From 3efc6f885064a4dbbaa101290e2e837afb1dbe28 Mon Sep 17 00:00:00 2001 From: Gregory Gridin Date: Tue, 23 Jul 2024 21:15:14 -0700 Subject: [PATCH 05/13] Adding temp changes 2 --- katas/content/nonlocal_games/index.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/katas/content/nonlocal_games/index.md b/katas/content/nonlocal_games/index.md index 278023833a..3de33d40e0 100644 --- a/katas/content/nonlocal_games/index.md +++ b/katas/content/nonlocal_games/index.md @@ -12,13 +12,13 @@ so they cannot communicate with each other during the game. Another characteristics of these games is that they are "refereed", which means the players try to win against the referee. **This kata covers the following topics:** -- Clauser, Horne, Shimony, and Hold thought experiment (often abbreviated as CHSH game) -- Greenberger-Horne-Zeilinger game (often abbreviated as GHZ game) -- The Mermin-Peres Magic Square game + - Clauser, Horne, Shimony, and Hold thought experiment (often abbreviated as CHSH game) + - Greenberger-Horne-Zeilinger game (often abbreviated as GHZ game) + - The Mermin-Peres Magic Square game **What you should know to start working on this kata:** -- Basic linear algebra -- Basic knowledge of quantum gates and measurements + - Basic linear algebra + - Basic knowledge of quantum gates and measurements @[section]({ "id": "nonlocal_games__chsh_game", From 9e8c94356884137eb5e6f9e1390e92b2a4726e53 Mon Sep 17 00:00:00 2001 From: Gregory Gridin Date: Mon, 29 Jul 2024 16:59:39 -0700 Subject: [PATCH 06/13] Address code review comments from parallel PR --- .../nonlocal_games/ghz_classical_game/Placeholder.qs | 4 ++-- .../content/nonlocal_games/ghz_classical_game/Solution.qs | 4 ---- .../nonlocal_games/ghz_classical_game/Verification.qs | 4 ---- katas/content/nonlocal_games/ghz_classical_game/index.md | 2 +- .../content/nonlocal_games/ghz_classical_game/solution.md | 1 - .../nonlocal_games/ghz_classical_strategy/Verification.qs | 3 +-- .../nonlocal_games/ghz_classical_strategy/index.md | 8 +++++--- .../nonlocal_games/ghz_classical_strategy/solution.md | 2 +- katas/content/nonlocal_games/ghz_win_condition/index.md | 7 ++++--- .../content/nonlocal_games/ghz_win_condition/solution.md | 4 ++-- 10 files changed, 16 insertions(+), 23 deletions(-) diff --git a/katas/content/nonlocal_games/ghz_classical_game/Placeholder.qs b/katas/content/nonlocal_games/ghz_classical_game/Placeholder.qs index cb3e69967f..1f596eec20 100644 --- a/katas/content/nonlocal_games/ghz_classical_game/Placeholder.qs +++ b/katas/content/nonlocal_games/ghz_classical_game/Placeholder.qs @@ -1,7 +1,7 @@ namespace Kata { - operation PlayClassicalGHZ (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] { // Implement your solution here... - return []; + + return []; } } diff --git a/katas/content/nonlocal_games/ghz_classical_game/Solution.qs b/katas/content/nonlocal_games/ghz_classical_game/Solution.qs index 11e2d417d1..91929343b3 100644 --- a/katas/content/nonlocal_games/ghz_classical_game/Solution.qs +++ b/katas/content/nonlocal_games/ghz_classical_game/Solution.qs @@ -1,10 +1,6 @@ namespace Kata { // 3 players, each player has own strategy and receives a bit from the referee operation PlayClassicalGHZ (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] { - - if Length(strategies) != 3 or Length(inputs) != 3 { - return []; - } let r = inputs[0]; let s = inputs[1]; let t = inputs[2]; diff --git a/katas/content/nonlocal_games/ghz_classical_game/Verification.qs b/katas/content/nonlocal_games/ghz_classical_game/Verification.qs index 2abc2e3d35..50cd482431 100644 --- a/katas/content/nonlocal_games/ghz_classical_game/Verification.qs +++ b/katas/content/nonlocal_games/ghz_classical_game/Verification.qs @@ -14,10 +14,6 @@ namespace Kata.Verification { } operation PlayClassicalGHZ_Reference (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] { - - if Length(strategies) != 3 or Length(inputs) != 3 { - return []; - } let r = inputs[0]; let s = inputs[1]; let t = inputs[2]; diff --git a/katas/content/nonlocal_games/ghz_classical_game/index.md b/katas/content/nonlocal_games/ghz_classical_game/index.md index e52a0fd8ab..4131b03f6d 100644 --- a/katas/content/nonlocal_games/ghz_classical_game/index.md +++ b/katas/content/nonlocal_games/ghz_classical_game/index.md @@ -3,6 +3,6 @@ 1. An operations which implement classical strategies (i.e., takes an input bit and produces an output bit), 2. An array of 3 input bits that should be passed to the players. -**Output:** +**Goal:** An array of 3 bits that will be produced if each player uses this strategy. diff --git a/katas/content/nonlocal_games/ghz_classical_game/solution.md b/katas/content/nonlocal_games/ghz_classical_game/solution.md index 42937ae9bb..f07412d9cf 100644 --- a/katas/content/nonlocal_games/ghz_classical_game/solution.md +++ b/katas/content/nonlocal_games/ghz_classical_game/solution.md @@ -1,6 +1,5 @@ You are given both the input bits and the strategy each of the players are using, so you have simply to convert them to the output bits and return those. - @[solution]({ "id": "nonlocal_games__ghz_classical_game_solution", "codePath": "Solution.qs" diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/Verification.qs b/katas/content/nonlocal_games/ghz_classical_strategy/Verification.qs index c594f6949e..d2dc43a4a1 100644 --- a/katas/content/nonlocal_games/ghz_classical_strategy/Verification.qs +++ b/katas/content/nonlocal_games/ghz_classical_strategy/Verification.qs @@ -18,7 +18,6 @@ namespace Kata.Verification { } operation PlayClassicalGHZ_Reference (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] { - if Length(strategies) != 3 or Length(inputs) != 3 { return []; } @@ -50,7 +49,7 @@ namespace Kata.Verification { if wins < iterations*Length(inputs)*3/4 { Message("Alice, Bob, and Charlie's classical strategy is not optimal"); return false; - } + } Message("Correct!"); true } diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/index.md b/katas/content/nonlocal_games/ghz_classical_strategy/index.md index 7a9d44045e..7b5f004242 100644 --- a/katas/content/nonlocal_games/ghz_classical_strategy/index.md +++ b/katas/content/nonlocal_games/ghz_classical_strategy/index.md @@ -1,9 +1,11 @@ In this task you have to implement three functions, one for each player's classical strategy. Note that they are covered by one test, so you have to implement all of them to pass the test. -For non-deterministic strategies, DrawRandomBoolean or [DrawRandomInt](https://learn.microsoft.com/en-us/qsharp/api/qsharp-lang/microsoft.quantum.random/drawrandomint) functions from Q# library can be used. +For non-deterministic strategies, DrawRandomBoolean or [DrawRandomInt](https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.random/drawrandomint) functions from Q# library can be used. + +**Inputs:** -**Input:** Alice, Bob, and Charlie's starting bits (X, Y, and Z). -**Output:** +**Goal:** + Alice, Bob, and Charlie's output bits (A, B, and C) to maximize their chance of winning. diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/solution.md b/katas/content/nonlocal_games/ghz_classical_strategy/solution.md index a9952ac3d4..1b44cdda62 100644 --- a/katas/content/nonlocal_games/ghz_classical_strategy/solution.md +++ b/katas/content/nonlocal_games/ghz_classical_strategy/solution.md @@ -3,7 +3,7 @@ This will win against inputs 011, 101, and 110 and lose against 000. Another solution is one player retuns TRUE, and two others return FALSE. Since the four above inputs have equal probability, and represent all possible inputs, -this deterministic strategy wins with 75% probability. +this deterministic strategy wins with $75\%$ probability. @[solution]({ "id": "nonlocal_games__ghz_classical_strategy_solution", diff --git a/katas/content/nonlocal_games/ghz_win_condition/index.md b/katas/content/nonlocal_games/ghz_win_condition/index.md index 9639a451a0..59021d3a1a 100644 --- a/katas/content/nonlocal_games/ghz_win_condition/index.md +++ b/katas/content/nonlocal_games/ghz_win_condition/index.md @@ -1,8 +1,9 @@ **Inputs:** -1. Alice, Bob and Charlie's input bits (r, s and t), stored as an array of length 3, +1. Alice, Bob and Charlie's input bits (r, s and t), stored as an array of length 3. + The input bits will have zero or two bits set to true. 2. Alice, Bob and Charlie's output bits (a, b and c), stored as an array of length 3. -The input bits will have zero or two bits set to true. -**Output:** +**Goal:** + True if Alice, Bob and Charlie won the GHZ game, that is, if r ∨ s ∨ t = a ⊕ b ⊕ c, and false otherwise. diff --git a/katas/content/nonlocal_games/ghz_win_condition/solution.md b/katas/content/nonlocal_games/ghz_win_condition/solution.md index 3b2957acc4..370421033e 100644 --- a/katas/content/nonlocal_games/ghz_win_condition/solution.md +++ b/katas/content/nonlocal_games/ghz_win_condition/solution.md @@ -1,7 +1,7 @@ -There are four inputs possible, (0,0,0), (0,1,1), (1,0,1), and (1,1,0), each with 25% probability. +There are four inputs possible, (0,0,0), (0,1,1), (1,0,1), and (1,1,0), each with $25\%$ probability. Therefore, in order to win, the sum of the output bits has to be even if the input is (0,0,0) and odd otherwise. -To check whether the win condition holds, you need to compute the expressions $r \vee s \vee t$ and $a \oplus b \oplus c$ and to compare them: if they are equal, the game is won. To compute the expressions, you can use [built-in operators](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions) and logical function `Xor` from the [`Microsoft.Quantum.Logical`](https://learn.microsoft.com/en-us/qsharp/api/qsharp-lang/microsoft.quantum.logical/xor) library. +To check whether the win condition holds, you need to compute the expressions $r \vee s \vee t$ and $a \oplus b \oplus c$ and to compare them: if they are equal, the game is won. To compute the expressions, you can use [built-in operators](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions) and logical function `Xor` from the [`Microsoft.Quantum.Logical`](https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.logical/xor) library. @[solution]({ "id": "nonlocal_games__ghz_win_condition_solution", From aac58527f6acf86480a12169e34b2f8f26caf1bc Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Sat, 3 Aug 2024 16:25:46 -0700 Subject: [PATCH 07/13] Update katas/content/nonlocal_games/ghz_classical_strategy/solution.md Co-authored-by: Mariia Mykhailova --- katas/content/nonlocal_games/ghz_classical_strategy/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/solution.md b/katas/content/nonlocal_games/ghz_classical_strategy/solution.md index 1b44cdda62..61770244b2 100644 --- a/katas/content/nonlocal_games/ghz_classical_strategy/solution.md +++ b/katas/content/nonlocal_games/ghz_classical_strategy/solution.md @@ -3,7 +3,7 @@ This will win against inputs 011, 101, and 110 and lose against 000. Another solution is one player retuns TRUE, and two others return FALSE. Since the four above inputs have equal probability, and represent all possible inputs, -this deterministic strategy wins with $75\%$ probability. +either of these deterministic strategies wins with $75\%$ probability. @[solution]({ "id": "nonlocal_games__ghz_classical_strategy_solution", From 0a6d2e4f946a4bfc5b0a641d75b6568adbc8ca77 Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Sat, 3 Aug 2024 16:26:17 -0700 Subject: [PATCH 08/13] Update katas/content/nonlocal_games/ghz_classical_game/index.md Co-authored-by: Mariia Mykhailova --- katas/content/nonlocal_games/ghz_classical_game/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/katas/content/nonlocal_games/ghz_classical_game/index.md b/katas/content/nonlocal_games/ghz_classical_game/index.md index 4131b03f6d..3dc6c0471d 100644 --- a/katas/content/nonlocal_games/ghz_classical_game/index.md +++ b/katas/content/nonlocal_games/ghz_classical_game/index.md @@ -1,6 +1,6 @@ **Inputs:** -1. An operations which implement classical strategies (i.e., takes an input bit and produces an output bit), +1. An array of three operations which implement the classical strategies of the players (that is, take an input bit and produce an output bit), 2. An array of 3 input bits that should be passed to the players. **Goal:** From 3e44e186bae433fd9ffd2a4298de06d190b7912e Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Sat, 3 Aug 2024 16:26:34 -0700 Subject: [PATCH 09/13] Update katas/content/nonlocal_games/ghz_classical_game/index.md Co-authored-by: Mariia Mykhailova --- katas/content/nonlocal_games/ghz_classical_game/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/katas/content/nonlocal_games/ghz_classical_game/index.md b/katas/content/nonlocal_games/ghz_classical_game/index.md index 3dc6c0471d..eaaceab984 100644 --- a/katas/content/nonlocal_games/ghz_classical_game/index.md +++ b/katas/content/nonlocal_games/ghz_classical_game/index.md @@ -3,6 +3,6 @@ 1. An array of three operations which implement the classical strategies of the players (that is, take an input bit and produce an output bit), 2. An array of 3 input bits that should be passed to the players. -**Goal:** +**Output:** An array of 3 bits that will be produced if each player uses this strategy. From 1813305ef54c66d6963cc0794dd4444ba8836d7b Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Sat, 3 Aug 2024 16:26:54 -0700 Subject: [PATCH 10/13] Update katas/content/nonlocal_games/ghz_classical_game/Solution.qs Co-authored-by: Mariia Mykhailova --- katas/content/nonlocal_games/ghz_classical_game/Solution.qs | 1 - 1 file changed, 1 deletion(-) diff --git a/katas/content/nonlocal_games/ghz_classical_game/Solution.qs b/katas/content/nonlocal_games/ghz_classical_game/Solution.qs index 91929343b3..64a843554c 100644 --- a/katas/content/nonlocal_games/ghz_classical_game/Solution.qs +++ b/katas/content/nonlocal_games/ghz_classical_game/Solution.qs @@ -1,5 +1,4 @@ namespace Kata { - // 3 players, each player has own strategy and receives a bit from the referee operation PlayClassicalGHZ (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] { let r = inputs[0]; let s = inputs[1]; From 8297fb44684121ec903432f571b9d730dea05f16 Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:11:57 -0700 Subject: [PATCH 11/13] Update katas/content/nonlocal_games/ghz_classical_game/index.md Co-authored-by: Mariia Mykhailova --- katas/content/nonlocal_games/ghz_classical_game/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/katas/content/nonlocal_games/ghz_classical_game/index.md b/katas/content/nonlocal_games/ghz_classical_game/index.md index eaaceab984..33b9fef212 100644 --- a/katas/content/nonlocal_games/ghz_classical_game/index.md +++ b/katas/content/nonlocal_games/ghz_classical_game/index.md @@ -5,4 +5,4 @@ **Output:** -An array of 3 bits that will be produced if each player uses this strategy. +An array of three bits that will be produced if each player uses their given strategy. From 586821b146ef2456cf92df9a4e38f05602707895 Mon Sep 17 00:00:00 2001 From: Gregory Gridin Date: Sun, 4 Aug 2024 15:13:13 -0700 Subject: [PATCH 12/13] Address code review comments --- .../chsh_classical_strategy/solution.md | 4 ++-- .../chsh_classical_win_condition/index.md | 4 ++-- .../chsh_classical_win_condition/solution.md | 7 +++++-- .../ghz_classical_strategy/Placeholder.qs | 6 +++--- .../ghz_classical_strategy/Solution.qs | 6 +++--- .../ghz_classical_strategy/Verification.qs | 11 ++++------- .../nonlocal_games/ghz_classical_strategy/index.md | 6 +++--- .../ghz_classical_strategy/solution.md | 2 +- .../nonlocal_games/ghz_win_condition/Solution.qs | 4 +--- .../ghz_win_condition/Verification.qs | 3 +-- .../nonlocal_games/ghz_win_condition/index.md | 2 +- .../nonlocal_games/ghz_win_condition/solution.md | 4 +++- katas/content/nonlocal_games/index.md | 14 +++++++------- 13 files changed, 36 insertions(+), 37 deletions(-) diff --git a/katas/content/nonlocal_games/chsh_classical_strategy/solution.md b/katas/content/nonlocal_games/chsh_classical_strategy/solution.md index fb22c98290..f21b32b6d4 100644 --- a/katas/content/nonlocal_games/chsh_classical_strategy/solution.md +++ b/katas/content/nonlocal_games/chsh_classical_strategy/solution.md @@ -1,5 +1,5 @@ -If Alice and Bob always return TRUE, they will have a 75% win rate, since TRUE ⊕ TRUE = FALSE, and the AND operation on their input bits will be FALSE with 75% probability. -Alternatively, Alice and Bob could agree to always return FALSE to achieve the same 75% win probability. A classical strategy cannot achieve a higher success probability. +If Alice and Bob always return TRUE, they will have a $75\%$ win rate, since TRUE $\oplus$ TRUE == FALSE, and the AND operation on their input bits will be FALSE with $75\%$ probability. +Alternatively, Alice and Bob could agree to always return FALSE to achieve the same $75\%$ win probability. A classical strategy cannot achieve a higher success probability. @[solution]({ "id": "nonlocal_games__chsh_classical_strategy_solution", diff --git a/katas/content/nonlocal_games/chsh_classical_win_condition/index.md b/katas/content/nonlocal_games/chsh_classical_win_condition/index.md index bacc59426d..018b6056e3 100644 --- a/katas/content/nonlocal_games/chsh_classical_win_condition/index.md +++ b/katas/content/nonlocal_games/chsh_classical_win_condition/index.md @@ -1,8 +1,8 @@ -**Input:** +**Inputs:** - Alice and Bob's starting bits (X and Y). - Alice and Bob's output bits (A and B). **Output:** - True if Alice and Bob won the CHSH game, that is, if X ∧ Y = A ⊕ B, and false otherwise. + True if Alice and Bob won the CHSH game, that is, if X $\land$ Y = A $\oplus$ B, and false otherwise. diff --git a/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md b/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md index f80b0552ae..708820e27d 100644 --- a/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md +++ b/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md @@ -1,7 +1,10 @@ -There are four input pairs (X, Y) possible, (0,0), (0,1), (1,0), and (1,1), each with 25% probability. +There are four input pairs (X, Y) possible, (0,0), (0,1), (1,0), and (1,1), each with $25\%$ probability. In order to win, Alice and Bob have to output different bits if the input is (1,1), and same bits otherwise. -To check whether the win condition holds, you need to compute $x ∧ y$ and $a ⊕ b$ and to compare these values: if they are equal, Alice and Bob won. You can compute these values using [built-in operators](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions): $x ∧ y$ as `x and y` and $a ⊕ b$ as `a != b`. +To check whether the win condition holds, you need to compute X $\land$ Y and A $\oplus$ B and to compare these values: +if they are equal, Alice and Bob won. You can compute these values using +[built-in operators](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions): +X $\land$ Y as `x and y` and A $\oplus$ B as `a != b`. @[solution]({ diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/Placeholder.qs b/katas/content/nonlocal_games/ghz_classical_strategy/Placeholder.qs index 1e1ee33f51..117253509b 100644 --- a/katas/content/nonlocal_games/ghz_classical_strategy/Placeholder.qs +++ b/katas/content/nonlocal_games/ghz_classical_strategy/Placeholder.qs @@ -1,17 +1,17 @@ namespace Kata { - operation AliceClassical (x : Bool) : Bool { + operation AliceClassical (r : Bool) : Bool { // Implement your solution here... return false; } - operation BobClassical (y : Bool) : Bool { + operation BobClassical (s : Bool) : Bool { // Implement your solution here... return false; } - operation CharlieClassical (z : Bool) : Bool { + operation CharlieClassical (t : Bool) : Bool { // Implement your solution here... return false; diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/Solution.qs b/katas/content/nonlocal_games/ghz_classical_strategy/Solution.qs index 79b5fcf626..0418ec4aa2 100644 --- a/katas/content/nonlocal_games/ghz_classical_strategy/Solution.qs +++ b/katas/content/nonlocal_games/ghz_classical_strategy/Solution.qs @@ -1,13 +1,13 @@ namespace Kata { - operation AliceClassical (x : Bool) : Bool { + operation AliceClassical (r : Bool) : Bool { return true; } - operation BobClassical (y : Bool) : Bool { + operation BobClassical (s : Bool) : Bool { return true; } - operation CharlieClassical (z : Bool) : Bool { + operation CharlieClassical (t : Bool) : Bool { return true; } } diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/Verification.qs b/katas/content/nonlocal_games/ghz_classical_strategy/Verification.qs index d2dc43a4a1..853abaa47a 100644 --- a/katas/content/nonlocal_games/ghz_classical_strategy/Verification.qs +++ b/katas/content/nonlocal_games/ghz_classical_strategy/Verification.qs @@ -5,7 +5,7 @@ namespace Kata.Verification { open Microsoft.Quantum.Random; function WinCondition_Reference (rst : Bool[], abc : Bool[]) : Bool { - return (rst[0] or rst[1] or rst[2]) == Xor(Xor(abc[0], abc[1]), abc[2]); + return (rst[0] or rst[1] or rst[2]) == (abc[0] != abc[1] != abc[2]); } // All possible starting bits (r, s and t) that the referee can give @@ -18,9 +18,6 @@ namespace Kata.Verification { } operation PlayClassicalGHZ_Reference (strategies : (Bool => Bool)[], inputs : Bool[]) : Bool[] { - if Length(strategies) != 3 or Length(inputs) != 3 { - return []; - } let r = inputs[0]; let s = inputs[1]; let t = inputs[2]; @@ -35,7 +32,7 @@ namespace Kata.Verification { let inputs = RefereeBits(); let strategies = [Kata.AliceClassical, Kata.BobClassical, Kata.CharlieClassical]; - let iterations = 10000; + let iterations = 1000; mutable wins = 0; for _ in 0 .. iterations - 1 { for bits in inputs { @@ -45,9 +42,9 @@ namespace Kata.Verification { } } } - // The solution is correct if the players win 75% (3/4) of the time. + // The solution is correct if the players win 75% (3/4) of the time. if wins < iterations*Length(inputs)*3/4 { - Message("Alice, Bob, and Charlie's classical strategy is not optimal"); + Message($"Alice, Bob, and Charlie's classical strategy gets {wins} wins out of {iterations*Length(inputs)} possible inputs, which is not optimal"); return false; } Message("Correct!"); diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/index.md b/katas/content/nonlocal_games/ghz_classical_strategy/index.md index 7b5f004242..ef615eba6f 100644 --- a/katas/content/nonlocal_games/ghz_classical_strategy/index.md +++ b/katas/content/nonlocal_games/ghz_classical_strategy/index.md @@ -2,10 +2,10 @@ In this task you have to implement three functions, one for each player's classi Note that they are covered by one test, so you have to implement all of them to pass the test. For non-deterministic strategies, DrawRandomBoolean or [DrawRandomInt](https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.random/drawrandomint) functions from Q# library can be used. -**Inputs:** +**Input:** -Alice, Bob, and Charlie's starting bits (X, Y, and Z). +Alice, Bob, and Charlie's starting bits (R, S, and T). -**Goal:** +**Output:** Alice, Bob, and Charlie's output bits (A, B, and C) to maximize their chance of winning. diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/solution.md b/katas/content/nonlocal_games/ghz_classical_strategy/solution.md index 61770244b2..b5817b8ab6 100644 --- a/katas/content/nonlocal_games/ghz_classical_strategy/solution.md +++ b/katas/content/nonlocal_games/ghz_classical_strategy/solution.md @@ -1,4 +1,4 @@ -If all three players return TRUE, then a ⊕ b ⊕ c = TRUE by necessity (since the sum of their bits is odd). +If all three players return TRUE, then A $\oplus$ B $\oplus$ C == TRUE by necessity (since the sum of their bits is odd). This will win against inputs 011, 101, and 110 and lose against 000. Another solution is one player retuns TRUE, and two others return FALSE. diff --git a/katas/content/nonlocal_games/ghz_win_condition/Solution.qs b/katas/content/nonlocal_games/ghz_win_condition/Solution.qs index 702e7553ff..3b50a7f155 100644 --- a/katas/content/nonlocal_games/ghz_win_condition/Solution.qs +++ b/katas/content/nonlocal_games/ghz_win_condition/Solution.qs @@ -1,7 +1,5 @@ namespace Kata { - open Microsoft.Quantum.Logical; - function WinCondition (rst : Bool[], abc : Bool[]) : Bool { - return (rst[0] or rst[1] or rst[2]) == Xor(Xor(abc[0], abc[1]), abc[2]); + return (rst[0] or rst[1] or rst[2]) == (abc[0] != abc[1] != abc[2]); } } diff --git a/katas/content/nonlocal_games/ghz_win_condition/Verification.qs b/katas/content/nonlocal_games/ghz_win_condition/Verification.qs index 0ef3a94ed7..f4d60d7b4f 100644 --- a/katas/content/nonlocal_games/ghz_win_condition/Verification.qs +++ b/katas/content/nonlocal_games/ghz_win_condition/Verification.qs @@ -1,9 +1,8 @@ namespace Kata.Verification { open Microsoft.Quantum.Convert; - open Microsoft.Quantum.Logical; function WinCondition_Reference (rst : Bool[], abc : Bool[]) : Bool { - return (rst[0] or rst[1] or rst[2]) == Xor(Xor(abc[0], abc[1]), abc[2]); + return (rst[0] or rst[1] or rst[2]) == (abc[0] != abc[1] != abc[2]); } // All possible starting bits (r, s and t) that the referee can give diff --git a/katas/content/nonlocal_games/ghz_win_condition/index.md b/katas/content/nonlocal_games/ghz_win_condition/index.md index 59021d3a1a..f61068ff2e 100644 --- a/katas/content/nonlocal_games/ghz_win_condition/index.md +++ b/katas/content/nonlocal_games/ghz_win_condition/index.md @@ -6,4 +6,4 @@ **Goal:** -True if Alice, Bob and Charlie won the GHZ game, that is, if r ∨ s ∨ t = a ⊕ b ⊕ c, and false otherwise. +True if Alice, Bob and Charlie won the GHZ game, that is, if R $\lor$ S $\lor$ T = A $\oplus$ B $\oplus$ C, and false otherwise. diff --git a/katas/content/nonlocal_games/ghz_win_condition/solution.md b/katas/content/nonlocal_games/ghz_win_condition/solution.md index 370421033e..29524442a7 100644 --- a/katas/content/nonlocal_games/ghz_win_condition/solution.md +++ b/katas/content/nonlocal_games/ghz_win_condition/solution.md @@ -1,7 +1,9 @@ There are four inputs possible, (0,0,0), (0,1,1), (1,0,1), and (1,1,0), each with $25\%$ probability. Therefore, in order to win, the sum of the output bits has to be even if the input is (0,0,0) and odd otherwise. -To check whether the win condition holds, you need to compute the expressions $r \vee s \vee t$ and $a \oplus b \oplus c$ and to compare them: if they are equal, the game is won. To compute the expressions, you can use [built-in operators](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions) and logical function `Xor` from the [`Microsoft.Quantum.Logical`](https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.logical/xor) library. +To check whether the win condition holds, you need to compute the expressions R $\lor$ S $\lor$ T and A $\oplus$ B $\oplus$ C and to compare them: +if they are equal, the game is won. To compute the expressions, you can use [built-in operators](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions): +X $\lor$ Y as `x or y` and A $\oplus$ B as `a != b`. @[solution]({ "id": "nonlocal_games__ghz_win_condition_solution", diff --git a/katas/content/nonlocal_games/index.md b/katas/content/nonlocal_games/index.md index e6f73df7ff..2eb25e8aad 100644 --- a/katas/content/nonlocal_games/index.md +++ b/katas/content/nonlocal_games/index.md @@ -31,10 +31,10 @@ In **CHSH Game**, two players (Alice and Bob) try to win the following game: Each of them is given a bit (Alice gets X and Bob gets Y), and they have to return new bits (Alice returns A and Bob returns B) -so that X ∧ Y = A ⊕ B. The trick is, they can not communicate during the game. +so that X $\land$ Y = A $\oplus$ B. The trick is, they can not communicate during the game. -> - ∧ is the standard bitwise AND operator. -> - ⊕ is the exclusive or, or XOR operator, so (P ⊕ Q) is true if exactly one of P and Q is true. +> - $\land$ is the standard bitwise AND operator. +> - $\oplus$ is the exclusive or, or XOR operator, so (P $\oplus$ Q) is true if exactly one of P and Q is true. To start with, let's take a look at how you would play the classical variant of this game without access to any quantum tools. Then, let's proceed with quantum strategies for Alice and Bob. @@ -196,14 +196,14 @@ In the example below you can compare winning percentage of classical and quantum In **GHZ Game** three players (Alice, Bob and Charlie) try to win the following game: -Each of them is given a bit (r, s and t respectively), and they have to return new bits (a, b and c respectively) -so that **r ∨ s ∨ t = a ⊕ b ⊕ c**. +Each of them is given a bit (R, S and T respectively), and they have to return new bits (A, B and C respectively) so that +R $\lor$ S $\lor$ T = A $\oplus$ B $\oplus$ C. The input bits will have zero or two bits set to true and three or one bits set to false. The players are free to share information (and even qubits!) before the game starts, but are forbidden from communicating with each other afterwards. -- ∨ is the standard bitwise OR operator. -- ⊕ is the exclusive or, or XOR operator, so (P ⊕ Q) is true if exactly one of P and Q is true. +> - $\lor$ is the standard bitwise OR operator. +> - $\oplus$ is the exclusive or, or XOR operator, so (P $\oplus$ Q) is true if exactly one of P and Q is true. To start with, take a look at how you would play the classical variant of this game without access to any quantum tools. Then, let's proceed with quantum strategy and game implementation. From 1a98cf8bfb5d2ce910fd51fe885e34846739b8fd Mon Sep 17 00:00:00 2001 From: Gregory Gridin Date: Sun, 4 Aug 2024 15:33:03 -0700 Subject: [PATCH 13/13] Address code missed code review comment --- katas/content/nonlocal_games/ghz_classical_strategy/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/katas/content/nonlocal_games/ghz_classical_strategy/index.md b/katas/content/nonlocal_games/ghz_classical_strategy/index.md index ef615eba6f..29b2169b6f 100644 --- a/katas/content/nonlocal_games/ghz_classical_strategy/index.md +++ b/katas/content/nonlocal_games/ghz_classical_strategy/index.md @@ -1,6 +1,6 @@ In this task you have to implement three functions, one for each player's classical strategy. Note that they are covered by one test, so you have to implement all of them to pass the test. -For non-deterministic strategies, DrawRandomBoolean or [DrawRandomInt](https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.random/drawrandomint) functions from Q# library can be used. +In each function, the input is the starting bit of the corresponding player, and it should return the output bit chosen by that player. **Input:**