1.5 Product types
Given types $A,B:\mathrm{\pi \x9d\x92\xb0}$ we introduce the type $A\Gamma \x97B:\mathrm{\pi \x9d\x92\xb0}$, which we call their cartesian product. We also introduce a nullary product type, called the unit type $\mathrm{\pi \x9d\x9f\x8f}:\mathrm{\pi \x9d\x92\xb0}$. We intend the elements of $A\Gamma \x97B$ to be pairs $(a,b):A\Gamma \x97B$, where $a:A$ and $b:B$, and the only element of $\mathrm{\pi \x9d\x9f\x8f}$ to be some particular object $\beta \x8b\x86:\mathrm{\pi \x9d\x9f\x8f}$. However, unlike in set theory^{}, where we define ordered pairs^{} to be particular sets and then collect them all together into the cartesian product, in type theory^{}, ordered pairs are a primitive concept^{}, as are functions.
Remark 1.5.1.
There is a general pattern for introduction of a new kind of type in type theory, and because products^{} are our second example following this pattern,^{1}^{1}The description of universes^{} above is an exception. it is worth emphasizing the general form: To specify a type, we specify:

1.
how to form new types of this kind, via formation rules. (For example, we can form the function type $A\beta \x86\x92B$ when $A$ is a type and when $B$ is a type. We can form the dependent function type ${\beta \x88\x8f}_{(x:A)}B\beta \x81\u2019(x)$ when $A$ is a type and $B\beta \x81\u2019(x)$ is a type for $x:A$.)

2.
how to construct elements of that type. These are called the typeβs constructors or introduction rules. (For example, a function type has one constructor, $\mathrm{\Xi \xbb}$abstraction. Recall that a direct definition like $f(x):\beta \x89\u20182x$ can equivalently be phrased as a $\mathrm{\Xi \xbb}$abstraction $f:\beta \x89\u2018\mathrm{\Xi \xbb}x\mathrm{.\beta \x80\x892}x$.)

3.
how to use elements of that type. These are called the typeβs eliminators or elimination rules. (For example, the function type has one eliminator, namely function application.)

4.
a computation rule^{2}^{2}also referred to as $\mathrm{\Xi \xb2}$reduction^{}, which expresses how an eliminator acts on a constructor. (For example, for functions, the computation rule states that $(\mathrm{\Xi \xbb}x.\mathrm{\Xi \xa6})(a)$ is judgmentally equal to the substitution of $a$ for $x$ in $\mathrm{\Xi \xa6}$.)

5.
an optional uniqueness principle^{3}^{3}also referred to as $\mathrm{\Xi \xb7}$expansion, which expresses uniqueness of maps into or out of that type. For some types, the uniqueness principle characterizes maps into the type, by stating that every element of the type is uniquely determined by the results of applying eliminators to it, and can be reconstructed from those results by applying a constructorβthus expressing how constructors act on eliminators, dually to the computation rule. (For example, for functions, the uniqueness principle says that any function $f$ is judgmentally equal to the βexpandedβ function $\mathrm{\Xi \xbb}\beta \x81\u2019x.f\beta \x81\u2019(x)$, and thus is uniquely determined by its values.) For other types, the uniqueness principle says that every map (function) from that type is uniquely determined by some data. (An example is the coproduct type introduced in Β§1.7 (http://planetmath.org/17coproducttypes), whose uniqueness principle is mentioned in Β§2.15 (http://planetmath.org/215universalproperties).)
When the uniqueness principle is not taken as a rule of judgmental equality, it is often nevertheless provable as a propositional equality from the other rules for the type. In this case we call it a propositional uniqueness principle. (In later chapters we will also occasionally encounter propositional computation rules.)
The inference rules in Β§A.3 (http://planetmath.org/a3homotopytypetheory) are organized and named accordingly; see, for example, Β§A.2.4 (http://planetmath.org/a24dependentfunctiontypespitypes), where each possibility is realized.
The way to construct pairs is obvious: given $a:A$ and $b:B$, we may form $(a,b):A\Gamma \x97B$. Similarly, there is a unique way to construct elements of $\mathrm{\pi \x9d\x9f\x8f}$, namely we have $\beta \x8b\x86:\mathrm{\pi \x9d\x9f\x8f}$. We expect that βevery element of $A\Gamma \x97B$ is a pairβ, which is the uniqueness principle for products; we do not assert this as a rule of type theory, but we will prove it later on as a propositional equality.
Now, how can we use pairs, i.e.Β how can we define functions out of a product type? Let us first consider the definition of a nondependent function $f:A\Gamma \x97B\beta \x86\x92C$. Since we intend the only elements of $A\Gamma \x97B$ to be pairs, we expect to be able to define such a function by prescribing the result when $f$ is applied to a pair $(a,b)$. We can prescribe these results by providing a function $g:A\beta \x86\x92B\beta \x86\x92C$. Thus, we introduce a new rule (the elimination rule for products), which says that for any such $g$, we can define a function $f:A\Gamma \x97B\beta \x86\x92C$ by
$$f((a,b)):\beta \x89\u2018g(a)(b).$$ 
We avoid writing $g\beta \x81\u2019(a,b)$ here, in order to emphasize that $g$ is not a function on a product. (However, later on in the book we will often write $g\beta \x81\u2019(a,b)$ both for functions on a product and for curried functions of two variables.) This defining equation is the computation rule for product types.
Note that in set theory, we would justify the above definition of $f$ by the fact that every element of $A\Gamma \x97B$ is a pair, so that it suffices to define $f$ on pairs. By contrast, type theory reverses the situation: we assume that a function on $A\Gamma \x97B$ is welldefined as soon as we specify its values on tuples, and from this (or more precisely, from its more general version for dependent functions, below) we will be able to prove that every element of $A\Gamma \x97B$ is a pair. From a categorytheoretic perspective, we can say that we define the product $A\Gamma \x97B$ to be left adjoint to the βexponentialβ $B\beta \x86\x92C$, which we have already introduced.
As an example, we can derive the projection functions
${\mathrm{\pi \x9d\x97\x89\pi \x9d\x97\x8b}}_{1}$  $:A\Gamma \x97B\beta \x86\x92A$  
${\mathrm{\pi \x9d\x97\x89\pi \x9d\x97\x8b}}_{2}$  $:A\Gamma \x97B\beta \x86\x92B$ 
with the defining equations
${\mathrm{\pi \x9d\x97\x89\pi \x9d\x97\x8b}}_{1}\beta \x81\u2019((a,b))$  $:\beta \x89\u2018a$  
${\mathrm{\pi \x9d\x97\x89\pi \x9d\x97\x8b}}_{2}\beta \x81\u2019((a,b))$  $:\beta \x89\u2018b.$ 
Rather than invoking this principle of function definition every time we want to define a function, an alternative approach is to invoke it once, in a universal^{} case, and then simply apply the resulting function in all other cases. That is, we may define a function of type
$${\mathrm{\pi \x9d\x97\x8b\pi \x9d\x96\u038e\pi \x9d\x96\u038c}}_{A\Gamma \x97B}:\underset{C:\mathrm{\pi \x9d\x92\xb0}}{\beta \x88\x8f}(A\beta \x86\x92B\beta \x86\x92C)\beta \x86\x92A\Gamma \x97B\beta \x86\x92C$$  (1.5.2) 
with the defining equation
$${\mathrm{\pi \x9d\x97\x8b\pi \x9d\x96\u038e\pi \x9d\x96\u038c}}_{A\Gamma \x97B}(C,g,(a,b)):\beta \x89\u2018g(a)(b).$$ 
Then instead of defining functions such as ${\mathrm{\pi \x9d\x97\x89\pi \x9d\x97\x8b}}_{1}$ and ${\mathrm{\pi \x9d\x97\x89\pi \x9d\x97\x8b}}_{2}$ directly by a defining equation, we could define
${\mathrm{\pi \x9d\x97\x89\pi \x9d\x97\x8b}}_{1}$  $:\beta \x89\u2018{\mathrm{\pi \x9d\x97\x8b\pi \x9d\x96\u038e\pi \x9d\x96\u038c}}_{A\Gamma \x97B}(A,\mathrm{\Xi \xbb}a.\mathrm{\Xi \xbb}b.a)$  
${\mathrm{\pi \x9d\x97\x89\pi \x9d\x97\x8b}}_{2}$  $:\beta \x89\u2018{\mathrm{\pi \x9d\x97\x8b\pi \x9d\x96\u038e\pi \x9d\x96\u038c}}_{A\Gamma \x97B}(B,\mathrm{\Xi \xbb}a.\mathrm{\Xi \xbb}b.b).$ 
We refer to the function ${\mathrm{\pi \x9d\x97\x8b\pi \x9d\x96\u038e\pi \x9d\x96\u038c}}_{A\Gamma \x97B}$ as the recursor for product types. The name βrecursorβ is a bit unfortunate here, since no recursion is taking place. It comes from the fact that product types are a degenerate example of a general framework for inductive types, and for types such as the natural numbers^{}, the recursor will actually be recursive. We may also speak of the recursion principle for cartesian products, meaning the fact that we can define a function $f:A\Gamma \x97B\beta \x86\x92C$ as above by giving its value on pairs.
We leave it as a simple exercise to show that the recursor can be derived from the projections and vice versa.
We also have a recursor for the unit type:
$${\mathrm{\pi \x9d\x97\x8b\pi \x9d\x96\u038e\pi \x9d\x96\u038c}}_{\mathrm{\pi \x9d\x9f\x8f}}:\underset{C:\mathrm{\pi \x9d\x92\xb0}}{\beta \x88\x8f}C\beta \x86\x92\mathrm{\pi \x9d\x9f\x8f}\beta \x86\x92C$$ 
with the defining equation
$${\mathrm{\pi \x9d\x97\x8b\pi \x9d\x96\u038e\pi \x9d\x96\u038c}}_{\mathrm{\pi \x9d\x9f\x8f}}(C,c,\beta \x8b\x86):\beta \x89\u2018c.$$ 
Although we include it to maintain the pattern of type definitions, the recursor for $\mathrm{\pi \x9d\x9f\x8f}$ is completely useless, because we could have defined such a function directly by simply ignoring the argument of type $\mathrm{\pi \x9d\x9f\x8f}$.
To be able to define dependent functions over the product type, we have to generalize the recursor. Given $C:A\Gamma \x97B\beta \x86\x92\mathrm{\pi \x9d\x92\xb0}$, we may define a function $f:{\beta \x88\x8f}_{(x:A\Gamma \x97B)}C\beta \x81\u2019(x)$ by providing a function $g:{\beta \x88\x8f}_{(x:A)}{\beta \x88\x8f}_{(y:B)}C\beta \x81\u2019((x,y))$ with defining equation
$$f((x,y)):\beta \x89\u2018g(x)(y).$$ 
For example, in this way we can prove the propositional uniqueness principle, which says that every element of $A\Gamma \x97B$ is equal to a pair. Specifically, we can construct a function
$$\mathrm{\pi \x9d\x97\x8e\pi \x9d\x97\x89\pi \x9d\x97\x89\pi \x9d\x97\x8d}:\underset{x:A\Gamma \x97B}{\beta \x88\x8f}(({\mathrm{\pi \x9d\x97\x89\pi \x9d\x97\x8b}}_{1}(x),{\mathrm{\pi \x9d\x97\x89\pi \x9d\x97\x8b}}_{2}(x)){=}_{A\Gamma \x97B}x).$$ 
Here we are using the identity type, which we are going to introduce below in Β§1.12 (http://planetmath.org/112identitytypes). However, all we need to know now is that there is a reflexivity^{} element ${\mathrm{\pi \x9d\x97\x8b\pi \x9d\x96\u038e\pi \x9d\x96\u038f\pi \x9d\x97\x85}}_{x}:x{=}_{A}x$ for any $x:A$. Given this, we can define
$$\mathrm{\pi \x9d\x97\x8e\pi \x9d\x97\x89\pi \x9d\x97\x89\pi \x9d\x97\x8d}((a,b)):\beta \x89\u2018{\mathrm{\pi \x9d\x97\x8b\pi \x9d\x96\u038e\pi \x9d\x96\u038f\pi \x9d\x97\x85}}_{(a,b)}.$$ 
This construction works, because in the case that $x:\beta \x89\u2018(a,b)$ we can calculate
$$({\mathrm{\pi \x9d\x97\x89\pi \x9d\x97\x8b}}_{1}\beta \x81\u2019((a,b)),{\mathrm{\pi \x9d\x97\x89\pi \x9d\x97\x8b}}_{2}\beta \x81\u2019((a,b)))\beta \x89\u2018(a,b)$$ 
using the defining equations for the projections. Therefore,
$${\mathrm{\pi \x9d\x97\x8b\pi \x9d\x96\u038e\pi \x9d\x96\u038f\pi \x9d\x97\x85}}_{(a,b)}:({\mathrm{\pi \x9d\x97\x89\pi \x9d\x97\x8b}}_{1}\beta \x81\u2019((a,b)),{\mathrm{\pi \x9d\x97\x89\pi \x9d\x97\x8b}}_{2}\beta \x81\u2019((a,b)))=(a,b)$$ 
is welltyped, since both sides of the equality are judgmentally equal.
More generally, the ability to define dependent functions in this way means that to prove a property for all elements of a product, it is enough to prove it for its canonical elements, the tuples. When we come to inductive types such as the natural numbers, the analogous property will be the ability to write proofs by induction. Thus, if we do as we did above and apply this principle once in the universal case, we call the resulting function induction^{} for product types: given $A,B:\mathrm{\pi \x9d\x92\xb0}$ we have
$${\mathrm{\pi \x9d\x97\x82\pi \x9d\x97\x87\pi \x9d\x96\xbd}}_{A\Gamma \x97B}:\underset{C:A\Gamma \x97B\beta \x86\x92\mathrm{\pi \x9d\x92\xb0}}{\beta \x88\x8f}\left(\underset{(x:A)}{\beta \x88\x8f}\underset{(y:B)}{\beta \x88\x8f}C\beta \x81\u2019((x,y))\right)\beta \x86\x92\underset{x:A\Gamma \x97B}{\beta \x88\x8f}C\beta \x81\u2019(x)$$ 
with the defining equation
$${\mathrm{\pi \x9d\x97\x82\pi \x9d\x97\x87\pi \x9d\x96\xbd}}_{A\Gamma \x97B}(C,g,(a,b)):\beta \x89\u2018g(a)(b).$$ 
Similarly, we may speak of a dependent function defined on pairs being obtained from the induction principle of the cartesian product. It is easy to see that the recursor is just the special case of induction in the case that the family $C$ is constant. Because induction describes how to use an element of the product type, induction is also called the (dependent) eliminator, and recursion the nondependent eliminator.
Induction for the unit type turns out to be more useful than the recursor:
$${\mathrm{\pi \x9d\x97\x82\pi \x9d\x97\x87\pi \x9d\x96\xbd}}_{\mathrm{\pi \x9d\x9f\x8f}}:\underset{C:\mathrm{\pi \x9d\x9f\x8f}\beta \x86\x92\mathrm{\pi \x9d\x92\xb0}}{\beta \x88\x8f}C\beta \x81\u2019(\beta \x8b\x86)\beta \x86\x92\underset{x:\mathrm{\pi \x9d\x9f\x8f}}{\beta \x88\x8f}C\beta \x81\u2019(x)$$ 
with the defining equation
$${\mathrm{\pi \x9d\x97\x82\pi \x9d\x97\x87\pi \x9d\x96\xbd}}_{\mathrm{\pi \x9d\x9f\x8f}}(C,c,\beta \x8b\x86):\beta \x89\u2018c.$$ 
Induction enables us to prove the propositional uniqueness principle for $\mathrm{\pi \x9d\x9f\x8f}$, which asserts that its only inhabitant is $\beta \x8b\x86$. That is, we can construct
$$\mathrm{\pi \x9d\x97\x8e\pi \x9d\x97\x89\pi \x9d\x97\x8e\pi \x9d\x97\x87}:\underset{x:\mathrm{\pi \x9d\x9f\x8f}}{\beta \x88\x8f}x=\beta \x8b\x86$$ 
by using the defining equations
$$\mathrm{\pi \x9d\x97\x8e\pi \x9d\x97\x89\pi \x9d\x97\x8e\pi \x9d\x97\x87}(\beta \x8b\x86):\beta \x89\u2018{\mathrm{\pi \x9d\x97\x8b\pi \x9d\x96\u038e\pi \x9d\x96\u038f\pi \x9d\x97\x85}}_{\beta \x8b\x86}$$ 
or equivalently by using induction:
$$\mathrm{\pi \x9d\x97\x8e\pi \x9d\x97\x89\pi \x9d\x97\x8e\pi \x9d\x97\x87}:\beta \x89\u2018{\mathrm{\pi \x9d\x97\x82\pi \x9d\x97\x87\pi \x9d\x96\xbd}}_{\mathrm{\pi \x9d\x9f\x8f}}(\mathrm{\Xi \xbb}x.x=\beta \x8b\x86,{\mathrm{\pi \x9d\x97\x8b\pi \x9d\x96\u038e\pi \x9d\x96\u038f\pi \x9d\x97\x85}}_{\beta \x8b\x86}).$$ 
Title  1.5 Product types 

\metatable 