Download Relations-Discrete Mathematics-Lecture Slides and more Slides Discrete Mathematics in PDF only on Docsity!
Relations
Discrete Mathematics
Relations
- Relations are a formal means to specify which elements from two or more sets are related to each other
- Examples
- {students} who take {courses}
- {businesses} and their {telephone numbers}
- {integers} and their {divisors}
- {program variables} and the {subroutines} they are used in
Relations
Definition:
- Let A and B be two sets. A binary relation R from A to B is a subset of A × B. Example:
- Let A be the students in a the CS major
- • AA = {Ali Babar Daud}= {Ali, Babar, Daud}
- Let B be the courses the department offers
- B = {CIS101, CIS102, CIS143}
- We specify relation R = A × B as the set that lists all students a ∈ A enrolled in class b ∈ B
- R = { (Ali, CIS101), (Babar, CIS102), (Babar, CS143), (Daud, CIS143), (Daud, CIS102) }
Representing Relations
Ali
CIS101 CIS102 CIS
We can represent relations graphically:
We can represent relations in a table:
4
CIS
CIS
CIS
Ali
Babar
Daud
Ali (^) X Babar (^) X X Daud (^) X X
Not valid functions!
docsity.com
Relations
Functions
- A function f : A → B is a special case of a relation from A to B. A function f from a set A to a set B assigns a unique element of B to each element of A. The graph of f is the set of ordered pairs (a,b) such that b=f(a).
Relations
Relations
- Relations are a generalization of functions
- They allow unmapped elements from A
- They allow one-to-many mappings where an element from A maps to multiple elements from B
- They also allow many-to-one and many-to-many mappings
Relations vs. Functions
- Not all relations are functions
- But consider the following function:
1 2 3
a b
7
- All functions are relations!
3 4
c d
When to use which?
- A function is used when you need to obtain a SINGLE result for any element in the domain - Example: sin, cos, tan
- A relation is when there are multiple mappings between the domain and the co-domain
8
- Example: students enrolled in multiple courses
docsity.com
Relations
Example: Let A be the set {1,2,3,4}. Which ordered pairs are in the relation R ={(a,b) | a divides b}?
Solution: R = {(1,1), (1,2), (1,3), (1,4), (2,2), (2,4), (3,3), (4,4)}
Relations
Example: Let A be the set {1,2,3,4}. Which ordered pairs are in the relation R ={(a,b) | a divides b}?
Solution: R = {(1,1), (1,2), (1,3), (1,4), (2,2), (2,4), (3,3), (4,4)}
Properties of Relations
One-One Relations:
- In a one-one relation between the elements of a set A and the elements of a set B, each element of A is related to exactly one element of B, and each element of B is related to exactly one element of A. Example:Example:
- Let x stand for one of the twenty-six numbers in the set {1, 2, ..., 25, 26} and let y stand for one of the letters of the alphabet: {A, B, ..., Y, Z}. Let x R y mean x is the position of the letter y in alphabetical order. Then we have a one-one relation with the elements related as follows: 1 R A, 2 R B, ..., 25 R Y, 26 R Z.
Properties of Relations
One-Many Relations:
- In a one-many relation between the elements of a set A and the elements of a set B, each element of A may be related to more than one element of B, but each element of B is related to only one element of A. Example:Example:
- Let x and y stand for people, and let x R y mean x is the father of y. This is a one-many relation because each father can have any number of children, but each child has only one father. Note that in this example the people in the set A are all men with children.
docsity.com
Properties of Relations
Many-Many Relations:
- In a many-one relation between the elements of a set A and the elements of a set B, each element of A is related to only one element of B, but each element of B may be related to more than one element of A. Example:Example:
- Let x stand for a person, let y stand for a number of years, and let x R y mean x is y years old. This is a many-one relation because there are many people with the same age in years, but each person has only one age.
Properties of Relations
Department of Computer & Information Sciences Pakistan Institute of Engineering and Applied Sciences
Umar Faiz http://www.pieas.edu.pk/umarfaiz/cis
Discrete Mathematics
Properties of Relations
Reflexive Relations:
- A relation R on a set A is called reflexive if every element of A is related to itself. Example: Let x and y stand for telescopes, and let x R y mean x hhas the same power as y. Then R is reflexive because th Th R i fl i b every telescope has the same power as itself.
Reflexivity
- Reflexive Relations (Matrix Representation):
- Consider a reflexive relation having the property that every element of A is related to itself. Let A = { 1, 2, 3, 4, 5 }
20
⎥
⎥
⎥
⎥
⎥
⎥
⎦
⎤
⎢
⎢
⎢
⎢
⎢
⎢
⎣
⎡
≤=
0 0 0 0 1
0 0 0 1 1
0 0 1 1 1
0 1 1 1 1
1 1 1 1 1
M
If the center (main) diagonal is all 1’s, a relation is reflexive
docsity.com
Properties of Relations
Example:
- Let A = {1, 2, 3} and R = {(1, 1), (1, 2)} be a relation on A x A
- R is neither reflexive nor irreflexive.
- Examples of relations that are not irreflexive: =, ≤, ≥
Properties of Relations
Symmetric Relations:
- A relation R on set A is called symmetric if whenever aRb then bRa. Example:
- If a is a sibling of b, then b is a sibling of a.
- Other examples of symmetric relations: near to, compatriot of, married to.
Properties of Relations
Symmetric Relations (Matrix Representation):
- Consider an symmetric relation R having the property that if a is related to b then b is related to a for all (a,b) Let A = { 1, 2, 3, 4, 5 }
27
⎥
⎥
⎥
⎥
⎥
⎥
⎦
⎤
⎢
⎢
⎢
⎢
⎢
⎢
⎣
⎡
≤=
0 1 0 0 1
1 0 0 1 0
1 0 0 0 0
0 0 0 0 1
1 0 1 1 0
M
If, for every value, it is the equal to the value in its transposed position, then the relation is symmetric
Properties of Relations
Example: Which of the following relations on {1,2,3,4} are symmetric? R1={(1,1), (1,2), (2,1), (2,2), (3,4), (4,1), (4,4)} R2={(1,1), (1,2), (2,1)} R3={(1,1), (1,2), (1,4), (2,1), (2,2), (3,3), (4,1), (4,4)} R4={(2,1), (3,1), (3,2), (4,1), (4,2), (4,3)}{( , ), ( , ), ( , ), ( , ), ( , ), ( , )} R5={(1,1}, (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4), (4,4)} R6={(3,4)} Solution: The relations R2 and R3 are symmetric, because in each case (b,a) belongs to the relation whenever (a,b) does. For R2, the only thing to check is that both (2,1) and (1,2) are in the relation.
docsity.com
Properties of Relations
Symmetric Relations:
- The empty relation {} on any set is symmetric, because "(x
- The relation {(1,1)} is symmetric, since (x,y) in R is only true for x = y = 1, and, in that case, we also have (y x) in R (it's the same pair) y) in R" is always false(y,x) in R (it s the same pair).,y) in R is always false.
Properties of Relations
Asymmetric Relations:
- A relation R on set A is called asymmetric having the property that whenever (a,b) ∈R then (b,a) ∉R. In other words, a relation R on set A is called asymmetric having the property that whenever x R y thenthen itit isis nevernever thethe casecase thatthat y R xy R x Example:
- For example, if a is a parent of b, then b is not a parent of a.
- Other example of asymmetric relations: East of, bigger than, taller than, ancestor of.
Properties of Relations
Asymmetric Relations (Matrix Representation):
- Consider an asymmetric relation having the property that if a is related to b then b is not related to a for all (a,b) Let A = { 1, 2, 3, 4, 5 } If f l d h l i
31
⎥
⎥
⎥
⎥
⎥
⎥
⎦
⎤
⎢
⎢
⎢
⎢
⎢
⎢
⎣
⎡
=
0 0 0 0 0
0 0 0 0 1
0 0 0 1 1
0 0 1 1 1
0 1 1 1 1
M
If, for every value and the value in its transposed position, if they are not both 1, then the relation is asymmetric An asymmetric relation must also be irreflexive. Thus, the main diagonal must be all 0’s
Properties of Relations
AntiSymmetric Relations:
- A relation R on set A is called antisymmetric if whenever aRb and bRa then a=b. A relation R is antisymmetric if for every a≠b ∈A, aRb implies ¬(bRa),
- Antisymmetry is not the opposite of symmetry EExample: l
- If a is a brother of b, it is open whether or not b is a brother of a.
- Other example of asymmetric relations: in love with, bigger-than-or-equal-to, logically follows from, =, ≤, ≥
docsity.com
Properties of Relations
Transitive Relations (Matrix Representation):
- Consider an transitive relation having the property that if a is related to b and b is related to c then a is related to c for all (a,b), (b,c) and (a,c) Let A = { 1, 2, 3, 4, 5 }
37
⎥
⎥
⎥
⎥
⎥
⎥
⎦
⎤
⎢
⎢
⎢
⎢
⎢
⎢
⎣
⎡
≤=
0 0 0 0 1
0 0 0 1 1
0 0 1 1 1
0 1 1 1 1
1 1 1 1 1
M
If, for every spot (a,b) and (b,c) that each have a 1, there is a 1 at (a,c), then the relation is transitive. Matrices don’t show this property easily
Properties of Relations
Example: Which of the following relations on {1,2,3,4} are transitive? R1={(1,1), (1,2), (2,1), (2,2), (3,4), (4,1), (4,4)} R2={(1,1), (1,2), (2,1)} R3={(1,1), (1,2), (1,4), (2,1), (2,2), (3,3), (4,1), (4,4)} R4={(2,1), (3,1), (3,2), (4,1), (4,2), (4,3)}R4 {(2,1), (3,1), (3,2), (4,1), (4,2), (4,3)} R5={(1,1}, (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4), (4,4)} R6={(3,4)} Solution: R2 and R5 are transitive.
Properties of Relations
Transitive Relations:
- The empty relation {} on any set is transitive, because "(x,y) in R" is always false.
Properties of Relations
Summary:
- To show that a relation is:
- not reflexive, you must find an element x of A such that (x,x) is not in R
- asymmetric, you must find elements x and y of A such th t Rthat R contains (x,y) but not (y,x) t i ( ) b t t ( )
- not transitive, you must find elements x,y,z of A (not necessarily distinct) such that R contains (x,y) and (y,z) but not (x,z)
docsity.com
Relations on a Set
Number of Relations on a Set: Let A be a set with 8 elements. How many binary relations are there on A? Solution: A binary relation is any subset of AxA and AxA has 8^^2 = 64 elements So there are 2^= 64 elements. So there are 2 64 binary relations on Abinary relations on A.
Relations on a Set
Number of Relations on a Set: Let A be a set with 8 elements. How many binary relations are there on A are reflexive? Solution: There are exactly 8x, so you have 8 of the 64 results of AxA so you have 2^AxA so you have 2 (64-8)(^ )^ = 2^= 2 56 reflexive relationsreflexive relations.
Relations on a Set
Number of Relations on a Set: Let A be a set with 8 elements. How many binary relations are there on A are symmetric? Solution: Form a symmetric relation by a 2 step process: 1 Pick a set of pairs of elements of the form (a a) (there1. Pick a set of pairs of elements of the form (a,a) (there are 8 such elements , so 2^^8 sets);
- Pick a set of pairs of elements of the form (a,b) and (b,a) where a != b (there are (64-8)/2 = 28 such pairs or 2^^28 such sets. By the multiplication rule is 2^^8 * 2^^28 = 2^^36.
Operations on Relations
Department of Computer & Information Sciences Pakistan Institute of Engineering and Applied Sciences
Umar Faiz http://www.pieas.edu.pk/umarfaiz/cis
Discrete Mathematics
docsity.com
Combining Relations via Relational Composition
- Let R be a relation from A to B, and S be a relation from B to C - Let a ∈ A, b ∈ B, and c ∈ C - Let (a,b) ∈ R, and (b,c) ∈ S - Then the composite of R and S consists of the ordered pairs (a,c)d d i ( ) - We denote the relation by S ◦ R - Note that S comes first when writing the composition!
49
Combining Relations via Relational Composition
- Let M be the relation “is mother of”
- Let F be the relation “is father of”
- What is M ◦ F?
- If (a,b) ∈ F, then a is the father of b
- If (b,c) ∈ M, then b is the mother of c
- Thus, MTh M ◦ F dF d enotes the relation “maternal grandfather”t th l ti “ t l df th ”
- What is F ◦ M?
- If (a,b) ∈ M, then a is the mother of b
- If (b,c) ∈ F, then b is the father of c
- Thus, F ◦ M denotes the relation “paternal grandmother”
50
Combining Relations via Relational composition
- Let M be the relation “is mother of”
- Let F be the relation “is father of”
- What is M ◦ M?
- If (a,b) ∈ M, then a is the mother of b
- If (b,c) ∈ M, then b is the mother of c
- Thus, MTh M ◦ M dM d enotes the relation “maternal grandmother”t th l ti “ t l d th ”
- Note that M and F are not transitive relations!!!
51
Combining Relations via Relational Composition
- Given relation R
- R ◦ R can be denoted by R^2
- R^2 ◦ R = (R ◦ R) ◦ R = R^3
- Example: M^3 is your mother’s mother’s mother
52
docsity.com
Composite of a Relation
Composite of a Relation:
- Suppose R is a relation from A to B (R ⊆ AxB), and S is a relation from B to C (S ⊆ BxC). The composite of R and S (S°R) is the relation from A to C (S°R ⊆ AxC)consisting of ordered pairs (a,c) such that there exists an element b in B with (a,b) element-of R andexists an element b in B with (a,b) element of R and (b,c) element-of S. S°R = {(a,c): ∃ b∈B, (a,b) ∈ R, (b,c) ∈ S}
Composite of a Relation
S°R = {(1,u),(1,v),(2,t),(3,t),(4,u)}
1 x s
R (^) S
A B C
2 3 4
y z
t u v
Composite of a Relation
- Let R be a relation on A. Inductively define R^1 = R Rn+1^ = Rn^ ° R A A^ A 1 1
R (^) R 1 1
R^2 = R^1 °R = {(1,1),(1,2),(1,3),(2,3),(3,3),(4,1), (4,2)}
2 3 4
2 3 4
2 3 4
Composite of a Relation
- Let R be a relation on A. Inductively define R^1 = R Rn+1^ = Rn^ ° R A A^ A 1 1
R (^) R 1 1
R^3 = R^2 °R = {(1,1),(1,2),(1,3),(2,3),(3,3),(4,1),(4,2),(4,3)}
2 3 4
2 3 4
2 3 4
docsity.com
Power of a Relation
Power of a Relation:
- Suppose R is relation on set A. The POWERS of R are defined recursively as R^ 1 = RR^{n+1}^ = R^n^ ° R. Example: Suppose A = {1,2,3,4} R = {(1,1), (2,1), (3,2), (4,3)} R^^1 = {(1,1), (2,1), (3,1), (4,2)} R^^2 = {(1,1), (2,1), (3,1), (4,2)} R^^3 = {(1,1), (2,1), (3,1), (4,1)} R^^4 = R^^3 etc.
Closure of Relations
Closure of Relations:
- Sometimes we have a relation that does NOT have a desired property (such as transitivity or symmetry or reflexivity) and we would like to modify the relation as little as possible so that it does have the property.
Closure of Relations
Reflexive/Symmetric/Transitive Closure:
- Given a relation R on a set, the smallest superset of R that is reflexive/symmetric/transitive is called the reflexive/symmetric/transitive CLOSURE of R.
Closure of Relations
Computing Reflexive Closure:
- Just add all pairs of the form (a,a) Computing Symmetric Closure:
- Just add all pairs that are the "opposite" of the pairs in the relation. Computing Transitive Closure:
- This is more complicated than the other two. General idea is to keep adding new pairs that are required for transitivity until no new pairs are needed.
docsity.com
Reflexive Closure
Example: Consider relation R={(1,2),(2,2),(3,3)} on the set A = {1,2,3,4}. Is R reflexive? Solution: No What can we add to R to make it reflexive? (1,1), (4,4)
R’ = R U {(1,1),(4,4)} is called the reflexive closure of R.
Symmetric Closure
Example: Consider relation R={(1,2),(2,2),(3,3)} on the set A = {1,2,3,4}. Is R symmetric? Solution: No What can we add to R to make it symmetric? (2,1)
R’ = R U {(2,1)} is called the symmetric closure of R.
Transitive Closure
Example: Consider the relation R={(1,2),(2,3),(3,4)} on the set A={1,2,3,4}. Is the relation R transitive? Solution: No
WhWhat should be added to make it transitive? h ld b dd d k i i i?
R’ = R U {(1,3),(2,4)}
Equivalence Relations
Equivalence Relations:
- An equivalence relation is a relation which is reflexive, symmetric and transitive.
docsity.com
Equivalence Relations
Equivalence Classes: (2) The union of all the equivalence classes is the universal set.
The reason for property (2) is that every element in the universali l sett iis usedd tto fform ththe collectionll ti off equivalence classes; no element is left out.
Equivalence Relations
Example:
- Let the universal set consist of motor vehicles; and let x R y mean x has the same number of wheels as y. Then motorcycles are equivalent because they all have two wheels; motor-cars are equivalent because they all have four wheels; etc.all have four wheels; etc. (1) Since every vehicle has the same number of wheels as itself, R is reflexive. (2) x has the same number of wheels as y always implies y has the same number of wheels as x, R is symmetric. (3) If x and y have the same number of wheels, and if y and z have the same number of wheels, then x and z have the same number of wheels; therefore, R is transitive.
Equivalence Relations
Example:
- Consider assigning exam grades to a class. A grading scale like 80–100 is an A+, 75–79 is a A, etc. It is same as establishing an equivalence relation. All scores from 80 to 100 are “the same” They all give students the same grade. In this sense you might write 81=87 butsame grade. In this sense you might write 81 87 but 79 ≠80 since 81 and 87 are both A+’s, but 79 is a A.
2/2/
75
Equivalence Relations
Example:
- Let A be the set of congruent triangles in the plane, prove that a relation R on A is an equivalence relation - If a is a triangle, then a is congruent to itself, so aRa. Thus R is reflexive. - If a and b are triangles with aRb, then bRa as well (if aIf d b t i l ith Rb th bR ll (if is congruent to b, then b is congruent to a). Thus R is symmetric. - If a, b, and c are triangles with aRb and bRc, then aRc (if a is congruent to b and b is congruent to c, then a is congruent to c). Thus R is transitive. Therefore congruence of triangles is an equivalence relation.
docsity.com
Equivalence Relations
Example:
- Let A be the set of people living at only one address in the Pakistan. Define a relation R on A by aRb if and only if a and b live in the same zip code. Show that R is an equivalence relation.
2/2/
77
Equivalence Relations
Solution:
- Let aאA. Then aRa since everyone lives in the same zip code as himself, so R is reflexive. Let a,bאA with aRb. This say a lives in the same zip code as b. Thus b lives in the same zip code as a, so bRa and R is symmetric. Let a,b,csymmetric. Let a,b,c אאA with aRb and bRc. Then aA with aRb and bRc. Then a lives in the same zip code as b and b lives in the same zip code as c, so a lives in the same zip code as c. So aRc and R is transitive. Therefore R is an equivalence relation.
78
Ordering
Partially Ordered Sets (Posets):
- Let A be a set, and let R be a relation on A that is reflexive, antisymmetric, and transitive: Then R is a partial order on A, and the pair (A,R) is called a partially ordered set or poset for short.
- The only difference between an equivalence relation– The only difference between an equivalence relation and a partial order is that the former is symmetric and the latter is antisymmetric.
- We use the symbol “≤” to denote a partial order on a set.
79
Ordering
- Partially Ordered Sets (Posets):
- Suppose we have a set A and build a collection S of subsets of A. Then set inclusion is a partial order on S. For example, suppose A = {a, b, c} and S contains all subsets of A. Then we have
- Notice that {a, b} and {b, c} aren't comparable, because neither is a subset of the other. (^80)
docsity.com