Skip to main content
Engineering LibreTexts

2.4: Functions

  • Page ID
    6718
  • Both the real world and the world of mathematics are full of what are called, in mathematics, “functional relationships.” A functional relationship is a relationship between two sets, which associates exactly one element from the second set to each element of the first set.

    For example, each item for sale in a store has a price. The first set in this relationship is the set of items in the store. For each item in the store, there is an associated price, so the second set in the relationship is the set of

    possible prices. The relationship is a functional relationship because each item has a price. That is, the question “What is the price of this item?” has a single, definite answer for each item in the store.

    Similarly, the question “Who is the (biological) mother of this person?” has a single, definite answer for each person. So, the relationship “mother of” defines a functional relationship. In this case, the two sets in the relationship are the same set, namely the set of people.2 On the other hand, the relationship “child of” is not a functional relationship. The question “Who is the child of this person?” does not have a single, definite answer for each person. A given person might not have any child at all. And a given person might have more than one child. Either of these cases—a person with no child or a person with more than one child—is enough to show that the relationship “child of” is not a functional relationship.

    Or consider an ordinary map, such as a map of New York State or a street map of Rome. The whole point of the map, if it is accurate, is that there is a functional relationship between points on the map and points on the surface of the Earth. Perhaps because of this example, a functional relationship is sometimes called a mapping.

    There are also many natural examples of functional relationships in mathematics. For example, every rectangle has an associated area. This fact expresses a functional relationship between the set of rectangles and the set of numbers. Every natural number n has a square, n^{2}. The relationship “square of” is a functional relationship from the set of natural numbers to itself.

    In mathematics, of course, we need to work with functional relationships in the abstract. To do this, we introduce the idea of function. You should think of a function as a mathematical object that expresses a functional relationship between two sets. The notation \(f : A → B\) expresses the fact that \(f\) is a function from the set \(A\) to the set \(B\). That is,\(f\) is a name for a mathematical object that expresses a functional relationship from the set \(A\) to the set \(B\). The notation \(f : A → B\) is read as “\(f\) is a function from \(A\) to \(B\)” or more simply as “\(f\) maps \(A\) to \(B\).”

    If \(f: A → B\) and if \(a ∈ A\), the fact that \(f\) is a functional relationship from \(A\) to \(B\) means that \(f\) associates some element of \(B\) to \(a\). That element is denoted \(f(a)\). That is, for each \(a ∈ A\), \(f(a) ∈ B\) and \(f(a)\) is the single, definite answer to the question “What element of \(B\) is associated to \(a\) by the function \(f\) ?” The fact that \(f\) is a function from \(A\) to \(B\) means that this question has a single, well-defined answer. Given \(a ∈ A\), \(f(a)\) is called the value of the function \(f\) at \(a\).

    For example, if \(I\) is the set of items for sale in a given store and \(M\) is the set of possible prices, then there is function \(c: I → M\) which is defined by the fact that for each \(x ∈ I\), \(c(x)\) is the price of the item \(x\). Similarly, if \(P\) is the set of people, then there is a function \(m: P → P\) such that for each person \(p\), \(m(p)\) is the mother of \(p\). And if \(\mathbb{N}\) is the set of natural numbers, then the formula \(s(n) = n^{2}\) specifies a function \(s: \mathbb{N} → \mathbb{N}\). It is in the form of formulas such as \(s(n) = n^{2}\) or \(f(x) = x^{3} − 3x + 7\) that most people first encounter functions. But you should note that a formula by itself is not a function, although it might well specify a function between two given sets of numbers. Functions are much more general than formulas, and they apply to all kinds of sets, not just to sets of numbers.

    Suppose that \(f:A→B\) and \(g:B→C\) are functions. Given \(a∈A\), there is an associated element \(f(a) ∈ B\). Since \(g\) is a function from \(B\) to \(C\), and since \(f(a) ∈ B\), \(g\) associates some element of \(C\) to \(f(a)\). That element is \(g(f(a))\). Starting with an element \(a\) of \(A\), we have produced an associated element \(g(f(a))\) of \(C\). This means that we have defined a new function from the set \(A\) to the set \(C\). This function is called the composition of \(g\) with \(f\),and it is denoted by \(g◦f\). That is,if \(f:A→B\) and \(g:B→C\) are functions, then \(g ◦ f : A → C\) is the function which is defined by

    \[(g ◦ f)(a) = g(f(a)) \nonumber \]

    for each \(a ∈ A\). For example, suppose that \(p\) is the function that associates to each item in a store the price of the item, and suppose that \(t\) is a function that associates the amount of tax on a price to each possible price. The composition, \(t ◦ p\), is the function that associates to each item the amount of tax on that item. Or suppose that \(s:\mathbb{N}→\mathbb{N}\) and \(r:\mathbb{N}→\mathbb{N}\) are the functions defined by the formulas \(s(n) = n^{2}\) and \(r(n) = 3n + 1\), for each \(n∈\mathbb{N}\). Then \(r◦s\) is a function from \(\mathbb{N}\) to \(mathbb{N}\), and for \(n∈\mathbb{N}\), \((r◦s)(n)=r(s(n)) = r(n^{2}) = 3n^{2} + 1\). In this case, we also have the function \(s ◦ r\), which satisfies \((s◦r)(n) = s(r(n)) = s(3n+1) = (3n+1)^{2} = 9n^{2} +6n+1\). Note in particular that \(r ◦ s\) and \(s ◦ r\) are not the same function. The operation ◦ is not commutative.

    If A is a set and \(f:A→A\), then \(f◦f\),the composition of \(f\) with itself, is defined. For example, using the function \(s\) from the preceding example, \(s ◦ s\) is the function from \(\mathbb{N}\) to \(mathbb{N}\) given by the formula \((s ◦ s)(n) = s(s(n)) =s(n^{2}) = (n^{2})^{2} = n^{4}\). If \(m\) is the function from the set of people to itself which associates to each person that person’s mother, then \(m ◦ m\) is the function that associates to each person that person’s maternal grandmother.

    If \(a\) and \(b\) are entities, then \((a, b)\) denotes the ordered pair containing \(a\) and \(b\). The ordered pair \((a, b)\) differs from the set \({a, b}\) because a set is not ordered. That is, \({a, b}\) and \({b, a}\) denote the same set, but if \(a \ne b\), then \((a, b)\) and \((b, a)\) are different ordered pairs. More generally, two ordered pairs \((a,b)\) and \((c,d)\) are equal if and only if both \(a = c\) and \(b = d\). If \((a,b)\) is an ordered pair, then \(a\) and \(b\) are referred to as the coordinates of the ordered pair. In particular, \(a\) is the first coordinate and \(b\) is the second coordinate.

    If \(A\) and \(B\) are sets, then we can form the set \(A×B\) which is defined by

    \[A × B = {(a, b) | a ∈ A and b ∈ B}. \nonumber\]

    This set is called the cross product or Cartesian product of the sets \(A\) and \(B\). The set \(A × B\) contains every ordered pair whose first coordinate is an element of \(A\) and whose second coordinate is an element of \(B\). For example, if \(X = {c,d}\) and \(Y = {1,2,3}\), then \(X×Y ={(c, 1), (c, 2), (c, 3), (d, 1), (d, 2), (d, 3)}\). It is possible to extend this idea to the cross product of more than two sets. The cross product of the three sets \(A, B,\) and \(C\) is denoted \(A × B × C\). It consists of all ordered triples \((a,b,c)\) where \(a ∈ A\), \(b ∈ B\), and \(c ∈ C\). The definition for four or more sets is similar. The general term for a member of a cross product is tuple or, more specifically, ordered n-tuple. For example, \((a, b, c, d, e)\) is an ordered 5-tuple.

    Given a function \(f: A → B\), consider the set \(\{(a,b) ∈ A × B|a ∈A and b = f(a)\}\). This set of ordered pairs consists of all pairs \((a,b)\) such that \(a ∈ A\) and \(b\) is the element of \(B\) that is associated to a by the function \(f\). The set \(\{(a,b) ∈ A×B|a ∈ A and b = f(a)\}\) is called the graph of the function \(f\). Since \(f\) is a function, each element \(a ∈ A\) occurs once and only once as a first coordinate among the ordered pairs in the graph of \(f\). Given \(a ∈ A\), we can determine \(f(a)\) by finding that ordered pair and looking at the second coordinate. In fact, it is convenient to consider the function and its graph to be the same thing, and to use this as our official mathematical definition\(.^{3}\)

    \(^{3}\)This is a convenient definition for the mathematical world, but as is often the case in mathematics, it leaves out an awful lot of the real world. Functional relationships in the real world are meaningful, but we model them in mathematics with meaningless sets of ordered pairs. We do this for the usual reason: to have something precise and rigorous enough that we can make logical deductions and prove things about it.

    Definition 2.2. Let \(A\) and \(B\) be sets. A function from \(A\) to \(B\) is a subset of \(A × B\) which has the property that for each \(a ∈ A\), the set contains one and only one ordered pair whose first coordinate is \(a\). If \((a, b)\) is that ordered pair, then \(b\) is called the value of the function at \(a\) and is denoted \(f(a)\). If \(b = f(a)\), then we also say that the function \(f\) maps \(a\) to \(b\). The fact that \(f\) is a function from \(A\) to \(B\) is indicated by the notation \(f : A → B\).

    For example, if \(X = {a,b}\) and \(Y = \{1,2,3\}\), then the set \(\{(a,2),(b,1)\}\) is a function from \(X\) to \(Y\), and \(\{(1,a),(2,a),(3,b)\}\) is a function from \(Y\) to \(X\). On the other hand, \(\{(1,a),(2,b)\}\) is not a function from \(Y\) to \(X\), since it does not specify any value for 3. And \(\{(a,1),(a,2),(b,3)\}\) is not a function from \(X\) to \(Y\) because it specifies two different values, 1 and 2, associated with the same element, \(a\), of \(X\).

    Even though the technical definition of a function is a set of ordered pairs, it’s usually better to think of a function from \(A\) to \(B\) as something that associates some element of \(B\) to every element of \(A\). The set of ordered pairs is one way of expressing this association. If the association is expressed in some other way, it’s easy to write down the set of ordered pairs. For example, the function \(s: \mathbb{N} → \mathbb{N}\) which is specified by the formula \(s(n) = n^{2}\) can be written as the set of ordered pairs \(\{(n, n^{2}) | n ∈ \mathbb{N}\}\).

    Suppose that \(f:A → B\) is a function from the set \(A\) to the set \(B\). We say that \(A\) is the domain of the function \(f\) and that \(B\) is the range of the function. We define the image of the function \(f\) to be the set \(\{b ∈ B|∃a ∈ A(b = f(a))\}\). Put more simply, the image of \(f\) is the set \(\{f(a)|a ∈ A\}\). That is, the image is the set of all values, \(f(a)\), of the function, for all \(a ∈ A\). (You should note that in some cases—particularly in calculus courses—the term “range” is used to refer to what I am calling the image.) For example, for the function \(s: \mathbb{N} → \mathbb{N}\) that is specified by \(s(n) = n^{2}\), both the domain and the range are \(\mathbb{N}\), and the image is the set \(\{n^{2} |n ∈ \mathbb{N}\}\), or {0,1,4,9,16,...}.

    Note that the image of a function is a subset of its range. It can be a proper subset, as in the above example, but it is also possible for the image of a function to be equal to the range. In that case, the function is said to be onto. Sometimes, the fancier term surjective is used instead. Formally, a function \(f : A → B\) is said to be onto (or surjective) if every element of \(B\) is equal to \(f(a)\) for some element of \(A\). In terms of logic, \(f\) is onto if and only if

    \[∀b ∈ B ∃a ∈ A (b = f (a)). \nonumber \]

    For example, let \(X = {a,b}\) and \(Y = {1,2,3}\), and consider the function from \(Y\) to \(X\) specified by the set of ordered pairs \(\{(1, a), (2, a), (3, b)\}\). This function is onto because its image, \(\{a, b\}\), is equal to the range, \(X\). However, the function from \(X\) to \(Y\) given by \(\{(a,1),(b,3)\}\) is not onto, because its image, \(\{1,3\}\), is a proper subset of its range, \(Y\). As a further example, consider the function \(f\) from \(\mathbb{Z}\) to \(\mathbb{Z}\) given by \(f (n) = n − 52\). To show that \(f\) is onto, we need to pick an arbitrary \(b\) in the range \(\mathbb{Z}\) and show that there is some number \(a\) in the domain \(\mathbb{Z}\) such that \(f(a) = b\). So let \(b\) be an arbitrary integer; we want to find an a such that \(a − 52 = b\). Clearly this equation will be true when \(a = b + 52\). So every element \(b\) is the image of the number \(a = b + 52\), and \(f\) is therefore onto. Note that if \(f\) had been specified to have domain \(\mathbb{N}\), then \(f\) would not be onto, as for some \(b ∈ \mathbb{Z}\) the number \(a = b + 52\) is not in the domain \(\mathbb{N}\) (for example, the integer−73 is not in the image of \(f\), since −21 is not in \(\mathbb{N}\).)

    If \(f : A → B\) and if \(a ∈ A\), then \(a\) is associated to only one element of \(B\). This is part of the definition of a function. However, no such restriction holds for elements of \(B\). If \(b ∈ B\), it is possible for \(b\) to be associated to zero, one, two, three, . . . , or even to an infinite number of elements of \(A\). In the case where each element of the range is associated to at most one element of the domain, the function is said to be one-to-one. Sometimes, the term injective is used instead. The function \(f\) is one-to-one (or injective) if for any two distinct elements \(x\) and \(y\) in the domain of \(f\) , \(f(x)\) and \(f (y)\) are also distinct. In terms of logic, \(f : A → B\) is one-to-one if and only if

    \[∀x ∈ A ∀y ∈ Ax ̸= y → f(x) ̸= f(y). \nonumber\]

    Since a proposition is equivalent to its contrapositive, we can write this condition equivalently as

    \[∀x ∈ A ∀y ∈ Af(x) = f(y) → x = y. \nonumber\]

    Sometimes, it is easier to work with the definition of one-to-one when it is expressed in this form. The function that associates every person to his or her mother is not one-to-one because it is possible for two different people to have the same mother. The function \(s: \mathbb{N} → \mathbb{N}\) specified by \(s(n) = n^{2}\) is one-to-one. However, we can define a function \(r: \mathbb{Z} → \mathbb{Z}\) by the same formula: \(r(n) = n^{2}\), for \(n ∈ \mathbb{Z}\). The function \(r\) is not one-to-one since two different integers can have the same square. For example, \(r(−2) = r(2)\).

    A function that is both one-to-one and onto is said to be bijective. The function that associates each point in a map of New York State to a point in the state itself is presumably bijective. For each point on the map, there is a corresponding point in the state, and vice versa. If we specify the function f from the set {1, 2, 3} to the set \(\{a, b, c\}\) as the set of ordered pairs \(\{(1,b),(2,a),(3,c)\}\), then \(f\) is a bijective function. Or consider the function from \(\mathbb{Z}\) to \(mathbb{Z}\) given by \(f(n) = n − 52\). We have already shown that \(f\) is onto. We can show that it is also one-to-one: pick an arbitrary \(x\) and \(y\) in \(\mathbb{Z}\) and assume that \(f(x) = f(y)\). This means that \(x−52 = y−52\), and adding 52 to both sides of the equation gives \(x = y\). Since \(x\) and \(y\) were arbitrary, we have proved \(∀x ∈ Z ∀y ∈ Z(f(x) = f(y) → x = y)\), that is, that \(f\) is one-to-one. Altogether, then, \(f\) is a bijection.

    One difficulty that people sometimes have with mathematics is its generality. A set is a collection of entities, but an “entity” can be anything at all, including other sets. Once we have defined ordered pairs, we can use ordered pairs as elements of sets. We could also make ordered pairs of sets. Now that we have defined functions, every function is itself an entity. This means that we can have sets that contain functions. We can even have a function whose domain and range are sets of functions. Similarly, the domain or range of a function might be a set of sets, or a set of ordered pairs. Computer scientists have a good name for this. They would say that sets, ordered pairs, and functions are first-class objects. Once a set, ordered pair, or function has been defined, it can be used just like any other entity. If they were not first-class objects, there could be restrictions on the way they can be used. For example, it might not be possible to use functions as members of sets. (This would make them “second class.”)

    For example, suppose that \(A, B,\) and \(C\) are sets. Then since \(A × B\) is a set, we might have a function \(f:A×B→C\). If \((a,b)∈A×B\), then the value of \(f\) at \((a, b)\) would be denoted \(f((a, b))\). In practice, though, one set of parentheses is usually dropped, and the value of \(f\) at \((a,b)\) is denoted \(f(a, b)\). As a particular example, we might define a function \(p : \mathbb{N} × \mathbb{N} → \mathbb{N}\)with the formula \(p(n, m) = nm + 1\). Similarly, we might define a function \(q : \mathbb{N} × \mathbb{N} × \mathbb{N} → \mathbb{N} × \mathbb{N}\) by \(q(n, m, k) = (nm − k, nk − n)\).

    Suppose that \(A\) and \(B\) are sets. There are, in general, many functions that map \(A\) to \(B\). We can gather all those functions into a set. This set, whose elements are all the functions from \(A\) to \(B\), is denoted \(B^{A}\). (We’ll see later why this notation is reasonable.) Using this notation, saying \(f : A → B\) is exactly the same as saying \(f ∈ B^{A}\). Both of these notations assert that \(f\) is a function from \(A\) to \(B\). Of course, we can also form an unlimited number of other sets, such as the power set \(\mathcal{P(BA)}\), the cross product \(B^{A} ×A\), or the set \(A^{A×A}\), which contains all the functions from the set \(A × A\) to the set \(A\). And of course, any of these sets can be the domain or range of a function. An example of this is the function \(E: BA × A → B\) defined by the formula \(E(f,a) = f(a)\). Let’s see if we can make sense of this notation. Since the domain of \(E\) is \(B^{A} × A\), an element in the domain is an ordered pair in which the first coordinate is a function from \(A\) to \(B\) and the second coordinate is an element of \(A\). Thus, \(E(f,a)\) is defined for a function \(f : A → B\) and an element \(a ∈ A\). Given such an \(f\) and \(a\), the notation \(f(a)\) specifies an element of \(B\), so the definition of \(E(f,a)\) as \(f(a)\) makes sense. The function \(E\) is called the “evaluation function” since it captures the idea of evaluating a function at an element of its domain.


    Exercises

    1. Let \(A\) = {1, 2, 3, 4} and let \(B\) = {a, b, c}. Find the sets \(A × B\) and \(B × A\).

    2. Let \(A\) be the set \(\{a,b,c,d\}\). Let \(f\) be the function from \(A\) to \(A\) given by the set of ordered pairs \(\{(a, b), (b, b), (c, a), (d, c)\}\), and let g be the function given by the set of ordered pairs \(\{(a, b), (b, c), (c, d), (d, d)\}\). Find the set of ordered pairs for the composition \(g ◦ f\) .

    3. Let \(A = \{a,b,c\}\) and let \(B = \{0,1\}\). Find all possible functions from \(A\) to \(B\). Give each function as a set of ordered pairs. (Hint: Every such function corresponds to one of the subsets of \(A\).)

    4.Consider the functions from \(\mathbb{Z}\) to \(\mathbb(Z)\) which are defined by the following formulas. Decide whether each function is onto and whether it is one-to-one; prove your answers.

    a) \(f(n) = 2n\)
    b) \(g(n) = n +1\)
    c) \(h(n) = n^{2} + n +1\)
    d) \(s(x) = \left\{
    \begin{array}{ll}
    n/2, \text{ if } n \text{ is even }\\
    (n+1)/2, \text{ if } n \text{ is odd }
    \end{array}
    \right.\)

    5.Prove that composition of functions is an associative operation. That is, prove that for functions \(f: A → B, g: B → C,\) and \(h: C → D\), the compositions \((h◦g)◦f\) and \(h◦(g◦f)\) are equal.

    6.Suppose that \(f : A → B\) and \(g : B → C\) are functions and that \(g ◦ f\) is one- to-one.
    a) Prove that \(f\) is one-to-one. (Hint: use a proof by contradiction.)
    b) Find a specific example that shows that \(g\) is not necessarily one-to-one.

    7.Suppose that \(f: A → B\) and \(g: B → C\), and suppose that the composition \(g ◦ f\) is an onto function.

    a) Prove that \(g\) is an onto function.
    b) Find a specific example that shows that \(f\) is not necessarily onto.