<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Free Chapters | Coders' Compass Publishing</title><link>https://coderscompass.org/free-chapters/</link><description>Free chapters from books published by Coders' Compass — sample any book before you buy.</description><language>en-gb</language><copyright>Coders' Compass Publishing</copyright><generator>Hugo -- gohugo.io</generator><lastBuildDate>Fri, 27 Mar 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://coderscompass.org/free-chapters/index.xml" rel="self" type="application/rss+xml"/><item><title>Representation of Sets: Set Builder Notation and Venn Diagrams</title><link>https://coderscompass.org/books/set-theory-for-beginners/representation-of-sets/</link><guid isPermaLink="true">https://coderscompass.org/books/set-theory-for-beginners/representation-of-sets/</guid><pubDate>Fri, 27 Mar 2026 00:00:00 +0000</pubDate><dc:creator>Subhomoy Haldar</dc:creator><description>Free chapter from Set Theory for Beginners. Learn roster form, set builder notation, and Venn diagrams with clear, practical examples for developers.</description><content:encoded>&lt;blockquote style="text-align: right; margin-bottom: 4rem;">
&lt;p>
&lt;strong>To new concepts correspond, necessarily, new signs.&lt;/strong> These we choose in such a way that they remind us of the phenomena which were the occasion for the formation of the new concepts.
&lt;/p>
&lt;footer>
&amp;mdash; David Hilbert, &lt;em>Mathematical Problems&lt;/em> (1900)
&lt;/footer>
&lt;/blockquote>
&lt;blockquote style="text-align: right; margin-bottom: 4rem;">
&lt;p>
By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and in effect increases... mental power... Probably nothing in the modern world would have more astonished a Greek mathematician than to learn that, under the influence of compulsory education, the whole population of Western Europe, from the highest to the lowest, could perform the operation of division for the largest numbers. This fact would have seemed to him a sheer impossibility.
&lt;/p>
&lt;footer>
&amp;mdash; Alfred North Whitehead, &lt;em>An Introduction to Mathematics&lt;/em> (1911) Ch. 5, p. 59.
&lt;/footer>
&lt;/blockquote>
&lt;h2 id="introduction">Introduction&lt;/h2>
&lt;p>We know what sets are and how they can be useful. In this chapter, we will discuss the various ways we can represent sets. We will start with the most basic form of representation and move on to more complex forms. We will also discuss the importance of each form and when to use them.&lt;/p>
&lt;h2 id="roster-and-descriptive-notations">Roster and Descriptive Notations&lt;/h2>
&lt;p>We can list all the items in a set to define it. We call it the &lt;em>roster form&lt;/em>. A few sets in this form with their descriptions are:&lt;/p>
&lt;p>$$A = \{1, 2, 3, 4, 5\}$$&lt;/p>
&lt;p>A set of the first five natural numbers starting from &lt;strong>1&lt;/strong>.&lt;/p>
&lt;p>$$B = \{\text{tree}, \text{pebble}, \text{shrub}, \text{flower}\}$$&lt;/p>
&lt;p>A set of things you would spot in nature.&lt;/p>
&lt;p>$$C = \{♣, ♦, ♥, ♠\}$$&lt;/p>
&lt;p>Set of playing card suits.&lt;/p>
&lt;p>$$D = \{1, 2, 3, 4, 5, 6, \ldots\}$$&lt;/p>
&lt;p>An infinite set of all the natural numbers starting from &lt;strong>1&lt;/strong>. Note that theoretically, sets can be infinite. We never need to list all the members of an infinite set. We just need to know a few of them, enough to notice the trend indicated. In almost all situations that need infinite sets, we need the idea that binds the elements together, not the actual elements themselves. There are more examples of infinite sets in the &lt;a href="https://coderscompass.org/books/set-theory-for-beginners/">&lt;em>Cardinality&lt;/em>&lt;/a> section of the full book.&lt;/p>
&lt;h2 id="set-builder-notation">Set Builder Notation&lt;/h2>
&lt;p>The roster form becomes impractical when we want to convey a non-trivial relationship between the members and simply listing some members might not be enough. An obvious solution here would be to use the description we want to define the set. If we use words, we call it a &lt;strong>descriptive definition&lt;/strong> of the set. If we use a Boolean predicate defined using mathematical notation and symbols, we call it the &lt;strong>set builder notation&lt;/strong>.&lt;/p>
&lt;p>We&amp;rsquo;ve discussed predicates in a &lt;a href="https://coderscompass.org/books/set-theory-for-beginners/">previous chapter&lt;/a>. They are mathematical expressions that evaluate to either true or false. By applying these predicates to potential members of a set, we can determine if they belong or not. We call these predicates &lt;strong>membership conditions&lt;/strong>.&lt;/p>
&lt;p>Previously, we have seen descriptive definitions next to the roster forms. Here are some more next to examples of set builder notation using predicates:&lt;/p>
&lt;p>$$E = \{x \mid x \text{ is even}\}$$&lt;/p>
&lt;p>This is a set of all elements that are even. We assume that all elements in this context are numbers. Note the syntax being used. The element belonging to the set is identified by the variable &lt;strong>x&lt;/strong>. We allow &lt;strong>x&lt;/strong> to be a member of the set only if the condition &amp;ldquo;x is even&amp;rdquo; is satisfied.&lt;/p>
&lt;p>$$F = \{a \mid a \text{ is prime} \land a &amp;lt; 10\}$$&lt;/p>
&lt;p>Set of all integers which are prime, and they are less than 10. See how we can be very specific in our description by connecting smaller logical expressions or predicates into larger ones?&lt;/p>
&lt;p>$$G = \{z \mid 1 &amp;lt; z \leq 3\}$$&lt;/p>
&lt;p>Set of all real numbers - which can be represented on the number line - between 1 (excluding it) and 3 (including it). In disciplines such as calculus and algebra, we use these types of sets often. To make it convenient, we use a shorthand &lt;strong>interval notation&lt;/strong>.&lt;/p>
&lt;p>This set would be represented in interval notation as &lt;strong>(1, 3]&lt;/strong>. The parenthesis indicates that the set is &amp;ldquo;open&amp;rdquo; on the left-hand side (with the smaller number) and the square bracket represents the set is &amp;ldquo;closed&amp;rdquo; on the right-hand side (with the larger number). When one side of the interval is open, the number is &lt;em>excluded&lt;/em>. The endpoint number is &lt;em>included&lt;/em> if the interval is closed. Another property we could assign this set is being &amp;ldquo;half-open&amp;rdquo;. Can you figure out what being (fully) open and (fully) closed means in terms of intervals?&lt;/p>
&lt;p>You might find other textual ways to represent sets, but in essence, they will be derived from one of these three basic methods discussed above.&lt;/p>
&lt;h2 id="venn-diagrams">Venn Diagrams&lt;/h2>
&lt;p>You might not always want to extract information about sets from staring at a wall of text or a cryptic mathematical expression. If you have two or more sets, the relationship between them might not be immediately obvious. Let us take the following sets &lt;strong>A&lt;/strong> and &lt;strong>B&lt;/strong>:&lt;/p>
&lt;p>$$A = \{1, 2, 3, 4, 5, 6\}$$&lt;/p>
&lt;p>and&lt;/p>
&lt;p>$$B = \{2, 3, 5, 7, 11\}$$&lt;/p>
&lt;p>What elements do they have in common? &lt;strong>2&lt;/strong> is common because it belongs to both &lt;strong>A&lt;/strong> and &lt;strong>B&lt;/strong>. So is &lt;strong>3&lt;/strong>. But what about the others? It is not clear from an immediate inspection. The readers need to do some additional work to convert &lt;strong>B&lt;/strong> to its roster form, then identify the common elements.&lt;/p>
&lt;p>Now consider the representation of the same sets using a Venn diagram:&lt;/p>
&lt;p>&lt;img src="https://coderscompass.org/images/books/set-theory-for-beginners/ch3/venn_diagram_introduction.webp" alt="Venn diagram of sets A and B" decoding="async">
&lt;/p>
&lt;p>The ellipse with &lt;strong>A&lt;/strong> next to it represents the bounds of the set &lt;strong>A&lt;/strong>. Set &lt;strong>B&lt;/strong> has a similar representation. The region where they overlap shows the elements they have in common. We will see later that this region is known as the &lt;a href="https://coderscompass.org/books/set-theory-for-beginners/">&lt;em>intersection&lt;/em>&lt;/a> of sets &lt;strong>A&lt;/strong> and &lt;strong>B&lt;/strong>.&lt;/p>
&lt;h2 id="chapter-summary">Chapter Summary&lt;/h2>
&lt;p>Sets are important in mathematics and related fields. They are the simplest potential building blocks of more complex structures. However, they can be a bit too abstract and unintuitive if we do not have any relatable examples. To explain the examples and show the various properties we wish to highlight, we need different ways to represent sets.&lt;/p>
&lt;p>In this chapter, we looked at the simplest ways first: roster form - where we list all the elements of a set, and descriptive notation - where we describe the set using words. We then moved on to set builder notation, where we use a logical membership condition to define the set. Finally, we discussed Venn diagrams, which are graphical representations of two or more sets and their relationships.&lt;/p>
&lt;p>This is the end of Chapter 1.3. The book continues with chapters on special sets, operations on sets, and much more. &lt;a href="https://coderscompass.org/books/set-theory-for-beginners/">Get the full book&lt;/a> to continue your set theory journey.&lt;/p></content:encoded><category>set-theory</category><category>mathematics</category><category>beginners</category><category>programming</category></item><item><title>What Are Sets? An Introduction to Set Theory</title><link>https://coderscompass.org/books/set-theory-for-beginners/what-are-sets/</link><guid isPermaLink="true">https://coderscompass.org/books/set-theory-for-beginners/what-are-sets/</guid><pubDate>Sat, 21 Mar 2026 00:00:00 +0000</pubDate><dc:creator>Subhomoy Haldar</dc:creator><description>Free chapter from Set Theory for Beginners. Learn what sets are, why uniqueness and order matter, and how set theory helps everyday programming.</description><content:encoded>&lt;blockquote style="text-align: right; margin-bottom: 4rem;">
&lt;p>
[A]ll science as it grows towards perfection becomes mathematical in its ideas.
&lt;/p>
&lt;footer>
&amp;mdash; Alfred North Whitehead, &lt;em>"An Introduction to Mathematics"&lt;/em> (1911) Ch.1, p. 14.
&lt;/footer>
&lt;/blockquote>
&lt;blockquote style="text-align: right; margin-bottom: 4rem;">
&lt;p>
The lowest steps of the ladder are as useful as the highest.
&lt;/p>
&lt;footer>
&amp;mdash; Augustus De Morgan, On the Study and Difficulties of Mathematics (1831), Ch. I.
&lt;/footer>
&lt;/blockquote>
&lt;blockquote style="text-align: right; margin-bottom: 4rem;">
&lt;p>
The moving power of mathematical invention is not reasoning, but imagination.
&lt;/p>
&lt;footer>
&amp;mdash; Augustus De Morgan, quoted in Robert Perceval Graves, &lt;em>The Life of Sir William Rowan Hamilton&lt;/em>, Vol. 3 (1889), p. 219.
&lt;/footer>
&lt;/blockquote>
&lt;h2 id="introduction">Introduction&lt;/h2>
&lt;p>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.&lt;/p>
&lt;p>Let us start with a few examples of collections that we can imagine:&lt;/p>
&lt;ol>
&lt;li>A deck of playing cards.&lt;/li>
&lt;li>The letters in the English alphabet.&lt;/li>
&lt;li>All whole numbers like 1, 15, 1,000,000, and so on.&lt;/li>
&lt;li>All points which are between two endpoints of a continuous line segment.&lt;/li>
&lt;li>Individual grains of sand on the earth.&lt;/li>
&lt;/ol>
&lt;p>These have one thing in common - they are &lt;em>sets&lt;/em>. Note that examples 1 and 2 are obviously finite.&lt;/p>
&lt;p>You may find it hard to believe, but example 5 is also an example of a finite set. See &lt;a href="https://www.npr.org/sections/krulwich/2012/09/17/161096233/which-is-greater-the-number-of-sand-grains-on-earth-or-stars-in-the-sky">Which Is Greater, The Number Of Sand Grains On Earth Or Stars In The Sky? - NPR&lt;/a>&lt;sup>28&lt;/sup>. 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 &lt;a href="https://coderscompass.org/books/set-theory-for-beginners/">&lt;em>Cardinality&lt;/em>&lt;/a> section of the full book: some infinities are bigger than others.&lt;/p>
&lt;p>We will now describe what exactly we mean by a &lt;em>set&lt;/em> in mathematical terms, with full generality.&lt;/p>
&lt;h2 id="definition">Definition&lt;/h2>
&lt;blockquote>
&lt;p>&lt;strong>&lt;em>A set is an unordered collection of unique arbitrary objects.&lt;/em>&lt;/strong>&lt;/p>
&lt;/blockquote>
&lt;p>In symbolic notation, we usually represent a set with a capital letter and list its assigned contents using curly braces.&lt;/p>
&lt;p>$$A = \{1, 2, 3, \ldots\}$$&lt;/p>
&lt;p>Let us look at the words used in the definition in more detail:&lt;/p>
&lt;h3 id="arbitrary-objects">Arbitrary Objects&lt;/h3>
&lt;p>&lt;img src="https://coderscompass.org/images/books/set-theory-for-beginners/ch1/arbitrary_objects.webp" alt="Figure 2: Elements of a set can be of arbitrary type." decoding="async">
&lt;/p>
&lt;p>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.&lt;/p>
&lt;p>$$S = \{\text{triangle}, \text{circle}, \text{square}\}$$&lt;/p>
&lt;h3 id="unique">Unique&lt;/h3>
&lt;p>&lt;img src="https://coderscompass.org/images/books/set-theory-for-beginners/ch1/unique_members.webp" alt="Figure 4: All members of a set are unique." loading="lazy" decoding="async">
&lt;/p>
&lt;p>All members of a set need to be unique. We cannot have the same item twice. In the set &lt;strong>S&lt;/strong> defined above, we have each shape appear only once.&lt;/p>
&lt;p>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 &lt;em>&amp;ldquo;triangle&amp;rdquo;&lt;/em> to the set &lt;strong>S&lt;/strong> will not change the set.&lt;/p>
&lt;h3 id="collection">Collection&lt;/h3>
&lt;p>&lt;img src="https://coderscompass.org/images/books/set-theory-for-beginners/ch1/collection_or_grouping.webp" alt="Figure 5: A set is a collection of elements." loading="lazy" decoding="async">
&lt;/p>
&lt;p>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 &lt;strong>M&lt;/strong> has elements who share the property of “being a mammal”.&lt;/p>
&lt;p>$$M = \{\text{lion}, \text{tiger}, \text{elephant}\}$$&lt;/p>
&lt;h3 id="unordered">Unordered&lt;/h3>
&lt;p>&lt;img src="https://coderscompass.org/images/books/set-theory-for-beginners/ch1/unordered.webp" alt="Figure 7: The order of elements in a set does not matter." loading="lazy" decoding="async">
&lt;/p>
&lt;p>In a regular set, we do not care about the order in which we present the members. Consider a set of numbers &lt;strong>N&lt;/strong>.&lt;/p>
&lt;p>$$N = \{1, 2, 3\}$$&lt;/p>
&lt;p>We can write the same set in a different order, and it will still be the same set.&lt;/p>
&lt;p>$$N = \{3, 1, 2\} = \{1, 2, 3\}$$&lt;/p>
&lt;p>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.&lt;/p>
&lt;h2 id="why-should-we-care-about-sets">Why Should We Care About Sets?&lt;/h2>
&lt;p>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.&lt;/p>
&lt;p>$$\text{Sets} : \text{Devs} :: \text{Transmission} : \text{Drivers}$$&lt;/p>
&lt;p>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.&lt;/p>
&lt;h3 id="organising-information-better">Organising Information Better&lt;/h3>
&lt;p>&lt;img src="https://coderscompass.org/images/books/set-theory-for-beginners/ch1/organising_information_better.webp" alt="Figure 11: Sets help us organise all available information and make it more manageable." loading="lazy" decoding="async">
&lt;/p>
&lt;p>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.&lt;/p>
&lt;p>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).&lt;/p>
&lt;p>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.&lt;/p>
&lt;h3 id="avoiding-duplicates">Avoiding Duplicates&lt;/h3>
&lt;p>&lt;img src="https://coderscompass.org/images/books/set-theory-for-beginners/ch1/avoiding_duplicates.webp" alt="Figure 12: Sets help us avoid duplicates." loading="lazy" decoding="async">
&lt;/p>
&lt;p>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.&lt;/p>
&lt;p>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.&lt;/p>
&lt;h3 id="combining-and-filtering-data">Combining and Filtering Data&lt;/h3>
&lt;p>&lt;img src="https://coderscompass.org/images/books/set-theory-for-beginners/ch1/combining_and_filtering_data.webp" alt="Figure 13: Sets help us combine and filter data effectively." loading="lazy" decoding="async">
&lt;/p>
&lt;p>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.&lt;/p>
&lt;p>This list of users can be obtained using a basic set operation called a &lt;a href="https://coderscompass.org/books/set-theory-for-beginners/">&lt;em>difference&lt;/em>&lt;/a>, covered in the full book.&lt;/p>
&lt;h3 id="making-decisions">Making Decisions&lt;/h3>
&lt;p>&lt;img src="https://coderscompass.org/images/books/set-theory-for-beginners/ch1/deciding.webp" alt="Figure 14: Sets help us make decisions." loading="lazy" decoding="async">
&lt;/p>
&lt;p>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).&lt;/p>
&lt;p>The result we want is a smaller list of places that are present in both sets. We call this operation an &lt;em>intersection&lt;/em> and will discuss it in more detail in the &lt;a href="https://coderscompass.org/books/set-theory-for-beginners/">&lt;em>Union and Intersection&lt;/em>&lt;/a> section of the full book.&lt;/p>
&lt;h3 id="step-by-step-problem-solving">Step-by-Step Problem-Solving&lt;/h3>
&lt;p>&lt;img src="https://coderscompass.org/images/books/set-theory-for-beginners/ch1/step-by-step.webp" alt="Figure 15: Sets help us solve problems step-by-step." loading="lazy" decoding="async">
&lt;/p>
&lt;p>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.&lt;/p>
&lt;p>For example, to find a list of the top ten (10) selling items in our store, we need to do the following:&lt;/p>
&lt;ol>
&lt;li>Look at sales and orders. From there, we tally up items with their sale counts.&lt;/li>
&lt;li>Next, we (partially) sort the item-count pairs in the descending order of sales.&lt;/li>
&lt;li>Finally, we select the top ten items from the (partially) sorted list.&lt;/li>
&lt;/ol>
&lt;p>All these atomic steps, including being able to identify them, require implicit knowledge of set theory and other principles of discrete mathematics.&lt;/p>
&lt;p>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.&lt;/p>
&lt;h2 id="chapter-summary">Chapter Summary&lt;/h2>
&lt;p>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.&lt;/p>
&lt;p>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.&lt;/p>
&lt;p>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. &lt;a href="https://coderscompass.org/books/set-theory-for-beginners/">Get the full book&lt;/a> to continue your set theory journey.&lt;/p></content:encoded><category>set-theory</category><category>mathematics</category><category>beginners</category><category>programming</category></item></channel></rss>