Introduction to Relations CSE 191, Class Note 09 Computer Sci & Eng Dept SUNY Buffalo c Xin He (University at Buffalo) CSE 191 Descrete Structures 1 / 57 Binary relation Definition: Let A and B be two sets. A binary relation from A to B is a subset of A B. × In other words, a binary relation from A to B is a set of pair (a, b) such that a A and b B. ∈ ∈ We often omit “binary” if there is no confusion. If R is a relation from A to B and (a, b) R, we say a is related to b by R. ∈ We write a R b. Example: Let A be the set of UB students, and B be the set of UB courses. Define relation R from A to B as follows: a R b if and only if student a takes course b. So for every student x in this classroom, we have that (x, CSE191) R, or ∈ equivalently, x R CSE191. For your TA Ding , we know that Ding is NOT related to CSE191 by R. c XinSo He (University(Ding, CSE at Buffalo)191) R. CSE 191 Descrete Structures 3 / 57 6∈ Relation on a set We are particularly interested in binary relations from a set to the same set. If R is a relation from A to A, then we say R is a relation on set A. Example: We can define a relation R on the set of positive integers such that a R b if and only if a b. | 3 R 6. And 13 is not related to 6 by R. Example: We can define a relation R on the set of real numbers such that a R b if and only if a > b + 1. Is 2 related to 3? Is 5 related to 3? For what values of x is x2 related to 2x? c Xin He (University at Buffalo) CSE 191 Descrete Structures 4 / 57 Reflexive relation Definition: A relation R on a set A is called reflexive if every a A is related to itself. ∈ Example: We can define a relation R on the set of positive integers such that a R b if and only if a b. | This relation is reflexive because every positive integer divides itself. Example: Consider the following relations on the set 1, 2, 3 : { } R = (1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (3, 3) 1 { } R = (1, 1), (1, 3), (2, 2), (3, 1) 2 { } R = (2, 3) 3 { } R = (1, 1) 4 { } Which of them are reflexive? c Xin He (University at Buffalo) CSE 191 Descrete Structures 5 / 57 Symmetric and antisymmetric relation Definition: A relation R on set A is called symmetric if (a, b) R whenever (b, a) R. ∈ ∈ It is called antisymmetric if for all a, b A, (a, b) R and (b, a) R ∈ ∈ ∈ implies that a = b. Example: We can define a relation R on the set of positive integers such that a R b if and only if a b. | This relation is NOT symmetric because, e.g., 2 R 4 but 4 is not related to 2 by R. This relation is antisymmetric because a b and b a implies that a = b. | | c Xin He (University at Buffalo) CSE 191 Descrete Structures 6 / 57 More examples Example: Consider the following relations on the set 1, 2, 3 : { } R = (1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (3, 3) 1 { } R = (1, 1), (1, 3), (2, 2), (3, 1) 2 { } R = (2, 3) 3 { } R = (1, 1) 4 { } Which of them are symmetric? Which of them are antisymmetric? c Xin He (University at Buffalo) CSE 191 Descrete Structures 7 / 57 Transitive relation Definition: A relation R on set A is transitive if for all a, b, c A, (a, b) R and (b, c) R ∈ ∈ ∈ implies that (a, c) R. ∈ Example: We can define a relation R on the set of positive integers such that a R b if and only if a b. | This relation is transitive because a b and b c implies that a c. | | | Example: Consider the following relations on the set 1, 2, 3 : { } R = (1, 1), (1, 2), (2, 3) 1 { } R = (1, 2), (2, 3), (1, 3) 2 { } Which of them is transitive? c Xin He (University at Buffalo) CSE 191 Descrete Structures 8 / 57 Example relations and properties Let R be the relation on the set of students in this class. Decide whether R is: reflexive (r/not r), symmetric (s/not s), antisymmetric (a/not a), transitive (t/not t). 1 (a, b) R if and only if a has a higher GPA than b. ∈ not r; not s; a; t. 2 a and b have the same last name. r; s; not a; t. 3 a and b have a common hobby. r; s; not a; not t. c Xin He (University at Buffalo) CSE 191 Descrete Structures 9 / 57 Composite relation Definition: Let R be a relation from set A to set B. Let S be a relation from set B to set C. The composite of R and S is a relation from A to C is: (a, c) there exists b such that (a, b) R and (b, c) S { | ∈ ∈ } We write it as S R (NOT R S). ◦ ◦ Example: We can define a relation R on the set of positive integers such that a R b if and only if a b. | We also define relation S on the same set such that b S c if and only if b = 2c. Let T = S R. We have a T c if and only if a 2c. ◦ | c Xin He (University at Buffalo) CSE 191 Descrete Structures 11 / 57 Power relation Definition Let R be a relation on set A. For positive integer n, we define the nth power of R as follows: First, R1 = R. Second, for all positive integer n, Rn+1 = Rn R. ◦ This definition actually means: R2 = R R ◦ R3 = (R R) R ◦ ◦ R4 = ((R R) R) R ◦ ◦ ◦ ... c Xin He (University at Buffalo) CSE 191 Descrete Structures 12 / 57 Example for power relation Example: Let R = (1, 1), (2, 1), (3, 2), (4, 3) be a relation on 1, 2, 3, 4 . { } { } We can calculate the powers as follows: R2 = R R = (1, 1), (2, 1), (3, 1), (4, 2) ◦ { } R3 = R2 R = (1, 1), (2, 1), (3, 1), (4, 1) ◦ { } ... n Keep in mind: (a, c) R if and only if there exist b1, b2,..., bn 1, such that ∈ − (a, b1), (b1, b2),..., (bn 1, c) R. − ∈ c Xin He (University at Buffalo) CSE 191 Descrete Structures 13 / 57 Transitive relation and power Theorem: A relation R on set A is transitive if and only if for all positive integer n, Rn R. ⊆ Proof: First we show the “if” part. Suppose for all positive integer n, Rn R. In particular, R2 R. For all ⊆ ⊆ a, b, c A such that (a, b), (b, c) R, we always have (a, c) R2. ∈ ∈ ∈ Consequently, (a, c) R. This means R is transitive. ∈ Next, we prove the “only if” part. Suppose R is transitive. We prove Rn R by induction. ⊆ When n = 1, clearly R1 = R R. ⊆ For the inductive step, we assume Rn R and try to establish that Rn+1 R. ⊆ ⊆ For any (a, c) Rn+1, there exists b A such that (a, b) Rn and (b, c) R. ∈ ∈ ∈ ∈ By the inductive assumption, we get that (a, b) R and (b, c) R. Since R is ∈ ∈ transitive, we have that (a, c) R. ∈ The above tells us that Rn+1 R. ∈ c Xin He (University at Buffalo) CSE 191 Descrete Structures 14 / 57 n-ary Relations and their Applications in Computer Science Definition: Let A1, A2,..., An be sets. An n-ary relation on these sets is a subset of A A A . 1 × 2 × · · · × n Example: Let R be the relation on Z Z Z consisting of all triples of integers (a, b, c) × × such that a, b, c form an arithmetic progression. Namely (a, b, c) R if and only if b a = c b: ∈ − − R = (a, b, c) a Z, b Z, c Z, and b a = c b { | ∈ ∈ ∈ − − } (1, 3, 5) R. ∈ ( 1, 11, 21) R. − − − ∈ (1, 3, 7) R. 6∈ c Xin He (University at Buffalo) CSE 191 Descrete Structures 15 / 57 n-ary Relations and their Applications in Computer Science The concept of n-ary relations plays a central role in computer science. Especially in Database Systems. A database D consists of records, which are n-tuples, made up of fields. Example: A database D of student records may be made up of fields containing: the name, student ID, major, GPA. Student Datadase Name ID major GPA Ackermann 231455 Computer Science 3.88 Adams 888323 Physics 3.45 Chou 102147 Mathematics 3.49 ... c Xin He (University at Buffalo) CSE 191 Descrete Structures 16 / 57 n-ary Relations and their Applications in Computer Science In this example, R Names ID Major GPA. is a 4-ary relation. ⊂ × × × Each student record is a member of R. All database systems consist of such relations. (Examples: Sales record, inventory, factory order record, ....) One can define operators on n-ary relations, such as: selection operator, projection operator, join operators. These operators are used to construct new relations from existing relations in the database. They can also be used to retrieve information from the database records. Such a database system is called a relational database. SQL (short for Structured Query Language) is a database query language that uses these operators to perform database operations.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages25 Page
-
File Size-