In Section 6.1, we studied relations and one important operation on relations,
namely composition. This operation enables us to generate new relations from
previously known relations. In Section 6.3, we discussed some key properties
of relations. We now wish to consider the situation of constructing a new
relation*r*+_{from an existing relation}_{r}_{where, first,}* _{r}*+

_{contains}

_{r}_{and, second,}

*r*+ _{satisfies the transitive property.}

**6.5.1 Transitive Closure**

Consider a telephone network in which the main office*a*is connected to, and
can communicate to, individuals *b* and *c. Both* *b* and *c* can communicate
to another person, *d; however, the main office cannot communicate with* *d.*
Assume communication is only one way, as indicated. This situation can be
described by the relation *r* = *{*(a, b),(a, c),(b, d),(c, d)*}*. We would like to
change the system so that the main office*a*can communicate with person*d*and
still maintain the previous system. We, of course, want the most economical
system.

This can be rephrased as follows; Find the smallest relation*r*+ which con-
tains*r*as a subset and which is transitive;*r*+=*{*(a, b),(a, c),(b, d),(c, d),(a, d)*}*.
**Definition 6.5.1 Transitive Closure.** Let*A* be a set and*r* be a relation
on *A. The transitive closure of* *r, denoted by* *r*+_{, is the smallest transitive}

relation that contains*r*as a subset. ♢

Let *A* = *{*1,2,3,4*}*, and let *S* =*{*(1,2),(2,3),(3,4)*}* be a relation on *A.*
This relation is called the successor relation on*A*since each element is related
to its successor. How do we compute *S*+_{? By inspection we note that} _{(1,}_{3)}

must be in*S*+_{. Let’s analyze why. This is so because}_{(1,}_{2)}_{∈ S}_{and}_{(2,}_{3)}_{∈ S}_{,}

and the transitive property forces(1,3) to be in*S*+_{.}

In general, it follows that if(a, b)*∈ S*and(b, c)*∈S,*then(a, c)*∈ S*+_{. This}

condition is exactly the membership requirement for the pair (a, c) to be in
the composition*SS* =*S*2_{. So every element in} * _{S}*2

_{must be an element in}

*+*

_{S}. So we now know that, *S*+ _{contains at least} * _{S ∪ S}*2

_{. In particular, for this}

example, since*S* =*{*(1,2),(2,3),(3,4)*}*and*S*2_{=}_{{}_{(1,}_{3),}_{(2,}_{4)}_{}}_{, we have}

*S ∪ S*2_{=}_{{}_{(1,}_{2),}_{(2,}_{3),}_{(3,}_{4),}_{(1,}_{3),}_{(2,}_{4)}_{}}

Is the relation *S ∪ S*2 _{transitive? Again, by inspection,} _{(1,}_{4)} _{is not an}

element of *S ∪ S*2_{, but}_{(1,}_{3)}* _{∈ S}*2

_{and}

_{(3,}

_{4)}

_{∈ S}_{. Therefore, the composition}

CHAPTER 6. RELATIONS 128

(3,4)are required to be in *S*+_{. This shows that}* _{S}*3

*+*

_{⊆ S}_{. This process must}

be continued until the resulting relation is transitive. If*A* is finite, as is true
in this example, the transitive closure will be obtained in a finite number of
steps. For this example,

*S*+_{=}* _{S ∪ S}*2

*3*

_{∪ S}_{=}

_{{}_{(1,}

_{2),}

_{(2,}

_{3),}

_{(3,}

_{4),}

_{(1,}

_{3),}

_{(2,}

_{4),}

_{(1,}

_{4)}

_{}}**Theorem 6.5.2 Transitive Closure on a Finite Set.** *Ifris a relation on*
*a setAand|A|*=*n, then the transitive closure of* *ris the union of the first* *n*
*powers of r. That is,*

*r*+=*r∪r*2*∪r*3*∪ · · · ∪rn.*

Let’s now consider the matrix analogue of the transitive closure. Consider the relation

*r*=*{*(1,4),(2,1),(2,2),(2,3),(3,2),(4,3),(4,5),(5,1)*}*
on the set*A*=*{*1,2,3,4,5*}*. The matrix of*r*is

*R*=
0 0 0 1 0
1 1 1 0 0
0 1 0 0 0
0 0 1 0 1
1 0 0 0 0

Recall that *r*2* _{, r}*3

_{, . . .}_{can be determined through computing the matrix}

powers*R*2* _{, R}*3

_{, . . .. For our example,}*R*2=
0 0 1 0 1
1 1 1 1 0
1 1 1 0 0
1 1 0 0 0
0 0 0 1 0
*R*
3_{=}
1 1 0 0 0
1 1 1 1 1
1 1 1 1 0
1 1 1 1 0
0 0 1 0 1
*R*4=
1 1 1 1 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 0 0 0
*R*
5_{=}
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 0
**Table 6.5.3**
How do we relate *∪*5
*i*=1*r*
*i* _{to the powers of}_{R?}

**Theorem 6.5.4 Matrix of a Transitive Closure.** *Let* *r* *be a relation on*
*a finite set and letR*+ _{be the matrix of}* _{r}*+

_{, the transitive closure of}_{r. Then}*R*+=*R*+*R*2+*· · ·*+*Rn, using Boolean arithmetic.*

Using this theorem, we find *R*+ _{is the} _{5}_{×}_{5} _{matrix consisting of all} _{1}*′ _{s,}*

thus,*r*+ _{is all of}_{A}_{×}_{A.}

**6.5.2 Algorithms for computing transitive closure**

Let*r*be a relation on the set*{*1,2, . . . , n*}*with relation matrix*R. The matrix*
of the transitive closure*R*+, can be computed by the equation*R*+=*R*+*R*2+

*· · ·*+*Rn*_{. By using ordinary polynomial evaluation methods, you can compute}

*R*+ _{with}_{n}_{−}_{1}_{matrix multiplications:}

CHAPTER 6. RELATIONS 129
For example, if *n*= 3,*R*+_{=}_{R(I}_{+}_{R(I}_{+}_{R)).}

We can make use of the fact that if*T* is a relation matrix,*T*+*T* =*T* due
to the fact that1 + 1 = 1in Boolean arithmetic. Let*Sk* =*R*+*R*2+*· · ·*+*Rk*.

Then
*R*=*S*1
*S*1(I+*S*1) =*R(I*+*R) =R*+*R*2=*S*2
*S*2(I+*S*2) = (R+*R*2)(I+*R*+*R*2)
= (R+*R*2) + (R2+*R*3) + (R3+*R*4)
=*R*+*R*2+*R*3+*R*4=*S*4
.
Similarly,
*S*4(I+*S*4) =*S*8

and by induction we can prove

*S*2*k*(I+*S*_{2}*k*) =*S*_{2}*k*+1

Notice how each matrix multiplication doubles the number of terms that
have been added to the sum that you currently have computed. In algorithmic
form, we can compute*R*+ as follows.

**Algorithm 6.5.5** **Transitive Closure Algorithm.** *Let* *R* *be a relation*
*matrix and letR*+ _{be its transitive closure matrix, which is to be computed as}

*matrixT*

1.0. S = R 2.0 T = S *( I + S) 3.0 While T != S

3.1 S = T

3.2 T= S *( I+ S) // using Boolean arithmetic 4.0 Return T

**Listing 6.5.6**

**Note 6.5.7**

• Often the higher-powered terms in*Sn*do not contribute anything to*R*+.

When the condition*T* =*S* becomes true in Step 3, this is an indication
that no higher-powered terms are needed.

• To compute*R*+ _{using this algorithm, you need to perform no more than}

*⌈*log_{2}*n⌉* matrix multiplications, where *⌈x⌉* is the least integer that is
greater than or equal to*x. For example, ifr*is a relation on 25 elements,
no more than*⌈*log_{2}25*⌉*= 5matrix multiplications are needed.

A second algorithm, Warshall’s Algorithm, reduces computation time to the time that it takes to multiply two square matrices with the same order as the relation matrix in question.

**Algorithm 6.5.8 Warshall’s Algorithm.** *LetRbe ann×nrelation matrix*
*and letR*+ *be its transitive closure matrix, which is to be computed as matrix*
*T* *using Boolean arithmetic*

CHAPTER 6. RELATIONS 130
1.0 T = R
2.0 for k = 1 to n :
for i = 1 to n :
for j = 1 to n:
T [i ,j ]= T[i ,j] + T [i ,k ] * T[k , j ]
3.0 Return T
**Listing 6.5.9**

**6.5.3 Exercises for Section 6.5**

**1.** Let*A*=*{*0,1,2,3,4*}*and*S*=*{*(0,1),(1,3),(2,3),(3,4),(4,1)*}*. Compute

*S*+ _{using the matrix representation of} _{S}_{. Verify your results by check-}

ing against the result obtained directly from the definition of transitive closure.

**2.** Let*A*=*{*1,2,3,4,6,12*}*and*t*=*{*(a, b)*|b/a*is a prime number*}*. Deter-
mine*t*+ _{by any means. Represent your answer as a matrix.}

**3.**

(a) Draw digraphs of the relations*S*,*S*2_{,}* _{S}*3

_{, and}

*+*

_{S}_{where}

_{S}_{is defined}

in the first exercise above.

(b) Verify that in terms of the graph of *S*, *aS*+_{b}_{if and only if} _{b}_{is}

reachable from*a*along a path of any finite nonzero length.
**4.** Let*r* be the relation represented by the following digraph.

(a) Find *r*+ _{using the definition based on order pairs.}

(b) Determine the digraph of*r*+ _{directly from the digraph of}_{r.}

(c) Verify your result in part (b) by computing the digraph from your result in part (a).

CHAPTER 6. RELATIONS 131
**5.**

(a) Define reflexive closure and symmetric closure by imitating the de- finition of transitive closure.

(b) Use your definitions to compute the reflexive and symmetric closures of examples in the text.

(c) What are the transitive reflexive closures of these examples?
(d) Convince yourself that the reflexive closure of the relation*<*on the

set of positive integersPis*≤*.

**6.** What common relations on Zare the transitive closures of the following
relations?

(a) *aSb*if and only if *a*+ 1 =*b.*
(b) *aRb*if and only if*|a−b|*= 2.
**7.**

(a) Let *A*be any set and*r*a relation on*A, prove that*(r+_{)}+_{=}* _{r}*+

_{.}

(b) Is the transitive closure of a symmetric relation always both sym- metric and reflexive? Explain.

**8.** The definition of theTransitive Closureof*r*refers to the “smallest transi-
tive relation that contains*r*as a subset.” Show that the intersection of all
transitive relations on*A* containing*r*is a transitive relation containing*r*
and is precisely*r*+_{.}

**Chapter 7**

**Functions**

**countably infinite**

A countably infinite set
Is as simple as things like this get. Just start counting at 1,

Then continue—it’s fun!

I’ll check back when you’re done, so don’t sweat.

*Chris Doyle, The Omnificent English Dictionary In Limerick Form*

In this chapter we will consider some basic concepts of the relations that are called functions. A large variety of mathematical ideas and applications can be more completely understood when expressed through the function concept.

**7.1 Definition and Notation**

**7.1.1 Fundamentals**

**Definition 7.1.1 Function.** A function from a set*A*into a set*B*is a relation
from*A* into *B* such that each element of*A* is related to exactly one element
of the set*B. The setA*is called the**domain**of the function and the set*B* is

called the**codomain.** ♢

The reader should note that a function*f* is a relation from*A*into *B* with
two important restrictions:

• Each element in the set *A, the domain of* *f*, must be related to some
element of *B, the codomain.*

• The phrase “is related to exactly one element of the set *B” means that*
if(a, b)*∈f* and(a, c)*∈f*, then*b*=*c.*

**Example 7.1.2 A function as a list of ordered pairs.** Let*A*=*{−*2,*−*1,0,1,2*}*
and*B* =*{*0,1,2,3,4*}*, and if *s*=*{*(*−*2,4),(*−*1,1),(0,0),(1,1),(2,4)*}*, then*s*

is a function from*A*into*B.* □

**Example 7.1.3 A function as a set of ordered pairs in set-builder**
**notation.** Let R be the real numbers. Then *L* = *{*(x,3x) *|* *x* *∈* R*}* is a
function fromRintoR, or, more simply,*L*is a function onR. □

CHAPTER 7. FUNCTIONS 133
It is customary to use a different system of notation for functions than the one
we used for relations. If*f* is a function from the set*A*into the set*B*, we will
write*f* :*A→B.*

The reader is probably more familiar with the notation for describing func-
tions that is used in basic algebra or calculus courses. For example, *y*= 1* _{x}* or

*f*(x) =

*1 both define the function {(*

_{x}*x,*1

*)*

_{x}*x∈*R

*, x̸*= 0}. Here the domain was assumed to be those elements ofRwhose substitutions for

*x*make sense, the nonzero real numbers, and the codomain was assumed to be R. In most cases, we will make a point of listing the domain and codomain in addition to describing what the function does in order to define a function.

The terms **mapping,** **map, and** **transformation**are also used for func-
tions.

**Definition 7.1.4 The Set of Functions Between Two Sets.** Given two
sets,*A*and*B, the set of all function from A into B is denoted* *BA*_{.} _{♢}

The notation used for sets of functions makes sense in light of Exercise 7. One way to imagine a function and what it does is to think of it as a machine. The machine could be mechanical, electronic, hydraulic, or abstract. Imagine that the machine only accepts certain objects as raw materials or input. The possible raw materials make up the domain. Given some input, the machine produces a finished product that depends on the input. The possible finished products that we imagine could come out of this process make up the codomain.

**Example 7.1.5 A definition based on images.** We can define a function
based on specifying the codomain element to which each domain element is re-
lated. For example,*f* :R*→*Rdefined by*f*(x) =*x*2is an alternate description

of*f* ={(*x, x*2)*x∈*R}. □

**Definition 7.1.6 Image of an element under a function.** Let*f* :*A→B,*
read “Let*f* be a function from the set*A* into the set*B.” Ifa∈A, then* *f*(a)
is used to denote that element of *B* to which*a* is related. *f*(a) is called the
**image**of*a, or, more precisely, the image ofa*under *f*. We write*f(a) =b*to

indicate that the image of*a*is*b.* ♢

In Example 7.1.5, the image of 2 under *f* is 4; that is, *f*(2) = 4. In
Example 7.1.2, the image of*−*1 under*s*is 1; that is,*s(−*1) = 1.

**Definition 7.1.7 Range of a Function.** The range of a function is the set
of images of its domain. If*f* :*X* *→Y*, then the range of*f* is denoted*f*(X),
and

*f*(X) =*{f*(a)*|a∈X}*=*{b∈Y* *| ∃a∈X* such that*f*(a) =*b}*.
♢
Note that the range of a function is a subset of its codomain. *f*(X)is also
read as “the image of the set*X* under the function*f*” or simply “the image of
*f*.”

In Example 7.1.2,*s(A) =* *{*0,1,4*}*. Notice that 2 and 3 are not images of
any element of*A. In addition, note that both 1 and 4 are related to more than*
one element of the domain: *s(1) =* *s(−*1) = 1 and *s(2) =* *s(−*2) = 4. This
does not violate the definition of a function. Go back and read the definition
if this isn’t clear to you.

InExample 7.1.3, the range of*L*is equal to its codomain,R. If*b*is any real
number, we can demonstrate that it belongs to*L(*R)by finding a real number

CHAPTER 7. FUNCTIONS 134

*x*for which*L(x) =b. By the definition ofL,L(x) = 3x, which leads us to the*
equation3x=*b. This equation always has a solution,* *b*

3; thus*L(*R) =R.

The formula that we used to describe the image of a real number under
*L,* *L(x) = 3x, is preferred over the set notation forL*due to its brevity. Any
time a function can be described with a rule or formula, we will use this form
of description. InExample 7.1.2, the image of each element of*A*is its square.
To describe that fact, we write *s(a) =* *a*2 (a*∈A), or* *S* :*A* *→B* defined by
*S(a) =a*2.

There are many ways that a function can be described. Many factors, such as the complexity of the function, dictate its representation.

**Example 7.1.8 Data as a function.** Suppose a survey of 1,000 persons is
done asking how many hours of television each watches per day. Consider the
function*W* :*{*0,1, . . . ,24*} → {*0,1,2, . . . ,1000*}*defined by

*W*(t) =the number of persons who gave a response of*t* hours

This function will probably have no formula such as the ones for*s*and*L*above.
□
**Example 7.1.9** **Conditional definition of a function.** Consider the
function*m*:P*→*Qdefined by the set

*m*=*{*(1,1),(2,1/2),(3,9),(4,1/4),(5,25), ...*}*

No simple single formula could describe*m, but if we assume that the pattern*
given continues, we can write

*m(x) =*

{

*x*2 _{if}_{x}_{is odd}

1/x if*x*is even

□

**7.1.2 Functions of Two Variables**

If the domain of a function is the Cartesian product of two sets, then our
notation and terminology changes slightly. For example, consider the function
*C* : N*×*N *→* N defined by *C*((n1*, n*2)) = *n*21 +*n*

2

2*−n*1*n*2+ 10. For this

function, we would drop one set of parentheses and write *C(4,*2) = 22, not
*C((4,*2)) = 22. We call*C* a function of two variables. From one point of view,
this function is no different from any others that we have seen. The elements
of the domain happen to be slightly more complicated. On the other hand, we
can look at the individual components of the ordered pairs as being separate.
If we interpret*C*as giving us the cost of producing quantities of two products,
we can imagine varying*n*1 while*n*2is fixed, or vice versa.

**7.1.3 SageMath Note**

There are several ways to define a function in Sage. The simplest way to
implement*f* is as follows.

f( x) = x ^2 f

x |- -> x ^2 [f (4) ,f (1.2) ]

CHAPTER 7. FUNCTIONS 135

[16 ,1.44000000000000]

Sage is built upon the programming language Python, which is a*strongly typed*
*language*and so you can’t evaluate expressions such asf('Hello'). However a
function such as*f*, as defined above, will accept any type of number, so a bit
more work is needed to restrict the inputs of*f* to the integers.

A second way to define a function in Sage is based on Python syntax.

**def** fa (x ):

**return** x ^2
[ fa (2) , fa (1.2) ]
[16 ,1.44000000000000]

**7.1.4 Non-Functions**

We close this section with two examples of relations that are not functions.
**Example 7.1.10** **A non-function.** Let *A* = *B* = *{*1,2,3*}* and let *f* =

*{*(1,2),(2,3)*}*. Here*f* is not a function from*A*into*B* since*f* does not act on,

or “use,” all elements of*A.* □

**Example 7.1.11 Another non-function.** Let*A* =*B* =*{*1,2,3*}* and let
*g* =*{*(1,2),(2,3),(2,1),(3,2)*}*. We note that *g* acts on all of *A. However,* *g*
is still not a function since(2,3)*∈g* and(2,1)*∈g* and the condition on each
domain being related to exactly one element of the codomain is violated. □

**7.1.5 Exercises for Section 7.1**

**1.** Let*A*=*{*1,2,3,4*}*and*B* =*{a, b, c, d}*. Determine which of the following
are functions. Explain.

(a) *f* *⊆A×B, where* *f* =*{*(1, a),(2, b),(3, c),(4, d)*}*.
(b) *g⊆A×B, where* *g*=*{*(1, a),(2, a),(3, b),(4, d)*}*.
(c) *h⊆A×B, whereh*=*{*(1, a),(2, b),(3, c)*}*.

(d) *k⊆A×B, wherek*=*{*(1, a),(2, b),(2, c),(3, a),(4, a)*}*.
(e) *L⊆A×A, whereL*=*{*(1,1),(2,1),(3,1),(4,1)*}*.

**2.** Let *A* be a set and let *S* be any subset of *A. Let* *χS* : *A* *→ {*0,1*}* be

defined by

*χS*(x) =

{

1 if*x∈S*
0 if*x∈*/*S*

The function*χS* is called the**characteristic function**of*S.*

(a) If*A*=*{a, b, c}*and*S*=*{a, b}*, list the elements of*χS* .

(b) If*A*=*{a, b, c, d, e}*and*S*=*{a, c, e}*, list the elements of*χS*.

(c) If*A*=*{a, b, c}*, what are *χ _{∅}* and

*χA*?

**3.** Find the ranges of each of the relations that are functions in Exercise 1.
**4.** Find the ranges of the following functions onZ:

CHAPTER 7. FUNCTIONS 136
(a) *g*=*{*(x,4x+ 1)*|x∈*Z*}*.

(b) *h(x) =*the least integer that is greater than or equal to√*|x|*.
(c) *P*(x) =*x*+ 10.

**5.** Let*f* :P*→*P, where*f*(a)is the largest power of two that evenly divides*a;*
for example,*f*(12) = 4, f(9) = 1,andf(8) = 8. Describe the equivalence
classes of the kernel of*f*.

**6.** Let*U* be a set with subsets*A*and*B.*

(a) Show that *g* :*U* *→ {*0,1*}* defined by*g(a) =*min(C*A*(a), C*B*(a))is

the characteristic function of*A∩B.*

(b) What characteristic function is *h* : *U* *→ {*0,1*}* defined by *h(a) =*
max(C*A*(a), C*B*(a))?

(c) How are the characteristic functions of*A*and*Ac* related?

**7.** If*A*and*B* are finite sets, how many different functions are there from*A*
into*B?*

**8.** Let*f* be a function with domain*A*and codomain*B. Consider the relation*
*K* *⊆* *A×A* defined on the domain of *f* by (x, y) *∈* *K* if and only if
*f*(x) =*f*(y). The relation*K* is called \textit{ the kernel of f}.

(a) Prove that *K*is an equivalence relation.

(b) For the specific case of *A* = Z, where Z is the set of integers, let
*f* :Z*→*Zbe defined by*f*(x) =*x*2. Describe the equivalence classes
of the kernel for this specific function.