Section 1 · 9 min read

Sets, relations, functions, partial orders and lattices

Set identities, properties and counts of relations, equivalence relations and partitions, function types and their counts, posets, Hasse diagrams and lattices.

On this page
  1. Sets
  2. Relations
  3. Functions
  4. Partial orders and lattices
  5. Worked examples
  6. Common traps
  7. Quick revision

This topic produces counting questions (how many relations have property X, how many onto functions), property checks on a given relation, and questions on posets and lattices. The counting formulas below cover most of them.

Sets

Operations and identities

For sets A,B,CA, B, C inside a universe UU:

  • De Morgan: A∪B‾=Aˉ∩Bˉ\overline{A \cup B} = \bar A \cap \bar B, A∩B‾=Aˉ∪Bˉ\overline{A \cap B} = \bar A \cup \bar B.
  • Distribution: A∩(B∪C)=(A∩B)∪(A∩C)A \cap (B \cup C) = (A \cap B) \cup (A \cap C) and the dual.
  • Difference: A−B=A∩BˉA - B = A \cap \bar B.
  • Symmetric difference: A⊕B=(A−B)∪(B−A)A \oplus B = (A - B) \cup (B - A). It is associative and A⊕A=∅A \oplus A = \emptyset.

Sizes:

  • ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A \cup B| = |A| + |B| - |A \cap B|
  • ∣A∪B∪C∣=∣A∣+∣B∣+∣C∣−∣A∩B∣−∣B∩C∣−∣A∩C∣+∣A∩B∩C∣|A \cup B \cup C| = |A| + |B| + |C| - |A \cap B| - |B \cap C| - |A \cap C| + |A \cap B \cap C|
  • ∣P(A)∣=2∣A∣|\mathcal{P}(A)| = 2^{|A|}, ∣A×B∣=∣A∣ ∣B∣|A \times B| = |A|\,|B|.

Countability

N\mathbb{N}, Z\mathbb{Z}, Q\mathbb{Q}, the set of all finite strings over a finite alphabet, and a countable union of countable sets are countable. R\mathbb{R}, P(N)\mathcal{P}(\mathbb{N}) and the set of all functions N→{0,1}\mathbb{N} \to \{0, 1\} are uncountable (Cantor's diagonal argument). This links to theory of computation: there are countably many Turing machines but uncountably many languages.

Relations

A relation RR on a set AA is a subset of A×AA \times A. With ∣A∣=n|A| = n there are n2n^2 ordered pairs and 2n22^{n^2} relations.

Properties

Property Definition In the 0-1 matrix
Reflexive (a,a)∈R(a,a) \in R for all aa diagonal all 1
Irreflexive (a,a)∉R(a,a) \notin R for all aa diagonal all 0
Symmetric (a,b)∈R⇒(b,a)∈R(a,b) \in R \Rightarrow (b,a) \in R matrix equals its transpose
Antisymmetric (a,b),(b,a)∈R⇒a=b(a,b), (b,a) \in R \Rightarrow a = b no off-diagonal pair has both 1
Asymmetric (a,b)∈R⇒(b,a)∉R(a,b) \in R \Rightarrow (b,a) \notin R antisymmetric and irreflexive
Transitive (a,b),(b,c)∈R⇒(a,c)∈R(a,b), (b,c) \in R \Rightarrow (a,c) \in R M2≤MM^2 \le M (Boolean product)

Symmetric and antisymmetric are not opposites. The empty relation and the identity relation are both. "Not reflexive" is also different from "irreflexive".

Counting relations on an nn-element set

The diagonal has nn pairs. The off-diagonal has n2−nn^2 - n pairs, forming (n2)\binom{n}{2} unordered pairs {(a,b),(b,a)}\{(a,b), (b,a)\}.

Relations that are Count
All 2n22^{n^2}
Reflexive 2n2−n2^{n^2 - n}
Irreflexive 2n2−n2^{n^2 - n}
Symmetric 2n⋅2(n2)=2n(n+1)/22^{n}\cdot 2^{\binom{n}{2}} = 2^{n(n+1)/2}
Reflexive and symmetric 2(n2)2^{\binom{n}{2}}
Antisymmetric 2n⋅3(n2)2^{n}\cdot 3^{\binom{n}{2}}
Asymmetric 3(n2)3^{\binom{n}{2}}
Both symmetric and antisymmetric 2n2^{n} (subsets of the diagonal)

The idea behind every row: decide each diagonal pair independently, then decide each unordered off-diagonal pair. For antisymmetric, each off-diagonal pair has 3 allowed states: neither, only (a,b)(a,b), only (b,a)(b,a).

There is no simple closed formula for the number of transitive relations or partial orders. For small nn, memorise: partial orders on 1, 2, 3, 4 elements number 1, 3, 19, 219.

Closures

  • Reflexive closure: R∪ΔR \cup \Delta, where Δ\Delta is the identity relation.
  • Symmetric closure: R∪R−1R \cup R^{-1}.
  • Transitive closure: R+=R∪R2∪⋯∪RnR^+ = R \cup R^2 \cup \dots \cup R^n; computed by Warshall's algorithm in O(n3)O(n^3).

Equivalence relations and partitions

An equivalence relation is reflexive, symmetric and transitive. Its classes partition AA, and every partition comes from exactly one equivalence relation. So

  • the number of equivalence relations on nn elements is the Bell number BnB_n: 1,2,5,15,52,2031, 2, 5, 15, 52, 203 for n=1..6n = 1..6;
  • the number with exactly kk classes is the Stirling number of the second kind S(n,k)S(n, k), with S(n,k)=k S(n−1,k)+S(n−1,k−1)S(n, k) = k\,S(n-1, k) + S(n-1, k-1).

Useful values: S(n,2)=2n−1−1S(n, 2) = 2^{n-1} - 1, S(n,n−1)=(n2)S(n, n-1) = \binom{n}{2}.

The intersection of two equivalence relations is an equivalence relation. The union need not be (transitivity can fail).

Functions

f:A→Bf: A \to B assigns exactly one element of BB to each element of AA. With ∣A∣=m|A| = m and ∣B∣=n|B| = n:

Type Count
All functions nmn^m
One to one (injective), m≤nm \le n n(n−1)⋯(n−m+1)=n!(n−m)!n(n-1)\cdots(n-m+1) = \frac{n!}{(n-m)!}
Onto (surjective), m≥nm \ge n ∑k=0n(−1)k(nk)(n−k)m=n! S(m,n)\sum_{k=0}^{n} (-1)^k \binom{n}{k}(n-k)^m = n!\,S(m, n)
Bijections, m=nm = n n!n!

Composition facts used in "which is always true" questions, for f:A→Bf: A \to B, g:B→Cg: B \to C:

  • g∘fg \circ f injective ⇒\Rightarrow ff injective.
  • g∘fg \circ f surjective ⇒\Rightarrow gg surjective.
  • Both injective ⇒\Rightarrow g∘fg \circ f injective; both surjective ⇒\Rightarrow g∘fg \circ f surjective.

A function has an inverse exactly when it is a bijection.

Partial orders and lattices

Posets

A partial order is reflexive, antisymmetric and transitive. A Hasse diagram draws only the covering pairs (no loops, no edges implied by transitivity), with larger elements higher.

Terms: maximal (nothing strictly above), greatest (above everything, unique if it exists), and the duals minimal and least. A finite poset always has at least one maximal and one minimal element, but may lack a greatest or least one. A chain is a totally ordered subset; an antichain is a set of pairwise incomparable elements.

A topological sort (linear extension) of a finite poset always exists.

Lattices

A poset is a lattice if every pair a,ba, b has a least upper bound a∨ba \lor b (join) and a greatest lower bound a∧ba \land b (meet). Every finite lattice is bounded: it has a least element 00 and a greatest element 11.

  • Distributive: a∧(b∨c)=(a∧b)∨(a∧c)a \land (b \lor c) = (a \land b) \lor (a \land c) for all elements. A lattice is distributive iff it contains no sublattice isomorphic to M3M_3 (the diamond: 0, three incomparable atoms, 1) or N5N_5 (the pentagon).
  • Complemented: every aa has some bb with a∧b=0a \land b = 0 and a∨b=1a \lor b = 1.
  • In a distributive lattice each element has at most one complement.
  • Boolean algebra: a complemented distributive lattice. Every finite Boolean algebra has 2k2^k elements and looks like P({1,…,k})\mathcal{P}(\{1, \dots, k\}).

Standard examples:

Poset Lattice? Notes
(P(S),⊆)(\mathcal{P}(S), \subseteq) yes Boolean algebra, meet ∩\cap, join ∪\cup
(Dn,∣)(D_n, \mid), divisors of nn yes distributive; Boolean iff nn is square free
Any chain yes distributive, complemented only if at most 2 elements
(Z+,∣)(\mathbb{Z}^+, \mid) yes meet gcd⁡\gcd, join lcm⁡\operatorname{lcm}; no greatest element

Worked examples

Worked example 1: Counting antisymmetric relations

How many antisymmetric relations are there on {1,2,3,4}\{1, 2, 3, 4\}?

  1. Diagonal: 4 pairs, each in or out: 24=162^4 = 16.
  2. Unordered off-diagonal pairs: (42)=6\binom{4}{2} = 6, each with 3 allowed states: 36=7293^6 = 729.
  3. Total =16×729=11664= 16 \times 729 = 11664.

Worked example 2: Onto functions

How many onto functions are there from a 5-element set to a 3-element set?

Inclusion-exclusion over the codomain elements that are missed: 35−(31)25+(32)15−0=243−96+3=150.3^5 - \binom{3}{1}2^5 + \binom{3}{2}1^5 - 0 = 243 - 96 + 3 = 150. Check: 3! S(5,3)=6×25=1503!\,S(5, 3) = 6 \times 25 = 150.

Worked example 3: Is the relation an equivalence?

On Z\mathbb{Z}, define a R ba\,R\,b iff a2≡b2(mod5)a^2 \equiv b^2 \pmod 5.

  • Reflexive and symmetric: clear.
  • Transitive: a2≡b2a^2 \equiv b^2 and b2≡c2b^2 \equiv c^2 give a2≡c2a^2 \equiv c^2.

So RR is an equivalence relation. Squares mod 5 take values 0,1,40, 1, 4: residue 0 gives 0; residues 1, 4 give 1; residues 2, 3 give 4. So there are 3 classes.

Any relation of the form "a R ba\,R\,b iff h(a)=h(b)h(a) = h(b)" is an equivalence relation, with one class per value of hh that is actually hit.

Worked example 4: Complements in a divisor lattice

In D30D_{30}, find the complement of 6. In D12D_{12}, does 2 have a complement?

  • 30=2⋅3⋅530 = 2 \cdot 3 \cdot 5 is square free. Complement of 6 is 30/6=530/6 = 5: gcd⁡(6,5)=1\gcd(6, 5) = 1, lcm⁡(6,5)=30\operatorname{lcm}(6, 5) = 30.
  • In D12D_{12} we need gcd⁡(2,c)=1\gcd(2, c) = 1 and lcm⁡(2,c)=12\operatorname{lcm}(2, c) = 12. The lcm forces 4∣c4 \mid c, which contradicts gcd⁡=1\gcd = 1. So 2 has no complement, and D12D_{12} is not a Boolean algebra.

Worked example 5: Is this poset a lattice?

Poset on {a,b,c,d}\{a, b, c, d\} with a<ca < c, a<da < d, b<cb < c, b<db < d, and no other strict relations.

Upper bounds of {a,b}\{a, b\} are cc and dd, which are incomparable, so there is no least upper bound. Not a lattice. This "bowtie" shape is the smallest example where pairs have upper bounds but no join.

Common traps

  • Confusing symmetric and antisymmetric as opposites.
  • Forgetting that divisibility on all nonzero integers is not antisymmetric (2∣−22 \mid -2 and −2∣2-2 \mid 2).
  • Using 2n(n−1)/22^{n(n-1)/2} for symmetric relations. That count is for reflexive and symmetric; plain symmetric is 2n(n+1)/22^{n(n+1)/2}.
  • Counting onto functions as nm−nn^m - n or similar. Use inclusion-exclusion.
  • Assuming a complemented lattice is distributive. The diamond M3M_3 is complemented but not distributive, and its atoms have two complements each.
  • Mixing up maximal and greatest. A poset can have several maximal elements and no greatest one.
  • Assuming the union of two equivalence relations is an equivalence relation.

Quick revision

  • Relations on nn elements: 2n22^{n^2}. Reflexive: 2n2−n2^{n^2 - n}. Symmetric: 2n(n+1)/22^{n(n+1)/2}.
  • Reflexive and symmetric: 2n(n−1)/22^{n(n-1)/2}. Antisymmetric: 2n3n(n−1)/22^n 3^{n(n-1)/2}. Asymmetric: 3n(n−1)/23^{n(n-1)/2}.
  • Equivalence relations: Bell numbers 1,2,5,15,52,2031, 2, 5, 15, 52, 203. With kk classes: S(n,k)S(n, k).
  • Functions m→nm \to n: nmn^m. Injective: n!/(n−m)!n!/(n-m)!. Onto: n! S(m,n)n!\,S(m, n).
  • Partial orders on 3 elements: 19.
  • g∘fg \circ f injective forces ff injective; g∘fg \circ f onto forces gg onto.
  • Lattice: every pair has join and meet. Distributive iff no M3M_3 or N5N_5 sublattice.
  • DnD_n is Boolean iff nn is square free.
  • Boolean algebra = complemented + distributive; finite ones have 2k2^k elements.

Further reading

Test this section