1 Introduction

The possibility of explaining the results obtained in quantum mechanics within a theory admitting hidden variables has been excluded via two theorems. The Bell-Kochen-Specker theorem [1, 2], which is the most general, and the theorem of John Bell [3]. The first one discards all the noncontextual hidden variable (NCHV) theories, namely all those in which physical quantities have a predefined outcome value, no matter the experimental context. A context is defined by the other comeasurable observables that are measured simultaneously with a given one. The formalism of quantum mechanics imposes that two observables, A and B, are comeasurable if their associated operators commute, i.e. \( [ A, B ]:= AB - BA = 0 \). The second theorem rules out local hidden variable (LHV) theories. Originally, Bell employed a locality argument in formulating his theorem. He postulated that if two systems lie outside each other’s light cones, any measurement conducted on one system will not impact the other. This locality assumption is a fundamental constraint for these theories. Consequently, the outcomes of measurements on spatially separated systems remain unaffected by the specific selection of measurement settings in a different, spacelike-separated region of space-time.

The conflict between the assumptions of quantum mechanics and the concept of locality can be demonstrated in two distinct ways. One way is through the violation of an inequality that local hidden variable (LHV) models would normally satisfy. The other way is by revealing a logical contradiction between the predictions of quantum mechanics and those of LHV models.

Specifically, the first approach, based on inequality violation, provides remarkable and empirically testable cases. For instance, the Clauser-Horne-Shimony-Holt (CHSH) inequality [4] is defined in terms of two-point correlation functions. On the other hand, the more comprehensive Clauser-Horne (CH) inequality [5] is expressed in terms of joint probabilities. For scenarios involving more than two parties, other examples of inequalities can be found in [6, 7, 8].

The main difference between the Bell-Kochen-Specker theorem and the Bell’s one is the number of systems they involve. In fact, the proof of the former refers to a single individual system but requires carrying out measurements of non-compatible observables that cannot be simultaneously measured on an individual system. Whereas the proof of the Bell theorem, in the form of inequality, involves the outcome statistics of measurement performed on different separated subsystems. Moreover, Bell inequalities are satisfied by any LHV theory and they are independent of the assumptions needed in quantum mechanics [9].

In contrast, the original proofs of the Bell-Kochen-Specker theorem refer to NCHV theories that share some properties with the formulation of quantum theory. Consequently, this enables two distinctive tests of the contextual nature of quantum mechanics, generally referred to as state-independent, as in the argument of Peres-Mermin square, and state-dependent contextuality. The primary distinction between these tests lies in their sensitivity to state preparation and the considered measurement scenario. The state-independent test reveals a contradiction between noncontextual hidden variable (NCHV) theories and quantum mechanics, regardless of the state’s preparation. In contrast, the state-dependent test is scenario-sensitive. The most well-known of these tests include the KCBS inequality for qutrits [10] and the CHSH [4], both of which form part of a broader range of inequalities associated with compatibility structures.

The aim of this paper is to link tests of quantum contextuality to the deeper explored field of Bell-nonclassicality. The latter has been proven that constitutes the essential resource for applications such as device-independent protocols [11], and while understanding the relevance of the former to quantum computation and information processing is still in its infancy, see [12] for a thorough discussion. In fact, possible new forms of quantum information technologies involving the least number of physical systems, such as cryptographic protocols [13, 14] and sensing [15], require a deeper understanding of the quantum resources fueling their advantage over classical approaches [16, 18]. This research aiming at characterizing robust and trustful certification of quantumness with a single particle is an active field of research [18, 19, 20, 21].

We investigate a particular instance of the relationship between a noncontextuality inequality violation stemming from a two-qubit Peres Mermin square and the maximal violation of the CHSH inequality. As pointed out in ref. [22], a still valuable avenue for future research is to explore how contextuality can be converted into nonlocality. This is an old open problem in quantum theory, whose investigation started in the 1970s and followed two lines of research: the one culminated in the so-called free will theorem [23] and the other originating from the Peres-Mermin proof of the Kochen-Specker theorem.

2 Kochen-Specker–Like Noncontextuality Inequalities

In this section, we review the basic concept of quantum contextuality in the sense of Kochen-Specker and Bell-nonclassicality, focusing our attention on tests involving systems belonging to the Hilbert space \(\mathbb {C}^4\simeq \mathbb {C}^2\otimes \mathbb {C}^2\).

2.1 Tests of Quantum Contextuality à la Cabello

The simplest argument that manifests Kochen-Specker contextuality has been introduced by Peres and Mermin [24, 25, 26, 27]. This approach is known as the Peres-Mermin (PM) square, due to the fact that the nine considered measurements are arranged in a \(3 \times 3 \) square. All measurements are dichotomic (i.e., they have only two possible results \(-1\) or \(+1\)) and a context is given by the product of three measurements in a row or in a column. The PM square then reads:

$$\begin{aligned} \textrm{PM} = \begin{bmatrix} O_{11} &{} O_{12} &{} O_{13} \\ O_{21} &{} O_{22} &{} O_{23} \\ O_{31} &{} O_{32} &{} O_{33} \\ \end{bmatrix} \end{aligned}$$
(1)

Any classical NCHV theory assigns a preexisting value to the outcomes independently of the state preparation and context. Therefore we can introduce the first inequality based on the \(\textrm{PM}\) square:

$$\begin{aligned} \textrm{PM}= & {} \langle O_{11} O_{12} O_{13} \rangle +\langle O_{21} O_{22} O_{23} \rangle +\langle O_{31} O_{32} O_{33} \rangle \nonumber \\+ & {} \langle O_{11} O_{21} O_{31} \rangle +\langle O_{12} O_{22} O_{32} \rangle - \langle O_{13} O_{23} O_{33} \rangle \le 4, \end{aligned}$$
(2)

where

$$\begin{aligned} \langle O_{ij} O_{kl} O_{mn} \rangle \equiv \text {Prob}[O_{ij} O_{kl} O_{mn} = 1 ] - \text {Prob}[O_{ij} O_{kl} O_{mn} = - 1 ] \end{aligned}$$

is computed by preparing an ensemble of systems in the same state and measuring the three quantities. It is easy to prove that in any classical theory, the bound 4 is never violated [9]. Moving to the quantum domain, one can associate an observable to each measurement \(O_{ij}\), with the condition that if two observables share a subindex, then they are compatible. Thence, introducing \(\sigma _\alpha \) with \(\alpha =\{0, x, y, z\}\) (\(\sigma _0\) denotes the identity operator) in the case of a two-qubit system, one has:

$$\begin{aligned} PM = \begin{bmatrix} \sigma _z \otimes \sigma _0 &{} \sigma _0 \otimes \sigma _z &{} \sigma _z \otimes \sigma _z \\ \sigma _0 \otimes \sigma _x &{} \sigma _x \otimes \sigma _0 &{} \sigma _x \otimes \sigma _x \\ \sigma _z \otimes \sigma _x &{} \sigma _x \otimes \sigma _z &{} \sigma _y \otimes \sigma _y \\ \end{bmatrix} \end{aligned}$$
(3)

and the expectation value on a state \( |{\psi }\rangle \) is given by

$$\begin{aligned} \langle {O_{ij} O_{kl} O_{mn}}\rangle = \langle {\psi }|O_{ij} O_{kl} O_{mn} |{\psi }\rangle . \end{aligned}$$
(4)

The computation of the expectation value of the product of observable on either a row or a column straightforwardly yields a result of 1, with the exception of the third column, which provides a result of \(-1\). Consequently, this leads to an expectation value of \( PM = 6\) for each quantum mechanical state under consideration. Notably, experimental findings consistently align with the quantum mechanics prescription [28, 29]. Additionally, this principle has been recently expanded to encompass bosonic fields [30]. To summarize, the PM inequality in (2) is derived under the assumption that the value of the outcomes of the nine observables are independent of the context in which they are measured, hence its violation implies that an a priori value cannot be assigned, thereby underscoring the role of context in the measurement process.

The inequality in (2) can be written in terms of a sum of probabilities once the orthogonality graph associated with such a scenario is known [22]. This task has been carried out and tested in several experimental setups, see e.g. [31, 31], and the corresponding test of contextuality is then given by the following inequality:

$$\begin{aligned} \sum _{k=0}^9 P(\Pi _k = 1) \le 3, \end{aligned}$$
(5)

with the upper bound satisfied by any noncontextual hidden variable theory, while quantum mechanics and generalized probabilistic theories achieve the value \(\frac{7}{2}.\) In this particular scenario, the ten projectors, \(\Pi _k = |{u_k}\rangle \langle {u_k}|\), follow exclusivity relationships, and the unit vectors defining them are the following

$$\begin{aligned} \langle {u_0}|\equiv&\frac{1}{\sqrt{2}} (0,0,1,1), \\ \langle {u_1}|\equiv&\frac{1}{2} (1,-1,1,-1), \\ \langle {u_2}|\equiv&\frac{1}{2} (1,-1,-1,1), \\ \langle {u_3}|\equiv&\frac{1}{\sqrt{2}} (1,0,0,-1), \\ \langle {u_4}|\equiv&\frac{1}{2} (1,1,1,1), \\ \langle {u_5}|\equiv&\frac{1}{\sqrt{2}} (0,1,0,-1), \\ \langle {u_6}|\equiv&\frac{1}{2} (-1,1,1,1), \\ \langle {u_7}|\equiv&\frac{1}{\sqrt{2}} (1,0,0,1), \\ \langle {u_8}|\equiv&\frac{1}{2} (1,1,1,-1), \\ \langle {u_9}|\equiv&\frac{1}{2} (1,1,-1,1). \end{aligned}$$

More recently, Cabello and coauthors in a series of papers [9, 32, 33] presented several inequalities that are experimental-friendly and that can detect quantum noncontextuality [34]. We revise here his reasoning briefly. Let us consider again dichotomic observables as in the PM square case and with the same definition of compatibility based on a shared subindex. Cabello proved that in any NCHV theory, the following inequality holds:

$$\begin{aligned}- & {} \langle O_{12} O_{16} O_{17} O_{18} \rangle - \langle O_{12} O_{23} O_{28} O_{29} \rangle - \langle O_{23} O_{34} O_{37} O_{39} \rangle \nonumber \\- & {} \langle O_{34} O_{45} O_{47} O_{48} \rangle - \langle O_{45} O_{56} O_{58} O_{59} \rangle - \langle O_{16} O_{56} O_{67} O_{69} \rangle \nonumber \\- & {} \langle O_{17} O_{37} O_{47} O_{67} \rangle - \langle O_{18} O_{28} O_{48} O_{58} \rangle - \langle O_{29} O_{39} O_{59} O_{69} \rangle \le 7. \end{aligned}$$
(6)

The maximal classical value is computed considering all the possible values of the product of the 18 observables, and then if we can measure it on different systems, the average satisfies the bound in (6). It is worth underlining that the product cannot be measured on a single system because it contains observables that are not compatible. Anyway, the fundamental assumption is that the result of any of the observables \(O_{ij}\) is independent of the context in which it is measured. So, one can measure during an experimental run a subset of compatible observables on equally prepared states. In the case of a physical system of dimension \(d=4\), the quantum mechanical prediction of the left side of (6) is 9, independently of the state, and that is indisputably violating the value obtained within a noncontextual theory.

A recent work that appears to be at the moment the simplest approach to connect Kochen-Specker and Bell’s theorems has been addressed in [22]. There, the method is to map measurements acting on a single system, into bipartite measurements on a maximally entangled state. The main observation there is that the expectation values of bipartite operators on a maximally entangled state are (almost) equal to the corresponding expectation value of their products on the local marginal mixed states. Therefore, a mapping between a contextuality scenario for a system of dimension \(d\ge 3\) can be mapped in a bipartite Bell scenario with two subsystems of dimension d. However, it is known that the qutrits are the smallest quantum systems for which one can show contextual behavior.

2.2 CHSH-Bell Inequality

A similar derivation of the inequality in (6), but assuming that the result of a measurement of an observable \(O_{ij}\) does not dependent on spacelike separated measurements and not on compatible measurements, leads to the well celebrated CHSH-Bell inequality [4, 35, 36]. In this case, the measurements are also dichotomic, but one has to identify spatially separated observers acting on a different subsystem. We denote the observables of the first part by \(A_i\) and those of the second by \(B_i\), and we can introduce the Bell–CHSH functional as:

$$\begin{aligned} \mathcal {B}= \langle A_1 B_1 \rangle + \langle A_1 B_2 \rangle + \langle A_2 B_1 \rangle - \langle A_2 B_2 \rangle . \end{aligned}$$
(7)

This expression constitutes a necessary and sufficient condition to establish if a state admits a description in terms of a LHV model derived under the assumption of local realism. In fact, all they are constrained by \(\mathcal {B} \le 2.\) A similar bound can be derived also for all quantum states, there are no quantum states that can have a value \(\mathcal {B} \ge 2\sqrt{2}\), this value is often referred to as Tsirelson bound [37].

3 Quantum Contextuality vs Bell-Nonclassicality

In this section, we compare the violations of two inequalities, having different aims. The first one holds in any NCHV theory, and the second one in any LHV theory. The main difference between them is that the first one is violated by any quantum state, while the second is necessarily violated only by non-separable states.

Fig. 1
figure 1

The probability distribution P(C) of the expression in (8) for an ensemble of \(M=10^6\) two-qubit random pure states. We give also the first four central moments of the distribution \(\{3.998, 0.808, 0.00038, 2.132\}\). The black dashed line corresponds to the value separating states admitting a NCHV model \((C\le 4)\) and those violating the contextuality inequality considered \((C>4)\). Considering we are dealing with a finite number of states it is worth reporting also the median of the distribution, i.e. \(m_{P(C)}= 4.007\)

In order to infer the nonlocal properties from the contextual one we need to identify two appropriate inequalities. The author of [9] shows how a particular variation of the observables considered by Peres and Mermin to prove the Bell-Kochen-Specker theorem can also serve as a state-dependent test of Bell nonlocality for two-qubit systems. In particular, when the term \(O_{33}\) is replaced with the four-dimensional identity operator the lhs of the inequality can be reformulated as:

$$\begin{aligned} C= & {} \langle O_{11} O_{12} O_{13} \rangle +\langle O_{21} O_{22} O_{23} \rangle +\langle O_{31} O_{32} \rangle \nonumber \\+ & {} \langle O_{11} O_{21} O_{31} \rangle +\langle O_{12} O_{22} O_{32} \rangle - \langle O_{13} O_{23} \rangle . \end{aligned}$$
(8)

If we generate all the \(2^{2^3}\) possible classical values of C,  we obtain the bound satisfied in a NCHV theory, namely \(C\le 4\). To test quantum states, we use the observables as in (2). This inequality is maximally violated by the product state \(|{\circlearrowleft }\rangle |{\circlearrowleft }\rangle ,\) where \(\sigma _y|{\circlearrowleft }\rangle = +1 |{\circlearrowleft }\rangle ,\) for which it reaches the value \(C=6.\) This is related to the fact that any quantum state would violate the inequality in (2) and returns the same value for every quantum state due to the set of measurements considered. In contrast, the noncontextual bound that follows from the expression we have introduced in (8) allows us to perform a state-dependent test of noncontextuality.

Fig. 2
figure 2

We report the histogram of the probability distribution \(P(B_{\max })\) of the expression in (7) for the ensemble of \(M_c=50212\) two-qubit random pure states satisfying the constraint on the contextual behavior \(C > 4.\) The dashed black line on the left indicates the threshold value separating states admitting a local model \((B\le 2)\) and those violating local realism \((B>2)\), while the dashed black line on the right corresponds to the Tsirelson bound \((B=2\sqrt{2})\)

The second inequality has been already introduced in (7). In the case of two-qubit systems one can introduce as dichotomic local observables the measurements along an arbitrary direction in the Bloch sphere of one of the two observers. Therefore, the quantum mechanical observables are parametrized in the following way \(W_j = \textbf{w}_j \cdot \varvec{\sigma }\), in which \(X=\{A, B\}\) and \(j=\{1,2\},\) and explicitly we have:

$$\begin{aligned} \hat{{\textbf {w}}_j}\cdot \varvec{\sigma } = \left( \begin{array}{cc} \cos \theta _{w_j} &{} e^{- i \phi _{w_j}} \sin \theta _{w_j} \\ e^{i \phi _{w_j}} \sin \theta _{w_j} &{} \cos \theta _{w_j}\\ \end{array} \right) , \end{aligned}$$
(9)

where the angles \(\theta _{w_j}, \phi _{w_j}\) define the direction of the unit vector \(\textbf{w}_j\), namely \(\textbf{w}_j= (\sin \theta _{w_j} \cos \phi _{w_j},\sin \theta _{w_j}\sin \phi _{w_j},\cos \theta _{w_j}).\)

Our first aim is to study the typical behavior of the value of C defined in (8). For this reason, we have generated a random ensemble of \(M=10^6\) pure two-qubit states [38]. They are obtained by choosing the columns of a random unitary matrix generated according to the Haar measure of SU(4) [39, 40].

In Fig. 1 we report the histogram for the probability distribution P(C) evaluated numerically using the ensemble of random states. It is evident from our empirical evidence that the probability to have a two-qubit violating the value of 4, for which a NCHV description is possible, is \(P(C \ge 4) \simeq 1/2.\)

Subsequently, we have selected a subensamble \(M_c\) of the original ensemble M, which is composed of the states violating the noncontextual bound. We have computed the optimal violation of the expression in (7). Namely, we have performed an optimization over the eight angles that defines the four directions necessary to perform the Bell test, in the form of a violation of the CHSH inequality, the optimization problem can be formulated as follow: and computed the maximum value:

$$\begin{aligned} B_{\max }= \max _{\theta _{A_1}, \phi _{A_1}, \theta _{A_2},\phi _{A_2}, \theta _{B_1}, \phi _{B_1}, \theta _{B_2}, \phi _{B_2}} \vert \langle {\psi }|\mathcal {B} |{\psi }\rangle \vert . \end{aligned}$$
(10)

For the optimization, we employed the RandomSearch algorithm present in the Wolfram Mathematica software. The choice compared with the other optimization algorithms offered by the same software provides the most reliable results, and in a shorter time, see also [41]. The results are shown in Fig. 2. The histogram shows that all the states that are quantum contextual according to the definition given in (8) do not also admit a description in terms of local realism. Moreover, considering that we have only considered pure states, the violation of the CHSH is also a signature of the nonseparability of the states and therefore, that it is entangled [42]. It is worth noting now that the contextuality test has been conducted with measurements along fixed axes, and does not require any numerical optimization as in the case of the CHSH test. Moreover, to assess the entanglement content of a state from the experimental point of view (e.g. by performing any methods based on the singular value decomposition), requires a full tomography of the state, that in the case of qubit requires a quorum of observables higher [43] than those required to evaluate C.

One question remains to be answered. Is it possible to infer from the value of the functional C how strongly a state violating the noncontextual classical will violate also the CHSH inequality? In other words, we are asking if the magnitude of the violation of the classical bound of C for a given state \(|{\psi }\rangle \) can give any information on how much that same state would violate the local realism. The answer emerging from our numerical analysis is negative and it is reported in Fig. 3. There, we have plotted the value of \(B_{max}\) as a function of the corresponding value of C for all the \(M_c\) states. This analysis confirms that contextuality and Bell nonlocality are independent concepts unless further studies towards this direction would unveil the existence of an underpinned mechanism that activates an emergent fundamental connection between them. This goes into the direction pointed out in [44] that there is no contextuality-nonlocality tradeoff, even if they consider a qutrit-qubit system.

Fig. 3
figure 3

We show the numerical values obtained for the \(M_c\) used to plot the histogram in Fig. 2 and compare for each of the quantum contextuality with the corresponding value of the maximal violation of the CHSH inequality. The lower and upper horizontal black dashed lines refer to the classical and Tsirelson bound, respectively. While the left and right vertical black dashed lines represent the minimum and maximal quantum contextualize, that we were numerically able to achieve with the functional in (8)

4 Conclusions and Applications

The forthcoming success of quantum technologies like cryptography, computing, and sensing is inextricably linked to advancements at the most fundamental level. Therefore expanding the theoretical and foundational basis for the design of future quantum technologies is nowadays of paramount importance. In particular, we studied the relationship between quantum contextuality and Bell-nonclassicality for an ensemble of two-qubit pure states. We focused on pure states because, in the near future we expect to move from noisy quantum devices to fault-tolerant ones. Therefore, the need to devise a test for evaluating effective quantum resources is increasingly essential. Therefore, the need to devise a test for evaluating effective quantum resources and the connection among them [45] is essential. Drawing inspiration from one of the most straightforward proofs of quantum contextuality - the Peres-Mermin square - we managed to establish a link between a simple inequality targeted at demonstrating quantum contextuality and the impossibility of depicting the state in a local realistic scenario.

Our analysis based on typical pure quantum states seems to suggest that the violation of the noncontextual bound of (8) is a sufficient condition for the subsequent violation of the CHSH inequality. Anyway, we are aware that this cannot be true due to the fact that a separable state maximally violates the aforementioned bound. In our opinion, a deeper analysis, outside the scope of the present paper, is to investigate the relationship between the local polytope [35] defined in the CHSH scenario and the noncontextual one. We acknowledge that experiments testing Bell inequalities on different degrees of freedom of the same particle, have to be intended as a way to rule out NCHV theories and not the LHV models [46]. In contrast, our aim is complementary to those already established and we numerically addressed how the detection of the violation of a suitably chosen Bell-like inequality for contextuality would give a hint on the amount of “truly” Bell-nonclassicality of the state. We conclude our paper we a future outlook. In fact, we believe that akin to the analysis performed here one can check how a contextuality scenario for a qudit with \(d\ge 4\), e.g. a single spin\(-3/2\) particle or two qubits. It is interesting to characterize in terms of contextual and local polytopes and how one can be converted into a nonlocality [47] and performing a similar statistical analysis performed here.