As we all know, except the cranks, the foundation of mathematics is said to be set theory. So I will give a foundational definition of a function from a set theoretical perspective. We will however not bother with existence of sets or the likes, we will use only the rigors of set theory to define it here. Let and be two given sets, by the axiom of union from ZFC do we have that the set exists such that it contains all elements of our previous two sets. Now we will define the concept of ordered pair , it is easy isn't it? A pair of elements where the order matters! Well sorry we need to define it from a set theoretical perspective and hence it must be a set. However that is easy to do and we define it as .

I leave it to the reader to prove that this set in ZFC satisfies the desired properties we have of an ordered pair. One may say that how is that possible, the elements don't necciserily from the same set or anything! No the elements are not but that doesn't matter because the set it is in however in which we are garantueed does exist for any two sets.

From this we can define the operation of cartesian product, that is . We define that as the collection of all ordered pairs with and . For the reader with an accute sense of mathematics they will notice that from this we have that in set theoretical point of view. However we of course do not think about this much in normal usage because we really don't give a damn then. Here however we do because it is set theory and we are being foundational. With this established we move on and treat our cartesian product as just another set, a set of ordered pairs.

Next we define what a relation is, a relation is a subset of . If we have that then we say that a is in relation to b with respect to . This may or may not be all of the cartesian product, relations are very broad and a dicipline on their own. However we will consider only a specific subset of all possible subsets of the cartesian product. Namely those that satisfies the following 2 properties

  1. For all there exists a such that
  2. If we have then

If our relation has those properties, we call it a function and write and . Of course writing all the relations and such in a strictly set theoretical manner, as we have partially avoided already, is dull and it is easy to get lost so we will use various shortcuts that are understood to be just that. Criteria 1 secures that every element of is in relation, or mapped to, some element in and the second criteria secures that the mapping is unique for each single element in . Pay attention that the second criteria does not secure that the target element is in a unique relation with some element in , there may be multiple elements in our set that is in relation to the same element in . These are just the criterias we want of a function.

Through these steps have we now defined a function using nothing but set theory and secured their existence. Questions about morphisms, continuity etc requires other properties to be added upon a set and restricts the subset of the cartesian product that will be valid. That is not a topic for today.