Transitive Closure Theorem 1 Let R be a
Transitive Closure Theorem 1. Let R be a relation on a set A. Then R is the transitive closure of R. • the reachability relation R* of a relation R on a set A is defined as x. R*y, which means that x=y or x. R y, i. e. y is reachable from x if either y is x or there is some path from x to y • R*=R • M =M (M ) … Theorem 2. Let A be a set with |A|=n, and let R be a relation on A. Then R =R R 2 … Rn. In other words, powers of R greater than n are not needed to computer R.
Warshall’s Algorithm • Let R be a relation on a set A={a 1, …, an}. For 1≤k≤n, define a Boolean matrix Wk as follows: Wk has a 1 in position i, j if and only if there is a path from ai to aj in R whose interior vertices, if any, come from the set {a 1, …, ak}. • Since any vertex must come from the set {a 1, …, an}, it follows that the matrix Wn has a 1 in position i, j if and only if some path in R connects ai with aj, i. e. Wn=M • Define W 0 to be MR, then the sequence W 0, W 1 …, Wn has the first term as MR and last term as M • Suppose Wk =[tij] and Wk-1 =[sij], then tij =1 if and only if either (1) sij =1 or (2) sik =1 and skj =1
Warshall’s Algorithm To compute Wk from Wk-1 Step 1: First transfer to Wk all 1’s in Wk-1 Step 2: List the locations p 1, p 2 …, in column k of Wk-1, where the entry is 1, and the locations q 1, q 2 …, in row k of Wk-1, where the entry is 1 Step 3: Put 1’s in all the positions pi, pj of Wk (if they are not already there) • Compared with the formula (1) M =M (M ) …(M ), which requires about n 4 steps without the final joins, while the Warshall’s algorithm requires n 3 steps in all • Thus Warshall’s algorithm is a significant improvement over direct computation M of using the formula (1)
Transitive Closure • if R and S are equivalence relations on a set A, then the relation R S is the largest equivalence relation contained in both R and S Theorem 3. If R and S are equivalence relations on a set A, then the smallest equivalence relation containing both R and S is (R S).
5. Functions in Computer Science Growth of Functions
Functions Function, a special type of relation • let A and B be nonempty sets, a function f from A to B, denoted as f: A B, is a relation from A to B such that for all a Dom(f), f(a), the f-relative set of a, contains only one element of B, i. e. f(a)={b}, or f(a)=b • the relation f can be described as the set of pairs {(a, f(a)) | a Dom(f)} • functions are also called mappings or transformations; the element a is called an argument of the function f, and f(a) is called the value of the function for the argument a, and is also referred to as the image of a under f
Functions • let A be an arbitrary nonempty set, the identity function on A, denoted by 1 A, is defined by 1 A(a)=a, if A 1 A, then 1 A(A 1)= A 1 • 1 A is the relation • suppose that f: A B and g: B C are functions, then the composition of f and g, g f is a relation; let a Dom(g f), then (g f)(a)=g(f(a)) • if f and g are functions specified by giving formulas, then g f is also a function, and the formula for g f is produced by substituting the formula for f into the formula for g
Special Types of Functions • let f be a function from A to B, then f is everywhere defined if Dom(f)=A; f is onto if Ran(f)=B; f is one to one if there is no f(a)=f(a') for two distinct elements a and a' of A • one to one: if f(a)=f(a'), then a=a' • if f is one to one and onto, it’s also called a bijection between Dom(f) and Ran(f) • f is called a one-to-one correspondence between A and B if f is everywhere defined, onto and one to one • a function f: A B is said to be invertible if its inverse relation f-1 is also a function
Invertible Functions Theorem 1. Let f: A B be a function. (a) then f-1 is a function from B to A if and only if f is one to one if f-1 is a function, then (b) the function f-1 is also one to one (c) f-1 is everywhere defined if and only if f is onto (d) f-1 is onto if and only if f is everywhere defined • if f is a one-to-one correspondence between A and B, then f-1 is a one-to-one correspondence between B and A; for all a in A and b in B, f(f-1(b))=b and f-1(f(a))=a • if f: A B is a one-to-one function, then the equation b=f(a) is equivalent to a= f-1(b)
Composition of Functions Theorem 2. Let f: A B be any function. Then (a) 1 B f=f (b) f 1 A=f if f is a one-to-one correspondence between A and B, then (c) f-1 f = 1 A (d) f f-1=1 B Theorem 3. (a) Let f: A B and g: B A be functions such that g f= 1 A and f g= 1 B. Then f is a one-toone correspondence between A and B, g is a one-to-one correspondence between B and A, and each is the inverse of the other (b) Let f: A B and g: B C be invertible. Then g f is invertible, and (g f)-1= f-1 g-1
Functions • It’s often easier to show that a function is one to one and onto by constructing an inverse instead of proceeding directly Theorem 4. Let A and B be two finite sets with the same number of elements, and let f: A B be an everywhere defined function. (a) if f is one to one, then f is onto (b) if f is onto, then f is one to one
- Slides: 11