# BellInequalityMaxQubits

 Other toolboxes required BellInequalityMaxQubits Approximates the optimal value of a Bell inequality in qubit (i.e., 2-dimensional quantum) settings CVX BellInequalityMaxNonlocalGameValueXORGameValue Nonlocality and Bell inequalities no

BellInequalityMaxQubits is a function that computes an upper bound for the maximum possible value of a given Bell inequality in a quantum mechanical setting where the two parties each have access to qubits (i.e., 2-dimensional quantum systems). This bound is computed using the method presented in [1].

## Syntax

• BMAX = BellInequalityMaxQubits(JOINT_COE,A_COE,B_COE,A_VAL,B_VAL)
• [BMAX,RHO] = BellInequalityMaxQubits(JOINT_COE,A_COE,B_COE,A_VAL,B_VAL)

## Argument descriptions

### Input arguments

• 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.

### Output arguments

• BMAX: An upper bound on the qubit value of the Bell inequality.
• RHO: A many-qubit quantum state that acts as a witness that verifies the bound provided by BMAX. This is the positive-partial-transpose (PPT) state described by [1].

## Examples

### The I3322 inequality

The I3322 inequality[2][3] 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.$ It is straightforward to check that a 2-qubit maximally-entangled Bell state allows for a value of $1/4$ in this Bell inequality. The following code verifies that it is not possible to get a value of larger than $1/4$ using $2$-dimensional systems:

>> BellInequalityMaxQubits([1 1 -1;1 1 1;-1 1 0], [0 -1 0], [-1 -2 0], [0 1], [0 1])

ans =

0.2500

It is worth taking a look at the $I_{3322}$ example at the BellInequalityMax page to compare the computations provided there.

## Source code

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

1. %%  BELLINEQUALITYMAXQUBITS    Approximates the optimal value of a 2-outcome Bell inequality in qubit (i.e., 2-dimensional quantum) settings
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. Must have exactly 2 entries.
11. %     B_VAL: A vector whose i-th entry is the value of the i-th measurement
12. %            outcome on Bob's system. Must have exactly 2 entries.
13. %
14. %   BMAX = BellInequalityMaxQubits(JOINT_COE,A_COE,B_COE,A_VAL,B_VAL) is an
15. %   upper bound on the maximum value that the specified Bell inequality can
16. %   take on in 2-dimensional quantum settings (i.e., when the two parties
17. %   have access to qubits). This bound is computed using the method of
18. %   arXiv:1308.3410
19. %
20. %   This function has now optional input arguments.
21. %
22. %   URL: http://www.qetlab.com/BellInequalityMaxQubits
23. 
24. %   requires: CVX (http://cvxr.com/cvx/), PartialTranspose.m,
25. %             PermutationOperator.m, Swap.m
26. %
27. %   author: Nathaniel Johnston (nathaniel@njohnston.ca)
28. %   package: QETLAB
29. %   last updated: April 13, 2015
30. 
31. function [bmax,rho] = BellInequalityMaxQubits(joint_coe,a_coe,b_coe,a_val,b_val)
32. 
33.     % Get some basic values and make sure that the input vectors are column
34.     % vectors.
35.     [ma,mb] = size(joint_coe);
36.     oa = length(a_val);
37.     ob = length(b_val);
38.     a_val = a_val(:); b_val = b_val(:);
39.     a_coe = a_coe(:); b_coe = b_coe(:);
40. 
41.     if(length(a_val) ~= 2 || length(b_val) ~= 2)
42.         error('BellInequalityMaxQubits:InvalidInequality','This script is only capable of handling Bell inequalities with two outcomes.');
43.     end
44.     m = ma;
45. 
46.     tot_dim = 2^(2*m+2);
47.     obj_mat = sparse(tot_dim,tot_dim);
48. 
49.     for a = 0:1
50.         for b = 0:1
51.             for x = 1:m
52.                 for y = 1:m
53.                     b_coeff = joint_coe(x,y)*a_val(a+1)*b_val(b+1);
54.                     if(y==1)
55.                         b_coeff = b_coeff + a_coe(x)*a_val(a+1);
56.                     end
57.                     if(x==1)
58.                         b_coeff = b_coeff + b_coe(y)*b_val(b+1);
59.                     end
60.                     obj_mat = obj_mat + b_coeff*kron(MN_matrix(m,a,x),MN_matrix(m,b,y));
61.                 end
62.             end
63.         end
64.     end
65.     obj_mat = (obj_mat+obj_mat')/2; % avoids some numerical problems in CVX
66.     aux_mat = [1,0,0,0; 0,0,0,0; 0,0,0,0; 0,0,0,0];
67. 
68.     % Now construct the SDP that does the separability (really PPT)
69.     % optimization
70.     cvx_begin sdp quiet
71.         variable W(2^(2*m),2^(2*m)) hermitian;
72. 
73.         maximize trace(Swap(Swap(kron(Swap(W,[2,m+1],2*ones(1,2*m)),aux_mat),[m+1,2*m+1],2*ones(1,2*m+2)),[m+2,2*m+1],2*ones(1,2*m+2)) * obj_mat)
74. 
75.         subject to
76.             trace(W) == 1;
77.             W >= 0;
78. 
79.             % Now construct all of the different possible PPT constraints
80.             for sz = 1:(m-1)
81.                 ppt_partitions = nchoosek(1:(2*m-1),sz);
82.                 for j = 1:size(ppt_partitions,1)
83.                     PartialTranspose(W, ppt_partitions(j,:), [4,2*ones(1,2*(m-1))]) >= 0;
84.                 end
85.             end
86.     cvx_end
87.     rho = W;
88. 
89.     bmax = cvx_optval;
90. 
91.     % Deal with error messages.
92.     if(strcmpi(cvx_status,'Inaccurate/Solved'))
93.         warning('BellInequalityMaxQubits:NumericalProblems','Minor numerical problems encountered by CVX. Consider adjusting the tolerance level TOL and re-running the script.');
94.     elseif(strcmpi(cvx_status,'Inaccurate/Infeasible'))
95.         warning('BellInequalityMaxQubits:NumericalProblems','Minor numerical problems encountered by CVX. Consider adjusting the tolerance level TOL and re-running the script.');
96.     elseif(strcmpi(cvx_status,'Unbounded') || strcmpi(cvx_status,'Inaccurate/Unbounded') || strcmpi(cvx_status,'Failed'))
97.         error('BellInequalityMaxQubits:NumericalProblems',strcat('Numerical problems encountered (CVX status: ',cvx_status,'). Please try adjusting the tolerance level TOL.'));
98.     end
99. end
100. 
101. % This function computes the matrices M_a^x and N_b^y. Input arguments:
102. % M: the number of measurement settings for Alice and Bob
103. function MN = MN_matrix(m,a,x)
104.     perm = 1:(m+1);
105.     perm(1) = x+1;
106.     perm(x+1) = 1;
107. 
108.     MN = a*speye(2^(m+1)) + ((-1)^a)*PermutationOperator(2*ones(1,m+1), perm, 0, 1);
109. end

## References

1. M. Navascués, G. de la Torre, and T. Vértesi. Characterization of quantum correlations with local dimension constraints and its device-independent applications. Phys. Rev. X, 4:011011, 2014. E-print: arXiv:1308.3410 [quant-ph]
2. M. Froissart. Constructive generalization of Bell's inequalities. Nuov. Cim. B, 64:241, 1981
3. D. Collins and N. Gisin. A relevant two qubit Bell inequality inequivalent to the CHSH inequality. J. Phys. A: Math. Gen., 37(5):1175, 2004. E-print: arXiv:quant-ph/0306129