# Sets

Definition: Set
A set is a collection of things. If is a set and is a thing, then is either in (written ) or not in (written ).

If we say that is an element of .

Two sets are equal if they contain the same set of things (see the definition of set equality for more details).

## examples

Here are some useful sets:

Sets can contain things other than numbers:

• Let be the set of people in the room

The defining feature of a set is that every object is unambiguously either in or not in . You don't need an algorithm for determining which is true. For example:

• Let be the set of Java programs that never crash

This is a perfectly good set (assuming you define "Java program" and "crash"), even though there is no algorithm to determine whether a given program crashes or not. It either does or it doesn't, we don't have to know which.

This is an example of a degenerate object. An informal definition of a set would be something that has things in it; the empty set has no things in it, so perhaps we should rule it out. But most proofs work just as well with special cases as they do for the general case, so by default we include the special cases. We do the same thing when we define subset below.

We can list (or enumerate) the elements of a set:

• denotes the set containing 1, 2, and 3 (and nothing else).

You can think of this as shorthand for the set comprehension .

Sometimes we include a $\dots$ in an enumerated set if its meaning is clear (such as in the definition of ). This can be formalized more carefully as an inductively defined set.

Sets can contain other sets:

• is a set containing two elements: the first is the set ; the second is the set containing .
• Note that ; the former contains one thing (the empty set), while the latter contains no things. This is analogous to the difference in python between [] and [[]]:
>>> len([])
0
>>> len([[]])
1


One easy way to construct a set is to draw a picture of it. A common way of doing so is a Venn diagram such as this one:

This diagram indicates that the set consists of all of the points in the left-hand circle, while set consists of the points in the right hand circle.

Be careful: although Venn diagrams are a great way to create examples, they do not provide proofs that work for arbitrary sets. For example, an argument made using the diagram above does not describe the cases where or when . Moreover, it doesn't consider finite sets or sets that are larger than any set of points in the plane. Venn diagrams give intuition (and examples) but not proofs.

## Set comprehensions

The notation denotes the set of all that satisfy the property. You should read as "such that". For example,

indicates the set of all even numbers. because is even, while because is not even.

We may want to specify that we're only interested in natural numbers; we often use notation like . This should be read as "the set of natural numbers which are even".

We can also have more complicated expressions to the left of the vertical bar, for example also denotes the set of even natural numbers: because and , while because there is no natural number that when multiplied by 2 gives 7.

# Set relationships

## Set equality

The defining feature of a set is the collections of elements that are in or not in it. This suggests that we should consider two sets to be the same if they contain the same elements. This motivates the definition of equality:

Two sets and are equal if every is in , and every is in .

This definition tells us that sets "ignore" duplicates and order. For example, ; we can prove this using the definition. First, we check every in the left hand side (LHS) is in the right hand side (RHS); by inspection, we see that , , , and . Then, we check that every in the RHS is in the LHS; which they are, again by inspection.

## Subset

Definition: Subset
If and are sets, then is a subset of (written ) if every is also in

For example, in the following Venn diagram, is a subset of :

Note the difference between and : says that is a set and that everything in is also in ; means that 'itself' is an element of .

# Set operations

There are several ways to combine sets together; here we discuss three: the union, intersection and set difference.

## Union

Definition: Union
If and are sets, then the union of and (written ) is given by .

This means that if you know , you can conclude that 'either' 'or' , and similarly you can prove if you can either prove or that .

In this Venn diagram, the union of and is shaded:

## Intersection

Definition: Intersection
If and are sets, then the intersection of and (written ) is given by .

This means that if you know , you can conclude 'both' that 'and' , and similarly you must prove both and to prove .

In this Venn diagram, the intersection of and is shaded:

## Set difference

Definition: Set difference
If and are sets, then the set difference minus (written ) is given by .

We use the symbol instead of the normal because occasionally we will want to use sets to represent number-like things, and we will want to define subtraction differently for those sets (in particular, we will do this in the section on Category:number theory).

This means that if you know , you can conclude 'both' that 'and' , and similarly you must prove both and to prove .

In this Venn diagram, the set difference minus is shaded:

# Proofs

Now that we have some definitions, we can turn our attention to proving things using those definitions. During the lecture, we listed some general techniques as we went; here we discuss the general techniques first, and then present the two proofs given.

## General techniques

A proof is just an argument that something is true. While writing a proof, you will make a series of claims; each claim should be

• clearly described (all terms have definitions)
• true (based on the current set of assumptions)
• obviously true based on what has already been stated.

### Separate goals from knowns

While writing a proof (as with any technical writing), it is often helpful to remind the reader where you are going. However, it is important to clearly indicate that this is what you are doing.

I often write "we want to show" (abbreviated WTS) to clearly indicate that I haven't already proved what I'm stating. Failing to do so can lead to a backwards proof. For example, while trying to prove , I shouldn't write something like

• every is in
• ...

because the reader will believe that you are claiming what you are trying to prove is true on the very first line (remember, every claim should be obvious based on what came before). However, the following solves this problem:

Here, each sentence is obviously true: we obviously do want to prove , and that is obviously the same as saying that every is in (we consider definitions to be "obvious").

### Plug in definitions

It is often helpful to plug in definitions; indeed, this is the whole point of clearly writing down definitions! If you are trying to prove two things are equal, find the appropriate definition of equality and plug it in.

We often indicate that we are using a definition by writing by definition, in other words, or i.e..

You can often save yourself some handwriting by expanding the outermost definitions first. For example, if you are proving , you could choose to expand any of the uses of the definition of the , of , or of . If you reduce or first, you will likely have to repeat its defintiion several times. If you expand first, on the other hand, you can immediately dive into the proof of without having to copy long formulas down.

### Do what it says, use what you know

A good way to approach proofs is to "Do what it says, use what you know". In other words, look at the structure of what you've already proved (or assumed) and what you are trying to prove.

Often, this can help you make progress. We will present a table of proof techniques in a future lecture, but we list some of the techniques here.

#### Case analysis

If you know that "P or Q" is true for some statements P and Q, and you wish to show a third statement R, you can do so by separately considering the cases where P is true and where Q is true. If you are able to prove R in either case, then you know that R is necessarily true.

This technique is often referred to as case analysis.

#### Proving "for all" statements

If your goal is to prove "for all , P", you can proceed by choosing an arbitrary value and then proving that P holds for that .

The fact that is arbitrary does not mean you get to pick ; on the contrary, your proof should work no matter what you choose. This means you can't use any property of other than that .

## First example proof: A ∩ B ⊆ A

Here is our first proof:

Proof:
We want to show that , i.e. that every is also in A. Choose an arbitrary ; our new goal is to show that . But this comes directly from the definition of , since we know .

## Second example proof: A = (A ∩ B) ∪ (A ∖ B)

Proof:
Let RHS denote the right hand side ().

In order to show that , we must show both that 1. and 2. .

1. Choose an arbitrary . Clearly is either in or not. In the first case, we have that so (by definition of ). In the second case, we have that , so again . In either case, we have as desired.

2. Now we wish to show that , so we choose an arbitrary . By definition of the union, we know that either or . In the first case, we have (by definition of ), while in the second case we have by definition of . In either case we have as

desired.