Presentation is loading. Please wait.

Presentation is loading. Please wait.

Logic for computer science Transparency No. 2-0 Chapter 2 Mathematical Preliminaries.

Similar presentations


Presentation on theme: "Logic for computer science Transparency No. 2-0 Chapter 2 Mathematical Preliminaries."— Presentation transcript:

1 Logic for computer science Transparency No. 2-0 Chapter 2 Mathematical Preliminaries

2 mathematical preliminaries Transparency No. 2-2 Contents Relations Functions Partial orders Induction (Formal) Language Trees

3 mathematical preliminaries Transparency No. 2-3 Cartesian products A, B: two sets AxB (Cartesian Product of A and B) is the set of all ordered pairs { | a  A and b  B }. Examples: A= {1,2,3}, B= {4,5,6} => AxB = ? A 1,A 2,...,A n (n > 0): n sets A 1 xA 2 x...xA n = { | a i  A i }. Example: 1. A 1 ={1,2},A 2 ={a,b},A 3 ={x,y} ==> |A 1 xA 2 xA 3 | = ? 2. A 1 = {}, A 2 ={a,b} => A 1 xA 2 = ?

4 mathematical preliminaries Transparency No. 2-4 Binary Relation Binary relation: A,B: two sets A binary relation R between A and B is any subset of AxB. Example: If A={1,2,3}, B ={4,5,6}, then which of the following is a binary relation between A and B ? R1 = {,, } R2 = {} R3 = {1,2,3,4} R4 = {,, }

5 mathematical preliminaries Transparency No. 2-5 Basic terminology about relation R: a binary relation between A and B (I.e., a subset of AxB), then The domain of R: dom(R) = {x  A |  y  B s.t.  R} The range of R: range(R) ={y  B, |  x  A, s.t.,  R}  R is usually written as x R y. If A = B, then R is simply called a relation over(on) A. An n-tuple relation R among A 1,A 2,...,A n is any subset of A 1 xA 2...xA n, n is called the arity of R If A 1 =A 2 =...=A n =A => R is called an n-tuple relation (on A).

6 mathematical preliminaries Transparency No. 2-6 Examples about relations A = the set of All human beings = {..., 蔣中正, 蔣經國, 蔣緯國,...} the-father-of ( 父子關係 ) = { | x,y are human and x is the father of y } is a binary relation over humans. the-brother-of ( 兄弟關係 ) = { | x and y are human and x is the brother of y } So,,  the-father-of and,  the-brother-of

7 mathematical preliminaries Transparency No. 2-7 (Partial) Functions A relation R between A and B is functional iff, for all x  A and y,z  B, x R y and x R z implies y = z. (I.e., for each x in A, there is at most one y in B, s.t., x R y.) A partial function is a triple f= where A and B are sets and G is a functional relation between A and B. A is called the domain of f B is called the codomain of f and G is called the graph of f. Notation:1. f : A  B; 2. A= dom(f); B=Codom(f); G=graph(f) Note: Dom(f)  Dom(G) in general. For every element x ∈ A, the unique y in the range of f with (x,y)  G is denoted f(x).

8 mathematical preliminaries Transparency No. 2-8 (partial) functions If Dom(f) = Dom(G), (I.e., for all x in A, there is y in B, s.t., x G y), then call f a (total) function f and its graph G are usually identified. G Dom(G) range(G) or imgae(G) A=Dom(f) B=Codom(f) f is a total function iff Dom(f) = Dom(G) Note: In the following, if not stated otherwise, all functions are assumed to be total function.

9 mathematical preliminaries Transparency No. 2-9 Classification of (total) functions f:A  B a (partial) function; X a subset of A, Y a subset of B; then f(X) : the image of X under f = {y  B | there is x in X s.t., f(x) = y } f -1 (Y):the inverse image of Y under f = {x  A | there is y  Y s.t., f(x) = y } f is surjective(onto) iff f(A) = B f is injective(1-1) iff for each y in B, there is at most one x in A, s.t., f(x) =y. f is bijective (or a bijection) iff f is 1-1 and onto. If f is 1-1 and onto then there exists a unique function g:B  A s.t., g(y)=x iff f(x) = y. g is called the inverse of f and is denoted f -1.

10 mathematical preliminaries Transparency No. 2-10 Example: A= {1,2,3}  B= {4,5,6} Let fi =. then dom(gi) = ?; range(gi) = ? which are total functions? which are 1-1 functions? which are surjective, bijective? 123123 456456 123123 456456 123123 456456 g1 g3 g5 123123 456456 g2 123123 456456 g4

11 mathematical preliminaries Transparency No. 2-11 Operations on relations (and functions) R  AxB; S  B x C: two relations composition of R and S: R · S = { | there is b  B s.t.,  R and  S }. Identity relation: I A = { | a  A } Converse relation: R -1 = { |  R } f:A  B; g: B  C: two functions, then g·f:A  C defined by g·f(x) = g(f(x)). Note: function and relation compositions are associative, I.e., for any function or relation f,g,h, f· (g·h) = (f·g) ·h

12 mathematical preliminaries Transparency No. 2-12 Properties of binary relations R: A binary relation on S, 1. R is reflexive iff for all x in S, x R x. 2. R is irreflexive iff for all x in S, not x R x. 3. R is symmetric iff for all x, y in S, xRy ⇒ yRx. 4. R is asymmetric iff for all x,y in S, xRy ⇒ yRx. 5. R is antisymmetric iff for all x,y in S, xRy and yRx ⇒ x=y. 6. R is transitive iff for all x,y,z in S, xRy and yRz ⇒ xRz. Graphical realization of a binary relation and its properties. xx yy ss rule: if xRy then draw an arc from x on left S to y on right S.

13 mathematical preliminaries Transparency No. 2-13 Examples The relation  on the set of natural numbers N. What properties does  satisfy ? ref. irref, or neither ? symmetric, asymmetric or antisymmetric ? transitive ? The relation  on the set of natural numbers N. The divide | relation on integers N ? x | y iff x divides y. (eg. 2 | 10, but not 3 | 10) What properties do  and | satisfy ? The BROTHER relation on males (or on all people) (x,y)  BROTHER iff x is y’s brother. The ANCESTOR relation in a family. (x,y)  ANCESTOR if x is an ancestor of y. What properties does BROTHER(ANCESTOR) have ?

14 mathematical preliminaries Transparency No. 2-14 Some special relations R: a binary relation on S 1. R is a preorder iff it is ref. and trans. 2. R is a partial order (p.o.) iff R is ref.,trans. and antisym. (usually written as  ). 3. R is a strict partial order (s.p.o) iff it is irref. and transitive. usually written <. 4. R is a total (or linear) order iff it is a partial order and every two element are comparable (i.e., for all x,y either xRy or yRx.) 5. R is an equivalence relation iff it is ref. sym. and trans. If R is a preorder (resp. po or spo) then (S,R) is called a preorder set (resp. poset, strict poset). What order sets do (N, <), (N,  ) and (N, |) belong to ?

15 mathematical preliminaries Transparency No. 2-15 Relationship between properties of relations R: a nonempty binary relation on a nonempty set S. 1. If R is ref., then it is not irref. (ref. ⇒ not irref.) 2. irref. and antisym.  asym. 3. If  is a partial order, then the relation < defined by “x < y iff x  y and x  y” is a strict partial order. 4. If <  is a strict partial order, then the relation  defined by “x  y iff x < y or x = y” is a partial order. 5. According to 3 and 4, basically there is no difference b/t partial order and strict partial order. Note: In the literature, 1. if  is given first, then x < y means x  y /\ x  y. 2. If < is given first, then x  y means x < y \/ x = y. 3. x > y means y < x; x  y means y  x.

16 mathematical preliminaries Transparency No. 2-16 Properties of ordered set (S,  ): a poset, X: a subset of S. 1. b  X is the least (or called minimum) element of X iff b  x for all x  X. 2. b  X is the greatest (or called maximum or largest) element of X iff X  b for all x  X. Least element and greatest element, if existing, is unique for any subset X of a poset (S,  ) pf: let x, y be least elements of X. Then, x  y and y  x. So by antisym. of , x = y. 3. X is a chain iff (X,R) is a linear order(, i.e., for all x, y  X, either x  y or y  x). 4. b  S is a lower bound (resp., upper bound) of X iff b  x (resp., x  b) for all x  X. Note: b may not belong to X.

17 mathematical preliminaries Transparency No. 2-17 Properties of ordered sets (S,  ) : a poset, X: a nonempty subset of S. 5. b in X is minimal in X iff there is no element less than it. i.e., there is no x ∈ X, s.t., (x < b), or “for all x, x  b ⇒ x =b.” 6. b in X is a maximal element of X iff there is no element greater then it. i.e., there is no x ∈ X, s.t., (b < x), or “for all x, b  x ⇒ x=b.” Note: 1.Every maximum element is maximal, but not the converse in general. 2. Maximal and minimal are not unique in general.

18 mathematical preliminaries Transparency No. 2-18 well-founded set and minimum conditions (S,  ) : a poset ( 偏序集 ).  is said to be well-founded ( 良基性 ) iff there is no infinite descending sequence. (i.e., there is no infinite sequence x 1,x 2,x 3,.... s.t., x 1 > x 2 > x 3 >... ). Note: x > y means y < x (i.e., y  x and y  x) if  is well-founded => (S,  ) is called a well-founded set. 2. (S,  ) is said to satisfy the minimal condition iff every nonempty subset of S has a minimal element. (S,  ): a total ordered set ( 全序集 ).  is said to be a well-ordering( 良序 ) iff every nonempty subset of S has a least (or equivalently, minimal) element. If  is well ordered, then (S,  ) is called a well-ordered set.

19 mathematical preliminaries Transparency No. 2-19 Examples of ordered sets Among the relations (N,  ), (N,  ), (N, |), (Z,  ), (Z,  ), (Z,|) and (R,  ), 1. Which are well-founded ? 2. Which are well-ordered ?

20 mathematical preliminaries Transparency No. 2-20 Equivalence of well-foundness and minimal condition (S,  ) is well-founded (w.f.) iff it satisfies the minimum conditions (m.c.). pf: scheme: (1) not w.f => not m.c. (2) not m.c. => not w.f. (1) Let x1,x2,... be any infinite sequence s.t. x1 > x2 > x3 >.... Now let X={x1,x2,...}. Then X has no minimal element. Hence, S does not satisfy m.c. (2) Let X be any nonempty subset of S w/o minimal elements. Now (*) chose arbitrarily an element a1 from X,let X1 = {x | x  X and a1 > x } (i.e. the set of elements in X < a1 ) since a1 is not minimal, X1 is nonempty and has no minimal element, too. So we can repeat the procedure (*) infinitely to find a2, X2, a3, X3,... and obtain the infinite descending sequence a1 > a2 > a3 >... So S is not w.f. Q.E.D.

21 mathematical preliminaries Transparency No. 2-21 Equivalence of w.f. and w.o. If (S,  ) is linear ordered then S is well- founded(or equ., satisfies the m.c.) iff S is well- ordered. pf: (1): w.f. => well-ordered. In total ordered set, every minimum element is a least element. x: minimal in X, let y  x be any element in X => either y < x (impossible!) or x  y. Hence x is least in X. Existence of minimum elements is implied by m.c. (2) well-ordered => w.f. Trivial. Since every nonempty subset have a least element, which is a minimal element. qed

22 mathematical preliminaries Transparency No. 2-22 Variants of Inductions Mathematical Induction: To prove a property P(n) holds for all natural number n  N, it suffices to show that (1) P(0) holds --- (base step) and (2) For all n  N, p(n) => p(n+1) --- (induction step)  P(n) in (2) is called induction hypothesis (h.p.) Well-order induction: (S,  ) a well-ordered set; P(x): a property about S. To show that P(x) holds for all x in S, it suffices to show (1) P(x) holds for the least element x of S. --- (base step) (2) for all x in S, (for all y in S y P(y)) => p(x) ---(ind. step)  (1) is a special case of (2) [i.e., (2) implies (1)]  (for all y in S y P(y)) in (2) is called the ind. hyp. of (2).

23 mathematical preliminaries Transparency No. 2-23 Variants of inductions Well-founded induction: (S,  ) a well-founded set. P(x) a property about S. w.f. induction says that to prove that P(x) holds for all x in S, it suffices to show that (1) P(x) holds for all minimal elements x of S --- base step, and (2) for all x in S, (for all y in S y P(y)) => p(x) ---ind. step  (1) is already implied by (2)  (for all y in S y P(y)) in (2) is the ind. hyp. of the proof. Facts: w.f. Ind. => well-ordered ind. => math ind. (I.e., If w.f ind. is true, then so is well-ordered ind. and if well-ordered ind. is true, then so is math. ind.)

24 mathematical preliminaries Transparency No. 2-24 relationship between types of inductions Show that w.f. Ind. => well-ordered ind. If 1. (S,  ) is any well-ordered set, and 2. for all x in S (for all y in S, y P(x)) => P(x) holds, then for all x  S, P(x) holds. Pf: Since (S,  ) is well-ordered, (S,  ) is well-founded. By condition 2, (w.f. ind and w.o. ind. have the same form) for all x in S (for all y in S, y P(x)) => P(x) holds Hence (by w.f. induction) P(x) holds for all x in S. Show that math ind. is implied by well-order ind. pf: left as an exercise.

25 mathematical preliminaries Transparency No. 2-25 Correctness of w.f. induction (S,  ) : a well-founded set. P(x) : a property about S. Then P(x) holds for all x  S, if (1) P(x) holds for all minimal elements x  S --- base step, and (2) for all x  S, (for all y  S y P(y)) = > p(x) ---ind. step pf: Assume NP = { x | x  S and P(x) is not true } is not empty. ==> Let x be any minimal element of NP. case (1): x is minimal in S. --> impossible! (violating (1) ) by (1), P(x) holds and x  NP. case (2): x is not minimal. --> impossible, either! (hence NP has no minimal element and NP is empty, ie. P(x) holds for all x in S) x not minimal ==> L = {y | y  S /\ y < x} is not empty. ==> L  NP = { } (o/w x would not be minimal in NP.) ==> (ind. hyp. holds for x, i.e., for all y  S, y p(y) is true) ==> (by (2).) p(x) holds ==> x  NP. qed

26 mathematical preliminaries Transparency No. 2-26 Definition by induction (or recursion) Consider the following ways of defining a set. 1. the set of even numbers Even = {0,2,4,...}: Initial rule : 0  Even. closure rule: if x  Even then x +2  ven. 2. The set of strings  + over an alphabets  = {a,b,c,...,z} Initial: if x  , then x   +. closure: If x   and    +, then x    +. 3. The set of lists of numbers. Initial: [ ] is a (empty) list, closure: If x is number and L is a list, then [x | L] is a list.  [x | L] is the result of inserting x into the head position of L.  e.g., [ 5 | [2,3,4]] = [5,2,3,4] Problem:All definitions well-defined? What’s wrong?

27 mathematical preliminaries Transparency No. 2-27 Problems about recursive definition The above definitions are incomplete in the sense that there are multiple sets satisfy each definition Example: Let N i = {0,2,4,6,...} U { 2i+1, 2i+3,...}. Then {0,2,4,6,...} and N i (i >  all satisfy Def. 1. Among {0,2,4,6,...} and N i (i > 0), which one is our intended set ? How to overcome the incompleteness ? Relationship between {0,2,4,...} and the collection of sets satisfying the definitions? {0,2,4,...} is the least set among all sets. {0,2,4,...} is equal to the intersection of all sets. Every other set contains at least one element which is not grounded.

28 mathematical preliminaries Transparency No. 2-28 General form of inductively defining a set (or domain)  : a set, Init: a subset of  F: a set of functions on , we define a subset  of  as follows: 1. Initialization: Every element of Init is an element of . (or simply Init   ) 2. closure: If f:  n ->  in F and t 1,...,t n are members of , then so are f(t 1,...,t n ) 3. plus one of the following 3 phrases. 3.1  is the least subset of  with the above two properties. 3.2  is the intersection of all subsets of  with property 1,2. 3.3 Only elements obtainable by a finite number of applications of rules 1 and 2 are elements of . Note: Although phrase 3. is necessary, it is usually replaced by an adv. “inductively” or “recursively” before “define”, and sometimes even totally omitted if it is understood in mind.

29 mathematical preliminaries Transparency No. 2-29 Define functions on recursively defined domains Consider the following function: Na :  +  N with Na(x) = def number of a’s in string x. Now we can define Na as follows: Initial: specify the value Na(x) of x for each x in Init = . ==> Na(a) = 1 ; Na(x) = 0 if x  a. recursion: specify the value Na(f(t 1,...,t n ) of element f(t 1,...,t n ) for each f  F and t 1,...,t n   =  +. ==> for any y   +, Na(ay) = 1 + Na(y) and Na(xy) = Na(y) if x is any symbol  a. Such kind of definitions are well defined. why ? sufficient condition: The recursively defined domain is not multi-defined. [I.e., There is exactly one way to form (or derive ) each element in the domain. ]

30 mathematical preliminaries Transparency No. 2-30 Example of a multi-defined Domain Arithmetic expression (Ar1   *) : Init: Constants a,b,c,… and variables x,y,z,… are arithmetic expressions Closure: If  and  are arithmetic expressions then so are , , ,  x  and . ambiguous arithmetic expressions: 2 – 3 x 5 ; x – y + 2 two ways to form “ 2 – 3 x 5 “: 1. 2, 3, 2-3, 5, 2-3 x 5. 2. 2, 3, 5, 3x5, 2- 3x 5. x  5 32  x 532

31 mathematical preliminaries Transparency No. 2-31 Structural induction(SI)  : an inductively defined domain P(x): a property on . To show that P(x) holds for all x in , it suffices to show Base step: P(x) holds for all x  Init. Ind. step: P(t1),...,P(tn)  P(f(t1,...,tn)) for all f  F, and for all t1,...,tn  . Example: show P(x)  “Na(x)  0” holds for all x. Base step: x  Init = (  = {a,b,c,...})  x = a => Na(x) = 1  0.  x  a => Na(x) = 0  0 Ind. step: x: any element in , y: any element in  . Assume (ind. hyp.) Na(y)  0. then  if x = a => Na(x y) = 1 + N(y)  0  if x  a => Na(x y) = N(y)  0.

32 mathematical preliminaries Transparency No. 2-32 Correctness of structural induction (SI) Structural induction is a special case of well-founded induction. Why? Let  be an inductively defined domain. We can define a (strict) partial ordering < on  as follows: [All elements of Init are minimal in <.] t i < f(t 1,...,t n ) i=1,..,n, for each f in F and for all t 1,..,t n  . moreover, if s < t and t < u then s < u for all s,t,u  . Notes: 1. < may not be a s.p.o. 2. However, if every element of  is not multi-defined, then < must be a s.p.o. Ex of multi-defined set: Even = 0  E | x + 2, x - 4  E. 3. If < is a spo, then structural ind. is just w.f. ind. on the ordered set ( , <). 4. Even if < is not a spo, SI still holds. (a more complicated ordering then < is needed to show its correctness)

33 mathematical preliminaries Transparency No. 2-33 Correctness of recursively defining a function on a recursively defined domain without ambiguous elements.  : a recursively defined domain s.t. every element has exactly one form. g:   T defined as follows: (1) Init: g(i) = c i is given explicitly for each i  Init. (2) recursion: for each operation f of arity n and for all t 1, t1,…,t n  , g(f  t ,…,t n )) = h(g(t 1 ),…,(t n )) is given in terms of g(t 1 ),..,g(t n ). Then there is exactly one function from  to T satisfying conditions (1) and (2). pf: (I) : Existence: Assume the set N = { y  D | y cannot be assigned value by (1) and (2)} is not empty. =>let x be any element minimal N.  (1) x ∉ Init.  (2) let x = f(t 1,…,t n ) for some f and some t 1,…,t n.

34 mathematical preliminaries Transparency No. 2-34  (by ind. hyp.,) t 1,…,t n can be assigned values g(t 1 ),…,g(t n )  by closure rule x can be assigned value h(g(t 1 ),…,g(t n ).  x ∉ N, a contradiction!. (II) : Uniquess: Assume there are two distinct functions g1, g2: D  T satisfying condition (1) and (2). Let N = {y  D | g1(y) ≠ g2(y) } and let x be any minimal element  N. ⇒ (1) x ∉ Init. [since both g1(x) and g2(x) must equal to c x.]  (2) let x = f(t 1,…,t n ) for some f and some t 1,…,t n ∉ N  (g1(t 1 ),…,g1(t n )) = (g2(t 1 ),…,g2(t n ))  by closure rule g1(x) = h(g(t 1 ),…,g(t n ). = h(g(t 1 ),…,g(t n )=g2(x).  x ∉ N, a contradiction!.

35 mathematical preliminaries Transparency No. 2-35 More example: Define the set of labeled binary trees as follows:  : a set of labels = {a,b,c,..}  =  U {(, )},  * = the set of strings over . T  is a subset of  * defined inductively as follows: Init: () is a tree. closure: if x is a label, and L and R are trees, then (x L R) is a tree. Examples: (), (a ()()), ((a), (b),()), For each tree T, lf(T) = # of “(“ and lb(T) =# of labels in T; e(T) = number of empty subtrees “()”, can be defined as Init: l(()) = 1; lb(()) = 0; e(()) = 1. recursion: lf((x LR)) = 1+ l(L) + l(R) ; lb((x L R)) = 1 + lb(L) +lb(R) ; e((x L R)) = e(L) + e(R).

36 mathematical preliminaries Transparency No. 2-36 more example(cont’d) Use structural ind. to prove properties of trees. Show that for all tree T  T , P(T) = def “ lf(T) = lb(T) + e(T)” holds for all tree T. Base step: lf(()) = 1, lb(())=0, e(())=1. OK. ind. step: x: any label, L, R: any trees. assume (ind.hyp.:) lf(L) = lb(L) + e(L) and lf(R) = lb(R) + e(R), then lf((x L R)) = 1 + lf(L) + lf(R) = 1 +lb(L) +lb(R) + e(L) +e(R) e((x L R)) = e(L) +e(R) lb((x L R)) =1 + lb(L) + lb(R) ==> lf((X L R)) = lb((X L R)) + e((X L R)). qed

37 mathematical preliminaries Transparency No. 2-37 math. induction revisited Math. ind. is a special case of structural ind. why? Inductively define N={0,1,2,...}. Init: 0 is a natural number. closure: if n is a natural number, then n’ (called the successor of n, ie., n+1) is a natural number. Example of natural numbers and non natural numbers: 0, 0’, 0’’, 0’’’,... --- unary representation of numbers. 00, 0’0, 0’’00 --- not numbers. Now applying structural Ind. on N based on the above def. To prove p(x) holds for all natural number x, it suffices to show: Base step: P(0) Ind. step: Let x be any number, If P(x) then P(x’). ---- This is just the math. ind.

38 mathematical preliminaries Transparency No. 2-38 More Example Let N = {0, s0,ss0,sss0,…}. Define + : N 2  N by recursion: for all x in N Basis: +(x, 0) = x, Recursion: for all y in N, +(x, y’) = +(x,y) + 1 =s. +(x,y) Prove by SI that for all x, y  N 1. x + (y + z) = (x+y) + z 2. x + y = y + x

39 mathematical preliminaries Transparency No. 2-39 Languages  : any arbitrary set (called alphabet, or set of symbols) any finite sequence of symbols in  is called a string over . Ex:  = {0, 1} => , 000, 10, 1111,... are strings over {0,1}. Concatenation of strings: x= x 1 x 2...x m ; y = y 1...y n => xy = x 1 x 2...x m y 1...y n Definitions  * is the set of all strings over .  + =  * \ {  } is the set of strings of positive length. Any subset  of  * is called a language over . Ex: {},{  }, {0,1}, {0,1}*, {0,00,000,...}, { , 10,1010,1010,...} are all languages over {0,1}.


Download ppt "Logic for computer science Transparency No. 2-0 Chapter 2 Mathematical Preliminaries."

Similar presentations


Ads by Google