Sunteți pe pagina 1din 114

Limbaje Formale si Automate

Instructor Andrei PAUN Semestrul II 2009-2010

Departmentul de Infomrmatica Universitatea Bucuresti Bucuresti, Romania

Structura cursului: 1. Cunostinte de baza multimi, multiseturi, secvente, functii, relatii, metode si tehnici de demonstratie, alfabet, cuvinte, limbaje 2. Automate nite automate nite nedeterministe (NFA), automate nite deterministe (DFA), transformarea de la NFA la DFA, proprietati pentru limbajele acceptate de automate, lema de pompare 3. Expresii regulate echivalenta dintre expresiile regulate si automatele nite (in denirea limbajelor) 4. Gramatici independente de context (CFG) simplicare si forme normale, algoritmi de parsare, lema de pompare si alte proprietati
2

5. Automate pushdown (PDA) nondeterministic pushdown automata (NPDA), deterministic pushdown automata (DPDA), PDA vs. CFGs 6. Masini Turing (TM) diverse tipuri de TM, TM universale, decidabilitate si nedecidabilitate, complexitate de timp si spatiu

Motivare pentru curs


Programming Database AI Graphics VLSI

Compiler

Theory of Computing
(1) Putere de calcul (2) Complexitate (3) Software design (4) Circuit design .....................

I. Cunostinte de baza
1. Multimi 1) O multime este o colectie de elemente luate dintr-un univers. 2) O multime este nita daca contine un numar nit de elemente, si este innita in caz contrar. 3) Cardinalitatea unei multimi este numarul sau de elemente si se noteaza cu # sau (pentru multimea ).

Cum specicam o multime: (1) Listam toate elementele sale: {} (or ), = {2, 3, 5, 7}, = {3, 2, 2, 7, 5, 7} (2) Precizam o proprietate: { ( )} = { este numar prim}, = { este un cuvant in romana si este si palindrom}, = { este un intreg divizibil cu 3 si mai mic decat 10 } (3) Denite recursiv: Forma generala: i) Anumite elemente initiale sau de baza sunt in ii) Daca , , atunci iii) Nici un alt element nu apartine lui

Exemplu Denirea lui A: i) 2 ii) Daca , , atunci + iii) Nici un alt element nu apartine lui (4) Inchiderea la operatii Spunem ca o multime este inchisa la o operatie binara daca pentru toate , , Fie si este inchisa la . Spunem ca este o inchidere a lui la operatia daca nu exista astfel incat si este inchisa la . Forma generala (pentru multimi denite prin inchidere) este cea mai mica multime care contine anumite elemente initiale (de baza) si care este inchisa la operatia .

Exemplu este cea mai mica multime care il contine pe si este inchisa la +. Operatii cu multimi Daca se dau si doua multimi:

={

este in

sau

este in

={

este in

si

este si in

={

este in

si

nu este in

=1 } =1

={ ={

este in este in

, pentru un , 1 , 1 }

Proprietati ale operatiilor cu multimi Distributivitate ( )=( ( )=( Indempotenta = ; Involutie ( ) = Comutativitate = ; = ) )
9

)( ) )( )

Asociativitate ( )=( ( )=(

Regulile lui De Morgan ( ) = ( ) = Multimea submultimilor Multimea tuturor submultimilor unei multimi (power set of ) se noteaza cu 2 . Exemplu: = {2, 3, 5} 2 = {, {2}, {3}, {5}, {2, 3}, {2, 5}, {3, 5}, {2, 3, 5}} Cateva multimi speciale: : multimea vida; : multimea intregilor; : multimea intregilor pozitivi; 0 : multimea intregilor care nu sunt negativi; : multimea numerelor reale. ...............

10

2. Multiseturi Un multiset este o colectie de elemente dintr-un univers oarecare, colectie in care repetitiile nu sunt ignorate. 3. Secvente O secventa de elemente dintr-un univers oarecare este o lista de elemente care sunt ordonate (ecare element are o pozitie).

11

4. Functii Denitie Daca se dau doua multimi si , o la asociaza cu functie (partiala) de la ecare din (cel mult) un element din . Notatii: functie : asocierea ( ) = nedenita ( ) = Functii speciale: functia identitate: : si ( ) = pentru toti

pentru :

Functia caracteristica a lui : { , } ( )= , ( )= ,


12

Cateva proprietati ale functiilor

totala: ( ) este denita pentru toate elementele din surjectiva: pentru toate elementele din exista un din astfel incat ( ) = injectiva: , , = implica faptul ca ( ) = ( ) bijectiva: in acelasi timp si surjectiva si injectiva Notatia big-O ( ) = ( ( )) daca exista > 0 si intregul pozitiv astfel incat pentru toate ( ) ( ) = ( ( )) daca ( ) ( ) ( ) = ( ( )) daca ( )= ( ( )) si ( ) = ( ( ))
13

( )

functie (partiala) :
1

, ...
2, . . . , 2, . . . ,

( 1,

)=

... )

) = ( 1, . . . ,

sau ( 1,

14

5. Relatii O relatie -ara , 1, pentru multimile este orice submultime a produsu1, . . . , lui cartezian 1 . . . . Exemplu

= { 1, 2}, = { 1, 2, 3, 4} = {( 1, 1), ( 1, 2), ( 1, 3), ( 2, 1), ( 2, 4)}

15

Compunerea relatiilor Fie si doua relatii. Atunci compunerea lui cu , notata prin , este relatia , denita prin: = {( , ) ( , ) este in si ( , ) este in pentru un din } Compunerea unei relatii
0

cu ea insasi

: {( , ) este in } 1 : , 1 : 1 + = inchiderea tranzitiva a lui =1 = inchiderea reexiva si tranzitiva a =0 lui

16

Proprietatile relatiei reexiva:

din

pentru toti

simetrica:

implica

antisimetrica:

implica

17

tranzitiva:

implica

O relatie binara peste este o relatie de echivalenta daca este reexiva, simetrica, si tranzitiva. O relatie de echivalenta peste deneste submultimi disjuncte ale lui numite clase de echivalenta. [ ] ={ este in si }

18

Fie o relatie binara de echivalenta peste si . Spunem ca este -inchisa daca pentru toti din , implica faptul ca este in . Exemplu : multimea intregilor; = {9, 4, 3, 2}; :este patratul lui (is the square este -inchisa.

of) Atunci

este o relatie n-ara peste . este -inchisa daca pentru toate 1, . . . , 1 din , avem ca daca ( 1, . . . , 1, ) este in atunci este in . Exemplu : multimea tuturor intregilor; = {( , , ) = }; = { 1} pentru un intreg Atunci este -inchisa.

19

Lema Fie o relatie de echivalenta peste . Atunci pentru toti , din avem sau [ ] = [ ] sau [ ] [ ] = O relatie binara peste tiala daca este reexiva, tranzitiva, si antisimetrica. Inchidere
+

este o ordine par-

este inchiderea tranzitiva a lui

O reprezentare in digraf pentru o inchidere tranzitiva:

20

6. Cardinalitate Daca se dau doua multimi si , spunem ca ele au cardinalitate egala daca exista o bijectie : . Exemplu # = # 0 ( ) = 2 1, < 0 ()=2, 0 O multime este numarabila sau enumerabila daca este ori nita ori innita, caz in care are aceeasi cardinalitate cu .

21

7. Metode de demonstratie demonstratie directa demonstratie prin contradictie demonstratie prin inductie Demonstratie directa Enumeram toate cazurile pentru a arata ca proprietatea este adevarate. Exemplu Orice numar par dintre 4 si 232 este suma a doua numere prime. Demonstratie prin contradictie Stabilim validitatea propozitiei presupunand ca nu este adevarata si inferam o contradictie. Exemplu Exista un numar innit de numere impare.
22

Demonstratia prin inductie baza ipoteza inductiva pasul inductiv concluzie Two forms: (1) Prove it holds for a basis value , Hypothesize it holds for value , Prove it holds for value + 1. (2) Prove it holds for basis values, Hypothesize it holds for all values less than and greater than basis value, Prove it holds for value .

23

Example (proof by induction) (i) no two lines are parallel; (ii) no three lines have a common intersection point.

Prove that the number of regions in an arrangement of lines is 1 + ( + 1)/2

24

8. Proof Techniques pigeonhole principle counting diagonalisation The Pigeonhole Principle Let 1 be an integer, let there be pigeonholes, and there be + 1 items of mail to be placed in the pigeonholes. Then, however the the items are placed, at least one pigeonhole will contain at least two items. The Pigeonhole Principle(Extended version) Let 1, . . . , 1. There exists a positive integer ( 1, . . . , ). If ( 1, . . . , ), then however items are placed into pigeonholes, there exists , 1 such that the -th pigeonhole contains at least 1 + 1 items.

25

Example Let = ( , ) be a digraph with # = 1. Then has a cycle if and only if has a path of length at least .

 

 

     

26

9. Alphabets, Words, and Languages An alphabet is a nite, nonempty set of elements. The elements of the alphabet are called symbols or letters. A word over an alphabet is a nite sequence of symbols from . A language is a set of words. Examples: (1) English alphabet, words and language. (2) Alphabet: { , } words: , , , , language: { , , i.e. { , ...... , , . . . . . .} 0}

(3) Alphabet : Fortran reserved words and identiers words : a Fortran program Language : the set of all Fortran programs.
27

Empty word is a word over every alphabet.

The length of a word is the number of symbols in the given word. Example: =0 =4 is the number of

The -length of a word times occurs in . Example: 011010 = 2 =0

28

The catenation of two words and , denoted by , is the word obtained by appending the word to . Example = = = = = = =

Catenation is associative: (
0

) = (

= + = = (Power of a word) 1 , 1 )0 = )3 =
29

Example ( (

Prex:

is a prex of =

if such that

Example is a prex of is a prex of any word Any word is a prex of itself Sux: is a sux of = Example is a sux of is a sux of any word 01011 is a sux of 01011 Subword: is a subword of = Example The subwords of , , , , , , , , , are: , if , s.t. if such that

Proper prex (sux, subword): is a proper prex (sux, subword) of if is a prex (sux, subword) of and = and = .
30

Reversal: (i) (ii) Lemma If

= , if = ; = , if = is a word =
1...

for

for some = ...


1.

0, then

Proof: By induction on . Basis: = 0. = by (i). I.H.: Assume Lemma holds for all with = . I.S.: Consider a word with = + 1. Then = 1 . . . +1 = 1 , where =
2... +1 .

Then = 1. But = , by I.H., so we get =


+1 . . . 1 .

+1 . . . 2 ,

Universal Language over : = {0, 1}, = { , 0, 1, 00, 01, 10, 11, 000, . . .}
31

Mappings (Morphism and Substitution) Denition Let and be two alphabets. Then a mapping : is said to be a morphism if (i) ( ) = ; (ii) ( ) = ( )( ), for all , in . Note: (ii) implies that we need only dene the images of letters to dene the images of words. Example: = {0, 1}, = { , , , }, (0) = , (1) = . Then (1001) = (1)(0)(0)(1) = A morphism is said to be = , ( ) = .

-free if, for all

32

Denition Let and be two alphabets. A mapping : 2 is said to be a substitution if i) ( ) = { }; ii) ( ) = ( ) ( ), for all , . Example: 1 = { , }, 1 = { , , }, a substitution 1: , }; 1( ) = { , }. 1( ) = { , Then
1(

)=

Example: 2 = {0, 1, 2}, 2 = { , }, 1} 2 (0) = { 2 (1) = { 1} 2 (2) = { } Then


2 (1020)

33

Given an alphabet , is dened as follows: (i) ; (ii) if , then for all . A language of , i.e., over an alphabet is a subset .

Example: is a language over every alphabet . { } is a language over every alphabet. { 0} is a language over { , } { 0} is a language over { , , }

34

Catenation of Languages 2 = { 1 2 1 in 1, usually written as 1 2.


1 2

in

2 },

Examples
1

={ , ={

}; ,
1

={ , } }

1 2

,
2

(Note that =
1

= {( ,

), ( , ), ( ,

), ( , )})

{ }

{ } = ={ , = }; ={ , }

35

Powers of Languages: 0 ={ } +1 = , 1 Plus


+

= =1 = =0
0

Star

......

Examples = { , }. Then 0 ={ } 1 = ={ , } 2 ={ , , = { } = { }0 = { } ={ , , , , (Note 4)


0

, . . . . . .}

36

Reversal of Languages = { is in } Examples ={ , , }; ={ , , } ={ > > 0} ={ > > 0} properties of reversal ( ( ( ( ( ) ) ) + ) ) = = = = ( = ( )+ )

Complementation of Languages Given a language over , = = ? { } ( ) = ={ 0} over = { , } =

37

Alternative denition of
+

and

={

in

= 1 2... 1, 2, . . . ,

, for and 1}

={

in

= 1 2 . . . , for and 1, 2, . . . ,

0}

Given a word in , and a language to test if is in we use = and test =0 if is in 0, 1, . . . .

38

Property Summaries properties of catenation (of languages) Associativity Identity Zero Distributivity w.r. 1( 2 3) = ( 1 2) 3 { }={ } = = = 1( 2 3) = 1 2 ( 1 2) 3 = 1 3

1 3 2 3

Distributivity does not hold with respect to properties of Plus and Star
+

+ +

{ }+
+

= + { } ( But + = { }?) = = + , ( ) = = , = { }, 0 = { } = { }, { } = { }, 2 = + = , = + + and

39

Chapter 2. FINITE AUTOMATA


Example Design a sequential lock. The lock has 1-bit sequential input. Initially the lock is closed. If the lock is closed it will open when the last three input signals are 1, 0, 1, and then remains open. state (transition) diagram

state (or transition) table

40

state set : {0, 1, 2, 3} input alphabet : {0, 1} Transition function : (0, 0) = 0, (0, 1) = 1, . . . Start state : 0 Final state set : {3} Deterministic Finite Automata (DFA) = ( , , , , ) where is a nite nonempty set of states is the input alphabet : transition function s start state nal state set

41

A computer is a nite state system (i.e. FA) which has millions of states. There are many examples of FINITE STATE SYSTEMS. A nite automaton is an ABSTRACTION of them. View a DFA as a machine

42

Specifying 1)

State diagram (Transition diagram)

Start state

Final state 2)

43

Congurations a word in

where is the present state, and is the remaining input Example: 0 ... 1 (start conguration) Moves of a DFA 0 1 1 2 ... 2 (nal conguration)

if =

and ( , ) =

Conguration sequence 0 1 2 + and is a binary relation over . + : transitive closure of . : reexive transitive closure of .
44

0 0 0 0

+ 2

2 2 0 2

if

2 steps

...

Accepting Conguration Sequence 0 1 2 can also be viewed as a function : ,

since the next conguration is determined uniquely for a given conguration. The DFA stops when: (i) we have no more input, or (ii) the next conguration is undened.
45

A word if

is said to be accepted by a DFA , . , ( ), is dened }

The language of a DFA as: ( )={ Examples

, for some

)=

( )=
46

DFA membership problem

DFA MEMBERSHIP INSTANCE: A DFA, = ( , , , , ) and a word . QUESTION: Is in ( ) ? Run the DFA with input . In at most steps it accepts, rejects or aborts. Examples

Checking for words that contain as subword. Check:


47

Let denote any letter of English alphabet and any decimal digit; the form of PASCAL IDENTIFIERS can be specied by

Recognizing comments that may go over several lines. /*................*/

: symbols other than and /


48

A DFA which has a total is said to be complete; if is nontotal it is incomplete. Theorem. Every incomplete DFA can be completed by adding one new state (sink) to give DFA such that ( ) = ( ). Example:

( ) is the set of all words that do not contain two consecutive s.

49

Two DFA if ( 1) = (

1 2 ).

and

are equivalent

The collection of languages accepted by DFAs is denoted by .

It is called the family of DFA languages and it is dened as: ={ 1} is not accepted by any DFA. ={ = ( ) for some DFA }

50

Proof: Use contradiction and Pigeonhole principle. Assume = ( ), for some DFA = ( , { , }, , , ). Let = # . Consider the accepting conguration sequence for ,
1

...

...

where 0 = and 2 . Now + 1 states appear during the reading of , but there are only distinct states in . By Pigeonhole principle at least one state must appear at least twice during the reading of s. Assume Then
0 ( )

,0 <

...

...
2

...

Therefore ( ) . This is a contradiction.


51

= { }, 1. For any 1, is a DFA language?

={ : 0 }, 1. For any 1, is a DFA language ?

52

Nondeterministic Finite Automata (NFA) = ( , , , , ) same as a DFA except . is a nite transition relation. In a DFA is a transition function: : It can be viewed as a relation : In a NFA, can be be viewed as a function: : 2 Examples: NFA for words in { , } that contain three consecutive as.

53

Both (0, , 1) and (0, , 3) are in . We dene acceptance by existence of a computation that leads to a nal state. Conversely, we dene rejection by the nonexistence of any computation that leads to a nal state. The language of an NFA = ( , , , , ) is dened by ( )={ , for some in }.

54

The family of NFA languages is dened by: ={ = (


1, 2 ).

), for some NFA


2

}.

Two NFAs ( 1) = ( Why NFA?

and

are equivalent if

(i) easy to construct; (ii) useful theoretically; (iii) are of same power as DFA. Note: congurations are dened in the same way Transition (move) if = , for some , and ( , , ) .

55

Transforming NFA to DFA Consider the NFA


1

again

There are only limited number of choices. For example: 0 1 1 2 0 3 3 {0} {1, 3} {1, 3} {2} Why limited number of choices? The state set is nite. We summarize the choices at each step by combining all conguration sequences into one super-conf. sequence. {0} {1, 3} {1, 3} {2}.
56

We now have a set of all possible states at each step. From this point of view the computation of the NFA on an input word is deterministic. A super-conguration has the form

where

and

Note that is a super-conf., it means that the NFA cannot be in any state at that point, i.e., an abort has occured. We say that if = , for some , and }

= { ( , , ) , for some

57

More examples on super-congurations : ( ) is the set of all words that have as a subword.

The super-conguration sequence on input word is as follows: {0} {0} {0, 2} {0, 2} {0, 1} {0, 1}

58

Notice that given a set and an input symbol , the set s.t. is uniquely determined. Lemma (2.3.1) (Determinism Lemma) Let = ( , , , , ) be an NFA. Then for all words in and for all . implies = . and

Lemma (2.3.2) Let = ( , , , , ) be an NFA. Then for all words in and for all in , i { } , for some with in .

59

Example (Transformation of an NFA to a DFA) = ( , , , , ) where = 0, 1, 2, = 0, = , = {2}

= ( , , , ,

) where

= 2 = {, {0}, {1}, {2}, {0, 1}, {0, 2}, {1, 2}, {0, 1, 2}}

( , )={ ( , , )
60

and

= {0} ={ Algorithm NFA to DFA The Subset Construction On entry: An NFA = ( , , , , ). On exit: A DFA = ( , , , , ) satisfying ( ) = ( ). = 2 , = { } and = { , and = } We dene : by For all and for all , ( , ) = , if in . end of Algorithm begin Let if ={ ( , , ) and
61

= {0}

Algorithm NFA to DFA 2 The Iterative Subset Construction

62

Theorem Given an NFA = ( , , , , ), then the DFA = ( , , , , ) obtained by either subset construction satises ( ) = ( ). Proof: By Lemma 2.3.2, for all , i { }

in with

for some

By the construction of { } in i { } in .

) , for some { } , , in { } , in and , ( )


63

Theorem Every NFA Language is a DFA language and conversely. ( = ) Example Every nite language is accepted by a DFA.

64

NFA It is useful to loosen the denition of NFA even more by allowing the read head to remain over the same symbol of the input and read nothing. Example 1 = { M: 0, 0}

)=

: (0, , 0) (0, , 1) (1, , 1) 0 0 0 1 0 1 1 1 0 0 1


65

Formally, a -NFA = ( , , , , ) where , , , are as before, but is a nite transition relation for which ( { })

Congurations are as before. is dened by if either = for and ( , , ) or = and ( , , ) Example Given FA 1 and 2, construct a FA 3 such that ( 3) = ( 1) ( 2)

66

Transforming -NFA to NFA Two steps: Step I: completion Step II: transition removal (I). -Completion Given a -NFA = ( , , , , ) perform the following process: For all , , : whenever ( , , ), ( , , ) are in add ( , , ) to until no new transitions are added to and let this be . Let the new NFA be = ( , , , , ) where = { ( , , ) and = {( , , ) + } Example:

and

67

Claim 1: For any , + Theorem: Example: (

if and only if , ,

Claim 2: For any ,

if and only if )= ( )

68

(II) Transition Removal Given a -completed -NFA = ( , , , , ),

perform the following process: (0) = ; ( ) For all , , , if ( , , ) and ( , , ) in then add ( , , ) to ; ( ) Delete all -transitions from

Now we got = ( , , , , ) where = ( {( , , ) ( , , ), ( , , ) }) {( , , ) , } Example

69

Claim Whenever for some , we have and vice versa. Claim (

)= (

Theorem

70

Properties of FA Languages I. Closure Properties Union: The union of two DFA languages is a DFA language. Proof: Given 1 = ( 1) and 2 = ( 2), 1, 2 are generic DFA languages.
1

=(
2

1,

1,

1,

1,

1)

and ) where

= ( 2, 2, 2, 2, 2). Construct a -NFA = ( , , , , = 1 2{ } = 1 2 = 1 2 {( , , 1), ( , , 2)} = 1 2

71

Now we claim that (1) Let

)=

be a generic word in ( ). ( ) implies for some 1 or 2. + If 1, then and then 1 1 . We know that ( 1). 1 If 2, then . Since 2 2 , we know that ( 2), 2 therefore ( 1) ( 2), i.e., 1 2. So ( ) 1 2.

(2) Let be a generic word in 1 2. Without losing of generality we can assume that 1, i.e., ( 1). Then 1 1 , for some 1. Then . Therefore ( ). 1 So, 1 2 ( ). (3) By the results of (1) and (2), we conclude ( ) = 1 2. Since every -NFA language is a DFA language, ( ) is a DFA language.
72

2. Complementation: The complement of a DFA language is a DFA language. Proof: There is a complete DFA = ( , , , , ) with = ( ). Dene = ( , , , , )

3. Intersection:
1

and
1

2 2

73

4. Catenation: The catenation of two DFA languages is a DFA language:


1 2

=( =( (

1,

1, 2 , 2 ,
1)

1, 2, 2)

1, 2,

1 ); 2 ).

) =

= ( 1 2, 1 2, , 1, = 1 2 {( , , 2) 1}

2 ),

= ( , , , = = = = =

,
1

) where

2 1 2 1 2 {( , , 2 )
1 2

1}

74

5. Star: The star of a DFA language is a DFA language = ( ) where = ( , , , , )

= ( ) = ( , ,

) where

= { } = = {( , , )} {( , , ) = { } = { }

6. Plus:

75

II. Decidability Properties A decision problem is a problem each instance of which is either false or true. A decision algorithm is an algorithm whose result for each possible input is either false or true. A decision problem is decidable if there exists a decision algorithm for it. Otherwise it is undecidable. 1. DFA membership INSTANCE: A DFA = ( , , , and a word . QUESTION: Is ( ) ?

Theorem: DFA membership is decidable.

76

Proof: Compute for the given and the terminating state such that . If then answer True else answer false. 2. DFA Emptiness INSTANCE: A DFA = ( , , , QUESTION: Is ( ) = ? , ).

Theorem DFA emptiness is decidable. Proof: ( ) = i there is no path in the state diagram of from to a nal state. If = , then this holds immediately. Otherwise, enumerate the states that can be reached from . (Mark . Now mark all states reachable by one transition from one of the marked states. Repeat this until no newly marked state is introduced. The marked states are the reachable states).

77

3. DFA Universality INSTANCE: A DFA = ( , , , QUESTION: Is ( ) = ? , ).

Theorem DFA universality is decidable. Proof: 4. DFA Containment INSTANCE: Two DFA 1 = ( 1 , 1 , 2 = ( 2 , 2 , QUESTION: Is ( 1) (
1, 2, 2) 1, 2, 1) 2 ).

and

Theorem DFA containment is decidable. Proof: (


1)

2)

= means that

1)

2)

78

5. DFA Equivalence INSTANCE: Two DFA 1 = ( 1 , 1 , 2 = ( 2 , 2 , QUESTION: Is ( 1) = (


1, 2, 2) 1, 2, 1) 2 ).

and

Theorem DFA equivalence is decidable. ( (


1) 2)

( (

2) 1)

? yes ? yes

79

Pumping Lemma and Non-DFA Language. The DFA Pumping Lemma Let = ( , , , , ) be a DFA and let = # . For all words in ( ) such that , can be decomposed into , for some , , and in such that (i) (ii) (iii) Example ={ , , = { }. ; 1; and for all 0,

is in

).

= ( , , , , ) where }, = { , }, # =3

Let be an arbitrary word of length # in ( ), e.g. = . The accepting conf. sequence for is: . So, = , = , = and ( ) ( ) for all 0.
80

Proof of DFA Pumping Lemma: Let be in ( ) with . Then has an accepting conguration sequence
0 1 2...

1 2...

...

where 0 = , . Consider the rst transitions. , 1, . . . , cannot all be distinct since there are only distinct states (by pigeonhole principle). This means that = for some 0 < . Let = 1... , = = So, we have
0 +1 . . . +1 . . .

, . ) 0

Since

( = . for any

81

( ) , since ( ) 1, since < ( ) ( ) for all 0 qed.

0, since

Re-state Pumping Lemma If is a DFA Language then ( = ( ) for some of states;) for every word of length in , there exists one decomposition = which satises () , ( ) 1, ( ) (

) for all

0.

82

Comments: The DFA pumping lemma shows a property of DFA languages. It can be used possitively; but it is mainly used negatively to show that some languages are not in . The DFA pumping lemma gives a necessary condition for DFA languages. The condition is not sucient. Review of logic: if then if then if then if then if then if then Example if it is sugar then it is sweet. if it is not sweet then it is not sugar. if it is sweet then it is sugar. So, pumping lemma can be used to show that a language is not a DFA language, but cannot be used to show that a language is a DFA language.

83

Non-DFA Language ={ 0} is not a DFA Language

Proof (I): Assume is a DFA language. Then = ( ) for some DFA = ( , , , , ) with = . Consider = , . By DFA pumping lemma, there is a decomposition = which satises (i), (ii), and (iii). Consider all the possible decompositions Case 1 : = , 1. But 0 = . Case 2 : = , 1. 0 = . Case 3 : = , , 1. Then 2 = .

All the possible decompositions fail. Therefore, is not a DFA language.


84

Proof (II): .................. = . Consider = in . Obviously, . By DFA pumping lemma, there is a decomposition = that satises (i), (ii), and (iii). The only decompositions that satisfy (i) and (ii) are the following: = for 1. But 0 = . So, there is no such decomposition. is not a DFA language. (i) ; (ii) 1;

85

Notes on proving that a language is not a DFA language by pumping lemma

1) Assume L is a DFA language. Then we have a constant . 2) Choose a word in of length . 3) Consider all the possible decompositions of . If none of them satisfy (i), (ii), and (iii) at the same time, then conclude that such decomposition does not exist. So, is not a DFA language.

86

={

0} is not a DFA language.

Proof: (1) Assume = ( ) for some = ( , , , , ) with = . 2 +1 (2) Consider = , . (3) By DFA P.L., there is a decomposition = satisfying (i), (ii), and (iii). The only decompositions of (i) and (ii) are the following: = ,
+1

which satisfy

1.
+1

Notice that = 2 . 2 +1 > 2 +1 2 +1 > 2 i.e., 2 +1 > 2 +1 > 2 .


2 +1

2 =2
2

>

>

So, / . It is contrary to (iii), so not a DFA language.


87

is

6. DFA Finiteness INSTANCE: A DFA = ( , , , , ) QUESTION: Is ( ) nite? It is decidable. Theorem ( ) is nite i accepts no words that satisfy < 2 accepts no words with Proof: If: Assume < 2 and ( ) is innite. Since ( ) is innite, it must accept some word with 2 . By P.L., = with 1, and = is in ( ). Notice that > . If 2 , then repeat this process. Otherwise 2 > . (i.e., 2 ). This is a contradiction. Only if: By P.L., = , 1. Since ( ) for all 0, ( nite. ) is in-

88

Theorem The family of DFA languages is closed under morphisms. Proof: Let be a DFA language. Then there is a DFA = ( , , , , ) such that ( ) = . Let : be a morphism. We are going to show that ( ) = { ( ) } is a DFA language. Construct = ( , , , , ) by dening ( , ( ), ) is in i ( , ) = . is a lazy FA. So, L(M) is a DFA language. It is not dicult to show that ( ) = ( ). Therefore, ( ) is a DFA language.

89

Finite Transducers and Finite Transductions (Translations) In automata and language theory, a machine with input and output is called a transducer.

I in

O in

A transducer is single-valued if it produces at most one output word for each input word. It is multi-valued otherwise. A transducer denes a function : , if it is single-valued, a relation , otherwise. A function or a relation that is dened by a transducer is called a transduction (translation).
90

Specically, a nite automaton with output is called a nite transducer. FA(DFA, NFA, or -NFA) + output (output alphabet, output tape) = FT

Input tape read-only head

Finite control

write-only head Output tape

Formally, a nite transducer (FT) is a sixtuple ( , , , , , ) where is an output alphabet; ( { }) is a nite transition relation; the others are the same as in a FA.
91

A conguration

is a word in .

output till now; current state; remaining input. We write if ( , , , ) is in . , +, are dened as usual. Given , we say that w.r.t. if for some . is an output for

Let ( ) be the set of all outputs for , then ( )={ for some }. The transduction or translation dened by is ( ) = {( , ) and ( )}

92

Example

0 1

1 2

1 2

i.e. 0 2 Since 2 , we say ( ), and ( , ) ( ). We can see that ( ) = {( , ) , , 0} Example Let ( ) = 101, ( ) = 11. Encoding:

Decoding:

93

REGULAR EXPRESSIONS
The Second Model for Dening Languages Example: Consider the language of all the words that consist of s and s and have as a subword. We can formally dene this language by the following: (1) = { { , } and has as a subword}; (2) = ( ) where is an NFA given by the following diagram:

Both of the above denitions are lengthy. It can also be expressed by ([ ] [ ])

94

Denition Let be an alphabet. A regular expression over is dened recursively: Basis: (1) , (2) , (3) , where are R.E.s over Induction Step: If 1 and 2 are R.E.s over , then (4) [ 1 2], (5) [ 1 2], (6) 1 are R.E.s over We usually omit . The set of all regular expressions over is denoted by

95

[[ + ] ] is the same as [[ ] ] Example: [[


1 2

3 5

]
4

] is a R.E. over { , }

We display the parsing by an expression tree:

What language does an R.E. dene? { { , , } }

{ , } { } { } { }

96

Denition Given a regular expression , the language ( ) denoted by is dened as follows: Basis: (1) if = , then ; (2) if = , then { }; (3) if = , then { }; Induction Step: (4) if = [ 1 2], then ( 1) ( 2); (5) if = [ 1 2], then ( 1) ( 2); (6) if = 1 , then ( ( 1)). Properties of R.E.s : 1 2 2 1; [ 1 2] 3 1 [ So, [ 1 2] 3 1 : [ 1 2 ] 3 1 [ 2 3 ]; So, [ 1 2] 3 1 2 3.

3 ]; 2 3.

..........................................

97

Denition A language is regular i there is a regular expression such that = ( ). The family of (all) regular languages is denoted by . Example = [ ] . = { in { , } and number of }. Claim: ( )=

contains an even

Proof: (i) ( ) , since every word in ( ) contains an even number of s. (ii)Let . Then can be written as 0 1 ...... 2 , 0 , 1 , . . . , 2 0. So, = ( 0 1 )( 2 3 ) . . . . . . ( 2 2 2 1 ) 2 . ([ ]) ( ) = ( ). . . .

98

Examples = { , }. = , 1 ={

}.

= { 0 mod 3}. [ [ ]]

= { has 2 or 3 with the last two appearances nonconsecutive }

={

1}

99

Examples What are the languages denoted by the following R.E.s ?

= [

[ ]

=[

100

How many languages over do R.E.s dene? ={ , }

(1) Innitely many ?

(2) Countable ?

101

Regular Expression into Finite Automata Let be a regular expression over . Then we can construct a -NFA such that ( ) = ( ), using the following rules: (i) = . Construct such that ( ) =
 

(ii) = . Construct

such that

)={ }

   

(iii) = , Construct

. such that
 

)={ }

#   "!

102

(iv) = [ 1 2]. Construct such that

)= (

1)

2 ).

(v) = [ 1 Construct

2 ].

such that

)= (

1)

2 ).

(vi) = 1 . Construct

such that

)= (

1) .

103

Example = [ [ [ ]]] Construct a FA , , by (iii)

such that

) = ( ).

by (vi)

] by (v)

] by (iv)

] by (vi)

[ [

] ] by (v)

104

Theorem For , an arbitrary regular expression over , the -NFA, , constructed as above satises ( ) = ( ). Proof: Let ( ) be the total number of , , and operations in . We prove this theorem by induction on ( ). Basis: ( ) = 0. Then = , , or Then clearly we have ( ) = ( ). Induction Hypothesis: Assume the claim holds for all , for some 0. .

with

( )

Induction Step: Consider an arbitrary regular expression with ( ) = + 1. Since + 1 1, contains at least one operator , , or . Case I: = 1 2. Then ( 1) and ( 2) . So, ( 1) = ( 1) and ( 2) = ( 2) by I.H.. We know the construction of = 1 2 satises ( ) = ( 1) ( 2), and ( ) = ( 1) ( 2)
105

Therefore, ( ) = ( ). Case II: = 1 2 .................................... Case III: =


1

....................................

In each of the three cases, we have shown that ( ) = ( ). Therefore this holds for all regular expressions by the principle of induction. . . .

106

Finite Automata into Regular Expressions To prove that every DFA language is regular we introduce an extension of nite automata. Denition An extended nite automaton (EFA), , is a quintuple ( , , , , ) where , , are as in -NFA, is the only nal state, = , : is a total extended transition function. Example of an EFA:

( , )= ( , )= ...... One nal state

=
107

A conguration is in Move if (i) = , , (ii) ( , ) = , and (iii) ( ). , + are dened similarly as before. Lemma If with ( is a DFA, Then there is an EFA ) = ( ).

Example DFA into EFA.

108

Example: An extended nite Automaton (EFA). M:

Check if the following words are in (1) (2) (3) (4)

109

State Elimination Technique Goal of the technique:

i.e.:

(1) EFA has 2 states

Example

110

(2) EFA has + 1 states, 2. Then eliminate a state from :

to form

Note: { , } Consider all transitions ( , and ( , :

, ,

) )

( ,

)= ( ,

) ( , )( ( , )) ( ,
111

Example

112

Example

113

Summary of the State Elimination Technique (0) Change FA into EFA (1) Add a new start state if the original one has incoming transitions. (2) Add a new nal state if there are more than one nal states originally. Old nal states become non-nal states. (3) Eliminate the states in { , } one by one. (4) Eliminate the transition ( , ).

114