type theory (dependent, extensional, intensional type theory)
In logic, the context of an assertion (or judgement) consists of all of the assumptions that are made when that assertion is claimed to be valid; whether an assertion is in fact valid (or even meaningful) may depend on the context. The precise definition depends on the theory (or doctrine) that one is working in.
Generally, a context is thought of as relative to some underlying logical theory. This underlying theory will contain most of the assumptions of what constitutes validity; the context of an assertion in this theory will then include only those extra assumptions that may be used by that assertion. On the other hand, one could also think of the entire base theory as part of the context.
For example, in the theory of a group, it is understood that there is a group , that has various elements, that two elements of may be equal, that any two elements of have as product an element of , and that various equational laws are satisfied (which we will not list here). That is all taken for granted when discussing a group. However, the validity and meaningfulness of an assertion that two elements of commute will depend on (the rest of) the context.
To be more explicit, the assertion that and commute does not make sense without the additional context that and are elements of . Even in that context, this assertion, while at least meaningful, is not valid. However, if we add to the context the assumption that , then the assertion is valid. Written symbolically,
is meaningless;
is meaningful but invalid; and
is valid.
In a sufficiently rich logical language, contexts are unnecessary, which is why contexts are not usually explained in accounts of logic for ordinary reasoning (including in ordinary mathematics). For example, the two meaningful assertions above may be rewritten thus:
and
Here the context on the left side is the empty context, consisting of no assumptions whatsoever (beyond those underlying the base theory).
However, these versions involve and , while the previous versions work in weaker logics. In fact, these assertions make sense (and the valid one may be proved) in the internal logic of a group object in a finitely complete category (and somewhat more generally than that). Accordingly, they can be interpreted as statements about any group object in any finitely complete category (and the valid one will then be interpreted as a true statement), exactly as they do for groups (which are group objects in the finitely complete category Set).
Even if one is completely uninterested in internalization or weak logics, a basic familiarity with contexts may help drive home a point that is important throughout reasoning: What you can state and prove depends on your assumptions.
Given a type theory , it induces a category , whose
objects are the contexts in the type theory;
morphisms between contexts are substitutions, or interpretations of variables.
A morphism from the context to the context consists of a way of fulfilling the assumptions required by by appropriately interpreting those provided by , generally by substituting terms available in for variables needed in and proving whatever is necessary from the assumptions at hand.
This is called the category of contexts or category of contexts and substitutions of .
A review is for instance in (Taylor section 2.8).
Let and be contexts of some type theory of the form
and
(Here we allow the possibility that each type in these contexts depends on the variables occurring earlier in the context, but for simplicity we can ignore that. )
Then a morphism in the category of contexts consists of a sequence of terms such as the following:
In other words, to give such a morphism we must give, for each type (or assumption) required by , a way to construct an element of that type (or a proof of that assumption) out of the data and assumptions contained in .
This might fit better after the motivating examples below; but maybe those examples don't make sense to a newcomer. This is incomplete, however, since it doesn't address contexts that include equational hypotheses. —Toby
The category of contexts has the universal property that for any suitable category, functors
that preserve the relevant structure correspond precisely to an interpretation of in .
The construction
is the left adjoint in an adjunction that relates type theories and categories, whose right adjoint extracts the internal logic of a category. See at type theory the section Categorical semantics.
Accordingly, the adjunction counit evaluated on any category
says that there a canonical interpretatin of the internal logic of a category in itself. As it should be.
Given a context and a type , there is a new context .
Given a term there is a canonical morphism of contexts
which picks that term in . The base change functor along this morphism
is the operation of substitution of variables: it sends a dependent type to .
There is also the canonical morphism of contexts
which simply forgets the type . The base change along this morphism is the context extension functor
Its right adjoint is the dependent product functor giving the universal quantifier , and its left adjoint is the dependent sum functor giving the existential quantifier .
For example, consider these contexts in the theory of a group :
One interpretation of in (that is, a morphism from to ) is given by the substitution
The fact that in is ignored. In type-theoretic language, this would consist of the two terms
Note that in this way of presenting things, the names of the variables in do not appear; only the order in which the types appear in matters.
A less obvious interpretation of in is the substitution
There is no reason to keep variable names the same. (At this point, compare and ; when the definition is complete, it ought to follow that these are isomorphic.)
Another, perhaps even less obvious, morphism is
Not only does this ignore that ; it also ignores the very existence of in . (It also uses the existence of more than once. Ignoring and reusing information like this is not always allowed in substructural logics such as linear logic.)
That we can interpret in without renaming variables is essentially the meaning of the judgement (1) above. That is, we get a morphism from to by performing the substitution
and then inserting a proof of (1). As it happens, the argument in such a proof is reversible, so you should expect that and are also isomorphic.
Are there any morphisms from to ? The obvious substitution does not define a morphism, since the required fact cannot be proved. However, you get one using the substitution
and then inserting a proof that
All the same, we would not want to say that and are isomorphic contexts; although there are morphisms in each direction, composing them should never produce identity morphisms on both sides.
Now I should finish defining the category. First, given a context , there is an obvious identity morphism where every variable is substituted for itself and every statement assumed is proved immediately from itself.
Given morphisms , form the composite as follows: First, for each variable required by , tells us how to substitute a term built out of the variables in , while tells us how to substitute a term from for each of these variables. So in the end, is expressed as a term involving variables available in . Also, by combining the proofs provided by and , we get the proofs required for their composite.
To really complete the definition of a category, I should also describe when two morphisms are equal. There are actually many options here; the most strict is to say that they are equal only if the substitutions and proofs used are syntactically identical, and the most weak is to say that any parallel morphisms are equal. Neither of these is very useful; for purposes of this example, let us require only that the expressions substituted for each variable in can be proved equal in the context .
Now you should be able to prove that composition satisfies the axioms of a category.
Notice that the exact definition of equality of morphisms can depend heavily on the theory in question and your own purposes. For example, this definition makes sense only because we have a notion of proving equality of elements of a group. Also, you can sometimes place interesting conditions on whether two proofs count as equivalent, rather than requiring either syntactic identity or (as we do here) accepting proof irrelevance.
Now that the category of contexts (in one sense) of the theory of a group has been completely defined, describe that category (up to equivalence) in terms familiar to an algebraist. In particular, compare it to the category of groups.
In rot13 (so that you have a chance to think about it yourself without accidentally seeing the answer): gur bccbfvgr bs gur pngrtbel bs svavgryl cerfragrq tebhcf.
The result of this exercise is true in more generality: it works for any finite-limit theory; see in particular Lawvere theory. Presumably there are also infinitary generalizations. There’s some general discussion in the Elephant.
A way of describing categorical semantics, even for weak theories, which doesn’t require the explicit introduction of contexts is to use cartesian multicategories.
The category of contexts is also known as the syntactic category of the corresponding theory.
Section D4.4 of
A description of the construction of the category of contexts is in
Another description, via sketches, is in chapter VIII of
A review of this is around section 2.8 of