260 likes | 406 Views
MT263F Discrete Structures. Li Tak Sing ( 李德成 ). Functions. If A and B are sets and so that each element in A is associated with exactly one element in B. Such association is called a function from A to B.
E N D
MT263F Discrete Structures Li Tak Sing (李德成)
Functions • If A and B are sets and 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.
Some function examples • f(x)=x2 • f(x)=sin(x)
Terminology • If f is a function from A to B, we denote this by writingf: A BA 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 A1xA2x…xAn, then f(x1,x2,…,xn) denotes the value of at(x1,x2,..,xn).
Ranges, images, pre-images • f: A BThe 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) | aA} • For any subset SA, 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)|xS}
Pre-images • For any set TB, 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)={aA|f(a)T}
Examples • Let f:NN be defined by f(x)=x+1. Evaluate each of the following expressions: • f({0,2,4,6,8,10}) • range(f) • f-1({0}) • f-1({1,3,5,7,9})
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.
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.
Some useful functions • The floor and ceiling functions • x=y, yZ and yx<y+1 • x=y, yZ and y<x y
Floor and ceiling properties • x+1= x+1 • x-1= x-1 • x= x iff xZ • x= x+1 iff xZ • x= x-1 iff xZ
Examples • Evaluate each of the following expressions • -2.3 • 2.3 • 9.4 • -9.4
Functions and Not Functions • f:RR, f(x) = square root of x. • f:R+R, f(x) = square root of x. • f:R+R+, f(x) = square root of x.
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.
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
Division Algorithm • If a and b are integers and b0, then there are unique integers q and r such that a=bq+r, where 0r<|b|. • g(a,b)=g(b,a-bq)=g(b,r) • We can use the above result to find the gcd of two integers.
Euclid's Algorithm • Input natural numbers a and b, not both zero, and output gcd(a,b). • while b>0 do Construct a=bq+r, where 0r<b; a:=b; b:=rod; • Output a.
Finding the gcd • Evalue each of the following expressions: • gcd(235,110) • gcd(15,63)
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 - ba/b
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.
Evaluate each of the following expressions • 25 mod 4 • 68 mod 7 • (-16) mod 3 • (-16) mod 5
The Log Function • log:R+R • logbx=y means by=x
Log Function Properties • logb(bx)=x • logb(xy)=logbx+logby • logb(xy)=ylogbx • logb(x/y)=logbx-logby • logax=(logab)(logbx)
Evaluate each of the following expressions • log2(1024) • log2(512) • log2(2543) • log2(49)