Skip to content

7.1 Sets, Relations, Functions

Basic set theoretic language, including sets, membership, subsets, operations, relations, equivalence relations, order relations, and functions.

Set theory provides a common language for modern mathematics. Many mathematical objects can be described as sets with additional structure, and many mathematical constructions can be described using membership, subsets, relations, and functions. In this section we introduce these basic notions carefully, since later parts of logic and foundations use them constantly.

Sets and Membership

A set is a collection of objects, called its elements or members. If an object aa is an element of a set AA, we write:

aA a \in A

If aa is not an element of AA, we write:

aA a \notin A

The relation \in is called membership. It is the most basic relation in set theory. The expression aAa \in A is a statement, and it says that the object aa belongs to the set AA.

For example, if:

A={1,2,3} A = \{1,2,3\}

then:

1A 1 \in A

and:

4A 4 \notin A

A set is determined by its elements. This means that two sets are equal exactly when they have the same elements.

Definition 7.1 (Equality of Sets)

Two sets AA and BB are equal if and only if every object belongs to AA exactly when it belongs to BB:

A=Bif and only ifx(xAxB) A = B \quad \text{if and only if} \quad \forall x\,(x \in A \leftrightarrow x \in B)

This principle is often called extensionality. It says that a set has no hidden structure beyond its elements. If two sets contain the same elements, then they are the same set.

Example 7.2

The sets:

{1,2,3} \{1,2,3\}

and:

{3,2,1} \{3,2,1\}

are equal, because they have exactly the same elements.

Also:

{1,1,2,3}={1,2,3} \{1,1,2,3\} = \{1,2,3\}

because repetition does not create new elements.

Thus order and repetition do not matter for sets.

Definition 7.3 (Subset)

Let AA and BB be sets. We write:

AB A \subseteq B

if:

x(xAxB) \forall x\,(x \in A \to x \in B)

In words, ABA \subseteq B means that every element of AA is also an element of BB.

If:

AB A \subseteq B

and:

AB A \ne B

then AA is called a proper subset of BB.

Example 7.4

Let:

A={1,2} A = \{1,2\}

and:

B={1,2,3} B = \{1,2,3\}

Then:

AB A \subseteq B

because every element of AA is also an element of BB.

But:

BA B \nsubseteq A

because:

3B 3 \in B

and:

3A 3 \notin A

Lemma 7.5 (Set Equality by Double Inclusion)

For any sets AA and BB:

A=B A = B

if and only if:

ABandBA A \subseteq B \quad \text{and} \quad B \subseteq A

Proof

Suppose first that A=BA = B. Then every element of AA is an element of BB, and every element of BB is an element of AA, because the two sets are the same set. Hence:

AB A \subseteq B

and:

BA B \subseteq A

Conversely, suppose that:

ABandBA A \subseteq B \quad \text{and} \quad B \subseteq A

Let xx be any object. If xAx \in A, then xBx \in B because ABA \subseteq B. If xBx \in B, then xAx \in A because BAB \subseteq A. Therefore:

xAxB x \in A \leftrightarrow x \in B

for every object xx. By extensionality:

A=B A = B

Definition 7.6 (Empty Set)

The empty set is the set with no elements. It is denoted by:

\varnothing

A set EE is empty if:

x(xE) \forall x\,(x \notin E)

The empty set is the unique set with this property.

Lemma 7.7 (Uniqueness of the Empty Set)

If EE and FF are empty sets, then:

E=F E = F

Proof

Assume that EE and FF are empty sets. To show E=FE = F, it is enough to show double inclusion.

First, let xEx \in E. Since EE is empty, this is impossible. Therefore the implication:

xExF x \in E \to x \in F

is true for every xx, and hence:

EF E \subseteq F

The same argument shows:

FE F \subseteq E

By Lemma 7.5:

E=F E = F

Lemma 7.8 (Empty Set Is a Subset of Every Set)

For every set AA:

A \varnothing \subseteq A

Proof

We must show:

x(xxA) \forall x\,(x \in \varnothing \to x \in A)

Let xx be arbitrary. The statement xx \in \varnothing is false by definition of the empty set. Therefore:

xxA x \in \varnothing \to x \in A

is true. Since xx was arbitrary:

A \varnothing \subseteq A

Definition 7.9 (Union)

The union of AA and BB is the set:

AB={x:xA or xB} A \cup B = \{x : x \in A \text{ or } x \in B\}

Thus:

xABif and only ifxAxB x \in A \cup B \quad \text{if and only if} \quad x \in A \lor x \in B

The union contains everything that belongs to at least one of the two sets.

Definition 7.10 (Intersection)

The intersection of AA and BB is the set:

AB={x:xA and xB} A \cap B = \{x : x \in A \text{ and } x \in B\}

Thus:

xABif and only ifxAxB x \in A \cap B \quad \text{if and only if} \quad x \in A \land x \in B

The intersection contains exactly the elements common to both sets.

Definition 7.11 (Difference)

The difference of AA and BB is the set:

AB={x:xA and xB} A \setminus B = \{x : x \in A \text{ and } x \notin B\}

Thus:

xABif and only ifxAxB x \in A \setminus B \quad \text{if and only if} \quad x \in A \land x \notin B

The difference consists of the elements of AA that are not in BB.

Example 7.12

Let:

A={1,2,3} A = \{1,2,3\}

and:

B={3,4,5} B = \{3,4,5\}

Then:

AB={1,2,3,4,5} A \cup B = \{1,2,3,4,5\} AB={3} A \cap B = \{3\} AB={1,2} A \setminus B = \{1,2\} BA={4,5} B \setminus A = \{4,5\}

Lemma 7.13 (Commutativity of Union and Intersection)

For all sets AA and BB:

AB=BA A \cup B = B \cup A

and:

AB=BA A \cap B = B \cap A

Proof

We prove the statement for union first. Let xx be arbitrary. Then:

xAB x \in A \cup B

if and only if:

xAxB x \in A \lor x \in B

which is equivalent to:

xBxA x \in B \lor x \in A

which is equivalent to:

xBA x \in B \cup A

Therefore:

AB=BA A \cup B = B \cup A

The proof for intersection is similar. We have:

xAB x \in A \cap B

if and only if:

xAxB x \in A \land x \in B

which is equivalent to:

xBxA x \in B \land x \in A

which is equivalent to:

xBA x \in B \cap A

Therefore:

AB=BA A \cap B = B \cap A

Lemma 7.14 (Associativity of Union and Intersection)

For all sets AA, BB, and CC:

(AB)C=A(BC) (A \cup B) \cup C = A \cup (B \cup C)

and:

(AB)C=A(BC) (A \cap B) \cap C = A \cap (B \cap C)

Proof

We prove the statement for union. Let xx be arbitrary. Then:

x(AB)C x \in (A \cup B) \cup C

if and only if:

xABxC x \in A \cup B \lor x \in C

if and only if:

(xAxB)xC (x \in A \lor x \in B) \lor x \in C

if and only if:

xA(xBxC) x \in A \lor (x \in B \lor x \in C)

if and only if:

xAxBC x \in A \lor x \in B \cup C

if and only if:

xA(BC) x \in A \cup (B \cup C)

By extensionality:

(AB)C=A(BC) (A \cup B) \cup C = A \cup (B \cup C)

The proof for intersection is the same with “or” replaced by “and”. For every xx:

x(AB)C x \in (A \cap B) \cap C

if and only if:

(xAxB)xC (x \in A \land x \in B) \land x \in C

if and only if:

xA(xBxC) x \in A \land (x \in B \land x \in C)

if and only if:

xA(BC) x \in A \cap (B \cap C)

Thus:

(AB)C=A(BC) (A \cap B) \cap C = A \cap (B \cap C)

Lemma 7.15 (Distributive Laws)

For all sets AA, BB, and CC:

A(BC)=(AB)(AC) A \cap (B \cup C) = (A \cap B) \cup (A \cap C)

and:

A(BC)=(AB)(AC) A \cup (B \cap C) = (A \cup B) \cap (A \cup C)

Proof

We prove the first identity. Let xx be arbitrary. Then:

xA(BC) x \in A \cap (B \cup C)

if and only if:

xAxBC x \in A \land x \in B \cup C

if and only if:

xA(xBxC) x \in A \land (x \in B \lor x \in C)

if and only if:

(xAxB)(xAxC) (x \in A \land x \in B) \lor (x \in A \land x \in C)

if and only if:

xABxAC x \in A \cap B \lor x \in A \cap C

if and only if:

x(AB)(AC) x \in (A \cap B) \cup (A \cap C)

Therefore:

A(BC)=(AB)(AC) A \cap (B \cup C) = (A \cap B) \cup (A \cap C)

The second identity is proved similarly. For every xx:

xA(BC) x \in A \cup (B \cap C)

if and only if:

xA(xBxC) x \in A \lor (x \in B \land x \in C)

if and only if:

(xAxB)(xAxC) (x \in A \lor x \in B) \land (x \in A \lor x \in C)

if and only if:

x(AB)(AC) x \in (A \cup B) \cap (A \cup C)

Thus:

A(BC)=(AB)(AC) A \cup (B \cap C) = (A \cup B) \cap (A \cup C)

Definition 7.16 (Power Set)

The power set of AA is:

P(A)={X:XA} \mathcal{P}(A) = \{X : X \subseteq A\}

Thus:

XP(A)if and only ifXA X \in \mathcal{P}(A) \quad \text{if and only if} \quad X \subseteq A

Example 7.17

If:

A={1,2} A = \{1,2\}

then:

P(A)={,{1},{2},{1,2}} \mathcal{P}(A)=\{\varnothing,\{1\},\{2\},\{1,2\}\}

The power set contains sets as elements. The elements of P(A)\mathcal{P}(A) are subsets of AA, not usually elements of AA.

Definition 7.18 (Ordered Pair)

An ordered pair is written:

(a,b) (a,b)

and is characterized by the property:

(a,b)=(c,d)if and only ifa=c and b=d (a,b)=(c,d) \quad \text{if and only if} \quad a=c \text{ and } b=d

This property is the essential feature of ordered pairs.

Definition 7.19 (Cartesian Product)

The Cartesian product of sets AA and BB is:

A×B={(a,b):aA and bB} A \times B = \{(a,b) : a \in A \text{ and } b \in B\}

Thus an element of A×BA \times B is an ordered pair whose first coordinate belongs to AA and whose second coordinate belongs to BB.

Example 7.20

If:

A={1,2} A = \{1,2\}

and:

B={x,y} B = \{x,y\}

then:

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

In general, A×BA \times B and B×AB \times A are different, because ordered pairs remember which coordinate comes first.

Definition 7.21 (Relation)

A relation from AA to BB is a subset:

RA×B R \subseteq A \times B

If A=BA=B, then a relation from AA to AA is called a relation on AA.

If:

(a,b)R (a,b) \in R

we often write:

aRb aRb

A relation records which elements are related to which other elements.

Example 7.22

Let:

A={1,2,3} A = \{1,2,3\}

Define a relation RR on AA by:

aRbif and only ifa<b aRb \quad \text{if and only if} \quad a < b

Then:

R={(1,2),(1,3),(2,3)} R = \{(1,2),(1,3),(2,3)\}

The pair (2,1)(2,1) is not in RR, because 2<12 < 1 is false.

Properties of Relations

Let RR be a relation on a set AA.

The relation RR is reflexive if:

aA, aRa \forall a \in A,\ aRa

It is symmetric if:

a,bA, aRbbRa \forall a,b \in A,\ aRb \to bRa

It is transitive if:

a,b,cA, (aRbbRc)aRc \forall a,b,c \in A,\ (aRb \land bRc) \to aRc

It is antisymmetric if:

a,bA, (aRbbRa)a=b \forall a,b \in A,\ (aRb \land bRa) \to a=b

These properties are used to define important classes of relations, especially equivalence relations and order relations.

Definition 7.23 (Equivalence Relation)

A relation RR on a set AA is an equivalence relation if it is reflexive, symmetric, and transitive.

Equivalence relations formalize the idea of treating objects as the same according to some chosen criterion.

Example 7.24

On the set of integers Z\mathbb{Z}, define:

aRbif and only ifab is even aRb \quad \text{if and only if} \quad a-b \text{ is even}

This relation means that aa and bb have the same parity.

It is reflexive because:

aa=0 a-a=0

is even.

It is symmetric because if aba-b is even, then:

ba=(ab) b-a=-(a-b)

is also even.

It is transitive because if aba-b is even and bcb-c is even, then:

ac=(ab)+(bc) a-c=(a-b)+(b-c)

is even.

Therefore RR is an equivalence relation.

Definition 7.25 (Equivalence Class)

Let RR be an equivalence relation on AA, and let aAa \in A. The equivalence class of aa is:

[a]={xA:xRa} [a] = \{x \in A : xRa\}

The equivalence class of aa consists of all elements equivalent to $a`.

Lemma 7.26 (Equivalence Classes Are Equal or Disjoint)

Let RR be an equivalence relation on AA. For any a,bAa,b \in A, either:

[a]=[b] [a]=[b]

or:

[a][b]= [a] \cap [b]=\varnothing

Proof

Suppose:

[a][b] [a] \cap [b] \ne \varnothing

Then there exists an element xx such that:

x[a][b] x \in [a] \cap [b]

Thus:

xRa xRa

and:

xRb xRb

Since RR is symmetric, from xRaxRa we get:

aRx aRx

Since aRxaRx and xRbxRb, transitivity gives:

aRb aRb

We show that [a][b][a]\subseteq [b]. Let y[a]y \in [a]. Then:

yRa yRa

Since aRbaRb, transitivity gives:

yRb yRb

Therefore:

y[b] y \in [b]

So:

[a][b] [a]\subseteq [b]

Similarly, since aRbaRb, symmetry gives:

bRa bRa

The same argument shows:

[b][a] [b]\subseteq [a]

Hence:

[a]=[b] [a]=[b]

Therefore, if two equivalence classes meet, they are equal. If they do not meet, they are disjoint.

Definition 7.27 (Partial Order)

A relation \leq on a set AA is a partial order if it is reflexive, antisymmetric, and transitive.

That is, for all a,b,cAa,b,c \in A:

aa a \leq a (abba)a=b (a \leq b \land b \leq a) \to a=b (abbc)ac (a \leq b \land b \leq c) \to a \leq c

A set together with a partial order is called a partially ordered set, or poset.

Example 7.28

Let AA be any set. The subset relation:

\subseteq

is a partial order on P(A)\mathcal{P}(A).

It is reflexive because:

XX X \subseteq X

for every XAX \subseteq A.

It is antisymmetric because:

XYandYX X \subseteq Y \quad \text{and} \quad Y \subseteq X

imply:

X=Y X=Y

It is transitive because:

XYandYZ X \subseteq Y \quad \text{and} \quad Y \subseteq Z

imply:

XZ X \subseteq Z

Definition 7.29 (Linear Order)

A partial order \leq on AA is a linear order if every two elements are comparable:

a,bA, abba \forall a,b \in A,\ a \leq b \lor b \leq a

Linear orders are also called total orders.

Example 7.30

The usual order on the natural numbers:

\leq

is a linear order, because any two natural numbers can be compared.

The subset order on a power set is usually not a linear order. For example, if:

A={1,2} A=\{1,2\}

then:

{1}{2} \{1\} \nsubseteq \{2\}

and:

{2}{1} \{2\} \nsubseteq \{1\}

Thus {1}\{1\} and {2}\{2\} are not comparable under \subseteq.

Definition 7.31 (Function)

A function from AA to BB is a relation:

fA×B f \subseteq A \times B

such that for every aAa \in A, there exists a unique bBb \in B with:

(a,b)f (a,b) \in f

We write:

f:AB f : A \to B

and we write:

f(a)=b f(a)=b

when:

(a,b)f (a,b) \in f

The set AA is called the domain of ff, and the set BB is called the codomain of ff.

Example 7.32

Let:

A={1,2,3} A=\{1,2,3\}

and:

B={a,b} B=\{a,b\}

The relation:

f={(1,a),(2,a),(3,b)} f=\{(1,a),(2,a),(3,b)\}

is a function from AA to BB, because every element of AA appears exactly once as a first coordinate.

The relation:

g={(1,a),(1,b),(2,a)} g=\{(1,a),(1,b),(2,a)\}

is not a function from AA to BB, because 11 has two outputs and 33 has no output.

Definition 7.33 (Image and Preimage)

Let:

f:AB f : A \to B

If XAX \subseteq A, the image of XX under ff is:

f[X]={f(x):xX} f[X]=\{f(x):x \in X\}

If YBY \subseteq B, the preimage of YY under ff is:

f1[Y]={xA:f(x)Y} f^{-1}[Y]=\{x \in A:f(x)\in Y\}

The image moves subsets of the domain forward into the codomain. The preimage moves subsets of the codomain backward into the domain.

Lemma 7.34 (Basic Image Properties)

Let f:ABf:A\to B, and let X,YAX,Y\subseteq A. Then:

f[XY]=f[X]f[Y] f[X\cup Y]=f[X]\cup f[Y]

Also:

f[XY]f[X]f[Y] f[X\cap Y]\subseteq f[X]\cap f[Y]

Proof

First we prove:

f[XY]=f[X]f[Y] f[X\cup Y]=f[X]\cup f[Y]

Let bf[XY]b \in f[X\cup Y]. Then there exists aXYa \in X\cup Y such that:

f(a)=b f(a)=b

Since aXYa \in X\cup Y, either aXa \in X or aYa \in Y. If aXa \in X, then bf[X]b \in f[X]. If aYa \in Y, then bf[Y]b \in f[Y]. Hence:

bf[X]f[Y] b \in f[X]\cup f[Y]

Thus:

f[XY]f[X]f[Y] f[X\cup Y]\subseteq f[X]\cup f[Y]

Conversely, let bf[X]f[Y]b \in f[X]\cup f[Y]. Then either bf[X]b \in f[X] or bf[Y]b \in f[Y].

If bf[X]b \in f[X], then there exists aXa \in X such that f(a)=bf(a)=b. Since XXYX\subseteq X\cup Y, we have aXYa \in X\cup Y, so bf[XY]b \in f[X\cup Y].

If bf[Y]b \in f[Y], the same argument shows bf[XY]b \in f[X\cup Y].

Therefore:

f[X]f[Y]f[XY] f[X]\cup f[Y]\subseteq f[X\cup Y]

By double inclusion:

f[XY]=f[X]f[Y] f[X\cup Y]=f[X]\cup f[Y]

Now we prove:

f[XY]f[X]f[Y] f[X\cap Y]\subseteq f[X]\cap f[Y]

Let bf[XY]b \in f[X\cap Y]. Then there exists aXYa \in X\cap Y such that:

f(a)=b f(a)=b

Since aXYa \in X\cap Y, we have aXa \in X and aYa \in Y. Therefore bf[X]b \in f[X] and bf[Y]b \in f[Y]. Hence:

bf[X]f[Y] b \in f[X]\cap f[Y]

So:

f[XY]f[X]f[Y] f[X\cap Y]\subseteq f[X]\cap f[Y]

The reverse inclusion does not hold for arbitrary functions, because two different elements may have the same image.

Definition 7.35 (Injective, Surjective, Bijective)

Let:

f:AB f:A\to B

The function ff is injective if distinct inputs have distinct outputs:

x,yA, f(x)=f(y)x=y \forall x,y \in A,\ f(x)=f(y)\to x=y

The function ff is surjective if every element of the codomain is hit by the function:

bB, aA, f(a)=b \forall b \in B,\ \exists a \in A,\ f(a)=b

The function ff is bijective if it is both injective and surjective.

Injective functions are also called one to one functions. Surjective functions are also called onto functions.

Example 7.36

The function:

f:ZZ f:\mathbb{Z}\to\mathbb{Z}

defined by:

f(n)=n+1 f(n)=n+1

is bijective.

It is injective because if:

n+1=m+1 n+1=m+1

then:

n=m n=m

It is surjective because for every kZk\in\mathbb{Z}, the integer:

k1 k-1

satisfies:

f(k1)=k f(k-1)=k

The function:

g:NN g:\mathbb{N}\to\mathbb{N}

defined by:

g(n)=n+1 g(n)=n+1

is injective but not surjective if 0N0\in\mathbb{N}, because no natural number maps to 00.

Lemma 7.37 (Inverse of a Bijection)

Let:

f:AB f:A\to B

be a bijection. Then there exists a unique function:

f1:BA f^{-1}:B\to A

such that:

f1(f(a))=a f^{-1}(f(a))=a

for all aAa\in A, and:

f(f1(b))=b f(f^{-1}(b))=b

for all bBb\in B.

Proof

Since ff is surjective, for every bBb\in B there exists at least one aAa\in A such that:

f(a)=b f(a)=b

Since ff is injective, this element aa is unique. Indeed, if:

f(a)=b f(a)=b

and:

f(a)=b f(a')=b

then:

f(a)=f(a) f(a)=f(a')

and injectivity gives:

a=a a=a'

Therefore, for each bBb\in B, there is a unique aAa\in A satisfying f(a)=bf(a)=b. Define:

f1(b)=a f^{-1}(b)=a

where aa is this unique element.

This defines a function:

f1:BA f^{-1}:B\to A

By construction, if b=f(a)b=f(a), then the unique element mapping to bb is aa, so:

f1(f(a))=a f^{-1}(f(a))=a

Also, for any bBb\in B, the definition of f1(b)f^{-1}(b) gives:

f(f1(b))=b f(f^{-1}(b))=b

Uniqueness follows because any function satisfying these two identities must send each bBb\in B to the unique element of AA that maps to bb under ff.

Definition 7.38 (Composition)

Let:

f:AB f:A\to B

and:

g:BC g:B\to C

The composition of gg with ff is the function:

gf:AC g\circ f:A\to C

defined by:

(gf)(a)=g(f(a)) (g\circ f)(a)=g(f(a))

for all aAa\in A.

The function ff is applied first, and then gg is applied.

Lemma 7.39 (Associativity of Composition)

Let:

f:AB f:A\to B g:BC g:B\to C h:CD h:C\to D

Then:

h(gf)=(hg)f h\circ(g\circ f)=(h\circ g)\circ f

Proof

To prove equality of functions, it is enough to show that they have the same value at every input.

Let aAa\in A. Then:

(h(gf))(a)=h((gf)(a)) (h\circ(g\circ f))(a) = h((g\circ f)(a))

By definition of composition:

h((gf)(a))=h(g(f(a))) h((g\circ f)(a)) = h(g(f(a)))

On the other hand:

((hg)f)(a)=(hg)(f(a)) ((h\circ g)\circ f)(a) = (h\circ g)(f(a))

Again by definition of composition:

(hg)(f(a))=h(g(f(a))) (h\circ g)(f(a)) = h(g(f(a)))

Thus:

(h(gf))(a)=((hg)f)(a) (h\circ(g\circ f))(a)=((h\circ g)\circ f)(a)

for every aAa\in A. Therefore:

h(gf)=(hg)f h\circ(g\circ f)=(h\circ g)\circ f

Definition 7.40 (Identity Function)

For a set AA, the identity function on AA is:

idA:AA \mathrm{id}_A:A\to A

defined by:

idA(a)=a \mathrm{id}_A(a)=a

for all aAa\in A.

Lemma 7.41 (Identity Laws)

Let:

f:AB f:A\to B

Then:

fidA=f f\circ \mathrm{id}_A=f

and:

idBf=f \mathrm{id}_B\circ f=f

Proof

Let aAa\in A. Then:

(fidA)(a)=f(idA(a))=f(a) (f\circ \mathrm{id}_A)(a) = f(\mathrm{id}_A(a)) = f(a)

Thus:

fidA=f f\circ \mathrm{id}_A=f

Also:

(idBf)(a)=idB(f(a))=f(a) (\mathrm{id}_B\circ f)(a) = \mathrm{id}_B(f(a)) = f(a)

Thus:

idBf=f \mathrm{id}_B\circ f=f