Contents

Idea

In type theory a product type of two types $A$ and $B$ is the type whose terms are ordered pairs $(a,b)$ with $a\colon A$ and $b\colon B$.

In a model of the type theory in categorical semantics, this is a product. In set theory, it is a cartesian product. In dependent type theory, it is a special case of a dependent sum.

Note that a dependent product type is something different (a generalization of a function type).

Overview

type theorycategory theory
syntaxsemantics
natural deductionuniversal construction
product typeproduct
type formation$\frac{\vdash \;A \colon Type \;\;\;\;\; \vdash \;B \colon Type}{\vdash A \times B \colon Type}$$A,B \in \mathcal{C} \Rightarrow A \times B \in \mathcal{C}$
term introduction$\frac{\vdash\; a \colon A\;\;\;\;\; \vdash\; b \colon B}{ \vdash \; (a,b) \colon A \times B}$$\array{ && Q\\ & {}^{\mathllap{a}}\swarrow &\downarrow_{\mathrlap{(a,b)}}& \searrow^{\mathrlap{b}}\\ A &&A \times B&& B }$
term elimination$\frac{\vdash\; t \colon A \times B}{\vdash\; p_1(t) \colon A} \;\;\;\;\;\frac{\vdash\; t \colon A \times B}{\vdash\; p_2(t) \colon B}$$\array{ && Q\\ &&\downarrow^{t} && \\ A &\stackrel{p_1}{\leftarrow}& A \times B &\stackrel{p_2}{\to}& B}$
computation rule$p_1(a,b) = a\;\;\; p_2(a,b) = b$$\array{ && Q \\ & {}^{\mathllap{a}}\swarrow &\downarrow_{(a,b)}& \searrow^{\mathrlap{b}} \\ A &\stackrel{p_1}{\leftarrow}& A \times B& \stackrel{p_2}{\to} & B}$

Definition

Like any type constructor in type theory (see at natural deduction), a product type is specified by rules saying when we can introduce it as a type, how to construct terms of that type, how to use or “eliminate” terms of that type, and how to compute when we combine the constructors with the eliminators.

There are actually two ways to present product types, as a negative type or as a positive type. In both cases the type formation rule is the following:

$\frac{A\colon Type \qquad B\colon Type}{A\times B\colon Type}$

but the constructors and eliminators may be different.

As a negative type

When presented negatively, primacy is given to the eliminators. We specify that there are two ways to eliminate a term of type $A\times B$: by projecting out the first component, or by projecting out the second.

$\frac{p \colon A\times B}{\pi_1 p\colon A} \qquad \frac{p\colon A\times B}{\pi_2 p\colon B}$

This then determines the form of the constructors: in order to construct a term of type $A\times B$, we have to specify what value that term should yield when all the eliminators are applied to it. In other words, we have to specify a pair of elements, one of $A$ (to be the value of $\pi_1 p$) and one of $B$ (to be the value of $\pi_2 p$).

$\frac{a\colon A \qquad b\colon B}{(a,b)\colon A\times B}$

Finally, we have computation rules which say that the relationship between the constructors and the eliminators is as we hoped. We always have beta reduction rules

$\pi_1(a,b) \to_\beta a \qquad \pi_2(a,b) \to_\beta b$

and we may or may not choose to have an eta reduction rule

$(\pi_1 p, \pi_2 p) \to_\eta p$

As a positive type

When presented positively, primacy is given to the constructors. We specify that the way to construct something of type $A\times B$ is to give something of type $A$ and something of type $B$:

$\frac{a\colon A \qquad b\colon B}{(a,b)\colon A\times B}$

Of course, this is the same as the constructor obtained from the negative presentation. However, the eliminator is different. Now, in order to say how to use something of type $A\times B$, we have to specify how we should behave for all possible ways that it could have been constructed. In other words, we have to say, assuming that $p$ were of the form $(a,b)$, what we want to do. Thus we end up with the following rule:

$\frac{p\colon A\times B \qquad x\colon A, y\colon B \vdash c\colon C}{let (x,y) = p in c \;\colon C}$

We need a term $c$ in the context of two variables of types $A$ and $B$, and the destructor or match “binds those variables” to the two components of $p$. Note that the “ordered pair” $(x,y)$ in the destructor is just a part of the syntax; it is not an instance of the constructor ordered pair. In dependent type theory, this elimination rule must be generalized to allow the type $C$ to depend on $A\times B$.

Now we have beta reduction rule:

$let (x,y) = (a,b) \,in c \;\to_\beta\; c[a/x, b/y]$

In other words, if we build an ordered pair and then break it apart, what we get is just the things we put into it. (The notation $c[a/x, b/y]$ means to substitute $a$ for $x$ and $b$ for $y$ in the term $c$).

And (if we wish) the eta reduction rule, which is a little more subtle:

$let (x,y) = p in c[(x,y)/z] \;\to_\eta\; c[p/z]$

This says that if we break something of type $A\times B$ into its components, but then we only use those two components by way of putting them back together into an ordered pair, then we might as well just not have broken it down in the first place.

Positively defined products are naturally expressed as inductive types. For instance, in Coq syntax we have

Inductive prod (A B:Type) : Type :=
| pair : A -> B -> prod A B.

(Coq then implements beta-reduction, but not eta-reduction. However, eta-equivalence is provable with the internally defined identity type, using the dependent eliminator mentioned above.)

Arguably, negatively defined products should be naturally expressed as coinductive types, but this is not exactly the case for the presentation of coinductive types used in Coq.

Positive versus negative

In ordinary “nonlinear” type theory, the positive and negative product types are equivalent. They manifestly have the same constructor, while we can define the eliminators in terms of each other as follows:

\begin{aligned} \pi_1 p &\;\coloneqq\; let (x,y) = p in x\\ \pi_2 p &\;\coloneqq\; let (x,y) = p in y\\ let (x,y) = p in c &\;\coloneqq\; c[\pi_1 p / x, \pi_2 p / y] \end{aligned}

It is obvious that the $\beta$-reduction rules in the two cases correspond; see below for $\eta$-conversion.

In dependent type theory, in order to recover the dependent eliminator for the positive product type from the eliminators for the negative product type, we need the latter to satisfy the $\eta$-conversion rule so as to make the above definition well-typed. It is sufficient to have the $\eta$-conversion up to propositional equality, however, if we are willing to insert a substitution along such an equality in the definition of the dependent eliminator. Conversely, the dependent eliminator for the positive product allows us to prove a propositional version of the negative $\eta$-conversion (without assuming the positive $\eta$-conversion). See propositional eta-conversions.

Now from $\eta$-conversion for the negative product, we can also derive

\begin{aligned} let (x,y) = p in c[(x,y)/z] &\;\coloneqq\; c[(\pi_1 p,\pi_2 p)/z]\\ &\;\to_\eta\; c[p/z] \end{aligned}

so the defined positive product also satisfies its $\eta$-conversion, which will be definitional or propositional according to that of the negative product.

On the other hand, if the positive product has a definitional $\eta$-conversion, then for the defined negative product we have

\begin{aligned} (\pi_1 p, \pi_2 p) &\;\coloneqq\; (let (x,y) = p in x, let (x,y) = p in y)\\ &\;\leftarrow_\eta\; (let (x',y') = p in \;( let (x,y) = (x',y') in x , let (x,y) = (x',y') in y )\\ &\;\to_\beta\; let (x',y') = p in (x',y')\\ &\;\to_\eta\; p \end{aligned}

Note that this involves a beta-reduction step and also a “backwards” $\eta$-reduction step. So from positive $\eta$ reduction we cannot derive negative $\eta$-reduction, only negative $\eta$-equivalence. (However, the directionality of $\eta$-reduction is somewhat questionable anyway.)

In conclusion, we have:

• In non-dependent type theory, positive and negative products are equivalent, as are their definitional $\beta$-reduction rules.

• In dependent type theory with identity types, improving the positive eliminator to a dependent eliminator is equivalent to asserting propositional versions of either $\eta$-conversion rule.

• In any case, the two definitional $\eta$-conversion rules also correspond.

It is of importance to note that these translations require the contraction rule and the weakening rule; that is, they duplicate and discard terms. In linear logic these rules are disallowed, and therefore the positive and negative products become different. The positive product becomes “tensor” $A\otimes B$, and the negative product becomes “with” $A \& B$.

Categorical interpretation

Under categorical semantics, product types satisfying both beta and eta conversions correspond to products in a category. More precisely:

• categorical products may be used to interpret product types that validate both beta and eta rules, while

• the syntactic category of a type theory with product types has categorical products, as long as the type theory satisfies both beta and eta rules.

Of course, the categorical notion of product matches the negative definition of a product most directly. In linear logic, therefore, the categorical product interprets “with” $\&$, while an additional monoidal structure interprets “tensor” $\otimes$. On the other hand, in a representable cartesian multicategory, the product has a “from the left” universal property which matches the positive definition.

References

A textbook account in the context of programming languages is in section 11 of

Revised on December 4, 2012 21:54:21 by Urs Schreiber (131.174.40.191)