Languages
Dec 05, 2015
• A language is a set of strings/words
• A string is a finite sequence of symbols
Example: “cat”, “dog”, “house”, …defined over an alphabet:
Example: “aaaab”, “bbbbbb”, “ababababa”, …defined over an alphabet:
Languages
{ }a,b,c, ,zΣ =
{ }a,bΣ =2
Alphabets and Strings• We usually use small alphabets:
• Strings
u abv bbbaaaw abba
===
{ } { }a,b , 0,1Σ = Σ =
aababbababaaaabbbaabab
3
String Operations
1 2 n
1 2 m
w a a av b b b==
abbabbbaaa
1 2 n 1 2 mwv a a a b b b=
Concatenation
abbabbbaaa
4
Length of Concatenation
• Example:
uv u v= +
u aab, u 3v abaab, v 5
uv aababaab 8uv u v 3 5 8
= =
= =
= =
= + = + =
7
Empty String• A string without symbols:
• Observations:
λ
0
w w w
abba abba ab ba abba
λ =
λ = λ =
λ = λ = λ =
8
Substring• A substring of a string is
a subsequence of consecutive symbols
String Substringababbabbabbab
ababba
b
babb
ab ababbababbab
9
* Operation• : the set of all possible strings from
alphabet
• Example:
∗Σ
.Σ
{ }{ }*
a,b
,a,b,aa,ab,ba,bb,aaa,aab,
Σ =
Σ = λ
12
+ Operation• : the set of all possible strings from
alphabet except
• Example:
+ΣΣ
{ }{ }a,b
* ,a,b,aa,ab,ba,bb,aaa,aab,Σ =
Σ = λ
{ }+ ∗Σ = Σ − λ
{ }a,b,aa,ab,ba,bb,aaa,aab,+Σ =
.λ
13
Language• A language is any subset of
• Example:
• Languages:
∗Σ
{ }{ }*
a,b
,a,b,aa,ab,ba,bb,aaa,
Σ =
Σ = λ
{ }{ }a,aa,aab{ ,abba,baba,aa,ab,aaaaaa}
λ
λ14
Operations on Languages• The usual set operations:
• Complement:
{ } { }{ } { }{ } { } { }
a,ab,aaaa bb,ab {a,ab,bb,aaaa}a,ab,aaaa bb,ab {ab}a,ab,aaaa bb,ab a,aaaa
∪ =
∩ =
− =
L L∗= Σ −
{ } { }a,ba ,b,aa,ab,bb,aaa,= λ
, ,∪ ∩ −
16
Reverse
• Definition:
• Examples:
R RL {w : w L}= ∈
{ } { }Rab,aab,baba ba,baa,abab=
n n
R n n
L {a b : n 0}
L {b a : n 0}
= ≥
= ≥
17
Concatenation
• Definition:
• Example:
{ }1 2 1 2L L xy : x L , y L= ∈ ∈
{ }{ } { }a,ab,ba b,aa ab,aaa,abb,abaa,bab,baaa=
18
Replication• Definition:
• Special case:
n
n
L LL L=
{ } { }{ }{ }{ }
3a,b a,b a,b a,baaa,aab,aba,abb,baa,bab,bba,bbb
= =
{ }
{ } { }
0
0
L
a,bba,aaa
= λ
= λ
19
Star-Closure (Kleene *)
• Definition:
• Example:
0 1 2L L L L∗ = ∪ ∪
{ }
,a,bb,
a,bbaa,abb,bba,bbbb,aaa,aabb,abba,abbbb,
∗
λ =
21
Positive Closure (Kleene +)
• Definition: { }1 2L L L L+ ∗= ∪ ∪ = − λ
{ }a, bb,
a, bb aa, abb, bba, bbbb,aaa, aabb, abba, abbbb,
+ =
22
Exercises
1. Let 𝐿𝐿 = 𝑎𝑎𝑎𝑎, 𝑎𝑎𝑎𝑎, 𝑎𝑎𝑎𝑎𝑎𝑎 . Which strings are in 𝐿𝐿2, 𝐿𝐿3, and
𝐿𝐿4?
2. Let Σ = 𝑎𝑎, 𝑎𝑎 and 𝐿𝐿 = 𝑎𝑎𝑎𝑎, 𝑎𝑎𝑎𝑎 . Use set notation to
describe �𝐿𝐿.
3. Prove that 𝑤𝑤𝑅𝑅 𝑅𝑅 = 𝑤𝑤 for all 𝑤𝑤 ∈ Σ∗.
4. Prove that 𝐿𝐿1𝐿𝐿2 𝑅𝑅 = 𝐿𝐿2𝑅𝑅𝐿𝐿1𝑅𝑅 for all languages 𝐿𝐿1 and 𝐿𝐿2.
23
• An automaton is an abstract model of a digital computer.
Finite Automaton
Input
String
Output
String
FiniteAutomaton
25
• An automaton is an abstract model of a digital computer.
Finite Accepter
Input
“Accept”or
“Reject”
String
FiniteAutomaton
Output
26
Transition Graph
initialstate
finalstate
“accept”statetransition
Abba -Finite Accepter
0q 1q 2q 3q 4qa b b a
5qa a bb
a,b
a,b
27
Formalities• Deterministic Finite Accepter (DFA)
( )0M Q, , ,q ,F= Σ δ
Q
Σ
δ
0q
F
: set of states
: input alphabet
: transition function
: initial state
: set of final states49
Transition Function
δ a b0q1q2q3q4q
5q
1q 5q5q 2q2q 3q4q 5q
5q5q5q5q
0q 1q 2q 3q 4qa b b a
5qa a bb
a,b
a,b
δ
58
Extended Transition Function ∗δ
0q 1q 2q 3q 4qa b b a
5qa a bb
a,b
a,b
0 5(q ,abbbaa) q∗δ =
• Observation: there is a walk from to with label
0q 5qabbbaa.
63
Languages Accepted by DFAs• Take DFA
• Definition:
The language contains
all input strings accepted by
= { strings that drive to a final state}
M
( )L M
MM( )L M
64
Formally
• For a DFA
• Language accepted by :
( )0M Q, , ,q ,F= Σ δ
M
( ) ( ){ }0L M w : q ,w F∗ ∗= ∈Σ δ ∈
alphabet
transition function
initial state
final states
67
Observation• Language accepted by :
• Language rejected by :
( ) ( ){ }0L M w : q ,w F∗ ∗= ∈Σ δ ∈
M
( ) ( ){ }0L M w : q ,w F∗ ∗= ∈Σ δ ∉
M
68
Regular Languages
• A language is regular if there is a DFA such that
• All regular languages form the family of regular languages.
L M
( )L L M .=
72
Exercises• For , construct DFAs that accept the
languages consisting of
a) all strings with exactly one 𝑎𝑎.
b) all strings with at least one 𝑎𝑎.
c) all strings with no more than three 𝑎𝑎’s.
d) all strings with at least one 𝑎𝑎 and exactly 2 𝑎𝑎’s.
e) all strings in which 𝑎𝑎𝑎𝑎 occurs at least twice.
{a,b}∑ =
74