1
Language Recognition (12.4) Longin Jan LateckiTemple University
Based on slides by Costas Busch from the coursehttp://www.cs.rpi.edu/courses/spring05/modcomp/and …
2
Three Equivalent Representations
Finite automata
Regularexpressions
Regular languages
Each can
describethe others
Kleene’s Theorem: For every regular expression, there is a deterministic finite-state automaton that defines the same language, and vice versa.
3
EXAMPLE 1
Consider the language { ambn | m, n N}, which is represented by the regular expression a*b*.
A regular grammar for this language can
be written as follows:
S | aS | B B b | bB.
4
Regular Expression
Regular Grammar
a* S | aS(a+b)* S | aS | bSa* + b* S | A | B
A a | aAB b | bB
a*b S b | aSba* S bA
A | aA(ab)* S | abS
5
NFAs Regular grammarsThus, the language recognized by FSA
is a regular language Every NFA can be converted into a corresponding regular grammar and vice versa.Each symbol A of the grammar is associated with a non-terminal node of the NFA sA, in particular, start symbol
S is associated with the start state sS.
Every transition is associated with a grammar production: T(sA,a) = sB A aB.
Every production B is associated with final state sB.
6
Equivalent FSA and regular grammar, Ex. 4, p. 772.
G=(V,T,S,P)V={S, A, B, 0, 1} withS=s0, A=s1, and B=s2,
T={0,1}, and productions areS 0A | 1B | 1 | λA 0A | 1B | 1 B 0A | 1B | 1 | λ
7
Kleene’s Theorem
LanguagesGenerated byRegular Expressions
LanguagesRecognizedby FSA
8
LanguagesGenerated byRegular Expressions
LanguagesRecognizedby FSA
LanguagesGenerated byRegular Expressions
LanguagesRecognizedby FSA
We will show:
9
Proof - Part 1
r)(rL
For any regular expression the language is recognized by FSA (= is a regular language)
LanguagesGenerated byRegular Expressions
LanguagesRecognizedby FSA
Proof by induction on the size of r
10
Induction BasisPrimitive Regular Expressions: a,,
NFAs
)()( 1 LML
)(}{)( 2 LML
)(}{)( 3 aLaML
regularlanguages
a
11
Inductive Hypothesis
Assume for regular expressions andthat and are regular languages
1r 2r
)( 1rL )( 2rL
12
Inductive StepWe will prove:
1
1
21
21
*
rL
rL
rrL
rrL
Are regular Languages
13
By definition of regular expressions:
11
11
2121
2121
**
rLrL
rLrL
rLrLrrL
rLrLrrL
14
)( 1rL )( 2rLBy inductive hypothesis we know: and are regular languages
Regular languages are closed under: *1
21
21
rLrLrL
rLrL Union Concatenation
Star
We need to show:
This fact is illustrated in Fig. 2 on p. 821.
15
Therefore:
** 11
2121
2121
rLrL
rLrLrrL
rLrLrrL
Are regularlanguages
And trivially: ))(( 1rL is a regular language
16
Proof - Part 2
LanguagesGenerated byRegular Expressions
LanguagesRecognizedby FSA
Lr LrL )(
For any regular language there is a regular expression with
Proof by construction of regular expression
17
Since is regular take the NFA that accepts it
LM
LML )(
Single final state
18
From construct the equivalentGeneralized Transition Graph in which transition labels are regular
expressions
M
Example:
a
ba,
cM
a
ba
c
19
Another Example:
ba a
b
b0q 1q 2q
ba,a
b
b0q 1q 2q
b
b
20
Reducing the states:ba
ab
b0q 1q 2q
b
0q 2q
babb*
)(* babb
21
Resulting Regular Expression:
0q 2q
babb*
)(* babb
*)(**)*( bbabbabbr
LMLrL )()(
22
In GeneralRemoving states:
iq q jqa b
cde
iq jq
dae* bce*dce*
bae*
23
The final transition graph:
0q fq
1r
2r
3r4r
*)*(* 213421 rrrrrrr
LMLrL )()(
The resulting regular expression:
24
Three Equivalent Representations
Finite automata
Regularexpressions
Regular languages
Each can
describethe others