What Are Sets? An Introduction to Set Theory

Free chapter from Set Theory for Beginners. Learn what sets are, why uniqueness and order matter, and how set theory helps everyday programming. | Preview Image | Coders' Compass Publishing
Free chapter from Set Theory for Beginners. Learn what sets are, why uniqueness and order matter, and how set theory helps everyday programming.

[A]ll science as it grows towards perfection becomes mathematical in its ideas.

— Alfred North Whitehead, "An Introduction to Mathematics" (1911) Ch.1, p. 14.

The lowest steps of the ladder are as useful as the highest.

— Augustus De Morgan, On the Study and Difficulties of Mathematics (1831), Ch. I.

The moving power of mathematical invention is not reasoning, but imagination.

— Augustus De Morgan, quoted in Robert Perceval Graves, The Life of Sir William Rowan Hamilton, Vol. 3 (1889), p. 219.

Introduction

In order to get you to care about sets, we need to do a couple of things. First, we need to describe what a set is. Once you have a rough idea, we can work on figuring out why learning about sets and their theory is useful.

Let us start with a few examples of collections that we can imagine:

  1. A deck of playing cards.
  2. The letters in the English alphabet.
  3. All whole numbers like 1, 15, 1,000,000, and so on.
  4. All points which are between two endpoints of a continuous line segment.
  5. Individual grains of sand on the earth.

These have one thing in common - they are sets. Note that examples 1 and 2 are obviously finite.

You may find it hard to believe, but example 5 is also an example of a finite set. See Which Is Greater, The Number Of Sand Grains On Earth Or Stars In The Sky? - NPR28. Examples 3 and 4 are infinite sets. You might be inclined to think they are both the same size, but that is not true! We will come to know in the Cardinality section of the full book: some infinities are bigger than others.

We will now describe what exactly we mean by a set in mathematical terms, with full generality.

Definition

A set is an unordered collection of unique arbitrary objects.

In symbolic notation, we usually represent a set with a capital letter and list its assigned contents using curly braces.

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

Let us look at the words used in the definition in more detail:

Arbitrary Objects

Figure 2: Elements of a set can be of arbitrary type.

Sets can be made from anything you can imagine and identify. It can be numbers, shapes, points, names, certain other sets, etc. For example, the following set has three members or elements, each of which is a shape.

$$S = \{\text{triangle}, \text{circle}, \text{square}\}$$

Unique

Figure 4: All members of a set are unique.

All members of a set need to be unique. We cannot have the same item twice. In the set S defined above, we have each shape appear only once.

If we repeat a shape, the number of elements in the set remains the same because we have not added a new unique member. Trying to add “triangle” to the set S will not change the set.

Collection

Figure 5: A set is a collection of elements.

Sets contain zero or more members. A set is a collection in the sense that we group some items together based on a shared property among all its members. For example, the following set of mammal species M has elements who share the property of “being a mammal”.

$$M = \{\text{lion}, \text{tiger}, \text{elephant}\}$$

Unordered

Figure 7: The order of elements in a set does not matter.

In a regular set, we do not care about the order in which we present the members. Consider a set of numbers N.

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

We can write the same set in a different order, and it will still be the same set.

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

Both are representations of the same set of three integers. It is like checking items off a to-do list. It does not matter what order you do the tasks in, as long as you do them all.

Why Should We Care About Sets?

The concept of Set Theory to developers is like knowing about the transmission system of a car to a driver. You do not need to know how it works to drive a car, but knowing about it can help you understand how the car works and how to maintain it. Similarly, knowing about sets can help you understand how logical fields like mathematics, computer science, and data science work.

$$\text{Sets} : \text{Devs} :: \text{Transmission} : \text{Drivers}$$

Not just developers but people from other professions, like scientists, statisticians, doctors often need to understand and analyse the problems they are trying to solve with well-defined procedures. Knowing about sets and their basic theory (properties like member uniqueness, operations like unions and intersections, etc.) can improve how we make use of problem-solving techniques. Here are some reasons why learning set theory is beneficial.

Organising Information Better

Figure 11: Sets help us organise all available information and make it more manageable.

If we have too much information in front of us at once, we usually get overwhelmed and do not know what to do. If we organise a bit, we can make the steps that follow afterwards more intuitive.

Consider the case where we want customers of our store or users of our website to upload a profile picture. When we allow them to use a file-picker, we want only image files. Other file types are irrelevant to us (and potentially dangerous, from the viewpoint of security).

Similarly, if we ask a search engine for the nutritional information of an apple, we want to look at web pages that only contain information about apples, not oranges or bananas.

Avoiding Duplicates

Figure 12: Sets help us avoid duplicates.

When we process a list of information (like a list of users, products, or transactions), we can make a lot of very useful assumptions if we do not have duplicates. In case we are searching for a specific item, like a user or a product, we can stop searching once we find it. We can do this because we know that there are no duplicates down the line.

This is a very helpful property of sets that we can use to our advantage, especially when we are dealing with large amounts of data.

Combining and Filtering Data

Figure 13: Sets help us combine and filter data effectively.

Suppose we already have a list of people signed up to our mailing list. We also have a list of customers who have purchased something from our store. We want to run a discount for new customers who have signed up to our mailing list but have not purchased anything yet.

This list of users can be obtained using a basic set operation called a difference, covered in the full book.

Making Decisions

Figure 14: Sets help us make decisions.

Imagine we are planning a trip for our holiday. We want to do a fair bit of sightseeing, but want to stay at an excellent hotel. When choosing holiday spots, we would select those that have a fair number of tourist attractions (one set), and those that have well-reviewed hotels (another set).

The result we want is a smaller list of places that are present in both sets. We call this operation an intersection and will discuss it in more detail in the Union and Intersection section of the full book.

Step-by-Step Problem-Solving

Figure 15: Sets help us solve problems step-by-step.

A common approach that mathematicians and people from relevant technical professions use is to break down a problem into smaller, more manageable parts. Once we have solved these smaller parts, we can combine them to solve the larger problem. An advantage of breaking problems into smaller parts is that we might encounter a type of problem that we have already solved before. Therefore, we can reuse the solution and save time. Set theory helps with both approaches.

For example, to find a list of the top ten (10) selling items in our store, we need to do the following:

  1. Look at sales and orders. From there, we tally up items with their sale counts.
  2. Next, we (partially) sort the item-count pairs in the descending order of sales.
  3. Finally, we select the top ten items from the (partially) sorted list.

All these atomic steps, including being able to identify them, require implicit knowledge of set theory and other principles of discrete mathematics.

Knowing set theory helps us go further than just solving problems. It enables us to look deeper and solve problems correctly (investigate all cases) and efficiently (save resources like time and money). If we understand and internalise these concepts, we become better at skilfully and thoughtfully approaching problems.

Chapter Summary

In this chapter, we introduced the concept of a set through some examples, its definition, and discussed the terms used in the definition. Sets can comprise any type of elements, and all members of a set must be unique. Sets are a collection or grouping of elements, and the order of elements in a set does not matter.

We have explored the importance of set theory in various fields. Sets help us organise information, avoid duplicates, combine and filter data, make decisions, and solve problems step-by-step.

This is the end of Chapter 1.1. The book continues with chapters on mathematical terms, representations of sets, operations on sets, and much more. Get the full book to continue your set theory journey.

Comments