Relations I Margaret M. Fleck 7 November 2008 This lecture covers relations and basic properties of relations, which is most of section 8.1 of Rosen. 1 Announcements Model solutions for the second midterm will be posted as soon as we finish doing makeup exams, which will probably be mid next week. 2 Relations Suppose that A and B are sets. A relation from A to B is a subset of A B. That is, it s a set of ordered pairs (a, b) where a A and b B. For example, suppose that A is a set of US states and B is the set of US political parties. We could create a relation S that associates each state with the parties of its senators. So S would contain the pair (Illinois, Democrat) since both of our senators are democrats. And it contains (Utah, Republican) because they have two Republican senators. Notice that S isn t a function. Iowa has one senator of each party. So S must contain both the pairs (Iowa, Democrat) and (Iowa, Republican). A relation from A to B can associate an element of A with multiple elements of B, or no elements of B. For example, we could extend our set A to include the District of Columbia, even though it doesn t have a senator. 1
Relations are a very general construct, which unifies a wide range of examples that probably don t look very similar to you. In fact, much of the time, we will be looking at one or another special type of relation. 3 Functions and relations Functions are one special case of relations. For example, suppose we want to associate each state with its capital. We can describe this as a relation F from the set of US states (A) to the set of US cities (C) So F is a set containing pairs like (Massachusetts, Boston) and (Iowa, Des Moines). In this case, the relation happens to associate each state with exactly one city. So we can also describe C as a function from A to C. You can formally define a function from A to B as a relation from A to B such that each element of A is associated with exactly one element of B. Or you can think of a relation as a generalized type of function, which allows missing or multiple outputs for certain inputs. Many mathematical applications use partial functions, which are functions that might not return a value for every input. Similarly, many programming languages let you define procedures that do not return a value. Some programming languages even let you define procedures that return multiple values. If a relation is a function, it s usually more convenient to define it as a function and use function notation. So, if we observe them in the wild, mathematicians normally call something a relation only when it isn t a function, or they are worried that it might not turn out to be a function. 4 Relations and databases The facts stored in a computer database are also relations. For this application, we need to generalize our notion of relation to more than two sets. For example, a simple registration database might contain 4-tuples like (Jean Luc Picard, Math CS 173, Fall 2325, A-) 2
(James T. Kirk, CS 173, Spring 2248, B) (Kathryn Janeway, Math 347, Fall 2345, A+) So this database is a subset of A B C D, where A is the set of students, B is the set of courses, C is the set of terms, and D is the set of letter grades. Database records don t look at all like functions, because there s often no obvious way to identify one field as the input. The whole point of a database is to let us easily switch perspective and organize the data according to a different field, e.g. sort students by name or by grade. We won t make much use of n-ary relations in this class. If you are curious about database applications, look in section 8.2 of Rosen. 5 Relations on a single set The final big group of relations are relations that associate two elements of the same set. A relation R on a set A is a relation from A to A, or equivalently, a subset of A A. That is, R is a set of pairs of elements from A. For example, suppose we let A = {2, 3, 4, 5, 6, 7} We can define a relation R on A by (x, y) R if and only if x y 2. This relation contains the pairs (3, 4) and (4, 6) and (6, 4), but not the pair (3, 6). Another relation on A is the familiar = relation. It contains only pairs whose two elements are identical, such as (5, 5) and (3, 3). Another similar relation is congruence mod 3 ( 3 ). The 3 relation contains a wider range of pairs, e.g. (4, 7) and (6, 3). Relations like these, which resemble equality, are known as equivalence relations. We ll get back to defining them precisely in a couple lectures. Order relations such as < and are also relations on the set A. example, the relation contains pairs like (5, 4) and (7, 2) and (5, 5). No one said that a relation needs to involve finite sets or even onedimensional sets. We can define similar relations on infinite sets. For example, normal numerical is a relation on the set of integers or the set of 3 For
real numbers. Another example: we can define a relation T on the real plane R 2 in which (x, y) is related to (p, q) if and only if x 2 + y 2 = p 2 + q 2. In other words, two points are related if they are the same distance from the origin. 6 Random relations No one said that a relation had to make sense or have any practical use. For example, let s let A = {a, b, c, d}. We can select any random subset of A A to be a relation. For example, R = {(a, a), (b, a), (c, d), (d, d)} is a perfectly good relation on A. Wierdo relations like this are often easiest to represent by making a table showing which pairs are in the set, or by drawing a dot-and-arrow diagram of the relation. [See pictures pp. 520 521 of Rosen. Notice that we can do the dot-and-arrow diagram with either one copy of the points or two copies.] If a set A has n elements, how many possible relations are there on A? A A contains n 2 elements. A relation is just a subset of A A, and so there are 2 n2 relations on A. So a 3-element set has 2 9 = 512 possible relations. Yup: most of these relations are of no practical use whatsoever. Most of the time, you will be manipulating relations generated by some underlying pattern and, thus, make more sense. Just be aware that these random guys are also legitimate relations. 7 Properties of relations: reflexive Familiar relations such as = and < have certain special properties which make them especially useful, both in proofs and in practical applications. Moreover, some relations seem to be structurally similar: similar properties for apparently similar reasons. For example, and and divides. We can make these intuitions concrete by classifying relations according to certain key properties. The commonly-used properties are: reflexive, irreflexive, symmetric, antisymmetric, and transitive. Relations that act like equality are all reflexive, symmetric, and transitive. Relations that act like < are all irreflexive, anti- 4
symmetric, and transitive. And so forth. A relation R on a set A is reflexive if every element is related to itself. That is, for every x A, (x, x) R. For example, normal equality (on the integers, or on the reals, or on sets of integers, or whatever) is reflexive. Another example: let B contain sets of UIUC students. So B might contain {Hanna, Melissa} and {John, Marco, Oscar} and so forth. Let s define a relation R by saying that x and y are in R iff x = y (i.e x and y contain the same number of people. R isn t equality, because two non-equal elements can be related. For example, R contains ({Hanna, Melissa}, {Yunsook, Jaebum}). But R is reflexive, because every set of students is related to itself. Yet another example: the relation on B is reflexive, because every set is a subset of itself. 8 Irreflexive A relation R on a set A is irreflexive if every element is not related to itself. That is, for every x A, (x, x) R. For example, the < relation on the integers is irreflexive, because no integer is less than itself. Notice that irreflexive is not the negation of reflexive. Let s look at the definitions more closely: reflexive: x A, (x, y) R not reflexive: x A, (x, y) R. irreflexive: x A, (x, y) R So we can have a relation which is neither reflexive nor irreflexive, if some elements are related to themselves and some aren t. For example, let s define a relation S on the integers by (x, y) S if and only if x + y = 0. (2, 2) isn t in S, but (0, 0) is. 5
9 Symmetric and antisymmetric Another important property of a relation is whether the order matters within each pair. That is, if (x, y) is in R, is (y, x) always in R? A relation satisfying this property is called symmetric. Generalizations of equality are normally symmetric. For example, the relation R on the integers defined by (x, y) R iff x = y. Or the relation S on the real plane defined by ((x, y), (p, q)) S iff (x p) 2 + (y q) 2 25 (i.e. the two points are no more than 5 units apart). A relation R is antisymmetric if (y, x) and (x, y) are never both in R, except when x = y. This is typically true of order relations such as < and, or relations based on them. For example, the divides relation on the integers is antisymmetric because n m and m n are only both true when m = n. Formally, we can define them as: symmetric: x, y A, (x, y) R (y, x) R antisymmetric: x, y A with x y, (x, y) R (y, x) R Even if we restrict our attention to pairs whose two coordinates aren t the same, symmetric and antisymmetric still aren t opposites. Rather, they represent two pure patterns of what might happen with the reversed pairs. Most random relations and some real practical relations are mixed cases. Specifically a relation is neither symmetric nor antisymmetric if (x, y) and (y, x) are both in the relation for some values of x and y, but only one is in the set for other values. For example, the loves relation is neither symmetric nor antisymmetric for most large sets of people. There are some pairs of people who both love each other. But there are also some people who love another person, but their love isn t reciprocated. 6