Functions

Last time we talked about sets, and introduced notation and formalisms for defining and manipulating sets. Now we talk about ways mapping from one set to other. This is done through talk of "functions".

Writing the statement:

f: A --> B
says that function "f" maps elements of set A to elements of set B. that is, if "a" is a specific element of A, then f(a) is an element of B. For f to be a function, we need to have:
  1. f(a) is uniquely defined for every element in A.
  2. for all a, f(a) is an element of B.

Just to ground this discussion in several examples, we can define A as the set of students in this class, and define N as the natural numbers and define, for all x in A:

f(x) = how many years old is person x.
Some examples that look like functions may not be:
f: {people in this room} --> {brands of cars}
Note that if any person "a" has 2 cars, then f(a) is not unique
if any person "a" has no car, then f(a) is not defined
either of these cases would make "f" not be a function.
We can, (and soon will) capture such mappings between sets using "relations".

So, as the trend is in this class, we aren't so interested in specific functions, rather, we care about properties of functions. Once we are sure function "f" is a function, we can define several terms: Given f:A --> B,

Why do we have seperate terms for the co-Domain and the range? In part, to support reasoning about "Composition". Composition is a way of making a function out of two functions:

Given f: A --> B, and g: B --> C, the (g o f)(x) = g(f(x)). This composition is only valid if the domain of B is a superset or equal to the range of f. Using these terms, we can define several properties that a function may or may not have (and, you guessed it, we'll try to prove these properties!). The most important properties are:

If a function f is "bijective", then its inverse is a function. Why? What about the inverse isn't a function if f isn't 1-1? What isn't a function if f isn't onto?

Before we prove anything, lets do a bit of practice:

Let f(x) = 2x + 1 and g(x) = (x-3)2. For each function defined below, answer:

  1. the function f, when the domain and co-domain are the reals.
  2. the function f, when the domain in the integers and co-domain is the reals.
  3. the function (f o g) when the domain and co-domain are the reals. [Recall, (f o g)(x) = f(g(x))]
So why do we care about all this crap? Some of these properties are important for reasoning about computer programs.
One example of a function is a "hash function". It would be useful to know that your hash function was mostly (?) "onto" (because if it isn't, you have an inefficient hash function). You also want a "hash function" to be close to one-to-one (because if it isn't you have an inefficient hash function).
Another example is a password encryption function. You want this to be a 1-1 and onto function (because you want to be sure that only the correct password gets mapped to be the same as the encrypted version you store, but you also want it to be very difficult to invert that mapping. How difficult such things is talked about in other classes.

So if you now accept that these properties are important, how can we prove them for a particular function. Examples