Raw

Lecture 3. Relations

Learning objectives

After studying this chapter you should be able to:

  • state precisely what a binary relation and an nn-ary relation are, and move fluently between the three standard representations (set of pairs, Boolean matrix, digraph);
  • recognise and prove the structural properties of a relation — reflexive, irreflexive, symmetric, antisymmetric, asymmetric, transitive — including their algebraic characterisations (ΔAR\Delta_A\subseteq R, R=R1R=R^{-1}, R2RR^2\subseteq R, RR1ΔAR\cap R^{-1}\subseteq\Delta_A);
  • compute inverses and compositions, and justify why composition is realised by the Boolean matrix product and why it is associative;
  • construct the reflexive, symmetric and transitive closures of a relation, prove the formula t(R)=k1Rkt(R)=\bigcup_{k\ge1}R^{k}, and explain why the union is finite on a finite set;
  • prove the Fundamental Theorem of Equivalence Relations (equivalence relations \leftrightarrow partitions) in both directions and apply it to congruence classes in modular arithmetic;
  • analyse partial orders: comparability, Hasse diagrams, minimal/maximal and least/greatest elements, bounds, and a first look at lattices;
  • connect the theory to computer science, especially the relational database model and relational algebra.

This chapter builds directly on Lecture 1 (subsets, power sets) and Lecture 2 (set operations, ordered tuples, and the Cartesian product). It is used later whenever we group outcomes into cases — for example in Lecture 13, where an equivalence relation on a sample space partitions it into the disjoint events that make counting and probability tractable.

3.1 Overview and motivation

Sets on their own describe collections of objects, but almost every interesting mathematical or computational statement is about how objects are linked: “xx is less than yy”, “student ss received mark mm in subject jj”, “city aa has a direct flight to city bb”, “web page uu links to page vv”, “process pp must run before process qq”. A relation is the mathematical object that captures exactly this idea of a link between elements — nothing more and nothing less.

The whole subject rests on one deceptively small idea from Lecture 2: an ordered pair (a,b)(a,b) remembers not only which two objects are involved but also which comes first. (Recall Kuratowski’s set-theoretic encoding (a,b)={{a},{a,b}}(a,b)=\{\{a\},\{a,b\}\}, which makes (a,b)=(c,d)(a,b)=(c,d) hold iff a=ca=c and b=db=d.) A relation is then simply a set of such pairs selected out of a Cartesian product. Everything else in this chapter — matrices, digraphs, equivalence classes, orders, database tables — is a consequence of taking that one definition seriously.

Three themes recur throughout:

  1. One object, several faces. A relation is simultaneously a set of tuples, a Boolean matrix, and a directed graph. Each face makes some questions trivial: the matrix face turns “is there a two-step path?” into arithmetic; the graph face makes reachability visible; the set face makes union/intersection obvious.
  2. Structure via properties. A handful of properties (reflexive, symmetric, transitive, …) carve out the two most important species of relation: equivalence relations, which formalise “the same for our purposes”, and partial orders, which formalise “ranking, possibly with ties left incomparable”.
  3. From theory to systems. The generalisation to nn-ary relations is not an afterthought: it is literally the data model of every relational database, and the set operations of Lecture 2 reappear as the core of relational algebra and hence of SQL.

3.2 Tuples and the Cartesian product (recap from Lecture 2)

A tuple is an ordered list of elements. Given sets A,B,CA,B,C, an ordered triple is written (a,b,c)(a,b,c) with aAa\in A, bBb\in B, cCc\in C; order matters and repetition is allowed, distinguishing tuples from sets. The Cartesian product collects all such tuples:

X=A×B×C={(a,b,c)aA, bB, cC}.X = A \times B \times C = \{(a,b,c) \mid a\in A,\ b\in B,\ c\in C\}.

For finite sets the product rule gives A×B×C=ABC|A\times B\times C| = |A|\cdot|B|\cdot|C|.

Example. With A={1,2,3}A=\{1,2,3\}, B={4,5}B=\{4,5\}, C={6,7}C=\{6,7\} we get X=322=12|X| = 3\cdot 2\cdot 2 = 12 triples:

X={(1,4,6),(1,4,7),(1,5,6),(1,5,7),(2,4,6),(2,4,7),X = \{(1,4,6),(1,4,7),(1,5,6),(1,5,7),(2,4,6),(2,4,7),

(2,5,6),(2,5,7),(3,4,6),(3,4,7),(3,5,6),(3,5,7)}.(2,5,6),(2,5,7),(3,4,6),(3,4,7),(3,5,6),(3,5,7)\}.

The Cartesian product is the “universe” of all conceivable tuples; a relation picks out the tuples we actually care about.

Remark (why order and repetition matter). The pair (2,5)(2,5) is not the pair (5,2)(5,2), and (3,3)(3,3) is a perfectly good pair even though the set {3,3}={3}\{3,3\}=\{3\} collapses. This is precisely why relations can express asymmetric links such as “xx is the parent of yy” that a symmetric set-of-two could never record.

3.3 Binary relations as subsets of a Cartesian product

Definition 3.1 (binary relation). A binary relation RR from a set AA to a set BB is any subset RA×BR \subseteq A \times B. When A=BA=B we say RR is a relation on AA (so RA×AR\subseteq A\times A). Its elements are ordered pairs (a,b)(a,b).

Two notations mean exactly the same thing:

(a,b)RaRb,(a,b)\in R \qquad\Longleftrightarrow\qquad aRb,

read “aa is related to bb”. They are interchangeable because RR is its set of pairs — the infix statement aRbaRb is only shorthand for membership in that set. The infix form mirrors the familiar aba \le b or a=ba = b and is usually more readable; we shall use whichever is clearer.

There are two standard ways to specify a relation:

  1. By listing the ordered pairs explicitly (an extensional definition), and
  2. By a predicate, i.e. a defining property (an intensional definition): R={(x,y)P(x,y)}R = \{(x,y) \mid P(x,y)\}.

Example 3.2 (both ways, one relation). Let A=B={1,2,3,4}A = B = \{1,2,3,4\} and let RR be “strictly less than”. Extensionally,

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

intensionally,

R={(x,y)xA, yB, x<y}.R = \{(x,y) \mid x\in A,\ y\in B,\ x<y\}.

Both describe the same six pairs. The intensional form scales to infinite sets (the relation << on Z\mathbb{Z}) where listing is impossible.

More examples of the infix form aRbaRb.

  • R1=R_1={} “less than or equal to”: 4R1164\,R_1\,16, 5R175\,R_1\,7, 3R133\,R_1\,3.
  • R2=R_2={} “is divisible by”: 4R224\,R_2\,2, 9R239\,R_2\,3, 7R217\,R_2\,1.
  • R3=R_3={} “uses the same digits as”: 132R3123132\,R_3\,123, 34R34334\,R_3\,43, 121R31112121\,R_3\,1112 (both sides use only the digits {1,2}\{1,2\}).

Common pitfall (a relation is not a rule). A relation need not be describable by any tidy formula. On {1,2,3}\{1,2,3\} the set {(1,3),(3,1),(2,2)}\{(1,3),(3,1),(2,2)\} is a perfectly legitimate relation even though no arithmetic condition singles out those three pairs. Conversely, do not confuse the predicate with the relation: two different predicates (x<yx<y and “yxy-x is a positive integer”) can define the same relation.

3.4 Domain and range

For RA×BR \subseteq A \times B:

Definition 3.3. The domain of RR is dom(R)={aAbB, (a,b)R}\operatorname{dom}(R) = \{a\in A \mid \exists b\in B,\ (a,b)\in R\} — the first components that actually occur. The range (or image) of RR is ran(R)={bBaA, (a,b)R}\operatorname{ran}(R) = \{b\in B \mid \exists a\in A,\ (a,b)\in R\} — the second components that actually occur.

Example 3.4. For the “strictly less than” relation of Example 3.2, dom(R)={1,2,3}\operatorname{dom}(R) = \{1,2,3\} (the value 44 is less than nothing in AA) and ran(R)={2,3,4}\operatorname{ran}(R) = \{2,3,4\} (nothing is less than 11). Both are subsets of AA; neither need be all of AA.

Remark. The domain and range are projections of RR onto its first and second coordinates. We will meet projection again in §3.11 as the relational- algebra operator π\pi; it is the very same idea applied to nn-ary relations.

3.5 Representing a relation

A relation admits three interchangeable representations; picking the right one often turns a hard-looking question into an easy one.

3.5.1 As a set of ordered pairs

The direct definition, e.g. R={(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)}R = \{(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)\}. This is compact for sparse relations and makes set operations (,,\cup,\cap,\setminus) transparent.

3.5.2 As a relation matrix (Boolean / adjacency matrix)

For a relation on a finite set A={a1,,an}A=\{a_1,\dots,a_n\}, build an n×nn\times n table indexed by the elements. The entry in row aia_i, column aja_j is

mij={1if aiRaj,0otherwise.m_{ij} = \begin{cases}1 & \text{if } a_iRa_j,\\[2pt] 0 & \text{otherwise.}\end{cases}

Relation matrix on a small set: the entry in row , column  is  exactly when  is related to

For the “strictly less than” relation on {1,2,3,4}\{1,2,3,4\}:

x\yx \backslash y 1 2 3 4
1 0 1 1 1
2 0 0 1 1
3 0 0 0 1
4 0 0 0 0

The matrix form is ideal for checking structural properties by inspection and for computing compositions and closures (below). Its size is fixed at n2n^2 bits regardless of how many pairs are present, so it is best for dense relations.

3.5.3 As a directed graph (digraph)

Draw one vertex (node) per element and one arrow aba \to b for every pair (a,b)R(a,b)\in R. A pair (a,a)(a,a) becomes a self-loop at aa. For “strictly less than” on {1,2,3,4}\{1,2,3,4\} the digraph has four vertices with arrows from every smaller number to every larger one.

A relation drawn as a digraph: one node per element, an arrow  for each pair , and a self-loop for a pair

The strict order "less than" on {1,2,3,4} as a digraph: an arrow from every smaller number to every larger one, with no self-loops

Two extreme relations are worth naming, both instantly recognisable in matrix form:

  • Universal (full) relationR=A×AR = A\times A; every pair is related, so the matrix is all ones.
  • Empty relationR=R = \varnothing; no pair is related, so the matrix is all zeros.

A third, quietly important, is the identity (diagonal) relation

ΔA={(a,a)aA},\Delta_A = \{(a,a)\mid a\in A\},

also called the equality relation; its matrix is the identity matrix InI_n and its digraph is a self-loop at every vertex and nothing else. We will use ΔA\Delta_A constantly when defining reflexive closures and powers of a relation.

Remark (bridge to Lecture 10). A relation on a set is exactly the data of a directed graph, and a symmetric relation with no self-loops is exactly an undirected graph. The matrix MRM_R is the graph’s adjacency matrix. Graph theory (Lecture 10) can therefore be read as the study of relations from a visual, combinatorial angle.

3.6 Properties of binary relations

Let RR be a relation on a set AA. The following properties classify how RR behaves; each has a crisp logical definition, a matrix “fingerprint”, and — as we prove in §3.6.1 — a slick algebraic form.

Definition 3.5. The relation RR on AA is

  • reflexive if aA: aRa\forall a\in A:\ aRa. Matrix: the whole main diagonal is 11.
  • irreflexive if aA: ¬(aRa)\forall a\in A:\ \lnot(aRa). Matrix: the whole diagonal is 00.
  • symmetric if a,b: aRbbRa\forall a,b:\ aRb \Rightarrow bRa. Matrix: M=MTM=M^{\mathsf T}.
  • antisymmetric if a,b: (aRbbRa)a=b\forall a,b:\ (aRb \wedge bRa) \Rightarrow a=b. Matrix: no off-diagonal mirror pair mij=mji=1m_{ij}=m_{ji}=1 with iji\ne j.
  • asymmetric if a,b: aRb¬(bRa)\forall a,b:\ aRb \Rightarrow \lnot(bRa). Matrix: zero main diagonal and no mirror pair mij=mji=1m_{ij}=m_{ji}=1 (equivalently RR1=R\cap R^{-1}=\varnothing).
  • transitive if a,b,c: (aRbbRc)aRc\forall a,b,c:\ (aRb \wedge bRc) \Rightarrow aRc. Matrix: wherever a two-step path exists, the direct entry is also 11.
  • antitransitive if a,b,c: (aRbbRc)¬(aRc)\forall a,b,c:\ (aRb \wedge bRc) \Rightarrow \lnot(aRc) — a two-step path never has its direct shortcut. Example: the successor chain {(1,2),(2,3),(3,4)}\{(1,2),(2,3),(3,4)\} on {1,2,3,4}\{1,2,3,4\}; or “beats” in rock–paper–scissors.

Common pitfall (reflexive vs. irreflexive are not opposites). A relation can be neither. On {1,2}\{1,2\} the relation {(1,1)}\{(1,1)\} has 1R11R1 but not 2R22R2, so it is neither reflexive (misses 2R22R2) nor irreflexive (has 1R11R1). “Not reflexive” means some diagonal entry is missing; “irreflexive” means every diagonal entry is missing. Likewise symmetric and antisymmetric are not opposites: the identity relation ΔA\Delta_A is both, while {(1,2),(2,1),(1,3)}\{(1,2),(2,1),(1,3)\} is neither.

Proposition 3.6 (asymmetric == irreflexive ++ antisymmetric). RR is asymmetric iff RR is both irreflexive and antisymmetric.

Proof. (\Rightarrow) Suppose RR is asymmetric. Taking b=ab=a in the definition, aRa¬(aRa)aRa\Rightarrow\lnot(aRa), which forces ¬(aRa)\lnot(aRa) for every aa; hence RR is irreflexive. For antisymmetry, suppose aRbaRb and bRabRa; asymmetry applied to aRbaRb gives ¬(bRa)\lnot(bRa), contradicting bRabRa. So the hypothesis aRbbRaaRb\wedge bRa is never satisfiable, and the implication “aRbbRaa=baRb\wedge bRa\Rightarrow a=b” holds vacuously. (\Leftarrow) Suppose RR is irreflexive and antisymmetric, and suppose aRbaRb. If also bRabRa, antisymmetry gives a=ba=b, whence aRaaRa — contradicting irreflexivity. Therefore ¬(bRa)\lnot(bRa), and RR is asymmetric.   \;\blacksquare

A strict order such as << on Z\mathbb{Z} is the archetypal asymmetric relation.

Worked example 3.7 (checking properties from a matrix). Consider RR on {1,2,3,4}\{1,2,3,4\}:

x\yx \backslash y 1 2 3 4
1 0 0 1 1
2 1 0 1 1
3 0 0 0 0
4 0 0 0 0

So R={(1,3),(1,4),(2,1),(2,3),(2,4)}R=\{(1,3),(1,4),(2,1),(2,3),(2,4)\}.

  • Reflexive? No — the diagonal is all 00 (in fact RR is irreflexive).
  • Symmetric? No — (2,1)R(2,1)\in R but (1,2)R(1,2)\notin R.
  • Antisymmetric? Yes — there is no mirror pair mij=mji=1m_{ij}=m_{ji}=1 with iji\ne j.
  • Transitive? Yes — the only two-step chains start at 22: 2R12R1 then 1R31R3 needs 2R32R3 ✓, and 2R12R1 then 1R41R4 needs 2R42R4 ✓. Every other chain dies immediately because rows 33 and 44 are empty. Since all required “shortcuts” are present, RR is transitive.

Worked example 3.8 (a symmetric relation). The matrix

x\yx \backslash y 1 2 3 4
1 0 1 1 0
2 1 0 0 0
3 1 0 0 0
4 0 0 0 0

satisfies M=MTM=M^{\mathsf T}, so RR is symmetric: every arrow aba\to b is matched by bab\to a, and in the digraph edges come in bidirectional pairs. It is not transitive: 2R12R1 and 1R31R3 but ¬(2R3)\lnot(2R3).

3.6.1 Algebraic characterisations

Each property can be phrased purely in the algebra of relations — using the identity relation ΔA\Delta_A, the inverse R1R^{-1} (§3.7) and composition R2=RRR^2=R\circ R. These forms are the ones that make later proofs short.

Theorem 3.9. For a relation RR on AA:

  1. RR is reflexive     ΔAR\iff \Delta_A \subseteq R.
  2. RR is symmetric     R=R1\iff R = R^{-1}.
  3. RR is antisymmetric     RR1ΔA\iff R \cap R^{-1} \subseteq \Delta_A.
  4. RR is transitive     R2R\iff R^2 \subseteq R (equivalently RRRR\circ R\subseteq R).

Proof. (1) ΔAR\Delta_A\subseteq R says (a,a)R(a,a)\in R for all aa, i.e. aRaaRa for all aa — the definition of reflexive.

(2) By definition R1={(b,a)(a,b)R}R^{-1}=\{(b,a)\mid (a,b)\in R\}. If RR is symmetric and (a,b)R1(a,b)\in R^{-1} then (b,a)R(b,a)\in R, so by symmetry (a,b)R(a,b)\in R; hence R1RR^{-1}\subseteq R. The reverse inclusion RR1R\subseteq R^{-1} is symmetric (swap roles), giving R=R1R=R^{-1}. Conversely if R=R1R=R^{-1} and aRbaRb, then (a,b)R=R1(a,b)\in R=R^{-1}, so (b,a)R(b,a)\in R, i.e. bRabRa; thus RR is symmetric.

(3) Suppose RR is antisymmetric and (a,b)RR1(a,b)\in R\cap R^{-1}. Then (a,b)R(a,b)\in R (so aRbaRb) and (a,b)R1(a,b)\in R^{-1} (so (b,a)R(b,a)\in R, i.e. bRabRa); antisymmetry gives a=ba=b, so (a,b)ΔA(a,b)\in\Delta_A. Conversely, suppose RR1ΔAR\cap R^{-1}\subseteq\Delta_A and aRbbRaaRb\wedge bRa. Then (a,b)R(a,b)\in R and (a,b)R1(a,b)\in R^{-1}, so (a,b)RR1ΔA(a,b)\in R\cap R^{-1}\subseteq\Delta_A, whence a=ba=b.

(4) Suppose RR is transitive and (a,c)R2=RR(a,c)\in R^2=R\circ R. Then there is bb with (a,b)R(a,b)\in R and (b,c)R(b,c)\in R; transitivity gives (a,c)R(a,c)\in R. Hence R2RR^2\subseteq R. Conversely suppose R2RR^2\subseteq R and aRbbRcaRb\wedge bRc. Then (a,c)RR=R2R(a,c)\in R\circ R=R^2\subseteq R, so aRcaRc; thus RR is transitive.   \;\blacksquare

Remark. Part (4) is the engine behind transitive closure (§3.8): “make RR transitive” means “keep composing RR with itself until nothing new appears”.

3.6.2 Counting relations with a given property

Because a relation on an nn-element set is exactly a filling of an n×nn\times n grid of bits, counting them is pure combinatorics — a favourite source of exam problems and a first taste of the counting techniques of later lectures.

Proposition 3.10. On a set with A=n|A|=n:

  • the number of relations is 2n22^{n^2};
  • the number of reflexive relations is 2n2n2^{\,n^2-n};
  • the number of symmetric relations is 2n(n+1)/22^{\,n(n+1)/2};
  • the number of antisymmetric relations is 2n3(n2)2^{\,n}\,3^{\,\binom{n}{2}}.

Proof. Each of the n2n^2 cells is independently 00 or 11, giving 2n22^{n^2} relations. For reflexive relations the nn diagonal cells are forced to 11 and the remaining n2nn^2-n cells are free: 2n2n2^{\,n^2-n}. For symmetric relations the nn diagonal cells are free and the (n2)\binom{n}{2} cells strictly above the diagonal are free, while each cell below the diagonal is forced to equal its mirror; this gives 2n+(n2)=2n(n+1)/22^{\,n+\binom{n}{2}}=2^{\,n(n+1)/2}. For antisymmetric relations the nn diagonal cells are free (2n2^n choices), while each of the (n2)\binom{n}{2} mirror-pairs {(i,j),(j,i)}\{(i,j),(j,i)\} with i<ji<j may be filled in exactly 33 admissible ways — 0000, 1010, or 0101 (but not 1111) — giving 2n3(n2)2^{\,n}\,3^{\,\binom{n}{2}}.   \;\blacksquare

Example 3.11. For n=3n=3: 29=5122^{9}=512 relations in all; 26=642^{6}=64 reflexive; 26=642^{6}=64 symmetric; 2333=827=2162^{3}\,3^{3}=8\cdot27=216 antisymmetric; and 2(32)=23=82^{\binom32}=2^{3}=8 relations that are both reflexive and symmetric (diagonal forced to 11, the three upper cells free).

3.7 Inverse and composition of relations

Definition 3.12 (inverse). The inverse (or converse) of RA×BR\subseteq A\times B is

R1={(b,a)(a,b)R}B×A,R^{-1} = \{(b,a) \mid (a,b)\in R\} \subseteq B\times A,

so that bR1a    aRbbR^{-1}a \iff aRb. In matrix terms MR1=MRTM_{R^{-1}} = M_R^{\mathsf T}; in the digraph, every arrow is reversed.

For instance the inverse of “less than” is “greater than”, and the inverse of “is a child of” is “is a parent of”. By Theorem 3.9(2), RR is symmetric exactly when R=R1R=R^{-1}.

Definition 3.12a (complement). The complement of a relation RR on a set AA is R=(A×A)R\overline{R} = (A\times A)\setminus R — the pairs RR omits — so that aRb    ¬(aRb)a\,\overline{R}\,b \iff \lnot(aRb). In matrix terms every entry flips 010\leftrightarrow 1; in the digraph, present and absent arrows swap. For example, the complement of << is \ge, and the complement of == is \ne.

Definition 3.13 (composition). Given RA×BR\subseteq A\times B and SB×CS\subseteq B\times C, their composition SRA×CS\circ R \subseteq A\times C is

SR={(a,c)bB: (a,b)R and (b,c)S}.S\circ R = \{(a,c) \mid \exists\, b\in B:\ (a,b)\in R \text{ and } (b,c)\in S\}.

Read SRS\circ R right-to-left: “RR first, then SS”, exactly as with function composition gfg\circ f. Composition chains relations through a common middle set.

Composition  chains two relations through a middle set : follow an arrow  then  to obtain a pair in

Common pitfall (order matters, and it flips for matrices). In general SRRSS\circ R \ne R\circ S; they may even live in different Cartesian products. And note the reversal in the matrix formula below: the composite SRS\circ R corresponds to the product MRMSM_R M_S, with the factors in the opposite order to the composition symbols.

Worked example 3.14. Let A={1,2}A=\{1,2\}, B={x,y,z}B=\{x,y,z\}, C={p,q}C=\{p,q\}, with R={(1,x),(1,y),(2,z)}R=\{(1,x),(1,y),(2,z)\} and S={(x,p),(y,q),(z,q)}S=\{(x,p),(y,q),(z,q)\}. Tracing paths 1xp1\to x\to p, 1yq1\to y\to q, 2zq2\to z\to q gives

SR={(1,p), (1,q), (2,q)}.S\circ R = \{(1,p),\ (1,q),\ (2,q)\}.

3.7.1 Composition via the Boolean matrix product

The Boolean matrix product multiplies two 0/10/1 matrices like ordinary matrices but with logical OR (\vee) in place of ++ and logical AND (\wedge) in place of \cdot. For an m×nm\times n matrix PP and an n×pn\times p matrix QQ,

(PQ)ik=j=1n(pijqjk).\bigl(P\odot Q\bigr)_{ik} = \bigvee_{j=1}^{n}\bigl(p_{ij}\wedge q_{jk}\bigr).

Theorem 3.15 (composition = Boolean product). Let RA×BR\subseteq A\times B and SB×CS\subseteq B\times C with A={a1,,am}A=\{a_1,\dots,a_m\}, B={b1,,bn}B=\{b_1,\dots,b_n\}, C={c1,,cp}C=\{c_1,\dots,c_p\}. Then

MSR  =  MRMS.M_{S\circ R} \;=\; M_R \odot M_S .

Proof. Write MR=[rij]M_R=[r_{ij}] (so rij=1    (ai,bj)Rr_{ij}=1 \iff (a_i,b_j)\in R) and MS=[sjk]M_S=[s_{jk}] (so sjk=1    (bj,ck)Ss_{jk}=1 \iff (b_j,c_k)\in S). Fix indices i,ki,k. By the definition of the Boolean product,

(MRMS)ik=1    j{1,,n}: rijsjk=1    j: rij=1 and sjk=1.\bigl(M_R\odot M_S\bigr)_{ik}=1 \iff \exists\, j\in\{1,\dots,n\}:\ r_{ij}\wedge s_{jk}=1 \iff \exists\, j:\ r_{ij}=1 \text{ and } s_{jk}=1.

By the meaning of the matrix entries this says

bjB: (ai,bj)R and (bj,ck)S,\exists\, b_j\in B:\ (a_i,b_j)\in R \text{ and } (b_j,c_k)\in S,

which is precisely the defining condition for (ai,ck)SR(a_i,c_k)\in S\circ R (Definition 3.13). Hence (MRMS)ik=1    (ai,ck)SR    (MSR)ik=1\bigl(M_R\odot M_S\bigr)_{ik}=1 \iff (a_i,c_k)\in S\circ R \iff \bigl(M_{S\circ R}\bigr)_{ik}=1. As the two matrices agree in every entry, they are equal.   \;\blacksquare

Worked example 3.16 (Example 3.14, done by matrix). Index A=(1,2)A=(1,2), B=(x,y,z)B=(x,y,z), C=(p,q)C=(p,q):

MR=(110001),MS=(100101).M_R=\begin{pmatrix}1&1&0\\0&0&1\end{pmatrix},\qquad M_S=\begin{pmatrix}1&0\\0&1\\0&1\end{pmatrix}.

Then

MRMS=((11)(10)(00)(10)(11)(01)(01)(00)(10)(00)(01)(11))=(1101),M_R\odot M_S=\begin{pmatrix}(1\wedge1)\vee(1\wedge0)\vee(0\wedge0) & (1\wedge0)\vee(1\wedge1)\vee(0\wedge1)\\[2pt](0\wedge1)\vee(0\wedge0)\vee(1\wedge0) & (0\wedge0)\vee(0\wedge1)\vee(1\wedge1)\end{pmatrix} =\begin{pmatrix}1&1\\0&1\end{pmatrix},

i.e. SR={(1,p),(1,q),(2,q)}S\circ R=\{(1,p),(1,q),(2,q)\}, reproducing the hand computation.

Remark (why OR, not ++). A relation records only whether a connecting element exists, never how many. Using ordinary ++ would count the number of intermediate bb’s (e.g. give a 22), which is meaningless for a 0/10/1 relation. Replacing ++ by \vee (equivalently, capping every sum at 11) keeps us inside {0,1}\{0,1\} and matches the existential quantifier “b\exists b” in Definition 3.13.

3.7.2 Associativity, and powers of a relation

Theorem 3.17 (associativity of composition). For RA×BR\subseteq A\times B, SB×CS\subseteq B\times C, TC×DT\subseteq C\times D,

T(SR)=(TS)R.T\circ(S\circ R) = (T\circ S)\circ R.

Proof. Both sides are subsets of A×DA\times D; we show they contain the same pairs. For arbitrary (a,d)A×D(a,d)\in A\times D,

(a,d)T(SR)    cC: (a,c)SR  (c,d)T    cC: (bB: (a,b)R(b,c)S)(c,d)T    bB cC: (a,b)R(b,c)S(c,d)T.\begin{aligned} (a,d)\in T\circ(S\circ R) &\iff \exists c\in C:\ (a,c)\in S\circ R \ \wedge\ (c,d)\in T\\ &\iff \exists c\in C:\ \bigl(\exists b\in B:\ (a,b)\in R \wedge (b,c)\in S\bigr)\wedge (c,d)\in T\\ &\iff \exists b\in B\ \exists c\in C:\ (a,b)\in R \wedge (b,c)\in S \wedge (c,d)\in T. \end{aligned}

On the other side,

(a,d)(TS)R    bB: (a,b)R  (b,d)TS    bB: (a,b)R(cC: (b,c)S(c,d)T)    cC bB: (a,b)R(b,c)S(c,d)T.\begin{aligned} (a,d)\in (T\circ S)\circ R &\iff \exists b\in B:\ (a,b)\in R \ \wedge\ (b,d)\in T\circ S\\ &\iff \exists b\in B:\ (a,b)\in R \wedge \bigl(\exists c\in C:\ (b,c)\in S \wedge (c,d)\in T\bigr)\\ &\iff \exists c\in C\ \exists b\in B:\ (a,b)\in R \wedge (b,c)\in S \wedge (c,d)\in T. \end{aligned}

The two final conditions differ only in the order of the independent existential quantifiers bc\exists b\,\exists c versus cb\exists c\,\exists b; since bb and cc range over unrelated sets, both simply assert the existence of a pair (b,c)B×C(b,c)\in B\times C with the stated three-part property. Hence the conditions are logically equivalent, and the two sets coincide.   \;\blacksquare

Associativity is exactly what lets us write powers of a relation on AA without brackets. Define

R1=R,Rk+1=RRk(k1),R^{1}=R,\qquad R^{k+1}=R\circ R^{k}\quad(k\ge1),

and, for reflexive/transitive purposes, R0=ΔAR^{0}=\Delta_A. By Theorem 3.17, RiRj=Ri+jR^{i}\circ R^{j}=R^{\,i+j} regardless of grouping, and by Theorem 3.15 the powers are computed by repeated Boolean matrix products: MRk=MRkM_{R^{k}}=M_R^{\odot k}.

Lemma 3.18 (powers count paths). For k1k\ge1, (a,b)Rk(a,b)\in R^{k} iff there exist x0,x1,,xkAx_0,x_1,\dots,x_k\in A with x0=ax_0=a, xk=bx_k=b, and (xt1,xt)R(x_{t-1},x_t)\in R for every t=1,,kt=1,\dots,k — that is, iff there is a directed walk of length kk from aa to bb in the digraph of RR.

Proof. Induction on kk. Base k=1k=1: R1=RR^{1}=R, and a walk of length 11 from aa to bb is exactly a single edge (a,b)R(a,b)\in R. Step: assume the claim for kk. Then

(a,b)Rk+1=RRk    cA: (a,c)Rk  (c,b)R.(a,b)\in R^{k+1}=R\circ R^{k} \iff \exists\, c\in A:\ (a,c)\in R^{k}\ \wedge\ (c,b)\in R.

By the induction hypothesis (a,c)Rk(a,c)\in R^{k} iff there is a walk a=x0,,xk=ca=x_0,\dots,x_k=c of length kk; appending the edge (c,b)R(c,b)\in R yields a walk a=x0,,xk=c, xk+1=ba=x_0,\dots,x_k=c,\ x_{k+1}=b of length k+1k+1. Conversely any length-(k+1)(k+1) walk from aa to bb splits at its penultimate vertex c=xkc=x_k into a length-kk walk aca\to c (so (a,c)Rk(a,c)\in R^{k}) followed by the edge (c,b)R(c,b)\in R. Hence (a,b)Rk+1(a,b)\in R^{k+1} iff such a walk exists.   \;\blacksquare

This “walks” reading is the key to understanding transitive closure, to which we now turn.

3.8 Closures of a relation

Sometimes a relation lacks a property we need. The closure of RR with respect to a property P\mathcal{P} is the smallest relation that contains RR and has property P\mathcal{P} — it adds as few pairs as possible. “Smallest” means: it is contained in every relation that contains RR and has P\mathcal{P}. (When such a smallest relation exists it is automatically unique, since if C1,C2C_1,C_2 were both smallest then C1C2C_1\subseteq C_2 and C2C1C_2\subseteq C_1.)

3.8.1 Reflexive and symmetric closures

Definition/Theorem 3.19. Let RR be a relation on AA.

  • The reflexive closure is r(R)=RΔAr(R)=R\cup\Delta_A.
  • The symmetric closure is s(R)=RR1s(R)=R\cup R^{-1}. Each is the smallest relation with the stated property containing RR.

Proof. Reflexive. r(R)ΔAr(R)\supseteq\Delta_A, so it is reflexive (Theorem 3.9(1)), and r(R)Rr(R)\supseteq R. If TT is any reflexive relation with RTR\subseteq T, then ΔAT\Delta_A\subseteq T (reflexivity) and RTR\subseteq T, hence r(R)=RΔATr(R)=R\cup\Delta_A\subseteq T. So r(R)r(R) is smallest.

Symmetric. First s(R)s(R) is symmetric: take (a,b)s(R)(a,b)\in s(R). If (a,b)R(a,b)\in R then (b,a)R1s(R)(b,a)\in R^{-1}\subseteq s(R); if (a,b)R1(a,b)\in R^{-1} then (b,a)Rs(R)(b,a)\in R\subseteq s(R); either way (b,a)s(R)(b,a)\in s(R). Clearly Rs(R)R\subseteq s(R). Now let TT be symmetric with RTR\subseteq T. Then RTR\subseteq T implies R1T1R^{-1}\subseteq T^{-1}, and T=T1T=T^{-1} by symmetry (Theorem 3.9(2)), so R1TR^{-1}\subseteq T. Hence s(R)=RR1Ts(R)=R\cup R^{-1}\subseteq T, and s(R)s(R) is smallest.   \;\blacksquare

3.8.2 Transitive closure and the connectivity relation

The transitive closure is subtler: adding shortcuts for existing two-step paths may create new two-step paths, which need their own shortcuts, and so on. The correct construction gathers all finite walks.

Definition 3.20. The transitive closure of RR is denoted t(R)t(R) or R+R^{+}, and the reflexive–transitive closure (or connectivity relation) is R=ΔAR+=k0RkR^{*}=\Delta_A\cup R^{+}=\bigcup_{k\ge0}R^{k}.

Theorem 3.21 (transitive-closure formula). For any relation RR on a set AA,

t(R)=k1Rk=RR2R3.t(R)=\bigcup_{k\ge1}R^{k}=R\cup R^{2}\cup R^{3}\cup\cdots .

That is, R+:=k1RkR^{+}:=\bigcup_{k\ge1}R^{k} is transitive, contains RR, and is contained in every transitive relation containing RR.

Proof. Write R+=k1RkR^{+}=\bigcup_{k\ge1}R^{k}. We verify the three defining properties.

(i) RR+R\subseteq R^{+}. Immediate, since R=R1R=R^{1} is one of the terms of the union.

(ii) R+R^{+} is transitive. Suppose (a,b)R+(a,b)\in R^{+} and (b,c)R+(b,c)\in R^{+}. Then (a,b)Ri(a,b)\in R^{i} for some i1i\ge1 and (b,c)Rj(b,c)\in R^{j} for some j1j\ge1. By Lemma 3.18 there is a walk of length ii from aa to bb and a walk of length jj from bb to cc; concatenating them (the first ends where the second begins) yields a walk of length i+ji+j from aa to cc. By Lemma 3.18 again, (a,c)Ri+jR+(a,c)\in R^{\,i+j} \subseteq R^{+}. Hence R+R^{+} is transitive.

(iii) Minimality. Let TT be any transitive relation with RTR\subseteq T. We show RkTR^{k}\subseteq T for all k1k\ge1 by induction. Base: R1=RTR^{1}=R\subseteq T. Step: assume RkTR^{k}\subseteq T. Take (a,b)Rk+1=RRk(a,b)\in R^{k+1}=R\circ R^{k}; then there is cc with (a,c)Rk(a,c)\in R^{k} and (c,b)R(c,b)\in R. By the induction hypothesis (a,c)T(a,c)\in T, and (c,b)RT(c,b)\in R\subseteq T; transitivity of TT gives (a,b)T(a,b)\in T. Thus Rk+1TR^{k+1}\subseteq T. By induction RkTR^{k}\subseteq T for every kk, so R+=k1RkTR^{+}=\bigcup_{k\ge1}R^{k}\subseteq T.

By (i)–(iii), R+R^{+} is a transitive relation containing RR and contained in every such relation; hence it is the smallest one, i.e. t(R)=R+t(R)=R^{+}.   \;\blacksquare

On an infinite set the union may be genuinely infinite (think of the successor relation nn+1n\mapsto n+1 on N\mathbb{N}, whose transitive closure is <<). On a finite set, however, the union stops early.

Theorem 3.22 (termination on a finite set). If A=n|A|=n, then

t(R)=k=1nRk=RR2Rn.t(R)=\bigcup_{k=1}^{n}R^{k}=R\cup R^{2}\cup\cdots\cup R^{n}.

Proof. Since t(R)=k1Rkt(R)=\bigcup_{k\ge1}R^{k} by Theorem 3.21, it suffices to prove that every RkR^{k} with k>nk>n is already contained in i=1nRi\bigcup_{i=1}^{n}R^{i}; the inclusion i=1nRit(R)\bigcup_{i=1}^{n}R^{i}\subseteq t(R) is clear. So suppose (a,b)Rk(a,b)\in R^{k} for some kk. Among all lengths 1\ell\ge1 for which (a,b)R(a,b)\in R^{\ell}, choose the minimum such \ell; by Lemma 3.18 there is a walk

a=x0,x1,,x=b,(xt1,xt)R.a=x_0,\,x_1,\,\dots,\,x_\ell=b,\qquad (x_{t-1},x_t)\in R.

We claim n\ell\le n. Suppose not, so n+1\ell\ge n+1; then the walk lists +1n+2\ell+1\ge n+2 vertices x0,,xx_0,\dots,x_\ell, all drawn from the nn-element set AA. By the pigeonhole principle two of them coincide: xs=xrx_s=x_r for some 0s<r0\le s<r\le \ell. Excise the loop between positions ss and rr to obtain the shorter sequence

a=x0,,xs  (=xr),xr+1,,x=b.a=x_0,\dots,x_s\;(=x_r),\,x_{r+1},\dots,x_\ell=b.

This is still a valid walk from aa to bb: the only new consecutive pair is (xs,xr+1)=(xr,xr+1)R(x_s,x_{r+1})=(x_r,x_{r+1})\in R, an original edge. Its length is (rs)<\ell-(r-s)<\ell, contradicting the minimality of \ell. Therefore n\ell\le n, so (a,b)Ri=1nRi(a,b)\in R^{\ell}\subseteq\bigcup_{i=1}^{n}R^{i}.   \;\blacksquare

Remark (Warshall’s algorithm — a CS connection). Theorem 3.22 already gives an algorithm: compute MR,MR2,,MRnM_R,M_R^{\odot2},\dots,M_R^{\odot n} by Boolean matrix products and OR them together, at a cost of O(n4)O(n^{4}) bit-operations. Warshall’s algorithm (Stephen Warshall, 1962) computes t(R)t(R) far more cleverly in O(n3)O(n^{3}): it processes the vertices v1,,vnv_1,\dots,v_n one at a time, after step kk recording exactly those pairs joined by a walk whose intermediate vertices all lie in {v1,,vk}\{v_1,\dots,v_k\}, via the update “mijmij(mikmkj)m_{ij}\leftarrow m_{ij}\vee(m_{ik}\wedge m_{kj})”. This is the Boolean specialisation of the Floyd–Warshall shortest-path algorithm and underlies reachability queries in graphs and databases.

Worked example 3.23 (all three closures). For R={(1,2),(2,3)}R=\{(1,2),(2,3)\} on {1,2,3}\{1,2,3\}:

r(R)=R{(1,1),(2,2),(3,3)};s(R)=R{(2,1),(3,2)};r(R)=R\cup\{(1,1),(2,2),(3,3)\};\qquad s(R)=R\cup\{(2,1),(3,2)\};

R2={(1,3)},R3=,sot(R)=RR2={(1,2),(2,3),(1,3)}.R^{2}=\{(1,3)\},\quad R^{3}=\varnothing,\quad\text{so}\quad t(R)=R\cup R^{2}=\{(1,2),(2,3),(1,3)\}.

Worked example 3.24 (closure can become universal). Let R={(1,2),(2,3),(3,4),(4,1)}R=\{(1,2),(2,3),(3,4),(4,1)\} be the directed 44-cycle on {1,2,3,4}\{1,2,3,4\}. Then

R2={(1,3),(2,4),(3,1),(4,2)},R3={(1,4),(2,1),(3,2),(4,3)},R^{2}=\{(1,3),(2,4),(3,1),(4,2)\},\quad R^{3}=\{(1,4),(2,1),(3,2),(4,3)\},

R4={(1,1),(2,2),(3,3),(4,4)},R^{4}=\{(1,1),(2,2),(3,3),(4,4)\},

and t(R)=RR2R3R4t(R)=R\cup R^{2}\cup R^{3}\cup R^{4} contains all 1616 pairs: the transitive closure of a directed cycle through every vertex is the universal relation. (Note R5=RR^{5}=R, so nothing new would ever appear — consistent with the bound kn=4k\le n=4 of Theorem 3.22.)

3.9 Equivalence relations, classes and partitions

Definition 3.25 (equivalence relation). A relation on AA that is simultaneously reflexive, symmetric and transitive is an equivalence relation. We usually write it \sim (or \equiv) and read aba\sim b as “aa is equivalent to bb”.

Equivalence relations formalise “being the same for our present purposes”: having the same remainder on division by nn, the same colour, the same connected component, the same last digit, the same value under some measurement. They are the tool by which we deliberately forget irrelevant distinctions.

Definition 3.26 (equivalence class). For aAa\in A, the equivalence class of aa is [a]={xAxa}[a]=\{x\in A\mid x\sim a\} — everything equivalent to aa. Any b[a]b\in[a] is called a representative of the class.

We also need the companion notion from Lecture 2.

Definition 3.27 (partition). A partition of a set AA is a collection P\mathcal{P} of subsets (the blocks or cells) of AA such that (i) every block is nonempty; (ii) distinct blocks are disjoint; and (iii) the blocks cover AA, i.e. P=A\bigcup\mathcal{P}=A.

The equivalence classes of a set are nonempty, pairwise disjoint, and together cover it — exactly a partition into blocks

3.9.1 The Fundamental Theorem of Equivalence Relations

We first isolate the two facts on which everything hinges.

Lemma 3.28. Let \sim be an equivalence relation on AA. For all a,bAa,b\in A,   ab    [a]=[b]\;a\sim b \iff [a]=[b].

Proof. (\Rightarrow) Suppose aba\sim b. We show [a][b][a]\subseteq[b]: if x[a]x\in[a] then xax\sim a; combined with aba\sim b, transitivity gives xbx\sim b, so x[b]x\in[b]. By symmetry aba\sim b also gives bab\sim a, and the same argument yields [b][a][b]\subseteq[a]. Hence [a]=[b][a]=[b]. (\Leftarrow) Suppose [a]=[b][a]=[b]. By reflexivity aaa\sim a, so a[a]=[b]a\in[a]=[b], which means aba\sim b.   \;\blacksquare

Lemma 3.29 (classes are equal or disjoint). Let \sim be an equivalence relation on AA. For all a,bAa,b\in A, either [a]=[b][a]=[b] or [a][b]=[a]\cap[b]=\varnothing.

Proof. Suppose the classes are not disjoint; we show they are equal. Pick c[a][b]c\in[a]\cap[b]. Then cac\sim a and cbc\sim b. By symmetry aca\sim c, and with cbc\sim b transitivity gives aba\sim b; Lemma 3.28 then yields [a]=[b][a]=[b]. So whenever the classes meet they coincide, which is exactly the stated dichotomy.   \;\blacksquare

Theorem 3.30 (Fundamental Theorem of Equivalence Relations). Let AA be a nonempty set.

  1. If \sim is an equivalence relation on AA, then the set of equivalence classes A/={[a]aA}A/{\sim}=\{[a]\mid a\in A\} is a partition of AA.
  2. Conversely, if P\mathcal{P} is a partition of AA, then the relation P\sim_{\mathcal{P}} defined by

aPb    a,b lie in the same block of Pa\sim_{\mathcal{P}}b \iff a,b \text{ lie in the same block of }\mathcal{P}

is an equivalence relation on AA, and its equivalence classes are exactly the blocks of P\mathcal{P}. 3. The two constructions are mutually inverse: they set up a bijection between equivalence relations on AA and partitions of AA.

Proof of (1). We check the three conditions of Definition 3.27 for A/A/{\sim}.

  • Nonempty blocks. By reflexivity aaa\sim a, so a[a]a\in[a]; hence no class is empty.
  • Cover. Each class [a]A[a]\subseteq A, and every element aa lies in the class [a][a], so aA[a]=A\bigcup_{a\in A}[a]=A.
  • Disjointness. Two distinct classes are disjoint by Lemma 3.29 (if they intersected they would be equal, not distinct).

Thus the distinct classes form a partition of AA.   \;\blacksquare

Proof of (2). Write aba\sim b for aPba\sim_{\mathcal P}b. Because the blocks of P\mathcal{P} cover AA and are pairwise disjoint, every aAa\in A lies in exactly one block; call it B(a)B(a). Then by definition ab    B(a)=B(b)a\sim b\iff B(a)=B(b).

  • Reflexive: B(a)=B(a)B(a)=B(a), so aaa\sim a.
  • Symmetric: B(a)=B(b)B(b)=B(a)B(a)=B(b)\Rightarrow B(b)=B(a), so abbaa\sim b\Rightarrow b\sim a.
  • Transitive: B(a)=B(b)B(a)=B(b) and B(b)=B(c)B(b)=B(c) give B(a)=B(c)B(a)=B(c), so ab,bcaca\sim b, b\sim c\Rightarrow a\sim c. Hence \sim is an equivalence relation. Its class of aa is [a]={xB(x)=B(a)}=B(a)[a]=\{x\mid B(x)=B(a)\}=B(a), the block containing aa. So the equivalence classes are precisely the blocks of P\mathcal{P}.   \;\blacksquare

Proof of (3). Start from an equivalence relation \sim, form the partition A/A/{\sim}, then form its “same-block” relation. Two elements share a block iff they lie in the same class, i.e. iff [a]=[b][a]=[b], iff (Lemma 3.28) aba\sim b; so we recover \sim. Conversely, start from a partition P\mathcal{P}, form P\sim_{\mathcal P}, then take its classes; by part (2) these are exactly the blocks of P\mathcal{P}, so we recover P\mathcal{P}. The two constructions are therefore inverse to each other, establishing the bijection.   \;\blacksquare

Remark (why this matters). Theorem 3.30 says that “equivalence relation” and “partition” are two languages for the same phenomenon. Whenever you sort objects into non-overlapping categories that between them cover everything, you have — like it or not — defined an equivalence relation, and vice versa. This is why the theorem is invoked all over mathematics and CS: connected components of a graph, congruence classes of integers, types in a type system, disjoint-set (union–find) data structures, and — in Lecture 13 — the decomposition of a sample space into mutually exclusive, exhaustive events on which probabilities are summed.

The set of classes A/A/{\sim} is called the quotient set of AA by \sim, and Bn:={partitions of an n-set}B_n:=|\{\text{partitions of an }n\text{-set}\}| (equivalently, the number of equivalence relations on it) is the Bell number; B1,B2,B3,B4=1,2,5,15B_1,B_2,B_3,B_4=1,2,5,15.

Worked example 3.31 (three views of one equivalence relation). On A={0,1,2,3,4,5}A=\{0,1,2,3,4,5\} define ab    3(ab)a\sim b\iff 3\mid(a-b) (“congruent modulo 33”). It is reflexive (303\mid0), symmetric (3(ab)3(ba)3\mid(a-b)\Rightarrow3\mid(b-a)) and transitive (if 3(ab)3\mid(a-b) and 3(bc)3\mid(b-c) then 3(ac)3\mid(a-c)), hence an equivalence relation. Its classes are

[0]={0,3},[1]={1,4},[2]={2,5},[0]=\{0,3\},\quad [1]=\{1,4\},\quad [2]=\{2,5\},

giving the partition {{0,3},{1,4},{2,5}}\bigl\{\{0,3\},\{1,4\},\{2,5\}\bigr\} of AA. Conversely, starting from this partition and declaring two numbers equivalent when they share a block returns exactly (mod3)\equiv\pmod 3 — the round trip promised by Theorem 3.30(3).

3.9.2 Application: congruence classes and modular arithmetic

Fix an integer n1n\ge1. On the whole set Z\mathbb{Z} define

ab(modn)    n(ab).a\equiv b\pmod n \iff n\mid (a-b).

Theorem 3.32. Congruence modulo nn is an equivalence relation on Z\mathbb{Z} with exactly nn classes, namely the residue classes [0],[1],,[n1][0],[1],\dots,[n-1], where [r]={r+knkZ}[r]=\{r+kn\mid k\in\mathbb{Z}\}.

Proof. Reflexive: n(aa)=0n\mid(a-a)=0. Symmetric: if ab=kna-b=kn then ba=(k)nb-a=(-k)n, so n(ba)n\mid(b-a). Transitive: if ab=kna-b=kn and bc=nb-c=\ell n then ac=(k+)na-c=(k+\ell)n, so n(ac)n\mid(a-c). Hence (modn)\equiv\pmod n is an equivalence relation. By the division algorithm every integer aa can be written a=qn+ra=qn+r with a unique remainder r{0,1,,n1}r\in\{0,1,\dots,n-1\}; then ar=qna-r=qn, so ara\equiv r and a[r]a\in[r]. Thus the classes [0],,[n1][0],\dots,[n-1] cover Z\mathbb{Z}. They are distinct because if 0r<rn10\le r<r'\le n-1 then 0<rr<n0<r'-r<n, so n(rr)n\nmid(r'-r) and r≢rr\not\equiv r'. Hence there are exactly nn classes.   \;\blacksquare

The quotient set Z/nZ={[0],[1],,[n1]}\mathbb{Z}/n\mathbb{Z}=\{[0],[1],\dots,[n-1]\} is written Zn\mathbb{Z}_n. The reason it is genuinely useful is that arithmetic descends to the classes:

Theorem 3.33 (arithmetic is well-defined mod nn). If aa(modn)a\equiv a'\pmod n and bb(modn)b\equiv b'\pmod n, then a+ba+b(modn)a+b\equiv a'+b'\pmod n and abab(modn)ab\equiv a'b'\pmod n.

Proof. Write a=a+nsa'=a+ns and b=b+ntb'=b+nt for integers s,ts,t. Then

a+b=(a+b)+n(s+t),a'+b'=(a+b)+n(s+t),

so n((a+b)(a+b))n\mid\bigl((a'+b')-(a+b)\bigr), i.e. a+ba+ba+b\equiv a'+b'. And

ab=(a+ns)(b+nt)=ab+n(at+bs+nst),a'b'=(a+ns)(b+nt)=ab+n\,(at+bs+nst),

so n(abab)n\mid(a'b'-ab), i.e. ababab\equiv a'b'.   \;\blacksquare

Consequently the definitions [a]+[b]:=[a+b][a]+[b]:=[a+b] and [a][b]:=[ab][a]\cdot[b]:=[ab] do not depend on which representatives a,ba,b we pick — the operations are well-defined on Zn\mathbb{Z}_n, turning it into a finite arithmetic system.

Common pitfall (well-definedness is not automatic). Not every formula on representatives descends to classes. On Z3\mathbb{Z}_3 the “operation” [a][2a][a]\mapsto[2^{a}] is ill-defined: 03(mod3)0\equiv3\pmod3 but 20=12^{0}=1 while 23=82(mod3)2^{3}=8\equiv2\pmod3, so the answer depends on the representative. Theorem 3.33 is a genuine theorem, not a triviality, precisely because such failures are possible.

CS connections. Modular arithmetic is the arithmetic of finite machines and is everywhere in computing: hash functions and hash tables (h(k)=kmodmh(k)=k\bmod m), checksums and cyclic redundancy checks, pseudo-random generators, cyclic buffers (indices mod capacity), clock arithmetic, and the public-key cryptosystem RSA, whose security rests on modular exponentiation. All of these silently rely on the fact that congruence classes form a well-behaved arithmetic (Theorems 3.32–3.33).

3.10 Partial orders, Hasse diagrams, and a first look at lattices

Definition 3.34 (partial order, poset). A relation \preceq on AA that is reflexive, antisymmetric and transitive is a partial order. The pair (A,)(A,\preceq) is a partially ordered set (poset). We write aba\prec b for “aba\preceq b and aba\ne b” (the associated strict order).

Partial orders model ranking with possible incomparabilities: precedence of tasks, refinement of specifications, subset containment, divisibility, information order. Compare with equivalence relations: swap symmetry for antisymmetry and the character changes completely — from “grouping equals” to “ordering unequals”.

3.10.1 Comparability and total orders

Definition 3.35. In a poset (A,)(A,\preceq), elements a,ba,b are comparable if aba\preceq b or bab\preceq a; otherwise they are incomparable (written aba\parallel b). If every pair is comparable, \preceq is a total (or linear) order, and (A,)(A,\preceq) is a chain.

Examples: \le on Z\mathbb{Z}, Q\mathbb{Q} or R\mathbb{R} is total; alphabetical/lexicographic order on strings is total; but subset order and divisibility are only partial.

Worked example 3.36 (divisibility is a partial order). Divisibility aba\mid b on D={1,2,3,4,6,12}D=\{1,2,3,4,6,12\} (the positive divisors of 1212) is a partial order: aaa\mid a (reflexive); for positive integers aba\mid b and bab\mid a force a=ba=b (antisymmetric); and aba\mid b, bcb\mid c give aca\mid c (transitive). It is only partial: 232\mid3 and 323\mid2 both fail, so 232\parallel3; likewise 464\parallel6.

3.10.2 Hasse diagrams

Drawing every arrow of a partial order is wasteful: reflexive loops and transitivity-forced edges clutter the picture. A Hasse diagram strips it to essentials.

Definition 3.37 (cover; Hasse diagram). In a poset, bb covers aa (written aba\lessdot b) if aba\prec b and there is no cc with acba\prec c\prec b. The Hasse diagram draws one node per element and one line for each covering pair, placing the smaller element lower; direction is read off the vertical position, so no arrowheads are needed. Reflexive loops and transitively implied edges are omitted.

Worked example 3.38 (Hasse diagram of (D,)(D,\mid)). For D={1,2,3,4,6,12}D=\{1,2,3,4,6,12\} the covering pairs are

12,13,24,26,36,412,612,1\lessdot2,\quad 1\lessdot3,\quad 2\lessdot4,\quad 2\lessdot6,\quad 3\lessdot6,\quad 4\lessdot12,\quad 6\lessdot12,

(e.g. 141\lessdot4 is not a cover because 1241\prec2\prec4, and 3123\lessdot12 is not a cover because 36123\prec6\prec12). An ASCII sketch (with 11 at the bottom and 1212 at the top):

            12
           /  \
          4    6
          |   / \
          2 -/   3
          |     /
          1 ---/

Hasse diagram of the divisors of  ordered by divisibility:  at the bottom,  at the top, with an upward line for each covering pair

Here the seven line-segments realise the seven covers above: 1212 sits over 44 and 66; 44 over 22; 66 over both 22 and 33; and 11 under both 22 and 33. All other relationships (such as 1121\mid12 or 2122\mid12) are recovered by following lines upward and using transitivity.

3.10.3 Minimal, maximal, least and greatest elements

Let (A,)(A,\preceq) be a poset and SAS\subseteq A.

Definition 3.39.

  • mSm\in S is a minimal element of SS if no xSx\in S satisfies xmx\prec m (nothing in SS lies strictly below mm).
  • mSm\in S is a maximal element of SS if no xSx\in S satisfies mxm\prec x.
  • S\ell\in S is the least (or minimum) element if x\ell\preceq x for every xSx\in S.
  • gSg\in S is the greatest (or maximum) element if xgx\preceq g for every xSx\in S.

Common pitfall (minimal \ne least). Minimal means “nothing below it”; least means “below everything”. A poset may have several minimal elements and no least element. In (D,)(D,\mid) the whole set has least element 11 and greatest element 1212; but the subset {2,3,4,6}\{2,3,4,6\} has two minimal elements (22 and 33) and no least element, and two maximal elements (44 and 66) with no greatest.

Theorem 3.40 (uniqueness). A subset SS of a poset has at most one least element and at most one greatest element.

Proof. Suppose ,\ell,\ell' are both least elements of SS. Since \ell is least and S\ell'\in S, \ell\preceq\ell'. Since \ell' is least and S\ell\in S, \ell'\preceq\ell. Antisymmetry gives =\ell=\ell'. The greatest-element case is dual (reverse every \preceq).   \;\blacksquare

Because of Theorem 3.40 we may speak of the least element minS\min S and the greatest element maxS\max S when they exist.

Theorem 3.41 (least \Rightarrow unique minimal). If SS has a least element \ell, then \ell is the unique minimal element of SS.

Proof. First, \ell is minimal: if xSx\in S and xx\preceq\ell, then x\ell\preceq x (as \ell is least), so antisymmetry gives x=x=\ell; hence no element is strictly below \ell. Now let mm be any minimal element of SS. Since \ell is least, m\ell\preceq m. If m\ell\ne m then m\ell\prec m with S\ell\in S, contradicting the minimality of mm. Therefore m=m=\ell, so \ell is the only minimal element.   \;\blacksquare

Theorem 3.42 (finite posets have extremal elements). Every finite nonempty poset (A,)(A,\preceq) has at least one minimal element and at least one maximal element.

Proof (minimal; maximal is dual). Note \prec is irreflexive (aaa\prec a would require aaa\ne a). Pick any a0Aa_0\in A. If a0a_0 is minimal, stop. Otherwise choose a1a0a_1\prec a_0; if a1a_1 is minimal, stop; otherwise choose a2a1a_2\prec a_1, and so on, generating a0a1a2a_0\succ a_1\succ a_2\succ\cdots. These elements are pairwise distinct: if ai=aja_i=a_j with i<ji<j, then chaining the strict steps by transitivity gives ajai=aja_j\prec a_i=a_j, i.e. ajaja_j\prec a_j, impossible. Since AA is finite the process cannot continue forever, so it must halt — and it halts only when it reaches a minimal element.   \;\blacksquare

Remark (why finiteness is needed). In an infinite poset a unique minimal element need not be least. Let A={u}{1,2,3,}A=\{u\}\cup\{-1,-2,-3,\dots\}, where the negative integers carry their usual order (descending forever, with no minimum) and uu is a brand-new element declared incomparable to every negative integer. No negative integer is minimal (each has a smaller one below it), while uu is minimal (nothing is below it), so uu is the unique minimal element. Yet uu is not least: u⪯̸1u\not\preceq -1. Theorem 3.42 fails here precisely because the descending chain 12-1\succ-2\succ\cdots never terminates.

3.10.4 Bounds and a first look at lattices

Beyond elements of SS, we often care about elements of the whole poset that sit above or below all of SS.

Definition 3.43. Let SAS\subseteq A in a poset (A,)(A,\preceq). An element uAu\in A is an upper bound of SS if sus\preceq u for all sSs\in S; a lower bound \ell satisfies s\ell\preceq s for all sSs\in S. The least upper bound (supremum, join), if it exists, is the least element of the set of upper bounds, written supS\sup S; for two elements it is aba\vee b. Dually the greatest lower bound (infimum, meet) is infS\inf S, written aba\wedge b.

By Theorem 3.40, joins and meets are unique when they exist.

Definition 3.44 (lattice). A poset (A,)(A,\preceq) is a lattice if every pair of elements a,ba,b has both a join aba\vee b and a meet aba\wedge b.

Example 3.45 (three familiar lattices).

  • Power set (P(U),)(\mathcal{P}(U),\subseteq): here AB=ABA\vee B=A\cup B and AB=ABA\wedge B=A\cap B (Lecture 2’s operations are literally join and meet). Its Hasse diagram for U={a,b}U=\{a,b\} is the diamond

          {a,b}
          /    \
        {a}    {b}
          \    /
            ∅
    
  • Divisibility (Z+,)(\mathbb{Z}^{+},\mid): ab=lcm(a,b)a\vee b=\operatorname{lcm}(a,b) and ab=gcd(a,b)a\wedge b=\gcd(a,b). The poset (D,)(D,\mid) of Example 3.38 is a finite lattice; e.g. 46=lcm(4,6)=124\vee6=\operatorname{lcm}(4,6)=12 and 46=gcd(4,6)=24\wedge6=\gcd(4,6)=2.

  • Total orders are lattices with ab=max(a,b)a\vee b=\max(a,b) and ab=min(a,b)a\wedge b=\min(a,b).

Example 3.46 (a poset that is not a lattice). Take A={a,b,c,d}A=\{a,b,c,d\} with ac, ad, bc, bda\prec c,\ a\prec d,\ b\prec c,\ b\prec d and cdc\parallel d, aba\parallel b (a “crown”). ASCII (the two middle segments cross at ×\times):

      c     d
      | \ / |
      |  ×  |
      | / \ |
      a     b

The pair {a,b}\{a,b\} has upper bounds cc and dd, but cdc\parallel d, so there is no least upper bound; aba\vee b does not exist and AA is not a lattice. (Dually, {c,d}\{c,d\} has no meet.)

Remark (forward pointer). A lattice that is also bounded (has a least element 00 and greatest element 11), distributive, and complemented is a Boolean algebra — the algebraic skeleton of propositional logic and digital circuits. The power-set lattice (P(U),)(\mathcal{P}(U),\subseteq) is the prototype. We return to Boolean algebra in a later lecture; for now, note how the set operations of Lecture 2 already exhibit the lattice structure in miniature.

3.11 nn-ary relations and the relational database model

Definition 3.47 (nn-ary relation). An nn-ary relation is a subset RA1×A2××AnR\subseteq A_1\times A_2\times\cdots\times A_n; its elements are nn-tuples. Binary relations are the case n=2n=2, and the Cartesian product itself is the universal nn-ary relation.

A database table is an -ary relation: each row is a tuple, each column an attribute with its own domain

Motivating example (students · subjects · marks). Let

STUDENTS={Shevchenko,Franko,Kosach},\text{STUDENTS}=\{\text{Shevchenko},\text{Franko},\text{Kosach}\},

SUBJECTS={Discrete Math,Algebra,Programming},\text{SUBJECTS}=\{\text{Discrete Math},\text{Algebra},\text{Programming}\},

MARKS={A,B,C,D,E,F,Fx}.\text{MARKS}=\{A,B,C,D,E,F,Fx\}.

An examination record is a ternary relation RSTUDENTS×SUBJECTS×MARKSR\subseteq\text{STUDENTS}\times\text{SUBJECTS}\times\text{MARKS}, e.g.

R={(Shevchenko,Programming,B), (Kosach,Algebra,A), (Franko,Discrete Math,E)}.R=\{(\text{Shevchenko},\text{Programming},B),\ (\text{Kosach},\text{Algebra},A),\ (\text{Franko},\text{Discrete Math},E)\}.

This is exactly a database table: each tuple is a row (record), each factor AiA_i is a column (attribute) with its own domain, and nn is the number of columns (the table’s arity).

STUDENT SUBJECT MARK
Shevchenko Programming B
Kosach Algebra A
Franko Discrete Math E

Remark (a set has no duplicates and no order). Because a relation is a set of tuples, a table in this idealised model has no duplicate rows and no inherent row order — mirroring the mathematical fact that {x,x}={x}\{x,x\}=\{x\} and that sets are unordered. Real SQL tables relax this (bags, not sets), but the theory is set-based.

3.11.1 Relational algebra

Since relations are sets, the operations of Lecture 2 apply between two relations of the same shape (same sequence of attribute domains): union RSR\cup S, intersection RSR\cap S, and difference RSR\setminus S. Adding a few relation-specific operators yields relational algebra, the theory underlying SQL, introduced by E. F. Codd in 1970.

  • Selection σφ(R)\sigma_{\varphi}(R) — keep the rows (tuples) satisfying a condition φ\varphi; σ\sigma chooses a subset of the tuples. (SQL WHERE.)
  • Projection πi1,,ik(R)\pi_{i_1,\dots,i_k}(R) — keep only certain columns, discarding the others (and any duplicate rows that result); π\pi chooses a subset of the attributes. (SQL SELECT of specific columns.)
  • Cartesian product R×SR\times S — pair every row of RR with every row of SS (the same product as in §3.2).
  • Natural join RSR\bowtie S — combine rows of RR and SS that agree on their shared attribute(s); a filtered, matched Cartesian product. It is the workhorse that reconnects data split across tables.

Worked example 3.48 (projection, selection, join). Let

ENROLL: STUDENT COURSE
Kosach Algebra
Kosach DM
Franko DM

and

OFFER: COURSE ROOM
Algebra 101
DM 205

Then πSTUDENT(ENROLL)={Kosach,Franko}\pi_{\text{STUDENT}}(\text{ENROLL})=\{\text{Kosach},\text{Franko}\} (the duplicate Kosach collapses); σCOURSE=DM(ENROLL)\sigma_{\text{COURSE}=\text{DM}}(\text{ENROLL}) keeps the two DM rows; and the natural join on COURSE is

ENROLL ⋈ OFFER: STUDENT COURSE ROOM
Kosach Algebra 101
Kosach DM 205
Franko DM 205

each enrolment matched to the room where its course is offered.

So the abstract notion of an nn-ary relation is not merely theory: it is the data model every relational database implements, and the humble set operations of Lecture 2 are its computational core.

3.12 Functions as a special kind of relation

Definition 3.49 (functional relation; function). A relation FA×BF\subseteq A\times B is functional (single-valued) if each xAx\in A relates to at most one yBy\in B: whenever (x,y)F(x,y)\in F and (x,y)F(x,y')\in F, then y=yy=y'. If in addition every xAx\in A relates to exactly one yy, then FF is a total function f:ABf:A\to B, and we write y=f(x)y=f(x) in place of (x,y)F(x,y)\in F.

Thus a function is a relation — one obeying the single-valuedness condition. Its domain is its set of inputs and its range is the set of attained outputs — the very domain/range of §3.4. Functions may be injective (distinct inputs give distinct outputs), surjective (every element of BB is attained), or bijective (both) — the properties we have just defined, which recur throughout the course (for example in counting and in graph isomorphism).

Common pitfall (which relations fail to be functions). On {1,2,3}\{1,2,3\} the relation {(1,2),(1,3)}\{(1,2),(1,3)\} is not a function: the input 11 has two outputs, so single-valuedness fails. The relation {(1,2),(2,2)}\{(1,2),(2,2)\} is a (partial) function even though two inputs share the output 22 — single-valuedness restricts outputs per input, not inputs per output. And a total function additionally forbids the input 33 from having no output at all.

Remark. Reading a function as its graph {(x,f(x))}A×B\{(x,f(x))\}\subseteq A\times B is not a mere formality: it is how functions are defined rigorously in set theory, and how they are stored (as key–value tables) in computing.

Historical note

The set-theoretic viewpoint on relations grew out of Georg Cantor’s creation of set theory in the 1870s–1880s. The now-standard encoding of the ordered pair, (a,b)={{a},{a,b}}(a,b)=\{\{a\},\{a,b\}\}, is due to Kazimierz Kuratowski (1921) and is what lets relations be defined purely as sets (Lecture 2). Modular arithmetic — our flagship equivalence relation — was placed on a firm footing by Carl Friedrich Gauss in the Disquisitiones Arithmeticae (1801), which introduced the congruence notation ab(modn)a\equiv b\pmod n. The systematic theory of order and lattices was developed by Richard Dedekind around 1900 (his Dualgruppen) and brought to maturity by Garrett Birkhoff, whose Lattice Theory (1940) is the classic reference; the diagrams are named after Helmut Hasse. The transitive-closure algorithm of §3.8 is due to Stephen Warshall (1962). Finally, the entire nn-ary story found its most consequential application when Edgar F. (“Ted”) Codd of IBM published A Relational Model of Data for Large Shared Data Banks (Communications of the ACM, 1970), founding the relational database — arguably the single most commercially important application of discrete mathematics.

Chapter summary

  • A relation is a subset of a Cartesian product; a binary relation is RA×BR\subseteq A\times B, with (a,b)R(a,b)\in R written aRbaRb. Specify it by listing or by a predicate; represent it as a set of pairs, a Boolean matrix, or a digraph. The identity relation ΔA\Delta_A and the universal/empty relations are the reference points.
  • Domain and range collect the first and second components that occur.
  • Core properties — reflexive, irreflexive, symmetric, antisymmetric, asymmetric, transitive (and the rarer antitransitive) — each have a matrix fingerprint and an algebraic form: ΔAR\Delta_A\subseteq R; R=R1R=R^{-1}; RR1ΔAR\cap R^{-1}\subseteq\Delta_A; R2RR^{2}\subseteq R (Theorem 3.9). Counting relations with a property is combinatorics (Proposition 3.10).
  • Inverse R1R^{-1} transposes the matrix / reverses arrows. Composition SRS\circ R chains relations and equals the Boolean matrix product MRMSM_R\odot M_S (Theorem 3.15); composition is associative (Theorem 3.17), so powers RkR^{k} are well-defined and count walks of length kk (Lemma 3.18).
  • Closures add the fewest pairs to gain a property: r(R)=RΔAr(R)=R\cup\Delta_A, s(R)=RR1s(R)=R\cup R^{-1}, and t(R)=k1Rkt(R)=\bigcup_{k\ge1}R^{k} (Theorem 3.21), a finite union k=1nRk\bigcup_{k=1}^{n}R^{k} on an nn-element set (Theorem 3.22, via pigeonhole); Warshall’s algorithm computes it in O(n3)O(n^{3}).
  • Equivalence relations (reflexive + symmetric + transitive) correspond exactly to partitions via the Fundamental Theorem (Theorem 3.30), proved in both directions. The prototype is congruence mod nn, whose classes support well-defined modular arithmetic (Theorems 3.32–3.33).
  • Partial orders (reflexive + antisymmetric + transitive) are drawn as Hasse diagrams. Distinguish minimal/maximal from least/greatest: least/greatest are unique when they exist (Theorem 3.40) and finite posets always have extremal elements (Theorem 3.42). Adding joins and meets for every pair gives a lattice; power sets and divisibility are the standard examples.
  • nn-ary relations are precisely the tables of the relational database model, manipulated by relational algebra (selection, projection, product, natural join). A function is the special case of a single-valued relation.

Exercises

Warm-up

W1. Let A={1,2,3,4}A=\{1,2,3,4\} and R={(1,1),(1,2),(2,3),(3,4),(4,4)}R=\{(1,1),(1,2),(2,3),(3,4),(4,4)\}. (a) Write the relation matrix. (b) Give dom(R)\operatorname{dom}(R) and ran(R)\operatorname{ran}(R). (c) Decide whether RR is reflexive, symmetric, antisymmetric, transitive.

W2. For the RR of W1, compute R1R^{-1} as a set of pairs and give its matrix. How is MR1M_{R^{-1}} related to MRM_R?

W3. On {a,b,c}\{a,b,c\} let R={(a,b),(b,c),(a,c)}R=\{(a,b),(b,c),(a,c)\} and S={(b,a),(c,b)}S=\{(b,a),(c,b)\}. Compute SRS\circ R and RSR\circ S. Are they equal?

W4. For each relation on {1,2,3}\{1,2,3\} decide which of reflexive / symmetric / antisymmetric / transitive it has: (a) \varnothing; (b) A×AA\times A; (c) ΔA={(1,1),(2,2),(3,3)}\Delta_A=\{(1,1),(2,2),(3,3)\}.

W5. List the equivalence classes of congruence modulo 44 on {0,1,,11}\{0,1,\dots,11\}, and write the induced partition.

W6. For R={(1,2),(2,1),(2,3)}R=\{(1,2),(2,1),(2,3)\} on {1,2,3}\{1,2,3\} give the reflexive closure r(R)r(R) and the symmetric closure s(R)s(R).

Standard

S7. Let R={(1,2),(2,3),(3,4),(4,1)}R=\{(1,2),(2,3),(3,4),(4,1)\} on {1,2,3,4}\{1,2,3,4\}. Compute R2,R3,R4R^{2},R^{3},R^{4} and hence t(R)t(R). Is t(R)t(R) the universal relation? Explain using Theorem 3.22 why you need not compute beyond R4R^{4}.

S8. On Z\mathbb{Z} define ab    aa\sim b\iff a and bb have the same parity (both even or both odd). Prove \sim is an equivalence relation and describe its classes as a partition of Z\mathbb{Z}.

S9. Consider divisibility on D24={1,2,3,4,6,8,12,24}D_{24}=\{1,2,3,4,6,8,12,24\}. (a) State why it is a poset. (b) List all covering pairs and describe the Hasse diagram. (c) Identify the least, greatest, minimal and maximal elements. (d) Is (D24,)(D_{24},\mid) a lattice? Compute 8128\vee12 and 8128\wedge12.

S10. On an nn-element set, count (a) all relations, (b) reflexive relations, (c) symmetric relations, (d) relations that are both reflexive and symmetric. Evaluate each for n=3n=3.

S11. Let MR=(101010100)M_R=\begin{pmatrix}1&0&1\\0&1&0\\1&0&0\end{pmatrix} on {1,2,3}\{1,2,3\}. Use the Boolean matrix product to compute MR2M_{R^{2}} and list R2R^{2}. Is RR transitive? Justify via Theorem 3.9(4).

S12. Prove that if RR and SS are transitive relations on AA, then RSR\cap S is transitive. Then give a concrete example on {1,2,3}\{1,2,3\} of two transitive relations whose union is not transitive.

S13. The partition {{1,4},{2},{3,5}}\{\{1,4\},\{2\},\{3,5\}\} of {1,2,3,4,5}\{1,2,3,4,5\} induces an equivalence relation \sim. List all pairs of \sim and state |{\sim}|.

S14. With ENROLL and OFFER as in Example 3.48, write out (a) σSTUDENT=Kosach(ENROLL)\sigma_{\text{STUDENT}=\text{Kosach}}(\text{ENROLL}), (b) πCOURSE(ENROLL)\pi_{\text{COURSE}}(\text{ENROLL}), and (c) the natural join ENROLLOFFER\text{ENROLL}\bowtie\text{OFFER}, explaining in one sentence what each result represents.

Challenge

C15. Prove that composition distributes over union: T(RS)=(TR)(TS)T\circ(R\cup S)=(T\circ R)\cup(T\circ S) for relations of compatible shapes. Show also that T(RS)(TR)(TS)T\circ(R\cap S)\subseteq(T\circ R)\cap(T\circ S), and give an example where the inclusion is strict.

C16 (equivalence closure). (a) Prove that the intersection of any nonempty family {Ei}iI\{E_i\}_{i\in I} of equivalence relations on AA is again an equivalence relation. (b) Deduce that for any relation RR on AA there is a smallest equivalence relation e(R)e(R) containing RR. (c) Prove that e(R)=t(RR1ΔA)e(R)=t\bigl(R\cup R^{-1}\cup\Delta_A\bigr).

C17. Let (A,)(A,\preceq) be a poset. (a) Prove that if AA is finite and nonempty then it has a maximal element. (b) Prove that if a finite poset has a unique maximal element, that element is the greatest. (c) Give an infinite poset with a unique maximal element that is not greatest.

C18. (a) Prove that the number of symmetric relations on an nn-set is 2n(n+1)/22^{\,n(n+1)/2} and the number of antisymmetric relations is 2n3(n2)2^{\,n}3^{\,\binom{n}{2}}. (b) How many relations are both symmetric and antisymmetric? Identify them explicitly. (c) Explain why the count of equivalence relations is the Bell number BnB_n, and compute B4B_4.

Selected answers & hints

W1. (a) Rows/cols indexed 1,2,3,41,2,3,4:

x\yx\backslash y 1 2 3 4
1 1 1 0 0
2 0 0 1 0
3 0 0 0 1
4 0 0 0 1

(b) dom(R)={1,2,3,4}\operatorname{dom}(R)=\{1,2,3,4\}, ran(R)={1,2,3,4}\operatorname{ran}(R)=\{1,2,3,4\}. (c) Not reflexive ((2,2),(3,3)R(2,2),(3,3)\notin R); not symmetric ((1,2)R(1,2)\in R, (2,1)R(2,1)\notin R); antisymmetric (no off-diagonal mirror pair); not transitive ((1,2),(2,3)R(1,2),(2,3)\in R but (1,3)R(1,3)\notin R).

W3. SRS\circ R (“RR then SS”): abaa\to b\to a gives (a,a)(a,a); bcbb\to c\to b gives (b,b)(b,b); acba\to c\to b gives (a,b)(a,b). So SR={(a,a),(b,b),(a,b)}S\circ R=\{(a,a),(b,b),(a,b)\}. RSR\circ S (“SS then RR”): babb\to a\to b, bacb\to a\to c, cbcc\to b\to c give {(b,b),(b,c),(c,c)}\{(b,b),(b,c),(c,c)\}. They are not equal — composition is not commutative.

W5. [0]={0,4,8}[0]=\{0,4,8\}, [1]={1,5,9}[1]=\{1,5,9\}, [2]={2,6,10}[2]=\{2,6,10\}, [3]={3,7,11}[3]=\{3,7,11\}; partition {{0,4,8},{1,5,9},{2,6,10},{3,7,11}}\bigl\{\{0,4,8\},\{1,5,9\},\{2,6,10\},\{3,7,11\}\bigr\}.

S7. R2={(1,3),(2,4),(3,1),(4,2)}R^{2}=\{(1,3),(2,4),(3,1),(4,2)\}, R3={(1,4),(2,1),(3,2),(4,3)}R^{3}=\{(1,4),(2,1),(3,2),(4,3)\}, R4=ΔA={(1,1),(2,2),(3,3),(4,4)}R^{4}=\Delta_A=\{(1,1),(2,2),(3,3),(4,4)\}. Their union with RR is all 1616 pairs, so t(R)=A×At(R)=A\times A, the universal relation. Since A=4|A|=4, Theorem 3.22 guarantees t(R)=k=14Rkt(R)=\bigcup_{k=1}^{4}R^{k}, so no higher power is needed (indeed R5=RR^{5}=R).

S8. Reflexive: aa has the same parity as itself. Symmetric: if a,ba,b share parity then so do b,ab,a. Transitive: if a,ba,b share parity and b,cb,c share parity, then a,ca,c share parity (parity is a two-valued attribute). Classes: the evens [0]=2Z[0]=2\mathbb{Z} and the odds [1]=2Z+1[1]=2\mathbb{Z}+1; partition {2Z,2Z+1}\{2\mathbb{Z},\,2\mathbb{Z}+1\}. (This is congruence mod 22, a special case of Theorem 3.32.)

S10. (a) 2n22^{n^{2}}; (b) 2n2n2^{\,n^{2}-n}; (c) 2n(n+1)/22^{\,n(n+1)/2}; (d) 2(n2)=2n(n1)/22^{\,\binom{n}{2}}=2^{\,n(n-1)/2}. For n=3n=3: 512, 64, 64, 8512,\ 64,\ 64,\ 8 respectively.

S12. If (a,b),(b,c)RS(a,b),(b,c)\in R\cap S then both pairs lie in RR (so (a,c)R(a,c)\in R by transitivity of RR) and both lie in SS (so (a,c)S(a,c)\in S); hence (a,c)RS(a,c)\in R\cap S. Counterexample for union: R={(1,2)}R=\{(1,2)\} and S={(2,3)}S=\{(2,3)\} are each transitive (no composable pairs within either), but RS={(1,2),(2,3)}R\cup S=\{(1,2),(2,3)\} lacks (1,3)(1,3) and is not transitive.

C16. Hints. (a) Reflexivity: each EiΔAE_i\supseteq\Delta_A, so iEiΔA\bigcap_i E_i\supseteq\Delta_A. Symmetry and transitivity: if a pair (or two composable pairs) lie in the intersection, they lie in every EiE_i, which is symmetric/transitive, so the required consequence lies in every EiE_i, hence in the intersection. (b) Apply (a) to the family of all equivalence relations containing RR (nonempty, since A×AA\times A is one); their intersection is the smallest such, namely e(R)e(R). (c) Show Q:=t(RR1ΔA)Q:=t(R\cup R^{-1}\cup\Delta_A) is an equivalence relation containing RR (reflexive since ΔA\Delta_A\subseteq it, symmetric because RR1ΔAR\cup R^{-1}\cup\Delta_A is symmetric and transitive closure preserves symmetry, transitive by construction), so e(R)Qe(R)\subseteq Q; conversely any equivalence relation ERE\supseteq R contains R1R^{-1} (symmetry), ΔA\Delta_A (reflexivity) and all their walks (transitivity), so QEQ\subseteq E, giving Qe(R)Q\subseteq e(R).

C17. Hints. (a) Mirror Theorem 3.42 with ascending chains. (b) In a finite poset every element lies below some maximal element (ascend a chain until it stops); if the maximal element is unique, every element lies below it, so it is greatest. (c) Take A={u}{1,2,3,}A=\{u\}\cup\{1,2,3,\dots\} with the usual order on the positive integers (ascending forever, no maximum) and uu incomparable to all of them: uu is the unique maximal element but u⪰̸1u\not\succeq1, so uu is not greatest.

Further reading

  • Kenneth H. Rosen, Discrete Mathematics and Its Applications, 8th ed., Chapter 9 (“Relations”): §9.1 relations and their properties, §9.3 representing relations, §9.4 closures (Warshall’s algorithm), §9.5 equivalence relations, §9.6 partial orderings and lattices.
  • Susanna S. Epp, Discrete Mathematics with Applications, 5th ed., Chapter 8 (“Relations”): reflexivity/symmetry/transitivity, equivalence relations and partitions, partial-order relations.
  • E. F. Codd, “A Relational Model of Data for Large Shared Data Banks”, Communications of the ACM 13(6), 1970 — the origin of the relational database connection in §3.11.
  • (For the order-theory strand) Garrett Birkhoff, Lattice Theory, American Mathematical Society — the classic reference behind §3.10.4.

Lectures/CDM-L03.md · 66.2 KB · updated 2026-08-01 20:48