0% found this document useful (0 votes)
187 views73 pages

CS375 Automata 2 PDF

This document outlines the topics to be covered in the CS375: Logic and Theory of Computing course, including preliminaries, regular languages, finite automata, context-free languages, pushdown automata, Turing machines, and propositional and predicate logic. It also provides examples and explanations of finite automata and regular expressions. The key topics are regular languages, which are languages that can be recognized by finite automata, and proofs that the class of regular languages is equivalent to languages recognized by deterministic finite automata.

Uploaded by

charuk0504
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
187 views73 pages

CS375 Automata 2 PDF

This document outlines the topics to be covered in the CS375: Logic and Theory of Computing course, including preliminaries, regular languages, finite automata, context-free languages, pushdown automata, Turing machines, and propositional and predicate logic. It also provides examples and explanations of finite automata and regular expressions. The key topics are regular languages, which are languages that can be recognized by finite automata, and proofs that the class of regular languages is equivalent to languages recognized by deterministic finite automata.

Uploaded by

charuk0504
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 73

CS375:

Logic and Theory of Computing

Fuhua (Frank) Cheng

Department of Computer Science


University of Kentucky

9/12/2020 University of Kentucky 1


Table of Contents:

◼ Week 1: Preliminaries (set algebra, relations,


functions) (read Chapters 1-4)
◼ Weeks 2-5: Regular Languages, Finite
Automata (Chapter 11)
◼ Weeks 6-8: Context-Free Languages,
Pushdown Automata (Chapters 12)
◼ Weeks 9-11: Turing Machines (Chapter 13)

9/12/2020 University of Kentucky 2


Table of Contents (conti):

▪ Weeks 12-13: Propositional Logic (Chapter


6), Predicate Logic (Chapter 7),
Computational Logic (Chapter 9),
Algebraic Structures (Chapter 10)

9/12/2020 University of Kentucky 3


6. Regular Languages & Finite Automata
- Finite Automata algorithm
Can a machine recognize a regular language?
Yes

Deterministic Finite Automaton (DFA)


A finite digraph over an alphabet A (vertices are called
states).
Each state emits one labeled edge for each letter of A.
One state is defined as the start state and several
states may be final states.
9/12/2020 University of Kentucky indicated by double 4

circles
6. Regular Languages & Finite Automata
- Finite Automata
Example.
Either one is acceptable

A={a, b}
9/12/2020 University of Kentucky 5
6. Regular Languages & Finite Automata
- Finite Automata
The execution of DFA for input string w ∈ A* begins at
the start state and follows a path whose edges
concatenate to w.
The DFA accepts w if the path ends in a final state.
Otherwise the DFA rejects w.
The language of a DFA is the set of accepted strings.

an empty string will


enter the start state
but the empty set
Input string: abab
9/12/2020 University of Kentucky
will not. 6
6. Regular Lan|guages & Finite Automata
- Finite Automata

Example. The example DFA accepts the strings

The language of the DFA is { abn, bbm | n ϵ N, m ϵ N }


9/12/2020 University of Kentucky 7
6. Regular Languages & Finite Automata
- Finite Automata

Example. The example DFA accepts the strings

The regular expression of the language of the DFA is


(a + b)b* Why?

a+b (a+b)b (a+b)b2 (a+b)bn


9/12/2020 University of Kentucky 8
6. Regular Languages & Finite Automata
- Finite Automata
Theorem (Kleene) The class of regular languages is
exactly the same as the class of languages accepted
by DFAs.
Proof. Need three lemmas or by induction.
accepts 

accepts {}

a
accepts {a}
9/12/2020 University of Kentucky 9
6. Regular Languages & Finite Automata
- Finite Automata
Specifically, say A = {a, b}, then
1 accepts 

a, b
a, b

1 2 accepts {}
a, b

a
1 2 accepts {a}
b a, b
3
9/12/2020 a, b
University of Kentucky 10
6. Regular Languages & Finite Automata
- Finite Automata
Theorem (Kleene) The class of regular languages is
exactly the same as the class of languages accepted
by DFAs.
Proof. (conti.)

together with the basis step would prove the theorem.


9/12/2020 University of Kentucky 11
6. Regular Languages & Finite Automata
- Finite Automata
For instance, if 𝐿1 = {a} and 𝐿2 = {b}
a, b
a a

b a, b b
a, b
accepts {a} a, b accepts {b}

a, b
a
then a, b
b
a, b
9/12/2020 University of Kentucky 12
accepts {a, b}
6. Regular Languages & Finite Automata
- Finite Automata
For instance, if 𝐿1 = {a} and 𝐿2 = {b}
a, b
a a

b a, b b
a, b
accepts {a} a, b accepts {b}

a b

then a
b
a, b
9/12/2020 University of Kentucky 13
accepts {ab}
a, b
6. Regular Languages & Finite Automata
- Finite Automata
For instance, if 𝐿1 = {a} and 𝐿2 = {b}
a, b
a a

b a, b b
a, b
accepts {a} a, b accepts {b}

a, b

then a, b
b b
a a
9/12/2020 University of Kentucky accepts {aa} 14
6. Regular Languages & Finite Automata
- Finite Automata
For instance, if 𝐿1 = {a} and 𝐿2 = {b}
a, b
a a

b a, b b
a, b
accepts {a} a, b accepts {b}

a, b

a, b
or b b b
a a a
9/12/2020 University of Kentucky
accepts {aaa}
15
6. Regular Languages & Finite Automata
- Finite Automata
Example. Find a DFA for each language over the alphabet {a,b}.
n
(a) ∅. (b) {Λ}. (c) { (ab) | n ∈ N}, which has regular
expression (ab)*.
Solution:

9/12/2020 University of Kentucky 16


6. Regular Languages & Finite Automata
- Finite Automata
Example. Find a DFA for the language of a + aa*b.

a, b

a, b

9/12/2020 University of Kentucky 17


What is the problem with the
following approach?
Example. Find a DFA for the language of a + aa*b.

a, b

a, b

9/12/2020 University of Kentucky 18


What is the problem with the
following approach?
Example. Find a DFA for the language of a + aa*b.
Solution:

Question:
Would this DFA work?
aa is accepted by this
DFA, but …
9/12/2020 University of Kentucky 19
6. Regular Languages & Finite Automata
- Finite Automata

Loops are dangerous because if a path


contains a loop then the length of that
path is not unique!

You use an internal or external loop in a


DFA only if you want to recognize an
expression with variable length.
9/12/2020 University of Kentucky 20
A DFA that recognizes A DFA that recognizes
bc* + ac bc* + abc* + ac

c c

b
b b
a a
start start
c c c c

9/12/2020 University of Kentucky 21


A DFA that recognizes A DFA that recognizes
bc* + ac bc* + abc* + ac

a, b, c a, b, c
c c
a,b a,b

b
b a,b b a
a a, a a,
b, b,
start start
c c
c c c c

9/12/2020 a, b, c University of Kentucky a, b, c 22


A DFA that recognizes A DFA that recognizes
bc* + ac bc* + abc* + ac

c c

a, b a, b
b
b b
a a
start start
a, b a
c c c c
a, a, a, a,
b, b, b, b,
c c c c
9/12/2020 University of Kentucky 23
To make each of these FA’s a DFA, you either
create a new state or use a non-final state as
the sink of all the remaining edges of the FA.

That state should not have outgoing edges.

9/12/2020 University of Kentucky 24


Would the following DFA recognize a*bc* + ac ?

c In addition to
a*bc* and ac,
does it recognize
b
anything else?
b
a
a
start Yes, such as
c c aac, aaac, …

9/12/2020 University of Kentucky 25


A DFA that recognizes bc* + abc* + 𝑎2 bc* + ac

b
b b
a a
start
c c c

9/12/2020 University of Kentucky 26


A DFA that recognizes a*bc* + ac

bc* + abc* + 𝑎2 bc* + 𝑎𝑛 bc*


c

n≥3
b
b b a
a a
start How to make
c c c this FA a real
DFA?

9/12/2020 University of Kentucky 27


A DFA that recognizes a*bc* + ac

c One option:
a,b
b
b b
a
a a
start a real DFA now
a,b,c c c c

a,b,c a,b,c
9/12/2020 University of Kentucky 28
6. Regular Languages & Finite Automata
- Finite Automata
Table Representation of a DFA
DFA over A can be represented by a transition function
T : States × A → States,
where T(i, a) is the state reached from state i along the edge
labeled a, and we mark the start and final states.

Example:

9/12/2020 University of Kentucky 29


6. Regular Languages & Finite Automata
- Finite Automata

Note: T can be extended to T : States × A* → States


by T(i, Λ) = i , T(i, aw) = T(T(i, a), w) a ∈ A, w ∈ A*

Question: T(0, bba) =? or


T(0, bba) = T(1, ba) = T(1, a) = T(2, Λ) = 2.
9/12/2020 University of Kentucky 30
6. Regular Languages & Finite Automata
- Finite Automata
Example. Find a DFA to recognize (a + ba)*bb(a + ab)*.
A solution:
{bb}
a a
a,b
After excuting (a+ba)*,
return to start point of bb

{( a + ba) bb}
a,b
any combination a
9/12/2020 of a* and (ba)* University of Kentucky 31
6. Regular Languages & Finite Automata
- Finite Automata
Example (conti). Find a DFA to recognize (a + ba)*bb(a + ab)*.
A solution:

{(a + ba) bb (a + ab)} a


b b

any combination
of a* and (ab)* a,b a

9/12/2020 University of Kentucky 32


Would the following approach work?
Example (conti). Find a DFA to recognize (a + ba)*bb(a + ab)*.
A solution:

a,b

{(a + ba) bb (a + ab)}


b

any combination
of a* and (ab)*

9/12/2020 University of Kentucky 33


6. Regular Languages & Finite Automata
- Finite Automata
Nondeterministic Finite Automata (NFA)
An NFA over an alphabet A is similar to a DFA except that
Λ-edges are allowed,
there is no requirement to emit edges from a state, and
multiple edges with the same letter can be emitted from a state.
Example. The following NFA recognizes the language of
a + aa*b + a*b.
a ?
aa*b: ab, aab ?
a*b: b, ab ?
9/12/2020 University of Kentucky 34
Intuitive examples
A = { d, g, m, o, r}
NFA
d o g

m r

9/12/2020 University of Kentucky 35


Intuitive examples
DFA A = { d, g, m, o, r}

d o g

o
d,g,m,r d,g,m,o,r
d,m,r
g,m,o,r
d,g,o
m r
d,g,m,o
d,g,m,o,r
9/12/2020 University of Kentucky 36
Intuitive examples
Actually, the NFA can also be defined as follow:

d o g
o

A = { d, g, m, o, r}
o

m r

9/12/2020 University of Kentucky 37


Example. NFA for the language of a + aa*b + a*b.

a, b, ab,
DFA for the language of a + aa*b + a*b. aab, aaab,
a …

a b a, b

Start
9/12/2020 University of Kentucky 38
b a, b
DFA and NFA are equivalent concept.

A DFA is also an NFA.

But actually for every NFA there's a


corresponding DFA that accepts the same
language, but if the NFA has n states, the
DFA could have O(2𝑛 ) states.

So we work with NFAs because they’re


usually a lot smaller than DFAs.
9/12/2020 University of Kentucky 39
A few points about NFA’s.

The existence of Ʌ-edges implicitly creates the


concept of an extended state (a multiple-node
state) of a given state.

a c d

Ʌ Ʌ e
0 1 2

b d f

Extended
9/12/2020 University of Kentucky 40

state of 0
Edges a, b, c, d, e, f, g are edges of the
extended state of 0.
Each edge of the extended state of 0 can be
used by state 0 through some Ʌ-edges.
So essentially state 0 has 7 edges to use
even though there are only 2 real edges
emitted from state 0.
a c e

Ʌ Ʌ f
0 1 2

Extended d g
9/12/2020
b University of Kentucky 41

state of 0
For an NFA, only edges really needed for its
function have to be designed.

NFA for the language of a + aa*b + a*b.

We don’t
need to
design any
edges for
state 2.
9/12/2020 University of Kentucky 42
Why do we need “multiple edges with the
same letter”?

NFA for the language of a + aa*b + a*b.

A letter can be used


as the lead symbol
for disjoint paths

9/12/2020 University of Kentucky 43


Question: can you think of a DFA that
would recognize a+ aa*b + a*b ?
How about:
a,b
a,b

b
b b
a a a
start

a b ab aab aaab
9/12/2020 University of Kentucky 44
6. Regular Languages & Finite Automata
- Finite Automata
Table representation of NFA
An NFA over A can be represented by a function
T : States × A ∪ {Λ} → power(States),
where T(i, a) is the set of states reached from state i along the
edge(s) labeled a, and we mark the start and final states.

Example:
0

9/12/2020 University of Kentucky 45


6. Regular Languages & Finite Automata
the proof is similar to Kleene’s theorem
- Finite Automata
Theorem (Rabin and Scott): The class of regular languages is
exactly the same as the class of languages accepted by NFAs.

Questions. Find an NFA for each of the languages over {a, b}.

{a  , b , (ab)}

a,b
=
9/12/2020 University of Kentucky
? 46
6. Regular Languages & Finite Automata
- Finite Automata
Example. Find an NFA to recognize (a + ba)*bb(a + ab)*.
A solution:
{bb}

{( a + ba) bb}
any combination
of a* and (ba)*

{( a + ba) bb(a + ab)}

9/12/2020
any combination University of Kentucky 47
of a* and (ab)*
6. Regular Languages & Finite Automata
- Finite Automata
Example (conti). Find an NFA to recognize (a + ba)*bb(a + ab)*.
A solution:

But not

{( a + ba ) bb (aa b)*}

9/12/2020 University of Kentucky a 48


6. Regular Languages & Finite Automata
(DFA or NFA)
- Finite Automata
Algorithm: Transform a Regular Expression (RE) into a Finite
Automaton
(1) Placing the RE on the edge between a start and final state:

(2) Apply the following rules to obtain a finite automaton after


erasing any ∅-edges.

9/12/2020 University of Kentucky 49


6. Regular Languages & Finite Automata
- Finite Automata
Example. Use the algorithm to construct a finite automaton for
(ab)* + ba.
Solution:

9/12/2020 University of Kentucky 50


6. Regular Languages & Finite Automata
- Finite Automata
Algorithm: Transform a Finite Automaton to a Regular
Expression

Connect a new start state s to the start state of the FA


and connect each final state of the FA to a new final state ƒ
as shown in the figure.

Ʌ Given Ʌ
s FA f

Connect to start Connect from each


state of FA final state of FA
9/12/2020 University of Kentucky 51
6. Regular Languages & Finite Automata
- Finite Automata
If needed, combine all multiple edges between the same
two nodes into one edge with label the sum of the
labels on the multiple edges.
If there is no edge between two states, assume there is
an ∅-edge.

9/12/2020 University of Kentucky 52


Φ
6. Regular Languages & Finite Automata
- Finite Automata
Now eliminate each state k of the FA by constructing a
new edge (i, j) for each pair of edges (i, k) and (k, j)
where i ≠ k and j ≠ k.
New label new(i, j) is defined as follows:

new(i, j) = old(i, j) + old(i, k) old(k, k)* old(k, j)


Example:

A A+ BC*D

9/12/2020 University of Kentucky 53


Think of the process of eliminating state k as a
two-step procedure:

A
i j
B k D

A
i j Put Φ here if
BC*D there was not
a direct edge
between i and
j originally
A + BC*D
9/12/2020 i University of Kentucky j 54
6. Regular Languages & Finite Automata
- Finite Automata
Example. Transform the following NFA into a regular expression.

a*a(ba*a)*

Solution I (eliminate state 1 first):


State 1 is considered a state
between state 0 and state f
State 1 is also considered a
state between state 0 and
0 a state 0
a 1
9/12/2020 University of Kentucky 55

0 b
6. Regular Languages & Finite Automata
- Finite Automata
Example. Transform the following NFA into a regular expression.

Solution I (eliminate state 1 first): new( 0, f ) =  + a = a

new (0,0) = a + ab = a + ab

0 a
a 1
9/12/2020 University of Kentucky 56

0 b
6. Regular Languages & Finite Automata
- Finite Automata
Example. Transform the following NFA into a regular expression.

Solution I (eliminate state 1 first):

new ( s, f ) =  + (a + ab) a = (a + ab) a


9/12/2020 University of Kentucky 57
Or, eliminate state 1 first, the
following way:
You can think of the given
NFA as an NFA of the
following form

a
Ʌ a Ʌ
s 0 1 f
b a

9/12/2020
1 University of Kentucky 58
Or, eliminate state 1 first, the
following way:
a
Ʌ a Ʌ
s 0 1 f
b a
aɅ*Ʌ
1
a
Ʌ a
s 0 f
aɅ*b ab

9/12/2020 University of Kentucky 59


Or, eliminate state 1 first, the
following way:
a
Why?
Ʌ a
s 0 f a

ab 0 ab 0

0 a+ab 0
a + ab
Ʌ a
s 0 f
9/12/2020 University of Kentucky 60
Or, eliminate state 1 first, the
following way:
a + ab
Ʌ a
s 0 f

Ʌ(a+ab)*a
s f

(a+ab)*a
9/12/2020
s
University of Kentucky
f 61
6. Regular Languages & Finite Automata
- Finite Automata
Example. Transform the following NFA into a regular expression.

Solution II (eliminate state 0 first):


State 0 is considered a state
between state s and state 1
State 0 is also considered a
state between state 1 and
a
1 state 1
9/12/2020
0 University of Kentucky 62
b 1
6. Regular Languages & Finite Automata
- Finite Automata
Example. Transform the following NFA into a regular expression.

Solution II (eliminate state 0 first):


new( s,1) =  + a a = a a

new (1, 1) =  + baa = baa

9/12/2020 University of Kentucky 63


6. Regular Languages & Finite Automata
- Finite Automata
Example. Transform the following NFA into a regular expression.

Solution II (eliminate state 0 first):

new( s, f ) =  + a a(baa)  = aa(baa)


9/12/2020 University of Kentucky 64
Or, eliminate state 0 first, the
following way:
You can think of the given
NFA as an NFA of the
following form

a
Ʌ a Ʌ
s 0 1 f
a b

0
9/12/2020 University of Kentucky 65

a
Or, eliminate state 0 first, the
following way:
a
Ʌ a Ʌ
s 0 1 f
a b

Ʌa*a
0

a*a Ʌ
s 1 f
ba*a

9/12/2020
ba*a University of Kentucky 66
Or, eliminate state 0 first, the
following way:
a*a Ʌ
s 1 f

ba*a

a*a(ba*a)*Ʌ
s f

a*a(ba*a)*
9/12/2020
sUniversity of Kentucky f 67
6. Regular Languages & Finite Automata
- Finite Automata
Note. The two regular expressions obtained in the previous
example are equal, i.e., a*a( ba* a)* = (a + ab)*a.
Proof I.
( a + ab )* a ( R + S )* = R* (S R* )*

= [ a* ( (ab) a* )* ] a · is associative

= a* [ ( ( a b ) a* )* a ] · is associative

= a* [ ( a ( b a* ) )* a ] (R S )* R = R (S R )*

= a* [ a (( ba* ) a )* ] · is associative
9/12/2020 University of Kentucky 68

= a* a (ba* a)*
6. Regular Languages & Finite Automata
- Finite Automata
Note. The two regular expressions obtained in the previous
example are equal, i.e., a*a(ba*a)* = (a + ab)*a.
Proof II.
a* a ( ba*a )* = a*[a(( ba* ) a)*] · is associative
= a*[( a (ba*) )*a ] R(SR)* = (RS)*R
= a*[ ( (ab)a* )* a] · is associative
= [a* ((ab) a*)* ] a · is associative
= (a + ab)*a R*(SR*)* = (R + S)*
QED.

9/12/2020 University of Kentucky 69


6. Regular Languages & Finite Automata any combinations of
a* and (ab)*
- Finite Automata
Note. The two regular expressions obtained in the previous
example are equal, i.e., a*a(ba*a)* = (a + ab)*a.
Intuitive Proof.
LHS = a* a ( ba*a )* = a*a(ba*a)(ba*a)(ba*a) ⋯ (ba*a)
RHS = (a + ab)*a = a*(ab)*a*(ab)* ⋯ a*(ab)*a
LHS ⊆ RHS Why?
a*a(ba*a)(ba*a)(ba*a) ϵ LHS
= a*(ab)a*(ab)a*(ab)a*a
= a*(ab)a*(ab)a*(ab)a*(𝑎𝑏)0 a ϵ RHS
Hence, LHS ⊆ RHS
9/12/2020 University of Kentucky 70
6. Regular Languages & Finite Automata
- Finite Automata
Note. The two regular expressions obtained in the previous
example are equal, i.e., a*a(ba*a)* = (a + ab)*a.
Intuitive Proof (conti).
LHS = a* a ( ba*a )* = a*a(ba*a)(ba*a)(ba*a) ⋯ (ba*a)
RHS = (a + ab)*a = a*(ab)*a*(ab)* ⋯ a*(ab)*a
RHS ⊆ 𝐿HS Why?
a*(𝑎𝑏)2 a*(𝑎𝑏)2 a*(𝑎𝑏)2 a ϵ RHS
= a*(ab)(ab)a*(ab)(ab)a*(ab)(ab)a
= a*a(ba)(ba*a)(ba)(ba*a)(ba)(ba)
= a*a(b𝑎0 a)(ba*a)(b𝑎0 a)(ba*a)(b𝑎0 a)(b𝑎0 a) ϵ LHS
Hence,
9/12/2020
RHS ⊆ LHS University of Kentucky 71
End of Regular
Languages and Finite
Automata II

9/12/2020 University of Kentucky 74


Regular expression of this NFA:
a*a(ba*a)*

9/12/2020 University of Kentucky 75

You might also like