1.11 Propositions as types
As mentioned in the introduction, to show that a proposition is true in type theory corresponds to exhibiting an element of the type corresponding to that proposition. We regard the elements of this type as evidence or witnesses that the proposition is true. (They are sometimes even called proofs, but this terminology can be misleading, so we generally avoid it.) In general, however, we will not construct witnesses explicitly; instead we present the proofs in ordinary mathematical prose, in such a way that they could be translated into an element of a type. This is no different from reasoning in classical set theory, where we don’t expect to see an explicit derivation using the rules of predicate logic and the axioms of set theory.
However, the type-theoretic perspective on proofs is nevertheless different in important ways. The basic principle of the logic of type theory is that a proposition is not merely true or false, but rather can be seen as the collection of all possible witnesses of its truth. Under this conception, proofs are not just the means by which mathematics is communicated, but rather are mathematical objects in their own right, on a par with more familiar objects such as numbers, mappings, groups, and so on. Thus, since types classify the available mathematical objects and govern how they interact, propositions are nothing but special types — namely, types whose elements are proofs.
The basic observation which makes this identification feasible is that we have the following natural correspondence between logical operations on propositions, expressed in English, and type-theoretic operations on their corresponding types of witnesses.
English | Type Theory |
---|---|
True | |
False | |
and | |
or | |
If then | |
if and only if | |
Not |
The point of the correspondence is that in each case, the rules for constructing and using elements of the type on the right correspond to the rules for reasoning about the proposition on the left. For instance, the basic way to prove a statement of the form “ and ” is to prove and also prove , while the basic way to construct an element of is as a pair , where is an element (or witness) of and is an element (or witness) of . And if we want to use “ and ” to prove something else, we are free to use both and in doing so, analogously to how the induction principle for allows us to construct a function out of it by using elements of and of .
Similarly, the basic way to prove an implication “if then ” is to assume and prove , while the basic way to construct an element of is to give an expression which denotes an element (witness) of which may involve an unspecified variable element (witness) of type . And the basic way to use an implication “if then ” is deduce if we know , analogously to how we can apply a function to an element of to produce an element of . We strongly encourage the reader to do the exercise of verifying that the rules governing the other type constructors translate sensibly into logic.
Of special note is that the empty type corresponds to falsity. When speaking logically, we refer to an inhabitant of as a contradiction: thus there is no way to prove a contradiction,11More precisely, there is no basic way to prove a contradiction, i.e. has no constructors. If our type theory were inconsistent, then there would be some more complicated way to construct an element of . while from a contradiction anything can be derived. We also define the negation of a type as
Thus, a witness of is a function , which we may construct by assuming and deriving an element of . Note that although the logic we obtain is “constructive”, as discussed in the introduction, this sort of “proof by contradiction” (assume and derive a contradiction, concluding ) is perfectly valid constructively: it is simply invoking the meaning of “negation”. The sort of “proof by contradiction” which is disallowed is to assume and derive a contradiction as a way of proving . Constructively, such an argument would only allow us to conclude , and the reader can verify that there is no obvious way to get from (that is, from ) to .
The above translation of logical connectives into type-forming operations is referred to as propositions as types: it gives us a way to translate propositions and their proofs, written in English, into types and their elements. For example, suppose we want to prove the following tautology (one of “de Morgan’s laws”):
“If not and not , then not ( or )”. | (1.11.1) |
An ordinary English proof of this fact might go as follows.
Suppose not and not , and also suppose or ; we will derive a contradiction. There are two cases. If holds, then since not , we have a contradiction. Similarly, if holds, then since not , we also have a contradiction. Thus we have a contradiction in either case, so not ( or ).
Now, the type corresponding to our tautology (1.11.1), according to the rules given above, is
(1.11.2) |
so we should be able to translate the above proof into an element of this type.
As an example of how such a translation works, let us describe how a mathematician reading the above English proof might simultaneously construct, in his or her head, an element of (1.11.2). The introductory phrase “Suppose not and not ” translates into defining a function, with an implicit application of the recursion principle for the cartesian product in its domain . This introduces unnamed variables (hypotheses) of types and . When translating into type theory, we have to give these variables names; let us call them and . At this point our partial definition of an element of (1.11.2) can be written as
with a “hole” of type indicating what remains to be done. (We could equivalently write , using the recursor instead of pattern matching.) The next phrase “also suppose or ; we will derive a contradiction” indicates filling this hole by a function definition, introducing another unnamed hypothesis , leading to the proof state:
Now saying “there are two cases” indicates a case split, i.e. an application of the recursion principle for the coproduct . If we write this using the recursor, it would be
while if we write it using pattern matching, it would be
Note that in both cases we now have two “holes” of type to fill in, corresponding to the two cases where we have to derive a contradiction. Finally, the conclusion of a contradiction from and is simply application of the function to , and similarly in the other case. (Note the convenient coincidence of the phrase “applying a function” with that of “applying a hypothesis” or theorem.) Thus our eventual definition is
As an exercise, you should verify the converse tautology “If not ( or ), then (not ) and (not )” by exhibiting an element of
for any types and , using the rules we have just introduced.
However, not all classical tautologies hold under this interpretation. For example, the rule “If not ( and ), then (not ) or (not )” is not valid: we cannot, in general, construct an element of the corresponding type
This reflects the fact that the “natural” propositions-as-types logic of type theory is constructive. This means that it does not include certain classical principles, such as the law of excluded middle () or proof by contradiction, and others which depend on them, such as this instance of de Morgan’s law.
Philosophically, constructive logic is so-called because it confines itself to constructions that can be carried out effectively, which is to say those with a computational meaning. Without being too precise, this means there is some sort of algorithm specifying, step-by-step, how to build an object (and, as a special case, how to see that a theorem is true). This requires omission of , since there is no effective procedure for deciding whether a proposition is true or false.
The constructivity of type-theoretic logic means it has an intrinsic computational meaning, which is of interest to computer scientists. It also means that type theory provides axiomatic freedom. For example, while by default there is no construction witnessing , the logic is still compatible with the existence of one (see §3.4 (http://planetmath.org/34classicalvsintuitionisticlogic)). Thus, because type theory does not deny , we may consistently add it as an assumption, and work conventionally without restriction. In this respect, type theory enriches, rather than constrains, conventional mathematical practice.
We encourage the reader who is unfamiliar with constructive logic to work through some more examples as a means of getting familiar with it. See http://planetmath.org/node/87565Exercise 1.12,http://planetmath.org/node/87566Exercise 1.13 for some suggestions.
So far we have discussed only propositional logic. Now we consider predicate logic, where in addition to logical connectives like “and” and “or” we have quantifiers “there exists” and “for all”. In this case, types play a dual role: they serve as propositions and also as types in the conventional sense, i.e., domains we quantify over. A predicate over a type is represented as a family , assigning to every element a type corresponding to the proposition that holds for . We now extend the above translation with an explanation of the quantifiers:
English | Type Theory |
---|---|
For all , holds | |
There exists such that |
As before, we can show that tautologies of (constructive) predicate logic translate into inhabited types. For example, If for all , and then (for all , ) and (for all , ) translates to
An informal proof of this tautology might go as follows:
Suppose for all , and . First, we suppose given and prove . By assumption, we have and , and hence we have . Second, we suppose given and prove . Again by assumption, we have and , and hence we have .
The first sentence begins defining an implication as a function, by introducing a witness for its hypothesis:
At this point there is an implicit use of the pairing constructor to produce an element of a product type, which is somewhat signposted in this example by the words “first” and “second”:
The phrase “we suppose given and prove ” now indicates defining a dependent function in the usual way, introducing a variable for its input. Since this is inside a pairing constructor, it is natural to write it as a -abstraction:
Now “we have and ” invokes the hypothesis, obtaining , and “hence we have ” implicitly applies the appropriate projection:
The next two sentences fill the other hole in the obvious way:
Of course, the English proofs we have been using as examples are much more verbose than those that mathematicians usually use in practice; they are more like the sort of language one uses in an “introduction to proofs” class. The practicing mathematician has learned to fill in the gaps, so in practice we can omit plenty of details, and we will generally do so. The criterion of validity for proofs, however, is always that they can be translated back into the construction of an element of the corresponding type.
As a more concrete example, consider how to define inequalities of natural numbers. One natural definition is that if there exists a such that . (This uses again the identity types that we will introduce in the next section, but we will not need very much about them.) Under the propositions-as-types translation, this would yield:
The reader is invited to prove the familiar properties of from this definition. For strict inequality, there are a couple of natural choices, such as
or
The former is more natural in constructive mathematics, but in this case it is actually equivalent to the latter, since has “decidable equality” (see §3.4 (http://planetmath.org/34classicalvsintuitionisticlogic),Theorem 7.2.6 (http://planetmath.org/72uniquenessofidentityproofsandhedbergstheorem#Thmprethm4)).
The representation of propositions as types also allows us to incorporate axioms into the definition of types as mathematical structures using -types, as discussed in §1.6 (http://planetmath.org/16dependentpairtypes). For example, suppose we want to define a semigroup to be a type equipped with a binary operation (that is, a magma) and such that for all we have . This latter proposition is represented by the type , so the type of semigroups is
From an inhabitant of this type we can extract the carrier , the operation , and a witness of the axiom, by applying appropriate projections. We will return to this example in §2.14 (http://planetmath.org/214exampleequalityofstructures).
Note also that we can use the universes in type theory to represent “higher order logic” — that is, we can quantify over all propositions or over all predicates. For example, we can represent the proposition for all properties , if then as
where and . However, a priori this proposition lives in a different, higher, universe than the propositions we are quantifying over; that is
We will return to this issue in §3.5 (http://planetmath.org/35subsetsandpropositionalresizing).
We have described here a “proof-relevant” translation of propositions, where the proofs of disjunctions and existential statements carry some information. For instance, if we have an inhabitant of , regarded as a witness of “ or ”, then we know whether it came from or from . Similarly, if we have an inhabitant of , regarded as a witness of “there exists such that ”, then we know what the element is (it is the first projection of the given inhabitant).
As a consequence of the proof-relevant nature of this logic, we may have “ if and only if ” (which, recall, means ), and yet the types and exhibit different behavior. For instance, it is easy to verify that “ if and only if ”, and yet clearly and differ in important ways. The statement “ if and only if ” tells us only that when regarded as a mere proposition, the type represents the same proposition as (in this case, the true proposition). We sometimes express “ if and only if ” by saying that and are logically equivalent. This is to be distinguished from the stronger notion of equivalence of types to be introduced in §2.4 (http://planetmath.org/24homotopiesandequivalences),http://planetmath.org/node/87577Chapter 4: although and are logically equivalent, they are not equivalent types.
In http://planetmath.org/node/87576Chapter 3 we will introduce a class of types called “mere propositions” for which equivalence and logical equivalence coincide. Using these types, we will introduce a modification to the above-described logic that is sometimes appropriate, in which the additional information contained in disjunctions and existentials is discarded.
Finally, we note that the propositions-as-types correspondence can be viewed in reverse, allowing us to regard any type as a proposition, which we prove by exhibiting an element of . Sometimes we will state this proposition as “ is inhabited.” That is, when we say that is inhabited, we mean that we have given a (particular) element of , but that we are choosing not to give a name to that element. Similarly, to say that is not inhabited is the same as to give an element of . In particular, the empty type is obviously not inhabited, since is inhabited by .22This should not be confused with the statement that type theory is consistent, which is the meta-theoretic claim that it is not possible to obtain an element of by following the rules of type theory.
Title | 1.11 Propositions as types |
---|---|
\metatable |