Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discrete Mathematics 7th edition, 2009

Similar presentations


Presentation on theme: "Discrete Mathematics 7th edition, 2009"— Presentation transcript:

1 Discrete Mathematics 7th edition, 2009
Chapter 3 Functions, sequences, and relations

2 3.1 Functions A function f from X to Y
(in symbols f : X  Y) is a relation from X to Y such that Dom(f) = X and if two pairs (x,y) and (x,y’)  f, then y = y’ Example: Dom(f) = X = {a, b, c, d}, Rng(f) = {1, 3, 5} f(a) = f(b) = 3, f(c) = 5, f(d) = 1. a b c d 1 2 3 4 5 f X = dom(f) RNG(f)  Y

3 Domain and Range o x x Domain of f = X
Range of f = { y | y = f(x) for some x X} A function f : X  Y assigns to each x in Dom(f) = X a unique element y in Rng(f)  Y. Therefore, no two pairs in f have the same first coordinate. a b c d 1 2 3 4 5 f X = dom(f) RNG(f)  Y a b c d 1 2 3 4 5 f X  dom(f) RNG(f)  Y RNG(f)  Y a b c d 1 2 3 4 5 f X = dom(f) o x x

4 Modulus operator Let x be a nonnegative integer and y a positive integer r = x mod y is the remainder when x is divided by y Examples: 1 = 13 mod 3 6 = 234 mod 19 4 = 2002 mod 111 mod is called the modulus operator Hash Function Pseudo-random Numbers ISBN (International Standard Book Numbers)

5 One-to-one functions (단사 함수)
A function f : X  Y is one-to-one  for each y  Y there exists at most one x  X with f(x) = y. Alternative definition: f : X  Y is one-to-one  for each pair of distinct elements x1, x2  X there exist two distinct elements y1, y2  Y such that f(x1) = y1 and f(x2) = y2. Examples: 1. The function f(x) = 2x from the set of real numbers to itself is one-to-one 2. The function f : R  R defined by f(x) = x2 is not one-to-one, since for every real number x, f(x) = f(-x) a b c d 1 2 3 4 5 o a b c d 1 2 3 4 5 x |x|  |Y|

6 Onto functions (전사 함수) x o A function f : X  Y is onto 
for each y  Y there exists at least one x  X with f(x) = y, i.e. Rng(f) = Y. Example The function f(x) = ex from the set of real numbers to itself is not onto Y = the set of all real numbers. However, if Y is restricted to Rng(f) = R+, the set of positive real numbers, then f(x) is onto. a b c d 1 2 3 4 5 x |x|  |Y| e f o

7 Bijective functions (전단사 함수)
A function f : X Y is bijective  f is one-to-one and onto Examples: A linear function f(x) = ax + b is a bijective function from the set of real numbers to itself The function f(x) = x3 is bijective from the set of real numbers to itself. a b c d e 1 2 3 4 5 |x| = |Y|

8 Inverse function Given a function y = f(x), the inverse f -1 is
the set {(y, x) | y = f(x)}. The inverse f -1 of f is not necessarily a function. Example: if f(x) = x2, then f -1 (4) = 4 = ± 2, not a unique value and therefore f is not a function. However, if f is a bijective function, it can be shown that f -1 is a function.

9 Exponential and logarithmic functions
Let f(x) = 2x and g(x) = log2x = lg x f ◦ g(x) = f(g(x)) = f(lg x) = 2 lg x = x g ◦ f(x) = g(f(x)) = g(2x) = lg 2x = x Therefore, the exponential and logarithmic functions are inverses of each other.

10 Composition of functions
Given two functions g : X  Y and f : Y  Z, the composition f ◦ g is defined as follows: f ◦ g (x) = f(g(x)) for every x  X. Example: f(x) = x2 -1, g(x) = 3x Then f ◦ g(x) = f(g(x)) = f(3x + 5) = (3x + 5)2 - 1 Composition of functions is associative: f ◦ (g ◦h) = (f ◦ g) ◦ h, But, in general, it is not commutative: f ◦ g  g ◦ f.

11 Binary operators A binary operator on a set X is a function f that
associates a single element of X to every pair of elements in X, i.e. f : X x X  X and f(x1, x2)  X for every pair of elements x1, x2. Examples : addition, subtraction and multiplication of real numbers unions or intersections of sets concatenation of two strings over a set X etc.

12 Unary operators A unary operator on a set X associates to each single element of X one element of X. Example 1 Let X = U be a universal set and P(U) the power set of U. Define f : P(U)  P(U) the function defined by f (A) = A', the set complement of A in U, for every A  U. Then f defines a unary operator on P(U). Example 2 : String Inverse Let X be any set, X* the set of all strings over X. If  = x1x2…xn  X*, let f() = -1 = xnxn-1…x2x1, the string written in reverse order. Then f :X*  X* is a function that defines a unary operator on X*.

13 3.2 Sequences and strings A sequence is an ordered list of numbers,
usually defined according to a formula: sn = a function of n = 1, 2, 3,... If s is a sequence {sn| n = 1, 2, 3,…}, s1 denotes the first element, s2 the second element,… sn the nth element… {n} is called the indexing set of the sequence. Usually the indexing set is N (natural numbers) or an infinite subset of N.

14 Examples of sequences Examples:
1. Let s = {sn} be the sequence defined by sn = 1/n , for n = 1, 2, 3,… The first few elements of the sequence are: 1, 1/2, 1/3, 1/4, 1/5,1/6,… 2. Let s = {sn} be the sequence defined by sn = n2 + 1, for n = 1, 2, 3,… The first few elements of s are: 2, 5, 10, 17, 26, 37, 50,…

15 Increasing and decreasing
A sequence s = {sn} is said to be increasing if sn < sn+1 decreasing if sn > sn+1 nonincreasing if sn > sn+1 nondecreasing if sn < sn+1, for every n = 1, 2, 3,… Examples: Sn = 4 – 2n, n = 1, 2, 3,… is decreasing: 2, 0, -2, -4, -6,… Sn = 2n -1, n = 1, 2, 3,… is increasing: 1, 3, 5, 7, 9, …

16 Subsequences A subsequence of a sequence s = {sn} is a sequence t = {tn} that consists of certain elements of s retained in the original order they had in s Example let s = {sn = n | n = 1, 2, 3,…} 1, 2, 3, 4, 5, 6, 7, 8,… Let t = {tn = 2n | n = 1, 2, 3,…} 2, 4, 6, 8, 10, 12, 14, 16,… t is a subsequence of s

17 Sigma, pi notation  ak = a1 + a2 + … + am  ak = a1a2…am
If {an} is a sequence, then the sum m  ak = a1 + a2 + … + am k = 1 This is called the “sigma notation”, where the Greek letter  indicates a sum of terms from the sequence If {an} is a sequence, then the product  ak = a1a2…am k=1 This is called the “pi notation”, where the Greek letter  indicates a product of terms of the sequence

18 Strings Let X be a nonempty set. A string over X is
a finite sequence of elements from X. Example: if X = {a, b, c} Then  = bbaccc is a string over X Notation: bbaccc = b2ac3 The length of a string  is the number of elements of  and is denoted by ||. If  = b2ac3 then || = 6. The null string is the string with no elements and is denoted by the Greek letter  (lambda). It has length zero.

19 More on strings Let X* = {all strings over X including }
Let X+ = X* - {}, the set of all non-null strings Concatenation of two strings  and  is the operation on strings consisting of writing  followed by  to produce a new string  Example:  = bbaccc and  = caaba, then  = bbaccccaaba = b2ac4a2ba Clearly, || = | | + ||

20 3.3 Relations Given two sets X and Y its Cartesian product XY is the set of all ordered pairs (x,y) where xX and yY In symbols XY = {(x, y) | xX and yY} A binary relation R from a set X to a set Y is a subset of the Cartesian product XY Example: X = {1, 2, 3} and Y = {a, b} R = {(1,a), (1,b), (2,b), (3,a)} is a relation between X and Y

21 Domain and range Given a relation R from X to Y,
The domain of R is the set Dom(R) = { xX | (x, y) R for some yY} The range of R is the set Rng(R) = { yY | (x, y) R for some x X} Example: if X = {1, 2, 3} and Y = {a, b} R = {(1,a), (1,b), (2,b)} Then: Dom(R)= {1, 2}, Rng(R) = {a, b}

22 Example of a relation Let X = {1, 2, 3} and Y = {a, b, c, d}.
Define R = {(1,a), (1,d), (2,a), (2,b), (2,c)} The relation can be pictured by a graph:

23 A digraph of a relation (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)}
R = {(x, y)| x≤y, x, y in X}, X = {1, 2, 3, 4} R = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)} 1 2 3 4

24 Properties of relations
Let R be a relation on a set X i.e. R is a subset of the Cartesian product XX R is reflexive if (x,x) R for every xX R is symmetric if for all x, y X such that (x,y) R then (y,x) R R is transitive if (x,y) R and (y,z) R imply (x,z) R R is antisymmetric if for all x,yX such that xy, (x,y)R then (y,x)R

25 Order relations Let X be a set and R a relation on X.
R is a partial order on X if R is reflexive, antisymmetric and transitive. Let x,yX If (x,y) or (y,x) are in R, then x and y are comparable If (x,y) R and (y,x) R then x and y are incomparable If every pair of elements in X are comparable, then R is a total order on X Ex) (x, y) in R if x divides y, x and y are positive integers. Ex) (x, y) in R if x  y, x and y are positive integers.

26 Inverse of a relation Given a relation R from X to Y, its inverse R-1
is the relation from Y to X defined by R-1 = { (y,x) | (x,y)  R } Example: if R = {(1,a), (1,d), (2,a), (2,b), (2,c)} then R -1= {(a,1), (d,1), (a,2), (b,2), (c,2)}

27 Composition of relation
R1 : relation from X to Y R2 : relation from Y to Z R2  R1 composition of R1 and R2 the relation from X to Z R2  R1 = {(x,z) | (x,y)R1 and (y,z)R2 for some yY}

28 3.4 Equivalence relations
Let X be a set and R a relation on X R is an equivalence relation on X  R is reflexive, symmetric and transitive. Example: Let X = {integers} and R be the relation on X defined by: xRy  x - y = 5k, for some integer k It is easy to show that R is an equivalence relation on the set of integers.

29 Example Relation R on X X = {a, b, c, d, e, f, g, h, i} F1 = {a, c, e}, F2 = {b}, F3={d, f, g, h, i} a e d c b g i h f

30 Partitions A partition S on a set X is a family {A1, A2,…, An} of subsets of X, such that A1A2A3…An = X Aj  Ak =  for every j, k with j  k, 1 < j, k < n. Example: if X = {integers}, E = {even integers) and O = {odd integers}, then S = {E, O} is a partition of X.

31 Partitions and equivalence relations
Theorem 3.2.1: Let S be a partition on a set X. Define a relation R on X by xRy if x, y are in the same set T for T  S. Then R is an equivalence relation on X. i.e. an equivalence relation on a set X corresponds to a partition of X and conversely.

32 Equivalence classes Let X be a set and let R be an equivalence relation on X. Let a  X. Define [a] ={ xX | xRa } Let S = { [a] | a  X } Theorem 3.2.8: S is a partition on X. The sets [a] are called equivalence classes of X induced by the relation R. Given a, b  X, then [a] = [b] or [a][b] = 

33 Example (([a][g])  ([a][g])?)
Equivalence relation R on X X = {a, b, c, d, e, f, g, h, i} F1 = {a, c, e}, F2 = {b}, F3={e, d, f, g, h, i} [a] a e g [g] a e d c b g i h f ? aRe^eRa eRg^gRe aRg gRa [a] = [g]

34 Set of equivalence classes
If R is an equivalence relation on a set X, define X/R = {[a] | a  X }. Theorem : If each equivalence class on a finite set X has k elements, then X/R has |X|/k elements, i.e. |X/R| = |X| / k.

35 3.5 Matrices of relations Let X, Y be sets and R a relation from X to Y Write the matrix A = (aij) of the relation as follows: Rows of A = elements of X Columns of A = elements of Y Element ai,j = 0 if the element of X in row i and the element of Y in column j are not related Element ai,j = 1 if the element of X in row i and the element of Y in column j are related

36 The matrix of a relation (1)
Example: Let X = {1, 2, 3}, Y = {a, b, c, d} Let R = {(1,a), (1,d), (2,a), (2,b), (2,c)} The matrix A of the relation R is A = a b c d 1 2 3

37 The matrix of a relation (2)
If R is a relation from a set X to itself and A is the matrix of R then A is a square matrix. Example Let X = {a, b, c, d} and R = {(a,a), (b,b), (c,c), (d,d), (b,c), (c,b)}. Then A = a b c d 1

38 The product of matrices
Let A be the (lm) matrix of R1 and let B be the (mn) matrix of R2 The ij-th element of the product of these matrices, AB, is computed as 1 : if 0 : if i A B C j Ci,j m개

39 The matrix of a composed relation
Theorem 3.3.6: Let R1 be a relation from X to Y and let R2 be a relation from Y to Z. Choose orderings of X, Y, and Z. Let A1 be the matrix of R1 and let A2 be the matrix of R2 with respect to the orderings selected. The matrix of the relation R2  R1 with respect to the orderings selected is obtained by replacing each nonzero terms in the matrix product A1A2 by 1

40 The matrix of a relation on a set X
Let A be the square matrix of a relation R from X to itself. Let A2 = the matrix product AA. R is reflexive  All terms aii in the main diagonal of A are 1. R is symmetric  aij = aji for all i and j, i.e. R is a symmetric relation on X if A is a symmetric matrix R is transitive  whenever cij in C = A2 is nonzero then entry aij in A is also nonzero.

41 3.6 Relational databases A binary relation R is a relation among two sets X and Y, already defined as R  X  Y. An n-ary relation R is a relation among n sets X1, X2,…, Xn, i.e. a subset of the Cartesian product, R  X1  X2  …  Xn. Thus, R is a set of n-tuples (x1, x2,…, xn) where xk  Xk, 1 < k < n.

42 Databases A database is a collection of records that are manipulated by a computer. They can be considered as n sets X1 through Xn, each of which contains a list of items with information. Database management systems are programs that help access and manipulate information stored in databases.

43 Relational database model
Columns of an n-ary relation are called attributes An attribute is a key if no two entries have the same value e.g. social security number A query is a request for information from the database

44 Relational databases model
Table PLAYER 4-ary relation X X X X4 ID Number 22012 93831 58199 84341 01180 26710 61049 39826 Name Johnsonbaugh Glover Battey Cage Homer Score Singleton Position c of p 1b 2b Age 22 24 18 30 37 31 key (uniquely defines an n-tuple)

45 Operators The selection operator chooses n-tuples from a relation by giving conditions on the attributes The projection operator chooses two or more columns and eliminates duplicates The join operator manipulates two relations

46 (22012, Johnsonbaugh, c, 22) , (84341, Cage, c, 30)
Operator - select <PLAYER> ID Number 22012 93831 58199 84341 01180 26710 61049 39826 Name Johnsonbaugh Glover Battey Cage Homer Score Singleton Position c of p 1b 2b Age 22 24 18 30 37 31 PLAYER[Position=c] (22012, Johnsonbaugh, c, 22) , (84341, Cage, c, 30)

47 Operator - project <PLAYER> ID Number 22012 93831 58199 84341
01180 26710 61049 39826 Name Johnsonbaugh Glover Battey Cage Homer Score Singleton Position c of p 1b 2b Age 22 24 18 30 37 31 PLAYER[Name, Position] (Johnsonbaugh, c), (Glover,of), (Battey, p), (Cage, c), (Homer, 1b), (Score, p), (Johnsonbaugh, of), (Singleton, 2b)

48 PLAYER[ID Number = PID] ASSIGNMENT
Operator - join PID 39826 26710 58199 01180 Team Blue Sox Mutts Jackalopes <ASSIGNMENT> <PLAYER> ID Number 22012 93831 58199 84341 01180 26710 61049 39826 Name Johnsonbaugh Glover Battey Cage Homer Score Singleton Position c of p 1b 2b Age 22 24 18 30 37 31 PLAYER[ID Number = PID] ASSIGNMENT <PLAYER[ID Number = PID] ASSIGNMENT> ID Number 58199 01180 26710 39826 Name Battey Homer Score Singleton Position p 1b 2b Age 18 37 22 31 Team Jackalopes Mutts Blue Sox


Download ppt "Discrete Mathematics 7th edition, 2009"

Similar presentations


Ads by Google