Download Deterministic Finite Automata - Automata and Complexity Theory - Lecture Slides and more Slides Theory of Automata in PDF only on Docsity!
Chapter 2
Deterministic Finite Automata (DFA)
(include Lecture 3 and 4)
Finite Automata and regular sets
(languages)
- States and transitions: Ex: Consider a counter data structure (system):
- unsigned integer counter: pc; { initially pc = 0}
- operations: inc, dec; ==> The instantaneous state of the system can be identified by the value of the counter. Operations called from outside world will cause transitions from states to states and hence change the current state of the system. Problem: how to describe the system : Mathematical approach: CS = ( S, O, T, s, F) where S = The set of all possible states = N O = the set of all possible [types of] operations T = the response of the system on operations at all possible states. (present state, input operation) --> (next state)
Deterministic Finite automata (the
definition)
- a DFA is a structure M = (Q,Σ, δ,s,F) where
- Q is a finite set; elements of Σ are called states
- Σ is a finite set called the input alphabet
- δ:QxΣ --> Q is the transition function with the intention that if M is in state q and receive an input a, then it will move to state δ(q,a). - e.g; in CS: δ(3, inc) = 4 and δ(3, dec) = 2.
- s in Q is the start state
- F is a subset of Q; elements of F are called accept or final states.
- To specify a finite automata, we must give all five parts (maybe in some other forms)
- Other possible representations:
- [state] transition diagram or [state] transition table
Example and other representations
Ex 3.1: M 1 = (Q,S,δ,s,F) where
- Q={0,1,2,3}, S={a,b}, s = 0, F = {3} and δ is define by:
- δ(0,a) = 1; δ(1,a) = 2; δ(2,a) = δ(3,a) = 3 and
- δ(q,b)=q if q = {0,1,2,3}.
- problem: Although precise but tedious and not easy to understand (the behavior of) the machine.
- Represent M 1 by a table: =====>
- Represent M 1 by a diagram:
**a b
0 1 0 1 2 1 2 3 2 3F 3 3**
0 a^1 a^2 a 3
b b^ b^ a,b
state-transition diagram for M 1 note: the naming of states is not necessary
• Meaning of the transition function:The extended transition function ∆
q1 -- a --> q2 [or δ(q1,a) = q2 ] means if M is in state q1 and the currently scanned symbol (of the input strings is a) then
- Move right one position on the input string (or remove the currently scanned input symbol)
- go to state q2. [So M will be in state q2 after using up a)
- Now we extend δ to a new function ∆: Q x Σ* --> Q with the intention that : ∆(q1,x) =q2 iff starting from q1, after using up x the machine will be in state q2. --- ∆ is a multi-step version of δ. Problem: Given a machine M, how to define ∆ [according to δ]? Note: when string x is a symbol (i.e., |x| = 1) then ∆(q,x) = δ(q,x). for all state q, so we say ∆ is an extension of δ.
The extended transition function ∆
(cont'd)
- ∆ can be defined by induction on |x| as follows:
- Basis: |x|= 0 (i.e., x = ε) ==> ∆(q, ε) = q --- (3.1)
- Inductive step: (assume ∆(q,x) has been defined ) then
- ∆(q, xa) = δ(∆(q,x), a) --- (3.2)
- --- To reach the state ∆(q,xa) from q by using up xa, first use up x (and reach ∆(q,x)) and then go to δ((∆,qx),a) by using up a.
- Exercise: Show as expected that ∆(q,a) = δ(q,a) for all a in Σ. pf: ∆(q,a) = ∆(q,εa) = δ(∆(q,ε),a) = δ(q,a).
Languages accepted by DFAs
- M = (Q,Σ,δ,s,F) : a DFA; x: any string over Σ;
∆: the extended transition function of M.
- x is said to be accepted by M if ∆(s,x) ∈ F
x is said to be rejected by M if ∆(s,x) ∉ F.
- The set (or language) accepted by M, denoted L(M), is the set of all strings accepted by M. i.e., - L(M) = (^) def {x ∈ Σ* | ∆(s,x) ∈ F }.
- A subset A ⊆ Σ* (i.e., a language over Σ) is said to be regular if A is accepted by some finite
Another example
Ex 3.2: Let A = {xaaay | x,y ∈ {a,b}*}
= {x ∈ {a,b}* | x contains substring aaa }.
Then baabaaaab ∈ A and babbabab ∉ A.
An Automaton accept A: (diagram form)
a a^ a
b
b
b a,b
a little harder example
==> s(x0) = #(x0) mod 3 = 2(#(x) mod 3) mod 3
= 2s(x) mod 3 ==> s(x) can be show as follows: (note: the DFA M defined by the table is also the automata accepting A)
- Exercise: draw the diagram form
of the machine M accepting A.
- Fact: L(M) = A. (i.e., for all bit
**0 1
0F 0 1 1 2 0 2 1 2 s(x) s(x0) s(x1)**
Some closure properties of regular
sets
Issue: what languages can be accepted by finite automata?
- Recall the definitions of some language operations:
- A U B = {x | x ∈ A or x ∈ B}.
- A ∩ B = {x | x ∈ A /\ x ∈ B}
- ~A = Σ* - A = {x ∈ Σ* | x ∉ A}
- AB = {xy | x ∈ A /\ y ∈ B}
- A* = {x 1 x 2 ...xn | n ≥ 0 /\ x (^) i ∈ A for 0 ≤ i ≤ n}
- and more ... ex: A / B = {x | ∃y ∈ B s.t. xy ∈ A }.
- Problem: If A and B are regular [languages], thenDocsity.com
The product construction (cont'd)
Ind. step: assume the lemma hold for x in Σ*, we show it holds for xa, where a in Σ. ∆ 3 ((p,q),xa) = δ 3 ( ∆ 3 ((p,q),x), a) --- definition of ∆ 3 = δ 3 ((∆ 1 (p,x), ∆(q,x)), a) --- Ind. hyp. = (δ 1 (∆ 1 (p,x),a), δ 2 (∆(q,x),a) --- def. of δ 3 = (∆ 1 (p,xa), ∆ 2 (p,xa)) QED --- def of ∆ 1 and ∆ 2.
Theorem 4.2: L(M 3 ) = L(M 1 ) ∩ L(M 2 ).
pf: for all x ∈ Σ*, x ∈ L(M 3 )
iff ∆ 3 (s 3 ,x) ∈ F 3 --- def. of
Regular languages are closed under U,
∩ and ~
Theorem: IF A and B are regular than so are A∩B, ~A and AUB.
pf: (1) A and B are regular
=> ∃ DFA M 1 and M 2 s.t. L(M 1 ) = A and L(M 2 ) = B -- def. of RL => L(M 1 xM 2 ) = L(M 1 ) ∩ L(M 2 ) = A∩ B --- Theorem
==> A ∩ B is regular. -- def. of RL. (2) Let M = (Q,Σ,δ,s,F) be the machine s.t. L(M) = A. Define M' = (Q,Σ,d,s,F') where F' = ~F = {q ∈ Q | qDocsity.com