− unusual / visual, different from conventional programming languages
+ major concepts of imperative programming (e.g. sequences, branching, loops) can be simulated
+ elegant, simple to use (visual), has a developed theory
+ all pattern matching can be described
− limited expressive power (constant amount of memory)
Combining two automata
High-level languages typically implement things such as method calling and modularity, in this section we try to determine if we can do the same with finite automata.
Design an automaton A such that L(A) consits of all the strings of as and bs that have either two consecutive as or two consecutive bs.
Since we already have the ‘methods’ to solve the problem for aas and bbs, we could design a ‘main program’ that would just call the given methods. One possible solution would be to combine the initial states.
L(A3)L(A3′)=all the words having two consecutive as=all the words having two consecutive bs
Observe that the state transition diagram on the previous slide no longer represents a DFA:
there is more than one a-arrow leaving state s
there is more than one b-arrow leaving state s
We say that this automaton is nondeterministic, this is because given a state s and reading a from the input tape, the device has a choice to either move to state q1 or s.
In order words, the next state is not determined by the previous state and the symbol read.
Apart from having a choice in certain situations, there are other permitted features in nondeterministic finite automata (NFA):
There can be states and symbols such that no arrow labelled by that symbol leaves thes tate in question: reading that symbol in the state the device would get stuck.
We also allow the machine to jump from a state to another state, without ‘consuming’ any input symbol from the tape (the head doesn’t move).
The allowed ‘state-jumps’ will be indicated on the state transition digrams by arrows labelled by the empty word ϵ.
From the NFA described above, we know that the states are s,q,r, the input alphabet is {a,b}, the initial state is s and the favourable state is s. We find the table:
a
b
ϵ
s
−
r
q
q
s
−
−
r
q,r
q
−
This table has a few notable features:
There can be ‘cells’ in the table containing no or more than one states.
The table has an ϵ-column (for any jumps).
An NFA can be regarded as a DFA if all cells in the ϵ-column are empty, and in vevery other column every cell contains a single state.
Acceptance of words by NFAs
In an NFA, there can be more than one computation on an input word. Some of these may end up in a favourable state, some may not.
A word w is accepted by NFA A if there is a computation of A on input w that ends up in some favourable state.
title: There may be other bad computations.
title: Getting stuck in a favourable state may not mean acceptance. The entire word needs to be read.
In any other case, A rejects the input word.
So an NFA can reject an input word w if every computation on w is either ‘stuck’ or ends up in a non-favourable state.
baba is accepted←{(s,baba),(q,baba)(s,baba),(r,aba),(q,ba),(q,a),(s,ϵ)stuckfavourableaa is accepted←{(s,aa),(q,aa),(s,a),(q,a),(s,ϵ)favourablebabba is accepted←⎩⎨⎧(s,babba),(q,babba)(s,babba),(r,abba),(r,bba),(q,ba)(s,babba),(r,abba),(q,bba)stuckstuckstuck, no more casesLink to original
11 is rejected←{(s,11),(q,1)(s,11),(p,11),(q,1)stuckstuck, no more00 is rejected←⎩⎨⎧(s,00),(s,0),(s,ϵ)(s,00),(s,0),(s,ϵ),(p,ϵ)(s,00),(s,0),(s,ϵ)(s,00),(s,0),(p,0)(s,00),(p,0)(s,00),(p,00)stuckstuckstuck, no more001 is accepted←{(s,001),(s,01),(s,1),(q,ϵ)⋯favourable stateLink to original
8. Designing NFAs
Designing NFAs
Nondeterminism can be viewed as a sort of parallel computing model, within which several processes can be running concurrently.
NDAs are much easier to design than DFAs, whatever can be done by an NDA can also be done (in a more complicated way) in a DFA. Nondeterminism does not increase computation power of finite automata.
In a DFA, we are not allowed multiple choices, being stuck or to use ϵ-jumps.
We need to define:
new states: named after subsets of the original NFA’s states
new initial state: the set containing the original NFA’s initial state, plus all states that are reachable from it by some ϵ-jumps
new favourable states: those subsets that contain at least one of the original NFA’s favourable states
digraph { init[shape=point] node[shape=doublecircle]; s, sq, sr, sqr; node[shape=circle]; init->sq s [label="{s}"] sq [label="{s,q}"] sr [label="{s,r}"] sqr [label="{s,q,r}"] 0 [label="{}"] r [label="{r}"] q [label="{q}"] qr [label="{q,r}"]}
The new states are named after subsets of the old states:
digraph { label="for each symbol x in the input alphabet" rankdir=LR P->a a[label="?"]}
Where ? is the set of all those states that are reachable from some state in the set P, either by a x-arrow or by an x-arrow followed by possibly one or more ϵ-jumps (but not ϵ-jump then x-arrow).
In a DFA every state must have one a-arrow out and one b-arrow out. We being with the initial state an compute where two arrows go from it:
a
b
{s,q}
{s,q}
{r}
We look at the NFA again to find that:
from s we cannot reach anything by an a-arrow
from q we can reach s by an a-arrow
from q we can reach q by an a-arrow followed by an ϵ-jump
Hence the a-arrow from state {s,q} goes to state {s,q} itself.
from s we can reach r by a b-arrow
from q we cannot reach anything by a b-arrow
The b-arrow from state {s,q} goes to state {r}.
Next, for every obtained new state, we compute where the a-arrow and the b-arrow goes from it. We do this until there are no newly obtained states.
An important field where finite automata are being used is in hardware design, some components of hardware (chips) are based on simulating DFAs.
Given a task, an NFA is designed, since it is easier to design than a DFA.
This NFA is turned into a DFA doing the same thing (using subset construction).
The number of states of the resulting DFA may increase significantly.
The worst case scenario is 2number of states of original NFA.
The resulting DFA is ‘minimised’, to obtain a DFA that has the minimum possible number of states for the given task.
title: There are various ways to do this, see recommended literature.