Two-way finite automata -...
-
Upload
duongnguyet -
Category
Documents
-
view
258 -
download
8
Transcript of Two-way finite automata -...
TWO-WAY FINITE AUTOMATA &
PEBBLE AUTOMATA
Written by Liat Peterfreund 1
AUTOMATA FINITE WAY-WOT
A two way deterministic finite automata (2DFA)
is a quintuple 0, , , ,M Q q F where:
0, , ,Q q F are as before
: { , }Q Q L R
o If ( , ) ( , )q a p L then in state q ,
scanning the input symbol a , the 2DFA enters state
p and moves its head left one square.
o If ( , ) ( , )q a p R then in state q ,
scanning the input symbol a , the 2DFA enters state
p and moves its head right one square. 2
:OMMENTSC
o In describing the behavior of one-way finite automata,
we extend to *Q . This notion is insufficient for 2DFA
because the head may move left.
o Instead we introduce the notion of instantaneous
description ( ID ) of 2DFA which describes the input string,
current state and current position if the input head.
o The relation M on ID 's such that 1 2MI I if and only if M
can go from 1I to 2I in one move.
o An ID of M is a sting in * *Q . 3
o The ID wqx whereas *,w x and q Q is
intended to represent :
1) wx is the input string
2) q is the current state
3) the input head is scanning the first symbol of x
(If x then the input head has moved off the
right hand end of the input).
4
o We define the relation M
or just if M is
understood, by
1) 1 2 1 1 2 1 1... ... ... ...i i n i i i na a a qa a a a a a pa a
whenever ( , ) ( , )iq a p R
2) 1 2 2 1 1 2 2 1... ... ... ...i i i n i i i na a a a qa a a a a pa a a
whenever ( , ) ( , )iq a p L and 1i (The
condition 1i prevents any action in the event
that the tape head would move off the left hand
end of the tape).
o Note that no move is possible if 1i n (the tape
head has moved off the right hand end).
5
Let * be the reflexive and transitive closure of .
*
1 kI I whenever 1 2 ... kI I I for some
2 1,..., kI I we
define *
0( ) | ,L M w q w wp p F . That is w is
accepted by M if, starting in state 0q with w on the input
tape and the head at the left end of w , M eventually enters
a final state at the same time it falls off the right hand of the
input tape. 6
Example:
Consider a 2DFA M that behaves as follows: starting in
state 0q , M repeats a cycle of moves wherein the tape head
moves right until two ones have been encountered then left
until encountering a zero at which point state 0q is reentered
and the cycle repeated. More precisely M has three states
all of which are final. is given as follows:
0 1
0q 0 ,q R 1,q R
1q 1,q R 2 ,q L
2q 0 ,q R 2 ,q L
7
Consider the input 101001:
0 1
1
2
0
1
1
1
2
101001 1 01001
10 1001
1 01001
10 1001
101 001
1010 01
10100 1
1010 01
q q
q
q
q
q
q
q
q
0
1
10100 1
101001
q
q
than 101001 ( )L M
8
Crossing sequences
The list of states below each boundary between squares is
termed a crossing sequence.
1 0 1 0 0 1
0q
1q 1q
2q
0q
1q 1q
1q
2q
0q
1q
9
Observations:
o If a 2DFA accepts its input, no crossing sequence
may have a repeated state with the head moving in
the same direction. Otherwise the 2DFA being
deterministic would be in a loop.
o The first time a boundary is crossed, the head must
be moving right.
o Subsequent crossings must be in alternate directions:
odd-numbered elements of the crossing
sequence represents right moves
even-numbered elements of the crossing
sequence represents left moves
10
o If the input is accepted then all crossing sequences
are of odd length
o A crossing sequence 1,..., kq q is said to be valid if :
it is of odd length
no two odd-numbered and no two even-
numbered elements are identical
o The number of valid crossing sequences is finite (a
2DFA with s states can have valid crossing sequence
of length at most 2s-1). 11
Theorem:
2DFA and DFA (deterministic finite automata) have the
same expressive power.
12
Proof:
o We construct a NFA (non-deterministic finite automata)
that will simulate the 2DFA M and whose states are
the valid crossing sequences of M .
o In order to construct the transition function we first
examine the relationship between adjacent crossing
sequences.
13
o Suppose we are given an isolated tape square holding the
symbol a and are also given valid crossing sequences
1 2, ,..., kq q q and 1 2, ,..., lp p p at the left and the right
boundaries of the square, respectively.
Note that there may be no input strings that can
be attached to the left and right of symbol a to
actually produce these two crossing sequences
14
o We can test two sequences for local compatibility as
follows:
If the tape head moves left from the square
holding a in state iq , restart the automaton on
the square holding a in state 1iq
If the tape head moves right from the square
holding a in state ip , restart the automaton on
the square holding a in state 1ip
15
We take 1 2, ,..., kq q q to appear at the left boundary of a and
1 2, ,..., lp p p at the right boundary of a then,
1 2, ,..., kq q q right-match
1 2, ,..., lp p p on a if these
sequences are consistent, assuming we initially reach
a in state 1q moving right
1 2, ,..., kq q q left-match 1 2, ,..., lp p p on a if these
sequences are consistent, assuming we initially reach
a in state 1p moving left 16
We define right-matching and left matching pairs of crossing
sequences recursively in (1) through (5):
(1) The null sequence left- and right-matches the null
sequence. (if we never reach the square holding a ,
then it is consistent that the boundaries on neither
side should be crossed).
17
(2) If 3,..., kq q right-matches 1 2, ,..., lp p p
and
1 2( , ) ( , )q a q L then 1 2, ,..., kq q q
right-matches
1 2, ,..., lp p p (if the first crossing of the left boundary
is in state 1q and the head immediately moves left in
state 2q, then if we follow these two crossings by any
consistent behavior starting from another crossing of
the left boundary, we obtain a consistent pair of
sequences with first crossing moving right i.e. a right
matched pair).
(3) If 2 ,..., kq q left-matches
2 ,..., lp p and
1 1( , ) ( , )q a p R then 1 2, ,..., kq q q right-matches
1 2, ,..., lp p p .
18
(4) If 1,..., kq q left-matches
3,..., lp p and
1 2( , ) ( , )p a p R then 1,..., kq q left-matches
1 2, ,..., lp p p .
(5) If 2 ,..., kq q right matches 2 ,..., lp p and
1 1( , ) ( , )p a q L then 1,..., kq q left-matches
1 2, ,..., lp p p .
19
The construction:
Let 0, , , ,M Q q F be a 2DFA . We contruct a NFA
0' ', , ', ', 'M Q q F which accepts ( )L M such that:
1) 'Q consists of all valid crossing sequences for M .
2) 0 'q is the crossing sequence consisting of
0q alone.
3) 'F is the set of all crossing sequences of length one
consisting of a state in F .
4) | is a valid crossing sequence
'( , )that is right matched by on input
d dc a
c a
20
The intuitive idea is that 'M puts together pieces of
computations of M as it scans the input string. This is
done by guessing successive crossing sequences. If 'M
has guessed that c is the crossing sequence at a
boundary, and a is the next input symbol then 'M can
guess any valid crossing sequence that c right matches
on input a .
If the guessed computation results in M moving off the
right end of the input in an accepting state, then 'M
accepts. 21
Claim:
( ) ( ')L M L M
Proof:
( ) ( ')L M L M :
Let ( )w L M . Look at the crossing sequences generated by
an accepting computation of M on w . Each crossing
sequence right-matches the one at the next boundary, so 'M
can guess the proper crossing sequence (among its other
guesses) and accept i.e. ( ')w L M .
22
( ') ( )L M L M :
Let ( ')w L M .
Consider the crossing sequence 0 ,..., nc c of M
corresponding the states of 'M as 'M scans
1,..., nw a a .
For each 0 i n ic right matches 1ic on ia
We can construct an accepting computation of M on
input w by determining when the head reverses
direction. 23
We prove by induction on i that 'M on reading 1... ia a
can enter state 1,...,i kc q q only if the following two
conditions hold:
1) M started in state 0q on
1... ia a will first move right
from position i in state 1q
2) for 2,4,...j , if M is started at position i in state
jq , M will eventually move right from position i in
state 1jq (this implies k must be odd). 24
Basis: 0i then 0 0c q . (1) is satisfied since M
begins its computation by "moving right from position
0" in state 0q . (2) holds vacuously.
25
Assume the hypothesis is true for 1i . Suppose that
'M on reading 1... ia a can enter state
1,...,i lc p p from state 1 1,...,i kc q q .
o Since k and l are odd, and 1ic right
matches ic on ia there must exist an odd j
such that in state jq on input ia , M moves
right. Let 1j be the smallest such j . By
definition of "right matches" it follows that
1 1 1( , ) ( , )jq a p R . This proves (1).
o We will prove (2) by induction:
Basis: vacuously
Inductive step: by the definition of
"right-matches" (rule (3))
1 1[ ,..., ]j kq q left-matches 2[ ,..., ]lp p
26
Now if 1( , ) ( , )j i jp a p R for all
even j , then (2) follows immediately.
In the case that for some smallest
even 2j ,
2( , ) ( , )j ip a q L , then by
definition of "left-matches" (rule (5))
q must be 1 1jq
and 1 2[ ,..., ]j kq q
right matches 2 1[ ,..., ]j lp p
By induction hypothesis, (2) holds for
1 2[ ,..., ]j kq q and 2 1[ ,..., ]j lp p 27
With the induction hypothesis for all i established, the
fact that [ ]nc p for some p F implies that M
accepts 1... na a .
28
Reminder - Example:
Consider a 2DFA M that behaves as follows: starting in
state 0q , M repeats a cycle of moves wherein the tape head
moves right until two ones have been encountered then left
until encountering a zero at which point state 0q is reentered
and the cycle repeated. More precisely M has three states
all of which are final. is given as follows:
0 1
0q 0 ,q R 1,q R
1q 1,q R 2 ,q L
2q 0 ,q R 2 ,q L
29
Consider the construction of NFA 'M equivalent to the
2DFA M :
Since 2q is only entered on a left move and 1q and 3q are
only entered on right moves, all even numbered
components of valid crossing sequences must be 2q .
Since a valid crossing sequence must be of odd length,
and no two odd numbered states can be the same, nor
can two even-numbered states be the same, there are
only four crossing sequences of interest:
0 1 0 2 1 1 2 0[ ],[ ],[ , , ],[ , , ]q q q q q q q q . 30
Their right matches:
Valid crossing sequences
Right matches on 0
Right matches on 1
0[ ]q 0[ ]q 1[ ]q
1[ ]q 1 1 2 0[ ],[ , , ]q q q q -
0 2 1[ , , ]q q q - -
1 2 0[ , , ]q q q - 1[ ]q
Thus the automaton is:
0 0
1
1 0
0[ ]q
1[ ]q
1 2 0[ , , ]q q q
31
Pebble Automata
32
Preface:
We consider strings over infinite alphabet D .
A -stringD is a finite sequence 1... nd d where 0n
and 1 : ii n d D .
dom( ) 1,2,...,w w .
For dom( )i w we write ( )wval i for id .
A language is a set of -stringsD .
33
We delimit input strings by two special symbols ,
for the left and for the right of the string, neither of
which are in D .
Therefore the automata work on extended strings of
the form w u where *u D .
The positions of , are 0 and 1w respectively
We write ( )dom w for the extended set
0,..., 1w of positions
We likewise extend the function wval by defining
(0)wval and ( 1)wval w
34
Pebble automata are finite state machines equipped
with a finite number of pebbles.
The use of pebbles is restricted by a stack discipline
(pebble 1i can only be placed when pebble i is
present on the string and pebble i can only be lifted
when pebble 1i is not present on the string).
The highest numbered pebble present on the string
acts as the head of the automaton.
35
A transition depends on:
o The current state
o The pebbles placed on the current position of
the head
o Equality type of the data values under the
placed pebbles.
The transition relation specifies:
o Change of state
o Movement of the head
o Possibly whether the head pebble is removed
or a new pebble is placed 36
Definition:
A nondeterministic two-way k-pebble automaton A over D
(infinite alphabet) is a tuple 0( , , , )Q q F T where:
o Q is a finite set of states
o 0q Q is the initial state
o F Q is a set of finite states
37
o T is a finite set of transitions of the form
where
o is of the form ( , , , , )i s P V q or ( , , , )i P V q
where 1,...,i k , ,s D ,
, 1,..., 1P V i
o is of the form ( , )q d with q Q and
stay,left,right,place-new-pebble,
lift-current-pebbled
38
Given a string w , a configuration of A on w is of the form
, ,i q where 1,...,i k , q Q and
:{1,..., } dom ( )i w .
We call pebble assignment and i the depth of
configuration (and of pebble assignment).
Initial configuration: 0 0 0: 1, ,q where 0(1) 0 .
Accepting configuration: , ,i q where F . 39
A transition ( , , , , )i s P V q applies to a configuration
, ,j q if:
1) ,i j p q
2) | ( ( )) ( ( ))w wV l i val l val i
3) | ( ) ( )P l i l i
4) ( ( ))wval i s
A transition ( , , , )i P V q applies to a configuration
, ,j q if 1-3 holds and no transition
( , , , , )i s P V q applies to . 40
We define the transition relation as follows:
[ , , ] [ ', ', ']i q i q iff there is a transition ( , )p d that
applies to such that 'q p and : '( ) ( )j i j j and:
If stayd , then 'i i and '( ) ( )i i
If leftd , then 'i i and '( ) ( ) 1i i
If rightd , then 'i i and '( ) ( ) 1i i
If place-new-pebbled , then ' 1i i and
'( ) '( 1) ( )i i i
If lift-current-pebbled , then ' 1i i
41
An automaton is deterministic if in each configuration at most
one transition applies.
If there are no left transitions then the automaton is one-
way.
The language of the automaton: A string w is accepted by A
if *
0 for some accepting configuration .
42
Example 1:
Let 1... | 0, , :n i jL d d n i j i j d d .
We define a 2-pebble-automata A accepting this language.
0( , , , )A Q q F T is defined as follows:
1 2, , , accQ q q q q
{ }accF q
T consists of the following transitions:
(1) 1 1(1, , , ) ( , right)q q
(2) 1(1, , , ) ( ,place-new-pebble)q q
(3) 2(2,{1},{1}, ) ( , right)q q
(4) 2 2(2, , , ) ( , right)q q
(5) 2(2, ,{1}, ) ( ,stay)accq q
43
Intuitive explanation:
(1-2) A stays in state 1q while moving to the right or places a
pebble
(3) After the placement of the pebble A moves one position
to the right
(4-5) A continues moving to the right and when it reads a
symbol equal to the symbol under the first pebble, it moves
to the final state 44
Example 2:
Let *$ | , $ [ ] [ ]L u v u v D D u v whereas
[ ],[ ]u v are the sets of all the letters of ,u v respectively.
We define a 2-pebble-automata A accepting this language
that operates as follows:
o The first pebble passes through all of the positions of
the word u (until it encounters the sign $ ) and for
each such position it checks whether there is a
position in v with the same letter.
o The above check is done by placing the second pebble
and iterating through all of the positions in v - if
there is such a position it lifts the pebble and
continues with the next position in u , if there is not it
rejects.
o When the first pebble reaches the $ it moves to an
accepting state.
45
Formally, 0( , , , )A Q q F T whereas
0 , , , , ,u uv v rej accQ q q q q q q , accF q and T contains
the following transitions:
0( 1)(1, , , ) ( , right)
( 1)(1,$, , , ) ( ,stay)
( 1)(1, , , ) ( , place-new-pebble)
( 2)(2,{1},{1}, ) ( , right)
( 2)(2,$, , , ) ( , right)
( 2)(2, , , ) ( , right)
( 2)(2, ,{1}, ) ( , r
u
u acc
u uv
uv uv
uv v
uv uv
uv uv
a q q
b q q
c q q
a q q
b q q
c q q
d q q
0
ight)
( 2)(2, ,{1}, ) ( , lift-current-pebble)
( 2)(2, , , , ) ( ,stay)
( 2)(2, , , ) ( , right)
v
v rej
v v
e q q
f q q
g q q
46
Intuitive explanation:
( 1)a is used to skip a sign
( 1),( 1)b c are used to iterate all over u 's elements
( 2) ( 2)a d skip the end of u and the $
( 2) ( 2)e f iterates through v and compares the sign under
the current pebble with the sign under pebble 1
47
Example 3:
We define a two-way nondeterministic pebble
automaton with three pebbles that accepts all words
w where 2w and there exists some position i in
( )dom w such that the set of symbols occurring at
positions smaller than i is disjoint from the set of
symbols occurring at position larger than or equal to
i .
For example the automaton accepts abb and
rejects abab 48
The automaton will work as follows:
o The first pebble is used nondeterministically
to guess i
o The second pebble is used to step through
position to the left of i one at a time, from
1i to
o For each such position of the second pebble,
the third pebble is used to check that all
symbols at positions i are distinct from the
symbol under the second pebble.
o The input is excepted if the second pebble
can reach the leftmost symbol
49
Formal definition: , , ,oA Q q F T where
0 7,...,Q q q , 5{ }F q and T is the set of
transitions:
50
0 0
0 1
1 2
( 1) (1, , , , ) ( , right) } skip
(b1) (1, , , ) ( , right) } 1
(c1) (1, , , , ) ( ,stay) } reached the e
a q q
q q i
q q
1 1
1 3
3 4
nd without guessing
(d1) (1, , , ) ( , right) guess
(e1) (1, , , ) ( , place-new-pebble)
( 2) (2,{1},{1}, ) ( , left) } move to pos
i
q qi
q q
a q q
3 4
4 5
ition 1
( 2) (2, , , ) ( , left) } move one position left (after lifting pebble 3)
( 2) (2, , , , ) ( ,stay) } finished reading
i
b q q
c q q
4 6
6 6
6 6
6 6
positions 1
( 2) (2, , , ) ( , place-new-pebble) } "save" position
( 3) (3,{2},{2}, ) ( , right)
(b3) (3, , ,q ) ( , right)
( 3) (3, ,{2}, ) ( , right)
( 3) (3,{1}
i
d q q
a q q
q
c q q
d
6 7
7 7
7 3
7 7
move right to position 1
,{1}, ) ( , right)
(e3) (3, ,{1},q ) ( , right)
( 3) (3, , , , ) ( , lift-pebble) scan positions >
( 3) (3, , , ) ( , right)
i
q q
q
f q q i
g q q
51
For example, an accepting run on abb will be:
52
In the above definition, new pebbles are placed at the
position if the most recent pebble. An alternative would
be to place new pebbles at the beginning of the string.
While the choice makes no difference in the two-way
case, it is significant in the one way case. We refer to the
model as defined above as weak pebble automata and to
the latter as strong pebble automata. Strong pebble
automata are formally defined by setting '( 1) 0i in
the place-new-pebble case of the definition of the
transition relation. 53
54
Our next result shows that the variants of strong pebble
automata, one-way and two-way, collapse.
Theorem:
Two-way weak 2-pebble automata and two-way strong 2-
pebble automata have the same expressive power.
55
Proof:
Let , , ,oA Q q F T be a two-way strong 2-pebble
automaton. We want to construct a two-way weak 2-pebble
automaton that will simulate A 's behavior.
Idea of construction: For every state in q Q we will add a
new state 'q and transition that such that the automaton head
will move left until it encounters the left delimiter and then
move to the appropriate state.
56
Let , , ,oA Q q F T be a two-way weak 2-pebble
automaton. We construct a two-way 2-pebble strong
automaton that will simulate A 's behavior. The only difference
between the automata is in placing a new pebble.
Idea of construction: For every state in q Q we will add a
new state 'q and transition that such that the automaton head
will move right until it encounters the first pebble and then
move to the appropriate state.
57
Theorem:
Two-way strong 2-pebble automata and one-way strong 2-
pebble automata have the same expressive power.
Proof:
A one-way strong 2-pebble automaton is a particular case of
two-way strong automaton.
58
Claim: For each two-way non-deterministic pebble automata
A there is a strong one-way deterministic pebble automata that accepts the same language.
Proof: Assumptions:
(1) A lifts pebble only in the right delimiter (2) A accepts its input only in configurations [1, q, θ],
i.e., with only one pebble.
59
By virtually adding two steps we view an accepting computation as consisting of: (1) a first step in which the first pebble is placed at the left delimiter, i.e., position 0. (2) a computation in which always at least one pebble is present. (3) a final step in which the only remaining pebble is removed.
60
Writing [0, , ]p for a (virtual) configuration without pebble,
to determine whether A accepts, one has to find out whether *
0[0, , ] [0, , ]q q for some final state q.
The latter can be done by recursively solving subproblems of
the form *[ , , ] [ , ', ]ii q i q
where the subscript > i indicates that only subcomputations are considered in which, at every step, more than i pebbles are present.
61
More formally, we show the following claim by induction on i (starting from i = k).
Claim: For each {0,...,k}i and each finite set of states R,
there is a strong one-way deterministic pebble automata Bi
(with k pebbles) such that, whenever Bi starts from a
configuration[i,p, ] , where p R , the next configuration of
depth i of Bi is [i, (p, S), ] , where *S {(q,q ) | [i,q, ] [i, q , ]}.iQ Q
The set of states of Bi includes R and 2R RR .
62
The theorem indeed follows from the claim: Let i = 0 and let
0R {p } (the intended initial state of 0B ). We obtain an
automaton which ends up in a state 0(p , S) where *
0S {(q,q ) | [0,q, ] [0,q , ]}Q Q
The set of final states of 0B consists of all states 0(p , S)
where S contains a pair 0(q , q) with q F .
63
For i k the proof of the claim is trivial, as there are no
configurations of depth k . Hence, kB can compute (p, S)
by a stay-transition.
Therefore, let i k and suppose the claim holds for all j i
64
Let the input string w of length n be fixed. Hence iB
works on the string w with positions from
dom ( ).w
For 1l n , let l denote the ( 1)i -pebble
assignment that coincides with in the first i pebbles
and for which ( 1)l i l .
( )lS is the set of pairs ( , )q q of states such that
there is a computation starting at [ 1, , ]li q and
reaching [ 1, ', ]li q which only includes
configurations [ , , ]j q that fulfill 1j i or (
1j i and ( 1)i l ). Intuitively, this says that
pebble 1i is not allowed to move to the right of
position l .
65
We write ( )lS for the set of pairs ( , )q q of states
for which [ 1, , ]li q can be reached from 1[ 1, , ]i q by a subcomputation satisfying the same
property.
The set ( )lS can be computed as follows:
Let ( )lR be the set of pairs ( , )q q for which one
of the following holds:
(a) There exist 1 2,p p such that 1
1[ 1, , ] [ 1, , ]l li q i p , 1
1 2( , ) ( )lp p S and 1
2[ 1, , ] [ 1, , ]l li p i q .
(b) *
1[ 1, , ] [ 1, , ]l l
ii q i q
(c) [ 1, , ] [ 1, , ]l li q i q
66
( )lS is the transitive closure of ( )lR .
They are computed simultaneously.
The information needed for (a) can be computed in one
left-to-right pass of pebble 1i .
By induction we can assume a subautomaton 1iB that
computes, for each position l , the part of ( )lR
contributed by condition (b).
(c) and the computation of the transitive closure do not require any pebble movements.
During the same pass, the automaton can compute, for
each position l , the set ( )lS . The computation of
( )lS makes use of the sets ( )mS , m l .
67
From 1( )nS , 1( )nS and the transition relation
of A one can deduce, during a lift-pebble step, the set
S as in the claim. Note that 1n is the position of the
right delimiter and recall that A lifts its pebbles only at that position.
This completes the proof of the claim and of the
theorem.