Documente Academic
Documente Profesional
Documente Cultură
Vdocuments - MX - Curs Limbaje Formale Si Automate PDF
Vdocuments - MX - Curs Limbaje Formale Si Automate PDF
˘
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)
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 2/114
7/16/2019 Curs Limbaje Formale si Automate
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 3/114
7/16/2019 Curs Limbaje Formale si Automate
Programming AI
Database Graphics
Compiler VLSI
Theory of Computing
(1) Putere de calcul
(2) Complexitate
.....................
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.
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 5/114
7/16/2019 Curs Limbaje Formale si Automate
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 6/114
7/16/2019 Curs Limbaje Formale si Automate
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 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
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
— 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}}
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
Notatii:
functie : →
asocierea () =
nedefinita () =
Functii speciale:
functia identitate:
: → si
() = pentru toti ∈
12
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 12/114
7/16/2019 Curs Limbaje Formale si Automate
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
() = (()) si () = Ω(())
13
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 13/114
7/16/2019 Curs Limbaje Formale si Automate
: 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
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
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 ⊆ ×
17
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 17/114
7/16/2019 Curs Limbaje Formale si Automate
∙ reflexiva,
∙ simetrica, si
∙ tranzitiva.
18
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 18/114
7/16/2019 Curs Limbaje Formale si Automate
:=
{9, 4,patratul
“este 3, 2}; lui” (“is the square
of”)
Atunci este -inchisa.
19
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 19/114
7/16/2019 Curs Limbaje Formale si Automate
△ Inchidere
20
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 20/114
7/16/2019 Curs Limbaje Formale si Automate
6. Cardinalitate
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 directa
Enumeram toate cazurile pentru a arata ca
proprietatea este adevarate.
22
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 22/114
7/16/2019 Curs Limbaje Formale si Automate
– 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.
23
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 23/114
7/16/2019 Curs Limbaje Formale si Automate
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
25
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 25/114
7/16/2019 Curs Limbaje Formale si Automate
26
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 26/114
7/16/2019 Curs Limbaje Formale si Automate
Examples:
(1) English alphabet, words and language.
27
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 27/114
7/16/2019 Curs Limbaje Formale si Automate
△ 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
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
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
31
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 31/114
7/16/2019 Curs Limbaje Formale si Automate
Example:
Σ = {0, 1}, Δ = {, , , },
ℎ(0) = , ℎ(1) = .
Then ℎ(1001) = ℎ(1)ℎ(0)ℎ(0)ℎ(1) = =
32
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 32/114
7/16/2019 Curs Limbaje Formale si Automate
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
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
Examples
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
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(23) = (12)3
Identity — {} = {} =
Zero — = =
Distributivity — 1(2 ∪ 3) = 12 ∪ 13
w.r. ∪ — (1 ∪ 2)3 = 13 ∪ 23
Distributivity does not hold with respect to
∩
+ =
=∗∪ {} ( 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
40
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 40/114
7/16/2019 Curs Limbaje Formale si Automate
41
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 41/114
7/16/2019 Curs Limbaje Formale si Automate
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:
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
⊢ 0
can ⊢ 1be
also 2
⊢ viewed as a function
⊢ : Σ∗ → Σ∗,
since the next configuration is determined
uniquely for a given configuration.
45
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 45/114
7/16/2019 Curs Limbaje Formale si Automate
Examples
( ) =
( ) =
46
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 46/114
7/16/2019 Curs Limbaje Formale si Automate
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
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 47/114
7/16/2019 Curs Limbaje Formale si Automate
/*................*/
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 48/114
7/16/2019 Curs Limbaje Formale si Automate
49
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 49/114
7/16/2019 Curs Limbaje Formale si Automate
ℒ .
△
= { ∣ ≥ 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
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.
52
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 52/114
7/16/2019 Curs Limbaje Formale si Automate
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
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
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
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 56/114
7/16/2019 Curs Limbaje Formale si Automate
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
⊢
57
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 57/114
7/16/2019 Curs Limbaje Formale si Automate
58
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 58/114
7/16/2019 Curs Limbaje Formale si Automate
59
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 59/114
7/16/2019 Curs Limbaje Formale si Automate
==00,
, 1, 2, Σ=
= {,2}
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}
62
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 62/114
7/16/2019 Curs Limbaje Formale si Automate
Proof:
∗
By Lemma 2.3.2, for all ∈ Σ in
⊢∗ , iff {} ⊢∗ for some with ∈
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
64
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 64/114
7/16/2019 Curs Limbaje Formale si Automate
–NFA
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
where , Σ,transition
is a finite , are as before, but
relation
for which
⊆ × (Σ ∪ {}) ×
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
Two steps:
Step I: − completion
Step II: − transition removal
(I). -Completion
Given a -NFA = (, Σ,, , )
perform the following process:
Example:
67
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 67/114
7/16/2019 Curs Limbaje Formale si Automate
Example:
68
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 68/114
7/16/2019 Curs Limbaje Formale si Automate
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.
71
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 71/114
7/16/2019 Curs Limbaje Formale si Automate
( ) = 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:
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
1. DFA membership
INSTANCE: A DFA = (, Σ, , , )
and a word ∈ Σ∗.
QUESTION: Is ∈ ( ) ?
76
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 76/114
7/16/2019 Curs Limbaje Formale si Automate
2. DFA Emptiness
77
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 77/114
7/16/2019 Curs Limbaje Formale si Automate
3. DFA Universality
4. DFA Containment
78
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 78/114
7/16/2019 Curs Limbaje Formale si Automate
5. DFA Equivalence
79
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 79/114
7/16/2019 Curs Limbaje Formale si Automate
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 80/114
7/16/2019 Curs Limbaje Formale si Automate
81
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 81/114
7/16/2019 Curs Limbaje Formale si Automate
() ∣ ∣ ≤ ,
() ∣ ∣ ≥ 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
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.
83
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 83/114
7/16/2019 Curs Limbaje Formale si Automate
Non-DFA Language
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
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
88
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 88/114
7/16/2019 Curs Limbaje Formale si Automate
Proof:
89
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 89/114
7/16/2019 Curs Limbaje Formale si Automate
I in Σ∗ O in Δ∗
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
Input tape
read-only head
Finite control
write-only head
Output tape
91
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 91/114
7/16/2019 Curs Limbaje Formale si Automate
We write
⊢
if ( , , , ) is in .
⊢, ⊢+, ⊢∗ are defined as usual.
92
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 92/114
7/16/2019 Curs Limbaje Formale si Automate
Example :
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:
94
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 94/114
7/16/2019 Curs Limbaje Formale si Automate
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
3 4
5
We display
expression the “parsing” by an
tree:
∗
⋅
∪
{, } ∪ {}
{} {}
96
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 96/114
7/16/2019 Curs Limbaje Formale si Automate
Properties of R.E.’s
..........................................
97
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 97/114
7/16/2019 Curs Limbaje Formale si Automate
∗ ∗ ∗ ∗
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
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 = [ ∪ ]∗
= [ ∪ ∪ ∪ ]∗
4
100
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 100/114
7/16/2019 Curs Limbaje Formale si Automate
(2) Countable ?
101
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 101/114
7/16/2019 Curs Limbaje Formale si Automate
(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
(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)
104
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 104/114
7/16/2019 Curs Limbaje Formale si Automate
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
....................................
....................................
106
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 106/114
7/16/2019 Curs Limbaje Formale si Automate
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.
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).
(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
i.e.:
Example
110
http://slidepdf.com/reader/full/curs-limbaje-formale-si-automate 110/114
7/16/2019 Curs Limbaje Formale si Automate
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
(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