Skip to content

Instantly share code, notes, and snippets.

@csferrie
Created February 22, 2023 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csferrie/3facbbe18f977ace02a78474349b2ead to your computer and use it in GitHub Desktop.
Save csferrie/3facbbe18f977ace02a78474349b2ead to your computer and use it in GitHub Desktop.
Entanglement For The Win
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyNzFJpURBAh2mlX0fzkh9RD",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/csferrie/3facbbe18f977ace02a78474349b2ead/entanglement-for-the-win.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"# Entanglement For The Win\n",
"**Chris Ferrie** \n",
"([csferrie.com](https://www.csferrie.com/), [@csferrie](https://twitter.com/csferrie))\n",
"\n",
"I recently wrote [a piece for Scientific American](https://www.scientificamerican.com/article/quantum-entanglement-isnt-all-that-spooky-after-all/) about how quantum entanglement isn't that \"spooky.\" In it, I outlined a little problem that is solved when thinking about entanglement as correlations. Due to various constraints such as word limits and the fact that they weren't going to let me put math in the article, I alluded to the fact the problem could be solved if you knew a little bit of linear algebra. Well, anyway, I got a lot of messages asking me for that solution. So, here it is.\n"
],
"metadata": {
"id": "qzjhyDwaudQ6"
}
},
{
"cell_type": "markdown",
"source": [
"Imagine two people, Alice and Bob, are implicated in a crime and are being questioned in separate rooms with no way to communicate. The investigators, trying to seem lenient, say they will be set free if they can corroborate each other’s story on more than 75% of questions they are asked.\n",
"\n",
"They have two alibis, Charlie and Diane. Alice and Bob know that they are each going to be asked one of two questions: were you with Charlie? Or, were you with Diane? They also know from an informant, Eve, that the investigators are trying to trap them. Eve has told them that to corroborate each other’s story, they must answer exactly the same if either of them are asked if they were with Charlie, but differently if they are both asked if they were with Diane.\n",
"\n",
"So, Alice and Bob do the obvious thing and devise a strategy so that their answers will be correlated in just the right way. Alice points out that there are four possible question scenarios: Charlie-Charlie, Charlie-Diane, Diane-Charlie, or Diane-Diane. She writes them on a piece of paper as CC, CD, DC, and DD. She goes on to say that there are also four possible answers the pair of them could give to any question: yes-yes, yes-no, no-yes, or no-no. In total, then, there are sixteen possible ways the investigation could play out, and Alice shows a table she has drawn for them to Bob.\n",
"\n",
"$$\n",
"\\begin{array}{c|cccc}\n",
" & CC & CD & DC & DD \\\\ \\hline\n",
" YY & & & & \\\\\n",
" YN & & & & \\\\\n",
" NY & & & & \\\\\n",
" NN & & & & \n",
"\\end{array}\n",
"$$\n",
"\n",
"Bob looks at the table and quickly marks it up with ones and zeros. He tells Alice this the simple strategy they should use — She should always say yes, and he will do the same, except when they are both asked about Diane. \n",
"\n",
"$$\n",
"\\begin{array}{c|cccc}\n",
" & CC & CD & DC & DD \\\\ \\hline\n",
" YY & 1 & 1 & 1 & 0 \\\\\n",
" YN & 0 & 0 & 0 & 1 \\\\\n",
" NY & 0 & 0 & 0 & 0 \\\\\n",
" NN & 0 & 0 & 0 & 0 \n",
"\\end{array}\n",
"$$\n",
"\n",
"Alice shakes her head, reminding Bob that he won’t know what question *she* is asked, and vice versa. Each column in the table has to be the same if they go with a fixed strategy. Bob suggests a random strategy might do the trick. *Each column will list the **probabilities** for the possible answers such that the columns no longer need to be the same.*\n",
"\n",
"\"There are some constrainsts, though,\" Alice says. \"To sort it out, we are going to need some math.\""
],
"metadata": {
"id": "WcCmxZvBl0dE"
}
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {
"id": "5bjbLEq5EdVA"
},
"outputs": [],
"source": [
"# sympy is python package that allows symbolic \n",
"# manipulation. Basically, it does algebra.\n",
"\n",
"from sympy import *\n",
"from sympy.physics.quantum.circuitplot import *\n",
"\n",
"# We have to let sympy know which letters we \n",
"# are going to use as variables. Let's just \n",
"# set a bunch aside for now.\n",
"a, b, c, d, p, q, r, y, x = symbols('a b c d p q r y x', real = True)\n",
"\n",
"# 'real' means these will be interpreted by sympy\n",
"# as real numbers, rather than integers or complex"
]
},
{
"cell_type": "markdown",
"source": [
"Alice tells Bob that her answer to either question reveals one bit of information. This can be represented as vector,\n",
"\n",
"$$\n",
"\\begin{pmatrix}\n",
" p \\\\\n",
" 1-p \n",
"\\end{pmatrix},\n",
"$$\n",
"\n",
"where $p$ is the probability she will say yes and $1-p$ is the probability she will say no. Similary, Bob's answer is represented by a vector,\n",
"\n",
"$$\n",
"\\begin{pmatrix}\n",
" q \\\\\n",
" 1-q \n",
"\\end{pmatrix},\n",
"$$\n",
"\n",
"which might have different probabilities. We need to \"multiply\" these vectors together to get the four probabilities for the pair of answers they might give. Since it is not the usual multiplication of numbers, which using the \"times\" symbol $\\times$, we use a new symbol $\\otimes$. The four dimensional vector is then,"
],
"metadata": {
"id": "fWJJh-51tfAb"
}
},
{
"cell_type": "code",
"source": [
"# First create the two individual vectors\n",
"Alice = Matrix([p, 1-p])\n",
"Bob = Matrix([q, 1-q])\n",
"\n",
"# Then use this function which does the \"otimes\"\n",
"Both = kronecker_product(Alice, Bob)\n",
"\n",
"Both"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 98
},
"id": "rhufhNxLvt-f",
"outputId": "e85a1be0-a0e0-4445-bdca-917ed0a783bb"
},
"execution_count": 71,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Matrix([\n",
"[ p*q],\n",
"[ p*(1 - q)],\n",
"[ q*(1 - p)],\n",
"[(1 - p)*(1 - q)]])"
],
"text/latex": "$\\displaystyle \\left[\\begin{matrix}p q\\\\p \\left(1 - q\\right)\\\\q \\left(1 - p\\right)\\\\\\left(1 - p\\right) \\left(1 - q\\right)\\end{matrix}\\right]$"
},
"metadata": {},
"execution_count": 71
}
]
},
{
"cell_type": "markdown",
"source": [
"Interestingly, there are some vectors, like this one,\n",
"\n",
"$$\n",
"\\begin{pmatrix}\n",
" \\frac12 \\\\\n",
" 0\\\\\n",
" 0\\\\\n",
" \\frac12 \n",
"\\end{pmatrix},\n",
"$$\n",
"\n",
"which you can never write as,\n",
"\n",
"$$\n",
"\\begin{pmatrix}\n",
" \\frac12 \\\\\n",
" 0\\\\\n",
" 0\\\\\n",
" \\frac12 \n",
"\\end{pmatrix} \\neq \\begin{pmatrix}\n",
" p \\\\\n",
" 1-p \n",
"\\end{pmatrix} \\otimes \\begin{pmatrix}\n",
" q \\\\\n",
" 1-q \n",
"\\end{pmatrix},\n",
"$$\n",
"\n",
"for any values of $p$ and $q$. Such vectors represent *correlation* between the bits of Alice and Bob. The vector above, for example, means that Alice and Bob always reveal the same answer, but which one it is is random. In other words, they both say yes or both say no.\n",
"\n",
"Bob suggest they correlate their bits and then change them independently when they hear what question they have. Changing a bit amounts to multiply the vector by a matrix to get a new vector. Bob's idea is to flip the bit (change the answer) with some probability $r$ if they are asked whether they are were with Diane. They will use some clever math to determine what value of $r$ gives them the best success probability.\n",
"\n",
"That matrix changing the vector looks like this:\n",
"\n",
"$$\n",
"R:= \\begin{pmatrix}\n",
" 1-r & r \\\\\n",
" r & 1-r \n",
"\\end{pmatrix}.\n",
"$$\n",
"\n",
"If $r=0$, that means \"do nothing\" and the matrix is,\n",
"\n",
"$$\n",
"I: = \\begin{pmatrix}\n",
" 1 & 0 \\\\\n",
" 0 & 1 \n",
"\\end{pmatrix},\n",
"$$\n",
"often called the *identity* matrix.\n",
"\n",
"If Alice and Bob start with correlated bits as represented by the vector above, and change their own bits if they are asked about Diane then there are four possible matrices than can change that vector:\n",
"\n",
"$$\n",
"I \\otimes I, \\, I \\otimes R,\\, R\\otimes I, \\; \\text{and} \\, R\\otimes R,\n",
"$$\n",
"which look explicitly like\n",
"\n"
],
"metadata": {
"id": "uUYiCwNHt6fZ"
}
},
{
"cell_type": "code",
"source": [
"def R(r):\n",
" return Matrix([[1-r, r],[r, 1-r]])\n",
"\n",
"Id = Matrix([[1,0],[0,1]])\n",
"\n",
"display(kronecker_product(Id,Id))\n",
"display(kronecker_product(Id,R(r)))\n",
"display(kronecker_product(Id,R(r)))\n",
"display(kronecker_product(R(r),R(r)))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 350
},
"id": "rumetIs_Ed8e",
"outputId": "9d2df0f8-9942-4a1a-d512-88643c839181"
},
"execution_count": 72,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"Matrix([\n",
"[1, 0, 0, 0],\n",
"[0, 1, 0, 0],\n",
"[0, 0, 1, 0],\n",
"[0, 0, 0, 1]])"
],
"text/latex": "$\\displaystyle \\left[\\begin{matrix}1 & 0 & 0 & 0\\\\0 & 1 & 0 & 0\\\\0 & 0 & 1 & 0\\\\0 & 0 & 0 & 1\\end{matrix}\\right]$"
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"Matrix([\n",
"[1 - r, r, 0, 0],\n",
"[ r, 1 - r, 0, 0],\n",
"[ 0, 0, 1 - r, r],\n",
"[ 0, 0, r, 1 - r]])"
],
"text/latex": "$\\displaystyle \\left[\\begin{matrix}1 - r & r & 0 & 0\\\\r & 1 - r & 0 & 0\\\\0 & 0 & 1 - r & r\\\\0 & 0 & r & 1 - r\\end{matrix}\\right]$"
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"Matrix([\n",
"[1 - r, r, 0, 0],\n",
"[ r, 1 - r, 0, 0],\n",
"[ 0, 0, 1 - r, r],\n",
"[ 0, 0, r, 1 - r]])"
],
"text/latex": "$\\displaystyle \\left[\\begin{matrix}1 - r & r & 0 & 0\\\\r & 1 - r & 0 & 0\\\\0 & 0 & 1 - r & r\\\\0 & 0 & r & 1 - r\\end{matrix}\\right]$"
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"Matrix([\n",
"[(1 - r)**2, r*(1 - r), r*(1 - r), r**2],\n",
"[ r*(1 - r), (1 - r)**2, r**2, r*(1 - r)],\n",
"[ r*(1 - r), r**2, (1 - r)**2, r*(1 - r)],\n",
"[ r**2, r*(1 - r), r*(1 - r), (1 - r)**2]])"
],
"text/latex": "$\\displaystyle \\left[\\begin{matrix}\\left(1 - r\\right)^{2} & r \\left(1 - r\\right) & r \\left(1 - r\\right) & r^{2}\\\\r \\left(1 - r\\right) & \\left(1 - r\\right)^{2} & r^{2} & r \\left(1 - r\\right)\\\\r \\left(1 - r\\right) & r^{2} & \\left(1 - r\\right)^{2} & r \\left(1 - r\\right)\\\\r^{2} & r \\left(1 - r\\right) & r \\left(1 - r\\right) & \\left(1 - r\\right)^{2}\\end{matrix}\\right]$"
},
"metadata": {}
}
]
},
{
"cell_type": "markdown",
"source": [
"Now, to determine what the probabilities are for each question, these matrices need to be multiplied by the original correlated vector. Then we can put them back into the table."
],
"metadata": {
"id": "XQW2-Jl0_n6Z"
}
},
{
"cell_type": "code",
"source": [
"final_probs = lambda rA, rB: kronecker_product(R(rA),R(rB))*Matrix([Rational(1/2),0,0,Rational(1/2)])\n",
"\n",
"Bobs_strategy = simplify(expand(Matrix([final_probs(0,0).T,\n",
" final_probs(0,r).T,\n",
" final_probs(r,0).T,\n",
" final_probs(r,r).T\n",
" ]))).T\n",
"\n",
"Bobs_strategy"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 98
},
"id": "JQh5Prqs_5CQ",
"outputId": "c6c95a1e-0c89-4ebc-e3ea-7b1f310e9750"
},
"execution_count": 73,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Matrix([\n",
"[1/2, 1/2 - r/2, 1/2 - r/2, r**2 - r + 1/2],\n",
"[ 0, r/2, r/2, r*(1 - r)],\n",
"[ 0, r/2, r/2, r*(1 - r)],\n",
"[1/2, 1/2 - r/2, 1/2 - r/2, r**2 - r + 1/2]])"
],
"text/latex": "$\\displaystyle \\left[\\begin{matrix}\\frac{1}{2} & \\frac{1}{2} - \\frac{r}{2} & \\frac{1}{2} - \\frac{r}{2} & r^{2} - r + \\frac{1}{2}\\\\0 & \\frac{r}{2} & \\frac{r}{2} & r \\left(1 - r\\right)\\\\0 & \\frac{r}{2} & \\frac{r}{2} & r \\left(1 - r\\right)\\\\\\frac{1}{2} & \\frac{1}{2} - \\frac{r}{2} & \\frac{1}{2} - \\frac{r}{2} & r^{2} - r + \\frac{1}{2}\\end{matrix}\\right]$"
},
"metadata": {},
"execution_count": 73
}
]
},
{
"cell_type": "markdown",
"source": [
"Alice shows Bob the calculated matrix and reminds him that this represents the outcome probabilities of their correlated strategy. The success probabilities can be computed by adding up the top and bottom probabilities for the first three columns with the middle two probabilities for the last column, then dividing that number by four."
],
"metadata": {
"id": "Tm3EfCPdBC1s"
}
},
{
"cell_type": "code",
"source": [
"def success(strat_matrix):\n",
" return (strat_matrix[0,0]+strat_matrix[3,0]+\n",
" strat_matrix[0,1]+strat_matrix[3,1]+\n",
" strat_matrix[0,2]+strat_matrix[3,2]+\n",
" strat_matrix[1,3]+strat_matrix[2,3])/4\n",
"\n",
"simplify(success(Bobs_strategy))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 54
},
"id": "qAJ5hCq0BfZi",
"outputId": "98fd0c5c-42c5-4578-a921-a6f24eea15fc"
},
"execution_count": 74,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"3/4 - r**2/2"
],
"text/latex": "$\\displaystyle \\frac{3}{4} - \\frac{r^{2}}{2}$"
},
"metadata": {},
"execution_count": 74
}
]
},
{
"cell_type": "markdown",
"source": [
"When the calculation is complete, Bob's heart immediately sinks. He can see that $r^2$ is a positive number. So *any* value of $r$ will reduce the probability of success, which has a maximum of $0.75$. \n",
"\n",
"He suggests that maybe different correlations to begin with, or different random bit changes might work, but Alice quickly stops him. She knew all along that any strategy using correlated bits would have a maximum success probability of $0.75$. But, she also has a trick up her sleeve.\n",
"\n",
"Alice suggests to Bob a different way to represent information. Instead of bits they are called *qubits*. Each qubit is represented by a vector like this:\n",
"\n",
"$$\n",
"\\begin{pmatrix}\n",
"a \\\\\n",
"\\sqrt{1-a^2}\n",
"\\end{pmatrix}.\n",
"$$\n",
"\n",
"The difference between bits and qubits is that, instead of the sum of the entries being equal to $1$, it's the sum of the *squares* of the entries that must equal $1$.\n",
"\n",
"Alice points out that $a$ doesn't even need to be a positive number because it's $a^2$ that represents the probability of her responding yes, and $1-a^2$ the probabiity of her responding no.\n",
"\n",
"Everything else about qubits is roughly the same as with bits. For example, this correlated vector above doesn't have entries that square and sum to $1$, but this one does:\n",
"\n",
"$$\n",
"\\begin{pmatrix}\n",
" \\frac1{\\sqrt2} \\\\\n",
" 0\\\\\n",
" 0\\\\\n",
" \\frac1{\\sqrt2} \n",
"\\end{pmatrix}.\n",
"$$\n",
"\n",
"Just as with correlated bits, this vector cannot be written as,\n",
"\n",
"$$\n",
"\\begin{pmatrix}\n",
" \\frac1{\\sqrt2} \\\\\n",
" 0\\\\\n",
" 0\\\\\n",
" \\frac1{\\sqrt2} \n",
"\\end{pmatrix} \\neq \\begin{pmatrix}\n",
" a \\\\\n",
" \\sqrt{1-a^2} \n",
"\\end{pmatrix} \\otimes \\begin{pmatrix}\n",
" b \\\\\n",
" \\sqrt{1-b^2} \n",
"\\end{pmatrix},\n",
"$$\n",
"\n",
"for any $a$ or $b$. We could call this qubit correlation, but a much cooler sounding name is *entanglement*!\n",
"\n",
"Alice suggest they correlated their qubits using the vector\n",
"\n",
"$$\n",
"\\begin{pmatrix}\\frac{\\sqrt{2 \\sqrt{2} + 4}}{4}\\\\\n",
"- \\frac{\\sqrt{4 - 2 \\sqrt{2}}}{4}\\\\\n",
"- \\frac{\\sqrt{4 - 2 \\sqrt{2}}}{4}\\\\\n",
"- \\frac{\\sqrt{2 \\sqrt{2} + 4}}{4}\n",
"\\end{pmatrix} \\approx \n",
"\\begin{pmatrix} 0.653\\\\\n",
" -0.271\\\\ \n",
" -0.271\\\\\n",
" -0.653\n",
" \\end{pmatrix}.\n",
"$$\n",
"\n",
"\n",
"Bob asks why and Alice tells him that it doesn't have to be specifically this one, but it works out easily later on. She says that they could start with a different one, but then what they do later will be more complicated. The point is that the vector is entangled.\n",
"\n",
"Just as Bob suggested earlier, they both with change their own qubit if they are asked about Diane. One simple matrix that can ensure the sum of the squares of the entries remains $1$ is this one, for any number $y$,\n",
"\n",
"$$\n",
"RY := \\begin{pmatrix}\n",
"\\cos\\left(\\frac y 2\\right) & -\\sin\\left(\\frac y 2\\right)\\\\\n",
"\\sin\\left(\\frac y 2\\right) & \\cos\\left(\\frac y 2\\right) \n",
"\\end{pmatrix}\n",
"$$\n",
"\n",
"\n",
"\"Let me check,\" Bob says.\n",
"\n"
],
"metadata": {
"id": "ZPaAYBrwB6df"
}
},
{
"cell_type": "code",
"source": [
"def RY(y): \n",
" return Matrix([[cos(y/2),-sin(y/2)],[sin(y/2),cos(y/2)]])\n",
"\n",
"old_vector = Matrix([a, sqrt(1-a**2)])\n",
"new_vector = RY(y)*old_vector\n",
"\n",
"sum_of_squares = sum(new_vector.applyfunc(lambda i: i**2))\n",
"display(sum_of_squares)\n",
"\n",
"if simplify(sum_of_squares) == 1:\n",
" print(\"It is equal to 1.\")\n",
"else:\n",
" print(\"It is not equal to 1.\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 69
},
"id": "Dp_L_k2bMU5E",
"outputId": "d9652d05-7011-41f7-e782-408b855a9e52"
},
"execution_count": 75,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"(a*sin(y/2) + sqrt(1 - a**2)*cos(y/2))**2 + (a*cos(y/2) - sqrt(1 - a**2)*sin(y/2))**2"
],
"text/latex": "$\\displaystyle \\left(a \\sin{\\left(\\frac{y}{2} \\right)} + \\sqrt{1 - a^{2}} \\cos{\\left(\\frac{y}{2} \\right)}\\right)^{2} + \\left(a \\cos{\\left(\\frac{y}{2} \\right)} - \\sqrt{1 - a^{2}} \\sin{\\left(\\frac{y}{2} \\right)}\\right)^{2}$"
},
"metadata": {}
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"It is equal to 1.\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"\"Great, go on,\" Bob says.\n",
"\n",
"If $y=0$, then the matrix is the identity matrix again, which doesn't change the vector. \n",
"\n",
"Alice and Bob start with correlated qubits as represented by the vector above, and change their own qubits if they are asked about Diane. Alice calculates the probability table for her strategy.\n",
"\n"
],
"metadata": {
"id": "Yvgzvf38-FBe"
}
},
{
"cell_type": "code",
"source": [
"entanglement = Matrix([sqrt(2*sqrt(2) + 4)/4, \n",
" -sqrt(4 - 2*sqrt(2))/4,\n",
" -sqrt(4 - 2*sqrt(2))/4,\n",
" -sqrt(2*sqrt(2) + 4)/4])\n",
"\n",
"def final_probs_qubits(yA, yB):\n",
" temp_vec = kronecker_product(RY(yA),RY(yB))*entanglement\n",
" return temp_vec.applyfunc(lambda i: i**2)\n",
"\n",
"Alices_strategy = lambda y: simplify(expand(Matrix([final_probs_qubits(0,0).T,\n",
" final_probs_qubits(0,y).T,\n",
" final_probs_qubits(y,0).T,\n",
" final_probs_qubits(y,y).T\n",
" ]))).T\n",
"\n",
"Alices_strategy(y)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 150
},
"id": "5DvM3Y-C-bbw",
"outputId": "58e55ec1-6fc2-4fe1-cf9d-d7d8e31ff3c1"
},
"execution_count": 76,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Matrix([\n",
"[sqrt(2)/8 + 1/4, -sqrt(2)*sin(y/2)**2/4 + sqrt(2)*sin(y)/8 + sqrt(2)/8 + 1/4, -sqrt(2)*sin(y/2)**2/4 + sqrt(2)*sin(y)/8 + sqrt(2)/8 + 1/4, -3*sqrt(2)*(1 - cos(2*y))/32 + sqrt(2)*sin(y/2)**4/8 + sin(y/2)**4/4 - sqrt(2)*sin(y/2)**3*cos(y/2)/2 + sqrt(2)*sin(y/2)*cos(y/2)**3/2 + sqrt(2)*cos(y/2)**4/8 + cos(y/2)**4/4 - cos(2*y)/16 + 1/16],\n",
"[1/4 - sqrt(2)/8, sqrt(2)*sin(y/2)**2/4 - sqrt(2)*sin(y)/8 - sqrt(2)/8 + 1/4, sqrt(2)*sin(y/2)**2/4 - sqrt(2)*sin(y)/8 - sqrt(2)/8 + 1/4, 3*sqrt(2)*(1 - cos(2*y))/32 - sqrt(2)*sin(y/2)**4/8 + sin(y/2)**4/4 + sqrt(2)*sin(y/2)**3*cos(y/2)/2 - sqrt(2)*sin(y/2)*cos(y/2)**3/2 - sqrt(2)*cos(y/2)**4/8 + cos(y/2)**4/4 - cos(2*y)/16 + 1/16],\n",
"[1/4 - sqrt(2)/8, sqrt(2)*sin(y/2)**2/4 - sqrt(2)*sin(y)/8 - sqrt(2)/8 + 1/4, sqrt(2)*sin(y/2)**2/4 - sqrt(2)*sin(y)/8 - sqrt(2)/8 + 1/4, 3*sqrt(2)*(1 - cos(2*y))/32 - sqrt(2)*sin(y/2)**4/8 + sin(y/2)**4/4 + sqrt(2)*sin(y/2)**3*cos(y/2)/2 - sqrt(2)*sin(y/2)*cos(y/2)**3/2 - sqrt(2)*cos(y/2)**4/8 + cos(y/2)**4/4 - cos(2*y)/16 + 1/16],\n",
"[sqrt(2)/8 + 1/4, -sqrt(2)*sin(y/2)**2/4 + sqrt(2)*sin(y)/8 + sqrt(2)/8 + 1/4, -sqrt(2)*sin(y/2)**2/4 + sqrt(2)*sin(y)/8 + sqrt(2)/8 + 1/4, -3*sqrt(2)*(1 - cos(2*y))/32 + sqrt(2)*sin(y/2)**4/8 + sin(y/2)**4/4 - sqrt(2)*sin(y/2)**3*cos(y/2)/2 + sqrt(2)*sin(y/2)*cos(y/2)**3/2 + sqrt(2)*cos(y/2)**4/8 + cos(y/2)**4/4 - cos(2*y)/16 + 1/16]])"
],
"text/latex": "$\\displaystyle \\left[\\begin{matrix}\\frac{\\sqrt{2}}{8} + \\frac{1}{4} & - \\frac{\\sqrt{2} \\sin^{2}{\\left(\\frac{y}{2} \\right)}}{4} + \\frac{\\sqrt{2} \\sin{\\left(y \\right)}}{8} + \\frac{\\sqrt{2}}{8} + \\frac{1}{4} & - \\frac{\\sqrt{2} \\sin^{2}{\\left(\\frac{y}{2} \\right)}}{4} + \\frac{\\sqrt{2} \\sin{\\left(y \\right)}}{8} + \\frac{\\sqrt{2}}{8} + \\frac{1}{4} & - \\frac{3 \\sqrt{2} \\left(1 - \\cos{\\left(2 y \\right)}\\right)}{32} + \\frac{\\sqrt{2} \\sin^{4}{\\left(\\frac{y}{2} \\right)}}{8} + \\frac{\\sin^{4}{\\left(\\frac{y}{2} \\right)}}{4} - \\frac{\\sqrt{2} \\sin^{3}{\\left(\\frac{y}{2} \\right)} \\cos{\\left(\\frac{y}{2} \\right)}}{2} + \\frac{\\sqrt{2} \\sin{\\left(\\frac{y}{2} \\right)} \\cos^{3}{\\left(\\frac{y}{2} \\right)}}{2} + \\frac{\\sqrt{2} \\cos^{4}{\\left(\\frac{y}{2} \\right)}}{8} + \\frac{\\cos^{4}{\\left(\\frac{y}{2} \\right)}}{4} - \\frac{\\cos{\\left(2 y \\right)}}{16} + \\frac{1}{16}\\\\\\frac{1}{4} - \\frac{\\sqrt{2}}{8} & \\frac{\\sqrt{2} \\sin^{2}{\\left(\\frac{y}{2} \\right)}}{4} - \\frac{\\sqrt{2} \\sin{\\left(y \\right)}}{8} - \\frac{\\sqrt{2}}{8} + \\frac{1}{4} & \\frac{\\sqrt{2} \\sin^{2}{\\left(\\frac{y}{2} \\right)}}{4} - \\frac{\\sqrt{2} \\sin{\\left(y \\right)}}{8} - \\frac{\\sqrt{2}}{8} + \\frac{1}{4} & \\frac{3 \\sqrt{2} \\left(1 - \\cos{\\left(2 y \\right)}\\right)}{32} - \\frac{\\sqrt{2} \\sin^{4}{\\left(\\frac{y}{2} \\right)}}{8} + \\frac{\\sin^{4}{\\left(\\frac{y}{2} \\right)}}{4} + \\frac{\\sqrt{2} \\sin^{3}{\\left(\\frac{y}{2} \\right)} \\cos{\\left(\\frac{y}{2} \\right)}}{2} - \\frac{\\sqrt{2} \\sin{\\left(\\frac{y}{2} \\right)} \\cos^{3}{\\left(\\frac{y}{2} \\right)}}{2} - \\frac{\\sqrt{2} \\cos^{4}{\\left(\\frac{y}{2} \\right)}}{8} + \\frac{\\cos^{4}{\\left(\\frac{y}{2} \\right)}}{4} - \\frac{\\cos{\\left(2 y \\right)}}{16} + \\frac{1}{16}\\\\\\frac{1}{4} - \\frac{\\sqrt{2}}{8} & \\frac{\\sqrt{2} \\sin^{2}{\\left(\\frac{y}{2} \\right)}}{4} - \\frac{\\sqrt{2} \\sin{\\left(y \\right)}}{8} - \\frac{\\sqrt{2}}{8} + \\frac{1}{4} & \\frac{\\sqrt{2} \\sin^{2}{\\left(\\frac{y}{2} \\right)}}{4} - \\frac{\\sqrt{2} \\sin{\\left(y \\right)}}{8} - \\frac{\\sqrt{2}}{8} + \\frac{1}{4} & \\frac{3 \\sqrt{2} \\left(1 - \\cos{\\left(2 y \\right)}\\right)}{32} - \\frac{\\sqrt{2} \\sin^{4}{\\left(\\frac{y}{2} \\right)}}{8} + \\frac{\\sin^{4}{\\left(\\frac{y}{2} \\right)}}{4} + \\frac{\\sqrt{2} \\sin^{3}{\\left(\\frac{y}{2} \\right)} \\cos{\\left(\\frac{y}{2} \\right)}}{2} - \\frac{\\sqrt{2} \\sin{\\left(\\frac{y}{2} \\right)} \\cos^{3}{\\left(\\frac{y}{2} \\right)}}{2} - \\frac{\\sqrt{2} \\cos^{4}{\\left(\\frac{y}{2} \\right)}}{8} + \\frac{\\cos^{4}{\\left(\\frac{y}{2} \\right)}}{4} - \\frac{\\cos{\\left(2 y \\right)}}{16} + \\frac{1}{16}\\\\\\frac{\\sqrt{2}}{8} + \\frac{1}{4} & - \\frac{\\sqrt{2} \\sin^{2}{\\left(\\frac{y}{2} \\right)}}{4} + \\frac{\\sqrt{2} \\sin{\\left(y \\right)}}{8} + \\frac{\\sqrt{2}}{8} + \\frac{1}{4} & - \\frac{\\sqrt{2} \\sin^{2}{\\left(\\frac{y}{2} \\right)}}{4} + \\frac{\\sqrt{2} \\sin{\\left(y \\right)}}{8} + \\frac{\\sqrt{2}}{8} + \\frac{1}{4} & - \\frac{3 \\sqrt{2} \\left(1 - \\cos{\\left(2 y \\right)}\\right)}{32} + \\frac{\\sqrt{2} \\sin^{4}{\\left(\\frac{y}{2} \\right)}}{8} + \\frac{\\sin^{4}{\\left(\\frac{y}{2} \\right)}}{4} - \\frac{\\sqrt{2} \\sin^{3}{\\left(\\frac{y}{2} \\right)} \\cos{\\left(\\frac{y}{2} \\right)}}{2} + \\frac{\\sqrt{2} \\sin{\\left(\\frac{y}{2} \\right)} \\cos^{3}{\\left(\\frac{y}{2} \\right)}}{2} + \\frac{\\sqrt{2} \\cos^{4}{\\left(\\frac{y}{2} \\right)}}{8} + \\frac{\\cos^{4}{\\left(\\frac{y}{2} \\right)}}{4} - \\frac{\\cos{\\left(2 y \\right)}}{16} + \\frac{1}{16}\\end{matrix}\\right]$"
},
"metadata": {},
"execution_count": 76
}
]
},
{
"cell_type": "markdown",
"source": [
"Bob thinks it looks hideous, but agrees that it would be easy to let a computer find the $y$ value that gives the maximum success probability. "
],
"metadata": {
"id": "zyDvZZs8p4TE"
}
},
{
"cell_type": "code",
"source": [
"expr = simplify(success(Alices_strategy(x)))\n",
"\n",
"expr_deriv = trigsimp(diff(expr, x))\n",
"\n",
"# Solve for the critical points\n",
"crit_points = solve(expr_deriv, x)\n",
"\n",
"# Check which critical point(s) yield(s) the maximum value\n",
"vals = [simplify(expr.subs(x, simplify(expand_complex(point)))) for point in crit_points]\n",
" \n",
"max_val = max(vals)\n",
"\n",
"max_val.evalf()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 37
},
"id": "OKSufdSw_qyC",
"outputId": "1083e533-7722-45d8-850b-647b1385af6d"
},
"execution_count": 77,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0.853553390593274"
],
"text/latex": "$\\displaystyle 0.853553390593274$"
},
"metadata": {},
"execution_count": 77
}
]
},
{
"cell_type": "markdown",
"source": [
"Alice smiles since this number is larger than $0.75$, the probability of success using correlated bits, meaning they will be set free."
],
"metadata": {
"id": "6FAEWqScqcke"
}
},
{
"cell_type": "markdown",
"source": [
"# Appendix"
],
"metadata": {
"id": "Tw8em_kjsG1N"
}
},
{
"cell_type": "markdown",
"source": [
"By the way, here is that value of $y$. If you are into polar forms of complex numbers, it's about as simple as it gets."
],
"metadata": {
"id": "Kqd8_3RPsMVI"
}
},
{
"cell_type": "code",
"source": [
"best_y = simplify(expand_complex(crit_points[vals.index(max_val)]))\n",
"best_y"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 47
},
"id": "1Y6ZwQS6Clqh",
"outputId": "deeaa8fd-7afe-438b-c036-4ca0b1f9c1d3"
},
"execution_count": 78,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"pi/2"
],
"text/latex": "$\\displaystyle \\frac{\\pi}{2}$"
},
"metadata": {},
"execution_count": 78
}
]
},
{
"cell_type": "markdown",
"source": [
"The correlation table looks like this. You should compare it to the table which would have 100% success:\n",
"\n",
"$$\n",
"\\begin{pmatrix}\n",
" \\frac12 & \\frac12 & \\frac12 & 0 \\\\\n",
" 0 & 0 & 0 & \\frac12 \\\\\n",
" 0 & 0 & 0 & \\frac12 \\\\\n",
" \\frac12 & \\frac12 & \\frac12 & 0 \n",
"\\end{pmatrix}.\n",
"$$\n",
"\n",
"In case you were wondering, this type of correlation wouldn't necessarily violate special relativity, but it can't be acheived with correlated bits or qubits. The hypothetical \"thing\" that implements such a table is called a *nonlocal box*. If you can discover a part of the world that corresponds to such a thing, there's definitely a Nobel Prize in it for you. It's an open research question as to why the world seems to allow \"stronger\" than classical correlations, but not the strongest theoretically possible. \n",
"\n"
],
"metadata": {
"id": "NuIgEMcisU43"
}
},
{
"cell_type": "code",
"source": [
"simplify(Alices_strategy(best_y)).evalf()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 98
},
"id": "_kxMTLTAZw2F",
"outputId": "4bad705b-d501-4321-da65-81f31274b932"
},
"execution_count": 79,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Matrix([\n",
"[ 0.426776695296637, 0.426776695296637, 0.426776695296637, 0.0732233047033631],\n",
"[0.0732233047033631, 0.0732233047033631, 0.0732233047033631, 0.426776695296637],\n",
"[0.0732233047033631, 0.0732233047033631, 0.0732233047033631, 0.426776695296637],\n",
"[ 0.426776695296637, 0.426776695296637, 0.426776695296637, 0.0732233047033631]])"
],
"text/latex": "$\\displaystyle \\left[\\begin{matrix}0.426776695296637 & 0.426776695296637 & 0.426776695296637 & 0.0732233047033631\\\\0.0732233047033631 & 0.0732233047033631 & 0.0732233047033631 & 0.426776695296637\\\\0.0732233047033631 & 0.0732233047033631 & 0.0732233047033631 & 0.426776695296637\\\\0.426776695296637 & 0.426776695296637 & 0.426776695296637 & 0.0732233047033631\\end{matrix}\\right]$"
},
"metadata": {},
"execution_count": 79
}
]
},
{
"cell_type": "markdown",
"source": [
"If you are into quantum computing, you can create the mysterious entangled state above with a hadamard gate, a CNOT gate, and a Y-rotation."
],
"metadata": {
"id": "hA1hk8upteLJ"
}
},
{
"cell_type": "code",
"source": [
"X = Matrix([[0,1],[1,0]])\n",
"H = Matrix([[1/sqrt(2),1/sqrt(2)],[1/sqrt(2),-1/sqrt(2)]])\n",
"\n",
"P0 = Matrix([[1,0],[0,0]])\n",
"P1 = Matrix([[0,0],[0,1]])\n",
"cnot = kronecker_product(P0, Id) + kronecker_product(P1, X)\n",
"\n",
"# start in |00>\n",
"state = Matrix([1,0,0,0])\n",
"\n",
"# change to |10>\n",
"state = kronecker_product(X, Id) * state\n",
"\n",
"# apply H and CNOT to create a standard Bell state\n",
"entanglement = cnot * kronecker_product(H, Id) * state\n",
"\n",
"# finally rotate the first qubit about Y\n",
"simplify(kronecker_product(RY(-pi/4), Id) * entanglement)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 131
},
"id": "d_4cDEBWLkw5",
"outputId": "217ed5d5-5b19-450f-8dd7-a4b655071b97"
},
"execution_count": 85,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Matrix([\n",
"[ sqrt(2*sqrt(2) + 4)/4],\n",
"[-sqrt(4 - 2*sqrt(2))/4],\n",
"[-sqrt(4 - 2*sqrt(2))/4],\n",
"[-sqrt(2*sqrt(2) + 4)/4]])"
],
"text/latex": "$\\displaystyle \\left[\\begin{matrix}\\frac{\\sqrt{2 \\sqrt{2} + 4}}{4}\\\\- \\frac{\\sqrt{4 - 2 \\sqrt{2}}}{4}\\\\- \\frac{\\sqrt{4 - 2 \\sqrt{2}}}{4}\\\\- \\frac{\\sqrt{2 \\sqrt{2} + 4}}{4}\\end{matrix}\\right]$"
},
"metadata": {},
"execution_count": 85
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment