Sets

We will cover the topics:

  • Defining Sets

  • Operations: Union, intersections, complement, set difference.

  • Venn Diagrams

  • Cardinality: Inclusion-Exclusion Principle

Defining Sets

For now, it is convenient to assume that there is a universe U of elements.

Set

A set is any collection of elements from a universe U.

The concept of a set is so basic in mathematics that it defies an easy definition. Most definitions just devolve to a set is a set :-).

Elements of a Set

The contents of a set are called its elements. For an element e, we say e in S if e belongs to the set S. The negation is written as mbox{NOT} (e in S) or often as e notin S.

There are two ways to define a set:

  • Explicitly: Just list out its elements. Eg., { A,E,I,O,U }.

  • Implicitly: Write a description of what belongs to the set in English or better still in Logic. Eg., { x in Alphabets | isVowel(x) }.

For now, whenever we are discussing sets, the universe U needs to be made clear.

Naive Set Theory

The notion of set theory that we are studying in this lecture is called naive set theory.

The reason, we call it naive is the assumption of the universal set U. Before the 20th century, mathematicians and philosophers imagined a collection mathbb{U} of all possible entities and called it the universal set. This set mathbb{U} has literally everything one can imagine: goats, ants, Higgs Bosons, tables, chairs, numbers, groups and all that. Think of it, and presto!, the universal set mathbb{U} has it. But the work of mathematicians such as Cantor and Bertrand Russell in the early 20th century proved that the universal set mathbb{U} cannot exist, since it existence leads to paradoxes or contradictions.

Nonexistence of the Universal Set

The universal set mathbb{U} containing everything does not exist.

Therefore, we will continue to describe a version in this notes that we will call informally ‘‘semi-naive’’ (Note that this is our own invention and not a standard term in mathematics). Wherever possible, we will note the changes needed due to the non-existence of an universal set.

Example 1: Integers

We assume that the universe is restricted the set of all integers mathbb{Z}.

What do the following sets define:

  • { x in mathbb{Z} |  (exists z) x = z^2 }.

    • All numbers that are perfect squares.

  • { x in mathbb{Z} | x  mod 2 = 0 }

    • All even numbers.

  • { x in mathbb{Z} | mathit{true} } .

    • All numbers in mathbb{Z}, since every number trivially satisfies the predicate mathit{true}.

  • { x in mathbb{Z} | mathit{false} } .

    • The empty set: since no number satisfies the predicate mathit{false}.

Note that restricting our universe to the set of integers, poses no contradiction or paradox in the definitions above.

Example 2: Animals

Let the universe U be all the animal species on planet earth.

  • { x in U | hasVertebrae(x) } defines all animals with vertebrae.

  • { Human, Monkey, Orang-Utan, Bonobo, ldots } describes all primates. Note the loose usage of ldots to signify and so on.

Note that restricting the universe to that of all animal species on the planet earth makes the sets above well defined and free of contradictions.

Empty/Universal Sets

Empty Set

The set with no elements is called the empty set. It is written { } or emptyset. We will use the latter.

Naive set theory often adds a special universal set mathbb{U}. As noted earlier, the universal set does not exist, and will need to be unlearned.

However, in many contexts, we will specifically name a set such as mathbb{R} (the set of all real numbers) to be a restricted universe. Since mathbb{R} is a well-defined set, it is fine to assume such a set as a restricted universe.

Union, Intersection, Difference and Complement.

Let A,B,C,ldots denote sets drawn from a restricted universe U.

  • Union: A cup B = { x in U | x in A mbox{OR} x in B }.

  • Intersection: A cap B = { xin U   | x in A mbox{AND} x in B }.

  • Set Difference: A - B (also written A setminus B ) = { x in U | x in A mbox{AND} x notin B }.

The operation of complementation is defined in naive set theory.

  • bar{A} = { x in U | x notin A }.

If we operate inside a restricted universe U, then bar{A}= U - A.

Otherwise, bar{A} does not exist, strictly speaking, because the universal set mathbb{U} containing everything does not exist.

Example 1

Let U be the restricted universe given by set of all integers mathbb{Z}.

Let O be the set of all odd integers, E be the set of all even integers, P be the set of all prime integers and C be the set of all composite numbers (0,1 are neither prime nor composite).

What are the sets?

  • O cup P

    • The set of numbers that are either odd or prime. We can write it as {pm 1, pm 2, pm 3, pm 5,pm 7,pm 9, pm 11,ldots, } (caution on using ldots).

  • O cup E

    • The set of all integers.

  • O cap E

    • The empty set.

  • O cap P

    • The set of all odd and prime numbers.

  • E cap P

    • The set { -2, 2} (we assume -2 is prime as well).

  • overline{O}= mathbb{Z} - O

    • The complement of the odd numbers is the set of even numbers.

  • overline{E} = mathbb{Z} - E

    • The complement of the even numbers is the set of odd numbers.

  • O - E

    • The set of all odd numbers since “subtracting” even numbers from odd, ends up removing nothing from the set.

  • E - O

    • The set of all even numbers since “subtracting” odd numbers ends up removing nothing from the set.

  • P - E

    • The set of all odd prime numbers.

  • P cap C

    • Empty set.

  • mathbb{N} - (P cup C)

    • The set {0,1} of neither prime nor composite numbers.

Example-2

Is A cup B the same as B cup A? What about A cap B?

  • In general, A cup B = B cup A but  A cup B is not necessarily the same as A cap B. As an example take A = {a,b,c} and B = emptyset. We have Acup B = A but A cap B = emptyset.

Is A - B the same as B -A? Give a simple example.

  • Not necessarily, Take A = {1,2,3} and B = {2,3,4}. We have A - B = {1} and B - A = {4}.

Finite Vs. Infinite Sets

Finite sets are those that have finitely many elements. Infinite sets, on the other hand, have infinitely many elements. We will define infinite sets and deal with infinite sets in a lot of detail soon.

Venn Diagrams

Venn Diagrams are easy diagrammatic ways of visualizing sets and operations between them. We assume that you already know a lot about these (this is high school material, really). We will do some quick recap in class.

On the other hand, Venn diagrams are nothing to sneeze at. The wikipedia article on Venn diagrams or this site has a lot of interesting information.

We can use Venn diagrams to prove certain properties of sets.

  •  C cap (A cup B) = (C cap A) cup (C cap B). (Distributivity Law #1)

  •  C cup (A cap B) = (C cup A) cap (C cup B). (Distributivity Law #2)

  •  A -  B = A - (A cap B).

Cardinality

The cardinality of a set is the number of elements in it. For now, it makes sense to talk of cardinality just for finite sets. We will discuss the issue of infinite sets and cardinality after we have covered relations and functions. The cardinality of the empty set is, of course, zero. The cardinality of a set can never be negative.

What is the cardinality of the following sets:

  • A: { x in Z | -10 leq x leq 10 } (Answer: 21).

  • B: { x in Z | -15 leq x < 0 } (Answer 15).

  • A cup B (Answer: 26)

  • A cap B? (Answer: 10)

  • B - A?

  • A - B?

The cardinality of a set A is denoted |A| or sometimes by c(A). We will use |A|.

Notice the following interesting fact: | A cup B | not= |A| + |B|. Why is this true?

Using a Venn diagram, we can derive that

 | A cup B| = |A| + |B| - | A cap B |

The relation above is called the inclusion exclusion principle.

We can extend it to three sets A,B,C:

 |A cup B cup C | = |A| + |B| + |C| - | A cap B| - | A cap C| - | B cap C| + |A cap B cap C|

Notice the curious sign change!!

Example-1

Let A = { 1 ,2,3,4,5} and B = {2,4,6,8,10}.

Verify the inclusion-exclusion principle for A cup B?

We see that |A cup B| = | { 1,2,3,4,5,6,8,10 } | = 8.

We can also see this using the inclusion exclusion principle:

 | A cup B| = |A| + |B| - | A cap B |  = 5 + 5 - 2 = 8  ,.

Example-2

If we look at all numbers from 1 to 99. How many numbers contain a 3?

Off the top of our head, this kind of calculation is tricky. We have 10 numbers with 3 in the second digit (3,13,23,ldots,93) and 10 numbers with a 3 in the first digit 30,ldots,39. Therefore, there are total of 20 numbers with a 3 in them. However, note that 33 has been counted twice. So the answer should be 19.

Using inclusion-exclusion: Let A be the set of all numbers with 3 in the seond digit and B be all numbers with 3 in the first (most-significant) digit. Our argument above is using the inclusion exclusion principle:

 |A cup B| = |A| + |B| - | A cap B|

Example -3

How many numbers between 1 and 10^5 are divisible by 2 or by 3 or by 5?

Let us fix the universe to be U = { 1.ldots,10^5-1 }.

Let A = { n in U | n mod 2 = 0 }. Similarly, let B be the numbers divisible by 3 and C be the numbers divisible by 5.

We seek |A cup B cup C| = |A| + |B| + |C| - | A cap B| - | A cap C| - |B cap C| + | A cap B cap C |.

We have

  • |A| = 10^5/2 = 50,000.

  • |B| = lfloor 10^5/3 rfloor = 33,333.

  • |C| = lfloor 10^5/5 rfloor  = 20,000.

  • |A cap B| =  | { n in U | n div 6 } | = lfloor 10^5 / 6 rfloor = 16,666

  • |B cap C| = lfloor 10^5/15 rfloor = 6,666

  • |C cap A| = lfloor 10^5/10 rfloor = 2000.

  • | A cap B cap C | = lfloor 10^5/30 rfloor = 3,333.

Overall |A cup B cup C| = |A| + |B| + |C| - | A cap B| - | A cap C| - |B cap C| + | A cap B cap C |=  50,000 + 33,333 + 20,000 - 16,666 - 6,666 - 2000 + 3,333 = 106,666 - 16,666 - 6,666 - 2000 = 81,333.

(I could be off in my calculations, please check).

General Inclusion Exclusion Principle

We have seen inclusion exclusion for cardinality of |A cup B cup C|. Suppose we have n > 0 sets A_1,ldots,A_n, we can generalize this to

 begin{array}{rcl} | A_1 cup A_2 cup ldots cup A_n | & = &  sum_{i=1}^n | A_i |  - sum_{1 leq i < j leq n} |A_i cap A_j| + sum_{1 leq i < j < k leq n} | A_i cap A_j cap A_k | -  cdots + (-1)^n | A_1 cap cdots cap A_n |  end{array}

Puzzle (Counting Prime Numbers)

Given a list of prime numbers from 1 to 10,000, show how the list can be used to count the number of primes from 1 to 10^8 using inclusion exclusion.

Let us try a simpler case of counting primes from 2..36. Instead of primes, we will count composites. Once we count composites, we can immediately conclude how many primes there are.

The universal set is N_{36} =2,ldots,36. Let us define the set C_k = { i in N_{36} | i mbox{divisible by} k } . We omit 1 since it is neither prime nor composite.

We take our seed set of prime numbers to be 2,3,5.

Theorem Every composite number from 1.. 36 is divisible by 2,3, or 5. In other words, every composite number 1 leq n leq 36 has 2,3 or 5 as one of their prime factor.

Proof

Proof is by contradiction. Let n be a composite number such that 1 leq n leq 36 and n does not have 2,3,5 as a prime factor. Therefore, n can be factored as a product of k geq 2 prime numbers n = p_1 p_2 ldots p_k, wherein, p_1 geq 7, p_2 geq 7, ldots, p_k geq 7. In other words, we conclude that n = p_1 p_2 ldots p_k geq p_1 p_2 geq 7 times 7 = 49. But we assumed that n leq 36, yielding a contradiction.

In other words, we will first count  N = |C_2 cup C_3 cup C_5| using the inclusion exclusion principle. This will give us the count of composites with a caveat. C_2 includes 2, 3 in C_3 and 5 in C_5. So whatever the cardinality of their union is, we need to subtract 3 from them to obtain numbers that are truly composite.

We write

 |C_2 cup C_3 cup C_5| = |C_2| + |C_3| + | C_5 | - | C_2 cap C_3 | - | C_2 cap C_5 | - | C_3 cap C_5| + | C_2 cap C_3 cap C_5|

We note that C_2 cap C_3 is just C_6. We know |C_6| = 6 because there are 36/6 numbers that are divisible by 6.

Therefore,

 |C_2 cup C_3 cup C_5| = |C_2| + |C_3| + | C_5 | - | C_2 cap C_3 | - | C_2 cap C_5 | - | C_3 cap C_5| + | C_2 cap C_3 cap C_5| = 18 + 12 + 7 - 6 - 3 - 2 + 1  = 27

The number of composites is therefore 27 - 3 = 24 (why did we subtract 3?) The number of primes will be 35-24 = 11 (why from 35? why not 36 here?). Check that there are indeed 11 primes from 1 to 36: { 2,3,5,7,11,13,17,19,23,29,31 }.

The same calculation can be carried out for all primes upto 48. For that we get:

 | C_2 cup C_3 cup C_5| = 24 + 16 + 9 - 8 - 4 - 3 + 1 = 35

Using this, number of composites is 35 -3 = 32. Therefore, we conclude that 15 primes exist. The additional four primes beyond 36 are 37,41,43,47.

There is a very close connection between this way of counting and Eratosthenes Sieve for enumerating all primes. Therefore, inclusion-exclusion principle is often called the sieve principle.

As a fun exercise: implement a counter to solve the puzzle. You will definitely need to write a program rather than attempt this by hand.

Cartesian Products and Power Sets

We will now look at two other operations over sets:

  • Cartesian Products

  • Power Sets

Cartesian Product

Take sets A and B over some universe U. The Cartesian product of A,B is defined as

 A times B = { (a,b) | a in A, b in B }

In other words, we build the set of all 2-tuples (x,y) where the first component is from set A and second component is from set B.

We can extend Cartesian product to more than 2 sets:

 A times B times C = { (a,b,c) |  a in A, b in B, c in C }

Here we take Cartesian product of 3 sets and the resulting product is a set of 3-tuples.

Example-1

If R is the set of all real numbers represented by the real line, what is the set R times R?

Answer: R times R consists of all tuples of reals of the form (x,y) where x and y are reals. In other words, we have moved from a single number to 2-dimensional co-ordinates.

For simplicity, the product of a set with itself R times R is written R^2.

What is R^3?

Example-2: Empty Set

What is the Cartesian product of the empty set emptyset with a set A?

Answer: The empty set.

Cardinality of Cartesian Products

The rule for Cartesian product is that

 | A times B | = |A| | B|

We can convince ourselves by drawing a table of all entries. Let us assume A = { 1,2 } and B = {a,b,c}.

a b c
1 (1,a) (1,b) (1,c)
2 (2,a) (2,b) (2,c)

Order of Cartesian Product Matters

If A not= B for sets A,B, we note that  A times B will not equal B times A. In other words, it matters in a tuple (a,b) that a comes first and b comes second. For example, if I asked you to draw a pixel at (1,3) it is not the same as drawing one at (3,1), right?

If A = B, however, it is trivial that A times B = B times A = A^2 = B^2 are all the same thing.

Example

What is the size of cartesian product |A times B times C| if  |A| = 5, |B| = 3, |C| = 2 ?

Subset

Set A is a subset of B written A subseteq B iff every element of A is also an element of B.

Examples

  •  { 1,2,3 } subseteq { 1,2,3,4 } ?

  •  {1,2,3} subseteq { 1,2 } ?

  • Is it true that A subseteq A for any set A?

  • Is it true that A subseteq emptyset for all sets A?

  • Is it true that emptyset subseteq A for all sets A?

Answers: yes, no, yes, no, yes!