CS375: Logic nd Theory of Computing Fuhu (Frnk) Cheng Deprtment of Computer Science University of Kentucky 1
Tble of Contents: Week 1: Preliminries (set lgebr, reltions, functions) (red Chpters 1-4) Weeks 3-6: Regulr Lnguges, Finite Automt (Chpter 11) Weeks 7-9: Context-Free Lnguges, Pushdown Automt (Chpters 12) Weeks 10-12: Turing Mchines (Chpter 13) 2
Tble of Contents (conti): Weeks 13-14: Propositionl Logic (Chpter 6), Predicte Logic (Chpter 7), Computtionl Logic (Chpter 9), Algebric Structures (Chpter 10) 3
lgorithm Cn mchine recognize regulr lnguge? Yes Deterministic Finite Automton (DFA) A finite digrph over n lphbet A (vertices re clled sttes). Ech stte emits one lbeled edge for ech letter of A. One stte is defined s the strt stte nd severl sttes my be finl sttes. indicted by double circles 4
Exmple. Either one is cceptble A={, b} 5
The execution of DFA for input string w A* begins t the strt stte nd follows pth whose edges conctente to w. The DFA ccepts w if the pth ends in finl stte. Otherwise the DFA rejects w. The lnguge of DFA is the set of ccepted strings. Input string: bb n empty string will enter the strt stte but the empty set will not. 6
The execution of DFA for input string w A* begins t the strt stte nd follows pth whose edges conctente to w. The DFA ccepts w if the pth ends in finl stte. Otherwise the DFA rejects w. The lnguge of DFA is the set of ccepted strings. Input string: bb n empty string will enter the strt stte but the empty set will not. 7
6. Regulr Ln guges & Finite Automt Exmple. The exmple DFA ccepts the strings The lnguge of the DFA is n m { b, bb n ϵ N, m ϵ N } 8
Exmple. The exmple DFA ccepts the strings The regulr expression of the lnguge of the DFA is ( + b)b* Why? +b (+b)b (+b)b 2 (+b)b n 9
Theorem (Kleene) The clss of regulr lnguges is exctly the sme s the clss of lnguges ccepted by DFAs. Proof. Need three lemms or by induction. ccepts ccepts { } ccepts { } 10
Theorem (Kleene) The clss of regulr lnguges is exctly the sme s the clss of lnguges ccepted by DFAs. Proof. (conti.) together with the bsis step would prove the theorem. 11
Exmple. Find DFA for ech lnguge over the lphbet {,b}. Solution: n (). (b) {Λ}. (c) { (b) n N}, which hs regulr expression (b)*. This DFA does not ccept nything, even n empty string. Why? 12
Exmple. Find DFA for the lnguge of + *b., b, b 13
Exmple. Find DFA for the lnguge of + *b. Solution: Question: Would this DFA work? is ccepted by this DFA, but 14
A DFA tht recognizes bc* + c A DFA tht recognizes bc* + bc* + c c c b b b strt strt c c c c 15
A DFA tht recognizes bc* + c A DFA tht recognizes bc* + bc* + c c,b c,b strt b c,b c, b, c strt b c b c, b, c, b, c, b, c 16
Would the following DFA recognize *bc* + c? c strt b b c c 17
A DFA tht recognizes bc* + bc* + 2 bc* + c c strt b b b c c c 18
A DFA tht recognizes *bc* + c c bc* + bc* + 2 bc* + n bc* b b b n 3 strt c c c How to mke this FA rel DFA? 19
A DFA tht recognizes *bc* + c c,b strt,b,c b b b c c c rel DFA now,b,c,b,c 20
Tble Representtion of DFA DFA over A cn be represented by trnsition function T : Sttes A Sttes, where T(i, ) is the stte reched from stte i long the edge lbeled, nd we mrk the strt nd finl sttes. Exmple: 21
Note: T cn be extended to T : Sttes A* Sttes by T(i, Λ) = i, T(i, w) = T(T(i, ), w) A, w A* Question: T(0, bb) =? T(0, bb) = T(1, b) = T(1, ) = T(2, Λ) = 2. 22 or
Exmple. Find DFA to recognize ( + b)*bb( + b)*. A solution: {bb},b {( b) bb} ny combintion of * nd (b)*,b 23
Exmple (conti). Find DFA to recognize ( + b)*bb( + b)*. A solution: {( b) bb ( b) } b b ny combintion of * nd (b)*,b 24
Nondeterministic Finite Automt (NFA) An NFA over n lphbet A is similr to DFA except tht Λ-edges re llowed, there is no requirement to emit edges from stte, nd multiple edges with the sme letter cn be emitted from stte. Exmple. The following NFA recognizes the lnguge of + *b + *b.? *b: b, b? *b: b, b? 25
Tble representtion of NFA An NFA over A cn be represented by function T : Sttes A {Λ} power(sttes), where T(i, ) is the set of sttes reched from stte i long the edge lbeled, nd we mrk the strt nd finl sttes. Exmple: 0 26
the proof is similr to Kleene s theorem Theorem (Rbin nd Scott): The clss of regulr lnguges is exctly the sme s the clss of lnguges ccepted by NFAs. Questions. Find n NFA for ech of the lnguges over {, b}. {, b, ( b) } 27 =?,b
Exmple. Find n NFA to recognize ( + b)*bb( + b)*. A solution: {bb} {( b) bb} ny combintion of * nd (b)* {( b) bb( b) } ny combintion of * nd (b)* 28
Exmple (conti). Find n NFA to recognize ( + b)*bb( + b)*. A solution: But not {( b) bb ( b) * } 29
(DFA or NFA) Algorithm: Trnsform Regulr Expression (RE) into Finite Automton (1) Plcing the RE on the edge between strt nd finl stte: (2) Apply the following rules to obtin finite utomton fter ersing ny -edges. 30
Exmple. Use the lgorithm to construct finite utomton for (b)* + b. Solution: 31
Algorithm: Trnsform Finite Automton into Regulr Expression Connect new strt stte s to the strt stte of the FA nd connect ech finl stte of the FA to new finl stte ƒ s shown in the figure. s Ʌ Given FA Ʌ f Connect to strt stte of FA Connect from ech finl stte of FA 32
If needed, combine ll multiple edges between the sme two nodes into one edge with lbel the sum of the lbels on the multiple edges. If there is no edge between two sttes, ssume there is n -edge. 33 Φ
Now eliminte ech stte k of the FA by constructing new edge (i, j) for ech pir of edges (i, k) nd (k, j) where i k nd j k. New lbel new(i, j) is defined s follows: new(i, j) = old(i, j) + old(i, k) old(k, k)* old(k, j) Exmple: A A+ BC*D 34
Think of the process of eliminting stte k s two-step procedure: i A B k D j i i A BC*D A + BC*D 35 j j Put Φ here if there ws not direct edge between i nd j originlly
Exmple. Trnsform the following NFA into regulr expression. Solution I (eliminte stte 1 first): 0 Stte 1 is lso considered stte between stte 0 nd stte 0 36 0 b 1 Stte 1 is considered stte between stte 0 nd stte f
Exmple. Trnsform the following NFA into regulr expression. Solution I (eliminte stte 1 first): new(0, f ) new(0,0) b b 0 37 0 b 1
Exmple. Trnsform the following NFA into regulr expression. Solution I (eliminte stte 1 first): new( s, ( b) ( b) 38 f )
Exmple. Trnsform the following NFA into regulr expression. Solution II (eliminte stte 0 first): 0 b 1 Stte 0 is considered stte between stte s nd stte 1 Stte 0 is lso considered stte between stte 1 nd stte 1 39 1
Exmple. Trnsform the following NFA into regulr expression. Solution II (eliminte stte 0 first): new( s,1) new(1, 1) b b 40
Exmple. Trnsform the following NFA into regulr expression. Solution II (eliminte stte 0 first): new( s, ( b ) ( b ) 41 f )
Note. The two regulr expressions obtined in the previous exmple re equl, i.e., *( b* )* = ( + b)*. Proof I. ( + b )* ( R + S )* = R* (S R* )* = [ * ( (b) * )* ] is ssocitive = * [ ( ( b ) * )* ] is ssocitive = * [ ( ( b * ) )* ] (R S )* R = R (S R )* = * [ (( b* ) )* ] is ssocitive 42 = * (b* )*
Note. The two regulr expressions obtined in the previous exmple re equl, i.e., *(b*)* = ( + b)*. Proof II. * ( b* )* = *[(( b* ) )*] is ssocitive = *[( (b*) )* ] R(SR)* = (RS)*R = *[ ( (b)* )* ] is ssocitive = [* ((b) *)* ] is ssocitive = ( + b)* R*(SR*)* = (R + S)* QED. 43
6. Regulr Lnguges & Finite ny combintions Automt of Note. The two regulr expressions obtined in the previous exmple re equl, i.e., *(b*)* = ( + b)*. Intuitive Proof. LHS = * ( b* )* = *(b*)(b*)(b*) (b*) RHS = ( + b)* = *(b)**(b)* *(b)* LHS RHS Why? *(b*)(b*)(b*) ϵ LHS = *(b)*(b)*(b)* = *(b)*(b)*(b)*(b) 0 ϵ RHS Hence, LHS RHS * nd (b)* 44
Note. The two regulr expressions obtined in the previous exmple re equl, i.e., *(b*)* = ( + b)*. Intuitive Proof (conti). LHS = * ( b* )* = *(b*)(b*)(b*) (b*) RHS = ( + b)* = *(b)**(b)* *(b)* RHS LHS Why? *(b) 2 *(b) 2 *(b) 2 ϵ RHS = *(b)(b)*(b)(b)*(b)(b) = *(b)(b*)(b)(b*)(b)(b) = *(b 0 )(b*)(b 0 )(b*)(b 0 )(b 0 ) ϵ LHS Hence, RHS LHS 45
End of Regulr Lnguge nd Finite Automt II 48