Contents / Discrete Mathematics / Sets and Functions
Chapter 2
Sets and Functions
Set operations and the double-inclusion method used throughout; distributive and De Morgan laws by element chasing; inclusion-exclusion for two and three sets; functions, images and preimages; injectivity and surjectivity characterised by left and right inverses; bijections and composition; power sets with the count 2 to the n; and Cantor's theorem proved by the diagonal set.
Introduction
Mathematics needs a single language in which every other object can be described, and since the end of the nineteenth century that language has been sets. A number, a list, a graph, a program's state space, a relation, a function — each of them can be presented as a set, or as a set equipped with a little extra structure. That is not a philosophical flourish; it is a practical economy. Prove something about sets once and it holds everywhere, because everything else is built on top.
Two ideas carry this chapter. The first is that a set is determined by its members and by nothing else — not by how it was described, not by the order in which you list them, not by how many times you mention an element. The second is that a function is the right notion of "comparison" between sets, and that three properties of functions — injectivity, surjectivity, and their conjunction, bijectivity — turn into three ways of comparing sizes: at most as big, at least as big, exactly as big. Once sizes are compared by functions rather than by counting, the comparison keeps working for infinite sets, and the last theorem in this chapter is the startling thing that happens when it does.
The technique to master here is not a formula but a habit: to prove two sets equal, prove each is a subset of the other. We prove that this is legitimate at the start of the chapter and then use it constantly — for the distributive laws, for De Morgan's laws, for every identity of set algebra. Take an arbitrary element of the left side, walk it across to the right side, then walk an arbitrary element back. The argument is always the same shape, and a reader who has internalised that shape has learned most of what set algebra has to teach.
We also count. Counting subsets, functions, injections, surjections and bijections is where discrete mathematics starts to earn its keep, and inclusion–exclusion — the correction term that stops double counting — is the first genuinely useful counting theorem most people meet. The chapter ends with Cantor's theorem: for every set , no function can be onto. Its proof is four lines long, uses nothing but the material of this chapter, and shows that there is no largest set and no single "infinity".
A word on scope. Sets are also the subject of a foundational theory with axioms, ordinals, cardinal arithmetic and independence results; that belongs to the separate subject Set Theory and is not developed here. In this chapter a set is a collection of things, and the only care we take with "collection" is to note, in one remark, where naive use of the word goes wrong.
2.1Sets, membership, and the double-inclusion method
A set is specified by saying what belongs to it. Everything else in this section follows from taking that sentence literally.
Definition 2.1 (Set and membership). A set is a collection of distinct objects, called its elements or members. We write for " is an element of " and for its negation. A finite set may be given by roster notation, listing its elements between braces, as in .
Because a set is fixed by its membership, the roster carries no information beyond which objects appear in it. Order is not part of the data, and repetition adds nothing:
Both sides have exactly the elements , and , so they are the same set. If you need order, use a sequence or a tuple; if you need repetition, use a multiset. A set is the structure that has thrown both away, and that is precisely what makes it the simplest one.
Definition 2.2 (Set-builder notation). For a property , we write
for the set of those elements of an already-given set that satisfy . Read the colon as "such that". For example is the set of even integers.
Notation. Throughout, , is the integers, the rationals and the reals. For a positive integer we write
the standard -element set. Almost every counting argument below is phrased with in the background.
Remark. Set-builder notation as written above carves a subset out of a set that is already in hand, and that restriction is not decoration. Allowing for an arbitrary property, with no ambient set, produces Russell's paradox: let and ask whether ; either answer contradicts the other. Repairing this is the business of Set Theory and its axioms. For this chapter, the discipline of always drawing elements from a stated set is enough to keep us out of trouble.
Definition 2.3 (Empty set). The empty set, written , is the set with no elements: for every .
Definition 2.4 (Subset and proper subset). A set is a subset of a set , written , if every element of is an element of ; that is, if the implication
holds for all . If and , then is a proper subset, written .
Pitfall. and are different relations between different kinds of thing. For we have and , but is a type error and is false. An element of is a member; a subset of is a set of members. The distinction matters most in the section on power sets, where the elements of are exactly the subsets of .
Set equality is now definable, and the definition is the engine of the whole chapter.
Definition 2.5 (Equality of sets). Two sets are equal, , if they have exactly the same elements: for every , if and only if . This principle is called extensionality.
Proposition 2.6 (Set equality by double inclusion). For all sets and ,
Proof. Suppose . Let . By extensionality if and only if , so . As was arbitrary, ; the same argument with the roles exchanged gives .
Conversely suppose and , and let be arbitrary. If then , because . If then , because . So if and only if , and extensionality gives .∎
This innocuous-looking proposition is a method, and it is the method this chapter uses more than any other. To prove an identity between two set expressions:
- Take an arbitrary in the left-hand set. Unfold the definitions until you have a logical statement about .
- Reason with that statement — using the ordinary rules for "and", "or" and "not" — until you reach the statement defining the right-hand set. Conclude lies in the right-hand set, hence .
- Repeat starting from an arbitrary in the right-hand set.
Step 3 is not optional in general, though it is often unnecessary in practice: when every step in part 2 is an if and only if rather than a one-way implication, the same chain read backwards is the reverse inclusion, and it is honest to say so instead of writing it out. We will do exactly that once the reader has seen the long form several times.
Proposition 2.7 (The empty set is a subset of every set). For every set , .
Proof. We must show that holds for every . Fix an . By the definition of the hypothesis is false, and an implication with a false hypothesis is true. Hence the implication holds for every , which is the definition of .∎
Intuition. The argument feels like a trick the first time, so it is worth naming the reason it is not. To refute you would have to exhibit an element of that is missing from . There are no elements of at all, so no such counterexample can be produced, and a claim with no possible counterexample is true. A statement true this way is called vacuously true. Nothing has been smuggled in: "all my unicorns are purple" is true for the same reason, and would become informative only if I owned a unicorn.
Proposition 2.8 (Uniqueness of the empty set). There is exactly one set with no elements.
Proof. Suppose and both have no elements. By the proposition The empty set is a subset of every set, applied with in the role of the empty set, ; applied with in that role, . By Set equality by double inclusion, .∎
Proposition 2.9 (Inclusion is reflexive and transitive). For all sets , , : ; and if and then .
Proof. Reflexivity is the implication , which holds for every .
For transitivity, let . Since we get , and since we get . As was arbitrary, .∎
Together with antisymmetry — which is exactly Set equality by double inclusion — this says is a partial order, a notion taken up in the chapter on relations. It is only partial: two sets may be incomparable, as and are, neither containing the other.
Example 2.10 (Deciding inclusions). Let , and . Decide each of , , , , , .
Solution.
- : true — both and lie in .
- : false. The elements of are , and ; the set is not among them.
- : true. The set is listed as an element of .
- : true, but for a different reason — its only element belongs to . Note that items 3 and 4 are both true here by coincidence of this example, not in general.
- : true, by The empty set is a subset of every set.
- : false. No element of is the empty set.
Example 2.11 (A first double-inclusion proof). Let and . Prove .
Solution.
- (.) Let , so for some integer . Then is even and is a multiple of , so .
- (.) Let . Being even, for some integer . Since and , and is prime, — this is Euclid's lemma from number theory. Write ; then , so .
- Both inclusions hold, so by Set equality by double inclusion, .
Pitfall. The second inclusion above needed a real idea, while the first was routine. That asymmetry is typical, and it is the reason you must actually write both halves rather than assert "similarly". "Even and divisible by " implying "divisible by " is false for the analogous claim with and : is a multiple of and of , but is the multiples of , not of .
2.2Operations on sets and the algebra they obey
Set operations are defined by the logical connectives: union is "or", intersection is "and", complement is "not". Every identity in this section is therefore a fact of propositional logic in disguise, and element chasing is the translation.
Definition 2.12 (Union, intersection, difference, complement). Let and be subsets of a universal set fixed by context. Then
The "or" in the union is inclusive: may lie in both. Sets with are called disjoint.
Definition 2.13 (Symmetric difference). The symmetric difference of and is
the elements lying in exactly one of the two sets.
Definition 2.14 (Cartesian product). The Cartesian product of and is the set of ordered pairs
where means and . Write for , and more generally for the set of -tuples from .
Unlike union and intersection, the Cartesian product is neither commutative nor associative in the strict sense: , so unless or one of them is empty. The product is where order re-enters a theory built on unordered collections, and it is what makes relations and functions expressible in the language of sets at all.
The picture is a proof aid, not a proof. It is reliable for two or three sets — three circles in general position really do produce all eight combinations — and unreliable beyond that, since four circles cannot cut the plane into the sixteen regions four sets require. Element chasing has no such limit, which is why the arguments below are written in symbols even where a diagram would convince you.
Theorem 2.16 (Distributive laws). For all sets , , ,
Proof. We prove the first law by double inclusion.
(.) Let . Then , and , so or . In the first case and , so . In the second case and , so . Either way .
(.) Let . Then or . In the first case and ; in the second and . In both cases , and in both cases lies in or in , hence in . Therefore .
Both inclusions hold, so the sets are equal by Set equality by double inclusion.
The second law is the same argument with "and" and "or" exchanged throughout: says , or else lies in both and ; and says lies in or , and in or . If both hold. If , the first says and , and the second says exactly the same, so the two statements agree in every case.∎
Intuition. The two laws are the set-theoretic reading of the two distributive laws of logic. Arithmetic has only one such law — multiplication distributes over addition, but addition does not distribute over multiplication — so the symmetry here is genuinely new. Do not import the arithmetic instinct that one operation is "stronger"; with and neither is.
Theorem 2.17 (De Morgan's laws for sets). For all subsets , of a universal set ,
Proof. Take the first. For , the following statements are equivalent, each line following from the previous by the definition named beside it:
; (definition of complement); it is not the case that ( or ) (definition of union); and (De Morgan's law of logic); and ; .
Every step is an equivalence, so reading the chain downwards gives and reading it upwards gives the reverse inclusion. By Set equality by double inclusion the two sets are equal.
For the second law, apply the first to the sets and : it gives , using . Taking complements of both sides yields .∎
Remark. The pattern to remember is: a complement turns a union into an intersection and an intersection into a union. It reappears verbatim for logical connectives (), for quantifiers (), and in Boolean circuit design, where it is the rule that lets any circuit be rebuilt from NAND gates alone.
Proposition 2.18 (Difference as intersection with a complement). For all subsets , of : .
Proof. For , means and , which is exactly and , which is . Each step is an equivalence, so both inclusions hold at once.∎
That proposition is a labour-saving device: it removes from any expression, leaving only , and , on which the distributive and De Morgan laws can be used directly. The next example shows the technique.
Example 2.19 (Simplifying a set expression). Simplify .
Solution.
- By Difference as intersection with a complement, .
- By the Distributive laws read right to left, this is .
- , since every either lies in or does not.
- , because . Final answer: .
Example 2.20 (Proving an identity by element chasing). Prove .
Solution.
- Let . Then and .
- By De Morgan's laws for sets (or directly), means and .
- So and , giving ; and and , giving . Hence lies in the intersection.
- Conversely, if then , and , so and , that is .
- Both inclusions hold, so the sets are equal.
Proposition 2.21 (Three readings of inclusion). For all sets and the following are equivalent:
- ;
- ;
- .
Proof. (1 2.) Certainly . For the other inclusion, let ; then , in which case by hypothesis, or already. So , and the two are equal.
(2 3.) Assume . Then , and every lies in , so .
(3 1.) Assume and let . Then , so in particular . Hence .
The three implications close a cycle, so the three statements are equivalent.∎
Now to counting. If is finite we write for the number of its elements, its cardinality. The union of two sets is the first place where naive counting goes wrong, and the fix is the most reused idea in combinatorics.
Theorem 2.22 (Inclusion–exclusion for two sets). For finite sets and ,
Proof. Split into the three pairwise disjoint pieces , and ; every element of lies in exactly one of them, according to whether it lies in only, in both, or in only. Counting a disjoint union adds the counts, so
Similarly is the disjoint union of and , so , and likewise . Substituting,
Intuition. Adding and counts everything in the overlap twice, once from each set. Subtracting removes exactly one of those two counts, leaving every element counted once. The whole of inclusion–exclusion, at every size, is this bookkeeping carried out systematically.
Theorem 2.23 (Inclusion–exclusion for three sets). For finite sets , , ,
Proof. Apply Inclusion–exclusion for two sets to the pair and :
Expand by the same theorem. For the last term, the Distributive laws give , and a third application of the two-set formula gives
Finally , since intersection is idempotent and commutative. Substituting the three expansions and collecting signs gives the stated formula.∎
Intuition. Count each element by which of , , it belongs to. An element in exactly one set is counted once, by one positive term, and by nothing else. An element in exactly two, say and , is counted time. An element in all three is counted time. Every element is counted exactly once, which is what the theorem asserts.
Example 2.24 (A survey count). Of students, study Python, study C, study Haskell; study both Python and C, Python and Haskell, C and Haskell, and study all three. How many study at least one of the languages, and how many study none?
Solution.
- By Inclusion–exclusion for three sets, the number studying at least one is .
- The positive terms give ; the pairwise terms subtract ; adding back gives .
- Those studying none are the complement inside the students: . Final answer: study at least one, study none.
Example 2.25 (Recovering an unknown intersection). Two finite sets satisfy , and . Find and .
Solution.
- Rearranging Inclusion–exclusion for two sets, .
- The symmetric difference is everything in the union but not the intersection, so . Final answer: and .
Proposition 2.26 (Cardinality of a Cartesian product). For finite sets and , .
Proof. Write with . Every pair in has exactly one first coordinate, so is the disjoint union of the sets . For each the assignment matches the elements of with those of one for one, so . Summing over the disjoint pieces, .∎
Corollary 2.27 (Tuples from one set). For a finite set and , .
Proof. Induct on . For the claim is . If , then identifying with and applying Cardinality of a Cartesian product gives .∎
Example 2.28 (Counting strings). How many binary strings of length are there, and how many of them start with and end with ?
Solution.
- A binary string of length is an element of , so by Tuples from one set there are .
- Fixing the first and last symbols leaves the six middle positions free, giving . Final answer: and .
2.3Functions: the definition that removes the ambiguity
Informally a function is a rule. That description is too loose to prove anything with — two different rules can compute the same function, and some "rules" fail to define a function at all — so the working definition names the data instead: a domain, a codomain, and an assignment that is total and single-valued.
Definition 2.29 (Function). A function from a set to a set , written , assigns to each element exactly one element . The set is the domain, the codomain, and the value or image of .
Formally, is a subset — its graph — such that for every there is exactly one with .
The two conditions packed into "exactly one" are worth separating. At least one makes total: no element of the domain may be left without a value, so is not a function , though it is one on . At most one makes well defined: no element may receive two values, so the "rule" does not define a function .
Definition 2.30 (Image and preimage). For , and , define
The set is the image (or range) of . The notation is the preimage of and is defined for every , whether or not has an inverse function.
Pitfall. Codomain and image are different sets, and a function carries its codomain as part of its data. The squaring maps and have the same rule and the same graph read as a set of pairs, but the second is surjective and the first is not. Any statement about surjectivity is a statement about the chosen codomain.
Definition 2.31 (Equality of functions). Two functions are equal if for every . Functions with different domains or different codomains are never equal.
Definition 2.32 (Composition and identity). For and , the composite is defined by . The identity function is given by .
Proposition 2.33 (Composition is associative, with identities). For , and ,
Proof. All four composites in the first identity are functions , so by Equality of functions it suffices to check them at an arbitrary :
For the second, and .∎
Associativity is what licenses writing with no brackets, and it is used silently in every inverse argument later. Note that composition is emphatically not commutative: with and on , while .
Theorem 2.34 (Counting functions). Let and be finite with and . The number of functions is .
Proof. List the domain as . A function is determined by the tuple of its values , since knowing every value is knowing by Equality of functions. Conversely every tuple arises from exactly one function, namely the one sending — this assignment is total and single valued because each appears once in the list. So the functions correspond one for one with the elements of , and by Tuples from one set there are of them.∎
Intuition. Choosing a function is filling in a table with one row per element of the domain. Each row is filled independently, from options, and there are rows: . The notation for the set of functions is chosen so that this count reads .
Example 2.35 (Counting assignments). How many ways can distinct jobs be assigned to machines, if every job goes to exactly one machine and machines may sit idle?
Solution.
- An assignment is a function from the -element set of jobs to the -element set of machines.
- By Counting functions there are of them. Final answer: .
Proposition 2.36 (Images and unions, preimages and everything). Let , let and . Then
The inclusion for images can be strict.
Proof. For the first identity: means for some , that is for some or some , which says or . Every step is an equivalence, so the sets are equal.
For the inclusion: if then with in both and , so and . The reverse fails because the element of witnessing need not be the element of witnessing . Concretely, take with and : then , so the left side is , while both images are and the right side is .
For the preimages: means , that is or , that is or . Replacing "or" by "and" throughout proves the intersection case, and the argument works because is a single element, so asking which sets it lies in commutes with the connectives.∎
Remark. This is the reason preimages are the better-behaved notion. Preimage respects unions, intersections and complements; image respects only unions. A great deal of later mathematics — continuity in topology, measurability in probability — is defined using rather than for exactly this reason.
Example 2.37 (Images and preimages of a concrete map). Let be . Compute , , and .
Solution.
- , a set of size — images can shrink.
- , since those are the integers squaring to .
- : no integer squares to . A preimage may be empty; that is not an error.
- , which has elements.
2.4Injections and surjections
Two questions can be asked of a function , and they are independent of each other. Does ever collide, sending two inputs to one output? Does reach everything in ? The answers name the two classes that organise the rest of the chapter.
Definition 2.38 (Injective, surjective, bijective). A function is
- injective (one-to-one) if implies , for all ;
- surjective (onto) if for every there exists with , that is ;
- bijective if it is both.
The contrapositive of injectivity is often the more usable form: , "distinct inputs give distinct outputs". In practice one proves injectivity by assuming and deducing algebraically; one proves surjectivity by taking an arbitrary and constructing an that maps to it.
Example 2.40 (Deciding the two properties). For each function decide injectivity and surjectivity: (a) , ; (b) , ; (c) , ; (d) , .
Solution.
- (a) Injective: gives . Not surjective: no integer maps to , since has no integer solution.
- (b) Injective, as forces ; and surjective, since for every . So is bijective.
- (c) Not injective, since . Not surjective, since never equals .
- (d) Not injective (), but surjective, since every satisfies .
The next two theorems recast the definitions in terms of inverses, and they are the reason these particular properties matter: injectivity means the function can be undone from the left, surjectivity means it can be undone from the right.
Definition 2.41 (Left and right inverses). Let . A function is a left inverse of if , and a right inverse if .
Theorem 2.42 (Injective iff a left inverse exists). Let with . Then is injective if and only if there is a function with .
Proof. () Suppose such a exists and . Applying to both sides, , that is since . So is injective.
() Suppose is injective. Since is nonempty, fix some . Define by
The first clause is legitimate precisely because is injective: for at least one such exists by definition of the image, and at most one exists by injectivity, so the value is well defined. The second clause makes total. For any we have , and the unique preimage of is itself, so . Hence .∎
Remark. The hypothesis is needed only to have somewhere to send the unreached elements of . The empty function is injective but admits no left inverse when , since there is no function at all.
Theorem 2.43 (Surjective iff a right inverse exists). Let . Then is surjective if and only if there is a function with .
Proof. () Suppose and let . Then , so is in the image of . As was arbitrary, is surjective.
() Suppose is surjective. For each the set is nonempty. Choose one element from each of these sets and call it ; this defines a function , and holds for every by construction, so .∎
Remark. The phrase "choose one element from each" in the last proof is the axiom of choice when is infinite: making infinitely many independent choices at once is not something the other axioms provide. For finite no axiom is needed — repeated use of "the set is nonempty, so pick an element" suffices. We use choice silently from here on, as every introductory treatment does; what it costs and what it buys is the business of Set Theory.
Example 2.44 (Building the two one-sided inverses). Let be and let be . Verify that is a left inverse of , and show has no right inverse.
Solution.
- for every integer , so and is a left inverse — consistent with being injective.
- If were a right inverse then , that is , which has no integer solution. So no right inverse exists, consistent with not being surjective by Surjective iff a right inverse exists.
- Note : a left inverse need not be a right inverse.
Theorem 2.45 (Composition preserves both properties). Let and .
- If and are injective, so is .
- If and are surjective, so is .
Proof. (1) Suppose , that is . Injectivity of gives , and injectivity of gives .
(2) Let . Since is surjective there is with ; since is surjective there is with . Then , so lies in the image of .∎
Theorem 2.46 (Partial converses for a composite). Let and .
- If is injective, then is injective.
- If is surjective, then is surjective.
Neither conclusion can be strengthened: injective does not force injective, and surjective does not force surjective.
Proof. (1) Suppose . Applying gives , that is ; since is injective, .
(2) Let . Since is surjective there is with . Then is an element of with , so is surjective.
For the counterexamples, take , , with and . Then is the identity on , hence both injective and surjective, while is not injective (it collapses and ) and is not surjective (it misses ).∎
Intuition. Read the arrows. In , information can only be destroyed as you move right, so if nothing was lost overall then nothing was lost in the first step — that is (1). Dually, everything in must be reached by the last step, so if the composite reaches all of then so does — that is (2). The two halves that fail are the ones about the far end of the chain, where the other map can hide the defect.
Example 2.47 (Using the partial converses). Let be and be . Is injective? Is injective? What does Partial converses for a composite let you conclude?
Solution.
- on , and with forces , so is injective.
- itself is not injective on , since .
- The theorem concludes only that is injective, which it is. This is exactly the case showing the missing half — an injective composite with a non-injective outer map — is genuinely possible.
Theorem 2.48 (Counting injections). Let and . The number of injections is the falling factorial
when , and when .
Proof. List and build an injection by choosing values in order. The value may be any of the elements of . Given the first values, all distinct, the value must avoid them and may be anything else, so there are choices. Each sequence of choices yields a distinct injection and every injection arises from exactly one such sequence, namely the sequence of its own values. Multiplying the independent counts gives .
If the process stalls: after steps every element of has been used and the factor appears, so the product is . That no injection exists in this case is the content of the next theorem.∎
Theorem 2.49 (Pigeonhole principle, in function form). Let and be finite with . Then no function is injective; equivalently, some has .
Proof. Let and let be any function. The sets for are pairwise disjoint — an element lies in the one indexed by and no other — and their union is , because is total. Hence
If every term were at most the sum would be at most , a contradiction. So some term is at least , meaning two distinct elements of share an image, and is not injective.∎
Intuition. Put pigeons into holes with more pigeons than holes and some hole holds two. The argument above is just that statement with the holes named . Its power comes from choosing the function well: to show that among any people two share a birth month, take from people to months.
Example 2.50 (A pigeonhole argument). Show that any set of distinct integers chosen from contains two whose difference is , or explain why it can fail.
Solution.
- Pair the numbers by remainder-style blocks: — five pairs, each with difference .
- Define from the chosen integers to these pairs by sending each integer to the pair containing it. This is a function from a -element set to a -element set.
- By the Pigeonhole principle, in function form, is not injective, so two chosen integers lie in the same pair. Those two differ by exactly .
2.5Bijections and the comparison of sizes
A bijection pairs the elements of two sets with nothing left over on either side. That is what "same size" ought to mean, and taking it as the definition of same size is what lets the notion survive the passage to infinite sets.
Theorem 2.51 (Bijective iff a two-sided inverse exists). Let . Then is bijective if and only if there is a function with
Moreover such a function is unique.
Proof. () If such a function exists it is in particular a left inverse and a right inverse, so is injective by Injective iff a left inverse exists and surjective by Surjective iff a right inverse exists.
() Suppose is bijective. For each , surjectivity provides an with and injectivity makes it unique; define to be that . This is a total, single-valued assignment, hence a function . By construction for all , and for the unique preimage of is , so .
For uniqueness, suppose and both satisfy the two identities. Then, using associativity from Composition is associative, with identities,
Definition 2.52 (Inverse function). For a bijection , the unique function of the preceding theorem is the inverse of .
Pitfall. The symbol is overloaded. Applied to a set it means the preimage and always makes sense; applied to an element it means the inverse function and makes sense only when is bijective. Context disambiguates, but write rather than whenever is not known to be a bijection.
Theorem 2.53 (The inverse of a bijection is a bijection). If is a bijection then is a bijection, and .
Proof. The two identities characterising read, from the point of view of , as: is a left inverse of (since ) and a right inverse of (since ). So has a two-sided inverse, namely , and by Bijective iff a two-sided inverse exists it is a bijection with inverse .∎
Proposition 2.54 (Composites of bijections). If and are bijections, then is a bijection and
Proof. That is bijective follows from Composition preserves both properties applied twice. For the formula, compute both composites using associativity:
and symmetrically . By the uniqueness clause of Bijective iff a two-sided inverse exists, is the inverse of .∎
Intuition. Undoing "socks then shoes" is "shoes off then socks off": the order reverses. That is the whole content of , and the same reversal appears for matrix inverses and for group inverses, because it depends only on associativity and identities.
Theorem 2.55 (Counting bijections). If , the number of bijections is .
Proof. A bijection between two -element sets is in particular an injection, and by Counting injections with there are injections . Conversely every injection here is already a bijection: its image is a subset of with distinct elements, and a subset of an -element set having elements is the whole set. So bijections and injections coincide in this case, and there are of them.∎
Definition 2.56 (Equinumerosity). Sets and are equinumerous, written , if some bijection exists. A set is finite if it is equinumerous with for some , countably infinite if it is equinumerous with , and uncountable otherwise.
Proposition 2.57 (Equinumerosity behaves like an equality). For all sets , , : ; if then ; and if and then .
Proof. For the first, is a bijection , since it is its own two-sided inverse. For the second, a bijection yields the bijection by The inverse of a bijection is a bijection. For the third, bijections and compose to the bijection by Composites of bijections.∎
Example 2.58 (An infinite set equinumerous with a proper subset). Exhibit a bijection from to the set of even natural numbers, and say what it shows.
Solution.
- Define by .
- Injective: gives . Surjective: any even is with .
- So , even though . For infinite sets a proper subset may have the same size — a phenomenon impossible for finite sets, where Pigeonhole principle, in function form forbids it. This is Hilbert's hotel, and it is a theorem, not a paradox.
Theorem 2.59 (Counting surjections). The number of surjections from an -element set onto an -element set is
Proof. Let and for each let be the set of functions that miss . A function fails to be surjective exactly when it lies in , so the surjections number by Counting functions.
For a set of indices, the functions missing every with are precisely the functions from into the remaining elements, of which there are ; and there are such index sets. The inclusion–exclusion principle — the pattern proved above for two and three sets, extended to sets by the same alternating bookkeeping — therefore gives
Subtracting from and absorbing as the term of the alternating sum yields the stated formula.∎
Example 2.60 (Surjections onto a three-element set). How many functions from a -element set onto a -element set are there?
Solution.
- By Counting surjections with , : .
- That is .
- Check against the structure: a surjection collapses exactly one pair of inputs, and there are pairs and ways to assign the resulting three blocks to the three targets, giving . Final answer: .
2.6Power sets, and a set that outruns every function into it
The power set is the first construction that takes a set to a strictly bigger one, and the argument that it does so is the deepest thing in this chapter.
Definition 2.61 (Power set). The power set of a set is the set of all subsets of :
The elements of are sets. For ,
a four-element set, and note that and always, by The empty set is a subset of every set and reflexivity of inclusion. In particular has one element, not none: the empty set has exactly one subset, itself.
Theorem 2.62 (The size of a power set). If is finite, then .
Proof. Write and define by sending a subset to its indicator string
This is a function: each subset determines each bit unambiguously.
is injective. If then for every we have if and only if if and only if . Since every element of is some , the sets and have the same elements, so by extensionality.
is surjective. Given a string , put . Then and is the given string.
So is a bijection, and by Tuples from one set the codomain has elements. Hence .∎
Intuition. Building a subset is walking down the list of elements answering one yes/no question each: in or out? The record of your answers is a binary string of length , every string is a possible record, and different records give different subsets. So subsets and strings are the same objects wearing different clothes — which is why a set data type is often implemented as a bit vector.
Corollary 2.63 (Subsets by size). For and , the number of subsets of with exactly elements is , and consequently
Proof. Under the bijection of The size of a power set, a subset of size corresponds to a binary string with exactly ones, and the number of such strings is the number of ways to choose which of the positions carry a one, namely . Every subset has exactly one size, so classifying by size partitions it into the disjoint pieces counted by , whose total is .∎
Example 2.64 (Power sets of small sets). Compute and for , and list .
Solution.
- by The size of a power set.
- Applying the theorem again to the -element set : .
- , four elements, as predicts. Final answer: and .
Example 2.65 (Counting subsets with a constraint). How many subsets of contain the element but not the element ?
Solution.
- Membership of is forced to "in" and membership of is forced to "out", so two of the ten yes/no decisions are made for us.
- The remaining elements are unconstrained, giving subsets by the indicator-string argument of The size of a power set. Final answer: .
Everything so far has been finite bookkeeping. The final theorem is not, and it is the reason this chapter ends here rather than with a summary of counting formulas. Cantor's question is: can a set be listed by its own elements? Can we index every subset of by an element of ?
Theorem 2.67 (Cantor's theorem). For every set , there is no surjection . Consequently .
Proof. Let be any function. Define the diagonal set
This is a legitimate subset of : it is carved out of by the property " ", which is a well-formed statement about , since is a subset of and membership in it is a yes-or-no question. So .
We claim is not in the image of . Suppose, for contradiction, that for some , and ask whether .
- If , then by the defining property of we have , a contradiction.
- If , then fails the defining property, so , again a contradiction.
Both cases are impossible, yet one of them must hold, so no such exists. Hence is missed by , and is not surjective.
Since was arbitrary, no surjection exists. A bijection is in particular a surjection, so no bijection exists either, and .∎
Intuition. Read as a table with one row per element of , row holding the membership string of the subset , as in the figure. The set is built by walking down the main diagonal and writing the opposite of what you find. The resulting string cannot be row , because it differs there in column ; it cannot be row , because it differs in column ; and so on for every row. The table lists some subsets and is not among them, no matter how the table was filled in.
Remark. Note what the proof does not need: may be finite, countable or anything else, and no counting is performed. For finite the conclusion is the familiar ; for it says is uncountable, which is the standard proof that the reals cannot be listed. Iterating gives , an unending ladder of strictly increasing infinities, so there is no largest set and no single "infinity". Where exactly the reals sit on that ladder is the continuum hypothesis, and the answer — that the usual axioms settle neither yes nor no — belongs to Set Theory.
Remark. The map is an injection , so is at least as large as ; Cantor's theorem says it is never exactly as large. The two together are what justify calling the power set strictly bigger.
Example 2.68 (The diagonal set for a small map). Let and let , , . Compute and verify it is missed by .
Solution.
- Test each element: , so . , so . , so .
- Hence .
- The image of is , and is not among its three members, exactly as Cantor's theorem predicts. Indeed misses subsets in all; the theorem's contribution is to name one that is missed for every at once.
Summary. The chapter's spine: extensionality gives Set equality by double inclusion, which is the proof technique for every identity of set algebra — the Distributive laws, De Morgan's laws for sets, and the rest. Counting starts with Inclusion–exclusion for two sets and its three-set version, and with , from which Counting functions gives , Counting injections gives the falling factorial, Counting bijections gives and Counting surjections gives an alternating sum. Injectivity and surjectivity are characterised by one-sided inverses and bijectivity by a two-sided one; composition preserves both properties, and the partial converses hold only at the near and far ends of the chain. Finally by the indicator-string bijection, and Cantor's theorem shows that no function from can reach every subset of .
- Confusing with . For : and are true; and are not. The confusion is fatal in , whose elements are sets.
- Believing . The first has no elements; the second has one. Hence , not .
- Proving only one inclusion. " " is half of an equality. If your steps are genuine equivalences, say so and cite that the chain reads both ways; otherwise write the second half out, because it may need a different idea — as in the example.
- Distrusting a vacuous argument. is true because no element of can witness a failure. This is not a loophole; it is what "for all" means over an empty range.
- Adding cardinalities of overlapping sets. needs . Otherwise subtract the overlap, and for three sets remember to add back.
- Confusing codomain with image. as a map is not surjective; the same rule as a map is. Surjectivity is never a property of the rule alone.
- Checking injectivity with one example. Showing proves nothing. Assume and derive for arbitrary ; a single collision, on the other hand, does disprove it.
- Assuming a left inverse is a right inverse. undoes doubling from the left but not from the right. Only a bijection has a two-sided inverse.
- Over-reading the partial converses. injective gives only that is injective, and surjective only that is. The other halves are false, with a two-line counterexample.
- Counting functions as instead of . With and , the count of is : one independent choice per element of the domain.
- Writing for a non-invertible and then treating it as a function. is always a preimage set; as an element requires bijectivity.
- Claiming Cantor's proof needs infinity. It needs nothing but the definition of , and it applies verbatim to a three-element set. Infinity is where the conclusion becomes surprising, not where the proof lives.