Foundations to Frontier
Tests
A. Mathematical Foundations › A1 Prerequisites and Mathematical Thinking

Sets, Functions, Relations and Cardinality

The four words every other part of mathematics, AI and robotics is written in. We start with toy boxes and end with the theory of learning.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Sets are boxes of things

Imagine a toy box. Inside are a ball, a teddy bear and a car. In maths, a box of things like this is called a set.

Two simple rules make a set a set:

  • No copies. A box with two identical balls counts the ball only once.
  • Order doesn’t matter. Ball, bear, car is the same box as car, ball, bear.

You can ask one question about any set: “Is this thing inside?” Is the bear in the box? Yes. Is a banana in the box? No.

Sets can overlap. Some things fly, and some things are alive. A bird is in both groups. A plane only flies. A dog is only alive. A rock is in neither. Try it:

Set playground: click a button to light up a set
Everything in our worldFliesAlive🐦🦋🐝✈️🪁🐶🌳🐟🚗🪨
Fly AND alive = { 🐦, 🦋, 🐝 }→ 3 things

Functions are machines

A function is like a machine: you put something in, and exactly one thing comes out. Put in 3 to a “double it” machine and 6 comes out, every single time.

A machine that sometimes gives 6 and sometimes gives 7 for the same input is not a function. Try the moody machine below and catch it misbehaving:

The function machine
3➜⚙️ Double it➜?

Relations are lines between things

A relation is a set of connections. Draw a line from each child to every ice cream flavour they like. Some children like many flavours, some like none. That bunch of lines is a relation. A function is a special relation where every child points to exactly one favourite.

Cardinality is “how many?”

The cardinality of a set is just how many things are in it. Here’s a clever trick: you can tell if two groups are the same size without counting. If every child sits on exactly one chair and no chair is left empty, there are as many children as chairs. Mathematicians use this matching trick to compare even infinitely big sets.

Why AI cares

An AI that recognises photos is a function. In goes a picture, out comes one answer, like “cat”. The set of all possible pictures is huge, and the set of answers is small.

In robotics

A robot’s map is often a set: the set of squares on the floor that are blocked. To plan a path, the robot only moves through squares that are not in that set.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A box holds a red ball, a red ball and a blue ball. As a set, how many different things are in it?
  2. 2. A machine gives 10 when you put in 5, but later gives 12 for the same 5. Is it a function?
  3. 3. A bee flies and is alive. Where does it go in the playground?

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

Writing sets down

We write a set with curly brackets and list its members: A={1,2,3,4}A = \{1, 2, 3, 4\}. The symbol ∈\in means “is a member of”, and ∉\notin means “is not”:

3∈A7∉A3 \in A \qquad 7 \notin A
Symbol Read it as Example with A={1,2,3,4}, B={3,4,5}A=\{1,2,3,4\},\ B=\{3,4,5\}
A∪BA \cup B union: in A or B (or both) {1,2,3,4,5}\{1,2,3,4,5\}
A∩BA \cap B intersection: in A and B {3,4}\{3,4\}
A∖BA \setminus B difference: in A but not in B {1,2}\{1,2\}
A⊆CA \subseteq C A is a subset of C: everything in A is also in C {1,2}⊆A\{1,2\} \subseteq A
∅\varnothing the empty set, with nothing in it A∩{9}=∅A \cap \{9\} = \varnothing
AcA^c complement: everything (in the universe UU) not in A if U={1,…,6}U=\{1,\dots,6\}, Ac={5,6}A^c=\{5,6\}
∣A∣\lvert A \rvert cardinality: how many members ∣A∣=4\lvert A \rvert = 4

Here’s the same playground, now with the maths names:

Set playground: click a button to light up a set
U (everything)A: FliesB: Alive🐦🦋🐝✈️🪁🐶🌳🐟🚗🪨
A ∩ B = { 🐦, 🦋, 🐝 }→ |A ∩ B| = 3

Worked example: counting a union

How many numbers are in A∪BA \cup B? It’s tempting to add ∣A∣+∣B∣=4+3=7\lvert A \rvert + \lvert B \rvert = 4 + 3 = 7, but that counts 3 and 4 twice. Subtract the overlap once:

∣A∪B∣=∣A∣+∣B∣−∣A∩B∣=4+3−2=5\lvert A \cup B \rvert = \lvert A \rvert + \lvert B \rvert - \lvert A \cap B \rvert = 4 + 3 - 2 = 5

Check by listing: {1,2,3,4,5}\{1,2,3,4,5\} has 5 members. ✅ This is called the inclusion–exclusion rule.

Functions

A function f:A→Bf: A \to B takes every member of the set AA (the domain) to exactly one member of BB (the codomain). For example, f(x)=2x+1f(x) = 2x + 1 on the domain {0,1,2,3}\{0,1,2,3\}:

xx 0 1 2 3
f(x)f(x) 1 3 5 7

The outputs that actually appear, {1,3,5,7}\{1,3,5,7\}, are called the range.

Pairs and relations

An ordered pair (a,b)(a, b) is two things where order matters: (1,2)≠(2,1)(1,2) \ne (2,1). The Cartesian product A×BA \times B is the set of all pairs you can make:

{1,2}×{x,y}={(1,x), (1,y), (2,x), (2,y)}\{1,2\} \times \{x,y\} = \{(1,x),\ (1,y),\ (2,x),\ (2,y)\}

A relation from AA to BB is any set of these pairs. “Is less than” on {1,2,3}\{1,2,3\} is the relation {(1,2),(1,3),(2,3)}\{(1,2),(1,3),(2,3)\}.

Why AI cares

A dataset for machine learning is a set of pairs (x,y)(x, y): an input xx (say, a photo) and its correct label yy (say, “cat”). Training a model means finding a function ff with f(x)≈yf(x) \approx y on those pairs.

📝 Quick check (Level 1)
0/4 answered
  1. 1. A = {2, 4, 6} and B = {4, 5, 6}. What is A ∩ B?
  2. 2. Using the same sets, what is |A ∪ B|?
  3. 3. How many pairs are in {1, 2, 3} × {a, b}?
  4. 4. f(x) = x² on the domain {−2, −1, 0, 1, 2}. What is the range?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

Formal definitions

Definition

Set-builder notation describes a set by a rule: {x∈U:P(x)}\{x \in U : P(x)\} is the set of members of UU for which the statement P(x)P(x) is true. For example, {n∈Z:n is even}\{n \in \mathbb{Z} : n \text{ is even}\}.

The standard number sets are N={0,1,2,… }\mathbb{N} = \{0, 1, 2, \dots\} (natural numbers; some books start at 1), Z\mathbb{Z} (integers), Q\mathbb{Q} (fractions), and R\mathbb{R} (real numbers), with N⊆Z⊆Q⊆R\mathbb{N} \subseteq \mathbb{Z} \subseteq \mathbb{Q} \subseteq \mathbb{R}. Rn\mathbb{R}^n is the set of lists of nn real numbers. That’s where data points, robot joint angles, and neural network weights live.

The power set P(A)\mathcal{P}(A) is the set of all subsets of AA:

P({a,b})={∅, {a}, {b}, {a,b}},∣P(A)∣=2∣A∣\mathcal{P}(\{a,b\}) = \{\varnothing,\ \{a\},\ \{b\},\ \{a,b\}\}, \qquad \lvert \mathcal{P}(A) \rvert = 2^{\lvert A \rvert}

The algebra of sets

Law Statement
Commutative A∪B=B∪A,A∩B=B∩AA \cup B = B \cup A, \quad A \cap B = B \cap A
Associative (A∪B)∪C=A∪(B∪C)(A \cup B) \cup C = A \cup (B \cup C)
Distributive A∩(B∪C)=(A∩B)∪(A∩C)A \cap (B \cup C) = (A \cap B) \cup (A \cap C)
De Morgan (A∪B)c=Ac∩Bc,(A∩B)c=Ac∪Bc(A \cup B)^c = A^c \cap B^c, \quad (A \cap B)^c = A^c \cup B^c
Difference A∖B=A∩BcA \setminus B = A \cap B^c

The indicator function turns a set into numbers, which is how computers store sets:

1A(x)={1x∈A0x∉A1A∩B=1A1B,1Ac=1−1A\mathbf{1}_A(x) = \begin{cases} 1 & x \in A \\ 0 & x \notin A \end{cases} \qquad \mathbf{1}_{A\cap B} = \mathbf{1}_A \mathbf{1}_B, \quad \mathbf{1}_{A^c} = 1 - \mathbf{1}_A

Functions, precisely

Definition

A function f:A→Bf: A \to B is a relation f⊆A×Bf \subseteq A \times B such that every a∈Aa \in A appears in exactly one pair (a,b)∈f(a, b) \in f. We write f(a)=bf(a) = b.

  • Injective (one-to-one): different inputs give different outputs. f(a1)=f(a2)⇒a1=a2f(a_1) = f(a_2) \Rightarrow a_1 = a_2.
  • Surjective (onto): every output is reached. For every b∈Bb \in B there is an aa with f(a)=bf(a) = b.
  • Bijective: both. A bijection has an inverse f−1:B→Af^{-1}: B \to A.
Build a function f: {1, 2, 3} → {a, b, c}
DomainCodomain123abc
✅ Injective
No two inputs share an output.
✅ Surjective
Every output is hit.
✅ Bijective
A perfect pairing: it has an inverse.
Try it: with 2 outputs, can you ever make f injective? With 4 outputs, can you ever make it surjective? (This is the pigeonhole principle.)

Counting functions. For finite sets with ∣A∣=n\lvert A \rvert = n and ∣B∣=k\lvert B \rvert = k, each of the nn inputs can go to any of kk outputs, so there are knk^n functions A→BA \to B. For an injective function, the first input has kk choices, the next k−1k-1, and so on, giving k!/(k−n)!k!/(k-n)! injective functions when n≤kn \le k. A relation on AA is any subset of A×AA \times A, so there are 2n22^{n^2} relations.

Two more tools you’ll use constantly:

  • Composition: (g∘f)(x)=g(f(x))(g \circ f)(x) = g(f(x)). A deep neural network is a long composition of simple functions: f=fL∘⋯∘f2∘f1f = f_L \circ \dots \circ f_2 \circ f_1.
  • Image and preimage: for S⊆AS \subseteq A, f(S)={f(a):a∈S}f(S) = \{f(a) : a \in S\}. For T⊆BT \subseteq B, f−1(T)={a∈A:f(a)∈T}f^{-1}(T) = \{a \in A : f(a) \in T\}. The preimage exists even if ff has no inverse.

Properties of relations

A relation RR on a set AA (written aRba \mathrel{R} b) can be:

Property Meaning Example
Reflexive aRaa \mathrel{R} a for all aa ≤\le, “same colour as”
Symmetric aRb⇒bRaa \mathrel{R} b \Rightarrow b \mathrel{R} a “is a sibling of”
Antisymmetric aRb and bRa⇒a=ba \mathrel{R} b \text{ and } b \mathrel{R} a \Rightarrow a = b ≤\le, ⊆\subseteq
Transitive aRb, bRc⇒aRca \mathrel{R} b,\ b \mathrel{R} c \Rightarrow a \mathrel{R} c ≤\le, “is an ancestor of”
  • An equivalence relation is reflexive, symmetric and transitive. It splits a set into non-overlapping equivalence classes. “Same remainder when divided by 3” splits Z\mathbb{Z} into three classes: {…,0,3,6,… }\{\dots,0,3,6,\dots\}, {…,1,4,7,… }\{\dots,1,4,7,\dots\}, and {…,2,5,8,… }\{\dots,2,5,8,\dots\}.
  • A partial order is reflexive, antisymmetric and transitive, like ≤\le on numbers or ⊆\subseteq on sets.

Where this shows up in AI, robotics and data science

Idea Where you’ll meet it
Set of pairs D⊆X×YD \subseteq X \times Y A labelled dataset
Function f:X→Yf: X \to Y A classifier, a regression model, a robot controller (state → action)
Set of functions H\mathcal{H} A model family (“hypothesis class”), such as all linear models
Preimage f−1({cat})f^{-1}(\{\text{cat}\}) The decision region where the model says “cat”
Equivalence classes Clusters, class labels, robot poses that differ by a full 360° turn
Intersection over union The main score for image segmentation and object detection
Set difference The free space a robot can move in: workspace minus obstacles
SQL JOIN, UNION, INTERSECT Relational databases are built on relations and set operations

Sets in Python

Python has sets built in. Run this and change it:

🐍 Sets in Python

Exercise: classify a function

🐍 Exercise 1: injective, surjective, bijective
A function is stored as a Python dict (input → output). Fill in the three functions, then press Check my answer.

Exercise: Intersection over Union

Segmentation models (for example, finding a rock in a rover camera image) are scored with the Jaccard index, also called IoU:

IoU(P,T)=∣P∩T∣∣P∪T∣\text{IoU}(P, T) = \frac{\lvert P \cap T \rvert}{\lvert P \cup T \rvert}
🐍 Exercise 2: IoU of two masks
P and T are sets of pixel coordinates (row, col). Return the IoU. If both sets are empty, return 1.0.
📝 Quick check (Level 2)
0/4 answered
  1. 1. f: ℝ → ℝ, f(x) = x². Which is true?
  2. 2. If |A| = 5, how many subsets does A have?
  3. 3. 'Is a sibling of' is symmetric. Which other property does it fail?
  4. 4. By De Morgan, (A ∩ B)ᶜ equals…

Level 3: Advanced

★★★★☆ Advanced⏱ 50 minGraduate level, with full derivations and proofs.

How to prove two sets are equal

The standard method is double inclusion: show X⊆YX \subseteq Y and Y⊆XY \subseteq X. To show X⊆YX \subseteq Y, take an arbitrary x∈Xx \in X and prove x∈Yx \in Y.

Theorem (De Morgan)

For any sets A,BA, B in a universe UU: (A∪B)c=Ac∩Bc(A \cup B)^c = A^c \cap B^c.

Proof. (⊆\subseteq) Let x∈(A∪B)cx \in (A \cup B)^c. Then x∉A∪Bx \notin A \cup B, so xx is in neither set: x∉Ax \notin A and x∉Bx \notin B. Hence x∈Acx \in A^c and x∈Bcx \in B^c, so x∈Ac∩Bcx \in A^c \cap B^c. (⊇\supseteq) Let x∈Ac∩Bcx \in A^c \cap B^c. Then x∉Ax \notin A and x∉Bx \notin B, so x∉A∪Bx \notin A \cup B, meaning x∈(A∪B)cx \in (A \cup B)^c. ∎

Theorem (size of the power set)

If ∣A∣=n\lvert A \rvert = n, then ∣P(A)∣=2n\lvert \mathcal{P}(A) \rvert = 2^n.

Proof by bijection. List A={a1,…,an}A = \{a_1, \dots, a_n\}. Map each subset SS to its indicator vector (1S(a1),…,1S(an))∈{0,1}n(\mathbf{1}_S(a_1), \dots, \mathbf{1}_S(a_n)) \in \{0,1\}^n. Different subsets give different vectors (injective), and every 0/1 vector defines a subset (surjective). So ∣P(A)∣=∣{0,1}n∣=2n\lvert \mathcal{P}(A) \rvert = \lvert \{0,1\}^n \rvert = 2^n. ∎

Why AI cares

This is why feature selection is hard. With n=50n = 50 features there are 250≈10152^{50} \approx 10^{15} subsets to choose from, far too many to try. It’s also why a binary mask over nn pixels can encode 2n2^n different shapes.

Inclusion–exclusion in general

For three sets, add the singles, subtract the pairs, add back the triple:

∣A∪B∪C∣=∣A∣+∣B∣+∣C∣−∣A∩B∣−∣A∩C∣−∣B∩C∣+∣A∩B∩C∣\lvert A \cup B \cup C \rvert = \lvert A\rvert + \lvert B\rvert + \lvert C\rvert - \lvert A\cap B\rvert - \lvert A\cap C\rvert - \lvert B\cap C\rvert + \lvert A\cap B\cap C\rvert

In general, ∣⋃i=1nAi∣=∑∅≠S⊆{1..n}(−1)∣S∣+1∣⋂i∈SAi∣\big\lvert \bigcup_{i=1}^n A_i \big\rvert = \sum_{\varnothing \ne S \subseteq \{1..n\}} (-1)^{\lvert S\rvert+1} \big\lvert \bigcap_{i \in S} A_i \big\rvert. The same formula works for probabilities, with PP in place of ∣⋅∣\lvert\cdot\rvert.

Composition and the pigeonhole principle

Theorem

If f:A→Bf: A \to B and g:B→Cg: B \to C are injective, then g∘fg \circ f is injective.

Proof. Suppose g(f(a1))=g(f(a2))g(f(a_1)) = g(f(a_2)). Since gg is injective, f(a1)=f(a2)f(a_1) = f(a_2). Since ff is injective, a1=a2a_1 = a_2. ∎ (The same pattern works for surjective and bijective.)

Pigeonhole principle

If AA and BB are finite and ∣A∣>∣B∣\lvert A \rvert > \lvert B \rvert, then no function f:A→Bf: A \to B is injective.

A beautiful consequence: no compression program can shrink every file. There are 2n2^n files of nn bits, but only 2n−12^n - 1 files shorter than nn bits. Two files would have to share a compressed version, and then you couldn’t decompress both. This links to information theory (A7).

Equivalence relations are partitions

Theorem

Every equivalence relation on AA splits AA into disjoint, non-empty classes that cover AA (a partition). Conversely, every partition defines an equivalence relation: “is in the same block as”.

Proof sketch. Let [a]={x:xRa}[a] = \{x : x \mathrel{R} a\}. Reflexivity gives a∈[a]a \in [a], so classes are non-empty and cover AA. If [a][a] and [b][b] share an element cc, symmetry and transitivity give aRba \mathrel{R} b, and then [a]=[b][a] = [b]. So two classes are either identical or disjoint. ∎

This is exactly what clustering produces, and it’s how mathematicians build new objects. For example, the set of angles is R\mathbb{R} with θ∼θ+2πk\theta \sim \theta + 2\pi k, which is why robot joint angles “wrap around”.

Infinite cardinality: some infinities are bigger

Two sets have the same cardinality if there’s a bijection between them. This is the chair-matching trick from Level 0, made precise.

  • A set is countable if it’s finite or in bijection with N\mathbb{N}. You can list its members as a first, second, third, and so on.
  • Z\mathbb{Z} is countable: 0,1,−1,2,−2,3,…0, 1, -1, 2, -2, 3, \dots. Surprising, since N⊊Z\mathbb{N} \subsetneq \mathbb{Z}.
  • Q\mathbb{Q} is countable too: list fractions p/qp/q by ∣p∣+q=1,2,3,…\lvert p\rvert + q = 1, 2, 3, \dots and skip repeats.
  • N×N\mathbb{N} \times \mathbb{N} is countable. The Cantor pairing function π(a,b)=(a+b)(a+b+1)2+b\pi(a, b) = \tfrac{(a+b)(a+b+1)}{2} + b is a bijection N×N→N\mathbb{N} \times \mathbb{N} \to \mathbb{N}. It walks through the grid of pairs one diagonal at a time.
Theorem (Cantor, 1891)

R\mathbb{R} is not countable.

Proof (diagonal argument). It’s enough to show the numbers in (0,1)(0,1) can’t be listed. Suppose they could: r1,r2,r3,…r_1, r_2, r_3, \dots, each written as a decimal ri=0.di1di2di3…r_i = 0.d_{i1} d_{i2} d_{i3}\dots. Build a new number x=0.x1x2x3…x = 0.x_1 x_2 x_3 \dots with xi=5x_i = 5 if dii≠5d_{ii} \ne 5, and xi=4x_i = 4 otherwise. Then xx differs from every rir_i in the ii-th digit, so it isn’t on the list. (Using only the digits 4 and 5 avoids the 0.0999…=0.10.0999\ldots = 0.1 double-representation problem.) Contradiction. ∎

Theorem (Cantor)

For every set AA, there is no surjection A→P(A)A \to \mathcal{P}(A). So ∣A∣<∣P(A)∣\lvert A \rvert < \lvert \mathcal{P}(A) \rvert, and there is an endless ladder of bigger infinities.

Proof. Take any f:A→P(A)f: A \to \mathcal{P}(A). Let D={a∈A:a∉f(a)}D = \{a \in A : a \notin f(a)\}. If D=f(d)D = f(d) for some dd, then d∈D  ⟺  d∉f(d)=Dd \in D \iff d \notin f(d) = D, which is impossible. So DD is never an output, and ff isn’t surjective. ∎

The Schröder–Bernstein theorem says that if there are injections A→BA \to B and B→AB \to A, then there’s a bijection. It’s the standard tool for proving two sets have equal size, for example ∣(0,1)∣=∣R∣\lvert (0,1) \rvert = \lvert \mathbb{R} \rvert.

Exercise 3.1: Prove that A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)

Use double inclusion. (⊆\subseteq) If x∈Ax \in A and x∈B∪Cx \in B \cup C, then x∈Bx \in B or x∈Cx \in C. In the first case x∈A∩Bx \in A \cap B, in the second x∈A∩Cx \in A \cap C. Either way xx is in the union. (⊇\supseteq) If x∈A∩Bx \in A \cap B, then x∈Ax \in A and x∈B⊆B∪Cx \in B \subseteq B \cup C. The case x∈A∩Cx \in A \cap C works the same way. ∎

Exercise 3.2: Show that f: ℝ → (0, ∞), f(x) = eˣ, is a bijection, and give its inverse

Injective: exe^x is strictly increasing, so x1≠x2⇒ex1≠ex2x_1 \ne x_2 \Rightarrow e^{x_1} \ne e^{x_2}. Surjective: for any y>0y > 0, x=ln⁡yx = \ln y gives ex=ye^x = y. The inverse is f−1(y)=ln⁡yf^{-1}(y) = \ln y. This is why log-probabilities are safe to use in ML: ln⁡\ln is a bijection, so it never loses information.

Exercise 3.3: Prove that the set of finite binary strings is countable, but the set of infinite binary sequences is not

Finite strings: list all strings of length 0, then length 1, then length 2, and so on. Each length has finitely many strings, so this lists them all. Infinite sequences: run the diagonal argument. Given any list s1,s2,…s_1, s_2, \dots, flip the ii-th bit of sis_i to build a sequence that isn’t on the list. Since infinite sequences correspond to subsets of N\mathbb{N}, this is Cantor’s theorem for A=NA = \mathbb{N}.

📝 Quick check (Level 3)
0/4 answered
  1. 1. Which set is uncountable?
  2. 2. Why can't a lossless compressor shorten every 1000-bit file?
  3. 3. In Cantor's proof that A has no surjection onto P(A), what is the 'diagonal set' D?
  4. 4. g ∘ f is injective. Which must be true?

Level 4: Expert

★★★★★ Expert⏱ 40 minResearchers: original papers and open problems.

The foundations crisis: when sets broke mathematics

Early set theory let you form “the set of all xx with property PP” for any PP. In 1901 Bertrand Russell asked about R={x:x∉x}R = \{x : x \notin x\}. If R∈RR \in R, then R∉RR \notin R, and if R∉RR \notin R, then R∈RR \in R. This is the same diagonal trick as Cantor’s theorem.

The fix was axiomatic set theory. Zermelo (1908), later refined into ZFC (Zermelo–Fraenkel with the Axiom of Choice), only lets you build sets from existing ones in controlled ways. Nearly all of modern mathematics, including everything on this site, can be written inside ZFC.

Two consequences matter for you as a scientist:

  • The Axiom of Choice guarantees things like “every vector space has a basis”. It also implies that some subsets of R\mathbb{R} can’t be given a sensible length (Vitali, 1905). That’s why probability theory only assigns probabilities to sets in a σ-algebra instead of to every subset. You’ll see this in A4.3.
  • The Continuum Hypothesis: is there an infinity strictly between ∣N∣\lvert\mathbb{N}\rvert and ∣R∣\lvert\mathbb{R}\rvert? Gödel (1940) and Cohen (1963) showed that ZFC can’t decide it either way. Some questions are genuinely independent of the axioms.

Cardinality is the first theory of learning

Here’s where sets meet AI research directly. Suppose your model family H\mathcal{H} is finite, the true rule is in H\mathcal{H}, and you pick any h∈Hh \in \mathcal{H} that makes zero mistakes on mm random training examples.

Finite-class PAC bound (Valiant, 1984; Blumer et al., 1987)

With probability at least 1−δ1 - \delta, every such consistent hh has true error at most

ε=ln⁡∣H∣+ln⁡(1/δ)m.\varepsilon = \frac{\ln \lvert \mathcal{H} \rvert + \ln (1/\delta)}{m}.

Derivation. Call hh “bad” if its true error is above ε\varepsilon. A bad hh gets one random example right with probability below 1−ε1 - \varepsilon, so it gets all mm right with probability below (1−ε)m≤e−εm(1-\varepsilon)^m \le e^{-\varepsilon m}. There are at most ∣H∣\lvert\mathcal{H}\rvert bad hypotheses, so by the union bound, the chance that any of them looks perfect is at most ∣H∣e−εm\lvert\mathcal{H}\rvert e^{-\varepsilon m}. Set this equal to δ\delta and solve for ε\varepsilon. ∎

Notice what controls learning: ln⁡∣H∣\ln \lvert\mathcal{H}\rvert, which is the number of bits needed to name one hypothesis. This is the root of the Occam’s razor and minimum description length ideas (A7).

Reproduce it. The simulation below uses 1,000 threshold classifiers, trains on 200 points, and checks how often the bound fails. Theory says at most 5% of the time.

🐍 Research task: test the PAC bound

Try changing m, delta and the size of H. You’ll see the observed failure rate is far below δ\delta. The bound is correct but loose, because the union bound treats all 1,000 hypotheses as unrelated when neighbouring thresholds make almost the same mistakes.

When cardinality stops working

Most real model families are infinite (all lines, all neural networks with real weights), so ln⁡∣H∣=∞\ln\lvert\mathcal{H}\rvert = \infty and the bound says nothing. Two research answers:

  1. Count behaviours, not functions. Vapnik and Chervonenkis (1971) asked how many different labellings H\mathcal{H} can produce on mm points: the growth function. Its largest fully-shattered set size is the VC dimension, an “effective cardinality” for infinite classes (B2).
  2. Computers are finite anyway. A network with pp parameters stored as 32-bit floats can represent at most 232p2^{32p} functions, so ln⁡∣H∣≤32pln⁡2\ln\lvert\mathcal{H}\rvert \le 32p \ln 2. This “discretization trick” (Shalev-Shwartz and Ben-David, 2014) gives a real but very loose bound.
Open problem

Modern deep networks have far more parameters than training examples, yet they generalise well. Zhang et al. (2017) showed that standard networks can perfectly memorise randomly labelled data, so capacity-counting bounds like these can’t explain their success. Explaining why deep learning generalises is still an active research area (B4).

Sets in robotics and space science

  • Configuration space. A robot arm’s possible poses form a set C\mathcal{C}. Obstacles define Cobs\mathcal{C}_{\text{obs}}, and motion planning searches the free space Cfree=C∖Cobs\mathcal{C}_{\text{free}} = \mathcal{C} \setminus \mathcal{C}_{\text{obs}} (U1).
  • Safe sets. In safety-critical control, the safe states are written S={x:h(x)≥0}\mathcal{S} = \{x : h(x) \ge 0\}. A control barrier function guarantees the robot never leaves S\mathcal{S} (Ames et al., 2019). Proving that a set is forward invariant is a core tool for certifying autonomous spacecraft and robots (S6).
  • Remote sensing. Satellite analysis combines masks with set operations, for example “pixels that are land and not cloud and burned”. Segmentation accuracy is reported as IoU, which Jaccard introduced in 1912 to compare plant species across alpine regions.
  • Databases. E. F. Codd’s relational model (1970) defines a database table as a mathematical relation, a subset of a Cartesian product. SQL is applied set theory (Y2).

Research directions to explore

  • Tighter generalization bounds: PAC-Bayes, compression-based bounds (B2, B4).
  • Set-valued learning: models whose input is a set must not depend on order, which is the idea behind Deep Sets (Zaheer et al., 2017) and point-cloud networks like PointNet (E18).
  • Set-valued predictions with guarantees: conformal prediction outputs a set of labels that contains the truth with a chosen probability (I4).

References

  1. G. Cantor (1874). “Ueber eine Eigenschaft des Inbegriffes aller reellen algebraischen Zahlen.” Journal für die reine und angewandte Mathematik, 77.
  2. G. Cantor (1891). “Über eine elementare Frage der Mannigfaltigkeitslehre.” Jahresbericht der DMV, 1. (The diagonal argument.)
  3. E. Zermelo (1908). “Untersuchungen über die Grundlagen der Mengenlehre I.” Mathematische Annalen, 65.
  4. P. Jaccard (1912). “The distribution of the flora in the alpine zone.” New Phytologist, 11(2).
  5. P. Cohen (1963). “The independence of the continuum hypothesis.” PNAS, 50(6).
  6. E. F. Codd (1970). “A relational model of data for large shared data banks.” Communications of the ACM, 13(6).
  7. V. Vapnik and A. Chervonenkis (1971). “On the uniform convergence of relative frequencies of events to their probabilities.” Theory of Probability and Its Applications, 16(2).
  8. L. Valiant (1984). “A theory of the learnable.” Communications of the ACM, 27(11).
  9. A. Blumer, A. Ehrenfeucht, D. Haussler, M. Warmuth (1987). “Occam’s razor.” Information Processing Letters, 24(6).
  10. S. Shalev-Shwartz and S. Ben-David (2014). Understanding Machine Learning: From Theory to Algorithms. Cambridge University Press. Chapters 2–3.
  11. C. Zhang, S. Bengio, M. Hardt, B. Recht, O. Vinyals (2017). “Understanding deep learning requires rethinking generalization.” ICLR.
  12. M. Zaheer et al. (2017). “Deep Sets.” NeurIPS.
  13. A. Ames, S. Coogan, M. Egerstedt, G. Notomista, K. Sreenath, P. Tabuada (2019). “Control barrier functions: theory and applications.” European Control Conference.
  14. P. Halmos (1960). Naive Set Theory. Van Nostrand. (A classic, short first book on the subject.)