Skip to content
The Lumenary
Grades 9–12Ages 14–18 60 min

Products by maps: a first universal property

A journey on a map is just two functions — latitude and longitude. Turning that observation around describes the set of pairs A×BA \times B without ever looking inside it.

Formally verified · 14 LeanComputationally tested · 1 PythonAI-drafted · awaiting human reviewMathematically reviewed: Awaiting human review

Your guides: Chloe, Margaret, Gideon

MotivationH

A journey is two functions

A minibus leaves Kampala's old taxi park at 7:00 and heads for Entebbe. A phone on the dashboard records where it is every minute: a latitude and a longitude. So the journey is one function

time  ⟶  latitude×longitude,t⟼(lat(t),lon(t)),\text{time} \;\longrightarrow\; \text{latitude} \times \text{longitude}, \qquad t \longmapsto \big(\text{lat}(t), \text{lon}(t)\big),

whose outputs are pairs. But the phone could equally store two separate columns in a spreadsheet: one function t↦lat(t)t \mapsto \text{lat}(t) and another t↦lon(t)t \mapsto \text{lon}(t). Nothing is lost either way. One function into pairs is the same information as two functions.

That modest observation — true for every journey, every spreadsheet with two columns, every point moving in a plane — turns out to describe the set of pairs completely. Mathematicians call this kind of description a universal property, and it is one of the central ideas of modern mathematics. This lesson is your first meeting with one.

IntuitionH

Describing a set from the outside

Usually we describe a set by listing or characterising its elements: A×BA \times B is the set of ordered pairs (a,b)(a, b) with a∈Aa \in A and b∈Bb \in B.

A universal property describes it instead by how it connects to everything else through functions. For A×BA \times B the connections are:

  1. Two functions out of it, the projections, which read off the first and second coordinates.
  2. A rule for functions into it: whenever you have a function to AA and a function to BB from the same set XX, they combine into exactly one function from XX to A×BA \times B that "projects back" to them.
DefinitionsH

Projections, pairing and the universal property

Throughout, AA and BB are sets. Recall from Composition that g∘fg \circ f means "first ff, then gg".

Definition— projections

The projections of A×BA \times B are the functions

πA:A×B→A,πA(a,b)=a,πB:A×B→B,πB(a,b)=b.\pi_A : A \times B \to A, \quad \pi_A(a, b) = a, \qquad\qquad \pi_B : A \times B \to B, \quad \pi_B(a, b) = b.

Definition— pairing

Let XX be a set, and let f:X→Af : X \to A and g:X→Bg : X \to B. Their pairing is the function

⟨f,g⟩:X→A×B,⟨f,g⟩(x)=(f(x),g(x)).\langle f, g \rangle : X \to A \times B, \qquad \langle f, g \rangle(x) = \big(f(x), g(x)\big).

Feeding the pairing into a projection gives back the original functions: for every x∈Xx \in X,

(πA∘⟨f,g⟩)(x)=πA(f(x),g(x))=f(x),(πB∘⟨f,g⟩)(x)=g(x).(\pi_A \circ \langle f, g \rangle)(x) = \pi_A\big(f(x), g(x)\big) = f(x), \qquad (\pi_B \circ \langle f, g \rangle)(x) = g(x).

So πA∘⟨f,g⟩=f\pi_A \circ \langle f, g \rangle = f and πB∘⟨f,g⟩=g\pi_B \circ \langle f, g \rangle = g. A function h:X→Ph : X \to P that satisfies equations like these is called compatible with ff and gg.

Definition— product (universal property)

Let PP be a set with two functions p:P→Ap : P \to A and q:P→Bq : P \to B. We say that (P,p,q)(P, p, q) is a product of AA and BB, or has the universal property of the product, if:

for every set XX and every pair of functions f:X→Af : X \to A, g:X→Bg : X \to B, there is exactly one function h:X→Ph : X \to P with

p∘h=fandq∘h=g.p \circ h = f \qquad \text{and} \qquad q \circ h = g.

"Exactly one" packs in two demands. Existence: at least one such hh. Uniqueness: no more than one. Both matter, as the non-examples below show.

A universal property, in general, describes an object by how it relates, through maps, to all other objects of the same kind. The product is the first and simplest example; you will meet many more.

Explore

The picture, and two explorations

The universal property is usually drawn as a diagram. The dashed arrow is the one whose existence and uniqueness are claimed; the two triangles commute, meaning that following the arrows along either route gives the same function.

XX
A×BA \times B
AA
BB
ff
gg
⟨f,g⟩\langle f, g \rangle
πA\pi_A
πB\pi_B
For every XX, ff and gg there is exactly one dashed arrow making both triangles commute: πA∘⟨f,g⟩=f\pi_A \circ \langle f, g \rangle = f and πB∘⟨f,g⟩=g\pi_B \circ \langle f, g \rangle = g.

In the first exploration, ZZ has three elements, AA is a set of two colours and B={1,2,3}B = \{1, 2, 3\}. Choose ff and gg, then try to build a function h:Z→A×Bh : Z \to A \times B that projects back to them. Try hard to find a second one that works. Why can't you?

The product, by its maps

Choose maps f : Z → A and g : Z → B. Then try to build a map h : Z → A × B that projects back to f and g.

f : Z → A

g : Z → B

⟨f, g⟩ : Z → A × B

p ↦ (red, 2) q ↦ (blue, 2) r ↦ (red, 3)

Your turn: choose h(p), h(q), h(r) by clicking cells.

A × B123
red
blue

In the second, a point moves in the plane. Its position at time tt is the pair (cos⁡(at),sin⁡(bt))\big(\cos(at), \sin(bt)\big): one function of tt into R×R\R \times \R, built by pairing two functions of tt into R\R. Change aa and bb and watch how the two coordinate functions together determine the whole curve — and how the curve determines them back.

One curve = two coordinate functions

A point moves along the curve as t changes: x and y are both functions of t.

  • t ↦ (cos at, sin bt)
  • (0.707, 1)
Worked examplesH

Examples and non-examples

Example— Computing a pairing

Let X={1,2,3}X = \{1, 2, 3\}, A={red,blue}A = \{\text{red}, \text{blue}\} and B=ZB = \Z. Define f(1)=redf(1) = \text{red}, f(2)=f(3)=bluef(2) = f(3) = \text{blue}, and g(n)=n2g(n) = n^2. Then

⟨f,g⟩(1)=(red,1),⟨f,g⟩(2)=(blue,4),⟨f,g⟩(3)=(blue,9).\langle f, g \rangle(1) = (\text{red}, 1), \qquad \langle f, g \rangle(2) = (\text{blue}, 4), \qquad \langle f, g \rangle(3) = (\text{blue}, 9).

Projecting the three pairs onto their first coordinates gives back red, blue, blue — the values of ff — and onto their second coordinates gives 1,4,91, 4, 9 — the values of gg.

Example— A curve in the plane

The unit circle traced at constant speed is γ:R→R×R\gamma : \R \to \R \times \R, γ(t)=(cos⁡t,sin⁡t)\gamma(t) = (\cos t, \sin t). In the language of this lesson, γ=⟨cos⁡,sin⁡⟩\gamma = \langle \cos, \sin \rangle, and π1∘γ=cos⁡\pi_1 \circ \gamma = \cos, π2∘γ=sin⁡\pi_2 \circ \gamma = \sin. Every parametric curve in the plane is the pairing of its two coordinate functions — that is exactly what "parametric" means.

Example— A product that is not made of pairs

Let A={red,blue}A = \{\text{red}, \text{blue}\} and B={1,2,3}B = \{1, 2, 3\}, and let P={1,2,3,4,5,6}P = \{1, 2, 3, 4, 5, 6\} with

p(k)={redk≤3bluek≥4q(k)=the remainder of k−1 on division by 3, plus 1.p(k) = \begin{cases} \text{red} & k \le 3 \\ \text{blue} & k \ge 4 \end{cases} \qquad\qquad q(k) = \text{the remainder of } k - 1 \text{ on division by } 3, \text{ plus } 1.

The table of (p(k),q(k))(p(k), q(k)) is 1↦(red,1)1 \mapsto (\text{red}, 1), 2↦(red,2)2 \mapsto (\text{red}, 2), 3↦(red,3)3 \mapsto (\text{red}, 3), 4↦(blue,1)4 \mapsto (\text{blue}, 1), 5↦(blue,2)5 \mapsto (\text{blue}, 2), 6↦(blue,3)6 \mapsto (\text{blue}, 3): every combination of a colour and a number occurs for exactly one kk. So, given f:X→Af : X \to A and g:X→Bg : X \to B, the only compatible hh sends xx to the unique kk with p(k)=f(x)p(k) = f(x) and q(k)=g(x)q(k) = g(x). Hence (P,p,q)(P, p, q) is a product of AA and BB — even though its elements are numbers, not pairs.

Example— Swapping the order

B×AB \times A, with p(b,a)=ap(b, a) = a and q(b,a)=bq(b, a) = b, is also a product of AA and BB: the unique compatible hh is x↦(g(x),f(x))x \mapsto \big(g(x), f(x)\big). A product is not "the set of pairs in a particular order"; it is any set with two maps that behave correctly.

Example— Non-example: existence fails

Take P=AP = A, with p=idAp = \mathrm{id}_A and qq the constant function with value 11. If g:X→Bg : X \to B ever takes a value other than 11, there is no compatible hh at all, because q∘hq \circ h is always constant 11. Too few elements: some pairs of maps cannot be combined.

Example— Non-example: uniqueness fails

Take P=A×B×{0,1}P = A \times B \times \{0, 1\}, with pp and qq reading off the first and second coordinates and ignoring the extra bit. Now every pair f,gf, g has a compatible hh — but not just one: at each point xx we may choose the extra bit freely. If XX has 33 elements, there are 23=82^3 = 8 compatible maps. Too many elements: the combination is not determined.

ProofH

The theorems, with proofs

Theorem— Theorem 1 (the product of sets)

A×BA \times B, with the projections πA\pi_A and πB\pi_B, is a product of AA and BB. For f:X→Af : X \to A and g:X→Bg : X \to B, the unique compatible function is ⟨f,g⟩\langle f, g \rangle.

Proof

Existence. We computed above that πA∘⟨f,g⟩=f\pi_A \circ \langle f, g \rangle = f and πB∘⟨f,g⟩=g\pi_B \circ \langle f, g \rangle = g.

Uniqueness. Suppose h:X→A×Bh : X \to A \times B also satisfies πA∘h=f\pi_A \circ h = f and πB∘h=g\pi_B \circ h = g. Fix x∈Xx \in X. The element h(x)h(x) is some pair (a,b)(a, b). Then a=πA(h(x))=f(x)a = \pi_A(h(x)) = f(x) and b=πB(h(x))=g(x)b = \pi_B(h(x)) = g(x), so h(x)=(f(x),g(x))=⟨f,g⟩(x)h(x) = (f(x), g(x)) = \langle f, g \rangle(x). As this holds for every xx, h=⟨f,g⟩h = \langle f, g \rangle.

∎

The uniqueness proof used one fact about pairs: a pair is determined by its two coordinates. That is the whole content of the universal property.

Theorem— Theorem 2 (maps into a product)

For every set XX, the rule h↦(πA∘h,  πB∘h)h \mapsto (\pi_A \circ h, \; \pi_B \circ h) is a bijection from the set of functions X→A×BX \to A \times B to the set of pairs of functions (X→A,  X→B)(X \to A, \; X \to B). Its inverse is (f,g)↦⟨f,g⟩(f, g) \mapsto \langle f, g \rangle.

Proof

Starting from a pair (f,g)(f, g), pairing and then projecting gives (πA∘⟨f,g⟩,πB∘⟨f,g⟩)=(f,g)(\pi_A \circ \langle f, g \rangle, \pi_B \circ \langle f, g \rangle) = (f, g). Starting from hh, projecting and then pairing gives ⟨πA∘h,πB∘h⟩\langle \pi_A \circ h, \pi_B \circ h \rangle, which is compatible with πA∘h\pi_A \circ h and πB∘h\pi_B \circ h — and so is hh itself. By the uniqueness in Theorem 1, ⟨πA∘h,πB∘h⟩=h\langle \pi_A \circ h, \pi_B \circ h \rangle = h. Both round trips are the identity, so the two rules are inverse bijections.

∎

Theorem— Corollary (counting)

If XX, AA and BB are finite, then ∣A×B∣∣X∣=∣A∣∣X∣⋅∣B∣∣X∣|A \times B|^{|X|} = |A|^{|X|} \cdot |B|^{|X|}.

Proof

A function from a set with nn elements to a set with mm elements chooses one of mm outputs for each of the nn inputs, so there are mnm^n of them. The left side counts functions X→A×BX \to A \times B; the right side counts pairs of functions X→AX \to A and X→BX \to B. Theorem 2 matches them up one-to-one, so the two numbers are equal.

∎

Of course ∣A×B∣∣X∣=(∣A∣ ∣B∣)∣X∣=∣A∣∣X∣∣B∣∣X∣|A \times B|^{|X|} = (|A|\,|B|)^{|X|} = |A|^{|X|} |B|^{|X|} also follows from the rule (mn)k=mknk(mn)^k = m^k n^k. The point is that the universal property explains this algebra: the familiar exponent law is a shadow of a bijection between sets of functions.

Now the main theorem: the universal property determines the product up to a unique compatible bijection. We first isolate the key trick.

Theorem— Lemma (the only compatible self-map)

Let (P,p,q)(P, p, q) be a product of AA and BB, and let k:P→Pk : P \to P satisfy p∘k=pp \circ k = p and q∘k=qq \circ k = q. Then k=idPk = \mathrm{id}_P.

Proof

Apply the universal property of PP with X=PX = P, f=pf = p and g=qg = q: there is exactly one h:P→Ph : P \to P with p∘h=pp \circ h = p and q∘h=qq \circ h = q. Both kk and idP\mathrm{id}_P have this property. Since there is only one such map, k=idPk = \mathrm{id}_P.

∎

Theorem— Theorem 3 (uniqueness up to unique bijection)

Let (P,p,q)(P, p, q) be a product of AA and BB. Then φ=⟨p,q⟩:P→A×B\varphi = \langle p, q \rangle : P \to A \times B is a bijection with πA∘φ=p\pi_A \circ \varphi = p and πB∘φ=q\pi_B \circ \varphi = q, and it is the only function P→A×BP \to A \times B compatible with pp and qq.

Proof

φ\varphi is compatible with pp and qq by the definition of pairing, and by Theorem 1 (applied with X=PX = P) it is the only compatible function P→A×BP \to A \times B. It remains to show that φ\varphi is a bijection; we do this by finding an inverse.

Apply the universal property of PP to the set X=A×BX = A \times B and the projections πA\pi_A, πB\pi_B: there is a function ψ:A×B→P\psi : A \times B \to P with p∘ψ=πAp \circ \psi = \pi_A and q∘ψ=πBq \circ \psi = \pi_B.

  • ψ∘φ:P→P\psi \circ \varphi : P \to P is compatible with pp and qq:   p∘(ψ∘φ)=(p∘ψ)∘φ=πA∘φ=p\;p \circ (\psi \circ \varphi) = (p \circ \psi) \circ \varphi = \pi_A \circ \varphi = p, and likewise q∘(ψ∘φ)=qq \circ (\psi \circ \varphi) = q. By the Lemma, ψ∘φ=idP\psi \circ \varphi = \mathrm{id}_P.
  • φ∘ψ:A×B→A×B\varphi \circ \psi : A \times B \to A \times B is compatible with πA\pi_A and πB\pi_B:   πA∘(φ∘ψ)=(πA∘φ)∘ψ=p∘ψ=πA\;\pi_A \circ (\varphi \circ \psi) = (\pi_A \circ \varphi) \circ \psi = p \circ \psi = \pi_A, and likewise for πB\pi_B. The identity of A×BA \times B is also compatible, so by the uniqueness in Theorem 1 (with X=A×BX = A \times B), φ∘ψ=idA×B\varphi \circ \psi = \mathrm{id}_{A \times B}.

So ψ\psi is a two-sided inverse of φ\varphi, and φ\varphi is a bijection.

∎

Note

Testing one point at a time. Take X={⋆}X = \{\star\}, a set with one element. A function {⋆}→P\{\star\} \to P is just a choice of an element of PP. So the universal property for this one XX says: for every a∈Aa \in A and b∈Bb \in B there is exactly one u∈Pu \in P with p(u)=ap(u) = a and q(u)=bq(u) = b — that is, ⟨p,q⟩\langle p, q \rangle is a bijection. Conversely, if ⟨p,q⟩\langle p, q \rangle is a bijection, the universal property holds for every XX (choose h(x)h(x) point by point). So for sets, it is enough to test one-element sets. In other settings, such as groups, "points" do not see everything and the property must really be tested on every XX.

Formal mathematicsF

The universal property in Lean

In Lean we work with types and functions, the type-theoretic counterpart of sets and functions. The product type A × B comes with Prod.fst and Prod.snd, our πA\pi_A and πB\pi_B. Here is the pairing and the two equations, which hold by computation (rfl):

pairLean 4Formally verified
/-- The **pairing** `⟨f, g⟩ : X → A × B` of `f : X → A` and `g : X → B` sends `x` to the
ordered pair `(f x, g x)`. -/
def pair {X A B : Type u} (f : X → A) (g : X → B) : X → A × B :=
  fun x => (f x, g x)
Axioms used: No axiomsformal/Lumenary/IntroUniversalProperties.leanTry it in the Lean web editor
fst_comp_pairLean 4Proved here from basic factsFormally verified
/-- First projection after pairing gives back `f`: `π₁ ∘ ⟨f, g⟩ = f`. Both sides send `x` to
`f x`, so Lean accepts `rfl` ("true by computation"). -/
theorem fst_comp_pair {X A B : Type u} (f : X → A) (g : X → B) :
    Prod.fst ∘ pair f g = f :=
  rfl
Axioms used: No axiomsformal/Lumenary/IntroUniversalProperties.leanTry it in the Lean web editor
snd_comp_pairLean 4Proved here from basic factsFormally verified
/-- Second projection after pairing gives back `g`: `π₂ ∘ ⟨f, g⟩ = g`. -/
theorem snd_comp_pair {X A B : Type u} (f : X → A) (g : X → B) :
    Prod.snd ∘ pair f g = g :=
  rfl
Axioms used: No axiomsformal/Lumenary/IntroUniversalProperties.leanTry it in the Lean web editor

Uniqueness follows the human proof line by line: compare at each x, and use that a pair is determined by its coordinates (Prod.ext).

pair_uniqueLean 4Proved here from basic factsFormally verified
/-- **Uniqueness.** If `h : X → A × B` satisfies `π₁ ∘ h = f` and `π₂ ∘ h = g`, then
`h = ⟨f, g⟩`. Proof, as in the lesson: for each `x`, the pair `h x` has first coordinate
`f x` and second coordinate `g x`, and a pair is determined by its two coordinates
(`Prod.ext`). -/
theorem pair_unique {X A B : Type u} {f : X → A} {g : X → B} (h : X → A × B)
    (h₁ : Prod.fst ∘ h = f) (h₂ : Prod.snd ∘ h = g) : h = pair f g := by
  funext x
  apply Prod.ext
  · -- first coordinates: `(h x).1 = f x`
    exact congrFun h₁ x
  · -- second coordinates: `(h x).2 = g x`
    exact congrFun h₂ x
Axioms used: Quot.soundformal/Lumenary/IntroUniversalProperties.leanTry it in the Lean web editor

Theorem 2 becomes an equivalence — Lean's word for a bijection packaged with its inverse and the two round-trip proofs. Mathlib already contains it, and the counting corollary follows by comparing cardinalities:

mapsIntoProdEquivLean 4Formally verified
/-- Functions `X → A × B` correspond one-to-one with pairs of functions `(X → A, X → B)`.
Forward: compose with the two projections. Backward: pair. The two round trips are the
identity: one by `fst_comp_pair`/`snd_comp_pair`, the other by `pair_unique`. -/
def mapsIntoProdEquiv (X A B : Type u) : (X → A × B) ≃ (X → A) × (X → B) where
  toFun h := (Prod.fst ∘ h, Prod.snd ∘ h)
  invFun fg := pair fg.1 fg.2
  left_inv h := (pair_unique h rfl rfl).symm
  right_inv _ := rfl
Axioms used: Quot.soundformal/Lumenary/IntroUniversalProperties.leanTry it in the Lean web editor
mapsIntoProdEquivLibraryLean 4Applies a library theoremFormally verified
/-- Mathlib already has this correspondence, for dependent functions too:
`Equiv.arrowProdEquivProdArrow`. Here we just specialise it to ordinary functions. -/
def mapsIntoProdEquivLibrary (X A B : Type u) : (X → A × B) ≃ (X → A) × (X → B) :=
  Equiv.arrowProdEquivProdArrow X (fun _ => A) (fun _ => B)
Axioms used: No axiomsformal/Lumenary/IntroUniversalProperties.leanTry it in the Lean web editor
card_maps_into_prodLean 4Proved here from basic factsFormally verified
/-- **Counting.** For finite types, `|A × B|^|X| = |A|^|X| · |B|^|X|`. The left side counts
functions `X → A × B`, the right side counts pairs of functions, and `mapsIntoProdEquiv`
matches them up one-to-one. -/
theorem card_maps_into_prod (X A B : Type u) [Fintype X] [DecidableEq X] [Fintype A]
    [Fintype B] :
    Fintype.card (A × B) ^ Fintype.card X =
      Fintype.card A ^ Fintype.card X * Fintype.card B ^ Fintype.card X := by
  calc Fintype.card (A × B) ^ Fintype.card X
      = Fintype.card (X → A × B) := Fintype.card_fun.symm
    _ = Fintype.card ((X → A) × (X → B)) := Fintype.card_congr (mapsIntoProdEquiv X A B)
    _ = Fintype.card (X → A) * Fintype.card (X → B) := Fintype.card_prod _ _
    _ = Fintype.card A ^ Fintype.card X * Fintype.card B ^ Fintype.card X := by
        rw [Fintype.card_fun, Fintype.card_fun]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/IntroUniversalProperties.leanTry it in the Lean web editor

Now the universal property itself, as a definition. ∃! is Lean's "there exists exactly one".

IsProductLean 4Formally verified
/-- `IsProduct p q` says that the type `P` with maps `p : P → A` and `q : P → B` has the
**universal property of the product**: for every type `X` and every pair of maps
`f : X → A`, `g : X → B` there is **exactly one** `h : X → P` with `p ∘ h = f` and
`q ∘ h = g`. (`∃!` is Lean's "there exists exactly one".) -/
def IsProduct {A B P : Type u} (p : P → A) (q : P → B) : Prop :=
  ∀ (X : Type u) (f : X → A) (g : X → B), ∃! h : X → P, p ∘ h = f ∧ q ∘ h = g
Axioms used: No axiomsformal/Lumenary/IntroUniversalProperties.leanTry it in the Lean web editor
prod_isProductLean 4Proved here from basic factsFormally verified
/-- The set of ordered pairs `A × B`, with its two projections, has the universal property:
existence is the pairing `⟨f, g⟩`, uniqueness is `pair_unique`. -/
theorem prod_isProduct (A B : Type u) : IsProduct (Prod.fst : A × B → A) Prod.snd := by
  intro X f g
  refine ⟨pair f g, ⟨fst_comp_pair f g, snd_comp_pair f g⟩, ?_⟩
  rintro h ⟨h₁, h₂⟩
  exact pair_unique h h₁ h₂
Axioms used: Quot.soundformal/Lumenary/IntroUniversalProperties.leanTry it in the Lean web editor
swap_isProductLean 4Proved here from basic factsFormally verified
/-- A *different* type can be a product of `A` and `B`: `B × A`, with the first map reading
off the **second** coordinate and the second map the **first**. Given `f` and `g`, the unique
compatible map is `x ↦ (g x, f x)`. -/
theorem swap_isProduct (A B : Type u) : IsProduct (Prod.snd : B × A → A) Prod.fst := by
  intro X f g
  refine ⟨fun x => (g x, f x), ⟨rfl, rfl⟩, ?_⟩
  rintro h ⟨h₁, h₂⟩
  funext x
  exact Prod.ext (congrFun h₂ x) (congrFun h₁ x)
Axioms used: Quot.soundformal/Lumenary/IntroUniversalProperties.leanTry it in the Lean web editor

And the main theorem, in two steps exactly as in the proof above:

eq_id_of_isProductLean 4Proved here from basic factsFormally verified
/-- **The key trick.** If `(P, p, q)` is a product and `k : P → P` is compatible with the maps
(`p ∘ k = p` and `q ∘ k = q`), then `k` is the identity. Reason: apply the universal property
with `X = P`, `f = p`, `g = q`. Both `k` and `id` are compatible maps, and there is only one. -/
theorem eq_id_of_isProduct {A B P : Type u} {p : P → A} {q : P → B} (hP : IsProduct p q)
    (k : P → P) (hk₁ : p ∘ k = p) (hk₂ : q ∘ k = q) : k = id := by
  obtain ⟨_, _, huniq⟩ := hP P p q
  have hk : k = _ := huniq k ⟨hk₁, hk₂⟩
  have hid : id = _ := huniq id ⟨rfl, rfl⟩
  exact hk.trans hid.symm
Axioms used: No axiomsformal/Lumenary/IntroUniversalProperties.leanTry it in the Lean web editor
isProduct_bijectiveLean 4Proved here from basic factsFormally verified
/-- **A product is determined up to a unique compatible bijection.** If `(P, p, q)` has the
universal property, then `⟨p, q⟩ : P → A × B` is a bijection. (It is compatible with the maps
by `fst_comp_pair`/`snd_comp_pair`, and it is the *only* compatible map by `pair_unique`.)

Proof, as in the lesson. The universal property of `P`, applied to the projections of `A × B`,
gives `ψ : A × B → P` with `p ∘ ψ = π₁` and `q ∘ ψ = π₂`. Then `ψ ∘ ⟨p, q⟩ : P → P` is
compatible with `p` and `q`, so it is the identity by `eq_id_of_isProduct`; and
`⟨p, q⟩ ∘ ψ : A × B → A × B` is compatible with the projections, so it is the identity by
`pair_unique`. A map with a two-sided inverse is a bijection. -/
theorem isProduct_bijective {A B P : Type u} {p : P → A} {q : P → B} (hP : IsProduct p q) :
    Function.Bijective (pair p q) := by
  obtain ⟨ψ, ⟨hψ₁, hψ₂⟩, _⟩ := hP (A × B) (Prod.fst : A × B → A) (Prod.snd : A × B → B)
  rw [Function.bijective_iff_has_inverse]
  refine ⟨ψ, ?_, ?_⟩
  · -- `ψ ∘ ⟨p, q⟩ = id` on `P`
    have h : ψ ∘ pair p q = id := by
      apply eq_id_of_isProduct hP
      · calc p ∘ (ψ ∘ pair p q) = (p ∘ ψ) ∘ pair p q := rfl
          _ = Prod.fst ∘ pair p q := by rw [hψ₁]
          _ = p := fst_comp_pair p q
      · calc q ∘ (ψ ∘ pair p q) = (q ∘ ψ) ∘ pair p q := rfl
          _ = Prod.snd ∘ pair p q := by rw [hψ₂]
          _ = q := snd_comp_pair p q
    exact congrFun h
  · -- `⟨p, q⟩ ∘ ψ = id` on `A × B`
    have h : pair p q ∘ ψ = id := by
      have hu : pair p q ∘ ψ = pair (Prod.fst : A × B → A) (Prod.snd : A × B → B) :=
        pair_unique (pair p q ∘ ψ) hψ₁ hψ₂
      rw [hu]
      rfl
    exact congrFun h
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/IntroUniversalProperties.leanTry it in the Lean web editor

Finally, the two fake products. Each one fails one half of "exactly one":

not_isProduct_emptyLean 4Proved here from basic factsFormally verified
/-- **Existence can fail.** Take `A = B = Unit` (one element each) and `P = Empty`. There is no
map at all from `Unit` to `Empty`, so the pair of maps `Unit → Unit` cannot factor through `P`. -/
theorem not_isProduct_empty :
    ¬ IsProduct (fun e : Empty => (Empty.elim e : Unit)) (fun e : Empty => (Empty.elim e : Unit)) := by
  intro hP
  obtain ⟨h, _, _⟩ := hP Unit id id
  exact (h ()).elim
Axioms used: No axiomsformal/Lumenary/IntroUniversalProperties.leanTry it in the Lean web editor
not_isProduct_boolLean 4Proved here from basic factsFormally verified
/-- **Uniqueness can fail.** Take `A = B = Unit` and `P = Bool` (two elements), with the only
possible maps `P → Unit`. Then *both* constant maps `Unit → Bool` are compatible, so there is
not exactly one. The universal property needs its "exactly". -/
theorem not_isProduct_bool : ¬ IsProduct (fun _ : Bool => ()) (fun _ : Bool => ()) := by
  intro hP
  obtain ⟨_, _, huniq⟩ := hP Unit id id
  have ht : (fun _ : Unit => true) = _ := huniq (fun _ => true) ⟨rfl, rfl⟩
  have hf : (fun _ : Unit => false) = _ := huniq (fun _ => false) ⟨rfl, rfl⟩
  have h : (fun _ : Unit => true) = (fun _ : Unit => false) := ht.trans hf.symm
  exact Bool.noConfusion (congrFun h ())
Axioms used: No axiomsformal/Lumenary/IntroUniversalProperties.leanTry it in the Lean web editor
ComputationC

Counting compatible maps

Counting compatible maps into a candidate productPythonExhaustive finite checkCounterexampleComputationally tested
"""Testing the universal property of the product on small finite sets.

A candidate product is a set P with two maps p : P -> A and q : P -> B.
For every pair of functions f : X -> A and g : X -> B we count the maps
h : X -> P with p(h(x)) = f(x) and q(h(x)) = g(x) for all x, by listing all
maps X -> P. The universal property says the count is always exactly 1.
We test the set of ordered pairs, a 6-element product that is not made of
pairs, and two fakes: one where some counts are 0 (existence fails) and one
where counts are 4 (uniqueness fails). This is exhaustive-finite evidence
for the small sets X used here; the lesson's proof covers every X.

Runs unchanged in the browser (Pyodide) using only the standard library.
"""

from collections import Counter
from itertools import product
import textwrap

A = ("red", "blue")
B = (1, 2, 3)

def all_functions(domain, codomain):
    """Every function domain -> codomain, as a tuple of values in domain order."""
    return list(product(codomain, repeat=len(domain)))

def count_compatible(domain, P, p, q, f, g):
    """Number of h : domain -> P with p(h(x)) = f(x) and q(h(x)) = g(x).

    ``f``, ``g`` are tuples of values (one per element of ``domain``); ``p``,
    ``q`` are dicts on P. Every map h : domain -> P is listed and tested.
    """
    count = 0
    for h in product(P, repeat=len(domain)):
        if all(p[h[i]] == f[i] and q[h[i]] == g[i] for i in range(len(domain))):
            count += 1
    return count

def profile(domain, P, p, q):
    """Counter {number of compatible h: how many pairs (f, g) have it}."""
    fs = all_functions(domain, A)
    gs = all_functions(domain, B)
    return Counter(count_compatible(domain, P, p, q, f, g) for f in fs for g in gs)

def is_product_on(domain, P, p, q):
    """True if every pair (f, g) on ``domain`` has exactly one compatible h."""
    return set(profile(domain, P, p, q)) == {1}

def candidates():
    """The four candidate products (name, P, p, q) studied in the lesson."""
    pairs = list(product(A, B))
    six = list(range(1, 7))
    triples = [(a, b, c) for a, b in pairs for c in (0, 1)]
    return [
        ("ordered pairs A x B", pairs,
         {u: u[0] for u in pairs}, {u: u[1] for u in pairs}),
        ("numbers 1..6", six,
         {k: "red" if k <= 3 else "blue" for k in six},
         {k: (k - 1) % 3 + 1 for k in six}),
        ("A with q constant 1", list(A),
         {a: a for a in A}, {a: 1 for a in A}),
        ("A x B x {0, 1}", triples,
         {u: u[0] for u in triples}, {u: u[1] for u in triples}),
    ]

def main():
    X = ("x", "y")
    print(f"A = {{red, blue}}, B = {{1, 2, 3}}, X = {{x, y}}")
    n_pairs = len(all_functions(X, A)) * len(all_functions(X, B))
    print(f"pairs of functions (f, g): {n_pairs}")
    print("candidate P               |P|  compatible h per (f, g)   product?")
    for name, P, p, q in candidates():
        prof = profile(X, P, p, q)
        if len(prof) == 1:
            counts = "{} for all {}".format(*next(iter(prof.items())))
        else:
            counts = ", ".join(f"{k} for {v}" for k, v in sorted(prof.items()))
        verdict = "yes" if set(prof) == {1} else "no"
        print(f"{name:<25} {len(P):>3}  {counts:<24}  {verdict}")
    print()
    print("Listing maps: |A x B|^|X| = |A|^|X| * |B|^|X|")
    pairs = candidates()[0][1]
    for n in range(5):
        dom = tuple(range(n))
        lhs = len(all_functions(dom, pairs))
        rhs = len(all_functions(dom, A)) * len(all_functions(dom, B))
        print(f"  |X| = {n}: {lhs:>5} maps X -> A x B, {rhs:>5} pairs (f, g)")
    X3 = ("x", "y", "z")
    name, P, p, q = candidates()[1]
    print(f"With |X| = 3, '{name}' still gives one h each time: "
          f"{is_product_on(X3, P, p, q)}")
    print()
    print(textwrap.fill(
        "Epistemic status: exhaustive-finite. Every pair (f, g) and every map "
        "h was checked, but only for X with 2 or 3 elements and these "
        "particular A and B. The universal property is about every set X; "
        "the lesson proves it for ordered pairs, and proves that any two "
        "products are matched by exactly one compatible bijection.",
        width=78,
    ))

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

The two genuine products give 11 for all 3636 pairs. The candidate with too few elements gives 00 for most pairs (existence fails); the one with an extra bit gives 4=224 = 2^2 for every pair (uniqueness fails; with ∣X∣=2|X| = 2 there are two free bits). This is exhaustive-finite evidence: complete for these particular small sets, silent about all others. The proofs above are what cover every XX.

Exercises

Exercises

1. Products by maps: a first universal property

Warm-upHuman

Let X={1,2,3}X = \{1, 2, 3\}, f:X→{red,blue}f : X \to \{\text{red}, \text{blue}\} with f(1)=redf(1) = \text{red} and f(2)=f(3)=bluef(2) = f(3) = \text{blue}, and g:X→Zg : X \to \Z with g(n)=n2g(n) = n^2. What is ⟨f,g⟩(2)\langle f, g \rangle(2)?

Choose one

2. Products by maps: a first universal property

Warm-upHuman

Let ∣X∣=2|X| = 2, ∣A∣=2|A| = 2 and ∣B∣=3|B| = 3. How many functions X→A×BX \to A \times B are there?

3. Products by maps: a first universal property

CoreHuman

Let A=B={0,1}A = B = \{0, 1\}. Which of these (P,p,q)(P, p, q) are products of AA and BB? (Choose all that apply.)

Choose all that apply

4. Products by maps: a first universal property

CoreHuman

In the proof of Theorem 3 we showed that ψ∘φ=idP\psi \circ \varphi = \mathrm{id}_P. Which fact justifies that final equality?

Choose one

5. Products by maps: a first universal property

CoreHuman

Let P=A×B×{0,1}P = A \times B \times \{0, 1\}, with p(a,b,c)=ap(a, b, c) = a and q(a,b,c)=bq(a, b, c) = b. Let XX have 33 elements and fix f:X→Af : X \to A and g:X→Bg : X \to B. How many functions h:X→Ph : X \to P satisfy p∘h=fp \circ h = f and q∘h=gq \circ h = g?

6. Products by maps: a first universal property

CoreFormal

Given p : P → A, q : P → B, f : X → A and g : X → B, which Lean proposition says "there is exactly one hh compatible with ff and gg"?

Choose one

7. Products by maps: a first universal property

CoreComputational

Represent a finite function as a Python dict. Write pairing(f, g), which takes two dicts with the same keys and returns the dict x↦(f(x),g(x))x \mapsto (f(x), g(x)), and components(h), which takes a dict whose values are pairs and returns the two dicts (πA∘h,πB∘h)(\pi_A \circ h, \pi_B \circ h). Check that the two are inverse to each other (Theorem 2).

Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

8. Products by maps: a first universal property

StretchHuman

Let ∣A∣=3|A| = 3 and ∣B∣=4|B| = 4, and suppose a set PP with maps p:P→Ap : P \to A and q:P→Bq : P \to B has the universal property of the product. How many elements must PP have?

9. Products by maps: a first universal property

StretchHuman

Make the positive integers into a category: there is one arrow x→yx \to y exactly when xx divides yy (and no arrow otherwise). A product of 1212 and 1818 is a number PP with arrows P→12P \to 12 and P→18P \to 18 such that every XX with arrows X→12X \to 12 and X→18X \to 18 has an arrow X→PX \to P (uniqueness is automatic, as there is at most one arrow between two numbers). What is PP?

Choose one
Common misconceptionsH

Common misconceptions

Misconception

"The universal property defines some new object, different from A×BA \times B." It describes A×BA \times B by its behaviour. The set of ordered pairs has the property (Theorem 1), and anything else with the property is matched with it by exactly one compatible bijection (Theorem 3).

Misconception

Forgetting the uniqueness part. "There is a compatible hh" is not enough: A×B×{0,1}A \times B \times \{0, 1\} has compatible maps for every f,gf, g but is not a product. Uniqueness is what makes the proof of Theorem 3 work — the Lemma is nothing but uniqueness.

Misconception

"Only the set of ordered pairs is really a product." Any set with two maps having the property serves equally well, like {1,…,6}\{1, \dots, 6\} in the examples, or B×AB \times A with swapped maps. Even "ordered pair" itself is defined in more than one way in set theory (see below); the universal property is what all the definitions agree on.

Misconception

Confusing ⟨f,g⟩\langle f, g \rangle with f×gf \times g. For f:X→Af : X \to A and g:Y→Bg : Y \to B, the map f×g:X×Y→A×Bf \times g : X \times Y \to A \times B sends (x,y)(x, y) to (f(x),g(y))(f(x), g(y)): two inputs, processed separately. The pairing ⟨f,g⟩:X→A×B\langle f, g \rangle : X \to A \times B takes one input and feeds it to both. They are related by ⟨f,g⟩=(f×g)∘Δ\langle f, g \rangle = (f \times g) \circ \Delta, where Δ(x)=(x,x)\Delta(x) = (x, x) (when Y=XY = X).

Misconception

"Unique up to bijection" means "equal". {1,…,6}\{1, \dots, 6\} and A×BA \times B are different sets. What is unique is the compatible bijection between them — so we may treat them as interchangeable, as long as we use that bijection to translate.

ViewpointsH

The same idea, seen by others

Geometry— Coordinates are projections

When Descartes and Fermat put coordinates on the plane, they identified it with R×R\R \times \R: a point is its pair of coordinates, and the two coordinate functions are the projections. A curve γ:I→R2\gamma : I \to \R^2 is the pairing of its coordinate functions, and every statement about the curve can be translated into two statements about real functions. In three dimensions R3=R×R×R\R^3 = \R \times \R \times \R has three projections, and a path in space is three functions of time — exactly what a GPS receiver records (adding altitude).

Topology— Continuity, one coordinate at a time

A map γ:R→R2\gamma : \R \to \R^2 is continuous if and only if both coordinate functions π1∘γ\pi_1 \circ \gamma and π2∘γ\pi_2 \circ \gamma are continuous. So t↦(cos⁡t,sin⁡t)t \mapsto (\cos t, \sin t) is continuous because cos⁡\cos and sin⁡\sin are. This is the universal property again, now for continuous maps: for spaces AA and BB, the product topology on A×BA \times B is chosen precisely so that continuous maps X→A×BX \to A \times B correspond to pairs of continuous maps X→AX \to A, X→BX \to B. (It is the coarsest topology making both projections continuous.) See point-set topology.

Algebra— Direct products of groups

For groups GG and HH, the set G×HG \times H with componentwise operation (g,h)(g′,h′)=(gg′,hh′)(g, h)(g', h') = (gg', hh') is again a group, and a homomorphism K→G×HK \to G \times H is the same as a pair of homomorphisms K→GK \to G and K→HK \to H. For example, n↦(n mod 2, n mod 3)n \mapsto (n \bmod 2, \, n \bmod 3) pairs two homomorphisms Z→Z/2\Z \to \Z/2 and Z→Z/3\Z \to \Z/3; it sends exactly the multiples of 66 to (0,0)(0, 0), and this leads to the Chinese remainder theorem Z/6≅Z/2×Z/3\Z/6 \cong \Z/2 \times \Z/3, an isomorphism you can check in structure-preserving maps.

Probability— Random vectors, and a warning

Two random variables X,Y:Ω→RX, Y : \Omega \to \R on the same sample space pair up into one random vector (X,Y):Ω→R2(X, Y) : \Omega \to \R^2, and every random vector arises this way. But the distributions of XX and YY do not determine the distribution of (X,Y)(X, Y). Toss a fair coin: let X=1X = 1 for heads and 00 for tails, and compare Y=XY = X with Y=1−XY = 1 - X. In both cases YY is a fair 0/10/1 variable, yet (X,Y)(X, Y) takes the values (0,0),(1,1)(0,0), (1,1) in the first case and (0,1),(1,0)(0,1), (1,0) in the second. The universal property is about functions on the same Ω\Omega, not about distributions — which is exactly why independence and correlation are interesting (conditional probability and independence).

Logic— 'And' has the same property

Order propositions by implication. Then P∧QP \wedge Q behaves exactly like a product: R⇒P∧QR \Rightarrow P \wedge Q holds if and only if both R⇒PR \Rightarrow P and R⇒QR \Rightarrow Q hold, and P∧QP \wedge Q implies each of PP and QQ (the "projections"). In a proof assistant such as Lean this is literal: a proof of P∧QP \wedge Q is a pair of proofs, written ⟨hp, hq⟩. See First steps in Lean.

Wonder Trails

Wonder Trails

Set-theoretic connectionH

Set-theoretic connection: what is an ordered pair?

In set theory everything is a set, so an ordered pair must be one too. The standard choice, due to Kazimierz Kuratowski (1921), is

(a,b)={{a},{a,b}}.(a, b) = \{\{a\}, \{a, b\}\}.

One proves that (a,b)=(a′,b′)(a, b) = (a', b') exactly when a=a′a = a' and b=b′b = b' — the one fact our uniqueness proof used. But this is not the only choice: Norbert Wiener proposed a different encoding in 1914, and others work too. Each encoding produces a different set "A×BA \times B", but every one of them satisfies the universal property, so by Theorem 3 they are all matched by unique compatible bijections. The encoding is an implementation; the universal property is the specification.

Category-theoretic connectionH

Products in any category

In a category (see Composition), a product of objects AA and BB is an object PP with arrows p:P→Ap : P \to A, q:P→Bq : P \to B such that for every object XX and arrows f:X→Af : X \to A, g:X→Bg : X \to B there is exactly one arrow h:X→Ph : X \to P with p∘h=fp \circ h = f and q∘h=gq \circ h = g. Our definition is the case of the category of sets, and the proof of Theorem 3 works word for word in every category: any two products of AA and BB are isomorphic by a unique isomorphism compatible with the projections.

The same words describe very different things:

  • In sets: the Cartesian product. In groups: the direct product. In spaces: the product space.
  • In the positive integers ordered by divisibility (an arrow x→yx \to y means xx divides yy), a product of 1212 and 1818 is a number that divides both, and is divisible by every number dividing both: gcd⁡(12,18)=6\gcd(12, 18) = 6.
  • In the subsets of a set ordered by ⊆\subseteq, the product of AA and BB is A∩BA \cap B.

Turning all the arrows around gives the coproduct: in sets, the disjoint union; for divisibility, the least common multiple. These ideas continue in universal properties, products and coproducts and, eventually, the Yoneda lemma, which says that every object is determined up to isomorphism by the maps into it.

History & global context

History and global context

  • Coordinates. Describing a position by two numbers is ancient. Ptolemy's Geography (2nd century, Alexandria) listed places by longitude and latitude; in 9th-century Baghdad, al-Khwārizmī's Book of the Description of the Earth tabulated coordinates for thousands of places; in 3rd-century China, the cartographer Pei Xiu set out principles of mapmaking that included a scale and a rectangular grid. In 17th-century France, René Descartes (La Géométrie, 1637) and Pierre de Fermat turned coordinates into a method for geometry.
  • Ordered pairs as sets. Norbert Wiener (1914) and Kazimierz Kuratowski (1921) showed how to define ordered pairs inside set theory.
  • Universal properties. In the late 1940s, mathematicians began describing constructions by their maps rather than their elements. Pierre Samuel's 1948 paper On universal mappings and free topological groups used "universal mappings"; Saunders Mac Lane's papers on duality for groups (1948–1950) characterised products and free products by such properties, building on the theory of categories that he and Samuel Eilenberg had introduced in 1945. The style was taken up by the Bourbaki group and by Daniel Kan's adjoint functors (1958), and is now everywhere.
Further reading

Further reading

  • F. William Lawvere and Stephen H. Schanuel, Conceptual Mathematics: A First Introduction to Categories (1997; 2nd edition 2009) — products appear early, with many pictures.
  • Eugenia Cheng, The Joy of Abstraction (2022) — a gentle, carefully explained route to universal properties.
  • Tom Leinster, Basic Category Theory (2014) — universal properties in the introduction, products in chapter 5.
  • Saunders Mac Lane, Categories for the Working Mathematician (1971; 2nd edition 1998), for the professional account.