Finite Substitutions and Integer Weighted Finite ... - Semantic Scholar

1 downloads 0 Views 542KB Size Report
Aug 27, 1998 - very grateful to the reviewers, Dr. Alexandru Mateescu and Prof. Paavo. Turakainen, for .... v = w1u then u is called a su x of v. If u is a prefix of v, ...
Finite Substitutions and Integer Weighted Finite Automata Vesa Halava

Turku Centre for Computer Science TUCS, Lemminkäisenkatu 14 A, 4th oor, FIN-20520 Turku, Finland. e-mail: vehalava@utu.

Turku Centre for Computer Science TUCS Technical Report No 197 August 1998 ISBN 952-12-0260-2 ISSN 1239-1891

Abstract In this work we present a new chain of undecidability reductions, which begins from the classical halting problem of Turing machines and ends to the undecidability proof of the equivalence problem for nite substitutions on regular languages in Chapter 4. This undecidability result was originally proved by L. Lisovik in 1997. We present a new proof, which is shorter and more elementary than the original one. Our proof uses the undecidability of the universe problem for the integer weighted nite automata. An integer weighted nite automaton is a nite automaton, which has integer weights on its edges. This automaton accepts an input word, if there exists a path reading the word such that the sum of the weights of the used edges is zero. In the universe problem we ask whether a given integer weighted nite automaton accepts all its input words. This problem is proved undecidable in Chapter 3. The proof uses the undecidability of a certain modication of the Post Correspondence Problem, proved in Chapter 2. We also compare integer weighted nite automata to some other counter automata and consider the closure properties of the languages accepted by the integer weighted nite automata. Further, we also compare Lisovik's original chain of undecidability reduction to the one presented in this work.

Keywords: undecidability, weighted nite automata, unimodal, universe

problem, nite substitutions, equivalence problem, Post Correspondence Problem

TUCS Research Group

Theory Group: Mathematical Structures in Computer Science

Acknowledgements This report is a somewhat corrected version of my Licentiate's Thesis accepted in the Department of Mathematics of the University of Turku. I am very grateful to the reviewers, Dr. Alexandru Mateescu and Prof. Paavo Turakainen, for these corrections. I would like to thank my supervisor Dr. Tero Harju for the help and suggestions he has given to me in our many discussions. His advice have made many improvements to the results in this work. I would also like to thank Prof. Juhani Karhumäki for guiding me to this topic. Finally, of course, I would like to thank my wife Heli for the support.

August 27, 1998 Vesa Halava

Contents

1 Preliminaries 1.1 1.2 1.3 1.4 1.5 1.6

Semigroups, monoids and groups . Basics of words . . . . . . . . . . . Morphisms and nite substitutions Turing Machines . . . . . . . . . . Decidability and undecidability . . Finite automata . . . . . . . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

5

. 5 . 5 . 6 . 7 . 10 . 11

2 A modication of the PCP

13

3 Integer weighted nite automata

16

2.1 The prex PCP . . . . . . . . . . . . . . . . . . . . . . . . . . 13

3.1 3.2 3.3 3.4 3.5 3.6

Denitions . . . . . . . . . . . . . . . . . . . . The universe problem . . . . . . . . . . . . . . A comparison with onecounter automata . . Closure properties . . . . . . . . . . . . . . . . Deterministic integer weighted nite automata Summary . . . . . . . . . . . . . . . . . . . .

4 Finite substitutions

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

16 19 28 32 39 42

43

4.1 A special inclusion problem . . . . . . . . . . . . . . . . . . . 43 4.2 The equivalence problem . . . . . . . . . . . . . . . . . . . . . 44 4.3 Defense systems . . . . . . . . . . . . . . . . . . . . . . . . . . 49

Preface In this thesis we shall present a chain of undecidability reductions to show that the equivalence problem of nite substitutions on regular language is undecidable. This result was originally proved by Lisovik in 1997 [17]. The chain we shall present is a new one, which is shorter than the original one and the proofs are elementary. The base of our chain will be the halting problem for Turing machines. First we prove that a certain modication of the Post Correspondence Problem is undecidable. In this modication we are given two special type of morphisms, and we are asked whether there exists a xed type of a word such that the image of the word under the rst morphism is a prex of the image of the word under the second morphism. The formal denition of this modication and the undecidability proof is given in Chapter 2. In the rst main chapter of the thesis, Chapter 3, we dene integer weighted nite automata, which are nite automata without nal states and having integer weights on the transitions. The sum of the weights of the transitions on a given path (or a computation) is the weight of this path and the automaton accepts an input word if there is a path for this word starting from the initial state and having the weight zero. The main new result in this thesis is that the universe problem, asking whether all input words are accepted by a given integer weighted nite automaton, is undecidable. Actually, we prove that the universe problem is undecidable for a very special kind of integer weighted nite automata, called unimodal, where the weights on the transitions are dened so that all paths of the automaton can be divided into four consecutive parts; rst having positive weights on the transitions, second having zero weights on the transitions, third having negative weights on the transitions and fourth having zero weights on the transitions. Any of these parts can also be trivial. The proof we shall present is from Halava and Harju [7], and this proof uses the modication of the Post Correspondence Problem mentioned above. An integer weighted nite automaton is closely related to some models of counter automata that are known in the literature. Similarities and dierences between these automata are considered in Section 3.3. In Chapter 3 we also consider the closure properties of the family of languages accepted by the integer weighted nite automata. In Chapter 4 we present a new proof for the undecidability of the equivalence problem of nite substitutions on regular language, a result originally proved by Lisovik in [17]. Our proof uses the undecidability of the universe 3

problem for integer weighted nite automata and it is from Halava and Harju [8]. The proof we present is considerably easier and the chain of undecidability results used in it is much shorter than in Lisovik's proof. Also a special inclusion problem, asking whether for all words, the image of a word under a given periodic morphism is included in the image of the same word under a given nite substitution, is proved to be undecidable in Chapter 4. This result is also from Halava and Harju [8]. In the last section of Chapter 4 we shall compare the chain of undecidability reduction of the original proof of Lisovik to the one presented in this thesis.

4

1 Preliminaries Throughout this work we shall denote the sets of natural numbers, integers, rational numbers and real numbers by N , Z, Q and R , respectively. For a set S we denote by 2S the power set of S , i.e. the collection of all subsets of S . Sometimes a singleton set fug is written simply u.

1.1 Semigroups, monoids and groups Let S be a set and assume that  is an associative binary operation on S , that is, for all a, b and c in S ,

a  b 2 S and a  (b  c) = (a  b)  c: Then (S; ) is called a semigroup. Usually, if no confusion is possible, we denote ab = a  b, and the semigroup (S; ) is denoted simply by S . An element  in a semigroup S is called an identity if, for all a in S , a = a = a. If there is an identity element in a semigroup S , then S is called a monoid. Note that the identity element in a monoid is necessarily unique. An element z in S is called a zero if, for all a in S , za = az = z. Note that also the zero element, if it exists, is unique in a semigroup. Let G be a set. A triple G = (G; ; ) is called group, if (G; ) is a monoid with identity  and, for all a in S , there exists an inverse element a?1 such that

a  a?1 = a?1  a = :

A group G is called Abelian, if it is commutative, i.e. if for all a and b in G, ab = ba. For example, (Z; +; 0) is an Abelian group. We shall use this additive group of integers quite often in what follows.

1.2 Basics of words

Let A be a nite set of symbols, called an alphabet. A word over A is a nite sequence of symbols in A. We denote by A the set of all words over A. Note that also the empty word is in A. Throughout this paper we shall denote the empty word by ". Let u = u1 : : : un and v = v1 : : : vm be two words in A , where ui and vj are in A for 1  i  n and 1  j  m. Dene the binary operation  on A , 5

called concatenation, in a usual way by

u  v = uv = u1 : : : unv1 : : : vm : This operation is clearly associative on A and, since the empty word is the identity element of A , A is a monoid. We say that A is the word monoid generated by the alphabet A. The word semigroup generated by A is A+ = A n f"g. A semigroup S is called free or freely generated if there is a subset X of S such that each element of S has a unique factorization over X . Such a set X is called the free generating set of S . A monoid M with identity element  is called free if M n fg is a free semigroup. Note that a word monoid A is free and A is its free generating set. Let A be an alphabet and assume that u = u1 : : : un is in A with ui 2 A. The length of the word u is n and it is denoted by juj = n. The rth letter of a word v will be sometimes denoted by (v)r for 1  r  jvj. Assume that u and v are in A . Then u is a factor of v, if v = w1uw2 for some words w1 and w2 in A. If u 6= ", then it is called proper factor. Further, we say that u is a prex of v, if w1 = ", i.e. v = uw2. If w2 = ", i.e. v = w1u then u is called a sux of v. If u is a prex of v, we denote u < v. If u < v, i.e. v = uw for some w 2 A , then we write u?1v = w. For an alphabet A, a subset L of A is called a language. The concatenation of languages K and L, where K; L  A, is dened as the language

K  L = KL = fuv j u 2 K; v 2 Lg  A : Now the concatenation is an associative binary operation on 2A , and therefore 2A is a monoid of sets, where f"g is the identity (and ; is the zero). Finally, we mention that we shall denote the alphabets in this thesis by A, B , , , ? and , depending on the considerations.

1.3 Morphisms and nite substitutions

Let  and  be two alphabets. A mapping h from  into  is called a (monoid) morphism if, for all u; v 2  ,

h(uv) = h(u)h(v): It follows that a morphism becomes dened by the images of the letters of the domain alphabet . Note that for all morphisms, the image of the empty 6

word is the empty word. On the other hand, if h(a) 6= " for all a 2 , then h is said to be nonerasing. A mapping ' :  ! 2 is called a substitution, if 1. '(") = f"g and 2. '(uv) = '(u)'(v) for all u and v in . These conditions mean that a substitution is a morphism from  into the  monoid 2 . A substitution ' is called "free if " 2= '(a) for all a 2 , and nite if, for all a 2 , '(a) is a nite subset of  . Let L   be a language. Two substitutions ';  :  ! 2 are equivalent on L if for all w 2 L, '(w) =  (w). The equivalence problem of two nite "free substitutions will be considered in Chapter 4.

1.4 Turing Machines

Turing machines were dened by Alan Turing in 1936 as a theoretical model for the notion of algorithm, that is, of an eective procedure that produces the value of a function f for each possible argument given as an input. We shall give here a short account on the well known undecidability result that states that it is undecidable for a given Turing machine whether its computation halts on a given input word. For a more complete treatment the reader is referred to Rozenberg and Salomaa [21]. Our denition of a Turing machine is not the usual one. However, it is rather immediate that this denition of Turing machine has equivalent accepting power than the one given in the literature, see e.g. [21]. A Turing machine, TM for short, is a 8-tuple

M = (Q; ; ; R; q0; #; X; qh); where Q is the nite set of states,  and  are the nite input and tape alphabets, respectively, with   , R is a set of transition rules, q0 2 Q is the initial state, # 2  is the blank symbol, X is the symbol of the left boundary and qh 2 Q is the halting state. In the model that we consider, a Turing machine consists of a nite control unit, one left bounded potentially innite tape, where the input is written, and one readwrite head, which moves to both directions of the tape. The leftbound is denoted by the symbol X 2  and X appears only as this 7

leftbound, which cannot be overwritten. Here the tape being potentially innite means that the input can be arbitrarily long. The transition rules in R are of the form 8 > acq; :aqc;

for a 6= X;

(1.1)

where a 2 , b; c 2  n fX g, q 2 Q and p 2 Q n fqhg. A transition rule means that if the head scans b in the state p, the machine moves to the state q, replaces b with c, and moves the head one square to the left (the rst case), to the right (the second case) or stays in the same square (the third case). Note that there is no rules in R having qh on the left hand side. Usually, a TM is dened with a twoway innite tape and the the transitions are dened by a transitions function  : Q   ! Q    fL; R; S g, where L, R and S are the moving direction of a transition. Note that our denition of a Turing machine with the above transition rules is, in eect, a semiThue system, cf. [12, 21].

!

X I N P U T   

^

read and write head

q0 . . q1 . qh

Figure 1: A Turing machine. A conguration (or an instantaneous description ) of a TM M is a word

X 1q 2 2 X Q+; where 1 2 is a context of the tape. The initial conguration is Xq0w#k , where w is the input word and some k 2 N . A one step computation or a 8

move of M is dened as follows: Let Xx1 : : : xi?1 pxi xi+1 : : : xn be the current conguration. For xi?1 pxi ! qxi?1y 2 R (where i 6= 1), we write

Xx1 : : : xi?1 pxixi+1 : : : xn `M Xx1 : : : xi?2 qxi?1yxi+1 : : : xn; for xi?1 pxi ! xi?1 yq 2 R, we write

Xx1 : : : xi?1 pxixi+1 : : : xn `M Xx1 : : : xi?2 xi?1 yqxi+1; and, for xi?1 pxi ! xi?1 qy, we write

Xx1 : : : xi?1 pxixi+1 : : : xn `M Xx1 : : : xi?1 qyxi+1 : : : xn : Note that there is no transition from the conguration Xuq, since our model of Turing machine cannot extend the tape. But if the computation leads to such conguration, we may of course add one blank symbol to the end already in the initial conguration. Let `M (or ` for short) be the reexive and transitive closure of the relation `M. Then the language accepted by M is 



L(M) = w 2  j 9k 2 N : Xq0 w#k `M Xqhv with v 2 ( [ #)+ : Note that although we think that the tape is nite we may add any number of blank symbols to the end of the input. Here the word v is sometimes thought as the result of the computation. A language L   is called recursively enumerable, if there is a TM M such that L(M) = L. Moreover, L is called recursive if there is a halting TM M such that L = L(M) and M halts on all input words from  , meaning that the computations stop on every input. If the input word is not in L, then the computation stops on some state not qh . As mentioned earlier, Turing machines are used as a formalism for algorithms. A halting Turing machine M provides an algorithm to decide whether or not w 2  is in L(M), in a way that, if the computation on given input w ends in the conguration Xqhv, then w 2 L(M), and if the computation ends in some other conguration, then w 2= L(M). Here L(M) is necessarily recursive, since we assumed that the computation halts on every input. 9

1.5 Decidability and undecidability

Let P be a well-dened decision problem, i.e. a set of instances each of which either has or does not have a certain property and we are asked to decide whether the instance given as an input has or does not have the property. We say that the problem P is decidable, if there exists an algorithm, which for every correct input of an instance of P terminates and gives an answer yes, if the input has the required property and answers no otherwise. If no such algorithm exists, then P is said to be undecidable. To prove that a problem P is decidable, we must nd an algorithm which decides P , or show that such an algorithm exists. Note that here  P has an algorithm means, by Church thesis, that there exists a halting TM M, such that 



L(M) = I is an instance of P j Xq0I #k `M Xqhv for some k 2 N : Here the instance I is encoded to the input alphabet in a specic way. In this thesis we are mainly interested in the undecidability results. The usual method to prove undecidability of a problem P is to reduce some already known undecidable problem Q to P . This means that we transform eectively an arbitrary instance q of Q to some instance p of P , in a way that the condition  p has the property of P  is equivalent with the condition  q has the property of Q. It follows that if the problem P is decidable, then the instances q of the problem Q can be solved and therefore the problem Q becomes decidable, which leads to a contradiction. We shall present a chain of undecidability results. We use a classical undecidable problem, the halting problem for Turing machines, stated in the next theorem, as a base of this chain. Our form of the halting problem is not the usual one, since our denition of Turing machine is not quite orthodox. Moreover, let M = (Q; ; ; R; q0; #; X; qh) be a Turing machine. For any correct input w 2  of M we may easily construct a TM M0 such that it begins with empty tape, writes w to the tape and then simulates M on the input w. Assume that q00 is the initial state of M0. It follows that, for some k; ` 2 N ,

Xq00 #k `M0 Xq0 w#` `M0 Xqhu () Xq0 w#` `M Xqhu: In the original halting problem we are asked to decide whether a Turing machine halts on a input word, but based on the above considerations, we state 10

Theorem 1.1. It is undecidable for a TM whether it halts on the empty tape, i.e. whether, for some k 2 N and u 2 , Xq0#k ` Xqhu: This is the form of the halting problem we shall use in the next chapter. Note that we may assume that the tape is physically left bounded, not only marked by some symbol. For the proof of the halting problem, see for example Rozenberg and Salomaa [21].

1.6 Finite automata

We conclude this chapter with the denition of a nite nondeterministic automaton, which is a restricted machine model for accepting languages. As a general reference for nite automata we give Eilenberg [5]. A nite automaton, FA for short, is a quintuple A = (Q; A; ; I; F ); where Q is a nite set of states, A is a nite input alphabet,  is a transition function,  : Q  A ! 2Q ; I is the set of initial states and F is the set of nal states. A transition p 2 (q; a), where p; q 2 Q and a 2 A, will also be written as (q; a; p), in which case   Q  A  Q is regarded as a relation (and sometimes also as an alphabet). A path (or a computation )  of A is a sequence  = (q1 ; a1; q2)(q2 ; a2; q3 )    (qn; an; qn+1); (1.2) where (qi ; ai; qi+1) 2  for all 1  i  n. If we think  as an alphabet, then we can write  2  . If q1 = qn+1 , then  is called a cycle. A cycle (q; a; q) is called a loop. The label of the path  is the word kk = a1 : : : an. A path is called successful (or accepting ) or we say that A accepts the word kk, if q1 2 I and qn+1 2 F in (1.2). The language accepted by A (or the behaviour of A) is the subset L(A) of A consisting of the labels of the successful paths of A. Actually, k  k is a morphism from  into A , dened by k(q; a; p)k = a, for all (q; a; p) 2 , and L(A) = fw 2 A jw = kk;  2  is a successful path in A; and w = " if I \ F 6= ;g: 11

a A transition (p; a; q) 2  is also denoted by p ! q. A path  in (1.2) can be written in the form an?1 a1 a2 an  = q1 ?! q2 ?! q3    ?! qn ?! qn+1 :

This notation of transitions leads to the graph presentation of the nite automata, where Q is a set of vertices and there is an labeled directed edge from the vertex p to the vertex q with label a, if (p; a; q) is in . An automaton A is said to be deterministic, if  is a partial function from Q  A into Q. This means that for all q 2 Q and a 2 A, there is at most one p 2 Q such that (q; a; p) is in . If this is not the case, then A is called nondeterministic. We shall also use the notation DFA for a deterministic and NFA for a nondeterministic nite automaton. A language L  A is called regular if there is an FA A such that L is the behaviour of A, i.e. if L(A) = L. We shall denote the family of regular languages by Reg. Note that A can also be nondeterministic, since we know that each language accepted by an NFA, is also accepted by a DFA. This result is very basic in the formal language theory, see Salomaa [22]. Let A = (Q; A; ; I; F ) be a nite automaton. There exists a nite automaton A0 = (Q [ fq0 g ; A; 0; q0; F 0) with only one initial state such that L(A0) = L(A). Such an A0 can be constructed for A as follows: for all a 2 A,

0(q0 ; a) = fp j p 2 (q; a) for some q 2 I g ; 0(q; a) = (q; a) for all q 2 Q and a 2 A and (

F 0 = F [ fq0 g if I \ F 6= ;; F otherwise: There exists a same kind of procedure for nonempty languages to construct an FA with only one nal state, if " 2= L(A), and with two nal states, if " 2 L(A), and accepting the same language L(A). A nite automaton is said to be complete, if for all input words there is a path in the automaton. It is known that, for every regular language L, there is a complete (nondeterministic) FA A with only one initial and one (or two) nal states such that L(A) = L. If all states of an FA A = (Q; A; ; q0; F ) are nal, i.e. F = Q, then we say that A = (Q; A; ; q0) is a nite automaton without nal states. Such automata are used as a base of the weighted nite automata dened later in Chapter 3. 12

2 A modication of the PCP In this chapter we shall dene a modication of the famous undecidability result called Post Correspondence Problem, the PCP for short. In the PCP we are given two morphisms h; g :  !  and it is asked whether their equality set  E (h; g) = w 2 + j h(w) = g(w) is empty or not. Theorem 2.1. The Post Correspondence Problem is undecidable. The undecidability of the PCP is a classical result in formal language theory, and it was rst proved by Post in [20]. For the proof, see Rozenberg and Salomaa [21]. The size of an instance (h; g) of the PCP is dened to be the cardinality of the alphabet . We denote by PCP(n) the subproblem of the PCP for instances of size at most n. It is also known that if n  2, then PCP(n) is decidable, and if n  7 then the problem is undecidable. For the proof of the undecidability of PCP(7), see Matiyasevich and Senizerques [18], and for the proof of the decidability of PCP(2), see Ehrenfeucht, Karhumäki and Rozenberg [4]. For n greater than 2 and smaller than 7 the decidability status of the PCP is open.

2.1 The prex PCP

In this section we shall consider a modication of the PCP, called a prex PCP. We need the undecidability of this problem in the next chapter. In the undecidability proof we use the halting problem of Turing machines on the empty tape, namely Theorem 1.1. Recall that in Theorem 1.1 we assumed that the tape is left bounded, X is the symbol of the left boundary, we have only one nal state qh and if the machine halts on a given input, it halts on the conguration Xqhw for some w. Let M be a Turing machine, R be the set of its transition rules and  be the tape alphabet. For this given Turing machine M, dene two morphisms h and g in a standard way: here a; b and c are new letters.

h #2 Xq0 x v #2

letter a b x2 r: u ! v 2 R c 13

g # #2 x u Xqh

Here # is the blank symbol and X is the symbol for the left boundary of the tape. Both # and X are in . Denote B = fbg [ R [ ; and A = B [ fa; cg: Notice that jg(w)j  jh(w)j for all words w 2 A, since our rules are length preserving. Further, let (w) = g(w)?1h(w) be the overow of the word w whenever g(w) < h(w). Lemma 2.2. The Turing machine M halts on the empty tape if and only if there exists a word w 2 a+B  c such that g(w) < h(w). Proof. Assume that there is a halting computation  in M on the empty tape. Therefore  is of the form

Xq0 #s?2 = z1 u1z10 ` z1 v1z10 = z2 u2z20 ` z2 v2z20 = z3 u3z30 `    ` zm?1 vm?1 zm0 ?1 = zm umzm0 ` zm vm zm0 = Xqhz;

(2.1)

where s  3, jziuizi0 j = jzivi zi0 j = s and ri : ui ! vi 2 R are the rules used, for 1  i  m. Let

w = asb#s?2 z1 r1z10 z2 r2z20 : : : zm?1 rm?1zm0 ?1 zmrm zm0 c 2 a+B c: By the denitions of h and g,

h(w) = #2sXq0#s?2 z1v1 z10 z2v2 z20 : : : zm?1 vm?1zm0 ?1 Xqhz#2 ; g(w) = #s#2#s?2 z1u1z10 z2 u2z20 : : : zm?1 um?1 zm0 ?1 zmum zm0 Xqh: By the equalities in (2.1),

g(w) = #2sXq0 #s?2z1 v1z10 z2 v2 z20 : : : zm?1 vm?1 zm0 ?1 Xqh; and we get that g(w) < h(w). Assume next that g(w) < h(w) for some w 2 a+B c. Note that w 2= a+c, since g(z)  h(z) for all z 2 a+c. In order that g(w) < h(w), the word w must start with w1 = as#j b#s?2 for some s > 0 and any j  0. For this prex we have (w1) = Xq0#s?2, 14

which corresponds to the initial conguration of the Turing machine M for some s. We shall dene a sequence wi, i 2 N , of the necessary prexes of w. The only way to obtain Xq0 #s?2 as an image of g is to have z1 r1z10 as a factor of w, where r : Xq0# ! v1 2 R, z1 = " and z10 = #s?3. Let w2 = w1z1 r1 z10 . It follows that (w2) = z1v1 z10 . Now if Xqh is not a prex of this overow, we must continue by z2 r2z20 , where r : u2 ! v2 2 R, z1 v1z10 = z2 u2z20 . Dene w3 = w2z2 r2z20 . We continue this procedure, and dene wi = wi?1zi?1ri?1 zi0?1 until for some m, (wm) = zm vm zm0 = Xqhz, z 2 . Note that this m is unique, since there is no transitions from qh, and necessarily w = wmc, since the procedure itself is unique. It follows now that

Xq0#s?2 ` Xqhz in M, where ri, for 1  i  m, is the sequence of the rules used in this halting computation. Note that the weight h(c) = #2 is superuous in the above construction. What matters is that g writes Xqh at some point  and if this occurrence matches that written earlier by h, then M has entered the halting state in a proper computation. As a corollary to the above, we state a rather general undecidability result for instances of morphisms. Theorem 2.3. It is undecidable for an instance (h; g) of two nonerasing morphisms whether there exists a word w 2 a+ B  c such that g(w) < h(w), where h(a) 2 g(a), and jg(x)j = jh(x)j for all x 2 B [ fcg. We shall refer to this modication of the PCP as the prex PCP. Note that the previous theorem does not imply that it is undecidable for two given morphisms h; g;  !  , whether there exists a word w 2  such that g(w) < h(w). For example, for (h; g) in the proof of Lemma 2.2, g(ak ) < h(ak ) for all k 2 N . Indeed, the existence of a word w such that g(w) < h(w) is trivially decidable. Therefore the xed ending with c is essential in the above undecidability result.

15

3 Integer weighted nite automata In this chapter we shall dene a restricted type of nite automata with integer weights on the transitions and prove a simple undecidability property for such automata. The type of automata we consider is closely related to the 1-turn onecounter automata as considered by Baker and Book [2], Greibach [6], and especially by Ibarra [11]. In our model the counter is replaced by a weight function of the transitions, and while doing so, the nite automaton becomes independent of the counter.

3.1 Denitions We shall rst give a general denition of a weighted nite automaton that is a restricted case of an extended nite automaton of Mitrana and Stiebe [19]. Consider a (nondeterministic) nite automaton A = (Q; A; ; q0) without nal states with the states Q, the alphabet A, the set of transitions   Q  A  Q and the initial state q0. We shall redene the transitions using a set of edges T = ft1 ; t2; : : : ; tm g and a transition function  : T ! . We do this to allow transitions ti and tj , where i 6= j , but (ti) = (tj ). In other words, there may exist many copies of one transition in this new set of edges. Clearly this new denition of the transitions does not aect the language accepted by the automaton. Let G, or (G; ; ), be a group with identity . A (G-)weighted nite automaton A consists of a nite automaton A = (Q; A; ; q0 ) as above, and a weight function : ft1; : : : ; tng ! G of the edges. To simplify the notation, we shall write the edges in the form

t = hq; a; p; zi if (t) = (q; a; p) and (t) = z. Similarly, we shall write the transition function  as a set,   Q  A  Q  Z, where

 = fhq; a; p; zi j 9t 2 T : (t) = (q; a; p) and (t) = zg : In the gures we shall denote such an edge t by (a;z) q ?! p:

Note that the function does not aect the computations of the nite automaton A. 16

Dene a morphism kk : T  ! A by setting ktk = a if (t) = (q; a; p). Let  = ti0 ti1 : : : tin be a path of A, where (tij ) = (qij ; aj ; qij+1 ) for 0  j  n ? 1. The weight of the path  is the element

() = (ti0 ) (ti1 )    (tin ) 2 G : Moreover, we let L(A ) = k ?1()k, that is, L(A ) = fw 2 A j w = kk; () = g ; be the language accepted by A . A conguration of A is any triple (q; w; g) 2 Q  A  G. A conguration (q; aw; g1) is said to yield in a conguration (p; w; g1g2), denoted by (q; aw; g1) j=A (p; w; g1g2) ; if there is an edge t such that (t) = (q; a; p) with (t) = g2. Let j=A , or simply j= if A is clear from the context, be the reexive and transitive closure of the relation j=A . We shall restrict to the case, where the group of the automaton is the additive group of integers, namely (Z; +; 0). Such automata are called integer weighted nite automata and denoted by FA(Z). As mentioned, our denition of the integer weighted nite automata is a restricted case of the extended nite automata of Mitrana and Stiebe [19]. In the extended nite automata the underlying automata has nal states F  Q and the transitions reading the empty word are allowed. An FA(Z) A is said to be unimodal (or 1turn ) if for all paths in A the weights of the edges are rst strictly positive, then 0, then strictly negative and nally 0. To be more precise a weighted A is unimodal, if every path  (not only those that have weight 0) can be partitioned into  = 1 23 4 , where the edges in 1 have positive weight, those in 3 have negative weight, and those in 2 and 4 have zero weight, see Figure 2. Any of these subpaths i may also be trivial, for example, we may have only zero weights or only strictly negative weights in our path. The requirement made for all paths in the unimodality condition is clearly a structural restriction of an FA(Z) A , and therefore it is not an additional condition imposed on the weight functions, or on the acceptance of a word. Let A be an FA(Z). The empty word is always included in L(A ), since in an integer weighted nite automaton all states, including the initial state, are nal. Therefore we known that not all regular languages can be accepted by an FA(Z). On the other hand, 17

1 

2

L

LL3 L 4 

Figure 2: The behaviour of the weights in a unimodal FA(Z).

Theorem 3.1. For each regular language L, there exists an FA(Z) A such that L(A ) = L [ f"g. Proof. Let L be a regular language and let A = (Q; A; ; q0 ; F ) be a (nondeterministic) nite automaton such that L(A) = L, where   Q  A  Q. We may assume that A has one initial state q0 and one nal state qf (or two nal states q0 and qf , if " 2 L) such that there are no transitions to q0 and no transitions from qf . It is well known that such an A exists for all regular languages L. We shall dene an FA(Z) A = (Q; A; ; q0 ), where  is a bijection and therefore we may dene T = . One such required weight function is dened, for (p; a; q) 2 , by 8 0 > > >
1 if p = q0 and q 6= qf ; ?1 if p 6= q0 and q = qf ; > > : 0 if p 6= q0 and q 6= qf :

(3.1)

It is obvious that () = 0 only in the case where  is an accepting path of A. This proves our claim. Note that actually the above denition of denes a unimodal FA(Z) that accepts L [ f"g. As we mentioned, not all regular languages are accepted by a (unimodal) FA(Z). On the other hand, it is easy to show that not all languages accepted by integer weighted nite automata are regular, since the language

L = fanbn j n  0g is accepted by a unimodal FA(Z) of Figure 3, but L is not regular. Our main result in this chapter is the undecidability of the universe problem for the unimodal integer weighted automata. In other words, we 18

(b; ?1)

(a; 1)

 -  ? 

- q0 

(b; 1)

q1

Figure 3: A unimodal FA(Z) accepting the language fan bn j n  0g. shall prove that it is undecidable for a given unimodal FA(Z) A , whether L(A ) = A . The undecidability property of the universe problem for the unimodal weighted nite automata turns out to hold in a more restrictive case. Indeed, we shall show that it is sucient to have only four states, and that the nite automata are acyclic, that is, the states can be ordered, Q = fq0; q1; : : : ; qsg, in such a way that (qi; a; qj ) 2  implies i  j .

3.2 The universe problem In this section we shall consider the universe problem for the integer weighted nite automata.

Theorem 3.2. The universe problem is undecidable for 4-state unimodal integer weighted nite automata.

Proof. Let h and g be two nonerasing morphisms from A as constructed in Section 2.1, where A = fa; cg [ B , h(a) 2 g(a) and jg(y)j = jh(y)j for all y 2 B [ fcg. We shall construct an FA(Z) A , where = (Q; A; ; q0) such that L(A ) 6=  A if and only if there exists a word w 2 a+B  c with g(w) < h(w). For this we must show that A accepts all words for which

1. w in a+B c such that g(w)  h(w) and 2. in A n a+ B c. Case 1 is equivalent to the fact that w 2 a+B  c and for some r, 1  r  jg(w)j, g(w)r 6= h(w)r . A picture of the full A is given at the end of the proof, see Figure 4 on page 25. Let A = fa1; a2 ; : : : ; am?2g, Q = fq0; q1 ; q2; q3 g, and note that by the construction of Section 2.1, if y is a letter in A then jh(y)j  3. We shall 19

rst dene the edges for the acceptance of the words of Case 1. For a(= ak ), dene the edges hq0 ; a; q0; 5mi ; hq0 ; a; q2; 5m(?jg(a)j + 3) ? 5k + 1i ; and for all ak 2 B , dene the edges

hq0 ; ak ; q1 ; 15m + 1i ; hq0 ; ak ; q2 ; 5m(?jg(ak )j + 3) ? 5k + 1i ; hq1 ; ak ; q1 ; 0i ; hq1 ; ak ; q2 ; ?5mjg(ak )j ? 5ki ; hq0 ; ak ; q3 ; 5m(i ? j )i ; hq1 ; ak ; q3 ; 5m(i ? j ? 3) ? 1i ; where 1  i  jh(ak )j, 1  j  jg(ak)j and h(ak )i 6= g(ak )j . For c, dene the

edges

hq1; c; q3; 5m(i ? j ? 3) ? 1i ; where 1  i  jh(c)j, 1  j  jg(c)jg and h(c)i = 6 g(c)j . Finally, for all y 2 A, dene the edges hq3; y; q3; 0i ; hq2 ; y; q2; ?5mjg(y)ji ; hq2; y; q3; 5m(i ? j ? 3) + 5` ? 1i ; where 1  `  m ? 2, 1  i  jh(a`)j, 1  j  jg(y)j and h(a` )i = 6 g(y)j .

We denote by L(qi ) the subset of L(A ) that is accepted with zero weight in state qi , for i = 0; 1; 2; 3. It is clear by the denitions that L(q0 ) = f"g and that L(q1 ) = ; = L(q2 ), since the paths that end in q1 or q2 have weights 1 modulo 5, and thus certainly the weights are nonzero. Next we shall consider the language L(q3 ). Claim. Let w be a word in a+ B  c. Then w 2 L(q3 ) if and only if g(w)  h(w). Proof. Assume w 2 a+ B  c is such that g(w)  h(w). This means that for some r, 1  r  jg(w)j, h(w)r 6= g(w)r. We have two possibilities. (a) Let ak 2 B [ fcg, and w = uak v with jh(u)j < r  jh(uak )j and jg(u)j < r  jg(uak )j: Then for some 1  i  jh(ak )j and 1  j  jg(ak )j, jh(u)j + i = r = jg(u)j + j: (3.2) 20

Note that ak 6= a, since h(a) 2 g(a). (b) Let ak 2 B [ fag, y 2 A, and

w = uak vyz with jh(u)j < r  jh(uak )j and jg(uakv)j < r  jg(uak vy)j: Then for some 1  i  jh(ak )j and 1  j  jg(y)j,

jh(u)j + i = r = jg(uakv)j + j:

(3.3)

If we count the dierence of the images by these morphisms step by step for all prexes of w, we notice that when reading the symbol a, the dierence increases by 1, and when reading symbols from B [ fcg the dierence does not change. It follows that the above factorization is unique for a given r. In both of these cases, u 2 a+ B , i.e. u = ef , where e 2 a+ and f 2 B  . By the denitions of h and g this implies that jh(u)j?jg(u)j = jej. Note also that the words w 2 a+c belong to the case (b). In the case (a) there are two possibilities depending on whether f = " or not. If f = " then our path goes from q0 straight to q3. If f 6= " then u = ef is read in a way that ends up in the state q1 , then goes to the state q3 while reading ak and nally reads v in q3. The weight of such a path is, for i and j as in (3.2), in the case f = ", 5mjej + 5m(i ? j ) = 5m(jej + i ? j ) = 5m(jh(u)j + i ? jg(u)j ? j ) = 0; and, in the case f 6= ", 5mjej + 15m + 1 + 5m(i ? j ? 3) ? 1 = 5m(jej + i ? j ) = 5m(jh(u)j + i ? jg(u)j ? j ) = 0: Therefore the path has weight 0. In the case (b) we have two subcases. First, if f = ", then we end up in the state q0 by reading u. Second, if f 6= " we end up in the state q1 by reading u; then we move to the state q2 by reading ak , read v in q2 , go to the state q3 while reading y with the weight 5m(i ? j ? 3) + 5k ? 1, for i and j as in (3.3), and nally z is read in q3 . The weight of the path of the rst subcase is 5mjuj + 5m(?jg(ak )j + 3) ? 5k + 1 ? 5mjg(v)j + 5m(i ? j ? 3) + 5k ? 1 = 5m(juj ? jg(ak v)j + i ? j ) = 5m(jh(u)j + i ? jg(uakv)j ? j ) = 0: 21

In the second subcase our path has the weight 5mjej + 15m + 1 ? 5mjg(ak )j ? 5k ? 5mjg(v)j + 5m(i ? j ? 3) + 5k ? 1 = 5m(jej ? jg(ak v)j + i ? j ) = 5m(jh(u)j + i ? jg(uakv)j ? j ) = 0: We have proved that words w in a+ B c with g(w)  h(w) are accepted by our automaton. To prove the claim in the other direction, we show that for all w 2 A accepted in q3 , there exists an r, 1  r  jg(w)j such that h(w)r 6= g(w)r . Assume that w 2 A is accepted in q3. Then we have four cases. (1) If the accepting path of w goes from q0 straight to q3 . Then w = eak v, where e 2 a , ak 2 B and v 2 A , and this path gives (q0 ; w; 0) j= (q0 ; ak v; 5mjej) j= (q3; v; 5mjej + 5m(i ? j )) j= (q3 ; "; 5m(jej + i ? j )); where 1  i  jh(ak )j, 1  j  jg(ak)j, and h(ak )i 6= g(ak )j . Since the weight of this path is 0, and jh(e)j ? jg(e)j = jej, we get that 5m(jh(e)j + i ? jg(e)j ? j ) = 0, and therefore jh(e)j + i = r = jg(e)j + j , which shows that g(w)  h(w) (2) If the accepting path of w goes from q0 to q1 and from there to q3, then w = edfak v, where e 2 a , d 2 B , f 2 B , ak 2 A and v 2 A, and this path gives (q0 ; w; 0) j= (q0; dfak v; 5mjej) j= (q1 ; fak v; 5mjej + 15m + 1) j= (q1; ak v; 5mjej + 15m + 1) j= (q3 ; v; 5mjej + 15m + 5m(i ? j ? 3) ? 1) j= (q3; "; 5mjej + 5m(i ? j )); where 1  i  jh(ak )j, 1  j  jg(ak)j, and h(ak )i 6= g(ak )j . Since the weight of this path is 0, and jh(edf )j ? jg(edf )j = jej, we get that 5m(jh(edf )j + i ? jg(edf )j ? j ) = 0, and therefore again jh(edf )j + i = r = jg(edf )j + j , and so g(w)  h(w). (3) If the accepting path goes from q0 to q2 and from there to q3 then 22

w = uak vyz, where u 2 a , ak 2 B [ fag and y 2 A, and this path gives (q0; w; 0) j= (q0; ak vyz; 5mjuj) j= (q2 ; vyz; 5mjuj + 5m(?jg(ak )j + 3) ? 5k + 1) j= (q2; yz; 5m(juj ? jg(ak )j + 3) ? 5k + 1 ? 5mjg(v)j) j= (q3 ; z; 5m(juj ? jg(akv)j + 3) ? 5k + 1 + 5m(i ? j ? 3) + 5` ? 1) j= (q3; "; 5m(juj + i ? jg(ak v)j ? j ) + 5(` ? k)); where ` 2 f1; : : : ; m ? 2g, 1  i  jh(a`)j, 1  j  jg(y)j, and h(a` )i 6= g(y)j . Since the path is accepting, necessarily 5(` ? k)  0 (mod 5m), which implies that k = `, and juj + i ? jg(ak v)j ? j = jh(u)j ? jg(u)j + i ? jg(ak v)j ? j = 0 and therefore jh(u)j + i = r = jg(uakv)j + j , and so g(w)  h(w). (4) If the path goes through both q1 and q2. Then w = udvak zyf , where u 2 a , v 2 B  , d; ak 2 B , y 2 A and z; f 2 A , and this path gives (q0 ;w; 0) j= (q0 ; dvak zyf; 5mjuj) j= (q1 ; vak zyf; 5mjuj + 15m + 1) j= (q1; ak zyf; 5mjuj + 15m + 1) j= (q2 ; zyf; 5mjuj + 15m + 1 ? 5mjg(ak )j ? 5k) j= (q2; yf; 5m(juj ? jg(ak)j) + 15m ? 5k ? 5mjg(z)j + 1) j= (q3 ; f; 5m(juj ? jg(ak z)j) + 15m + 1 ? 5k + 5m(i ? j ? 3) + 5` ? 1) j= (q3; "; 5m(juj ? jg(ak z)j + i ? j ) + 5(` ? k)); where ` 2 f1; : : : ; m ? 2g, 1  i  jh(a`)j, 1  j  jg(y)j, and h(a` )i 6= g(y)j . Since the weight of the path is 0, we get that 5(` ? k)  0 (mod 5m) and therefore k = `. Since juj = jh(udv)j?jg(udv)j, we have that juj+i?jg(ak z)j? j = jh(udv)j + i ?jg(udvakz)j? j = 0, and jh(udv)j + i = r = jg(udvakz)j + j . Again, g(w)  h(w). This completes the proof of the present claim. We have shown that w 2 a+B  c is accepted if and only if g(w)  h(w). This implies that a+B  cA  L(A ) if and only if for all w 2 a+B c, g(w)  h(w), since the automaton can read any word in A while in the state q3 . There are also other words accepted in q3 , but by the proof of the claim, we know that all accepted words w do satisfy the condition g(w)  h(w). It remains to make sure that all words of the case 2 are accepted by the (nal) A , i.e. that the words not in a+B  cA should also be accepted by our automaton. This is done by introducing new edges. To get the languages BA and cA accepted in the state q3, we dene, for x 2 B , hq0 ; x; q3; 0i and hq0; c; q3 ; 0i : 23

To get the language a+(B [ fag) accepted in the state q1, we dene the edges hq0; a; q1 ; 0i ; and hq1; a; q1 ; 0i : For the language a+(B [ fag)BaA , we dene new edges, for x 2 B , hq0 ; a; q1; 4i ; hq1 ; x; q2 ; ?2i and hq2; a; q3 ; ?2i : Then the language is accepted in q3 , since for w = avdaz, where v 2 (B [ a), d 2 B and z 2 A , we have (q0 ; w; 0) j= (q1; vdaz; 4) j= (q1; daz; 4) j= (q2 ; az; 4 ? 2) j= (q3; z; 2 ? 2) j= (q3 ; "; 0): Therefore all words not in a+ B cA are accepted by the automaton. It now remains to be shown that these new edges do not interfere with the ones dened earlier for case 1, that is, we show that no words from a+B  c are accepted with a path, which uses these new edges together with the edges dened earlier. It is obvious that in q0 or q1 no such thing can happen. In q2 and q3 the weight of the path is always of the form 5mr + 5s + t, where r; s; t 2 Z, ?(m ? 2)  s  m ? 2 and ?4  t  4, and since a path is accepting if and only if the weight is 0, necessarily t = 0. The only new possible path with t = 0 and ending in q2 is for w = uavak z, where u 2 a , v 2 (B [ fag), ak 2 B and z 2 A , and (q0; w; 0) j= (q0 ; avak z; 5mjuj) j= (q1 ; vak z; 5mjuj) j= (q1 ; ak z; 5mjuj) j= (q2 ; z; 5mjuj ? 5mjg(ak )j ? 5k) j= (q2 ; "; 5m(juj ? jg(akz)j) ? 5k); and to get the weight equal with 0, necessarily 5k  0 (mod 5m), which is impossible by the choise of m. There are two new ways to get to q3 with t = 0. First, if the only new edge is hq1; a; q1 ; 0i, then we rst have used the edge reading a letter in B with weight 15m +1 from q0 to q1 , but our word is then in a B +a+A and not in a+ B +cA. The second case is that we use edges hq0 ; a; q1; 4i, hq1; x; q2 ; ?2i for x 2 B and hq2 ; a; q3; ?2i together with edges dened earlier. But then the word is in a+(B [ fag) BAaA and not in a+B  cA, and no new words are accepted. Finally we show that A is unimodal. Note that for all a 2 A, min fjh(a)j; jg(a)jg > 0: 24

In q0 the weight of the loop edge when reading a is strictly positive, and the edges to q1 have weight 0 or positive. From q1 the loops have weight 0, and since i ? j ? 3 < 0, 1  i; j  3, we see that the leaving edges from q1 and all edges from q2 have strictly negative weight. The edges from q0 to q2 have either positive, 0 or negative weight, but this causes no harm, because before that we have only positively and after that we have only negatively weighted edges. In q3 all edges have weight 0. This shows that A is unimodal, and we have proved the theorem. (a; 0)

a; 5m)

(

(x; 0)

x; 15m + 1)

(

q0

q1

(a; 4)

;

(

ak ;

?5

mj g(a

k)

j?

5

k)

; c

z; 5m(i ? j ? 3) ? 1)

(

(x

;

(x

?2

j)) i ? 0) m( ( x; 5 0)

)

(

a ; m(?jg(ak )j + 3) ? 5k + 1)

( k 5

q2

(a; 0)

y; 5m(i ? j ? 3) + 5` ? 1)

(

(a;

y; ?5mjg(y)j)

?2)

q3

(y; 0)

(

Figure 4: A picture of A constructed in the proof of Theorem 3.2. Here we denote y 2 A, x 2 B and z 2 B [ fcg. Note that in the FA(Z) A of the proof of Theorem 3.2 the transition function  is not bijective. It is easy to see that A can be transformed to one having a bijective transition function. Since we have edges hq0; a; q1 ; 0i 25

and hq0 ; a; q1; 4i, we have to make one copy of the state q1 . Similarly we have to make copies of the state q3, since there might be many edges with dierent weights reading same letter from q0 q1 and q2 to the state q3 . In other words, if we want to have a bijective transition function, we need much more states. Next we state few corollaries of Theorem 3.2. Let A , where A = (Q; A; ; q0 ), be the FA(Z) constructed in the proof of Theorem 3.2, see Figure 4. Let be a new weight function for the underlying automaton A such that all edges in A have weight zero. It is now obvious that L(A ) = A ; and we can state the next corollary considering the equivalence problem for two integer weighted nite automaton. Corollary 3.3. It is undecidable for nite automata A with edge set T , transition function  and two weight functions ; : T ! Z whether L(A ) = L(A ). We may extend the above by stating Corollary 3.4. It is undecidable for two given FA(Z)'s A and B whether L(A ) = L(B ). In fact, B can be restricted to one state automata. Since A is a regular language we have also Corollary 3.5. It is undecidable for FA(Z) A and regular languages R whether L(A ) = R. Recall that a group G is locally nite, if its nitely generated subgroups are nite. It is clear that if G is locally nite, then L(A ) is eectively regular, and thus in this case the universe problem is always decidable. On the other hand, if G is an abelian group that is not locally nite, then it has a nitely generated innite subgroup, and as is well known, G contains a subgroup isomorphic to Z. Therefore Corollary 3.6. Let G be an abelian group. Then the universe problem is decidable for nite automata with weights from G if and only if G is locally nite. In the next lemma we state a simple closure property of the languages accepted by the integer weighted nite automata. This collection of languages is referred to as the family of FA(Z) languages. Lemma 3.7. The family of FA(Z) languages is closed under union. 26

Proof. Let L1 and L2 be two FA(Z) languages accepted by the FA(Z)'s A , where A = (Q1; A; 1 ; q1), and B , where B = (Q2; A; 2 ; q2), respectively. Assume that Q1 \ Q2 = ;. We dene an FA(Z) C , where C = (Q1 [ Q2 [ fq0g ; A; ; q0); and q0 2= Q1 [ Q2 is the new initial state. The edges in C are as in A and B , except that we dene new edges from q0 in a way that there is an edge hq0 ; a; p; zi for p 2 Q1 [ Q2 in C if the edge hq1; a; p; zi, where p 2 Q1 , is in A or the edge hq2; a; p; zi, where p 2 Q2 , is in B. Clearly L(C ) = L(A ) [ L(B ) = L1 [ L2 . This proves the claim. The next corollary will be needed in Chapter 4. Corollary 3.8. The universe problem is undecidable for FA(Z) over a binary alphabet. Proof. We shall construct an FA(Z) B with a weight function over a binary alphabet fa; bg from the FA(Z) A of the proof of Theorem 3.2 such that L(B ) = fa; bg if and only if L(A ) = A. First we encode the alphabet A = fa1 ; : : : ; ang used in Theorem 3.2 to a binary alphabet. One such encoding is provided by (ai) = aib for ai 2 A. Each edge in A is divided in a way that, for each q 2 fq0; q1 ; q2g, we have new states q1; q2; : : : ; qn and in B we there are edges,



q; a; q1; 0 ; qk ; a; qk+1; 0 ; for 1  k  n ? 1, and, for all 1  i  n and hq; ai; p; zi in A ,

i q ; b; p; z :

For the state q3 , we shall dene loops for both letters with weight zero, i.e. hq3; y; q3; 0i for y 2 fa; bg. Assume that there is a path  for a word w 2 (A) in B . Then  ends in some of the states fq0; q1 ; q2; q3g and we can transform  to a path in A having the same same weight and reading the word ?1(w). Similarly, if we have a path in A reading a word v 2 A, we can transform it to a path in B having the same weight and reading the word (v). So we get that a word w 2 (A ) is in L(B ) if and only if w 2 L(A ). Finally, we add a part that accepts the words in the regular language fa; bg n (A+). This can be done, since, by Lemma 3.7, the family of FA(Z) languages is closed under union. Note that the number of states in the FA(Z) B is less than or equal to 4n + 7, where n = jAj, since the part which accepts fa; bg n (A) can be done by n + 3 additional states. 27

3.3 A comparison with onecounter automata

As we mentioned, the integer weighted nite automata are closely related to the onecounter automata that we considered in this section. A pushdown automaton P , PDA for short, is a 7-tuple

P = (Q; ; ?; ; q0 ; z0; F ); where Q is the set of states,  and ? are the nite input and stack alphabets, respectively, q0 is the initial state, z0 2 ? is the initial stack symbol and  is a transition function,

 : Q  ( [ f"g)  ? ! 2Q? : A PDA consists of a tape, where the input is written, and of a pushdown stack, which initially has z0 as the topmost symbol. The input is read from the tape in a way that if " is read, then we stay in the same position of the tape, and if a 2  is read, then we move one position to the right. The transitions are of the form (p; a; z; q; v) 2 Q  ( [ f"g)  ?  Q  ? ; which can be explained as follows. When in state p, reading a, and z being the topmost symbol of the stack, then P moves to the state q, replaces z by v, and stays in the same position or moves one position to the right, depending on whether a = " or not. If z = z0 , then v = uz0 for some u 2 (? nfz0 g), i.e. the initial stack symbol z0 cannot be erased. We also assume that z0 is used only as a mark for empty stack, in other words, the context of the stack is always of the form vz0 , where v 2 (? n fz0g). The stack is said to be empty, if v = ". A conguration of P is a triple (q; u; v) 2 Q    ? , where q is the current state, u the sux of the input word, which is not yet read, and v is the current content of the stack. The acceptance of the input words can be dened in three ways: by nal states, by empty stack, or both. These lead to the same family of languages accepted by the pushdown automata, see Harrison [9]. We shall use the acceptance by the nal states only. We say that the word w 2  is accepted by a PDA P if, as usual, there is a sequence of transitions in P that lead from the initial conguration (q0; w; z0) to a nal conguration (qf ; "; z), where qf 2 F and z 2 ?. As usual, a sequence of compatible transitions is called a computation. The language accepted by a PDA P is denoted by L(P ). 28

It is known that the family of languages accepted by pushdown automata and the family of contextfree languages, denoted by LCF , coincide. For a proof of this, see [1, 9, 22]. A onecounter automaton is a pushdown automaton, where the stack alphabet consists of only one symbol other than the initial stack symbol, say ? = f1; z0g. The stack of a onecounter automata can be thought of as a counter, where the value of the counter is the number of 1's in the stack. Actually, we may extend the value of the counter to be an integer instead of a natural number, since the sign of an integer can be remembered in the states. We dened accepting on nal states because in this way we may use the counter so that not all congurations with an empty stack contents are accepting. We shall next compare the integer weighted nite automata and one counter automata. Here we think that the weights of the paths in an FA(Z) are counted in the stack. In a onecounter automaton the transitions depend on the topmost element of the stack, and thus the transitions depend on the counter, but in an FA(Z) this is not the case. Also, in a onecounter automaton the "transitions are allowed. In an FA(Z), on the other hand, we may add any negative number to the counter on one transition, but in a onecounter automaton we can delete only one symbol at a time from the stack. However, using the "transitions, we may delete as many we want. We conclude that the signicant dierences are that in a onecounter automaton the " transitions are allowed and the transitions depend on the topmost element of the stack. The latter is equivalent to the fact that the transitions depend on the emptiness of the stack. Theorem 3.9. Let A , where A = (Q; A; ; q0 ), be an FA(Z). There exists a onecounter automaton P such that L(P ) = L(A ). Proof. First transform A into the form, where each edge has weight ?1, 0 or 1 by using "edges. This can be done by cutting each edge hq; a; p; zi into jzj pieces by introducing jzj ? 1 new states. Denote this new state set by Q0 , the set of all edges by 0 and call a sequence of such a cut transition a modular sequence. Each of these modular sequences can be thought to be ordered. Dene Q 0 = fq j q 2 Q0 g, where q is a new state. Let P = (Q0 [ Q 0 [ fqf g ; A; f1; z0g ; ; q0 ; z0; qf ); where qf is a new state, be a onecounter automaton with a transition function , that is dened in the following. For hq; a; p; zi 2 0, where 29

z 2 f?1; 0; 1g, p; q 2 Q0 and a 2 A [ f"g, and u 2 f1; z0g, dene 8 (p; u) > > >
(p; 1u) if z = 1; if z = ?1 and u = 1; >(p; ") > : (p; 1u) if z = ?1 and u = z0 ; 8 (p; u) > > >
(p; 1u) if z = ?1; (p; ") if z = 1 and u = 1; > > : (p; 1u) if z = 1 and u = z0 : For all q 2 Q [ Q0 , dene

(q; "; z0) = (qf ; "):

(3.4)

This clearly means that the sign of the weight is remembered in a way that if the onecounter automaton is in the state q 2 Q0, then the weight is greater than or equal to zero and if it is in the state q 2 Q 0, then the weight is less than or equal to zero. The transition in (3.4) implies that we can get to the nal state qf only from the states in Q [ Q0 . Note that there is no transitions from the state qf . If a word is accepted by A in the state q, then it is accepted in P in the state qf , since the weight of the path is simulated on the stack, and from q or q there is a transition to qf with empty stack. On the other hand, if a word is accepted by P in the state qf , then by the denition of the transitions function  we get that the word is accepted by automaton with modular sequences in some state state q such that the state before qf in P was q or q. Therefore it is accepted also by A . It follows that the family of FA(Z) languages is included in the one counter languages, which we denote by LOC for short. Actually, this inclusion is proper, since the language

fan bnam bm j n; m  0g is clearly a onecounter language, but not an FA(Z) language by the forthcoming proof of Theorem 3.13. We shall denote the family of FA(Z) languages by LFA(Z) and write that

LFA(Z)  LOC  LCF : 30

A onecounter automaton is called 1-turn if the stack is used in a way that rst we do not change the content of the stack, then we write to it, then, again we do not change the content of the stack, then we delete from it, and nally the content is not changed. In other words, the value on the counter is changed like in the unimodal FA(Z) dened earlier, except that we now allow noncounting transitions at the beginning. It is obvious that for a unimodal FA(Z) the procedure of changing it to a onecounter automaton dened in the proof of Theorem 3.9 yields a 1turn onecounter automaton. It follows that the family of unimodal FA(Z) languages is properly included in the family of 1-turn onecounter languages. It is known that for a 1-turn onecounter automata the universe problem is undecidable. This is a result of Baker and Book [2] and Greibach [6]. By the above inclusion property, the undecidability of the universe problem for a unimodal FA(Z) is a somewhat stronger result. Ibarra proved in [11] that the universe problem is undecidable for a 1turn onecounter automaton without "transitions. Actually, Ibarra proved this undecidability for two restricted forms of "free 1-turn onecounter automata; rst, having nondeterminism only in deciding when the counter is started to be used, and second, having nondeterminism only in deciding when the counter goes to the decreasing mode. The automata in the Ibarra's proofs use quite many states. Note that these automata accept with nal states. Next we compare an unimodal FA(Z) and an "free 1-turn onecounter automaton. It seems to be obvious that the language  nm k a b c j 3n + 5m = 7k;

n; m; k 2 N



cannot be accepted by an "free 1-turn onecounter automaton, since we need to delete more than one element from the stack when reading a single letter. But clearly this language can be accepted by a unimodal FA(Z), see Figure 5. On the other hand the language

a fanbn j n  0g can accepted by an "free 1-turn onecounter automaton, since in these we allow transitions, which do not change the stack at the beginning of the calculation. But in the denition of unimodality we did not allow the zero weighted edges before the positively weighted edges. We conclude that the families of languages accepted by 1-turn one counter automata and unimodal integer weighted nite automata are incomparable. Note that their intersection contains nonregular languages, since 31

(a; 3)

 

- q0 

(b; 5)

 

(c; ?7)

 

- q1  (c; ?7) - q2 

(b; 5)

Figure 5: A unimodal FA(Z) accepting the language fanbm ck j 3n + 5m = 7k; n; m; k 2 N g. the language is in both of these families.

fanbn j n  0g

3.4 Closure properties

In this section we consider the closure properties of the family of FA(Z) languages under various operations. We have proved already in Lemma 3.7 that the family of FA(Z) languages is closed under union. Actually, this also holds for the family of unimodal FA(Z) languages, since the proof of Lemma 3.7 preserves the unimodality. We state this as a corollary: Corollary 3.10. The family of unimodal FA(Z) languages is closed under unions. Next we consider the intersection. For this, let

L1 = a fbn cn j n  0g and

L2 = fanbn j n  0g c: These languages can be accepted by integer weighted nite automata, but L = L1 \ L2 = fanbn cn j n  0g cannot be, since we know that L is not even a context-free language. 32

Theorem 3.11. The family of FA(Z) languages is not closed under intersections.

The language L1 dened above cannot be accepted by a unimodal FA(Z), since we did not allow zero weights at the beginning of the computation. But if we redene L1 = fanbm cn j n; m  0g ; then we may state

Theorem 3.12. The family of unimodal FA(Z) languages is not closed under intersections.

Next we consider the concatenation operation on languages.

Theorem 3.13. The family of FA(Z) languages is not closed under concatenations.

Proof. Let L = fan bn j n  0g. We shall show that the language

L2 = L  L = fanbn am bm j n; m  0g cannot be accepted by an FA(Z). Assume on the contrary that there is an FA(Z) A with states Q and weight function such that it accepts L2 . Since L2 is an innite language and it contains words that have length greater than jQj, necessarily there is a cycle in A. We have now two cases to consider: 1) Suppose A has only one cycle. Assume that the weight of the cycle is d. To accept all words in L2 with only one cycle, necessarily d = 0, since L2 is innite. Let uv 2 L2 , u; v 2 L and juvj > jQj. Then we have a factorization uv = xyz, where y is read during the cycle. Since uv = xyz gives a path of weight 0, we get that xyk z 2 L(A ) for all k 2 N . But L2 does not contain any words xyk z for k > 2 and y 6= ". 2) Suppose that A has more than one cycle. If there exists a cycle of weight zero in any accepting path, then we get a contradiction as in the case 1, and on the other hand, the weights of all cycles cannot be of the same sign, since L2 is an innite language. It follows that there must be u; v 2 L such that uv = xyzrs, and, in a accepting path  = xy z r s of uv, y is read during the cycle y and r is read during the cycle r , and (y ) and

(r ) are of dierent sign. But now the word

xykj (r)j+1 zrkj (y )j+1s 2 L(A ) 33

for each k > 0 is accepted by path 0 = xykj (r )j+1z rkj (y )j+1 s; since

(0) = (x) + (y )(kj (r )j + 1) + (z ) + (r )(kj (y )j + 1) + (s) = (x) + (y ) + (z ) + (r ) + (s) + k( (y )j (r )j + (r )j (y )j) = 0: Since these new words are not in L2 we get a contradiction that proves the claim. Since the above language L = fanbn j n  0g can be accepted by a unimodal FA(Z), we have also Corollary 3.14. The family of unimodal FA(Z) languages is not closed under concatenations. Note that although the family of FA(Z) languages is not closed under intersections and concatenation, it is closed under these operations with regular languages (that contain the empty word). This is stated in the next theorem. Theorem 3.15. Let R be a regular language with " 2 R and L be an FA(Z) language. Then R \ L, RL and LR are FA(Z) languages. Proof. Assume that R is accepted by the FA B = (Q; A; ; q0 ; F ) and L with the FA(Z) A , where A = (P; A; 1; p0). Assume also that Q \ P = ;. We can transform B into a B accepting R, where is dened as in (3.1) on page 18. We may also assume that in A all edges have even weight, since we can multiply each weight by 2, and the accepted language remains the same. For R \ L, we dene C , where C = (Q  P; A; ; (q0; p0)), and there is an edge h(q; p); a; (r; s); (z1 + z2 )i in C , for all edges hq; a; r; z1i in B and hp; a; s; z2i in A . By the denition in (3.1) of , the weight of a path starting from (q0 ; p0) and ending in a (q; p) is 0 (mod 2) if and only if q 2 F , which is equivalent to the fact that the word is in R. It follows that w 2 A is in R \ L if and only if it is in L(C ). For RL we construct an FA(Z) C , where C = (Q [ P; A; ; q0), by connecting the two FA(Z)'s by introducing new edges hf; a; p; zi ; 34

for f 2 F and a 2 A, if hp0 ; a; p; zi is an edge in A . It is then clear that L(C ) = RL. For LR the same construction can be used, but this time we connect the two FA(Z) in the opposite order. Now the new edges are dened for all p 2 P , that is, hp; a; q; zi ; for p 2 P and a 2 A, if hq0 ; a; q; zi is an edge in B . Again, it is clear that L(C ) = LR. Next we shall consider the star operation. Let K be a language and dene the star of K by 1 [  K = K i; i=0

where K i is the concatenation of the language with itself i times, dened recursively by

K 0 = f"g ; K 1 = K and K i = K i?1 K: K i is also referred to as the ith power of K . By using again the same language L = fanbn j n  0g and the proof of Theorem 3.13 we can show

Theorem 3.16. The family of (unimodal) FA(Z) languages are not closed under star.

Proof. Assume that there is an (unimodal) FA(Z) A accepting L for L = fanbn j n  0g. It follows by Theorem 3.15 that the language

L \ a b ab = L2 can be accepted by an FA(Z), since a b a b is a regular language. But this is a contradiction by the proof of Theorem 3.13. Next we consider the complement of an FA(Z) language. The family of FA(Z) languages is not closed under complement, since each FA(Z) language contains the empty word, and therefore it is not in the complement. But let us consider the complement modulo ". For any language L   , the complement modulo " of L is

L " = ( n L) [ f"g : 35

For example, let  = fa; bg and L = fanbn j n  0g. Now there is a partition L " = a [ b [ a ba (3.5) [ fanbm j 0 < m < ng [ fam bn j m > n > 0g ; and this language can be accepted by the unimodal FA(Z) in Figure 6. In other words to prove that the family of (unimodal) FA(Z) languages is not closed under complement modulo ", we have to use some other language than L. It is also clear that this new language cannot be regular, since the family of regular languages is closed under complement.

(a; 0) (b; 0)

(a; 0) (b; 0)

  ? -? -  :  "*      "  "  ""  (b; 1)

(a; 1)

"  " - "a  eeaaaaa ?    ee aaaj - XX ? XXXXX  ee   XXz  ee !!* ! ee ! !!!?    Re ! !  - (a; 2)

q0

(a; 0)

(b; 0) (a; 0)

(a; 1)

(a; 1)

(a; 1)

(a; 1)

(b; 1)

(b; 1)

(b; 0)

(b; 0)

(b; 1)

Figure 6: The unimodal FA(Z) accepting the complement of the language fanbn j n  0g modulo ". Let  = fa; b; cg and S = fanbn cn j n  0g. Now S is not an FA(Z) 36

language, since it is not a contextfree language. But S" =a [ fb; cg  [  ba [  c fa; bg  



[ anbm ck j n 6= k; k; m; n 2 N  [ anbm ck j n 6= m; k; m; n 2 N :

(3.6)

is a unimodal FA(Z) language, since the languages on the rst row are regular and the languages on the second row are easily seen to be unimodal FA(Z) languages. Since (S")" = S; we may write Theorem 3.17. The family of (unimodal) FA(Z) languages is not closed under complement modulo ". It is obvious that the family of FA(Z) languages is closed under taking the image of a nonerasing morphism h : A ! B , since each transition reading a letter a 2 A can be replaced by a new path, which reads the image h(a) and has the same weight as the original transition. To do this replacing so that it preserves unimodality, we rst have to multiply each weight in the original FA(Z) by the maximal length of an image of a letter under h, and then do the above construction. Note that the morphism must be nonerasing, since otherwise we would get "transitions. For inverse morphisms, we prove the next theorem. Lemma 3.18. Let h : B + ! A+ be a morphism and A , where A = (Q; A; ; q0 ), be an FA(Z). Then there exists an FA(Z) B such that 



L(B ) = h?1(L(A )) = h?1(w) j w 2 L(A ) : Proof. Let B , where B = (Q; B;  0 ; q0 ). We dene the edges of B , for all q 2 Q and b 2 B , by

(3.7) hq; b; p; zi if (q; h(b); 0) j=A (p; "; z); where p 2 Q and z 2 Z. Note that if h(b) = ", then there is a loop hq; b; q; 0i ; (3.8) for all q 2 Q. Now it is straightforward to show that (q0; v; 0) j=B (q; "; 0) if and only if (q0 ; h(v); 0) j=A (q; "; 0). This proves the claim. 37

The above construction does not preserve unimodality in the case, where the morphism is erasing, i.e. the image of some letter is the empty word. This is obvious, since we have a loop with weight zero in each state, dened in (3.8). Next we claim that if the morphism h in Lemma 3.18 is nonerasing and

A is unimodal, then the constructed FA(Z) B is also unimodal. We shall prove this by assuming on the contrary that this is not the case. Then we have dened two edges hq1 ; a; q2; z1 i and hq2 ; b; q3; z2 i in (3.7), where z1  0 and z2 > 0 (or z1 < 0 and z2  0). But, since z1 and z2 are sums of weights of paths of A reading h(a) and h(b), respectively, it follows that necessarily on the path from q1 to q3 reading h(ab) on A we also have two consecutive edges with, the rst having weight less than or equal to zero and, the second having weight larger than zero. In other words A is not unimodal, which is a contradiction proving the claim. We have proved Theorem 3.19. The family of FA(Z) languages is closed under taking the images of nonerasing morphisms and under taking the image of inverse morphisms. The family unimodal of FA(Z) languages is closed under taking the images of nonerasing morphisms and inverse morphisms. Next we shall consider the shue operation, denoted by . For u; v 2 A and a; b 2 A the shue is dened recursively by (au bv) = a(u bv) [ b(au v); and (" u) = (u ") = fug : For two languages K; L  A , dene the shue by

K L=

[

u2K; v2L

(u v):

Theorem 3.20. The family of (unimodal) FA(Z) languages is not closed under shue. Proof. Let L1 = fan bn j n  0g and L2 = fcm dm j m  0g. We shall prove that L1 L2 is not an FA(Z) language.

38

Assume on the contrary that L1 L2 is an FA(Z) language. Then by Theorem 3.15 the language (L1 L2 ) \ (a+b+ c+d+ [ f"g) = L1  L2 is also an FA(Z) language, since a+b+ c+d+ is a regular language. Since L1  L2 has a morphic image L21, also L21 is an FA(Z) language. But this is contradicts the proof of Theorem 3.13. This proves the claim.

3.5 Deterministic integer weighted nite automata

An integer weighted nite automata A , where A = (Q; A; ; q0 ) is said to be deterministic, if the underlying nite automata A is deterministic. This means that for all q 2 Q and a 2 A there is at most one edge form the state q reading the letter a. This necessarily implies that the transitions function  : T !  of A is bijective, and   Q  A  Q denes a deterministic nite automaton. We shall denote a deterministic integer weighted nite automaton by DFA(Z). Note that each regular language containing the empty word can be accepted by a DFA(Z), since we know that each regular language modulo " is accepted by a deterministic nite automaton with only one initial state, and by using the weight function in (3.1) on page 18, we get a DFA(Z) accepting the given regular language. It is obvious that we can accept by DFA(Z)'s more than regular languages. This follows, since the FA(Z) accepting L = fanbn j n  0g in Figure 3 on page 19 is deterministic. Next theorem is obvious, since in the proofs of the previous section for the FA(Z) languages, the languages used are DFA(Z) languages. Theorem 3.21. The family of (unimodal) DFA(Z) languages is not closed under intersections, concatenations, star or shue. For nonclosures under the union and the complement modulo ", we have to give new proofs. Theorem 3.22. The family of (unimodal) DFA(Z) languages is not closed under unions or complement modulo ". Proof. The counter example in the case of union is the language a [ fanbn j n  0g : Assume on the contrary that this language can be accepted be a DFA(Z). We see that to get all words in language accepted we must have path for 39

all powers of a with weight zero. On the other hand, this path is unique for each power of a. To do this with nitely many states the path reading the a's must be of the form, where rst we have states in a row and then at the and we have a cycle, see Figure 7. The lengths of the row and cycle are xed. In other words, there must be a state q such that (q; ak ; 0) j= (q; "; 0) for some minimal k  1. Let q be the state where the cycle begins. There is also a unique path from the initial state to q not using any cycles, reading an0 and having weight 0, for some n0 2 N . Now for all m = n0 + tk, where t  0, we must have a unique path from q reading bm with weight 0. So we have also an accepting path for ak b` , where k = n0 + tk and ` = n0 + (t + 1)k for some t  0. Since this word is not in the language, this is a contradiction, that proves the claim. In the case of the complement, we consider the complement of the language L = fan bn j n  0g modulo ". The FA(Z) accepting L " = a [ b [ a ba

[ fan bm j 0 < m < ng [ fambn j m > n > 0g

was given in Figure 6 on page 36. The proof goes now similarly to the case of union. Since this is straightforward, we shall omit the further details.

-  -    q0

a

a

  PPPq 1  JJ



 J^



J]J

 

 J  PiPP )   a

a

a

a

a ...

a

a

q

a

a

Figure 7: A deterministic path reading a . 40

Although the family of DFA(Z) languages is not closed under union, the union of two DFA(Z) languages is an FA(Z) language, since the latter languages are closed under union. Next we consider the closure of the family of DFA(Z) languages under taking the image of a nonerasing morphism and under taking the inverse image of a morphism. Theorem 3.23. The family of (unimodal) DFA(Z) languages is not closed under taking the image of a morphism, but it is closed under taking the inverse image of a morphism. Proof. For the nonclosure under taking the image of a morphism, we give a counter example. Let

L = c [ fanbn j n 2 N g : Clearly this language can be accepted by a DFA(Z). Let then h : fa; b; cg ! fa; bg, h(a) = h(c) = a and h(b) = b. Then

h(L) = a [ fanbn j n 2 N g ; and this languages can not be accepted by a DFA(Z). This follows by the proof of Theorem 3.22 The closure under the inverse image follows similarly than in the case of FA(Z) languages, since the proof of Lemma 3.18 holds also in the deterministic case. Indeed, in the deterministic case for all h(a) there exists at most one path from every state. Note that the image of a DFA(Z) language under a nonerasing morphism is necessarily an FA(Z) language, since the latter languages are closed under the image of a nonerasing morphism. We end this chapter by considering the universe problem for the deterministic integer weighted nite automata. Lemma 3.24. Let A , where A = (Q; A; ; q0), be a DFA(Z) and P  Q be the set of the states to which there is a path from q0 . Then L(A ) = A if and only if, for all p 2 P and a 2 A, there is an edge from p reading a and all these edges have weight 0 in . Proof. Assume that L(A ) = A and assume on the contrary that for some p 2 P and a 2 A, there is no edge hp; a; q; zi. Since A is deterministic, there is only one path in A for every word in A+. Let w be a word of a path which 41

ends in p according to A. Then there is no path for wa in A, which is a contradiction. The latter condition follows similarly, since if there is an edge hp; a; q; zi, where z 6= 0, then wa is not in L(A ). The other direction is trivial. As a corollary we get Theorem 3.25. The universe problem is decidable for deterministic integer weighted nite automata.

3.6 Summary

In this section we present a table where we summarize the results of the integer weighted nite automata proved in this chapter. In the following table we denote that closure by + and nonclosure by ?.

FA(Z) unimodal FA(Z) (unimodal) DFA(Z) Union + 3.7 + 3.10 ? 3.22 Intersection ? 3.11 ? 3.12 ? 3.21 Concatenation ? 3.13 ? 3.14 ? 3.21 Star ? 3.16 ? 3.16 ? 3.21 Complement mod " ? 3.17 ? 3.17 ? 3.22 Shue ? 3.20 ? 3.20 ? 3.21 Image(h) + (*) 3.19 + (*) 3.19 ? 3.23 ? 1 Image(h ) + 3.19 + (*) 3.19 + 3.23 Universe problem undecidable undecidable decidable

Here h is a morphism, and it assumed to be nonerasing in the cases denoted by (*). Note that we actually proved that the universe problem is undecidable for 4-state unimodal FA(Z), and for FA(Z) over binary alphabet.

42

4 Finite substitutions In this chapter we present two undecidability results concerning the inclusion and the equivalence problem for nite "free substitutions. In these undecidability reductions we shall use the undecidability of the universe problem for the integer weighted nite automaton over a binary alphabet, proved in the previous chapter. The proofs presented are from Halava and Harju [8].

4.1 A special inclusion problem

In this section we prove the undecidability of a special inclusion problem. Let A and B be alphabets, and h : A ! B  be a morphism. Then h is said to be periodic nonerasing morphism, if there exists a word w 2 B + such that h(u) 2 w+ for all u 2 A+. Theorem 4.1. It is undecidable for periodic nonerasing morphisms h : fb; 0; 1; cg ! fa; bg and "free nite substitutions  : fb; 0; 1; cg ! 2fa;bg whether h(u) 2 (u) for all u 2 b f0; 1g c: Proof. Let A , where A = (Q; f0; 1g; ; q1), be an FA(Z). We shall dene h and  in a way that h(u) 2 (u) for all u 2 bf0; 1gc if and only if L(A ) = f0; 1g. As usual we shall identify a singleton set fug with its sole member u. Let s = jQj + 1, say Q = fq1 ; : : : ; qs?1g, where q1 is the initial state of A. Further, let r = j minfz j hq; x; p; zi 2 gj; i.e. r is the absolute value of the minimal weight of an edge in A . Dene

w = asb;

N=

s[ ?1

k=1

ak b; and Tx =

[ hqk ;x;qj ;zi2

as?k bwz+r aj :

(4.1)

Here Tx encodes the rules of A . Dene then (b) = a; (c) = Nw; (x) = Tx; for both x 2 f0; 1g, and h(b) = w; h(c) = w; h(x) = wr+1: Let L = bf0; 1gc. Clearly, for all u 2 f0; 1g, h(buc) = w  wjuj(r+1)  w, and we shall prove that wjuj(r+1)+2 2 (buc) for u 2 f0; 1g if and only if u 2 L(A ). 43

Let u = x1 : : : xm , where xi 2 f0; 1g for 1  i  m and let v 2 (buc). By the denition of  we obtain that

v = a  as?k1 bwz1+r aj1  as?k2 bwz2+r aj2    as?km bwzm+r ajm  a`bw; for a sequence

hqki ; xi; qji ; zii ; 1  i  m:

(4.2)

Assume that v 2 w+. Then necessarily k1 = 1, ki+1 = ji , for 1  i  m ? 1, and ` = s ? jm . This means that the sequence (4.2) is a path of u in A starting from the initial state q1 and ending in the state qjm . It follows that Pm Pm v = w1+ i=1(zi +r+1)+1 = w i=1 zi+m(r+1)+2 : P Now v = wjuj(r+1)+2 if and only if mi=1 zi = 0, which means that the sequence hqki ; xi; qji ; zii, 1  i  m, is an accepting path of u in A . The undecidability claim of the theorem follows from the undecidability of the universe problem of the FA(Z) A , see Corollary 3.8.

4.2 The equivalence problem

We shall now prove that the equivalence problem of nite substitutions is undecidable for the regular language b f0; 1g c. The proof we present modies the proof of Lisovik [17]. In the original proof Lisovik used the undecidability of the reliability of the defense systems, cf. [16]. We shall consider these systems and the chain of the undecidability reductions proving the undecidability in Section 4.3. We shall use the undecidability of the universe problem for nite integer weighted automata over an binary alphabet. Our chain of undecidability reductions is shorter than the original chain of Lisovik, and the model of an automaton we use is simple, and the undecidability proofs for it are elementary. Note that the undecidability of the equivalence problem is not trivial, since it is known that there are rather general decidable special cases. For example, for nite prex substitutions the equivalence problem on regular language is known to be decidable, see Karhumäki [14]. This follows from the fact that the monoid of all prex codes is free and from the pumping property of regular languages. Also note that the question asking, whether the equivalence problem of nite substitutions on regular language is decidable, was a well-known and studied problem until Lisovik solved it in 1997, for example see Culik and Karhumäki [3]. 44

There also exist some other undecidability results on "free nite substitutions, see especially Turakainen [23]. We shall state these results of Turakainen at the end of this section. For decidability and undecidability results of the equivalence problem for other mappings, see Karhumäki [13]. Theorem 4.2. The equivalence problem for "-free nite substitutions on the regular language bf0; 1gc is undecidable. Proof. Let A , where A = (Q; f0; 1g; ; q1) be an FA(Z). We shall dene two nite substitutions ';  : fb; 0; 1; cg ! fa; bg such that ' and  are equivalent on bf0; 1gc if and only if L(A ) = f0; 1g. As in the proof of Theorem 4.1, let s = jQj + 1, and Q = fq1; : : : ; qs?1g, where q1 is the initial state of A, and let

r = j minfz j hq; x; p; zi 2 gj: We dene w, N and Tx, for x 2 f0; 1g, as in (4.1). Further, for both x 2 f0; 1g, dene [ Cx = as?k bwz+r+1: hqk ;x;qj ;zi2

Finally, we dene the substitutions  and ' as follows:

for x 2 f0; 1g, and

 (b) = a [ wN;  (c) = (" [ N )w;  (x) = wr+1 [ (" [ N )(Tx [ CxN );

'(b) =  (b) [ w; '(c) =  (c); '(x) =  (x): Let

L = bf0; 1gc: Clearly  (v)  '(v) for all v 2 L, since  (x)  '(x) for all letters x 2 fb; 0; 1; cg. Therefore to prove the claim we need to show that '(x)   (x) for all x 2 L if and only if L(A ) = f0; 1g. Assume rst that L(A ) 6= f0; 1g. Let u 2 f0; 1g be such that u 2= L(A ), and assume that h and  are dened as in the proof of Theorem 4.1. Clearly h(buc) 2 '(buc) and (buc)   (buc), and by the proof of Theorem 4.1 and the form of N , h(buc) 2  (buc) if and only if u 2 L(A ). By our assumption h(buc) = wjuj(r+1)+2 2=  (buc). It follows from L(A ) 6= f0; 1g that '(x) 2=  (x) for some x 2 bf0; 1gc. 45

Assume next that L(A ) = f0; 1g and let x = x0 : : : xn+1 2 L, and u = u0 : : : un+1, where xi 2 fb; 0; 1; cg and ui 2 '(xi ) for all 0  i  n + 1. Note that necessarily x0 = b and xn+1 = c. We have to show that there exist words vi 2  (xi) for all 0  i  n + 1 such that v0 : : : vn+1 = u. First, we note that the only dierence in the images of  and ' is in the image of b, and  (b) n '(b) = w. If u0 6= w, then we have a trivial solution ui = vi for all 0  i  n + 1. Therefore we assume that u0 = w. We shall use parentheses to illustrate the factorizations by ' and  to ui's and vi 's, respectively. We divide the considerations into three cases: (i) If n = 0, then x = bc and we have two subcases: (1) If u1 = w 2 '(c), then u0u1 = (w)(w) = (a)(as?1 bw) 2  (x). (2) If u1 2 Nw  '(c), then for some 1  k  s ? 1,

u0u1 = (w)(as?k bw) = (was?k b)(w) 2  (x):

(ii) If n  1 and u1 6= wr+1, then we show that there is a factorization such that ui = vi for 2  i  n + 1 and u0u1 = v0 v1. For this, there are four subcases: (1) If u1 2 Tx1 , then u1 = as?k bwz+r aj for some hqk ; x1 ; qj ; zi, and

u0u1 = (w)(as?k bwz+r aj ) = (a)(as?1bas?k bwz+r aj ) = v0v1 2 a  NTx1 ; where a 2  (b) =  (x0 ) and NTx1   (x1) as required. (2) If u1 2 NTx1 , then u1 = as?`bas?k bwz+r aj for some hqk ; x1; qj ; zi and 1  `  s ? 1, u0u1 = (w)(as?`bas?k bwz+r aj ) = (was?`b)(as?k bwz+r aj ) = v0 v1 2 wN  Tx1 ; where wN   (b) =  (x0) and Tx1   (x1) as required. (3) If u1 2 Cx1 N , then u1 = as?k bwz+r+1as?`b for some hqk ; x1; qj ; zi and 1  `  s ? 1, and u0u1 = (w)(as?k bwz+r+1as?`b) = (a)(as?1bas?k bwz+r+1as?`b) = v0 v1 2 a  NCx1 N; where a 2  (b) =  (x0 ) and NCx1 N   (x1) as required. (4) If u1 2 NCx1 N , then u1 = as?`bas?k bwz+r+1as?tb for some hqk ; x1 ; qj ; zi and 1  `; t  s ? 1, and u0u1 = (w)(as?`bas?k bwz+r+1as?t b) = (was?`b)(as?k bwz+r+1as?t b) = v0 v1 2 wN  Cx1 N; 46

where wN   (b) =  (x0) and Cx1 N   (x1 ) as required. (iii) If n  1 and u1 = wr+1 then we need the fact that L(A ) = f0; 1g. Let t = minfi j i  1; ui 6= wr+1g. Note that t  n + 1, since xn+1 = c and wr+1 2= '(c). Now u0u1 : : : ut?1 = w(wr+1)    (wr+1) = w(t?1)(r+1)+1 . By our assumption, for the sequence x0 = x1 : : : xt?1 2 f0; 1g, A has edges

qji?1 ; xi; qji ; zi ; i = f1; : : : ; t ? 1g ; where 1  ji  s ? 1 and j0 = 1, and t?1 X i=1

zi = 0;

(4.3)

since x0 2 L(A ) = f0; 1g. Therefore there exist words

vi0 = as?ji?1 bwzi+r aji 2 Txi ; for 1  i  t ? 1. By setting v0 = a, we get v0 v10 : : : vt0?1 = aas?1 bwz1+r aj1 as?j1 bwz2 +r aj2 : : : as?jt?2 bwzt?1+r ajt?1 = wwz1+r wwz2+r w : : : wwzt?1+r ajt?1 : By (4.3) v0v10 : : : vt0?1 = w(t?1)r+(t?1) ajt?1 = w(t?1)(r+1) ajt?1 ; (4.4) and therefore u0u1 : : : ut?1 = v00 v10 : : : vt0?1 as?jt?1 b. We may now choose vi = vi0 for 1  i  t ? 2. We have two cases depending on t. First if t = n + 1, then we have two subcases. Recall that xn+1 = c. (1) If un+1 = w, then we can choose vn = vt?1 = vt0?1 and vn+1 = as?jt?1 bw 2 Nw 2  (c). We get that u = v by (4.4). (2) If un+1 = as?k bw 2 Nw for some 1  k  s ? 1, then we set vt?1 = vn = as?jt?2 bwzt?1+r+1as?k b 2 Cxn N and vn+1 = w: Again this yields that u = v by (4.4). The second case is that t  n. In this case xt 2 f0; 1g. Then we choose vi = ui for t + 1  i  n + 1 and there are four subcases for vt?1 and vt depending on ut: (1) If ut = as?k bwz+r aj 2 Txt for some hqk ; x; qj ; zi, then we set vt?1 = vt0?1 and vt = as?jt?1 bas?k bwz+r aj 2 NTxt ; 47

to obtain u = v. (2) If ut = as?`bas?k bwz+r aj 2 NTxt for some hqk ; x; qj ; zi and 1  `  s ? 1, then we set

vt?1 = as?jt?2 bwzt?1+r ajt?1 as?jt?1 bas?`b = as?jt?2 bwzt?1+r+1as?`b 2 Cxt N and

vt = as?k bwz+r aj 2 Txt ; to obtain u = v. (3) If ut = as?k bwz+r+1as?`b 2 Cxt N for some hqk ; x; qj ; zi and 1  `  s ? 1, then we set

vt?1 = vt0?1 and vt = as?jt?1 bas?k bwz+r+1as?`b 2 NCxt N; to obtain u = v. (4) If ut = as?`bas?k bwz+r+1as?hb 2 NCxt N for some hqk ; x; qj ; zi and 1  `; h  s ? 1, then we set

vt?1 = as?jt?2 bwzt?1+r ajt?1 as?jt?1 bas?` = as?jt?2 bwzt?1+r+1as?`b 2 Cxt N and

vt = as?k bwz+r+1as?hb 2 Cxt N; to obtain u = v. We have proved that if L(A ) = f0; 1g then '(L)   (L). The undecidability now follows by the undecidability of the universe problem for FA(Z) over a binary alphabet, Corollary 3.8. In the previous proof we actually proved that it is undecidable, whether the inclusion '(x)   (x); holds for all word x 2  . This also follows from the statement of Theorem 4.2. As we mentioned, there are also some other undecidability results concerning nite substitutions. We shall state two propositions proved by Turakainen in [23]. 48

Note that, for a a nite substitution ' :  ! 2 , the inverse of ' is dened by '?1(w) = fv 2  j w 2 '(v)g for all w 2  .

Proposition 4.3. The following are undecidable for the class of all "free   f a;b;c g nite substitutions ' : fa; bg ! 2 : (i) Does the equality '1 (w) \ fac; bcg = '2 (w) \ fac; bcg hold for all w in fa; bg ? (ii) Does the equality '1 (w) \ fac; bcg = '2 (w) hold for all w in fa; bg? (iii) Does the equality '?1 1(w) = '?2 1(w) hold for all w in fac; bcg ? Let S be a set. The cardinality of S is denoted by card S

Proposition 4.4. It is undecidable, given an "free nite substitution 'and two morphisms h and g, whether '(w) = gh?1 (w) for all w in fac; bcg . It is also undecidable whether card '(w) = card gh?1(w) for all w in fac; bcg .

4.3 Defense systems

In this section we shall consider the so called defense systems, DS for short, dened by Lisovik in [16]. We summarize the chain of the undecidability reduction for the original proof of L. Lisovik for Theorem 4.2. A defense system is supposed to defense innitely many nodes numbered by the integers Z. A DS is a triple D = (K; H; ?), where K is a set of lines,

K = fi j 1  i  s; i 2 N g; for a given s 2 N , H is a set of instructions and ? is a set of attacking symbols. Each node can be defended by any of the lines from K . In other words, each node can be defended by s dierent lines. The initial situation in our case is that only the node 0 is defended by the line 1, and the other nodes do not have defense at all. The attacker is supposed to send symbols from the set ? to the defending system, which on the other hand uses some instruction dened for these symbols. This means that the attacks can be thought as words from ?, and the behaviour of the DS is dened by the instructions under this attack word. Each rule of the set H is of the form (k; a; j; z; p), where 1  k; j  s, a 2 ?, z 2 f?1; 0; 1g and p is a real number, 0  p  1. Such a rule means 49

1 2 3

?2   

?1   

s





h

0

     

1

2

  

  





Figure 8: A picture illustrating a defense system in the initial conguration defending the node 0 by the line 1. that when an attacking symbol a is sent, defense of the node i by the line k can move with probability p to defend the node i + z by the line j . We shall denote this probability also by pza;k;j . Naturally we set, for all a 2 ?, s X 1 X pza;k;j = 1 j =1 z=?1

for each k. Note that the underlying system in the defense system is nondeterministic and therefore the model of the defense system we have dened is also called nondeterministic DS, NDS for short. An NDS can also be viewed as a countable Markov system. To simplify the notations we denote each conguration of an NDS by an integer. If the node i is defended by the line j , we denote this conguration by the integer i  s + (j ? 1). Recall that the initial conguration is that the node 0 is defended by the line 1, which is represented as the integer 0. Let w 2 ? . We shall denote the probability that the NDS is in a conguration k 2 Z in response to a nite sequence of attacking signals w by pw (k). Let D = (K; H; ?) be a defense system. D is called unreliable if, for some w 2 ?, after an attacking sequence w the probability that the node 0 is defended by some line is 0, i.e. pw (j ) = 0 for all 0  j  s ? 1. The word w here is called critical. If there is no critical words w 2 ? for D, then D is called reliable. 50

Note that the problem of reliability of the NDS D = (K; H; ?) is equivalent to the universe problem for the integer weighted nite automaton

A = (K; ?; ; 0); where the edges in  are constructed from the instructions in H by selecting only those instructions with positive probability and then omitting the probabilities. Actually, we are interested in the case when ? is xed to be a binary alphabet f0; 1g. The next result is from Lisovik [16]. Proposition 4.5. The unreliability of nondeterministic defense system is undecidable, i.e. it is undecidable for NDS D = (K; H; f0; 1g) whether there exists w 2 f0; 1g such that pw (j ) = 0 for all 0  j  s ? 1. This propositions also yields, that the universe problem is undecidable for integer weighted nite automata. But our proof for this presented in Chapter 3 is much simpler, and the number of lines in the proof of the previous proposition is very large. The proof of the previous proposition uses the undecidability of the inclusion problem of the Ztransducers, a special type of a nite transducer. A nite transducer is a nite automaton with output, i.e. each transition has labels from A  B  , where B is the output alphabet. In a Ztransducer the input alphabet is binary, say f0; 1g, and the output alphabet is unary, say fcg. Further, the labels in transitions are from f0; 1g  fc; ccg and the transducer has only one initial and one nal state. A Ztransducer is deterministic, if the underlying automaton is deterministic, and complete, if the underlying automaton is complete. For a Ztranducer C , let 



O(C ) = (u; v) j u 2 f0; 1g+; v 2 fcg+ ; and v is a output of u : Lemma 4.6. It is undecidable for deterministic Ztransducer C and nondeterministic and complete Ztransducer D whether O(C )  O(D) The previous lemma is a corollary from [15]. It is a corollary of the next proposition. Proposition 4.7. It is undecidable for two nite transducers C and D with unary output alphabet whether 1) O(C )  O(D), 2) O(C ) = O(D).

51

For the proof of the previous proposition, see also Ibarra [10] and for further result, see Turakainen [23]. Lisovik's proof of the previous propositions in [15] uses the undecidability of the PCP, which, as we already mentioned, follows from the halting problem for Turing machines. We compare the two dierent chains of the undecidability reductions for the the equivalence problem of two "free nite substitutions on regular language in Figure 9 below.

52

Halting problem , @ , @ Theorem 2.3 ,

@@ @@ @R

, , , [20] , =, ,

PCP

Prex PCP

[15]

?

Inclusion for FT with unary output

Theorem 3.2

?

Universe problem for FA(Z)

[15]

?

Inclusion for Ztransducers

Corollary 3.8

[16]

? ? Reliability of the NDS Universe problem for binary FA(Z) ll ? ? ll [17] ? ll ? ?Theorem 4.2 ll ? l~ ?

Equivalence of the "-free nite substitutions on regular language

Figure 9: Two dierent proof chains for the undecidability of the equivalence problem of "free nite substitutions on the regular language bf0; 1gc.

53

References [1] J. Autebert, J. Berstel, and L. Boasson, Context-Free languages and Pushdown Automata, Handbook of Formal Languages (G. Rozenberg and A. Salomaa, eds.), vol. 1, Springer-Verlag, 1997. [2] B. Baker and R. Book, Reversal-bounded multipushdown machines, J. Comput. System Sci. 8 (1974), 315332. [3] K. Culik II and J. Karhumäki, Decision problems solved with the help of the Ehrenfeucht's conjecture, Bulletin of the EATCS, no. 27, 1985, pp. 3035. [4] A. Ehrenfeucht, J. Karhumäki, and G. Rozenberg, The (generalized) Post Correspondence Problem with lists consisting of two words is decidable, Theoret. Comput. Sci. 21 (1982), 119144. [5] S. Eilenberg, Automata, languages and machines, vol. A, Academic Press, 1974. [6] S. A. Greibach, An innite hierarchy of context-free languages, J. Assoc. Comput. Mach. 16 (1969), 91106. [7] V. Halava and T. Harju, Undecidability in integer weighted nite automata, Tech. Report 158, Turku Centre for Computer Science, January 1998. [8]

, Undecidability of the equivalence of nite substitutions on regular language, Tech. Report 160, Turku Centre for Computer Science, February 1998.

[9] M. A. Harrison, Introduction to Formal Language Theory, AddisonWesley, 1978. [10] O. H. Ibarra, The unsolvability of the equivalence problem for -free NGSM's with unary input (output) alphabet and applications, SIAM J. of Comput. 7 (1978), no. 4, 524532. [11]

, Restricted one-counter machines with undecidable universe problems, Math. Systems Theory 13 (1979), 181186.

[12] M. Jantzen, Conuent String Rewriting, Springer-Verlag, 1988. 54

[13] J. Karhumäki, The equivalence of mappings on languages, Trends, techniques, and problems in theoretical computer science (Smolenice, 1986), Lecture Notes in Comput. Sci., vol. 281, Springer, 1987, pp. 2638. [14] J. Karhumäki, Equations over nite sets of words and equivalence problems in automata theory, Theoret. Comput. Sci. 108 (1993), no. 1, 103 118. [15] L. P. Lisovik, Minimal undecidable identity problem for nite-automaton mappings, Cybernetics 19 (1983), no. 2, 160165. [16] , An undecidable problem for countable Markov chains, Cybernetics 27 (1991), no. 2, 163169. , Nondeterministic systems and nite substitutions on regular [17] language, Bulletin of the EATCS, no. 63, 1997, pp. 156160. [18] Y. Matiyasevich and G. Sénizergues, Decision problems for semi-Thue systems with a few rules, Proceedings, 11th Annual IEEE Symposium on Logic in Computer Science (New Brunswick, New Jersey), IEEE Computer Society Press, 2730 July 1996, pp. 523531. [19] V. Mitrana and R. Stiebe, The accepting power of nite automata over groups, New Trends in Formal Language (G. P un and A. Salomaa, eds.), Lecture Notes in Comput. Sci., vol. 1218, Springer-Verlag, 1997, pp. 3948. [20] E. Post, A variant of a recursively unsolvable problem, Bulletin of Amer. Math. Soc. 52 (1946), 264268. [21] G. Rozenberg and A. Salomaa, Cornerstones of Undecidability, Prentice Hall, 1994. [22] A. Salomaa, Formal languages, Academic Press, 1973. [23] P. Turakainen, The undecidability of some equivalence problems concerning ngsm's and nite substitutions, Theoret. Comput. Sci. 174 (1997), no. 1-2, 269274.

55

Turku Centre for Computer Science Lemminkäisenkatu 14 FIN-20520 Turku Finland http://www.tucs.abo.

University of Turku  Department of Mathematical Sciences

Åbo Akademi University  Department of Computer Science  Institute for Advanced Management Systems Research

Turku School of Economics and Business Administration  Institute of Information Systems Science