Computing Fundamentals 1 Lecture 7 Relations

Slides:



Advertisements
Similar presentations
Functions Reading: Epp Chp 7.1, 7.2, 7.4
Advertisements

Chapter 2 Revision of Mathematical Notations and Techniques
Computing Fundamentals 1 Lecture 8 Functions
The Engineering Design of Systems: Models and Methods
Discrete Structures Chapter 5 Relations and Functions Nurul Amelina Nasharuddin Multimedia Department.
Computing Fundamentals 1 Lecture 7 Relations Lecturer: Patrick Browne Room K308 Based on Chapter 14. A Logical approach.
Computing Fundamentals 1 Lecture 1 Lecturer: Patrick Browne Room K308 Based on Chapter 1. A Logical approach to Discrete.
CS5371 Theory of Computation Lecture 1: Mathematics Review I (Basic Terminology)
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,
Relations Chapter 9.
Chapter 9 1. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing.
Foundations of Discrete Mathematics Chapter 3 By Dr. Dalia M. Gil, Ph.D.
INTRODUCTION TO THE THEORY OF COMPUTATION INTRODUCTION MICHAEL SIPSER, SECOND EDITION 1.
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.
An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered.
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.
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.
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
MSU/CSE 260 Fall Functions Read Section 1.8.
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 5 – Relations and Functions. 5.1Cartesian Products and Relations Definition 5.1: For sets A, B  U, the Cartesian product, or cross product, of.
Language: Set of Strings
Discrete Mathematics Relation.
11 DISCRETE STRUCTURES DISCRETE STRUCTURES UNIT 5 SSK3003 DR. ALI MAMAT 1.
MATH 224 – Discrete Mathematics
CHAPTER 3 FUZZY RELATION and COMPOSITION. 3.1 Crisp relation Product set Definition (Product set) Let A and B be two non-empty sets, the product.
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
Relations. Important Definitions We covered all of these definitions on the board on Monday, November 7 th. Definition 1 Definition 2 Definition 3 Definition.
CS 103 Discrete Structures Lecture 19 Relations. Chapter 9.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing 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.
8.4 Closures of Relations Definition: The closure of a relation R with respect to property P is the relation obtained by adding the minimum number of.
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.
Discrete Mathematics 3. MATRICES, RELATIONS, AND FUNCTIONS Lecture 6 Dr.-Ing. Erwin Sitompul
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.
Discrete Mathematics Lecture # 17 Function. Relations and Functions  A function F from a set X to a set Y is a relation from X to Y that satisfies the.
Relations Chapter 9 Copyright © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill.
Relations and Their Properties
Chapter 5 Relations and Operations
Function Hubert Chan (Chapter 2.1, 2.2) [O1 Abstract Concepts]
Relations.
Relations, Functions, and Matrices
Equivalence Relations
Relations Chapter 9.
Set, Combinatorics, Probability & Number Theory
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.
MATH 224 – Discrete Mathematics
Chapter 2 Sets and Functions.
Relation and function.
Function Hubert Chan (Chapter 2.1, 2.2) [O1 Abstract Concepts]
Applied Discrete Mathematics Week 9: Equivalence Relations
CS201: Data Structures and Discrete Mathematics I
Jaya Krishna, M.Tech, Assistant Professor
Lecture 7 Functions.
CS2210 Discrete Structures Relations
Lesson 5 Relations, mappings, countable and uncountable sets
Advanced Algorithms Analysis and Design
Lesson 5 Relations, mappings, countable and uncountable sets
Mathematical Background 1
Mathematical Background 1
Introduction to Relations and Functions
Ch 5 Functions Chapter 5: Functions
MCS680: Foundations Of Computer Science
Lecture 4.1: Relations Basics
REVISION Relation. REVISION Relation Introduction to Relations and Functions.
Presentation transcript:

Computing Fundamentals 1 Lecture 7 Relations Lecturer: Patrick Browne http://www.comp.dit.ie/pbrowne/ Room K308 Based on Chapter 14. A Logical approach to Discrete Math By David Gries and Fred B. Schneider

Relations and Functions The term tuple is used to describe a row in a database. Tuples are record like structure e.g. <name,age>. Cross products represent the types (or sorts in CafeOBJ) in a tuple e.g. String  Nat Relations describe relationships between objects. Functions (covered in next lecture) are relations with some special properties.

Tuples1 Given expressions b and c then b,c is called an ordered pair. Well known ordered pairs are x,y coordinates in the plane, or name,address in a database. Axiom, Pair equality: b,c = b’,c’  b = b’  c = c’ A 2-tuple is called an ordered pair. http://en.wikipedia.org/wiki/Tuple 2. http://en.wikipedia.org/wiki/Plane_(mathematics)

Cross Products The Cross product (or Cartesian product) ST of two sets S and T is the set of all ordered pairs b,c such that b is in S and c is in T. Axiom Cross product (used in later proof): ST = {b,c | bS  cT : b,c} Cross products can be extended to n sets producing n-tuples.

Cross Products A 2-tuple: S = {2,5} T = {1,2,3}

Cross Products Example of a 2-tuple: S = {Mary,John} T = {John,Bill,Brent} ST = {Mary, John, Mary,Bill , Mary,Brent , John, John , John,Bill , John,Brent}

Cross Products Example ST =/= TS : S = {Mary,John} T = {John,Bill,Brent} TS = {<John,Mary>, <John,John>, <Bill,Mary>,<Bill,John>, <Brent,Mary>,<Brent,John>} ST = {Mary, John, Mary,Bill , Mary,Brent , John, John , John,Bill , John,Brent}

Some Theorems for Cross products Membership: x,y  ST  xS  yT Distributivity of  over  S  (TU)  (S  T)  (S  U) (S  T)  U  (S  U)  (T  U) Monotonicity T  U  (S  T)  (S  U)

Relations A relation is a subset of a cross product B1 B2  …  Bn A binary relation over BC is a subset of BC. It is possible to have a relation on BB. Well know relation lessThan(i,j)is difficult to enumerate (or list), so use: {i,j :  | j-i is positive : i,j}

Relations A relation can be represented by: A Set of ordered pairs A table e.g. a tuple in a database A directed graph A set comprehension; a rule based description similar to the quantifications of Chapter 8 Two notations for membership of relation  b,c   (set of pairs) b  c (infix, conjunctional)

Relation as Directed Graph One vertex for each element of the set. There is a directed edge from each vertex b to vertex c iff <b,c> is in the binary relation. 2 1 3 6 4 5 Set = {1,2,3,4,5,6} Relation = {<1,1>,<1,3>,<2,5>,<2,1>, <5,3>}

Diagraph of Relations Given the relation On the set {1,2,3} Below is the digraph of R. 1 2 3

Digraph Relations is a set of ordered pairs: Q = {<1, 4> ,<2, 4>} 2 2 1 1 3 4 4 (a) (b)

Digraphs Relations as sets of ordered pairs and digraphs: (c) R = {<1, 4>, <2, 3>, <3, 3>,<2, 1>} (d) S = {<3, 1> ,<1, 2> ,<2, 3>} 2 2 1 1 3 3 4 (c) (d)

A set of ordered pairs A Set of Relations (Ordered Pairs) With sets order is not significant {<3, 1> ,<1, 2> ,<2, 3>} = {<1, 2> ,<2, 3>, <3, 1>} With relations order is significant <3, 1> =/= <1, 3> {<3, 1> ,<1, 2> ,<2, 3>}=/={<1, 3> ,<1, 2> ,<2, 3>} 2 1 2 1 3 3

Relations on Sets The relation R on {1,2,3,4} is defined by <x,y>  R if x2y . The relation R can be written as a set of ordered pairs: R = {<1,1>,<2,1>,<3,1>,<4,1>,<2,2>,<3,2>,<4,2>,<2,3>,<3,3>,<4,3>,<2,4>,<3,4>,<4,4>}

Some Relations The empty relation on ST is the empty set . The identity relation iB on B is { x | x  B : x,x } The relation parent, b is a parent of c. The relation predecessor (pred(x)). The relation square root (see book1). The algorithm relation between input and output state. 1. Every positive number x has two square roots.

Relations Lower case Greek letters represent relations. The Greek letter  is pronounced rho. The Greek letter  is pronounced sigma. The domain, Dom., and range Ran. of a relation  on BC are defined as: Dom. = {Õb:B | (c |: b  c)} Ran. = {Õc:C | (b |: b  c)} The Greek letter  is pronounced rho (r in English) The Greek letter  is pronounced sigma (s in English)

Relations  Dom. = {b:B | (c|: b  c)} Ran. ={c:C | (b|: b  c)}

Classes of relations Name Property Reflexive (b| b  b) Irreflexive (b| (b  b)) Symmetric (b,c | (b  c)  (c  b))

Classes of relations Antisymmetric (b,c | (b  c)  (c  b)  b=c) Asymmetric (non-symmetric, see notes section) (b,c | (b  c)  (c  b)) Transitive (b,c,d | (b  c)  (c  d)  b  d) We will take the terms ‘non-symmetric’ and ‘not symmetric’ to mean asymmetric as defined above. Strictly speaking the ‘asymmetry’ described in the course text is stronger than ‘not symmetric’. There are definitions of ‘non-symmetric’ that may permit some pairs to have symmetry. Hence, we are omitting the mixed case where the relation holds for some elements of the relation, but not for others. For example, A = {1,2,3}  = {<1,2>, <2,1>,<2,3>} Then the relation  is neither symmetric nor antisymmetric, nor does it fit the definition of asymmetric above, which is kind of the opposite to symmetry. The relation < on integers is asymmetric. The relation <= on integers is antisymmetric. The relation ‘a fatherOf b’ is asymmetric. The stronger course definition of asymmetry implies ‘non-symmetric’, but the reverse implication does not hold.

Relations Discussion Common relations

Relations Discussion For symmetric relations  does not have to hold for all of A, (b  c) need only hold where (c  b) holds and visa versa. The relation  on {1,2,3}  = {<1,2>,<2,1>,<1,3>} is neither symmetric nor antisymmetric. It is not symmetric because there is no <3,1> to match the <1,3>. It is not antisymmetric because it has both <2,1> and <1,2>, but 12. Antisymmetric allows <1,1>. Recall that we will take the terms ‘non-symmetric’ and ‘not symmetric’ to mean asymmetric as defined above. The love(X,Y) relation is neither symmetric nor antisymmetric,

Relation Properties reflexive, yes <a,a> symmetric, no, has <3,2> and not <2,3> Antisymmetric, yes, because it is not symmetric and has symmetry on <a,a>. Asymmetric (which precludes <a,a>), no, because it is antisymmetric (which allows <a,a>).

Relation Properties reflexive, no because <a,a> doesn’t hold symmetric, yes for all <a,b> then <b,a> asymmetric, no, because it is symmetric. antisymmetric, no because no <a,b>,<b,a> with a=b.

Relation closure Example Let R = {<a,b>,<c,a>,<c,c> } be a relation on the set A={a,b,c}. The reflexive closure is: r(R) = {<a,b>,<c,a>,<a,a>,<b,b>,<c,c>} The symmetric closure is: s(R) = {<a,b>,<c,a>,<c,c>,<b,a>,<a,c>}

Closure The closure of a relation  with respect to some property (e.g. reflexivity) is the smallest relation that both has the property and contains . To construct a closure, add pairs to , but not too many, until it has the property. The less-than relation is not reflexive, but the less-than-or-equal-to relation is. For example, the reflexive closure of < over integers is the relation constructed by adding to the relation all pairs (b,b) for b an integer. Therefore  is the reflexive closure of <.

Closures Let R = {<1,2>,<3,1>,<3,3> } be a relation on the set A={1,2,3}. Calculate the following closures: the reflexive closure, the symmetric closure, Introductory Logic and Sets for Computer Scientists Addison Wesley Longman, 1999. http://myweb.lsbu.ac.uk/~nissanke/

Closures Reflexive Closure: A={1,2,3}. Closures Reflexive Closure: r(R) = {<1,2>,<3,1>,<1,1>,<2,2>,<3,3>} Symmetric Closure: s(R) = {<1,2>,<3,1>,<3,3>,<2,1>,<1,3>}

Functions Functions can be considered as a restricted form of relation. This is useful because the terminology and theory of relations carries over to function. In programming languages like Python or CafeOBJ a function can have a signature, which includes its name, type of argument and the type of the expected return value.

Fibonacci Function in Python and CafeOBJ Signature of a function consists of a name, argument(s) type, and return type Function Name Argument type p is a predecessor function mod* FIBO-NAT { pr(NAT) op fib : Nat -> Nat var N : Nat eq fib(0) = 0 . eq fib(1) = 1 . ceq fib(N) = fib(p(N)) + fib(p(p(N))) if N > 1 .} def fib(n): a, b = 0, 1 while b < n: print(b, end=' ') a, b = b, a+b print() Argument variable

Functions as relations While we can consider functions as a rule we can also think of functions as a binary relation B  C, that contains all pairs <b,c> such that f.b=c. A relation can have distinct values c and c’ that satisfy bfc and bfc’, but a function cannot. c Informally we can say that there is ‘no fan out’ from domain to range. Allowed for relations but not allowed for functions b c’

Types of Function Surjective : A function f:A → B is an surjective, or onto, function if the range of f equals the codomain of f. Injective : A function f : A → B is injective, or one-to-one, if no member of B is the image under f of two distinct elements of A. Bijective : A function f : A → B is bijective (a bijection) if it is both surjective and injective. A bijective function has an inverse.

A Function Given the data type Side. Side = left  right the function driveON Country  Side Representing the side of the road vehicles drive on is a surjection, because the range includes all the values of the type Side. Several countries may allow driving on the same side, It would usually be considered total because driveOn should be defined in all countries.

A function f from X to Y is a relation from X to Y having the Some examples, range on the left domain on the right A function is called a bijection , if it is onto and one-to-one. A bijective function has an inverse Function Application A function f from X to Y is a relation from X to Y having the properties: 1. The domain of f is in X. 2. If (x,y),(x,y’)f, then y=y’ (no fan out from domain). A total function from X to Y is denoted f: X Y.

Injective Surjective For each map state whether or not it represents a function. If it is a function state whether or not it represents a surjective, injective or bijective function. In each case explain your reasoning.