{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# All the Bell inequalities" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### (For two observers, two settings, two outcomes, and full correlation functions)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "noncontextual = Polyhedron(vertices=[(1,1,1,1),(1,1,-1,-1),(1,-1,1,-1),(1,-1,-1,1),(-1,1,1,-1),(-1,1,-1,1),(-1,-1,1,1),(-1,-1,-1,-1)])" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "A 4-dimensional polyhedron in ZZ^4 defined as the convex hull of 8 vertices (use the .plot() method to plot)" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "noncontextual" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "Graphics3d Object" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "noncontextual.plot()" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(An inequality (0, 0, 1, 0) x + 1 >= 0,\n", " An inequality (1, 1, -1, 1) x + 2 >= 0,\n", " An inequality (1, 0, 0, 0) x + 1 >= 0,\n", " An inequality (1, 1, 1, -1) x + 2 >= 0,\n", " An inequality (0, 1, 0, 0) x + 1 >= 0,\n", " An inequality (-1, 1, 1, 1) x + 2 >= 0,\n", " An inequality (0, 0, 0, 1) x + 1 >= 0,\n", " An inequality (1, -1, 1, 1) x + 2 >= 0,\n", " An inequality (0, -1, 0, 0) x + 1 >= 0,\n", " An inequality (-1, -1, 1, -1) x + 2 >= 0,\n", " An inequality (0, 0, -1, 0) x + 1 >= 0,\n", " An inequality (1, -1, -1, -1) x + 2 >= 0,\n", " An inequality (0, 0, 0, -1) x + 1 >= 0,\n", " An inequality (-1, 1, -1, -1) x + 2 >= 0,\n", " An inequality (-1, 0, 0, 0) x + 1 >= 0,\n", " An inequality (-1, -1, -1, 1) x + 2 >= 0)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "noncontextual.Hrepresentation()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### (full correlation functions and single-party marginals)" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [], "source": [ "# All deterministic configurations\n", "\n", "allConfigs = [[(-1)**((x >> i) % 2) for i in range(4)] for x in range(2**4)]\n", "\n", "verts = [\n", " [c[0], c[2], c[0]*c[2],\n", " c[0], c[3], c[0]*c[3],\n", " c[1], c[2], c[1]*c[2],\n", " c[1], c[3], c[1]*c[3]\n", " ]\n", " for c in allConfigs\n", "]" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [], "source": [ "noncontextual=Polyhedron(vertices=verts)" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "A 8-dimensional polyhedron in ZZ^12 defined as the convex hull of 16 vertices (use the .plot() method to plot)" ] }, "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [ "noncontextual" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(An equation (0, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0) x + 0 == 0,\n", " An equation (0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0) x + 0 == 0,\n", " An equation (0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0) x + 0 == 0,\n", " An equation (1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0) x + 0 == 0,\n", " An inequality (-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0) x + 1 >= 0,\n", " An inequality (-1, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0) x + 1 >= 0,\n", " An inequality (-1, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0) x + 1 >= 0,\n", " An inequality (-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0) x + 1 >= 0,\n", " An inequality (0, 0, 0, 0, 0, 0, 0, -1, -1, 1, 0, 0) x + 1 >= 0,\n", " An inequality (1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0) x + 1 >= 0,\n", " An inequality (0, 0, 0, 0, 0, 0, 0, -1, 1, -1, 0, 0) x + 1 >= 0,\n", " An inequality (0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1) x + 1 >= 0,\n", " An inequality (0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 1) x + 1 >= 0,\n", " An inequality (0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1, -1) x + 1 >= 0,\n", " An inequality (0, 0, 0, 0, 0, 0, 0, 1, -1, -1, 0, 0) x + 1 >= 0,\n", " An inequality (1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0) x + 1 >= 0,\n", " An inequality (1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0) x + 1 >= 0,\n", " An inequality (1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0) x + 1 >= 0,\n", " An inequality (0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1) x + 2 >= 0,\n", " An inequality (0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1) x + 1 >= 0,\n", " An inequality (0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0) x + 1 >= 0,\n", " An inequality (0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, 1) x + 2 >= 0,\n", " An inequality (0, 0, -1, 0, 0, 1, 0, 0, 1, 0, 0, 1) x + 2 >= 0,\n", " An inequality (0, 0, 1, 0, 0, -1, 0, 0, 1, 0, 0, 1) x + 2 >= 0,\n", " An inequality (0, 0, -1, 0, 0, -1, 0, 0, 1, 0, 0, -1) x + 2 >= 0,\n", " An inequality (0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 1) x + 2 >= 0,\n", " An inequality (0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1) x + 2 >= 0,\n", " An inequality (0, 0, -1, 0, 0, 1, 0, 0, -1, 0, 0, -1) x + 2 >= 0)" ] }, "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ "noncontextual.Hrepresentation()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Non-Signalling Polytope" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "# Buid linear constraints\n", "\n", "def unitVector(i,n):\n", " return([0]*(i-1)+[1]+[0]*(n-i));\n", "\n", "def normal(i):\n", " return([\n", " [-1]+[0]*(4*(i-1))+[1]*4+[0]*(4*(4-i)),\n", " [1]+[0]*(4*(i-1))+[-1]*4+[0]*(4*(4-i))\n", " ]);\n", "\n", "positivity = [ [0]+unitVector(i,16) for i in range(1,17)];\n", "normal = flatten([normal(i) for i in range(1,5)], max_level=1);\n", "nonsig = [\n", " [0]+[1,1,0,0,-1,-1,0,0]+[0]*8,\n", " [0]+[-1,-1,0,0,1,1,0,0]+[0]*8,\n", " [0]+[0]*8+[1,1,0,0,-1,-1,0,0],\n", " [0]+[0]*8+[-1,-1,0,0,1,1,0,0],\n", " [0]+[1,0,1,0]+[0]*4+[-1,0,-1,0]+[0]*4,\n", " [0]+[-1,0,-1,0]+[0]*4+[1,0,1,0]+[0]*4,\n", " [0]+[0]*4+[1,0,1,0]+[0]*4+[-1,0,-1,0],\n", " [0]+[0]*4+[-1,0,-1,0]+[0]*4+[1,0,1,0]\n", "];" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "ns=Polyhedron(ieqs=positivity+normal+nonsig)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "A 8-dimensional polyhedron in QQ^16 defined as the convex hull of 24 vertices (use the .plot() method to plot)" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ns" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "(A vertex at (0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0),\n", " A vertex at (0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0),\n", " A vertex at (0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1),\n", " A vertex at (1/2, 0, 0, 1/2, 0, 1/2, 1/2, 0, 1/2, 0, 0, 1/2, 1/2, 0, 0, 1/2),\n", " A vertex at (0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0),\n", " A vertex at (0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0),\n", " A vertex at (1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1),\n", " A vertex at (1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0),\n", " A vertex at (0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0),\n", " A vertex at (1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0),\n", " A vertex at (0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),\n", " A vertex at (0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0),\n", " A vertex at (0, 1/2, 1/2, 0, 1/2, 0, 0, 1/2, 0, 1/2, 1/2, 0, 0, 1/2, 1/2, 0),\n", " A vertex at (0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0),\n", " A vertex at (0, 1/2, 1/2, 0, 0, 1/2, 1/2, 0, 1/2, 0, 0, 1/2, 0, 1/2, 1/2, 0),\n", " A vertex at (1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0),\n", " A vertex at (0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0),\n", " A vertex at (0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1),\n", " A vertex at (0, 1/2, 1/2, 0, 0, 1/2, 1/2, 0, 0, 1/2, 1/2, 0, 1/2, 0, 0, 1/2),\n", " A vertex at (1/2, 0, 0, 1/2, 1/2, 0, 0, 1/2, 0, 1/2, 1/2, 0, 1/2, 0, 0, 1/2),\n", " A vertex at (1/2, 0, 0, 1/2, 0, 1/2, 1/2, 0, 0, 1/2, 1/2, 0, 0, 1/2, 1/2, 0),\n", " A vertex at (0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0),\n", " A vertex at (1/2, 0, 0, 1/2, 1/2, 0, 0, 1/2, 1/2, 0, 0, 1/2, 0, 1/2, 1/2, 0),\n", " A vertex at (0, 1/2, 1/2, 0, 1/2, 0, 0, 1/2, 1/2, 0, 0, 1/2, 1/2, 0, 0, 1/2))" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ns.Vrepresentation()" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "am = ns.adjacency_matrix()" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 1 0 0 1 0 1]\n", "[1 0 1 0 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 1 1 0 0]\n", "[1 1 0 0 1 1 1 0 1 1 1 0 1 1 0 1 1 1 1 1 0 1 0 1]\n", "[1 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0]\n", "[1 1 1 0 0 1 0 1 0 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1]\n", "[0 1 1 0 1 0 1 1 1 1 1 1 1 1 0 1 1 0 0 1 1 1 1 0]\n", "[1 1 1 1 0 1 0 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 0 0]\n", "[1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 0 0 1 0 1 0]\n", "[1 1 1 1 0 1 1 1 0 1 1 1 0 0 0 1 1 1 1 1 1 1 0 0]\n", "[1 0 1 1 1 1 1 1 1 0 1 1 0 1 0 1 0 1 0 1 0 1 1 1]\n", "[1 0 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1]\n", "[1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1 0 1 0]\n", "[0 1 1 0 1 1 0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 1 0 0]\n", "[1 1 1 0 1 1 0 1 0 1 1 1 1 0 1 1 1 1 0 0 0 1 1 1]\n", "[1 1 0 0 1 0 0 1 0 0 0 1 0 1 0 0 1 1 0 0 0 0 0 0]\n", "[0 1 1 0 1 1 1 1 1 1 1 1 1 1 0 0 1 0 0 1 1 1 1 0]\n", "[1 1 1 0 1 1 1 1 1 0 0 1 1 1 1 1 0 1 1 0 1 1 0 0]\n", "[1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 1 0 1 0 0 1 0 1]\n", "[1 1 1 0 0 0 1 0 1 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0]\n", "[0 0 1 0 0 1 1 0 1 1 1 0 0 0 0 1 0 0 0 0 0 1 0 0]\n", "[0 1 0 0 0 1 1 1 1 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0]\n", "[1 1 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 1 1 1 0 0 0 1]\n", "[0 0 0 0 1 1 0 1 0 1 1 1 0 1 0 1 0 0 0 0 0 0 0 0]\n", "[1 0 1 0 1 0 0 0 0 1 1 0 0 1 0 0 0 1 0 0 0 1 0 0]\n" ] } ], "source": [ "print(am)" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "17" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sum(am[0])" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "8" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sum(am[-1])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "SageMath 9.0", "language": "sage", "name": "sagemath" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }