Introduction

The Kochen-Specker (KS) theorem1,2 is a cornerstone result in the foundations of quantum mechanics, which delineates the differences between quantum theory and a class of hidden-variable theories obeying the principle of non-contextuality (NCHVTs). NCHVTs assume that outcomes are pre-assigned to measurements and independent of the particular contexts in which the measurements are realized. Informally, the KS theorem states that for every quantum system belonging to a Hilbert space of dimension d greater than two, irrespective of its actual state, a finite set of measurements exists whose results are logically impossible to be assigned of truth value 0 or 1 in a context-independent manner, satisfying (i) Exclusivity: two orthogonal projectors are not allowed to be both assigned 1, and (ii) Completeness: for each d mutually orthogonal projectors, one of them must be assigned 1.

KS sets are not the only means to identify the differences between quantum mechanics and NCHVTs. An interesting class of statistical state-dependent proofs of contextuality was also presented by Clifton3, Stairs4, Hardy5 and others6,7. In these works, a prediction occurs with certainty in every non-contextual theory (such as the probability of an event being 0 or 1), while this is not the case in quantum theory. Such statistical proofs provide a simple and appealing contradiction between quantum and NCHVTs. Considering each projector in a Hilbert space as an atomic proposition, sets of the form \(P\to \overline{Q}\) (P being true implies Q is false) or P → Q (P being true implies Q is true) have been termed as gadgets7, definite-prediction sets8, bugs or true-implies-false and true-implies-true sets9.

As a central result in the foundations of quantum mechanics, KS contextuality has yielded several exciting applications in quantum information science recently. These applications include entanglement-assisted advantage in zero-error communication10, semi-device-independent randomness generation11, device-independent security12, universal quantum computation via magic state distillation13, advantage in communication complexity14, self-testing quantum systems15, etc.

In this paper, we introduce a general class of definite-prediction sets termed higher-order gadgets that goes beyond the basic ‘true-implies-false’ and ‘true-implies-true’ structures considered thus far and show how these gadget measurement structures provide an optimal toolbox for a plethora of applications of contextuality12,13,14,16,17. (i) We show how the entanglement-assisted advantage in zero-error communication, previously discovered for KS proofs alone, persists for the smaller and experimentally feasible classical channels corresponding to gadgets, under a suitable generalization. (ii) We apply gadgets to provide an experimentally feasible test of a recent result demonstrating that quantum correlations cannot be reproduced by fundamentally binary theories. These are a natural class of alternatives to the set of correlations allowed by quantum theory, and are defined as general probabilistic theories that posit that on a fundamental level only measurements with two outcomes exist. (iii) We point out that gadget-based contextuality tests allow to certify the maximal amount of \(\log d\) bits of randomness from d-dimensional systems, making them ideal candidates for contextuality-based semi-device-independent randomness generation. (iv) We also use gadgets to point out a subtle modification to the famous Cabello-Severini-Winter (CSW) graph-theoretic framework of contextuality, namely that the classical value of non-contextuality inequalities does not always equal the weighted independence number of the corresponding orthogonality graph, when the KS rules of Exclusivity and Completeness are enforced. Furthermore, we show the constructions of definite prediction vector sets corresponding to arbitrary compound propositions, i.e., the entire spectrum of Hardy tests of contextuality from basic ‘true-implies-false’ sets to KS sets. We identify how these vector sets can be found inside general KS proofs, and demonstrate how these can be applied as building blocks for constructing KS proofs as well as general state-independent contextual (SI-C) proofs. Consequently, since higher-order gadgets form an essential ingredient in the constructions of KS proofs, minimal constructions of gadgets may be expected to help resolve the long-standing open questions of minimal KS proofs in a given Hilbert space dimension.

Results

Our results presented in this work are in two parts. On the one hand, as the fundamental results, we introduced the order (m, k) gadgets which play a crucial role in contextuality proofs. On the other hand, from the practical point of view, we proved that gadgets serve as the optimal measurement structures for several contextuality applications.

Order (m, k) gadgets and forbidden value assignments

In this work, we first introduced a general class of state-dependent contextuality proofs termed order (m, k) gadgets, which go beyond the known 01-gadgets3,4,5,6,7,8,9. An order (m, k) gadget contains m mutually non-orthogonal vectors with the property that at most k vectors among them can be assigned value 1 in any valid {0, 1}-assignment. In Hilbert space of dimension d, under some special constructions, we showed that when m = d, k = d − 1 an order (m, k) gadget can be constructed by any set of arbitrary non-orthogonal vectors \(\{\left\vert {v}_{1}\right\rangle ,\ldots ,\left\vert {v}_{m}\right\rangle \}\). With this statement and construction, the Kochen-Specker (KS) sets as well as the general state-independent contextuality (SI-C) sets in dimension d can be constructed with the order (k, k − 1) gadgets as building blocks (for a fixed value k with 2 ≤ k ≤ d). Apart from this, we also showed that order (m, k) gadgets form the building blocks of every KS proof by identifying them as induced subgraphs within any arbitrary KS proof.

We discussed a class of even more general measurement structures in which some specific {0, 1}-assignments are forbidden, a result that may be of independent interest and application. From this point of view, a 01-gadget is a set of vectors where the assignment {(1, 1)} is forbidden on two given non-orthogonal vectors, an order (m, k) gadget is a set of vectors and for a given mutually non-orthogonal vectors subset I = {v1, …, vm} of it, the assignments of the form \(\{(\underbrace{1,\ldots ,1}_{\begin{array}{c}k+1\end{array}},f({v}_{k+2}),\ldots ,f({v}_{m}))\wedge \left({\mathtt{permutations}}\right)\}\) are forbidden (f is any {0, 1}-assignment function). And the KS sets are the ones that demonstrate the full forbidden value assignments {0, 1}I on any mutually non-orthogonal vectors subset I. A natural question then arises - can a gadget be constructed for every forbidden value assignment set? We answered this question in the affirmative and demonstrated the construction process in a concrete step-by-step manner.

Gadgets as optimal measurement structures to contextuality applications

Zero-error information theory is one of the most important applications of contextuality. Given a single use of a discrete, memoryless channel \({{{\mathcal{N}}}}\), the maximum number of (classical) messages that (a sender) Alice can send to (a receiver) Bob without causing any error is known as the one-shot zero-error capacity of \({{{\mathcal{N}}}}\). In groundbreaking work, Cubitt, Leung, Matthews and Winter10 showed how to use KS proofs (specifically the KS graphs) to construct channels (confusability graphs) for which shared entanglement between Alice and Bob can increase the one-shot zero-error capacity. In analogy with them, we took the confusability graphs to be the orthogonality graphs of a certain class of gadgets and we considered a weighted version of the problem in which we assign weights wi to the input symbols denoting the desirability of their transmission. It is in such a weighted version of the zero-error communication problem, we obtained an enhancement of the one-shot zero-error capacity via shared entanglement for channels corresponding to specific types of gadgets, which is a much wider class of graphs than was previously known.

While Quantum Theory is the most successful theory ever devised, there is still a huge research effort devoted to understanding physical and information-theoretic principles that force its formalism, one class of them is the Fundamentally Binary theories, these are no-signaling theories in which measurements yield many outcomes are constructed by selecting from binary measurements. Previously, the authors in16,18 showed a Bell-type inequality to exclude the set of fundamentally binary non-signaling correlations as an underlying mechanism generating the set of quantum correlations, however, the proof is experimentally demanding since only small violations of the derived inequalities are possible, the violation of the derived inequality requires visibilities of ≈ 91.7% of a suitably prepared two-qutrit state. We use the 01-gadget structures to derive the inequalities which are actually the maximum fractional assignments sum of the distinguished vectors, and from which the genuinely ternary character of quantum measurements can be certified in the much simpler single-system contextuality scenario with arbitrarily large separations between the set of quantum contextual correlations and the binary consistent correlations.

Contextuality can serve as the basis for randomness (or key) generation, and importantly one may utilize gadget-based contextuality tests to certify the optimal amount of randomness \({\log }_{2}d\) per run which is the maximum randomness that can be extracted from a system of dimension d. To do that, in general one needs to derive a rigid contextuality test in dimension d and identify a suitable measurement x* with fully random outcomes PAX(ax*) = 1/d a [d] when the maximum quantum value of the contextuality test is observed. We showed that the general constructions in7 and the tunability of the overlap between the distinguished vectors of the gadgets make them ideal candidates for protocols allowing to certify the maximum amount of \({\log }_{2}d\) bits of randomness. Specifically, we demonstrated the 01-gadgets in dimension d = 4 and 5 with the maximum overlaps between the distinguished vertices being \(\frac{1}{\sqrt{d}}\) (for any orthogonal representation in \({{\mathbb{R}}}^{d}\)), which indicate that one can readily derive contextuality tests allowing \({\log }_{2}d\) bits optimal randomness certification from these constructions.

Discussion

In this paper, we have introduced a generalization of gadget structures to definite prediction sets for arbitrary logical propositions and shown how gadgets are optimal measurement structures in many applications of contextuality. A number of interesting open questions remain. A fundamental question is to leverage the constructions of gadgets and their utility in building KS proofs to identify minimal KS proofs in a given dimension. It is still an open question to identify the minimal KS proof in dimension 3 while the 18-vector set introduced in19,20 is conjectured to be minimal in dimension 4. With regard to applications, it is of interest to construct minimal gadget sets of measurements giving a contextuality test to certify the optimal amount of \(\log d\) bits from a system of dimension d (constructions were shown for small dimensions here), and to use them in experimentally feasible contextuality-based randomness generation protocols. It is also of interest to experimentally test the separation between quantum mechanics and general binary consistent theories. In the future, it would be interesting to see if gadget generalizations can be used to show separations between quantum correlations and the set of n-ary consistent correlations that are defined analogously to the binary theories as composed from measurements yielding at most n outcomes.

Methods

Preliminaries

Much of the reasoning involving outcome contextuality has traditionally been carried out using graph-theoretic representations of KS sets, we therefore begin by establishing some graph-theoretic notation.

In this paper, we deal with simple, undirected, finite graphs G = (VG, EG) where VG and EG denote the vertex and edge set of the graph respectively. If two vertices vi, vj are connected by an edge, we say that they are adjacent and denote it by vi ~ vj. A clique C in the graph G is a subset of vertices CVG such that every pair of vertices in C is connected by an edge. A maximal clique is a clique that is not a subset of a larger clique, while a maximum clique in G is a clique of maximum size in G, we denote the size of the maximum clique by ω(G). An independent set in a graph G is a subset IVG such that every pair of vertices in I is non-adjacent in G, the maximum size of an independent set is denoted α(G). A set of vertices DVG is said to dominate a clique C if for every vC there exists a wD such that {v, w} E, that is every vertex of clique C has a neighbor in D. The set D is a minimal dominating set of C if no proper subset of D dominates C.

For any set of vectors \({{{\mathcal{V}}}}\), one can define an orthogonality graph \({G}_{{{{\mathcal{V}}}}}\) as the graph in which vector \(\left\vert v\right\rangle \in {{{\mathcal{V}}}}\) is represented by a vertex v in \({G}_{{{{\mathcal{V}}}}}\) and two vertices v1, v2 are connected by an edge in \({G}_{{{{\mathcal{V}}}}}\) if and only if 〈v1v2〉 = 021. Checking the orthogonality relations among the vectors from a given set \({{{\mathcal{V}}}}\) allows to efficiently establish its orthogonality graph \({G}_{{{{\mathcal{V}}}}}\). The problem of {0, 1}-coloring of a given set of vectors is then equivalently formulated as the problem of {0, 1}-coloring of its orthogonality graph defined in an analogous way as:

Definition 1

A {0, 1}-coloring of a graph G is a map f: VG → {0, 1} such that (i) for every clique C in G, it holds that ∑vCf(v) ≤ 1, and (ii) for every clique C in G of size ω(G), there exists exactly one vertex vC satisfying f(v) = 1.

The converse problem of identifying sets of vectors satisfying the orthogonality constraints dictated by the edges of a given graph is the question of finding an orthogonal representation of a graph.

Definition 2

An orthogonal representation of a graph G in dimension d is a set of (unit) vectors \({{{\mathcal{S}}}}\) from \({{\mathbb{C}}}^{d}\) such that there exists a map \(f:{V}_{G}\mapsto {{{\mathcal{S}}}}\) satisfying the condition that f(v1) and f(v2) are orthogonal vectors if {v1, v2} EG. The minimal dimension of an orthogonal representation of G is denoted d(G). A faithful orthogonal representation of a graph G in dimension d is a set of (unit) vectors \({{{\mathcal{S}}}}\) from \({{\mathbb{C}}}^{d}\) such that there exists a map \(f:{V}_{G}\mapsto {{{\mathcal{S}}}}\) satisfying the condition that f(v1) and f(v2) are orthogonal vectors if and only if {v1, v2} EG, and furthermore f(u) and f(v) are non-parallel vectors if u ≠ v. The minimal dimension of a faithful orthogonal representation of G is denoted d*(G).

We recall here the notion of 01-gadgets formalized in7.

Definition 3

7 A 01-gadget in dimension d is a {0,1}-colorable set \({{{{\mathcal{S}}}}}_{gad}\subset {{\mathbb{C}}}^{d}\) of vectors containing two distinguished non-orthogonal vectors \(\left\vert u\right\rangle\) and \(\left\vert v\right\rangle\) that nevertheless satisfy f(u) + f(v) ≤ 1 in every {0,1}-coloring f of \({{{{\mathcal{S}}}}}_{gad}\).

Equivalently, the 01-gadgets may be defined in graph-theoretic terms as:

Definition 4

7 A 01-gadget in dimension d is a {0,1}-colorable graph Ggad with faithful dimension d*(Ggad) = ω(Ggad) = d and with two distinguished non-adjacent vertices u and v such that f(u) + f(v)≤1 in every {0,1}-coloring f of Ggad.

In other words, 01-gadgets are particular definite-prediction sets with a logical implication of the form \(P\to \overline{Q}\), i.e., in any logical assignment of the set of atomic propositions, when one of the two distinguished propositions is assigned the value True the other is necessarily assigned value False, even though the distinguished atomic propositions are not represented by orthogonal vectors and are therefore not inherently exclusive to each other. In7, it was shown that 01-gadgets identify the essential contradiction captured by the Kochen-Specker theorem, in that every KS graph contains a 01-gadget and from every 01-gadget one can construct a proof of the Kochen-Specker theorem (see also22,23). Note that by the famous Erdős-Stone theorem24 of extremal graph theory, graphs of sufficiently high density necessarily contain subgraphs isomorphic to 01-gadgets, specifically the maximum number of edges in a graph (with faithful dimension d) with n vertices not containing a subgraph isomorphic to a 01-gadget (of dimension d) is \(\left[\frac{d-2}{d-1}+o(1)\right]{{n}\choose{2}}\). This can be seen by observing that 01-gadgets in dimension d have chromatic number χ(G) = d, where the chromatic number of a graph denotes the minimum number of colors needed to color the vertices such that adjacent vertices are assigned distinct colors.

From the preceding discussion, we recognize that the orthogonality graphs of Kochen-Specker vector sets do not admit a {0, 1}-coloring. The {0, 1}-colorability of a graph can also be formulated as an SAT instance and solved using a solver such as MiniSAT (http://minisat.se). To do this, one introduces a variable for each vertex in the graph. For each edge in the graph, a clause is added stating that the two incident vertices cannot both have value 1 (True). For each maximum clique in the graph, a clause is added stating that not all vertices in the clique have value 0 (False). The Boolean formulas for KS graphs are then seen to be unsatisfiable. Specifically, for the dimension d = 3 setting, one can formulate the {0, 1}-colorability of KS graphs as a 1-in-3 SAT instance. To do this, we complete the bases in the KS set by adding appropriate (unique) vectors, such that each edge in the graph belongs to a triangle. The Boolean formula in conjunctive normal form then has exactly three literals per clause, i.e., the formula is of the form \({\wedge }_{({i}_{1},{i}_{2},{i}_{3})\in {{\rm{Cliques}}}}({v}_{{i}_{1}}\vee {v}_{{i}_{2}}\vee {v}_{{i}_{3}})\) and the {0, 1}-colorability is equivalent to the 1-in-3 SAT question of determining whether there exists a truth assignment to the variables so that each clause has exactly one true literal. Furthermore, one can also obtain a similar unsatisfiable formula for 01-gadgets with an added clause stating that the two distinguished non-adjacent vertices both have value 1. Thus, from the point of view of satisfiability, 01-gadgets provide a similar (and in many cases, smaller) unsatisfiable instance. From the point of view of contextuality, 01-gadgets provide a state-dependent version of Kochen-Specker contextuality.

Order (m, k) gadgets

Let us now consider generalizations of gadget measurement structures that go beyond the basic ‘true-implies-false’ and ‘true-implies-true’ logical implications. Our first generalization is to gadgets of order (m, k) with k ≤ m. Essentially, these are prediction sets corresponding to the proposition \(\left[\left({\wedge }_{i = 1}^{k}{P}_{i}\to {\wedge }_{j = k+1}^{m}{\overline{P}}_{j}\right)\wedge \left({\mathtt{permutations}}\right)\right]\) for m mutually non-exclusive atomic propositions P1, …, Pm. In other words, the gadgets of order (m, k) contain m mutually non-orthogonal vectors such that at most k vectors can be assigned value 1 in any {0, 1}-coloring. The 01-gadgets3,7,25,26,27,28 then correspond to the special case of gadgets of order (2, 1).

Definition 5

A gadget of order (m, k) in dimension d is a {0,1}-assignable set of vectors \({{{{\mathcal{S}}}}}_{m,k}\subset {{\mathbb{C}}}^{d}\) containing m distinguished mutually non-orthogonal vectors \({\widetilde{{{{\mathcal{S}}}}}}_{m,k}=\{\left\vert {v}_{1}\right\rangle ,...,\left\vert {v}_{m}\right\rangle \}\subsetneq {{{{\mathcal{S}}}}}_{m,k}\), such that

  • for every subset \({{{\mathcal{R}}}}\subset {\widetilde{{{{\mathcal{S}}}}}}_{m,k}\) of size smaller than or equal to k, there exists a {0,1}-coloring which attributes 1 to all vectors in \({{{\mathcal{R}}}}\), and

  • for any subset \({{{\mathcal{R}}}}\subset {\widetilde{{{{\mathcal{S}}}}}}_{m,k}\) of size greater than k, no {0, 1}-coloring exists that attributes 1 to all vectors in \({{{\mathcal{R}}}}\).

One can also give an equivalent definition of the order (m, k) gadget in graph-theoretic terms:

Definition 6

A gadget of order (m, k) in dimension d is a {0, 1}-colorable graph G with faithful dimension d*(Ggad) = ω(Ggad) = d and with a distinguished independent set I of cardinality I = m such that

  • for every subset \({I}^{{\prime} }\subset I\) of cardinality \(| {I}^{{\prime} }| \le k\), there exists a {0, 1}-coloring of G in which all \(v\in {I}^{{\prime} }\) are assigned value 1, and

  • no {0, 1}-coloring of G exists that assigns value 1 to more than k vertices from I.

We first study the question of whether a higher order (m, k) gadget can be constructed with any set of arbitrary vectors \(\{\left\vert {v}_{1}\right\rangle ,\ldots ,\left\vert {v}_{m}\right\rangle \}\) as the distinguished vectors. While it is possible to consider every value of k [m − 1], here we focus on the construction for the special case m = d, k = d − 1. As in the construction of KS sets, the construction of such general gadgets is complicated by the fact that even deciding the {0, 1}-colorability of a general graph is an NP-complete problem29. It is also hard in general to derive the faithful orthogonal representation of a graph in a given dimension. As such, there isn’t a systematic method to derive minimal gadget structures. Nevertheless, we propose specific graphs G with candidate vertices to play the role of the distinguished vertices of the gadget. We then construct a symmetric matrix Gram with entries Grami,j = Gramj,i = 0 corresponding to edges (i, j) in G. The matrix Gram is meant to represent the Gram matrix of a set of vectors realizing the graph G so that Grami,j = 〈vivj〉. We study the question of finding a positive-semi-definite matrix completion Gram ≥ 0 with a rank-d constraint. We thus exhibit a graph that serves as an order (d, d − 1) gadget for arbitrary d, with the d distinguished vectors being \(\left\vert {m}_{1}\right\rangle ,\left\vert {m}_{2}\right\rangle ,\cdots \,,\left\vert {m}_{d}\right\rangle\) (details are in the Supplementary Information Note 1). The feature of this construction is that the distinguished vectors can be chosen to be arbitrarily close to each other, i.e., 〈mimj〉 → 1 as the number of repeating units increases.

We now show an application of the higher-order gadgets in constructing KS proofs as well as general state-independent contextual (SI-C) proofs and also defer the details of these contractions to Supplementary Information Note 2.

Construction 1

Order (k, k − 1) gadgets can be used as building blocks to construct KS proofs in dimension d.

In the construction, we start with k bases B1, B2, …, Bk in dimension d, then randomly pick one vector in each basis to form a set \({S}_{i}=\left\{\left\vert {v}_{{B}_{p}}^{q}\right\rangle \right\}\) with p [k]  {1, …, k} and q [d]. In total, we have dk such sets Si. Then for each i [dk], we construct an order (k, k − 1) gadget in dimension d with the vectors in Si being the d istinguished vectors. Thus, assigning a single value 1 to each of the bases B1, …, Bk−1 forces all the vectors in the basis Bk to be assigned value 0 giving a contradiction, so that the union of all vectors is a KS proof.

Construction 2

Order (k, k − 1) gadgets can be used as building blocks to construct general SI-C sets in dimension d.

To realize the general SI-C set, we first construct a set of r 2n distinct unit vectors \(\left\vert {u}_{i}\right\rangle\) in dimension d satisfying \(\mathop{\sum }\nolimits_{i = 1}^{r\cdot {2}^{n}}\left\vert {u}_{i}\right\rangle \left\langle {u}_{i}\right\vert =\frac{r\cdot {2}^{n}}{d}{{\mathbb{1}}}_{d}\), where \(r > \max \left\{\frac{d(k-1)}{{2}^{n}},4\right\}\) is an even integer and \(n=\left\{\begin{array}{ll}\lceil {\log }_{2}\frac{d-1}{2}\rceil ,\quad &d\ \,{{\mbox{is odd}}}\,\\ \lceil {\log }_{2}\frac{d-2}{2}\rceil ,\quad &d\ \,{{\mbox{is even}}}\,\end{array}\right.\). Then any k of these vectors form a set Si, we first delete all the mutually orthogonal vectors in the set Si and construct an order (Si, Si − 1) gadget in dimension d with the vectors in Si being the distinguished vectors. As a result, in any {0, 1}-assignment f, the sum of assignments of these r 2n vectors is smaller than k. On the other hand, in quantum theory we obtain the value \(\frac{r\cdot {2}^{n}}{d} > k\) for every state in dimension d, so that the union of all the vectors gives a proof of state-independent contextuality. Finally, not only can the higher-order gadgets be used as building blocks to construct KS proofs, we also show that specific such gadgets may be found as necessary substructures (induced subgraphs) in any proof of the KS theorem.

Theorem 1

Every KS set in dimension d contains a gadget of order (k, k − 1) for some k satisfying 2 ≤ k ≤ d.

The intuition behind the proof is that if no {0, 1}-coloring exists for a graph G, a brute-force greedy algorithm that attempts to assign 0s and 1s to its vertices must stop at some point in its execution, before each maximum clique has a single 1-valued vertex. Therefore, there must exist some clique C in G such that each vertex in C is adjacent to some 1-valued vertex at this point in the execution. Call such a minimal set of adjacent vertices to a maximum clique as D, then the induced subgraph formed by DC constitutes a gadget. Furthermore, such a gadget must be of order at least (k, k − 1).

Order (m, k) gadgets are thus a natural generalization of ‘True-implies-False’ sets, where we consider an independent set I = {v1, …, vm} of vertices (mutually non-orthogonal vectors) with forbidden value assignments of the form \(\{\underbrace{1,\ldots ,1}_{k+1},f({v}_{k+2}),\ldots ,f({v}_{m})\}\) and permutations thereof, for any {0, 1}-coloring f. One may consider yet more general structures in which we specify a general set of forbidden value assignments \({{{\mathcal{H}}}}\subset {\{0,1\}}^{m}\), we elaborate on this in Supplementary Information Note 3.

Entanglement-assisted advantage in Zero-error communication in channels constructed from gadgets

One of the most important and tantalizing applications of contextuality is in the field of zero-error information theory. In classical zero-error coding, we consider a discrete, memoryless channel \({{{\mathcal{N}}}}\) connecting a sender Alice and a receiver Bob. Given a single use of such a channel, the maximum number of classical messages that Alice can send to Bob under the constraint that there be no error is known as the one-shot zero-error capacity of \({{{\mathcal{N}}}}\). In groundbreaking work, Cubitt et al.10 showed how to use KS proofs to construct channels for which shared entanglement between Alice and Bob can increase the one-shot zero-error capacity. Since 01-gadgets are substructures of KS proofs, it is an interesting question to investigate whether these smaller (and experimentally more feasible) measurement structures already exhibit the phenomenon of entanglement-assisted advantage in zero-error capacity.

The classical channel \({{{\mathcal{N}}}}\) has finite inputs X and outputs Y and its behavior is characterized by the probability distribution \({{{{\mathcal{N}}}}}_{Y| X}(y| x)\) of outputs given inputs. Two inputs x are confusable if the corresponding distributions on outputs overlap. The confusability graph \(G({{{\mathcal{N}}}})\) is constructed with vertex set being the set of input symbols and two vertices connected by an edge if the corresponding input symbols are confusable. A zero-error code is then a set of non-confusable inputs and the one-shot zero-error capacity of the channel is the maximum size of such a set. When Alice and Bob only share correlations which can be obtained using shared randomness, this number can be readily seen to be the independence number of the graph \(G({{{\mathcal{N}}}})\), i.e., \({c}_{SR}({{{\mathcal{N}}}})=\alpha \left(G({{{\mathcal{N}}}})\right)\) where \({c}_{SR}({{{\mathcal{N}}}})\) denotes the zero-error capacity when using correlations obtained using shared randomness as a resource. On the other hand, Cubitt et al. showed examples of channels for which sharing entanglement can improve the zero-error capacity of sending classical messages, i.e., such that \({c}_{SE}({{{\mathcal{N}}}}) > {c}_{SR}({{{\mathcal{N}}}})\) where \({c}_{SE}({{{\mathcal{N}}}})\) denotes the zero-error capacity when using shared entanglement as a resource. In particular, they showed that such channels arise naturally from proofs of the Kochen-Specker theorem, specifically one may take \(G({{{\mathcal{N}}}})\) to be the (non-{0, 1}-colorable) orthogonality graph of some Kochen-Specker vector set.

We show that one may also take \(G({{{\mathcal{N}}}})\) to be the orthogonality graph of a certain class of gadgets, by a suitable generalization to a weighted version of the zero-error communication problem. In the weighted generalization, we assign weights \(w={\{{w}_{i}\}}_{i = 1}^{| V| }\) to the input symbols (denoting the desirability of their transmission). The one-shot zero-error capacity is then the maximum total weight of any set of non-confusable inputs, which corresponds to the weighted independence number of the confusability graph, i.e., \({c}_{SR}({{{\mathcal{N}}}},w)=\alpha \left(G({{{\mathcal{N}}}}),w\right)\).

Consider a gadget in which we complete each of the bases (by addition of suitable vectors satisfying the orthogonality relations) such that a clique cover of the graph is possible in which the vertices of the graph are partitioned into q maximum cliques (of size ω(G) = d) given as Cm = {vm,1, …, vm,d} for m = 1, …, q (i.e., \(V={\cup }_{m = 1}^{q}{C}_{m}\)). We remark that a similar completion is required for the graphs obtained from Kochen-Specker proofs in10, and only such Kochen-Specker proofs (such as the Peres-Mermin proof30 with 24 vectors partitioned into six cliques in dimension 4) display the enhancement proven there.

We construct the channel \({{{\mathcal{N}}}}\) as having inputs in [q] × [d] with inputs (m, i) and \(({m}^{{\prime} },{i}^{{\prime} })\) being confusable if and only if the corresponding vectors are orthogonal to each other, i.e., if and only if \(\langle {v}_{m,i}| {v}_{{m}^{{\prime} },{i}^{{\prime} }}\rangle =0\). \(G({{{\mathcal{N}}}})\) has an edge between such pairs of confusable inputs and is exactly the orthogonality graph corresponding to the (base-completed) gadget. By construction, the vertices of \(G({{{\mathcal{N}}}})\) can be partitioned into q maximum cliques (of size d). We now consider the weighted version of the zero-error communication problem with Vdist denoting the set of distinguished vertices in the gadget as

$${w}_{i}=\left\{\begin{array}{ll}{w}^{* }\,&i\in {V}_{{{\rm{dist}}}}\\ 1\,&i\in V\setminus {V}_{{{\rm{dist}}}}\\ \end{array}\right.$$
(1)

for a parameter w*. The one-shot zero-error capacity when only shared randomness is available is then readily calculated to be \({c}_{SR}\left(G({{{\mathcal{N}}}})\right)=\max \left\{\alpha \left(G({{{\mathcal{N}}}})\right)-1+{w}^{* },\alpha \left(G({{{\mathcal{N}}}})\right)-3+2{w}^{* }\right\}\). We choose w* > 1 such that 2w* − 3 < w* − 1, i.e., 1 < w* < 2 giving \({c}_{SR}\left(G({{{\mathcal{N}}}})\right)=\alpha \left(G({{{\mathcal{N}}}})\right)-1+{w}^{* } < q+{w}^{* }-1\).

On the other hand, suppose Alice and Bob share a maximally entangled state \(\left\vert {\psi }_{d}\right\rangle =\frac{1}{\sqrt{d}}\mathop{\sum }\nolimits_{i = 1}^{d}\left\vert i,i\right\rangle\). Each message m that Alice wishes to send corresponds to a maximum clique in the aforementioned clique partitioning of the graph \(G({{{\mathcal{N}}}})\). To send m, Alice measures in the bases given by the clique Cm and obtains an outcome k [d] with probability 1/d. Her input to the channel is then (m, k). The output of the channel at Bob’s end is one of the maximum cliques containing the vertex vm,k (not necessarily belonging to the clique partitioning of the graph). Bob performs a projective measurement corresponding to his received maximum clique, and his outcome reveals Alice’s input to the channel. The one-shot zero-error capacity when shared entanglement is used as a resource is then calculated to be \({c}_{SE}\left(G({{{\mathcal{N}}}})\right)=\frac{1}{d}\left[qd-| {V}_{{{\rm{dist}}}}| +| {V}_{{{\rm{dist}}}}| \cdot {w}^{* }\right]=q+\frac{({w}^{* }-1)| {V}_{{{\rm{dist}}}}| }{d}\). We see that \({c}_{SE}\left(G({{{\mathcal{N}}}})\right)\, >\, {c}_{SR}\left(G({{{\mathcal{N}}}})\right)\) whenever Vdist > d, i.e., whenever we have a gadget-type graph with Vdist distinguished vertices of which only one can be assigned value 1 in any non-contextual {0, 1} value assignment.

We note that such a gadget-type graph does not correspond to a Kochen-Specker proof since it is {0, 1}-colorable. On the other hand, one can construct a state-independent non-contextuality inequality for the graph that is violated by all states in dimension d, namely \({\sum }_{{v}_{i}\in {V}_{{{\rm{dist}}}}}P({e}_{{v}_{i}})\le 1\), where P(ei) refers to the probability of the event \({e}_{{v}_{i}}\) corresponding to the distinguished vertex vi. Such graphs may therefore be said to be of the type discovered by Yu and Oh in31, namely they exhibit state-independent contextuality despite not corresponding to a Kochen-Specker proof. And as we have seen, we obtain an enhancement via entanglement of the one-shot zero-error capacity for all such graphs, a much wider (and easily constructible following the constructions in7 and Construction 2 in this work) class of graphs than was previously known.

Large violations of binary consistent correlations in quantum theory

In this section, we describe an application of the gadget constructions to the task of excluding a natural alternative to quantum theory, namely the so-called “Fundamentally Binary theories”16,18. While Quantum Theory is the most successful theory ever devised, there is still a huge research effort devoted to understanding physical and information-theoretic principles that force its formalism. Seemingly natural alternatives to the set of correlations allowed by Quantum Theory exist such as the so-called ‘Almost Quantum’ correlation set32. Another class of natural alternatives is given by the Fundamentally Binary theories, these are no-signaling theories in which measurements yielding many outcomes are constructed by selecting from binary measurements. In other words, these theories posit that on a fundamental level only measurements with two outcomes exist, and scenarios where a measurement has more than two outcomes are achieved by classical post-processing of one or more two-outcome measurements. Fundamentally binary correlations are characterized as the convex hull of all consistent correlations {P(ax)} obeying the constraint that for all x, it holds that P(ax) = 0 for all but two outcomes a.

In16,18, it was shown that two-party non-locality scenarios exist such that the corresponding class of fundamentally binary non-signaling correlations does not fully encompass the set of quantum correlations. In other words, it was shown that a Bell-type inequality can be constructed to exclude the set of fundamentally binary non-signaling correlations as an underlying mechanism generating the set of quantum correlations. The authors of16,18 considered the simplest non-trivial polytope of fundamentally binary non-signaling correlations involving two parties that perform two measurements with three outcomes each. They computed the facets of the polytope using Fourier-Motzkin elimination using the software porta and calculated the corresponding quantum violations using the NPA semidefinite programming hierarchy33. While an important foundational result, the proof in18 is experimentally demanding in that only small violations of the derived inequalities are possible (the quantum value being Ia = 2(2/3)3/2 ≈ 1.0887 compared to the value in binary theories of Ia = 1), the violation of the derived inequality requires visibilities of ≈ 91.7% of a suitably prepared two-qutrit state. In this section, we show that the genuinely ternary character of quantum measurements can be certified in the much simpler single-system contextuality scenario with arbitrarily large separations between the set of quantum contextual correlations and the binary consistent correlations. The price to pay for such large violations is the assumption, common to all contextuality experiments, that the same projector is measured in different contexts.

Consider an orthogonality graph G = (VG, EG) with a set of maximum cliques (contexts) \({{{\mathcal{C}_G}}}=\{{A}_{1},\ldots ,{A}_{k}\}\) where each clique Ai is of size ω(G) = d. A box B = {P(ax)} is a set of conditional probability distributions with input x {1, …, k} and output a {1, …, d}. A box is said to be compatible with an orthogonality graph G if it is a family of (normalized) probability distributions such that for each c {A1, …, Ak}, there is a corresponding probability distribution in this family.

Definition 7

For a given orthogonality graph G = (VG, EG) with a set of contexts \({{{{\mathcal{C}}}}}_{G}=\{{A}_{1},\ldots ,{A}_{k}\}\), a box \(B=\{P\left(a| x\right.\}\) is said to be a Consistent Box if for all pairs \(c,{c}^{{\prime} }\in {{{{\mathcal{C}}}}}_{G}\) and for sets of vertices (projectors) \({S}_{c,{c}^{{\prime} }}=c\cap {c}^{{\prime} }\ne {{\emptyset}}\), it holds that

$$\forall s\in {S}_{c,{c}^{{\prime} }}\ \ \ \ P(a=s| x=c)=P(a=s| x={c}^{{\prime} }).$$
(2)

The set of all consistent boxes B compatible with an orthogonality graph G is denoted by \({{\mathtt{B}}}_{G}^{c}\).

Note that the set of non-signaling boxes is a special case of such consistent boxes.

Fundamentally binary correlations are a sub-class of consistent correlations obtained as the convex hull of consistent boxes for which for each context c in the graph G (maximum clique of size ω(G) = d) at most two projectors (vertices in the clique) are assigned non-zero values that sum to unity and the remaining projectors in the context are assigned value 0, together with any box obtained by local classical postprocessing of such boxes. Note that in each extremal binary consistent box, the assignment of values to the projectors is done in a consistent manner, so that the value assigned to any projector is independent of the context in which it is measured. Formally we define binary consistent correlations as follows.

Definition 8

For a given orthogonality graph G = (VG, EG) with a set of contexts \({{{{\mathcal{C}}}}}_{G}=\{{A}_{1},\ldots ,{A}_{k}\}\), a binary consistent assignment is a function f: VG → [0, 1] such that \(\forall c\in {{{{\mathcal{C}}}}}_{G}\), existsv1, v2c such that f(v1) + f(v2) = 1 and f(vi) = 0 for all \(v_{i} \in c \setminus\{v_{1}, v_{2}\}\). Define the set of boxes \({{\mathtt{B}}}_{G}^{\,{{\rm{bin-cons}}}\,}\) as the convex hull of boxes obtained by binary consistent assignments, i.e.,

$$\begin{array}{rcl}{{\mathtt{B}}}_{G}^{\,{{\mbox{bin-cons}}}\,}:= &&\,{{\mbox{conv}}}\,\left\{\{P(a| x)\}\in {{\mathtt{B}}}_{G}^{c}\ | \ \forall c\in {{{{\mathcal{C}}}}}_{G},\ \exists {s}_{1},{s}_{2}\in c\right.\ \\ &&\left.\,{{\mbox{s.t.}}}\,\ P(a={s}_{1}| x=c)+P(a={s}_{2}| x=c)=1\right\}.\end{array}$$
(3)

The set of Fundamentally Binary boxes \({{\mathtt{B}}}_{G}^{\,{{\rm{bin}}}\,}\) is defined as the set of boxes that can be obtained by local classical postprocessing from any \(B\in {{\mathtt{B}}}_{G}^{\,{{\rm{bin-cons}}}\,}\).

We now show that not only does the set of Fundamentally Binary boxes not encompass the set of quantum contextual correlations, but that in fact there exist separating inequalities for which large violations by quantum contextual correlations can be obtained.

Theorem 2

There exist inequalities bounding the set of fundamentally binary consistent correlations that admit close to algebraic violations in quantum theory.

Proof

The proof will make use of the idea of ‘extended 01-gadgets’ that we introduced in7.

Definition 9

An extended 01-gadget in dimension d is a {0, 1}-colorable graph Gxgad = (Vxgad, Exgad) with faithful dimension d*(Gxgad) = ω(Gxgad) = d and with two distinguished non-adjacent vertices v1v2 such that in any assignment f: Vxgad → [0, 1], it holds that f(v1) + f(v2) < 2.

In other words, an extended 01-gadget is similar to a normal 01-gadget except that the defining characteristic holds for arbitrary assignments in [0, 1] rather than only to {0, 1} assignments.

In7, we had proven the following statement that shows a construction of an extended 01-gadget between any two non-orthogonal vectors in \({{\mathbb{C}}}^{d}\).

Lemma 1

(Theorem 4 in7). Let \(\left\vert {v}_{1}\right\rangle\) and \(\left\vert {v}_{2}\right\rangle\) be any two distinct non-orthogonal vectors in \({{\mathbb{C}}}^{d}\) with d ≥ 3. Then there exists an orthogonality graph Gxgad that constitutes an extended 01-gadget in dimension d with the corresponding vertices v1 and v2 being the distinguished vertices.

We now show that for any extended 01-gadget, the sum of the binary consistent (probability) assignments to the two distinguished vertices in any box \(B\in {{\mathtt{B}}}_{G}^{\,{{\rm{bin-cons}}}\,}\) is at most 3/2. To do so, we recall the notion of the Fractional Stable-Set Polytope (FSTAB(G)) of a graph G = (VG, Eg) which is defined as

$$FSTAB(G)=\left\{\overrightarrow{x}\in {{\mathbb{R}}}_{+}^{| {V}_{G}| }\ | \ {x}_{v}+{x}_{w}\le 1\ \ \forall (v,w)\in {E}_{G}\right\}.$$
(4)

We recognize that the fractional stable-set polytope is defined by similar constraints to the set of binary boxes \({{\mathtt{B}}}_{G}^{\,{{\rm{bin-cons}}}\,}\) except for the fact that the defining constraint xv + xw≤1 in FSTAB(G) is replaced by the constraint that \(\forall c\in {{{{\mathcal{C}}}}}_{G}\), v, wc such that xv + xw = 1 in \({{\mathtt{B}}}_{G}^{\,{{\rm{bin-cons}}}\,}\). By introducing a slack variable yv,w for each edge constraint, we rewrite the fractional stable-set polytope as

$$FSTAB(G)=\left\{(\overrightarrow{x},\overrightarrow{y})\in {{\mathbb{R}}}_{+}^{| {V}_{G}| }\times {{\mathbb{R}}}_{+}^{| {E}_{G}| }\ | \ {x}_{v}+{x}_{w}+{y}_{v,w}=1\ \ \forall (v,w)\in {E}_{G}\right\}.$$
(5)

Here, every vertex of G indexes an x variable while every edge of G indexes a slack y variable, so that x and y can be termed vertex variables and edge variables respectively. A vertex v is said to be k-valued in the fractional assignment \((\overrightarrow{x},\overrightarrow{y})\) if the corresponding vertex variable takes value k, and similarly an edge (v, w) is said to be j-valued in the assignment if the corresponding edge variable takes value j. The following theorem by Nemhauser and Trotter34, following an earlier result by Balinski35 provides a characterization of the vertices of FSTAB(G).

Theorem 3

(Balinski35, Nemhauser and Trotter34). Let \(\overrightarrow{x}\in {{\mathbb{R}}}_{+}^{| {V}_{G}| }\) be a vertex of FSTAB(G). Then for every vertex vVG, it holds that \({x}_{v}\in \{0,\frac{1}{2},1\}\), i.e., that every vertex is 0 or 1/2 or 1-valued in \(\overrightarrow{x}\).

Now, since the set of normalization conditions \(NOR{M}_{G}:= {\{{{{\mbox{NORM}}}}_{G}^{c}\}}_{c}\) for the maximum cliques \(c\in {{{{\mathcal{C}}}}}_{G}\) where

$${\,{{\mbox{NORM}}}\,}_{G}^{c}:= \{\exists v,w\in c\ \,{{\mbox{s.t.}}}\,\ f(v)+f(w)=1\}$$
(6)

form supporting hyperplanes of FSTAB(G), we see that the vertices of FSTAB(G) ∩ NORMG inherit the characterization derived in the above theorem, i.e., the corresponding edge (slack) variables y take value 0 for each edge in the graph. We thus obtain

Corollary 1

Let {P(ax)} be a vertex of \({{\mathtt{B}}}_{G}^{\,{{\rm{bin-cons}}}\,}\). Then for every context \(c\in {{{{\mathcal{C}}}}}_{G}\) and for every outcome s [d], it holds that \(P(a=s| x=c)\in \{0,\frac{1}{2},1\}\).

It is also worth remarking that classical processing does not change the above property so that it holds also for the extreme points of the polytope of Fundamentally Binary boxes \({{\mathtt{B}}}_{G}^{\,{{\rm{bin}}}\,}\). Applying the above corollary to any orthogonality graph Gxgad that constitutes an extended 01-gadget, we see that the sum of the binary consistent assignments to the two distinguished vertices is at most 3/2.

This statement, in conjunction with the constructions of extended 01-gadgets in the lemma for distinguished vectors \(\left\vert {v}_{1}\right\rangle ,\left\vert {v}_{2}\right\rangle\) satisfying v1v2 → 1 shows that the inequality \(P(a={v}_{1}| x={c}_{{v}_{1}})+P(a={v}_{2}| x={c}_{{v}_{2}})\le 3/2\) forms a supporting inequality for \({{\mathtt{B}}}_{{G}_{xgad}}^{\,{{\rm{bin}}}\,}\), where \({c}_{{v}_{1}}\) and \({c}_{{v}_{2}}\) are two contexts containing the vertices v1 and v2 respectively. On the other hand, measurements of the contexts on the state \(\left\vert v\right\rangle =\frac{1}{\sqrt{2(1+\cos \theta )}}(\left\vert {v}_{1}\right\rangle +\left\vert {v}_{2}\right\rangle )\) with \(\langle {v}_{i}| {v}_{j}\rangle =\cos \theta\) show that Quantum Theory achieves the value \(\left(1+\cos \theta \right)\to 2\) as θ → 0.

It is worth remarking that separations between the sets of binary consistent correlations and quantum correlations are not achieved by considering the inequalities for the usual Kochen-Specker proofs since both sets achieve the algebraic value for those inequalities. This shows the importance of the constructions of gadgets and extended gadgets in deriving such separating hyperplanes. Furthermore, it is also clear that higher-order extended gadgets can be constructed in analogy with the constructions of higher-order gadgets in the rest of this paper. In the future, it would be interesting to see if these constructions can be used to show large separations between the set of quantum contextual correlations and the set of n-ary consistent correlations that are defined analogously to the binary consistent correlations as composed from measurements yielding at most n outcomes.

Optimal semi-device-independent randomness generation using gadgets

Contextuality can serve as the basis for randomness (or key) generation, either via stand-alone protocols that test for the violation of a non-contextuality inequality11 (where one assumes that the measurements conform to the specific orthogonality graph), or through the conversion of a single-party contextuality test into a two-party Bell inequality12 or through the conversion of a non-contextuality inequality to a prepare-and-measure protocol14. A common step in all such protocols36,37,38,39,40,41 is the identification of a suitable measurement in the (contextuality) test that yields the highest possible randomness or key generation rate. It is well-known that the maximum randomness (quantified by the min-entropy) per run that can be extracted from a test where the parties perform projective measurements on a system of dimension d is \({\log }_{2}d\). The importance and utility of gadgets for randomness certification have been commented on previously, we elaborate on this aspect and focus on their importance for optimal randomness certification in this section.

The Kochen-Specker theorem shows that it is impossible to assign classical (deterministic) values to all quantum observables in a consistent manner, i.e., independent of the context in which the observables are measured. However, as pointed out in42,43, the fact that not all quantum observables can be assigned definite values does not imply that no observable can be assigned a definite outcome. And in general, proofs of contextuality do not specify which observables are value-indefinite. Specifically, for a contextuality test with a set of observables {A1, …, Ak} we want to solve

$$\begin{array}{ll}\max \ \,{P}_{guess}({A}_{i}| E)\\ s.t.\ \,\,I({P}_{A| X})={I}^{* },\\ \qquad \,{P}_{A,E| X}\in {{{\mathcal{Q}}}},\end{array}$$
(7)

where I(PAX) is a non-contextuality inequality evaluated on the observed conditional probability distributions PAX, I* (Ic, Iq] with classical and quantum values given by Ic and Iq respectively, and \({{{\mathcal{Q}}}}\) denotes the set of conditional distributions (boxes) achievable by performing measurements (compatible with the test structure on Alice’s side) on quantum states shared between Alice and adversary Eve, Pguess(AiE) = ∑eP(e)Pe(a = ei) is the guessing probability of Alice’s outcome by an adversary E. By an optimal rigid contextuality test in dimension d we mean one in which there exists a measurement basis x* such that PAX(ax*) = 1/d for all outcomes a [d] when the maximum value Iq is observed. It is an open question to derive such a rigid class of contextuality tests for arbitrary dimension d (see for example14 where the guessing probability was calculated for the well-known 5-cycle non-contextuality inequality44).

Constructions of gadgets provide a candidate solution to the problem. Specifically, the extended 01-gadgets from Definition 9 were used in7 as building blocks to construct sets of vectors \({{{{\mathcal{S}}}}}^{{\prime} }\) such that for any [0, 1]-assignment \(f:{{{{\mathcal{S}}}}}^{{\prime} }\to [0,1]\) it holds that \(f(\left\vert {v}_{1}\right\rangle ),f(\left\vert {v}_{2}\right\rangle )\in \{0,1\}\) if and only if \(f(\left\vert {v}_{1}\right\rangle )=f(\left\vert {v}_{2}\right\rangle )=0\). A first interesting aspect of these gadgets for randomness certification is that they allow to localize the randomness guaranteed by the KS theorem (note that a similar theorem with a more complicated construction was explored in45). In other words, the observation in the contextuality test of \(P(\left\vert {v}_{1}\right\rangle )=1\) guarantees that \(0 < P(\left\vert {v}_{2}\right\rangle ) < 1\) for any consistent box P compatible with the measurement structure of the gadget. Secondly, if one has a rigid construction15 with overlap \(| \langle {v}_{1}| {v}_{2}\rangle | =1/\sqrt{d}\), one can readily derive a contextuality test allowing optimal randomness certification (for example with a non-contextuality inequality of the form \(\beta P(\left\vert {v}_{1}\right\rangle )+P(\left\vert {v}_{2}\right\rangle )\le \beta\) with β 1, for which the optimal quantum value is then β + 1/d). Here, by a rigid construction we mean one for which there exists a non-contextuality inequality whose maximum violation certifies a fully random outcome (with uniform probabilities 1/d) for one of the measurement bases in the construction. One way to ensure this is if for the construction, the set of vectors realizing its orthogonality graph G is unique in \({{\mathbb{C}}}^{\omega (G)}\) (up to unitaries). For the gadget-within-gadget construction in the proof of Theorem 4 in7, it was shown that for the k-th iteration in the construction the maximum overlap of the distinguished vectors takes the form \(\frac{k}{k+2}\), so that the construction allows optimal randomness certification for d = 4 at k = 2. As shown in Fig. 1, the maximum overlap between the distinguished vectors \(\vert {u}_{1}^{(2)}\rangle ,\vert {u}_{8}^{(2)}\rangle\) is \(\frac{1}{2}\), and the orthogonal representation of this gadget is \(\langle {v}_{1}^{(1)}\vert =\langle {v}_{4}^{(2)}\vert =(1,0,0)\), \(\langle {v}_{2}^{(1)}\vert =(0,-\frac{\sqrt{3}}{2},\frac{1}{2})\), \(\langle {v}_{3}^{(1)}\vert =(0,\frac{\sqrt{3}}{2},\frac{1}{2})\), \(\langle {v}_{4}^{(1)}\vert =(-1,-\frac{\sqrt{2}}{2},-\frac{\sqrt{6}}{2})\), \(\langle {v}_{5}^{(1)}\vert =(-1,-\frac{\sqrt{2}}{2},\frac{\sqrt{6}}{2})\), \(\langle {v}_{6}^{(1)}\vert =(\frac{\sqrt{2}}{3},-\frac{1}{6},-\frac{\sqrt{3}}{6})\), \(\langle {v}_{7}^{(1)}\vert =(\frac{\sqrt{2}}{3},-\frac{1}{6},\frac{\sqrt{3}}{6})\), \(\langle {v}_{8}^{(1)}\vert =\langle {v}_{5}^{(2)}\vert =\frac{2\sqrt{2}}{3}(\frac{\sqrt{2}}{4},1,0)\), \(\langle {v}_{1}^{(2)}\vert =(-\frac{3}{2},-\frac{3\sqrt{2}}{4},\frac{3\sqrt{2}}{4})\), \(\langle {v}_{2}^{(2)}\vert =(0,1,1)\), \(\langle {v}_{3}^{(2)}\vert =(-\frac{3\sqrt{2}}{4},\frac{3}{8},-\frac{8}{9})\), \(\langle {v}_{6}^{(2)}\vert =(0,-1,1)\), \(\langle {v}_{7}^{(2)}\vert =(1,-\frac{\sqrt{2}}{4},-\frac{3\sqrt{2}}{4})\,\)\(\langle {v}_{8}^{(2)}\vert =(\sqrt{2},1,1)\).

Fig. 1: An example illustrating the construction of a gadget with prescribed maximum overlap between the distinguished vectors \(\vert {v}_{1}^{(2)}\rangle ,\vert {v}_{8}^{(2)}\rangle\) of \(\frac{1}{2}\) for any real orthogonal representation.
figure 1

The example illustrates the utility of gadgets in deriving contextuality tests that allow for optimal randomness certification for d = 4.

We give a different construction that allows to certify \({\log }_{2}d\) bits of randomness in dimension d = 5 here, and pursue the general question of rigid contextuality tests15,46 certifying \({\log }_{2}d\) bits for arbitrary d (as well as their monogamy relations47,48 and the security proofs of the corresponding protocols) for future work.

Consider the orthogonality graph shown in Fig. 2. Without loss of generality, we consider \(\left\langle {u}_{1}\right\vert =(1,0,0)\), \(\left\langle {u}_{13}\right\vert =\frac{1}{\sqrt{1+{x}^{2}}}(x,1,0)\). Parametrizing \(\left\langle {u}_{2}\right\vert =(0,\cos {\theta }_{1},\sin {\theta }_{1})\), \(\left\langle {u}_{3}\right\vert =(0,\cos {\theta }_{2},\sin {\theta }_{2})\) and \(\left\langle {u}_{4}\right\vert =(0,\cos {\theta }_{4},\sin {\theta }_{4})\) to ensure orthogonality with \(\left\langle {u}_{1}\right\vert\), we deduce the following (unnormalized) vectors by taking appropriate cross products \(\left\langle {u}_{11}\right\vert =(-\sin {\theta }_{1},x\sin {\theta }_{1},-x\cos {\theta }_{1})\), \(\left\langle {u}_{5}\right\vert =(-x,-{\sin }^{2}{\theta }_{1},(1/2)\sin 2{\theta }_{1})\), \(\left\langle {u}_{6}\right\vert =(-\cos ({\theta }_{1}-{\theta }_{2})\sin {\theta }_{1},x\sin {\theta }_{2},-x\cos {\theta }_{2})\), \(\left\langle {u}_{7}\right\vert =(-x,-\cos ({\theta }_{1}-{\theta }_{2})\sin {\theta }_{1}\sin {\theta }_{2},\cos ({\theta }_{1}-{\theta }_{2})\sin {\theta }_{1}\cos {\theta }_{2})\), \(\left\langle {u}_{13}\right\vert =(-\sin {\theta }_{3},x\sin {\theta }_{3},-x\cos {\theta }_{3})\), \(\left\langle {u}_{10}\right\vert =(-x,-{\sin }^{2}{\theta }_{3},(1/2)\sin 2{\theta }_{3})\), \(\left\langle {u}_{9}\right\vert =(\cos ({\theta }_{2}-{\theta }_{3})\sin {\theta }_{3},-x\sin {\theta }_{2},x\cos {\theta }_{2})\) and \(\left\langle {u}_{8}\right\vert =(x,\cos ({\theta }_{2}-{\theta }_{3})\sin {\theta }_{2}\sin {\theta }_{3},-\cos ({\theta }_{2}-{\theta }_{3})\cos {\theta }_{2}\sin {\theta }_{3})\). We now ask what is the maximum value of the overlap \(| \langle {u}_{1}| {u}_{13}\rangle | =\frac{x}{\sqrt{1+{x}^{2}}}\) under the constraint that \(-\langle {u}_{7}| {u}_{8}\rangle ={x}^{2}+\cos ({\theta }_{1}-{\theta }_{2})\cos ({\theta }_{3}-{\theta }_{2})\sin {\theta }_{1}\sin {\theta }_{3}\) equals 0. Or equivalently we wish to minimize \(\cos ({\theta }_{1}-{\theta }_{2})\cos ({\theta }_{2}-{\theta }_{3})\sin {\theta }_{1}\sin {\theta }_{3}\). Setting the partial derivatives of this expression with respect to θ1, θ2, θ3 to equal zero, and finding the maximum overlap over all the solutions gives that θ1 = − θ3 = π/4 and θ2 = 0 with the optimal overlap \(| \langle {u}_{1}| {u}_{13}\rangle | =1/\sqrt{5}\). The addition of two other vertices u14, u15 that are adjacent to all the vertices of the graph as well as to each other, gives the natural orthogonal representation in dimension 5 with \(\left\langle {u}_{14}\right\vert =(0,0,0,1,0)\) and \(\left\langle {u}_{15}\right\vert =(0,0,0,0,1)\). We have thus constructed an extended 01-gadget in dimension 5 with the maximum overlap between the distinguished vertices being \(\frac{1}{\sqrt{5}}\) (for any orthogonal representation in \({{\mathbb{R}}}^{5}\)). While not a full self-testing statement, this indicates that the maximum violation of a non-contextuality inequality could allow to certify \({\log }_{2}5\) bits for this construction. As stated earlier, we leave for future work the derivation of rigid contextuality tests based on gadgets to certify \({\log }_{2}d\) bits for arbitrary dimension d and the security proofs of the corresponding (semi-device-independent) contextuality-based randomness generation.

Fig. 2: An example illustrating the construction of a gadget with prescribed maximum overlap between the distinguished vectors \(\left\vert {u}_{1}\right\rangle ,\left\vert {u}_{13}\right\rangle\) of \(\frac{1}{\sqrt{5}}\) for any real orthogonal representation.
figure 2

The example illustrates the utility of gadgets in deriving contextuality tests that allow for optimal randomness certification for d = 5.

Classical value of non-contextuality inequalities versus the weighted independence number

An interesting offshoot of the study of gadget structures is to point out a subtle modification in a famous result by Cabello, Severini and Winter (CSW) in17,49 when the Kochen-Specker rules of exclusivity and completeness are enforced. In formulating the graph-theoretic approach to quantum correlations, CSW had considered general non-contextuality inequalities S as a positive linear combination of probabilities of events S = ∑iwiP(ei) with wi > 0. For instance, the well-known KCBS inequality corresponding to the 5-cycle exclusivity graph is of the form \({S}_{KCBS}=\mathop{\sum }\nolimits_{i = 0}^{4}P(0,1| i,i+1)\le 2\) with 2 denoting the maximal value in all non-contextual hidden variable theories. In the CSW framework, one associates to every such non-contextuality inequality S a vertex-weighted graph (G, w) (note that a vertex-weighted graph (G, w) is a graph G with vertex set V and weight assignment \(w:V\to {{\mathbb{R}}}_{+}\)). The events ei appearing in S are represented by vertices in G, adjacent vertices in G represent exclusive events (events ei and ej are exclusive if there exist jointly measurable observables μi and μj that distinguish between the events), and the vertex weights represent the coefficients wi of the probabilities P(ei). The graph (G, w) is then called the exclusivity graph of S. The main result of CSW is the following theorem showing how the exclusivity graph of S can be used to calculate the optimal value of the inequality in classical and quantum theories.

Theorem 4

(Result 1 of CSW17). Given S corresponding to a non-contextuality inequality, the maximum value of S in classical and quantum theories is given by

$$S\mathop{\le }\limits^{\,{{\rm{NCHV}}}\,}\alpha (G,w)\mathop{\le }\limits^{\,{{\mbox{Q}}}\,}\theta (G,w),$$
(8)

where α(G, w) is the independence number of (G, w) and θ(G, w) is the Lovász-theta number of (G, w).

While it was recognized that θ(G, w) may only provide an upper bound to the quantum value in some cases - specifically when further constraints are imposed coming from the physical settings of the experiment, the statement that the classical value of any given non-contextuality inequality is given by α(G, w) is ubiquitous and taken to be true without any qualifications in much of the literature to this point. Furthermore, it is often also applied in situations when the Kochen-Specker rule of Completeness is enforced, namely that every maximum clique has exactly one vector that is assigned value 1. We now make the observation that this statement needs to be carefully considered in computing the classical value of non-contextuality inequalities arising from gadget-type structures, α(G, w) only provides an upper bound to the classical value for such inequalities when Completeness is enforced. Specifically consider a non-contextuality inequality S arising from a gadget-type exclusivity graph, so that vertex-weighted graph (G, w) corresponding to S is a gadget-type graph, meaning that the vertex set V of G can be partitioned into an independent set of distinguished vertices VdistV and the non-distinguished vertices \(V \setminus {V}_{{{\rm{dist}}}}\). And furthermore, the weights wi in S are given as

$${w}_{i}=\left\{\begin{array}{ll}1\quad i\in {V}_{{{\rm{dist}}}}\\ 0\quad {i}\in V\setminus {V}_{{{\rm{dist}}}}\end{array}\right.$$
(9)

Observation 1

Given S corresponding to a non-contextuality inequality, the maximum value of S under the KS rules of Exclusivity and Completeness, in any classical (non-contextual hidden variable) theory is given by α(G, w) if and only if the vertex-weighted graph (G, w) is not of gadget-type.

Proof

The proof of the observation is a direct consequence of the gadget property of the exclusivity graph (G, w). By this gadget property, it holds that the vertices in the distinguished set Vdist cannot all be assigned value 1 in any non-contextual assignment when Completeness is enforced, despite the fact that Vdist is an independent set. Therefore, for the non-contextuality inequality S = ∑iwiP(ei) with wi given by Eq. (9), the maximum value in any non-contextual hidden variable theory is only upper bounded by and never equal to α(G, w) (note that achieving α(G, w) requires assigning value 1 to every vertex in the independent set Vdist). Furthermore, this restriction on the assignment of 1s (arising from the KS requirement that every measurement returns an outcome) is exactly the defining feature of gadget-type graphs so that α(G, w) is not equal to the classical value (under Completeness) only for the non-contextuality inequalities arising from such measurement structures.

A generalization of gadgets with other forbidden value assignments

Thus far, we have generalized the well-known ‘True-implies-False’ sets or 01-gadgets to gadgets of order (m, k). These latter sets contain m independent vertices (mutually non-orthogonal vectors) of which exactly k may be assigned value 1 in any {0, 1}-coloring. In other words, given an independent set I = {v1, …, vm} these consider forbidden value assignments of the form \(\{\underbrace{1,\ldots ,1}_{k+1},f({v}_{k+2}),\ldots ,f({v}_{m})\}\) and permutations thereof, where f: V → {0, 1} is any {0, 1}-coloring of the vertices. One may consider a yet more general measurement structure in which we specify a set of forbidden value assignments \({{{\mathcal{H}}}}\subset {\{0,1\}}^{m}\). The usual ‘True-implies-False’ sets then correspond to \({{{\mathcal{H}}}}=\{(1,1)\}\) for a given independent set I = {v1, v2} of two vertices.

Definition 10

A {0, 1}-colorable set \({S}_{gad}\in {{\mathbb{C}}}^{d}\) is a gadget in dimension d for a specified forbidden set \({{{\mathcal{H}}}}\subset {\{0,1\}}^{m}\) if it contains an (ordered) set of mutually non-orthogonal vectors \(I=\{\left\vert {v}_{1}\right\rangle ,\ldots ,\left\vert {v}_{m}\right\rangle \}\) such that in any {0, 1}-coloring of Sgad it holds that \(f(I)\in {\{0,1\}}^{m}\setminus {{{\mathcal{H}}}}\).

Equivalently, the generalized gadget for a forbidden assignment \({{{\mathcal{H}}}}\) can be defined in graph-theoretic terms as follows.

Definition 11

A {0, 1}-colorable graph G = (V, E) is a gadget in dimension d for a specified forbidden set \({{{\mathcal{H}}}}\subset {\{0,1\}}^{m}\), if it has faithful dimension d*(Ggad) = ω(Ggad) = d and contains an (ordered) independent set IV of cardinality I = m such that in any {0, 1}-coloring f: V → {0, 1} it holds that \(f(I)\in {\{0,1\}}^{m}\setminus {{{\mathcal{H}}}}\).

A natural question then arises - can a gadget be constructed for every forbidden set \({{{\mathcal{H}}}}\subset {\{0,1\}}^{m}\) for arbitrary m≥2? Note that the number of such forbidden sets \({{{\mathcal{H}}}}\) is \({2}^{{2}^{m}}-1\) (i.e., all subsets of {0, 1}m except the empty set). We answer this question in the affirmative and demonstrate the precise steps of building such a gadget in Supplementary Information Note 4. It’s worth noting that Kochen Specker proofs themselves come under the umbrella of the generalized gadget structures defined here, with \({{{\mathcal{H}}}}={\{0,1\}}^{m}\) for some independent set in the graph I of size I = m and for arbitrary m≥1. In other words, there is no valid {0, 1}-assignment to the vertices of the independent set I.