Lecture 12: binary products and sums of sets; families of sets; products and sums of families of sets [01GQ]
- November 15, 2026
- Jon Sterling
Generative AI was not used to write these lecture notes.
Binary product and sum of sets [01HE]
- November 28, 2026
- Jon Sterling
Suppose that we have a pair of sets A,B. Unless we have introduced A and B as subsets of fixed set, it does not make sense to speak of the intersection or the union of A and B. What we can do, however, is speak of the product A\times B and the sum A+B of A and B; these operations in the world of sets have similar properties to intersections and unions in the world of subsets.
Axiom Binary product [01HF]
- November 28, 2026
- Jon Sterling
For any two sets A and B, we may form a third set A\times B called the product of A and B which consists precisely of pairs (a,b) of elements a:A and b:B. In other words:
- To construct an element of A\times B, you first construct an element of A and then you construct an element of B; if the two elements constructed are called a:A and b:B, we will write {\mathopen {}\left (a,b\right )\mathclose {}}:A\times B to denote the resultant pair.
- When using an assumed element x:A\times B, you may use its first component \pi _1{\mathopen {}\left (x\right )\mathclose {}}:A and its second component \pi _2{\mathopen {}\left (x\right )\mathclose {}}:B.
Callback Binary products in OCaml [01HH]
- November 28, 2026
- Jon Sterling
In OCaml, the binary product of two types s and t is written s * t. Given x:s and y:t, we can form the pair (x, y) : s * t. Given an element p : s * t, we may write fst p : s and snd p : t for its two components.
Axiom Binary sum (coproduct) [01HG]
- November 28, 2026
- Jon Sterling
For any two sets A and B, we may form a third set A+B called the sum of A and B, also called their coproduct, which consists precisely of either \iota _1{\mathopen {}\left (a\right )\mathclose {}} for a:A or \iota _2{\mathopen {}\left (b\right )\mathclose {}} for b:B. In other words:
- To construct an element of A\times B, you may either construct an element of A or you may construct an element of B. In the first case, if we choose to construct a:A the resultant element of A+B is written \iota _1{\mathopen {}\left (a\right )\mathclose {}}; in the second case, if we choose to construct b:B, the resultant element of A+B is written \iota _2{\mathopen {}\left (b\right )\mathclose {}}.
-
To use an assumed element x:A+B to carry out a task, you must consider two cases separately:
- You first assume a:A such that x = \iota _1{\mathopen {}\left (a\right )\mathclose {}} and then carry out the task under this assumption.
- You separately assume b:B such that x = \iota _2{\mathopen {}\left (b\right )\mathclose {}} and then carry out the task under this assumption.
Callback Binary sums in OCaml [01HI]
- November 28, 2026
- Jon Sterling
In OCaml, the binary sum of two types can be implemented as follows:
type ('a, 'b) coprod =
| Inl of 'a
| Inr of 'bThen the sum of two types s,t is written (s, t) coprod. Given x:s we may construct Inl x : (s, t) coprod, and similarly given y:t we may construct Inr y : (s, t) coprod.
We may use an element z : (s, t) coprod to produce an element of type r by case analysis:
match z with | Inl x -> (* use x:s to produce an element of r *) | Inl y -> (* use y:t to produce an element of r *)
Distributivity of products over sums; semiring vibes [01HJ]
- November 28, 2026
- Jon Sterling
The notation of \times and + for products and sum is not a coincidence. In fact, the collection of all sets under product and sum forms something like a commutative semiring, except that the equational laws of a semiring have to be replaced with isomorphism (which we will learn about later). Since we have already seen the concept of cardinality, we can at least make the following observations:
\begin {aligned} \mathord {\#}{\mathopen {}\left (A\times {\mathopen {}\left (B\times C\right )\mathclose {}}\right )\mathclose {}} &= \mathord {\#}{{\mathopen {}\left ({\mathopen {}\left (A\times B\right )\mathclose {}}\times C\right )\mathclose {}}} \\ \mathord {\#}{\mathopen {}\left (A+{\mathopen {}\left (B+C\right )\mathclose {}}\right )\mathclose {}} &= \mathord {\#}{{\mathopen {}\left ({\mathopen {}\left (A+B\right )\mathclose {}}+C\right )\mathclose {}}} \\ \mathord {\#}{\mathopen {}\left ({\mathopen {}\left \{*\right \}\mathclose {}}\times A\right )\mathclose {}} &= \mathord {\#}{A} \\ \mathord {\#}{\mathopen {}\left (\varnothing +A\right )\mathclose {}} &= \mathord {\#}{A} \\ \mathord {\#}{A\times B} &= \mathord {\#}{B\times A} \\ \mathord {\#}{\mathopen {}\left (A+B\right )\mathclose {}} &= \mathord {\#}{\mathopen {}\left (B+A\right )\mathclose {}} \\ \mathord {\#}{\mathopen {}\left (A\times {\mathopen {}\left (B+C\right )\mathclose {}}\right )\mathclose {}} &= \mathord {\#}{\mathopen {}\left ({\mathopen {}\left (A\times B\right )\mathclose {}}+{\mathopen {}\left (A\times C\right )\mathclose {}}\right )\mathclose {}} \end {aligned}So the set with a single element is the neutral set for the binary product operation, and the empty set is the neutral set for the binary sum operation. One way to understand what is happening here is to say that the collection of cardinalities forms something like a commutative semiring (but we must state this carefully, because there cannot exist a set of all cardinalities).
Once we learn about isomorphism, we will be able to see that the semiring structure of cardinalities shown above is the shadow of a richer structure on sets. If you become a mathematician, you may in the future refer to this semiring-like structure of sets under product and sum as a two dimensional semiring or 2-semiring for short. But you don’t need to know or use that terminology to work with these basic operations.
Families of sets [01HD]
- November 28, 2026
- Jon Sterling
In Lecture 11, we introduced the concept of a family of subsets of a fixed set. What if we want to talk about a bunch of sets that are not necessarily related? For this we need a more general concept, the family of sets.
Definition Family of sets [01HB]
- November 28, 2026
- Jon Sterling
A family of sets is given by a set I of indices together with an assignment of a set A_i to each i:I.
A family of sets may be written in several ways; for example:
{\mathopen {}\left (A_i\right )\mathclose {}}_{i:I} \qquad {\mathopen {}\left (A_i\mid i:I\right )\mathclose {}} \qquad i:I\mapsto A_iExample Families of subsets as families of sets [01HC]
- November 28, 2026
- Jon Sterling
Any be a family of subsets {\mathopen {}\left (U_i\right )\mathclose {}}_{i:I} of a fixed set A can be viewed on its own as a family of sets, without reference to A. In particular, we map each i:I to the set U_i.
“Big” operations on sets: product and sum [01HK]
- November 28, 2026
- Jon Sterling
Because the individual sets A_i, A_j in a family of sets {\mathopen {}\left (A_i\right )\mathclose {}}_{i:I} are not necessarily related to each other, it does not make sense to speak of the big intersection \bigcap _{i:I}A_i or big union \bigcup _{i:I}A_i. These only make sense when we understand {\mathopen {}\left (A_i\right )\mathclose {}}_{i:I} to be a family of subsets of some fixed set.
We can, however, talk about the product and sum of an entire family of sets, and these will generalise binary products and binary sums in the same way that intersections and unions of families of subsets generalise binary intersections and binary unions respectively.
Axiom The product of a family of sets [01HL]
- November 28, 2026
- Jon Sterling
For any family of sets {\mathopen {}\left (A_i\right )\mathclose {}}_{i:I} we may form a set \prod _{i:I}A_i called its product whose elements consist of mappings that assign to each index i:I an element a_i:A_i of the corresponding component of the family.
These mappings may be written in a number of styles:
\lambda i:I\mathpunct {.}a_i \qquad {\mathopen {}\left (a_i\right )\mathclose {}}_{i:I} \qquad i:I\mapsto a_iIn other words:
- To construct an element of the product \prod _{i:I}A_i, you assume an arbitrary index i:I and construct under this assumption an element of A_i.
- To use an element of the product f : \prod _{i:I}A_i, you may pick a specific index k:I and then use f(k) : A_k.
Example Binary products in terms of big products [01HM]
- November 28, 2026
- Jon Sterling
Let A and B be two sets. We can express the binary product A\times B in terms of products of families of sets by considering the following family of sets i:{\mathopen {}\left [2\right ]\mathclose {}}\mapsto \begin {cases} A & \text {if } i=0\\ B & \text {if } i=1 \end {cases} indexed in the standard finite set with two elements {\mathopen {}\left [2\right ]\mathclose {}}. In particular, the big product \prod _{i:{\mathopen {}\left [2\right ]\mathclose {}}} \begin {cases} A & \text {if } i=0\\ B & \text {if } i=1 \end {cases} consists of assignments that must send 0 to an element of A and 1 to an element of B. This is, up to a change of notation, the same as an element of A\times B.
Axiom The sum of a family of sets [01HN]
- November 28, 2026
- Jon Sterling
For any family of sets {\mathopen {}\left (A_i\right )\mathclose {}}_{i:I} we may form a set \sum _{i:I}A_i called its sum whose elements consist of pairs (k,a) where k:I is a specified index and a:A_k is an element of the component of the family at that index. In other words:
- To construct an element of the sum \sum _{i:I}A_i you first choose an index k:I and then construct an element a:A_k of the corrseponding component. The resulting element of the sum is written {\mathopen {}\left (k,a\right )\mathclose {}}.
- When using an element x:\sum _{i:I}A_i, you may make use of its index \pi _1{\mathopen {}\left (x\right )\mathclose {}}:I and its value \pi _2{\mathopen {}\left (x\right )\mathclose {}} : A_{\pi _1{\mathopen {}\left (x\right )\mathclose {}}}. Equivalently, you may assume some k:I and a:A_k such that x = {\mathopen {}\left (k,a\right )\mathclose {}}.
Sometimes you may see \sum _{i:I} A_i written as \coprod _{i:I}A_i and pronounced coproduct; both notations are valid!
There is an analogue of Example [01HM] for sums:
Example Binary sums in terms of big sums [01HO]
- November 28, 2026
- Jon Sterling
Let A and B be two sets. We can express the binary sum A+B in terms of sums of families of sets by considering the following family of sets i:{\mathopen {}\left [2\right ]\mathclose {}}\mapsto \begin {cases} A & \text {if } i=0\\ B & \text {if } i=1 \end {cases} indexed in the standard finite set with two elements {\mathopen {}\left [2\right ]\mathclose {}}. In particular, the big sum \sum _{i:{\mathopen {}\left [2\right ]\mathclose {}}} \begin {cases} A & \text {if } i=0\\ B & \text {if } i=1 \end {cases} consists of pairs either of the form {\mathopen {}\left (0,a\right )\mathclose {}} with a:A or of the form {\mathopen {}\left (1,b\right )\mathclose {}} with b:B. This is, up to a change of notation, the same as an element of A+B.
There is something a little bit confusing about big sums; although we have just shown that they directly generalise binary sums, insofar as they consist of pairs there is a sense that they also generalise binary products. There is nothing wrong with that! The same concept can generalise two different concepts in different ways. But let’s see how it works:
Example Binary products in terms of big sums; the “dependent pair” notation [01HP]
- November 28, 2026
- Jon Sterling
Let A and B be two sets. We may construct from B an A-indexed family of sets whose component at every a:A is simply the same set B. We may write this as {\mathopen {}\left (B\right )\mathclose {}}_{a:A} or a:A\mapsto B. Then the sum of this family, written \sum _{a:A}B, consists of pairs {\mathopen {}\left (a,b\right )\mathclose {}} where a:A and b:B. Therefore an element of \sum _{a:A}B carries precisely the same data as an element of A\times B.
For this reason, when {\mathopen {}\left (B_a\right )\mathclose {}}_{a:A} is a family of sets, sometimes people will refer to the sum \sum _{a:A}B_a as the “dependent pair type” and may even write {\mathopen {}\left (a:A\right )\mathclose {}}\times B_a instead of \sum _{a:A}B_a.
Something analogous to Example [01HP] happens for products.
Example Function sets in terms of big products; the “dependent function” notation [01HQ]
- November 28, 2026
- Jon Sterling
Let A and B be two sets. Then the product \prod _{a:A}B of the family {\mathopen {}\left (B\right )\mathclose {}}_{a:A} that assigns to each a:A the same set B consists of mappings that assign to each a:A an element of B. These are nothing more than functions from A to B: so we may, if we like, construct the set of functions A\to B as the product \prod _{a:A}B.
For this reason, when {\mathopen {}\left (B_a\right )\mathclose {}}_{a:A} is a family of sets, some may refer to \prod _{a:A}B_a as the “dependent function type” and write {\mathopen {}\left (a:A\right )\mathclose {}}\to B_a instead of \prod _{a:A}B_a.
Example Disjoint unions and sums [01HR]
- November 28, 2026
- Jon Sterling
Let U,V are two disjoint subsets of a fixed set A. Then we may form their union U \cup V; if we view the union U\cup V as a set on its own, forgetting A, we can see that it is very much like the sum U+V. In fact, up to a change in notation, the union of two disjoint subsets is their sum; we can translate between them as follows:
\begin {aligned} U \cup V &\to U+V \\ x &\mapsto \begin {cases} \iota _1{\mathopen {}\left (x\right )\mathclose {}} & \text {if } x\in U\\ \iota _2{\mathopen {}\left (x\right )\mathclose {}} & \text {if } x\in V \end {cases} \end {aligned}Conversely:
\begin {aligned} U+V &\to U\cup V\\ {\mathopen {}\left (i,x\right )\mathclose {}} &\mapsto x \end {aligned}Dropping the index in the backward translation above is OK because it is uniquely determined by the disjointness of U and V.
The same idea works for families. In particular, let {\mathopen {}\left (U_i\right )\mathclose {}}_{i:I} be a family of subsets of a fixed set A that is pairwise disjoint in the sense that \forall i,j:I\mathpunct {.} i \not =j \implies U_i \cap U_j = \varnothing \text {,} or, equivalently, \forall x:A\mathpunct {.} \forall i,j:I\mathpunct {.} x\in U_i\cap U_j \implies i=j \text {.}
Then the big union \bigcup _{i:I}U_i amounts, as a set, to the big sum \sum _{i:I}U_i up to a back-and-forth translation:
\begin {aligned} \bigcup _{i:I}U_i &\to \sum _{i:I} U_i \\ x&\mapsto \begin {cases} {\mathopen {}\left (k,x\right )\mathclose {}} &\textbf {where } \forall i:I\mathpunct {.} {\mathopen {}\left (x\in U_i \implies i=k\right )\mathclose {}} \end {cases} \\[18pt] \sum _{i:I}U_i &\to \bigcup _{i:I}U_i\\ {\mathopen {}\left (i,x\right )\mathclose {}} &\mapsto x \end {aligned}Sometimes you will hear mathematicians speak of “disjoint unions” of unrelated sets; in these cases, you should understand them to mean “sums” instead. It is still, however, very useful to know that when you really do have a union that is disjoint, you can view it as a sum, and vice versa.
Remark Families and their products and sums in programming languages? [01HS]
- November 28, 2026
- Jon Sterling
It has been encouraging to see we can think about both binary products and binary sums in terms of OCaml language features:
Unfortunately there is no such analogue to the concept of a family of sets (A_i)_{i:I} and its product \prod _{i:I}A_i and sum \sum _{i:I}A_i in a language like OCaml. That is because families of sets correspond to dependent types, which are not yet widespread in mainstream programming languages. Nonetheless, you can try them out in more obscure languages like Lean, Rocq, Agda, and Idris. From a dependently typed programmer’s perspective, it is useful to keep in mind the following remarks:
Cardinality and products and sums [01HT]
- November 28, 2026
- Jon Sterling
We have the following laws of cardinality for products and sums of families of sets, which explains the chosen notations:
\begin {aligned} \mathord {\#}{\prod _{i:I}A_i} &= \prod _{i:I} \mathord {\#}{A_i} \\ \mathord {\#}{\sum _{i:I}A_i} &= \sum _{i:I} \mathord {\#}{A_i} \end {aligned}In the case of binary products and binary sums we have the following:
\begin {aligned} \mathord {\#}{\mathopen {}\left (A\times B\right )\mathclose {}} &= \mathord {\#}{A}\times \mathord {\#}{B} \\ \mathord {\#}{\mathopen {}\left (A+B\right )\mathclose {}} &= \mathord {\#}{A} + \mathord {\#}{B} \end {aligned}Recalling the reconstruction of function sets in terms of products, we have:
\mathord {\#}{\mathopen {}\left (A\to B\right )\mathclose {}} = \mathord {\#}\prod _{a:A}B = \prod _{a:A}\mathord {\#}{B} = {\mathord {\#}{B}}^{\mathord {\#}{A}}