Continuous-variable nonlocality and contextuality

Contextuality is a non-classical behaviour that can be exhibited by quantum systems. It is increasingly studied for its relationship to quantum-over-classical advantages in informatic tasks. To date, it has largely been studied in discrete-variable scenarios, where observables take values in discrete and usually finite sets. Practically, on the other hand, continuous-variable scenarios offer some of the most promising candidates for implementing quantum computations and informatic protocols. Here we set out a framework for treating contextuality in continuous-variable scenarios. It is shown that the Fine--Abramsky--Brandenburger theorem extends to this setting, an important consequence of which is that Bell nonlocality can be viewed as a special case of contextuality, as in the discrete case. The contextual fraction, a quantifiable measure of contextuality that bears a precise relationship to Bell inequality violations and quantum advantages, is also defined in this setting. It is shown to be a non-increasing monotone with respect to classical operations that include binning to discretise data. Finally, we consider how the contextual fraction can be formulated as an infinite linear program. Through Lasserre relaxations, we are able to express this infinite linear program as a hierarchy of semi-definite programs that allow to calculate the contextual fraction with increasing accuracy.


Introduction
Contextuality is one of the principal non-classical behaviours that can be exhibited by quantum systems.The Heisenberg uncertainty principle identified that certain pairs of quantum observables are incompatible, e.g.position and momentum.In operational terms, observing one will disturb the outcome statistics of the other.Imprudent commentators will sometimes cite this as evidence that position and momentum cannot simultaneously be assigned definite values.However, this is not quite right and a more careful conclusion is that we simply cannot observe these values simultaneously.To make a stronger statement requires contextuality.Roughly speaking, the latter is present whenever the behaviour of a system is inconsistent with the basic assumptions that (i) all of its observable properties may be assigned definite values at all times, and (ii) jointly performing compatible observables does not disturb the global value assignment.Aside from its foundational importance, today contextuality is increasingly studied as the essential ingredient for enabling a range of quantum-over-classical advantages in informatic tasks, which include the onset of universal quantum computing in certain computational models [65,44,6,20,7].
It is notable that to date the study of contextuality has largely focused on discrete variable scenarios and that the main frameworks and approaches to contextuality are tailored to modelling these, e.g.[8,26,13,33].In such scenarios, observables can only take values in discrete, and usually finite, sets.Discrete variable scenarios typically arise in finitedimensional quantum mechanics, e.g. when dealing with quantum registers in the form of systems of multiple qubits as is common in quantum information and computation theory.
Yet, from a practical perspective, continuous-variable quantum systems are emerging as some of the most promising candidates for implementing quantum informational and computational tasks [25,74].The main reason for this is that they offer unrivalled possibilities for deterministic generation of large-scale resource states [76] and for highly-efficient measurements of certain observables.Together these cover many of the basic operations required in the one-way or measurement-based model of quantum computing [67] for example.Typical implementations are in optical systems where the continuous variables correspond to the position-like and momentum-like quadratures of the quantised modes of an electromagnetic field.Indeed position and momentum as mentioned previously in relation to the uncertainty principle are the prototypical examples of continuous variables in quantum mechanics.
Since quantum mechanics itself is infinite dimensional, it also makes sense from a foundational perspective to extend analyses of the key concept of contextuality to the continuous-variable setting.Furthermore, continuous variables can be useful when dealing with iteration, even when attention is restricted to finite-variable actions at discrete time steps, as is traditional in informatics.An interesting question, for example, is whether contextuality arises and is of interest in such situations as the infinite behaviour of quantum random walks.
The main contributions of this article are the following: • We present a robust framework for contextuality in continuous-variable scenarios that follows along the lines of the discrete-variable framework introduced by Abramsky and Brandenburger [8] (Section 3).
• We show that the Fine-Abramsky-Brandenburger theorem [36,8] extends to continuous variables (Section 4).This establishes that noncontextuality of an empirical behaviour, originally characterised by the existence of deterministic hidden-variable models [19,50], can equivalently be characterised by the existence of a factorisable hidden-variable models, and that ultimately both of these are subsumed by a canonical form of hidden-variable model -a global section in the sheaf-theoretic perspective.An important consequence is that nonlocality may be viewed as a special case of contextuality in continuous-variable scenarios just as for discrete-variable scenarios.
• The contextual fraction, a quantifiable measure of contextuality that bears a precise relationship to Bell inequality violations and quantum advantages [6], can also be defined in this setting using infinite linear programming (Section 5).It is shown to be a non-increasing monotone with respect to the free operations of a resource theory for contextuality [6,4].Crucially, these include the common operation of binning to discretise data.A consequence is that any witness of contextuality on discretised empirical data also witnesses and gives a lower bound on genuine continuous-variable contextuality.
• While the infinite linear programs are of theoretical importance and capture exactly the quantity and inequalities we are interested in, they are not directly useful for actual numerical computations.To get around this limitation, we introduce a hierarchy of semi-definite programs which are relaxations of the original problem, and whose values converge monotonically to the contextual fraction (Section 6).
Related work.Note that we will specifically be interested in scenarios involving observables with continuous spectra, or in more operational language, measurements with continuous outcome spaces.We will still consider scenarios featuring only discrete sets of observables or measurements, as is typical in continuous-variable quantum computing.The possibility of considering contextuality in settings with continuous measurement spaces has also been evoked in [30].We also note that several prior works have explicitly considered contextuality in continuous-variable systems [63,40,59,73,14,52,48].Our approach is distinct from these in that it provides a genuinely continuous-variable treatment of contextuality itself as opposed to embedding discrete variable contextuality arguments into, or extracting them from, continuous-variable systems.

Continuous-variable behaviours
In this section we provide a brief motivational example for the kind of continuous-variable empirical behaviour we are interested in analysing.Suppose that we can interact with a system by performing measurements on it and observing their outcomes.A feature of quantum systems is that not all observables commute, so that certain combinations of measurements may be incompatible.At best we obtain empirical observational data for contexts in which only compatible measurements are performed, which can be collected by running the experiment repeatedly.As we shall make more precise in Sections 3 and 4, contextuality arises when the empirical data obtained is inconsistent with the assumption that for each run of the experiment the system has a global and context-independent assignment of values to all of its observable properties.
To take an operational perspective, a typical example of an experimental setup or scenario that we can consider is the one depicted in Figure 1 [left].In this scenario, a system is prepared in some fixed bipartite state, following which parties A and B may each choose between two measurement settings, m A ∈ {a, a } for A and m B ∈ {b, b } for B. We will assume that outcomes of each measurement live in R R R, which typically would be a bounded measurable subspace of the real numbers R. Depending on which choices of inputs were made, the empirical data might for example be distributed according to one of the four hypothetical probability density plots in R R R 2 depicted in Figure 1 [right].This scenario and hypothetical empirical behaviour has been considered elsewhere [48] as a continuous-variable version of the Popescu-Rohrlich (PR) box [64].[Right] Hypothetical probability density plots for empirical data arising from such an experiment.Cf. the discrete-variable probability tables of [57,55].

Preliminaries on measures and probability
In order to properly treat probability on continuous-variable spaces, it is necessary to introduce a modicum of measure theory.This section serves to recall some basic ideas and fix notation.The reader may choose to skip the section and consult it as reference for the remainder of the article.
A measurable space is a pair X X X = X, F consisting of a set X and a σ -algebra (or σ -field) F on X, i.e. a family of subsets of X containing the empty set and closed under complementation and countable unions.In some sense, this specifies the subsets of X that can be assigned a 'size', and which are therefore called the measurable sets of X X X.Throughout this paper, we follow the convention of using boldface to denote the measurable space and the same symbol in regular face for its underlying set.
A trivial example of a σ -algebra over any set X is its powerset P(X), which gives the discrete measurable space X, P(X) , where every set is measurable.This is typically used when X is countable (finite or countably infinite), in which case this discrete σ -algebra is generated by the singletons.Another example, of central importance in measure theory, is R, B R , where B R is the σ -algebra generated from the open sets of R, whose elements are called the Borel sets.Working with Borel sets avoids the problems that would arise if we naively attempted to measure or assign probabilities to points in the continuum.More generally, any topological space gives rise to a Borel measurable space in this fashion.
A measurable function between measurable spaces X X X = X, F X and Y Y Y = Y, F Y is a function f : X −→ Y between the underlying sets whose preimage preserves measurable sets, i.e. such that f −1 (E) ∈ F X for any E ∈ F Y .This is analogous to the definition of a continuous function between topological spaces.Clearly, the identity function is measurable and measurable functions compose.We will denote by Meas the category whose objects are measurable spaces and whose morphisms are measurable functions.
The product of measurable spaces X X X where the so-called tensor-product σ -algebra F 1 ⊗ F 2 is the σ -algebra on the Cartesian product X 1 × X 2 generated by the 'rectangles', the subsets of the form E 1 × E 2 with E 1 ∈ F 1 and E 2 ∈ F 2 .This is the categorical product in Meas.
A measure on a measurable space X X X = X, F is a function µ : F −→ R from the σ -algebra to the extended real numbers R = R ∪ {−∞, +∞} satisfying: A measure on X X X allows one to integrate well-behaved1 measurable functions f : X X X −→ R, B R to obtain a real value, denoted X X X f d µ or x∈X X X f (x) d µ(x).The simplest example of such a measurable function is the indicator function of a measurable set E ∈ F : For any measure µ on X X X, its integral is A measure is finite if µ(X) < ∞ and in particular it is a probability measure if µ(X) = 1.We will denote by M(X X X) and P(X X X), respectively, the sets of measures and probability measures on the measurable space X X X.
A measurable function f : X X X −→ Y Y Y carries any measure µ on X X X to a measure f * µ on Y Y Y .This push-forward measure is given by f * µ(E) = µ( f −1 (E)) for any set E measurable in Y Y Y .An important use of push-forward measures is that for any integrable function g : Y Y Y −→ R, B R , it allows us to write the following change-of-variables formula ( The push-forward operation preserves the total measure, hence it takes P(X X X) to P(Y Y Y ).A case that will be of particular interest to us is the push-forward of a measure µ on a product space X X X 1 ×X X X 2 along a projection π i : X X X 1 ×X X X 2 −→ X X X i : this yields the marginal measure µ| X X X i = π i * µ, where e.g. for E measurable in ).In the opposite direction, given measures µ 1 on X X X 1 and µ 2 on X X X 2 , a product measure µ 1 × µ 2 is a measure on the product measurable space X X X 1 × X X X 2 satisfying (µ For probability measures, there is a uniquely determined product measure. 2e can view M as a map that takes a measurable space to the set of measures on that space, and similarly for P.These become functors Meas −→ Set if we define the action on morphisms to be the push-forward operation.Explicitly, for f : and similarly for P. Remarkably, the set P(X X X) of probability measures on X X X can itself be made into a measurable space by equipping it with the least σ -algebra that makes the evaluation functions ev E : P(X X X) −→ [0, 1] :: µ −→ µ(E) measurable for all E ∈ F X . 3This yields an endofunctor P : Meas −→ Meas, which moreover has the structure of a monad, called the Giry monad [39].The unit of this monad is given by η X X X : X X X −→ P(X X X) :: x −→ δ x where δ x is the Dirac measure, or point mass, at x given by δ x (E) := χ E (x).Multiplication of the monad is given by µ X X X : P(P(X X X)) −→ P(X X X) which takes a probability measure P on P(X X X) to its 'average', a probability measure µ X X X (P) : F X −→ [0, 1] on X X X whose value on a measurable set E ∈ F X is given by µ X X X (P)(E) := P(X X X) ev E d P.
The Kleisli category of this monad is the category of Markov kernels, which represent continuous-variable probabilistic maps and generalise the discrete notion of stochastic matrix.Concretely, a Markov kernel between measurable spaces

Framework
In this section we will follow closely the discrete-variable framework of [8] in more formally describing the kinds of experimental scenarios in which we are interested and the empirical behaviours that arise on these, although some extra care is required for continuous variables.

Measurement scenarios
Definition 1.A measurement scenario is a triple X, M , O O O whose elements are specified as follows.
• X is a finite set of measurement labels.
• M is a covering family of subsets of X, i.e. such that M = X.The elements C ∈ M are called maximal contexts and represent maximal sets of compatible observables.We therefore require that M be an anti-chain with respect to subset inclusion, i.e. that no element of this family is a proper subset of another.Any subset of a maximal context also represents a set of compatible measurements, and we refer to elements of Measurement scenarios can be understood as providing a concise description of the kind of experimental setup that is being considered.For example, the setup represented in Figure 1 is described by the measurement scenario: where R R R is a bounded measurable subspace of R.
If some set of measurements U ⊆ X is considered together, there is a joint outcome space given by the product of the respective outcome spaces: The map E that maps U ⊆ X to E (U) = O O O U is called the event sheaf as concretely it assigns to any set of measurements information about the outcome events that could result from jointly peforming them.Note that as well as applying the map to valid contexts U ∈ U we will see that it can also be of interest to consider hypothetical outcome spaces for sets of measurements that do not necessarily form valid contexts, in particular E (X) = O O O X , the joint outcome space for all measurements.Moreover, as we will briefly discuss, this map satisfies the conditions to be a sheaf E : P(X) op −→ Meas where P(X) denotes the powerset of X, similarly to its discrete-variable analogue in [8].

The language of sheaves
Sheaves are widely used in modern mathematics.They might roughly be thought of as providing a means of assigning information to the open sets of a topological space in such a way that information can be restricted to subsets and consistent information can be 'glued' on unions 6 .In this work we are concerned with discrete topological spaces whose points represent measurements, and the information that we are interested in assigning has to do with outcome spaces for these measurements and probability measures on these outcome spacess.Sheaves can be defined concisely in category-theoretic terms as contravariant functors (presheaves) satisfying an additional gluing condition, though in what follows we will also give a more concrete description in terms of restriction maps.Categorically, the event sheaf is a functor E : P(X) op −→ Meas where P(X) is viewed as a category in the standard way for partial orders, with morphisms corresponding to subset inclusions.
Sheaves come with a notion of restriction.In our example restriction arises in the following way: whenever U ⊆ V we have an obvious restriction map ρ V U : E (V ) −→ E (U) which simply projects from the product outcome space for V to that for U. Note that ρ U U is the identity map and that if Our map assigns outcome spaces E (U) = O O O U to sets of measurements U, and in sheaf and presheaf terminology elements of these outcome spaces are called sections over U.Sections over X are called global sections.
Additionally, the unique gluing property holds for E .Suppose we have a family of sections {o U ∈ O U } U∈N that is compatible in the sense that its assignments agree on restrictions, i.e. o U | U∩V = o V | U∩V for all U,V ∈ N .Then these sections can always be 'glued' together in a unique fashion to obtain a section o N over N := ∪N such that o N | U = o U for all U ∈ N .This makes E a sheaf.
We will primarily be concerned with probability measures on outcome spaces.For this, we recall that the Giry monad P : Meas −→ Meas takes a measurable space and returns the probability measures over that space.Composing it with the event sheaf yields the map P • E that takes any context and returns the probability measures on its joint outcome space.In fact, this is a presheaf P • E : P(X) op −→ Meas, where restriction on sections is given by marginalisation of probability measures.Note that marginalisation simply corresponds to the push-forward of a measure along projections to a component of the product space, which are precisely the restriction maps of E .Note, however, that this presheaf does not satisfy the gluing condition and thus it crucially is not a sheaf.Empirical models capture in a precise way the probabilistic behaviours that may arise upon performing measurements on physical systems.The compatibility condition ensures that the empirical behaviour of a given measurement or compatible subset of measurements is independent of which other compatible measurements might be performed along with them.This is sometimes referred to as the no-disturbance condition.A special case is no-signalling, which applies in multi-party or Bell scenarios such as that of Figure 1 and Eq. ( 3).In that case, contexts consist of measurements that are supposed to occur in space-like separated locations, and compatibility ensures for instance that the choice of performing a or a at the first location does not affect the empirical behaviour at the second location, i.e. e {a,b} | {b} = e {a ,b} | {b} .

Continuous-variable nonlocality and contextuality
Note also that while empirical models may arise from the predictions of quantum theory, their definition is theoryindependent.This means that empirical models can just as well describe hypothetical behaviours beyond what can be achieved by quantum mechanics such as the well-studied Popescu-Rohrlich box [64].This can be useful in probing the limits of quantum theory, and for singling out what distinguishes and characterises quantum theory within larger spaces of probabilistic theories, both established lines of research in quantum foundations.
Sheaf-theoretically.An empirical model is a compatible family of sections for the presheaf P • E indexed by the maximal contexts of the measurement scenario.A natural question that may occur at this point is whether these sections can be glued to form a global section, and this is what we address next.

Extendability and contextuality
Recall that O O O X is the global outcome space, whose elements correspond to global assignments of outcomes to all measurements.Of course, it is not always the case that X is a valid context, and if it were then µ = e X would trivially extend the empirical model.The question of the existence of such a probability measure that recovers the contextwise empirical content of e is particularly significant.When it exists, it amounts to a way of modelling the behaviour as arising stochastically from the behaviours of underlying states, identified with the elements of O X , each of which deterministically assigns outcomes to all the measurements in X independently of the context that is actually performed.If an empirical model is not extendable it is said to be contextual.Sheaf-theoretically.A contextual empirical model is a compatible family of sections for the presheaf P • E over the contexts of the measurement scenario that cannot be glued to form a global section.Contextuality thus arises as the tension between local consistency and global inconsistency.

A FAB theorem
Quantum theory presents a number of non-intuitive features.For instance, Einstein, Podolsky and Rosen (EPR) identified early on that if the quantum description of the world is taken as fundamental then entanglement poses a problem of "spooky action at a distance" [35].Their conclusion was that quantum theory should be consistent with a deeper or more complete description of the physical world, in which such problems would disappear.The import of seminal foundational results like the Bell [18] and Bell-Kochen-Specker [19,50] theorems is that they identify such non-intuitive behaviours and then rule out the possibility of finding any underlying model for them that would not suffer from the same issues.Incidentally, we note that the EPR paradox was originally presented in terms of continuous variables, whereas Bell's theorem addressed a discrete variable analogue of it.
In the previous section, we characterised contextuality of an empirical model by the absence of a global section for that empirical model.We also saw that global sections capture one kind of underlying model for the behaviour, namely via deterministic global states that assign predefined outcomes to all measurements, which is precisely the kind of model referred to in the Kochen-Specker theorem [50].Bell's theorem, on the other hand, related to a different kind of hidden-variable model, where the salient feature -Bell locality -was a kind of factorisability rather than determinism.Fine [36] showed that in one important measurement scenario (that of the concrete example from Fig. 1) the existence of one kind of model is equivalent to existence of the other.Abramsky and Brandenburger [8] proved in full generality that this existential equivalence holds for any measurement scenario, and that global sections of P • E provide a canonical form of hidden-variable model.
In this section, we prove a Fine-Abramsky-Brandenburger theorem in the continuous-variable setting.It establishes that in this setting there is also an unambiguous, unified description of locality and noncontextuality, which is captured in a canonical way by the notion of extendability.
We will begin by introducing hidden-variable models in a more precise way.The idea is that is that there exists some space Λ Λ Λ of hidden variables, which determine the empirical behaviour.However, elements of Λ may not be directly empirically accessible themselves, so we allow that we might only have probabilistic information about them in the form of a probability measure p on Λ Λ Λ.The empirically observable behaviour should then arise as an average over the hidden-variable behaviours.Definition 4. Let X, M , O O O be a measurement scenario.A hidden-variable model8 on this scenario consists of the following ingredients: • A measurable space Λ Λ Λ = Λ, F Λ of hidden variables.
Remark 5. Equivalently, we can regard Eq. ( 4 Note that our definition of hidden-variable model assumes the properties known as λ independence [31] and parameter-independence [45,69].The former corresponds to the fact that the probability measure p on the hiddenvariable space is independent of the measurement context to be performed, while the latter corresponds to the compatibility condition (4), which also ensures that the corresponding empirical model is no-signalling [23].We refer the reader to [24] for a detailed discussion of these and other properties of hidden-variable models specifically in the case of multi-party Bell scenarios.
The idea behind the introduction of hidden variables is that they could explain away some of the more non-intuitive aspects of the empirical predictions of quantum mechanics, which would then arise as resulting from an incomplete knowledge of the true state of a system rather than being a fundamental feature.There is some precedent for this in physical theories: for instance, statistical mechanics -a probabilistic theory -admits a deeper, albeit usually unwieldily complex, description in terms of classical mechanics which is purely deterministic.Therefore it is desirable to impose conditions on hidden-variable models which amount to requiring that they behave in some sense classically when conditioned on each particular value of the hidden variable λ .This motivates the notions of deterministic and of factorisable hidden-variable models.
is a Dirac measure for every λ ∈ Λ and for every maximal context C ∈ M ; in other words, there is an assignment In general discussions on hidden-variable models (e.g.[24]), the condition above, requiring that each hidden variable determines a unique joint outcome for each measurement context, is sometimes referred to as weak determinism.This is contraposed to strong determinism, which demands not only that each hidden variable fix a deterministic outcome to each individual measurement, but that this outcome be independent of the context in which the measurement is performed.Note, however, that since our definition of hidden-variable models assumes the compatilibity condition of (4) (i.e.parameter-independence), both notions of determinism coincide [23].
factorises as a product measure for every λ ∈ Λ and for every maximal context C ∈ M .That is, for any family of measurable sets where 10  Remark 9.In other words, if we consider elements of Λ as inaccessible 'empirical' models -i.e. if we use the alternative definition of hidden-variable models using the map k, see Remark 5 -then factorisability is the requirement that each of these be factorisable in the sense that where We now prove the continuous-variable analogue of the theorem proved in the discrete probability setting Abramsky and Brandenburger [8, Proposition 3.1 and Theorem 8.1], generalising the result of Fine [36] to arbitrary measurement scenarios.
Theorem 10.Let e be an empirical model on a measurement scenario X, M , O O O .The following are equivalent: (1) e is extendable; (2) e admits a realisation by a deterministic hidden-variable model; (3) e admits a realisation by a factorisable hidden-variable model.
(1) ⇒ (2).The idea is that E (X) = O O O X provides a canonical deterministic hidden-variable space.Suppose that e is extendable to a global probability measure µ.Let us set Λ Λ Λ := O O O X , set p := µ, and set k C (g, -) := δ g| C for all global outcome assignments g ∈ O X .This is by construction a deterministic hidden-variable model, which we claim gives rise to the empirical model e.
Let C ∈ M and write ρ : for the measurable projection which, in the event sheaf, is the restriction map For any E ∈ F C , we have and therefore, as required, Next we will show that this is a global section for the empirical probabilities.Let C ∈ M and consider a family of measurable sets {F x ∈ F x } x∈C and let F = ∏ x∈C F x ∈ F C be the corresponding rectangle.Then Since the σ -algebra F C of O O O C is generated by the rectangles (such as F above) and we have seen that µ| C agrees with e C on these sets, we conclude that µ| C = e C as required.

Quantifying contextuality
Beyond questioning whether a given empirical behaviour is contextual or not, it is also interesting to ask to what degree it is contextual.In discrete-variable scenarios, a very natural measure of contextuality is the contextual fraction [8].This measure was shown in [6] to have a number of very desirable properties.It can be calculated using linear programming, an approach that subsumes the more traditional approach to quantifying nonlocality and contextuality using Bell and noncontextual inequalities in the sense that we can understand the (dual) linear program as optimising over all such inequalities for the scenario in question and returning the maximum normalised violation of any Bell or noncontextuality inequality achieved by the given empirical model.Crucially, the contextual fraction was also shown to quantifiably relate to quantum-over-classical advantages in specific informatic tasks [6,58,75].Moreover it has been demonstrated to be a monotone with respect to the free operations of resource theories for contextuality [6,32,4].
In this section, we consider how to carry those ideas to the continuous-variable setting.The formulation as a linear optimisation problem and the attendant correspondence with Bell inequality violations requires special care as one needs to use infinite linear programming, necessitating some extra assumptions on the outcome measurable spaces.

The contextual fraction
Asking whether a given behaviour is noncontextual amounts to asking whether the empirical model is extendable, or in other words whether it admits a deterministic hidden-variable model.However, a more refined question to pose is what fraction of the behaviour admits a deterministic hidden-variable model?This quantity is what we call the noncontextual fraction.Similarly, the fraction of the behaviour that is left over and that can thus be considered irreducibly contextual is what we call the contextual fraction.

Monotonicity under free operations including binning
In the discrete-variable setting, the contextual fraction was shown to be a monotone under a number of natural classical operations that transform and combine empirical models and control their use as resources, therefore constituting the 'free' operations of a resource theory of contextuality [6,32,4].All of the operations defined for discrete variables in [6] -viz.translations of measurements, transformation of outcomes, probabilistic mixing, product, and choice -carry almost verbatim to our current setting.One detail is that one must insist that the coarse-graining of outcomes be achieved by (a family of) measurable functions.A particular example of practical importance is binning, which is widely used in continuous-variable quantum information as a method of discretising data by partitioning the outcome space O O O x for each measurement x ∈ X into a finite number of 'bins', i.e. measurable sets.Note that a binned empirical model is obtained by pushing forward along a family finite for all x ∈ X.For the conditional measurement operation introduced in [4], which allows for adaptive measurement protocols such as those used in measurement-based quantum computation [67], one must similarly insist that the map determining the next measurement to perform based on the observed outcome of a previous measurement be a measurable function.Since we are, for the moment, only considering scenarios with a finite number of measurements, this amounts to a partition into measurable subsets of the outcome space O O O x of the first measurement, x, indexed by measurements compatible with x, indicating which will be subsequently performed depending on the outcome observed for x.
The inequalities establishing monotonicity from [6, Theorem 2] will also hold for continuous variables.There is a caveat for the equality formula for the product of two empirical models, NCF(e 1 ⊗ e 2 ) = NCF(e 1 )NCF(e 2 ).Whereas the inequality establishing monotonicity (≥) stills holds in general, the proof establishing the other direction (≤) makes use of duality of linear programs.Therefore, it will only hold under the assumptions we will impose in the remainder of this section.Proposition 12.If e is an empirical model, and e bin is any discrete-variable empirical model obtained from e by binning, then contextuality of e bin witnesses contextuality of e, and quantifiably gives a lower bound CF(e bin ) ≤ CF(e).

Assumptions on the outcome spaces
In order to phrase the problem of contextuality as an (infinite) linear programming problem and establish the connection with violations of Bell inequalities, we need to impose some conditions on the measurable spaces of outcomes.From now on, we restrict attention to the case where the outcome space O O O x for each measurement x ∈ X is the Borel measurable space for a second-countable locally compact Hausdorff space, i.e. that the set O x is equipped with a secondcountable locally compact Hausdorff topology and F x is the σ -algebra generated by its open sets, written B(O x ).Note that this includes most situations of interest in practice.In particular, it includes the case of measurements with outcomes in R or R n or a bounded subset of these.
Second countability and Hausdorffness of two spaces Y and Z suffice to show that B(Y × Z) = B(Y ) ⊗ B(Z), i.e. the Borel σ -algebra of the product topology is the tensor product of the Borel σ -algebras [22, Lemma 6.4.2 (Vol.2)].Hence, these assumptions guarantee that O O O U is the Borel σ -algebra of the product topology on O U = ∏ x∈U O x .These spaces are also second-countable, locally compact, and Hausdorff as all three properties are preserved by finite products.
In order to phrase the problem as an infinite linear program, we need to work with vector spaces.However, probability measures, or even finite or arbitrary measures, do not form one.We will therefore consider the set M ± (Y Y Y ) of finite signed measures (a.k.a.real measures) on a measurable space Y Y Y = Y, F Y .These are functions µ : F Y −→ R such that µ( / 0) = 0 and µ is σ -additive.In comparison to the definition of a measure, one drops the nonnegativity requirement, but insists that the values be finite.The set M ± (Y Y Y ) forms a real vector space which includes the probability measures P(Y Y Y ), and total variation gives a norm on this space.When Y is a second-countable locally compact Hausdorff space and Y Y Y = Y, B(Y ) , the Riesz-Markov-Kakutani representation theorem [46] shows that M ± (Y Y Y ) is a concrete realisation of the topological dual space of C 0 (Y, R), the space of continuous real-valued functions on Y that vanish at infinity. 11The duality is given by µ

Linear programming
Calculation of the noncontextual fraction of an empirical model e = {e C } C∈M can be expressed as an infinite linear programming problem, (P).This is our primal linear program, which also has a dual linear program given by (D).We will see how to derive the dual and show that the optimal solutions of both programs coincide in what follows.We also refer the interested reader to Appendix A where the programs are expressed in the standard form for infinite linear programming [17].
We have written ρ X C for the projection O X −→ O C as before, and 1 for the constant function that assigns the number 1 to all g ∈ O X . 13We denote the optimal values of problems (P) and (D), respectively, as sup (P) = NCF(e) and inf (D).
Analogues of these programs have been studied in the discrete-variable setting [6].Note however that, in general, these continuous-variable linear programs are over infinite-dimensional spaces and thus not practical to compute directly.For this reason, in Section 6 we will introduce a hierarchy of finite-dimensional semi-definite programs that approximate the solution of (P) to arbitrary precision.

Bell inequalities and the dual program
The dual program is of particular interest in its own right.As we will now show, it can essentially be understood as computing a continuous-variable 'Bell inequality' that is optimised to the empirical model.Making the change of variables β C := |M | −1 f C for each C ∈ M , the dual program (D) transforms to the following. Here The above definition restricts to the usual notions of Bell inequality and noncontextual inequality in the discretevariable case and is particularly close to the presentation in [6].The following theorem also generalises to continuous variables the main result of [6].Theorem 14.Let e be an empirical model.(i) The normalised violation by e of any Bell inequality is at most CF(e); (ii) if CF(e) > 0 then for every ε > 0 there exists a Bell inequality whose normalised violation by e is at least CF(e) − ε.
Proof.The proof follows directly from the definitions of the linear programs, and from strong duality, i.e. the fact that their optimal values coincide (Proposition 15 below).

Deriving the dual via the Lagrangian
We now give an explicit derivation of (D) as the dual of (P) via the Lagrangian method.To simplify notation, we set Ẽ1 := M ± (O O O X ) and F 2 := ∏ C∈M C 0 (O C , R).This matches the standard form notation for infinite linear programming of [17], in which we present our programs in Appendix A. We do not take into account positivity constraints as they translate directly from primal to dual.Hence we introduce |M | dual variables, one continuous map f C ∈ C 0 (O C , R) for each C ∈ M , to account for the constraints µ| C ≤ e C .From (P), we then define the Lagrangian L : Ẽ1 × F 2 −→ R as The primal program (P) corresponds to sup Continuous-variable nonlocality and contextuality as the infimum here imposes the constraints that µ| C ≤ e C for all C ∈ M , for otherwise the Lagrangian diverges.If these constraints are satisfied, then because of the infimum, the second term of the Lagrangian vanishes yielding the objective of the primal problem.To express the dual, which amounts to permuting the infimum and the supremum, we need to rewrite the Lagrangian: The dual (D) indeed corresponds to inf Yhe supremum imposes that , since otherwise the Lagrangian diverges.If this constraint is satisfied, then the supremum makes the second term vanish yielding the objective of the dual problem (D).

Zero duality gap
A key result about the noncontextual fraction, which is essential in establishing the connection to Bell inequality violations, is that (P) and (D) are strongly dual, in the sense that no gap exists between their optimal values.Strong duality always holds in finite linear programming, but it does not hold in general for the infinite case.Proposition 15.Problems (P) and (D) have zero duality gap and their optimal values satisfy: Proof.This proof relies on [17, Theorem 7.2].The complete proof is provided in Appendix B. Here, we only provide a brief outline.Let Strong duality between (P) and (D) amounts to showing that the cone We do so by considering a sequence (µ k , (ν k C ) C ) k∈N in E 1+ and showing that the accumulation point lim k→∞ belongs to K .

Approximating the contextual fraction with SDPs
In Section 5, we presented the problem of computing the noncontextual fraction as an infinite linear program.Although this is of theoretical importance, it does not allow one to directly perform the actual, numerical computation of this quantity.Here we exploit the link between measures and their sequence of moments to express a hierarchy of truncated semi-definite programming problems which are relaxations of the original problem, in the particular case when the outcome spaces of measurements are certain subsets of R n .These finite problems can actually be implemented numerically and have the crucial feature that their optimal values converge monotonically to the noncontextual fraction.This section makes use of the global optimisation techniques developed by Lasserre and others [51,42].

Notation and terminology
Let R[x] denote the ring of real polynomials in the variables x ∈ R d , and let R contain those polynomials of total degree at most k.The latter forms a vector space of dimension s(k) := d+k k , with a canonical basis consisting of k can be expanded in this basis as p(x) = ∑ α∈N d k p α x α and we write p := (p α ) ∈ R s(k) for the resulting vector of coefficients.Given a sequence y = (y α ) α∈N d with y α ∈ R, we define the linear functional L y : R[x] −→ R by L y (p) := ∑ α∈N d p α y α .Let K K K be a Borel measurable subspace of R n .Given a measure µ ∈ M ± (K K K), its moment sequence y = (y α ) is given by The linear functional L y then gives integration of polynomials with respect to µ: for any p ∈ R[x], For each k ∈ N, the moment matrix M k (y) ∈ Mat s(k) (R) of µ is then the symmetric matrix with rows and columns indexed by N d k (i.e. by the canonical basis for R[x] k ) defined by: for any α, β ∈ N d k , Moreover, given a polynomial p ∈ R[x], the localising matrix M k (py) ∈ Mat s(k) (R) is defined by: for all α, β ∈ N d k , Note that moment matrices are positive semidefinite (see Appendix C).
A polynomial p is a sums-of-squares (SOS) polynomial if there exist polynomials {q i } such that p = ∑ i q 2 i .SOS polynomials are widely used in convex optimisation.We will denote by Σ 2 R[x] ⊂ R[x] the set of SOS polynomials, and the set of SOS polynomials of degree at most 2k Finally, the quadratic module Q((q j )) ∈ R[x] generated by a sequence of polynomials (q j ) j∈{1,...,m} is defined as Q((q j )) Assumptions.In what follows, we will operate under the assumption that the set of global sections of the event sheaf O X is a compact basic semi-algebraic set, i.e. that it can be described by polynomial inequalities: O X = x ∈ R d | ∀ j = 1, . . ., m. . .p j (x) ≥ 0 for some polynomials p j ∈ R[x] for which we will write r j := deg(p j ) 2 . We will also assume that there exists an a ∈ R such that the quadratic polynomial x → a 2 − x 2 belongs to the quadratic module Q((p j )).This amounts to requiring that the set O X be bounded.These are standard assumptions for semi-definite programming and in particular for Theorem 17 to hold.Note that both assumptions can be imposed on each set O x of outcomes for a single measurement, since these conditions are preserved by products.

Hierarchy of semidefinite relaxations for computing the noncontextual fraction
As a prerequisite, we first need to compute the sequences of moments associated with all measures derived from the empirical model.For C ∈ M , let y e,C = (y e,C α ) α∈N d be the sequence of all moments of e C .We will build a hierarchy of finite semidefinite programs (SP k ) which converge to the optimal solution of the primal (P), i.e. the noncontextual fraction.For a given k ∈ N, we only need to compute a finite number s(k) of moments.As k increases, the approximation becomes more precise and the hierarchy of SDPs provides a monotonically decreasing sequence of upper bounds on the noncontextual fraction that converges to its value.
We consider the following semidefinite programs in which y is interpreted as corresponding to the moment sequence of a measure µ These problems are dual (see Appendix E).We will denote the optimal values of these programs by sup (SP k ) and inf (SD k ), respectively.Theorem 16.The optimal values of the hierarchy of semidefinite programs (SD k ) provide monotonically decreasing upper bounds on the optimal solution of the linear program (D) that converge to its value NCF(e).That is, Proof.We want to show that we can approximate the problem (D) to arbitrary precision by the problem (SD k ) by choosing k sufficiently large.We first use the Stone-Weierstrass theorem to approximate the continuous functions that appear in (D) by polynomials.Then, because of the positivity constraints and the additional assumption on closure of quadratic modules, we can use the SOS based representation (see theorem 17 in Appendix D) to rewrite these polynomials as SOS polynomials.We can thus approximate (D) by (SD k ) to arbitrary precision.It holds that (inf (SD k )) k∈N decreases monotonically because for all k ∈ N, (SD k ) is included in (SD k+1 ).
Because (SD k ) is a relaxation of (D) and because problems (SP k ) and (SD k ) are dual, we have, respectively: Thus, Theorem 16 also holds for the primal SDP.

Outlook
Logical forms of contextuality, which are present at the level of the possibilistic rather than probabilistic information contained in an empirical model, remain to be considered (e.g.[38,8,2,57]).In the discrete setting, these can be treated by analysing 'possibilistic' empirical models obtained by considering the supports of the discrete-variable probability distributions [8], which indicate the elements of an outcome space that occur with non-zero probability.In general, the notion of support of a measure is not as straightforward, and the naïve approach is not viable since typically all singletons have measure 0. Nevertheless, supports can be defined in the setting of Borel measurable spaces, for instance, which in any case are the kind of spaces in which we are practically interested, in Sections 5 and 6.
Approaches to contextuality that characterise obstructions to global sections using cohomology have had some success [11,5,27,28,66,68,60,29,61] and typically apply to logical forms of contextuality.An interesting prospect is to explore how the present framework may be employed to these ends, and to see whether the continuous-variable setting can open the door to new techniques that can be applied, or whether qualitatively new forms of contextual behaviour may be uncovered.A related direction to be developed is to understand how our treatment of contextuality can be further extended to continuous measurement spaces as proposed in [30].
Another direction to be explored is how our continuous-variable framework for contextuality can be extended to apply to more general notions of contextuality that relate not only to measurement contexts but also more broadly to contexts of preparations and transformations as well [72,58], noting that these also admit quantifiable relationships to quantum advantage [58,41].
Indeed, a major motivation to study contextuality is for its connections to quantum-over-classical advantages in informatic tasks.An important line of questioning is to ask what further connections can be found in the continuousvariable setting, and whether continuous-variable contextuality might offer advantages that outstrip those achievable with discrete-variable contextual resources.Note that it is known that infinite-dimensional quantum systems can offer certain additional advantages beyond finite-dimensional ones [71], though the empirical model that arises in that example is still a discrete-variable one in our sense.
The present work sets the theoretical basis for computational exploration of continuous-variable contextuality in quantum-mechanical empirical models.This, we hope, can provide new insights and inform all other avenues to be developed in future work.It can also be useful in verifying the non-classicality of empirical models.Numerical implementation of the programs of Section 6 is of particular interest.The hierarchy of semi-definite programs can be used numerically to witness contextuality in continuous-variable experiments.Even if the time-complexity of the semidefinite program may increase drastically with its degree, a low-degree program can already provide a first witness of contextual behaviour.
Since our framework for continuous-variable contextuality is independent of quantum theory itself, it can equally be applied to 'empirical models' that arise in other, non-physical settings.The discrete-variable framework of [8] has led to a number of surprising connections and cross-fertilisations with other fields [3], including natural language [12], relational databases [1,16], logic [10,5,49], constraint satisfaction [9,7] and social systems [34].It may be hoped that similar connections and applications can be found for the present framework to fields in which continuous-variable data is of central importance.For instance probability kernels of the kind we have used are also widely employed in machine learning (e.g.[43]), inviting intriguing questions about how our framework might be used or what advantages contextuality may confer in that setting.2020 Research and Innovation Programme under the Marie Skłodowska-Curie Grant Agreement No. 750523, 'Resource Sensitive Quantum Computing' (SM).

Appendices A Linear programs in standard form
This appendix may be of particular interest to readers familiar with global optimisation.We express the problem (P) in the standard form of infinite linear programming [17,].
We first write (P) with an equality constraint.Adding slack variables in the form of complementary measures ν C representing the contextual parts of the empirical model, we can express (P) as: Problems (P) (or (P C )) and (D) are indeed a infinite linear programs as both the objective and the constraints are linear with respect to the unknown measure µ ∈ M ± (O O O X ).To write (P C ) in the standard form [17], we introduce the following spaces: ), and also Ẽ1 := M ± (O O O X ) when considering the problem (P).
The dualities -, -1 : E 1 × F 1 −→ R and -, -2 : E 2 × F 2 −→ R are defined as follows: We also define A * : F 2 −→ F 1 as: We can verify that A * is the dual transformation of A: for all ω = (µ, (ν C ) C∈M ) ∈ E 1 and for all F = (( f C ) C∈M ) ∈ F 2 , we have We can now rewrite problem (P C ).The vector function in the objective is c = (1, 0) ∈ F 1 and we also choose to set b = ((e C ) C∈M ) ∈ E 2 for the constraints.The standard form in the sense of [17] can then be written as follows.One can note that the primal program amounts to optimising on Ẽ1 with an inequality constraint while the problem (P C ) amounts to optimising on E 1 with an equality constraint.From [17], the standard form of the dual of problem ( 14) can be expressed as follows.

B Proof of Proposition 15: zero duality gap
In this appendix we give a full proof of Proposition 15; i.e. that strong duality holds between problems (P) and (D).
Proof.To show strong duality, we rely on [17,Theorem 7.2].We define: E 1+ is a positive convex cone in E 1 .Since the linear program of ( 5) is consistent with finite value (because µ = 0 is feasible for (A)), it suffices to show that the following cone is weakly closed in E 2 ⊕ R (i.e.closed in the weak topology of E 1+ ).We first notice that A is a bounded linear operator.Boundedness comes from the fact that, for all ω = (µ, (ν where we take the following norm on finite Borel measures over a measurable space X X X = X, F : Secondly, we consider a sequence (ω k ) k∈N = (µ k , (ν k C ) C ) k∈N in E 1+ and we want to show that the accumulation point ((Θ C ) C , λ ) = lim k→∞ A(ω k ), ω k , c 1 belongs to K , where Θ ∈ E 2 and λ ∈ R. The sequence (Ω k ) k is bounded because A(ω k ) = (µ| k C + ν k C ) C −→ (Θ C ) C as k → ∞.Next, by weak- * compactness of the unit ball (Alaoglu's theorem [53]), there exists a subsequence (ω k i ) k i that converges weakly to an element ω ∈ E 1+ .By continuity of A, it yields that the accumulation point is such that ((Θ C ) C , λ ) = (A(ω), ω, c 1 ) ∈ K .

C Moment matrices are positive semi-definite
For well-defined moment sequences, i.e. sequences that have a representing finite Borel measure, moment matrices are indeed positive semi-definite which provides insight on the reason why problem (P) features positive semi-definiteness constraints.
Let y = (y α ) the moment sequence of a given Borel measure µ on O O O X (and similarly by marginalisation on every O O O C for C ∈ M ).For a given integer k, we construct the moment matrice M k (y).Then for any vector V ∈ R s(k) (noting that V is canonically associated with a polynomial v ∈ R[x] k with its basis (x α )): Thus M k (y) 0 and similarly we can prove that the matrices (M k (P j y)) j=1...m are positive semi-definite.Indeed, it holds that, for all V ∈ R s (k) and for all j = 1 . . .m, V T M k (P j y)V = O X v 2 (x)P j (x) d µ ≥ 0 , (17) since O X = {x ∈ R n | P j (x) ≥ 0, j = 1, . . ., m}.

D Useful results on SOS polynomials
The following theorem is used to prove the convergence of the optimal values of (SD k ) to the noncontextual fraction.
Theorem 18.A polynomial p belongs to Σ 2 R[x] 2k if and only if there exists a positive semidefinite matrix Q ∈ M s(k) (R) such that p(x) = z(x)Qz(x) T for x ∈ R 2k , where z(x) ∈ R s(k) is the vector of monomials of degree at most s(k) R[x] k (z(x) α = x α ).

E Duality between (SP k ) and (SD k )
This appendix deals with the proof of duality between the semidefinite programs (SP k ) and (SD k ).

Figure 1 :
Figure 1: [Left] operational depiction of a typical bipartite experimental scenario.[Right]Hypothetical probability density plots for empirical data arising from such an experiment.Cf. the discrete-variable probability tables of[57,55].

2 .
An empirical model on a measurement scenario X, M , O O O is a compatible family for the presheaf P • E on the cover M .Concretely, it is a family e = {e C } C∈M , where e C is a probability measure on the space E (C) = O O O C for each maximal context C ∈ M , which satisfies the compatibility condition: e C | C∩C = e C | C∩C .
) as defining a function k from Λ to the set of empirical models over X, M , O O O .The function assigns to each λ ∈ Λ the empirical model k(λ ) := (k(λ ) C ) C∈M , where the correspondence with the definition above is via k(λ ) C = k C (λ , -).This function must be 'measurable' in Λ Λ Λ in the sense that k(-) C (B) : Λ −→ [0, 1] is a measurable function for all C ∈ M and B ∈ F C .Definition 6.Let X, M , O O O be a measurement scenario and Λ Λ Λ, p, k be a hidden-variable model.Then the corresponding empirical model e is given by of indicator function, Eq. (1) } µ| C (E) = { µ extends the empirical model e } e C (E) .

( 2 )
⇒ (3).It is enough to show that if a hidden-variable model Λ Λ Λ, p, k is deterministic then it is also factorisable.For this, it is sufficient to notice that a Dirac measureδ o with o ∈ O C on a product space O O O C = ∏ x∈C O O O x factorises as the product of Dirac measures δ o = ∏ x∈C δ o| {x} = ∏ x∈C δ o(x)(3) ⇒ (1).Suppose that e is realised by a factorisable hidden-variable model Λ Λ Λ, p, k .Write k x for k C | {x} as in the definition of factorisability.Define µ on O O O X as follows: for any family of measurable sets (E x ∈ F x ) x∈X , the value of µ on the corresponding rectangle is given by µ

Definition 11 .
Let e be an empirical model on the scenario X, M , O O O .The noncontextual fraction of e, written NCF(e), is defined as sup {µ(O X ) | µ ∈ M(O O O X ), ∀C ∈ M . . .µ| C ≤ e C } .Note that since e C ∈ P(O O O C ) for all C ∈ M it follows that NCF(e) ∈ [0, 1].The contextual fraction of e, written CF(e), is given by CF(e) := 1 − NCF(e).
(β C ) C∈M is a family of continuous functions β C ∈ C 0 (O C , R), one for the outcome space of each context.The program maximises, subject to constraints, the combined value obtained by integrating these functionals context-wise against the empirical model in question.The first set of constraints ensures that, for noncontextual empirical models, the value of the program will be at most 0, since any such model extends to a measure µ on O O O X such that µ(O X ) = 1.The final set of constraints act as a normalisation condition on the value of the program, ensuring that it takes values in the interval [0, 1] for any empirical model.Any family of functions β satisfying the constraints will thus result in what can be regarded as a generalised Bell inequality, ∑ C∈M O C β C d e C ≤ 0 , which is satisfied by all noncontextual empirical models.Definition 13.A generalised Bell inequality (β , R) on a measurement scenario X, M , O O O is a family β = (β C ) C∈M with β C ∈ C 0 (O C , R) for all C ∈ M , together with a bound R ∈ R, such that for all noncontextual empirical models e on X, M , O O O it holds that β , e 2 := ∑ C∈M O C β C d e C ≤ R. The normalised violation of a generalised Bell inequality (β , R) by an empirical model e is max{0, β , e 2 }/( β −R) where β

) C∈M ∈F 2 ∑
C∈M O C f C d e C , while the constraints A * (F) ≥ c and F ≥ 0 can be expressed as ∑ C∈M f C ≥ 1 on O X , and f C ≥ 0 on O C for all C ∈ M .This is exactly problem (D).