Sunteți pe pagina 1din 114

7/16/2019 Curs Limbaje Formale si Automate

Limbaje Formale si Automate

˘ 
Instructor Andrei P AUN 

Semestrul II 2009-2010

Departmentul de Infomrmatica 
Universitatea Bucuresti 
Bucuresti, Romania 

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 1/114
7/16/2019 Curs Limbaje Formale si Automate

Structura cursului:

1. Cunostinte de baza
multimi, multiseturi, secvente, functii,
relatii, metode si tehnici de demonstratie,
alfabet, cuvinte, limbaje

2. Automate finite
automate finite nedeterministe (NFA),
automate finite 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 au-
tomatele finite
(in definirea limbajelor)

4. Gramatici independente de context (CFG)


simplificare si forme normale,
algoritmi de parsare, lema de pompare si
alte proprietati
2

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 2/114
7/16/2019 Curs Limbaje Formale si Automate

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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 3/114
7/16/2019 Curs Limbaje Formale si Automate

Motivare pentru curs

Programming AI

Database Graphics
Compiler VLSI

Theory of Computing
(1) Putere de calcul

(2) Complexitate

(3) Software design

(4) Circuit design

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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 4/114
7/16/2019 Curs Limbaje Formale si Automate

I. Cunostinte de baza

1. Multimi
1) O multime este o colectie de elemente luate
dintr-un univers.

2) O multime este finita daca contine un nu-


mar finit de elemente, si este infinita in caz
contrar.

3) Cardinalitatea unei multimi este numarul sau


de elemente si se noteaza cu # sau ∣∣ (pen-
tru multimea ).

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 5/114
7/16/2019 Curs Limbaje Formale si Automate

– Cum specificam 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) Definite recursiv:


Forma generala:
i) Anumite elemente initiale sau de baza
sunt in 
ii) Daca ,  ∈ , atunci  ∘  ∈ 
iii) Nici un alt element nu apartine lui 

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 6/114
7/16/2019 Curs Limbaje Formale si Automate

Exemplu Definirea 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 op-


eratie 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 definite prin


inchidere)
 este cea mai mica multime care contine an-
umite elemente initiale (de baza) si care este
inchisa la operatia ∘.

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 7/114
7/16/2019 Curs Limbaje Formale si Automate

∙ 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  }

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 8/114
7/16/2019 Curs Limbaje Formale si Automate

∪=1 = { ∣  este in , pentru un , 1 ≤  ≤


}
∩=1 = { ∣  este in , 1 ≤  ≤ }

— Proprietati ale operatiilor cu multimi

Distributivitate
 ∩ ( ∪  ) = ( ∩ ) ∪ ( ∩  )
 ∪ ( ∩  ) = ( ∪ ) ∩ ( ∪  )

Indempotenta
 ∪  = ;  ∩  = 

Involutie
¬(¬) = 

Comutativitate
 ∩  =  ∩ ;  ∪  =  ∪ 

Asociativitate
 ∪ ( ∪  ) = ( ∪ ) ∪  
 ∩ ( ∩  ) = ( ∩ ) ∩  

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 9/114
7/16/2019 Curs Limbaje Formale si Automate

Regulile lui De Morgan


¬( ∪ ) = ¬ ∩ ¬
¬( ∩ ) = ¬ ∪ ¬

— Multimea submultimilor
Multimea tuturor submultimilor unei mul-
timi  (“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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 10/114
7/16/2019 Curs Limbaje Formale si Automate

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 oare-
care este o lista de elemente care sunt
ordonate (fiecare element are o pozitie).

11

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 11/114
7/16/2019 Curs Limbaje Formale si Automate

4. Functii

Definitie Daca se dau doua multimi  si  , o


functie (partiala) de la  la  asociaza cu
fiecare  din  (cel mult) un element  din  .

Notatii:
functie   :  → 
asocierea  () = 
nedefinita  () =  

Functii speciale:

functia identitate:
  :  →  si
 () =  pentru toti  ∈ 

Functia caracteristica a lui  pentru  :


⊆
  :  → {,  }
 () = ,   ∈ 
 () = ,   ∈  − 

12

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 12/114
7/16/2019 Curs Limbaje Formale si Automate

Cateva proprietati ale functiilor   :  → 

totala:
 () este definita 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 poz-


itiv  astfel incat pentru toate  ≥ 
 () ≤ ()
 () = Ω(()) daca

 () ≥ ()
 () = Θ(()) daca
 () = (()) si  () = Ω(())

13

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 13/114
7/16/2019 Curs Limbaje Formale si Automate

functie (partiala) ,

  : 1 × 2 × . . . ×  → 1 × . . . × 
 (1, 2, . . . , ) = (1, . . . , )
sau  (1, 2, . . . , ) =  

14

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 14/114
7/16/2019 Curs Limbaje Formale si Automate

5. Relatii

O relatie -ara ,  ≥ 1, pentru multimile


1, . . . ,  este orice submultime  a produsu-
lui cartezian 1 × . . . × .

Exemplu

  = {  ,  },   = { ,  ,  ,  }
  ⊆   1×  
2 1 2 3 4

  = {( 1, 1), ( 1, 2), ( 1, 3), ( 2, 1), ( 2, 4)}

15

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 15/114
7/16/2019 Curs Limbaje Formale si Automate

Compunerea relatiilor

Fie  ⊆  ×  si   ⊆  ×   doua relatii. Atunci


compunerea lui  cu  , notata prin  ∘  , este
relatia  ∘   ⊆  ×  , definita prin:
 ∘   = {(, ) ∣ (, ) este in  si (, ) este in  
pentru un  din  }

Compunerea unei relatii  :  ×  cu ea insasi

0 : {(, ) ∣  este in }
1 : 
, ≥1 :  ∘ −1
+ = ∪ =1 inchiderea tranzitiva a lui 

 ∗ = ∪∞ 
=0 inchiderea reflexiva si tranzitiva a
lui 

16

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 16/114
7/16/2019 Curs Limbaje Formale si Automate

Proprietatile relatiei  ⊆  × 

∙ reflexiva:  pentru toti  din 

∙ simetrica:  implica 

∙ antisimetrica: ,  implica  = 

17

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 17/114
7/16/2019 Curs Limbaje Formale si Automate

∙ tranzitiva: ,  implica 

△ O relatie binara  peste  este o


relatie de echivalenta daca este

∙ reflexiva,
∙ simetrica, si
∙ tranzitiva.

△ O relatie de echivalenta  peste 


defineste submultimi disjuncte ale lui ,
numite clase de echivalenta.

[] = { ∣  este in  si }

18

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 18/114
7/16/2019 Curs Limbaje Formale si Automate

∙ 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,patratul
“este 3, 2}; lui” (“is the square
of”)
Atunci  este -inchisa.

∙  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;


 = {(,,) ∣  ×  = };

Atunci = {este
 ∣ ≥ 1} pentru un intreg 
-inchisa.

19

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 19/114
7/16/2019 Curs Limbaje Formale si Automate

Lema Fie  o relatie de echivalenta peste .


Atunci pentru toti ,  din  avem sau [] =
[] sau [] ∩ [] = ∅

△ O relatie binara  peste  este o ordine par-


tiala daca este
∙∙ reflexiva,
tranzitiva, si
∙ antisimetrica.

△ Inchidere

– + este inchiderea tranzitiva a lui 


– O reprezentare in digraf pentru o inchidere
tranzitiva:

20

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 20/114
7/16/2019 Curs Limbaje Formale si Automate

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 finita ori infinita, caz in care are
aceeasi cardinalitate cu  .

21

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 21/114
7/16/2019 Curs Limbaje Formale si Automate

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 infinit de numere


impare.

22

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 22/114
7/16/2019 Curs Limbaje Formale si Automate

△ 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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 23/114
7/16/2019 Curs Limbaje Formale si Automate

Example (proof by induction)

(i) no two lines are parallel;

(ii) no three lines have a common intersec-


tion point.

Prove that the number of regions in an


arrangement of   lines is
1 + ( + 1)/2

24

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 24/114
7/16/2019 Curs Limbaje Formale si Automate

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, how-
ever 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 inte-
ger  ( 1, . . . ,  ). If   ≥  ( 1, . . . ,  ), then how-
ever  items are placed into  pigeonholes,
,   
there existscontains
pigeonhole 1 ≤ at≤least such  1 +that the -th
1 items.

25

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 25/114
7/16/2019 Curs Limbaje Formale si Automate

Example Let  = (,  ) be a digraph with


#  =  ≥ 1. Then  has a cycle if and only if 
 has a path of length at least .


  

  

  
  


 

  

   

   

  

  

  

26

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 26/114
7/16/2019 Curs Limbaje Formale si Automate

9. Alphabets, Words, and Languages

△ An alphabet is a finite, nonempty set of 


elements.
The elements of the alphabet are called
symbols or letters.

△ A word over an alphabet Σ is a finite se-


quence 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


identifiers
words : a Fortran program
Language : the set of all Fortran
programs.

27

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 27/114
7/16/2019 Curs Limbaje Formale si Automate

△ Empty word is a word over every alphabet.


△ The length of a word is the number of sym-
bols in the given word.

Example: ∣∣ = 0
∣∣ = 4
△ The -length of a word  is the number of 
times  occurs in .

Example: ∣01101∣0 = 2
∣∣ = 0

28

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 28/114
7/16/2019 Curs Limbaje Formale si Automate

△ The catenation of two words  and  , de-


noted by  , is the word obtained by append-
ing the word  to .

Example  = 
 = 
 = 
 = 
 =  = 
 = 

△ Catenation is associative:
()  = ( )
△ ∣ ∣ = ∣∣ + ∣ ∣

△ 0 =  (Power of a word)
 −1
 =  ,  ≥ 1
Example ()0 = 
()3 = 

29

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 29/114
7/16/2019 Curs Limbaje Formale si Automate

△ Prefix:  is a prefix of   if  ∃  such that


  = 
Example ∙  is a prefix of  
∙  is a prefix of any word
∙ Any word is a prefix of itself 

△ Suffix:  is a suffix of   if  ∃  such that


 = 
Example ∙  is a suffix of  
∙  is a suffix of any word
∙ 01011 is a suffix of  01011

△ Subword:  is a subword of   if  ∃,   s.t.


  = 
Example The subwords of   are:
, , , , , , , , , , 

△ Proper prefix (suffix, subword):


 is a proper prefix (suffix, subword) of  
if   is a prefix (suffix, subword) of  
and  ∕ =  and  ∕
= .
30

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 30/114
7/16/2019 Curs Limbaje Formale si Automate

△ Reversal:
(i)  = , if   = ;
(ii)  =   , if   =  for  ∈ Σ,
 is a word

Lemma If   = 1 . . .  for some  ≥ 0, then


 =  . . . 1.
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.,  = +1 . . . 2,
so we get

 = +1 . . . 1. 


△ Universal Language over Σ: Σ∗
Σ = {0, 1}, Σ∗ = {, 0, 1, 00, 01, 10, 11, 000, . . .}

31

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 31/114
7/16/2019 Curs Limbaje Formale si Automate

△ Mappings (Morphism and Substitution)

Definition 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 define
the images of letters to define 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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 32/114
7/16/2019 Curs Limbaje Formale si Automate

Definition 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 = {, },
2(0) = { ∣  ≥ 1}
2(1) = { ∣  ≥ 1}
2(2) = {}

Then 2(1020) =

33

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 33/114
7/16/2019 Curs Limbaje Formale si Automate

△ Given an alphabet Σ, Σ∗ is defined as fol-


lows:
(i)  ∈ Σ∗;
(ii) if   ∈ Σ∗, then  ∈ Σ∗ for all  ∈ Σ.

△ A language  over an alphabet Σ is a subset


∗ ∗
of  Σ , i.e., ⊆Σ .

Example:
 is a language over every alphabet .
{} is a language over every alphabet.
{ ∣  ≥ 0} is a language over {, }
{ ∣  ≥ 0} is a language over {, , }

34

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 34/114
7/16/2019 Curs Limbaje Formale si Automate

△ Catenation of Languages

1 ∘ 2 = {1 ∘ 2 ∣ 1 in 1, 2 in 2},


usually written as 12.

Examples

1 = {, }; 2 = {, }

12 = {, , }

(Note that 1 × 2 = {(,), (, ), (, ), (,)})

1 =
{}1 =

{} =

 = {, };  = {, }

 =

35

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 35/114
7/16/2019 Curs Limbaje Formale si Automate

△ Powers of Languages:
0 = {}
+1 =  ∘ ,  ≥ 1

△ Plus
+ = ∪∞
=1  

△ Star∗ = ∪∞  0 ∪ 1 ∪ 2 ∪ . . . . . .
=0

Examples
 = {, }. Then
0 = {}
1 =  = {, }
2 = {, , , }

0 = {} ∕
=
{}0 = {}
∗ = {, , , , , , , ...... }
(Note  ∈ 4)

36

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 36/114
7/16/2019 Curs Limbaje Formale si Automate

△ Reversal of Languages
 = { ∣  is in }
Examples
  = {, , };
  = {, , }
  = { ∣  >  > 0}
  
 
= {  ∣  >  > 0}
— properties of reversal
( ∪ ) =  ∪  
( ∩ ) =  ∩  
() =   
(+) = ()+
(∗) = ()∗
△ Complementation of Languages
Given a language  over Σ,
 = Σ∗ − 
∗ ∗  
Σ
 =={ ∣  ≥ 0Σ ? {}Σ = {, ()
} over } = 
=

37

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 37/114
7/16/2019 Curs Limbaje Formale si Automate

△ Alternative definition of  + and ∗

+ = { in Σ∗ ∣  = 12 . . . , for


1, 2, . . . ,  ∈  and  ≥ 1}

∗ = { in Σ∗ ∣  = 12 . . . , for

1, 2, . . . ,  ∈  and  ≥ 0}

△ Given a word  in Σ∗, and a language  ⊆ Σ∗


to test if   is in ∗ we use ∗ = ∪∞
=0  
and test
if   is in 0, 1, . . . .

38

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 38/114
7/16/2019 Curs Limbaje Formale si Automate

△ Property Summaries
— properties of catenation (of languages)
Associativity — 1(23) = (12)3
Identity — {} = {} = 
Zero —  =  = 
Distributivity — 1(2 ∪ 3) = 12 ∪ 13
w.r. ∪ — (1 ∪ 2)3 = 13 ∪ 23
Distributivity does not hold with respect to

— properties of Plus and Star


∗ + + ∗

+ =
=∗∪ {} ( But  =  − {}?)

(+)+ =+, (∗)∗ = ∗
+ =, ∗ = {}, 0 = {}
{}+ ={}, {}∗ = {}, 2 = 
+  =+, ∗ = ∗
⊆ ⇒ + ⊆  + and ∗ ⊆  ∗

39

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 39/114
7/16/2019 Curs Limbaje Formale si Automate

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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 40/114
7/16/2019 Curs Limbaje Formale si Automate

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 finite nonempty set of states
Σ is the input alphabet
  :  × Σ →  transition function
s start state
  ⊆  final state set

41

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 41/114
7/16/2019 Curs Limbaje Formale si Automate

A computer is a finite state system (i.e. FA)


which has millions of states.
There are many examples of FINITE
STATE SYSTEMS. A finite automaton is an
ABSTRACTION of them.

View a DFA as a machine

42

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 42/114
7/16/2019 Curs Limbaje Formale si Automate

Specifying  
1)

State diagram
(Transition diagram)

Start state

Final state

2)

43

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 43/114
7/16/2019 Curs Limbaje Formale si Automate

Configurations
a word in Σ∗

 
where  is the present state, and
 is the remaining input

Example:

0 ... 1 ... 2


(start configuration) (final configuration)

Moves of a DFA
0 ⊢ 1  ⊢ 
1 ⊢ 2 if   =  and  ( , ) =  

Configuration sequence
0 ⊢ 1 ⊢ 2

⊢+ and ⊢∗
⊢ is a binary relation over Σ∗.
⊢+ : transitive closure of  ⊢.
⊢∗ : reflexive transitive closure of  ⊢.
44

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 44/114
7/16/2019 Curs Limbaje Formale si Automate

0 ⊢+ 2
0 ⊢∗ 2
0 ⊢∗ 0
0 ⊢2 2

  ⊢ 
if   ⊢ 1 1 ⊢ 2 2 ⊢ . . . ⊢ 
    

 steps

Accepting Configuration Sequence

⊢ 0
can ⊢ 1be
also 2
⊢ viewed as a function
⊢ : Σ∗ → Σ∗,
since the next configuration is determined
uniquely for a given configuration.

The DFA stops when:


(i) we have no more input,
or (ii) the next configuration is undefined.

45

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 45/114
7/16/2019 Curs Limbaje Formale si Automate

A word  is said to be accepted by a DFA  


if   ⊢∗ ,   ∈  .
The language of a DFA  , ( ), is defined
as:
( ) = { ∣  ⊢∗ , for some   ∈  }

Examples

( ) =

( ) =
46

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 46/114
7/16/2019 Curs Limbaje Formale si Automate

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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 47/114
7/16/2019 Curs Limbaje Formale si Automate

Let  denote any letter of English alphabet


and  any decimal digit; the form of 
PASCAL IDENTIFIERS can be specified
by

Recognizing comments that may go over


several lines.

/*................*/

Δ: symbols other than ” ∗ ” and ”/”


48

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 48/114
7/16/2019 Curs Limbaje Formale si Automate

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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 49/114
7/16/2019 Curs Limbaje Formale si Automate

△ Two DFA  1 and  2 are equivalent


if  ( 1) = ( 2).

△ The collection of languages accepted


by DFA’s is denoted by

ℒ .

It is called the family of DFA languages


and it is defined as:

ℒ  = { ∣  = ( ) for some DFA   }


  = { ∣  ≥ 1} is not accepted
by any DFA.

50

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 50/114
7/16/2019 Curs Limbaje Formale si Automate

Proof: Use contradiction and


Pigeonhole principle.
Assume   = ( ), for some DFA

  = (, {, },, , ).


Let  = #. Consider the accepting
configuration sequence for ,

0 ⊢ 1−1 ⊢ . . . ⊢  ⊢ . . . ⊢ 2

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  =   , 0 ≤  <  ≤ .
Then
0−(  −) ⊢ . . . ⊢ −  
−   
   ⊢ 2 ⊢ . . . ⊢  ⊢ . . . ⊢

Therefore −(  −) ∈  .


This is a contradiction.
51

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 51/114
7/16/2019 Curs Limbaje Formale si Automate

△  = {},  ≥ 1.
For any  ≥ 1, is  a DFA language?

△    = { : 0 ≤  ≤  },  ≥ 1.

For any  ≥ 1, is    a DFA language ?

52

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 52/114
7/16/2019 Curs Limbaje Formale si Automate

Nondeterministic Finite Automata (NFA)


  = (, Σ,, , )
same as a DFA except
  ⊆  × Σ × .
  is a finite 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 a’s.

53

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 53/114
7/16/2019 Curs Limbaje Formale si Automate

Both (0, , 1) and (0, , 3) are in  .

We define acceptance by existence


of a computation that leads to a final
state.
Conversely, we define rejection by
the nonexistence of any computation
that leads to a final state.

The language of an NFA   = (, Σ,, , )

is defined by ∗
( ) = { ∣  ⊢  , for some   in   }.

54

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 54/114
7/16/2019 Curs Limbaje Formale si Automate

The family of NFA languages ℒ 


is defined by:
ℒ   = { ∣  = ( ), for some NFA   }.

Two NFAs  1, and  2 are equivalent if 


( 1) = ( 2).
Why NFA?
(i) easy to construct;
(ii) useful theoretically;
(iii) are of same power as DFA.

Note:
configurations are defined in the same way
Transition (move)

  
if   =  , for some  ⊢
∈ Σ, and ( , ,  ) ∈  .

55

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 55/114
7/16/2019 Curs Limbaje Formale si Automate

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

We summarize the choices at each step


by combining all configuration sequences
into one ”super-conf. sequence”.
{0} ⊢ {1, 3} ⊢ {1, 3} ⊢ {2}.
56

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 56/114
7/16/2019 Curs Limbaje Formale si Automate

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-configuration 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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 57/114
7/16/2019 Curs Limbaje Formale si Automate

More examples on super-configurations


 : ( ) is the set of all words
that have “” as a subword.

The super-configuration sequence


on input word “” is as follows:

{0} ⊢ {0} ⊢ {0, 1} ⊢ {0, 1}


⊢ {0, 2} ⊢ {0, 2}

58

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 58/114
7/16/2019 Curs Limbaje Formale si Automate

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   ⊆ .
 ⊢∗   and  ⊢∗  
implies
  =  .
Lemma (2.3.2) Let   = (, Σ,, , )
be an NFA. Then for all words  in Σ∗
and for all   in ,
 ⊢∗  
iff  { } ⊢∗  , for some   with  in  .

59

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 59/114
7/16/2019 Curs Limbaje Formale si Automate

Example (Transformation of an NFA to a DFA)


  = (, Σ,, , ) where

 ==00,
 , 1, 2, Σ=
  = {,2}

 ′ = (′, Σ,  ′, ′,  ′) where


′ = 2 = {∅, {0}, {1}, {2}, {0, 1}, {0, 2}, {1, 2}, {0, 1, 2}}

 ′(, ) = {  ∣ ( , ,  ) ∈   and  ∈  }


60

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 60/114
7/16/2019 Curs Limbaje Formale si Automate

′ = {0}
 ′ = {
Algorithm NFA to DFA
—The Subset Construction
On entry: An NFA   = (, Σ,, , ).
On exit: A DFA  ′ = (′, Σ,  ′, ′,  ′)
satisfying ( ) = ( ′).
begin Let ′ = 2, ′ = {} and
 ′ = {  ∣   ∈ ′, and   ∩   =
∕ ∅}
We define  ′ : ′ × Σ → ′ by
For   ∈ ′ and for all  ∈ Σ,
′(,all =
  )  , if   ⊢   in  .
end of Algorithm
if    = {  ∣ ( , ,  ) ∈   and  ∈  }
61

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 61/114
7/16/2019 Curs Limbaje Formale si Automate

′ = {0}

Algorithm NFA to DFA 2


—The Iterative Subset Construction

62

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 62/114
7/16/2019 Curs Limbaje Formale si Automate

Theorem Given an NFA   = (, Σ,, , ), then


the DFA  ′ = (′, Σ′,  ′, ′,  ′) obtained by ei-
ther subset construction satisfies
( ′) = ( ).

Proof:

By Lemma 2.3.2, for all  ∈ Σ in  
 ⊢∗  , iff  {} ⊢∗   for some   with  ∈  

By the construction of   ′,


{} ⊢∗   in   iff 
{} ⊢∗   in  ′.

 ∈ ( ) ⇔  ⊢∗ , for some   ∈  


⇔ {} ⊢∗ ,   ∈ , in  
∗ ′
=∅
⇔ {′} ∗⊢ , in   and   ∩   ∕
⇔   ⊢ ,   ∈  
⇔  ∈ ( ′)

63

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 63/114
7/16/2019 Curs Limbaje Formale si Automate

Theorem
Every NFA Language is a DFA language and
conversely.
(ℒ  = ℒ )

Example

Every finite language is accepted by a DFA.

64

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 64/114
7/16/2019 Curs Limbaje Formale si Automate

–NFA

It is useful to loosen the definition of NFA


even more by allowing the read head to re-
main over the same symbol of the input and
read nothing.

Example
  
1 = {  ∣  ≥ 0,  ≥ 0}
M:

( ) = 1

  : (0, , 0)
(0, , 1)  − 
(1, , 1)
0 ⊢ 0 ⊢ 0 ⊢ 1 ⊢ 1
0 ⊢ 1 ⊢ 1 ⊢ 1
0 ⊢ 0 ⊢ 1

65

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 65/114
7/16/2019 Curs Limbaje Formale si Automate

Formally, a -NFA   = (, Σ,, , )

where , Σ,transition
  is a finite  ,    are as before, but
relation
for which

  ⊆  × (Σ ∪ {}) × 

Configurations are as before.


⊢ is defined by
  ⊢ 
if either  =  for  ∈ Σ and ( , ,  ) ∈  
or  =  and ( , ,  ) ∈  

Example
Given FA  1 and  2, construct
a FA  3 such that
( 3) = ( 1) ∪ ( 2)

66

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 66/114
7/16/2019 Curs Limbaje Formale si Automate

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   ∈  }
and  ′ =   ∪ {( , ,  ) ∣  ⊢+  }

Example:

67

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 67/114
7/16/2019 Curs Limbaje Formale si Automate

Claim 1: For any ,   ∈ ,


    if and only if   ⊢ ′  
  ⊢+
Claim 2: For any ,   ∈ ,  ∈ Σ∗,
  ⊢∗    if and only if   ⊢∗ ′  
Theorem: ( ′) = ( )

Example:

68

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 68/114
7/16/2019 Curs Limbaje Formale si Automate

(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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 69/114
7/16/2019 Curs Limbaje Formale si Automate

Claim Whenever

 ⊢∗   
for some   ∈  , we have
 ⊢∗ ′  
and vice versa.

Claim (  ) = ( )

Theorem
ℒ−  = ℒ  

70

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 70/114
7/16/2019 Curs Limbaje Formale si Automate

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 = (1, Σ1,  1, 1,  1) and


 2 = (2, Σ2,  2, 2,  2).
Construct a -NFA   = (, Σ, , ,  ) where
 = 1 ∪ 2 ∪ {}
Σ = Σ1 ∪ Σ2

  =  1 ∪  2 ∪ {(,,1), (,,2)}


  =  1 ∪  2

71

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 71/114
7/16/2019 Curs Limbaje Formale si Automate

Now we claim that ( ) = 1 ∪ 2

(1) Let  be a generic word in ( ).


 ∈ ( ) implies
 ⊢+     for some   ∈  1 or   ∈  2.
If    ∈  1, then  ⊢  1 ⊢∗    and then
1 ⊢∗ 1  . We know that  ∈ ( 1).
If    ∈  2,∗ then  ⊢  2 ⊢∗   . Since
2 ⊢ 2  , we know that  ∈ ( 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  ⊢  1 ⊢∗   . Therefore  ∈ ( ).
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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 72/114
7/16/2019 Curs Limbaje Formale si Automate

2. Complementation:
The complement of a DFA language  ⊆ Σ∗
is a DFA language.
Proof: There is a complete DFA
  = (, Σ,  ,  ,   ) with  = ( ). Define

  = (, Σ, ,  ,  −  )

3. Intersection:

1 and 2

 = 1 ∩ 2 = 1 ∪ 2

73

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 73/114
7/16/2019 Curs Limbaje Formale si Automate

4. Catenation:

The catenation of two DFA languages is a


DFA language:
 1 = (1, Σ1,  1, 1,  1);
 2 = (2, Σ2,  2, 2,  2).
( ) = ( 1)( 2)
  = (1 ∪ 2, Σ1 ∪ Σ2,  , 1,  2),
  =  1 ∪  2 ∪ {( ,,2) ∣   ∈  1}

  = (, Σ, ,  ,  ) where


 = 1 ∪ 2
Σ = Σ1 ∪ Σ2
  =  1 ∪  2 ∪ {( ,,2) ∣   ∈  1}
 = 
1
  =  2

74

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 74/114
7/16/2019 Curs Limbaje Formale si Automate

5. Star:
The star of a DFA language is a DFA language
 = ( ) where   = (, Σ, ,  ,  )

∗ = ( ′)
 ′ = (′, Σ′,  ′, ′,  ′) where
′ =  ∪ {′}
Σ′ = Σ
 ′ =   ∪ {(′,  , )} ∪ {( ,,′) ∣   ∈  }
 ′ =   ∪ {′}  ′ = {′}
6. Plus:

75

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 75/114
7/16/2019 Curs Limbaje Formale si Automate

II. Decidability Properties

A decision problem is a problem each in-


stance 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 ex-
ists 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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 76/114
7/16/2019 Curs Limbaje Formale si Automate

Proof: Compute for the given   and  the ter-


minating state   such that  ⊢∗  . If    ∈  
then answer “True” else answer “false”.

2. DFA Emptiness

INSTANCE: A DFA   = (, Σ, ,  ,  ).


QUESTION: Is ( ) = ∅ ?

Theorem DFA emptiness is decidable.

Proof: ( ) = ∅ iff there is no path in the


state diagram of    from  to a final 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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 77/114
7/16/2019 Curs Limbaje Formale si Automate

3. DFA Universality

INSTANCE: A DFA   = (, Σ, ,  ,  ).


QUESTION: Is ( ) = Σ∗ ?

Theorem DFA universality is decidable.


Proof:

4. DFA Containment

INSTANCE: Two DFA


 1 = (1, Σ1, 1, 1,  1) and
 2 = (2, Σ2, 2, 2,  2).
QUESTION: Is ( 1) ⊆ ( 2) ?
Theorem DFA containment is decidable.
Proof:

( 1) ∩ ( 2) = ∅ means that ( 1) ⊆ ( 2)

78

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 78/114
7/16/2019 Curs Limbaje Formale si Automate

5. DFA Equivalence

INSTANCE: Two DFA


 1 = (1, Σ1, 1, 1,  1) and
 2 = (2, Σ2, 2, 2,  2).
QUESTION: Is ( 1) = ( 2) ?

Theorem DFA equivalence is decidable.

( 1) ⊆ ( 2) ? yes


( 2) ⊆ ( 1) ? yes

79

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 79/114
7/16/2019 Curs Limbaje Formale si Automate

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) ∣ ∣ ≥ 1; and
(iii) for all  ≥ 0,   is in ( ).
Example   = (, Σ,, , ) where
 = {, ,  }, Σ = {, },
  = { }. # = 3

Let  be an arbitrary word of length ≥ #


in ( ), e.g.  = . The accepting conf.
sequence for  is:
 ⊢  ⊢  ⊢  ⊢  .
So,  = ,  = ,  =  and () ∈ ( ) for
all  ≥ 0.
80

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 80/114
7/16/2019 Curs Limbaje Formale si Automate

Proof of DFA Pumping Lemma:

Let  be in ( ) with ∣∣ ≥ .


Then   has an accepting configuration se-
quence
 012 . . .  ⊢  12 . . .  ⊢ . . . ⊢  −1 ⊢  

where  0 = ,   ∈  .


Consider the first  transitions. ,  1, . . . ,   
cannot all be distinct since there are only 
distinct states (by pigeonhole principle).
This means that   =    for some 0 ≤  <  ≤ .
Let
 = 1 . . . ,
 = +1 . . .   ,
 =   +1 . . .  .
So, we have  0 ⊢∗  
  ⊢∗    (  =    )
    ⊢∗   .
Since   =    ,    ⊢∗    for any  ≥ 0

81

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 81/114
7/16/2019 Curs Limbaje Formale si Automate

() ∣ ∣ ≤ , since  ≤ 


() ∣ ∣ ≥ 1, since  < 
()    ∈ ( ) for all  ≥ 0, since
 0   ⊢∗     ⊢∗     ⊢   ∈  
qed.

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 satisfies

() ∣ ∣ ≤ ,
() ∣ ∣ ≥ 1,

()   ∈ ( ) for all  ≥ 0.

82

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 82/114
7/16/2019 Curs Limbaje Formale si Automate

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

Review of logic:
if   then  ⇔ if  ¬ then ¬
if   then  ∕
⇔ if   then 
if   then  ∕
⇔ if  ¬ then ¬

Example
if
if it
it is
is sugar thenthen
not sweet it is it
sweet.
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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 83/114
7/16/2019 Curs Limbaje Formale si Automate

Non-DFA Language

 = { ∣  ≥ 0} is not a DFA Language


Proof (I):

Assume  is a DFA language. Then  = ( )


for some DFA   = (, Σ, , ,  ) with ∣∣ = .
 
Consider  =   , ∣lemma,
By DFA pumping ∣ ≥ . there is a decom-
position
 = 
which satisfies (i), (ii), and (iii).
Consider all the possible decompositions

Case 1 :  =  ,  ≥ 1.  ≤ 
But  0 = −  ∕∈ .
Case 2 :  =  ,  ≥ 1.
 0 = − ∕∈ .
 
Case 3 : Then
=  
, 2, =≥1.
   
  ∕ ∈ .
All the possible decompositions fail.
Therefore,  is not a DFA language.
84

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 84/114
7/16/2019 Curs Limbaje Formale si Automate

Proof (II):
..................
∣∣ = .
Consider  =    in . Obviously, ∣∣ ≥ .
By DFA pumping lemma, there is a decom-
position
 = 

that
Thesatisfies (i), (ii), and (iii).
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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 85/114
7/16/2019 Curs Limbaje Formale si Automate

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)
3) Choose
Considera all
word  of length
theinpossible ≥ .
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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 86/114
7/16/2019 Curs Limbaje Formale si Automate


 = {2 ∣  ≥ 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   which satisfy
(i) and (ii) are the following:
 =  ,  ≥  ≥ 1.
 +1
Notice that  = 2 − .
2 +1 > 2 +1 −  ≥ 2 +1 −  > 2 +1 − 2  = 2 
i.e., 2 +1 > 2 +1 −  > 2 .
2 +1 2 
∣ ∣ > ∣∣ > ∣ ∣.

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

87

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 87/114
7/16/2019 Curs Limbaje Formale si Automate

6. DFA Finiteness

INSTANCE: A DFA   = (, Σ,, , )


QUESTION: Is ( ) finite?
It is decidable.
Theorem ( ) is finite iff 
  accepts no words  that satisfy

∣∣ ≤ ∣∣ < 2∣∣


Proof: If: Assume   accepts no words  with
∣∣ ≤ ∣∣ < 2∣∣ and ( ) is infinite. Since
( ) is infinite, it must accept some word
 with ∣∣ ≥ 2∣∣. By P.L.,  =  with
∣∣ ≥ ∣ ∣ ≥ 1, and ′ =  is in ( ). No-
tice 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, ( ) is infi-
nite.

88

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 88/114
7/16/2019 Curs Limbaje Formale si Automate

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 defining
( ,  (),  ) is in  ′ iff   ( , ) =  .
 ′ is a lazy FA. So, L(M’) is a DFA language.
It is not difficult to show that ( ′) =  ().
Therefore,  () is a DFA language. 

89

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 89/114
7/16/2019 Curs Limbaje Formale si Automate

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 defines
— a function   : Σ∗ → Δ∗, if it is single-valued,
—a relation  ⊆ Σ∗ × Δ∗, otherwise.
A function or a relation that is defined by a
transducer is called a transduction (transla-
tion).

90

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 90/114
7/16/2019 Curs Limbaje Formale si Automate

Specifically, a finite automaton with output


is called a finite 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 finite transducer (FT)   is a six-


tuple (, Σ, Δ,, , ) where
Δ is an output alphabet;
  ⊆  × (Σ ∪ {}) ×  × Δ∗ is a finite transition
relation;
the others are the same as in a FA.

91

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 91/114
7/16/2019 Curs Limbaje Formale si Automate

A configuration  is a word in Δ∗Σ∗.

 — output till now;


  — current state;
 — remaining input.

We write
 ⊢ 
if  ( , , ,  ) is in  .
⊢, ⊢+, ⊢∗ are defined as usual.

Given  ∈ Σ∗, we say that  is an output for


 w.r.t.   if 
 ⊢∗  
for some   ∈  .
Let  () be the set of all outputs for , then
 () = { ∣  ⊢∗   for some   ∈  }.
The transduction or translation defined by  
is  ( ) = {(, ) ∣  ∈ Σ∗ and  ∈  ()}

92

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 92/114
7/16/2019 Curs Limbaje Formale si Automate

Example  :

0 ⊢ 0 ⊢ 1 ⊢ 1


⊢ 1 ⊢ 2 ⊢ 2
i.e. 0 ⊢∗ 2
Since 2 ∈  , we say  ∈  (),
and (, ) ∈  ( ).
We can see that
 ( ) = {(   ,   ) ∣ ,, ≥ 0}
Example
Let ℎ() = 101, ℎ() = 11.
Encoding:

Decoding:

93

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 93/114
7/16/2019 Curs Limbaje Formale si Automate

REGULAR EXPRESSIONS
— The Second Model for Defining Languages

Example:
Consider the language of all the words that
consist of  ’s and ’s and have  as a sub-
word.
We can formally define 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 definitions are lengthy.


It can also be expressed by
([ ∪ ]∗[ ∪ ]∗)

94

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 94/114
7/16/2019 Curs Limbaje Formale si Automate

Definition Let Σ be an alphabet.


A regular expression over Σ is defined recur-
sively:
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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 95/114
7/16/2019 Curs Limbaje Formale si Automate

[[ + ]]∗ is the same as [[ ∪ ]]∗


Example:
 1  2
  

[[  ∪  ]  ]∗ is a R.E. over {, }


  

  
     

 3  4
      

 5

We display
expression the “parsing” by an
tree:



  

What language does an R.E. define?


∗ {, }∗
⋅ {, }

{, } ∪ {}
{} {}

96

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 96/114
7/16/2019 Curs Limbaje Formale si Automate

Definition Given a regular expression  , the


language ( ) denoted by   is defined as fol-
lows:
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 ∪ [ 2 ∪  3];
So, [ 1 ∪  2] ∪  3 ⇒  1 ∪  2 ∪  3.
⋅: [ 1 2] 3 ≡  1[ 2 3];
So, [ 1 2] 3 ⇒  1 2 3.

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

97

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 97/114
7/16/2019 Curs Limbaje Formale si Automate

Definition A language  is regular iff there is

a regular expression   such that  = ( ).

The family of (all) regular languages is


denoted by ℒ.

∗ ∗ ∗ ∗
Example ∣ =in[ {
 = {   , ]}∗and
.  contains an even
number of  ′}.
Claim: ( ) = 
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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 98/114
7/16/2019 Curs Limbaje Formale si Automate

Examples Σ = {, }.


1 = { ∣  = ,  ∈ Σ∗}.

2 = { ∣ ∣∣ ≡ 0 mod 3}.


[[]]∗

3 = { ∣  has 2 or 3 ′ with the last two


appearances nonconsecutive }

4 = { ∣  = ,  ≥ 1}

99

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 99/114
7/16/2019 Curs Limbaje Formale si Automate

Examples
What are the languages denoted by the fol-
lowing R.E.’s ?

 1 = ∗∗

 2 = [ ∪ ]∗

 3 = [ ∪ ]∗

  = [ ∪  ∪  ∪ ]∗
4

100

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 100/114
7/16/2019 Curs Limbaje Formale si Automate

How many languages over Σ do R.E.’s define?


Σ = {, }

(1) Infinitely many ?

(2) Countable ?

101

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 101/114
7/16/2019 Curs Limbaje Formale si Automate

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

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 102/114
7/16/2019 Curs Limbaje Formale si Automate

(iv)   = [ 1 ∪  2].


Construct   such that ( ) = ( 1) ∪ ( 2).

(v)   = [ 1 2].
Construct   such that ( ) = ( 1)( 2).

(vi)  =  1∗.
Construct   such that ( ) = ( 1)∗.

103

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 103/114
7/16/2019 Curs Limbaje Formale si Automate

Example
∗ ∗ ∗
  = [ [ ∪ [
Construct ]] ]   such that ( ) = ( ).
a FA

△ , ,  by (iii)


△  by (vi)

△ [∗] by (v)

△ [ ∪ ∗] by (iv)

△ [ ∪ ∗]∗ by (vi)

△ [∗[ ∪ ∗]∗] by (v)

104

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 104/114
7/16/2019 Curs Limbaje Formale si Automate

Theorem For  , an arbitrary regular expres-


sion over Σ, the -NFA,  , constructed as
above satisfies ( ) = ( ).
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   with ( ) ≤
 , for some  ≥ 0.

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 satisfies ( ) = ( 1) ∪ ( 2),
and ( ) = ( 1) ∪ ( 2)
105

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 105/114
7/16/2019 Curs Limbaje Formale si Automate

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 in-
duction. ...

106

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 106/114
7/16/2019 Curs Limbaje Formale si Automate

Finite Automata into Regular Expressions

To prove that every DFA language is regular

we introduce an extension of finite automata.

Definition An extended finite automaton


(EFA),  , is a quintuple (, Σ, , ,  ) where
, Σ,  are as in -NFA,
  is the only final state,   ∕
= ,
  :  ×  → Σ is a total extended transition
function.

Example of an EFA:

 (( ,
  ) =
,  ) = ∅∅
......
One final state   ∕
=

107

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 107/114
7/16/2019 Curs Limbaje Formale si Automate

△ A configuration is in Σ∗
△ Move
  ⊢  if 
(i)  = ,  ∈ Σ∗,
(ii)  ( ,  ) = , and
(iii)  ∈ ( ).
△ ⊢∗, ⊢+ are defined similarly as before.

Lemma If    is a DFA, Then there is an EFA


 ′ with ( ′) = ( ).

Example DFA into EFA.

108

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 108/114
7/16/2019 Curs Limbaje Formale si Automate

Example:

An
M:extended finite Automaton (EFA).

Check if the following words are in ( )

(1) 

(2) 
(3) 

(4) 

109

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 109/114
7/16/2019 Curs Limbaje Formale si Automate

State Elimination Technique


Goal of the technique:

i.e.:

(1) EFA has 2 states

Example

110

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 110/114
7/16/2019 Curs Limbaje Formale si Automate

(2) EFA   has  + 1 states,  ≥ 2.


  : eliminate a state from   to form   :


Then

Note:   ∈  − {,  }


Consider all transitions ( ,   ,  )
and (,   , )

  :

 ′( ,   ) =  ( ,   ) ∪  ( ,  )( (,  ))∗ (,   )


111

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 111/114
7/16/2019 Curs Limbaje Formale si Automate

Example

∗[ ∪ ∗]∗

112

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 112/114
7/16/2019 Curs Limbaje Formale si Automate

Example

113

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 113/114
7/16/2019 Curs Limbaje Formale si Automate

Summary of the State Elimination Technique

(0)
(1) Change FA start
Add a new into EFA
state if the original one
has incoming transitions.
(2) Add a new final state if there are more
than one final states originally. Old final
states become non-final states.
(3) Eliminate the states in  − {,  }
one by one.
(4) Eliminate the transition  (,  ).

http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 114/114

S-ar putea să vă placă și