39.2 KB · commit a9602da
In many instances we assign to each element of a set a particular element of a second set (which may be the same as the first). For example, suppose that each student in a discrete mathematics class is assigned a letter grade from the set {A,B,C,D,F}. And suppose that the grades are A for Adams, C for Chou, B for Goodfriend, A for Rodriguez, and F for Stevens. This assignment of grades is illustrated in Figure 1.
This assignment is an example of a function. The concept of a function is extremely important in mathematics and computer science. For example, in discrete mathematics functions are used in the definition of such discrete structures as sequences and strings. Functions are also used to represent how long it takes a computer to solve problems of a given size. Many computer programs and subroutines are designed to calculate values of functions. Recursive functions, which are functions defined in terms of themselves, are used throughout computer science; they will be studied in Chapter 5. This section reviews the basic concepts involving functions needed in discrete mathematics.
![]() |
|---|
| FIGURE 1 — Assignment of Grades in a Discrete Mathematics Class (Source: Page 139) |
Functions are specified in many different ways. Sometimes we explicitly state the assignments, as in Figure 1. Often we give a formula, such as f(x)=x+1, to define a function. Other times we use a computer program to specify a function.
A function f:A→B can also be defined in terms of a relation from A to B. Recall from Section 2.1 that a relation from A to B is just a subset of A×B. A relation from A to B that contains one, and only one, ordered pair (a,b) for every element a∈A, defines a function f from A to B. This function is defined by the assignment f(a)=b, where (a,b) is the unique ordered pair in the relation that has a as its first element.
Figure 2 represents a function f from A to B.
When we define a function we specify its domain, its codomain, and the mapping of elements of the domain to elements in the codomain. Two functions are equal when they have the same domain, have the same codomain, and map each element of their common domain to the same element in their common codomain. Note that if we change either the domain or the codomain of a function, then we obtain a different function. If we change the mapping of elements, then we also obtain a different function.
![]() |
|---|
| FIGURE 2 — The Function f Maps A to B (Source: Page 139) |
Examples 1–5 provide examples of functions. In each case, we describe the domain, the codomain, the range, and the assignment of values to elements of the domain.
What are the domain, codomain, and range of the function that assigns grades to students described in the first paragraph of the introduction of this section?
Solution: Let G be the function that assigns a grade to a student in our discrete mathematics class. Note that G(Adams)=A, for instance. The domain of G is the set {Adams,Chou,Goodfriend,Rodriguez,Stevens}, and the codomain is the set {A,B,C,D,F}. The range of G is the set {A,B,C,F}, because each grade except D is assigned to some student. ◀
Let R be the relation with ordered pairs (Abdul,22), (Brenda,24), (Carla,21), (Desire,22), (Eddie,24), and (Felicia,22). Here each pair consists of a graduate student and this student’s age. Specify a function determined by this relation.
Solution: If f is a function specified by R, then f(Abdul)=22, f(Brenda)=24, f(Carla)=21, f(Desire)=22, f(Eddie)=24, and f(Felicia)=22. (Here, f(x) is the age of x, where x is a student.) For the domain, we take the set {Abdul,Brenda,Carla,Desire,Eddie,Felicia}. We also need to specify a codomain, which needs to contain all possible ages of students. Because it is highly likely that all students are less than 100 years old, we can take the set of positive integers less than 100 as the codomain. (Note that we could choose a different codomain, such as the set of all positive integers or the set of positive integers between 10 and 90, but that would change the function. Using this codomain will also allow us to extend the function by adding the names and ages of more students later.) The range of the function we have specified is the set of different ages of these students, which is the set {21,22,24}. ◀
Let f be the function that assigns the last two bits of a bit string of length 2 or greater to that string. For example, f(11010)=10. Then, the domain of f is the set of all bit strings of length 2 or greater, and both the codomain and range are the set {00,01,10,11}. ◀
Let f:Z→Z assign the square of an integer to this integer. Then, f(x)=x2, where the domain of f is the set of all integers, the codomain of f is the set of all integers, and the range of f is the set of all integers that are perfect squares, namely, {0,1,4,9,…}. ◀
The domain and codomain of functions are often specified in programming languages. For instance, the Java statement
int floor(float real) { ... }
and the C++ function statement
int function(float x) { ... }
both tell us that the domain of the floor function is the set of real numbers (represented by floating point numbers) and its codomain is the set of integers.
◀
A function is called real-valued if its codomain is the set of real numbers, and it is called integer-valued if its codomain is the set of integers. Two real-valued functions or two integer-valued functions with the same domain can be added, as well as multiplied.
Note that the functions f1+f2 and f1f2 have been defined by specifying their values at x in terms of the values of f1 and f2 at x.
Let f1 and f2 be functions from R to R such that f1(x)=x2 and f2(x)=x−x2. What are the functions f1+f2 and f1f2?
Solution: From the definition of the sum and product of functions, it follows that (f1+f2)(x)=f1(x)+f2(x)=x2+(x−x2)=x and (f1f2)(x)=x2(x−x2)=x3−x4. ◀
When f is a function from A to B, the image of a subset of A can also be defined.
Let A={a,b,c,d,e} and B={1,2,3,4} with f(a)=2, f(b)=1, f(c)=4, f(d)=1, and f(e)=1. The image of the subset S={b,c,d} is the set f(S)={1,4}. ◀
Some functions never assign the same value to two different domain elements. These functions are said to be one-to-one.
![]() |
|---|
| FIGURE 3 — A One-to-One Function (Source: Page 142) |
Note that a function f is one-to-one if and only if f(a)=f(b) whenever a=b. This way of expressing that f is one-to-one is obtained by taking the contrapositive of the implication in the definition.
We illustrate this concept by giving examples of functions that are one-to-one and other functions that are not one-to-one.
Determine whether the function f from {a,b,c,d} to {1,2,3,4,5} with f(a)=4, f(b)=5, f(c)=1, and f(d)=3 is one-to-one.
Solution: The function f is one-to-one because f takes on different values at the four elements of its domain. This is illustrated in Figure 3. ◀
Determine whether the function f(x)=x2 from the set of integers to the set of integers is one-to-one.
Solution: The function f(x)=x2 is not one-to-one because, for instance, f(1)=f(−1)=1, but 1=−1.
Note that the function f(x)=x2 with its domain restricted to Z+ is one-to-one. (Technically, when we restrict the domain of a function, we obtain a new function whose values agree with those of the original function for the elements of the restricted domain. The restricted function is not defined for elements of the original domain outside of the restricted domain.) ◀
Determine whether the function f(x)=x+1 from the set of real numbers to itself is one-to-one.
Solution: The function f(x)=x+1 is a one-to-one function. To demonstrate this, note that x+1=y+1 when x=y. ◀
Suppose that each worker in a group of employees is assigned a job from a set of possible jobs, each to be done by a single worker. In this situation, the function f that assigns a job to each worker is one-to-one. To see this, note that if x and y are two different workers, then f(x)=f(y) because the two workers x and y must be assigned different jobs. ◀
We now give some conditions that guarantee that a function is one-to-one.
![]() |
|---|
| FIGURE 4 — An Onto Function (Source: Page 143) |
From these definitions, it can be shown (see Exercises 26 and 27) that a function that is either strictly increasing or strictly decreasing must be one-to-one. However, a function that is increasing, but not strictly increasing, or decreasing, but not strictly decreasing, is not one-to-one.
For some functions the range and the codomain are equal. That is, every member of the codomain is the image of some element of the domain. Functions with this property are called onto functions.
We now give examples of onto functions and functions that are not onto.
Let f be the function from {a,b,c,d} to {1,2,3} defined by f(a)=3, f(b)=2, f(c)=1, and f(d)=3. Is f an onto function?
Solution: Because all three elements of the codomain are images of elements in the domain, we see that f is onto. This is illustrated in Figure 4. Note that if the codomain were {1,2,3,4}, then f would not be onto. ◀
Is the function f(x)=x2 from the set of integers to the set of integers onto?
Solution: The function f is not onto because there is no integer x with x2=−1, for instance. ◀
Is the function f(x)=x+1 from the set of integers to the set of integers onto?
Solution: This function is onto, because for every integer y there is an integer x such that f(x)=y. To see this, note that f(x)=y if and only if x+1=y, which holds if and only if x=y−1. ◀
Consider the function f in Example 11 that assigns jobs to workers. The function f is onto if for every job there is a worker assigned this job. The function f is not onto when there is at least one job that has no worker assigned it. ◀
![]() |
|---|
| FIGURE 5 — Examples of Different Types of Correspondences: (a) One-to-one, not onto; (b) Onto, not one-to-one; (c) One-to-one, and onto; (d) Neither one-to-one nor onto; (e) Not a function (Source: Page 144) |
Examples 16 and 17 illustrate the concept of a bijection.
Let f be the function from {a,b,c,d} to {1,2,3,4} with f(a)=4, f(b)=2, f(c)=1, and f(d)=3. Is f a bijection?
Solution: The function f is one-to-one and onto. It is one-to-one because no two values in the domain are assigned the same function value. It is onto because all four elements of the codomain are images of elements in the domain. Hence, f is a bijection. ◀
Figure 5 displays four functions where the first is one-to-one but not onto, the second is onto but not one-to-one, the third is both one-to-one and onto, and the fourth is neither one-to-one nor onto. The fifth correspondence in Figure 5 is not a function, because it sends an element to two different elements.
Suppose that f is a function from a set A to itself. If A is finite, then f is one-to-one if and only if it is onto. (This follows from the result in Exercise 72.) This is not necessarily the case if A is infinite (as will be shown in Section 2.5).
Let A be a set. The identity function on A is the function ιA:A→A, where ιA(x)=x for all x∈A. In other words, the identity function ιA is the function that assigns each element to itself. The function ιA is one-to-one and onto, so it is a bijection. (Note that ι is the Greek letter iota.) ◀
For future reference, we summarize what needs be to shown to establish whether a function is one-to-one and whether it is onto. It is instructive to review Examples 8–17 in light of this summary.
Now consider a one-to-one correspondence f from the set A to the set B. Because f is an onto function, every element of B is the image of some element in A. Furthermore, because f is also a one-to-one function, every element of B is the image of a unique element of A. Consequently, we can define a new function from B to A that reverses the correspondence given by f. This leads to Definition 9.
Figure 6 illustrates the concept of an inverse function.
If a function f is not a one-to-one correspondence, we cannot define an inverse function of f. When f is not a one-to-one correspondence, either it is not one-to-one or it is not onto. If f is not one-to-one, some element b in the codomain is the image of more than one element in the domain. If f is not onto, for some element b in the codomain, no element a in the domain exists for which f(a)=b. Consequently, if f is not a one-to-one correspondence, we cannot assign to each element b in the codomain a unique element a in the domain such that f(a)=b (because for some b there is either more than one such a or no such a).
A one-to-one correspondence is called invertible because we can define an inverse of this function. A function is not invertible if it is not a one-to-one correspondence, because the inverse of such a function does not exist.
![]() |
|---|
| FIGURE 6 — The Function f−1 Is the Inverse of Function f (Source: Page 145) |
Let f be the function from {a,b,c} to {1,2,3} such that f(a)=2, f(b)=3, and f(c)=1. Is f invertible, and if it is, what is its inverse?
Solution: The function f is invertible because it is a one-to-one correspondence. The inverse function f−1 reverses the correspondence given by f, so f−1(1)=c, f−1(2)=a, and f−1(3)=b. ◀
Let f:Z→Z be such that f(x)=x+1. Is f invertible, and if it is, what is its inverse?
Solution: The function f has an inverse because it is a one-to-one correspondence, as follows from Examples 10 and 14. To reverse the correspondence, suppose that y is the image of x, so that y=x+1. Then x=y−1. This means that y−1 is the unique element of Z that is sent to y by f. Consequently, f−1(y)=y−1. ◀
Let f be the function from R to R with f(x)=x2. Is f invertible?
Solution: Because f(−2)=f(2)=4, f is not one-to-one. If an inverse function were defined, it would have to assign two elements to 4. Hence, f is not invertible. (Note we can also show that f is not invertible because it is not onto.) ◀
Sometimes we can restrict the domain or the codomain of a function, or both, to obtain an invertible function, as Example 21 illustrates.
Show that if we restrict the function f(x)=x2 in Example 20 to a function from the set of all nonnegative real numbers to the set of all nonnegative real numbers, then f is invertible.
Solution: The function f(x)=x2 from the set of nonnegative real numbers to the set of nonnegative real numbers is one-to-one. To see this, note that if f(x)=f(y), then x2=y2, so x2−y2=(x+y)(x−y)=0. This means that x+y=0 or x−y=0, so x=−y or x=y. Because both x and y are nonnegative, we must have x=y. So, this function is one-to-one. Furthermore, f(x)=x2 is onto when the codomain is the set of all nonnegative real numbers, because each nonnegative real number has a square root. That is, if y is a nonnegative real number, there exists a nonnegative real number x such that x=y, which means that x2=y. Because the function f(x)=x2 from the set of nonnegative real numbers to the set of nonnegative real numbers is one-to-one and onto, it is invertible. Its inverse is given by the rule f−1(y)=y. ◀
In other words, f∘g is the function that assigns to the element a of A the element assigned by f to g(a). That is, to find (f∘g)(a) we first apply the function g to a to obtain g(a) and then we apply the function f to the result g(a) to obtain (f∘g)(a)=f(g(a)). Note that the composition f∘g cannot be defined unless the range of g is a subset of the domain of f. In Figure 7 the composition of functions is shown.
![]() |
|---|
| FIGURE 7 — The Composition of the Functions f and g (Source: Page 147) |
Let g be the function from the set {a,b,c} to itself such that g(a)=b, g(b)=c, and g(c)=a. Let f be the function from the set {a,b,c} to the set {1,2,3} such that f(a)=3, f(b)=2, and f(c)=1. What is the composition of f and g, and what is the composition of g and f?
Solution: The composition f∘g is defined by (f∘g)(a)=f(g(a))=f(b)=2, (f∘g)(b)=f(g(b))=f(c)=1,and(f∘g)(c)=f(g(c))=f(a)=3. Note that g∘f is not defined, because the range of f is not a subset of the domain of g. ◀
Let f and g be the functions from the set of integers to the set of integers defined by f(x)=2x+3 and g(x)=3x+2. What is the composition of f and g? What is the composition of g and f?
Solution: Both the compositions f∘g and g∘f are defined. Moreover, (f∘g)(x)=f(g(x))=f(3x+2)=2(3x+2)+3=6x+7 and (g∘f)(x)=g(f(x))=g(2x+3)=3(2x+3)+2=6x+11. ◀
When the composition of a function and its inverse is formed, in either order, an identity function is obtained. To see this, suppose that f is a one-to-one correspondence from the set A to the set B. Then the inverse function f−1 exists and is a one-to-one correspondence from B to A. The inverse function reverses the correspondence of the original function, so f−1(b)=a when f(a)=b, and f(a)=b when f−1(b)=a. Hence, (f−1∘f)(a)=f−1(f(a))=f−1(b)=a, and (f∘f−1)(b)=f(f−1(b))=f(a)=b. Consequently f−1∘f=ιA and f∘f−1=ιB, where ιA and ιB are the identity functions on the sets A and B, respectively. That is, (f−1)−1=f.
We can associate a set of pairs in A×B to each function from A to B. This set of pairs is called the graph of the function and is often displayed pictorially to aid in understanding the behavior of the function.
From the definition, the graph of a function f from A to B is the subset of A×B containing the ordered pairs with the second entry equal to the element of B assigned by f to the first entry. Also, note that the graph of a function f from A to B is the same as the relation from A to B determined by the function f, as described on page 139.
Display the graph of the function f(n)=2n+1 from the set of integers to the set of integers.
Solution: The graph of f is the set of ordered pairs of the form (n,2n+1), where n is an integer. This graph is displayed in Figure 8. ◀
Display the graph of the function f(x)=x2 from the set of integers to the set of integers.
Solution: The graph of f is the set of ordered pairs of the form (x,f(x))=(x,x2), where x is an integer. This graph is displayed in Figure 9. ◀
![]() | ![]() |
|---|---|
| FIGURE 8 — The Graph of f(n)=2n+1 from Z to Z (Source: Page 148) | FIGURE 9 — The Graph of f(x)=x2 from Z to Z (Source: Page 148) |
Next, we introduce two important functions in discrete mathematics, namely, the floor and ceiling functions. Let x be a real number. The floor function rounds x down to the closest integer less than or equal to x, and the ceiling function rounds x up to the closest integer greater than or equal to x. These functions are often used when objects are counted. They play an important role in the analysis of the number of steps used by procedures to solve problems of a particular size.
These are some values of the floor and ceiling functions: ⌊21⌋=0,⌈21⌉=1,⌊−21⌋=−1,⌈−21⌉=0, ⌊3.1⌋=3,⌈3.1⌉=4,⌊7⌋=7,⌈7⌉=7. ◀
We display the graphs of the floor and ceiling functions in Figure 10. In Figure 10(a) we display the graph of the floor function ⌊x⌋. Note that this function has the same value throughout the interval [n,n+1), namely n, and then it jumps up to n+1 when x=n+1. In Figure 10(b) we display the graph of the ceiling function ⌈x⌉. Note that this function has the same value throughout the interval (n,n+1], namely n+1, and then jumps to n+2 when x is a little larger than n+1.
![]() |
|---|
| FIGURE 10 — Graphs of the (a) Floor and (b) Ceiling Functions (Source: Page 149) |
The floor and ceiling functions are useful in a wide variety of applications, including those involving data storage and data transmission. Consider Examples 27 and 28, typical of basic calculations done when database and data communications problems are studied.
Data stored on a computer disk or transmitted over a data network are usually represented as a string of bytes. Each byte is made up of 8 bits. How many bytes are required to encode 100 bits of data?
Solution: To determine the number of bytes needed, we determine the smallest integer that is at least as large as the quotient when 100 is divided by 8, the number of bits in a byte. Consequently, ⌈100/8⌉=⌈12.5⌉=13 bytes are required. ◀
In asynchronous transfer mode (ATM) (a communications protocol used on backbone networks), data are organized into cells of 53 bytes. How many ATM cells can be transmitted in 1 minute over a connection that transmits data at the rate of 500 kilobits per second?
Solution: In 1 minute, this connection can transmit 500,000⋅60=30,000,000 bits. Each ATM cell is 53 bytes long, which means that it is 53⋅8=424 bits long. To determine the number of cells that can be transmitted in 1 minute, we determine the largest integer not exceeding the quotient when 30,000,000 is divided by 424. Consequently, ⌊30,000,000/424⌋=70,754 ATM cells can be transmitted in 1 minute over a 500 kilobit per second connection. ◀
Table 1, with x denoting a real number, displays some simple but important properties of the floor and ceiling functions. Because these functions appear so frequently in discrete mathematics, it is useful to look over these identities.
| Property | Description / Identity |
|---|---|
| (1a) | ⌊x⌋=n if and only if n≤x<n+1 |
| (1b) | ⌈x⌉=n if and only if n−1<x≤n |
| (1c) | ⌊x⌋=n if and only if x−1<n≤x |
| (1d) | ⌈x⌉=n if and only if x≤n<x+1 |
| (2) | x−1<⌊x⌋≤x≤⌈x⌉<x+1 |
| (3a) | ⌊−x⌋=−⌈x⌉ |
| (3b) | ⌈−x⌉=−⌊x⌋ |
| (4a) | ⌊x+n⌋=⌊x⌋+n |
| (4b) | ⌈x+n⌉=⌈x⌉+n |
(where n is an integer, x is a real number)
Each property in this table can be established using the definitions of the floor and ceiling functions. Properties (1a), (1b), (1c), and (1d) follow directly from these definitions. For example, (1a) states that ⌊x⌋=n if and only if the integer n is less than or equal to x and n+1 is larger than x. This is precisely what it means for n to be the greatest integer not exceeding x, which is the definition of ⌊x⌋=n. Properties (1b), (1c), and (1d) can be established similarly. We will prove property (4a) using a direct proof.
The floor and ceiling functions enjoy many other useful properties besides those displayed in Table 1. There are also many statements about these functions that may appear to be correct, but actually are not. We will consider statements about the floor and ceiling functions in Examples 29 and 30.
A useful approach for considering statements about the floor function is to let x=n+ϵ, where n=⌊x⌋ is an integer, and ϵ, the fractional part of x, satisfies the inequality 0≤ϵ<1. Similarly, when considering statements about the ceiling function, it is useful to write x=n−ϵ, where n=⌈x⌉ is an integer and 0≤ϵ<1.
Prove that if x is a real number, then ⌊2x⌋=⌊x⌋+⌊x+21⌋.
Solution: To prove this statement we let x=n+ϵ, where n is an integer and 0≤ϵ<1. There are two cases to consider, depending on whether ϵ is less than, or greater than or equal to 21. (The reason we choose these two cases will be made clear in the proof.)
We first consider the case when 0≤ϵ<21. In this case, 2x=2n+2ϵ and ⌊2x⌋=2n because 0≤2ϵ<1. Similarly, x+21=n+(21+ϵ), so ⌊x+21⌋=n, because 0<21+ϵ<1. Consequently, ⌊2x⌋=2n and ⌊x⌋+⌊x+21⌋=n+n=2n.
Next, we consider the case when 21≤ϵ<1. In this case, 2x=2n+2ϵ=(2n+1)+(2ϵ−1). Because 0≤2ϵ−1<1, it follows that ⌊2x⌋=2n+1. Because ⌊x+21⌋=⌊n+(21+ϵ)⌋=⌊n+1+(ϵ−21)⌋ and 0≤ϵ−21<1, it follows that ⌊x+21⌋=n+1. Consequently, ⌊2x⌋=2n+1 and ⌊x⌋+⌊x+21⌋=n+(n+1)=2n+1. This concludes the proof. ◀
Prove or disprove that ⌈x+y⌉=⌈x⌉+⌈y⌉ for all real numbers x and y.
Solution: Although this statement may appear reasonable, it is false. A counterexample is supplied by x=21 and y=21. With these values we find that ⌈x+y⌉=⌈21+21⌉=⌈1⌉=1, but ⌈x⌉+⌈y⌉=⌈21⌉+⌈21⌉=1+1=2. ◀
There are certain types of functions that will be used throughout the text. These include polynomial, logarithmic, and exponential functions. A brief review of the properties of these functions needed in this text is given in Appendix 2. In this book the notation logx will be used to denote the logarithm to the base 2 of x, because 2 is the base that we will usually use for logarithms. We will denote logarithms to the base b, where b is any real number greater than 1, by logbx, and the natural logarithm by lnx.
Another function we will use throughout this text is the factorial function f:N→Z+, denoted by f(n)=n!. The value of f(n)=n! is the product of the first n positive integers, so f(n)=1⋅2⋯(n−1)⋅n[and f(0)=0!=1].
We have f(1)=1!=1, f(2)=2!=1⋅2=2, f(6)=6!=1⋅2⋅3⋅4⋅5⋅6=720, and f(20)=1⋅2⋅3⋅4⋅5⋅6⋅7⋅8⋅9⋅10⋅11⋅12⋅13⋅14⋅15⋅16⋅17⋅18⋅19⋅20=2,432,902,008,176,640,000. ◀
Example 31 illustrates that the factorial function grows extremely rapidly as n grows. The rapid growth of the factorial function is made clearer by Stirling’s formula, a result from higher mathematics that tell us that n!∼2πn(en)n. Here, we have used the notation f(n)∼g(n), which means that the ratio f(n)/g(n) approaches 1 as n grows without bound (that is, limn→∞f(n)/g(n)=1). The symbol ∼ is read “is asymptotic to.” Stirling’s formula is named after James Stirling, a Scottish mathematician of the eighteenth century.
A program designed to evaluate a function may not produce the correct value of the function for all elements in the domain of this function. For example, a program may not produce a correct value because evaluating the function may lead to an infinite loop or an overflow. Similarly, in abstract mathematics, we often want to discuss functions that are defined only for a subset of the real numbers, such as 1/x, x, and arcsin(x). Also, we may want to use such notions as the “youngest child” function, which is undefined for a couple having no children, or the “time of sunrise,” which is undefined for some days above the Arctic Circle. To study such situations, we use the concept of a partial function.
The function f:Z→R where f(n)=n is a partial function from Z to R where the domain of definition is the set of nonnegative integers. Note that f is undefined for negative integers. ◀