FLA Unit I PDF
FLA Unit I PDF
FLA Unit I PDF
AND AUTOMATA
UNIT I
1
UNIT 1
• Minimization of DFA
• Introduction to Automaton
• Problems related to Minimization of DFA
• Mathematical concepts
• Regular Languages : Equivalence of Finite
• Formal Languages: Strings, Languages, Properties Automata and Regular Languages
• Finite Representation : Regular Expressions • Equivalence of Finite Automata and Regular
Grammars
• Problems related to regular expressions
• Problems related to Equivalence of Finite
• Finite Automata :Deterministic Finite Automata Automata and Regular Languages and Regular
• Nondeterministic Finite Automata Grammars
• Variants of Finite Automata :Two-way Finite
• Finite Automaton with €- moves Automaton Mealy Machines
• Problems related to Deterministic and • Properties of Regular Languages: Closure
Nondeterministic Finite Automata Properties
• Problems related to Finite Automaton with €- • Set Theoretic Properties & Other Properties
moves
• Pumping Lemma
2
Introduction of Automaton
An automata is an abstract self-propelled computing device which follows a predetermined sequence of operations
automatically.
Automata-based programming is a programming paradigm in which the program or its part, is thought as a model of a
finite state machine or any other formal automation.
input: switch
BATTER output: light bulb
Y
actions: flip switch
states: on, off
3
1. Electric Switch
2. Fan Regulator
4
Simple Computer
Example:
OTHER EXAMPLES
1.Electric Switch
input : switch
Output : light bulb 2.Fan Regulator
BATTER
Y
Actions : flip switch 3.Automatic door controller
States : on, off 4.Binary string with divisible by 4
f
on bulb is on if and only if there was an odd number of flips
start off
f
5
Types of Automata
6
Introduction of Formal Proof - Basic Definitions
7
3. Empty string: e or ε denotes the empty sequence of symbols.
4. Language over alphabet Σ - a set of strings over Σ.
◦ Notation: L.
◦ Examples:
◦ {0, 00, 000, ...} is an "infinite" language over the binary alphabet.
◦ {a, b, c} is a "finite" language over the English alphabet.
8
Binary relations on strings
9
3. Substring - u is a substring of v if there are x and y such that v = xuy.
◦ Examples:
◦ let is a substring of appleton since appleton =
app.let.on
◦ 0 is a substring of 0 since 0 = epsilon.0.epsilon
10
Applications of the Concepts AND New Developments
Applications include:
◦ Text processing (editors, etc.)
◦ Compiler design
◦ Verification through model checking
Development’s include :
DNA Computing
Quantum Turing Machines
11
Introduction to Mathematical concepts
Inductive Proof
Deductive Proof
12
INDUCTIVE PROOF
Induction Principle:
If we prove S(i) and we prove that for all n>=I, S(n)=>S(n+1), then we may
conclude that s(n) for all n>=1.
It has two parts.
1.Basis part.
2.Inductive part.
13
Basis step: We have to show S(i) for a particular integer value “i”, here
“i “ may be zero or one.
14
Problems
Induction Principle:
If we prove S(i) and we prove that for all n>=I, S(n)=>S(n+1), then we may
conclude that s(n) for all n>=1.
15
Basis:
Put n=0 in the equ 1
RHS= (0 (0+1) (2*0+1))/6 => 0
LHS = i=0 ∑ n (02) => 0
i.e., LHS = RHS.
Inductive step:
Put n =1 in the equ 1
S(n) = (n(n+1)(2n+1))/6.
= (2n3+2n2+n2+n)/6. ---> Equ 2
16
Put n=n+1 in the equ 1
S(n+1) => ((n+1)(n+2)(2n+3))/6.
=> ((n2+3n+2) (2n+3))/6.
=> (2n3+6n2+4n+3n2+9n+6)/6.->equ 3
From the induction principle:
= S(n+1) =S(n) + (n+1)2.
= ((2n3+3n2+n)/6) + (n+1)2
17
= ((2n3+3n2+n)/6) + (n2+2n+1)
18
Deductive proof:
Consists of sequence of statements whose truth lead us from some
initial statement called the hypothesis or the give statement to a
conclusion statement.
Deductive Principle:
The theorem is proved when we go from a hypothesis H to a conclusion
C is the atatement “ if H then C”. i.e C is deduced from H
19
Additional forms of proof:
Proof of sets
Proof by contradiction
Proof by counter example
20
Direct proof (AKA) Constructive proof: If p is true then q is true
Eg: if a and b are odd numbers then product is also an odd number.
Odd number can be represented as 2n+1
a=2x+1, b=2y+1 product of a X b = (2x+1) X (2y+1)= 2(2xy+x+y)+1 =
2z+1 (odd number)
21
Proof by Contrapositve
The Contrapositive of the statement “ ifH then C” is “if not C then not
H”.A statement and its contrapositive are either both true or both false.
Theorem R U (S ∩ T) =(R U S) ∩ (R U T)
22
23
Proof by Contradiction:
24
Regular Expressions
25
Regular Expressions
• Example:
26
Recursive Definition
Are regular
Expressions
27
Regular Expressions
A regular expression:
28
Regular Expressions
Example
29
Regular Expressions
30
Regular Expressions
• Regular expression:
31
Regular Expressions
• Regular expression
• Regular expression
32
33
Example Problems in Regular Expressions
34
Solve Problems in Regular Expressions
35
Deterministic Finite Automata (DFA)
36
Formal definition of DFA
DFA M = (Q, Σ, δ, s, F)
Where,
◦ Q is finite set of states
◦ Σ is input alphabet
◦ s ∈ Q is initial state
◦ F ⊆ Q is set of final states
-
◦ δ: Q X Σ > Q
37
DFA
38
How does a DFA work?
After reading input string,
◦ if DFA state final, input accepted
◦ if DFA state not final, input rejected
Language of DFA -- set of all strings accepted by DFA.
39
Pictorial representation of
DFA
40
Formal definition of FA
41
42
Transition Diagram
43
Example
44
Transition table
45
Example
46
Extending the Transition functions to the strings
47
48
Language of DFA
49
Example: Diagram of DFA
2n + 1
L = {a | n >= 0}
Answer:
L = {a, aaa, aaaaa, ...}
50
Problem 1
Given a DFA accepting the following language over the alphabet {0,1}
Set of all the strings ending with 00.
51
In this problem ,
“00” as 2 inputs and it needs 3 states
52
Formal definition of L(M)
L(M) - Language accepted by M
Define δ*:
◦ δ*(q, ε) = q
◦ δ*(q, wσ) = δ(δ*(q,w),σ)
53
Problem 2
54
Regular Languages
Definition: A Language is regular iff there is a DFA that
accepts it.
Examples:
◦φ
◦ {ε}
◦ Σ*
◦ {w in {0,1}* | second symbol of w is a 1} Exercise
◦ {w in {0,1}* | second last symbol of w is a 1} Exercise
◦ {w in {0,1}* | w contains 010 as a substring} - (importance?)
55
Closure properties of Regular Languages
Regular languages are closed under:
◦ Union
◦ Notation: ∪
◦ Intersection
◦ Notation: ∩
56
Examples
Let Σ = {a,b}.
Let L1 = { w in Σ* | w has even number of a's}.
◦ Is L1 regular?
L2 = { w in Σ* | w has odd number of b's}.
◦ Is L2 regular?
L1 ∪ L2 = ?
◦ Ans: {w in Σ* | w has even a's or odd b's}.
L1 ∩ L2 = ?
◦ Ans: {w in Σ* | w has even a's and odd b's}.
57
Problem 3
58
Problem 4
59
Problem 5
60
Problem 6
61
Problem 8
62
Problem 9
Given a DFA accepting the following language over the
alphabet {0,1} Set of all the strings ending with 00.
63
Problem 10
Given a DFA accepting the following language over the alphabet {0,1}
Set of all the strings with 3 consecutive 0’s (not necessarily at the end).
64
Problem 11:
Given a DFA accepting the following language over the alphabet {0,1}
65
Problem 13
Given a DFA accepting the following language over the alphabet {0,1}
66
Problem 14
Given a DFA accepting the following language over the alphabet {0,1}
67
Problem 14
:
Consider the following transition diagram and to check the input string
110111,011101 is accepted or not.
68
Transition table:
0 1
A A B
B C B
C A D
*D A B
69
Input: 110111
δ( A,є) =A.
δ( A,1) =B.
δ( A,11) =δ( A,1),1) =δ( B,1) =B.
δ( A,110) =δ( A,11),0) =δ( B,0) = C.
δ( A,1101) =δ( A,110),1) =δ( C,1) = D.
δ( A,11010) =δ( A,1101),0) =δ( D,1) = B.
δ( A,110101) =δ( A,11010),0) =δ( B,1) = B.
It does not reach the final state.
The given string is not accepted by DFA.
70
Input: 011101
δ( A,є) =A.
δ( A,0) =A.
δ( A,01) =δ( A,0),1) =δ( A,1) =B.
δ( A,011) =δ( A,01),1) =δ( B,1) = B.
δ( A,0111) =δ( A,011),1) =δ( B,1) = B.
δ( A,01110) =δ( A,0111),0) =δ( B,0) = C.
δ( A,011101) =δ( A,011101),0) =δ( C,1) = D.
It reaches the final state.
The given string is accepted by DFA.
71
Problem 15
Give a DFA accepting the following language over the alphabet {0,1}.
All the strings with a substring 01 and to check the given input string 10010 is
accepted or not by a DFA.
0 1
q0 q1 q0
q1 q1 q2
*q2 q2 q2
72
Input 10010
δ( q0,є) =q0.
δ( q0,1) =q0.
δ( q0,10) =δ( q0,1),0) =δ( q0,0) =q1.
δ( q0,100) =δ( q0,10),0) =δ( q1,0) =q1.
δ( q0,1001) =δ( q0,100),1) =δ( q1,1) =q2.
δ( q0,10010) =δ( q0,1001),0) =δ( q2,0) =q2.
It reaches the final state
The given string is accepted by DFA.
73
Problem16 :
Design a DFA to accept the language
L ={w/w has an even number of 0’s and even number of 1’s}and to check the
given input strings are 110101 and 10010 is accepted or not by an DFA.
74
Let A be a DFA which has A={Q,∑,δ,q0,F)
Transition diagram:
75
Input: 110101
δ( q0,є) =q0.
δ( q0,1) =q1.
δ( q0,11) =δ( q0,1),1) =δ( q1,1) =q0.
δ( q0,110) =δ( q0,11),0) =δ( q0,0) =q2.
δ( q0,1101) =δ( q0,110),1) =δ( q2,1) =q3.
δ( q0,11010) =δ( q0,1101),0) =δ( q3,0) =q1.
δ( q0,110101) =δ( q0,11010),0) =δ( q1,1) =q0.
It reaches the final state. The given string is accepted
by DFA.
76
Input: 10010
δ( q0,є) =q0.
δ( q0,1) =q1.
δ( q0,10) =δ( q0,1),0) =δ( q1,0) =q3.
δ( q0,100) =δ( q0,10),0) =δ( q3,0) =q1.
δ( q0,1001) =δ( q0,100),1) =δ( q1,1) =q0.
δ( q0,10010) =δ( q0,1001),0) =δ( q0,0) =q2.
The state q2 is not a accepting state.
The given string is not accepted by DFA.
77
Nondeterministic Finite Automaton (NFA)
Generalization of DFA. Allows:
◦ 0 or more next states for the same (q, σ).
◦ Guessing
◦ Transitions labeled by the empty string.
◦ Changing state without reading input
Motivation: Flexibility.
◦ Easier to prove many closure properties.
78
How does an NFA work?
w is accepted by an NFA provided there is a sequence of guesses that
leads to a final state.
Language accepted by NFA is the set of all strings accepted by it.
79
Nondeterministic Finite Automata:
o Generalize FAs by adding nondeterminism,allowing several alternative computations
on the same input string.
o Ordinary deterministic FAs follow one path on each input.
80
Nondeterministic Finite Automata:
81
Nondeterministic Finite Automata:
NFA Example
82
Nondeterministic Finite Automata:
NFA Example
83
Problem 1
84
Formal definition of NFA
Notation: Σe = Σ U {e}.
NFA M = (Q, Σ, Δ, s, F) where:
◦ Q - finite set of states
◦ Σ - input alphabet
◦ s - initial state
◦ F ⊆ Q - set of final states
◦ Δ is a subset of Q X Σe X Q.
85
Formal definition of NFA acceptance
Δ*(q0, 1) = ?
◦ Ans: {q0, q1}
Δ*(q0, 11) = ?
◦ Ans: {q0, q1, q2}
86
NFA acceptance
87
NFA vs. DFA
Is NFA more powerful than DFA?
◦ Ans: No.
Theorem:
◦ For every NFA M there is an equivalent DFA M'
Proof Idea:
◦ NFA is in a set of states at any point during reading a string.
◦ DFA will use a lot of states to keep track of this.
Important Assumption:
◦ No transition labeled by epsilon.
(Will get rid of this assumption later.)
88
Equivalent DFA construction
NFA M = (Q, Σ, Δ, s, F)
DFA M' = (Q', Σ, δ, s', F') where:
◦ Q' = 2Q
◦ s' = {s}
◦ F' = {P | P ∩ F is nonempty}
◦ δ({p1, p2, pm}, σ) = Δ*(p1, σ) ∪ Δ*(p2, σ) ∪ ... ∪ Δ*(pm, σ)
i.e. find all the states that can be reached on σ from all the
NFA states in a DFA state.
89
Example: Equivalent DFA construction
NFA
90
Equivalent DFA construction
91
How to handle epsilon transitions?
92
Handling epsilon transitions (contd.)
Extend e-closure to sets of states by:
◦ e-closure({s1, ... , sm}) = e-closure(s1) ∪ ... ∪ e-closure(sm)
Now let
s' = e-closure({s}).
and,
δ({p1,..., pm}, σ) = e-closure(Δ*(p1, σ)) ∪ ... ∪ e-closure(Δ*(pm, σ))
93
Example: Handling epsilon transitions.
94
DFA = ?
95
Language Operations
1. Concatenation. Notation: L·L' or just LL'
◦ L · L' = {uv | u in L, v in L'}.
2. Kleene Star. Notation: L*
◦ L* = { w in Σ* | w = w1...wk for some k >= 0 and each wi in L}.
96
Closure properties of regular languages.
Previously we saw closure under ∪ and ∩.
New: Regular languages are closed under
◦ Concatenation
◦ Kleene star
◦ Complement.
97
Examples
98
Examples
99
Construction for L∙L'
L’’ = (K,Σ,Δ,s,F)
K = K 1 ∪ K2
s = s1
F = F2
Δ = Δ1 ∪ Δ2 ∪ F1 X {e} X
{s2}
100
L* and L'*
L*
M = (K, Σ, Δ, s, F)
K = {s} ∪ K1
F = {s} ∪ F1
Δ = Δ1 ∪ F1 X {e} X {s1} ∪ {(s, e,
s1)}
Given M1 = (K1, Σ, Δ1, s1, F1)
L’*
101
Complement of L and L'
Complement of L
Complement of L’
102
General Construction for Complement
DFA M = (K, Σ, δ, s, F)
K = K1
s = s1
F = K - F1
δ = δ1
L(M) = Complement of L(M1)
DFA M1 = (K1, Σ, δ1, s1, F1)
Exercise: Will this construction work for NFAs?
Explain your answer.
103
Regular expressions versus FA's
Regular expressions generate exactly the class of regular languages.
Theorem:
◦ (a) For every regular expression there is an equivalent NFA
◦ (b) For every DFA there is an equivalent regular expression.
Proof of (a):
◦ For φ, the NFA is:
104
Parse Tree for (a U b)* ∙ b
* b
a b
105
Example: NFA for (a U b)*b
aUb
106
Example (contd.) : NFA for (a U b)*b
(aUb)*
107
Example (contd.) : NFA for (a U b)*b
(a U b)*b
108
DFA → regular expression
Easier to do:
◦ DFA → GNFA → regular expression.
109
DFA → regular expression (contd.)
Idea:
◦ Convert DFA → special GNFA.
◦ Eliminate all states, except start and final state, one state at a time.
◦ Output the label on the single transition left at the end.
110
Eliminating state q{rip}
R4
qi qj
R1 R3
qrip
111
Constructing regular expression.
112
Constructing regular expression (contd.)
Added: a new start state and a new final state with empty transitions
113
Constructing regular expression (contd.)
qrip
Before we take out qrip, we have to see
all the paths to the qrip state and
all possible transitions.
We take out the qrip state and it leaves us with a 3 state Finite Automata
114
Constructing regular expression (contd.)
qrip
We take out the qrip state and we are left with the regular expression
115
Converting NFA to DFA
116
Converting NFA to DFA
117
Converting NFA to DFA
118
Converting NFA to DFA
119
Converting NFA to DFA
120
Converting NFA to DFA
121
Converting NFA to DFA
122
123
124
125
126
127
128
129
130
131
132
133
134
Applications of the Pumping Lemma
135
136
Applications of the Pumping Lemma
137
138
139
140
141