Documente Academic
Documente Profesional
Documente Cultură
Curs2013 Partea1
Curs2013 Partea1
Departmentul de Infomrmatica
Universitatea Bucuresti
Bucuresti, Romania
Structura cursului:
1. Cunostinte de baza
multimi, multiseturi, secvente, functii,
relatii, metode si tehnici de demonstratie,
alfabet, cuvinte, limbaje
2. Automate nite
automate nite nedeterministe (NFA),
automate nite deterministe (DFA),
transformarea de la NFA la DFA,
proprietati pentru limbajele acceptate de
automate,
lema de pompare
3. Expresii regulate
echivalenta dintre expresiile regulate si automatele nite
(in denirea limbajelor)
4. Gramatici independente de context (CFG)
simplicare si forme normale,
algoritmi de parsare, lema de pompare si
alte proprietati
2
Compiler
AI
Database
Graphics
VLSI
Theory of Computing
(1) Putere de calcul
(2) Complexitate
(3) Software design
(4) Circuit design
.....................
I. Cunostinte de baza
1. Multimi
1) O multime este o colectie de elemente luate
dintr-un univers.
2) O multime este nita daca contine un numar nit de elemente, si este innita in caz
contrar.
3) Cardinalitatea unei multimi este numarul sau
de elemente si se noteaza cu # sau (pentru multimea ).
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 }
= { este in , pentru un , 1
=1
}
= { este in , 1 }
=1
Proprietati ale operatiilor cu multimi
Distributivitate
( ) = ( ) ( )
( ) = ( ) ( )
Indempotenta
= ; =
Involutie
() =
Comutativitate
= ; =
Asociativitate
( ) = ( )
( ) = ( )
9
10
2. Multiseturi
Un multiset este o colectie de elemente
dintr-un univers oarecare, colectie in care
repetitiile nu sunt ignorate.
3. Secvente
O secventa de elemente dintr-un univers oarecare este o lista de elemente care sunt
ordonate (ecare element are o pozitie).
11
4. Functii
Denitie Daca se dau doua multimi si , o
functie (partiala) de la la asociaza cu
ecare din (cel mult) un element din .
Notatii:
functie :
asocierea () =
nedenita () =
Functii speciale:
functia identitate:
: si
() = pentru toti
Functia caracteristica a lui pentru :
: {, }
() = ,
() = ,
12
functie (partiala) ,
: 1 2 . . . 1 . . .
(1, 2, . . . , ) = (1, . . . , )
sau (1, 2, . . . , ) =
14
5. Relatii
O relatie -ara , 1, pentru multimile
1, . . . , este orice submultime a produsului cartezian 1 . . . .
Exemplu
15
Compunerea relatiilor
Fie si doua relatii. Atunci
compunerea lui cu , notata prin , este
relatia , denita prin:
= {(, ) (, ) este in si (, ) este in
pentru un din }
Compunerea unei relatii : cu ea insasi
0 : {(, ) este in }
1 :
, 1 : 1
+ = inchiderea tranzitiva a lui
=1
= inchiderea reexiva si tranzitiva a
=0
lui
16
Proprietatile relatiei
reexiva: pentru toti din
simetrica: implica
antisimetrica: , implica =
17
tranzitiva: , implica
18
19
20
6. Cardinalitate
Daca se dau doua multimi si , spunem
ca ele au cardinalitate egala daca exista o
bijectie : .
Exemplu # = #0
() = 2 1, < 0
() = 2, 0
O multime este numarabila sau enumerabila
daca este ori nita ori innita, caz in care are
aceeasi cardinalitate cu .
21
7. Metode de demonstratie
demonstratie directa
demonstratie prin contradictie
demonstratie prin inductie
Demonstratie directa
Enumeram toate cazurile pentru a arata ca
proprietatea este adevarate.
Exemplu Orice numar par dintre 4 si 232 este
suma a doua numere prime.
Demonstratie prin contradictie
Stabilim validitatea propozitiei presupunand
ca nu este adevarata si inferam o contradictie.
Exemplu Exista un numar innit de numere
impare.
22
23
24
8. Proof Techniques
pigeonhole principle
counting
diagonalisation
The Pigeonhole Principle
Let 1 be an integer, let there be
pigeonholes, and there be + 1 items of mail
to be placed in the pigeonholes. Then, however the the items are placed, at least one
pigeonhole will contain at least two items.
The Pigeonhole Principle(Extended version)
Let 1, . . . , 1. There exists a positive integer (1, . . . , ). If (1, . . . , ), then however items are placed into pigeonholes,
there exists , 1 such that the -th
pigeonhole contains at least 1 + 1 items.
25
26
= 0
= 4
011010 = 2
= 0
28
The catenation of two words and , denoted by , is the word obtained by appending the word to .
Example =
=
=
=
= =
=
Catenation is associative:
() = ()
= +
0 = (Power of a word)
= 1, 1
Example ()0 =
()3 =
29
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
32
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
34
Catenation of Languages
1 2 = {1 2 1 in 1, 2 in 2},
usually written as 12.
Examples
1 = {, }; 2 = {, }
12 = {, , }
(Note that 1 2 = {(, ), (, ), (, ), (, )})
1 =
{}1 =
{} =
= {, };
= {, }
35
Powers of Languages:
0 = {}
+1 = , 1
Plus
+ =
=1
Star
=
=0
0 1 2 . . . . . .
Examples
= {, }. Then
0 = {}
1 = = {, }
2 = {, , , }
0 = {} =
{}0 = {}
= {, , , , , , , . . . . . .}
(Note 4)
36
Reversal of Languages
= { is in }
Examples
= {, , };
= {, , }
= { > > 0}
= { > > 0}
properties of reversal
( )
( )
()
(+)
()
=
=
=
=
=
()+
()
Complementation of Languages
Given a language over ,
=
=
? {}
() =
= { 0} over = {, }
=
37
38
Property Summaries
properties of catenation (of languages)
Associativity
Identity
Zero
Distributivity
w.r.
1(23) = (12)3
{} = {} =
= =
1(2 3) = 12 13
(1 2)3 = 13 23
+
(+)+
+
{}+
+
=
=
=
=
=
=
+ {} ( But + = {}?)
+, () =
,
= {}, 0 = {}
{}, {} = {}, 2 =
+, =
+ + and
39
40
state set :
{0, 1, 2, 3}
input alphabet :
{0, 1}
Transition function : (0, 0) = 0, (0, 1) = 1, . . .
Start state :
0
Final state set :
{3}
Deterministic Finite Automata (DFA)
= (, , , , ) where
41
42
Specifying
1)
State diagram
(Transition diagram)
Start state
Final state
2)
43
Congurations
a word in
...
2
(nal conguration)
if = and (, ) =
Conguration sequence
0 1 2
+ and
is a binary relation over .
+ : transitive closure of .
: reexive transitive closure of .
44
0
0
0
0
2
2
0
2
if 1 1 2 2 . . .
steps
Accepting Conguration Sequence
0 1 2
can also be viewed as a function
: ,
since the next conguration is determined
uniquely for a given conguration.
The DFA stops when:
(i) we have no more input,
or (ii) the next conguration is undened.
45
( ) =
( ) =
46
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
47
49
= { 1} is not accepted
by any DFA.
50
= {}, 1.
For any 1, is a DFA language?
= { : 0 }, 1.
For any 1, is a DFA language ?
52
53
54
55
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
58
59
= ,
= {2}
= (, , , , ) where
= 2 = {, {0}, {1}, {2}, {0, 1}, {0, 2}, {1, 2}, {0, 1, 2}}
(, ) = { (, , ) and }
60
= {0}
= {
Algorithm NFA to DFA
The Subset Construction
On entry: An NFA = (, , , , ).
On exit: A DFA = (, , , , )
satisfying ( ) = ( ).
begin Let = 2, = {} and
= { , and = }
We dene : by
For all and for all ,
(, ) = , if in .
end of Algorithm
if = { (, , ) and }
61
= {0}
62
By the construction of ,
{} in i
{} in .
( )
, for some
{} , , in
{} , in and =
,
( )
63
Theorem
Every NFA Language is a DFA language and
conversely.
( = )
Example
Every nite language is accepted by a DFA.
64
NFA
It is useful to loosen the denition of NFA
even more by allowing the read head to remain over the same symbol of the input and
read nothing.
Example
1 = { 0, 0}
M:
( ) = 1
: (0, , 0)
(0, , 1)
(1, , 1)
0 0 0 1 1
0 1 1 1
0 0 1
65
Formally, a -NFA = (, , , , )
where , , , are as before, but
is a nite transition relation
for which
( {})
Congurations are as before.
is dened by
if either = for and (, , )
or
= and (, , )
Example
Given FA 1 and 2, construct
a FA 3 such that
(3) = (1) (2)
66
67
Theorem: ( ) = ( )
Example:
68
Now we got = (, , , , )
where = ( {(, , ) (, , ), (, , ) })
{(, , ) , }
Example
69
Claim Whenever
70
Properties of FA Languages
I. Closure Properties
Union: The union of two DFA languages
is a DFA language.
Proof: Given 1 = (1) and 2 = (2),
1, 2 are generic DFA languages.
1 = (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
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
2. Complementation:
The complement of a DFA language
is a DFA language.
Proof: There is a complete DFA
= (, , , , ) with = ( ). Dene
= (, , , , )
3. Intersection:
1 and 2
= 1 2
1 2
73
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
5. Star:
The star of a DFA language is a DFA language
= ( ) where = (, , , , )
= ( )
= (, , , , ) where
=
=
=
=
{}
{(, , )} {(, , ) }
{} = {}
6. Plus:
75
76
Proof: Compute for the given and the terminating state such that . If
then answer True else answer false.
2. DFA Emptiness
INSTANCE: A DFA = (, , , , ).
QUESTION: Is ( ) = ?
Theorem DFA emptiness is decidable.
Proof: ( ) = i there is no path in the
state diagram of from to a nal state. If
= , then this holds immediately.
Otherwise, enumerate the states that can be
reached from . (Mark . Now mark all states
reachable by one transition from one of the
marked states. Repeat this until no newly
marked state is introduced.
The marked states are the reachable states).
77
3. DFA Universality
INSTANCE: A DFA = (, , , , ).
QUESTION: Is ( ) = ?
Theorem DFA universality is decidable.
Proof:
4. DFA Containment
INSTANCE: Two DFA
1 = (1, 1, 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
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
;
1; and
for all 0, is in ( ).
Example = (, , , , ) where
= {, , }, = {, },
= {}.
# = 3
81
() , 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 satises
() ,
() 1,
() ( ) for all 0.
82
83
Non-DFA Language
= { 0} is not a DFA Language
Proof (I):
Assume is a DFA language. Then = ( )
for some DFA = (, , , , ) with = .
Consider = , .
By DFA pumping lemma, there is a decomposition
=
which satises (i), (ii), and (iii).
Consider all the possible decompositions
Case 1 : = , 1.
But 0 = .
Case 2 : = , 1.
0 = .
Case 3 : = , , 1.
Then 2 = .
All the possible decompositions fail.
Therefore, is not a DFA language.
84
Proof (II):
..................
= .
Consider = in . Obviously, .
By DFA pumping lemma, there is a decomposition
=
that satises (i), (ii), and (iii).
The only decompositions that satisfy
(i) and (ii) are the following:
= for 1.
But 0 = .
So, there is no such decomposition.
is not a DFA language.
(i) ;
(ii) 1;
85
86
Notice that = 2 .
2+1 > 2+1 2+1 > 2+1 2 = 2
i.e., 2+1 > 2+1 > 2.
+1
> > 2 .
6. DFA Finiteness
INSTANCE: A DFA = (, , , , )
QUESTION: Is ( ) nite?
It is decidable.
Theorem ( ) is nite i
accepts no words that satisfy
< 2
Proof: If: Assume accepts no words with
< 2 and ( ) is innite. Since
( ) is innite, it must accept some word
with 2. By P.L., = with
1, and = is in ( ). Notice that > . If 2,
then repeat this process.
Otherwise 2 > . (i.e., 2 ).
This is a contradiction.
Only if: By P.L., = , 1.
Since ( ) for all 0, ( ) is innite.
88
89
I in
O in
Input tape
read-only head
Finite control
write-only head
Output tape
A conguration is a word in .
output till now;
current state;
remaining input.
We write
if (, , , ) is in .
, +, are dened as usual.
Given , we say that 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 dened by
is ( ) = {(, ) and ()}
92
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
REGULAR EXPRESSIONS
The Second Model for Dening Languages
Example:
Consider the language of all the words that
consist of s and s and have as a subword.
We can formally dene this language by the
following:
(1) = { {, } and has as a
subword};
(2) = ( ) where is an NFA given by
the following diagram:
94
(6) 1
are R.E.s over
We usually omit .
The set of all regular expressions over is
denoted by
95
[[ + ]] is the same as [[ ]]
Example:
2
[[ ] ] is a R.E. over {, }
3
96
97
98
Examples = {, }.
1 = { = , }.
2 = { 0 mod 3}.
[[]]
4 = { = , 1}
99
Examples
What are the languages denoted by the following R.E.s ?
1 =
2 = [ ]
3 = [ ]
4 = [ ]
100
(2) Countable ?
101
(ii) = .
Construct such that ( ) = {}
(iii) = , .
Construct such that ( ) = {}
#
"!
102
(iv) = [1 2].
Construct such that ( ) = (1) (2).
(v) = [12].
Construct such that ( ) = (1)(2).
(vi) = 1 .
Construct such that ( ) = (1).
103
Example
= [[ []]]
Construct a FA such that ( ) = ().
, , by (iii)
by (vi)
[] by (v)
[ ] by (iv)
[ ] by (vi)
[[ ]] by (v)
104
Therefore, ( ) = ().
Case II: = 12
....................................
Case III: = 1
....................................
106
(, ) =
(, ) =
......
One nal state =
107
A conguration is in
Move
if
(i) = , ,
(ii) (, ) = , and
(iii) ().
, + are dened similarly as before.
Lemma If is a DFA, Then there is an EFA
with ( ) = ( ).
Example DFA into EFA.
108
Example:
An extended nite Automaton (EFA).
M:
109
i.e.:
Example
110
Note: {, }
Consider all transitions (, , )
and (, , )
:
(, ) = (, ) (, )((, ))(, )
111
Example
[ ]
112
Example
113
114