Quantum Magic Rectangles: Characterisation and Application to Certified Randomness Expansion

We study a generalisation of the Mermin-Peres magic square game to arbitrary rectangular dimensions. After exhibiting some general properties, these rectangular games are characterised in terms of their optimal win probabilities for quantum strategies. We find that for $m \times n$ rectangular games of dimensions $m,n \geq 3$ there are quantum strategies that win with certainty, while for dimensions $1 \times n$ quantum strategies do not outperform classical strategies. The final case of dimensions $2 \times n$ is richer, and we give upper and lower bounds that both outperform the classical strategies. Finally, we apply our findings to quantum certified randomness expansion by using our previous results and obtaining the winning probability of games with a distinguished input for which the devices give a deterministic outcome.


Introduction
Quantum theory has been arguably one of the most successful scientific theories, especially in terms of accuracy of predictions and applications. We are currently in the midst of the second "quantum revolution", where the ability to control quantum systems with great precision has resulted in a new wave of technological applications. What makes quantum theory unique is the fact that our classical intuition frequently fails, and it has been proven that understanding the foundations of this theory is crucial to fully realise the possibilities it offers. Quantum nonlocality and contextuality are two such concepts that conflict with our classical intuition, and at the same time enable one of the most interesting applications: that of device-independent cryptographic protocols. Device-independence, first introduced by Mayers and Yao [1], is the property that allows parties to achieve cryptographic tasks-from key distribution [2] to certified randomness expansion [3], oblivious transfer [4], and secure quantum computation [5]-without trusting the inner workings of their own devices.
Nonlocality is frequently expressed in terms of "guessing" games, in which remote parties that share entanglement try to fulfil a certain winning condition. Mermin [6] and Peres [7] introduced one such game called the magic square game (see details in Section 2). This game has a special place in the foundations of quantum theory due to two notable properties. Firstly, it is one of the simplest examples where quantum strategies can win with certainty (probability one) while classical strategies cannot. 1 This property (winning with certainty) can be used to illustrate (strong) contextuality in the spirit of the Kochen-Specker theorem [9]. Secondly, it is the simplest two-player game where the maximal nonlocality can be demonstrated using only Clifford computations [10] (preparation of Bell states and Pauli measurements). 2 The magic square game can, in principle, be used for any of the device-independent cryptographic tasks, and its performance in comparison to other games evaluated case-by-case. Furthermore, it can be used for efficient self-testing (e.g. [11]), another exciting concept made possible by nonlocality. That is, parties can deduce from their purely classical observations the (essentially) exact quantum state they share-a property stronger than simply observing non-classical correlations.
In this paper we attempt to see how one can generalise the magic square game, the winning probabilities that can be achieved, what qualitative properties are preserved, and how the generalisation can be used in applications. The specific application we focus upon is certified randomness expansion, while analysis of other device-independent cryptographic primitives is deferred to future publications.
Our contributions. We introduce a new class of nonlocal games which we call magic rectangle games, 3 characterise their winning probabilities, and apply the results to certified randomness expansion. Specifically: • We define a generalisation of the Mermin-Peres magic square game to general rectangular dimensions (Definition 3.1).
• We fully characterise the optimal winning probabilities for quantum behaviours of all these magic rectangle games (Theorem 5.1).
• In order to achieve this characterisation, we first prove a number of general properties, showing that the optimal winning probabilities for any set of behaviours (classical, quantum, almost quantum, non-signalling) are: (i) the same for all games of the same dimension, (ii) symmetric with respect to row/column exchange, and (iii) monotonically increasing with the dimension of the rectangle.
• Using the known fact that the regular magic square game (which is a special case of 3 × 3 magic rectangle games) can be won for quantum strategies with certainty, we reduce the full characterisation of magic rectangles to that of 1 × n and 2 × n games (Theorem 4.1). We also show that the CHSH game, according to our definitions, is a 2 × 2 magic rectangle game (Theorem 5.3). We then obtain the optimal winning probabilities for the 1 × n case, while we lower and upper bound the winning probabilities for 2 × n games. To upper bound the probabilities, we conjecture the almost quantum winning probability based on numerical evidence. As a side result, we get that 2 × n games with n ≥ 3 can be won with certainty using behaviours at level 1 of the NPA hierarchy (and so exhibit a version of "pseudo-telepathy"), while the quantum and almost quantum sets both give winning probabilities strictly smaller than unity (thus not exhibiting pseudo-telepathy).
• Finally, we use this characterisation to analyse certified randomness expansion from magic rectangle games. Specifically, we show that the winning probability of an m×n game with a distinguished input (with deterministic outcomes) can be obtained from the (m−1)×(n−1) game (Theorem 6.3). This, along with the results of Theorem 5.1, allows us to determine the noise tolerance (robustness) of each of these games. We then follow the analysis of Miller and Shi [14] to get rates for certified randomness expansion using different magic rectangle games (see Table 3).
Related works. The magic square game was introduced by Mermin [6] and Peres [7], while Cabello [15], [16] and subsequently Aravind [17] stated it as a two-player nonlocal game. Aravind [18] gives a non-technical demonstration of the Mermin-Peres magic square game. The term quantum pseudo-telepathy was first introduced by Brassard, Broadbent, and Tapp [19], and the magic square game, along with many others that share the property that there exist perfect quantum (but not classical) strategies, were reviewed in [8]. There are a number of generalisations of the magic square that have been considered in literature. Cleve and Mittal [20] analyse quantum strategies for "binary constraint" games-a general class of games that contains the magic rectangles we define-and give some (weaker than our analysis) upper bounds on winning probabilities from quantum strategies. Arkhipov [21] generalised the magic square and magic pentagram games to be played on hypergraphs called arrangements, and characterised which arrangements can exhibit quantum pseudo-telepathy. Coladangelo and Stark [22] considered "linear constraint" games, focusing on the uniqueness of winning quantum strategies in order to use such games for self-testing.
To determine optimal quantum strategies, it is important to be able to check if a given experimental behaviour admits a quantum model/realisation. This question is directly linked with the question of the "degree of nonlocality" present in quantum theory. Navascués, Pironio, and Acín [23], [24] addressed this by giving an infinite hierarchy of conditions that are satisfied by quantum behaviours, known as the NPA hierarchy. Navascués, Guryanova, Hoban, et al. [25] defined the almost quantum set of behaviours, which is the set closest to the quantum set that arises in a "natural" way and is easy to check. Sets of behaviours that are easy to handle and include the quantum set, as is the case for the levels of the NPA hierarchy and the almost quantum set, have been used successfully to bound the winning probabilities of quantum parties in many cryptographic settings-something we also exploit in this work.
Certified randomness expansion was first introduced by Colbeck and Kent [3]. Vazirani and Vidick [26] demonstrated quantum security for an exponential expansion protocol. Subsequently, Miller and Shi [27] additionally obtained cryptographic security and robustness. Acín and Masanes [28] reviewed efforts to design device-independent quantum random number generators (up to 2016), and included a comparison of the main protocols. Miller and Shi [14] give the spot-checking protocol that we use for our analysis of certified randomness expansion, and to obtain bounds on expansion rates. Finally, Arnon-Friedman, Renner, and Vidick [29] and Brown, Ragy, and Colbeck [30] detail alternative techniques, which give better rates for the spot-checking protocol by using the entropy accumulation theorem [31], [32]. These are more involved and case-specific than [14] and, thus, to give a general analysis of certified randomness for all magic rectangle games, we use [14] in our work. Note, however, that the noise tolerance we obtain for the different magic rectangle games does not depend on the specific technique used to bound the rates, and thus applies in general.
Organisation of the paper. In Section 2 we give some background on the magic square and the different levels of correlations. In Section 3 we define the magic rectangle games, and in Section 4 give some general results for these games. In Section 5 we give the full characterisation of the winning probabilities of magic rectangle games. We conclude in Section 6, where we apply our results to certified randomness expansion.

The magic square game
The Mermin-Peres magic square game [18] consists of two players, Alice and Bob, who are not allowed to communicate during each round of the game. This could be achieved, for example, by ensuring a spacelike separation between the two players. Each round consists of Alice and Bob respectively being assigned a row and column of an empty 3 × 3 table uniformly at random, which they must fill according to the rules: S1. Each filled cell of the table must belong to the set {+1, −1}.
S2. Alice's row must contain an even number of negative entries (i.e., the product of its entries must be positive).
S3. Bob's column must contain an odd number of negative entries (i.e., the product of its entries must be negative).
Neither player has knowledge of which row or column the other has been assigned, and nor does either player know what values the other has entered. The game is won if both players enter the same value into the cell shared by their row and column. It is clear that the optimal classical strategy succeeds with probability 8/9 only [8], and may be achieved by both players agreeing to each follow a particular configuration for their entire table before the game begins. Strikingly, if the players are allowed to share an entangled quantum state, it is possible for them to win the magic square game with certainty [6], [7]. Such games are said to exhibit quantum pseudo-telepathy [8], setting them apart from many other nonlocal games (including the CHSH game) for which optimal quantum strategies are not guaranteed to win. A possible quantum winning strategy for the magic square allows the players to share the entangled state which is the product of two maximally entangled two-qubit Bell states That is, Alice's quantum system is composed of qubits 1 and 3, and Bob's system of qubits 2 and 4. Depending on which row and column are assigned, the players make measurements on their respective quantum systems according to the observables given in the corresponding cells of Fig. 1. The outcomes of these determine the values which Alice and Bob should enter into their respective row and column to win with certainty. Figure 1: A quantum strategy for the magic square game, in which the players share the entangled state |Ψ given in Eq. (1). Observables X, Y , and Z are the Pauli spin operators, and I is the the identity operator. Measurements of Alice correspond to a row, and those of Bob to a column. Each row is formed of mutually commuting observables whose product is equal to I, and each column of mutually commuting observables whose product is −I. The eigenvalues of each observable are +1 and −1. These facts combined show Rules S1 to S3 are automatically satisfied. Moreover, if O A is any of the given observables for Alice's system, and O B is the corresponding observable for Bob's system, the correlation Ψ| O A O B |Ψ = 1 guarantees the players always win. Figure 1 shows that, unlike for the CHSH game, optimal quantum strategies for the magic square game can be implemented by performing measurements of the Pauli group only.

Levels of correlations
We consider local measurements made on a system shared by two observers, Alice and Bob. 4 Alice chooses an input x ∈ X and observes a corresponding measurement output a ∈ A x . Similarly, Bob chooses an input y ∈ Y and observes a measurement output b ∈ B y . We may implicitly assume that inputs for Alice and Bob are distinguishable from one another, and that each output is labelled by its corresponding input. Hence, we may write the sets of all possible outputs for Alice and Bob respectively as the disjoint unions A = x∈X A x and B = y∈Y B y .
We refer to a fixed configuration of all probabilities P (a, b | x, y) as a behaviour. These behaviours can also be thought of as vectors in R |A×B| , a convention that is particularly useful for dealing with classes of behaviours that are then mapped to sets of vectors.
Behaviours can be characterised according to properties they have, or according to what physical theories can give rise to such behaviours. The weakest condition (and thus the most general set of behaviours) one typically imposes is that "signalling" should be forbidden; behaviours should not allow for superluminal communication. A behaviour is said to exhibit non-signalling correlations [33] if it satisfies both P (a | x) = P (a | x, y) and P (b | y) = P (b | x, y), i.e. the input of one party does not influence the probability of outcomes for the other party. Similarly, a behaviour exhibits quantum correlations if it is realisable under the laws of quantum mechanics, meaning that there exists a joint state |ψ and "local" measurement operators [E a x , E b y ] = 0 that reproduce the behaviour, i.e. such that P (a, b | x, y) = ψ| E a x E b y |ψ . A behaviour exhibits classical correlations if there exists a unique joint probability distribution such that the behaviour arises as marginals. By Fine's theorem [34,Proposition (3)], this also implies that classical behaviours are local. We denote the sets of non-signalling, quantum, and classical behaviours by N , Q, and C respectively.
Given a behaviour, it is not easy to check whether there exists a corresponding quantum model (and thus whether the behaviour belongs to Q). Navascués, Pironio, and Acín [23], [24], in order to characterise the set of quantum behaviours, defined an infinite decreasing hierarchy of non-signalling correlations (known as the NPA hierarchy). These levels of correlations are intermediate; they are weaker than non-signalling correlations, but stronger than the quantum set. The different sets of behaviours in the NPA hierarchy are denoted by Q 1 ⊇ Q 2 ⊇ . . . , and converge to the quantum set in the sense that i≥1 Q i = Q. Each set Q i can be certified by a different semidefinite program.
A further important set of supra-quantum behaviours are the almost quantum correlations [25], which we denoteQ Q. It has been argued that this set is special, as it is the smallest set that contains the quantum set and arises naturally from some information theoretic principle (e.g. local orthogonality [35], non-trivial communication complexity [36], etc.). These correlations arise naturally by weakening a single one of the principles defining quantum correlations. Namely, instead of requiring the local measurement operators to commute, one only requires that they commute when acting on the special state that gives the behaviour, i.e. [E a x , E b y ] |ψ = 0. It is shown in [25] thatQ = Q 1+AB , where Q 1+AB is a set of correlations defined in [24] and satisfying Q 1 Q 1+AB Q 2 in the NPA hierarchy.
Overall, the above correlations satisfy the inclusions Here, it is worth stressing that the win probabilities in any game can only increase when considering a larger set of behaviours. It follows that to (upper or lower) bound the win probabilities for players of a nonlocal game in one level, one can use other levels of correlations that are easier to deal with. In this work, we will mainly be concerned with the non-signalling, almost quantum, quantum, and classical levels of correlations N ,Q, Q, and C respectively, where the almost quantum set is used to upper bound the win probabilities for quantum behaviours.

Magic rectangle games: Definition
More generally than in Section 2.1, it is possible to construct similar games for arbitrary sizes of magic square; a magic square game with m possible questions for Alice and n for Bob corresponds to an m×n table. 5 In order to avoid trivially winning classical strategies, we must also generalize the game rules.
Definition 3.1 (Magic rectangle game). We specify an m × n game by fixing some α 1 , . . . , α m and β 1 , . . . , β n each belonging to {+1, −1}, such that their product satisfies The rules of the given game are then: R1. Each filled cell of the table must belong to the set {+1, −1}.
R2. Upon being assigned the ith row, the product of Alice's entries must be α i .
R3. Upon being assigned the jth column, the product of Bob's entries must be β j .
As before, the game is won if both players enter the same value into their shared cell.
Notice that the requirement of Eq. (4) ensures that no deterministic classical strategy that wins with certainty can exist. In such a strategy, definite values would be assigned to each cell of the table which the players must both follow. The product of all cells would be α 1 . . . α m when calculated according to the rows, and β 1 . . . β n according to the columns, but Eq. (4) is exactly the statement that these products are not equal. Hence, the optimal classical success rate is at most 1 − (mn) −1 . In fact, this success rate is attainable deterministically by Alice and Bob answering according to fixed (but different) tables satisfying Rules R1 to R3, since such tables can always be constructed which differ in only a single one of their cells (Alice's table need not consider Rule R3 and Bob's table need not consider Rule R2). We denote this optimal classical success rate for our m × n magic rectangle games by The number of different specifications of an m × n game allowed by Eq. (4) is 2 m+n−1 , and the standard 3 × 3 magic square game described in Section 2.1 is simply the special case where Let us introduce some further notation to describe our magic rectangle games. We will let X and Y be uniformly distributed random variables taking values in the alphabets X = {1, . . . , m} and Y = {1, . . . , n} respectively, labelling the possible input rows and columns that may be assigned to Alice and Bob. We will denote the possible output rows of Alice and columns of Bob by the random vectors A = (A 1 , . . . , A n ) and B = (B 1 , . . . , B m ) T with alphabets A and B respectively, where each A j and B i takes values in {+1, −1}. Referring to Rules R1 to R3 above, the event that the m × n magic rectangle game is won upon input (X, Y ) = (x, y) is given by Perhaps more naturally for the games we consider, we can equivalently let A and B denote alphabets of the possible question/answer pairs for Alice and Bob allowed by the rules of Definition 3.1. To illustrate why this is the natural choice, we point out that Alice returning a string of ±1's that is not compatible with Rule R2 is equally forbidden with her returning the value 5 for one cell, and thus it is the natural choice to exclude such outcomes from the alphabet altogether. This is mathematically expressed as Then, with (X, A) and (Y, B) instead taking values in alphabets A and B respectively, the winning event upon input (X, Y ) = (x, y) becomes simply We will refer to these A and B as the natural alphabets of a magic rectangle game.
In what follows, we characterise the different sizes of magic rectangle games in terms of their optimal win probabilities and strategies, under different levels of allowed non-signalling correlations (notably quantum, almost quantum, and general non-signalling correlations). We will often suppress the numerical values +1 and −1 to the symbols + and − for simplicity.

Properties of magic rectangle games
To begin our characterisation of the magic rectangle games of Definition 3.1, we first show some general properties of these games, which allow us to narrow the considerations required for a full characterisation. Lemma 4.4 shows in what sense it is possible to identify games of the same dimension together. Corollary 4.5 then shows that for magic rectangle games of a given dimension m × n, all choices of specific values for parameters α 1 , . . . , α m and β 1 , . . . , β n satisfying Eq. (4) yield the same optimal win probability at a given level of allowed correlations L. We unambiguously refer to this value as ω L (m, n) and show in Corollary 4.9 the symmetry ω L (m, n) = ω L (n, m). We show in Corollary 4.11 that ω L (m, n) is independently increasing in both m and n (with an explicit lower bound given in Lemma 4.10 in terms of that for smaller magic rectangle games). Finally, the correlation hierarchy of Eq. (3) implies for any particular game Combining these facts leads us to the path we will take towards a characterisation, as stated in the following theorem.
Theorem 4.1. In order to fully characterise quantum (or stronger) optimal strategies for magic rectangle games of arbitrary dimension, it is sufficient to consider only 1 × n games, 2 × n games with n ≥ 2, and 3 × 3 games. Moreover, only a single example game for each different dimension need be considered.
Proof. Postponed until the end of this section, after we have shown some general properties of magic rectangle games. Remark. Under Definition 4.2, given a fixed allowed level for correlations, all equivalent games have the same optimal win probability; strategies are identified with others of equal win probabilities.
1} n be binary sequences of length n ≥ 2 with the same parity (that is their Hamming weights are either both odd or both even). Consider the operations ϕ i,j on binary sequences, which have the effect of flipping the bits in both the ith and jth positions. Then, there exists an involutory composition of these operations ϕ = ϕ im,jm • · · · • ϕ i1,j1 such that b = ϕ(b).
Proof. Starting with a binary sequence, we can apply operations ϕ i,j one-by-one in the following way: if there are two or more 1's in the sequence, apply the operation which replaces two of the 1's with 0's. If the initial binary sequence had even parity, repeating this process will eventually yield the sequence of zeros. Else, we will eventually have exactly one nonzero element in position k of the sequence. If it is not already the case, we can apply ϕ 1,k to take this to the sequence with exactly one nonzero element occurring in the first position. Hence, we can apply a sequence of these operations, taking each binary sequence to a canonical form depending only on its parity. Since each operation ϕ i,j is involutory, and the operations commute, any sequence of these operations is also involutory and thus invertible. Therefore, we may apply some sequence of the operations ϕ im,jm • · · · • ϕ i1,j1 taking b to its canonical form, and from its canonical form to b .
Lemma 4.4. Let G be an m × n magic rectangle game specified by the parameters α 1 , . . . , α m and β 1 , . . . , β n satisfying Eq. (4), and let G be a magic rectangle game of identical dimension specified by α 1 , . . . , α m and β 1 , . . . , β n also satisfying Eq. (4). Then G ∼ G and, moreover, there exists an involution F on the set of m × n games such that G = F (G).
Proof. Consider the operations F i,j which act on a game with parameters α 1 , . . . , α m and β 1 , . . . , β n to produce an identical game with exception that the sign of both α i and β j have been flipped (this is a valid game as Eq. (4) is still satisfied). Correspondingly, let f i,j and g i,j act on the natural alphabets of the game to produce identical alphabets with the exceptions that each player changes the sign of their output corresponding to the (i, j)th cell of the table.
That is, Upon applying F i,j to a game, the corresponding functions f i,j and g i,j leave the winning event Eq. (8) unchanged for all possible inputs. Moreover, the f i,j and g i,j are bijective when considered as maps to the natural alphabets of the game produced by F i,j . Hence, F i,j takes games to equivalent games.
We will now show that we can apply some sequence of these operations . Transitivity of ∼ then shows the desired equivalence.
Consider the parameters of G as a binary sequence b = (α 1 , . . . , α m , β 1 , . . . , β n ) containing an odd number of negative elements. The operation F i,j applied to G acts to flip the sign of α i and β j . Furthermore, we can always construct an operation F i2,j • F i1,j which flips the sign of α i1 and α i2 , and similarly an operation F i,j2 • F i,j1 which flips the sign of β j1 and β j2 . Thus, by applying a sequence of these operations to G, we can flip the sign of any pair of its parameters in b. Therefore, applying Lemma 4.3 shows the existence of a sequence of these operations F = F i k ,j k • · · · • F i1,j1 such that the game F (G) has parameters given by the binary sequence (also containing an odd number of negative elements) b = (α 1 , . . . , α m , β 1 , . . . , β n ). That is, G = F (G). Finally, since the F i,j are involutory and commute with one another, F is involutory.
Corollary 4.5. Given a fixed correlation level L, all magic rectangle games of dimension m × n have equal optimal win probability, which we denote ω L (m, n).
Proof. G and G in Lemma 4.4 are arbitrary m × n games, and so all games of a fixed dimension are equivalent, and must have equal optimal win probabilities. Definition 4.6 (Transpose game). We define the transpose of an m×n game G (with parameters α 1 , . . . , α m and β 1 , . . . , β n ), denoted by G T , to be the n × m game specified by the parameters α T i = β i and β T j = α j for all i ∈ {1, . . . , n} and j ∈ {1, . . . , m}.
Lemma 4.7. Let G be an m×n magic rectangle game, and fix an allowed level L for correlations. If S L is a strategy for G which wins with probability p, then there exists an involution T between strategies, such that the strategy S T L ≡ T (S L ) for the transpose game G T also wins with probability p.
Proof. We let T be the map which exchanges the roles of the players in a strategy, so that Bob's former strategy is now played by Alice, and vice versa. In particular, under the action of T , Alice in the transpose strategy S T L outputs Bob's columns of the strategy S L as rows. Similarly, Bob in S T L outputs Alice's rows of S L as columns. Such a T is clearly involutory, and preserves the probability assigned to the winning event for magic rectangle games.
Lemma 4.8. Let G be an m × n magic rectangle game, and let G be an n × m magic rectangle game. Fix an allowed level L for correlations. If S L is a strategy for G which wins with probability p, then there exists a bijection f between strategies such that the strategy S L = f (S L ) for G also wins with probability p.
Proof. Let S T L be the transpose strategy of S L , obtained from Lemma 4.7. Then, S T L is a valid strategy for G T , which wins with probability p. By Lemma 4.4, G ∼ G T , and so there exists a bijection F such that the strategy S L = F (S T L ) for G also wins with probability p. The required function f is defined by f (S) = F (S T ).
Proof. Let S L be an optimal strategy for an m×n game G, winning with probability p. Suppose that S L found from Lemma 4.8 (also winning with probability p) is not optimal for an n × m game G . Then, there exists a strategy for G which wins with probability q > p. Again by Lemma 4.8, this implies the existence of a strategy for G which also wins with probability q > p, contradicting the optimality of S L . Hence, S L is an optimal strategy for G . Since G and G were arbitrary, optimal strategies for all m × n and n × m games win with equal probability p = ω L (m, n) = ω L (n, m).
Lemma 4.10. Fix a level of allowed correlation L. Let the optimal win probability of m × n magic rectangle games be given by ω L (m, n). If m ≥ m and n ≥ n, then the optimal win probability of m × n games satisfies Proof. Let G be an m × n magic rectangle game specified by the parameters α 1 , . . . , α m and β 1 , . . . , β n . From this, define an m × n game G such that its parameters are Note that G is indeed a valid game, as its parameters automatically satisfy Eq. (4). Let S L be an optimal strategy for G, winning with probability ω L (m, n), in which Alice outputs according to the random row vector A = (A 1 , . . . , A n ) and Bob according to the random column vector B = (B 1 , . . . , B m ) T . Construct a strategy S L for G in which Alice and Bob play their part of the strategy S L upon inputs 1 ≤ X ≤ m and 1 ≤ Y ≤ n respectively, but deterministically append 1's to their outputs to make up the required output length; upon other inputs, the players output only 1's. That is, It is clear that these outputs always satisfy the rules given in Definition 3.1 for the parameters of G defined in Eq. (12). Moreover, by using strategy S L , the players succeed at G with probability ω L (m, n) upon mn of the m n possible inputs, and with certainty upon the remaining inputs. By Corollary 4.5, the win probability of S L at the m × n game G is at most the optimal win probability for m × n games ω L (m , n ). Hence, since the inputs are chosen uniformly at random, which is exactly Eq. (11).
Corollary 4.11. Fix a correlation level L, and let m ≥ m and n ≥ n. Then Proof. Immediate from Eq. (11) upon noting mn m n ≤ 1 and ω L (m, n) ≤ 1. Having stated and proven the preceding properties of magic rectangle games, it is now easy to see that Theorem 4.1 holds as follows.
Proof of Theorem 4.1. The second part of the claim (that only a single example game for each different dimension need be considered) is shown by Lemma 4.4 and Corollary 4.5, which state that all games of the same dimension are equivalent.
For the first part of the claim, we may first choose to consider optimal strategies for 1 × n games. Then, by Lemma 4.8 and Corollary 4.9, there are invertible maps between optimal strategies for n × 1 games and 1 × n games. Thus, we next study 2 × n games without the need to consider the 2 × 1 case. Similarly, we then need not consider n × 2 cases. Finally, considering the following observations, we can see that all m × n games where both m ≥ 3 and n ≥ 3 can be won with certainty for quantum (or stronger) behaviours. It was pointed out in Section 2.1 that quantum strategies for the standard 3 × 3 magic square game which win with certainty are already known. As the rules Rules S1 to S3 for the standard 3 × 3 magic square game are a special case of our magic rectangle games given in Definition 3.1, the existence of quantum winning strategies for all general 3 × 3 games is guaranteed by Lemma 4.4. Therefore, since by Corollary 4.11 the quantum value ω Q (m, n) is increasing in m and n, and noting the inequalities of Eq. (9), all magic rectangle games with m ≥ 3 and n ≥ 3 satisfy ω L (m, n) = 1, where L is any non-signalling correlation level at least as strong as the quantum set. Furthermore, the proof of Lemma 4.10 combined with Lemma 4.4 shows how to construct winning strategies for all such games from a winning 3 × 3 strategy. Hence, the 3 × 3 games already studied are the final case required to complete the characterisation of magic rectangle games.

Characterisation of magic rectangles
Following Theorem 4.1, we characterise magic rectangle games of all sizes by considering those of dimension 1 × n for n ≥ 1 and 2 × n for n ≥ 2. The final 3 × 3 case was already discussed in Section 2.1.
Theorem 5.1. The optimal success probabilities of all magic rectangle games can be characterised as follows: 1. Games of dimension 1 × n cannot exhibit superclassical behaviour; 2. Games of dimension 2 × n for n ≥ 2 satisfy where the final equality is conjectured, with strong numerical evidence for n ≤ 6. Such games can be won with certainty in the general non-signalling regime; ω N (2, n) = 1.
Moreover, for NPA hierarchy level 1 (or stronger) correlations and n ≥ 3, 3. For all quantum or stronger correlations, games of dimension m × n where both m ≥ 3 and n ≥ 3 can be won with certainty; Proof. The content of Item 1 is Theorem 5.2. The discussion in Section 5.2 covers Item 2. Item 3 was discussed as part of the proof of Theorem 4.1, and can be seen by combining Corollary 4.11 with the fact that ω Q (3, 3) = 1 by Corollary 4.5.

1-by-n magic rectangles
Theorem 5.2. Under any set of non-signalling correlations, the optimal win probability of 1×n games coincides with the classical value, Proof. For all possible inputs Y = j for Bob, his single output value is deterministically equal to β j according to Rule R3 of Definition 3.1. However, recalling Eq. (4) and denoting the product of Alice's single output row by α, we require any valid 1 × n game to satisfy α = β 1 . . . β n . That is, Alice's output row must contain at least one element, in position k say, which differs from the output value β k Bob would give if his input was Y = k. By the assumption of no-signalling, Alice cannot have any knowledge about which of n possible uniform inputs was provided to Bob. Thus, the probability of the losing event that A k = β k (the element of Alice's output corresponding to Bob's input differs from Bob's output) is at least n −1 . Therefore, ω N (1, n) ≤ 1−n −1 = ω C (1, n). Since trivially also ω N (1, n) ≥ ω C (1, n) by Eq. (9), we have the result.

2-by-n magic rectangles
Before discussing the general case of 2 × n magic rectangle games, let us first examine the special case of 2 × 2 magic square games.

2-by-2 magic squares
In this case, Eq. (4) states that either exactly one of the possible rows or columns is required to have a negative product, or exactly one is required to have a positive product. In fact, any such 2 × 2 magic square game can be identified with the well-known CHSH game, in which Alice and Bob are provided binary inputs X CHSH ∈ {0, 1} and Y CHSH ∈ {0, 1} uniformly at random, and win by returning binary outputs A CHSH ∈ {0, 1} and B CHSH ∈ {0, 1} which satisfy [37] A CHSH ⊕ B CHSH = X CHSH ∧ Y CHSH .
Theorem 5.3. Any 2 × 2 magic square game is equivalent (in the sense of Definition 4.2) to the CHSH game.
Proof. Consider the 2 × 2 magic square with specified row products (α 1 , α 2 ) = (+, +) and column products (β 1 , β 2 ) = (+, −). We first show that this game is equivalent to the CHSH game. Then, since all 2 × 2 games are equivalent (Lemma 4.4), the desired result follows by transitivity. We can identify the input events of the two games as Alice identifies her two possible outputs as simply Bob identifies his outputs depending on his assigned input. If Y CHSH = 0 (equivalently Y = 1), then he makes the identifications These identifications form bijections f : A CHSH → A and g : B CHSH → B between the natural alphabets of each game, and are explicitly tabulated in Table 1.
are identical under the functions f and g. We can rewrite these events to more closely resemble one another as x,y∈{0,1} for Eq. (22), and for Eq. (27) x,y∈{0,1} One can verify from the the identifications made (for example by examining Table 1) that terms in the first union above are pairwise equal to those in the second. That is, for all x, y ∈ {0, 1}, Corollary 5.4. The maximum probability with which the 2 × 2 magic square game can be won is (i) (2+ √ 2)/4 ≈ 0.854 for quantum strategies and (ii) unity for general non-signalling strategies.
Proof. The result of Theorem 5.3 means that the maximum attainable win probability for any quantum strategy coincides with that of the CHSH game, namely (2 + √ 2)/4 ≈ 0.854. For the same reason, under PR box assumptions [38], the 2 × 2 magic square game can be won with certainty.
An example of the identifications made for the 2 × 2 magic square game considered in the proof of Theorem 5.3 is depicted in Fig. 2.

General 2-by-n games
As stated in Theorem 4.1, it is enough to consider n ≥ 2. From Eq. (5), the optimal classical win probability for 2 × n games is given by  Table 1. The CHSH win condition of Eq. (22) is also satisfied.
Using the discussion of Section 5.2.1, we can apply Lemma 4.10 to an optimal 2 × 2 quantum strategy with quantum value ω Q (2, 2) = (2+ √ 2)/4 as given in Corollary 5.4. The win probability of the resulting 2 × n strategy lower bounds the 2 × n quantum value via Eq. (11) as In order to find an upper bound for this quantum value, we have used the implementation of the NPA hierarchy found in the Ncpol2sdpa [39] package with the MOSEK [40] semidefinite program solver. Optimal values for different 2 × n games and levels of the hierarchy are shown in Table 2.  Table 2: Optimal win probabilities for 2 × n magic rectangle games, under correlations allowed by different levels of the NPA hierarchy. We see that, for the cases tested, the optimal win probabilities are identical at every level beyond the almost quantum 1 + AB level. Moreover, these values appear to follow exactly the expression given in Eq. (33). For n ≥ 3, we observe games which can be won with certainty at level 1, but with lower than unit probability at the almost quantum and higher levels. Values were obtained through Ncpol2sdpa with the MOSEK solver. Results were also verified with the QETLAB [41] toolbox, using MOSEK [42] within CVX [43].
We note that for all levels 1 + AB and above that were tested, the optimal value is identical for each 2×n game, and appears to bound above the quantum value for n ≤ 6 by the closed-form expression Furthermore, since the complete bipartite graph K 2,n is planar for all n, we know from [21,Theorem 21] that ω Q (2, n) < 1. The classical value given by Eq. (31) and the quantum bounds given by Eqs. (32) and (33) are depicted in Fig. 3.
Conjecture 5.5. The expression for ω 1+AB (2, n) given in Eq. (33) holds for all n ≥ 1.  Table 2), which provides an upper bound to the quantum value; where the line is dashed corresponds to our conjectured values for large n, given by Eq. (33), which have proved to be too computationally intensive to test. The region within which the quantum values could possibly lie is shaded.
Remark. Using the SDPA-GMP [44]- [46] semidefinite program solver with arbitrary-precision arithmetic, we have been able to verify agreement of Eq. (33) with all but the most computationally intensive entries of Table 2 to a much higher precision than printed.
Since under general no-signalling assumptions the 2 × 2 magic square game can be won with certainty (Corollary 5.4), so too can all 2 × n games with n ≥ 2 by Corollary 4.11. It is interesting to note that, as far as the authors are aware, those 2 × n games for n ≥ 3 examined in Table 2 are the first examples of nonlocal games with the property that they can be won with certainty using NPA hierarchy level 1 correlations, but only with less than unit probability using almost quantum level 1 + AB correlations. An explicit strategy for winning the 2 × 3 game with certainty using NPA hierarchy level 1 correlations is given in Appendix A. Hence, by Corollary 4.11, the result that ω 1 (2, n) = 1 for all n ≥ 3 is exact.

Discussion: Magic rectangle characterisation
We now have a complete characterisation of magic rectangle games. We have shown that 1 × n games cannot exhibit superclassical behaviour. Moreover, any magic rectangle game of at least size 3 × 3 can be won with certainty using quantum or stronger correlations. For these games, the interesting properties of strong contextuality and implementation with only Clifford computations of the regular magic square game are preserved. We have also shown that the special case of dimension 2 × 2 is identical to the CHSH game, which is well studied and does not exhibit the aforementioned properties.
Finally, the class of 2×n games for n ≥ 3 is seen to exhibit the richest behaviour: there do not exist perfect quantum winning strategies for these games, however, we have shown superclassical lower bounds on their optimal success probabilities using quantum correlations. We have also given numerical upper bounds on quantum win probabilities for these games with small n, and conjectured a closed-form expression extending to all n. An interesting consequence of our analysis of 2 × n magic rectangle games is that they provide examples of nonlocal games that can be won with certainty using NPA level 1 correlations, and yet for which no quantum (or numerically almost quantum) winning strategy exists (see also Appendix A for an example).
Future works. An interesting future direction is to closer examine this special class of 2 × n magic rectangles. The problem of finding optimal quantum values is still an open question, where the possibilities that they coincide with our lower bounds, upper bounds, or something between all have interesting implications. In the first case, optimal strategies could be implemented using CHSH sub-games. Games of the third case would outperform the CHSH game while also exhibiting a separation between the quantum and almost quantum sets. We believe the second case, in which the quantum and almost quantum sets coincide for each magic rectangle, to be the most likely. This would provide further evidence of the naturality of almost quantum correlations. Once specific strategies (for games beyond CHSH) have been obtained, one could directly see how these perform for various device-independent cryptographic primitives or selftesting.

Application to certified randomness expansion
In this section, we will be concerned with utilising the Bell inequality violations provided by magic rectangle games to achieve certified randomness expansion, using the device-independent spot-checking protocol R gen described in [14, Figure 2]. The main technical result of this section is to relate the win probabilities of m × n magic rectangle games with distinguished input, to those of (m − 1) × (n − 1) games. This enables us to get the optimal noise tolerance of such games, as well as to simply obtain rates for randomness expansion using general magic rectangle games. In terms of rates, there are new techniques that could improve our results, but would need to be examined on a case-by-case basis (see also Section 6.3).
Given a nonlocal game, we will denote by ω its optimal win probability over quantum devices, and byω its optimal win probability over quantum devices with a distinguished input (that is, devices which give deterministic outputs upon a single distinguished choice of input). Protocol R gen is shown to produce quantum-secure extractable bits over N rounds, provided its score acceptance threshold parameter satisfies χ >ω. In our notation, this result can be stated as 2. The function π is nonzero on the interval (ω, ω]. 3. The function ∆ tends to 0 as (b, q) → (0, 0).
They note that modelling noise as a process in which an adversary is allowed to change the outputs of a device arbitrarily with some probability at each use, the noise tolerance of the protocol is ω − χ, since the adversary is allowed to change the expected score at the game by at most this amount. The noise tolerance is then maximally ω −ω.
Furthermore, an explicit lower bound on the function π was proved in [14], and can be stated as follows.
Theorem 6.2 ([14, Theorem 5.8]). Let G be a game with output alphabet size r ≥ 2, and letω be the maximum win probability of this game over compatible devices with a distinguished input.
Then, the following function is a rate curve:

Win probability with distinguished input
Since 1 × n magic rectangle games do not exhibit superclassical behaviour (Theorem 5.2), such games cannot be used in randomness expansion. We construct an optimal strategy for arbitrary m × n magic rectangle games having a distinguished input, where m, n ≥ 2.
Theorem 6.3. Fix an allowed level L for non-signalling correlations. The optimal win probability for any m × n magic rectangle game having a distinguished input, with m ≥ 2 and n ≥ 2, is given byω A strategy which attains this value is to play an optimal strategy for (m − 1) × (n − 1) games, but with all output strings extended to include one deterministic entry.
Proof. Without loss of generality, let us choose this distinguished input to be given by the event (X = 1) ∩ (Y = 1). Recall that the event that the game is won upon some input is given in Eq. (6). We will let W x,y ≡ W m,n x,y throughout the following for brevity. By imposing the no-signalling principle, we see that for all inputs x ∈ {1, . . . , m} and y ∈ {1, . . . , n}, there exists an output entry a x ∈ {+1, −1} for Alice such that where the second equality uses our conditioning on Eq. (6); the first, third, and fourth equalities use no-signalling; and the final equality comes from the third line alongside our choice of distinguished input. Similarly, there exists an output b y for Bob such that Combining Eqs. (36) and (37) yields Now, since for arbitrary events W , E, and F we have from Eq. (38) we can see We can now calculate the win probability for a device with a distinguished input. Expanding according to the uniformly distributed input variables and applying the result of Eq. (40) gives It is clear that if a 1 = b 1 then W 1,1 = ∅, and the first term of Eq. (41) vanishes so that P (W X,Y ) ≤ 1 − (mn) −1 . Let us now assume that a 1 = b 1 . In the case where n j=1 b j = α 1 , we can bound the terms of Eq. (41) where X = 1 as Similarly, in the case where m i=1 a i = β 1 , we can bound the terms where Y = 1 as Therefore, we have shown P (W X,Y ) ≤ 1 − (mn) −1 = ω C (m, n) in all cases other than where However, in all such remaining cases, combining the above Eq. (44) with the product condition for the α i and β j given by Eq. (4), and defining new symbols α i ≡ a i+1 α i+1 and β j ≡ b j+1 β j+1 , yields We will now assume Eq. (45) to be true in order to completely bound P (W X,Y ). Further bounding the win probability expansion of Eq. (41) by setting terms conditioned on X = 1 or Y = 1 to unity, we get Under a relabelling of the input variables, the square-bracketed terms above coincide exactly with the win probability of an m − 1 × n − 1 magic rectangle game, with its rules for row and column products specified by α 1 , . . . , α m−1 and β 1 , . . . , β n−1 respectively. These α i and β j specify a valid magic rectangle game since they satisfy Eq. (4), as shown by Eq. (45). Hence, we have the attainable upper bound Combining this with Eq. (46) gives the bound whereω L (m, n) is defined in Eq. (35) as We see this has the same form as Eq. (11). Indeed, the proof of Lemma 4.10 constructs a strategy which attains this bound and is deterministic upon one input. Finally, since for all levels of correlations L, Eq. (35) shows the upper boundω L (m, n) is always at least that of 1 − (mn) −1 = ω C (m, n) found for the previously considered cases. Therefore,ω L (m, n) represents the complete upper bound on the win probability of an m × n magic rectangle game with distinguished input and allowed non-signalling correlation level L.
6.2 Performance: Noise tolerance and rates Lemma 6.4. The magic rectangle games which can be used in the R gen protocol are those with dimension 2 × n where n ≥ 2, and dimension 3 × n where 2 ≤ n ≤ 7, along with their symmetric counterparts. If Conjecture 5.5 is true, this extends to all n ≥ 2.
Proof. We know from Theorem 5.2 that 1 × n games do not exhibit superclassical behaviour, and so cannot be used for randomness expansion. By Theorem 6.1, then, we seek m × n games with m, n ≥ 2 for whichω Q (m, n) < ω Q (m, n). This is clearly not the case for m, n > 3, since ω Q (m, n) = 1 for m, n ≥ 3, and substituting this into Eq. (35) of Theorem 6.3 yields ω Q (m, n) = 1 for m, n > 3. Thus, ω Q (m, n) =ω Q (m, n) for m, n > 3. It remains to show that 2 × n games for n ≥ 2 and 3 × n games for n ≥ 3 can be used in R gen . Then, the symmetry provided by Lemma 4.8 in ω Q (m, n) (and inherited byω Q (m, n) through Eq. (35)) shows that games with dimensions symmetric to those may also be used. Consider the 2 × n games for n ≥ 2. Using Theorem 5.2 in Eq. (35) gives where the final inequality is established by comparing with Eq. (32). Now consider the 3 × n games for n ≥ 3. From Eq. (33), we have the upper bound ω Q (2, n − 1) < 1 (which we can only assume holds for n ≤ 7 unless Conjecture 5.5 is true). Substituting into Eq. (35), we get where the final equality uses Corollary 4.11.
For the magic rectangle games which may be used in the protocol R gen (shown in Lemma 6.4), Theorem 6.1 results in a maximum noise tolerance of Furthermore, combining Theorem 6.1 with the universal lower bound of Theorem 6.2 shows that R gen produces (asymptotically in the number of protocol rounds) quantum-secure extractable bits at a rate of at least per round, where χ ∈ (ω, ω], and r ≥ 2 is the total size of the output alphabet for the game. According to Rules R2 and R3, a magic rectangle game of dimension m × n has 2 m−1 · 2 n−1 possible outputs. Substituting the result of Theorem 6.3 forω, this lower bound on the rate can be written for m × n magic rectangle games as whereω Q (m, n) is as given in Eq. (35). The maximum possible lower bound that Theorem 6.2 can achieve for the rate then occurs when the score acceptance threshold is set to its maximum χ = ω Q (m, n), such that there is no tolerance to noise, and is given by π max m,n = π m,n (ω Q (m, n)) = 2(log 2 e)(ρ max m,n ) 2 2 m+n−2 − 1 .
While this lower bound has the advantage that it only depends only on the dimension of the magic rectangle used, it gives rates that are far from optimal. More practical lower bounds on the rate for the spot-checking protocol could, for example, be calculated based on the techniques of [29], or numerically as in [30]. The noise tolerance for the CHSH game, or equivalently the 2 × 2 magic square game (Theorem 5.3), is already known to be ( √ 2 − 1)/4 ≈ 10.4%, and this is confirmed by Eq. (53). Combining our characterisation of magic rectangle games from Section 5 with the result of Theorem 6.3, we summarise the performance of all viable magic rectangle games in Table 3. Since the exact quantum values of the 2 × 2 and 3 × 3 games are known, inserting Eq. (35) of Theorem 6.3 into Eq. (53) gives exactly the optimal noise tolerance for R gen using the 3 × 3 game. Hence, the 3 × 3 noise tolerance stated in Table 3   . For 2 × 2 and 3 × 3 games, upper and lower bounds coincide, so their optimal noise tolerance is exact. The 3 × n lower bounds shown for n ≥ 8 are based on Conjecture 5.5. The 2 × n upper bounds for n ≥ 7 are also based on Conjecture 5.5, but may be more weakly bound as in Eq. (57). As noted in the main text, the rates found from Miller and Shi [14] depend only on the dimension of the magic rectangle game used. More practical rates could be calculated using the techniques of [29], [30].
It is important to note that, in Table 3, the upper bounds given for the noise tolerance and rate of 2 × n games where n ≥ 7 are calculated based on our Conjecture 5.5, that Eq. (33) holds for all such n. However, by trivially weakening Eq. (33) to ω Q (2, n) ≤ 1, we can still find less strict upper bounds for these quantities which must hold. Inputting this relaxation into Eqs. (53) and (56), we arrive at ρ max 2,n ≤ 1 2n , π max 2,n ≤ log 2 e 2n 2 (2 n − 1) .
These expressions are also strictly decreasing with n and, for the conjectural cases of n ≥ 7, do not exceed the upper bounds for the 2 × 3 game given in Table 3.

Discussion: Magic rectangles for certified randomness expansion
The optimal noise tolerance of an m × n magic rectangle game for certified randomness expansion in the spot-checking protocol is fully determined by the difference of the optimal quantum win probability ω Q (m, n) and the optimal quantum win probability with distinguished input ω Q (m, n). In Theorem 6.3 we relateω Q (m, n) with ω Q (m − 1, n − 1), and given that we have characterised the quantum win probabilities for magic rectangle games of all dimensions in Theorem 5.1, we can obtain the noise tolerance of all magic rectangle games (Table 3). Specifically, the noise tolerance of an m × n is given as the difference between its quantum value, and the corresponding value of the (m − 1) × (n − 1) game extended to dimension m × n by including in each of its outputs a deterministic entry. It follows that only magic rectangle games of dimension 2 × n and 3 × n, with n ≥ 2 can be used for certified randomness expansion (larger rectangle games fail, since the games can be won with certainty even with a distinguished input). Moreover, we can also see from Table 3 that the most robust game turns out to be the 2 × 2 magic square game (which we showed is equivalent to the CHSH game). The values given for general 2 × n and 3 × n games are strictly decreasing with n and, furthermore, of these only the 2 × 2 and 2 × 3 games outperform the noise tolerance and rate bound given for the 3 × 3 game. From the equivalence with the CHSH game, optimal strategies for the 2 × 2 game can be implemented using only a single Bell state shared between the players, whereas all known implementations of optimal strategies for the 3 × 3 game require a system of at least two Bell states. However, implementations of certain winning 3 × 3 strategies may still be advantageous, for example in cases where physical limitations on the quantum devices dictate certain additional constraints (such as requiring the use of only Clifford gates), or in the context of self-testing (where the use of pairs of Bell states enables parallel self-testing).
Future works. An important remaining question is that of the optimal rates that one can achieve with magic rectangle games. Since we showed that, in terms of noise tolerance, the optimal game coincides with the CHSH game, analysis of the rates has already been done extensively. However, it is still an interesting problem to obtain rates for all the games (whether this is because one is interested in a specific game, or because a protocol may provide better rates with worse noise tolerance-something conceivably possible).
Note that in Table 3 we do give some rates for all the different games. Theorem 6.2 directly relates noise tolerance to a lower bound on the rate of randomness expansion, which we can (and do) use to directly obtain indicative rates (Table 3 last column). However, we would like to stress that the rates obtained from this expression (unlike our noise tolerance analysis) are far from optimal. More practical rates can be calculated, for example, by referring to the techniques outlined in [29], or numerically as in [30]. To obtain these improved rates requires an involved, case-by-case analysis that treats each magic rectangle game separately, something that is sensible to do if one is interested in a given game, and is left for future publications.
Acknowledgements. We would like to thank Matty J. Hoban for useful discussions. S.A.A. gratefully acknowledges EPSRC studentship funding under grant number EP/R513209/1.

A Winning 2-by-3 games at NPA level 1
Consider the 2 × 3 magic rectangle game in which entries to the first column are required to have a negative product, and all other row and column products are required to be positive. That is, the 2 × 3 game specified by the parameters (β 1 , β 2 , β 3 ) = (−, +, +) and (α 1 , α 2 ) = (+, +) satisfying Definition 3.1. In order to write our strategy more easily, in Table 4 we introduce a more concise alphabet for the inputs and outputs of the game.