  Bell inequalities play a central role in the study of quantum non-locality
and entanglement, with many applications in quantum information. Despite the
huge literature on Bell inequalities, it is not easy to find a clear conceptual
answer to what a Bell inequality is, or a clear guiding principle as to how
they may be derived. In this paper, we introduce a notion of logical Bell
inequality which can be used to systematically derive testable inequalities for
a very wide variety of situations. There is a single clear conceptual
principle, based on purely logical consistency conditions, which underlies our
notion of logical Bell inequalities. We show that in a precise sense, all Bell
inequalities can be taken to be of this form. Our approach is very general. It
applies directly to any family of sets of commuting observables. Thus it covers
not only the n-partite scenarios to which Bell inequalities are standardly
applied, but also Kochen-Specker configurations, and many other examples. There
is much current work on experimental tests for contextuality. Our approach
directly yields, in a systematic fashion, testable inequalities for a very
general notion of contextuality.
  There has been much work on obtaining proofs of Bell's theorem `without
inequalities' or `without probabilities'. These proofs are seen as being in a
sense more definitive and logically robust than the inequality-based proofs. On
the hand, they lack the fault-tolerant aspect of inequalities. Our approach
reconciles these aspects, and in fact shows how the logical robustness can be
converted into systematic, general derivations of inequalities with provable
violations. Moreover, the kind of strong non-locality or contextuality
exhibited by the GHZ argument or by Kochen-Specker configurations can be shown
to lead to maximal violations of the corresponding logical Bell inequalities.
