Skip to main content

Function Automata: A Technique to Solve Finite State Automata Problems

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 nN. 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,,q1n 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 qkiQ. 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)=qk2f(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 mN 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)=qk2id(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 qQ. Let the new formed Also let f=(qk1,qk2,,qkn) then for any letter aΣ δaf=(δ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 {wwwL}
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 ff(q1)=qkj means on reading w q1qki then qkiqkj therefore q1wqkiwqkjqwwqkj
So if ff(q1)F that means if qkjF. Hence for any fF if there exists a word w such that idwf then ˆδ(q1,w)F and similarly for any w, if wwL then take f=(ˆδ(q1,w),ˆδ(q2,w),,ˆδ(qn,w)). Now fF. Hence idwf. Therefore we set F={fQQff(q1)F}. All is left is to define Δ. TakeΔ={(f,a,δaf) fQQ,  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 {yxxyL}
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 gf(q1)=qkj means q1 first reads x and goes to qki and then reads y and goes from there to qkj.q1xqkiyqkjq1xyqkj
So if gf(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,gQQ, gf(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,(δag,f,0)),((g,f,0),a,(δag,f,1)),((g,f,1),a,(g,δaf,1))|  f,gQQ, 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 {xzyxyzxL}
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  fhgf(q1)=qk4q1fxqk1gyqk2hzqk3fxqk4q1xyzxqk4
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,hQQ, fhgf(q1)F}
And now you can guess what will be the set Δ. Δ={((f,h,g,0),a,(δaf,h,g,0)),((f,h,g,0),a,(δaf,h,g,1)),((f,h,g,1),a,(f,δah,g,1)),((f,h,g,1),a,(f,δah,g,2)),((f,h,g,2),a,(f,h,δag,2)),|  f,g,hQQ, 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 {xxyxL}
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)fQQ,fgf(q1)F}
Notice that the set {xxyxL} 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 fQQ we take all such pairs and then check if fgf(q1)F is satisfied or not. So here we take S={(id,g) gQQ}
And we define Δ Δ={((f,g),a,(δaf,g)) fQQ,  aΣ}

Now you get what is the idea behind choosing S. Yes if any word wL 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 {x1x3x4x1x2x1x4x3x5L}
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)f5f3f4f1f2f1(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

Popular posts from this blog

Hierarchy Theorems (Time, Space, Alternation)

There are many hierarchy theorems based on Time, Space, Nondeterminism, Randomization etc. Time Hierarchy Theorem (Version 1) : If f,g are time-constructible functions satisfying f(n)logf(n)=o(g(n)), then DTIME(f(n))DTIME(g(n))
Proof:  Consider the following Turing machine D: "On input x, run for f(|x|)log(f(|x|)) steps the Universal TM U to simulate the execution of Mx on x. If U outputs some bit b{0,1} in this time, then output the opposite answer (i.e., output 1b ). Else output 0.” Here Mx is the machine represented by the string x.      By definition, D halts within f(n)log(f(n)) steps and hence the language L decided by D is in DTIME(g(n)). Claim:  L DTIME (f(n)) Proof:  For contradiction's sake, assume that there is some TM M and constant c such that TM M, given any input x{0,1}, halts within cf(|x|) steps and outputs D(x)....

Cook - Levin Theorem

Around 1971, Cook and Levin independently discovered the notion of NPcompleteness and gave examples of combinatorial NPcomplete problems whose definition seems to have nothing to do with Turing machines. Soon after, Karp showed that NPcompleteness occurs widely and many problems of practical interest are NPcomplete. To date, thousands of computational problems in a variety of disciplines have been shown to be NPcomplete. SAT is the language of all satisfiable CNF formulae. Cook-Levin Theorem : SAT is NPcomplete Before we go into the proof first we need to define some things Configuration of a Turing Machine: A configuration of a Turing Machine at any point of time t is basically the snapshot of the turning machine at that time. It is an ordered pair of the head position, current state, and tape content. Any configuration is initialized and ended with a special symbol, let # mark its ending. Then the contents of the tape at the left of ...