Efficient Learning of Real Time One-Counter Automata

We present an e(cid:14)cient learning algorithm for languages accepted by deterministic real time one counter automata (ROCA). The learning algorithm works by (cid:12)rst learning an initial segment, Bn, of the in(cid:12)nite state machine that accepts the unknown language and then decomposing it into a complete control structure and a partial counter. A new e(cid:14)cient ROCA decomposition algorithm, which will be presented in detail, allows this result. The decomposition algorithm works in O(n 2 log(n)) where nc is the number of states of Bn for some constant c. If Angluin's algorithm for learning regular languages is used to learn Bn and the complexity of this step is h(n;m) where m is the length of the longest counter example necessary for Angluin's algorithm, the complexity of our algorithm is thus O(h(n;m) + n 2 log(n)).


Introduction
We present an e cient learning algorithm for languages accepted by deterministic real time one counter automata (ROCA).The learning algorithm works by rst learning an initial segment, B n , of the in nite state machine that accepts the unknown language and then decomposing it into a complete control structure and a partial counter.A new e cient ROCA decomposition algorithm, which will be presented in detail, allows this result.The decomposition algorithm works in O(n 2 log(n)) where nc is the number of states of B n for some constant c.If Angluin's algorithm for learning the regular languages is used to learn B n and the complexity of this step is h(n; m) where m is the length of the longest counter example necessary for Angluin's algorithm, the complexity of our algorithm is thus O(h(n; m) + n 2 log(n)).
Roos and Berman BR87] and Roos Roo88], were the rst to nd a polynomial time algorithm for the exact learning of Deterministic One Counter Automata (DOCA) as de ned by Valiant in VP75].The polynomial is of large degree thus motivating this work to nd a practical algorithm.Fahmy and Biermann FB93] and Fahmy Fah89] introduced the idea of learning by automata decomposition.The method is applicable to a very wide class of real time languages using a variety of data structures such as counters, stacks, queues and double counters, however the algorithms they present are of exponential time in the worst case.The de nitions of control strcutures, data structures and behavior graphs that we use here and the relation between them were rst given in Bie77] and subequently in FB93].
A discussion and an example of the learning process will be presented in Section 2. Following this, de nitions of the control structure, the counter, the behavior graph and the relation between them are given in Section 3. In Section 4 the decomposition theorem and decomposition algorithm will be presented.Some notation and detailed proofs of lemmas are given in an Appendix.

The Learning Algorithm
We will present the learning process for a ROCA language using an example.Consider the language L = fa n ccb n d j n > 0g fa n d j n > 0g.This language is not regular and is accepted by an in nite state machine that we call the behavior graph (BG) and is denoted by B. An initial segment of B that includes all the states that are distance n or less from the initial state of B will be denoted by B n .The BG for our example appears in Figure 1.Note that transitions to dead states are not shown.
A ROCA A = (C; D) for L is a pair of state machines that also accepts L. C is a nite state machine called the control structure (CS) and D, called the data structure, is an in nite state machine that simulates the counter.State diagrams for a CS that accepts L and the counter also appear in Figure 1.L is accepted by A in the following manner.Input symbols are read by C which, using the symbol, its current state and the state of the counter, changes its states.While it is changing its state it sends a single instruction to the counter which it uses to change its state too.The triple (sym, val, instr) appear on the transitions of the CS in Figure 1 where sym is the input symbol, val is 0 if the counter state is 0 and :0 otherwise.If the nal symbol of an input string causes C to end up in a nal state then we say that the ROCA has accepted the input string.
In this paper we show that B is decomposable into C and D. We give e cient algorithms to do this decomposition.
The learning process for a ROCA language L starts by constructing B n , for some natural number n, for the unknown language.B n is constructed using a slight modi cation of Angluin's algorithm for the regular languages using queries and counter examples.After constructing B n and if n is large enough, the learning algorithm will be able to decompose B n into a complete CS and a nite counter.The nite counter is then replaced with an in nite one and the learning algorithm will have constructed a complete ROCA for the unknown language.The value of n depends only on the language being learned; it could be small for very simple languages and large for complex ones.
We note that Angluin's algorithm will not terminate if the state machine that accepts L has an in nite number of states as in the case of ROCAs.Thus the teacher must choose a suitable depth n after which it asks the learner to decompose B n .Also the teacher has to provide counter examples that will enable the learner to construct a complete B n in the sense that no states will be missing from B n .
After constructing B n , the learner will attempt to decompose it into a complete CS and a nite counter.
The CS must be complete in the sense that no transitions from it are missing.The decomposition is done by performing what we call a parallel breadth rst search (PBFS) from certain states.The PBFS marks the states of B n , for our example, the PBFS starts at states b1, b2, b3, and b4.The parallel searchs must mark isomorphic submachines of B n .In our example these isomorphic graphs are labeled G 0 , G 1 , G 2 and G 3 in Figure 1.These markers are then used to construct partitions over the set of states of B n that are necessary for the decomposition.Using the partitions it is then easy to construct the CS and the nite counter.To identify the states where the PBFS must start, a string w identifying a path from the initial state of B n to an exit point in B n must be identi ed.w is then broken into a string of the form xw 0 where w 0 is of the form y k for some k.The PBFS starts from the states reachable using the strings xy i 1 i k.In our example there is only one exit point reachable using the string w = a 5 and w is broken into x = a and y = a and the PBFS starts at states b1, b2, b3, and b4.The BFSs are performed in a manner that guarantees that the resulting graphs are all isomorphic.In our example, the transitions (b1; c); (b2; c); (b3; c) and (b4; c) are all done in parallel.If for any one of the searches a transition is missing, then the PBFS is declared a failure.If the searches collide then we require that they all collide in a single state as in state bf for this example.The searches can run into each other only in a well de ned manner where the search numbered i can collide with searches number i + 1 or i 1. Again it is required that they all collide in the same way.In general, it is possible to have more than one exit point and the process would be repeated for each one.
In the reset of this paper we formalize the notions presented in this section and prove it correct.
3  1.A formal de nition of the counter is given in the Appendix.A counter can be thought of as the memory of a computing device; it cannot, on its own, accept or reject input strings since it has no nal states.It is a means by which a ROCA can count the occurrence of some event such as counting the number of times a certain string has appeared in the input for example.

The Control Structure
The second component of a ROCA is the control structure which is a deterministic nite state machine that reads input symbols from a nite non-empty alphabet .Its next state depends on its own current state, the output value of the current state of the counter and the input symbol.The control structure issues instructions to the counter while it is changing states i.e. instructions to the counter appear on the control structure's transitions.O C is a set of instructions that can be issued to the counter, O C = D = fi; d; n; rg.

Real Time One Counter Automata
A Real Time One Counter Automaton (ROCA) A is a pair of state machines (C; D) where C, is a control structure and D, the data structure, is an in nite state machine that is isomorphic to a counter.A ROCA reads one input symbol at a time.After reading each symbol the CS changes states from its current state by examining the output symbol of the current state of the counter and using its transition function it makes the transition to the next state.While it is doing so, it sends exactly one instruction from the set fi; d; n; rg to the counter.The counter receives the instruction and executes it.The ROCA is now ready for a new symbol.If the input symbol has caused the CS to be in a nal state then we shall say that the ROCA has accepted the input string, otherwise we say that the input string has been rejected.
The following de nitions explain, in a more formal manner, how a ROCA works and how it accepts strings.An instantaneous description (ID) of a ROCA is given by the pair < c; d > where c and d are the current states of its CS and DS respectively.The initial ID of the ROCA is the ID < c 0 ; d 0 >.If the current ID of ROCA A is < c; d >, the following events take place when A reads an input symbol : A ROCA A accepts a string 2 i the sequence of transitions induced by the letters of leads from < c 0 ; d 0 > to < c 0 ; d 0 > where c 0 2 F C and the counter never enters its error state.Let L(A) denote the language accepted by A, that is L(A) = f 2 j A accepts : g Such a language will be called a ROCA language.

The Real Time Constraint
From the previous de nitions we can see that the CS of a ROCA, when given an input string of length n, can issue exactly n instructions, some of which could be the null or do nothing instruction, to the counter; one instruction per input symbol.So, for example, if the current state of the counter is d and if the current input string is of length n, then after the CS reads the input string, it can leave the counter in a state d 0 such that d n d 0 d + n In this respect the ROCA is more restricted than the DOCA since DOCAs can change the value of the counter by more than one per input symbol and also because ROCAs are not allowed to make epsilon transitions.

The Behavior Graph of a ROCA
A ROCA works in much the same way as nite state machines that accept the regular languages work.It consumes one input symbol at a time and after each such symbol we can determine if it has accepted the input.We shall now de ne a single in nite state machine that can do the work that a ROCA does.
De nition 3.3 The behavior graph (BG) of a ROCA A is the reduced Moore type state machine B = fS B ; ; B ; b 0 ; F B g that accepts L = L(A).
The BG is reduced in the sense that among its states, no two are equivalent.The BG of a ROCA is unique, up to isomorphism.It is a state machine with in nite number of states.
If L is the right invariant equivalence relation de ned by L over , L ( ) is the block of L that contains and T L ( ) is the set of su xes of with respect to L, then B is de ned as follows: S B = L , the set of states of the BG is the set of blocks of the partition L where 1 2 ( L ) i T L ( 1 ) = T L ( 2 ). is the same input alphabet as that of A.
B : S B ! S B and is de ned as follows B ( L ( ); ) = L ( ) , where e is the null string.The initial state of B is the unique block of L that contains the null string.
F B = f L ( ) j e 2 T L ( )g.The set of nal states of B is the set of blocks of L such that the null string is a su x for strings in the block.
B is well de ned since L is a right invariant equivalence relation i.e. if 1 2 ( L ) then 8 2 ; 1 2 ( L ).A string is accepted by a BG if it drives B from its initial state b 0 to a state b 2 F B , i.e. if the null string is in T L ( ).So far we have two di erent views of the language accepted by a ROCA; the CS and the counter of the ROCA working together to accept strings in the language and the BG that accepts the language.In the next section we will relate the two views.Our goal is to show that the CS and DS are a decomposition of the BG.

The Product of a Control Structure by the Counter
Let A = fC; Dg be a ROCA, the product of the CS by the counter is going to be a third machine M C D .
The set of states of the product machine is a subset of S C S D .The alphabet of the product machine is going to be the input alphabet, of the ROCA.To connect state (c; d) to state (c 0 ; d 0 ), there must be a transition from c to c 0 in C and a transition from d to d 0 in D. The instruction labeling the transition from c to c 0 must be the same as that leading from d to d 0 .Also the transition from c to c 0 must be labeled with a test value from O D which is the same as that of d.The initial state of the product machine is (c 0 ; d 0 ).State (c; d) will be labeled as a nal state of the product machine if c is a nal state of C. Notice that the product machine will contain many useless states, i.e. states that are unreachable and states that have no tails.If all the useless states are deleted from the set of states of the product machine, it will not a ect the language it accepts.

The Repetitive Structure of the Behavior Graph
De ne the mapping g from the set of con gurations to the set of states in the BG so that each state of M C D is mapped to the state corresponding to it.Then g(p; i) = g(q; j) i (p; i) is equivalent to (q; j).In other words, g maps con gurations, (c; d)-pairs into their equivalence classes, which, in turn, are the states of the BG.Extend g to submachines in the obvious way, i.e., map transitions using g( C D ((p; i); a)) = B (g(p; i); a).Then a subgraph of M C D is mapped into a subgraph of the BG.
Let X be a set of con gurations, let G(X) be the graph induced by X, i.e., the portion of the con guration graph containing X and all transitions among elements of X.Let X m;n be the set of reachable con gurations nX m;n = (p; i) : p 2 S C ; m i < n We call this a "slice" of the con guration graph; it consists of all con gurations with counter values bounded above and below by xed constants.
The overall goal is to prove that: There exist two constants, H and K, such that the graphs G(X H;H+K ); G(X H+K;H+2K ); G(X H+2K;H+3K ); :::: all have isomorphic images under the mapping g.Moreover, either all these images coincide, or they are all distinct subgraphs of the BG.Because a ROCA can distinguish only between zero and nonzero counter values, the in nite transition diagram of the automaton M C D has a special kind of translational invariance with respect to the counter value.More precisely, if C D ((p; i); a) = (q; j), for i; j > 0, then C D ((p; i + k); a) = (q; j + k) for any k > 0, and if C D ((p; i); a) = (q; 0) for some i > 1, then C D ((p; i + k); a) = (q; 0) for all k > 0.
We now show that we can assign arti cial counter values to the states of the behavior graph B to give it a similar repetitive structure; one way to do this is by examining the equivalence classes of the reachable states in M C D .We will drop the subscript \C D" on our transition function in the following discussion.
We need the following fact, whose proof should be self-evident: If ((p; i); w) is nal and ((p; j); w) is non nal, for some i; j > 0, then at least one of the two computations on w must visit a state (q; 0) without performing a reset.The next fact is an immediate consequence of the preceding one: For each w 2 , for each p 2 S C , there is a threshold value t (no larger than 1 + jwj) such that the states ((p; t + i); w) are all nal or are all non nal for every i 0.
Lemma 3.1 For each p 2 S C , there are constants t and k such that for each j, 0 j < k, either: all states (p; t + j + rk); r 0, are pairwise nonequivalent, or all states (p; t + j + rk); r 0, are equivalent Proof sketch.A detailed proof appears in the Appendix.Suppose there exist i; j > jS C j and string w such that ((p; i); w) and ((p; j); w) consist of a nal and a non nal state.By \pumping" a certain substring of w we can obtain pairwise nonequivalence for an in nite set of states f(p; r i )g where the r i belong to an in nite index set with a regular structure parameterized by a constant d jS C j. Iterate this process.We achieve the lemma with threshold t = maxflengths of all witnesses usedg and k = least common multiple of all the ds.(See gure 2(a).) 2 Corollary 3.1 There is some threshold t and constant k such that, for any p 2 S C , the results of the previous lemma hold.
Proof.Repeat the lemma for each state; take the largest threshold and the least common multiple of all the ks. 2 Lemma 3.2 Let p and q be any two states.There is a threshold t and a constant k such that, for each i; j; 0 i; j < k, either: (p; t + i + mk) and (q; t + j + mk) are nonequivalent for each m 0; or (p; t + i + mk) and (q; t + j + mk) are equivalent for all m 0.
Proof sketch.A detailed proof appears in the Appendix.Suppose we have a witness w to the nonequivalence of some state pair (p; i) and (q; j).In the only hard case that needs to be considered, we consider the two witness computations side-by-side.Some pair of states must repeat, forming \descending loops" in both computations over the same substring of w.By a case analysis, we can show that the family of witnesses obtained by \pumping" the loop will yield in nitely many nonequivalences of p-and q-state pairs above a certain threshold t. (See gure 2(b)). 2 We can now observe the desired regularity condition in B by assigning the labels to its states.Let t and k be the constants guaranteed by the lemma.For each state s of B, consider the set E(s) of states of M C D that are equivalent to s. Uniformly choose some representative state (p; i) from E(s) (e.g., the lowest-numbered state in the equivalence class, and the lowest counter value appearing with that state).If E(s) is an in nite set, or if it contains only states whose counter values are less than the threshold t determined by the last lemma, assign a unique state name and a counter value of zero to s.Otherwise, i is of the form t + kr + j, so assign s the name p; j] and the counter value r.The translational invariance now holds.
Now that we know that a labeling exists which establishes the regular structure of B, we know that any search for such a labeling will take place in a nonempty search space (although we will obtain our labels in a di erent way).
4 Decomposing the Behavior Graph of a ROCA Hartmanis and Stearns HS66] developed a theory for the decomposition of nite state machines in the early sixties.By decomposing a state machine into a number of state machines that emulate the behavior of the composite machine they were able to use less electronic components to realize the machine.They invented what is known as partition pairs, see the Appendix for a de nition, The basic idea behind decomposition is to merge states, and thus the use of partitions, while preserving the transitions.Merged states in one machine must not be merged in at least one other component machine.In this section we discuss the decomposition theorem that will tell us exactly when a decomposition is possible.

The Associated Partitions of a ROCA
Given a ROCA and its BG, Theorem 3.1 states that every state of the BG is equivalent to a state of M C D and vice versa.We shall de ne two partitions over the states of BG that group states with the same components in the same block.One partition groups states of the BG that have the same CS component in the same block and the second groups states of the BG that have the same counter component in the same block.Using these two partitions we can decompose the BG into a CS and a counter.

The Decomposition Theorem
The following theorem tells us exactly when a BG can be decomposed into a CS and a counter given a set of partitions over the set of states of the BG.This theorem is a special case of a theorem that appeared in FB93], Fah89] and HS66] and thus will be stated here without proof.Also the reader is refered to the Appendix for de nitions and properties of partitions and partitions pairs.

A Decomposition Algorithm
Given B n , our aim now is to describe an algorithm that will mark states of B n with (c; d)-pairs such that the necessary partitions for the decomposition can be created.Since B n is a submachine of B there are transitions in B n that lead to states that are not in B n , such transitions will be called exit points.
Let w be a shortest string that leads from the initial state of B n to an exit point e in B n .Such strings can be found in an e cient manner.The following algorithm uses w to identify a periodic structure in B n (and, hence, B).
for each pre x x of w do let w = xw 0 let p 0 = Bn (q 0 ; x) for each pre x y of w 0 do let p i = Bn (p 0 ; y i ) for i = 1; 2; : : :, until p i = e for some i or until a state is repeated.if e reached in previous step then PARBFS(p 0 ; p 1 ; : : :) if success then exit; end if end if end for end for The outer loop searches for a pre x of w su ciently long to reach states above some (unknown) threshold t.The inner loop searches for a pair of states, p 0 and p 1 , that are isomorphic under some periodic description of B, then uses the substring y to try to determine additional isomorphic copies of these states.Procedure PARBFS is described below; it performs breadth-rst searches \in parallel" from each of the states p 1 ; p 2 ; : : : and succeeds if it detects a periodic structure.(The precise mechanism for simulating this parallelism is unimportant.)Searches are synchronized so that, for any string m that labels a path from the root of a BFS search tree, the searches simultaneously visit the nodes Bn (p i ; m), for i = 0; 1; : : :.A single breadth-rst search from state p i marks nodes with a \search number" i and a word m (which describes the path used to reach that node).A BFS halts when it can't extend the search without using nodes that are already labelled (possibly by one of the searches operating in parallel with it).Each individual BFS is a standard queue-based breadth rst search; the search queue contains (state,string) pairs, and initially contains (p i ; ).When we remove (q; m) from the queue, we label it (i; m) and then, for each a 2 and each neighbor r of q, we add (r; ma) to the queue if r has not already been labelled.
Two graphs G i and G j visited by BFS(p i ; i) and BFS(p j ; j) are called isomorphic if there is a one-to-one correspondence f between their nodes that preserves membership in F n , the set of nal states, and such that p = f(q) if and only if, for some constant c and for each a 2 , Bn (p; a) = f( Bn (f(q); a)), the label of p is (i; m) and the label of q is (i + c; m) (for some string m).A nite sequence of graphs G 0 ; G 1 ; : : : satis es the property isom if there is a nonempty subsequence G i ; G i+1 ; G i+2 ; : : : such that G i is isomorphic to G i+1 with constant c = 1.
Finally, here is PARBFS; k is a small constant which may be used to ignore \bad" searches caused by being too near the zero counter states or too near the exit points: PARBFS(p 0 ; p 1 ; : : :): for i = 0; 1; : : : paralleldo

Complexity OF The Learning Algorithm
We measure the complexity of the learning algorithm in terms of the number of states of B n , nc for some constant c.Assume that Angluin's algorithm is used to construct B n and assume that the complexity of this step is in O(h(n; m)) steps where m is the length of the longest counter example necessary for this algorithm.The decomposition step rst searches for a string w to an exit point which can be found in O(n) steps.The string w is then partitioned into the form xw 0 which can be done in O(n) steps.For each such x, w 0 is partitioned into a string of the form y i in another O(n) steps for a total of O(n 2 ) steps to rewrite w in the form xy i .See ML84] for an O(nlog(n)) to perform this last step.For each such form of w, a PBFS must be performed.If there are k such BFSs then each must be of depth n=k and the complexity is O(n).The complexity of the decomposition step is thus O(n 3 ) or O(n 2 log(n)) if the algorithm in ML84] is used.The complexity of the learning algorithm is thus O(h(n; m) + n 2 log(n)).
If ( ; 0 ) is a pp then from the block of that contains the current state of the machine we can nd the block of 0 that contains the next state on every letter of the alphabet.We can see that ( ; ) 0 .A partial ordering, , is de ned on pps by comparing the respective components of pps.If ( ; 0 ) and ( ; 0 ) are two pps then ( ; 0 ) ( ; 0 ) i and 0 0 .See HS66] for more properties of partition pairs.Proof of Lemma 3.1 Suppose there exist i 1 ; j 1 > jS c j such that (p; i 1 ) and (p; j 1 ) are nonequivalent.Let w 1 be a (smallest) witness to their nonequivalence.By the pigeonhole principle applied to a sequence of states with decreasing counter values, the computation paths traced by ((p; i 1 ); w 1 ) and ((p; j 1 ); w 1 ) must contain a descending loop (a path that loops in the control structure while decreasing the counter).Write w 1 = 1 1 1 , where 1 6 = is the loop.The \drop" d 1 of 1 can be bounded by jS C j (consider only the states in the computation path that have counter components between i 1 jS C j and i 1 ).Consider the in nite family of witnesses f 1 i 1 1 : i 0g.These can be used to prove that (p; i 1 + t 1 + rd 1 is not equivalent to (p; j 1 + t 1 + sd 1 ) for any r; s 0, for some threshold t 1 bounded by jw 1 j+1.In addition, for at least one of the two values i 1 and j 1 , say i 1 , we have the pairwise nonequivalence of all states in the set f(p; i 1 + t 1 + rd 1 ) : r 0g.(The latter follows from the fact that, because w 1 was chosen smallest, 1 1 is not a witness between (p; i 1 ) and (p; j 1 ); hence, it is a witness between either (p; i 1 ) and (p; i 1 d 1 ) or (p; j 1 ) and (p; j 1 d 1 ); now we can \pump" 1 .)If an in nite number of nonequivalences among p-states remain unaccounted for, repeat this construction on other pairs of p-states (p; i r ), (p; j r ), r = 2; 3; : : :, obtaining witnesses w r .This process cannot continue forever; at any stage, the set of p-states containing nonequivalent pairs that have not been accounted for will be a union of periodic (with respect to the counter) sets, with period at most the least common multiple of all of the loop drops used so far.The above construction shows that some in nite periodic subset of this, with period bounded by jS C j, will be covered in the next step.Therefore, we will achieve the lemma with a threshold t that is no more than the maximum of all jw r j + 1 and a value of k that is no worse than the least common multiple of the d r .2Proof of Lemma 3.2 Choose constants t 0 and k 0 using the construction of corollary 3.1.Suppose neither condition of the lemma holds.Then we have a witness w 1 to the nonequivalence of some state pair (p 1 ; i 1 ) and (q 1 ; j 1 ), where i 1 ; j 1 > t 0 .Consider the sequence of state pairs visited during the computations of ((p 1 ; i 1 ); w 1 ) and ((q 1 ; j 1 ); w 1 ).If neither contains a state with zero counter value, or if both reach zero states using the reset operation, we can extend the nonequivalence to in nitely many state pairs (p 1 ; i 1 + r), (q 1 ; j 1 + s) using the same witness.Therefore, assume at least one computation descends to zero by counting down.If t 0 is at least jS C j 2 , some pair of states repeats in the two computations, forming loops in both computations over the same substring 1 .This repetition can be chosen so that the loop is descending in at least one of the computations (speci cally, the one that \counts down").
Let w 1 = 1 1 1 .For each state r 0, let m r denote the smallest value of m such that f ((p 1 ; i 1 + d 1 r); 1 m 1 1 ); ((p 1 ; i 1 +d 1 r); 1 m 1 1 1 )g contains both a nal and a non nal state.Let n r be the smallest n such that f ((q 1 ; j 1 +d 0 1 r); 1 n 1 1 ); ((q; j 1 +d 1 r); 1 n 1 1 1 )g contains a nal and a non nal state.When both d 1 r and d 0 1 r are greater than jw 1 j, each of these sequences will be either constant or will consist of consecutive integers.If both are constant, w is a witness between any pair of states (p 1 ; i 1 +d 1 r), (q 1 ; j 1 +d 0 1 s) (since it was a witness between (p 1 ; i 1 ) and (q 1 ; j 1 ).If either or both sequences consist of consecutive integers, a witness between (p 1 ; i 1 + d 1 r) and (q 1 ; j 1 + d 0 1 s) is 1 k 1 1 , where k = min(m r ; n s ).
Let t 1 = min(t 0 ; jw 1 j + 1), let k 1 be the least common multiple of k 0 and the drops d 1 , d 0 1 .
If there are still unaccounted-for nonequivalences among states, repeat the process on state pairs (p 2 ; i 2 ); (q 2 ; j 2 ), : : :.The process must halt after only a nite number of steps.2 De nition 3.2 A control structure is a nite deterministic state machine C = fS C ; C ; O C ; C ; c 0 ; C ; F C g where: S C is a nite nonempty set of states.C is a nite set of symbols called the input alphabet to C. C is the cross product of two alphabets; the nite nonempty input alphabet from the outside world, , and the output alphabet of the counter O D .Thus C = O D .

Figure 1 :
Figure1: The BG for the language L = fa n ccb n d j n > 0g fa n d j n > 0g, the state diagram for a CS for this language and the state diagram of the counter.Transitions to dead states in the BG and the CS are not shown.Also the error state of the counter and transitions from states to themselves are not shown for clarity.
Formally, De nition 3.4 For a ROCA, A = fC; Dg where C = fS C ; C ; O C ; C ; c 0 ; C ; F C g and D = fS D ; D ; O D ; D ; d 0 ; D g the product C D is the Moore type state machine M C D = fS C D ; ; C D ; p 0 F C D g where S C D S C S D .8 2 C D ((c; d); ) = ( C (c; ( ; D (d))); D (d; I)) where I = C (c; ( ; D (d))).p 0 = (c 0 ; d 0 ).(c; d) 2 F C D if c 2 F C .The following theorem characterizes the language accepted by M C D and relates it to B. Theorem 3.1 Let A = fC; Dg be a RTA with BG B, we have L(B) = L(M C D ): Proof: A proof is immediate by induction on the length of strings accepted by A and M C D .2Since the BG of a ROCA is equivalent to the product machine, there is an equivalence between the states of the two machines.Recall that two states are equivalent if the two states have the same set of tails.Every useful state, (c; d), of M C D is equivalent to some state b of the BG and every state, b of the BG is equivalent to some useful state (c; d) of M C D .If state b is equivalent to state (c; d) we shall write b = (c; d).It is going to be very useful to think of every state of the BG as having two components; a CS-component and a DS-component.
Figure 2: De nition 4.1 Given a ROCA A = fC; Dg with BG B, let b 1 and b 2 be two states of the BG, c 1 ; c 2 be states of the CS and d 1 ; d 2 be two states of the counter such that b 1 = (c 1 ; d 1 ) and b 2 = (c 2 ; d 2 ) We de ne the four partitions C , D , CD and DC over the set of states of B as follows b 1 b 2 ( C ) i c 1 = c 2 .b 1 b 2 ( D ) i d 1 = d 2 .b 1 b 2 ( CD ) i 8 2 ; 8v 2 O D ; C (c 1 ; ( ; v)) = C (c 2 ; ( ; v)).Two states of B share the same block of CD i , for every letter of the alphabet and every test value of the DS, the CS-components of the behavior states send the same instructions to the DS.b 1 b 2 ( DC ) i D (d 1 ) = D (d 2 ).Two states of B share the same block of DC i the DS-components of the two behavior states have the same test value.The four partitions are called the associated partitions of ROCA A over the set of states of B. They tell us which states of the BG will have the same properties when B is decomposed into C and D.
Theorem 4.1 Let A be a ROCA with BG B. Let C , D , CD and DC be four partitions over the set of states of B. The four partitions are the associated partitions of ROCA A over the BG B i (i) .( C : DC ; C ) is a partition pair.(ii) .( D : CD ; D ) is a partition pair.(iii) .C CD (iv) .D DC (v) .C : D = 0 (vi) .The number of blocks of C is nite.(vii) .C F , i.e.C is output consistent.(viii) .The machine D = fS D ; D ; O D ; D ; d 0 ; D g is isomorphic to a counter where D is de ned by S D = D .D = CD DC .O D = DC .d 0 = D (b 0 ).D ( D ) = DC ( D ).D ( D (b); ( CD (b); DC (b); )) = D ( B (b; )) G i = BFS(p i ; i); if k < i < n k and G i and G i+1 violate the isom property then