6. Relations When we were talking about logic earlier we considered predicates. These were rules (or functions) that took one or more objects and returned a value of true or false depending on whether or not the object(s) had some property or were related in some fashion. Consider, for example, the "Is-the capital-of" predicate. true false "Is-the-capital-of"(x, y) = if x is the capital of y if x is not the capital of y For example, "Is-the-capital-of"(Lansing, Michigan) = true "Is-the-capital-of"(Detroit, Michigan) = false When we talked about predicates they were used in forming statements that could be classified as true or false. In this chapter we are going to be looking at predicates again. However, now they are called relations, and we shall be looking at two special types of relations, namely equivalence relations and partial orderings. 6.1 Equivalence Relations In this section we shall be looking at equivalence relations. These are generalizations of equality. An equivalence relation determines whether two objects are the same in some respect or have some common property. Before giving the precise definition, let's look at some examples. p Example 1. Fractions. A fraction q is the ratio of two integers with a non-zero 1 2 3 denominator q. For example, 2, 4 and 4 are typical fractions. Note that we would 1 2 usually write 2 = 4. What we mean is that we think of them as representing the same 1 number. Technically speaking they are different objects. For example, 2 might represent 2 cutting a pie in two equal pieces and taking one while 4 might represent cutting a pie in four equal pieces and taking two. The fact that we end up with the same amount of pie in 2 2 p n both cases is why we often think of 4 and 4 as the same. In general two fractions q and m represent the same number if pm = qm. The reason for this is the following. Consider the following four senarios. 6.1 - 1 i. Think of cutting a pie into q pieces and taking p of them. This is represented by p the fraction q. ii. Now take an identical pie and cut it into qm pieces and take pm pieces. This is pm represented by the fraction qm. We get the same amount of pie as in the first case. p pm So q should be equal to qm. iii. Again, take an identical pie and cut it into m pieces and taking n of them. This is n represented by the fraction m. iv. Finally, take an identical pie and cut it into qm pieces and take qn pieces. This is qn represented by the fraction qm. We get the same amount of pie as in the third case. n qn So m should be equal to qm. Now compare the the second and fourth cases. In both of these cases we have cut the pie into qm pieces. We will get the same amount of pie if pm = qn. So we are led to the p n conclusion that q and m represent the same number if pm = qn. p n p n We write q = m if pm = qn, although we don't mean q and m are the same object. For 2 3 example 4 = 6. Example 2. Equivalent logical expressions. A logical expression is a combination of logical variables (e.g. p, q, etc), logical operations (e.g. and, or, not, etc.), logical constants (0 and 1) and parentheses. For example, (pq)', p' + q' and p q are logical expressions. Two logical expressions are equivalent if they have the same truth table. For example, (pq)' and p' + q' are equivalent since their truth tables are the p q pq (pq)' p' q' p' + q' same. We have been writing 0 0 0 1 1 1 1 (pq)' = p' + q' to indicate that they are 0 1 0 1 1 0 1 equivalent. 1 0 0 1 0 1 1 1 1 1 0 0 0 0 Example 3. Numbers congruent mod 12. Earlier we have seen several situations where we mod the result of an arithemetic calculation by some number p to get the final result. In this case, during the calculation we can replace any number by another number that has the same remainder when we divide by p. In this context the two numbers are equivalent. 6.1 - 2 To make this concrete, let's suppose p = 12. Thus we are working with numbers on a clock. We say two integers n and m are equivalent mod 12 if they have the same remainder when we divide by 12, i.e. n mod 12 = m mod 12. Let's write n m if this is the case. For example 15 27 since both have a remainder 3 when we divide by 12. In terms of clocks, the clock reads the same if 15 hours pass as if 27 hours pass. However, 15 / 29 since 15 has remainder 3 when we divide by 12 and 29 has a remainder 5 when we divide by 12. The clock does not read the same if 15 hours pass as if 29 hours pass. Equivalence mod 12 is another example of an equivalence relation. Example 4. for expressions. Earlier when we were comparing algorithms we defined what it meant for two expressions to be of the same order as n . If Sn and Tn are two S expressions involving n and 0 < lim Tn < then they are of the same order as n and n n we write Sn = (Tn). For example, n2 + 3n + 2 = (n2), but n (n2). Being of the same order is another example of an equivalence relation. Example 5. Congruence for Triangles. Recall, two triangles ABC and DEF are congruent if corresponding angles are equal and the lengths of corresponding sides are __ __ __ __ __ __ __ equal, i.e. A = D, B = E, C = F, AB = DE, BC = EF and CA = FD. Here AB denotes the length of the line segment joining A and B. Congruence of triangles is another example of an equivalence relation. Example 6. Similarity for Triangles. Recall, two triangles ABC and DEF are similar if corresponding angles are equal and the lengths of pairs of corresponding sides __ __ __ __ __ __ are proportional, i.e. A = D, B = E, C = F and AB/DE = BC/EF = CA/FD. Similarity of triangles is another example of an equivalence relation. Example 7. Same number of elements for sets. In some situations we consider two sets A and B as equivalent if they have the same number of elements. Let's write A B if A and B have the same number of elements. For example, {a, b, c} {e, f, g} but {a, b, c} / {e, f}. This is also an equivalence relation. Example 8. Have the same two parents. We say two people are siblings in the strong sense if both parents are the same. This is an equivalence relation. Example 9. Give the same output for the same input. We say two C++ functions are equivalent if they return the same value if they are given the same arguments. People reflecting on examples such have these decided that all these relations had three things in common and these three things are what constitutes an equivalence relation. 6.1 - 3 Definition 1. A relation is an equivalence relation if it has the following three properties. i. It is transitive ii. It is symmetric iii. It is reflexive A relation is transitive if whenever one has both a b and b c then one also has a c. A relation is symmetric if whenever one has a b then one also has b a. A relation is reflexive if a a for every object a. Let's see how these definitions work for our two examples above. p n Example 1. Fractions. In this case q = m means pm = nq. Let's show this is transitive. p n n r Suppose q = m and m = s. Then pm = nq and ns = mr. If we multiply the first by s and the second by q we get pms = nqs and nqs = mqr. So pms = mqr. Dividing by m gives p r ps = qr. So q = s . This shows the relation is transitive. Now let's show it is symmetric. p n n p We must show q = m implies m = q . The first implies pm = nq and to show the second we need nq = pm. However, these are the same so the relation is symmetric. Finally to show p p reflexive, we must show q = q . To show this we must show pq = pq. Since this is true the relation is reflexive. So equality for fractions meets the three requirements of an equivalence relation. 6.1 - 4