Introduction to Sets
Introduction
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!
Objectives
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
What is a set?
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
Subsets
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
Universal sets
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!
Elementary set operations
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} $.
a) Union of two sets
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>
b) Intersection of Two sets
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>
c) Relative complement or the difference
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>
d) Absolute complement
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>
Inclusion Exclusion principle
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>
Empty sets
When there are no elements in a certain set, we say that the set is empty, denoted by
Sets in Python
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
Summary
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.