Module #18: Relations, part I

Slides:



Advertisements
Similar presentations
CSE 211- Discrete Structures
Advertisements

CSE115/ENGR160 Discrete Mathematics 04/26/12 Ming-Hsuan Yang UC Merced 1.
5/16/20151 You Never Escape Your… Relations. 5/16/20152Relations If we want to describe a relationship between elements of two sets A and B, we can use.
In The Name of Allah Discrete Structures Instructor: Dr. Ali Movaghar
CS2210(22C:19) Discrete Structures Relations Spring 2015 Sukumar Ghosh.
1 Relations Rosen 5 th ed., ch Relations Relationships between elements of sets occur very often.Relationships between elements of sets occur very.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Relations.
Discrete Mathematics Lecture#11.
1 Section 7.1 Relations and their properties. 2 Binary relation A binary relation is a set of ordered pairs that expresses a relationship between elements.
1 Representing Relations Epp section ??? CS 202 Aaron Bloomfield.
Relations (1) Rosen 6 th ed., ch. 8. Binary Relations Let A, B be any two sets. A binary relation R from A to B, written (with signature) R:A↔B, is a.
Module #21 - Relations Representing Relations Rosen 6 th ed., Ch. 8.
Relations Rosen 5 th ed., ch. 7. Binary Relations Let A, B be any sets. A binary relation R from A to B, written (with signature) R:A×B, or R:A,B, is.
April 10, 2002Applied Discrete Mathematics Week 10: Relations 1 Counting Relations Example: How many different reflexive relations can be defined on a.
Chapter 9. Chapter Summary Relations and Their Properties Representing Relations Equivalence Relations Partial Orderings.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Chapter 9. Section 9.1 Binary Relations Definition: A binary relation R from a set A to a set B is a subset R ⊆ A × B. Example: Let A = { 0, 1,2 } and.
Sets Define sets in 2 ways  Enumeration  Set comprehension (predicate on membership), e.g., {n | n  N   k  k  N  n = 10  k  0  n  50} the set.
Discrete Structures1 You Never Escape Your… Relations.
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 8 Relations 歐亞書局.
2009/9 1 Matrices(§3.8)  A matrix is a rectangular array of objects (usually numbers).  An m  n (“m by n”) matrix has exactly m horizontal rows, and.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Relations.
Discrete Mathematics Relation.
Relations and their Properties
§ 每周五交作业,作业成绩占总成绩的 10% ; § 平时不定期的进行小测验,占总成绩的 20% ; § 期中考试成绩占总成绩的 20% ;期终考 试成绩占总成绩的 50% § 每周五下午 1 ; 00—3 : 00 ,答疑 § 地点:软件楼 301.
Module #9: Matrices Rosen 5 th ed., §2.7 Now we are moving on to matrices, section 7.
Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.
Fall 2002CMSC Discrete Structures1 You Never Escape Your… Relations.
Sets and Subsets Set A set is a collection of well-defined objects (elements/members). The elements of the set are said to belong to (or be contained in)
Relations. Important Definitions We covered all of these definitions on the board on Monday, November 7 th. Definition 1 Definition 2 Definition 3 Definition.
이산수학 (Discrete Mathematics) 7.3 관계의 표현 (Representing Relations) 2006 년 봄학기 문양세 강원대학교 컴퓨터과학과.
Lecture on Relations 1Developed by CSE Dept., CIST Bhopal.
Discrete Mathematics Lecture # 15 Types of Relations (contd.)
Relation. Combining Relations Because relations from A to B are subsets of A x B, two relations from A to B can be combined in any way two sets can be.
Problem Statement How do we represent relationship between two related elements ?
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Representing Relations Using Matrices A relation between finite sets can be represented using a zero-one matrix Suppose R is a relation from A = {a 1,
Relations Section 9.1, 9.3—9.5 of Rosen Spring 2012
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Relations.
Chapter 8: Relations. 8.1 Relations and Their Properties Binary relations: Let A and B be any two sets. A binary relation R from A to B, written R : A.
Relations. L222 Agenda –Relations 7.3 Representing Relations As subsets of Cartesian products Column/line diagrams Boolean matrix Digraph Operations on.
RelationsCSCE 235, Spring Introduction A relation between elements of two sets is a subset of their Cartesian products (set of all ordered pairs.
Relations and Functions ORDERED PAIRS AND CARTESIAN PRODUCT An ordered pair consists of two elements, say a and b, in which one of them, say a is designated.
2012 년 봄학기 강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics) n- 항 관계 (n-ary Relations)
Binary Relations Definition: A binary relation R from a set A to a set B is a subset R ⊆ A × B. Example: Let A = { 0, 1,2 } and B = {a,b} {( 0, a), (
Section 7.3: Representing Relations In this section, we will cover two ways to represent a relation over a finite set other than simply listing the relation.
Section 9.3. Section Summary Representing Relations using Matrices Representing Relations using Digraphs.
Chapter8 Relations 8.1: Relations and their properties.
15.1 CompSci 102© Michael Frank Today’s topics RelationsRelations –Kinds of relations –n-ary relations –Representations of relations Reading: Sections.
Relations and Their Properties
Chapter 5 Relations and Operations
Relations Chapter 9.
Relations and Digraphs
Dr. Ameria Eldosoky Discrete mathematics
Relations Rosen 5th ed., ch. 7.
Discrete Mathematics and its Applications
§7.3 Representing Relations Longin Jan Latecki
CS2210 Discrete Structures Relations
Rosen 5th ed., ch. 7 ~32 slides (in progress), ~2 lectures
Relations and Their Properties
8.1 Relations and Their Properties
Relations and their Properties
2/18/2019 §7.1 Binary Relations (2nd pass) and §7.2 n-ary Relations Longin Jan Latecki Slides adapted from Kees van Deemter who adopted them from Michael.
2/25/2019 §7.1 Binary Relations (2nd pass) and §7.2 n-ary Relations Longin Jan Latecki Slides adapted from Kees van Deemter who adopted them from Michael.
Combining relations via relational composition
REVISION Relation. REVISION Relation Introduction to Relations and Functions.
§7.3 Representing Relations Longin Jan Latecki
7/30/2019 §7.1 Binary Relations (2nd pass) and §7.2 n-ary Relations Longin Jan Latecki Slides adapted from Kees van Deemter who adopted them from Michael.
Relations 12/7/2019.
Presentation transcript:

Module #18: Relations, part I Rosen 5th ed., ch. 7

Binary Relations Let A, B be any two sets. A binary relation R from A to B, written (with signature) R:A↔B, is a subset of A×B. E.g., let < : N↔N :≡ {(n,m) | n < m} The notation a R b or aRb means (a,b)R. E.g., a < b means (a,b) < If aRb, we may say “a is related to b (by relation R)”, or “a relates to b (under relation R)”. A binary relation R corresponds to a predicate function PR:A×B→{T,F} defined over the 2 sets A,B; e.g., “eats” :≡ {(a,b)| animal a eats food b} Relationship?

Complementary Relations Let R:A↔B be any binary relation. Then, R:A↔B, the complement of R, is the binary relation defined by R :≡ {(a,b) | (a,b)R} = (A×B) − R Note this is just R if the universe of discourse is U = A×B; thus the name complement. Note the complement of R is R. Example: < = {(a,b) | (a,b)<} = {(a,b) | ¬a<b} = ≥

Inverse Relations Any binary relation R:A↔B has an inverse relation R−1:B↔A, defined by R−1 :≡ {(b,a) | (a,b)R}. E.g., <−1 = {(b,a) | a<b} = {(b,a) | b>a} = >. E.g., if R:People→Foods is defined by aRb  a eats b, then: b R−1 a  b is eaten by a. (Passive voice.)

Relations on a Set A (binary) relation from a set A to itself is called a relation on the set A. E.g., the “<” relation from earlier was defined as a relation on the set N of natural numbers. The identity relation IA on a set A is the set {(a,a)|aA}.

Reflexivity A relation R on A is reflexive if aA, aRa. E.g., the relation ≥ :≡ {(a,b) | a≥b} is reflexive. A relation is irreflexive iff its complementary relation is reflexive. Note “irreflexive” ≠ “not reflexive”! Example: < is irreflexive. (is it not reflexive?) Note: “likes” between people is not reflexive, but not irreflexive either. (Not everyone likes themselves, but not everyone dislikes themselves either.)

Symmetry & Antisymmetry A binary relation R on A is symmetric iff R = R−1, that is, if (a,b)R ↔ (b,a)R. E.g., = (equality) is symmetric. < is not. “is married to” is symmetric, “likes” is not. A binary relation R on A such that (a,b)R and (b,a)R only if a=b, for all (a,b) A, is antisymmetric < is antisymmetric, “likes” is not. “divides” relation: not symmetric, but antisymmetric Doesn’t care about whether reflexive or irreflexive A relation R is called asymmetric if (a,b)R → (b,a)R Antisymmetric and irreflexive

Transitivity A relation R is transitive iff (for all a,b,c) (a,b)R  (b,c)R → (a,c)R. A relation is intransitive if it is not transitive. Examples: “is an ancestor of” is transitive. “likes” is intransitive. “is within 1 mile of” is… ?

Totality A relation R:A↔B is total if for every aA, there is at least one bB such that (a,b)R. If R is not total, then it is called strictly partial. A partial relation is a relation that might be strictly partial. Or, it might be total. (In other words, all relations are considered “partial.”)

Functionality A relation R:A↔B is functional (that is, it is also a partial function R:A→B) if, for any aA, there is at most one bB such that (a,b)R. R is antifunctional if its inverse relation R−1 is functional. Note: A functional relation (partial function) that is also antifunctional is an invertible partial function. R is a total function R:A→B if it is both functional and total, that is, for any aA, there is exactly one b such that (a,b)R. If R is functional but not total, then it is a strictly partial function.

Composite Relations Let R:A↔B, and S:B↔C. Then the composite SR of R and S is defined as: SR = {(a,c) | aRb  bSc} Note function composition fg is an example. The nth power Rn of a relation R on a set A can be defined recursively by: R0 :≡ IA ; Rn+1 :≡ RnR for all n≥0. Negative powers of R can also be defined if desired, by R−n :≡ (R−1)n.

§7.2: n-ary Relations An n-ary relation R on sets A1,…,An, written R:A1,…,An, is a subset R  A1× … × An. The sets Ai are called the domains of R. The degree (arity) of R is n. nullary, unary, binary, ternary, …, n-ary R is functional in domain Ai if it contains at most one n-tuple (…, ai ,…) for any value ai within domain Ai.

Relational Databases A relational database is essentially an n-ary relation R. A domain Ai is a primary key for the database if the relation R is functional in Ai. A composite key for the database is a set of domains {Ai, Aj, …} such that R contains at most 1 n-tuple (…,ai,…,aj,…) for each composite value (ai, aj,…)Ai×Aj×… 학생리스트: 학번 이름 학점 출신고 고교졸업석차 고졸년도

Selection Operators Let A be any n-ary domain A=A1×…×An, and let C:A→{T,F} be any condition (predicate) on elements (n-tuples) of A. Then, the selection operator sC is the operator that maps any (n-ary) relation R on A to the n-ary relation of all n-tuples from R that satisfy C. I.e., RA, sC(R) = R{aA | sC(a) = T}

Selection Operator Example Suppose we have a domain A = StudentName × Standing × SocSecNos Suppose we define a certain condition on A, UpperLevel(name,standing,ssn) :≡ [(standing = junior)  (standing = senior)] Then, sUpperLevel is the selection operator that takes any relation R on A (database of students) and produces a relation consisting of just the upper-level classes (juniors and seniors).

Projection Operators Let A = A1×…×An be any n-ary domain, and let {ik}=(i1,…,im) be a sequence of indices all falling in the range 1 to n, That is, where 1 ≤ ik ≤ n for all 1 ≤ k ≤ m. Then the projection operator on n-tuples is defined by:

Projection Example Suppose we have a ternary (3-ary) domain Cars=Model×Year×Color. (note n=3). Consider the index sequence {ik}= 1,3. (m=2) Then the projection P simply maps each tuple (a1,a2,a3) = (model,year,color) to its image: This operator can be usefully applied to a whole relation RCars (database of cars) to obtain a list of model/color combinations available. {ik}

Join Operator Puts two relations together to form a sort of combined relation. If the tuple (A,B) appears in R1, and the tuple (B,C) appears in R2, then the tuple (A,B,C) appears in the join J(R1,R2). A, B, C can also be sequences of elements rather than single elements.

Join Example Suppose R1 is a teaching assignment table, relating Professors to Courses. Suppose R2 is a room assignment table relating Courses to Rooms,Times. Then J(R1,R2) is like your class schedule, listing (professor,course,room,time).

§7.3: Representing Relations Some ways to represent n-ary relations: With an explicit list or table of its tuples. With a function from the domain to {T,F}. Or with an algorithm for computing this function. Some special ways to represent binary relations: With a zero-one matrix. With a directed graph.

Using Zero-One Matrices To represent a relation R by a matrix MR = [mij], let mij = 1 if (ai,bj)R, else 0. E.g., Joe likes Susan and Mary, Fred likes Mary, and Mark likes Sally. The 0-1 matrix representation of that “Likes” relation:

Zero-One Reflexive, Symmetric Terms: Reflexive, non-Reflexive, irreflexive, symmetric, asymmetric, and antisymmetric. These relation characteristics are very easy to recognize by inspection of the zero-one matrix. any- thing any- thing anything anything any- thing any- thing Reflexive: all 1’s on diagonal Irreflexive: all 0’s on diagonal Symmetric: all identical across diagonal Antisymmetric: all 1’s are across from 0’s

Using Directed Graphs A directed graph or digraph G=(VG,EG) is a set VG of vertices (nodes) with a set EGVG×VG of edges (arcs,links). Visually represented using dots for nodes, and arrows for edges. Notice that a relation R:A↔B can be represented as a graph GR=(VG=AB, EG=R). Edge set EG (blue arrows) MR GR Joe Susan Fred Mary Mark Sally Node set VG (black dots)

Digraph Reflexive, Symmetric It is extremely easy to recognize the reflexive/irreflexive/ symmetric/antisymmetric properties by graph inspection.            Reflexive: Every node has a self-loop Irreflexive: No node links to itself Symmetric: Every link is bidirectional Antisymmetric: No link is bidirectional non-antisymmetric Non-reflexive, non-irreflexive How about asymmetric?