You are on page 1of 19

1 Not iuni elementare de matematica

1.1 Mult imi


Mult ime=colect ie de obiecte numite elemente.
Example 1.1. A-mult ime
Mod de descriere:
1. Prin enumerare A = {a, b, c, d}
2. Prin enunt area unei proprietat i comune A = {n|n numar par}
Submult ime=o mult ime format a din elemente ale unei mult imi date.
Example 1.2. A = {a, b, c, d}
B = {a, b}
B A (B este submult ime a lui A)
Mult imea vida=mult imea ce nu cont ine nici un element .
Mult imea part ilor. Unei mult imi A i se asociaza mult imea tuturor submult imilor
sale numit a mult imea p art ilor lui A.
Example 1.3. A = {a, b, c, d} P(A) = {{a}, {b}, {c}, {d}, {a, b}, {a, c}, {a, d}, {b, c}, {b, d}, {c, d}, {a, b, c}, {a, b, d}, {a, c, d}, {b, c, d}, {a, b, c, d}}
Observation 1.1. Daca A are 4 elemente atunci P(A) are 2
4
= 16 ele-
mente. Daca |A| noteaza numarul elementelor unei mult imi sau cardinalul
acesteia atunci are loc:
|A|-nita, atunci |P(A)| = 2
|A|
.
Mult imi innite: Mult imea numerelor naturale Nmult ime innita
num arabil a
Mult imea numerelor reale Rmult ime innit a nenumarabila.
1.2 Submult ime complementara. Complement
A-mult ime dat a. B A, atunci C
B
= {x A|x B}
Example 1.4. A = {a, b, c, d}, B = {b, d}, C
B
= {a, c}
Observation 1.2. Mult imea part ilor P(A) cont ine cu ecare submult ime a
lui A si complementul acesteia.
1
1.3 Operat ii cu mult imi
1.

-reuniunea
A, B dou a mult imi
A B = {x|x A sau x B}
Example 1.5. A = {a, c}, B = {b, d}, A B = {a, b, c, d}
2. Intersect ia
A, B dou a mult imi.
A B = {x|x A si x B}.
Example 1.6. A = {a, b, c}, B = {b, c, d}, A B = {b, c}
3. Produs cartezian
A, B dou a mult i. Mult imea perechilor ordonate (a, b) cu a A si b B
se numeste produs cartezian a mult imilor A si B.
A B = {(a, b)|a A, b B}
Example 1.7. A = {a, b}, B = {1, 2}, AB = {(a, 1), (a, 2), (b, 1), (b, 2)}.
Date dou a mult imi A si B. Numim relat ie orice submult ime a produsului
cartezian A B. Daca este o relat ie pe mult imea A, adic a A A,
putem deni:

2
:= {(x, y) A A|z A, (x, z) , (z, y) }

0
:= {(x, x)} =

n
:= {(x, y) AA|z
1
, z
2
, . . . z
n1
A, (x, z
1
) , (z
1
, z
2
) , . . . , (z
n1
, y)
}.
Dac a
+
:=

n1

n
, atunci
+
este relat ie tranzitiva numit a si nchiderea
tranzitiv a a relat iei .

:=
+
=

n0

n
, atunci

este si reexiv a, deci

este nchiderea
reexiv a si tranzitiv a a lui .
Propriet at i ale relat iei pe o mult ime( A A)
1. reexivitatea (x, x)
2. tranzitivitate (x, y) , (y, z) (x, z)
3. simetrie (x, y) (y, x)
4. antisimetrie (x, y) si (y, x) x = y
2
Relat ie funct ionala
A B e relat ie funct ional a dac a = {(x

, y

) : x

A, y

B}
f : A B. Funct ia f denit a pe A cu valori n B A x f(x) B

f
= {(x, f(x))|x A}.
Mult imea nit a V se numeste alfabet.
Elementele lui V se numesc simboluri sau litere.
String=nsiruire de simboluri.
cuv ant =string.
V

=mult imea string-urilor peste alfabetul V .
V + = V

{}, cuv antul string-ul vid.
O submult ime a lui V

cu proprietat i specice se va numi limbaj.
Observation 1.3. Un limbaj este o mult ime cel mult numarabila.
1.4 Operat ii
1. Concatenare
p L, p

, atunci L L

= {pp

|p L, p

}
G = (V, T, S, P)
V, Talfabet
V mult imea variabilelor
Tmult imea simbolurilor terminale
S V -simbol de start
P-mult imea product iilor
Observation 1.4. Product iile specica regulile dupa care se trans-
forma un string n altul.
P (V T)
+
(V T)

. Daca (x, y) P notam aceasta prin x y.


Mod de funct ionare:
Un string z = uxv se transforma n w = uyv n baza product iei x y.
Aceasta se noteaza prin z w si spunem ca w se deriva din z

nchiderea reexiva si tranzitiva a relat iei


+
nchiderea tranzitiva a relat iei
Denition 1.1. Dat a o gramatic a G = (V, T, S, P), numim limbajul gra-
maticii G mult imea
L(G) = {w T

: S

w}
Example 1.8. G = ({S}, {a, b}, S, P), P = {S aSb, S }.
Putem face urmatoarele derivari:
S aSb aaSbb aabb, deci S

aabb.
3
Deci aabb este un cuvant al limbajului L(G).
Example 1.9. Sa se demonstreze ca L(G) = {a
n
b
n
; n 0}.
Example 1.10. Se da limbajul L = {a
n
b
n+1
; n 0}. Gasit i o gramatica
care genereaza limbajul L.
Fat a de exemplul anterior avem nevoie de posibilitatea de a genera un b n
plus. O product ie adit ionala S Ab, unde A este limbajul denit n exemplul
1.8. Deci
G = ({S, A}, {a, b}, S, P) cu P = {S Ab; A aAb, A } genereaza
limbajul L.
Example 1.11. G = ({S}, {a, b}, S, P), P = {S SS; S ; S
aSb; S bSa} genereaza limbajul
L = {w : n
a
(w) = n
b
(w)}
unde n
a
(w), respectiv n
b
(w) seminca numarul de auri respectiv de buri
din cuvantul w.
Exercit iu 1.1.
|u
n
| = n |u|, u string, n N.
Exercit iu 1.2. Putem deni inversul unui string recursiv
a = a
( wa) = a w, a V, w V

.
Sa se arate ca uv = v u, u, v V
+
.
Exercit iu 1.3.

u = u, u V

Exercit iu 1.4. L = {ab, aa, baa}
Care din urmatoarele string-uri apart in lui L

?
i) abaabaaabaa
ii) baaaaabaaaaab
iii) aaaabaaaa
iv) baaaaabaa
4
2 Clasicarea gramaticilor. Ierarhia Chom-
sky
G = (V, T, S, P), P (V T)

V (V T)

(V T)

L(G) = {p T

|S

p}.
Gramatica de tip 0-f ara restrict ii asupra product iilor
Gramatic a de tip 1(dependente de context)
uAv upv, A V, p (V T)
+
, u, v (V T)

, S
Gramatici de tip 2(independente de context)
A p, A V, p (V T)

A p
A
Gramatic a de tip 3(regulate)
A Bp, A, B V, p T

C q, C V, q T

.
Exercit iu 2.1. Gasit i gramatici pentru V = {a, b}, care genereaza limba-
jele
L
1
= {w; n
a
(w) = 1}
L
2
= {w; n
a
(w) 1}
L
3
= {w; n
a
(w) 3}.
Un limbaj se numeste liber daca nu cont ine cuvantul vid.
O regul a (product ie) de tip p se numeste regula de stergere. Dac a L
i
noteaz a mult imea limbajelor generate de gramatici de tip i {0, 1, 2, 3}atunci
putem stabili sirul de incluziuni
L
0
L
1
L
2
L
3
Este evident c a orice gramatic a de tip 1, 2 sau 3 este si de tip 0. Asemenea
este evident c a orice gramatic a de tip 3 este si de tip 2. Deci incluziunile
L
0
L
1
si L
2
L
3
sunt stabilite.
Theorem 2.1. Orice limbaj generat de o gramatica de tip 2 poate generat
de o gramatica de tip 1.
Proof. G gramatic a de tip 2
i) L(G) exist a gramatica de tip 1, G

f ara reguli de stergere


L(G

) = L(G), G

gramatic a de tip 1.
ii) L(G) exist a gramatica de tip 2, G

cu regula de stergere S

,
iar S

nu apare n nici o product ie cu L(G

) = L(G)
5
Lemma 2.1. (Lema de localizare) Fie G = (V
N
, V
T
, S, P) o gramatica
independenta de context. Pentru orice derivare X
1
, X
2
, . . . , X
n

p cu
X
1
, X
2
, . . . , X
n
V, p V

, exista p
1
, p
2
, . . . , p
n
V

astfel ncat p =
p
1
p
2
p
m
si X
j

p
j
, j {1, 2, . . . , m}.
Proof. X
1
, X
2
, . . . , X
n

p, X
1
, X
2
, . . . , X
n
V, p V

. Induct ie dup a
lungimea l N a derivarii.
Fie l = 0 X
1
X
2
. . . X
m
= p
Alegem p
1
= X
1
, p
2
= X
2
, . . . , p
m
= X
m
. Evident cu aceste alegeri p
1
p
2
. . . p
m
=
p
x
j

p
j
, j. Presupunem c a pentru orice derivare de lungime l Nare loc
enunt ul:
Fie derivarea de lungime l
1
, X
1
X
2
. . . X
m

p, X
1
, X
2
, . . . , X
m
V, p V

X
1
X
2
. . . X
m

q p-lungimea l.
Conform ipotezei de induct ie q
1
, q
2
, . . . q
m
V

astfel nc at q = q
1
q
2
. . . q
m
si x
j

q
j
de lungime mai mic a decat l, pentru orice j {1, 2, . . . , m}
q p
O derivare direct a esyte o product ie mbr acata ntr-un context
q
Ax
p q = q

Aq

, p = q

xq

, A V
N
, x V

, q

, q

V

k {1, 2, . . . , m} astfel nc at q
k
= q
k
Aq
k

= q
k
q
k+1
. . . q
m
p = q

xq

= (q
1
q
2
. . . q
k1
q
k
)x(q
k
q
k+1
. . . q
m
).
Alegem
p
1
= q
1
, p
2
= q
2
. . . , p
k1
= q
k1
, p
k
= q
k
xq
k
, p
k+1
= q
k+1
, p
m
= q
m
.
p
1
p
2
. . . p
m
= q
1
q
2
. . . q
k1
q
k
xq
k
q
k+1
. . . q
m
= p.
x
j

p
j
x
k

q
k
Ax
p
k
.
Orice derivare ntr-o gramatic a independent a de context se factorizeaz a n
tr-un num ar netrivial de derivare.
Lemma 2.2. Lema de eliminare a regulilor de stergere. Orice limbaj de
tip 2 liber poate generat de o gramatica de tip 1 fara reguli de stergere.
Proof. Fie gramatica de tip 2 G = (V
N
, V
T
, S, P) avand limbajul L(G) .
Denim mult imile U
1
= {X V
N
|X P}
U
k+1
= {X V
N
|p U

k
, X p P}, k N

.
Sirul de mult imi (U
k
)
k1
este crescator.
Demonstr am c a U
k
U
k+1
prin induct ie dupa k N

.
Fie X U
1
X P, U

1
X U
2
.
Presupunem ca U
k
U
k+1
U

k
U

k+1
.
Fie X U
k+1
p U

k
astfel nc at X p P p U

k+1
astfel nc at
6
X p P X U
k+2
U
k+1
U
k+2
.
U
1
U
2
V
N
nit a (U
k
)
k1
este stat ionar, adica f N

astfel
ncat U
f
= U
f+1
= U
f+2
= = U U =

k1
U
k
.
Se poate demonstra c a pentru orice X V
N
avem X U X

.
Construim gramatica G

= (V
N
, V
T
, S, P) astfel:
Dac a X p P cu X V
N
si p V
+
, atunci includem aceast a product ie
n P

, mpreun a cu toate product iile de forma X q, unde q V


+
si se
obt ine din p prin ndep artarea n toate modurile posibile a unor simboluri
din V.
Theorem 2.2. L
1
L
2
. Orice limbaj de tip 2 este si de tip 1.
Proof. Fie G = (V
N
, V
T
, S, P) o gramatic a de tip 2. Avem doua cazuri:
a) L(G). Din lema precedenta exista o gramatic a G

de tip 1 f ar a
reguli de stergere cu L(G) = L(G

).
b) L(G). Repet am construct ia gramaticii G

din lema precendet a.


L(G

) = L(G){} Construim o gramatic a G

= (V
N
{S

}, V
T
, S

, P

),
unde S

V , iar P

= {S

S|} P

.
G gramatica de tip 1.
L(G

) = L(G

) {} = L(G) {} {} = L(G).
Lemma 2.3. Lema de eliminare a regulilor de stergere.
Orice limbaj de tip 2, liber poate generat de o gramatica de tip 1 fara
reguli de stergere.
Proof. Fie gramatica de tip 2 G = (V
N
, V
T
, S, P) avand limbajul L(G) .
Denim mult imile U
1
= {X V
N
|X P}.
U
k+1
= {X V
N
|p U

k
astfel nc at X p P}; k N

.
Sirul de mult imi (U
k
)
k1
este crecator.
Demonstr am c a U
k
U
k+1
prin induct ie dupa k N

. Fie X U
1
X
P, U

1
X U
2
.
Presupunem ca U
k
U
k+1
U

k
U

k+1
.
Fie X U
k+1
p U

k
astfel nc at X p P p U

k+1
astfel nc at
X p P X U
k+2
U
k+1
U
k+2
.
U
1
U
2
U
3
V
N
nit a. Atunci (U
k
)
k1
este stat ionar, adica exista
f N

astfel nc at U
f
= U
f+1
= U
f+2
= = U. Rezult a c a U =

k1
U
k
. Se
poate demonstra c a pentru orice x V
N
avem:
X U X


7
Construim gramatica G

= (V
N
, V
T
, S, P) astfel: dac a X p P cu x V
N
si p V
+
, atunci includem aceast a product ie n P

, mpreuna cu toate
product iile de forma X q, unde q V
+
si se obt ine din p prinndep artarea
prin toate modurile posibile a unor simboluri din V .
Example 2.1. X ABC P, A, B, C V, X V
N
.
a) A, B U, C U : p

X ABC, X BC, X AC, X C


b) A, B, C U : p

X ABC, X BC, X AC, X AB, X


C, X B, X A.
Observam ca prin aceasta construct ie au disparut regulile de stergere si au
aparut n loc alte product ii noi. Evident G

este o gramatica de tip 1(2) fara


reguli de stergere.
Demonstram ca L(G) = L(G

)
L(G) L(G

)
Vom demonstra ca daca X

p si derivarea are loc n gramatica G, cu
X V
N
si p V

T
, atunci X

p. Induct ie dupa lungimeal 1 a derivarii
X

p
l = 1, X

p X p P X p P

X
G

p.
Presupunem armat ia adevarata pentru orice lungime i l N

. Fie X

p X
G
X
G
y
1
y
2
. . . y
n

p, y
1
, y
2
, . . . , y
n
V .
Din lema de localizare rezulta ca exista p
1
, p
2
, . . . , p
n
V

T
astfel ncat Y
j

p
j
, j, p
1
, p
2
, . . . , p
m
= p.
Avem trei cazuri:
a) y
j
V
T
, atunci p
j
= y
j
, atunci y
j

p
j
b) y
j
V
N
, p
j
= l, atunci y
j

p
j
c) y
j
V
N
, p
j
= , atunci y
j
U.
Denim mult imea J = {j|p
j
= } = .
X
G
y
1
y
2
. . . y
m
X y
1
y
2
. . . y
m
P X y P

.
Avem derivarea
X
G

jJ
p
j
= p
Fie p L(G) S
G
p S
G

p p L(G

) L(G) L(G

).
L(G

) L(G)
8
p L(G

) S
G

p
S
G

u
G

V
G

p.
Presupunem ca u
G

V provine din product ia X Y P

P.
u = u

xu

v = u

yu

, x V
N
, y V

se obt ine prin eliminarea unor simboluri din U.
X Z P, z = y
1
z
1
y
2
z
2
. . . y
m
z
m
, unde z
1
, z
2
, . . . , z
m
U si y
1
, y
2
, . . . , y
m
=
y
X
G
Z = Y
1
Z
1
. . . Y
m
Z
m+1

G
Y
1
Y
2
. . . Y
m+1
X
G
Y u = u

xu


G
u

yu

= v S
G
p p L(G).
Theorem 2.3. L
1
L
2
. Orice limbaj de tip 2 este si de tip 1.
Proof. Fie G = (V
N
, V
T
, S, P) o gramatic a de tip 2. Avem doua cazuri:
a) L(G). Din lema precedenta exista o gramatica G

de tip 1 f ar a
reguli de stergere cu L(G) = L(G

).
b) L(G). Repet am construct ia gramaticii G

din lema precedenta.


L(G

) = L(G){}. Construim o gramatic a G

= (V
N
{S

}, V
T
, S

, P

),
unde S

V , iar P

= {S

S|} P

gramatic a de tip 1
L(G

) = L(G

) {} = L(G) {} {} = L(G).
3 Proprietat i de nchidere ale familiilor de
limbaje
A mult ime
o operat ie pe A
B submult ime a lui A
B se numeste nchisa relatic la dac a x y B, x, y B.
Lemma 3.1. Lema de nchidere la reuniune.
Familia de limbaje L
j
, j {0, 1, 2, 3} este nchisa relat iv la reuniune.
Proof. Fie G
1
= (V
N
1
, V
T
1
, S
1
, P
1
), G
2
= (V
N
2
, V
T
2
), S
2
, P + 2 doua gramatici
de tip j {0, 1, 2, 3}. Se poate presupune ca V
1
V
2
= .
V
1
= {a, A, b, B, c, C}
V
2
= {a, b, c}
V
2
= {a, b, c}. Fie gramatica G = (V
N
1
V
N
2
{S}, V
T
1
V
T
2
, S, P
1
P
2
{S
9
S
1
}S
2
), unde S V
1
V
2
.
Se constata c a G are acelasi tip cu G
1
si G
2
L(G) = L(G
1
) L(G
2
)
L(G) L(G
1
) L(G
2
). Fie p L(G) rezulta c a p V

T
si S
G
p.
Dac a S
1

G
p atunci S
1

G
1
p p V

T
1
p L(G).
L(G
1
) L(G
2
) L(G)?
Fie p L(G
1
) p V

T
1
si S
1

G
1
p S
G
S
1

G
p p L(G). Analog
p L(G
2
) p L(G
2
) L(G
1
) L(G
2
) L(G).
Lemma 3.2. Lema de nchidere la produs
Familia L
j
este nchisa relativ la produs.
Proof. j = 2
Fie G
1
= (V
N
1
, V
T
1
, S
1
, P
1
) si G
2
= (V
N
2
, V
T
2
, S
2
, P
2
) doua gramatici de tip 2
si e G = (V
N
1
V
N
2
{S}, V
T
1
V
T
2
, S, P
1
P
2
{S S
1
S
2
}) cu V
1
V
2
= ,
unde S V
1
V
2
.
Observ am c a G este de tip 2.
L(G) L(G
1
)L(G
2
).
L(G) L(G
1
)L(G
2
).
Fie p L(G) p V

T
si S
G
p.
S S
1
S
2

G
p p
1
, p
2
V

T
astfel nc at S
1

G
p
1
, S
2

G
p
2
, p
1
p
2
= p
S
1

G
p
1
S
1

G
1
p
1
, p
1
V

T
1
p
1
L(G
1
).
S
2

G
p
2
S
2

G
2
p
2
, p
2
V

T
2
p
2
L(G
2
) p L(G
1
)L(G
2
)
Ar atam c a L(G
1
)L(G
2
) L(G)
Fie p
1
L(G
1
) p
1
V

T
1
, S
1

G
1
p
1
S
1

G
p
1
p
2
L(G
2
) p
2
V

T
2
, S
2

G
2
p
2
S
2

G
p
2
. De aici avem c a S
1
S
2

G
p
1
p
2
S
G
S
1
S
2

G
p
1
p
2
p
1
p
2
L(G).
j = 3
G = (V
N
, V
T
, S, P) de tip 3
P =

A Bp(categoria1)
C q(categoria2)
A, B, C V
N
, p, q V

T
, r L(G), S
G
r
Fie G
1
= (V
N
1
, V
T
1
, S
1
, P
1
) si G
2
= (V
N
2
, V
T
2
, S
2
, P
2
) gramatici de tipul 3 cu
V
1
V
2
= .
Construim gramatica G = (V
N
1
V
N
2
, V
T
1
V
T
2
, S
1
, P
1
P

2
), unde P

2
se obt in
din P
2
nlocuind toate product iile de forma A q cu A S
1
q.
Observ am c a G este o gramatic a de tip 3.
Ar atam c a L(G) = L(G
1
)L(G
2
)
10
Demonstr am prima dat a L(G) L(G
1
)L(G2)
Fie p L(G) p V

T
, S
2

G
p
S
2

G
A
q
, unde A V
N
2
, q V
T
2
.
S
2

G
2
A
q

G
S
1
rqS
1
p
2

p = p
1
p
2
, unde S
1

G
p
2
S
1

G
p
1
S
1

G
1
p p
1
L(G
1
)
S
2

G
A
q
S
2

G
2
A
q

G
2
r
q
= p
2
p
2
L(G) p = p
1
p
2
L(G
1
)L(G
2
).
Vom ar ata ca L(G
1
)L(G
2
) L(G)
Fie p
1
L(G
1
) p
1
V

T
1
, S
1

G
1
p
1
p
2
L(G
2
) p
2
V

T
2
, S
2

G
2
p
2
S
2

G
2
p
2
se ncheie cu o product ie de categoria a 2-a.
c q, c V
N
2
, q V

T
2
S
2

G
2
cp

2

G
2
qp

2
c S
1
q
S
1

G
p

1
S
2

G
cp

2

G
S
1
qp

p
1
qp

2
= p
1
p
2
p
1
p
2
L(G).
Cazul j {0, 1}
Fie G
1
= (V
N
1
, V
T
1
, S
1
, P
1
), G
2
= (V
N
2
, V
T
2
, S
2
, P
2
) dou a gramatici de tip j,
unde V
1
V
2
= .
Presupunem c a dac a j = 1, atunci L(G
1
)L(G
2
). Construiesc gramatica
G = (V
N
1
V
N
2
{S}, V
T
1
V T
2
, S, P
1
P
2
{S S
1
S
2
}), unde S V
1
V
2
Evident G este de tip j.
L(G) = L(G
1
)L(G
2
) L(G)
Fie p L(G
1
)L(G
2
) p
1
L(G
1
), p
2
L(G
2
) astfel nc at p = p
1
p
2
.
p
1
(V
T
1
)

si S
1

G
1
p
1
p
2
(V
T
2
)

si S
2

G
2
p
2
S
G
S
1
S
2

G
p
1
S
2

G
p
1
p
2
= p si p (V

T
) p L(G).
Vom ar ata ca L(G) L(G
1
)L(G
2
)
S
G
w
1

G
w
2

G
. . .
G
w
m
, n N

si w
1
, w
2
, . . . , w
n
V

.
Cu necesitate w
1
= S
1
S
2
. Vom demonstra prin induct ie dupa i c a oricare ar
w
i
= w

i
w

i
, w

i
V

1
, w

i
V

2
, S
1

G
w

i
, S
2

G
w

i
.
Presupunem adevarate armat iile pentru i. Demonstr am pentru i + 1.
w
i

G
w
i+1
, w

i
w

i

G
w
i+1
.
Presupunem ca s-a folosit o product ie din P
1
.
w
i+1
= w

i+1
w

i
, unde w

i+1
V

1
, w

i

G

i+1
.
11
Punem w

i1
= w

i
, S
1

G
1
w

i
w

i+1
, S
2

G
2
w

i
= w

i+1
. De aici rezult a c a
w
i+1
= w

i+1
w

i+1
.
Dac a p L(G)

S
G
p
p V

T
p = p
1
p
2
, p
1
V

1
, p
2
V

2
, S
1

G
1
p
1
, S
2

G
2
p
2

p
1
L(G
1
)
p
2
L(G
2
)
p = p
1
p
2
L(G
1
)L(G
2
)
Presupunem ca j = 1 si L(G
1
) L(G
2
).
Fie L
1
= L(G
1
) {} si L
2
L(G
2
) {}.
L(G
1
)L(G
2
) = L
1
L
2
L
1
sau L(G
1
)L(G
2
) = L
1
L
2
L
2
sau L(G
1
)L(G
2
) =
L
1
L
2
L
1
L
2
{}limbaje de tip 1.
Lemma 3.3. Lema de nchidere la nchiderea KLEENE
Familia de limbaje L
j
, j {0, 1, 2, 3} este nchisa relativ lanchiderea KLEENE.
L

nN
L
n
= {} L L
2
L
3
. . .
Proof. Cazul j = 2.
Fie G = (V
N
, V
T
, S, P) o gramatic a de tip 2.
Construim gramatica G

= (V
N
{S

}, V
T
, S

, S

, P {S

S|}) unde
S

V.
G

este o gramatic a de tip 2.


Demonstr am c a L(G

) = [L(G)]

.
Pentru nceput arat am c a L(G

) [L(G)]

Fie p L(G

) p (V
T
)

si S

In derivarea de mai sus trebuie sa apara de n ori product ia S

S, n N
si exact o data S

, n aceast a ordine.
Modulo schimbarea ordinii aplicarii unei product ii este de forma:
S

S
n

S
n

G
p p
1
, p
2
, . . . , p
n
(V
T
)

astfel nc at S

p
1
, S
2

p
2
, . . . , S

p
n
si p = p
1
p
2
. . . p
n
p
1
, p
2
, . . . , p
n
L(G) p = p
1
p
2
. . . p
n

[(G)]
n
[L(G)]

.
Demonstr am reciproca.
Fie p [L(G)]

n N astfel nc at p [L(G)]
n
.
Dac a n = 0, atunci p = L(G

).
Dac a n 1, atunci p = p
1
p
2
. . . p
n
cu p
1
p
2
. . . p
n
L(G), p
1
, p
2
, . . . , p
n

(V
T
)

.
S
G
p
1
S p
2
G
. . . . . . . . . . . . . . .
S
G
p
n
.
12

In G

avem derivarea S

S
n
S
n

p
1
p
2
. . . p
n
= p p L(G

).
Cazul j = 3. Fie G = (V
N
, V
T
, S, P) o gramatic a de tip 3. Construim
G

= (V
N
{S

}, V
T
, S

, P P

{S

S|}), unde S

V, iar P

se obt ine
nlocuind ecare product ie de categoria 1 din P cu A p cu product ia
A S

p.
Se observa c a G

este o gramatic a de tip 3.


Ar atam c a L(G

) = [L(G)]

.
Pentru nceput vom demonstra c a L(G

) [L(G)]

.
Fie p L(G

) p (V
T
)

si S


G
p.
S

p = [L(G)]

.
S

S
G

p.
Dac a toate product iile de prim a categorie din derivarea S
G

p sunt din P,
atunci aceasta derivare are loc n G si astfel rezult a p L(G) [L(G)]

.
Presupunem ca n derivarea S
G

p avem si product ii din P

.
S

A
q
Srq = Sp
n

Sp
n1
p
n

. . .
r
q
= p
n
(V
T
)

. . .

Sp
2
. . . p
n

p
1
p
2
. . . p
n
p
n1
(V
T
)

. . . . . . . . . . . .
p
q
(V
T
)

p
1
(V
T
)

S
G
Aq
Ar
r
q
= p
n
p
n
L(G).
S
G
p
n1
p
n1
L(G).
. . .
. . .
. . .
S
G
p
1
p
1
L(G)
p = p
1
p
2
. . . p
n
[L(G)]
n
[L(G)]

.
13
4 Limjabe regulate
4.1 Automate nite
Prin automat nit nt elegem un dispozitiv care recunoaste limbajele generate
de gramatici de tip 3.
Un automat nit este un ansamblu alc atuit din c ateva p at i componente:
-cap de citire-act ioneaza asupra unor siruri de caractere
-dispozitiv de comand a -prelucreaz a informat ia transmis a de caractere-pastreaza
automatul ntr-o anumita stare intern a.
Denition 4.1. Se numeste automat nit un sistem A = (, I, f, s
P
,
f
),
unde -mult imea st arilor si I-alfabetul de intrare sunt mult imi nite si nev-
ide, f : I P()funct ie de tranzit ie, s
0
stare init ial a,
f
-
mult imea starilor nale. Daca |f(s, i)| 1, (s, i) I, automatul se
numeste determinist.
Funct ia f se prelungesten mod natural la o funct ie f : P()I

P(),
astfel:
a) f(Z, ) = Z, Z
b) f(, p) = , p I

c) f(Z, i) =

sZ
f(s, i), Z P() {}, i I
d) f(Z, p
i
) = f(f(Z, p), i), Z P() {}, p I
+
, i I.
Prelungirea f are urmatoarele propriet at i:
Proposition 4.1. a) Daca Z
1
, Z
2
, . . . , Z
n
, atunci
f(
n

k=1
Z
k
, i) =
n

k=1
f(Z
k
, i), i I
b) Daca Z si p I

, atunci
f(Z, p) =

sZ
f(s, p)
c) Daca s si p, q I

, atunci
f(s, pq) = f(f(s, p), q).
14
Denition 4.2. Limbajul recunoscut(acceptat) de automatul nit A =
(, I, f, s
0
,
f
) este mult imea
L(A) = {p I

|f(s
0
, p)
f
= }.
Denition 4.3. Un limbaj L I

se numeste limbaj regulat daca si numai


dac a exist a un automat nit A cu proprietatea ca L = L(A).
Lemma 4.1. Fie A un automat nit. Exista un automat determinist A

cu proprietatea L(A) = L(A

).
Proof. A = (, I, f, s
0
,
f
)
f : E I P()
Denim f : P() I P(), f(, i) = .

f
= {Z P()|Z
f
= }
Observ am c a A

este un automat nit determinist.


Mai mult f(Z, i) este un element bine determinat al lui P().
Demonstr am c a L(A) L(A

).
Fie p L(A) f(s
0
, p)
f
= f(s
0
, p)

f
Pe de alta parte f({s
0
}, p)

f p L(A

).
Demonstr am reciproca, si anume L(A

) L(A).
Fie p L(A

) f({s
0
}, p)

f
f(s
0
, p)

f
f(s
0
, p)
f
=
p L(A).
Corollary 4.1. Putem presupune ca orice automat nit A = (, I, f, s
0
,
f
)
este determinism. Mai mult se poate presupune ca f : I .
4.2 Caracterizarea limbajelor regulate
Exist a trei posibilitat i de a caracteriza limbajele regulate:
-prin mecanisme generative-gramatici de tip 3
-prin dispozitive de recunoastere-automate nite
prin propozit ii de natur a algebrica

Intr-o gramatica de tip 3 avem dou a categorii de product ii:

A Bp
C q
A, B, C
V
N
si p, q V

T
.
O gramatica de tip 3 este o gramatic a ce are product ii de forma:

A Bp
C q
A, B, C
V
N
si p, q V

T
.
Theorem 4.1. Orice limbaj regulat poate generat de o gramatica de tip
3. (n orice automat nit exista o gramatica al carei limbaj este limbajul unui
automat nit).
15
Proof. Fie A = (, I, f, s
0
,
f
) un automat nit. Putem presupune c a
|f(s, i)| = 1, (s, i) I, mai precis putem presupune c a f : I .
Denim gramatica:G = (, I, s
0
, P), unde P = P
1
P
2
P
3
.
P
1
= {s is

|f(s, i) = s

}
P
2
= {s i|f(s, i)
f
}
P
3
=

s
0
, s
o

f
, s
0

f
.
.
Observ am c a G este de tip 3. Vom demonstra c a L(A) = L(G).
Pentru aceasta vom arata mia ntai ca L(A) L(G).
Fie p L(A), p = i
1
i
2
. . . i
n
.
Dac a n = 0 p = f(s
0
, )
f
s
0

f
s
0
P
L(G).
Dac a n 1, f(s
0
, i
1
) = s
1
f(s
1
, i
2
) = s
2
= f(f(s
0
, i
1
), i
2
) = f(s
0
, i
1
i
2
)
.
.
.
f(s
n1
, i
n
) = s
n
= = f(s
0
, i
1
i
2
. . . i
n
) = f(s
0
, p)
f
.
s
0
i
1
s
1
P
s
1
i
2
s
2
P
.
.
.
s
n2
i
n1
s
n1
P
s
n1
i
n
P
s
0
s
0
i
1
s
1
i
1
s
1
s
1
i
2
s
2
i
1
i
2
s
2
i
1
i
2
. . . i
n1
s
n1
s
n1
i
n
i
1
i
2
. . . i
n
= p
p L(G).
Ar atam c a L(G) L(A).
Pentru aceasta consider am p = i
1
i
2
. . . i
n
L(G)
Dac a n = 0, atunci p = s
0
s
0

f
f(s
0
, )
f

L(A).
Dac a n = 0, s
0

p = i
1
i
2
. . . i
n
s
0
s
0
i
1
s
1
i
1
s
1
s
1
i
2
s
2
i
1
i
2
s
2
i
1
i
2
. . . i
n1
s
n1
s
n1
i
n
i
1
i
2
. . . i
n
= p
f(s
0
, i
1
) = s
1
f(s
1
, i
2
) = s
2
= f(f(s
0
, i
1
), i
2
) = f(s
0
, i
1
i
2
)
.
.
.
f(s
n2
, i
n1
) = s
n1
= = f(s
0
, i
1
i
2
. . . i
n1
)
f(s
n1
, i
n
)
f
f(s
0
, i
1
i
2
. . . i
n
)
f
f(s
0
, p)
f
p
L(A)
Lemma 4.2. Orice gramatica de tip 3 este echivalenta cu una de acelasi
tip care admite doar product ii de forma A iB, A, B V
N
, i V
T
; C
j, C V
N
, j V
T
si eventual S , dar n acest caz S nu apare n membrul
16
drept al niciunei product ii.
Proof. Fie G = (V
N
, V
T
, S, P) o gramatica de tip 3. Eliminam mai ntai
toate regulile de stergere(mai put in S cu condit iile precizate anterior n
enunt ) ca n lema de eleiminare a regulilor de stergere.
Construim gramatica G

= (V

N
, V
T
, S, P) n felul urmator:
Orice product ii de forma A i
1
i
2
. . . i
n
B cu n 2 o nlocuim cu product ia
A i
1
B
1
, B
1
i
2
B
2
, . . . , B
n1
i
n
B si ad augam terminalele B
1
, B
2
, . . . , B
n1
la V
N
.
Orice product ie de forma C j
1
j
2
. . . j
n
cu n 2 o nlocuim cu product ia
C
n1
j
n
si adaug am neterminalele C
1
, C
2
, . . . , C
n1
la V
N
.

In mod evident
L(G) = L(G

).
Theorem 4.2. Orice limbaj regulat este de tip 3.
Lemma 4.3. Orice gramatica de tip 3 este echivalenta cu una care admite
product ii: A iB, C j, S , A, B, C V
N
, i, j V
T
doar daca S nu
apare n membrul drept al niciunei product ii.
Theorem 4.3. Orice limbaj de tip 3 este regulat.
Proof. Fie G = (V
N
, V
T
, S, P) o gramatic a de tip 3. Putem presupune ca G
are doar product ii de forma A iB, C j, S , A, B, C V
N
, i, j V
T
,
doar daca S nu apare n membrul drept al niciunei product ii. Construim
automatul nit A = (, I, f, s
0
,
f
), unde = V
N
{X} cu X V, I =
V
T
, s
0
= S,

f
=

{x}, P S
{S, x}, P S
.
Dac a P A iB, atunci B f(A, i).
Dac a P C j, atunci X f(C, j).

In celelalte cazuri f se ia egal cu


Observation 4.4. 1. Automatul A este n general nedeterminist.
2. f(X, i) = , i V
T
3. Daca G are regula de stergere, atunci f(A, i) S, A V
N
, i V
T
4. L(G) L(A) f(S, ) = S S
f
.
Ramane de demonstrat ca L(G) {} = L(A) {}.
Demonstram pentru nceput ca L(G) {} L(A) {}. Fie p
L(G) {}, p = i
1
i
2
. . . i
n
, i
1
, i
2
, . . . , i
n
V
T
S
Si
1
B
1
i
1
B
1
B
1
i
2
B
2
i
1
i
2
B
2
i
1
i
2
. . . i
n1
B
n1
i
1
. . . i
n1
i
n
=
17
p.
P S i
1
B
1
B
1
f(S, i
1
)
P S i
2
B
2
B
2
f(B
1
, i
2
) f(f(S
1
, i
1
), i
2
) = f(S, i
1
i
2
)
.
.
.
P B
n1
i
n
. . . B
n1
f(S, i
1
i
2
. . . i
n1
) X f(B
n1
, i
n
)
f(f(S, i
1
i
2
. . . i
n1
), i
n
) = f(S, P)
Aratam ca L(A) {} L(G) {}
Fie p L(A) {}, p = i
1
i
2
. . . i
n
; i
1
, i2, . . . , i
n
V
T
f(S, P)

f
= B
n1
V
N
astfel ncat B
n1
f(S, i
1
i
2
. . . i
n1
) si f
(B
n1
, i
n
) X P B
n1
i
n
.
B
n1
f(S, i
1
i
2
. . . i
n1
) = f(f(S, i
1
i
2
. . . i
n2
), i
n1
) B
n2
V
N
astfel ncat B
n2
f(S, i
1
i
2
. . . i
n2
) si f (B
n1
, i
n1
) B
n1

B
n2
i
n1
B
n1
.
.
.
B
1
V
N
astfel ncat B f(S, i
1
) si f(B
1
, i
2
) B
2
P B
1
i
2
B
2
.
P S i
1
B
1
p L(G) {}.
4.3 Caracterizarea limbajelor regulate
Lemma 4.4. Lema de pompare.
Fie L un limbaj regulat si A = (, I, f, s
0
,
f
) un automat nit determinist
care-l recunoaste. Daca p L cu l(p) ||, atunci u, v, w I

cu v =
astfel ncat p = uvw si uv
n
w L, n N

Proof. p = i
1
i
2
. . . i
m
; i
1
, i
2
, . . . , i
m
I, m ||.
Not am
s
1
= f(s
0
, i
1
)
s
2
= f(s
1
, i
2
)
.
.
.
s
m
= f(s
m1
, i
m
)
s
2
= f(f(s
0
, i
1
)) = f(s
0
, i
1
i
2
)
.
.
.
s
m
= f(s
0
, i
1
i
2
. . . i
m
) = f(s
0
, p)
f
Principiul lui Diriclet(al cutiei) implima j, k, j < k astfel nc at s
j
= s
k
.
Not am u = i
1
i
2
. . . i
j
, v = i
j+1
, i
j+2
, . . . i
k
, w = i
k+1
, i
k+2
, . . . , i
m
.
p = (i
1
i
2
. . . i
j
)(i
j+1
i
j+2
. . . i
k
)(i
k+1
i
k+2
. . . i
m
) = uvw
f(s
0
, u) = s
j
f(s
j
, v) = f(s
0
, uv) = s
k
f(s
j
, w) = f(s
k
, w) = f(s
0
, p) = s
m
18
Rezult a ca f(s
0
, uv
n
w) = f(f(f(s
0
, u), v
n
)w) = f(s
j
, w) = s
m

f

uv
n
w L, n N

.
Corollary 4.2. L
2
L
3
Proof. Fie L = {a
k
b
k
|k N

}
Evident L L
2
.
L este generat de gramatica de tip 2 G = (V
N
, V
T
, S, P), unde V
N
= {S}, V
T
=
{a, b}, P = {S aSb|ab}.
Presupunem L L
3
L este regulat rezult a ca exista u, v, w {a, b}

, v =
cu proprietatea ca p = uvw si uv
n
w L, n N

, n Nk N

astfel
ncat uv
n
w = a
k
b
k
1. v {a}
+
contradict ie
2. v {b}
+
contradict ie
3. v = a
j
b
l
, j, l N

contradict ie , deci L L
3
.
19

You might also like