logic for computer science transparency no. 2-0 chapter 2 mathematical preliminaries

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

Post on 20-Dec-2015

230 views

Category:

Documents


0 download

TRANSCRIPT

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

Logic for computer science

Transparency No. 2-0

Chapter 2

Mathematical Preliminaries

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

mathematical preliminaries

Transparency No. 2-2

Contents

RelationsFunctionsPartial ordersInduction(Formal) LanguageTrees

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

mathematical preliminaries

Transparency No. 2-3

Cartesian products

A, B: two sets AxB (Cartesian Product of A and B) is the set of all ord

ered pairs {<a,b> | a A and b B }. Examples:

A= {1,2,3}, B= {4,5,6} => AxB = ?

A1,A2,...,An (n > 0): n sets A1xA2x...xAn = {<a1,a2,...,an> | ai Ai }.

Example:

1. A1={1,2},A2={a,b},A3={x,y} ==> |A1xA2xA3| = ?

2. A1= {}, A2={a,b} => A1xA2 = ?

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

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 A

xB. Example:

If A={1,2,3}, B ={4,5,6}, then which of the following is a binary relation between A and B ?

R1 = {<1,4>, <1,5>, <2,6> }

R2 = {}

R3 = {1,2,3,4}

R4 = {<1,2>, <3,4>, <5,6> }

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

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. <x,y> R} The range of R:

range(R) ={y B, | x A, s.t., <x,y> R} <x,y> 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 A1,A2,...,An is any subset of A1xA2...xAn, n is called the arity of R

If A1=A2=...=An=A => R is called an n-tuple relation (on A).

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

mathematical preliminaries

Transparency No. 2-6

Examples about relations

A = the set of All human beings

= {...,蔣中正 , 蔣經國 , 蔣緯國 , ...}

the-father-of (父子關係 ) = {<x,y> | x,y are human and x is the father of y }

is a binary relation over humans.

the-brother-of (兄弟關係 ) ={<x,y> | x and y are human and x is the brother of y }

So, <蔣中正 ,蔣經國 >,<蔣中正 ,蔣經國 > the-father-of

and <蔣經國 , 蔣緯國 >,<蔣緯國 , 蔣經國 > the-brother-of

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

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=<A,B,G> 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 wi∈

th (x,y) G is denoted f(x).

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

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) orimgae(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.

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

mathematical preliminaries

Transparency No. 2-9

Classification of (total) functions

f:AB 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 on

e 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.

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

mathematical preliminaries

Transparency No. 2-10

Example:

A= {1,2,3} B= {4,5,6}Let fi = <A,B,gi>. thendom(gi) = ?; range(gi) = ?•which are total functions?•which are 1-1 functions?•which are surjective, bijective?

123

456

123

456

123

456

g1

g3

g5

123

456

g2

123

456

g4

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

mathematical preliminaries

Transparency No. 2-11

Operations on relations (and functions)

R AxB; S B x C: two relationscomposition of R and S: R · S = {<a,c> | there is b B s.t., <a,b> R and <b,c> S }.

Identity relation: IA = {<a,a> | a A }

Converse relation: R-1 = {<b,a> | <a,b> R }f:A B; g: BC: two functions, then

g·f:AC defined by g·f(x) = g(f(x)).Note: function and relation compositions are ass

ociative, I.e., for any function or relation f,g,h,

f· (g·h) = (f·g) ·h

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

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.

x x

y y

s s

rule: if xRy then draw an arc from x on left S to y on right S.

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

mathematical preliminaries

Transparency No. 2-13

ExamplesThe 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?

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

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 preor

der set (resp. poset, strict poset).

What order sets do (N, <) , (N, ) and (N, |) belong to ?

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

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 b

y “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 xy /\ 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.

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

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 xy or yx) .

4. b S is a lower bound (resp., upper bound) of X iff

bx (resp., xb) for all x X. Note: b may not belong to X.

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

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.

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

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 x1,x2,x3,.... s.t., x1 > x2 > x3 >... ).

Note: x > y means y < x (i.e., y x and y x) if is well-founded => (S,) is called a well-founded s

et.

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.

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

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 ?

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

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. N

ow (*) 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.

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

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

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

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 < x => P(y)) => p(x) ---(ind. step)

(1) is a special case of (2) [i.e., (2) implies (1)] (for all y in S y < x => P(y)) in (2) is called the ind. hyp. of (2).

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

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 < x => P(y)) => p(x) ---ind. step (1) is already implied by (2) (for all y in S y < x => 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.)

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

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 < x => 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 < x => 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.

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

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 < x => P(y)) => p(x) ---ind. steppf: 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 < x => p(y) is true) ==> (by (2).) p(x) holds ==> x NP. qed

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

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?

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

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 Ni = {0,2,4,6,...} U { 2i+1, 2i+3, ...}. Then {0,2,4,6,...} and Ni (i > all satisfy Def. 1.

Among {0,2,4,6,...} and Ni (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.

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

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 t1,...,tn are members of ,

then so are f(t1,...,tn)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 applicatio

ns of rules 1 and 2 are elements of . Note: Although phrase 3. is necessary, it is usually replaced by an adv. “inductiv

ely” or “recursively” before “define”, and sometimes even totally omitted if it is understood in mind.

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

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(t1,...,tn) of element f(t1,...,

tn) for each f F and t1,...,tn = +. ==> 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 isnot multi-defined. [I.e., There is exactly one way to form (o

r derive ) each element in the domain. ]

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

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

532

x

532

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

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.

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

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 <.] ti < f(t1,...,tn) i=1,..,n, for each f in F and for all t1,..,tn .

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)

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

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) = ci is given explicitly for each i Init. (2) recursion: for each operation f of arity n and for all t1, t

1,…,tn , g(ft,…,tn)) = h(g(t1),…,(tn)) is given in terms of g(t1),..,g(tn). 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(t1,…,tn) for some f and some t1,…,tn.

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

mathematical preliminaries

Transparency No. 2-34

(by ind. hyp.,) t1,…,tn can be assigned values g(t1),…,g(tn)

by closure rule x can be assigned value h(g(t1),…,g(tn).

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 cx.]

(2) let x = f(t1,…,tn) for some f and some t1,…,tn∉ N

(g1(t1),…,g1(tn)) = (g2(t1),…,g2(tn))

by closure rule g1(x) = h(g(t1),…,g(tn). = h(g(t1),…,g(tn)=g2(x).

x ∉ N, a contradiction!.

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

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).

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

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

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

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 succ

essor 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 sh

ow: Base step: P(0) Ind. step: Let x be any number, If P(x) then P(x’). ---- This is just the math. ind.

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

mathematical preliminaries

Transparency No. 2-38

More Example

Let N = {0, s0,ss0,sss0,…}.Define + : N2 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

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

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 o

ver .Ex: = {0, 1}

=> , 000, 10, 1111,... are strings over {0,1}. Concatenation of strings:

x= x1x2...xm ; y = y1...yn => xy = x1x2...xm y1...yn

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}.