1 relations and their properties rosen, section 7.1 cs/apma 202 aaron bloomfield

Post on 04-Jan-2016

213 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

11

Relations and Their Relations and Their PropertiesProperties

Rosen, section 7.1Rosen, section 7.1

CS/APMA 202CS/APMA 202

Aaron BloomfieldAaron Bloomfield

22

What is a relationWhat is a relation

Let Let AA and and BB be sets. A binary relation be sets. A binary relation RR is a is a subset of subset of AA BB

ExampleExample Let Let AA be the students in a the CS major be the students in a the CS major

AA = {Alice, Bob, Claire, Dan} = {Alice, Bob, Claire, Dan} Let Let BB be the courses the department offers be the courses the department offers

BB = {CS101, CS201, CS202} = {CS101, CS201, CS202} We specify relation We specify relation RR = = AA BB as the set that lists all as the set that lists all

students students aa AA enrolled in class enrolled in class bb BB R = { (Alice, CS101), (Bob, CS201), (Bob, CS202),R = { (Alice, CS101), (Bob, CS201), (Bob, CS202),

(Dan, CS201), (Dan, CS202) } (Dan, CS201), (Dan, CS202) }

33

More relation examplesMore relation examples

Another relation example:Another relation example: Let Let AA be the cities in the US be the cities in the US Let Let BB be the states in the US be the states in the US We define We define RR to mean to mean aa is a city in state is a city in state bb Thus, the following are in our relation:Thus, the following are in our relation:

(C’ville, VA)(C’ville, VA)(Philadelphia, PA)(Philadelphia, PA)(Portland, MA)(Portland, MA)(Portland, OR)(Portland, OR)etc…etc…

Most relations we will see deal with ordered Most relations we will see deal with ordered pairs of integerspairs of integers

44

Representing relationsRepresenting relations

CS101

CS201

CS202

Alice

Bob

Claire

Dan

CS101CS101 CS201CS201 CS202CS202

AliceAlice XXBobBob XX XXClaireClaire

DanDan XX XX

We can represent relations graphically:

We can represent relations in a table:

Not valid functions!

55

Relations vs. functionsRelations vs. functions

Not all relations are functionsNot all relations are functions

But consider the following function:But consider the following function:

All functions are relations!All functions are relations!

1

2

3

4

a

b

c

d

66

When to use which?When to use which?

A function is used when you need to A function is used when you need to obtain a SINGLE result for any element in obtain a SINGLE result for any element in the domainthe domain Example: sin, cos, tanExample: sin, cos, tan

A relation is when there are multiple A relation is when there are multiple mappings between the domain and the co-mappings between the domain and the co-domaindomain Example: students enrolled in multiple Example: students enrolled in multiple

coursescourses

77

Relations on a setRelations on a set

A relation on the set A relation on the set AA is a relation from is a relation from AA to to AA In other words, the domain and co-domain are In other words, the domain and co-domain are

the same setthe same set We will generally be studying relations of this We will generally be studying relations of this

typetype

88

Relations on a setRelations on a set

Let Let AA be the set { 1, 2, 3, 4 } be the set { 1, 2, 3, 4 }

Which ordered pairs are in the relation Which ordered pairs are in the relation RR = { ( = { (a,ba,b) | ) | aa divides divides bb } }

R = { (1,1), (1,2), (1,3), (1,4), (2,2), (2,4), (3,3), (4,4) }R = { (1,1), (1,2), (1,3), (1,4), (2,2), (2,4), (3,3), (4,4) }

1

2

3

4

1

2

3

4

RR 11 22 33 44

11 XX XX XX XX

22 XX XX

33 XX

44 XX

99

Consider some relations on the set Consider some relations on the set ZZ

Are the following ordered pairs in the relation?Are the following ordered pairs in the relation?

(1,1) (1,2) (2,1) (1,-1) (2,2)(1,1) (1,2) (2,1) (1,-1) (2,2)

RR11 = { ( = { (aa,,bb) | ) | aa≤≤bb } }

RR22 = { ( = { (aa,,bb) | ) | aa>>bb } }

RR33 = { ( = { (aa,,bb) | ) | aa=|=|b|b| } }

RR44 = { ( = { (aa,,bb) | ) | aa==bb } }

RR55 = { ( = { (aa,,bb) | ) | aa==bb+1 }+1 }

RR66 = { ( = { (aa,,bb) | ) | aa++bb≤3 }≤3 }

More examplesMore examples

X

X

X

X

X

X

X

X

X

X

X

X

X

X

X

1010

Relation propertiesRelation properties

Six properties of relations we will study:Six properties of relations we will study: ReflexiveReflexive IrreflexiveIrreflexive SymmetricSymmetric AsymmetricAsymmetric AntisymmetricAntisymmetric TransitiveTransitive

1111

ReflexivityReflexivity

A relation is reflexive if every element is related A relation is reflexive if every element is related to itselfto itself Or, (Or, (aa,,aa))RR

Examples of reflexive relations:Examples of reflexive relations: =, ≤, ≥=, ≤, ≥

Examples of relations that are not reflexive:Examples of relations that are not reflexive: <, ><, >

1212

IrreflexivityIrreflexivity

A relation is irreflexive if every element is A relation is irreflexive if every element is notnot related to itselfrelated to itself Or, (Or, (aa,,aa))RR Irreflexivity is the opposite of reflexivityIrreflexivity is the opposite of reflexivity

Examples of irreflexive relations:Examples of irreflexive relations: <, ><, >

Examples of relations that are not irreflexive:Examples of relations that are not irreflexive: =, ≤, ≥=, ≤, ≥

1313

Reflexivity vs. IrreflexivityReflexivity vs. Irreflexivity

A relation can be neither reflexive nor A relation can be neither reflexive nor irreflexiveirreflexive Some elements are related to themselves, Some elements are related to themselves,

others are notothers are not

We will see an example of this later onWe will see an example of this later on

1414

Google MapsGoogle Maps

1515

SymmetrySymmetry

A relation is symmetric if, for every (A relation is symmetric if, for every (aa,,bb))RR, then , then ((bb,,aa))RR

Examples of symmetric relations:Examples of symmetric relations: =, isTwinOf()=, isTwinOf()

Examples of relations that are not symmetric:Examples of relations that are not symmetric: <, >, ≤, ≥<, >, ≤, ≥

1616

AsymmetryAsymmetry

A relation is asymmetric if, for every (A relation is asymmetric if, for every (aa,,bb))RR, , then (then (b,ab,a))RR Asymmetry is the opposite of symmetryAsymmetry is the opposite of symmetry

Examples of asymmetric relations:Examples of asymmetric relations: <, ><, >

Examples of relations that are not asymmetric:Examples of relations that are not asymmetric: =, isTwinOf(), ≤, ≥=, isTwinOf(), ≤, ≥

1717

AntisymmetryAntisymmetry

A relation is antisymmetric if, for every (A relation is antisymmetric if, for every (aa,,bb))RR, , then (then (b,ab,a))RR is true only when is true only when aa==bb Antisymmetry is Antisymmetry is not not the opposite of symmetrythe opposite of symmetry

Examples of antisymmetric relations:Examples of antisymmetric relations: =, ≤, ≥=, ≤, ≥

Examples of relations that are not antisymmetric:Examples of relations that are not antisymmetric: <, >, isTwinOf()<, >, isTwinOf()

1818

Notes on *symmetric relationsNotes on *symmetric relations

A relation can be neither symmetric or A relation can be neither symmetric or asymmetricasymmetric R = { (a,b) | a=|b| }R = { (a,b) | a=|b| } This is not symmetricThis is not symmetric

-4 is not related to itself-4 is not related to itself This is not asymmetricThis is not asymmetric

4 is related to itself4 is related to itself Note that it is antisymmetricNote that it is antisymmetric

1919

TransitivityTransitivity

A relation is transitive if, for every (A relation is transitive if, for every (aa,,bb))RR and (and (bb,,cc))RR, then (, then (aa,,cc))RR

If If aa < < bb and and bb < < cc, then , then aa < < cc Thus, < is transitiveThus, < is transitive

If If aa = = bb and and bb = = cc, then , then aa = = cc Thus, = is transitiveThus, = is transitive

2020

Transitivity examplesTransitivity examples

Consider isAncestorOf()Consider isAncestorOf() Let Alice be Bob’s parent, and Bob be Claire’s parentLet Alice be Bob’s parent, and Bob be Claire’s parent Thus, Alice is an ancestor of Bob, and Bob is an Thus, Alice is an ancestor of Bob, and Bob is an

ancestor of Claireancestor of Claire Thus, Alice is an ancestor of ClaireThus, Alice is an ancestor of Claire Thus, isAncestorOf() is a transitive relationThus, isAncestorOf() is a transitive relation

Consider isParentOf()Consider isParentOf() Let Alice be Bob’s parent, and Bob be Claire’s parentLet Alice be Bob’s parent, and Bob be Claire’s parent Thus, Alice is a parent of Bob, and Bob is a parent of Thus, Alice is a parent of Bob, and Bob is a parent of

ClaireClaire However, Alice is However, Alice is not not a parent of Clairea parent of Claire Thus, isParentOf() is Thus, isParentOf() is not not a transitive relationa transitive relation

2121

Relations of relations summaryRelations of relations summary

== << >> ≤≤ ≥≥

ReflexiveReflexive XX XX XX

IrreflexiveIrreflexive XX XX

SymmetricSymmetric XX

AsymmetricAsymmetric XX XX

AntisymmetricAntisymmetric XX XX XX

TransitiveTransitive XX XX XX XX XX

2222

Combining relationsCombining relations

There are two ways to combine relations There are two ways to combine relations RR11 and and RR22

Via Boolean operatorsVia Boolean operators Via relation “composition”Via relation “composition”

2323

Combining relations via Boolean Combining relations via Boolean operatorsoperators

Consider two relations Consider two relations RR≥≥ and and RR≤≤

We can combine them as follows:We can combine them as follows: RR≥≥ U U RR≤≤ = all numbers = all numbers ≥≥ OR OR ≤≤

That’s all the numbersThat’s all the numbers RR≥≥ ∩ ∩ RR≤≤ = all numbers = all numbers ≥≥ AND AND ≤≤

That’s all numbers equal toThat’s all numbers equal to RR≥≥ RR≤≤ = all numbers = all numbers ≥≥ or or ≤≤, but not both, but not both

That’s all numbers not equal toThat’s all numbers not equal to RR≥≥ - - RR≤≤ = all numbers = all numbers ≥≥ that are not also that are not also ≤≤

That’s all numbers strictly greater thanThat’s all numbers strictly greater than RR≤≤ - R - R≥≥ = all numbers = all numbers ≤≤ that are not also that are not also ≥≥

That’s all numbers strictly less thanThat’s all numbers strictly less than

Note that it’s possible the result is the empty setNote that it’s possible the result is the empty set

2424

Combining relations via relational Combining relations via relational compositioncomposition

Let Let RR be a relation from be a relation from AA to to BB, and , and SS be a be a relation from relation from BB to to CC Let Let aa AA, , bb BB, and , and cc CC Let (Let (aa,,bb) ) RR, and (, and (bb,,cc) ) SS Then the composite of R and S consists of the Then the composite of R and S consists of the

ordered pairs (ordered pairs (aa,,cc))We denote the relation by We denote the relation by SS ◦ ◦ RR

Note that Note that SS comes first when writing the comes first when writing the composition!composition!

2525

Combining relations via relational Combining relations via relational compositioncomposition

Let Let MM be the relation “is mother of” be the relation “is mother of”Let Let FF be the relation “is father of” be the relation “is father of”What is What is MM ◦ ◦ FF??

If (If (a,ba,b) ) FF, then , then aa is the father of is the father of bb If (If (b,cb,c) ) MM, then , then bb is the mother of is the mother of cc Thus, Thus, MM ◦ ◦ FF denotes the relation “maternal grandfather” denotes the relation “maternal grandfather”

What is What is FF ◦ ◦ MM?? If (If (a,ba,b) ) MM, then , then aa is the mother of is the mother of bb If (If (b,cb,c) ) FF, then , then bb is the father of is the father of cc Thus, Thus, FF ◦ ◦ MM denotes the relation “paternal grandmother” denotes the relation “paternal grandmother”

What is What is MM ◦ ◦ MM?? If (If (a,ba,b) ) MM, then , then aa is the mother of is the mother of bb If (If (b,cb,c) ) MM, then , then bb is the mother of is the mother of cc Thus, Thus, MM ◦ ◦ MM denotes the relation “maternal grandmother” denotes the relation “maternal grandmother”

Note that Note that MM and and FF are not transitive relations!!! are not transitive relations!!!

2626

Combining relations via relational Combining relations via relational compositioncomposition

Given relation Given relation RR RR ◦ ◦ RR can be denoted by can be denoted by RR22

RR22 ◦ ◦ R = (RR = (R ◦ ◦ R) R) ◦ ◦ RR = = RR33

Example: Example: MM33 is your mother’s mother’s mother is your mother’s mother’s mother

27

Quick surveyQuick survey

I felt I understood the material in this I felt I understood the material in this slide set…slide set…

a)a) Very wellVery well

b)b) With some review, I’ll be goodWith some review, I’ll be good

c)c) Not reallyNot really

d)d) Not at allNot at all

28

Quick surveyQuick survey

The pace of the lecture for this The pace of the lecture for this slide set was…slide set was…

a)a) FastFast

b)b) About rightAbout right

c)c) A little slowA little slow

d)d) Too slowToo slow

29

Quick surveyQuick survey

How interesting was the material in How interesting was the material in this slide set? Be honest!this slide set? Be honest!

a)a) Wow! That was SOOOOOO cool!Wow! That was SOOOOOO cool!

b)b) Somewhat interestingSomewhat interesting

c)c) Rather bortingRather borting

d)d) ZzzzzzzzzzzZzzzzzzzzzz

3030

Today’s demotivatorsToday’s demotivators

top related