<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://qetlab.com/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Araujoms</id>
	<title>QETLAB - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://qetlab.com/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Araujoms"/>
	<link rel="alternate" type="text/html" href="https://qetlab.com/Special:Contributions/Araujoms"/>
	<updated>2026-06-05T07:01:13Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.3</generator>
	<entry>
		<id>https://qetlab.com/wiki/index.php?title=BellInequalityMax&amp;diff=35670</id>
		<title>BellInequalityMax</title>
		<link rel="alternate" type="text/html" href="https://qetlab.com/wiki/index.php?title=BellInequalityMax&amp;diff=35670"/>
		<updated>2022-11-14T13:32:21Z</updated>

		<summary type="html">&lt;p&gt;Araujoms: /* The I3322 inequality */ we need &amp;quot;cvx_precision high&amp;quot; for &amp;quot;format long&amp;quot; to make sense&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Function&lt;br /&gt;
|name=BellInequalityMax&lt;br /&gt;
|desc=Computes the maximum value of a Bell inequality&lt;br /&gt;
|rel=[[NPAHierarchy]]&amp;lt;br /&amp;gt;[[ParallelRepetition]]&amp;lt;br /&amp;gt;[[XORGameValue]]&lt;br /&gt;
|req=[http://cvxr.com/cvx/ CVX]&lt;br /&gt;
|cat=[[List of functions#Nonlocality_and_Bell_inequalities|Nonlocality and Bell inequalities]]&lt;br /&gt;
|upd=January 22, 2015&lt;br /&gt;
|cvx=no}}&lt;br /&gt;
&amp;lt;tt&amp;gt;'''BellInequalityMax'''&amp;lt;/tt&amp;gt; is a [[List of functions|function]] that computes the maximum possible value of a given [http://en.wikipedia.org/wiki/Bell%27s_theorem Bell inequality] or nonlocal game 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 [[NPAHierarchy|NPA hierarchy]]).&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION,MTYPE)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION,MTYPE,K)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Argument descriptions==&lt;br /&gt;
* &amp;lt;tt&amp;gt;COEFFICIENTS&amp;lt;/tt&amp;gt;: A matrix or tensor that specifies the coefficients of the Bell inequality in either full probability, full correlator, or Collins-Gisin notation.&lt;br /&gt;
* &amp;lt;tt&amp;gt;DESC&amp;lt;/tt&amp;gt;: A vector of 4 elements describing the number of outputs of Alice, number of outputs of Bob, number of inputs of Alice, and number of inputs of Bob, in this order.&lt;br /&gt;
* &amp;lt;tt&amp;gt;NOTATION&amp;lt;/tt&amp;gt;: A string indicating in which notation are the coefficients of the Bell inequality given. Must be one of &amp;lt;tt&amp;gt;'fp'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;'fc'&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;'cg'&amp;lt;/tt&amp;gt;, for full probability, full correlator, or Collins-Gisin, respectively.&lt;br /&gt;
* &amp;lt;tt&amp;gt;MTYPE&amp;lt;/tt&amp;gt; (optional, default &amp;lt;tt&amp;gt;'classical'&amp;lt;/tt&amp;gt;): A string indicating which type of theory should be used when computing the maximum value of the Bell inequality. Must be one of &amp;lt;tt&amp;gt;'classical'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;'quantum'&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;'nosignal'&amp;lt;/tt&amp;gt;. If &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt; then only an upper bound on the Bell inequality is computed, not necessarily is &amp;lt;em&amp;gt;best&amp;lt;/em&amp;gt; upper bound (see the argument &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; below).&lt;br /&gt;
* &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; (optional, default &amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt;): If &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt; then this is a positive integer indicating what level of the NPA hierarchy should be used when bounding the Bell inequality. Higher values of &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; give better bounds, but require more memory and time. Alternatively, &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; can be a string of a form like &amp;lt;tt&amp;gt;'1+ab+aab'&amp;lt;/tt&amp;gt;, 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 &amp;lt;tt&amp;gt;MTYPE&amp;lt;/tt&amp;gt; is anything other than &amp;lt;tt&amp;gt;'quantum'&amp;lt;/tt&amp;gt; then &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; has no effect.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===The CHSH inequality===&lt;br /&gt;
One formulation of the [http://en.wikipedia.org/wiki/CHSH_inequality CHSH inequality]&amp;lt;ref&amp;gt;J.F. Clauser, M.A. Horne, A. Shimony, R.A. Holt. Proposed experiment to test local hidden-variable theories. &amp;lt;em&amp;gt;Phys. Rev. Lett.&amp;lt;/em&amp;gt;, 23(15):880&amp;amp;ndash;884, 1969.&amp;lt;/ref&amp;gt; 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:&lt;br /&gt;
: &amp;lt;math&amp;gt;\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.&amp;lt;/math&amp;gt;&lt;br /&gt;
Similarly, the best bound on this quantity is $2\sqrt{2}$ in a quantum mechanical setting (this is [http://en.wikipedia.org/wiki/Tsirelson%27s_bound Tsirelson's bound])&amp;lt;ref&amp;gt;B.S. Tsirelson. Quantum generalizations of Bell's inequality. &amp;lt;em&amp;gt;Lett. Math. Phys.&amp;lt;/em&amp;gt;, 4:93, 1980. [http://www.tau.ac.il/~tsirel/download/qbell80.pdf E-print]&amp;lt;/ref&amp;gt;, and it is $4$ in no-signalling theories. All three of these bounds can be found as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 0 0;0 1 1;0 1 -1];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','classical')&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     2&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    2.8284&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The CHSH inequality again===&lt;br /&gt;
Another (equivalent) formulation of the CHSH inequality is in Collins-Gisin notation. We write in terms of only the probabilities of obtaining one of the outcomes, as the other probabilities are redundant given the normalization and no-signalling conditions. In this formulation, the following inequality holds in classical theories:&lt;br /&gt;
: &amp;lt;math&amp;gt; p(11|11) + p(11|12) + p(11|21) - p(11|22) - p_A(1|1) - p_B(1|1) \leq 0.&amp;lt;/math&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 -1 0; -1 1 1; 0 1 -1];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','classical')        &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     0&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.2071&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.5000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The CHSH game===&lt;br /&gt;
The CHSH inequality can be reformulated as a nonlocal game, as is favoured in computer science&amp;lt;ref&amp;gt;Richard Cleve, Peter Hoyer, Ben Toner, John Watrous. Consequences and Limits of Nonlocal Strategies. E-print: [http://arxiv.org/abs/quant-ph/0404076 arXiv:quant-ph/0404076]&amp;lt;/ref&amp;gt;. The rules of the game are as follows:&lt;br /&gt;
* A referee asks Alice a question $x \in \{0,1\}$ and Bob a question $y \in \{0,1\}$ with uniform probability.&lt;br /&gt;
* Alice and Bob then reply with answers $a \in \{0,1\}$ and $b \in \{0,1\}$ respectively.&lt;br /&gt;
* Alice and Bob win if and only if $a \oplus b = xy$.&lt;br /&gt;
The optimal probability with which Alice and Bob can win this game in classical, quantum, and no-signalling theories are as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = chshd(2);&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','classical')  &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.7500&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.8536&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The auxiliary function &amp;lt;tt&amp;gt;chshd()&amp;lt;/tt&amp;gt; above produces the predicate of the CHSH-d game, an intensively studied variant of the CHSH game that generalizes it to a larger alphabet. The rules are analogous, with the difference that each of $a,b,x,y$ are taken from the set $\{0,1,\ldots,d-1\}$ and sum is done modulo $d$.&amp;lt;ref&amp;gt;M. Howard. Maximum nonlocality and minimum uncertainty using magic states. E-print: [http://arxiv.org/abs/1501.05319 arXiv:arXiv:1501.05319] [quant-ph], 2015.&amp;lt;/ref&amp;gt; The algorithm used to calculate the classical bound is parallelized and slightly smarter than naïve brute force&amp;lt;ref&amp;gt;M. Araújo, F. Hirsch, and M. T. Quintino. Bell nonlocality with a single shot. E-print: [https://arxiv.org/abs/2005.13418 arXiv:2005.13418]&amp;lt;/ref&amp;gt;. It can handle up to $d=8$ quickly:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = chshd(8);                             &lt;br /&gt;
&amp;gt;&amp;gt; desc = [8 8 8 8];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','classical')&lt;br /&gt;
Starting parallel pool (parpool) using the 'local' profile ... connected to 2 workers.&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.4688&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===The I&amp;lt;sub&amp;gt;3322&amp;lt;/sub&amp;gt; inequality===&lt;br /&gt;
The I&amp;lt;sub&amp;gt;3322&amp;lt;/sub&amp;gt; inequality&amp;lt;ref&amp;gt;M. Froissart. Constructive generalization of Bell's inequalities. &amp;lt;em&amp;gt;Nuov. Cim. B&amp;lt;/em&amp;gt;, 64:241, 1981&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;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: [http://arxiv.org/abs/quant-ph/0306129 arXiv:quant-ph/0306129]&amp;lt;/ref&amp;gt; is a Bell inequality where each of Alice and Bob has three possible inputs and 2 possible outputs. Its symmetric version in Collins-Gisin notation is given by:&lt;br /&gt;
: &amp;lt;math&amp;gt;-p(11|11) - p(11|12) - p(11|13) - p(11|21) - p(11|22) + p(11|23) - p(11|31) + p(11|32) + p_A(1|1) + p_B(1|1) \leq 1.&amp;lt;/math&amp;gt;&lt;br /&gt;
Similarly, it is known that a value of (strictly) larger than $1+1/4$ is possible in quantum mechanics&amp;lt;ref name=&amp;quot;palvertes&amp;quot;&amp;gt;K.F. Pál and T. Vértesi. Maximal violation of a bipartite three-setting, two-outcome Bell inequality using infinite-dimensional quantum systems. &amp;lt;em&amp;gt;Phys. Rev. A&amp;lt;/em&amp;gt;, 82:022116, 2010. E-print: [http://arxiv.org/abs/1006.3032 arXiv:1006.3032] [quant-ph]&amp;lt;/ref&amp;gt;, and the best possible bound is $2$ 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:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; format long&lt;br /&gt;
&amp;gt;&amp;gt; cvx_precision high&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 1 0 0;1 -1 -1 -1;0 -1 -1 1;0 -1 1 0];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 3 3];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','classical')&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     1&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',1)&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.374999999999371&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum','1+ab')&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.251470897748553&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',2)&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.250939721643942&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',3)&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.250875562046812&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',4)&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.250875384515790&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','nosignal') &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We note that the values provided for the quantum upper bound above for &amp;lt;tt&amp;gt;K = '1+ab'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;K = 2&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;K = 3&amp;lt;/tt&amp;gt; agree with the values found in &amp;lt;ref name=&amp;quot;npa2&amp;quot;&amp;gt;M. Navascués, S. Pironio, and A. Acín. A convergent hierarchy of semidefinite programs characterizing the set of quantum correlations. '' New J. Phys.'', 10:073013, 2008. E-print: [http://arxiv.org/abs/0803.4290 arXiv:0803.4290] [quant-ph]&amp;lt;/ref&amp;gt; (subtracted 1 to account for the different form of the inequality). Furthermore, the value when &amp;lt;tt&amp;gt;K = 4&amp;lt;/tt&amp;gt; agrees with the value found in &amp;lt;ref name=&amp;quot;palvertes&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt;. The exact value of the best upper bound in the quantum setting is an open problem, but is known to be approximately $1.250875384514$.&lt;br /&gt;
{{SourceCode|name=BellInequalityMax}}&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
In practice, &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; probably can't be any larger than 4 when &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Araujoms</name></author>
	</entry>
	<entry>
		<id>https://qetlab.com/wiki/index.php?title=BellInequalityMax&amp;diff=35665</id>
		<title>BellInequalityMax</title>
		<link rel="alternate" type="text/html" href="https://qetlab.com/wiki/index.php?title=BellInequalityMax&amp;diff=35665"/>
		<updated>2022-11-11T12:40:35Z</updated>

		<summary type="html">&lt;p&gt;Araujoms: /* Argument descriptions */ K cannot be zero&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Function&lt;br /&gt;
|name=BellInequalityMax&lt;br /&gt;
|desc=Computes the maximum value of a Bell inequality&lt;br /&gt;
|rel=[[NPAHierarchy]]&amp;lt;br /&amp;gt;[[ParallelRepetition]]&amp;lt;br /&amp;gt;[[XORGameValue]]&lt;br /&gt;
|req=[http://cvxr.com/cvx/ CVX]&lt;br /&gt;
|cat=[[List of functions#Nonlocality_and_Bell_inequalities|Nonlocality and Bell inequalities]]&lt;br /&gt;
|upd=January 22, 2015&lt;br /&gt;
|cvx=no}}&lt;br /&gt;
&amp;lt;tt&amp;gt;'''BellInequalityMax'''&amp;lt;/tt&amp;gt; is a [[List of functions|function]] that computes the maximum possible value of a given [http://en.wikipedia.org/wiki/Bell%27s_theorem Bell inequality] or nonlocal game 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 [[NPAHierarchy|NPA hierarchy]]).&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION,MTYPE)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION,MTYPE,K)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Argument descriptions==&lt;br /&gt;
* &amp;lt;tt&amp;gt;COEFFICIENTS&amp;lt;/tt&amp;gt;: A matrix or tensor that specifies the coefficients of the Bell inequality in either full probability, full correlator, or Collins-Gisin notation.&lt;br /&gt;
* &amp;lt;tt&amp;gt;DESC&amp;lt;/tt&amp;gt;: A vector of 4 elements describing the number of outputs of Alice, number of outputs of Bob, number of inputs of Alice, and number of inputs of Bob, in this order.&lt;br /&gt;
* &amp;lt;tt&amp;gt;NOTATION&amp;lt;/tt&amp;gt;: A string indicating in which notation are the coefficients of the Bell inequality given. Must be one of &amp;lt;tt&amp;gt;'fp'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;'fc'&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;'cg'&amp;lt;/tt&amp;gt;, for full probability, full correlator, or Collins-Gisin, respectively.&lt;br /&gt;
* &amp;lt;tt&amp;gt;MTYPE&amp;lt;/tt&amp;gt; (optional, default &amp;lt;tt&amp;gt;'classical'&amp;lt;/tt&amp;gt;): A string indicating which type of theory should be used when computing the maximum value of the Bell inequality. Must be one of &amp;lt;tt&amp;gt;'classical'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;'quantum'&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;'nosignal'&amp;lt;/tt&amp;gt;. If &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt; then only an upper bound on the Bell inequality is computed, not necessarily is &amp;lt;em&amp;gt;best&amp;lt;/em&amp;gt; upper bound (see the argument &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; below).&lt;br /&gt;
* &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; (optional, default &amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt;): If &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt; then this is a positive integer indicating what level of the NPA hierarchy should be used when bounding the Bell inequality. Higher values of &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; give better bounds, but require more memory and time. Alternatively, &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; can be a string of a form like &amp;lt;tt&amp;gt;'1+ab+aab'&amp;lt;/tt&amp;gt;, 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 &amp;lt;tt&amp;gt;MTYPE&amp;lt;/tt&amp;gt; is anything other than &amp;lt;tt&amp;gt;'quantum'&amp;lt;/tt&amp;gt; then &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; has no effect.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===The CHSH inequality===&lt;br /&gt;
One formulation of the [http://en.wikipedia.org/wiki/CHSH_inequality CHSH inequality]&amp;lt;ref&amp;gt;J.F. Clauser, M.A. Horne, A. Shimony, R.A. Holt. Proposed experiment to test local hidden-variable theories. &amp;lt;em&amp;gt;Phys. Rev. Lett.&amp;lt;/em&amp;gt;, 23(15):880&amp;amp;ndash;884, 1969.&amp;lt;/ref&amp;gt; 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:&lt;br /&gt;
: &amp;lt;math&amp;gt;\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.&amp;lt;/math&amp;gt;&lt;br /&gt;
Similarly, the best bound on this quantity is $2\sqrt{2}$ in a quantum mechanical setting (this is [http://en.wikipedia.org/wiki/Tsirelson%27s_bound Tsirelson's bound])&amp;lt;ref&amp;gt;B.S. Tsirelson. Quantum generalizations of Bell's inequality. &amp;lt;em&amp;gt;Lett. Math. Phys.&amp;lt;/em&amp;gt;, 4:93, 1980. [http://www.tau.ac.il/~tsirel/download/qbell80.pdf E-print]&amp;lt;/ref&amp;gt;, and it is $4$ in no-signalling theories. All three of these bounds can be found as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 0 0;0 1 1;0 1 -1];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','classical')&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     2&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    2.8284&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The CHSH inequality again===&lt;br /&gt;
Another (equivalent) formulation of the CHSH inequality is in Collins-Gisin notation. We write in terms of only the probabilities of obtaining one of the outcomes, as the other probabilities are redundant given the normalization and no-signalling conditions. In this formulation, the following inequality holds in classical theories:&lt;br /&gt;
: &amp;lt;math&amp;gt; p(11|11) + p(11|12) + p(11|21) - p(11|22) - p_A(1|1) - p_B(1|1) \leq 0.&amp;lt;/math&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 -1 0; -1 1 1; 0 1 -1];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','classical')        &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     0&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.2071&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.5000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The CHSH game===&lt;br /&gt;
The CHSH inequality can be reformulated as a nonlocal game, as is favoured in computer science&amp;lt;ref&amp;gt;Richard Cleve, Peter Hoyer, Ben Toner, John Watrous. Consequences and Limits of Nonlocal Strategies. E-print: [http://arxiv.org/abs/quant-ph/0404076 arXiv:quant-ph/0404076]&amp;lt;/ref&amp;gt;. The rules of the game are as follows:&lt;br /&gt;
* A referee asks Alice a question $x \in \{0,1\}$ and Bob a question $y \in \{0,1\}$ with uniform probability.&lt;br /&gt;
* Alice and Bob then reply with answers $a \in \{0,1\}$ and $b \in \{0,1\}$ respectively.&lt;br /&gt;
* Alice and Bob win if and only if $a \oplus b = xy$.&lt;br /&gt;
The optimal probability with which Alice and Bob can win this game in classical, quantum, and no-signalling theories are as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = chshd(2);&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','classical')  &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.7500&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.8536&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The auxiliary function &amp;lt;tt&amp;gt;chshd()&amp;lt;/tt&amp;gt; above produces the predicate of the CHSH-d game, an intensively studied variant of the CHSH game that generalizes it to a larger alphabet. The rules are analogous, with the difference that each of $a,b,x,y$ are taken from the set $\{0,1,\ldots,d-1\}$ and sum is done modulo $d$.&amp;lt;ref&amp;gt;M. Howard. Maximum nonlocality and minimum uncertainty using magic states. E-print: [http://arxiv.org/abs/1501.05319 arXiv:arXiv:1501.05319] [quant-ph], 2015.&amp;lt;/ref&amp;gt; The algorithm used to calculate the classical bound is parallelized and slightly smarter than naïve brute force&amp;lt;ref&amp;gt;M. Araújo, F. Hirsch, and M. T. Quintino. Bell nonlocality with a single shot. E-print: [https://arxiv.org/abs/2005.13418 arXiv:2005.13418]&amp;lt;/ref&amp;gt;. It can handle up to $d=8$ quickly:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = chshd(8);                             &lt;br /&gt;
&amp;gt;&amp;gt; desc = [8 8 8 8];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','classical')&lt;br /&gt;
Starting parallel pool (parpool) using the 'local' profile ... connected to 2 workers.&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.4688&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===The I&amp;lt;sub&amp;gt;3322&amp;lt;/sub&amp;gt; inequality===&lt;br /&gt;
The I&amp;lt;sub&amp;gt;3322&amp;lt;/sub&amp;gt; inequality&amp;lt;ref&amp;gt;M. Froissart. Constructive generalization of Bell's inequalities. &amp;lt;em&amp;gt;Nuov. Cim. B&amp;lt;/em&amp;gt;, 64:241, 1981&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;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: [http://arxiv.org/abs/quant-ph/0306129 arXiv:quant-ph/0306129]&amp;lt;/ref&amp;gt; is a Bell inequality where each of Alice and Bob has three possible inputs and 2 possible outputs. Its symmetric version in Collins-Gisin notation is given by:&lt;br /&gt;
: &amp;lt;math&amp;gt;-p(11|11) - p(11|12) - p(11|13) - p(11|21) - p(11|22) + p(11|23) - p(11|31) + p(11|32) + p_A(1|1) + p_B(1|1) \leq 1.&amp;lt;/math&amp;gt;&lt;br /&gt;
Similarly, it is known that a value of (strictly) larger than $1+1/4$ is possible in quantum mechanics&amp;lt;ref name=&amp;quot;palvertes&amp;quot;&amp;gt;K.F. Pál and T. Vértesi. Maximal violation of a bipartite three-setting, two-outcome Bell inequality using infinite-dimensional quantum systems. &amp;lt;em&amp;gt;Phys. Rev. A&amp;lt;/em&amp;gt;, 82:022116, 2010. E-print: [http://arxiv.org/abs/1006.3032 arXiv:1006.3032] [quant-ph]&amp;lt;/ref&amp;gt;, and the best possible bound is $2$ 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:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; format long&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 1 0 0;1 -1 -1 -1;0 -1 -1 1;0 -1 1 0];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 3 3];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','classical')                             &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     1&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',1)       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.374999892449922&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum','1+ab')&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.251470917522884&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',2)      &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.250939790350636&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',3)&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.250875663436317&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',4)&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.250875380616149&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','nosignal')          &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   2.000000000005738&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We note that the values provided for the quantum upper bound above for &amp;lt;tt&amp;gt;K = '1+ab'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;K = 2&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;K = 3&amp;lt;/tt&amp;gt; agree with the values found in &amp;lt;ref name=&amp;quot;npa2&amp;quot;&amp;gt;M. Navascués, S. Pironio, and A. Acín. A convergent hierarchy of semidefinite programs characterizing the set of quantum correlations. '' New J. Phys.'', 10:073013, 2008. E-print: [http://arxiv.org/abs/0803.4290 arXiv:0803.4290] [quant-ph]&amp;lt;/ref&amp;gt; (subtracted 1 to account for the different form of the inequality). Furthermore, the value when &amp;lt;tt&amp;gt;K = 4&amp;lt;/tt&amp;gt; agrees with the value found in &amp;lt;ref name=&amp;quot;palvertes&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt;. The exact value of the best upper bound in the quantum setting is an open problem, but is known to be approximately $1.250875$.&lt;br /&gt;
{{SourceCode|name=BellInequalityMax}}&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
In practice, &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; probably can't be any larger than 4 when &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Araujoms</name></author>
	</entry>
	<entry>
		<id>https://qetlab.com/wiki/index.php?title=NPAHierarchy&amp;diff=35664</id>
		<title>NPAHierarchy</title>
		<link rel="alternate" type="text/html" href="https://qetlab.com/wiki/index.php?title=NPAHierarchy&amp;diff=35664"/>
		<updated>2022-11-11T12:39:56Z</updated>

		<summary type="html">&lt;p&gt;Araujoms: /* Argument descriptions */ K=0 doesn't exist anymore&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Function&lt;br /&gt;
|name=NPAHierarchy&lt;br /&gt;
|desc=Determines whether or not a set of probabilities satisfy the conditions of the NPA hierarchy&lt;br /&gt;
|rel=[[BellInequalityMax]]&amp;lt;br /&amp;gt;[[XORGameValue]]&lt;br /&gt;
|req=[http://cvxr.com/cvx/ CVX]&lt;br /&gt;
|cat=[[List of functions#Nonlocality_and_Bell_inequalities|Nonlocality and Bell inequalities]]&lt;br /&gt;
|upd=November 11, 2022&lt;br /&gt;
|cvx=yes (concave)}}&lt;br /&gt;
&amp;lt;tt&amp;gt;'''NPAHierarchy'''&amp;lt;/tt&amp;gt; is a [[List of functions|function]] that determines whether or not a given set of probabilities satisfy the constraints specified by the NPA hierarchy&amp;lt;ref name=&amp;quot;npa&amp;quot;&amp;gt;M. Navascués, S. Pironio, and A. Acín. Bounding the set of quantum correlations. ''Phys. Rev. Lett.'', 98:010401, 2007. E-print: [http://arxiv.org/abs/quant-ph/0607119/ arXiv:quant-ph/0607119]&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;npa2&amp;quot;&amp;gt;M. Navascués, S. Pironio, and A. Acín. A convergent hierarchy of semidefinite programs characterizing the set of quantum correlations. '' New J. Phys.'', 10:073013, 2008. E-print: [http://arxiv.org/abs/0803.4290 arXiv:0803.4290] [quant-ph]&amp;lt;/ref&amp;gt;, which are a set of necessary conditions that probabilities arising from quantum mechanics must satisfy. That is, given a set of probabilities $\{p(a,b|x,y)\}$, this function tries to determine whether or not there is a quantum state $\rho$ shared between Alice and Bob, and sets of measurement operators $\{M_{a|x}\}$ for Alice and $\{M_{b|y}\}$ for Bob such that $p(a,b|x,y) = \mathrm{Tr}(\rho(M_{a|x} \otimes M_{b|y}))$ for all $a,b,x,y$ (here $x$ indexes the different measurement settings for Alice, while $a$ indexes the different measurement outcomes within that setting, and similarly for $y$ and $b$ for Bob).&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
* &amp;lt;tt&amp;gt;IS_NPA = NPAHierarchy(P,desc)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;IS_NPA = NPAHierarchy(P,desc,K)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Argument descriptions==&lt;br /&gt;
* &amp;lt;tt&amp;gt;P&amp;lt;/tt&amp;gt;: A behaviour in Collins-Gisin notation. That is, a matrix with components&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{pmatrix}&lt;br /&gt;
1 &amp;amp; p_B(0|0) &amp;amp; p_B(1|0) &amp;amp; \ldots &amp;amp; p_B(0|1) &amp;amp; p_B(1|1) &amp;amp; \ldots \\&lt;br /&gt;
p_A(0|0) &amp;amp; p(00|00) &amp;amp; p(01|00) &amp;amp; \ldots &amp;amp; p(00|01) &amp;amp; p(01|01) &amp;amp;\ldots \\&lt;br /&gt;
p_A(1|0) &amp;amp; p(10|00) &amp;amp; p(11|00) &amp;amp; \ldots &amp;amp; p(10|01) &amp;amp; p(11|01) &amp;amp;\ldots \\&lt;br /&gt;
\vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp;\vdots \\&lt;br /&gt;
p_A(0|1) &amp;amp; p(00|10) &amp;amp; p(01|10) &amp;amp; \ldots &amp;amp; p(00|11) &amp;amp; p(01|11) &amp;amp;\ldots \\&lt;br /&gt;
p_A(1|1) &amp;amp; p(10|10) &amp;amp; p(11|10) &amp;amp; \ldots &amp;amp; p(10|11) &amp;amp; p(11|11) &amp;amp;\ldots \\&lt;br /&gt;
\vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp;\ddots \\&lt;br /&gt;
\end{pmatrix}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;DESC&amp;lt;/tt&amp;gt;: A vector of 4 elements describing the number of outputs of Alice, number of outputs of Bob, number of inputs of Alice, and number of inputs of Bob, in this order.&lt;br /&gt;
* &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; (optional, default 1): A positive integer that determines the level of the NPA hierarchy to use. Alternatively, &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===Can be used within CVX===&lt;br /&gt;
Within CVX, this function is treated as any other concave function (so you can use it as an equality or &amp;lt;tt&amp;gt;&amp;gt;=&amp;lt;/tt&amp;gt; constraint, or maximize it subject to other constraints). It is used inside the function [[BellInequalityMax]] to upperbound the Tsirelson bound. One can use it to maximize a Bell inequality subject to further constraints, or to determine whether a behaviour belongs to the quantum set of correlations.&lt;br /&gt;
&lt;br /&gt;
For example, one might wonder what is the maximal violation of the CHSH inequality if Alice and Bob obtain equal outcomes with probability 1 in one of the settings. Translating into Collins-Gisin notation, this is the condition that &amp;lt;math&amp;gt;2p(00|xy) = p_A(0|x) + p_B(0|y)&amp;lt;/math&amp;gt; for some x,y.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; B = [0, -1, 0; -1, 1, 1; 0, 1, -1]; %CHSH functional in Collins-Gisin form&lt;br /&gt;
   desc = [2 2 2 2];&lt;br /&gt;
   cvx_begin&lt;br /&gt;
   variable p(3,3);&lt;br /&gt;
   objective = B(:)'*p(:);&lt;br /&gt;
   maximize objective&lt;br /&gt;
   subject to&lt;br /&gt;
	p(1,1) == 1; %the top left element of the behaviour must always be equal to 1&lt;br /&gt;
	NPAHierarchy(p,desc,2) == 1; %here we impose level 2 of the NPA hierarchy&lt;br /&gt;
	2*p(2,2) == p(1,2) + p(2,1); %this is the constraint that Alice and Bob have equal outcomes&lt;br /&gt;
   cvx_end&lt;br /&gt;
&lt;br /&gt;
Optimal value (cvx_optval): +0.125009&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One can see that the SDP solver runs into numerical problems and delivers a solution that is not so close to the analytical one, 1/8. This is not a problem with the code, but a fundamental problem with semidefinite programming: this problem is not strictly feasible, and the interior-point algorithms relies on strict feasibility to obtain a reliable solution. In order to obtain a reliable solution numerically one needs to reformulate the problem to make it strictly feasible, for example using facial reduction&amp;lt;ref&amp;gt;Dmitriy Drusvyatskiy, Henry Wolkowicz. The many faces of degeneracy in conic optimization. E-print: [http://arxiv.org/abs/1706.03705 arXiv:1706.03705]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In order to test whether a given behaviour belongs to the quantum set, one must also be careful to formulate the problem in a strictly feasible way. One way to do that is ask how much of the uniformly random behaviour must be mixed with P in order to make it fall into the quantum set. If the answer is zero, it means that the behaviour was already quantum. The following code shows that the PR-box is not in the quantum set:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; prbox = [2, 1, 1;1, 1, 1;1,1,0]/2; %PR box&lt;br /&gt;
   p_random = [4, 2, 2;2, 1, 1;2, 1, 1]/4; %uniformly random behaviour&lt;br /&gt;
   desc = [2 2 2 2];&lt;br /&gt;
   cvx_begin&lt;br /&gt;
   variable lambda;&lt;br /&gt;
   minimize lambda;&lt;br /&gt;
   subject to&lt;br /&gt;
	NPAHierarchy(lambda*p_random + (1-lambda)*prbox,desc,2) == 1;&lt;br /&gt;
   cvx_end&lt;br /&gt;
&lt;br /&gt;
Optimal value (cvx_optval): +0.292893&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{SourceCode|name=NPAHierarchy}}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Araujoms</name></author>
	</entry>
	<entry>
		<id>https://qetlab.com/wiki/index.php?title=ParallelRepetition&amp;diff=35663</id>
		<title>ParallelRepetition</title>
		<link rel="alternate" type="text/html" href="https://qetlab.com/wiki/index.php?title=ParallelRepetition&amp;diff=35663"/>
		<updated>2022-11-11T12:39:14Z</updated>

		<summary type="html">&lt;p&gt;Araujoms: created page to document new&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Function&lt;br /&gt;
|name=ParallelRepetition&lt;br /&gt;
|desc=Computes coefficients of parallel repetition of a nonlocal game&lt;br /&gt;
|rel=[[BCSGameValue]]&amp;lt;br /&amp;gt;[[BellInequalityMax]]&amp;lt;br /&amp;gt;[[NPAHierarchy]]&amp;lt;br /&amp;gt;[[XORGameValue]]&lt;br /&gt;
|req=[http://cvxr.com/cvx/ CVX]&lt;br /&gt;
|cat=[[List of functions#Nonlocality_and_Bell_inequalities|Nonlocality and Bell inequalities]]&lt;br /&gt;
|upd=March 6, 2015&lt;br /&gt;
|cvx=no}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;'''ParallelRepetition'''&amp;lt;/tt&amp;gt; is a [[List of functions|function]] that generates the coefficients of the parallel repetition of a nonlocal game, a concept widely used in computer science.&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
* &amp;lt;tt&amp;gt;NGVAL = NonlocalGameValue(G,REPT)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Argument descriptions==&lt;br /&gt;
* &amp;lt;tt&amp;gt;G&amp;lt;/tt&amp;gt;: A 4-D array whose $(a,b,x,y)$-entry gives the coefficient needed to compute the probability of winning the nonlocal game. It is defined as &amp;lt;math&amp;gt;G(a,b,x,y) = \mu(x,y)V(a,b,x,y)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;\mu(x,y)&amp;lt;/math&amp;gt; is the probability that the referee asks Alice question $x$ and Bob question $y$, and V(a,b,x,y) is the probability Alice and Bob win the game if they reply with answers $(a,b)$ to questions $(x,y)$.&lt;br /&gt;
* &amp;lt;tt&amp;gt;REPT&amp;lt;/tt&amp;gt;: A positive integer indicating the number of parallel copies of the nonlocal game.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===The CHSH game===&lt;br /&gt;
A well-known result is that the parallel repetition of the CHSH game has local bound higher then the product of the local bounds&amp;lt;ref&amp;gt;J. Barrett, D. Collins, L. Hardy, A. Kent and S. Popescu. ‘Quantum nonlocality, Bell inequalities, and the memory loophole’. Physical Review A 66 042111 (2002). [http://arxiv.org/abs/quant-ph/0205016 arXiv:quant-ph/0205016]&amp;lt;/ref&amp;gt;. We can do 2 parallel repetitions:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; G = chshd(2);                &lt;br /&gt;
&amp;gt;&amp;gt; G2 = ParallelRepetition(G,2);&lt;br /&gt;
&amp;gt;&amp;gt; desc = size(G2);&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(G2,desc,'fp','classical')&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.6250&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
We see that the local bound is 10/16, which is larger than &amp;lt;math&amp;gt;(3/4)^2&amp;lt;/math&amp;gt;. We can also do 3 parallel repetitions:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; G = chshd(2);                &lt;br /&gt;
&amp;gt;&amp;gt; G3 = ParallelRepetition(G,3);&lt;br /&gt;
&amp;gt;&amp;gt; desc = size(G3);&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(G3,desc,'fp','classical')&lt;br /&gt;
Starting parallel pool (parpool) using the 'local' profile ...&lt;br /&gt;
connected to 2 workers.&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.4844&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
We see that the local bound is 31/64, which is larger than &amp;lt;math&amp;gt;(3/4)^3&amp;lt;/math&amp;gt;. The code cannot handle 4 or more parallel repetitions.&lt;br /&gt;
&lt;br /&gt;
===The Fortnow-Feige-Lovász game===&lt;br /&gt;
The Fortnow-Feige-Lovász (FFL) game&amp;lt;ref&amp;gt;U. Feige, L. Lovász, In Proceedings of the 24th ACM STOC, pages 733-744, 1992.&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;L. Fortnow, PhD thesis, Massachusetts Institute of Technology, Technical Report MIT/LCS/TR-447, May 1989.&amp;lt;/ref&amp;gt; is well-known example of a non-local game for which perfect parallel repetition does not hold (i.e., quantum players playing two copies of the game in parallel can do better than they can by playing the games in succession).&lt;br /&gt;
&lt;br /&gt;
The game has binary inputs and outputs, and is defined by the rule that the referee asks Alice and Bob the question pair $(x,y) = (0,0)$, $(0,1)$, or $(1,0)$ with probability $1/3$ each, and Alice and Bob win if and only if their answers satisfy $x \vee a \neq y \vee b$, where $\vee$ denotes the bitwise OR operation.&lt;br /&gt;
&lt;br /&gt;
It is known that both the classical value and quantum value of this game equal $2/3$, which we can verify as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; G = ffl();                   &lt;br /&gt;
&amp;gt;&amp;gt; desc = size(G);&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(G,desc,'fp','classical') &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.6667&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(G,desc,'fp','quantum',2)       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.6667&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The FFL game is interesting because the classical value of two parallel repetitions is still $2/3$:&amp;lt;ref&amp;gt;R. Cleve, W. Slofstra, F. Unger, and S. Upadhyay. Perfect parallel repetition theorem for quantum XOR proof systems. ''Computational Complexity'', 17:282&amp;amp;ndash;299, 2008. E-print: [http://arxiv.org/abs/quant-ph/0608146 arXiv:quant-ph/0608146]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; G = ffl();                   &lt;br /&gt;
&amp;gt;&amp;gt; G2 = ParallelRepetition(G,2);&lt;br /&gt;
&amp;gt;&amp;gt; desc = size(G2);&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(G2,desc,'fp','classical')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.6667&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
We can also compute the classical value of three parallel repetitions, which decreases to $14/27$:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; G = ffl();                   &lt;br /&gt;
&amp;gt;&amp;gt; G3 = ParallelRepetition(G,3);&lt;br /&gt;
&amp;gt;&amp;gt; desc = size(G3);&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(G3,desc,'fp','classical')&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.5185&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{SourceCode|name=ParallelRepetition}}&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
* The algorithm for computing the classical value is parallelized, which leads to much faster performance on computers with multiple CPUs. Nevertheless, the complexity is still superexponential in &amp;lt;tt&amp;gt;REPT&amp;lt;/tt&amp;gt;, making 4 or more parallel repetitions intractable.&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Araujoms</name></author>
	</entry>
	<entry>
		<id>https://qetlab.com/wiki/index.php?title=NPAHierarchy&amp;diff=35662</id>
		<title>NPAHierarchy</title>
		<link rel="alternate" type="text/html" href="https://qetlab.com/wiki/index.php?title=NPAHierarchy&amp;diff=35662"/>
		<updated>2022-11-11T11:13:35Z</updated>

		<summary type="html">&lt;p&gt;Araujoms: update page to reflect new code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Function&lt;br /&gt;
|name=NPAHierarchy&lt;br /&gt;
|desc=Determines whether or not a set of probabilities satisfy the conditions of the NPA hierarchy&lt;br /&gt;
|rel=[[BellInequalityMax]]&amp;lt;br /&amp;gt;[[XORGameValue]]&lt;br /&gt;
|req=[http://cvxr.com/cvx/ CVX]&lt;br /&gt;
|cat=[[List of functions#Nonlocality_and_Bell_inequalities|Nonlocality and Bell inequalities]]&lt;br /&gt;
|upd=November 11, 2022&lt;br /&gt;
|cvx=yes (concave)}}&lt;br /&gt;
&amp;lt;tt&amp;gt;'''NPAHierarchy'''&amp;lt;/tt&amp;gt; is a [[List of functions|function]] that determines whether or not a given set of probabilities satisfy the constraints specified by the NPA hierarchy&amp;lt;ref name=&amp;quot;npa&amp;quot;&amp;gt;M. Navascués, S. Pironio, and A. Acín. Bounding the set of quantum correlations. ''Phys. Rev. Lett.'', 98:010401, 2007. E-print: [http://arxiv.org/abs/quant-ph/0607119/ arXiv:quant-ph/0607119]&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;npa2&amp;quot;&amp;gt;M. Navascués, S. Pironio, and A. Acín. A convergent hierarchy of semidefinite programs characterizing the set of quantum correlations. '' New J. Phys.'', 10:073013, 2008. E-print: [http://arxiv.org/abs/0803.4290 arXiv:0803.4290] [quant-ph]&amp;lt;/ref&amp;gt;, which are a set of necessary conditions that probabilities arising from quantum mechanics must satisfy. That is, given a set of probabilities $\{p(a,b|x,y)\}$, this function tries to determine whether or not there is a quantum state $\rho$ shared between Alice and Bob, and sets of measurement operators $\{M_{a|x}\}$ for Alice and $\{M_{b|y}\}$ for Bob such that $p(a,b|x,y) = \mathrm{Tr}(\rho(M_{a|x} \otimes M_{b|y}))$ for all $a,b,x,y$ (here $x$ indexes the different measurement settings for Alice, while $a$ indexes the different measurement outcomes within that setting, and similarly for $y$ and $b$ for Bob).&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
* &amp;lt;tt&amp;gt;IS_NPA = NPAHierarchy(P,desc)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;IS_NPA = NPAHierarchy(P,desc,K)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Argument descriptions==&lt;br /&gt;
* &amp;lt;tt&amp;gt;P&amp;lt;/tt&amp;gt;: A behaviour in Collins-Gisin notation. That is, a matrix with components&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{pmatrix}&lt;br /&gt;
1 &amp;amp; p_B(0|0) &amp;amp; p_B(1|0) &amp;amp; \ldots &amp;amp; p_B(0|1) &amp;amp; p_B(1|1) &amp;amp; \ldots \\&lt;br /&gt;
p_A(0|0) &amp;amp; p(00|00) &amp;amp; p(01|00) &amp;amp; \ldots &amp;amp; p(00|01) &amp;amp; p(01|01) &amp;amp;\ldots \\&lt;br /&gt;
p_A(1|0) &amp;amp; p(10|00) &amp;amp; p(11|00) &amp;amp; \ldots &amp;amp; p(10|01) &amp;amp; p(11|01) &amp;amp;\ldots \\&lt;br /&gt;
\vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp;\vdots \\&lt;br /&gt;
p_A(0|1) &amp;amp; p(00|10) &amp;amp; p(01|10) &amp;amp; \ldots &amp;amp; p(00|11) &amp;amp; p(01|11) &amp;amp;\ldots \\&lt;br /&gt;
p_A(1|1) &amp;amp; p(10|10) &amp;amp; p(11|10) &amp;amp; \ldots &amp;amp; p(10|11) &amp;amp; p(11|11) &amp;amp;\ldots \\&lt;br /&gt;
\vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp; \vdots &amp;amp;\ddots \\&lt;br /&gt;
\end{pmatrix}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;DESC&amp;lt;/tt&amp;gt;: A vector of 4 elements describing the number of outputs of Alice, number of outputs of Bob, number of inputs of Alice, and number of inputs of Bob, in this order.&lt;br /&gt;
* &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; (optional, default 1): A non-negative integer that determines the level of the NPA hierarchy to use. Alternatively, &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===Can be used within CVX===&lt;br /&gt;
Within CVX, this function is treated as any other concave function (so you can use it as an equality or &amp;lt;tt&amp;gt;&amp;gt;=&amp;lt;/tt&amp;gt; constraint, or maximize it subject to other constraints). It is used inside the function [[BellInequalityMax]] to upperbound the Tsirelson bound. One can use it to maximize a Bell inequality subject to further constraints, or to determine whether a behaviour belongs to the quantum set of correlations.&lt;br /&gt;
&lt;br /&gt;
For example, one might wonder what is the maximal violation of the CHSH inequality if Alice and Bob obtain equal outcomes with probability 1 in one of the settings. Translating into Collins-Gisin notation, this is the condition that &amp;lt;math&amp;gt;2p(00|xy) = p_A(0|x) + p_B(0|y)&amp;lt;/math&amp;gt; for some x,y.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; B = [0, -1, 0; -1, 1, 1; 0, 1, -1]; %CHSH functional in Collins-Gisin form&lt;br /&gt;
   desc = [2 2 2 2];&lt;br /&gt;
   cvx_begin&lt;br /&gt;
   variable p(3,3);&lt;br /&gt;
   objective = B(:)'*p(:);&lt;br /&gt;
   maximize objective&lt;br /&gt;
   subject to&lt;br /&gt;
	p(1,1) == 1; %the top left element of the behaviour must always be equal to 1&lt;br /&gt;
	NPAHierarchy(p,desc,2) == 1; %here we impose level 2 of the NPA hierarchy&lt;br /&gt;
	2*p(2,2) == p(1,2) + p(2,1); %this is the constraint that Alice and Bob have equal outcomes&lt;br /&gt;
   cvx_end&lt;br /&gt;
&lt;br /&gt;
Optimal value (cvx_optval): +0.125009&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One can see that the SDP solver runs into numerical problems and delivers a solution that is not so close to the analytical one, 1/8. This is not a problem with the code, but a fundamental problem with semidefinite programming: this problem is not strictly feasible, and the interior-point algorithms relies on strict feasibility to obtain a reliable solution. In order to obtain a reliable solution numerically one needs to reformulate the problem to make it strictly feasible, for example using facial reduction&amp;lt;ref&amp;gt;Dmitriy Drusvyatskiy, Henry Wolkowicz. The many faces of degeneracy in conic optimization. E-print: [http://arxiv.org/abs/1706.03705 arXiv:1706.03705]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In order to test whether a given behaviour belongs to the quantum set, one must also be careful to formulate the problem in a strictly feasible way. One way to do that is ask how much of the uniformly random behaviour must be mixed with P in order to make it fall into the quantum set. If the answer is zero, it means that the behaviour was already quantum. The following code shows that the PR-box is not in the quantum set:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; prbox = [2, 1, 1;1, 1, 1;1,1,0]/2; %PR box&lt;br /&gt;
   p_random = [4, 2, 2;2, 1, 1;2, 1, 1]/4; %uniformly random behaviour&lt;br /&gt;
   desc = [2 2 2 2];&lt;br /&gt;
   cvx_begin&lt;br /&gt;
   variable lambda;&lt;br /&gt;
   minimize lambda;&lt;br /&gt;
   subject to&lt;br /&gt;
	NPAHierarchy(lambda*p_random + (1-lambda)*prbox,desc,2) == 1;&lt;br /&gt;
   cvx_end&lt;br /&gt;
&lt;br /&gt;
Optimal value (cvx_optval): +0.292893&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{SourceCode|name=NPAHierarchy}}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Araujoms</name></author>
	</entry>
	<entry>
		<id>https://qetlab.com/wiki/index.php?title=BellInequalityMax&amp;diff=35660</id>
		<title>BellInequalityMax</title>
		<link rel="alternate" type="text/html" href="https://qetlab.com/wiki/index.php?title=BellInequalityMax&amp;diff=35660"/>
		<updated>2022-11-10T11:23:07Z</updated>

		<summary type="html">&lt;p&gt;Araujoms: /* The I3322 inequality */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Function&lt;br /&gt;
|name=BellInequalityMax&lt;br /&gt;
|desc=Computes the maximum value of a Bell inequality&lt;br /&gt;
|rel=[[NPAHierarchy]]&amp;lt;br /&amp;gt;[[ParallelRepetition]]&amp;lt;br /&amp;gt;[[XORGameValue]]&lt;br /&gt;
|req=[http://cvxr.com/cvx/ CVX]&lt;br /&gt;
|cat=[[List of functions#Nonlocality_and_Bell_inequalities|Nonlocality and Bell inequalities]]&lt;br /&gt;
|upd=January 22, 2015&lt;br /&gt;
|cvx=no}}&lt;br /&gt;
&amp;lt;tt&amp;gt;'''BellInequalityMax'''&amp;lt;/tt&amp;gt; is a [[List of functions|function]] that computes the maximum possible value of a given [http://en.wikipedia.org/wiki/Bell%27s_theorem Bell inequality] or nonlocal game 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 [[NPAHierarchy|NPA hierarchy]]).&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION,MTYPE)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION,MTYPE,K)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Argument descriptions==&lt;br /&gt;
* &amp;lt;tt&amp;gt;COEFFICIENTS&amp;lt;/tt&amp;gt;: A matrix or tensor that specifies the coefficients of the Bell inequality in either full probability, full correlator, or Collins-Gisin notation.&lt;br /&gt;
* &amp;lt;tt&amp;gt;DESC&amp;lt;/tt&amp;gt;: A vector of 4 elements describing the number of outputs of Alice, number of outputs of Bob, number of inputs of Alice, and number of inputs of Bob, in this order.&lt;br /&gt;
* &amp;lt;tt&amp;gt;NOTATION&amp;lt;/tt&amp;gt;: A string indicating in which notation are the coefficients of the Bell inequality given. Must be one of &amp;lt;tt&amp;gt;'fp'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;'fc'&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;'cg'&amp;lt;/tt&amp;gt;, for full probability, full correlator, or Collins-Gisin, respectively.&lt;br /&gt;
* &amp;lt;tt&amp;gt;MTYPE&amp;lt;/tt&amp;gt; (optional, default &amp;lt;tt&amp;gt;'classical'&amp;lt;/tt&amp;gt;): A string indicating which type of theory should be used when computing the maximum value of the Bell inequality. Must be one of &amp;lt;tt&amp;gt;'classical'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;'quantum'&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;'nosignal'&amp;lt;/tt&amp;gt;. If &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt; then only an upper bound on the Bell inequality is computed, not necessarily is &amp;lt;em&amp;gt;best&amp;lt;/em&amp;gt; upper bound (see the argument &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; below).&lt;br /&gt;
* &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; (optional, default &amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt;): If &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt; 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 &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; give better bounds, but require more memory and time. Alternatively, &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; can be a string of a form like &amp;lt;tt&amp;gt;'1+ab+aab'&amp;lt;/tt&amp;gt;, 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 &amp;lt;tt&amp;gt;MTYPE&amp;lt;/tt&amp;gt; is anything other than &amp;lt;tt&amp;gt;'quantum'&amp;lt;/tt&amp;gt; then &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; has no effect.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===The CHSH inequality===&lt;br /&gt;
One formulation of the [http://en.wikipedia.org/wiki/CHSH_inequality CHSH inequality]&amp;lt;ref&amp;gt;J.F. Clauser, M.A. Horne, A. Shimony, R.A. Holt. Proposed experiment to test local hidden-variable theories. &amp;lt;em&amp;gt;Phys. Rev. Lett.&amp;lt;/em&amp;gt;, 23(15):880&amp;amp;ndash;884, 1969.&amp;lt;/ref&amp;gt; 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:&lt;br /&gt;
: &amp;lt;math&amp;gt;\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.&amp;lt;/math&amp;gt;&lt;br /&gt;
Similarly, the best bound on this quantity is $2\sqrt{2}$ in a quantum mechanical setting (this is [http://en.wikipedia.org/wiki/Tsirelson%27s_bound Tsirelson's bound])&amp;lt;ref&amp;gt;B.S. Tsirelson. Quantum generalizations of Bell's inequality. &amp;lt;em&amp;gt;Lett. Math. Phys.&amp;lt;/em&amp;gt;, 4:93, 1980. [http://www.tau.ac.il/~tsirel/download/qbell80.pdf E-print]&amp;lt;/ref&amp;gt;, and it is $4$ in no-signalling theories. All three of these bounds can be found as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 0 0;0 1 1;0 1 -1];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','classical')&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     2&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    2.8284&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The CHSH inequality again===&lt;br /&gt;
Another (equivalent) formulation of the CHSH inequality is in Collins-Gisin notation. We write in terms of only the probabilities of obtaining one of the outcomes, as the other probabilities are redundant given the normalization and no-signalling conditions. In this formulation, the following inequality holds in classical theories:&lt;br /&gt;
: &amp;lt;math&amp;gt; p(11|11) + p(11|12) + p(11|21) - p(11|22) - p_A(1|1) - p_B(1|1) \leq 0.&amp;lt;/math&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 -1 0; -1 1 1; 0 1 -1];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','classical')        &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     0&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.2071&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.5000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The CHSH game===&lt;br /&gt;
The CHSH inequality can be reformulated as a nonlocal game, as is favoured in computer science&amp;lt;ref&amp;gt;Richard Cleve, Peter Hoyer, Ben Toner, John Watrous. Consequences and Limits of Nonlocal Strategies. E-print: [http://arxiv.org/abs/quant-ph/0404076 arXiv:quant-ph/0404076]&amp;lt;/ref&amp;gt;. The rules of the game are as follows:&lt;br /&gt;
* A referee asks Alice a question $x \in \{0,1\}$ and Bob a question $y \in \{0,1\}$ with uniform probability.&lt;br /&gt;
* Alice and Bob then reply with answers $a \in \{0,1\}$ and $b \in \{0,1\}$ respectively.&lt;br /&gt;
* Alice and Bob win if and only if $a \oplus b = xy$.&lt;br /&gt;
The optimal probability with which Alice and Bob can win this game in classical, quantum, and no-signalling theories are as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = chshd(2);&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','classical')  &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.7500&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.8536&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The auxiliary function &amp;lt;tt&amp;gt;chshd()&amp;lt;/tt&amp;gt; above produces the predicate of the CHSH-d game, an intensively studied variant of the CHSH game that generalizes it to a larger alphabet. The rules are analogous, with the difference that each of $a,b,x,y$ are taken from the set $\{0,1,\ldots,d-1\}$ and sum is done modulo $d$.&amp;lt;ref&amp;gt;M. Howard. Maximum nonlocality and minimum uncertainty using magic states. E-print: [http://arxiv.org/abs/1501.05319 arXiv:arXiv:1501.05319] [quant-ph], 2015.&amp;lt;/ref&amp;gt; The algorithm used to calculate the classical bound is parallelized and slightly smarter than naïve brute force&amp;lt;ref&amp;gt;M. Araújo, F. Hirsch, and M. T. Quintino. Bell nonlocality with a single shot. E-print: [https://arxiv.org/abs/2005.13418 arXiv:2005.13418]&amp;lt;/ref&amp;gt;. It can handle up to $d=8$ quickly:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = chshd(8);                             &lt;br /&gt;
&amp;gt;&amp;gt; desc = [8 8 8 8];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','classical')&lt;br /&gt;
Starting parallel pool (parpool) using the 'local' profile ... connected to 2 workers.&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.4688&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===The I&amp;lt;sub&amp;gt;3322&amp;lt;/sub&amp;gt; inequality===&lt;br /&gt;
The I&amp;lt;sub&amp;gt;3322&amp;lt;/sub&amp;gt; inequality&amp;lt;ref&amp;gt;M. Froissart. Constructive generalization of Bell's inequalities. &amp;lt;em&amp;gt;Nuov. Cim. B&amp;lt;/em&amp;gt;, 64:241, 1981&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;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: [http://arxiv.org/abs/quant-ph/0306129 arXiv:quant-ph/0306129]&amp;lt;/ref&amp;gt; is a Bell inequality where each of Alice and Bob has three possible inputs and 2 possible outputs. Its symmetric version in Collins-Gisin notation is given by:&lt;br /&gt;
: &amp;lt;math&amp;gt;-p(11|11) - p(11|12) - p(11|13) - p(11|21) - p(11|22) + p(11|23) - p(11|31) + p(11|32) + p_A(1|1) + p_B(1|1) \leq 1.&amp;lt;/math&amp;gt;&lt;br /&gt;
Similarly, it is known that a value of (strictly) larger than $1+1/4$ is possible in quantum mechanics&amp;lt;ref name=&amp;quot;palvertes&amp;quot;&amp;gt;K.F. Pál and T. Vértesi. Maximal violation of a bipartite three-setting, two-outcome Bell inequality using infinite-dimensional quantum systems. &amp;lt;em&amp;gt;Phys. Rev. A&amp;lt;/em&amp;gt;, 82:022116, 2010. E-print: [http://arxiv.org/abs/1006.3032 arXiv:1006.3032] [quant-ph]&amp;lt;/ref&amp;gt;, and the best possible bound is $2$ 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:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; format long&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 1 0 0;1 -1 -1 -1;0 -1 -1 1;0 -1 1 0];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 3 3];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','classical')                             &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     1&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',1)       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.374999892449922&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum','1+ab')&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.251470917522884&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',2)      &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.250939790350636&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',3)&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.250875663436317&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',4)&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.250875380616149&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','nosignal')          &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   2.000000000005738&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We note that the values provided for the quantum upper bound above for &amp;lt;tt&amp;gt;K = '1+ab'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;K = 2&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;K = 3&amp;lt;/tt&amp;gt; agree with the values found in &amp;lt;ref name=&amp;quot;npa2&amp;quot;&amp;gt;M. Navascués, S. Pironio, and A. Acín. A convergent hierarchy of semidefinite programs characterizing the set of quantum correlations. '' New J. Phys.'', 10:073013, 2008. E-print: [http://arxiv.org/abs/0803.4290 arXiv:0803.4290] [quant-ph]&amp;lt;/ref&amp;gt; (subtracted 1 to account for the different form of the inequality). Furthermore, the value when &amp;lt;tt&amp;gt;K = 4&amp;lt;/tt&amp;gt; agrees with the value found in &amp;lt;ref name=&amp;quot;palvertes&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt;. The exact value of the best upper bound in the quantum setting is an open problem, but is known to be approximately $1.250875$.&lt;br /&gt;
{{SourceCode|name=BellInequalityMax}}&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
In practice, &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; probably can't be any larger than 4 when &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Araujoms</name></author>
	</entry>
	<entry>
		<id>https://qetlab.com/wiki/index.php?title=BellInequalityMax&amp;diff=35659</id>
		<title>BellInequalityMax</title>
		<link rel="alternate" type="text/html" href="https://qetlab.com/wiki/index.php?title=BellInequalityMax&amp;diff=35659"/>
		<updated>2022-11-10T11:22:00Z</updated>

		<summary type="html">&lt;p&gt;Araujoms: /* The I3322 inequality */ fix typo in the inequality and update values for the new code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Function&lt;br /&gt;
|name=BellInequalityMax&lt;br /&gt;
|desc=Computes the maximum value of a Bell inequality&lt;br /&gt;
|rel=[[NPAHierarchy]]&amp;lt;br /&amp;gt;[[ParallelRepetition]]&amp;lt;br /&amp;gt;[[XORGameValue]]&lt;br /&gt;
|req=[http://cvxr.com/cvx/ CVX]&lt;br /&gt;
|cat=[[List of functions#Nonlocality_and_Bell_inequalities|Nonlocality and Bell inequalities]]&lt;br /&gt;
|upd=January 22, 2015&lt;br /&gt;
|cvx=no}}&lt;br /&gt;
&amp;lt;tt&amp;gt;'''BellInequalityMax'''&amp;lt;/tt&amp;gt; is a [[List of functions|function]] that computes the maximum possible value of a given [http://en.wikipedia.org/wiki/Bell%27s_theorem Bell inequality] or nonlocal game 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 [[NPAHierarchy|NPA hierarchy]]).&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION,MTYPE)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION,MTYPE,K)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Argument descriptions==&lt;br /&gt;
* &amp;lt;tt&amp;gt;COEFFICIENTS&amp;lt;/tt&amp;gt;: A matrix or tensor that specifies the coefficients of the Bell inequality in either full probability, full correlator, or Collins-Gisin notation.&lt;br /&gt;
* &amp;lt;tt&amp;gt;DESC&amp;lt;/tt&amp;gt;: A vector of 4 elements describing the number of outputs of Alice, number of outputs of Bob, number of inputs of Alice, and number of inputs of Bob, in this order.&lt;br /&gt;
* &amp;lt;tt&amp;gt;NOTATION&amp;lt;/tt&amp;gt;: A string indicating in which notation are the coefficients of the Bell inequality given. Must be one of &amp;lt;tt&amp;gt;'fp'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;'fc'&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;'cg'&amp;lt;/tt&amp;gt;, for full probability, full correlator, or Collins-Gisin, respectively.&lt;br /&gt;
* &amp;lt;tt&amp;gt;MTYPE&amp;lt;/tt&amp;gt; (optional, default &amp;lt;tt&amp;gt;'classical'&amp;lt;/tt&amp;gt;): A string indicating which type of theory should be used when computing the maximum value of the Bell inequality. Must be one of &amp;lt;tt&amp;gt;'classical'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;'quantum'&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;'nosignal'&amp;lt;/tt&amp;gt;. If &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt; then only an upper bound on the Bell inequality is computed, not necessarily is &amp;lt;em&amp;gt;best&amp;lt;/em&amp;gt; upper bound (see the argument &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; below).&lt;br /&gt;
* &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; (optional, default &amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt;): If &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt; 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 &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; give better bounds, but require more memory and time. Alternatively, &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; can be a string of a form like &amp;lt;tt&amp;gt;'1+ab+aab'&amp;lt;/tt&amp;gt;, 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 &amp;lt;tt&amp;gt;MTYPE&amp;lt;/tt&amp;gt; is anything other than &amp;lt;tt&amp;gt;'quantum'&amp;lt;/tt&amp;gt; then &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; has no effect.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===The CHSH inequality===&lt;br /&gt;
One formulation of the [http://en.wikipedia.org/wiki/CHSH_inequality CHSH inequality]&amp;lt;ref&amp;gt;J.F. Clauser, M.A. Horne, A. Shimony, R.A. Holt. Proposed experiment to test local hidden-variable theories. &amp;lt;em&amp;gt;Phys. Rev. Lett.&amp;lt;/em&amp;gt;, 23(15):880&amp;amp;ndash;884, 1969.&amp;lt;/ref&amp;gt; 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:&lt;br /&gt;
: &amp;lt;math&amp;gt;\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.&amp;lt;/math&amp;gt;&lt;br /&gt;
Similarly, the best bound on this quantity is $2\sqrt{2}$ in a quantum mechanical setting (this is [http://en.wikipedia.org/wiki/Tsirelson%27s_bound Tsirelson's bound])&amp;lt;ref&amp;gt;B.S. Tsirelson. Quantum generalizations of Bell's inequality. &amp;lt;em&amp;gt;Lett. Math. Phys.&amp;lt;/em&amp;gt;, 4:93, 1980. [http://www.tau.ac.il/~tsirel/download/qbell80.pdf E-print]&amp;lt;/ref&amp;gt;, and it is $4$ in no-signalling theories. All three of these bounds can be found as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 0 0;0 1 1;0 1 -1];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','classical')&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     2&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    2.8284&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The CHSH inequality again===&lt;br /&gt;
Another (equivalent) formulation of the CHSH inequality is in Collins-Gisin notation. We write in terms of only the probabilities of obtaining one of the outcomes, as the other probabilities are redundant given the normalization and no-signalling conditions. In this formulation, the following inequality holds in classical theories:&lt;br /&gt;
: &amp;lt;math&amp;gt; p(11|11) + p(11|12) + p(11|21) - p(11|22) - p_A(1|1) - p_B(1|1) \leq 0.&amp;lt;/math&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 -1 0; -1 1 1; 0 1 -1];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','classical')        &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     0&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.2071&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.5000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The CHSH game===&lt;br /&gt;
The CHSH inequality can be reformulated as a nonlocal game, as is favoured in computer science&amp;lt;ref&amp;gt;Richard Cleve, Peter Hoyer, Ben Toner, John Watrous. Consequences and Limits of Nonlocal Strategies. E-print: [http://arxiv.org/abs/quant-ph/0404076 arXiv:quant-ph/0404076]&amp;lt;/ref&amp;gt;. The rules of the game are as follows:&lt;br /&gt;
* A referee asks Alice a question $x \in \{0,1\}$ and Bob a question $y \in \{0,1\}$ with uniform probability.&lt;br /&gt;
* Alice and Bob then reply with answers $a \in \{0,1\}$ and $b \in \{0,1\}$ respectively.&lt;br /&gt;
* Alice and Bob win if and only if $a \oplus b = xy$.&lt;br /&gt;
The optimal probability with which Alice and Bob can win this game in classical, quantum, and no-signalling theories are as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = chshd(2);&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','classical')  &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.7500&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.8536&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The auxiliary function &amp;lt;tt&amp;gt;chshd()&amp;lt;/tt&amp;gt; above produces the predicate of the CHSH-d game, an intensively studied variant of the CHSH game that generalizes it to a larger alphabet. The rules are analogous, with the difference that each of $a,b,x,y$ are taken from the set $\{0,1,\ldots,d-1\}$ and sum is done modulo $d$.&amp;lt;ref&amp;gt;M. Howard. Maximum nonlocality and minimum uncertainty using magic states. E-print: [http://arxiv.org/abs/1501.05319 arXiv:arXiv:1501.05319] [quant-ph], 2015.&amp;lt;/ref&amp;gt; The algorithm used to calculate the classical bound is parallelized and slightly smarter than naïve brute force&amp;lt;ref&amp;gt;M. Araújo, F. Hirsch, and M. T. Quintino. Bell nonlocality with a single shot. E-print: [https://arxiv.org/abs/2005.13418 arXiv:2005.13418]&amp;lt;/ref&amp;gt;. It can handle up to $d=8$ quickly:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = chshd(8);                             &lt;br /&gt;
&amp;gt;&amp;gt; desc = [8 8 8 8];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','classical')&lt;br /&gt;
Starting parallel pool (parpool) using the 'local' profile ... connected to 2 workers.&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.4688&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===The I&amp;lt;sub&amp;gt;3322&amp;lt;/sub&amp;gt; inequality===&lt;br /&gt;
The I&amp;lt;sub&amp;gt;3322&amp;lt;/sub&amp;gt; inequality&amp;lt;ref&amp;gt;M. Froissart. Constructive generalization of Bell's inequalities. &amp;lt;em&amp;gt;Nuov. Cim. B&amp;lt;/em&amp;gt;, 64:241, 1981&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;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: [http://arxiv.org/abs/quant-ph/0306129 arXiv:quant-ph/0306129]&amp;lt;/ref&amp;gt; is a Bell inequality where each of Alice and Bob has three possible inputs and 2 possible outputs. Its symmetric version in Collins-Gisin notation is given by:&lt;br /&gt;
: &amp;lt;math&amp;gt;-p(11|11) - p(11|12) - p(11|13) - p(11|21) - p(11|22) + p(11|23) - p(11|31) + p(11|32) + p_A(1|1) + p_B(1|1) \leq 1.&amp;lt;/math&amp;gt;&lt;br /&gt;
Similarly, it is known that a value of (strictly) larger than $1+1/4$ is possible in quantum mechanics&amp;lt;ref name=&amp;quot;palvertes&amp;quot;&amp;gt;K.F. Pál and T. Vértesi. Maximal violation of a bipartite three-setting, two-outcome Bell inequality using infinite-dimensional quantum systems. &amp;lt;em&amp;gt;Phys. Rev. A&amp;lt;/em&amp;gt;, 82:022116, 2010. E-print: [http://arxiv.org/abs/1006.3032 arXiv:1006.3032] [quant-ph]&amp;lt;/ref&amp;gt;, and the best possible bound is $2$ 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:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; format long&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 1 0 0;1 -1 -1 -1;0 -1 -1 1;0 -1 1 0];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 3 3];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','classical')                             &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     1&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',1)       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.374999892449922&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum','1+ab')&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.251470917522884&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',2)      &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.250939790350636&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',3)&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.250875663436317&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',4)&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.250875380616149&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','nosignal')          &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    2.000000000005738&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We note that the values provided for the quantum upper bound above for &amp;lt;tt&amp;gt;K = '1+ab'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;K = 2&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;K = 3&amp;lt;/tt&amp;gt; agree with the values found in &amp;lt;ref name=&amp;quot;npa2&amp;quot;&amp;gt;M. Navascués, S. Pironio, and A. Acín. A convergent hierarchy of semidefinite programs characterizing the set of quantum correlations. '' New J. Phys.'', 10:073013, 2008. E-print: [http://arxiv.org/abs/0803.4290 arXiv:0803.4290] [quant-ph]&amp;lt;/ref&amp;gt; (subtracted 1 to account for the different form of the inequality). Furthermore, the value when &amp;lt;tt&amp;gt;K = 4&amp;lt;/tt&amp;gt; agrees with the value found in &amp;lt;ref name=&amp;quot;palvertes&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt;. The exact value of the best upper bound in the quantum setting is an open problem, but is known to be approximately $1.250875$.&lt;br /&gt;
{{SourceCode|name=BellInequalityMax}}&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
In practice, &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; probably can't be any larger than 4 when &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Araujoms</name></author>
	</entry>
	<entry>
		<id>https://qetlab.com/wiki/index.php?title=BellInequalityMax&amp;diff=35595</id>
		<title>BellInequalityMax</title>
		<link rel="alternate" type="text/html" href="https://qetlab.com/wiki/index.php?title=BellInequalityMax&amp;diff=35595"/>
		<updated>2022-09-17T12:52:16Z</updated>

		<summary type="html">&lt;p&gt;Araujoms: /* The I3322 inequality */ switch I3322 inequality to symmetric form&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Function&lt;br /&gt;
|name=BellInequalityMax&lt;br /&gt;
|desc=Computes the maximum value of a Bell inequality&lt;br /&gt;
|rel=[[NonlocalGameValue]]&amp;lt;br /&amp;gt;[[NPAHierarchy]]&amp;lt;br /&amp;gt;[[XORGameValue]]&lt;br /&gt;
|req=[http://cvxr.com/cvx/ CVX]&lt;br /&gt;
|cat=[[List of functions#Nonlocality_and_Bell_inequalities|Nonlocality and Bell inequalities]]&lt;br /&gt;
|upd=January 22, 2015&lt;br /&gt;
|cvx=no}}&lt;br /&gt;
&amp;lt;tt&amp;gt;'''BellInequalityMax'''&amp;lt;/tt&amp;gt; is a [[List of functions|function]] that computes the maximum possible value of a given [http://en.wikipedia.org/wiki/Bell%27s_theorem Bell inequality] or nonlocal game 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 [[NPAHierarchy|NPA hierarchy]]).&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION,MTYPE)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION,MTYPE,K)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Argument descriptions==&lt;br /&gt;
* &amp;lt;tt&amp;gt;COEFFICIENTS&amp;lt;/tt&amp;gt;: A matrix or tensor that specifies the coefficients of the Bell inequality in either full probability, full correlator, or Collins-Gisin notation.&lt;br /&gt;
* &amp;lt;tt&amp;gt;DESC&amp;lt;/tt&amp;gt;: A vector of 4 elements describing the number of outputs of Alice, number of outputs of Bob, number of inputs of Alice, and number of inputs of Bob, in this order.&lt;br /&gt;
* &amp;lt;tt&amp;gt;NOTATION&amp;lt;/tt&amp;gt;: A string indicating in which notation are the coefficients of the Bell inequality given. Must be one of &amp;lt;tt&amp;gt;'fp'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;'fc'&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;'cg'&amp;lt;/tt&amp;gt;, for full probability, full correlator, or Collins-Gisin, respectively.&lt;br /&gt;
* &amp;lt;tt&amp;gt;MTYPE&amp;lt;/tt&amp;gt; (optional, default &amp;lt;tt&amp;gt;'classical'&amp;lt;/tt&amp;gt;): A string indicating which type of theory should be used when computing the maximum value of the Bell inequality. Must be one of &amp;lt;tt&amp;gt;'classical'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;'quantum'&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;'nosignal'&amp;lt;/tt&amp;gt;. If &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt; then only an upper bound on the Bell inequality is computed, not necessarily is &amp;lt;em&amp;gt;best&amp;lt;/em&amp;gt; upper bound (see the argument &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; below).&lt;br /&gt;
* &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; (optional, default &amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt;): If &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt; 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 &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; give better bounds, but require more memory and time. Alternatively, &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; can be a string of a form like &amp;lt;tt&amp;gt;'1+ab+aab'&amp;lt;/tt&amp;gt;, 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 &amp;lt;tt&amp;gt;MTYPE&amp;lt;/tt&amp;gt; is anything other than &amp;lt;tt&amp;gt;'quantum'&amp;lt;/tt&amp;gt; then &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; has no effect.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===The CHSH inequality===&lt;br /&gt;
One formulation of the [http://en.wikipedia.org/wiki/CHSH_inequality CHSH inequality]&amp;lt;ref&amp;gt;J.F. Clauser, M.A. Horne, A. Shimony, R.A. Holt. Proposed experiment to test local hidden-variable theories. &amp;lt;em&amp;gt;Phys. Rev. Lett.&amp;lt;/em&amp;gt;, 23(15):880&amp;amp;ndash;884, 1969.&amp;lt;/ref&amp;gt; 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:&lt;br /&gt;
: &amp;lt;math&amp;gt;\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.&amp;lt;/math&amp;gt;&lt;br /&gt;
Similarly, the best bound on this quantity is $2\sqrt{2}$ in a quantum mechanical setting (this is [http://en.wikipedia.org/wiki/Tsirelson%27s_bound Tsirelson's bound])&amp;lt;ref&amp;gt;B.S. Tsirelson. Quantum generalizations of Bell's inequality. &amp;lt;em&amp;gt;Lett. Math. Phys.&amp;lt;/em&amp;gt;, 4:93, 1980. [http://www.tau.ac.il/~tsirel/download/qbell80.pdf E-print]&amp;lt;/ref&amp;gt;, and it is $4$ in no-signalling theories. All three of these bounds can be found as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 0 0;0 1 1;0 1 -1];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','classical')&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     2&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    2.8284&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The CHSH inequality again===&lt;br /&gt;
Another (equivalent) formulation of the CHSH inequality is in Collins-Gisin notation. We write in terms of only the probabilities of obtaining one of the outcomes, as the other probabilities are redundant given the normalization and no-signalling conditions. In this formulation, the following inequality holds in classical theories:&lt;br /&gt;
: &amp;lt;math&amp;gt; p(11|11) + p(11|12) + p(11|21) - p(11|22) - p_A(1|1) - p_B(1|1) \leq 0.&amp;lt;/math&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 -1 0; -1 1 1; 0 1 -1];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','classical')        &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     0&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.2071&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.5000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The CHSH game===&lt;br /&gt;
The CHSH inequality can be reformulated as a nonlocal game, as is favoured in computer science&amp;lt;ref&amp;gt;Richard Cleve, Peter Hoyer, Ben Toner, John Watrous. Consequences and Limits of Nonlocal Strategies. E-print: [http://arxiv.org/abs/quant-ph/0404076 arXiv:quant-ph/0404076]&amp;lt;/ref&amp;gt;. The rules of the game are as follows:&lt;br /&gt;
* A referee asks Alice a question $x \in \{0,1\}$ and Bob a question $y \in \{0,1\}$ with uniform probability.&lt;br /&gt;
* Alice and Bob then reply with answers $a \in \{0,1\}$ and $b \in \{0,1\}$ respectively.&lt;br /&gt;
* Alice and Bob win if and only if $a \oplus b = xy$.&lt;br /&gt;
The optimal probability with which Alice and Bob can win this game in classical, quantum, and no-signalling theories are as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = chshd(2);&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','classical')  &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.7500&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.8536&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The auxiliary function &amp;lt;tt&amp;gt;chshd()&amp;lt;/tt&amp;gt; above produces the predicate of the CHSH-d game, an intensively studied variant of the CHSH game that generalizes it to a larger alphabet. The rules are analogous, with the difference that each of $a,b,x,y$ are taken from the set $\{0,1,\ldots,d-1\}$ and sum is done modulo $d$.&amp;lt;ref&amp;gt;M. Howard. Maximum nonlocality and minimum uncertainty using magic states. E-print: [http://arxiv.org/abs/1501.05319 arXiv:arXiv:1501.05319] [quant-ph], 2015.&amp;lt;/ref&amp;gt; The algorithm used to calculate the classical bound is parallelized and slightly smarter than naïve brute force&amp;lt;ref&amp;gt;M. Araújo, F. Hirsch, and M. T. Quintino. Bell nonlocality with a single shot. E-print: [https://arxiv.org/abs/2005.13418 arXiv:2005.13418]&amp;lt;/ref&amp;gt;. It can handle up to $d=8$ quickly:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = chshd(8);                             &lt;br /&gt;
&amp;gt;&amp;gt; desc = [8 8 8 8];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','classical')&lt;br /&gt;
Starting parallel pool (parpool) using the 'local' profile ... connected to 2 workers.&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.4688&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===The I&amp;lt;sub&amp;gt;3322&amp;lt;/sub&amp;gt; inequality===&lt;br /&gt;
The I&amp;lt;sub&amp;gt;3322&amp;lt;/sub&amp;gt; inequality&amp;lt;ref&amp;gt;M. Froissart. Constructive generalization of Bell's inequalities. &amp;lt;em&amp;gt;Nuov. Cim. B&amp;lt;/em&amp;gt;, 64:241, 1981&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;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: [http://arxiv.org/abs/quant-ph/0306129 arXiv:quant-ph/0306129]&amp;lt;/ref&amp;gt; is a Bell inequality where each of Alice and Bob has three possible inputs and 2 possible outputs. Its symmetric version in Collins-Gisin notation is given by:&lt;br /&gt;
: &amp;lt;math&amp;gt;-p(11|11) - p(11|12) - p(11|13) - p(11|21) - p(11|22) + p(11|23) + p(11|31) - p(11|32) + p_A(1|1) + p_B(1|1) \leq 1.&amp;lt;/math&amp;gt;&lt;br /&gt;
Similarly, it is known that a value of (strictly) larger than $1+1/4$ is possible in quantum mechanics&amp;lt;ref name=&amp;quot;palvertes&amp;quot;&amp;gt;K.F. Pál and T. Vértesi. Maximal violation of a bipartite three-setting, two-outcome Bell inequality using infinite-dimensional quantum systems. &amp;lt;em&amp;gt;Phys. Rev. A&amp;lt;/em&amp;gt;, 82:022116, 2010. E-print: [http://arxiv.org/abs/1006.3032 arXiv:1006.3032] [quant-ph]&amp;lt;/ref&amp;gt;, and the best possible bound is $2$ 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:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; format long&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 1 0 0;1 -1 -1 -1;0 -1 -1 1;0 -1 1 0];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 3 3];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','classical')                             &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     1&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',1)       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.366025379559893&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum','1+ab')&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.251470960767171&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',2)      &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.250939737834008&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',3)&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.250875720765148&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',4)&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   1.250875328899517&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','nosignal')          &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We note that the values provided for the quantum upper bound above for &amp;lt;tt&amp;gt;K = '1+ab'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;K = 2&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;K = 3&amp;lt;/tt&amp;gt; agree with the values found in &amp;lt;ref name=&amp;quot;npa2&amp;quot;&amp;gt;M. Navascués, S. Pironio, and A. Acín. A convergent hierarchy of semidefinite programs characterizing the set of quantum correlations. '' New J. Phys.'', 10:073013, 2008. E-print: [http://arxiv.org/abs/0803.4290 arXiv:0803.4290] [quant-ph]&amp;lt;/ref&amp;gt; (subtracted 1 to account for the different form of the inequality). Furthermore, the value when &amp;lt;tt&amp;gt;K = 4&amp;lt;/tt&amp;gt; agrees with the value found in &amp;lt;ref name=&amp;quot;palvertes&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt;. The exact value of the best upper bound in the quantum setting is an open problem, but is known to be approximately $1.250875$.&lt;br /&gt;
{{SourceCode|name=BellInequalityMax}}&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
In practice, &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; probably can't be any larger than 4 when &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Araujoms</name></author>
	</entry>
	<entry>
		<id>https://qetlab.com/wiki/index.php?title=BellInequalityMax&amp;diff=35593</id>
		<title>BellInequalityMax</title>
		<link rel="alternate" type="text/html" href="https://qetlab.com/wiki/index.php?title=BellInequalityMax&amp;diff=35593"/>
		<updated>2022-09-16T21:37:13Z</updated>

		<summary type="html">&lt;p&gt;Araujoms: rewrite to agree with the new input form for the function&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Function&lt;br /&gt;
|name=BellInequalityMax&lt;br /&gt;
|desc=Computes the maximum value of a Bell inequality&lt;br /&gt;
|rel=[[NonlocalGameValue]]&amp;lt;br /&amp;gt;[[NPAHierarchy]]&amp;lt;br /&amp;gt;[[XORGameValue]]&lt;br /&gt;
|req=[http://cvxr.com/cvx/ CVX]&lt;br /&gt;
|cat=[[List of functions#Nonlocality_and_Bell_inequalities|Nonlocality and Bell inequalities]]&lt;br /&gt;
|upd=January 22, 2015&lt;br /&gt;
|cvx=no}}&lt;br /&gt;
&amp;lt;tt&amp;gt;'''BellInequalityMax'''&amp;lt;/tt&amp;gt; is a [[List of functions|function]] that computes the maximum possible value of a given [http://en.wikipedia.org/wiki/Bell%27s_theorem Bell inequality] or nonlocal game 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 [[NPAHierarchy|NPA hierarchy]]).&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION,MTYPE)&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;BMAX = BellInequalityMax(COEFFICIENTS,DESC,NOTATION,MTYPE,K)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Argument descriptions==&lt;br /&gt;
* &amp;lt;tt&amp;gt;COEFFICIENTS&amp;lt;/tt&amp;gt;: A matrix or tensor that specifies the coefficients of the Bell inequality in either full probability, full correlator, or Collins-Gisin notation.&lt;br /&gt;
* &amp;lt;tt&amp;gt;DESC&amp;lt;/tt&amp;gt;: A vector of 4 elements describing the number of outputs of Alice, number of outputs of Bob, number of inputs of Alice, and number of inputs of Bob, in this order.&lt;br /&gt;
* &amp;lt;tt&amp;gt;NOTATION&amp;lt;/tt&amp;gt;: A string indicating in which notation are the coefficients of the Bell inequality given. Must be one of &amp;lt;tt&amp;gt;'fp'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;'fc'&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;'cg'&amp;lt;/tt&amp;gt;, for full probability, full correlator, or Collins-Gisin, respectively.&lt;br /&gt;
* &amp;lt;tt&amp;gt;MTYPE&amp;lt;/tt&amp;gt; (optional, default &amp;lt;tt&amp;gt;'classical'&amp;lt;/tt&amp;gt;): A string indicating which type of theory should be used when computing the maximum value of the Bell inequality. Must be one of &amp;lt;tt&amp;gt;'classical'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;'quantum'&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;'nosignal'&amp;lt;/tt&amp;gt;. If &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt; then only an upper bound on the Bell inequality is computed, not necessarily is &amp;lt;em&amp;gt;best&amp;lt;/em&amp;gt; upper bound (see the argument &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; below).&lt;br /&gt;
* &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; (optional, default &amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt;): If &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt; 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 &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; give better bounds, but require more memory and time. Alternatively, &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; can be a string of a form like &amp;lt;tt&amp;gt;'1+ab+aab'&amp;lt;/tt&amp;gt;, 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 &amp;lt;tt&amp;gt;MTYPE&amp;lt;/tt&amp;gt; is anything other than &amp;lt;tt&amp;gt;'quantum'&amp;lt;/tt&amp;gt; then &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; has no effect.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===The CHSH inequality===&lt;br /&gt;
One formulation of the [http://en.wikipedia.org/wiki/CHSH_inequality CHSH inequality]&amp;lt;ref&amp;gt;J.F. Clauser, M.A. Horne, A. Shimony, R.A. Holt. Proposed experiment to test local hidden-variable theories. &amp;lt;em&amp;gt;Phys. Rev. Lett.&amp;lt;/em&amp;gt;, 23(15):880&amp;amp;ndash;884, 1969.&amp;lt;/ref&amp;gt; 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:&lt;br /&gt;
: &amp;lt;math&amp;gt;\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.&amp;lt;/math&amp;gt;&lt;br /&gt;
Similarly, the best bound on this quantity is $2\sqrt{2}$ in a quantum mechanical setting (this is [http://en.wikipedia.org/wiki/Tsirelson%27s_bound Tsirelson's bound])&amp;lt;ref&amp;gt;B.S. Tsirelson. Quantum generalizations of Bell's inequality. &amp;lt;em&amp;gt;Lett. Math. Phys.&amp;lt;/em&amp;gt;, 4:93, 1980. [http://www.tau.ac.il/~tsirel/download/qbell80.pdf E-print]&amp;lt;/ref&amp;gt;, and it is $4$ in no-signalling theories. All three of these bounds can be found as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 0 0;0 1 1;0 1 -1];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','classical')&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     2&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    2.8284&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fc','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The CHSH inequality again===&lt;br /&gt;
Another (equivalent) formulation of the CHSH inequality is in Collins-Gisin notation. We write in terms of only the probabilities of obtaining one of the outcomes, as the other probabilities are redundant given the normalization and no-signalling conditions. In this formulation, the following inequality holds in classical theories:&lt;br /&gt;
: &amp;lt;math&amp;gt; p(11|11) + p(11|12) + p(11|21) - p(11|22) - p_A(1|1) - p_B(1|1) \leq 0.&amp;lt;/math&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = [0 -1 0; -1 1 1; 0 1 -1];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','classical')        &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     0&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.2071&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.5000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The CHSH game===&lt;br /&gt;
The CHSH inequality can be reformulated as a nonlocal game, as is favoured in computer science&amp;lt;ref&amp;gt;Richard Cleve, Peter Hoyer, Ben Toner, John Watrous. Consequences and Limits of Nonlocal Strategies. E-print: [http://arxiv.org/abs/quant-ph/0404076 arXiv:quant-ph/0404076]&amp;lt;/ref&amp;gt;. The rules of the game are as follows:&lt;br /&gt;
* A referee asks Alice a question $x \in \{0,1\}$ and Bob a question $y \in \{0,1\}$ with uniform probability.&lt;br /&gt;
* Alice and Bob then reply with answers $a \in \{0,1\}$ and $b \in \{0,1\}$ respectively.&lt;br /&gt;
* Alice and Bob win if and only if $a \oplus b = xy$.&lt;br /&gt;
The optimal probability with which Alice and Bob can win this game in classical, quantum, and no-signalling theories are as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = chshd(2);&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 2 2];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','classical')  &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.7500&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','quantum')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.8536&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','nosignal')       &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The auxiliary function &amp;lt;tt&amp;gt;chshd()&amp;lt;/tt&amp;gt; above produces the predicate of the CHSH-d game, an intensively studied variant of the CHSH game that generalizes it to a larger alphabet. The rules are analogous, with the difference that each of $a,b,x,y$ are taken from the set $\{0,1,\ldots,d-1\}$ and sum is done modulo $d$.&amp;lt;ref&amp;gt;M. Howard. Maximum nonlocality and minimum uncertainty using magic states. E-print: [http://arxiv.org/abs/1501.05319 arXiv:arXiv:1501.05319] [quant-ph], 2015.&amp;lt;/ref&amp;gt; The algorithm used to calculate the classical bound is parallelized and slightly smarter than naïve brute force&amp;lt;ref&amp;gt;M. Araújo, F. Hirsch, and M. T. Quintino. Bell nonlocality with a single shot. E-print: [https://arxiv.org/abs/2005.13418 arXiv:2005.13418]&amp;lt;/ref&amp;gt;. It can handle up to $d=8$ quickly:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; M = chshd(8);                             &lt;br /&gt;
&amp;gt;&amp;gt; desc = [8 8 8 8];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'fp','classical')&lt;br /&gt;
Starting parallel pool (parpool) using the 'local' profile ... connected to 2 workers.&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
    0.4688&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===The I&amp;lt;sub&amp;gt;3322&amp;lt;/sub&amp;gt; inequality===&lt;br /&gt;
The I&amp;lt;sub&amp;gt;3322&amp;lt;/sub&amp;gt; inequality&amp;lt;ref&amp;gt;M. Froissart. Constructive generalization of Bell's inequalities. &amp;lt;em&amp;gt;Nuov. Cim. B&amp;lt;/em&amp;gt;, 64:241, 1981&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;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: [http://arxiv.org/abs/quant-ph/0306129 arXiv:quant-ph/0306129]&amp;lt;/ref&amp;gt; is a Bell inequality where each of Alice and Bob has three possible inputs and 2 possible outputs. Written in Collins-Gisin notation, it is given by:&lt;br /&gt;
: &amp;lt;math&amp;gt;p(11|11) + p(11|12) - p(11|13) + p(11|21) + p(11|22) + p(11|23) - p(11|31) + p(11|32) - p_A(1|2) - p_B(1|1) - 2p_B(1|2) \leq 0.&amp;lt;/math&amp;gt;&lt;br /&gt;
Similarly, it is known that a value of (strictly) larger than $1/4$ is possible in quantum mechanics&amp;lt;ref name=&amp;quot;palvertes&amp;quot;&amp;gt;K.F. Pál and T. Vértesi. Maximal violation of a bipartite three-setting, two-outcome Bell inequality using infinite-dimensional quantum systems. &amp;lt;em&amp;gt;Phys. Rev. A&amp;lt;/em&amp;gt;, 82:022116, 2010. E-print: [http://arxiv.org/abs/1006.3032 arXiv:1006.3032] [quant-ph]&amp;lt;/ref&amp;gt;, 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:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt; format long                                &lt;br /&gt;
&amp;gt;&amp;gt; M = [0 -1 -2 0;0 1 1 -1;-1 1 1 1;0 -1 1 0];&lt;br /&gt;
&amp;gt;&amp;gt; desc = [2 2 3 3];&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','classical')&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     3.330669073875470e-16&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',1) &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   0.366025400377779&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum','1+ab')&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   0.251470925489524&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',2)      &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   0.250939729037211&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',3)&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   0.250875635269154&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','quantum',4)&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
   0.250875356409269&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; BellInequalityMax(M,desc,'cg','nosignal')         &lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We note that the values provided for the quantum upper bound above for &amp;lt;tt&amp;gt;K = '1+ab'&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;K = 2&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;K = 3&amp;lt;/tt&amp;gt; agree with the values found in &amp;lt;ref name=&amp;quot;npa2&amp;quot;&amp;gt;M. Navascués, S. Pironio, and A. Acín. A convergent hierarchy of semidefinite programs characterizing the set of quantum correlations. '' New J. Phys.'', 10:073013, 2008. E-print: [http://arxiv.org/abs/0803.4290 arXiv:0803.4290] [quant-ph]&amp;lt;/ref&amp;gt;. Furthermore, the value when &amp;lt;tt&amp;gt;K = 4&amp;lt;/tt&amp;gt; agrees with the value found in &amp;lt;ref name=&amp;quot;palvertes&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt;. The exact value of the best upper bound in the quantum setting is an open problem, but is known to be approximately $0.250875$.&lt;br /&gt;
{{SourceCode|name=BellInequalityMax}}&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
In practice, &amp;lt;tt&amp;gt;K&amp;lt;/tt&amp;gt; probably can't be any larger than 4 when &amp;lt;tt&amp;gt;MTYPE = 'quantum'&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Araujoms</name></author>
	</entry>
	<entry>
		<id>https://qetlab.com/wiki/index.php?title=List_of_functions&amp;diff=35592</id>
		<title>List of functions</title>
		<link rel="alternate" type="text/html" href="https://qetlab.com/wiki/index.php?title=List_of_functions&amp;diff=35592"/>
		<updated>2022-09-16T20:15:06Z</updated>

		<summary type="html">&lt;p&gt;Araujoms: /* Nonlocality and Bell inequalities */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a '''list of functions''' provided by QETLAB, arranged by category. If you would prefer an alphabetical list of all functions please see [[:Category:Functions|this page]]. Brief descriptions of these functions are provided here, as well as links to their documentation pages, where full details and numerous examples can be found.&lt;br /&gt;
&lt;br /&gt;
==Basic operations==&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[IsPSD]]&amp;lt;/tt&amp;gt;: Determines whether or not a matrix is positive semidefinite&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[Tensor]]&amp;lt;/tt&amp;gt;: Kronecker tensor product of two or more matrices&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[TensorSum]]&amp;lt;/tt&amp;gt;: Computes a vector or operator from its tensor decomposition&lt;br /&gt;
&lt;br /&gt;
==Coherence and incoherence==&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[L1NormCoherence]]&amp;lt;/tt&amp;gt;: Computes the ℓ&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt;-norm of coherence of a quantum state&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[RelEntCoherence]]&amp;lt;/tt&amp;gt;: Computes the relative entropy of coherence of a quantum state&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[RobustnessCoherence]]&amp;lt;/tt&amp;gt;: Computes the robustness of coherence of a quantum state&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[TraceDistanceCoherence]]&amp;lt;/tt&amp;gt;: Computes the trace distance of coherence of a quantum state&lt;br /&gt;
&lt;br /&gt;
==Distinguishing objects==&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[ChannelDistinguishability]]&amp;lt;/tt&amp;gt;: Computes the maximum probability of distinguishing two quantum channels&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[Distinguishability]]&amp;lt;/tt&amp;gt;: Computes the maximum probability of distinguishing quantum states&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[LocalDistinguishability]]&amp;lt;/tt&amp;gt;: Computes the maximum probability of distinguishing quantum states by symmetric-extendible and/or PPT measurements&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[UPBSepDistinguishable]]&amp;lt;/tt&amp;gt;: Determines whether or not an unextendible product basis is distinguishable by separable measurements&lt;br /&gt;
&lt;br /&gt;
==Entanglement and separability==&lt;br /&gt;
===Pure states===&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[IsProductVector]]&amp;lt;/tt&amp;gt;: Determines if a pure state is a product vector&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[SchmidtDecomposition]]&amp;lt;/tt&amp;gt;: Computes the Schmidt decomposition of a bipartite vector&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[SchmidtRank]]&amp;lt;/tt&amp;gt;: Computes the Schmidt rank of a bipartite vector&lt;br /&gt;
&lt;br /&gt;
===Mixed states===&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[FilterNormalForm]]&amp;lt;/tt&amp;gt;: Computes the filter normal form of an operator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[IsBlockPositive]]&amp;lt;/tt&amp;gt;: Determines whether or not an operator is block positive&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[IsEntanglingGate]]&amp;lt;/tt&amp;gt;: Determines if a unitary is an entangling gate&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[IsPPT]]&amp;lt;/tt&amp;gt;: Determines whether or not a matrix has positive partial transpose&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[IsProductOperator]]&amp;lt;/tt&amp;gt;: Determines if an operator is an elementary tensor&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[IsSeparable]]&amp;lt;/tt&amp;gt;: Determines whether or not a bipartite operator is separable&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[OperatorSchmidtDecomposition]]&amp;lt;/tt&amp;gt;: Computes the operator Schmidt decomposition of a bipartite operator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[OperatorSchmidtRank]]&amp;lt;/tt&amp;gt;: Computes the operator Schmidt rank of a bipartite operator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[SymmetricExtension]]&amp;lt;/tt&amp;gt;: Determines whether or not an operator has a symmetric extension&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[SymmetricInnerExtension]]&amp;lt;/tt&amp;gt;: Determines whether or not an operator has a symmetric inner extension&lt;br /&gt;
&lt;br /&gt;
===Ball of separability===&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[AbsPPTConstraints]]&amp;lt;/tt&amp;gt;: Builds the eigenvalue matrices that determine whether or not a state is absolutely PPT&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[InSeparableBall]]&amp;lt;/tt&amp;gt;: Checks whether or not an operator is in the ball of separability centered at the maximally-mixed state&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[IsAbsPPT]]&amp;lt;/tt&amp;gt;: Determines whether or not a density matrix is absolutely PPT&lt;br /&gt;
&lt;br /&gt;
===Entanglement measures===&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[Concurrence]]&amp;lt;/tt&amp;gt;: Computes the concurrence of a 2-qubit state&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[EntFormation]]&amp;lt;/tt&amp;gt;: Computes the entanglement of formation of a bipartite quantum state&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[Negativity]]&amp;lt;/tt&amp;gt;: Computes the negativity of a bipartite density matrix&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[RandomRobustnessEntanglement]]&amp;lt;/tt&amp;gt;: Computes the random robustness of entanglement of a bipartite quantum state&lt;br /&gt;
&lt;br /&gt;
==Information theory==&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[Entropy]]&amp;lt;/tt&amp;gt;: Computes the von Neumann or Rényi entropy of a density matrix&lt;br /&gt;
&lt;br /&gt;
==Nonlocality and Bell inequalities==&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[BCSGameLB]]&amp;lt;/tt&amp;gt;: Computes a lower bound on the quantum value of a binary contraint system (BCS) game&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[BCSGameValue]]&amp;lt;/tt&amp;gt;: Computes the maximum value of a binary constraint system (BCS) game&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[BellInequalityMax]]&amp;lt;/tt&amp;gt;: Computes the maximum value of a Bell inequality or nonlocal game&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[BellInequalityMaxQubits]]&amp;lt;/tt&amp;gt;: Approximates the optimal value of a Bell inequality in qubit (i.e., 2-dimensional quantum) settings&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[NonlocalGameLB]]&amp;lt;/tt&amp;gt;: Computes a lower bound on the quantum value of a non-local game&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[NonlocalGameValue]]&amp;lt;/tt&amp;gt;: Computes the value of a two-player non-local game&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[NPAHierarchy]]&amp;lt;/tt&amp;gt;: Determines whether or not a set of probabilities satisfy the conditions of the NPA hierarchy&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[XORGameValue]]&amp;lt;/tt&amp;gt;: Computes the classical or quantum value of a non-local binary XOR game&lt;br /&gt;
&lt;br /&gt;
==Norms and distance measures==&lt;br /&gt;
===Vectors and pure states===&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[SkVectorNorm]]&amp;lt;/tt&amp;gt;: Computes the s(k)-norm of a vector&lt;br /&gt;
&lt;br /&gt;
===Operators and mixed states===&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[Fidelity]]&amp;lt;/tt&amp;gt;: Computes the (Uhlmann) fidelity of two density matrices&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[InducedMatrixNorm]]&amp;lt;/tt&amp;gt;: Computes a lower bound of the induced p&amp;amp;rarr;q norm of a matrix&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[kpNorm]]&amp;lt;/tt&amp;gt;: Computes the (k,p)-norm of a vector or matrix&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[kpNormDual]]&amp;lt;/tt&amp;gt;: Computes the dual of the (k,p)-norm of a vector or matrix&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[KyFanNorm]]&amp;lt;/tt&amp;gt;: Computes the Ky Fan k-norm of an operator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[MatsumotoFidelity]]&amp;lt;/tt&amp;gt;: Computes the Matsumoto fidelity of two density matrices&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[SkOperatorNorm]]&amp;lt;/tt&amp;gt;: Bounds the S(k)-norm of an operator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[SchattenNorm]]&amp;lt;/tt&amp;gt;: Computes the Schatten p-norm of an operator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[TraceNorm]]&amp;lt;/tt&amp;gt;: Computes the trace norm of an operator&lt;br /&gt;
&lt;br /&gt;
===Superoperators and channels===&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[CBNorm]]&amp;lt;/tt&amp;gt;: Computes the completely bounded norm of a superoperator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[DiamondNorm]]&amp;lt;/tt&amp;gt;: Computes the diamond norm of a superoperator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[InducedSchattenNorm]]&amp;lt;/tt&amp;gt;: Computes a lower bound of the induced Schatten p&amp;amp;rarr;q norm of a superoperator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[MaximumOutputFidelity]]&amp;lt;/tt&amp;gt;: Computes the maximum output fidelity of two quantum channels&lt;br /&gt;
&lt;br /&gt;
==Permutations and symmetry of subsystems==&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[AntisymmetricProjection]]&amp;lt;/tt&amp;gt;: Produces the projection onto the antisymmetric subspace&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[PermutationOperator]]&amp;lt;/tt&amp;gt;: Produces a unitary operator that permutes subsystems&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[PermuteSystems]]&amp;lt;/tt&amp;gt;: Permutes subsystems within a state or operator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[Swap]]&amp;lt;/tt&amp;gt;: Swaps two subsystems within a state or operator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[SwapOperator]]&amp;lt;/tt&amp;gt;: Produces a unitary operator that swaps two subsystems&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[SymmetricProjection]]&amp;lt;/tt&amp;gt;: Produces the projection onto the symmetric subspace&lt;br /&gt;
&lt;br /&gt;
==Random things==&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[RandomDensityMatrix]]&amp;lt;/tt&amp;gt;: Generates a random density matrix&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[RandomPOVM]]&amp;lt;/tt&amp;gt;: Generates a random POVM (positive-operator valued measure)&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[RandomProbabilities]]&amp;lt;/tt&amp;gt;: Computes a random probability vector, distributed uniformly on the unit simplex&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[RandomStateVector]]&amp;lt;/tt&amp;gt;: Generates a random pure state vector&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[RandomSuperoperator]]&amp;lt;/tt&amp;gt;: Generates a random superoperator (completely positive map)&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[RandomUnitary]]&amp;lt;/tt&amp;gt;: Generates a random unitary or orthogonal matrix&lt;br /&gt;
&lt;br /&gt;
==Special states, vectors, and operators==&lt;br /&gt;
===Pure states===&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[Bell]]&amp;lt;/tt&amp;gt;: Produces a Bell state&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[BrauerStates]]&amp;lt;/tt&amp;gt;: Produces all Brauer states&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[DickeState]]&amp;lt;/tt&amp;gt;: Generates a Dicke state&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[GHZState]]&amp;lt;/tt&amp;gt;: Generates a (generalized) GHZ state&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[MaxEntangled]]&amp;lt;/tt&amp;gt;: Produces a maximally entangled bipartite pure state&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[WState]]&amp;lt;/tt&amp;gt;: Generates a (generalized) W-state&lt;br /&gt;
&lt;br /&gt;
===Mixed states===&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[BreuerState]]&amp;lt;/tt&amp;gt;: Generates a Breuer state, which is a specific family of bound entangled states on even local dimensions&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[ChessboardState]]&amp;lt;/tt&amp;gt;: Produces a chessboard state&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[GisinState]]&amp;lt;/tt&amp;gt;: Generates a 2-qubit Gisin state&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[HorodeckiState]]&amp;lt;/tt&amp;gt;: Generates a bound entangled &amp;quot;Horodecki&amp;quot; state&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[IsotropicState]]&amp;lt;/tt&amp;gt;: Produces an isotropic state&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[WernerState]]&amp;lt;/tt&amp;gt;: Produces a Werner state&lt;br /&gt;
&lt;br /&gt;
===Other operators===&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[FourierMatrix]]&amp;lt;/tt&amp;gt;: Generates the unitary matrix that implements the quantum Fourier transform&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[GellMann]]&amp;lt;/tt&amp;gt;: Produces a Gell-Mann operator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[GenGellMann]]&amp;lt;/tt&amp;gt;: Produces a generalized Gell-Mann operator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[GenPauli]]&amp;lt;/tt&amp;gt;: Produces a generalized Pauli operator (sometimes called a Weyl operator)&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[Pauli]]&amp;lt;/tt&amp;gt;: Produces a Pauli operator&lt;br /&gt;
&lt;br /&gt;
==Superoperators==&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[ApplyMap]]&amp;lt;/tt&amp;gt;: Applies a superoperator to an operator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[ChoiMatrix]]&amp;lt;/tt&amp;gt;: Computes the Choi matrix of a superoperator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[ChoiMap]]&amp;lt;/tt&amp;gt;: Produces the Choi map or one of its generalizations&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[ComplementaryMap]]&amp;lt;/tt&amp;gt;: Computes the complementary map of a superoperator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[DephasingChannel]]&amp;lt;/tt&amp;gt;: Produces a dephasing channel&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[DepolarizingChannel]]&amp;lt;/tt&amp;gt;: Produces a depolarizing channel&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[DualMap]]&amp;lt;/tt&amp;gt;: Computes the dual of a superoperator in the Hilbert-Schmidt inner product&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[IsCP]]&amp;lt;/tt&amp;gt;: Determines whether or not a superoperator is completely positive&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[IsHermPreserving]]&amp;lt;/tt&amp;gt;: Determines whether or not a superoperator is Hermiticity preserving&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[KrausOperators]]&amp;lt;/tt&amp;gt;: Computes a set of Kraus operators for a superoperator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[PartialMap]]&amp;lt;/tt&amp;gt;: Applies a superoperator to a subsystem of an operator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[PartialTrace]]&amp;lt;/tt&amp;gt;: Computes the partial trace of a vector or a matrix&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[PartialTranspose]]&amp;lt;/tt&amp;gt;: Computes the partial transpose of a matrix&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[PauliChannel]]&amp;lt;/tt&amp;gt;: Generates a Pauli channel (i.e., a quantum channel with Pauli Kraus operators)&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[Realignment]]&amp;lt;/tt&amp;gt;: Computes the realignment of a bipartite operator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[ReductionMap]]&amp;lt;/tt&amp;gt;: Produces the reduction map&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[Twirl]]&amp;lt;/tt&amp;gt;: Twirls a bipartite or multipartite operator&lt;br /&gt;
&lt;br /&gt;
==Unextendible product bases==&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[IsUPB]]&amp;lt;/tt&amp;gt;: Determines whether or not a set of product vectors form a UPB&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[MinUPBSize]]&amp;lt;/tt&amp;gt;: Gives the minimum cardinality of an unextendible product basis in given dimensions&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[UPB]]&amp;lt;/tt&amp;gt;: Generates an unextendible product basis&lt;br /&gt;
&lt;br /&gt;
==Miscellaneous==&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[Commutant]]&amp;lt;/tt&amp;gt;: Computes the commutant of a set of matrices&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[IsTotallyNonsingular]]&amp;lt;/tt&amp;gt;: Determines whether or not a matrix is totally nonsingular&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[IsTotallyPositive]]&amp;lt;/tt&amp;gt;: Determines whether or not a matrix is totally positive&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[Majorizes]]&amp;lt;/tt&amp;gt;: Determines whether or not a vector or matrix majorizes another&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[OperatorSinkhorn]]&amp;lt;/tt&amp;gt;: Performs the operator Sinkhorn iteration, making all single-party reduced states proportional to the identity&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[Purity]]&amp;lt;/tt&amp;gt;: Computes the purity of a quantum state&lt;br /&gt;
&lt;br /&gt;
==Helper functions==&lt;br /&gt;
These are functions that only serve auxiliary roles within other functions of QETLAB. As an end-user of QETLAB, you likely won't have any use for these functions, but they are listed here anyway just in case.&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[bcs_to_nonlocal]]&amp;lt;/tt&amp;gt;: Converts a constraint description of a binary constraint system (BCS) game to a general non-local game description&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[dec_to_bin]]&amp;lt;/tt&amp;gt;: Converts a decimal number to a binary number in a similar way to `de2bi' in MATLAB&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[iden]]&amp;lt;/tt&amp;gt;: Computes a sparse or full identity matrix&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[jacobi_poly]]&amp;lt;/tt&amp;gt;: Computes the coefficients of Jacobi polynomials&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[normalize_cols]]&amp;lt;/tt&amp;gt;: Scales the columns of a matrix to have norm 1&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[one_factorization]]&amp;lt;/tt&amp;gt;: Computes a 1-factorization of a list of objects&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[opt_args]]&amp;lt;/tt&amp;gt;: Handles optional input arguments for functions&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[opt_disp]]&amp;lt;/tt&amp;gt;: Display a message to the user (sometimes)&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[pad_array]]&amp;lt;/tt&amp;gt;: Pads an array with zeroes in a similar way to `padarray' in MATLAB&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[perfect_matchings]]&amp;lt;/tt&amp;gt;: Gives all perfect matchings of N objects&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[perm_inv]]&amp;lt;/tt&amp;gt;: Computes the inverse of a permutation&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[perm_sign]]&amp;lt;/tt&amp;gt;: Computes the sign of a permutation&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[pure_to_mixed]]&amp;lt;/tt&amp;gt;: Converts a state vector or density matrix representation of a state to a density matrix&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[sk_iterate]]&amp;lt;/tt&amp;gt;: Computes a lower bound of the S(k)-norm of an operator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[spnull]]&amp;lt;/tt&amp;gt;: Returns a sparse orthonormal basis for the null space&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[sporth]]&amp;lt;/tt&amp;gt;: Returns a sparse orthonormal basis for the range&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[superoperator_dims]]&amp;lt;/tt&amp;gt;: Computes the input, output, and environment dimensions of a superoperator&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[unique_perms]]&amp;lt;/tt&amp;gt;: Computes all distinct permutations of a given vector&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[update_odometer]]&amp;lt;/tt&amp;gt;: Increases the entries of a vector subject to constraints on how large the entries of that vector can be&lt;br /&gt;
* &amp;lt;tt&amp;gt;[[vec_partitions]]&amp;lt;/tt&amp;gt;: Produces all possible partitions of a vector&lt;/div&gt;</summary>
		<author><name>Araujoms</name></author>
	</entry>
</feed>