Closure Operations on Relations

In document Applied Discrete Structures (Page 141-150)

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 relationr+from an existing relationrwhere, first,r+containsrand, second,

r+ satisfies the transitive property.

6.5.1 Transitive Closure

Consider a telephone network in which the main officeais 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 officeacan communicate with persondand still maintain the previous system. We, of course, want the most economical system.

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

relation that containsras 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 onAsince each element is related to its successor. How do we compute S+? By inspection we note that (1,3)

must be inS+. Let’s analyze why. This is so because(1,2)∈ Sand(2,3)∈ S,

and the transitive property forces(1,3) to be inS+.

In general, it follows that if(a, b)∈ Sand(b, c)∈S,then(a, c)∈ S+. This

condition is exactly the membership requirement for the pair (a, c) to be in the compositionSS =S2. So every element in S2 must be an element inS+

. So we now know that, S+ contains at least S ∪ S2 . In particular, for this

example, sinceS ={(1,2),(2,3),(3,4)}andS2={(1,3),(2,4)}, we have

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

Is the relation S ∪ S2 transitive? Again, by inspection, (1,4) is not an

element of S ∪ S2, but(1,3)∈ S2 and(3,4)∈ S. Therefore, the composition


(3,4)are required to be in S+. This shows thatS3⊆ S+. This process must

be continued until the resulting relation is transitive. IfA 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 ∪ S2∪ S3={(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∪r2∪r3∪ · · · ∪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 setA={1,2,3,4,5}. The matrix ofris

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 r2, r3, . . . can be determined through computing the matrix

powersR2, R3, . . .. For our example,

R2=       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       R4=       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=1r i to the powers ofR?

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 ofr. Then

R+=R+R2+· · ·+Rn, using Boolean arithmetic.

Using this theorem, we find R+ is the 5×5 matrix consisting of all 1s,

thus,r+ is all ofA×A.

6.5.2 Algorithms for computing transitive closure

Letrbe a relation on the set{1,2, . . . , n}with relation matrixR. The matrix of the transitive closureR+, can be computed by the equationR+=R+R2+

· · ·+Rn. By using ordinary polynomial evaluation methods, you can compute

R+ withn1matrix multiplications:

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

We can make use of the fact that ifT is a relation matrix,T+T =T due to the fact that1 + 1 = 1in Boolean arithmetic. LetSk =R+R2+· · ·+Rk.

Then R=S1 S1(I+S1) =R(I+R) =R+R2=S2 S2(I+S2) = (R+R2)(I+R+R2) = (R+R2) + (R2+R3) + (R3+R4) =R+R2+R3+R4=S4 . Similarly, S4(I+S4) =S8

and by induction we can prove

S2k(I+S2k) =S2k+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 computeR+ 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


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 inSndo not contribute anything toR+.

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

• To computeR+ using this algorithm, you need to perform no more than

log2n⌉ matrix multiplications, where ⌈x⌉ is the least integer that is greater than or equal tox. For example, ifris a relation on 25 elements, no more thanlog225= 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. LetA={0,1,2,3,4}andS={(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. LetA={1,2,3,4,6,12}andt={(a, b)|b/ais a prime number}. Deter- minet+ by any means. Represent your answer as a matrix.


(a) Draw digraphs of the relationsS,S2,S3, andS+whereSis 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 fromaalong a path of any finite nonzero length. 4. Letr be the relation represented by the following digraph.

(a) Find r+ using the definition based on order pairs.

(b) Determine the digraph ofr+ directly from the digraph ofr.

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


(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) aSbif and only if a+ 1 =b. (b) aRbif and only if|a−b|= 2. 7.

(a) Let Abe any set andra relation onA, 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 Closureofrrefers to the “smallest transi- tive relation that containsras a subset.” Show that the intersection of all transitive relations onA containingris a transitive relation containingr and is preciselyr+.

Chapter 7


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 setAinto a setBis a relation fromA into B such that each element ofA is related to exactly one element of the setB. The setAis called thedomainof the function and the setB is

called thecodomain.

The reader should note that a functionf is a relation fromAinto 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, thenb=c.

Example 7.1.2 A function as a list of ordered pairs. LetA={−2,1,0,1,2} andB ={0,1,2,3,4}, and if s={(2,4),(1,1),(0,0),(1,1),(2,4)}, thens

is a function fromAintoB.

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,Lis 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. Iff is a function from the setAinto the setB, we will writef :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= 1x or f(x) = x1 both define the function {(x,1x)x∈R, x̸= 0}. Here the domain was assumed to be those elements ofRwhose substitutions for xmake 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 transformationare also used for func- tions.

Definition 7.1.4 The Set of Functions Between Two Sets. Given two sets,AandB, 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 :RRdefined byf(x) =x2is an alternate description

off ={(x, x2)x∈R}. □

Definition 7.1.6 Image of an element under a function. Letf :A→B, read “Letf be a function from the setA into the setB.” Ifa∈A, then f(a) is used to denote that element of B to whicha is related. f(a) is called the imageofa, or, more precisely, the image ofaunder f. We writef(a) =bto

indicate that the image ofaisb.

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 of1 undersis 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. Iff :X →Y, then the range off is denotedf(X), and

f(X) ={f(a)|a∈X}={b∈Y | ∃a∈X such thatf(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 setX under the functionf” 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 ofA. 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 ofLis equal to its codomain,R. Ifbis any real number, we can demonstrate that it belongs toL(R)by finding a real number


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

3; thusL(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 forLdue 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 ofAis its square. To describe that fact, we write s(a) = a2 (a∈A), or S :A →B defined by S(a) =a2.

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 functionW :{0,1, . . . ,24} → {0,1,2, . . . ,1000}defined by

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

This function will probably have no formula such as the ones forsandLabove. □ Example 7.1.9 Conditional definition of a function. Consider the functionm:PQdefined by the set

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

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

m(x) =


x2 ifxis odd

1/x ifxis 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, n2)) = n21 +n


2−n1n2+ 10. For this

function, we would drop one set of parentheses and write C(4,2) = 22, not C((4,2)) = 22. We callC 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 interpretCas giving us the cost of producing quantities of two products, we can imagine varyingn1 whilen2is fixed, or vice versa.

7.1.3 SageMath Note

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

f( x) = x ^2 f

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


[16 ,1.44000000000000]

Sage is built upon the programming language Python, which is astrongly typed languageand so you can’t evaluate expressions such asf('Hello'). However a function such asf, as defined above, will accept any type of number, so a bit more work is needed to restrict the inputs off 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)}. Heref is not a function fromAintoB sincef does not act on,

or “use,” all elements ofA.

Example 7.1.11 Another non-function. LetA =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. LetA={1,2,3,4}andB ={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 ifx∈S 0 ifx∈/S

The functionχS is called thecharacteristic functionofS.

(a) IfA={a, b, c}andS={a, b}, list the elements ofχS .

(b) IfA={a, b, c, d, e}andS={a, c, e}, list the elements ofχS.

(c) IfA={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. Letf :PP, wheref(a)is the largest power of two that evenly dividesa; for example,f(12) = 4, f(9) = 1,andf(8) = 8. Describe the equivalence classes of the kernel off.

6. LetU be a set with subsetsAandB.

(a) Show that g :U → {0,1} defined byg(a) =min(CA(a), CB(a))is

the characteristic function ofA∩B.

(b) What characteristic function is h : U → {0,1} defined by h(a) = max(CA(a), CB(a))?

(c) How are the characteristic functions ofAandAc related?

7. IfAandB are finite sets, how many different functions are there fromA intoB?

8. Letf be a function with domainAand codomainB. 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 relationK is called \textit{ the kernel of f}.

(a) Prove that Kis an equivalence relation.

(b) For the specific case of A = Z, where Z is the set of integers, let f :ZZbe defined byf(x) =x2. Describe the equivalence classes of the kernel for this specific function.

In document Applied Discrete Structures (Page 141-150)