Now I think I've covered the real numbers in enough detail to move on to the next topic, which is functions and sets. Intuition about functions from high school algebra is a good place to start, but as usual, we want to generalize the concept and examine it in more detail.

A function, broadly speaking, is a mapping from members of one set to members of another set. Strictly speaking, the members of the sets don't have to be numbers, although in practice they often are, and the function can be written as a mathematical expression. The set that we are mapping from is the domain of the function. The important rule about functions and domains is that every member, or point, of the domain set maps to exactly one point in the set the function is mapping to, or the codomain.

There is no similar restriction on the codomain. Points in the codomain may not be reachable from any point in the domain. A simple example makes this clear. Define a function f as a mapping from the real numbers to the real numbers. We can label the domain as X and the codomain as Y, to be clear that the two sets are distinct, although they both have as members all real numbers. The notation for this is f:X→Y.

We will define f as a formula that maps points in domain into the codomain. For any point x∈X, f(x)=x^{2}. For any x in the real numbers (the domain), we can find an f(x) in the codomain (also the real numbers), and no x in the domain maps to more that one point in codomain. However, there are points in the codomain that cannot be reached by this mapping, since no real number squared is a negative number. The subset of the codomain of points that can be mapped to from the domain is called the range. For this function, the range is the set of non-negative real numbers.

If the range of a function is equal to the codomain of the function, we can say that the function is onto or that it is a surjection.

The other thing to notice about f(x)=x^{2} is that for any positive f(x), there are two different numbers in the domain which map to that number. If every point in the range is mapped to by only one point in the domain, then the function is one-to-one or is an injection.

Any given function can be one-to-one, onto, both, or neither. If a function is both one-to-one and onto, it is a bijection.

For whatever reason, I am personally more comfortable with the terms injection, surjection, and bijection than I am with one-to-one and onto. I think "one-to-one" implies bijection to me, which is not correct. My goal is to deliberately use the words one-to-one and onto here to try to train myself to use them correctly.