Finite Automata: Regular Languages
Finite Automata: Regular Languages
Finite Automata: Regular Languages
Regular Languages
Today we start looking at our first class of
languages: Regular languages
Means of defining: Regular Expressions
Machine for accepting: Finite Automata
Input string
Language
recognition
machine
YES, string is
in Language
NO, string is
not in
Language
Finite Automata
A finite automaton(FA) consists of
A read tape
A machine that can be in one or more states
Start state The state the machine is in at the
beginning of execution
Accepting states The state(s) the machine has to be
in after execution in order for a string to be
accepted
Finite Automata
Input tape
2
3
State machine
Finite Automata
How the automaton works
Read a character on the tape
Based on the character read and the current
state of the machine, put your machine into
another state
Move the read head to the right
Repeat the above until all characters have been
read.
Finite Automata
Testing a string for membership
Finite Automata
Transition function
Defines what state the machine will move into
given:
The current machine state
The character read off the tape
Finite Automata
L = {x {0,1}* | x contains an odd number of
0s and an even number of 1s}
0
1
2
3
# 0s
even
odd
odd
even
#1s
even
even
odd
odd
1
0
1
0
1
1
1
2
0
3
Finite Automata
The transitions can also be described by a
table.
character
s
t
a
t
e
10
11
12
13
14
1
0
1
0
0
1
0
# 0s
even
odd
odd
even
#1s
even
even
odd
odd
1
0
1
0
1
1
1
2
0
3
15
RE from a FA
Intuitive notions
A branch in an FA implies a union
Sequence from one state to the next implies
concatenation
A loop in the graph implies a Kleene star.
16
RE from a FA
a,b
1
a
0
b
b
a
3
b
2
(ab + ba)*
17
RE from a FA
Observation
If the start state is also an accepting state then
is a member of the language accepted by the
FA.
18
Finite Automata
Consists of
A set of states
A start state
A set of accepting states
Read symbols
Transition function
19
Finite Automata
A finite automaton (finite-state machine) is
a 5-tuple (Q, , qo, , A) where
20
10
Finite Automata
The transition function
is a function from Q x to Q
(q, a) = q where
q, q Q
a
21
Finite Automata
Applying the transition function to a string.
* is a function from Q x * to Q
* (q, x) = q where
q, q Q
x *
22
11
Finite Automata
Recursive definition of *
Let M = (Q, , qo, , A) be an FA.
Define *: Q x * Q
1. For any q Q, * (q, ) = q
2. For any y * , a , and q Q
* (q, ya) = (* (q, y) , a)
23
Finite Automata
Example of *
q
q1
* (q, ) = q
q2
q3
24
12
Finite Automata
Another Recursive definition of *
Let M = (Q, , qo, , A) be an FA.
Define *: Q x * Q
1.For any q Q, * (q, ) = q
2.For any y * , a , and q Q
* (q, ay) = * ( (q, a) , y)
25
Finite Automata
Example of *
q
q1
q2
* (q, ) = q
q3
26
13
Language accepted by an FA
Let M = (Q, , qo, , A) be an FA.
A string x * is accepted by M if
* (q0, x) A
In other words,
Starting in your start state q0
Run the machine with input x
The machine ends up in an accepting state
27
Language accepted by an FA
The language accepted or recognized by
finite automata M is:
L(M) = { x * | x is accepted by M }
28
14
Kleene Theorem
29
Reality Check
What weve learned so far
An FA can be expressed by (Q, , qo, , A)
Transition function: : Q x Q
Transition function on strings
*: Q x * Q
Defined recursively
FA accepting a string
The language accepted by an FA
Kleene Theorem
30
15
31
32
16
33
Complement
Let L be a regular language
There exists an FA M= (Q, , q, A, ) such that
L(M) = L.
x L iff * (q, x) A
x L iff * (q, x) A
L = {x | x L }
So to construct an FA M that accepts L, we
simply let all accepting states in M be nonaccepting in M and all non-accepting states in
M be accepting in M
Computer Science Theory
34
17
Complement
In other words
M = (Q, , q, Q - A, )
0
1
1
0
1
0
1
35
36
18
37
38
2
4
1
5
State of M2
3
4
State of M1
M1
19
39
40
20
41
42
Intersection
A = {(p,q) | p A1 and q A2}
Difference
A = {(p,q) | p A1 and q A2}
21
43
44
1
0
A
0
B
M1
P
1
M2
22
45
46
23
AQ
AR
BP
BQ
BR
CP
CQ
CR
47
AR
BP
BQ
BR
CP
CQ
CR
AP
0
48
24
1
AQ
AP
AR
0
BP
BQ
BR
1
CP
CQ
0
CR
0
1
Computer Science Theory
49
50
AP
0
0
BQ
0
1
CP
CQ
0
CR
0
25
Intersection
A = {(p,q) | p A1 and q A2}
Difference
A = {(p,q) | p A1 and q A2}
51
Union
1
AR
AP
0
0
BQ
0
1
CP
CQ
0
1
CR
0
= accepting
Computer Science Theory
52
26
Intersection
1
AR
AP
0
0
BQ
0
1
CP
CQ
CR
0
0
1
= accepting
Computer Science Theory
53
Difference
1
AR
AP
0
0
BQ
0
1
CP
CQ
0
1
CR
0
= accepting
Computer Science Theory
54
27
55
28