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 colletion of objects.
Mathematically, you can define a set by
Example: Imagine we define
If
If
Set
Do note that this particular definition doesn't require
To avoid any confusion regarding whether
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.
So 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,...
Do note that a universal set can have an infinite number of elements, for example, the set of all real numbers!
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!
<img src="union.png",width=250,height=250>
The intersection of two sets
Applied to our example, the intersection of
In mathematical terms, the union of
<img src="intersection.png",width=250,height=250>
If we 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
<img src="rel_comp.png",width=250,height=250>
There is another definition of the complement when we consider 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
<img src="abs_comp.png",width=250,height=250>
Note that if we 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 we have a third set
<img src="venn_diag.png",width=350,height=350>
When there are no elements in a certain set, we say that the 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
In this section, we started off explaining what sets, subsets and universal sets are. Next, you learned about some elementary such as unions, intersections and complements. After that, we tied all this info together through the inclusion exclusion principle. Finally we talked a little bit about how sets work in Python.