You have definitely heard of sets before. In this section, however, you will learn about a formal definition of sets, which will serve as a foundation for everything related to probability and combinatorics!
You will be able to:
- Understand what a set is
- Define a universal set and subsets
- Learn about sets unions, intersections, complements
- Learn how to use Venn Diagrams to understand about the relationships between sets
In probability theory, a set is denoted as a well-defined collection of objects.
Mathematically, you can define a set by
Example: If
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,...
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 2 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 component 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 solve this problem.
When having 2 sets, the method for obtaining 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, considering a finite set.
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 substracted again.
This formula can be extended to three sets, four sets, etc. 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).
documentations can be found here: https://docs.python.org/2/library/sets.html
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 info 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!