---
title: "CHSH Game"
format:
  html:
    toc: true
    number-sections: true
---

::: {.hidden}
$$
\newcommand{\braket}[2]{\langle{#1}|{#2}\rangle}
$$
:::
[In-class notes](HandWrittenNotes/CHSHClass2.pdf)


## Learning Goals

- Analyze 2-qubit systems
- Show a quantum advantage in game playing

## CHSH Game Set-Up

The CHSH Game is a game played between two players (we'll call them Amir and Bei) and a referee. The two players can strategize before the start of the game, but once the game starts, they are not allowed to communicate. 

The referee sends Amir a bit $x$ and Bei a bit $y$. Then Amir must respond by sending a bit $a$ back to the referee, and likewise Bei responds by sending a bit $b$ back to the referee. Amir and Bei win the game if 
$$a\oplus b = x\wedge y,$$
where $\oplus$ means addition modulo 2, and $\wedge$ is Boolean AND.

::: {.callout-tip appearance="simple"}
### Group Exercise

What is Amir and Bei's best strategy, if the referee chooses $x,y$ randomly (i.e. $xy=00,01,10,11$ are all equally likely)? What is Amir and Bei's likelihood of winning?

:::

Now suppose we give Amir and Bei each a qubit. They are still not allowed to communicate once the game starts. 

So far we have been thinking of qubits as photons, but in this case, we will use diamond *nitrogen vacancy centers* or *NV centers*. The key properties of NV centers are that (unlike photons) they don't move around, they just sit at a particular place in a diamon, and the qubits they form are very stable, lasting ~1sec before decohering.

::: {.callout-note}

(A bit of physics/materials science - feel free to read if interested.) 
An NV center is a created from small piece of manufactured diamond. A diamond is a lattice is made of carbon atoms, but in an NV center there is a defect where a carbon atom gets replaces by a nitrogen atom.
This defect allows for relatively stable electronic states: one with a single unpaired electron, and one with two paired electrons, forming our $\ket{0}$ and $\ket{1}$ states. When there are two paired electrons, it causes photoluminscence when a light is shined on the diamond, but there is no photoluminescence with the single electron. In this way, we can make the measurement $M=\{\ket{0},\ket{1}\}.$
:::


::: {.callout-tip appearance="simple"}

### ABCD Question

If Amir's qubit is in the state $\ket{0}$, and Bei's qubit is in the state $\ket{1}$, how do we represent the combined state of both qubits? 

A) $\ket{0}\otimes\ket{1}$
A) $\ket{0}_A\ket{1}_B$
A) $\ket{01}_{AB}$
A) $\ket{01}$

:::

The $\otimes$ is read as "tensor product" or "tensor" and mathematically denotes the Kronecker product. The subscripts $A$ and $B$ are for clarity and can be dropped if the order is clear. Note that when a bra is followed by a ket, they collapse to form a number, but when a ket is followed by a ket, you just get a bigger ket.



## Mathematically Representing 2 Qubits

Suppose we have two qubits in the following generic individual states

  * Qubit A: $\ket{\psi_1}_A=a_0\ket{0}+a_1\ket{1}$   
  * Qubit B: $\ket{\psi_2}_B=b_0\ket{0}+b_1\ket{1}$

Then their combined state can be written as 
$$
\begin{align}
\ket{\psi}_{AB}=&\ket{\psi_1}_A\otimes \ket{\psi_2}_B& \textrm{stick kets together with }\otimes\textrm{ to combine}\\
=&\ket{\psi_1}_A \ket{\psi_2}_B & \textrm{ $\otimes$ is optional}\\
=&(a_0\ket{0}+a_1\ket{1})_A(b_0\ket{0}+b_1\ket{1})_B&\textrm{substituting single qubit states}\\
=&a_0b_0\ket{0}_A\ket{0}_B+a_0b_1\ket{0}_A\ket{1}_B+a_1b_0\ket{1}_A\ket{0}_B+a_1b_1\ket{1}_A\ket{1}_B&\textrm{Distribute the (hidden) }\otimes\textrm{ product}\\
=&a_0b_0\ket{00}+a_0b_1\ket{01}+a_1b_0\ket{10}+a_1b_1\ket{11}&\textrm{combine the double ket into a single ket with two bits}\\
\end{align}
$$
Note that the terms in the kets are the four possible 2-bit strings. 

### Generic 2-qubit state

Any two-qubit state can be written in the following form (and anything written in the following form  represents a two-qubit state):

$$\ket{\psi}_{AB}=a_{00}\ket{00}+a_{01}\ket{01}+a_{10}\ket{10}+a_{11}\ket{11},\quad \textrm{s.t. }a_i\in \mathbb{C}, \textrm{ and } \sum_{i\in \{0,1\}^2}|a_i|^2=1,$$
where again we call $a_{00},a_{01},a_{10},a_{11}$ amplitudes.

::: {.callout-note}

## Vector Note

A two qubit state can be represented as a  vector in $\mathbb{C}^4$. To do this we write:
$$\ket{\psi}=\left(
\begin{array}{c}
a_{00}\\
a_{01}\\
a_{10}\\
a_{11}
\end{array}\right)
$$
with the amplitudes as the elements of the vector.
::: 


## CHSH Strategy

Before the start of the game, Amir and Bei get together to strategize, and as part of their strategizing, they decide to share a two-qubit state, where Amir has the $A$ qubit and Bei has the $B$ qubit:
$$\ket{\psi}_{AB}=\frac{1}{\sqrt{2}}\left(\ket{00}+\ket{11}\right).$$

They decide they will both each perform a single-qubit measurement of the form $M(\omega)=\{R(\omega),Q(\omega)\}$ on each of their individual qubits, where they will choose $\omega$ depending on the bit that they get from the referee, where
$$
\begin{align}
R(\omega)=&\cos(\omega)\ket{0}+\sin(\omega)\ket{1}\\
Q(\omega)=&-\sin(\omega)\ket{0}+\cos(\omega)\ket{1}.
\end{align}$${#eq-RQdef}
(You can check for extra practice that $R(\omega)$ and $Q(\omega)$ are orthonormal.)

Amir and Bei choose $\omega$ and respond to the referee as follows: 

| Amir receives  |  measurement| response to referee
|-----------------|--------|--------|  
| $x=0$ | $M(0)$ | $R\rightarrow a=0,\quad$ $Q\rightarrow a=1$
| $x=1$ | $M(\pi/4)$ |     $R\rightarrow a=0,\quad$ $Q\rightarrow a=1$


| Bei receives  |  measurement|  response to referee
|-----------------|--------| --------|  
| $y=0$ | $M(\pi/8)$ | $R\rightarrow b=0,\quad$ $Q\rightarrow b=1$
| $y=1$ | $M(-\pi/8)$ |$R\rightarrow b=0,\quad$ $Q\rightarrow b=1$

### Two Single-Qubit Measurements on a Two-Qubit State {#sec-2qubit-meas}

We are now in a situation where we have two qubits, and a different single qubit measurement is being performed on each of those qubits. We will discuss the method to analyze this situation.

Let the initial state of the two qubits be $\ket{\psi}_{AB}$. If the measurement on qubit $A$ is $M_{A}=\{\ket{\phi_{1a}},\ket{\phi_{2a}}\}$, and
the measurement on qubit $B$ is is $M_{B}=\{\ket{\phi_{1b}},\ket{\phi_{2b}}\}$, there are four possible combinations of possible measurement outcomes. For example, the measurement on qubit $A$ could result in outcome $\ket{\phi_{2a}}$, and the measurement on qubit $B$ could get result in $\ket{\phi_{1b}}$, or we could get outcomes $\ket{\phi_{1a}}$ and $\ket{\phi_{1b}}$, etc.

If we get outcome $\ket{\phi_{ia}}$ on qubit $A$ and outcome $\ket{\phi_{ib}}$ on qubit $B$, we write the combined outcome on both qubits as $\ket{\phi_{ia}}_A\otimes\ket{\phi_{jb}}_B=\ket{\phi_{ia}}_A\ket{\phi_{jb}}_B$. 

Then the laws of quantum mechanics tell us that:     

  * the probability of getting outcome $\ket{\phi_{ia}}_A\ket{\phi_{jb}}_B$ is $|(\bra{\phi_{ia}}_A \bra{\phi_{jb}}_B)\ket{\psi}_{AB}|^2$    
  * $\ket{\phi}_{AB}$ collapses to $\ket{\phi_{ia}}_A\ket{\phi_{jb}}_B.$

This is similar to the single qubit case. We take the bra of the measurement outcome of interest and take the inner product between that bra and the ket of our initial state. 

**Important:** When you take the bra of a two-system ket, the $AB$ order stays the same:
$$\textrm{bra of} \ket{\psi}_A\ket{\phi}_B \rightarrow \bra{\psi}_A\bra{\phi}_B.$$


To calculate probabilities, we will also use a generalization of the inner product rule we used before:
$$
\textrm{If }\ket{x},\ket{y} \textrm{ are standard basis states, then} \braket{x}{y}=
\begin{cases}
1 & \textrm{if }x=y\\
0 & \textrm{if } x\neq y
\end{cases}
$$ {#eq-inner-product}
where standard basis states are $\ket{x}$ where $x$ is a bit string, like $00$, $10$, etc.

::: {.callout-note}




## Vector Note

While the bra is the conjugate transpose of the ket in matrix formalism, and when you take the bra of the product of two matrices you normally reverse the order, that is not the case here. While the order of matrices *does* reverse under standard transpose for normal matrix multiplication, for Kronecker product, the order *does not* reverse under transpose.
::: 
 

To understand what these rules mean, it is easiest to look at an example

::: {.callout-tip}


## Example

As discussed earlier, we assume Amir and Bei share the state $\ket{\psi}_{AB}=\frac{1}{\sqrt{2}}\left(\ket{00}+\ket{11}\right).$ If Amir makes measurement $M(\pi/4)$ and Bei makes measurement $M(-\pi/4)$, with what probability do they get outcome $\ket{R(\pi/4)}_A\ket{Q(-\pi/8}_B$?

Following @sec-2qubit-meas, we need to calculate
$$
\begin{align}
&\left|\bra{R(\pi/4)}_A\bra{Q(-\pi/8)}_B\ket{\psi}_{AB}\right|^2 &\\
= &\left|\left(\cos(\pi/4)\bra{0}+\sin(\pi/4)\bra{1}\right)_A(-\sin(-\pi/8)\bra{0}_B+\cos(-\pi/8)\bra{1})_B\right.\\
&\left.\left(\frac{1}{\sqrt{2}}\ket{00}_{AB}+\frac{1}{\sqrt{2}}\ket{11}_{AB}\right)\right|^2 & \textrm{ln 1}\\
 = &\left|\left(\cos(\pi/4)\sin(\pi/8)\bra{00}_{AB}+\cos(\pi/4)\cos(\pi/8)\bra{01}_{AB}\right.\right.\\
 &\left.\left.+\sin(\pi/4)\sin(\pi/8)\bra{10}_{AB}+\sin(\pi/4)\cos(\pi/8)\bra{11}_{AB}\right)\frac{1}{\sqrt{2}}\ket{00}_{AB}+\frac{1}{\sqrt{2}}\ket{11}_{AB}\right|^2& \textrm{ln 2}\\
  = &\left|\frac{1}{\sqrt{2}}\cos(\pi/4)\sin(\pi/8)\braket{00}{00}_{AB}+\frac{1}{\sqrt{2}}\cos(\pi/4)\cos(\pi/8)\braket{01}{00}_{AB}\right.\\
 &+\frac{1}{\sqrt{2}}\sin(\pi/4)\sin(\pi/8)\braket{10}{00}_{AB}+\frac{1}{\sqrt{2}}\sin(\pi/4)\cos(\pi/8)\braket{11}{00}_{AB}\\
 &\frac{1}{\sqrt{2}}\cos(\pi/4)\sin(\pi/8)\braket{00}{11}_{AB}+\frac{1}{\sqrt{2}}\cos(\pi/4)\cos(\pi/8)\braket{01}{11}_{AB}\\
 &\left.+\frac{1}{\sqrt{2}}\sin(\pi/4)\sin(\pi/8)\braket{10}{11}_{AB}+\frac{1}{\sqrt{2}}\sin(\pi/4)\cos(\pi/8)\braket{11}{11}_{AB}\right|^2& \textrm{ln 3}\\
 =&\left|\frac{1}{\sqrt{2}}\cos(\pi/4)\sin(\pi/8)+\frac{1}{\sqrt{2}}\sin(\pi/4)\cos(\pi/8)\right|^2& \textrm{ln 4}\\
  \approx&.426\\
 \end{align}
$$
Where line 1 comes from substituting in the definitions of $\ket{R}$ and $\ket{Q}$ in @eq-RQdef, line 2 comes from distributing the tensor product between $\bra{R}\otimes\bra{Q}$, line 3 comes from distributing the inner product between the bras and kets, and line 4 comes from @eq-inner-product.


:::


::: {.callout-tip appearance="simple"}
### Group Exercise

Fill in the question marks to determine Amir and Bei's probability of success with their new quantum strategy:



+-------------------+-------------------------------------------------------+------------------------+
| Referee's Question| Winning Meas. Outcomes                                | Prob. of each outcome  |
+===================+=======================================================+========================+
| $x=0$, $y=0$      | - **?**                                               | - **?**                |
|$x\wedge y=$ **?** | - **?**                                               | - **?**                |
+-------------------+-------------------------------------------------------+------------------------+
| $x=0$, $y=1$      | - **?**                                               | - **?**                |
|$x\wedge y=$ **?** | - **?**                                               | - **?**                |
+-------------------+-------------------------------------------------------+------------------------+
| $x=1$, $y=1$      | - $\ket{R(\pi/4)}\ket{Q(-\pi/8)}\rightarrow a=0,b=1$  | - .426                 |
|$x\wedge y=1$      | - $\ket{Q(\pi/4)}\ket{R(-\pi/8)}\rightarrow a=1,b=0$  | - .246                 |
+-------------------+-------------------------------------------------------+------------------------+

:::


For all of referees questions, success probability is $\approx .85$ with this strategy! Note that $.85>.75$,
the the quantum strategy can outperform the classical strategy.

You might be thinking that this is a pretty boring game, and wondering whether anyone ever plays this game in real life. It turns out that people do play this game, for two main purposes:

- To verify quantumness (both that our reality is quantum, and that a particular system is quantum)
- To generate genuine randomness. A side effect of winning this with larger than $3/4$ probability is generating quantum randomness. This randomness can be verified as genuinely random by the fact that the game is won with sufficiently high probability. Randomness is important for various algorithms and security protocols. Generally, when we ask a computer to generate a random number, it is only pseudorandom. This means that a bad actor, with sufficient information, could actually predict the random number. However, quantum random numbers can not be predicted, no matter what information you have.