You have definitely heard of sets before. In this section, however, you will learn about the formal definition of sets, which will serve as a foundation for everything related to probability and combinatorics!
You will be able to:
- Define a set in the context of probability theory
- Define a universal set and subsets
- Describe the process of making unions, intersections, and complements
- Use Venn Diagrams to visually demonstrate set operations
- Describe the inclusion-exclusion principle
In probability theory, a set is defined as a well-defined collection of objects.
Mathematically, you can denote a set by
Example: If
-
If
$x = 2$ ,$x\in S$ because$x$ is an even number. -
If
$x = 9$ ,$x\notin S$ because$x$ is not an even number.
Set
Typically, you'll be more interested in proper subsets. All proper subsets are subsets. The only difference between subsets and proper subsets is that a subset can technically be the entire set. In other words, if A = {1,2,3} and B = {1,2,3} A is subset of B. If C = {1,2} then C is both a subset and proper subset of A. C is also a subset and proper subset of B. The mathematical notation for proper subsets is : $ C \subset A $
Example: If S is the set of even numbers, set
The collection of all possible outcomes in a certain context or universe is called the universal set.
A universal set is often denoted by
Example of a universal set: All the possible outcomes when rolling a dice.
Remember that a universal set is not necessarily all the possible things that have ever existed. Typically, a universal set is just all the possible elements within certain bounds, e.g., the set of all countries in the world, the set of all the animal species in the Bronx Zoo, etc.
A universal set can have an infinite number of elements, for example, the set of all real numbers!
Next, let's talk about set operations. Imagine you have two sets of numbers, say the first 4 multiples of 3 in set
$ S = {3,6,9,12}$
and the first 4 multiples of 2 in set
$ T = {2,4,6,8} $.
The union of two sets
Applied to our example, the union of
In mathematical terms, the union of
A popular way to represent sets and their relationships is through Venn Diagrams, (https://en.wikipedia.org/wiki/Venn_diagram), see picture below!
The intersection of two sets
Applied to our example, the intersection of
In mathematical terms, the intersection of
If you have S and T, the relative complement of S contains all the elements of T that are NOT in S. This is also sometimes referred to as the difference. The difference is denoted by $ T\backslash S $ or
In this case, the relative complement of S (or $ T\backslash S
There is another definition of the complement when considering universal sets
The absolute complement of
Note how the definition of
Mathematically, the absolute complement of
Let's reconsider
Let's define
The absolute complement of
Note that if you want to know how many elements are in set
In combinational mathematics, the inclusion-exclusion principle is a counting technique that solves this problem.
When having two sets, the method for counting the number of elements in the union of two finite sets is given by:
where the horizontal lines denote the cardinality of a set, which is the number of elements in the set, considering a set with a finite number of elements.
The formula expresses the fact that the sum of the sizes of the two sets may be too large since some elements may be counted twice. For the double-counted elements, one is subtracted again.
This formula can be extended to three sets, four sets, etc. For example, imagine you have a third set
When there are no elements in a certain set, this set is empty, denoted by
Some things to bear in mind when working with sets in Python:
- Sets are unordered collections of unique elements.
- Sets are iterable.
- Sets are collections of lower level python objects (just like lists or dictionaries).
Documentation for sets in Python can be found here: Sets
To put this all together, let's consider an example with restaurants:
Think about a set A with all the restaurants that serve Italian food. Next, there is a set B with all the restaurants that serve burgers.
The union of these sets, set C, contains the set of restaurants that either serve Italian food, burgers or both.
You could say that the universal set here, set U, contains all the restaurants in the world (with any type of food). Then set C is a subset of set U.
The intersection of A and B contains the restaurants that serve both Italian food and burgers.
The relative complement of set A contains the restaurants that serve burgers but not Italian food.
The absolute complement of set A contains the restaurants that serve any food but no Italian food.
In this section, you learned about sets, subsets, and universal sets. Next, you were introduced to some elementary set operations such as unions, intersections, and complements. After that, all this information was tied together through the inclusion-exclusion principle. Next, you saw how sets translate into Python. You'll start exploring this in further detail in the next lab!