Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Logic for computer science
Chapter 2
Mathematical Preliminaries
Transparency No. 2-0
mathematical preliminaries
Contents
Relations
Functions
Partial orders
Induction
(Formal) Language
Trees
Transparency No. 2-2
mathematical preliminaries
Cartesian products
A, B: two sets
AxB (Cartesian Product of A and B) is the set of all
ordered 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 = ?
Transparency No. 2-3
mathematical preliminaries
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 = {<1,4>, <1,5>, <2,6> }
R2 = {}
R3 = {1,2,3,4}
R4 = {<1,2>, <3,4>, <5,6> }
Transparency No. 2-4
mathematical preliminaries
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).
Transparency No. 2-5
mathematical preliminaries
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
Transparency No. 2-6
mathematical preliminaries
(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
with (x,y) G is denoted f(x).
Transparency No. 2-7
mathematical preliminaries
(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.
range(G) or
imgae(G)
A=Dom(f)
G
B=Codom(f)
Dom(G)
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.
Transparency No. 2-8
mathematical preliminaries
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 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.
Transparency No. 2-9
mathematical preliminaries
Example:
1
2
3
g1
4
5
6
4
5
6
g5
1
2
3
1
2
3
4
5
6
g4
g3
1
2
3
g2
4
5
6
1
2
3
4
5
6
A= {1,2,3} B= {4,5,6}
Let fi = <A,B,gi>. then
dom(gi) = ?; range(gi) = ?
•which are total functions?
•which are 1-1 functions?
•which are surjective, bijective?
Transparency No. 2-10
mathematical preliminaries
Operations on relations (and functions)
R AxB; S B x C: two relations
composition 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
associative, I.e., for any function or relation f,g,h,
f· (g·h) = (f·g) ·h
Transparency No. 2-11
mathematical preliminaries
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
s
y
rule: if xRy then draw an
arc from x on left S to y
on right S.
s
Transparency No. 2-12
mathematical preliminaries
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?
Transparency No. 2-13
mathematical preliminaries
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 ?
Transparency No. 2-14
mathematical preliminaries
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 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.
Transparency No. 2-15
mathematical preliminaries
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
b x (resp., x b) for all x X.
Note: b may not belong to X.
Transparency No. 2-16
mathematical preliminaries
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.
Transparency No. 2-17
mathematical preliminaries
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 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.
Transparency No. 2-18
mathematical preliminaries
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 ?
Transparency No. 2-19
mathematical preliminaries
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.
Transparency No. 2-20
mathematical preliminaries
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
Transparency No. 2-21
mathematical preliminaries
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).
Transparency No. 2-22
mathematical preliminaries
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.)
Transparency No. 2-23
mathematical preliminaries
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.
Transparency No. 2-24
mathematical preliminaries
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. 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 < x => p(y) is true)
==> (by (2).) p(x) holds ==> x NP. qed
Transparency No. 2-25
mathematical preliminaries
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 S+ over an alphabets S = {a,b,c,...,z}
Initial: if x S, then x S+.
closure: If x S and a S+, then xa S+.
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?
Transparency No. 2-26
mathematical preliminaries
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 > 0) 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.
Transparency No. 2-27
mathematical preliminaries
General form of inductively defining a set (or domain)
W : a set,
Init: a subset of W
F: a set of functions on W,
we define a subset D of W as follows:
1. Initialization: Every element of Init is an element of D.
(or simply Init D)
2. closure: If f:Wn->W in F and t1,...,tn are members of D,
then so are f(t1,...,tn)
3. plus one of the following 3 phrases.
3.1 D is the least subset of W with the above two properties.
3.2 D is the intersection of all subsets of W with property 1,2.
3.3 Only elements obtainable by a finite number of
applications of rules 1 and 2 are elements of D.
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.
Transparency No. 2-28
mathematical preliminaries
Define functions on recursively defined domains
Consider the following function:
Na : S+ 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 = S.
==> 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 ∈ D= S +.
==> for any y S + ,
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. ]
Transparency No. 2-29
mathematical preliminaries
Example of a multi-defined Domain
Arithmetic expression (Ar1 ⊆ S*) :
Init: Constants a,b,c,… and variables x,y,z,… are
arithmetic expressions
Closure: If a and b are arithmetic expressions then so
are a+b, a-b, -a, ax b and a/b.
ambiguous arithmetic expressions:
2–3x5; 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
x
2
3
2
3
5
Transparency No. 2-30
5
mathematical preliminaries
Structural induction(SI)
D: an inductively defined domain
P(x): a property on D.
To show that P(x) holds for all x in D, 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 ∈ D.
Example: show P(x) “Na(x) 0” holds for all x.
Base step: x Init = (S= {a,b,c,...})
x = a => Na(x) = 1 0.
x a => Na(x) = 0 0
Ind. step: x: any element in S, y: any element in S+.
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.
Transparency No. 2-31
mathematical preliminaries
Correctness of structural induction (SI)
Structural induction is a special case of well-founded
induction. Why?
Let D be an inductively defined domain.
We can define a (strict) partial ordering < on D 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 ∈ D.
moreover, if s < t and t < u then s < u for all s,t,u ∈ D.
Notes:
1. < may not be a s.p.o.
2. However, if every element of D 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 (D, <).
4. Even if < is not a spo, SI still holds. (a more complicated
ordering then < is needed to show its correctness)
Transparency No. 2-32
mathematical preliminaries
Correctness of recursively defining a function on a recursively
defined domain without ambiguous elements.
D: a recursively defined domain s.t. every element
has exactly one form.
g:D 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,
t1,…,tn ∈ D, g(f(t,…,tn)) = h(g(t1),…,(tn)) is given in terms of
g(t1),..,g(tn). Then
there is exactly one function from D 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.
Transparency No. 2-33
mathematical preliminaries
(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!.
Transparency No. 2-34
mathematical preliminaries
More example:
Define the set of labeled binary trees as follows:
S: a set of labels = {a,b,c,..}
G = S U {(, )}, G* = the set of strings over G.
TS is a subset of G* 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).
Transparency No. 2-35
mathematical preliminaries
more example(cont’d)
Use structural ind. to prove properties of trees.
Show that for all tree T ∈ TS, 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
Transparency No. 2-36
mathematical preliminaries
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.
Transparency No. 2-37
mathematical preliminaries
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
Transparency No. 2-38
mathematical preliminaries
Languages
S: any arbitrary set (called alphabet, or set of symbols)
any finite sequence of symbols in S is called a string
over S.
Ex: S = {0, 1}
=> e , 000, 10, 1111,... are strings over {0,1}.
Concatenation of strings:
x= x1x2...xm ; y = y1...yn => xy = x1x2...xm y1...yn
Definitions
S* is the set of all strings over S.
S+ = S* \ {e} is the set of strings of positive length.
Any subset G of S* is called a language over S.
Ex: {},{e}, {0,1}, {0,1}*, {0,00,000,...},
{e, 10,1010,1010,...} are all languages over {0,1}.
Transparency No. 2-39