Download presentation
Presentation is loading. Please wait.
Published byEsmond Griffin Modified over 8 years ago
1
MT263F Discrete Structures Li Tak Sing ( 李德成 ) Lectures 5-6 1
2
Functions If A and B are sets so that each element in A is associated with exactly one element in B. Such association is called a function from A to B. If f is a function from A to B and x in A is associated with y in B under this function, we would write f(x)=y. 2
3
Some function examples f(x)=x 2 f(x)=sin(x) 3
4
Graphical representation of functions 4
5
Terminology If f is a function from A to B, we denote this by writing f: A B A is the domain of f, B is the codomain of f. If f(x)=y, then x is called an argument of f, and y is called a value of f. If the domain of f is the Cartesian product A 1 A 2 … A n, then f(x 1,x 2,…,x n ) denotes the value of at(x 1,x 2,..,x n ). 5
6
For example, f:R R R and f(x,y)=x+y. The domain is R R, the codomain is R. 6
7
Ranges, images, pre-images f: A B The range of f, denoted by range(f), is the set of elements in B that are associated with some element of A. range(f)={f(a) | a A} For any subset S A, the image of S under f, denoted by f(S), is the set of elements in B that are associated with some elements of S. f(S)={f(x)|x S} 7
8
Pre-images For any set T B, the pre-image of T under f, denoted by f -1 (T), is the set of elements in A that associate with elements of T. f -1 (T)={a A|f(a) T} 8
9
Examples Let f:N N be defined by f(x)=x+1. Evaluate each of the following expressions: 1.f({0,2,4,6,8,10}) 2.range(f) 3.f -1 ({0}) 4.f -1 ({1,3,5,7,9}) 9
10
Solution 1.{1,3,5,7,9,11} 2.{1,2,3,…} 3. 4.{0,2,4,6,8} 10
11
Functions and binary relations A function can be consider as a binary relation. If f(x)=y, then x is related to y under f. So every function is a relation. Note that not all relations are functions. 11
12
Equality of functions Two functions are equal if they have the same type and the same values for each domain element. f=g iff f(x)=g(x) for all x in A. 12
13
Some useful functions The floor and ceiling functions x =y, y Z and y x<y+1 x =y, y Z and y<x y 13
14
Floor and ceiling properties x+1 = x +1 x-1 = x -1 x+1 = x +1 x-1 = x -1 x = x iff x Z x = x +1 iff x Z x = x -1 iff x Z 14
15
Examples Evaluate each of the following expressions 1. -2.3 2. 2.3 3. 9.4 4. -9.4 15
16
Solution 1.-3 2.2 3.10 4.-9 16
17
Functions and Not Functions f:R R, f(x) = square root of x. f:R + R, f(x) = square root of x. f:R + R +, f(x) = square root of x. 17
18
Solution 1.This is not a function for two reasons: 1.There is no real square roots for negative real numbers. 2.For positive real numbers, there are two square roots. 2.This is not a function because every positive real number has two square roots. 3.This is a function. 18
19
Tuples are functions Any ordered sequence of objects can be thought of as a function. The tuple (9,4,5,2,3) can be thought of as a listing of values of the function: f:{0,1,2,3,4} N where f(0)=9, f(1)=4, f(2)=5, f(3)=2, f(4)=3. 19
20
Greatest Common Divisor gcd(a,b)=greatest positive integers that divides a and b which are not both 0. gcd(a,b)=gcd(b,a)=gcd(a,-b) gcd(a,b)=gcd(b,a-bq) if g=gcd(a,b), then there are integers x and y such that g=ax+by If d|ab and gcd(d,a)=1, then d|b 20
21
Division Algorithm If a and b are integers and b 0, then there are unique integers q and r such that a=bq+r, where 0 r<|b|. g(a,b)=g(b,a-bq)=g(b,r) We can use the above result to find the gcd of two integers. 21
22
Euclidean Algorithm Input natural numbers a and b, not both zero, and output gcd(a,b). while b>0 do Construct a=bq+r, where 0 r<b; a:=b; b:=r od; Output a. 22
23
Finding the gcd Evalue each of the following expressions: 1.gcd(235,110) 2.gcd(15,63) 23
24
Solution 1.5 2.3 24
25
Mod function If a and b are integers with b>0, then the remainder upon the division of a by b is denoted a mod b a mod b = a - b a/b 25
26
Mod Function Properties x mod n = y mod n iff n divides x-y iff (x-y) mod n =0. (x+y) mod n=((x mod n)+(y mod n)) mod n (xy) mod n =((x mod n)(y mod n)) mod n. If ax mod n=ay mod n and gcd(a,n)=1, then x mod n= y mod n. 26
27
Evaluate each of the following expressions 1.25 mod 4 2.68 mod 7 3.(-16) mod 3 4.(-16) mod 5 27
28
Solution 1.1 2.5 3.2 4.4 28
29
The Log Function log:R + R (Note that log is undefined for non-positive values) log b x=y means b y =x 29
30
Log Function Properties 1.log b (b x )=x 2.log b (xy)=log b x+log b y 3.log b (x y )=ylog b x 4.log b (x/y)=log b x-log b y 5.log a x=(log b x)/(log b a) (change of base) 30
31
Proof 31
32
32
33
33
34
34
35
35
36
Evaluate each of the following expressions log 2 (1024) log 2 (512) log 2 (2 5 4 3 ) log 2 (4 9 ) 36
37
10 9 11 18 37
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.