It’s often that a student’s first exposure to rigorous mathematics is through set theory, as originally studied by Georg Cantor. This means we will not treat set theory axiomatically (as in ZF set theory), but rather we will take the definition of a set for granted, and allow any operation to be performed on a set. This will be clear when we present examples, and it will be clear why this is a bad idea when we present paradoxes.

## The Basics of Sets

**Definition**: A *set * is a collection of distinct objects, each of which is called an *element* of S. For a potential element , we denote its membership in and lack thereof by the infix symbols , respectively. The proposition is true if and only if is an element of .

**Definition**: The *cardinality* of , denoted , is the number of elements in S.

The elements of a set can in principal be anything: numbers, equations, cats, morals, and even (especially) other sets. There is no restriction on their size, and the order in which we list the objects is irrelevant. For now, we will stick to sets of numbers and later we will move on to sets of other sets.

There are many ways to construct sets, and for finite sets it suffices to list the objects:

Clearly this set has cardinality six. The left and right curly braces are standard notation for the stuff inside a set. Another shorter construction is to simply state the contents of a set (let be the set of even numbers between 0 and 10, inclusive). Sometimes, it will be very important that we construct the sets in a more detailed way than this, because, as we will see, sets can become rather convoluted.

We may construct sets using an implied pattern, i.e. for the positive evens:

For now, we simply allow that this set has infinite cardinality, though we will revisit this notion in more detail later. In this way we define two basic sets of numbers:

We name the *natural numbers*, and the *integers*. Yet another construction allows us to populate a set with all values that satisfy a particular equation or proposition. We denote this . For example, we may define , the *rational numbers* (fractional numbers) as follows:

This is not quite a complete description of how rational numbers work: some fractions are “equivalent” to other fractions, like 2/4 and 1/2. There is an additional piece of data called a “relation” that’s imposed on this set, and any two things which are related are considered equivalent. We’re not going to go into the details of this, but the interested reader should look up an equivalence relation.

Next, we want to describe certain pieces of sets:

**Definition**: A set is a *subset *of a set , denoted , if all elements of are in . i.e., for all implies .

And we recognize that under our standard equality of numbers (i.e. ), we have .

We may now define equality on sets, extending the natural idea that two sets are equal if they contain precisely the same elements:

**Definition**: Two sets are equal if and .

A natural set to construct now is the *power set *of a given set:

**Definition**: the *power set* of , denoted , is the set of all subsets of . i.e. .

Elements of this set are sets themselves, and there are two trivial, yet important sets to recognize are in , namely itself and , the *empty set* which contains no elements, is vacuously a subset of every set.

For a finite set , power sets are strictly larger in size, since there exists a *singleton* set for each . As an exercise for the reader, determine the size of for any finite set , expressed in terms of . For infinite sets, we simply admit that their power sets are also infinite, since we don’t yet have a way to describe “larger” infinities.

## Building Sets From Other Sets

We have a couple of nice operations we may define on sets, which are rather trivial to define.

**Definition**: The *union* of two sets , denoted , is .

**Definition**: The *intersection* of two sets , denoted , is .

As an exercise, try to prove that .

The next definition requires one to remember what an *ordered tuple* is. Specifically, an ordered pair is just like a set which allows for repetition and respects the presented order of elements. So .

**Definition**: The *direct product *(or simply *product*) of two sets , denoted , is .

This is just like in defining the Cartesian Plane as ordered pairs of real numbers. We can extend this even further by defining to be the set of all -tuples of elements in .

## Functions, and Their -Jections

Now that we have sets and ways to build interesting sets, we may define mathematical objects which do stuff with them.

**Definition**: A *relation* on and , is a subset of . Denotationally, we write as shorthand for .

Relations are natural generalizations of on numbers. In general relations need no additional properties, but they are not very interesting unless they do. For more discussion on relations, we point the reader to the Wikipedia page on *equivalence relations*. As an exercise to the reader, prove that set equality (defined above) is an equivalence relation, as expected.

Now, we get to the meat of our discussion on sets: functions.

**Definition**: A *function * is a relation on and , a subset of , with the additional properties that for each , there is exactly one element of the form .

Colloquially, functions ‘accept’ a value from and output something in . This is why we may only have one ordered pair for each , because functions are deterministic. Furthermore, we must be able to put every value from into our function, so no values may be without a corresponding element of .

We have special notation for functions, which was established long before set theory was invented. If , we write to denote the corresponding element in . In addition, we say that a value *maps to* to mean . If the function is implicitly understood, we sometimes just write . Then we have the following definitions:

**Definition**: The *domain* of a function , sometimes denoted , is the set of input values . The *codomain*, denoted , is the set . Since not every value in must be in a pair in , we call the subset of values of which are produced by some input in the *range* of . Rigorously, the range of is .

Now we may speak of some “interesting” functions:

**Definition**: A function is a *surjection* if its range is equal to its codomain. In other words, for every , there is some with , or, equivalently, .

Note that being a surjection on finite sets implies that the domain is at least as big as the codomain. Though it seems trivial, we can use functions in this way to reason about the cardinalities of their domains and codomains.

**Definition**: A function is an *injection *if no two different values map to the same . In other words, if , then .

Similarly, for finite domains/codomains an injection forces the codomain to be at least as big as the domain in cardinality.

Now, we may combine the two properties to get a very special kind of function.

**Definition**: A function is a *bijection *if it is both a surjection and an injection.

A bijection specifically represents a “relabeling” of a given set, in that each element in the domain has exactly one corresponding element in the codomain, and each element in the codomain has exactly one corresponding element in the domain. Thus, the bijection represents changing the label into the label .

Note that for finite sets, since a bijection is both a surjection and an injection, the domain and codomain of a bijection must have the same cardinality! What’s better, is we can extend this to infinite sets.

## To Infinity, and Beyond! (Literally)

**Definition**: Two infinite sets have equal cardinality if there exists a bijection between them.

Now we will prove that two different infinite sets, the natural numbers and the integers, have equal cardinality. This is surprising, because despite the fact that the sets are not equal, one is a subset of the other and they have equal cardinality! So here we go.

Define as follows. Let . Continuing in this way, we see that , and for all . This is clearly a bijection, and hence .

We can extend this to any bijection between an infinite set of positive numbers and the set .

Let’s try to push bijections a bit further. Let’s see if we can construct a bijection between the natural numbers and the positive rationals (and hence the set of all rationals). If integers seemed bigger than the naturals, then the rational numbers must be truly huge. As it turns out, the rationals also have cardinality equal to the natural numbers!

It suffices to show that the natural numbers are equal in cardinality to the nonnegative rationals. Here is a picture describing the bijection:

We arrange the rationals into a grid, such that each blue dot above corresponds to some , where is the x-coordinate of the grid, and is the y-coordinate. Then, we assign to each blue dot a nonnegative integer in the diagonal fashion described by the sequence of arrows. Note these fractions are not necessarily in lowest terms, so some rational numbers correspond to more than one blue dot. To fix this, we simply eliminate the points for which their greatest common divisor is not 1. Then, in assigning the blue dots numbers, we just do so in the same fashion, skipping the places where we deleted bad points.

This bijection establishes that the natural numbers and rationals have identical cardinality. Despite how big the rationals seem, they are just a relabeling of the natural numbers! Astounding.

With this result it seems like *every *infinite set has cardinality equal to the natural numbers. It should be totally easy to find a bijection between the naturals and the real numbers .

Unfortunately, try as we might, no such bijection exists. This was a huge result proven by Georg Cantor in his study of infinite sets, and its proof has become a staple of every mathematics education, called Cantor’s Diagonalization Proof.

First, we recognize that every real number has a representation in base 2 as an infinite sequence of 0’s and 1’s. Thus, if there were such a bijection between the natural numbers and reals, we could list the reals in order of their corresponding naturals, as:

Here each corresponds to the th digit of the th number in the list. Now we may build a real number , the diagonal elements of this matrix. If we take and flip each digit from a 0 to a 1 and vice versa, we get the complement of , call it . Notice that differs from every real number at some digit, because the th real number shares digit with , and hence differs from at the same place. But is a real number, so it must occur somewhere in this list! Call that place . Then, differs from at digit , a contradiction.

Hence, no such bijection can exist. This is amazing! We have just found two infinite sets which *differ* in size! Even though the natural numbers are infinitely large, there are so many mind-bogglingly more real numbers that it is a larger infinity! We need new definitions to make sense of this:

**Definition**: An infinite set is *countably infinite* if there exists a bijection . If no such bijection exists, we call it *uncountably infinite*, or just *uncountable*.

Georg Cantor went on to prove this in general, that there cannot exist a bijection from a set onto its power set (we may realize the reals as the power set of the naturals by a similar decimal expansion). He did so simply by extending the diagonalization argument. But since we are dealing with infinite sets, we need even more definitions of “how hugely infinite” these infinite sets can be. These new measures of set cardinality were also invented by Cantor, and they are called transfinite numbers. Their investigation is beyond the scope of this post, but we encourage the reader to follow up on this fascinating subject.

We have still only scratched the surface of set theory, and we have even left out a lot of basic material to expedite our discussion of uncountability. There is a huge amount of debate that resulted from Cantor’s work, and it inspired many to further pick apart the foundations of mathematics, leading to more rigorous formulations of set theory, and extensions or generalizations such as category theory.

## Sets of Sets of Sets, and so on Ad Insanitum

We wrap up this post with a famous paradox, which makes one question whether all of the operations performed in set theory are justified. It is called Russell’s Paradox, after Bertrand Russell.

Suppose we define a set , which contains itself as an element. This does not break any rules of Cantor’s set theory, because we said a set could be any collection of objects. We may even speak of the set of all sets which contain themselves as elements.

Now let us define the set of all sets which *do not* contain themselves. Call this set . It must be true that either or . If , then is contained in itself, obviously, but then by the definition of , it does not contain itself as an element. This is a contradiction, so . However, if , then satisfies the definition of a set which does not contain itself, so . Again, a contradiction.

This problem has no resolution within Cantor’s world of sets. For this reason (and other paradoxes based on wild constructions of sets), many have come to believe that Cantor’s set theory is not well-founded. That is not to say his arguments and famous results are wrong, but rather that they need to be reproved within a more constrained version of set theory, in which such paradoxes cannot happen.

Such a set theory was eventually found that bypassed Russell’s paradox, and it is called Zermelo-Fraenkel set theory. But even that was not enough! Additional statements, like the Axiom of Choice (which nevertheless does lead to some counter-intuitive theorems), were found which cannot be proved or disproved by the other axioms of ZF set theory.

Rather than give up all that work on axiomatizing set theory, most mathematicians today accept the Axiom of Choice and work around any oddities that arise, resulting in ZFC (ZF + Choice), doing their mathematical work there.

So along with paradoxical curiosities, we have laid all the foundation necessary for reasoning about countability and uncountability, which has already shown up numerous times on this blog.

Until next time!

Hi! I’d like to point out that you make a very grave misunderstanding towards the end of this article when you discuss paradoxes arising from set theory. In particular, you seem to get caught up on the usage of the word paradox and don’t make clear that it is being used in multiple senses.

Russell’s paradox is a paradox in the logical sense. That is, if there exists a set of all sets which do not contain themselves, then a logical contradiction arises. The Banach-Tarski paradox is not a paradox in this sense. In fact, it is not logically inconsistent at all. The Banach-Tarski paradox is termed a paradox because it defies intution (or rather, it defies an intution not tempered by a proper understanding of measure theory). The Banach-Tarski paradox (roughly) states that it is possible to divide a sphere into pieces, rotate and translate these pieces, and then rearrange them into two spheres with same radius as the original. This seems like it should be impossible! The reason it is not impossible is that the pieces are what is termed

unmeasurable. Essentially what this means is that it is not possible to assign a volume to these sets of points. This is not the same as saying that the pieces have zero volume. Instead, it means that if you assigned them any volume, a contradiction would result.The area of mathematics which studies which sets can be assigned “volume” is known as measure theory, measures being a generalization of the notion of volume or area. A good place to start if you are interested in the Banach-Tarski paradox would be the construction of a Vitali set. Giuseppe Vitali showed that it is possible to construct a set of real numbers which is not

Lebesgue measurable. Lebesgue measure has a technical definition but conforms to what you would expect to be the length of “nice” sets. For example, any interval $[a,b]$ has Lebesgue measuer $b – a$. In higher dimensions, Lebesgue measure matches the geometric definitions of area and volume. While Vitali’s argument is not prerequisite per se for the proof of the Banach-Tarski paradox, it is a good place to build an understanding of nonmeasurable sets.To get back to the main point of this comment, it is misleading to say that ZFC results in paradoxes. Although we do not have a proof that ZFC is free of logical inconsistencies (cf. Goedel’s second incompleteness theorem), near universal opinion among mathematicians is that ZFC is consistent. Presenting the Banach-Tarski paradox as similar to Russell’s paradox ignores the very real differences between them. Russell’s paradox (and other paradoxes of naive set theory) were considered serious problems because logical contradictions in a theory make it useless and boring. Anything is provable from a logical contradiction (caveat: in classical logic—there are logics in which this is not true). Both the Banach-Tarski and Russell’s paradox present us with something that contradicts our intution. In the case of Banach-Tarski, our intuition is wrong. In the case of Russell’s paradox, the theory (naive set theory) is wrong (or at least inconsistent).

LikeLike

Yes, I’m well aware of the details of measure theory and of the difference between these two kinds of “paradoxes.” This was simply a misuse of the word in two meanings. That being said, there is a way to describe the BT paradox as a “paradox” in the classical sense. It involves laying down some reasonable axioms about volume being translation and rotation-preserving, etc., and concluding that the BT construction is still valid and hence no such system can be consistent. I believe I was thinking of this formulation when I had originally written this post.

But your clarification is more than ample to entice any readers interested in knowing more.

LikeLike

Thanks for these primers; They are motivating me to spend more time studying math. You have a typo: Colloquially, functions ‘accept’ a value form S and output something in R. (Form should be from.)

LikeLike

Great page! A couple of very minor points:

– Your definition of the rationals Q would be better if it used q \in N, since allowing q to be in Z means it can be 0, and no rational number has 0 as denominator.

– When you say “Note these fractions are not necessarily in lowest terms, so some blue dots correspond to more than one rational number”, I think what you really mean is “Note these fractions are not necessarily in lowest terms, so some rational numbers correspond to more than one blue dot”.

LikeLike

Thanks for the great intro to sets. For a newbie like myself something that’s not apparently obvious is the part where you make the |N| = |Z| demonstration, how’d you go from f(1), f(2), f(3) to the functions described afterwards?

LikeLike

There’s nothing tricky going on here, except perhaps in how I wrote the function in general. If you had to come up with a systematic way of pairing positive integers with all integers, you’d probably do it something like this: match up 1 -> 0, 2 -> 1, 3 -> -1, 4 -> 2, 5 -> -2, 6 -> 3, 7 -> -3, … In this way each even natural number is paired up with a positive integer, and each odd natural number is paired up with a negative integer (or zero). How can I describe this more compactly? Well even natural numbers can be written as 2 times a natural number, 2k, and odds as twice a natural number plus one (or minus one, if you prefer), 2k+1. The even numbers are just halving when we match them to positive integers, and the odds are subtracting one, halving, and taking a negative. So then I can describe the pairing as f(2k) = k, f(2k+1) = k, and f(0) = 0.

LikeLike

Great recap of the sets notation! Can you advice how to define a random subset? Something like this: S={x in D | Random() > 0.5}. If there more elegant and clear notation for this purpose, which preferably limits the cardinality of a new set? For example: let set S contain ‘n’ elements randomly drawn from set D. Thanks!

LikeLike

What you’re looking for is called a sample from a distribution. Unfortunately the ability to call a *thing* random is not really a definable term. For what does it mean for a “thing” to be random? (for more on ways to overcome this, see Kolmogorov Complexity). That being said, I don’t know if there is a way to “define” a sample via set theory. You can define a probability distribution for, say, n coin flips. Or more generally for n independent random variables distributed however you choose. But these aren’t considered sets.

LikeLike