HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

23
HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations

Transcript of HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Page 1: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

HALVERSON – MIDWESTERN STATE UNIVERSITY

CMPS 2433 Chapter 2 – Part 2

Functions & Relations

Page 2: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

2.2 Relations

A RELATION from set A to set B is any subset of the Cartesian Product A X B

If R is a relation from A to B & (a, b) is an element of R, a is related to b by R

Example A = {students enrolled at MSU in fall 2014} B = {courses offered at MSU in fall 2014} R = {(a,b)| student a is enrolled in course b} R = {(Smith,Math1233), (Jones, CMPS1044),

etc.}

Page 3: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Relations (cont’d)

A relation is ANY subset, so no repeated pairs but can have repeated elements in the pairs.

R = {(Smith,Math1233), (Jones, Cmps1044), (Smith, Engl1013), (Jones, Math1233), (Hunt, Math1233), (Williams, Cmps1044), etc.}

What is the Universal Set for R?Define a different Relation from A to B.

Page 4: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Relations (cont’d)

Example: R is a relation on AA = {students enrolled at MSU in fall 2014}

R = {(a, b)| a & b are in a course together}R = {(Smith, Jones), (Jones, Hunt), (Hunt, Wills), (Wills, Johnson), etc.}What about (Jones, Smith)?

Relation from a set S to itself is call a Relation on S

Page 5: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Reflexive Property of Relations

A Relation R on a set S is said to be Reflexive if for each x S, x R x is true if for each x S, (x, x) is in R that is, every element is related to itself

Is our previous example R a Reflexive Relation?

Page 6: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Reflexive Property of Relations - Examples

A = {students enrolled at MSU in fall 2014}Which of the following are Reflexive?R = {(a,b): a & b are siblings}R = {(a,b): a & b are not in a course

together}R = {(a,b): a & b are same classification}R = {(a,b): a & b are married}R = {(a,b): a & b are the same age}R = {(a,b): a has a higher GPA than b}

Page 7: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Symmetric Property of Relations

A Relation R on a set S is said to be Symmetric If x R y is true, then y R x is true If (x, y) R, then (y, x) is true That is, the elements of the relation R can

be reversed

Is R Symmetric?R = {(a, b)| a & b are in a course together}

Page 8: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Symmetric Property of Relations - Examples

A = {students enrolled at MSU in fall 2014}Which of the following are Symmetric?R = {(a,b): a & b are siblings}R = {(a,b): a & b are not in a course

together}R = {(a,b): a & b are same classification}R = {(a,b): a & b are married}R = {(a,b): a & b are the same age}R = {(a,b): a has a higher GPA than b}

Page 9: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Transitive Property of Relations

A Relation R on a set S is said to be Transitive If x R y and y R z are true, then x R z is

true If (x, y) R & (y, z) R, then (x, z) R

Is R Transitive?R = {(a, b)| a & b are in a course together}

Page 10: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Transitive Property of Relations - Examples

A = {students enrolled at MSU in fall 2014}Which of the following are Transitive?R = {(a,b): a & b are siblings}R = {(a,b): a & b are not in a course

together}R = {(a,b): a & b are same classification}R = {(a,b): a & b are married}R = {(a,b): a & b are the same age}R = {(a,b): a has a higher GPA than b}

Page 11: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Equivalence Relation

Any Relation that is Reflexive, Symmetric & Transitive is an Equivalence Relation

If R is an Equivalence Relation on S & x S, the set of all elements related to x is called an Equivalence Class Denoted [x]

Any 2 Equivalence Classes of a Relation are either Equal or Disjoint The Equivalence Classes of R Partition S

Page 12: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Equivalence Relations - Examples

A = {students enrolled at MSU in fall 2014}Which are Equivalence Relations? If so, what are the partitions?R = {(a,b): a & b are siblings}R = {(a,b): a & b are not in a course

together}R = {(a,b): a & b are same classification}R = {(a,b): a & b are married}R = {(a,b): a & b are the same age}R = {(a,b): a has a higher GPA than b}

Page 13: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Homework on Relations - Section 2.2

Page 52 – 54Problems 1 – 14, 19-20, 25

Page 14: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Section 2.4 - Functions

A Function f from set X to set Y is a relation from X to Y in which for each element x in X there is exactly one element y in Y for which x f y

Among the ordered pairs (x, y) in f, x appears only ONCE

Example: is F a function?F = {(2,3), (3,2), (4,2)}F = {(2,3), (3,2), (2,4), (4,6)}

Page 15: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Mathematical Functions

Consider mathematical FUNCTIONSAssume S = {0, 1, 2, 3, 4, 5,…}f(x) = x2 = {(0,0), (1,1),(2,4),(3,9),

(4,16),…}f(x) = x+2 = {(0,2),(1,3),(2,4),(3,5),

…}

For every x, there is only ONE value to which it is related, thus these are Functions!

Page 16: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Equivalence Relations - Examples

A = {students enrolled at MSU in fall 2014}Which are Functions? R = {(a,b): a & b are siblings}R = {(a,b): a & b are not in a course

together}R = {(a,b): a & b are same classification}R = {(a,b): a & b are married}R = {(a,b): a & b are the same age}R = {(a,b): a has a higher GPA than b}

Page 17: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Function Domain

If f is a function from X to Y, denote f: X YSet X is called the domain of the

functionSet Y is called co-domain Subset of Y actually paired with

elements of X under f is called the range

For f(x) = y, y is the image of x under f

Page 18: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Domain, Co-domain, Range Examples

S = {…, -3,-2,-1,0, 1, 2, 3, 4, 5,…}Define f as a function on SF(x) = x2

Domain = SCo-domain = SRange = ???

Page 19: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Functions – additional terms

One-to-One function For every x, there is a unique y & For every y, there is a unique x

{(x, y)| no repeats of x or y}S = {…, -3,-2,-1,0, 1, 2, 3, 4, 5,…}f(x) = x2

Is f one-to-one?

Page 20: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Exponential & Logarithmic Functions

Logarithmic functions IMPT in Computing

Generally, base 2NOTE:

2n is exponential function, base 220 = 1 and 2-n = 1/2n

See page 73 for graph – Figure 2.18Logarithmic Function base 2 is inverse

of Exponential Function

Page 21: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Logarithmic Function - Base 2

Notation: log2 x Read “log base 2 of x”

Defn: y = log2 x if and only if x = 2y

Examples: log2 8 = 3 because 23 = 8 log2 1024 = 10 because 210 = 1024 log2 256 = 8 because 28 = 256 log2 100 ~~ 6.65 because 26.65 ~~ 100

Page 22: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

More on Logarithmic Function - Base 2

Growth rate is small, less than linearSee graph page 74 – Figure 2.19Calculator Note:

Most calculators with LOG button is base 10

log 2 x = LOG x / LOG 2

Algorithms with O(log2 n) complexity??

Page 23: HALVERSON – MIDWESTERN STATE UNIVERSITY CMPS 2433 Chapter 2 – Part 2 Functions & Relations.

Homework – Section 2.4

Note – we omitted section on Composite & Inverse Functions

Page 74-75Problems 1 - 36