We present a formal theory of contextuality for a set of random variables
grouped into different subsets (contexts) corresponding to different, mutually
incompatible conditions. Within each context the random variables are jointly
distributed, but across different contexts they are stochastically unrelated.
The theory of contextuality is based on the analysis of the extent to which
some of these random variables can be viewed as preserving their identity
across different contexts when one considers all possible joint distributions
imposed on the entire set of the random variables. We illustrate the theory on
three systems of traditional interest in quantum physics (and also in
non-physical, e.g., behavioral studies). These are systems of the
Klyachko-Can-Binicioglu-Shumovsky-type, Einstein-Podolsky-Rosen-Bell-type, and
Suppes-Zanotti-Leggett-Garg-type. Listed in this order, each of them is
formally a special case of the previous one. For each of them we derive
necessary and sufficient conditions for contextuality while allowing for
experimental errors and contextual biases or signaling. Based on the same
principles that underly these derivations we also propose a measure for the
degree of contextuality and compute it for the three systems in question.Comment: Foundations of Physics 7, 762-78