Lecture 3: Functions

Notes on proofs

Even if something is "obvious", be sure to state it clearly, and at least think about how you would prove it. There's always a bit of judgement involved in how much detail to include; you want to capture what's "interesting" without flooding the reader with detail. For this course, especially at the beginning, err on the side of more detail.

If there's a fact you're going to use again and again, prove it once as a lemma, then refer to the lemma as necessary. It's just like a helper function when you're programming.

A proof by contradiction always starts by assuming the opposite (logical negation) of the fact to be proven, and then arrives at a logical contradiction.

NEVER Start a proof by assuming what you are trying to prove.

Example proof by contradiction in the context of the sudoku problem from last lecture:

Claim: if f is a sudoku solution, then each row, column, and box of f contains each number. In other words, - for all i, k, there exists a j such that f(i, j)=k - for all j, k, there exists an i such that f(i, j)=k - for all b, k, there exists an i and a j such that box(i, j)=b and f(i, j)=k

Proof: We prove the first part by contradiction. The other two are similar. Suppose that there exists some i and k such that there is no j with f(i, j)=k [NOTE: you should make sure you are convinced that this is the opposite of the claim]. Then the nine numbers f(i, 1), f(i, 2), ..., f(i, 9) are each one of the eight numbers {1, 2, …, k − 1, k + 1, …, 9}. There are nine cells, but only 8 numbers to put in them, so two different cells must contain the same number. But this contradicts the fact that f is a sudoku solution. Thus the original assumption, that there is a row that is missing a particular number, must have been false. Thus every row contains every number.

Example direct proof, using the lemma (Note, we gave this proof last time, but without the lemma it was incomplete):

Suppose we are working on the following puzzle:

1 5 7
3 7 1 2 6 8
1 6 5 3
5 9
2 1
5 3 7 1 4
8 7
4 _ 9

It is clear that the last entry of the third column (cell (9,3)) must be 1. Let's prove it.

Claim: if f is a sudoku solution compatible with the above board (that is, if f(2, 2)=1, f(1, 5)=8, f(2, 5)=5 and so on), then f(9, 3)=1.

Proof: There must be a 1 somewhere in box 3 (in other words, there exists some (i, j) such that square(i, j)=3 and f(i, j)=1). By rule 2, j cannot be 1, because f(4, 1)=1. Similarly, since f(2, 2)=1, j cannot be 2. Thus j must be 3; and f(7, 3)≠1, and f(8, 3)≠1. The only cell left is (9, 3), so f(9, 3) must be 1.

Example bogus proof:

Claim: if f is a sudoku solution compatible with the above board, then f(8, 5)=1.

Bogus proof: assume f(8, 5)=1. We know 1 must appear in the lower right square. It cannot be in row 7 by rule 1, because f(7, 7)=1. Our assumption lets us conclude that it cannot be in row 8. Therefore it must be in row 9. It can't be in cell (9, 1) by rule 2 (because f(4, 1)=1), so it must be in cell (9, 3). We proved above that f(9, 3)=1, so our assumption must be correct.

Example bogus proof:

Claim: if x2 + 3x + 2 = 0 then x = −1.

Proof: ( − 1)2 + 3(−1)+2 = 1 − 3 + 2 = 0.

Function properties

In the last lecture, I defined a function as follows:

A function f from a set A to a set B is an unambiguous rule, which gives an element of B for each element of A. A is called the domain of f, while B is called the codomain of f. We often write
f : A → B to represent the statement "f is a function from A to B".

The domain and codomain are different: every element of the domain must have a corresponding element of the codomain, but an element of the codomain may have any number (including 0) of elements of the domain that map to it.

MCS allows functions to be partial; to only provide outputs for some of their inputs (both of us refer to functions that provide outputs for all inputs as total functions).

I prefer to reserve the word function for total functions.

Other key definitions:

f : A → B is injective if, for all x1, x2 ∈ A, if f(x1)=f(x2) then x1 = x2. Informally, two different inputs can't map to the same output.

f : A → B is surjective if, for all y ∈ B, there exists an x in A such that f(x)=y. Informally, every element of the codomain gets hit by the function.

f : A → B is bijective if it is both injective and surjective.