1.11 Propositions as types


As mentioned in the introduction, to show that a propositionPlanetmathPlanetmath is true in type theoryPlanetmathPlanetmath 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 theoryMathworldPlanetmath, where we don’t expect to see an explicit derivationPlanetmathPlanetmath 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 collectionMathworldPlanetmath 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 operationsMathworldPlanetmath on propositions, expressed in English, and type-theoretic operations on their corresponding types of witnesses.

English Type Theory
True 𝟏
False 𝟎
A and B A×B
A or B A+B
If A then B AB
A if and only if B (AB)×(BA)
Not A A𝟎

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 “A and B” is to prove A and also prove B, while the basic way to construct an element of A×B is as a pair (a,b), where a is an element (or witness) of A and b is an element (or witness) of B. And if we want to use “A and B” to prove something else, we are free to use both A and B in doing so, analogously to how the inductionMathworldPlanetmath principle for A×B allows us to construct a function out of it by using elements of A and of B.

Similarly, the basic way to prove an implicationMathworldPlanetmath “if A then B” is to assume A and prove B, while the basic way to construct an element of AB is to give an expression which denotes an element (witness) of B which may involve an unspecified variable element (witness) of type A. And the basic way to use an implication “if A then B” is deduce B if we know A, analogously to how we can apply a function f:AB to an element of A to produce an element of B. We strongly encourage the reader to do the exercise of verifying that the rules governing the other type constructors translateMathworldPlanetmath 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 contradictionMathworldPlanetmathPlanetmath: 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 inconsistentPlanetmathPlanetmath, 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 negationMathworldPlanetmath of a type A as

¬A:A𝟎.

Thus, a witness of ¬A is a function A𝟎, which we may construct by assuming x:A and deriving an element of 𝟎. Note that although the logic we obtain is “constructive”, as discussed in the introduction, this sort of “proof by contradictionMathworldPlanetmath” (assume A and derive a contradiction, concluding ¬A) is perfectly valid constructively: it is simply invoking the meaning of “negation”. The sort of “proof by contradiction” which is disallowed is to assume ¬A and derive a contradiction as a way of proving A. Constructively, such an argument would only allow us to conclude ¬¬A, and the reader can verify that there is no obvious way to get from ¬¬A (that is, from (A𝟎)𝟎) to A.

The above translationMathworldPlanetmathPlanetmath 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 tautologyMathworldPlanetmath (one of “de Morgan’s laws”):

“If not A and not B, then not (A or B)”. (1.11.1)

An ordinary English proof of this fact might go as follows.

Suppose not A and not B, and also suppose A or B; we will derive a contradiction. There are two cases. If A holds, then since not A, we have a contradiction. Similarly, if B holds, then since not B, we also have a contradiction. Thus we have a contradiction in either case, so not (A or B).

Now, the type corresponding to our tautology (1.11.1), according to the rules given above, is

(A𝟎)×(B𝟎)(A+B𝟎) (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 A and not B” translates into defining a function, with an implicit application of the recursion principle for the cartesian productMathworldPlanetmath in its domain (A𝟎)×(B𝟎). This introduces unnamed variables (hypotheses) of types A𝟎 and B𝟎. When translating into type theory, we have to give these variables names; let us call them x and y. At this point our partial definition of an element of (1.11.2) can be written as

f((x,y))::A+B𝟎

with a “hole” of type A+B𝟎 indicating what remains to be done. (We could equivalently write f:𝗋𝖾𝖼(A𝟎)×(B𝟎)(A+B𝟎,λx.λy.), using the recursor instead of pattern matching.) The next phrase “also suppose A or B; we will derive a contradiction” indicates filling this hole by a function definition, introducing another unnamed hypothesisMathworldPlanetmath z:A+B, leading to the proof state:

f((x,y))(z)::𝟎

Now saying “there are two cases” indicates a case split, i.e. an application of the recursion principle for the coproductMathworldPlanetmath A+B. If we write this using the recursor, it would be

f((x,y))(z):𝗋𝖾𝖼A+B(𝟎,λa.,λb.,z)

while if we write it using pattern matching, it would be

f((x,y))(𝗂𝗇𝗅(a)) ::𝟎
f((x,y))(𝗂𝗇𝗋(b)) ::𝟎.

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 conclusionMathworldPlanetmath of a contradiction from a:A and x:A𝟎 is simply application of the function x to a, 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

f((x,y))(𝗂𝗇𝗅(a)) :x(a)
f((x,y))(𝗂𝗇𝗋(b)) :y(b).

As an exercise, you should verify the converseMathworldPlanetmath tautology “If not (A or B), then (not A) and (not B)” by exhibiting an element of

((A+B)𝟎)(A𝟎)×(B𝟎),

for any types A and B, using the rules we have just introduced.

However, not all classical tautologies hold under this interpretationMathworldPlanetmathPlanetmath. For example, the rule “If not (A and B), then (not A) or (not B)” is not valid: we cannot, in general, construct an element of the corresponding type

((A×B)𝟎)(A𝟎)+(B𝟎).

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 middleMathworldPlanetmathPlanetmath (𝖫𝖤𝖬) 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 compatibleMathworldPlanetmath 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 restrictionPlanetmathPlanetmathPlanetmath. 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 quantifiersMathworldPlanetmath “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 A is represented as a family P:A𝒰, assigning to every element a:A a type P(a) corresponding to the proposition that P holds for a. We now extend the above translation with an explanation of the quantifiers:

English Type Theory
For all x:A, P(x) holds (x:A)P(x)
There exists x:A such that P(x) (x:A) P(x)

As before, we can show that tautologies of (constructive) predicate logic translate into inhabited types. For example, If for all x:A, P(x) and Q(x) then (for all x:A, P(x)) and (for all x:A, Q(x)) translates to

((x:A)P(x)×Q(x))((x:A)P(x))×((x:A)Q(x)).

An informal proof of this tautology might go as follows:

Suppose for all x, P(x) and Q(x). First, we suppose given x and prove P(x). By assumption, we have P(x) and Q(x), and hence we have P(x). Second, we suppose given x and prove Q(x). Again by assumption, we have P(x) and Q(x), and hence we have Q(x).

The first sentenceMathworldPlanetmath begins defining an implication as a function, by introducing a witness for its hypothesis:

f(p)::((x:A)P(x))×((x:A)Q(x)).

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”:

f(p):(:(x:A)P(x),:(x:A)Q(x)).

The phrase “we suppose given x and prove P(x)” 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:

f(p):(λx.(:P(x)),:(x:A)Q(x)).

Now “we have P(x) and Q(x)” invokes the hypothesis, obtaining p(x):P(x)×Q(x), and “hence we have P(x)” implicitly applies the appropriate projectionMathworldPlanetmathPlanetmathPlanetmath:

f(p):(λx.𝗉𝗋1(p(x)),:(x:A)Q(x)).

The next two sentences fill the other hole in the obvious way:

f(p):(λx.𝗉𝗋1(p(x)),λx.𝗉𝗋2(p(x))).

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 languagePlanetmathPlanetmath 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 numbersMathworldPlanetmath. One natural definition is that nm if there exists a k: such that n+k=m. (This uses again the identity types that we will introduce in the next sectionPlanetmathPlanetmathPlanetmathPlanetmathPlanetmath, but we will not need very much about them.) Under the propositions-as-types translation, this would yield:

(nm):k:(n+k=m).

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

(n<m):k:(n+𝗌𝗎𝖼𝖼(k)=m)

or

(n<m):(nm)׬(n=m).

The former is more natural in constructive mathematics, but in this case it is actually equivalentMathworldPlanetmathPlanetmathPlanetmathPlanetmath 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 A equipped with a binary operationMathworldPlanetmath m:AAA (that is, a magma) and such that for all x,y,z:A we have m(x,m(y,z))=m(m(x,y),z). This latter proposition is represented by the type (x,y,z:A)m(x,m(y,z))=m(m(x,y),z), so the type of semigroups is

𝖲𝖾𝗆𝗂𝗀𝗋𝗈𝗎𝗉:(A:𝒰)(m:AAA)(x,y,z:A)m(x,m(y,z))=m(m(x,y),z).

From an inhabitant of this type we can extract the carrier A, the operation m, 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 universesPlanetmathPlanetmath 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 P:AU, if P(a) then P(b) as

P:A𝒰P(a)P(b)

where A:𝒰 and a,b:A. However, a priori this proposition lives in a different, higher, universe than the propositions we are quantifying over; that is

(P:A𝒰iP(a)P(b)):𝒰i+1.

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 disjunctionsMathworldPlanetmath and existential statements carry some information. For instance, if we have an inhabitant of A+B, regarded as a witness of “A or B”, then we know whether it came from A or from B. Similarly, if we have an inhabitant of (x:A)P(x), regarded as a witness of “there exists x:A such that P(x)”, then we know what the element x is (it is the first projection of the given inhabitant).

As a consequence of the proof-relevant nature of this logic, we may have “A if and only if B” (which, recall, means (AB)×(BA)), and yet the types A and B 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 “A if and only if B” by saying that A and B 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 A as a proposition, which we prove by exhibiting an element of A. Sometimes we will state this proposition as “A is inhabited.” That is, when we say that A is inhabited, we mean that we have given a (particular) element of A, but that we are choosing not to give a name to that element. Similarly, to say that A is not inhabited is the same as to give an element of ¬A. 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