§7.1 binary relations (2 nd pass) and §7.2 n-ary relations longin jan latecki

28
06/27/22 1 §7.1 Binary Relations (2 nd pass) and §7.2 n-ary Relations Longin Jan Latecki Slides adapted from Kees van Deemter who Slides adapted from Kees van Deemter who adopted them from Michael P. Frank’s adopted them from Michael P. Frank’s Course Based on the Text Course Based on the Text Discrete Mathematics & Its Applications Discrete Mathematics & Its Applications (5 (5 th th Edition) Edition) by Kenneth H. Rosen by Kenneth H. Rosen

Upload: trevor-camacho

Post on 31-Dec-2015

31 views

Category:

Documents


1 download

DESCRIPTION

§7.1 Binary Relations (2 nd pass) and §7.2 n-ary Relations Longin Jan Latecki. Slides adapted from Kees van Deemter who adopted them from Michael P. Frank’s Course Based on the Text Discrete Mathematics & Its Applications (5 th Edition) by Kenneth H. Rosen. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 1

§7.1 Binary Relations (2nd pass)and §7.2 n-ary Relations

Longin Jan Latecki

Slides adapted from Kees van Deemter who adopted them Slides adapted from Kees van Deemter who adopted them from Michael P. Frank’s from Michael P. Frank’s Course Based on the TextCourse Based on the Text

Discrete Mathematics & Its ApplicationsDiscrete Mathematics & Its Applications (5(5thth Edition) Edition)

by Kenneth H. Rosenby Kenneth H. Rosen

Page 2: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 2

§7.1 Binary Relations (2nd pass)

• Let Let AA, , BB be any sets. A be any sets. A binary relationbinary relation RR from from AA to to B B is a subset of is a subset of AA××BB. . – E.g.E.g.,, << can be seen ascan be seen as {({(nn,,mm)) | | n n < < mm}}

• ((aa,,bb))R R means thatmeans that aa is related to is related to bb (by (by RR))• Also written asAlso written as aRbaRb; ; alsoalso R(a,b)R(a,b)

– E.g.,E.g., aa<b<b and and << ( (a,b)a,b) both both meanmean (a,b)(a,b) <<• A binary relation A binary relation R R corresponds to a characteristic corresponds to a characteristic

function function PPRR::AA××BB→{→{TT,,FF} }

Page 3: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 3

Complementary Relations

• Let Let RR::AA,,BB be any binary relation. be any binary relation.• Then, Then, RR::AA××BB, the , the complementcomplement of of RR, is the , is the

binary relation defined bybinary relation defined by RR:≡{(:≡{(aa,,bb))AA××BB | ( | (aa,,bb))RR}=(}=(AA××BB) − ) − RR

• Note this is just Note this is just RR if the universe of if the universe of discourse is discourse is UU = = AA××BB; thus the name ; thus the name complement.complement.

• Note the complement of Note the complement of RR is is RR..Example: << = {( = {(aa,,bb) | () | (aa,,bb))<<} = {(} = {(aa,,bb) | ) | ¬¬aa<<bb} = } = ≥≥

Page 4: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 4

Inverse Relations

• Any binary relation Any binary relation RR::AA××BB has an has an inverseinverse relation relation RR−1−1::BB××AA, defined by, defined by

RR−1 −1 :≡ {(:≡ {(bb,,aa) | () | (aa,,bb))RR}}..

E.g.E.g., , <<−1−1 = {( = {(bb,,aa) | ) | aa<<bb} = {(} = {(bb,,aa) | ) | bb>>aa} = } = >>..

• E.g.E.g., if , if RR:People x Foods is defined by :People x Foods is defined by a R ba R b aa eatseats bb, then: , then: bb RR−1−1

aa bb is eaten byis eaten by aa. (Passive voice.). (Passive voice.)

Page 5: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 5

Relations on a Set

• A (binary) relation from a set A (binary) relation from a set AA to itself is to itself is called a relation called a relation onon the set the set AA..

• E.g.E.g., the “, the “<<” relation from earlier was ” relation from earlier was defined as a relation defined as a relation onon the set the set NN of natural of natural numbers.numbers.

Page 6: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 6

Reflexivity and relatives

• A relation A relation RR on on AA is is reflexivereflexive iff iff aaA(aRa)A(aRa)..– E.g.E.g., the relation , the relation ≥≥ :≡ {( :≡ {(aa,,bb) | ) | aa≥≥bb}} is reflexive. is reflexive.

• RR is is irreflexiveirreflexive iff iff aaA(A(aRa)aRa)

• Note “Note “irreflexiveirreflexive” does ” does NOTNOT mean “ mean “notnot reflexivereflexive”, which is just ”, which is just aaA(aRa)A(aRa)..

Page 7: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 7

Reflexivity and relatives

• Theorem:Theorem: A relation A relation RR is is irreflexiveirreflexive iff its iff its complementarycomplementary relation relation RR is reflexive. is reflexive.– Example: Example: << is irreflexive; ≥ is reflexive. is irreflexive; ≥ is reflexive.– Proof: trivialProof: trivial

Page 8: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 8

• Can you think ofCan you think of– Reflexive relationsReflexive relations– Irreflexive relationsIrreflexive relations

Involving numbers, propositions or sets?Involving numbers, propositions or sets?

Page 9: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 9

Some examples

• Reflexive: Reflexive: =, `have same cardinality’, =, `have same cardinality’, <=, >=, <=, >=, , , , etc., etc.

• Irreflexive:Irreflexive:<, >, `have different cardinality’, <, >, `have different cardinality’,

Page 10: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 10

Symmetry & relatives• A binary relation A binary relation RR on on AA is is symmetricsymmetric iff iff

a,b((a,b((aa,,bb))RR ↔ (↔ (bb,,aa))R)R)..– E.g.E.g., , == (equality) is symmetric. (equality) is symmetric. << is not. is not.– ““is married to” is symmetric, “likes” is not.is married to” is symmetric, “likes” is not.

• A binary relation A binary relation RR is is asymmetricasymmetric if if aa,,bb((((aa,,bb))RR → (→ (bb,,aa))R)R)..– Examples: <Examples: < is asymmetric, “likes” is not. is asymmetric, “likes” is not.

Page 11: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 11

Some direct consequencesTheorems:Theorems:

1.1. R is symmetric iff R is symmetric iff RR = = RR−1−1,,

2.2. R is asymmetric iff R is asymmetric iff RRRR−1−1 is empty is empty. .

Page 12: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 12

Symmetry & relatives1. R is symmetric iff 1. R is symmetric iff RR = = RR−1−1

Suppose R is symmetric. Then Suppose R is symmetric. Then (x,y) (x,y) R R (y,x) (y,x) R R (x,y) (x,y) RR−1−1

Suppose RR = = RR−1 −1 Then Then (x,y) (x,y) R R (x,y) (x,y) RR−1 −1 (y,x) (y,x) R R

Page 13: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 13

Symmetry & relatives2. R is asymmetric iff 2. R is asymmetric iff RRRR−1−1 is empty is empty..

(Straightforward application of the (Straightforward application of the definitions of asymmetry and definitions of asymmetry and RR−1−1) )

Page 14: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 14

Antisymmetry• Consider the relation Consider the relation xxyy

– It is not symmetric. (For instance, It is not symmetric. (For instance, 5566 but not but not 6655))

– It is not asymmetric. (For instance, It is not asymmetric. (For instance, 5 5 55))

– You might say it’s You might say it’s nearlynearly symmetric, since the symmetric, since the only symmetries occur when only symmetries occur when x=yx=y

• This is called This is called antisymmetryantisymmetry::

Page 15: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 15

Antisymmetry• A binary relation A binary relation RR on on AA is is antisymmetricantisymmetric iff iff

a,b((a,b((aa,,bb))RR ( (bb,,aa))RR a=b) a=b)..

• Examples: Examples: , , , ,

Page 16: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 16

Transitivity

• A relation A relation RR is is transitivetransitive iff (for all iff (for all aa,,bb,,cc))((((aa,,bb))RR ( (bb,,cc))R)R) → (→ (aa,,cc))RR..

Example: “is an ancestor of” Example: “is an ancestor of” is transitiveis transitive..

Page 17: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 17

Composite Relations

• Let Let RR::AA×B×B, and , and SS::B×CB×C. Then the . Then the compositecomposite SSRR of of RR and and SS is defined as: is defined as:

SSR R = {(= {(aa,,cc) | ) | bb: : aRbaRb bScbSc}}

• Function composition is an example: writing fFunction composition is an example: writing fT T for for

the function-version of the relation T, we havethe function-version of the relation T, we have

SSRR((aa,,cc)) iff iff bb: : aRbaRb bSc bSc iff fiff fRR(a)=b and f(a)=b and fSS(b)=c(b)=c

iff fiff fSSffRR(a)=c(a)=c

Page 18: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 18

Composite Relations

• The The nnthth power power RRnn of a relation of a relation RR on a set on a set AA can be defined recursively by:can be defined recursively by:

RR00 :≡ :≡ IIAA ;; RRnn+1 +1 :≡ :≡ RRnnRR for all for all nn≥0≥0..

• E.g., E.g., RR11 =R; =R; RR2 2 == RRR;R; RR33== RRRRRR

a

b c

de

Page 19: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 19

Composite Relations

• RR22== RRR =R =(a, c)(a, c) (e, c)(e, c) (b, d) (b, d) (d, d)(d, d) (c, c)(c, c)

a

b c

de

a

b c

de

Page 20: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 20

§7.2: n-ary Relations

• An An nn-ary relation -ary relation RR on sets on sets AA11,…,,…,AAnn,,

is a subsetis a subset R R AA11× … × × … × AAnn..

• The sets The sets AAii are called the are called the domainsdomains of of RR..

• The The degreedegree of of RR is is nn..

• A A relational databaserelational database is essentially just a is essentially just a set of relations.set of relations.

Page 21: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 21

§7.2: n-ary Relations

• An An nn-ary relation -ary relation RR is a straightforward is a straightforward generalisation of a binary relation. For generalisation of a binary relation. For example:example:

• 3-ary relations: 3-ary relations: – a is between b and c; a is between b and c; – a gave b to ca gave b to c

Page 22: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 22

Relational Databases

• A domain A domain AAii is a is a primary keyprimary key for the database if for the database if the relation the relation RR is functional in is functional in AAii..

• RR is is functional in the domain Afunctional in the domain Aii if it contains at if it contains at most one most one nn-tuple -tuple (…, (…, aai i ,…),…) for any value for any value aaii within domain within domain AAii..

• A A composite keycomposite key for the database is a set of for the database is a set of domains domains {{AAii, , AAjj,, … …}} such that such that RR contains at most 1 contains at most 1 nn-tuple -tuple (…,(…,aaii,…,,…,aajj,…),…) for each composite value for each composite value ((aaii,,aajj,…),…)AAii××AAjj×…×…

Page 23: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 23

Selection Operators

• Let Let AA be any be any nn-ary domain -ary domain AA==AA11××……××AAnn, , and let and let CC::AA→{→{TT,,FF}} be any be any conditioncondition (predicate) on elements ((predicate) on elements (nn-tuples) of -tuples) of AA..

• Then, the Then, the selection operatorselection operator ssCC is the is the operator that maps any (operator that maps any (nn-ary) relation -ary) relation RR on on AA to the to the nn-ary relation consisting of all -ary relation consisting of all nn-tuples from -tuples from RR that satisfy that satisfy C. C. That is,That is,ssCC((RR) = {) = {aaRR | C( | C(aa) = ) = TT}}

Page 24: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 24

Selection Operator Example

• Suppose we have a domain Suppose we have a domain A A = StudentName = StudentName × Standing × SocSecNos× Standing × SocSecNos

• Suppose we define a condition Suppose we define a condition UpperlevelUpperlevel on on A:A: UpperLevelUpperLevel((namename,,standingstanding,,ssnssn) :≡ ) :≡ [([(standing = standing = junior)junior) ( (standingstanding = senior)] = senior)]

• Then, Then, ssUpperLevelUpperLevel is the selection operator that takes is the selection operator that takes any relation any relation RR on on AA (database of students) and (database of students) and produces a relation consisting of produces a relation consisting of justjust the upper- the upper-level students (juniors and seniors).level students (juniors and seniors).

Page 25: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 25

Projection Operators

• Let Let AA = = AA11×…××…×AAnn be any be any nn-ary domain, and -ary domain, and let let {{iikk}=(}=(ii11,…,,…,iimm)) be a sequence of indices be a sequence of indices all falling in the range 1 to all falling in the range 1 to nn,,– That is, That is, 1 ≤ 1 ≤ iik k ≤ n≤ n for all for all 1 ≤ 1 ≤ kk ≤ ≤ mm..

• Then the Then the projection operatorprojection operator on on nn-tuples-tuples

is defined by:is defined by:

mk iii AAAP 1

:}{

),...,(),...,(11}{ mk iini aaaaP

Page 26: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 26

Projection Example

• Suppose we have a ternary (3-ary) domain Suppose we have a ternary (3-ary) domain CarsCars==ModelModel××YearYear××ColorColor. . (note (note nn=3).=3).

• Consider the index sequence Consider the index sequence {{iikk}= 1,3}= 1,3. (. (mm=2)=2)• Then the projection Then the projection P P maps each tuple maps each tuple

((aa11,,aa22,,aa33) = () = (modelmodel,,yearyear,,colorcolor)) to its image: to its image:

• This operator can be usefully applied to a whole This operator can be usefully applied to a whole relation relation RRCarsCars (a database of cars) to obtain a (a database of cars) to obtain a list of the model/color combinations available.list of the model/color combinations available.

{ik}

),(),(),( 3121colormodelaaaa ii

Page 27: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 27

Join Operator

• Puts two relations together to form a Puts two relations together to form a combined relation.combined relation.

• If the tuple If the tuple ((AA,,BB)) appears in appears in RR11, and the , and the

tuple tuple ((BB,,CC)) appears in appears in RR22, then the tuple , then the tuple

((AA,,BB,,CC)) appears in the join appears in the join JJ((RR11,,RR22))..

– AA, , BB, and , and CC can also be sequences of elements. can also be sequences of elements.

Page 28: §7.1  Binary Relations (2 nd  pass) and  §7.2  n-ary Relations  Longin Jan Latecki

04/19/23 28

Join Example

• Suppose Suppose RR11 is a teaching assignment table, is a teaching assignment table,

relating relating LecturersLecturers to to CoursesCourses. .

• Suppose Suppose RR22 is a room assignment table is a room assignment table

relating relating CoursesCourses to to RoomsRooms,,TimesTimes..

• Then Then JJ((RR11,,RR22)) is like your class schedule, is like your class schedule,

listing listing ((lecturerlecturer,,coursecourse,,roomroom,,timetime))..

• (For precise definition, see Rosen, p.486)(For precise definition, see Rosen, p.486)