languages and finite automata - florida institute of ...ryan/cse4083/busch/class02.pdf · 2 a...
TRANSCRIPT
1
Languages
2
A language is a set of strings
String: A sequence of letters
Examples: “cat”, “dog”, “house”, …
Defined over an alphabet:
Languages
zcba ,,,,
3
Alphabets and Strings
We will use small alphabets:
Strings
abbaw
bbbaaav
abu
ba,
baaabbbaaba
baba
abba
ab
a
4
String Operations
m
n
bbbv
aaaw
21
21
bbbaaa
abba
mn bbbaaawv 2121
Concatenation
abbabbbaaa
5
12aaaw nR
naaaw 21 ababaaabbb
Reverse
bbbaaababa
6
String Length
Length:
Examples:
naaaw 21
nw
1
2
4
a
aa
abba
7
Recursive Definition of Length
For any letter:
For any string :
Example:
1a
1 wwawa
4
1111
111
11
1
a
ab
abbabba
8
Length of Concatenation
Example:
vuuv
853
8
5,
3,
vuuv
aababaabuv
vabaabv
uaabu
9
Proof of Concatenation Length
Claim:
Proof: By induction on the length
Induction basis:
From definition of length:
vuuv
v
1v
vuuuv 1
10
Inductive hypothesis:
for
Inductive step: we will prove
for
vuuv
nv ,,2,1
1 nv
vuuv
11
Inductive Step
Write , where
From definition of length:
From inductive hypothesis:
Thus:
wav 1, anw
1
1
wwa
uwuwauv
wuuw
vuwauwuuv 1
12
Empty String
A string with no letters:
Observations:
abbaabbaabba
www
0
13
Substring
Substring of string:
a subsequence of consecutive characters
String Substring
bbab
b
abba
ab
abbab
abbab
abbab
abbab
14
Prefix and Suffix
Prefixes Suffixesabbab
abbab
abba
abb
ab
a
b
ab
bab
bbab
abbab uvw
prefix
suffix
15
Another Operation
Example:
Definition:
n
n wwww
abbaabbaabba 2
0w
0abba
16
The * Operation
: the set of all possible strings from
alphabet
*
,,,,,,,,,*
,
aabaaabbbaabaaba
ba
17
The + Operation
: the set of all possible strings from
alphabet except
,,,,,,,,,*
,
aabaaabbbaabaaba
ba
*
,,,,,,,, aabaaabbbaabaaba
18
Language
A language is any subset of
Example:
Languages:
*
,,,,,,,,*
,
aaabbbaabaaba
ba
},,,,,{
,,
aaaaaaabaababaabba
aabaaa
19
Another Example
An infinite language }0:{ nbaL nn
aaaaabbbbb
aabb
ab
L Labb
20
Operations on Languages
The usual set operations
Complement:
aaaaaabbbaaaaaba
ababbbaaaaaba
aaaabbabaabbbaaaaaba
,,,,
}{,,,
},,,{,,,
LL *
,,,,,,, aaabbabaabbaa
21
Reverse
Definition:
Examples:
}:{ LwwL RR
ababbaabababaaabab R ,,,,
}0:{
}0:{
nabL
nbaL
nnR
nn
22
Concatenation
Definition:
Example:
2121 ,: LyLxxyLL
baaabababaaabbaaaab
aabbaaba
,,,,,
,,,
23
Another Operation
Definition:
Special case:
n
n LLLL
bbbbbababbaaabbabaaabaaa
babababa
,,,,,,,
,,,, 3
0
0
,, aaabbaa
L
24
More Examples
}0:{ nbaL nn
}0,:{2 mnbabaL mmnn
2Laabbaaabbb
25
Star-Closure (Kleene *)
Definition:
Example:
210* LLLL
,,,,
,,,,
,,
,
*,
abbbbabbaaabbaaa
bbbbbbaabbaa
bbabba
26
Positive Closure
Definition:
*
21
L
LLL
,,,,
,,,,
,,
,
abbbbabbaaabbaaa
bbbbbbaabbaa
bba
bba
27
Finite Automata
28
Finite Automaton
Input
String
Output
String
Finite
Automaton
29
Finite Accepter
Input
“Accept”
or
“Reject”
String
Finite
Automaton
Output
30
Transition Graph
initial
state
final
state
“accept”statetransition
Abba -Finite Accepter
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
ba,
31
Initial Configuration
1q 2q 3q 4qa b b a
5q
a a bb
ba,
Input Stringa b b a
ba,
0q
32
Reading the Input
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
a b b a
ba,
33
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
a b b a
ba,
34
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
a b b a
ba,
35
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
a b b a
ba,
36
0q 1q 2q 3q 4qa b b a
Output: “accept”
5q
a a bb
ba,
a b b a
ba,
Input finished
37
Rejection
1q 2q 3q 4qa b b a
5q
a a bb
ba,
a b a
ba,
0q
38
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
a b a
ba,
39
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
a b a
ba,
40
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
a b a
ba,
41
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
Output:
“reject”
a b a
ba,
Input finished
42
Another Example
a
b ba,
ba,
0q 1q 2q
a ba
43
a
b ba,
ba,
0q 1q 2q
a ba
44
a
b ba,
ba,
0q 1q 2q
a ba
45
a
b ba,
ba,
0q 1q 2q
a ba
46
a
b ba,
ba,
0q 1q 2q
a ba
Output: “accept”
Input finished
47
Rejection
a
b ba,
ba,
0q 1q 2q
ab b
48
a
b ba,
ba,
0q 1q 2q
ab b
49
a
b ba,
ba,
0q 1q 2q
ab b
50
a
b ba,
ba,
0q 1q 2q
ab b
51
a
b ba,
ba,
0q 1q 2q
ab b
Output: “reject”
Input finished
52
Formalities
Deterministic Finite Accepter (DFA)
FqQM ,,,, 0
Q
0q
F
: set of states
: input alphabet
: transition function
: initial state
: set of final states
53
Input Alphabet
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
ba,
ba,
54
Set of States Q
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
543210 ,,,,, qqqqqqQ
ba,
55
Initial State 0q
1q 2q 3q 4qa b b a
5q
a a bb
ba,
ba,
0q
56
Set of Final States F
0q 1q 2q 3qa b b a
5q
a a bb
ba,
4qF
ba,
4q
57
Transition Function
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
QQ :
ba,
58
10, qaq
2q 3q 4qa b b a
5q
a a bb
ba,
ba,
0q 1q
59
50, qbq
1q 2q 3q 4qa b b a
5q
a a bb
ba,
ba,
0q
60
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
ba,
32, qbq
61
Transition Function
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
a b
0q
1q
2q
3q
4q
5q
1q 5q
5q 2q
2q 3q
4q 5q
ba,5q5q5q5q
62
Extended Transition Function *
QQ *:*
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
ba,
63
20,* qabq
3q 4qa b b a
5q
a a bb
ba,
ba,
0q 1q 2q
64
40,* qabbaq
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
ba,
65
50,* qabbbaaq
1q 2q 3q 4qa b b a
5q
a a bb
ba,
ba,
0q
66
50,* qabbbaaq
1q 2q 3q 4qa b b a
5q
a a bb
ba,
ba,
0q
Observation: There is a walk from to
with label0q
abbbaa1q
67
Recursive Definition
)),,(*(,*
,*
awqwaq
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
ba,
68
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
ba,
2
1
0
0
0
0
,
,,
,,,*
),,(*
,*
qbq
baq
baq
baq
abq
69
Languages Accepted by DFAs
Take DFA
Definition:
The language contains
all input strings accepted by
= { strings that drive to a final state}
M
ML
M
M ML
70
Example
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
ba,
abbaML M
accept
71
Another Example
0q 1q 2q 3q 4qa b b a
5q
a a bb
ba,
ba,
abbaabML ,, M
acceptacceptaccept
72
Formally
For a DFA
Language accepted by :
FqQM ,,,, 0
M
FwqwML ,*:* 0
alphabet transition
function
initial
state
final
states
73
Observation
Language accepted by :
Language rejected by :
FwqwML ,*:* 0
M
FwqwML ,*:* 0
M
74
More Examples
a
b ba,
ba,
0q 1q 2q
}0:{ nbaML n
accept trap state
75
ML = { all substrings with prefix }ab
a b
ba,
0q 1q 2q
accept
ba,3q
ab
76
ML = { all strings without
substring }001
0 00 001
1
0
1
10
0 1,0
77
Regular Languages
A language is regular if there is
a DFA such that
All regular languages form a language family
LM MLL
78
Example
The language
is regular: *,: bawawaL
a
b
ba,
a
b
ba
0q 2q 3q
4q