Languages and Finite Automata
Download
Report
Transcript Languages and Finite Automata
Languages
Prof. Busch - LSU
1
Language: a set of strings
String: a sequence of symbols
from some alphabet
Example:
Strings: cat, dog, house
Language: {cat, dog, house}
Alphabet:
a, b, c,, z
Prof. Busch - LSU
2
Languages are used to describe
computation problems:
PRIMES {1,2,3,5,7,11,13,17,}
EVEN {0,2,4,6,}
Alphabet:
{0,1,2,,9}
Prof. Busch - LSU
3
Computation is translated to set membership
Example computation problem:
Is number
x
prime?
Equivalent set membership problem:
x PRIMES {1,2,3,5,7,11,13,17,}?
Prof. Busch - LSU
4
Alphabets and Strings
An alphabet is a set of symbols
Example Alphabet:
a, b
A string is a sequence of
symbols from the alphabet
a
ab
Example Strings
abba
aaabbbaabab
Prof. Busch - LSU
String variables
u ab
v bbbaaa
w abba
5
Decimal numbers alphabet
102345
567463386
Binary numbers alphabet
100010001
{0,1,2,,9}
{0,1}
101101111
Prof. Busch - LSU
6
Unary numbers alphabet
{1}
Unary number: 1
11
111
1111
11111
Decimal number: 1
2
3
4
5
Prof. Busch - LSU
7
String Operations
w a1a2 an
abba
v b1b2 bm
bbbaaa
Concatenation
wv a1a2 anb1b2 bm
Prof. Busch - LSU
abbabbbaaa
8
w a1a2 an
ababaaabbb
Reverse
w an a2a1
R
bbbaaababa
Prof. Busch - LSU
9
String Length
w a1a2 an
Length:
w n
Examples:
abba 4
aa 2
a 1
Prof. Busch - LSU
10
Length of Concatenation
uv u v
Example:
u aab, u 3
v abaab, v 5
uv aababaab 8
uv u v 3 5 8
Prof. Busch - LSU
11
Empty String
A string with no letters is denoted:
or
Acts as a neutral element
Observations: 0
w w w
abba abba abba abba
Prof. Busch - LSU
12
Substring
Substring of string:
a subsequence of consecutive characters
String
Substring
abbab
abbab
ab
abba
abbab
b
abbab
bbab
Prof. Busch - LSU
13
Prefix and Suffix
string abbab
Prefixes
Suffixes
abbab
a
bbab
ab
bab
abb
ab
b
abba
abbab
w uv
prefix
suffix
Prof. Busch - LSU
14
Exponent Operation
w ww
w
n
n
Example:
Definition:
abba abbaabba
2
w
0
abba
0
Prof. Busch - LSU
15
The * Operation
* : the set of all possible strings from
alphabet
a, b
* , a, b, aa, ab, ba, bb, aaa, aab,
Prof. Busch - LSU
16
The + Operation
: the set of all possible strings from
alphabet except
a, b
* , a, b, aa, ab, ba, bb, aaa, aab,
*
a, b, aa, ab, ba, bb, aaa, aab,
Prof. Busch - LSU
17
Languages
A language over alphabet
is any subset of *
Example:
a, b
* , a, b, aa, ab, ba, bb, aaa,
Language:
a, aa, aab
Language:
{ , abba, baba, aa, ab, aaaaaa}
Language:
Prof. Busch - LSU
18
More Language Examples
Alphabet {a , b }
An infinite language
L {a b : n 0}
n n
ab
aabb
aaaaabbbbb
bbabb L
L
Prof. Busch - LSU
abb L
19
Prime numbers
Alphabet
{0,1,2,,9}
Language:
PRIMES {x : x and x is prime}
*
PRIMES {1,2,3,5,7,11,13,17,}
Prof. Busch - LSU
20
Even and odd numbers
Alphabet
{0,1,2,,9}
Languages:
EVEN {x : x and x is even}
*
EVEN {0,2,4,6,}
ODD {x : x and x is odd}
ODD {1,3,5,7,}
*
Prof. Busch - LSU
21
Addition
Alphabet:
(of unary numbers)
{1,, }
Language:
ADDITION {x y z : x 1 , y 1 , z 1 ,
n
m
k
nm k}
11 111 11111 ADDITION
111 111 111 ADDITION
Prof. Busch - LSU
22
Squares (of unary numbers)
Alphabet:
{1, # }
Language:
SQUARES {x # y : x 1 , y 1 , m n }
n
m
2
11#1111 SQUARES
111#1111 SQUARES
Prof. Busch - LSU
23
Note that:
Sets
{ } {}
Set size
{} 0
Set size
{} 1
String length
0
Prof. Busch - LSU
24
Operations on Languages
The usual set operations
a, ab, aaaa bb, ab {a, ab, bb, aaaa}
a, ab, aaaa bb, ab {ab}
a, ab, aaaa bb, ab a, aaaa
Complement:
L * L
a, ba , b, aa, ab, bb, aaa,
Prof. Busch - LSU
25
Reverse
Definition:
Examples:
L {w : w L}
R
R
ab, aab, baba ba, baa, abab
R
L {a b : n 0}
n n
L {b a : n 0}
R
n n
Prof. Busch - LSU
26
Concatenation
Definition:
Example:
L1L2 xy : x L1, y L2
a, ab, bab, aa
ab, aaa, abb, abaa, bab, baaa
Prof. Busch - LSU
27
Another Operation
Definition:
L
LL
L
n
n
a, b a, ba, ba, b
aaa, aab, aba, abb, baa, bab, bba, bbb
3
Special case:
0
L
0
a , bba , aaa
Prof. Busch - LSU
28
Example
L {a b : n 0}
n n
L {a b a b : n, m 0}
2
n n m m
2
aabbaaabbb L
Prof. Busch - LSU
29
Star-Closure (Kleene *)
All strings that can be constructed from
Definition:
L
L* L L L
0
1
2
Example:
,
a, bb,
a, bb*
aa
,
abb
,
bba
,
bbbb
,
aaa, aabb, abba, abbbb,
Prof. Busch - LSU
30
Positive Closure
Definition:
L L L
1
2
a, bb,
a, bb aa, abb, bba, bbbb,
aaa, aabb, abba, abbbb,
Prof. Busch - LSU
31