# FA19:Lecture 2 Set and function definitions

We discussed the definitions for sets and functions.

• key definitions:

# 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 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:

Definition: Equality (sets)
Two sets $A$ and $B$ are equal if and .

This is equivalent to the following definition:

Definition: Equality (sets)
Two sets $A$ and $B$ are equal if, for all , is also in and if for all , is also in .

Here is a third variant:

Definition: Equality (sets)
Two sets and are equal if, for all , if and only if .

These three definitions are equivalent (proof left as an exercise), so you can use them interchangeably.

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.

# Functions

Definition: Function
If and are sets, then a function from to (written ) is an unambiguous rule giving, for every input , an output . is called the domain of ; is called the codomain.

When giving a function, you must indicate the domain, the codomain, and an unambiguous rule giving an output for every input.

The output of a function is unambiguous if there is only one output for any input. It is especially important to check this when the input of the function can be written in different ways. For example, given by , , and is not unambiguous, because so it is not clear if or .

## Specifying functions

When giving a function, you must indicate the domain, the codomain, and an unambiguous rule giving an output for every input. There are many, many ways to do this, as long as the output is clear. We gave a few examples during lecture:

### direct specification

We can define the output of the function directly:

let be given by . The domain and codomain of are both ; the image is .

### drawings

We can draw a function:

The domain of is , and the codomain of is .

We might also write this as is given by , , and .

### tables

Another way to draw a function is with a table:

x
a 1
b 1
c 1

This almost describes a function; the domain is clearly (because if there were any other domain elements, would not be a function); and the rule is clear. However, the codomain is not clear: is it ? Or ? Or , or ? When describing a function with a table, the codomain should be specified somewhere.

### function description

A function need not have an algorithm for constructing the output; a description of the output is also fine. For example, let give, on input , the closing Dow-Jones Industrial average on day .

# Partial functions

A partial function is like a function, except that it does not need to give an output for every input. However, the outputs it does give must be unambiguous. One way to formalize this is by defining a partial function as a function from a restricted domain:

Definition: Partial function
A partial function is a subset (called the support of ), along with a function We say that if and is undefined if .
Definition: Total
A partial function is total if the support is equal to the domain, i.e. if is a function.

Note that, somewhat confusingly, not all partial functions are functions. However, we do consider a (total) function to be a partial function. We use this terminology because it is standard in mathematics and because it simplifies proofs (so that we don't have to say "a partial or total function" in places where the same argument works for both).

To summarize,

is a partial function, but not a function (because it is not total), while

is a partial function, a function and a total function (also an injection, a surjection, a bijection, and a relation).