# BellInequalityMax

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
 Other toolboxes required BellInequalityMax Computes the maximum value of a Bell inequality CVX NonlocalGameValueNPAHierarchyXORGameValue Nonlocality and Bell inequalities no

BellInequalityMax is a function that computes the maximum possible value of a given Bell inequality under either classical mechanics, quantum mechanics, or general no-signalling theories. In the classical and non-signalling cases, an exact value is computed, whereas the value computed in the quantum case is only an upper bound (found using the NPA hierarchy).

## Syntax

• BMAX = BellInequalityMax(JOINT_COE,A_COE,B_COE,A_VAL,B_VAL)
• BMAX = BellInequalityMax(JOINT_COE,A_COE,B_COE,A_VAL,B_VAL,MTYPE)
• BMAX = BellInequalityMax(JOINT_COE,A_COE,B_COE,A_VAL,B_VAL,MTYPE,K)

## Argument descriptions

• JOINT_COE: A matrix whose $(i,j)$-entry gives the coefficient of $\langle A_i B_j \rangle$ in the Bell inequality.
• A_COE: A vector whose $i$-th entry gives the coefficient of $\langle A_i \rangle$ in the Bell inequality.
• B_COE: A vector whose $i$-th entry gives the coefficient of $\langle B_i \rangle$ in the Bell inequality.
• A_VAL: A vector whose $i$-th entry gives the value of the $i$-th measurement result on Alice's side.
• B_VAL: A vector whose $i$-th entry gives the value of the $i$-th measurement result on Bob's side.
• MTYPE (optional, default 'classical'): A string indicating which type of theory should be used when computing the maximum value of the Bell inequality. Must be one of 'classical', 'quantum', or 'nosignal'. If MTYPE = 'quantum' then only an upper bound on the Bell inequality is computed, not necessarily is best upper bound (see the argument K below).
• K (optional, default 1): If MTYPE = 'quantum' then this is a non-negative integer indicating what level of the NPA hierarchy should be used when bounding the Bell inequality. Higher values of K give better bounds, but require more memory and time. Alternatively, K can be a string of a form like '1+ab+aab', which indicates that an intermediate level of the hierarchy should be used, where this example uses all products of 1 measurement, all products of one Alice and one Bob measurement, and all products of two Alice and one Bob measurement. Use plus signs to separate the different categories of products, as above. The first character of this string should always be a number, indicating the base level to use. If MTYPE is anything other than 'quantum' then K has no effect.

## Examples

### The CHSH inequality

One formulation of the CHSH inequality says that if $\{A_1,A_2\}$ and $\{B_1,B_2\}$ are $\{-1,+1\}$-valued measurement settings, then in classical physics the following inequality holds: $\langle A_1 B_1 \rangle + \langle A_1 B_2 \rangle + \langle A_2 B_1 \rangle - \langle A_2 B_2 \rangle \leq 2.$ Similarly, the best bound on this quantity is $2\sqrt{2}$ in a quantum mechanical setting (this is Tsirelson's bound), and it is $4$ in no-signalling theories. All three of these bounds can be found as follows:

>> BellInequalityMax([1 1;1 -1], [0 0], [0 0], [-1 1], [-1 1], 'classical')

ans =

2

>> BellInequalityMax([1 1;1 -1], [0 0], [0 0], [-1 1], [-1 1], 'quantum')

ans =

2.8284

>> BellInequalityMax([1 1;1 -1], [0 0], [0 0], [-1 1], [-1 1], 'nosignal')

ans =

4.0000

### The CHSH inequality again

Another (equivalent) formulation of the CHSH inequality says that if $\{A_1,A_2\}$ and $\{B_1,B_2\}$ are $\{0,1\}$-valued measurement settings, then in classical physics the following inequality holds: $\langle A_1 B_1 \rangle + \langle A_1 B_2 \rangle + \langle A_2 B_1 \rangle - \langle A_2 B_2 \rangle - \langle A_1 \rangle - \langle B_1 \rangle \leq 0.$ Similarly, the best bound on this quantity is $1/\sqrt{2} - 1/2$ in a quantum mechanical setting, and it is $1/2$ in no-signalling settings. These three bounds can be verified as follows:

>> BellInequalityMax([1 1;1 -1], [-1 0], [-1 0], [0 1], [0 1], 'classical')

ans =

0

>> BellInequalityMax([1 1;1 -1], [-1 0], [-1 0], [0 1], [0 1], 'quantum')

ans =

0.2071

>> BellInequalityMax([1 1;1 -1], [-1 0], [-1 0], [0 1], [0 1], 'nosignal')

ans =

0.5000

### The I3322 inequality

The I3322 inequality is a Bell inequality that says that if $\{A_1,A_2,A_3\}$ and $\{B_1,B_2,B_3\}$ are $\{0,1\}$-valued measurement settings, then in classical physics the following inequality holds: $\langle A_1 B_1 \rangle + \langle A_1 B_2 \rangle - \langle A_1 B_3 \rangle + \langle A_2 B_1 \rangle + \langle A_2 B_2 \rangle + \langle A_2 B_3 \rangle - \langle A_3 B_1 \rangle + \langle A_3 B_2 \rangle - \langle A_2 \rangle - \langle B_1 \rangle - 2\langle B_2 \rangle \leq 0.$ Similarly, it is known that a value of (strictly) larger than $1/4$ is possible in quantum mechanics, and the best possible bound is $1$ in no-signalling theories. The following code computes the best possible classical and no-signalling bounds exactly, and computes several different upper bounds for the quantum mechanical setting:

>> BellInequalityMax([1 1 -1;1 1 1;-1 1 0], [0 -1 0], [-1 -2 0], [0 1], [0 1], 'classical')

ans =

0

>> BellInequalityMax([1 1 -1;1 1 1;-1 1 0], [0 -1 0], [-1 -2 0], [0 1], [0 1], 'quantum', 1)

ans =

0.366025403693998

>> BellInequalityMax([1 1 -1;1 1 1;-1 1 0], [0 -1 0], [-1 -2 0], [0 1], [0 1], 'quantum', '1+ab')

ans =

0.251470897708374 % as we increase K, the upper bound gets lower (better)

>> BellInequalityMax([1 1 -1;1 1 1;-1 1 0], [0 -1 0], [-1 -2 0], [0 1], [0 1], 'quantum', 2)

ans =

0.250939721548844

>> BellInequalityMax([1 1 -1;1 1 1;-1 1 0], [0 -1 0], [-1 -2 0], [0 1], [0 1], 'quantum', 3)

ans =

0.250875554481214

>> BellInequalityMax([1 1 -1;1 1 1;-1 1 0], [0 -1 0], [-1 -2 0], [0 1], [0 1], 'quantum', 4)

ans =

0.250875378885565

>> BellInequalityMax([1 1 -1;1 1 1;-1 1 0], [0 -1 0], [-1 -2 0], [0 1], [0 1], 'nosignal')

ans =

0.999999991391596

We note that the values provided for the quantum upper bound above for K = '1+ab', K = 2, and K = 3 agree with the values found in . Furthermore, the value when K = 4 agrees with the value found in . The exact value of the best upper bound in the quantum setting is an open problem, but is known to be approximately $0.250875$.

## Source code

Click on "expand" to the right to view the MATLAB source code for this function.

1. %%  BELLINEQUALITYMAX    Computes the maximum value of a Bell inequality
2. %   This function has five required input arguments:
3. %     JOINT_COE: a matrix whose (i,j)-entry is the coefficient of the term
4. %                <A_iB_j> in the Bell inequality.
5. %     A_COE: a vector whose i-th entry is the coefficient of the term <A_i>
6. %            in the Bell inequality.
7. %     B_COE: a vector whose i-th entry is the coefficient of the term <B_i>
8. %            in the Bell inequality.
9. %     A_VAL: a vector whose i-th entry is the value of the i-th measurement
10. %            outcome on Alice's system
11. %     B_VAL: a vector whose i-th entry is the value of the i-th measurement
12. %            outcome on Bob's system
13. %
14. %   BMAX = BellInequalityMax(JOINT_COE,A_COE,B_COE,A_VAL,B_VAL) is the
15. %   maximum value that the specified Bell inequality can take on in
16. %   classical mechanics. For the maximum quantum or no-signalling value,
17. %   see the optional arguments described below.
18. %
19. %   This function has two optional input arguments:
20. %     MTYPE (default 'classical'): one of 'classical', 'quantum', or
21. %       'nosignal', indicating what type of Bell inequality maximum should
22. %       be computed. IMPORTANT NOTE: if MTYPE='quantum' then only an upper
23. %       bound on the Bell inequality is computed, not its exact value (see
24. %       the argument K below).
25. %     K (default 1): if MYTPE='quantum', then K is a non-negative integer
26. %       or string indicating what level of the NPA hierarchy to use to
27. %       bound the Bell inequality (higher values give better bounds, but
28. %       require more computation time). See the NPAHierarchy function for
29. %       details.
30. %
31. %   BMAX = BellInequalityMax(JOINT_COE,A_COE,B_COE,A_VAL,B_VAL,MTYPE,K) is
32. %   the maximum value that the specified Bell inequality can take on in the
33. %   setting (classical, quantum, or no-signalling) specified by MTYPE.
34. %
35. %   URL: http://www.qetlab.com/BellInequalityMax
36. 
37. %   requires: CVX (http://cvxr.com/cvx/), NPAHierarchy.m, opt_args.m,
38. %             update_odometer.m
39. %
40. %   author: Nathaniel Johnston (nathaniel@njohnston.ca)
41. %   package: QETLAB
42. %   last updated: March 6, 2015
43. 
44. function bmax = BellInequalityMax(joint_coe,a_coe,b_coe,a_val,b_val,varargin)
45. 
46.     % set optional argument defaults: MTYPE='classical', K=1
47.     [mtype,k] = opt_args({ 'classical', 1 },varargin{:});
48. 
49.     % Get some basic values and make sure that the input vectors are column
50.     % vectors.
51.     [ma,mb] = size(joint_coe);
52.     oa = length(a_val);
53.     ob = length(b_val);
54.     a_val = a_val(:); b_val = b_val(:);
55.     a_coe = a_coe(:); b_coe = b_coe(:);
56. 
57.     % The no-signalling maximum is just implemented by taking the zero-th
58.     % level of the NPA (quantum) hierarchy.
59.     if(strcmpi(mtype,'nosignal'))
60.         mtype = 'quantum';
61.         k = 0;
62.     end
63. 
64.     % Compute the maximum value of the Bell inequality, depending on which
65.     % type of maximum was requested.
66.     if(strcmpi(mtype,'quantum'))
67.         cvx_begin quiet
68.             variable p(oa,ob,ma,mb);
69. 
70.             % Set up the Bell inequality.
71.             D = squeeze(sum(sum(repmat(a_val*b_val',[1,1,ma,mb]).*p,1),2));
72.             Da = sum(repmat(a_val(:),[1,ma]).*squeeze(sum(p(:,:,:,1),2)),1);
73.             Db = sum(repmat(b_val(:),[1,mb]).*squeeze(sum(p(:,:,1,:),1)),1);
74. 
75.             maximize sum(sum(joint_coe.*D)) + Da*a_coe + Db*b_coe
76. 
77.             subject to
78.                 NPAHierarchy(p,k) == 1;
79.         cvx_end
80. 
81.         bmax = cvx_optval;
82. 
83.         % Deal with error messages.
84.         if(strcmpi(cvx_status,'Inaccurate/Solved'))
85.             warning('BellInequalityMax:NumericalProblems','Minor numerical problems encountered by CVX. Consider adjusting the tolerance level TOL and re-running the script.');
86.         elseif(strcmpi(cvx_status,'Inaccurate/Infeasible'))
87.             warning('BellInequalityMax:NumericalProblems','Minor numerical problems encountered by CVX. Consider adjusting the tolerance level TOL and re-running the script.');
88.         elseif(strcmpi(cvx_status,'Unbounded') || strcmpi(cvx_status,'Inaccurate/Unbounded') || strcmpi(cvx_status,'Failed'))
89.             error('BellInequalityMax:NumericalProblems',strcat('Numerical problems encountered (CVX status: ',cvx_status,'). Please try adjusting the tolerance level TOL.'));
90.         end
91.     elseif(strcmpi(mtype,'classical'))
92.         % Compute the classical maximum value just by brute-forcing over
93.         % all possibilities.
94.         bmax = -Inf;
95.         a_ind = zeros(1,ma);
96.         b_ind = zeros(1,mb);
97. 
98.         for i = 1:oa^ma
99.             for j = 1:ob^mb
100.                 bmax = max(bmax,sum(sum(joint_coe.*(a_val(a_ind+1)*b_val(b_ind+1)'))) + a_val(a_ind+1)'*a_coe + b_val(b_ind+1)'*b_coe);
101.                 b_ind = update_odometer(b_ind, ob*ones(1,mb));
102.             end
103.             a_ind = update_odometer(a_ind, oa*ones(1,ma));
104.         end
105.     else
106.         error('BellInequalityMax:InvalidMTYPE','MTYPE must be one of ''classical'', ''quantum'', or ''nosignal''.');
107.     end
108. end