15.1 CompSci 102© Michael Frank Today’s topics RelationsRelations –Kinds of relations –n-ary relations –Representations of relations Reading: Sections.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Discrete Mathematics Lecture # 16 Inverse of Relations.
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.
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 Chapter 9.
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.
Module #18: Relations, part I
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 歐亞書局.
Chapter 7: Relations Relations(7.1) Relations(7.1) n-any Relations & their Applications (7.2) n-any Relations & their Applications (7.2)
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Relations.
Discrete Mathematics Relation.
Relations and their Properties
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.
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.
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,
1 RELATIONS Learning outcomes Students are able to: a. determine the properties of relations – reflexive, symmetric, transitive, and antisymmetric b. determine.
Relations Section 9.1, 9.3—9.5 of Rosen Spring 2012
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)
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.
Discrete Mathematical
Relations and Their Properties
Chapter 5 Relations and Operations
Relations.
Relations Chapter 9.
Relations and Digraphs
Applied Discrete Mathematics Week 10: Relations
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
Introduction to Relations and Functions
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.
Agenda Lecture Content: Relations (Relasi)
Lecture # 16 Inverse of Relations
Relations 12/7/2019.
Presentation transcript:

15.1 CompSci 102© Michael Frank Today’s topics RelationsRelations –Kinds of relations –n-ary relations –Representations of relations Reading: Sections Reading: Sections UpcomingUpcoming –Minesweeper

15.2 CompSci 102© Michael Frank 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 (can be identified with) a subset of the set A×B.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 (can be identified with) a subset of the set A×B. –E.g., let < : N↔N :≡ {(n,m) | n < m} The notation a R b or aRb means that (a,b)  R.The notation a R b or aRb means that (a,b)  R. –E.g., a < b means (a,b)  < If aRb we may say “a is related to b (by relation R)”,If aRb we may say “a is related to b (by relation R)”, –or just “a relates to b (under relation R)”. A binary relation R corresponds to a predicate function P R :A×B→{T,F} defined over the 2 sets A,B;A binary relation R corresponds to a predicate function P R :A×B→{T,F} defined over the 2 sets A,B; –e.g., predicate “eats” :≡ {(a,b)| organism a eats food b}

15.3 CompSci 102© Michael Frank Complementary Relations Let R:A,B be any binary relation.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) − RThen, 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 this is just R if the universe of discourse is U = A×B; thus the name complement. Note the complement of R is R.Note the complement of R is R. < = {(a,b) | (a,b)  <} = {(a,b) | ¬a<b} = ≥ Example: < = {(a,b) | (a,b)  <} = {(a,b) | ¬a<b} = ≥

15.4 CompSci 102© Michael Frank 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}.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., a} = >. E.g., if R:People→Foods is defined by a R b  a eats b, then: b R −1 a  b is eaten by a. (Passive voice.)E.g., if R:People→Foods is defined by a R b  a eats b, then: b R −1 a  b is eaten by a. (Passive voice.)

15.5 CompSci 102© Michael Frank Relations on a Set A (binary) relation from a set A to itself is called a relation on the set A.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.E.g., the “ < ” relation from earlier was defined as a relation on the set N of natural numbers. The (binary) identity relation I A on a set A is the set {(a,a)|a  A}.The (binary) identity relation I A on a set A is the set {(a,a)|a  A}.

15.6 CompSci 102© Michael Frank Reflexivity A relation R on A is reflexive if  a  A, aRa.A relation R on A is reflexive if  a  A, aRa. –E.g., the relation ≥ :≡ {(a,b) | a≥b} is reflexive. A relation R is irreflexive iff its complementary relation R is reflexive.A relation R is irreflexive iff its complementary relation R is reflexive. –Example: < is irreflexive, because ≥ is reflexive. –Note “irreflexive” does NOT mean “not reflexive”! For example: the relation “likes” between people is not reflexive, but it is not irreflexive either.For example: the relation “likes” between people is not reflexive, but it is not irreflexive either. –Since not everyone likes themselves, but not everyone dislikes themselves either!

15.7 CompSci 102© Michael Frank Symmetry & Antisymmetry A binary relation R on A is symmetric iff R = R −1, that is, if (a,b)  R ↔ (b,a)  R.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 is antisymmetric if  a≠b, (a,b)  R → (b,a)  R.A binary relation R is antisymmetric if  a≠b, (a,b)  R → (b,a)  R. –Examples: < is antisymmetric, “likes” is not. –Exercise: prove this definition of antisymmetric is equivalent to the statement that R  R −1  I A.

15.8 CompSci 102© Michael Frank Transitivity A relation R is transitive iff (for all a,b,c) (a,b)  R  (b,c)  R → (a,c)  R.A relation R is transitive iff (for all a,b,c) (a,b)  R  (b,c)  R → (a,c)  R. A relation is intransitive iff it is not transitive.A relation is intransitive iff it is not transitive. Some examples:Some examples: –“is an ancestor of” is transitive. –“likes” between people is intransitive. –“is located within 1 mile of” is… ?

15.9 CompSci 102© Michael Frank 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.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.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.)A partial relation is a relation that might be strictly partial. (Or, it might be total.) –In other words, all relations are considered “partial.”

15.10 CompSci 102© Michael Frank Functionality A relation R:A×B is functional if, for any a  A, there is at most 1 b  B such that (a,b)  R.A relation R:A×B is functional if, for any a  A, there is at most 1 b  B such that (a,b)  R. –“R is functional”   a  A: ¬  b 1 ≠b 2  B: aRb 1  aRb 2. –Iff R is functional, then it corresponds to a partial function R:A→B where R(a)=b  aRb; e.g.where R(a)=b  aRb; e.g. –E.g., The relation aRb :≡ “a + b = 0” yields the function −(a) = b. R is antifunctional if its inverse relation R −1 is functional.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 1 b such that (a,b)  R. I.e.,  a  A: ¬  !b: aRb.R is a total function R:A→B if it is both functional and total, that is, for any a  A, there is exactly 1 b such that (a,b)  R. I.e.,  a  A: ¬  !b: aRb. –If R is functional but not total, then it is a strictly partial function. –Exercise: Show that iff R is functional and antifunctional, and both it and its inverse are total, then it is a bijective function.

15.11 CompSci 102© Michael Frank Lambda Notation The lambda calculus is a formal mathematical language for defining and operating on functions.The lambda calculus is a formal mathematical language for defining and operating on functions. –It is the mathematical foundation of a number of functional (recursive function-based) programming languages, such as LISP and ML. It is based on lambda notation, in which “λa: f(a)” is a way to denote the function f without ever assigning it a specific symbol.It is based on lambda notation, in which “λa: f(a)” is a way to denote the function f without ever assigning it a specific symbol. –E.g., (λx. 3x 2 +2x) is a name for the function f:R→R where f(x)=3x 2 +2x. Lambda notation and the “such that” operator “  ” can also be used to compose an expression for the function that corresponds to any given functional relation.Lambda notation and the “such that” operator “  ” can also be used to compose an expression for the function that corresponds to any given functional relation. –Let R:A×B be any functional relation on A,B. –Then the expression (λa: b  aRb) denotes the function f:A→B where f(a) = b iff aRb. E.g., If I write: f :≡ (λa: b  a+b = 0), this is one way of defining the function f(a)=−a.E.g., If I write: f :≡ (λa: b  a+b = 0), this is one way of defining the function f(a)=−a.

15.12 CompSci 102© Michael Frank Composite Relations Let R:A×B, and S:B×C. Then the composite S  R of R and S is defined as:Let R:A×B, and S:B×C. Then the composite S  R of R and S is defined as: S  R = {(a,c) |  b: aRb  bSc} Note that function composition f  g is an example.Note that function composition f  g is an example. Exer.: Prove that R:A×A is transitive iff R  R = R.Exer.: Prove that R:A×A is transitive iff R  R = R. The n th power R n of a relation R on a set A can be defined recursively by: R 0 :≡ I A ;R n+1 :≡ R n  R for all n≥0.The n th power R n of a relation R on a set A can be defined recursively by: R 0 :≡ I A ;R n+1 :≡ R n  R for all n≥0. –Negative powers of R can also be defined if desired, by R −n :≡ (R −1 ) n.

15.13 CompSci 102© Michael Frank §7.2: n-ary Relations An n-ary relation R on sets A 1,…,A n, written (with signature) R:A 1 ×…×A n or R:A 1,…,A n, is simply a subset R  A 1 × … × A n.An n-ary relation R on sets A 1,…,A n, written (with signature) R:A 1 ×…×A n or R:A 1,…,A n, is simply a subset R  A 1 × … × A n. The sets A i are called the domains of R.The sets A i are called the domains of R. The degree of R is n.The degree of R is n. R is functional in the domain A i if it contains at most one n-tuple (…, a i,…) for any value a i within domain A i.R is functional in the domain A i if it contains at most one n-tuple (…, a i,…) for any value a i within domain A i.

15.14 CompSci 102© Michael Frank Relational Databases A relational database is essentially just an n-ary relation R.A relational database is essentially just an n-ary relation R. A domain A i is a primary key for the database if the relation R is functional in A i.A domain A i is a primary key for the database if the relation R is functional in A i. A composite key for the database is a set of domains {A i, A j, …} such that R contains at most 1 n-tuple (…,a i,…,a j,…) for each composite value (a i, a j,…)  A i ×A j ×…A composite key for the database is a set of domains {A i, A j, …} such that R contains at most 1 n-tuple (…,a i,…,a j,…) for each composite value (a i, a j,…)  A i ×A j ×…

15.15 CompSci 102© Michael Frank Selection Operators Let A be any n-ary domain A=A 1 ×…×A n, and let C:A→{T,F} be any condition (predicate) on elements (n-tuples) of A.Let A be any n-ary domain A=A 1 ×…×A n, and let C:A→{T,F} be any condition (predicate) on elements (n-tuples) of A. Then, the selection operator s C 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.Then, the selection operator s C 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, s C (R) = {a  R | s C (a) = T}

15.16 CompSci 102© Michael Frank Selection Operator Example Suppose we have a domain A = StudentName × Standing × SocSecNosSuppose we have a domain A = StudentName × Standing × SocSecNos Suppose we define a certain condition on A, UpperLevel(name,standing,ssn) :≡ [(standing = junior)  (standing = senior)]Suppose we define a certain condition on A, UpperLevel(name,standing,ssn) :≡ [(standing = junior)  (standing = senior)] Then, s UpperLevel 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).Then, s UpperLevel 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).

15.17 CompSci 102© Michael Frank Projection Operators Let A = A 1 ×…×A n be any n-ary domain, and let {i k }=(i 1,…,i m ) be a sequence of indices all falling in the range 1 to n,Let A = A 1 ×…×A n be any n-ary domain, and let {i k }=(i 1,…,i m ) be a sequence of indices all falling in the range 1 to n, –That is, where 1 ≤ i k ≤ n for all 1 ≤ k ≤ m. Then the projection operator on n-tuplesThen the projection operator on n-tuples is defined by: is defined by:

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

15.19 CompSci 102© Michael Frank Join Operator Puts two relations together to form a sort of combined relation.Puts two relations together to form a sort of combined relation. If the tuple (A,B) appears in R 1, and the tuple (B,C) appears in R 2, then the tuple (A,B,C) appears in the join J(R 1,R 2 ).If the tuple (A,B) appears in R 1, and the tuple (B,C) appears in R 2, then the tuple (A,B,C) appears in the join J(R 1,R 2 ). –A, B, and C here can also be sequences of elements (across multiple fields), not just single elements.

15.20 CompSci 102© Michael Frank Join Example Suppose R 1 is a teaching assignment table, relating Professors to Courses.Suppose R 1 is a teaching assignment table, relating Professors to Courses. Suppose R 2 is a room assignment table relating Courses to Rooms,Times.Suppose R 2 is a room assignment table relating Courses to Rooms,Times. Then J(R 1,R 2 ) is like your class schedule, listing (professor,course,room,time).Then J(R 1,R 2 ) is like your class schedule, listing (professor,course,room,time).

15.21 CompSci 102© Michael Frank §7.3: Representing Relations Some ways to represent n-ary 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.Or with an algorithm for computing this function. Some special ways to represent binary relations:Some special ways to represent binary relations: –With a zero-one matrix. –With a directed graph.

15.22 CompSci 102© Michael Frank Using Zero-One Matrices To represent a binary relation R:A×B by an |A|×|B| 0-1 matrix M R = [m ij ], let m ij = 1 iff (a i,b j )  R.To represent a binary relation R:A×B by an |A|×|B| 0-1 matrix M R = [m ij ], let m ij = 1 iff (a i,b j )  R. E.g., Suppose Joe likes Susan and Mary, Fred likes Mary, and Mark likes Sally.E.g., Suppose Joe likes Susan and Mary, Fred likes Mary, and Mark likes Sally. Then the 0-1 matrix representation of the relation Likes:Boys×Girls relation is:Then the 0-1 matrix representation of the relation Likes:Boys×Girls relation is:

15.23 CompSci 102© Michael Frank Zero-One Reflexive, Symmetric Terms: Reflexive, non-reflexive, irreflexive, symmetric, asymmetric, and antisymmetric.Terms: Reflexive, non-reflexive, irreflexive, symmetric, asymmetric, and antisymmetric. –These relation characteristics are very easy to recognize by inspection of the zero-one matrix. 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 any- thing anything

15.24 CompSci 102© Michael Frank Using Directed Graphs A directed graph or digraph G=(V G,E G ) is a set V G of vertices (nodes) with a set E G  V G ×V G 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 G R =(V G =A  B, E G =R).A directed graph or digraph G=(V G,E G ) is a set V G of vertices (nodes) with a set E G  V G ×V G 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 G R =(V G =A  B, E G =R). Matrix representation M R : Graph rep. G R : Joe Fred Mark Susan Mary Sally Node set V G (black dots) Edge set E G (blue arrows)

15.25 CompSci 102© Michael Frank 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    These are asymmetric & non-antisymmetricThese are non-reflexive & non-irreflexive