Relations.

Slides:



Advertisements
Similar presentations
Teoria podejmowania decyzji Relacja preferencji. Binarny relations – properties Pre-orders and orders, relation of rational preferences Strict preference.
Advertisements

Chapter 3 Relations. Section 3.1 Relations and Digraphs.
The Engineering Design of Systems: Models and Methods
Basic Properties of Relations
Review of Mathematical Notation / Terminology
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Relations.
Discussion #26 Chapter 5, Sections /15 Discussion #26 Binary Relations: Operations & Properties.
Discrete Math for CS Chapter 5: Functions. Discrete Math for CS New Relation Operations: Given R, a relation on A x B, we define the inverse relation,
Module #18: Relations, part I
Mathematical Preliminaries Strings and Languages Preliminaries 1.
Chapter 9. Chapter Summary Relations and Their Properties Representing Relations Equivalence Relations Partial Orderings.
INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models.
Discrete Math for CS Binary Relation: A binary relation between sets A and B is a subset of the Cartesian Product A x B. If A = B we say that the relation.
08 April 2009Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Formal.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
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.
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
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
Mathematical Preliminaries
1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 5 Relations and Functions.
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.
Relations Compare with function – Function: Set of ordered pairs where x’s don’t repeat x’s come from domain; y’s come from co-domain Purpose: to transform.
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), (
Theory of Computing Topics Formal languages automata computability and related matters Purposes To know the foundations and principles of computer science.
Theory of Computing Topics Formal languages automata computability and related matters Purposes To know the foundations and principles of computer science.
English for Economic Informatics I Tomáš Foltýnek Theoretical Foundations of Informatics.
Lecture 7: Relations Dr Andrew Purkiss-Trew Cancer Research UK Mathematics for Computing.
Binary Relation: A binary relation between sets A and B is a subset of the Cartesian Product A x B. If A = B we say that the relation is a relation on.
Relations Chapter 9 Copyright © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill.
Representing Relations Using Digraphs
Chapter 5 Relations and Operations
Learn about relations and their basic properties
CS1022 Computer Programming & Principles
Introduction to the Theory of Computation
Applied Discrete Mathematics Week 10: Relations
Cartesian product Given two sets A, B we define their Cartesian product is the set of all the pairs whose first element is in A and second in B. Note that.
Relation and function.
CSE 504 Discrete Structures & Foundations of Computer Science
Relations: Operations & Properties
CSNB 143 Discrete Mathematical Structures
CS201: Data Structures and Discrete Mathematics I
Computing Fundamentals 1 Lecture 7 Relations
CS2210 Discrete Structures Relations
Introductory Material
Relations and Their Properties
CSE15 Discrete Mathematics 04/26/17
Relations.
Applied Discrete Mathematics Week 6: Relations/Digraphs
Mathematical Preliminaries Strings and Languages
Mathematical Background 1
Functions.
Mathematical Background 1
Relations and their Properties
COMPS263F Unit 2 Discrete Structures Li Tak Sing( 李德成 ) Room A
Introduction to Relations and Functions
MCS680: Foundations Of Computer Science
Relations - Exercises.
Mathematical Background
Discrete Math (2) Haiming Chen Associate Professor, PhD
교환 학생 프로그램 내년 1월 중순부터 6월 초 현재 학부 2,3 학년?
Functions.
REVISION Relation. REVISION Relation Introduction to Relations and Functions.
Agenda Lecture Content: Relations (Relasi)
Introductory Material
Relations 12/7/2019.
Presentation transcript:

Relations

Cartesian Product The Cartesian Product of A and B is defined as A X B = { (a,b)|a Î A and b Î B}. The Cartesian Product of n sets A1,A2 , A3 ,…………… An is defined as A1 X A2 X A3 X ……………….. X An = { (a1,a2,………an)|ai Î Ai ,i=1,2....n}. The Expression (a1,a2,………an) is called an ordered n-tuple. Example: Let A = { 0, 1, 2} and B = {a, b}. Then, A X B = {(0,a),(0,b),(1,a),(1,b),(2,a),(2,b)} A X A = { (0,0),(0,1),(0,2), (1,0),(1,1),(1,2), (2,0),(2,1),(2,2)}

Relations As Sets Computing is the science (and art) of processing information. A major concern is the relationship between different pieces of information. Databases. Examples of relations : John has savings account number 333. The File menu contains the exit option. The root directory is the parent of the directory tree. A binary relation can be represented as a set of pairs. N-ary relations are simply an extension of this. N-ary is mathematics speak for “any number of elements”. For example, a trinary relation could be written siblings(tim, dave, sharon) Databases are the second most import subject in Computing (after programming). Relational languages are all based on the Unification Algorithm invented by Alan Robinson. A Machine Orientated Logic Based On The Resolution Principle A.J. Robinson Journal Of The ACM Volume 22 pp22-41 Without Robinson’s Unification Algorithm Relational Databases wouldn’t work.

Relations in Computing Something like 80% of the software systems in existence involve databases. The vast majority of the databases in existence are based on relations : Relational Databases. There is a whole programming paradigm based on relations : the Relational programming languages. (PROLOG) Relational database query languages (SQL etc.) are Relational languages.

Source And Target Assume we have a set : Transport = { Car, Bike, Horse, Plane } The owns relation is a subset of People x Transport. owns = { (Dick, Bike), (Joe, Car), (Mary, Car) } In this case People is the source set of the relation owns and Transport is the target set of the relation owns. Note that not all the elements of either source or target sets needs to occur in the actual relation. The relation may be partial. (x  Transport  (Stan, x)  owns) x  Transport  (Stan, x)  owns In fact, it turns out that most useful relations are partial.

Domain And Range The set of elements which occur as the first of the pairs in a relation is called the domain (dom) of the relation. The set of elements which occur as the second of the pairs in a relation is called the range (ran) of the relation. dom(owns) = { Dick, Joe, Mary } ran(owns) = { Bike, Car } As a pretty picture : Yet again we have different names for the same things. domain and input are synonyms. range and output are synonyms. Also note not that domain  source range  target Dick owns Bike owns (Dick, Bike) (Dick, Bike)  owns Bike Mary Dick Car Stan Plane Joe

A relation is a set of ordered pairs. The domain is the set of all x values in the relation domain = {-1,0,2,4,9} These are the x values written in a set from smallest to largest This is a relation {(2,3), (-1,5), (4,-2), (9,9), (0,-6)} {(2,3), (-1,5), (4,-2), (9,9), (0,-6)} {(2,3), (-1,5), (4,-2), (9,9), (0,-6)} These are the y values written in a set from smallest to largest range = {-6,-2,3,5,9} The range is the set of all y values in the relation Relations are the theoretical basis for Relational programming languages such as Prolog and SQL.

A relation assigns the x’s with y’s 1 2 2 4 3 6 4 8 10 5 Domain (set of all x’s) Range (set of all y’s) This relation can be written {(1,6), (2,2), (3,4), (4,8), (5,10)}

Relational Inverse The inverse of a relation is obtained by swapping round the components of each pair. R~ = { (1,0), (2,0), (2,1), (5,3) } S~ = { (2,1), (5,3) } Mathematically, we can write S~  { (x,y)  S  (y,x) } A good example of the use of a relational inverse is the child relation. child = parent~ Actually, in most Relational programming languages you get the inverse of a relation “for free”. The query parent(X, dave) would produce the set X = {jim, theresa } parent(theresa, Y) Y = {tim, dave, sharon }

Relational Composition The composition of R with S is equal to the set of all those ordered pairs (x, z) such that we can find at least one value, say y, such that xRy and ySz. That is R ; S  { (x,y)  R, (y, z)  S  (x, z) } As usual, an alternative notation is sometimes used. Instead of R ; S we write S o R to mean the same thing. So R ; S = { (0,1), (1, 1) }. 1 3 2 5 A good example of the use of a relational composition is the grandparent relation. grandparent = parent ; parent If we add my brother’s children to our family database parent(tim, james). parent(tim, thomas). the query grandparent(theresa, Z) would produce the set Z = {james, thomas } This happens because the parent database already includes the following record : parent(theresa, tim).

Relational Override This is essentially an update operation. The override of R by S is denoted R  S by adding to S all those ordered pairs from R whose first component is not in the domain of S. R  S  R  S \ { (x,y)  R  x  dom S } This sounds a lot more complex than it is. Lets have an example. R = { (1,2), (3,4), (2,3) } S = { (1,6), (4,5), (2,7) } R  S = { (1,6), (4,5), (2,7), (3,4) } A good way to think of this is that R is the master database and S is a set of new records to be added, some of which update the data in already existing records. We used relational override on our parent relation on the last slide to add james and thomas. Another good example is the update that happens every academic year when this institution updates SITS (Student IT System) which entries for all the new students and the module results for all the continuing students. The new students’ records are added to the database. The continuing students’ records are amended to show their new results.

Diagrammatic Representations Relations are often best understood when represented by a pretty picture. A directed graph or digraph. R = { (1,2), (2,1), (2,2), (2,4), (2,5), (3,1), (3,5), (4,5), (5,5) } The following diagraph represents R : 2 1 3 5 4

Diagrammatic Representations II Given R = { (1,2), (4,2), (4,3), (1,3), (4,1), (3,2), (3,3), (4,5) } The following diagraph represents R : 4 3 2 1

Types Of Relations An homogeneous relation is a binary relation in which the source and target sets are identical. R  Names  Names Useful for things like A family tree (parent, ancestor, married to etc.) Traveling problems (bus, rail and road connections etc.) An identity relation is a binary relation in which every element of a set is related to itself and only to itself. Ix = {x  X  (x,x) } For example if X = { 0, 1, 2 } then Ix = { (0,0), (1,1), (2,2) } The parent and grandparent relations are homogenous relations on the set of People. The most famous traveling problem is called the Traveling Salesman Problem (TSP). Given a set of cities find the shortest route to visit each city once (and only once). Sounds simple. It’s not. The TSP is actually the simplest example of an NP-Complete problem. Basically, that means that it takes a long time to solve. NP stands for Nondeterministic Polynomial. In English, very, very slow. Another example of an NP-complete problem is RSA encryption. Which makes Internet security very, very slow. RSA is a public / private (asymmetric) key encryption algorithm. RSA is named after its supposed inventors, Ron Rivest, Adi Shamir and Leonard Adelman. The story is that public / private key encryption was first invented in the 1960s at GCHQ. Obviously, the spooks didn’t tell anyone.

Types Of Homogenous Relations Can R = R~? Obviously, only for homogeneous relations. Such a relation is called symmetric. Given a relation R on the set X, for a symmetric relation : x,y  X  (x,y)  R  (y,x)  R Reflexive relations : every element of the domain is related to itself. Ix  R Not quite the same as a identity relation. There may be other pairs as well. For example : R = { (1,1), (2,2), (1,5), (2,3) }

Types Of Homogenous Relations II If whenever a is related to b and b is related to c then a is related to c then the relation is transitive. R ; R  R If a relation is reflexive, symmetric and transitive then it is called an equivalence relation. Given the relation R on the set { 1, 2, 3 } R = { (1,1), (1,2), (2,1), (2,2), (3,3) } Is this relation : Reflexive? Symmetric? Transitive? An equivalence relation? R is reflexive, symmetric and transitive so it is an equivalence relation. In our family database we could define a transitive relation ancestor. ancestor = parent  parent ; ancestor In English, one of your ancestors is either your parent of the parent of another of your ancestors.

Reflexive xRx for all x Î A Symmetric If xRy, then yRx, for all x,y Î A Transitive If xRy and yRz, then xRz, for all x,y,z Î A Equivalence relation: Let R be a relation on A. R is an equivalence relation on A if the following conditions are satisfied: 1. xRx for all x Î A ( R is reflexive) 2. If xRy, then yRx, for all x,y Î A ( R is symmetric) 3. If xRy and yRz, then xRz, for all x,y,z Î A ( R is transitive)

Example: Prove R is an equivalence relation Example: Prove R is an equivalence relation. Let N be the set of natural numbers,that is, N = {1,2,3……..}. Define a relation R in N as follows: R = {(x,y)| x,y Î N and x + y is even}. Example :Let A = { 1,2,3,4}, and let R = { (1,3),(4,2),(2,4),(2,3),(3,1)}. Is it R is equivalence or not Antisymmetric relation: A relation R on a set A is called an antisymmetric relation if (a,b) Î R and (b,a) Î R implies a = b. Example: R = { (1,3),(4,2),(2,4),(2,3),(3,1)}. R is not antisymmetric because (1,3) Î R and (3,1) Î R, but certainly 1 ≠ 3.

Problems Let A = {1,2,3,4,5,6}. Construct the relation R on A for the following cases. a) R = {(j,k) | j divides k} b) R = {(j,k) | j is a multiple of k} c) R = {(j,k) | (j – k)2 Î A} d) R = {(j,k) | j/k is a prime} 2. Let R be the relation from A = {1,2,3,4,5} to B = {1,3,5} which is defined by “ x is less than y.” Write R as a set of ordered pairs. 3. Let R be the relation in the natural numbers N = {1,2,3,…..} defined by “x + 2y =10”, that is ,let R = {(x,y) | x Î N, y Î N, x + 2y = 10}. Find a) the domain and range of R b) R-1