Skip to main content
Engineering LibreTexts

4.4.D First-class objects

  • Page ID
    10898
  • 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 or first-class citizens. 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.’)

    One way that programming languages differ is by what they allow as first- class objects. For example, Java added a ‘lambda syntax’ to help writing ‘closures’ in version 8.

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

    Suppose that and are sets. There are, in general, many functions that map 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 \rightarrow B\) is exactly the same as saying \(f \in B^{A} .\) Both of these notations assert that is a function from to B. Of course, we can also form an unlimited number of other sets, such as the power set \(\mathcal{P}\left(B^{A}\right),\) the cross product \(B^{A} \times A,\) or the set \(A^{A \times A}\), which contains all the functions from the set × 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 \(\varepsilon : B^{A} \times A \rightarrow B\) defined by the formula \(\mathcal{E}(f, a)=f(a) .\) Let's see if we can make sense of this notation. Since the domain of \(\mathcal{E}\) is \(B^{A} \times A,\) an element in the domain is an ordered pair in which the first coordinate is a function from to and the second coordinate is an element of A. Thus, E( a) is defined for a function → and an element ∈ A. Given such an and a, the notation (a) specifies an element of B, so the definition ofE( a) as (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 = {1, 2, 3, 4} and let = {abc}. Find the sets × and × A.

    2.Let be the set {a,b,c,d}. Let be the function from to given by the set of ordered pairs {(ab), (bb), (ca), (dc)}, and let be the function given by the set of ordered pairs{(ab), (bc), (cd), (dd)}. Find the set of ordered pairs for the composition ◦ .

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

    2. Consider the functions from Z to 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) (n) = 2n        b) g(n) = + 1        c) \(h(n)=n^{2}+n+1\)        d) \(s(n)=\left\{\begin{array}{ll}{\mathrm{n} / 2,} & {\text { if } n \text { is even }} \\ {(\mathrm{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 functions f → B→ C, and → D, the compositions (◦ g) ◦ and ◦ (◦ ) are equal.

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

    7.Suppose that f→ and g→ C, and suppose that the composition g◦ is an onto function.

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