You are on page 1of 62

formal Language

Transparency No. 1-1
Formal Language and
Automata Theory
Cheng-Chia Chen
September 2010
Introduction
Transparency No. 1-2
Course outlines
- Introduction:
Mathematical preliminaries:
sets, relations, functions,sequences, graphs, trees, proof by
induction, definition by induction (recursion).
Basics of formal languages:
alphabet, word, sentence, concatenation ,union, iteration [= Kleene
star], language, infinity of languages, finite representations of
languages
- PART I: Finite Automata and Regular Sets
DFA,NFA,regular expressions and their equivalence
limitation of FAs;
Closure properties of FAs,
Optimization of FAs
Introduction
Transparency No. 1-3
course outline (cont'd)
- PART II: Pushdown Automata and Context Free
Languages
CFGs and CFLs; normal forms of CFG
Limitation of CFG; PDAs and their variations,
closure properties of CFLs
Equivalence of pda and CFGs; deterministic PDAs
parsing (Early or CYK's algorithms)
- PART III: Turing Machines and Effective
Computability
Turing machine [& its variations] and Equivalence models
Universal TMs
Decidable and undecidable problems (Recursive sets and
recursively enumerable sets)
Problems reductions ; Some undecidable problems
Introduction
Transparency No. 1-4
Goals of the course
- understand the foundation of computation
- make precise the meaning of the following terms:
[formal] languages, problems, Programs, machines,
computations
computable {languages, problems, sets, functions}
- understand various models of machines and their
relative power : FA, PDAs, LA (linear bounded
automata), TMs, [register machines, RAMs,...]
- study various representations of languages in finite
ways via grammars: RGs, CFGs, CSGs, general PSGs
formal Language
Transparency No. 1-1
Chapter 1 Introduction
include Lecture 1 and 2
Introduction
Transparency No. 1-6
Mathematical preliminaries (reviews)
- sets
- functions
- relations
- induction
- Recursive definitions
Introduction
Transparency No. 1-7
7
Sets
- Basic structure upon which all other (discrete and
continuous ) structures are built.
- a set is a collection of objects.
an object is anything of interest, maybe itself a set.
- Definition 1.
A set is a collection of objects.
The objects is a set are called the elements or members of
the set.
If x is a memebr of a set S, we say S contains x.
notation: x S vs x Z S
- Ex: In 1,2,3,4,5, the collection of 1,3 5 is a set.
Introduction
Transparency No. 1-8
8
Set description
- How to describe a set:?
1. List all its member.
the set of all positive odd integer >10 = ?
The set all decimal digits = ?
the set of all upper case English letters = ?
The set of all nonnegative integers = ?
2. Set builder notation:
P(x) : a property (or a statement or a proposition) about
objects.
e.g., P(x) = ³ x > 0 and x is odd´
then {x | P(x) } is the set of objects satisfying property P.
P(3) is true => 3 {x | P(x)}
P(2) is false => 2 Z {x | P(x)}
Introduction
Transparency No. 1-9
9
Set predicates
Definition 2.
Two sets S1, S2 are equal iff they have the same elements
S1 = S2 iff x (x S1 <=> x S2)
Ex: {1,3,5} = {1,5,3} = {1,1,3,3, 5}
- Null set ={} = © =
def
the collection of no objects.
Def 3¶: [empty set] for-all x x Z ©.
Def 3. [subset]
A  B iff all elements of A are elements of B.
A  B <=> for-all x (x A => x B)).
- Def 3¶¶: A · B =
def
A  B /\ A { B.
- Exercise : Show that: 1. For all set A (©  A)
2. (A  B /\ B  A) <=> (A = B) 3. A  © => A = ©
Introduction
Transparency No. 1-10
10
Size or cardinality of a set
Def. 4
| A | = the size(cardinality) of A = # of distinct elements of A.
- Ex:
|{1,3,3,5}| = ?
|{}| = ?
| the set of binary digits } | = ?
|N| = ? ; |Z| = ? ; | {2i | i in N} = ?
|R| = ?
- Def. 5.
A set A is finite iff |A| is a natural number ; o/w it is infinite.
Two sets are of the same size (cardinality) iff there is a 1-1
& onto mapping between them.
Introduction
Transparency No. 1-11
11
countability of sets
- Exercise: Show that
1. |N| = |Z| = | Q | = {4,5,6,...}
2. |R| = | [0, 1) |
3. |N| { |R|
- Def.
A set A is said to be denumerable iff |A| = |N|.
A set is countable (or enumerable) iff either |A| = n for some
n in N or |A| = |N|.
- By exercise 3,
R is not countable.
Q and Z is countable.
Introduction
Transparency No. 1-12
12
The power set
Def 6.
If A is a set, then the collection of all subsets of A is also a
set, called the poser set of A and is denoted as P(A) or 2
A
.
- Ex:
P({0,1,2}) = ?
P({}) = ?
|P({1,2,..., n})| = ?
- Order of elements in a set are indistinguishable. But
sometimes we need to distinguish between (1,3,4)
and (3,4,1) --> ordered n-tuples
Introduction
Transparency No. 1-13
More about cardinality
Theorem: for any set A, |A| { |2
A
|.
Pf: (1) The case that A is finite is trivial since |2
A
| = 2
|A|
> |A|
and there is no bijection b/t two finite sets with different sizes.
(2) assume |A| = |2
A
|, i.e., there is a bijection f: A -> 2
A
.
Let D = {x in A | x Z f(x) }. ==>
1. D is a subset of A; Hence
2. ny in A s.t. f(y) = D.
Problem: Is y D ?
if yes (i.e., y D) ==> y Z f(y) = D, a contradiction
if no (i.e., y Z D) ==> y f(y) =D, a contradiction too.
So the assumption is false, i.e., there is no bijection b/t A and
2
A
.
Note: Many proofs of impossibility results about computations
used arguments similar to this.
Introduction
Transparency No. 1-14
14
Cartesian Products
Def. 7 [n-tuple]
If a1,a2,...,an (n > 0) are n objects, then ³(a1,a2,...,an)´ is a
new object, called an (ordered) n-tuple [ with a
i
as the ith
elements.
Any orderd 2-tuple is called a pair.
(a1,a2,...,am) = (b1,b2,...,bn) iff
m = n and for i = 1,..,n a
i
= b
i
.
Def. 8: [Cartesian product]
A x B =
def
{(a,b) | a in A /\ b in B }
A1 x A2 x ...x An =def {(a1,...,an) | ai in Ai }.
Ex: A = {1,2}, B = {a,b,c} , C = {0,1}
1. A x B = ? ; 2. B x A = ?
3. A x {} = ? ;4. A x B x C = ?
Introduction
Transparency No. 1-15
15
Set operations
- union, intersection, difference , complement,
- Definition.
1. A B = {x | x in A or x in B }
2. A· B = {x | x in A and x in B }
3. A - B = {x | x in A but x not in B }
4. ~ A = U - A
5. If A · B = {} => call A and B disjoint.
Introduction
Transparency No. 1-16
16
Set identites
- Identity laws: A ? ? = A
- Domination law: U ? ? = U; {} ?? = {}
- Idempotent law: A ? A = A ;
- complementation: ~~A = A
- commutative : A ? B = B ? A
- Associative: A ? (B ? C) = (A ? B ) ? C
- Distributive: A ? (B ? C) = ?
- DeMoregan laws: ~(A ? B) = ~A ? ~B
Note: Any set of objects satisfying all the above laws is
called a Boolean algebra.
Introduction
Transparency No. 1-17
17
Prove set equality
1. Show that ~(A B) = ~A ·~B by show that
1. ~(A B)  ~A ·~B
2. ~A ·~B  ~(A B)
- pf: (By definition) Let x be any element in ~(A B)
2. show (1) by using set builder and logical equivalence.
3. Show distributive law by using membership table.
4. show ~(A (B· C)) = (~C ·~B) ~A by set identities.
Introduction
Transparency No. 1-18
18
Functions
- Def. 1 [functions] A, B: two sets
1. a function f from A to B is a set of pairs (x, y) in AxB s.t., for
each x in A there is at most one y in B s.t. (x,y) in f.
2. if (x,y) in f, we write f(x) = y.
3. f :A ->B means f is a function from A to B.
Def. 2. If f:A -> B ==>
1. A: the domain of f; B: the codomain of f
if f(a)=b =>
2. b is the image of a; 3. a is the preimage of b
4. range(f) = {y | nx s.t. f(x) = y} = f(A).
5. preimage(f) = {x | $ y s.t. f(x) = y } = f
-1
(B).
6. f is total iff f
-1
(B) = A.
Introduction
Transparency No. 1-19
19
Types of functions
- Def 4.
f: A x B; S: a subset of A,
T: a subset of B
1. f(S) =
def
{y | n x in S s.t. f(x) = y }
2. f
-1
(T) =
def
{x | n y in T s.t. f(x) = y }
Def. [1-1, onto, injection, surjection, bijection]
f: A -> B.
f is 1-1 (an injection) iff f(x)=(fy) => x = y.
f is onto (surjective, a surjection) iff f(A) = B
f is 1-1 & onto <=> f is bijective (a bijection, 1-1
correspondence)
Introduction
Transparency No. 1-20
Relations
- 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 = ?
Introduction
Transparency No. 1-21
Binary relations
- 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> }
Introduction
Transparency No. 1-22
Terminology about binary relations
- R: a binary relation between A and B (I.e., a subset
of AxB), then
The domain of R:
dom(R) = {x A | n y B s.t. <x,y> R}
The range of R:
range(R) ={y B, | n 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),.
Introduction
Transparency No. 1-23
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 in B s.t., <a,b> in R and <b,c> in
S }.
- Identity relation: I
A
= {<a,a> | a in A }
- Converse relation: R
-1
= {<b,a> | <a,b> in 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
Introduction
Transparency No. 1-24
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 => not 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.
Graph 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.
Introduction
Transparency No. 1-25
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 on a family.
(x,y) ANCESTOR if x is an ancestor of y.
What properties does BROTHER(ANCESTOR) have?
Introduction
Transparency No. 1-26
Properties of 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 portial 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 set do (N, <) , (N, · ) and (N, |) belong to ?
Introduction
Transparency No. 1-27
Properties of ordered set
- (S, ·): a poset, X: a subset of S.
1. b in X is the least (or called minimum) element of X iff b · x for
all x in X.
2. b in X is the greatest (or called maxmum or largest) element of
X iff X · b for all x in X.
- Least element and greatest element, if existing, is unigue 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 ia a chain iff (X,R) is a linear order(, i.e., for all x, y in X,
either x·y or y·x) .
4. b in S is a lower bound (resp., upper bound) of X iff
b · x (resp., x · b) for all x in X.
Note: b may or may not belong to X.
Introduction
Transparency No. 1-28
Properties of oredered 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 in 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 in 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.
Introduction
Transparency No. 1-29
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 element.
If · is well ordered, then (S,·) is called a well-ordered set.
Introduction
Transparency No. 1-30
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 ?
Introduction
Transparency No. 1-31
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.
So, 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 \in X1 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 ascending sequence a1 > a2 > a3 > ... So S is not w.f.
Introduction
Transparency No. 1-32
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.)
P(0), n P(n) => P(n+1)
-------------------------------------------MI1
n P(n)
P(0), n P(0)/\...p(n-1) => P(n)
-------------------------------------------MI2
n P(n)
Introduction
Transparency No. 1-33
Well-order Induction
- 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
min
) holds where x
min
is the least element of S. --- (base step)
(2) for all x in S, if (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).
- P(X
min
) , y [ ( x x< y =>P(x) ) => P(y)
--------------------------------------------------------------- WI
x P(x)
Introduction
Transparency No. 1-34
Variants of inductions
- Well-founded induction (WI ):
(S, ·) a well-founded set. P(x) a property about S.
WI 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 in S --- base step, and
(2) for all x in S, (for all y in S y < x => P(y)) => p(x) ---ind. step
(1) has 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.)
Introduction
Transparency No. 1-35
Correctness of WI
- (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: Suppose WI is incorrect. Then there must exist (S,·) satisfying (1)(2) but
the set 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 Z NP.
case (2): x is not minimal in S. --> still impossible!
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 Z NP.
case(1) and (2) imply NP has no minimal element and hence is empty,
which contradicts with (*). Hence the assumption that WI is incorrect is
wrong.
Introduction
Transparency No. 1-36
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 Even.
2. The set of strings L
+
over an alphabets L = {a,b,c,...,z}
Initial: if x in L, then x in L
+
.
closure: If x in L and e in L
+
, then xe in L
+
.
3. The set of lists of numbers.
Initial: [ ] is a 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?
Introduction
Transparency No. 1-37
Problems about recursive definition
- The above definitions are incomplete in 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 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 element which is not grounded.
Introduction
Transparency No. 1-38
General form of inductively defining a set (or domain)
- O : a set, Init: a subset of O
F: a set of functions on O,
- we define a subset A of O as follows:
1. Initialization: Every element of Init is an element of A.
(or simply Init  D)
2. closure: If f:O
n
->O in F and t
1
,...,t
n
are members of A,
then so are f(t
1
,...,t
n
)
3. plus one of the following 3 phrases.
3.1 A is the least subset of W with the above two properties.
3.2 A 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 A.
- 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.
Introduction
Transparency No. 1-39
Define functions on recursively defined domains
- Consider the following function:
#a : L
+
N with #a(x) = number of a¶s in string x.
- Now we can define #a as follows:
Initial: specify the value #a(x) of x for each x in Init = L.
==> #a(a) = 1 ; #a(x) = 0 if x { a.
closure: specify the value #a(f(t
1
,...,t
n
)) of element f(t
1
,...,t
n
)
for each f in F and t
1
,...,t
n
in A = L
+
.
==> for any y in L
+
and z in L:
#a(zy) = 1 + #a(y) if z = a and
#a(zy) = #a(y) if z { a.
- Such kind of definitions are well defined. why ?
There is exactly one way to form each element of the
domain.
Introduction
Transparency No. 1-40
Structural induction
- A: an inductively defined domain
P(x): a property on A.
- To show that P(x) holds for all x in A, it suffices to show
Base step: P(x) holds for all x in Init.
Ind. step: P(t
1
),...,P(t
n
) => P(f(t
1
,...,t
n
)) for all f in F,
and for all t
1
,...,t
n
in A.
- Example: show P(x) ÷ ³#a(x) > 0´ holds for all x.
Base step: x Init = (L = {a,b,c,...})
x = a => #a(x) = 1 > 0.
x { a => #a(x) = 0 >0
Ind. step: x = zy where z is any element in L and y is any element in
L
+
.
By ind. hyp. #a(y) > 0. hence
if z = a => #a(z y) = 1 + #a(y) >0
if z { a => #a(z y) = #a(y) > 0.
Introduction
Transparency No. 1-41
More example:
- Define the set of labeled binary trees as follows:
- L: a set of labels = {a,b,c,..}
- I = L U {(, )}, I* = the set of strings over I.
- T
L
is a subset of I* 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.
- Example / counter example:
(), (a ()()), ((a) (b) ()) .
- For each tree T, let lf(T) = # of ³(³ and lb(T) =# of
labels in T; e(T) = number of empty subtrees ³()´,
which can be defined as follows:
Init: lf(()) = 1; lb(()) = 0; e(()) = 1.
closure: lf( (x LR) ) = 1+ lf(L) + lf(R) ; lb( (x L R) ) = 1 + lb(L)
+lb(R) ; e( (x L R) ) = e(L) + e(R).
Introduction
Transparency No. 1-42
More example(cont¶d)
- Use structural ind. to prove properties of trees.
- Show that for all tree T in T
L
: P(T) =
def
lf(T) = lb(T) + e(T)
holds for all tree T.
Base step[ T = () ] : lf(()) = 1, lb(())=0, e(())=1. OK.
ind. step[ T= (x L R) where 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)).
Introduction
Transparency No. 1-43
2. Basics of formal languages
What is a language ?
The meaning triangle:
minds
language
External
world
refers to
stand for
symbolize
Introduction
Transparency No. 1-44
Different levels of language analysis
- phonetic and phonological analysis (ຨຯಽᨆ)
determine how words are related to sounds that realize
them; required for speech understanding.
- morphological analysis: (݆ᒵಽᨆ)
determine how words are formed from more basic meaning
units called "morphemes". (݆⚛)
morpheme: primitive unit of meaning in a language.
eg: friendly = friend + ly; luckily = lucky + ly
- syntax analysis: (ݶᴺಽᨆ)
determine how words can be put together to form correct
sentences
determine what structure role each word plays in the
sentence
determine what phrases are subparts of what other parts.
Introduction
Transparency No. 1-45
levels of language analysis
- Semantics analysis : (ݶᗧಽᨆ)
determine what words mean and how these meanings
combine in sentence to form sentence meanings.
context independent.
- Pragmatic analysis: (ݶ↪ಽᨆ)
concern how sentences are used in different situation and
how use affects the interpretation of sentences.
- Discourse analysis,...
- World knowledge,...
- Languages (including natural and programming
languages) contains many facets, each an active
research domain of AI, linguistics, psychology,
philosophy, cognitive science and mathematics.
Introduction
Transparency No. 1-46
What are formal languages
- In the study of formal languages we care only the well-
formedness (or more abstractly the membership of), but
not the meaning of sentences, in a language.
Ex1: Our usual decimal language of positive numbers ?
Prob: Which of the following are well-formed
[representation of] numbers:
(1) 128 (2) 0023 (3) 44ac (4) 3327
Let L be the set of all well-formed [representations of ]
numbers. ==> 123, 3327 in L but 0023, 44ac not in L.
So according to the view of FL, The usual decimal language
of positive numbers (i.e., L) is just the set { x | x is a finite
sequence of digits w/t leading zeros }.
Note: FL don't care that string '134' corresponds to the
(abstract) positive number whose binary rep. is 10000000
Introduction
Transparency No. 1-47
Definition 2.1
- An alphabet L (or vocabulary; ሼᲣ෨) is a finite set.
Ex: decimal_alphabet = {0,1,2,3,4,5,6,7,8,9}
binary_digit = {0,1}; Hexidecimal-alphabet = {0,..,9,A,..,F}
alphabet-of-English-sentences = {a, word, good, luckily,...}
alphabet-of-English-words = {a,...,z,A,...,Z}
- Elements of an alphabet are called letters or symbols
- A string (or word or sentence) over L is a finite sequence of
elements of L.
Ex: if L = {a,b} then 'aabaa' is a string over L of length 5.
Note: A string x = x
0
x
1
« x
n-1
of length n is in fact viewed as a function
x: [0..n) L such that x(k) = x
k
for k in [0,n).
- The length of a string x, denoted |x|, is the number of symbols
in x. ex: |abbaa| = 5.
- there is a unique string of length 0, called the null string or
empty string, and is denoted by s (or ì)
Introduction
Transparency No. 1-48
Definition 2.1 (cont'd)
- L* =
def
the set of all strings over L.
Ex: {a,b}* = {s,a,b,aa,ab,ba,bb,aaa,...}
{a}* = {s,a,aa,aaa,aaaa,...} = {a
n
| n > 0}.
{}* = ? ( {} or {s} or s ?)
- Note the difference b/t sets and strings:
{a,b} = {b,a} but ab { ba.
{a,a,b} = {a,b} but aab { ab
- So what's a (formal) language ?
- A language over 7 is a set of strings over 7 (i.e., a
subset of 7*). Ex: let L = {0,...,9} then all the followings
are languages over L.
1. {s} 2. {} 3. {0,...,9} = L 4. {x | x L* and has no leading
0s} 5. L
5
= {x | |x| = 5} 6. L* = {x | |x| is finite }
Introduction
Transparency No. 1-49
Examples of practical formal languages
Ex: Let A be the set of all ASCII codes.
a C program is simply a finite string over A satisfying all
syntax rules of C.
C-language =
def
{ x | x is a well-formed C program over A }.
PASCAL-language = {x | x is a well-formed PASCAL
program over A }.
Similarly, let ENG-DIC = The set of all English lexicons
= { John, Mary, is, are, a, an, good, bad, boys, girl,..}
an English sentence is simply a string over ENG-DIC
==> English =
def
{x | x is a legal English sentence over END-
DIC} ==>
1.John is a good boy . English.
2. |John is a good boy . | = ?
Introduction
Transparency No. 1-50
issues about formal languages
- Why need formal languages?
for specification (specifying programs, meanings etc.)
i.e., basic tools for communications b/t people and
machines.
although FL does not provide all needed theoretical
framework for subsequent (semantic processing...)
processing, it indeed provides a necessary start, w/t which
subsequent processing would be impossible -- first level of
abstraction.
Many basic problems [about computation] can be
investigated at this level.
- How to specify(or represent) a language ?
Notes: All useful natural and programming languages
contains infinite number of strings (or programs and
sentences)
Introduction
Transparency No. 1-51
How to specify a language
principles: 1. must be precise and no ambiguity among
users of the language: 2. efficient for machine processing
tools:
1. traditional mathematical notations:
A = {x | |x| < 3 and x {a,b}} = {e,a,b,aa,ab,ba,bb}
problem: in general not machine understandable.
2. via programs (or machines) :
P: a program; L(P) =
def
{x | P return 'ok' on input string x}
precise, no ambiguity, machine understandable.
hard to understand for human users !!
3. via grammars: (easy for human to understand)
Ex: noun := book | boy | jirl | John | Mary
art := a | an | the ; prep := on | under | of | ...
adj := good | bad | smart | ...
NP := noun | art noun | NP PP | ...
PP := prep NP ==> 'the man on the bridge' PP.
Introduction
Transparency No. 1-52
Non-enumerability of languages
- Recall that a set is denumerable if it is countably
infinite. (i.e., A set T is denumerable if there is a 1-1
and onto mapping b/t T and {0,1,...})
- Exercises: If L is finite and nonempty, then
1. L* is denumerable (i.e., |L*| = |N| )
2. 2
L*
(ie., the set of all languages over L) is uncountable.
pf: Since |2
L*
| { |L*| = |N|, hence |2
L*
| is not countable

Introduction
Transparency No. 1-53
Operations on strings
- string concatenations:
x,y: two strings ==> x·y is a new string with y appended to
the tail of x. i.e., x·y is the function :
z : [0, len(x)+len(y) ) L such that
z(n) = x(n) for 0 · n < len(x) and
z(len(x)+n) = y(n) for 0 · n < len(y).
Some properties of · :
1. ASSOC: (xy)z = x(yz) ; 2. Identity: sx = xs = x.
3. |xy| = |x| + |y|.
- conventions and abbreviations:
L: for alphabet ; a,b,c: for symbols;
x,y,z: for strings; A,B,C: for languages;
a
5
for aaaaa; a
1
= a ; a
0
= s.
#a(x) =
def
number of a's in x. ==> #a(aabbcca) = 3.
Introduction
Transparency No. 1-54
Operations on languages (i.e, string sets)
1. usual set operations:
Union: A U B = {x | x A or x B }
Ex: {a,ab} U { ab, aab} = {a,ab,aab}
intersection: A · B = {x | x A and x B }
complements in L*: ~A =
def
L* - A = { x | x not A}
ex: ~{x | |x| is even } = {x | |x| is odd }.
2. Set concatenations:
A·B =
def
{xy | x A and y B }.
Ex: {b,ba} {a,ab} = {ba,bab,baa,baab}.
3. Powers of A: A
n
( n > 0) is defined inductively:
1. A
0
= { s}; A
n+1
= A·A
n
= A·A·...·A. ----- n A's
Introduction
Transparency No. 1-55
Operations on languages (cont'd)
Ex: Let A = {ab,abb}. Then
1. A
0
= ? 2. A
1
= ? 3. A
2
= ? 4. |A
4
|=?
5. Hence {a,b,c}
n
= {x {a,b,c}* | |x| = n } and
A
n
= { x
1
x
2
...x
n
| x
1
,...,x
n
A }
5. Asterate (or star) A* of A is the union of all finite
powers of A:
A* =
def
U
k > 0
A
K
= A
0
U A UA
2
U A
3
U ...
= {x
1
x
2
...x
n
| n > 0 and x
i
A for 1 > i > n }
notes:
1. n can be 0 ==> s A*. ==> s {}*.
2. If A = L ==> A* = L* = the set of all finite strings
over L.
Introduction
Transparency No. 1-56
Properties of languages operations
6. A
+
=
def
the set of all nonzero powers of A
=
def
U
k \ge 1
A
k
= A U A
2
U A
3
U ... = A A*.
Properties of languages operations
1. associative: U, · , · :
AU(BUC) = (AUB)UC; A·(B·C) = (A·B)·C;
A(BC) = (AB)C
2. commutative : U,·:
3. Identities:
1. A U {} = {}UA = A; 2. A· L* = L*· A = A;
3. {s}A = A{s} = A.
4. Annihilator: A{} = {}A = {}.
Introduction
Transparency No. 1-57
Properties of languages operations (cont'd)
5. Distribution laws:
AU(B·C) = (AUB)· (AUC) ; A·(BUC) = (A·B)U(A·C)
A(BUC) = AB U AC ; A(B·C) = AB · AC (x)
Ex: Let A = {a,ab}, B = {b}, C = {s}
==> A(B· C) = ? AB = ? AC = ?
==> A(B·C) AB· AC.
Exercise: show that A(BUC) = AB UAC.
6. De Morgan Laws: ~(AUB) = ? ~(A·B) = ?
7. Properties about A*:
1. A*A* = A* ; 2. A** = A*; 3. A* = {s}UAA*
4. AA* = A*A = A
+
. 5. {}* = {s}.
Exercises: Prove 1~5. (hint: direct from the definition of A*)
Introduction
Transparency No. 1-58
A language for specifying languages
- In the term: 'a language for specifying languages',
the former language is called a metalanguage while
the later languages are called target languages.
So in the C language reference manual, the BNF form is a
meta language and C itself is the target language.
- L: an alphabet ; A = L U { +, *, e, ©, ·, ), ( };
- E = A U {~, ·}
- 1. The set of all regular expressions is a subset of A*
which can be defined inductively as follows:
Basis: 1. e, © are regular expressions
2. Every symbol a in L is a regular expression.
Induction: If e and 0 are regular expressions then so are
(e+0), (e·0), e*.
Introduction
Transparency No. 1-59
Regular expressions
Examples:
legal reg. expr. : e, (a+b)*, ((a +(b·c))+(e·b)*)
illegal reg. expr: (ab), a + b, ((a + L)) + d, where d ב L.
illegal formally but legal if treated as abbreviations:
ab --> (a·b) ; a+b --> (a+b);
a + bc* --> (a + (b·c*))
- Extended regular expressions (EREGs):
- EREGs are strings over E and can be defined
inductively as follows:
Basis: 1. e, © are EREGs
2. Every symbol a in L is an EREG.
Induction: If e and 0 are EREGs then so are
(e+0), (e·0), e*, (~e), (e·0), (e-0)
Introduction
Transparency No. 1-60
Languages represented by regular expressions
- [Extended] regular expressions provides a finite way
to specify infinite languages.
- Definition: for each EREG (and hence also REG) e,
the language (over L) specified (or denoted or
represented) by e, written L(e), is defined inductively
as follows:
Basis: L(e) = {s}; L(©) = {};
for each a א L, L(a) = {a}.
Induction: assume L(e) and L(0) have been defined for
EREG e and 0. Then
L(e+0) = L(e) U L(0); L(e0) = L(e) L(0); L(e*) = L(e)*;
L(~e) = L* - L(e); L(e - 0) = L(e) - L(0); L(e ·0) = L(e) · L(0).
- Definition: a language A is said to be regular if A = L(e) for
some regular expression e.
Introduction
Transparency No. 1-61
Examples:
- Let L = {a,b}. Then
L( a(a+b)*) = {x | x begins with a } = {a,aa,ab,aaa,aab,aba,...}
L(~(a(a+b)*)) = {x | x does not begin with a}
= {x | x begins with b } U {s} = L( e + b(a+b)*).
- Regular expressions and Extended regular
expressions give us finite ways to specify infinite
languages. But the following questions need to be
answered before we can be satisfied with such tools.
1. Are EREG or REGs already adequate ?
(i.e, For every A ك L*, there is an expression e s.t., L(e) =
A ? ) ==> ans: _____.
2. For every expression e, is there any [fast] machine that
can determine if x א L(e) for any input string x ?
Ans: _______
Introduction
Transparency No. 1-62
IS EREG more expressive than REG ?
- L1, L2: two [meta] languages;
we say L1 is at least as expressive as L2 if L(L2) =
def
{A |
there is an expression a in L2 s.t. A = L(a) } is a subset of
L(L1).
L1 is said to be equivalent to L2 in expressive power iff
both are at least as expressive as the other.
- Problem:
EREG is at least as expressive as REG since L(REG) is a
subset of L(EREG) (why?)
But does the converse hold ? (i.e, Is it true that for each
EREG e there is a REG 0 s.t., L(e) = L(0) ?
ans: _____.

Introduction

Course outlines

y Introduction:
Mathematical preliminaries:
sets, relations, functions,sequences, graphs, trees, proof by induction, definition by induction (recursion).

Basics of formal languages:
alphabet, word, sentence, concatenation ,union, iteration [= Kleene star], language, infinity of languages, finite representations of languages

y PART I: Finite Automata and Regular Sets
DFA,NFA,regular expressions and their equivalence limitation of FAs; Closure properties of FAs, Optimization of FAs

Transparency No. 1-2

Introduction

course outline (cont'd)

y PART II: Pushdown Automata and Context Free Languages
CFGs and CFLs; normal forms of CFG Limitation of CFG; PDAs and their variations, closure properties of CFLs Equivalence of pda and CFGs; deterministic PDAs parsing (Early or CYK's algorithms)

y PART III: Turing Machines and Effective Computability
Turing machine [& its variations] and Equivalence models Universal TMs Decidable and undecidable problems (Recursive sets and recursively enumerable sets) Problems reductions ; Some undecidable problems 1-3 Transparency No.

TMs. 1-4 .. sets. machines. LA (linear bounded automata). problems. CSGs. PDAs. Programs.] y study various representations of languages in finite ways via grammars: RGs.. general PSGs Transparency No.Introduction Goals of the course y understand the foundation of computation y make precise the meaning of the following terms: [formal] languages. RAMs.. computations computable {languages. [register machines. CFGs. functions} y understand various models of machines and their relative power : FA. problems.

1-1 .formal Language Chapter 1 Introduction include Lecture 1 and 2 Transparency No.

1-6 .Introduction Mathematical preliminaries (reviews) y y y y y sets functions relations induction Recursive definitions Transparency No.

y Definition 1. we say S contains x.4.3. notation: x S vs x ‘S y Ex: In 1. A set is a collection of objects.3 5 is a set.Introduction Sets y Basic structure upon which all other (discrete and continuous ) structures are built. an object is anything of interest. y a set is a collection of objects. 1-7 .2. maybe itself a set.5. the collection of 1. If x is a memebr of a set S. The objects is a set are called the elements or members of the set. 7 Transparency No.

. List all its member.Introduction Set description y How to describe a set:? 1. 1-8 . Set builder notation: P(x) : a property (or a statement or a proposition) about objects. the set of all positive odd integer >10 = ? The set all decimal digits = ? the set of all upper case English letters = ? The set of all nonnegative integers =? 2. P(x) = ³ x > 0 and x is odd´ then {x | P(x) } is the set of objects satisfying property P.g. P(3) is true => 3  {x | P(x)} P(2) is false => 2 ‘ {x | P(x)} 8 Transparency No. e.

y Exercise : Show that: 1. [subset] A  B iff all elements of A are elements of B. For all set A (ˆ% 2. (A  B /\ B  A) <=> (A = B) 3. Def 3.5.3.3} = {1.5} = {1. A ˆ!"%!ˆ 9 Transparency No. 5} y Null set ={} = ˆ =def the collection of no objects.1.Introduction Set predicates Definition 2. Two sets S1. y Def 3¶¶: A Ž B =def A  B /\ A { B.3. 1-9 . Def 3¶: [empty set] for-all x x ‘ˆ.3. A  B <=> for-all x (x  A => x  B)). S2 are equal iff they have the same elements S1 = S2 iff x (x S1 <=> x  S2) Ex: {1.

3. o/w it is infinite. 5. | {2i | i in N} = ? |R| = ? y Def. Two sets are of the same size (cardinality) iff there is a 1-1 & onto mapping between them.Introduction Size or cardinality of a set Def.3. 1-10 .5}| = ? |{}| = ? | the set of binary digits } | = ? |N| = ? . y Ex: |{1. |Z| = ? . A set A is finite iff |A| is a natural number . 4 | A | = the size(cardinality) of A = # of distinct elements of A. 10 Transparency No.

y By exercise 3. 11 Transparency No.5.6.. |R| = | [0. 1) | 3.. |N| { |R| y Def. Q and Z is countable. A set is countable (or enumerable) iff either |A| = n for some n in N or |A| = |N|. R is not countable. A set A is said to be denumerable iff |A| = |N|.} 2.Introduction countability of sets y Exercise: Show that 1.. 1-11 . |N| = |Z| = | Q | = {4.

n})| = ? y Order of elements in a set are indistinguishable. called the poser set of A and is denoted as P(A) or 2A.1) --> ordered n-tuples 12 Transparency No. 1-12 . then the collection of all subsets of A is also a set..1.4...2}) = ? P({}) = ? |P({1.. But sometimes we need to distinguish between (1. y Ex: P({0.3.Introduction The power set Def 6.4) and (3.2. If A is a set.

a contradiction too.e. Hence 2. there is no bijection b/t A and 2A. Note: Many proofs of impossibility results about computations used arguments similar to this.e.. (2) assume |A| = |2A|. a contradiction if no (i.. i. So the assumption is false. y ‘ D) ==> y  f(y) =D. f(y) = D. Let D = {x in A | x ‘ f(x) }. ==> 1.. y in A s.e. i. Pf: (1) The case that A is finite is trivial since |2A| = 2|A| > |A| and there is no bijection b/t two finite sets with different sizes. y  D) ==> y ‘ f(y) = D. there is a bijection f: A -> 2A.e.t. D is a subset of A. Transparency No. |A| {|2A|.. 1-13 . Problem: Is y  D ? if yes (i.Introduction More about cardinality Theorem: for any set A.

Ex: A = {1..Introduction Cartesian Products Def.am) = (b1.n ai = bi... 2. Any orderd 2-tuple is called a pair..2}.......4. 1-14 . B x A = ? 3.an)´ is a new object. A x {} = ? ... A x B x C = ? 14 Transparency No.. 7 [n-tuple] If a1.b. called an (ordered) n-tuple [ with ai as the ith elements.. then ³(a1.b) | a in A /\ b in B } A1 x A2 x .x An =def {(a1..a2.. C = {0..bn) iff m = n and for i = 1.an) | ai in Ai }.. Def. 8: [Cartesian product] A x B =def {(a.c} .. A x B = ? ... B = {a..a2... (a1.an (n > 0) are n objects..a2.b2.1} 1.

15 Transparency No. AŠ B = {x | x in A or x in B } 2. ~ A = U . A‰ B = {x | x in A and x in B } 3. intersection. 1-15 . 1.B = {x | x in A but x not in B } 4.Introduction Set operations y union. If A ‰ B = {} => call A and B disjoint. difference . A .A 5. y Definition. complement.

~~A = A A?B=B?A A ? (B ? C) = (A ? B ) ? C A ? (B ? C) = ? ~(A ? B) = ~A ? ~B Note: Any set of objects satisfying all the above laws is called a Boolean algebra.Introduction Set identites y y y y y y y y Identity laws: Domination law: Idempotent law: complementation: commutative : Associative: Distributive: DeMoregan laws: A??=A U ? ? = U. 1-16 . 16 Transparency No. {} ?? = {} A?A=A.

Introduction Prove set equality 1. show (1) by using set builder and logical equivalence. 4. show ~(AŠ (B‰ C)) = (~C ‰~B) Š~A by set identities. Show distributive law by using membership table. 3. ~A ‰~B ~(A Š B) y pf: (By definition) Let x be any element in ~(A Š B)  2. ~(A Š B) ~A ‰~B 2. Show that ~(A Š B) = ~A ‰~B by show that 1. 17 Transparency No. 1-17 .

18 Transparency No. 1 [functions] A. (x.t. range(f) = {y | x s. 3. y) in AxB s. B: two sets 1. If f:A -> B ==> 1. we write f(x) = y. 2.Introduction Functions y Def. a function f from A to B is a set of pairs (x. 1-18 . B: the codomain of f if f(a)=b => 2. preimage(f) = {x | $ y s. b is the image of a.y) in f. f is total iff f-1(B) = A.t. 2. f(x) = y } = f-1(B). if (x. 5. Def.t. A: the domain of f. a is the preimage of b 4. f :A ->B means f is a function from A to B. f(x) = y} = f(A). 6.y) in f..t. for each x in A there is at most one y in B s. 3.

t. f(S) =def {y | x in S s. bijection] f: A -> B. a surjection) iff f(A) = B f is 1-1 & onto <=> f is bijective (a bijection. 1-19 . T: a subset of B 1. f(x) = y } 2. injection. S: a subset of A.Introduction Types of functions y Def 4. 1-1 correspondence) 19 Transparency No. surjection. f(x) = y } Def. f: A x B. [1-1.t. onto. f-1(T) =def {x | y in T s. f is 1-1 (an injection) iff f(x)=(fy) => x = y. f is onto (surjective.

.an> | ai  Ai }.2.. B= {4..2}.y} ==> |A1xA2xA3| = ? 2..b}. A1= {}.a2. B: two sets AxB (Cartesian Product of A and B) is the set of all ordered pairs {<a.A2.6} => AxB = ? y A1.b> | a  A and b  B }.. 1-20 .An (n > 0): n sets A1xA2x.3}.xAn = {<a1.A3={x. A2={a.5. Example: 1.Introduction Relations y A... A1={1...b} => A1xA2 = ? Transparency No.. Examples: A= {1.A2={a.

3.Introduction Binary relations y Binary relation: A.B: two sets A binary relation R between A and B is any subset of AxB.5.2.2. <5.4>.4} R4 = {<1.5>.6> } Transparency No.3}.2>. B ={4. <1. Example: If A={1. then which of the following is a binary relation between A and B ? R1 = {<1. <3.4>. <2.6> } R2 = {} R3 = {1.6}. 1-21 .

Introduction

Terminology about binary relations

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

y If A = B, then R is simply called a relation over(on) A. y An n-tuple relation R among A1,A2,...,An is any subset of A1xA2...xAn, n is called the arity of R y If A1=A2=...=An=A => R is called an n-tuple relation (on A),.
Transparency No. 1-22

Introduction

Operations on relations (and functions)

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

y Identity relation: IA = {<a,a> | a in A } y Converse relation: R-1 = {<b,a> | <a,b> in R } y f:A -> B; g: B->C: two functions, then g·f:A->C defined by g·f(x) = g(f(x)). y 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. 1-23

Introduction

Properties of binary relations

y 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 => not 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. Graph realization of a binary relation and its properties. x y s s
Transparency No. 1-24

x y

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

asymmetric or antisymmetric ? transitive ? y The relation " on the set of natural numbers N. (eg. y The ANCESTOR relation on a family.y)  ANCESTOR if x is an ancestor of y. 2 | 10.y)  BROTHER iff x is y¶s brother. y The divide | relation on integers N ? x | y iff x divides y. What properties does e satisfy ? ref. What properties does BROTHER(ANCESTOR) have? Transparency No.Introduction Examples y The relation e on the set of natural numbers N. but not 3 | 10) What properties do " and | satisfy ? y The BROTHER relation on males (or on all people) (x. (x. irref. 1-25 . or neither ? symmetric.

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

e. 3. either xey or yex) . So by antisym.. y be least elements of X. xe y and ye x. x eb) for all x in X. Transparency No. X: a subset of S. y in X. 1-27 . 1. X ia a chain iff (X. is unigue for any subset X of a poset (S. b in X is the greatest (or called maxmum or largest) element of X iff X e b for all x in X. 4. if existing. for all x.R) is a linear order(. i. b in X is the least (or called minimum) element of X iff b ex for all x in X. e): a poset.. of e. b in S is a lower bound (resp.Introduction Properties of ordered set y (S. y Least element and greatest element.. upper bound) of X iff b ex (resp. Note: b may or may not belong to X. Then. x = y. e ) pf: let x. 2.

s. 1-28 .. b e x => x=b. (b < x)..e. Transparency No.t. x eb => x =b. Maximal and minimal are not unique in general. b in X is minimal in X iff there is no element less than it.Introduction Properties of oredered sets y (S.´ y Note: 1. s.´ 6.e.Every maximum element is maximal. i. 5. X: a nonempty subset of S. there is no x in X. or ³for all x.. (x < b). i. b in X is a maximal element of X iff there is no element greater then it. or ³for all x. there is no x in X.. but not the converse in general. e) : a poset. 2.t.

then (S. e is said to be a well-ordering( ) iff every nonempty subset of S has a least element.t..e) : a poset ( )... ye x and y = x) if eis well-founded => (S.Introduction well-founded set and minimum conditions y (S.e) is called a well-founded set..e) is said to satisfy the minimal condition iff every nonempty subset of S has a minimal element.. Note: x > y means y < x (i.. e ): a total ordered set ( ). 2. Transparency No. there is no infinite sequence x1. e is said to be well-founded ( ) iff there is no infinite descending sequence.x2. 1-29 .. If eis well ordered.x3. (S. (i.e) is called a well-ordered set.e. )...e. x1 > x2 > x3 >. y (S. s.

|) and (R. 1.u ).Introduction Examples of ordered sets y Among the relations (N. (N. e). e). 1-30 . Which are well-ordered ? Transparency No. Which are well-founded ? 2. (Z. (N. (Z. |). (Z.e ).u).

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

p.Introduction Variants of Inductions y Mathematical Induction: To prove a property P(n) holds for all natural number n  N. p(n) => p(n+1) --.(base step) and (2) For all n  N. n P(0)/\. it suffices to show that (1) P(0) holds --.(induction step) P(n) in (2) is called induction hypothesis (h..) P(0).p(n-1) => P(n) -------------------------------------------MI2 n P(n) Transparency No..  n P(n) => P(n+1) -------------------------------------------MI1  n P(n) P(0). 1-32 .

hyp. (2) implies (1)] (for all y in S y < x => P(y)) in (2) is called the ind. it suffices to show (1) P(xmin) holds where xmin is the least element of S.e ) a well-ordered set.WI x P(x) Transparency No. P(x): a property about S. --.(base step) (2) for all x in S. of (2). To show that P(x) holds for all x in S. if (for all y in S y < x => P(y)) => p(x) ---(ind. step) (1) is a special case of (2) [i. y [ ( x x< y =>P(x) ) => P(y) --------------------------------------------------------------. y P(Xmin) .e.Introduction Well-order Induction y Well-order induction: (S.. 1-33 .

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

e. i. (for all y  S y < x => P(y)) => p(x) ---ind. Step pf: Suppose WI is incorrect. P(x) : a property about S. hyp.e) satisfying (1)(2) but the set NP = { x | x  S and P(x) is not true } is not empty. 1-35 . Then P(x) holds for all x  S. if (1) P(x) holds for all minimal elements x  S --.) p(x) holds ==> x ‘NP.Introduction Correctness of WI y (S.) ==> (ind. holds for x . Transparency No. which contradicts with (*). --> impossible! (violating (1) ) By (1). case (2): x is not minimal in S. Then there must exist (S. case (1): x is minimal in S.base step. (*) ==> Let x be any minimal element of NP. Hence the assumption that WI is incorrect is wrong. for all y  S. ==> L ‰ NP = { } (o/w x would not be minimal in NP. case(1) and (2) imply NP has no minimal element and hence is empty. P(x) holds and x ‘ NP.. y < x => p(y) is true) ==> (by (2). and (2) for all x  S. --> still impossible! x not minimal ==> L = {y | y  S /\ y < x} is not empty.e) : a well-founded set.

then [x | L] is a list. The set of strings 7+ over an alphabets 7 = {a. 3.4. then xE in 7+.. 2.. [ 5 | [2.3. 1. e. 1-36 .2. [x | L] is the result of inserting x into the head position of L. The set of lists of numbers. the set of even numbers Even = {0..b.g. closure rule: if x Even then x +2 )ven.}: Initial rule : 0 Even.c.... closure: If x is number and L is a list. Initial: [ ] is a list.2.z} Initial: if x in 7. then x in 7+. closure: If x in 7 and E in 7+.4]] = [5.Introduction Definition by induction (or recursion) y Consider the following ways of defining a set..4] y Problem:All definitions well-defined? What¶s wrong? Transparency No..3.

2...} and Ni (i >  all satisfy Def..} U { 2i+1... y Among {0.2.} is the least set among all sets.Introduction Problems about recursive definition y The above definitions are incomplete in that there are multiple sets satisfy each definition y Example: Let Ni = {0. 1-37 .2.4.}.4.6....6.. Transparency No. . {0. Then {0.4...4. which one is our intended set ? y How to overcome the incompleteness ? y Relationship between {0.} and Ni (i > 0) .} is equal to the intersection of all sets.... 2i+3.} and the collection of sets satisfying the definitions? {0.. Every other set contains element which is not grounded...6.2.2.4. 1.2...4..

and sometimes even totally omitted if it is understood in mind. is necessary. Transparency No. y we define a subset ( of ..2 ( is the intersection of all subsets of W with property 1...tn) 3. it is usually replaced by an adv.. 3. Initialization: Every element of Init is an element of (.tn are members of (.Introduction General form of inductively defining a set (or domain) y . (or simply Init  D) 2.. ³inductively´ or ³recursively´ before ³define´... as follows: 1.n->.: a set... 3. 3. 1-38 .3 Only elements obtainable by a finite number of applications of rules 1 and 2 are elements of (. Init: a subset of .1 ( is the least subset of W with the above two properties. F: a set of functions on . y Note: Although phrase 3. in F and t1. then so are f(t1. plus one of the following 3 phrases. closure: If f:.2.

.Introduction Define functions on recursively defined domains y Consider the following function: #a : 7+ N with #a(x) = number of a¶s in string x.. y Such kind of definitions are well defined.. 1-39 . #a(x) = 0 if x { a.tn in (= 7+. y Now we can define #a as follows: Initial: specify the value #a(x) of x for each x in Init = 7.. closure: specify the value #a(f(t1..tn)) of element f(t1.. ==> for any y in 7+ and z in 7: #a(zy) = 1 + #a(y) if z = a and #a(zy) = #a(y) if z {a.. ==> #a(a) = 1 . Transparency No... why ? There is exactly one way to form each element of the domain.tn) for each f in F and t1....

.. hence if z = a => #a(z y) = 1 + #a(y) u0 if z {a => #a(z y) = #a(y) u 0. x {a => #a(x) = 0 u0 Ind.tn in (. Transparency No.. Base step: x  Init = (7= {a.. it suffices to show Base step: P(x) holds for all x in Init.. step: x = zy where z is any element in 7and y is any element in 7 . Ind..}) x = a => #a(x) = 1 u 0..tn)) for all f in F.. #a(y) u 0. By ind. step: P(t1). y To show that P(x) holds for all x in (.. 1-40 .c... y Example: show P(x) |³#a(x) u 0´ holds for all x. hyp..P(tn) => P(f(t1. and for all t1...b..Introduction Structural induction y (: an inductively defined domain P(x): a property on (.

y Example / counter example: (). lb( (x L R) ) = 1 + lb(L) +lb(R) . then (x L R) is a tree.. )}. closure: if x is a label. let lf(T) = # of ³(³ and lb(T) =# of labels in T. which can be defined as follows: Init: lf(()) = 1. e(()) = 1. T7 is a subset of +* defined inductively as follows: Init: () is a tree. lb(()) = 0. e( (x L R) ) = e(L) + e(R).b. y For each tree T. (a ()()). ((a) (b) ()) .c.Introduction More example: y y y y Define the set of labeled binary trees as follows: 7: a set of labels = {a. +* = the set of strings over +. e(T) = number of empty subtrees ³()´. and L and R are trees. closure: lf( (x LR) ) = 1+ lf(L) + lf(R) . Transparency No.. 1-41 .} + = 7 U {(.

lb(())=0.:) lf(L) = lb(L) + e(L) and lf(R) = lb(R) + e(R ). ind. OK. step[ T= (x L R) where x: any label. R: any trees] : assume (ind.Introduction More example(cont¶d) y Use structural ind. y Show that for all tree T in T7 : P(T) =def lf(T) = lb(T) + e(T) holds for all tree T. 1-42 . to prove properties of trees. 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)). Transparency No. L. Base step[ T = () ] : lf(()) = 1.hyp. e(())=1.

1-43 . Basics of formal languages What is a language ? minds symbolize language refers to External world stand for The meaning triangle: Transparency No.Introduction 2.

luckily = lucky + ly y syntax analysis: ( ) determine how words can be put together to form correct sentences determine what structure role each word plays in the sentence determine what phrases are subparts of what other parts. required for speech understanding. 1-44 . determine how words are formed from more basic meaning units called "morphemes". Transparency No. ( ) morpheme: primitive unit of meaning in a language.Introduction Different levels of language analysis y phonetic and phonological analysis ( y morphological analysis: ( ) ) determine how words are related to sounds that realize them. eg: friendly = friend + ly.

. 1-45 ... linguistics. y World knowledge.. psychology... y Discourse analysis. y Pragmatic analysis: ( ) concern how sentences are used in different situation and how use affects the interpretation of sentences.Introduction levels of language analysis y Semantics analysis : ( ) determine what words mean and how these meanings combine in sentence to form sentence meanings. philosophy. each an active research domain of AI. context independent. Transparency No. cognitive science and mathematics. y Languages (including natural and programming languages) contains many facets.

Note: FL don't care that string '134' corresponds to the (abstract) positive number whose binary rep. is 10000000 Transparency No. 1-46 . in a language. The usual decimal language of positive numbers (i. but not the meaning of sentences. 44ac not in L. ==> 123. Ex1: Our usual decimal language of positive numbers ? Prob: Which of the following are well-formed [representation of] numbers: (1) 128 (2) 0023 (3) 44ac (4) 3327 Let L be the set of all well-formed [representations of ] numbers.e. 3327 in L but 0023. L) is just the set { x | x is a finite sequence of digits w/t leading zeros }. So according to the view of FL.Introduction What are formal languages y In the study of formal languages we care only the wellformedness (or more abstractly the membership of)..

called the null string or empty string. ) is a finite set...1 y An alphabet 7 (or vocabulary..9} binary_digit = {0......9.Z} y Elements of an alphabet are called letters or symbols y A string (or word or sentence) over 7 is a finite sequence of elements of 7. and is denoted by I (or P) Transparency No. 1-47 .5. denoted |x|. Hexidecimal-alphabet = {0. y there is a unique string of length 0..3.n)..8.4... luckily..A.7.1}.F} alphabet-of-English-sentences = {a. good.b} then 'aabaa' is a string over 7 of length 5. word. y The length of a string x. Ex: if 7 = {a.} alphabet-of-English-words = {a. ex: |abbaa| = 5. Note: A string x = x0 x1 « xn-1 of length n is in fact viewed as a function x: [0..A.Introduction Definition 2. Ex: decimal_alphabet = {0..2.n) 7 such that x(k) = xk for k in [0.1. is the number of symbols in x.6...z..

a subset of 7*).aa.ab..Introduction Definition 2.bb.a.} {a}* = {I..b} = {a. {}* = ? ( {} or {I} or I ?) y Note the difference b/t sets and strings: {a.b. {x | x  7* and has no leading 0s} 5. Ex: let 7 = {0.. 7* = {x | |x| is finite } Transparency No..a} but ab { ba..9} = 7 4.aa..aaa.a.a. 75 = {x | |x| = 5} 6. {} 3. {I} 2.... 1-48 . {0.e. 1...b} but aab { ab y So what's a (formal) language ? y A language over 7 is a set of strings over 7 (i.} = {an | n u 0}.b}* = {I.9} then all the followings are languages over 7..aaa.b} = {b.aaaa.. {a..ba.1 (cont'd) y 7* =def the set of all strings over 7. Ex: {a..

bad. a. Similarly.} an English sentence is simply a string over ENG-DIC ==> English =def {x | x is a legal English sentence over ENDDIC} ==> 1. a C program is simply a finite string over ( satisfying all syntax rules of C. 2. girl. | = ? Transparency No. are. let ENG-DIC = The set of all English lexicons = { John. an. is.. boys. C-language =def { x | x is a well-formed C program over ( }.. 1-49 . |John is a good boy . Mary.  English. good.Introduction Examples of practical formal languages Ex: Let ( be the set of all ASCII codes. PASCAL-language = {x | x is a well-formed PASCAL program over ( }.John is a good boy .

w/t which subsequent processing would be impossible -.) processing.. y How to specify(or represent) a language ? Notes: All useful natural and programming languages contains infinite number of strings (or programs and sentences) Transparency No.) i.Introduction issues about formal languages y Why need formal languages? for specification (specifying programs.e. meanings etc. basic tools for communications b/t people and machines. Many basic problems [about computation] can be investigated at this level. although FL does not provide all needed theoretical framework for subsequent (semantic processing... 1-50 . it indeed provides a necessary start.first level of abstraction.

Introduction How to specify a language principles: 1. L(P) =def {x | P return 'ok' on input string x} precise. prep := on | under | of | . no ambiguity..b.. PP := prep NP ==> 'the man on the bridge'  PP....bb} problem: in general not machine understandable. adj := good | bad | smart | . via programs (or machines) : P: a program. via grammars: (easy for human to understand) Ex: noun := book | boy | jirl | John | Mary art := a | an | the .ba.b}} = {e. must be precise and no ambiguity among users of the language: 2. 2. 1-51 . Transparency No. NP := noun | art noun | NP PP | . hard to understand for human users !! 3.aa. efficient for machine processing tools: 1. machine understandable..a.ab. traditional mathematical notations: A = {x | |x| < 3 and x  {a.

(i. A set T is denumerable if there is a 1-1 and onto mapping b/t T and {0.Introduction Non-enumerability of languages y Recall that a set is denumerable if it is countably infinite... 27* (ie.. |7*| = |N| ) 2. then 1.e...e. hence |27*| is not countable Transparency No. 7* is denumerable (i. pf: Since |27*| { |7*| = |N|.}) y Exercises: If 7 is finite and nonempty.1. 1-52 . the set of all languages over 7) is uncountable..

len(x)+len(y) ) 7such that z(n) = x(n) for 0 e n < len(x) and z(len(x)+n) = y(n) for 0 e n < len(y). A. Transparency No.e.y: two strings ==> x·y is a new string with y appended to the tail of x. ASSOC: (xy)z = x(yz) . a0 = I. a. 3.. |xy| = |x| + |y|. Some properties of · : 1.B.C: for languages.b. 1-53 . x. a1 = a . #a(x) =def number of a's in x. a5 for aaaaa.c: for symbols.Introduction Operations on strings y string concatenations: x. i. x·y is the function : z : [0. ==> #a(aabbcca) = 3.y. Identity: Ix = xI = x. y conventions and abbreviations: 7: for alphabet .z: for strings. 2.

1-54 .Introduction Operations on languages (i.. ----.e.ab} U { ab. Powers of A: An ( n u 0) is defined inductively: 1.baa. Set concatenations: A·B =def {xy | x  A and y  B }.baab}. 3. string sets) 1. An+1 = A·An = A·A·..ab.ba} {a.·A. aab} = {a. A0 = { I}.A = { x | x not  A} ex: ~{x | |x| is even } = {x | |x| is odd }.ab} = {ba.bab. usual set operations: Union: A U B = {x | x  A or x  B } Ex: {a.n A's Transparency No.aab} intersection: A ‰ B = {x | x  A and x  B } complements in 7*: ~A =def 7* . 2. Ex: {b.

A0 = ? 2.. n can be 0 ==> I  A*. 2.b.abb}.xn | n u 0 and xi  A for 1 u i u n } notes: 1.. If A = 7 ==> A* = 7* = the set of all finite strings over 7.xn  A } 5... = {x1x2.xn | x1. 1-55 ..c}* | |x| = n } and An = { x1x2. A2 = ? 4... A1 = ? 3. |A4|=? 5. ==> I  {}*.b.c}n = {x  {a. Hence {a.Introduction Operations on languages (cont'd) Ex: Let A = {ab. Asterate (or star) A* of A is the union of all finite powers of A: A* =def Uk u 0 AK = A0 U A UA2 U A3 U .... Transparency No. Then 1.

Introduction Properties of languages operations 6. Annihilator: A{} = {}A = {}. A U {} = {}UA = A.. 1-56 . = A A*. A+ =def the set of all nonzero powers of A =def Uk \ge 1 Ak = A U A2 U A3U . 3.‰: 3. Properties of languages operations 1. {I}A = A{I} = A. ‰ . commutative : U. 2. Identities: 1. Transparency No. 4. A‰ 7* = 7*‰ A = A.. A‰(B‰C) = (A‰B)‰C. · : AU(BUC) = (AUB)UC. A(BC) = (AB)C 2. associative: U.

3. C = {I} ==> A(B‰ C) = ? AB = ? AC = ? AB‰ AC. 5. De Morgan Laws: ~(AUB) = ? ~(A‰B) = ? 7. A* = {I}UAA* 4. {}* = {I}. (hint: direct from the definition of A*) Transparency No. 6. Exercises: Prove 1~5. 1-57 . Properties about A*: 1. A*A* = A* .ab}. A‰(BUC) = (A‰B)U(A‰C) A(BUC) = AB U AC . AA* = A*A = A+. 2. B = {b}. A** = A*. A(B‰C) = AB ‰AC (x) Ex: Let A = {a.Introduction Properties of languages operations (cont'd) 5. ==> A(B‰C) Exercise: show that A(BUC) = AB UAC. Distribution laws: AU(B‰C) = (AUB)‰ (AUC) .

*. So in the C language reference manual.Introduction A language for specifying languages y In the term: 'a language for specifying languages'. ( }. the former language is called a metalanguage while the later languages are called target languages. E*. ˆare regular expressions 2. The set of all regular expressions is a subset of (* which can be defined inductively as follows: Basis: 1. the BNF form is a meta language and C itself is the target language. Every symbol a in 7 is a regular expression. y 7: an alphabet . ‰} y 1. (E·F). ). Transparency No. 1-58 . Induction: If E and F are regular expressions then so are (E+F). e. ·. eˆ. y E = ( U {~. ( = 7 U { +.

Every symbol a in 7 is an EREG. (a+b)*. Induction: If E and F are EREGs then so are (E+F). expr: (ab). expr.Introduction Regular expressions Examples: legal reg. 1-59 . where d 7. (~E). a + b. ˆare EREGs 2. E*. e. a+b --> (a+b). : e. (E·F). illegal formally but legal if treated as abbreviations: ab --> (a·b) . ((a +(b·c))+(e·b)*) illegal reg. a + bc* --> (a + (b·c*)) y Extended regular expressions (EREGs): y EREGs are strings over E and can be defined inductively as follows: Basis: 1. ((a + 7)) + d. (E-F) Transparency No. (E‰F).

F) = L(E) . L(EF) = L(E) L(F). Induction: assume L(E) and L(F) have been defined for EREG E and F. L(a) = {a}. L(~E) = 7* . 1-60 . y Definition: a language A is said to be regular if A = L(E) for some regular expression E.L(F). is defined inductively as follows: Basis: L(e) = {I}. L(E .Introduction Languages represented by regular expressions y [Extended] regular expressions provides a finite way to specify infinite languages. Transparency No. y Definition: for each EREG (and hence also REG) E. L(E*) = L(E)*.L(E). L(E ‰F) = L(E) ‰L(F). for each a 7. Then L(E+F) = L(E) U L(F). written L(E). L(ˆ) = {}. the language (over 7) specified (or denoted or represented) by E.

e. 2.b}. L(E) = A ? ) ==> ans: _____.aba... is there any [fast] machine that can determine if x L(E) for any input string x ? Ans: _______ Transparency No. Are EREG or REGs already adequate ? (i. But the following questions need to be answered before we can be satisfied with such tools.aa.Introduction Examples: y Let 7 = {a. Then L( a(a+b)*) = {x | x begins with a } = {a. 1-61 . For every expression E. y Regular expressions and Extended regular expressions give us finite ways to specify infinite languages. there is an expression E s.aaa. 1. For every A 7*.t...ab.aab.} L(~(a(a+b)*)) = {x | x does not begin with a} = {x | x begins with b } U {I} = L( e + b(a+b)*).

e. Transparency No.t. L(E) = L(F) ? ans: _____. 1-62 . L2: two [meta] languages. L1 is said to be equivalent to L2 in expressive power iff both are at least as expressive as the other.t. A = L(a) } is a subset of L(L1). we say L1 is at least as expressive as L2 if L(L2) =def {A | there is an expression a in L2 s. Is it true that for each EREG E there is a REG F s.Introduction IS EREG more expressive than REG ? y L1. y Problem: EREG is at least as expressive as REG since L(REG) is a subset of L(EREG) (why?) But does the converse hold ? (i..