04 PDF
04 PDF
04 PDF
(0+1)*101
or it has length 0, 1, or 2
(0+1)*101(0+1)*
If L is a regular language, so is L.
regular
NFA DFA
expression
accepts L
1 0
q0 q1 q2 (0+1)*10
0, 1
1 0
q0 q1 q2 (0+1)*
Intersection
• The intersection L L’ is the set of strings that are
in both L and L’
• Examples:
L = (0 + 1)*11 L’ = 1* L L’ = 1*11
L = (0 + 1)*10 L’ = 1* L L’ = ∅
regular
NFA DFA
expression
M 1 1 0 0
M’
0 1
r0 r1 s0 s1
0 1
0 0 0 0
1
r1, s0 r1, s1
1
L L’ = even number of 0s and odd number of 1s
Closure under intersection
M and M’ DFA for L L’
a
si’ sj’ in M’
Reversal
• The reversal wR of a string w is w written backwards
w = cave wR = evac
• How do we argue?
regular
NFA DFA
expression
Arguing closure under reversal
• Take a regular expression E for L
e e
a (alphabet symbol) a
E1 + E2 E1R + E2R
E1E2 E2RE1R
E1* (E1R)*
A question
regular
expression
?
NFA DFA
A question
• Let’s try with regular expression:
L = {a, b}
L DUP = LL LDUP = {aa, bb}
LL = {aa, ab, ba, bb}
• Let’s try with NFA:
L = 0*1 is regular
0 0 0 0
1 1 1 1
1 01 001 0001
Union: L1 L2
Concatenation: L1L2
Are regular
Star: L1 *
Languages
Reversal: R
L1
Complement: L1
Intersection: L1 L2
24
2
5
Regular Grammars
2
6 Regular Grammars
Grammars is generative description of a language
X → Y,
Legal: S → a, S → e, and T → aS
Examples:
G1 G2
S → abS S → Aab
S →a A → Aab | B
B→a
28
Observation
Regular grammars generate regular languages
Examples: G2
G1 S → Aab
S → abS A → Aab | B
S →a B→a
FSM:
3
1 Regular Grammar Example
L = {w {a, b}* : |w| is even}
Regular expression: ((aa) (ab) (ba) (bb))*
FSM:
Add production: q → ap
S→e
S → aT
S → bT
T → aS
T → bS
3
6 Example 1 - Even Length Strings
S→e
S → aT
S → bT
T → aS
T → bS
3
7 Strings that End with aaaa
L = {w {a, b}* : w ends with the pattern aaaa}.
S → aS
S → bS
S → aB
B → aC
C → aD
D→a
3
8 Strings that End with aaaa
L = {w {a, b}* : w ends with the pattern aaaa}.
S → aS
S → bS
S → aB
B → aC
C → aD
D→a
3
9 Example 2 – One Character Missing
S→e A → bA C → aC
S → aB A → cA C → bC
S → aC A→e C→e
S → bA B → aB
S → bC B → cB
S → cA B→e
S → cB
4
0 Example 2 – One Character Missing
S→e A → bA C → aC
S → aB A → cA C → bC
S → aC A→e C→e
S → bA B → aB
S → bC B → cB
S → cA B→e
S → cB
4
1 Regular Languages and Regular Grammars
FSM → Regular grammar:
Show by construction that, for every FSM M there exists a
regular grammar G such that L(G) = L(M).
S → aS
S → bS
S → aB
B → aC
C → aD
D→a