Here I will describe a strategy or technique to solve some finite state automata problems. This strategy was first taught to us by my Theory of Computation Professor. The term 'Function Automata' is given to me since we use function-like structures in this.
Suppose you are given a language that is a regular set L. So there exists a DFA for L, LD=(Q,Σ,δ,q1,F) where Q is the set of states, Σ is the set of alphabets, δ is the transition function, S is the starting state and f is the set of final states. Now let Q={q1,q2,…,qn where n∈N. Now we will do a kind of subset construction but every new state will have n states of Q but they can repeat. So (q1,q1,…,q1⏟n times)
is a state of the new automata. Now, what is the meaning of these new states? Let f=(qk1,qk2,…,qkn) be a new state where qki's are not necessary to be different and qki∈Q. Then it means on reading some word w from the state q1 goes to qk1, q2 goes to qk2 … qn goes to qkn. So basically the new set of states is the set of all functions from {1,…,n}→{1,…,n}. We denote it by QQ. So we write f(q1)=qk1f(q2)=qk2…f(qn)=qkn
So we will form transitions on these new elements based on
δ. In most cases, you will be creating
NFA with this. Let the new automata
N=((QQ)m,Σ,Δ,S′,F′) where
m∈N depends on question and
(QQ)m=m times cartesian product of
QQ Δ is the transition tuple. So if
(f,a,g)∈Δ that means the automata from state
f on reading
a goes to
g state in the new automata. Also we define
id a special element of
QQ which is basically
id(q1)=qk1id(q2)=qk2…id(qn)=qkn
So
id=(q1,…,qn). In the new form automata
S′,F′ depend on what is asked. We will describe some examples.
Now for any letter
a∈Σ,
δa(q)=δ(q,a) where
q∈Q. Let the new formed Also let
f=(qk1,qk2,…,qkn) then for any letter
a∈Σ δa∘f=(δa(qk1),δa(qk2),…,δa(qkn))
Now to show how this technique works I explain by examples.
Question 1: If
L is a regular language then construct
NFA for the set
{w∣ww∈L}
Solution: Let the
DFA of
L is
LD=(Q,Σ,δ,q1,F). We will create the function automata
N=(QQ,Σ,Δ,S′,F′) where
S′=id. Now I told you
f(q1)=qki means
q1 goes to
qki on reading some word
w. So
f∘f(q1)=qkj means on reading
w q1→qki then
qki→qkj therefore
q1→wqki→wqkj⟺q→wwqkj
So if
f∘f(q1)∈F that means if
qkj∈F. Hence for any
f∈F′ if there exists a word
w such that
id→wf then
ˆδ(q1,w)∈F and similarly for any
w, if
ww∈L then take
f=(ˆδ(q1,w),ˆδ(q2,w),…,ˆδ(qn,w)). Now
f∈F′. Hence
id→wf. Therefore we set
F′={f∈QQ∣f∘f(q1)∈F}. All is left is to define
Δ. Take
Δ={(f,a,δa∘f)∣∀ f∈QQ, ∀ a∈Σ}
Now I think you got a little hang of the use of it. Let's do another example but a tough one.
Question 2: If
L is a regular language then construct
NFA for the set
{yx∣xy∈L}
Solution: Let the
DFA of
L is
LD=(Q,Σ,δ,q1,F). We will create the function automata
N=(QQ×QQ×{0,1},Σ,Δ,S′,F′). Here since two subwords
x,y are involved and they are independent of each other, we will take two functions,
g,f and process with that. Here we will take
S′=(id,id). For any
(g,f)∈QQ×QQ,
g denotes the reading of
y and
f denotes the reading of
x. So
f(q1)=qki means
q1 goes to
qki on reading some word
x. Then
g(qki)=qkj means
qki goes to
qkj on reading some word
y. Hence
g∘f(q1)=qkj means
q1 first reads
x and goes to
qki and then reads
y and goes from there to
qkj.
q1→xqki→yqkj⟺q1→xyqkj
So if
g∘f(qi)∈F that means
q1 goes to final state
qkj on reading word
xy. Hence our final state will be
F′={(g,f,1)∣f,g∈QQ, g∘f(q1)∈F}. But what about the transitions. The reason for using
{0,1}comes now. See once you complete reading
y you can not read
y anymore you have to read
x. So when transitions of
g are complete you will move to transition
f and that's it. That's where
{0,1} comes. When you are reading
y you are in
0 and when you are reading
x you are in
1. So can go from 0 to 1 but not 1 to 0. And because of this, we took elements
(g,f,1) for
F′ to indicate that when you reach the final state you are reading
x. So
Δ={((g,f,0),a,(δa∘g,f,0)),((g,f,0),a,(δa∘g,f,1)),((g,f,1),a,(g,δa∘f,1))| ∀ f,g∈QQ,∀ a∈Σ}
Now you get how you can use this technique in solving complex problems. And you can use multiple functions in one automata. Now we will see another problem with more subwords.
Question 3: If
L is a regular language then construct
NFA for the set
{xzy∣xyzx∈L}
Solution: Let the
DFA of
L is
LD=(Q,Σ,δ,q1,F). We will create the function automata
N=(QQ×QQ×QQ×{0,1,2},Σ,Δ,S′,F′). Naturally we will take
S′=(id,id,id). Here same for any
(f,h,g)∈QQ×QQ×QQ,
f,g,h are for reading
x,y,z respectively
f∘h∘g∘f(q1)=qk4⟺q1f→xqk1g→yqk2h→zqk3f→xqk4⟺q1⟶xyzxqk4
We took the set
{0,1,2} for same reason as the previous question. 0 indicates you are reading
x, 1 indicates you are reading
z and 2 indicates you are reading
y. So naturally
F′={(f,h,g,2)∣f,g,h∈QQ, f∘h∘g∘f(q1)∈F}
And now you can guess what will be the set
Δ.
Δ={((f,h,g,0),a,(δa∘f,h,g,0)),((f,h,g,0),a,(δa∘f,h,g,1)),((f,h,g,1),a,(f,δa∘h,g,1)),((f,h,g,1),a,(f,δa∘h,g,2)),((f,h,g,2),a,(f,h,δa∘g,2)),| ∀ f,g,h∈QQ,∀ a∈Σ}
Till now you see we are taking S′=id or (id,id or id,id,id) but that does not mean starting state will be always the cartesian product of id. There is a specific reason why we took that.
Question 4: If
L is a regular language then construct
NFA for the set
{x∣xyx∈L}
Solution: Let the
DFA of
L is
LD=(Q,Σ,δ,q1,F). Since two independent subwords are involved we will create the function automata
N=(QQ×QQ,Σ,Δ,S′,F′). Now we can pretty easily guess that the final set will be
F′={(f,g)∣f∈QQ,f∘g∘f(q1)∈F}
Notice that the set
{x∣xyx∈L} the words don't have the part
y. So it doesn't matter if we start from
(id,id) or not. We can start from anywhere for the
y part and then keep progressing for the function for
x. So for any
(f,g) [where
f is for
x and
g is for
y] it does not matter if we progress
g or not. For any
f∈QQ we take all such pairs and then check if
f∘g∘f(q1)∈F is satisfied or not. So here we take
S′={(id,g)∣∀ g∈QQ}
And we define
Δ Δ={((f,g),a,(δa∘f,g))∣∀ f∈QQ, ∀ a∈Σ}
Now you get what is the idea behind choosing
S′. Yes if any word
w∈L is partitioned into
k parts and
l of them are taken in some order for constructing the new set of words then for the parts which is common in both
w and newly formed word form it we take
id and the parts of
w which aren't taken in the newly formed word we take the whole set
QQ and in transitions we don't move at all for the parts which is not in the new words. So for example for the set
{x1x3x4∣x1x2x1x4x3x5∈L}
where
L is regular then take for starting state in the function automata
{id}×QQ×{id}×{id}×QQ×{0,1,2} [Though the
{0,1,2,3,4} is when it is necessary. Like in Question 1 or 4 we didn't need it but in Question 2,3 we needed it] and for final state
F′={(f1,f2,f3,f4,f5,2)∣f5∘f3∘f4∘f1∘f2∘f1(q1)∈F} and the transitions will be independent of the
f2,f5.
So now I think you have learned how to use this technique for solving such finite state automata problems.
Comments
Post a Comment