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.