---
abstract: 'Contextuality has been identified as a potential resource responsible for the quantum advantage in several tasks. It is then necessary to develop a resource-theoretic framework for contextuality, both in its standard and generalized forms. Here we provide a formal resource-theoretic approach for generalized contextuality based on a physically motivated set of free operations with an explicit parametrization. Then, using an efficient linear programming characterization for the noncontextual set of prepared-and-measured statistics, we adapt known resource quantifiers for contextuality and nonlocality to obtain natural monotones for generalized contextuality in arbitrary prepare-and-measure experiments.'
author:
- Cristhiano Duarte
- Barbara Amaral
bibliography:
- 'biblio2.bib'
title: 'Resource theory of contextuality for arbitrary prepare-and-measure experiments'
---

Introduction
============

Prepare-and-measure experiments provide simple situations in which the differences between classical and nonclassical probabilistic theories can be explored. One such difference is related to the generalized notion of noncontextuality, a condition imposed on ontological models that asserts that operationally indistinguishable laboratory operations should be represented identically in the model [@RS05; @SSW17; @MPKRS16; @RK17]. Inconsistencies between observed data and the existence of such a model can be understood as a signature of nonclassicality.

Besides its importance for foundations of physics [@Specker60; @KS67; @RS05], noncontextuality has been identified as a potential resource responsible for the quantum advantage in several tasks [@VFGE12; @Raussendorf13; @UZZWYDDK13; @HWVE14; @DGBR14; @BDBOR17; @SS17; @SHP17]. Hence, it is important to investigate contextuality in arbitrary prepare-and-measure experiments from the perspective of resource theories, which give powerful frameworks for the formal treatment of a physical property as an operational resource [@SOT16; @BG15; @CMH16; @TF17; @CFS16; @ACTA17; @GL15; @BHORS13].

It is commonly understood, see Refs. [@BG15; @ACTA17; @TF17; @CFS16] for instance, that such theories consist in the specification of three main components: $i)$ a class ${\mathcal{O}}$ of *objects*, that represent those entities one aims to manipulate seeking for some gain or benefit, and that may possess the resource under consideration; $ii)$ a special class ${\mathcal{F}}$ of transformations, called the *free operations*, that fulfills the essential requirement of mapping every resourceless object of the theory into another resourceles object, *i.e.* a set of transformations that does not create a new resource from a resourceless object; and $iii)$ a *measure* or a *quantifier* that outputs the amount of resource a given object contains. For consistency, the fundamental requirement for a function to be a valid quantifier is that of being a monotone with respect to the considered resource: every quantifier is non-increasing under the corresponding free operations.

Resource-theoretic approaches for quantum nonlocality are highly developed [@Barrett05b; @Allcock09; @GWAN12; @Joshi13; @Vicente14; @LVN14; @GA15; @GA17] and the operational framework of the standard notion of contextuality as a resource has received much attention lately [@HGJKL15; @GHHHHJKW14; @ACTA17; @ABM17]. Nonetheless, a proper treatment for the generalized framework of prepare-and-measure experiments considered in Refs. [@RS05; @SSW17; @MPKRS16; @RK17] as a resource is still missing. Here, using the novel generalized-noncontextual polytope, an efficient linear programming [@LexSchrivjer99] characterization for the contextual set of prepared-and-measured statistics presented in Ref. [@SSW17], we present a mathematically well structured resource-theoretic approach for generalized contextuality based on a physically motivated set of free operations with an explicit parametrization. We then adapt known resource quantifiers for contextuality and nonlocality [@Barrett05b; @Allcock09; @GWAN12; @Joshi13; @Vicente14; @LVN14; @GHHHHJKW14; @GA15; @HGJKL15; @GA17; @ACTA17; @BAC17; @ABM17] to obtain natural monotones for generalized contextuality in arbitrary prepare-and-measure experiments.

This work is organized as follows: in Sec. \[sec: GenContextuality\] we review the definition of generalized non-contextuality and the linear programming characterization of the noncontextual set; in Sec. \[sec:RTofContextuality\] we introduce the three important components of the resource theory: in Subsec. \[subsec:Objects\] we define the objects of the theory, in Subsec. \[subsec:FreeOperations\] we provide a set of physically motivated free operations for generalized contextuality in prepare-and-measure experiments, and in Subsec. \[subsec:Quantifiers\] we list several contextuality quantifiers and we explicitly prove that they are monotones with respect to the set of free operations defined in Subsec. \[subsec:FreeOperations\]; we finish with discussion and open questions in Sec. \[sec:conc\].

Generalized Contextuality {#sec: GenContextuality}
=========================

A glimpse on the theory {#sec:glimpse}
-----------------------

We consider a prepare-and-measure experiment with a set of possible preparations $\mathcal{P}=\left\{P_1,P_2, \cdots , P_I\right\}$, a set of possible measurements $\mathcal{M}=\left\{M_1,M_2, \cdots , 
M_J\right\}$, each measurement with possible outcomes $\mathcal{D}=\left\{d_1, d_2, \ldots, d_K\right\}$. An operational probabilistic theory that describe this prepare-and-measure experiment specifies, for each measurement $M_j$, a probability distribution $p(k\vert j,i)$ over $\mathcal{D}$ wich specifies the probability of obtaining outcome $d_k$ when performing measurement $M_j$, conditioned on the preparation $P_i$. We denote the measurement event of measuring $M_j$ and obtaining outcome $d_k$ as $k \vert j$.

Two preparations $P_i$ and $P_{i'}$ are *operationally equivalent* if p(kj,i)= p(kj,i’)  d\_k, M\_j .

In other words, $P_i$ and $P_{i'}$ are said to be operationally equivalent if they give the same statistics for every measurement. Operational equivalence between $P_i$ and $P_{i'}$ will be denoted by $P_i \simeq P_{i'}$.

Two measurement events $k\vert j$ and $k'\vert j'$ are *operationally equivalent* if p(kj,i)= p(k’j’,i)  P\_i .

In other words, $k\vert j$ and $k'\vert j'$ are said to be operationally equivalent whenever they have the same statistics for every preparation in $\mathcal{P}$. Operational equivalence between $k\vert j$ and $k' \vert j'$ will be denoted by $k\vert j \simeq k'\vert j'$.

We then specify a set $\mathcal{E}_P$ of operational equivalences for the preparations \_i \_i\^sP\_i \_i \_i\^sP\_i,  s=1, …, |\_P|where $\sum_i \alpha_i^sP_i$ and $\sum_i \beta_i^sP_i$ represent convex combinations of the preparations $P_i$, and a set $\mathcal{E}_M$ of operational equivalences for the measurement effects \_[k,j]{} \_[kj]{}\^r\_[k,j]{} \_[kj]{}\^r,  r=1, …, |\_M|where $\sum_{k,j} \alpha_{k\vert j}^r\left[k\vert j\right]$ and $\sum_{k,j} \beta_{k\vert j}^r\left[k\vert j\right]$ represent convex combinations of measurement events.

A *prepare-and measure scenario* {, , , \_P, \_M}consists of a set of preparations $\mathcal{P}$, a set of measurements $\mathcal{M}$, a set of outcomes $\mathcal{D}$, a set of operational equivalences for the preparations $\mathcal{E}_P$ and a set of operational equivalences for the measurements $\mathcal{E}_M$. A prepare-and-measure statistics (more commonly known as behaviours or black-box correlations [@BCPSW13; @NGHA15; @Slofstra17]) is a set of conditional probability distributions $$\label{def:behaviour}
\boldsymbol{B} \coloneqq \left\{p\left(k \vert 
j,i\right)\right\}_{j \in [J], i \in [I], k \in [K]}$$ that give the probability of outcome $d_k$ for each measurement $M_j$ given the preparation $P_i$.

A schematic representation of a prepare-and-measure scenario is shown in Fig. \[Figure\_prepare\_and\_measure\].

![ \[Figure\_prepare\_and\_measure\]](Figure_prepare_and_measure.pdf)

### Ontological models

An *ontological model* for a prepare-and-measure statistics $B=\left\{p\left(k\vert j,i\right)\right\}$ is a specification of a set of *ontic states* $\Lambda$, for each preparation $P_i$ a probability space $\left(\Lambda, \Sigma, \mu_i\right)$ and for each $\lambda \in \Lambda$ and each $M_j \in \mathcal{M}$ a probability distribution $\left\{\xi_{k\vert j}\left(\lambda\right)\right\}$ over $\mathcal{D}$, such that p(kj,i) = \_[ ]{} \_[k j]{}()\_i().\[eq:model\]

![ \[Figure\_geometrical\_meaning\]](Figure_geometrical_meaning.pdf)

The interpretation of an ontological model is shown in Fig. \[Figure\_geometrical\_meaning\]. The ontic state $\lambda$ is understood as a variable that describes the behavior of the system that may not be accessible experimentally. If preparation $P_i$ is implemented, the ontic state $\lambda$ is sampled according to the associated probability distribution $\mu_{i}$. On the other hand, given $\lambda$, for every measurement $M_j$ the outcome $d_k$ is a probabilistic function of $\lambda$, described by the response functions $\xi_{k\vert 
j}\left(\lambda\right)$. The variable $\lambda$ mediates the correlations between measurements and preparations. From the perspective of causal models [@Pearl00], Eq. implies that the prepare-and-measure statistics is consistent with the causal structure shown in Fig. \[fig:causal\].

(4,1) – (4,-0.65); (4,-1) – (6.65,-1); (7,1) – (7,-0.65); (4,1) circle (10pt); (4,1) node [$i$]{}; (7,1) circle (10pt); (7,1) node [$j$]{}; (4,-1) circle (10pt); (4,-1) node [$\lambda$]{}; (7,-1) circle (10pt); (7,-1) node [$k$]{};

### Noncontextual models

The generalized notion of noncontextuality introduced in Ref. [@RS05] requires that preparations and measurement events that can not be distinguished operationally are identically represented in the model. This implies that the operational equivalences valid for $\mathcal{P}$ and $\mathcal{M}$ should also be valid for the functions $\mu_i$ and $\xi_{k\vert j}$, respectively. In terms of the previous definitions, we have:

An ontological model satisfies *preparation noncontextuality* if $\mu_{i}=\mu_{i'}$ whenever $P_i$ and $P_{i'}$ are operationally equivalent. An ontological model satisfies *measurement noncontextuality* if $\xi_{k\vert j}=\xi_{k' \vert j'}$ whenever $k\vert j$ and $k'\vert j'$ are operationally equivalent. An ontological model is *universally noncontextual*, or simply *noncontextual*, if it satisfies both preparation and measurement noncontextuality.

The non-existence of a noncontextual ontological model for the prepare-and-measure statistics $B$ can be interpreted as signature of the nonclassicality of $B$. It is a known fact that some prepare-and-measure statistics obtained with quantum systems do not admit a noncontextual ontological model [@RS05].

The prepare-and-measure statistics $B$ is called *noncontextual* if it has an noncontextual ontological model. The set of all noncontextual prepare-and-measure statistics for the scenario $\mathcal{S}$ will be denoted by $\mathsf{NC}\left(\mathcal{S}\right).$

Linear Characterization {#sec:linear_characterization}
-----------------------

It was shown in Ref. [@SSW17] that if a prepare-and-measure statistics $B$ has a noncontextual ontological model, then it also has a noncontextual ontological model with an ontic state space $\Lambda$ of finite cardinality. This implies that membership in $\mathsf{NC}\left(\mathcal{S}\right)$ can be formulated in terms of linear programming.

Given a ontic state $\lambda$, the value of the response functions $\xi_{k\vert j}$ can be represented in a vector ()(\_[11]{}(), …, \_[K1]{}(), …\_[1J]{}(), …, \_[KJ]{}() )

For fixed $\lambda \in \Lambda$, the vectors $\boldsymbol{\xi}\left(\lambda\right)$ defined by different choices of response functions $\xi_{m\vert M}$ satisfying measurement noncontextuality are called *noncontextual measurement assignments*. The set of all noncontextual measurement assignments is a called the *noncontextual measurement-assignment polytope*.

As shown in Ref. [@SSW17], fixed $\lambda \in \Lambda$, the set of all noncontextual measurement assignments is indeed a polytope since it is characterized by the following linear restrictions: $$\begin{aligned}
 \xi_{k\vert j}\left(\lambda\right)&\geq 0\\
 \sum_k \xi_{k\vert j}\left(\lambda\right)&=1\\
 \sum_{k,j}\left(\alpha_{k\vert j}^r -\beta_{k\vert j}^r\right)\xi_{k\vert 
j}\left(\lambda\right)&=0.\end{aligned}$$ Notice that since these constraints do not depend on $\lambda$, the noncontextual measurement-assignment polytope is the same for every $\lambda$. We denote by $\tilde{\boldsymbol{\xi}}\left(\kappa\right)$ the extremal points of this polytope, with $\kappa$ a discrete variable ranging over some enumeration of these extremal points.

A prepare-and-measure statistics $B=\left\{p\left(k\vert 
j,i\right)\right\}$ in the scenario $\mathcal{S}$ has a noncontextual ontological model if, and only if, there is a set of probability distributions $\left\{\mu_i\left(\kappa\right)\right\}$ over $\kappa$ such that $$\begin{aligned}
\sum_i\left(\alpha^s_i - \beta^s_i\right)\mu_i\left(\kappa\right)&=0     \\
\sum_{\kappa} \tilde{\xi}_{k\vert j}\left(\kappa\right)\mu_i\left(\kappa\right)&=p\left(k\vert j,i\right),\end{aligned}$$ where $\kappa$ ranges over the discrete set of vertices of the measurement-assignment polytope.

This proposition implies that membership in $\mathsf{NC}\left(\mathcal{S}\right)$ can be efficiently tested using linear programming, which in turn implies that some of the quantifiers proposed in Sec.\[subsec:Quantifiers\] can also be computed efficiently using linear programming.

Resource Theory of Generalized Contextuality {#sec:RTofContextuality}
============================================

Objects {#subsec:Objects}
-------

We define the set ${\mathcal{O}}$ of *objects* as the collection of all allowed prepare-and-measure statistics: $$\boldsymbol{B} = \left\{p\left(k \vert 
j,i\right)\right\}_{j \in J, i \in I, k \in K}$$ for a prepare-and-measure scenario $\mathcal{S}$. The *free objects*, or *resourceles* ones, correspond to those behaviors $\boldsymbol{B}\in \mathsf{NC}\left(\mathcal{S}\right)$ with a universally noncontextual model.

Given two objects $\boldsymbol{B}_{1}$ and $\boldsymbol{B}_{2}$ we also allow for a combination of them in order to obtain a third new object, denoted by $\boldsymbol{B}_{1} \otimes \boldsymbol{B}_{2}$. One may think of this such an object $\boldsymbol{B}_{1} \otimes \boldsymbol{B}_{2}$ as representing full access to both $\boldsymbol{B}_{1}$ and $\boldsymbol{B}_{2}$ together and at the same time. For our purposes it will be enough to consider that combination as the juxtaposition of two independent behaviours:

Given two behavior $B_1$ and $B_2$ (not necessarily in the same scenario), the juxtaposition of $B_1$ and $B_2$, denoted by $B_1 \otimes B_2$, is the behavior obtained by independently choosing preparation and measurement for $B_1$ and $B_2$. That is, the preparations in $B_1\otimes B_2$ correspond to a pair of preparations, $i_1$ for $B_1$ and $i_2$ for $B_2$ and analogously for the measurements. The corresponding probability distributions are given by p(k\_1k\_2j\_1j\_2, i\_1i\_2)=p(k\_1j\_1, i\_1)p(k\_2j\_2, i\_2).

As expected, the juxtaposition of two noncontextual behaviors is a noncontextual behavior.

If $B_1$ and $B_2$ are noncontextual if and only if $B_1 \otimes B_2$ is noncontextual.

Let $\left(\Lambda_1, \Sigma_1, \mu_{i_1}\right)$ and $\left\{\xi_{k_1\vert j_1} 
\right\}$ be an ontological model for $B_1$ and $\left(\Lambda_2, \Sigma_2, \mu_{i_2}\right)$ and $\left\{\xi_{k_2\vert j_2}\right\}$ be an ontological model for $B_2$. Then $\left(\Lambda_1 \times \Lambda_2, \Sigma_1 \times \Sigma_2, \mu_{i_1}\times 
\mu_{i_2}\right)$ and $\left\{\xi_{k_1\vert j_1}\times \xi_{k_2\vert j_2} \right\}$ is an ontological model for $B_1 \otimes B_2$. Conversely, if an ontological model for $B_1 \otimes B_2$ is given, an ontological model for $B_1$ can be obtained by marginalizing over $B_2$ and an ontological model for $B_2$ can be obtained by marginalizing over $B_1$.

Free Operations {#subsec:FreeOperations}
---------------

Given a prepare-and-measure scenario ${\mathcal{S}}$, we define the set ${\mathcal{F}}$ of free operations in analogy with simulation of communication channels [@TF17]: the image $\boldsymbol{\tilde{B}}=T(\boldsymbol{B})$ of $B$ through every mapping $T:{\mathcal{O}} 
\longrightarrow {\mathcal{O}}$ in ${\mathcal{F}}$ should be viewed as a simulation of a new scenario using one preprocessing for the preparation box $\mathcal{P}$, another preprocessing for the measurement box $\mathcal{M}$, and for the last a post-processing for the outcomes $\mathcal{D}$ of each measurement $M_j$ (see Fig.\[Figure\_free\_operations\_boxes\]). More formally, each free operation is a map: $$\begin{aligned}
\label{def:free_operations}
T: {\mathcal{O}} &\longrightarrow {\mathcal{O}}  \\
          \{p(k \vert j,i)\} &\mapsto \{p({\tilde{k}} \vert 
\tilde{j},\tilde{i}) \} \nonumber\end{aligned}$$ where for each ${\tilde{k}} \in {\tilde{K}},{\tilde{i}} \in {\tilde{I}},{\tilde{j}} \in {\tilde{J}}$: $$\label{def:free_operations2}
 \sum_{k,j,i}q_{O}({\tilde{k}} \vert {k})p(k \vert j,i)q_{P}(i 
\vert {{\tilde{i}}})q_{M}(j \vert 
{{\tilde{j}}}),$$ with $q_{P}:\tilde{I} \longrightarrow I$, $q_{M}:\tilde{J} \longrightarrow J$, and $q_O: 
K \longrightarrow \tilde{K}$ stochastic maps [@NC00] from certain input alphabets to another sets of output alphabets. In what follows, the stochastic map $q_O$ can also depend on the measurement $\tilde{j}$, that is, different post-processing of the outcomes can be applied to different measurements. Hence, it would be more appropriate to write $q^{\tilde{j}}_O$, but we avoid the use of this heavy notation. Eq.  shows that, after a suitable relabeling of the indexes, the overall effect of each free operation is a right-multiplication of a stochastic matrix and a left-multiplication of another stochastic matrix on prepare-and-measure statistics $\{p(k \vert j,i)\}$, thus each $T$ in ${\mathcal{F}}$ acts as a linear map on the set of objects. We have proved, therefore, the following results:

![ \[Figure\_free\_operations\_boxes\]](Figure_free_operations_boxes.pdf)

\[lemma:T\_is\_convex\] Let ${\mathcal{F}}$ be the above defined set of free operations. Given $B,B^{\prime}$ two prepare-and-measure statistics in ${\mathcal{O}}$, and given $\pi \in [0,1]$, one has: \[lemma:eq\_T\_is\_convex\] T(B+(1-)B\^)=T(B)+(1-)T(B\^), where the sum and multiplication on ${\mathcal{O}}$ are defined component-wise.

The set ${\mathcal{F}}$ of free operations is closed under composition.

It remains to show that the transformations belonging to $\mathcal{F}$ really fulfill the requirement of being free operations, *i.e.* we must show that any element $T$ in ${\mathcal{F}}$ does not create a resource from a resourceless object – it preserves the set of non-contextual prepare-and-measure statistics. More formally:

Given a free operation $T \in {\mathcal{F}}$, and a [prepare-and-measure statistics ]{} $B=\{p(k \vert j,i)\}$, if $B$ admits a universally noncontextual model, then $\tilde{B}=T(B)$ also admits a universally noncontextual model.

Since $B$ admits a universally contextual model (w.r.t. to sets ${\mathcal{E}}_{M}$ and ${\mathcal{E}}_{P}$ of operational equivalences for measurements and preparations), there exist a family of probability spaces $\{\Lambda,\Sigma_{i},\mu_{i}\}_{i}$ one for each preparation $P_i$, and a set of response functions $\{\xi_{k \vert j}(\lambda)\}$ such that: $$\begin{aligned}
\label{eq:thm_T_preservesNC_noncontextualboxes_begin}
 \forall& \,\, \lambda, j, k: &\xi_{k \vert j}(\lambda) \geq 0;    \\
 \forall& \,\, \lambda,j: &\sum_{k \in K}\xi_{k \vert j}(\lambda)=1; \\
 \forall& \,\, \lambda,r: &\sum_{j \in J}\sum_{k \in 
K}\left(\alpha^{r}_{k \vert j} - \beta^{r}_{k \vert j}\right)\xi_{k \vert 
j}(\lambda)=0; \\
 \forall& \,\, \lambda, i: &\mu_{i}(\lambda) \geq 0; \\
 \forall& \,\, i: &\int_{\Lambda}\mu_{i}(\lambda)=1; \\
 \forall& \,\, \lambda,s: &\sum_{i \in I}\left(\alpha^{s}_{i} - \beta^{s}_{i}\right)\mu_{i}(\lambda)=0; \\
 \forall& \,\, i,j,k: &\int_{\Lambda}\xi_{k \vert 
j}(\lambda)\mu_{i}(\lambda) = p(k \vert j,i).
 \label{eq:thm_T_preservesNC_noncontextualboxes_end}\end{aligned}$$ Therefore: $$\begin{aligned}
 &{p(\tilde{k} \vert \tilde{j},\tilde{i})}: =T({p({k} \vert {j},{i})}) \\
         &= {\sum_{k,j,i}q_{O}(\tilde{k} \vert k)p(k \vert 
j,i)q_{P}(i \vert \tilde{i} \,\, )q_{M} (j \vert \tilde{j} \,\,)}\\
         &=\sum_{k,j,i}q_{O}(\tilde{k} \vert k)\left( \int_{\Lambda}\xi_{k 
\vert 
j}(\lambda)\mu_{i}(\lambda)\right)q_{P}(i 
\vert {\tilde{i}} \,\, )q_{M} (j \vert {\tilde{j}} \,\,) \\
         &=\int_{\Lambda}\underbrace{\left(\sum_{k,j}q_{O}({\tilde{k}} \vert 
k) \xi_{k \vert j}(\lambda)q_{M}(j \vert {\tilde{j}}) 
\right)}_{:=\xi_{{\tilde{k}} \vert {\tilde{j}}}(\lambda)} \underbrace{\left( 
\sum_{i}\mu_{i}(\lambda)q_{P}(i \vert {\tilde{i}})  
\right)}_{:=\mu_{{\tilde{i}}}(\lambda)} \\
         &= \int_{\Lambda}\xi_{{\tilde{k}} \vert 
{\tilde{j}}}(\lambda)\mu_{{\tilde{i}}}(\lambda).
 \end{aligned}$$ With these new set of response functions $\{\xi_{{\tilde{k}} \vert 
{\tilde{j}}}(\lambda)\}$ and probability measures $\{\mu_{{\tilde{i}}}\}$ over $\Lambda$, we are going to prove that $\tilde{B}$ admits a universally noncontextual model (w.r.t. the transformed operational equivalences). For clarity we break the remaining of the proof into three statements:

-   The family $\{\xi_{{\tilde{k}} \vert 
    {\tilde{j}}}(\lambda)\}$ constitute an admissible set of response functions. On one hand: $$\begin{aligned}
    \forall {\tilde{k}},{\tilde{j}},\lambda:& \\
     \xi_{{\tilde{k}} \vert 
    {\tilde{j}}}(\lambda)&:=\sum_{k,j}q_{O}({\tilde{k}} \vert 
    k) \xi_{k \vert j}(\lambda)q_{M}(j \vert {\tilde{j}}) \\
      &\geq 0.\end{aligned}$$ On the other hand (see Fig. \[Figure\_free\_operations\_boxes\_rhs\_composition\]), for all $\lambda$ belonging to $\Lambda$: $$\begin{aligned}
     \sum_{{\tilde{k}}}&\xi_{{\tilde{k}} \vert {\tilde{j}}}(\lambda) = 
    \sum_{{\tilde{k}}}\sum_{k,j}q_{O}({\tilde{k}} \vert 
    k) \xi_{k \vert j}(\lambda)q_{M}(j \vert {\tilde{j}}) \\
      &=\sum_{{\tilde{k}}}\sum_{j} \underbrace{\left[\sum_{k}q_{O}({\tilde{k}}\vert 
    k)\xi_{k \vert j}(\lambda) \right]}_{:=q_{\lambda}({\tilde{k}}\vert j)}q_{M}(j 
    \vert {\tilde{j}}) \\
      &= \sum_{{\tilde{k}}} \underbrace{\sum_{j}q_{\lambda}({\tilde{k}}\vert j)q_{M}(j 
    \vert {\tilde{j}})}_{:=q_{\lambda}({\tilde{k}} \vert {\tilde{j}})} = 
    \sum_{{\tilde{k}}}q_{\lambda}({\tilde{k}} \vert {\tilde{j}})=1.\end{aligned}$$

    ![ \[Figure\_free\_operations\_boxes\_rhs\_composition\]](Figure_free_operations_boxes_rhs_composition.pdf)

-   The family $\{\mu_{{\tilde{i}}}\}$ constitute a set of probability measures over $\Lambda$.

    It is clear from the definition that each $\mu_{{\tilde{i}}}$ is a non-negative function over $\Lambda$. In addition, for each ${\tilde{i}} \in {\tilde{I}}$, one has: $$\begin{aligned}
     \int_{\lambda}\mu_{{\tilde{i}}}(\lambda)&=\int_{\Lambda} \sum_{i}q_{P}(i \vert 
    {\tilde{i}})\mu_{i}(\lambda) \\
               &=\sum_{i}q_{P}(i \vert {\tilde{i}}) 
    \underbrace{\int_{\lambda}\mu_{i}(\lambda)}_{=1} \\
               &=\sum_{i}q_{P}(i \vert {\tilde{i}})  =1.\end{aligned}$$

-   The operational equivalences ${\mathcal{E}}_{P}$ and ${\mathcal{E}}_{M}$ are lifted, through the action of free operations in ${\mathcal{F}}$, onto other sets of operational equivalences ${\mathcal{E}}_{{\tilde{P}}}$ and ${\mathcal{E}}_{{\tilde{M}}}$ which in turn also respect the principle of preparation noncontextuality and measurement noncontextulity [@RS05; @SSW17] respectively.

    We prove the result for operational equivalences among preparations, and the result will follow in complete analogy for operational equivalences among measurements. Given one operational equivalence among preparations for the ordinary prepare-and-measure scenario, labelled by $s$, *i.e.* an equality $$\begin{aligned}
      &\sum_{i \in I}\left(\alpha^{s}_{i} - \beta^{s}_{i}\right)\mu_{i}(\lambda)=0, \forall 
    \,\, \lambda \in \Lambda,\end{aligned}$$ we define novel set of coefficients $\{\alpha^{s}_{{\tilde{i}}}\}_{{\tilde{i}} \in 
    {\tilde{I}}}$ and $\{\beta^{s}_{{\tilde{i}}}\}_{{\tilde{i}} \in 
    {\tilde{I}}}$ satisfying $$\begin{aligned}
    \label{eq:proof_equivalences_td_alpha}
     \forall \,\, i \in [I]: \sum_{{\tilde{i}}}\alpha^{s}_{{\tilde{i}}}q_{P}(i \vert 
    {\tilde{i}})=\alpha^{s}_{i},\end{aligned}$$ and $$\begin{aligned}
    \label{eq:proof_equivalences_td_beta}
     \forall \,\, i \in [I]: \sum_{{\tilde{i}}}\beta^{s}_{{\tilde{i}}}q_{P}(i \vert 
    {\tilde{i}})=\beta^{s}_{i}.\end{aligned}$$ Now, if one defines the new set of operational equivalences for preparations ${\mathcal{E}}_{{\tilde{P}}}$ using Eqs.  and , it is straightforward to check that $$\forall \,\, s, \lambda: 
    \sum_{{\tilde{i}}}\alpha^{s}_{{\tilde{i}}}\mu_{{\tilde{i}}}(\lambda)= 
    \sum_{{\tilde{i}}}\beta^{s}_{{\tilde{i}}}\mu_{{\tilde{i}}}(\lambda),$$ since these novel operational equivalences come from a lift of operational equivalences which are noncontextual in the ordinary (non-)transformed scenario.

Monotones {#subsec:Quantifiers}
---------

Now that we have defined the sets of objects and free operations, we are in position to verify if the monotones introduced in Refs. [@Barrett05b; @Allcock09; @GWAN12; @Joshi13; @Vicente14; @LVN14; @GHHHHJKW14; @GA15; @HGJKL15; @GA17; @ACTA17; @BAC17; @ABM17] can be adapted to the framework of generalized contextuality.

### Contextual Fraction {#subsubsec:ConetxtualFract}

The *contexual fraction* is a contextuality quantifier based on the intuitive notion of what fraction of a given prepare-and-measure statistics admits a noncontextual description. Formally it is defined as follows [@AB11; @ADLPBC12; @ABM17; @AT17]: $$\begin{aligned}
{\mathcal{C}}: {\mathcal{O}} &\longrightarrow [0,1] \\ \nonumber
       B=\{p(k \vert j,i)\}   & \mapsto {\mathcal{C}}(B)\end{aligned}$$ where $$\begin{aligned}
1-{\mathcal{C}}(B):= \mbox{max } \lambda \nonumber  \\
\qquad \textup{s.t.}\quad &B=\lambda B^{NC}+(1-\lambda)B^{\prime} 
\nonumber\\
& B^{NC} \in \mathsf{NC}\left(\mathcal{S}\right)  \nonumber \\
& B^{\prime}  \in {\mathcal{O}}.  \label{def:cf2}\end{aligned}$$

\[thm:cf\_is\_monotone\] The contextual-fraction is a resource monotone with respect to ${\mathcal{F}}$.

Let $B \in {\mathcal{O}}$ be a given prepare-and-measure statistics, and let ${\mathcal{C}}(B)$ be equal to $\lambda_{\max}$ with the following decomposition: $$B=\lambda_{\max}B^{NC}_{\max}+(1-\lambda_{\max})B^{\prime}_{\max}.$$ Then: $$\begin{aligned}
T(B)&=T(\lambda_{\max}B^{NC}_{\max}+(1-\lambda_{\max})B^{\prime}_{\max}) \\
&=\lambda_{\max}T(B^{NC}_{\max})+(1-\lambda_{\max})T(B^{\prime}_{\max}) \\
&= \lambda_{\max}B^{NC}+(1-\lambda_{\max})B^{\prime}.\end{aligned}$$ with $B^{NC}=T(B^{NC}_{\max})$ a noncontextual box, since $T$ preserves the noncontextual set, and $B^{\prime}$ a valid object. Then $\lambda_{\max(T(B))} \geq \lambda_{\max}$. Therefore: 1-(T(B)) 1-(B) (T(B)) (B).

The contextual fraction is subadditive under independent juxtapositions.

\[thm:cf\_ad\] Given two behaviors $B_1$ and $B_2$,we have that (B\_1 B\_2) (B\_1 )+ (B\_2)-(B\_1 )(B\_2) (B\_1 )+ (B\_2) .

Let $B_1^*$ and $B_2^*$ be the behaviors achieving the minimum in Eq. for $B_1$ and $B_2$, respectively, with $1-\mathcal{C}\left(B_1 \right)=\lambda_1$ and $1-\mathcal{C}\left(B_2 \right)=\lambda_2$. The decomposition in Eq. implies that $$\begin{aligned}
  p\left(k_1 \vert j_1,i_1\right) &\leq \lambda_1  p^*\left(k_1 \vert j_1,i_1\right), \ \forall \ i_1,j_1,k_1,\\
  p\left(k_2 \vert j_2,i_2\right) &\leq \lambda_1  p^*\left(k_2 \vert j_2,i_2\right), \ \forall \ i_2,j_2,k_2,
 \end{aligned}$$ which in turn imply that p(k\_1 k\_2 j\_1j\_2,i\_1i\_2) \_1\_2 p\^\*(k\_1 k\_2 j\_1j\_2,i\_1i\_2),   i\_1,j\_1,k\_1,i\_2,j\_2,k\_2,\[eq:cf\_ad\] where $p^*\left(k_1 k_2 \vert j_1j_2,i_1i_2\right)= p^*\left(k_1 \vert j_1,i_1\right)p^*\left(k_2 \vert j_2,i_2\right)$ are the probabilities given by $B_1^* \otimes B_2^*$. From Eq. if follows that there is a behavior $B'$ such that B\_1 B\_2 = \_1 \_2 B\_1\^\* B\_2\^\* + B’. Hence, we have $$\begin{aligned}
1-\mathcal{C}\left(B_1 \otimes B_2 \right)& \geq \lambda_1 \lambda_2\\
&= \left(1-\mathcal{C}\left(B_1\right)\right)\left(1-\mathcal{C}\left( B_2 \right)\right),\end{aligned}$$ which in turn implies the desired result.

### Robustness Measures

Robustness of contextuality is a quantifier based on the intuitive notion of how much noncontextual noise a given prepare-and-measure statistics can sustain before becoming noncontextual. Given a scenario ${\mathcal{S}}$ one defines the *robustness measure* [@ACTA17] as follows:

$$\begin{aligned}
 \label{def:eq_robustness}
 {\mathcal{R}}: {\mathcal{O}} &\longrightarrow [0,1] \\
              B  &\mapsto {\mathcal{R}}(B) \nonumber\end{aligned}$$

where $$\begin{aligned}
\label{def:eq_minimization_for_robustness}
{\mathcal{R}}(B):= \mbox{min } \lambda \nonumber  \\
 \textup{s.t.}\quad &(\lambda B^{NC}+(1-\lambda)B)\in \mathsf{NC}\left(\mathcal{S}\right)  \nonumber\\
                   & B^{NC} \in \mathsf{NC}\left(\mathcal{S}\right) .\end{aligned}$$

\[thm:robustness\_is\_monotone\] The robustness measure ${\mathcal{R}}$ is a resource monotone with respect to the free-operations in ${\mathcal{F}}$.

Given $B \in {\mathcal{O}}$, let $\lambda_{\min}$ be the minimum of the optimization problem above, in which \_B\^[NC]{}\_+(1-\_)B = B\^, with $B^{\ast}$ noncontextual. Then: $$\begin{aligned}
T(B^{\ast})&=T(\lambda_{\min}B^{NC}_{\min}+(1-\lambda_{\min})B) \\
           &=\lambda_{\min}T(B^{NC}_{\min})+(1-\lambda_{\min})T(B) \\
           &=\lambda_{\min}{\tilde{B}}^{NC}_{\min}+(1-\lambda_{\min})T(B).\end{aligned}$$ Since, $T$ preserves the noncontextual set, $T(B^{\ast})$ is noncontextual as well as ${\tilde{B}}^{NC}_{\min}$ and therefore $\lambda_{\min(T(B))}\leq 
\lambda_{\min}$.

The robustness is subadditive under independent juxtapositions.

Given two behaviors $B_1$ and $B_2$,we have that (B\_1 B\_2) (B\_1 )+ (B\_2)-(B\_1 )(B\_2) (B\_1 )+ (B\_2) .

The proof follows the same lines of the proof of Thm. \[thm:cf\_ad\].

The proof of Thm.\[thm:robustness\_is\_monotone\] above suggests that for a more restrictive class of free operations, one can relax the assumption present at the constraints of the optimization problem in. , and instead of optimizing over all [prepare-and-measure statistics ]{}which are noncontextual, we could fix a given reference noncontextual prepare-and-measure statistics, say $B_{ref}$, and then define the a new robustness measure with respect to that fixed prepare-and-measure statistics:

$$\begin{aligned}
 \label{def:eq_robustness_ref}
 {\mathcal{R}}_{ref}: {\mathcal{O}} &\longrightarrow [0,1] \\
              B  &\mapsto {\mathcal{R}}_{ref}(B) \nonumber\end{aligned}$$

where $$\begin{aligned}
\label{def:eq_minimization_for_robustness_ref}
{\mathcal{R}}_{ref}(B):= \mbox{min } \lambda \nonumber  \\
 \textup{s.t.}\quad &(\lambda B_{ref}+(1-\lambda)B) \in \mathsf{NC}\left(\mathcal{S}\right) .      \end{aligned}$$ This new measure is a monotone whenever $B_{ref}$ is preserved upon action of (a more restrictive subset of) free operations. With this on hands it is possible to enunciate the following result:

Let ${\mathcal{F}}_{ref} \subseteq {\mathcal{F}}$ be all free operations which preserves $B_{ref} \in {\mathcal{O}}$, *i.e.* \_[ref]{}:={T ; T(B\_[ref]{})=B\_[ref]{}}. Under this new set of free operations, ${\mathcal{R}}_{ref}$ is a resource monotone.

The proof follows the same lines as the proof of the proof of Thm.\[thm:robustness\_is\_monotone\].

Notice that the proofs of Thms. \[thm:cf\_is\_monotone\] and \[thm:robustness\_is\_monotone\] rely only on the fact that the operations in $\mathcal{F}$ are linear and preserve $\mathsf{NC}\left(\mathcal{S}\right)$. The results in Sec. \[sec: GenContextuality\] imply that ${\mathcal{C}}, {\mathcal{R}}$ and ${\mathcal{R}}_{ref}$ can be computed efficiently using linear programming [@SSW17].

Kullback-Liebler divergence
---------------------------

Given two probability distributions $p$ and $q$ in a sample space $\Omega$, the Kullback-Leiber divergence or relative entropy between $p$ and $q$ D\_[KL]{}(pq)= \_[i]{} p\_i()is a measure of the difference between the two probability distributions $p$ and $q$ [@KL51]. With this, one can define the relative entropy $D_{KL}\left(B\|B'\right)$ between two prepare-and-measure statistics $B=\left\{p\left(\cdot \vert j,i\right)\right\}$ and $B'=\left\{p'\left(\cdot \vert j,i\right)\right\}$ as the relative entropy between the output distributions obtained from $B$ and $B'$ for the optimal choice of preparation and measurement: D\_[KL]{}(BB’) \_[i,j]{} D\_[KL]{}(p(j,i)p(j,i)).This quantity measures the distinguishability of $B$ from $B'$. We can now define the relative entropy of contextuality [@DGG05; @GHHHHJKW14; @HGJKL15] (B)\_[B’()]{}D\_[KL]{}(BB’), \[eq:defKL\]which quantifies the distinguishability of $B$ from its closest, with respect to $D_{KL}$, noncontextual preapre-and-measure statistics.

The relative entropy of contextuality $\mathcal{KL}$ is a resource monotone with respect to ${\mathcal{F}}$.

Given $B \in \mathcal{O}$, let $B^*$ be the noncontextual prepare-and-measure statistics achieving the minimum in Eq. . Given $T \in \mathcal{F}$, we have

$$\begin{aligned}
  {\mathcal{KL}}\left(T\left(B\right)\right) &\leq  \max_{\tilde{i},\tilde{j}} D_{KL}\left(p\left(\cdot\vert \tilde{j},\tilde{i}\right) \| p^*\left(\cdot\vert \tilde{j},\tilde{i}\right)\right)\label{eq:KLmon1}\\
  & =  \max_{\tilde{i},\tilde{j}} \sum_{\tilde{k}} p\left(\tilde{k}\vert \tilde{j},\tilde{i}\right) \log\left[\frac{p\left(\tilde{k}\vert \tilde{j},\tilde{i}\right)}{p^*\left(\tilde{k}\vert \tilde{j},\tilde{i}\right)}\right]\label{eq:KLmon2}\\
& = \max_{\tilde{i},\tilde{j}} \sum_{\tilde{k}} \sum_{i,j,k}q_O\left(\tilde{k}\vert k\right)p\left(k\vert j,i\right) q_M\left(j\vert \tilde{j}\right)q_P\left(i\vert \tilde{i}\right)\log\left[\frac{\sum_{i,j,k}q_O\left(\tilde{k}\vert k\right)p\left(k\vert j,i\right) q_M\left(j\vert \tilde{j}\right)q_P\left(i\vert \tilde{i}\right)}{\sum_{i,j,k}q_O\left(\tilde{k}\vert k\right)p^*\left(k\vert j,i\right) q_M\left(j\vert \tilde{j}\right)q_P\left(i\vert \tilde{i}\right)}\right]\label{eq:KLmon3}\\
& \leq  \max_{\tilde{i},\tilde{j}} \sum_{\tilde{k}} \sum_{i,j,k} q_O\left(\tilde{k}\vert k\right)p\left(k\vert j,i\right) q_M\left(j\vert \tilde{j}\right)q_P\left(i\vert \tilde{i}\right)\log\left[\frac{p\left(k\vert j,i\right) }{p^*\left(k\vert j,i\right) }\right]\label{eq:KLmon4}\\
&=  \max_{\tilde{i},\tilde{j}}  \sum_{i,j,k} p\left(k\vert j,i\right) q_M\left(j\vert \tilde{j}\right)q_P\left(i\vert \tilde{i}\right)\log\left[\frac{p\left(k\vert j,i\right) }{p^*\left(k\vert j,i\right) }\right]\label{eq:KLmon5}\\
&= \max_{\tilde{i},\tilde{j}}  \sum_{i,j}q_M\left(j\vert \tilde{j}\right)q_P\left(i\vert \tilde{i}\right)  \left(\sum_k p\left(k\vert j,i\right) \log\left[\frac{p\left(k\vert j,i\right) }{p^*\left(k\vert j,i\right) }\right]\right)\label{eq:KLmon6}\\
&\leq \max_{i,j} \sum_k p\left(k\vert j,i\right) \log\left[\frac{p\left(k\vert j,i\right) }{p^*\left(k\vert j,i\right) }\right]\label{eq:KLmon7}\\
&=\mathcal{KL}\left(B\right).\end{aligned}$$

Eq.  follows form the definition of $\mathcal{KL}\left(T(B)\right)$ and the fact that $T\left(B^*\right) \in \mathsf{NC}\left(\mathcal{S}\right)$, Eq.  follows from the definition of $D_{KL}$, Eq.  follows from the definition of $T\in \mathcal{F}$, Eq.  follows from the log sum inequality, Eq.  follows from basic algebra, Eq.  follows from $\sum_{\tilde{k}} q_{O}\left(\tilde{k}\vert k\right)=1$ and Eq.  follows from the fact that the average is smaller than the largest value.

The relative entropy of contextuality is subadditive under independent juxtapositions.

Given two behaviors $B_1$ and $B_2$,we have that (B\_1 B\_2) (B\_1 )+ (B\_2).

Let $B_1^*$ and $B_2^*$ be behaviors achieving the minimum in Eq. for $B_1$ and $B_2$, respectively. Then, we have $$\begin{aligned}
  \mathcal{KL}\left(B_1 \otimes B_2\right)&\leq D_{KL}\left(B_1\otimes B_2\|B_1^*\otimes B_2^*\right) \label{eq:kl_ad1}\\
  &= \max_{i_1,i_2,j_1,j_2} \sum_{k_1,k_2} p\left(k_1k_2\vert j_1j_2, i_1i_2\right)\log\left(\frac{p\left(k_1k_2\vert j_1j_2, i_1i_2\right)}{p^*\left(k_1k_2\vert j_1j_2, i_1i_2\right)}\right)\label{eq:kl_ad2}\\
  &=\max_{i_1,i_2,j_1,j_2} \sum_{k_1,k_2} p\left(k_1\vert j_1, i_1\right)p\left(k_2\vert j_2, i_2\right)\log\left(\frac{p\left(k_1\vert j_1, i_1\right)p\left(k_2\vert j_2, i_2\right)}{p^*\left(k_1\vert j_1, i_1\right)p^*\left(k_2\vert j_2, i_2\right)}\right)\label{eq:kl_ad3}\\
 &= \max_{i_1,i_2,j_1,j_2} \left[\sum_{k_1}  p\left(k_1\vert j_1, 
i_1\right)\log\left(\frac{ p\left(k_1\vert j_1, i_1\right)}{ p^*\left(k_1\vert j_1, 
i_1\right)}\right) + \sum_{k_2} p\left(k_2\vert j_2, 
i_2\right)\log\left(\frac{p\left(k_2\vert j_2, i_2\right)}{p^*\left(k_2\vert j_2, 
i_2\right)}\right)\right]\label{eq:kl_ad4}\\
 & \leq \max_{i_1,j_1} \sum_{k_1}  p\left(k_1\vert j_1, i_1\right)\log\left(\frac{ 
p\left(k_1\vert j_1, i_1\right)}{ p^*\left(k_1\vert j_1, i_1\right)}\right) + 
\max_{i_2,j_2}\sum_{k_2} p\left(k_2\vert j_2, i_2\right)\log\left(\frac{p\left(k_2\vert 
j_2, i_2\right)}{p^*\left(k_2\vert j_2, i_2\right)}\right)\label{eq:kl_ad5}\\
 &=\mathcal{KL}\left(B_1\right)+\mathcal{KL}\left(B_2\right). \label{eq:kl_ad6}
 \end{aligned}$$ Eq. follows from the definition of $\mathcal{KL}\left(B_1 \otimes B_2\right)$, Eq. follows from the definition of $D_{KL}$ and $B_1\otimes B_2$, Eq. follows from additivity of the relative entropy for independent distributions, Eq. follows from basic algebra, and Eq. follows from the fact that $B_1^*$ and $B_2^*$ are behaviors achieving the minimum in Eq. for $B_1$ and $B_2$, respectively.

Distance based monotones
------------------------

We now introduce contextuality monotones based on geometric distances, in contrast with the previous defined quantifier which is based on entropic distances, replacing the relative entropy by some geometric distance defined over real vector spaces in Eq.  [@BAC17; @AT17]. Let $D$ be any distance defined in real vector spaces $\mathds{R}^{K}$. We define the distance between two prepare-and-measure statistics $B$ and $B'$ as D(B, B’) \_[i,j]{} D(p(j,i),p(j,i)).\[eq:defD\_box\]We can now define the $D$-contextuality distance (B)\_[B’()]{}D(B,B’), \[eq:defD\]which quantifies the distance, with respect to $D$, from $B$ to the set of noncontextual prepare-and-measure statistics. We focus here on the contextuality quantifier obtained when we use the $\ell_1$ norm D\_1(x,y)=\_i |x\_i-y\_i|.

The $\ell_1$-contextuality distance is a resource monotone with respect to the free-operations in ${\mathcal{F}}$.

Given $B \in \mathcal{O}$, let $B^*$ be the noncontextual prepare-and-measure statistics achieving the minimum in Eq. . Given $T \in \mathcal{F}$, we have

$$\begin{aligned}
   \mathcal{D}\left(T\left(B\right)\right)&\leq \max_{\tilde{i},\tilde{j}}\sum_{\tilde{k}} \left|p\left(\tilde{k}\vert \tilde{j},\tilde{i}\right)-p^*\left(\tilde{k}\vert \tilde{j}, \tilde{i}\right)\right| \label{eq:dist1}\\   
  &= \max_{\tilde{i},\tilde{j}} \sum_{\tilde{k}} \left| \sum_{i,j,k} q_O\left(\tilde{k}\vert k\right)\left(p\left(k\vert j,i\right)-p^*\left(k\vert j,i\right)\right)q_M\left(j\vert \tilde{j}\right)q_P\left(i\vert \tilde{i}\right)\right|\label{eq:dist2}\\
  &\leq \max_{\tilde{i},\tilde{j}} \sum_{\tilde{k}} \sum_{i,j,k} q_O\left(\tilde{k}\vert k\right)q_M\left(j\vert \tilde{j}\right)q_P\left(i\vert \tilde{i}\right)\left| \left(p\left(k\vert j,i\right)-p^*\left(k\vert j,i\right)\right)\right|\label{eq:dist3}\\
  &= \max_{\tilde{i},\tilde{j}} \sum_{i,j,k} q_M\left(j\vert \tilde{j}\right)q_P\left(i\vert \tilde{i}\right)\left| \left(p\left(k\vert j,i\right)-p^*\left(k\vert j,i\right)\right)\right|\label{eq:dist4}\\
  &= \max_{i,j} \sum_k \left|p\left(k\vert j,i\right) - p^*\left(k\vert j,i\right)\right|\label{eq:dist5}\\
  &=\mathcal{D}\left(B\right).
  \end{aligned}$$

Eq.  follows form the definition of $\mathcal{D}\left(T(B)\right)$ and the fact that $T\left(B^*\right) \in \mathsf{NC}\left(\mathcal{S}\right)$, Eq.  follows from the definition of $T\in \mathcal{F}$, Eq.  follows from the triangular inequality for the $\ell_1$ norm, Eq.  follows from $\sum_{\tilde{k}} q_{O}\left(\tilde{k}\vert k\right)=1$ and Eq.  follows from the fact that the average is smaller than the largest value.

The $\ell_1$-contextuality distance is subadditive under independent juxtapositions.

\[thm:D\_add\] Given two behaviors $B_1$ and $B_2$,we have that (B\_1 B\_2) (B\_1 )+ (B\_2).

Let $B_1^*$ and $B_2^*$ be the behaviors achieving the minimum in Eq. for $B_1$ and $B_2$, respectively. Then, we have $$\begin{aligned}
  \mathcal{D}\left(B_1 \otimes B_2\right)&\leq D\left(B_1\otimes B_2,B_1^*\otimes B_2^*\right) \label{eq:D_ad1}\\
  &= \max_{i_1,i_2,j_1,j_2} \sum_{k_1,k_2} \left|p\left(k_1k_2\vert j_1j_2, i_1i_2\right)-p^*\left(k_1k_2\vert j_1j_2, i_1i_2\right)\right|\label{eq:D_ad2}\\
  &=\max_{i_1,i_2,j_1,j_2} \sum_{k_1,k_2} \left|p\left(k_1\vert j_1, i_1\right)p\left(k_2\vert j_2, i_2\right)-p^*\left(k_1\vert j_1, i_1\right)p^*\left(k_2\vert j_2, i_2\right)\right|\label{eq:D_ad3}\\
   &\leq \max_{i_1,i_2,j_1,j_2} \sum_{k_1,k_2} \left[\left|p\left(k_1\vert j_1, i_1\right)p\left(k_2\vert j_2, i_2\right)-p^*\left(k_1\vert j_1, i_1\right)p\left(k_2\vert j_2, i_2\right)\right|\right.\nonumber \\
   & \hspace{8em} + \left.\left|p^*\left(k_1\vert j_1, i_1\right)p\left(k_2\vert j_2, i_2\right)-p^*\left(k_1\vert j_1, i_1\right)p^*\left(k_2\vert j_2, i_2\right)\right|\right]\label{eq:D_ad4}\\
  &\leq \max_{i_1,i_2,j_1,j_2} \left[\sum_{k_1, k_2} p\left(k_2\vert j_2, i_2\right)\left|p\left(k_1\vert j_1, i_1\right)-p^*\left(k_1\vert j_1, i_1\right)\right|\right.\nonumber \\
    &  \hspace{8em} + \left.\sum_{k_1,k_2}p^*\left(k_1\vert j_1, i_1\right)\left|p\left(k_2\vert j_2, i_2\right)-p^*\left(k_2\vert j_2, i_2\right)\right|\right]\label{eq:D_ad5} \\
    &= \max_{i_1,i_2,j_1,j_2} \left[\sum_{k_1}\left|p\left(k_1\vert j_1, i_1\right)-p^*\left(k_1\vert j_1, i_1\right)\right|
   + \sum_{k_2}\left|p\left(k_2\vert j_2, i_2\right)-p^*\left(k_2\vert j_2, i_2\right)\right|\right]\label{eq:D_ad6} \\
   &=\mathcal{D}\left(B_1 \right)+ \mathcal{D}\left(B_2\right)
 \end{aligned}$$ Eq. follows from the definition of $\mathcal{KL}\left(B_1 \otimes B_2\right)$, Eq. follows from the definition of $D_{KL}$ and $B_1\otimes B_2$, Eq. follows from additivity of the relative entropy for independent distributions, Eq. follows from basic algebra, and Eq. follows from the definition of the fact that $B_1^*$ and $B_2^*$ be the behaviors achieving the minimum in Eq. for $B_1$ and $B_2$, respectively.

Trace Distance
--------------

Instead of taking the maximum over preparations and measurements in Eq. , we can take the average value to define the uniform $D$-contextuality distance $$\label{eq:def_trace_distance}
 \mathcal{D}_u(B):= \frac{1}{2 I  J}\min_{B^{\prime} \in \mathsf{NC}\left({\mathcal{S}}\right)} 
D\left( B,B^{\prime} \right) $$ with $B^{\prime}$ taken over all noncontextual prepare-and-measure statistics, and $D$ being some distance defined over real vector spaces. Of special importance is the uniform contextuality distance defined by the trace norm $\ell_1$ [@NC00; @BAC17; @AT17].

Again, the trace distance $\mathcal{D}_u$ is subadditive under independent juxtapositions.

Given two behaviors $B_1$ and $B_2$,we have that \_u(B\_1 B\_2) \_u(B\_1 )+ \_u(B\_2).

The proof is analogous to the proof of Thm. \[thm:D\_add\].

Although $\mathcal{D}_u$ is not a monotone under the entire class of of free operations $\mathcal{F}$, it is a suitable contextuality quantifier when the sets of preparations and measurements are fixed, with the advantage that, unlike $\mathcal{L}$ and $\mathcal{D}$, the uniform contextuality distance $\mathcal{D}_u$ defined with the $\ell_1$ norm can be computed efficiently using linear programming.

Conclusion {#sec:conc}
==========

Motivated by the recognition of contextuality as a potential resource for computation and information processing, we develop a resource theory for generalized contextuality that can be applied to arbitrary prepare-and-measure experiments. We introduce a minimal set of free operations (minimal in the sense that any other possible, and physically meaningful, set of physical operations should contain ours as a subset) with a clear operational interpretation and explicit analytical parametrization and show that several natural contextuality quantifiers are indeed monotones under this class of free operations. With the recognition that membership testing in the set of noncontextual prepare-and-measure statistics can be done efficiently using linear programming, many of these quantifiers can also be computed efficiently in the same way. This framework is useful to classify, quantify, and manipulate contextuality as a formal resource. It would be interesting to investigate whether there is a maximally-contextual single prepare-and-measure statistics that serve as contextuality bits for all scenarios, or to identify what is the simplest scenario admitting inequivalent (not freely interconvertible) classes of contextuality. Another important issue is to investigate protocols for contextuality distillation relying only on the set of free operations. This framework provides a new interpretation of generalized contextuality, now considered a useful resource rather than an odd feature exhibited for quantum physics [@CSW10; @CSW14; @ATC14]. Indeed, as it has occurred with entanglement [@BG15; @HHHH09; @RK17; @SHN16] over the years, we expect that works like the present one can shed new light on the phenomenon, giving to it new insights and making it easier to understand.

The authors thank Marcelo Terra Cunha for all suggestions on the manuscript, and the International Institute of Physics for its support and hospitality. BA and CD also acknowledges financial support from the Brazilian ministries MEC and MCTIC, and CNPq.
